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_b yahoo.com>,
  12. * Jan-Oliver Wagner <jan intevation.de>
  13. * PURPOSE: displays a barscale on graphics monitor
  14. * COPYRIGHT: (C) 1999-2011 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, *fsize;
  41. struct Flag *feet, *top, *linescale, *northarrow, *scalebar;
  42. struct Cell_head W;
  43. int fontsize;
  44. /* Initialize the GIS calls */
  45. G_gisinit(argv[0]);
  46. module = G_define_module();
  47. G_add_keyword(_("display"));
  48. G_add_keyword(_("cartography"));
  49. module->description = _("Displays a barscale on the graphics monitor.");
  50. feet = G_define_flag();
  51. feet->key = 'f';
  52. feet->description = _("Use feet/miles instead of meters");
  53. linescale = G_define_flag();
  54. linescale->key = 'l';
  55. linescale->description = _("Draw a line scale instead of a bar scale");
  56. top = G_define_flag();
  57. top->key = 't';
  58. top->description = _("Write text on top of the scale, not to the right");
  59. northarrow = G_define_flag();
  60. northarrow->key = 'n';
  61. northarrow->description = _("Draw a north arrow only");
  62. scalebar = G_define_flag();
  63. scalebar->key = 's';
  64. scalebar->description = _("Draw a scale bar only");
  65. opt1 = G_define_standard_option(G_OPT_C_BG);
  66. opt1->key = "bcolor";
  67. opt2 = G_define_standard_option(G_OPT_C_FG);
  68. opt2->key = "tcolor";
  69. opt2->label = _("Text color");
  70. opt3 = G_define_option();
  71. opt3->key = "at";
  72. opt3->key_desc = "x,y";
  73. opt3->type = TYPE_DOUBLE;
  74. opt3->answer = "0.0,5.0";
  75. opt3->options = "0-100";
  76. opt3->required = NO;
  77. opt3->description =
  78. _("The screen coordinates for top-left corner of label ([0,0] is lower-left of frame)");
  79. fsize = G_define_option();
  80. fsize->key = "fontsize";
  81. fsize->type = TYPE_INTEGER;
  82. fsize->required = NO;
  83. fsize->answer = "14";
  84. fsize->options = "1-72";
  85. fsize->description = _("Font size");
  86. if (G_parser(argc, argv))
  87. exit(EXIT_FAILURE);
  88. G_get_window(&W);
  89. if (W.proj == PROJECTION_LL && !northarrow->answer)
  90. G_fatal_error(_("%s does not work with a latitude-longitude location"),
  91. argv[0]);
  92. if (linescale->answer)
  93. do_bar = 0;
  94. use_feet = feet->answer ? 1 : 0;
  95. if (northarrow->answer && scalebar->answer)
  96. G_fatal_error(_("Choose either -n or -s flag"));
  97. if (northarrow->answer)
  98. draw = 1;
  99. else if (scalebar->answer)
  100. draw = 2;
  101. sscanf(opt3->answers[0], "%lf", &east);
  102. sscanf(opt3->answers[1], "%lf", &north);
  103. fontsize = atoi(fsize->answer);
  104. if (D_open_driver() != 0)
  105. G_fatal_error(_("No graphics device selected. "
  106. "Use d.mon to select graphics device."));
  107. D_setup(0);
  108. /* Parse and select background color */
  109. color1 = D_parse_color(opt1->answer, 1);
  110. if (color1 == 0)
  111. do_background = 0;
  112. /* Parse and select foreground color */
  113. color2 = D_parse_color(opt2->answer, 0);
  114. /* Draw the scale */
  115. draw_scale(top->answer, fontsize);
  116. D_save_command(G_recreate_command());
  117. D_close_driver();
  118. exit(EXIT_SUCCESS);
  119. }