main.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /****************************************************************************
  2. *
  3. * MODULE: d.graph
  4. * AUTHOR(S): Jim Westervelt (CERL) (original contributor)
  5. * Markus Neteler <neteler itc.it>,
  6. * Roberto Flor <flor itc.it>,
  7. * Bernhard Reiter <bernhard intevation.de>,
  8. * Cedric Shock <cedricgrass shockfamily.net>,
  9. * Huidae Cho <grass4u gmail.com>,
  10. * Eric G. Miller <egm2 jps.net>,
  11. * Glynn Clements <glynn gclements.plus.com>,
  12. * Hamish Bowman <hamish_b yahoo.com>,
  13. * Jan-Oliver Wagner <jan intevation.de>
  14. * PURPOSE: Draw graphics in a graphics window. Graph lines come from
  15. * stdin unless input specified.
  16. * COPYRIGHT: (C) 1999-2006 by the GRASS Development Team
  17. *
  18. * This program is free software under the GNU General Public
  19. * License (>=v2). Read the file COPYING that comes with GRASS
  20. * for details.
  21. *
  22. *****************************************************************************/
  23. /*
  24. * d.graph
  25. *
  26. *
  27. *
  28. */
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <grass/gis.h>
  32. #include <grass/colors.h>
  33. #include <grass/raster.h>
  34. #include <grass/display.h>
  35. #include <grass/glocale.h>
  36. #include "options.h"
  37. #include "local_proto.h"
  38. float hsize;
  39. float vsize;
  40. int mapunits;
  41. FILE *infile;
  42. int main(int argc, char **argv)
  43. {
  44. struct GModule *module;
  45. struct Option *opt1, *opt2;
  46. struct Flag *mapcoords;
  47. int R, G, B, color = 0;
  48. /* Initialize the GIS calls */
  49. G_gisinit(argv[0]);
  50. module = G_define_module();
  51. G_add_keyword(_("display"));
  52. G_add_keyword(_("cartography"));
  53. module->description =
  54. _("Program for generating and displaying simple graphics on the "
  55. "display monitor.");
  56. opt1 = G_define_option();
  57. opt1->key = "input";
  58. opt1->type = TYPE_STRING;
  59. opt1->required = NO;
  60. opt1->description = _("Name of file containing graphics commands, "
  61. "if not given reads from standard input");
  62. opt1->gisprompt = "old_file,file,input";
  63. opt2 = G_define_option();
  64. opt2->key = "color";
  65. opt2->type = TYPE_STRING;
  66. opt2->required = NO;
  67. opt2->description = _("Color to draw with, either a standard GRASS color "
  68. "or R:G:B triplet");
  69. opt2->answer = DEFAULT_FG_COLOR;
  70. opt2->gisprompt = "old_color,color,color";
  71. mapcoords = G_define_flag();
  72. mapcoords->key = 'm';
  73. mapcoords->description = _("Coordinates are given in map units");
  74. /* Check command line */
  75. if (G_parser(argc, argv))
  76. exit(EXIT_FAILURE);
  77. /* default font scaling: 5% of active frame */
  78. hsize = vsize = 5.;
  79. if (opt1->answer != NULL) {
  80. if ((infile = fopen(opt1->answer, "r")) == NULL)
  81. G_fatal_error(_("Graph file <%s> not found"), opt1->answer);
  82. }
  83. else
  84. infile = stdin;
  85. /* open graphics window */
  86. if (D_open_driver() != 0)
  87. G_fatal_error(_("No graphics device selected. "
  88. "Use d.mon to select graphics device."));
  89. /* Parse and select color */
  90. if (opt2->answer != NULL) {
  91. color = G_str_to_color(opt2->answer, &R, &G, &B);
  92. if (color == 0)
  93. G_fatal_error(_("[%s]: No such color"), opt2->answer);
  94. if (color == 1) {
  95. D_RGB_color(R, G, B);
  96. set_last_color(R, G, B, RGBA_COLOR_OPAQUE);
  97. }
  98. else /* (color==2) is "none" */
  99. set_last_color(0, 0, 0, RGBA_COLOR_NONE);
  100. }
  101. if (mapcoords->answer) {
  102. mapunits = TRUE;
  103. D_setup(0);
  104. }
  105. else {
  106. D_setup2(0, 0, 100, 0, 0, 100);
  107. mapunits = FALSE;
  108. }
  109. /* Do the graphics */
  110. set_graph_stuff();
  111. set_text_size();
  112. graphics(infile);
  113. D_save_command(G_recreate_command());
  114. D_close_driver();
  115. exit(EXIT_SUCCESS);
  116. }