what.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include <string.h>
  2. #include <grass/display.h>
  3. #include <grass/glocale.h>
  4. #include "what.h"
  5. #include "local_proto.h"
  6. int what(int once, int terse, int colrow, char *fs, int width, int mwidth)
  7. {
  8. int i;
  9. int row, col;
  10. int nrows, ncols;
  11. CELL *buf, null_cell;
  12. DCELL *dbuf, null_dcell;
  13. struct Cell_head window;
  14. int screen_x, screen_y;
  15. double east, north;
  16. int button;
  17. RASTER_MAP_TYPE *map_type;
  18. map_type = (RASTER_MAP_TYPE *) G_malloc(nrasts * sizeof(RASTER_MAP_TYPE));
  19. G_get_set_window(&window);
  20. nrows = window.rows;
  21. ncols = window.cols;
  22. buf = Rast_allocate_c_buf();
  23. dbuf = Rast_allocate_d_buf();
  24. screen_x = ((int)D_get_d_west() + (int)D_get_d_east()) / 2;
  25. screen_y = ((int)D_get_d_north() + (int)D_get_d_south()) / 2;
  26. for (i = 0; i < nrasts; i++)
  27. map_type[i] = Rast_get_map_type(fd[i]);
  28. do {
  29. if (!terse)
  30. show_buttons(once);
  31. R_get_location_with_pointer(&screen_x, &screen_y, &button);
  32. if (!once) {
  33. if (button == 2)
  34. continue;
  35. if (button == 3)
  36. break;
  37. }
  38. east = D_d_to_u_col(screen_x + 0.5);
  39. north = D_d_to_u_row(screen_y + 0.5);
  40. col = D_d_to_a_col(screen_x + 0.5);
  41. row = D_d_to_a_row(screen_y + 0.5);
  42. show_utm(name[0], mapset[0], north, east, &window, terse, colrow,
  43. button, fs);
  44. Rast_set_c_null_value(&null_cell, 1);
  45. Rast_set_d_null_value(&null_dcell, 1);
  46. for (i = 0; i < nrasts; i++) {
  47. if (row < 0 || row >= nrows || col < 0 || col >= ncols) {
  48. G_message(_("You are clicking outside the map"));
  49. continue;
  50. }
  51. Rast_get_c_row(fd[i], buf, row);
  52. if (map_type[i] == CELL_TYPE) {
  53. show_cat(width, mwidth, name[i], mapset[i], buf[col],
  54. Rast_get_c_cat(&buf[col], &cats[i]), terse, fs,
  55. map_type[i]);
  56. continue;
  57. }
  58. else { /* fp map */
  59. show_cat(width, mwidth, name[i], mapset[i], buf[col],
  60. "", terse, fs, map_type[i]);
  61. }
  62. if (map_type[i] == CELL_TYPE)
  63. continue;
  64. Rast_get_d_row(fd[i], dbuf, row);
  65. show_dval(width, mwidth, name[i], mapset[i], dbuf[col],
  66. Rast_get_d_cat(&dbuf[col], &cats[i]), terse,
  67. fs, map_type[i]);
  68. }
  69. }
  70. while (!once);
  71. return 0;
  72. }