main.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /****************************************************************************
  2. *
  3. * MODULE: r.digit
  4. *
  5. * AUTHOR(S): Michael Shapiro - CERL
  6. *
  7. * PURPOSE: Interactive tool used to draw and save vector features
  8. * on a graphics monitor using a pointing device (mouse)
  9. * and save to a raster map.
  10. *
  11. * COPYRIGHT: (C) 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 <string.h>
  20. #include <unistd.h>
  21. #include <grass/gis.h>
  22. #include <grass/display.h>
  23. #include "local_proto.h"
  24. #include <grass/glocale.h>
  25. int main(int argc, char **argv)
  26. {
  27. FILE *fd;
  28. char *polyfile, *mapname;
  29. int any;
  30. struct GModule *module;
  31. struct Option *output, *bgcmd;
  32. /* must run in a term window */
  33. G_putenv("GRASS_UI_TERM", "1");
  34. /* Initialize the GIS calls */
  35. G_gisinit(argv[0]);
  36. module = G_define_module();
  37. G_add_keyword(_("raster"));
  38. module->description =
  39. _("Interactive tool used to draw and save vector features on a graphics"
  40. " monitor using a pointing device (mouse) and save to a raster map.");
  41. output = G_define_standard_option(G_OPT_R_OUTPUT);
  42. bgcmd = G_define_option();
  43. bgcmd->key = "bgcmd";
  44. bgcmd->type = TYPE_STRING;
  45. bgcmd->description =
  46. _("Display commands to be used for canvas backdrop (separated by ';')");
  47. if (G_parser(argc, argv))
  48. exit(EXIT_FAILURE);
  49. mapname = output->answer;
  50. #ifdef DEBUG
  51. polyfile = "/tmp/r.digit.out";
  52. #else
  53. polyfile = G_tempfile();
  54. #endif
  55. fd = fopen(polyfile, "w");
  56. if (fd == NULL) {
  57. perror(polyfile);
  58. exit(EXIT_FAILURE);
  59. }
  60. if (bgcmd->answer)
  61. G_system(bgcmd->answer);
  62. /* open the graphics and get it setup */
  63. if (R_open_driver() != 0)
  64. G_fatal_error(_("No graphics device selected!"));
  65. setup_graphics();
  66. /* Do the digitizing and record the output into the polyfile */
  67. any = digitize(fd);
  68. fclose(fd);
  69. /* close the graphics */
  70. R_close_driver();
  71. #ifdef DEBUG
  72. fprintf(stdout, "Output is in %s\n", polyfile);
  73. exit(EXIT_FAILURE);
  74. #endif
  75. if (any)
  76. create_map(mapname, polyfile);
  77. else
  78. G_message(_("No map created"));
  79. unlink(polyfile);
  80. return (EXIT_SUCCESS);
  81. }