get_label.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 <grass/gis.h>
  19. #include <grass/display.h>
  20. #include <grass/glocale.h>
  21. long get_cat(char *type)
  22. {
  23. char buffer[256];
  24. long cat;
  25. for (;;) {
  26. fprintf(stdout, _("Enter the category number for this %s: "), type);
  27. if (!G_gets(buffer))
  28. continue;;
  29. if (sscanf(buffer, "%ld", &cat) != 1)
  30. continue;
  31. break;
  32. }
  33. return cat;
  34. }
  35. char *get_label(long cat, struct Categories *labels)
  36. {
  37. static char buffer[1024];
  38. for (;;) {
  39. fprintf(stdout, _("Enter a label for category %ld [%s] "),
  40. cat, Rast_get_c_cat((CELL *) &cat, labels));
  41. if (!G_gets(buffer))
  42. continue;;
  43. G_strip(buffer);
  44. break;
  45. }
  46. return buffer;
  47. }
  48. int get_category(FILE * fd, char *type, struct Categories *labels)
  49. {
  50. long cat;
  51. char *lbl;
  52. R_stabilize(); /* force out all graphics */
  53. do {
  54. fprintf(stdout, "\n");
  55. cat = get_cat(type);
  56. lbl = get_label(cat, labels);
  57. fprintf(stdout, "%ld [%s]\n", cat,
  58. *lbl ? lbl : Rast_get_c_cat((CELL) cat, labels));
  59. } while (!G_yes(_("Look ok? "), 1));
  60. if (*lbl)
  61. Rast_set_c_cat((CELL *) &cat, (CELL *) &cat, lbl, labels);
  62. fprintf(fd, "= %ld %s\n", cat, lbl);
  63. return (0);
  64. }