main.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /****************************************************************************
  2. *
  3. * MODULE: d.barscale
  4. * AUTHOR(S): unknown but from CERL code (original contributor)
  5. * Markus Neteler <neteler itc.it>,
  6. * Bernhard Reiter <bernhard intevation.de>,
  7. * Cedric Shock <cedricgrass shockfamily.net>,
  8. * Huidae Cho <grass4u gmail.com>,
  9. * Eric G. Miller <egm2 jps.net>,
  10. * Glynn Clements <glynn gclements.plus.com>,
  11. * Hamish Bowman <hamish_b yahoo.com>,
  12. * Jan-Oliver Wagner <jan intevation.de>
  13. * PURPOSE: displays a barscale on graphics monitor
  14. * COPYRIGHT: (C) 1999-2007 by the GRASS Development Team
  15. *
  16. * This program is free software under the GNU General Public
  17. * License (>=v2). Read the file COPYING that comes with GRASS
  18. * for details.
  19. *
  20. *****************************************************************************/
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <unistd.h>
  24. #include <string.h>
  25. #include <grass/gis.h>
  26. #include <grass/display.h>
  27. #include "options.h"
  28. #include <grass/glocale.h>
  29. int color1;
  30. int color2;
  31. double east;
  32. double north;
  33. int use_feet;
  34. int do_background = 1;
  35. int do_bar = 1;
  36. int draw = 0;
  37. int main(int argc, char **argv)
  38. {
  39. struct GModule *module;
  40. struct Option *opt1, *opt2, *opt3;
  41. struct Flag *feet, *top, *linescale, *northarrow, *scalebar;
  42. struct Cell_head W;
  43. /* Initialize the GIS calls */
  44. G_gisinit(argv[0]);
  45. module = G_define_module();
  46. G_add_keyword(_("display"));
  47. G_add_keyword(_("cartography"));
  48. module->description = _("Displays a barscale on the graphics monitor.");
  49. feet = G_define_flag();
  50. feet->key = 'f';
  51. feet->description = _("Use feet/miles instead of meters");
  52. linescale = G_define_flag();
  53. linescale->key = 'l';
  54. linescale->description = _("Draw a line scale instead of a bar scale");
  55. top = G_define_flag();
  56. top->key = 't';
  57. top->description = _("Write text on top of the scale, not to the right");
  58. northarrow = G_define_flag();
  59. northarrow->key = 'n';
  60. northarrow->description = _("Draw a north arrow only");
  61. scalebar = G_define_flag();
  62. scalebar->key = 's';
  63. scalebar->description = _("Draw a scale bar only");
  64. opt1 = G_define_standard_option(G_OPT_C_BG);
  65. opt1->key = "bcolor";
  66. opt2 = G_define_standard_option(G_OPT_C_FG);
  67. opt2->key = "tcolor";
  68. opt2->label = _("Text color");
  69. opt3 = G_define_option();
  70. opt3->key = "at";
  71. opt3->key_desc = "x,y";
  72. opt3->type = TYPE_DOUBLE;
  73. opt3->answer = "0.0,0.0";
  74. opt3->options = "0-100";
  75. opt3->required = NO;
  76. opt3->description =
  77. _("The screen coordinates for top-left corner of label ([0,0] is top-left of frame)");
  78. if (G_parser(argc, argv))
  79. exit(EXIT_FAILURE);
  80. G_get_window(&W);
  81. if (W.proj == PROJECTION_LL && !northarrow->answer)
  82. G_fatal_error(_("%s does not work with a latitude-longitude location"),
  83. argv[0]);
  84. if (linescale->answer)
  85. do_bar = 0;
  86. use_feet = feet->answer ? 1 : 0;
  87. if (northarrow->answer && scalebar->answer)
  88. G_fatal_error(_("Choose either -n or -s flag"));
  89. if (northarrow->answer)
  90. draw = 1;
  91. else if (scalebar->answer)
  92. draw = 2;
  93. sscanf(opt3->answers[0], "%lf", &east);
  94. sscanf(opt3->answers[1], "%lf", &north);
  95. if (D_open_driver() != 0)
  96. G_fatal_error(_("No graphics device selected"));
  97. D_setup(0);
  98. /* Parse and select background color */
  99. color1 = D_parse_color(opt1->answer, 1);
  100. if (color1 == 0)
  101. do_background = 0;
  102. /* Parse and select foreground color */
  103. color2 = D_parse_color(opt2->answer, 0);
  104. /* Draw the scale */
  105. draw_scale(top->answer);
  106. D_close_driver();
  107. exit(EXIT_SUCCESS);
  108. }