main.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /****************************************************************************
  2. *
  3. * MODULE: d.paint.labels
  4. * AUTHOR(S): Jim Westervelt (CERL) (original contributor)
  5. * Radim Blazek <radim.blazek gmail.com>,
  6. * Stephan Holl <sholl gmx net>,
  7. * Glynn Clements <glynn gclements.plus.com>,
  8. * Hamish Bowman <hamish_b yahoo.com>,
  9. * Markus Neteler <neteler itc.it>
  10. * PURPOSE: displays a paint label file in the active display frame
  11. * COPYRIGHT: (C) 2003-2006 by the GRASS Development Team
  12. *
  13. * This program is free software under the GNU General Public
  14. * License (>=v2). Read the file COPYING that comes with GRASS
  15. * for details.
  16. *
  17. *****************************************************************************/
  18. #include <stdlib.h>
  19. #include <math.h>
  20. #include <grass/gis.h>
  21. #include <grass/display.h>
  22. #include "local_proto.h"
  23. #include <grass/glocale.h>
  24. int main(int argc, char **argv)
  25. {
  26. struct Cell_head window;
  27. char *label_name;
  28. const char *mapset;
  29. double minreg, maxreg, reg, dx, dy;
  30. FILE *infile;
  31. struct Option *opt1;
  32. struct Option *maxreg_opt, *minreg_opt;
  33. struct Flag *horiz_flag;
  34. struct GModule *module;
  35. /* Initialize the GIS calls */
  36. G_gisinit(argv[0]);
  37. /* Set description */
  38. module = G_define_module();
  39. G_add_keyword(_("display"));
  40. G_add_keyword(_("paint labels"));
  41. module->description =
  42. _("Displays text labels (created with v.label) "
  43. "to the active frame on the graphics monitor.");
  44. horiz_flag = G_define_flag();
  45. horiz_flag->key = 'i';
  46. horiz_flag->description =
  47. _("Ignore rotation setting and draw horizontally");
  48. opt1 = G_define_option();
  49. opt1->key = "labels";
  50. opt1->type = TYPE_STRING;
  51. opt1->required = YES;
  52. opt1->gisprompt = "old,paint/labels,paint labels";
  53. opt1->description = _("Name of label file");
  54. minreg_opt = G_define_option();
  55. minreg_opt->key = "minreg";
  56. minreg_opt->type = TYPE_DOUBLE;
  57. minreg_opt->required = NO;
  58. minreg_opt->description =
  59. _("Minimum region size (diagonal) when labels are displayed");
  60. maxreg_opt = G_define_option();
  61. maxreg_opt->key = "maxreg";
  62. maxreg_opt->type = TYPE_DOUBLE;
  63. maxreg_opt->required = NO;
  64. maxreg_opt->description =
  65. _("Maximum region size (diagonal) when labels are displayed");
  66. /* Check command line */
  67. if (G_parser(argc, argv))
  68. exit(EXIT_FAILURE);
  69. /* Save map name */
  70. label_name = opt1->answer;
  71. /* Make sure map is available */
  72. mapset = G_find_file("paint/labels", label_name, "");
  73. if (mapset == NULL)
  74. G_fatal_error(_("Label file <%s> not found"), label_name);
  75. /* Read in the map window associated with window */
  76. G_get_window(&window);
  77. /* Check min/max region */
  78. dx = window.east - window.west;
  79. dy = window.north - window.south;
  80. reg = sqrt(dx * dx + dy * dy);
  81. if (minreg_opt->answer) {
  82. minreg = atof(minreg_opt->answer);
  83. if (reg < minreg) {
  84. G_warning(_("Region size is lower than minreg, nothing displayed."));
  85. D_close_driver();
  86. exit(0);
  87. }
  88. }
  89. if (maxreg_opt->answer) {
  90. maxreg = atof(maxreg_opt->answer);
  91. if (reg > maxreg) {
  92. G_warning(_("Region size is greater than maxreg, nothing displayed."));
  93. D_close_driver();
  94. exit(0);
  95. }
  96. }
  97. /* Open map is available */
  98. infile = G_fopen_old("paint/labels", label_name, mapset);
  99. if (infile == NULL)
  100. G_fatal_error(_("Unable to open label file <%s>"), label_name);
  101. D_open_driver();
  102. D_setup(0);
  103. /* Go draw the raster map */
  104. do_labels(infile, !horiz_flag->answer);
  105. D_save_command(G_recreate_command());
  106. D_close_driver();
  107. exit(EXIT_SUCCESS);
  108. }