main.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /****************************************************************************
  2. *
  3. * MODULE: d.northarrow
  4. *
  5. * AUTHOR(S): Hamish Bowman, Dunedin, NZ <hamish_b yahoo.com>
  6. *
  7. * PURPOSE: Displays a north arrow on graphics monitor
  8. *
  9. * COPYRIGHT: (C) 2013 by the GRASS Development Team
  10. *
  11. * This program is free software under the GNU General Public
  12. * License (>=v2). Read the file COPYING that comes with GRASS
  13. * for details.
  14. *
  15. *****************************************************************************/
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <unistd.h>
  19. #include <string.h>
  20. #include <grass/gis.h>
  21. #include <grass/display.h>
  22. #include <grass/glocale.h>
  23. #include "options.h"
  24. int fg_color, bg_color;
  25. int do_background = TRUE;
  26. int main(int argc, char **argv)
  27. {
  28. struct GModule *module;
  29. struct Option *bg_color_opt, *fg_color_opt, *coords, *n_arrow, *fsize;
  30. struct Flag *no_text;
  31. double east, north;
  32. double fontsize;
  33. /* Initialize the GIS calls */
  34. G_gisinit(argv[0]);
  35. module = G_define_module();
  36. G_add_keyword(_("display"));
  37. G_add_keyword(_("cartography"));
  38. module->description = _("Displays a north arrow on the graphics monitor.");
  39. n_arrow = G_define_option();
  40. n_arrow->key = "style";
  41. n_arrow->description = _("North arrow style (used only with the -n flag)");
  42. n_arrow->options = "1a,1b,2,3,4,5,6,7a,7b,8a,8b,9";
  43. n_arrow->answer = "1a";
  44. n_arrow->guisection = _("Style");
  45. coords = G_define_option();
  46. coords->key = "at";
  47. coords->key_desc = "x,y";
  48. coords->type = TYPE_DOUBLE;
  49. coords->answer = "85.0,15.0";
  50. coords->options = "0-100";
  51. coords->label =
  52. _("Screen coordinates of the rectangle's top-left corner");
  53. coords->description = _("(0,0) is lower-left of the display frame");
  54. fg_color_opt = G_define_standard_option(G_OPT_C_FG);
  55. fg_color_opt->label = _("North arrow color");
  56. fg_color_opt->guisection = _("Colors");
  57. bg_color_opt = G_define_standard_option(G_OPT_C_BG);
  58. bg_color_opt->label = _("Background color");
  59. bg_color_opt->answer = _("black");
  60. bg_color_opt->guisection = _("Colors");
  61. fsize = G_define_option();
  62. fsize->key = "fontsize";
  63. fsize->type = TYPE_DOUBLE;
  64. fsize->required = NO;
  65. fsize->answer = "12";
  66. fsize->options = "1-360";
  67. fsize->description = _("Font size");
  68. no_text = G_define_flag();
  69. no_text->key = 't';
  70. no_text->description = _("Draw the symbol without text");
  71. if (G_parser(argc, argv))
  72. exit(EXIT_FAILURE);
  73. sscanf(coords->answers[0], "%lf", &east);
  74. sscanf(coords->answers[1], "%lf", &north);
  75. fontsize = atof(fsize->answer);
  76. if (no_text->answer)
  77. fontsize = -1;
  78. /* Parse and select foreground color */
  79. fg_color = D_parse_color(fg_color_opt->answer, 0);
  80. /* Parse and select background color */
  81. bg_color = D_parse_color(bg_color_opt->answer, 1);
  82. if (bg_color == 0)
  83. do_background = FALSE;
  84. if (D_open_driver() != 0)
  85. G_fatal_error(_("No graphics device selected. "
  86. "Use d.mon to select graphics device."));
  87. D_setup(0);
  88. draw_n_arrow(east, north, fontsize, n_arrow->answer);
  89. D_save_command(G_recreate_command());
  90. D_close_driver();
  91. exit(EXIT_SUCCESS);
  92. }