main.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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_standard_option(G_OPT_F_INPUT);
  57. opt1->required = NO;
  58. opt1->description = _("Name of file containing graphics commands, "
  59. "if not given reads from standard input");
  60. opt2 = G_define_option();
  61. opt2->key = "color";
  62. opt2->type = TYPE_STRING;
  63. opt2->required = NO;
  64. opt2->description = _("Color to draw with, either a standard GRASS color "
  65. "or R:G:B triplet");
  66. opt2->answer = DEFAULT_FG_COLOR;
  67. opt2->gisprompt = "old_color,color,color";
  68. mapcoords = G_define_flag();
  69. mapcoords->key = 'm';
  70. mapcoords->description = _("Coordinates are given in map units");
  71. /* Check command line */
  72. if (G_parser(argc, argv))
  73. exit(EXIT_FAILURE);
  74. /* default font scaling: 5% of active frame */
  75. hsize = vsize = 5.;
  76. if (opt1->answer != NULL) {
  77. if ((infile = fopen(opt1->answer, "r")) == NULL)
  78. G_fatal_error(_("Graph file <%s> not found"), opt1->answer);
  79. }
  80. else
  81. infile = stdin;
  82. /* open graphics window */
  83. D_open_driver();
  84. /* Parse and select color */
  85. if (opt2->answer != NULL) {
  86. color = G_str_to_color(opt2->answer, &R, &G, &B);
  87. if (color == 0)
  88. G_fatal_error(_("[%s]: No such color"), opt2->answer);
  89. if (color == 1) {
  90. D_RGB_color(R, G, B);
  91. set_last_color(R, G, B, RGBA_COLOR_OPAQUE);
  92. }
  93. else /* (color==2) is "none" */
  94. set_last_color(0, 0, 0, RGBA_COLOR_NONE);
  95. }
  96. if (mapcoords->answer) {
  97. mapunits = TRUE;
  98. D_setup(0);
  99. }
  100. else {
  101. D_setup2(0, 0, 100, 0, 0, 100);
  102. mapunits = FALSE;
  103. }
  104. /* Do the graphics */
  105. set_graph_stuff();
  106. set_text_size();
  107. graphics(infile);
  108. D_save_command(G_recreate_command());
  109. D_close_driver();
  110. exit(EXIT_SUCCESS);
  111. }