|
@@ -1,3 +1,4 @@
|
|
|
|
+
|
|
/****************************************************************************
|
|
/****************************************************************************
|
|
*
|
|
*
|
|
* MODULE: d.northarrow
|
|
* MODULE: d.northarrow
|
|
@@ -18,6 +19,7 @@
|
|
#include <stdlib.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
#include <string.h>
|
|
|
|
+#include <math.h>
|
|
#include <grass/gis.h>
|
|
#include <grass/gis.h>
|
|
#include <grass/display.h>
|
|
#include <grass/display.h>
|
|
#include <grass/glocale.h>
|
|
#include <grass/glocale.h>
|
|
@@ -30,10 +32,12 @@ int main(int argc, char **argv)
|
|
{
|
|
{
|
|
struct GModule *module;
|
|
struct GModule *module;
|
|
struct Option *bg_color_opt, *fg_color_opt, *coords, *n_arrow, *fsize,
|
|
struct Option *bg_color_opt, *fg_color_opt, *coords, *n_arrow, *fsize,
|
|
- *width_opt;
|
|
|
|
- struct Flag *no_text;
|
|
|
|
|
|
+ *width_opt, *rotation_opt, *lbl_opt;
|
|
|
|
+ struct Flag *no_text, *rotate_text, *rads;
|
|
double east, north;
|
|
double east, north;
|
|
|
|
+ double rotation;
|
|
double fontsize, line_width;
|
|
double fontsize, line_width;
|
|
|
|
+ int rot_with_text;
|
|
|
|
|
|
/* Initialize the GIS calls */
|
|
/* Initialize the GIS calls */
|
|
G_gisinit(argv[0]);
|
|
G_gisinit(argv[0]);
|
|
@@ -41,45 +45,34 @@ int main(int argc, char **argv)
|
|
module = G_define_module();
|
|
module = G_define_module();
|
|
G_add_keyword(_("display"));
|
|
G_add_keyword(_("display"));
|
|
G_add_keyword(_("cartography"));
|
|
G_add_keyword(_("cartography"));
|
|
- module->description = _("Displays a north arrow on the graphics monitor.");
|
|
|
|
|
|
+ module->description =
|
|
|
|
+ _("Displays a north arrow on the graphics monitor.");
|
|
|
|
|
|
n_arrow = G_define_option();
|
|
n_arrow = G_define_option();
|
|
n_arrow->key = "style";
|
|
n_arrow->key = "style";
|
|
n_arrow->description = _("North arrow style");
|
|
n_arrow->description = _("North arrow style");
|
|
- n_arrow->options = "1a,1b,2,3,4,5,6,7a,7b,8a,8b,9,fancy_compass,basic_compass";
|
|
|
|
- G_asprintf((char **) &(n_arrow->descriptions),
|
|
|
|
- "1a;%s;"
|
|
|
|
- "1b;%s;"
|
|
|
|
- "2;%s;"
|
|
|
|
- "3;%s;"
|
|
|
|
- "4;%s;"
|
|
|
|
- "5;%s;"
|
|
|
|
- "6;%s;"
|
|
|
|
- "7a;%s;"
|
|
|
|
- "7b;%s;"
|
|
|
|
- "8a;%s;"
|
|
|
|
- "8b;%s;"
|
|
|
|
- "9;%s;"
|
|
|
|
- "fancy_compass;%s;"
|
|
|
|
- "basic_compass;%s;",
|
|
|
|
|
|
+ n_arrow->options =
|
|
|
|
+ "1a,1b,2,3,4,5,6,7a,7b,8a,8b,9,fancy_compass,basic_compass,arrow1,arrow2,arrow3,star";
|
|
|
|
+ G_asprintf((char **)&(n_arrow->descriptions),
|
|
|
|
+ "1a;%s;" "1b;%s;" "2;%s;" "3;%s;" "4;%s;" "5;%s;" "6;%s;"
|
|
|
|
+ "7a;%s;" "7b;%s;" "8a;%s;" "8b;%s;" "9;%s;" "fancy_compass;%s;"
|
|
|
|
+ "basic_compass;%s;" "arrow1;%s;" "arrow2;%s;" "arrow3;%s;"
|
|
|
|
+ "star;%s;",
|
|
_("Two color arrowhead"),
|
|
_("Two color arrowhead"),
|
|
_("Two color arrowhead with circle"),
|
|
_("Two color arrowhead with circle"),
|
|
- _("Narrow with blending N"),
|
|
|
|
- _("Long with small arrowhead"),
|
|
|
|
|
|
+ _("Narrow with blending N"), _("Long with small arrowhead"),
|
|
_("Inverted narrow inside a circle"),
|
|
_("Inverted narrow inside a circle"),
|
|
_("Triangle and N inside a circle"),
|
|
_("Triangle and N inside a circle"),
|
|
_("Arrowhead and N inside a circle"),
|
|
_("Arrowhead and N inside a circle"),
|
|
_("Tall half convex arrowhead"),
|
|
_("Tall half convex arrowhead"),
|
|
- _("Tall half concave arrowhead"),
|
|
|
|
- _("Thin arrow in a circle"),
|
|
|
|
- _("Fat arrow in a circle"),
|
|
|
|
- _("One color arrowhead"),
|
|
|
|
- _("Fancy compass"),
|
|
|
|
- _("Basic compass"));
|
|
|
|
|
|
+ _("Tall half concave arrowhead"), _("Thin arrow in a circle"),
|
|
|
|
+ _("Fat arrow in a circle"), _("One color arrowhead"),
|
|
|
|
+ _("Fancy compass"), _("Basic compass"), _("Simple arrow"),
|
|
|
|
+ _("Thin arrow"), _("Fat arrow"), _("4-point star"));
|
|
n_arrow->answer = "1a";
|
|
n_arrow->answer = "1a";
|
|
n_arrow->guisection = _("Style");
|
|
n_arrow->guisection = _("Style");
|
|
n_arrow->gisprompt = "old,northarrow,northarrow";
|
|
n_arrow->gisprompt = "old,northarrow,northarrow";
|
|
-
|
|
|
|
|
|
+
|
|
coords = G_define_option();
|
|
coords = G_define_option();
|
|
coords->key = "at";
|
|
coords->key = "at";
|
|
coords->key_desc = "x,y";
|
|
coords->key_desc = "x,y";
|
|
@@ -87,9 +80,25 @@ int main(int argc, char **argv)
|
|
coords->answer = "85.0,15.0";
|
|
coords->answer = "85.0,15.0";
|
|
coords->options = "0-100";
|
|
coords->options = "0-100";
|
|
coords->label =
|
|
coords->label =
|
|
- _("Screen coordinates of the rectangle's top-left corner");
|
|
|
|
|
|
+ _("Screen coordinates of the rectangle's top-left corner");
|
|
coords->description = _("(0,0) is lower-left of the display frame");
|
|
coords->description = _("(0,0) is lower-left of the display frame");
|
|
|
|
|
|
|
|
+ rotation_opt = G_define_option();
|
|
|
|
+ rotation_opt->key = "rotation";
|
|
|
|
+ rotation_opt->type = TYPE_DOUBLE;
|
|
|
|
+ rotation_opt->required = NO;
|
|
|
|
+ rotation_opt->answer = "0";
|
|
|
|
+ rotation_opt->description =
|
|
|
|
+ _("Rotation angle in degrees (counter-clockwise)");
|
|
|
|
+
|
|
|
|
+ lbl_opt = G_define_option();
|
|
|
|
+ lbl_opt->key = "label";
|
|
|
|
+ lbl_opt->required = NO;
|
|
|
|
+ lbl_opt->answer = "N";
|
|
|
|
+ lbl_opt->description =
|
|
|
|
+ _("Displayed letter on the top of arrow");
|
|
|
|
+ lbl_opt->guisection = _("Text");
|
|
|
|
+
|
|
fg_color_opt = G_define_standard_option(G_OPT_C);
|
|
fg_color_opt = G_define_standard_option(G_OPT_C);
|
|
fg_color_opt->label = _("Line color");
|
|
fg_color_opt->label = _("Line color");
|
|
fg_color_opt->guisection = _("Colors");
|
|
fg_color_opt->guisection = _("Colors");
|
|
@@ -114,31 +123,49 @@ int main(int argc, char **argv)
|
|
fsize->options = "1-360";
|
|
fsize->options = "1-360";
|
|
fsize->description = _("Font size");
|
|
fsize->description = _("Font size");
|
|
fsize->guisection = _("Text");
|
|
fsize->guisection = _("Text");
|
|
-
|
|
|
|
|
|
+
|
|
no_text = G_define_flag();
|
|
no_text = G_define_flag();
|
|
no_text->key = 't';
|
|
no_text->key = 't';
|
|
no_text->description = _("Draw the symbol without text");
|
|
no_text->description = _("Draw the symbol without text");
|
|
no_text->guisection = _("Text");
|
|
no_text->guisection = _("Text");
|
|
|
|
|
|
-/* TODO:
|
|
|
|
- - add rotation= option to rotate the north arrow by an arbitrary amount.
|
|
|
|
- do a bit of trig to figure out where to put the "N" (and rotate it too).
|
|
|
|
- - add a -n flag to rotate to match true north instead of grid north.
|
|
|
|
|
|
+ rotate_text = G_define_flag();
|
|
|
|
+ rotate_text->key = 'w';
|
|
|
|
+ rotate_text->description = _("Do not rotate text with symbol");
|
|
|
|
+ rotate_text->guisection = _("Text");
|
|
|
|
+
|
|
|
|
+ rads = G_define_flag();
|
|
|
|
+ rads->key = 'r';
|
|
|
|
+ rads->description = _("Use radians instead of degrees for rotation");
|
|
|
|
+
|
|
|
|
+ /* TODO:
|
|
|
|
+ - add a -n flag to rotate to match true north instead of grid north.
|
|
Similar to 'g.region -n' but use the at=x,y coord for the convergence
|
|
Similar to 'g.region -n' but use the at=x,y coord for the convergence
|
|
angle calc. (assuming that's the center of the icon)
|
|
angle calc. (assuming that's the center of the icon)
|
|
- */
|
|
|
|
|
|
+ */
|
|
|
|
|
|
|
|
|
|
if (G_parser(argc, argv))
|
|
if (G_parser(argc, argv))
|
|
- exit(EXIT_FAILURE);
|
|
|
|
-
|
|
|
|
|
|
+ exit(EXIT_FAILURE);
|
|
|
|
|
|
sscanf(coords->answers[0], "%lf", &east);
|
|
sscanf(coords->answers[0], "%lf", &east);
|
|
sscanf(coords->answers[1], "%lf", &north);
|
|
sscanf(coords->answers[1], "%lf", &north);
|
|
|
|
|
|
fontsize = atof(fsize->answer);
|
|
fontsize = atof(fsize->answer);
|
|
if (no_text->answer)
|
|
if (no_text->answer)
|
|
- fontsize = -1;
|
|
|
|
|
|
+ fontsize = -1;
|
|
|
|
+
|
|
|
|
+ rot_with_text = 0;
|
|
|
|
+ if (!rotate_text->answer)
|
|
|
|
+ rot_with_text = 1;
|
|
|
|
+
|
|
|
|
+ /* Convert to radians */
|
|
|
|
+ rotation = atof(rotation_opt->answer);
|
|
|
|
+ if (!rads->answer)
|
|
|
|
+ rotation *= M_PI / 180.0;
|
|
|
|
+ rotation = fmod(rotation, 2.0 * M_PI);
|
|
|
|
+ if (rotation < 0.0)
|
|
|
|
+ rotation += 2.0 * M_PI;
|
|
|
|
|
|
/* Parse and select foreground color */
|
|
/* Parse and select foreground color */
|
|
fg_color = D_parse_color(fg_color_opt->answer, 0);
|
|
fg_color = D_parse_color(fg_color_opt->answer, 0);
|
|
@@ -146,7 +173,7 @@ int main(int argc, char **argv)
|
|
/* Parse and select background color */
|
|
/* Parse and select background color */
|
|
bg_color = D_parse_color(bg_color_opt->answer, 1);
|
|
bg_color = D_parse_color(bg_color_opt->answer, 1);
|
|
if (bg_color == 0)
|
|
if (bg_color == 0)
|
|
- do_background = FALSE;
|
|
|
|
|
|
+ do_background = FALSE;
|
|
|
|
|
|
line_width = atof(width_opt->answer);
|
|
line_width = atof(width_opt->answer);
|
|
if (line_width < 0)
|
|
if (line_width < 0)
|
|
@@ -154,12 +181,12 @@ int main(int argc, char **argv)
|
|
else if (line_width > 72)
|
|
else if (line_width > 72)
|
|
line_width = 72;
|
|
line_width = 72;
|
|
|
|
|
|
-
|
|
|
|
D_open_driver();
|
|
D_open_driver();
|
|
|
|
|
|
D_setup(0);
|
|
D_setup(0);
|
|
|
|
|
|
- draw_n_arrow(east, north, fontsize, n_arrow->answer, line_width);
|
|
|
|
|
|
+ draw_n_arrow(east, north, rotation, lbl_opt->answer, rot_with_text,
|
|
|
|
+ fontsize, n_arrow->answer, line_width);
|
|
|
|
|
|
D_save_command(G_recreate_command());
|
|
D_save_command(G_recreate_command());
|
|
D_close_driver();
|
|
D_close_driver();
|