main.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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_nospam 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 <grass/raster.h>
  28. #include "options.h"
  29. #include <grass/glocale.h>
  30. int color1;
  31. int color2;
  32. double east;
  33. double north;
  34. int use_feet;
  35. int do_background = 1;
  36. int do_bar = 1;
  37. int draw = 0;
  38. int main(int argc, char **argv)
  39. {
  40. struct GModule *module;
  41. struct Option *opt1, *opt2, *opt3;
  42. struct Flag *feet, *top, *linescale, *northarrow, *scalebar;
  43. struct Cell_head W;
  44. /* Initialize the GIS calls */
  45. G_gisinit(argv[0]);
  46. module = G_define_module();
  47. module->keywords = _("display, 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_option();
  65. opt1->key = "bcolor";
  66. opt1->type = TYPE_STRING;
  67. opt1->answer = DEFAULT_BG_COLOR;
  68. opt1->required = NO;
  69. opt1->description =
  70. _("Background color, either a standard GRASS color, R:G:B triplet, or \"none\"");
  71. opt1->gisprompt = GISPROMPT_COLOR;
  72. opt2 = G_define_option();
  73. opt2->key = "tcolor";
  74. opt2->type = TYPE_STRING;
  75. opt2->answer = DEFAULT_FG_COLOR;
  76. opt2->required = NO;
  77. opt2->description =
  78. _("Text color, either a standard GRASS color or R:G:B triplet");
  79. opt2->gisprompt = GISPROMPT_COLOR;
  80. opt3 = G_define_option();
  81. opt3->key = "at";
  82. opt3->key_desc = "x,y";
  83. opt3->type = TYPE_DOUBLE;
  84. opt3->answer = "0.0,0.0";
  85. opt3->options = "0-100";
  86. opt3->required = NO;
  87. opt3->description =
  88. _("The screen coordinates for top-left corner of label ([0,0] is top-left of frame)");
  89. if (G_parser(argc, argv))
  90. exit(EXIT_FAILURE);
  91. G_get_window(&W);
  92. if (W.proj == PROJECTION_LL && !northarrow->answer)
  93. G_fatal_error(_("%s does not work with a latitude-longitude location"),
  94. argv[0]);
  95. if (linescale->answer)
  96. do_bar = 0;
  97. use_feet = feet->answer ? 1 : 0;
  98. if (northarrow->answer && scalebar->answer)
  99. G_fatal_error(_("Choose either -n or -s flag"));
  100. if (northarrow->answer)
  101. draw = 1;
  102. else if (scalebar->answer)
  103. draw = 2;
  104. sscanf(opt3->answers[0], "%lf", &east);
  105. sscanf(opt3->answers[1], "%lf", &north);
  106. if (R_open_driver() != 0)
  107. G_fatal_error(_("No graphics device selected"));
  108. D_setup(0);
  109. /* Parse and select background color */
  110. color1 = D_parse_color(opt1->answer, 1);
  111. if (color1 == 0)
  112. do_background = 0;
  113. /* Parse and select foreground color */
  114. color2 = D_parse_color(opt2->answer, 0);
  115. /* Draw the scale */
  116. draw_scale(top->answer);
  117. R_close_driver();
  118. exit(EXIT_SUCCESS);
  119. }