123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- /****************************************************************************
- *
- * MODULE: d.barscale
- * AUTHOR(S): unknown but from CERL code (original contributor)
- * Markus Neteler <neteler itc.it>,
- * Bernhard Reiter <bernhard intevation.de>,
- * Cedric Shock <cedricgrass shockfamily.net>,
- * Huidae Cho <grass4u gmail.com>,
- * Eric G. Miller <egm2 jps.net>,
- * Glynn Clements <glynn gclements.plus.com>,
- * Hamish Bowman <hamish_b yahoo.com>,
- * Jan-Oliver Wagner <jan intevation.de>
- * PURPOSE: displays a barscale on graphics monitor
- * COPYRIGHT: (C) 1999-2007 by the GRASS Development Team
- *
- * This program is free software under the GNU General Public
- * License (>=v2). Read the file COPYING that comes with GRASS
- * for details.
- *
- *****************************************************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <string.h>
- #include <grass/gis.h>
- #include <grass/display.h>
- #include "options.h"
- #include <grass/glocale.h>
- int color1;
- int color2;
- double east;
- double north;
- int use_feet;
- int do_background = 1;
- int do_bar = 1;
- int draw = 0;
- int main(int argc, char **argv)
- {
- struct GModule *module;
- struct Option *opt1, *opt2, *opt3;
- struct Flag *feet, *top, *linescale, *northarrow, *scalebar;
- struct Cell_head W;
- /* Initialize the GIS calls */
- G_gisinit(argv[0]);
- module = G_define_module();
- G_add_keyword(_("display"));
- G_add_keyword(_("cartography"));
- module->description = _("Displays a barscale on the graphics monitor.");
- feet = G_define_flag();
- feet->key = 'f';
- feet->description = _("Use feet/miles instead of meters");
- linescale = G_define_flag();
- linescale->key = 'l';
- linescale->description = _("Draw a line scale instead of a bar scale");
- top = G_define_flag();
- top->key = 't';
- top->description = _("Write text on top of the scale, not to the right");
- northarrow = G_define_flag();
- northarrow->key = 'n';
- northarrow->description = _("Draw a north arrow only");
- scalebar = G_define_flag();
- scalebar->key = 's';
- scalebar->description = _("Draw a scale bar only");
- opt1 = G_define_standard_option(G_OPT_C_BG);
- opt1->key = "bcolor";
- opt2 = G_define_standard_option(G_OPT_C_FG);
- opt2->key = "tcolor";
- opt2->label = _("Text color");
-
- opt3 = G_define_option();
- opt3->key = "at";
- opt3->key_desc = "x,y";
- opt3->type = TYPE_DOUBLE;
- opt3->answer = "0.0,0.0";
- opt3->options = "0-100";
- opt3->required = NO;
- opt3->description =
- _("The screen coordinates for top-left corner of label ([0,0] is top-left of frame)");
- if (G_parser(argc, argv))
- exit(EXIT_FAILURE);
- G_get_window(&W);
- if (W.proj == PROJECTION_LL && !northarrow->answer)
- G_fatal_error(_("%s does not work with a latitude-longitude location"),
- argv[0]);
- if (linescale->answer)
- do_bar = 0;
- use_feet = feet->answer ? 1 : 0;
- if (northarrow->answer && scalebar->answer)
- G_fatal_error(_("Choose either -n or -s flag"));
- if (northarrow->answer)
- draw = 1;
- else if (scalebar->answer)
- draw = 2;
- sscanf(opt3->answers[0], "%lf", &east);
- sscanf(opt3->answers[1], "%lf", &north);
- if (D_open_driver() != 0)
- G_fatal_error(_("No graphics device selected"));
- D_setup(0);
- /* Parse and select background color */
- color1 = D_parse_color(opt1->answer, 1);
- if (color1 == 0)
- do_background = 0;
- /* Parse and select foreground color */
- color2 = D_parse_color(opt2->answer, 0);
- /* Draw the scale */
- draw_scale(top->answer);
- D_close_driver();
- exit(EXIT_SUCCESS);
- }
|