zoom_box.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #include "globals.h"
  2. #include "local_proto.h"
  3. #include <grass/display.h>
  4. static int zoom1(int, int);
  5. static int zoom2(int, int);
  6. static int cancel(void);
  7. static int x1, y1, x2, y2;
  8. static View *pick_view, *zoom_view, *main_view;
  9. static int target_flag;
  10. int zoom_box(void)
  11. {
  12. static int use = 1;
  13. static Objects objects[] = {
  14. MENU("CANCEL", cancel, &use),
  15. INFO(" Mark first corner of region ", &use),
  16. OTHER(zoom1, &use),
  17. {0}
  18. };
  19. Input_pointer(objects);
  20. return 1;
  21. }
  22. static int zoom1(int x, int y)
  23. { /* called by Input_pointer */
  24. static int use = 1;
  25. static Objects objects[] = {
  26. MENU("CANCEL", cancel, &use),
  27. INFO(" Define the region ", &use),
  28. OTHER(zoom2, &use),
  29. {0}
  30. };
  31. /*
  32. * user has marked first corner
  33. * this determines which view is being zoomed
  34. */
  35. x1 = x;
  36. y1 = y;
  37. if (In_view(pick_view = VIEW_MAP1, x1, y1)) {
  38. main_view = VIEW_MAP1;
  39. zoom_view = VIEW_MAP1_ZOOM;
  40. target_flag = 0;
  41. }
  42. else if (In_view(pick_view = VIEW_MAP2, x1, y1)) {
  43. if (!pick_view->cell.configured)
  44. return 0; /* ignore the mouse event */
  45. main_view = VIEW_MAP2;
  46. zoom_view = VIEW_MAP2_ZOOM;
  47. target_flag = 1;
  48. }
  49. else if (In_view(pick_view = VIEW_MAP1_ZOOM, x1, y1)) {
  50. if (!pick_view->cell.configured)
  51. return 0; /* ignore the mouse event */
  52. main_view = VIEW_MAP1;
  53. zoom_view = VIEW_MAP1_ZOOM;
  54. target_flag = 0;
  55. }
  56. else if (In_view(pick_view = VIEW_MAP2_ZOOM, x1, y1)) {
  57. if (!pick_view->cell.configured)
  58. return 0; /* ignore the mouse event */
  59. main_view = VIEW_MAP2;
  60. zoom_view = VIEW_MAP2_ZOOM;
  61. target_flag = 1;
  62. }
  63. else
  64. return 0; /* ignore the mouse event */
  65. if (!pick_view->cell.configured)
  66. return 0; /* just to be sure */
  67. return Input_box(objects, x, y);
  68. }
  69. static int zoom2(int x, int y)
  70. {
  71. int top, bottom, left, right;
  72. int row, col;
  73. struct Cell_head cellhd;
  74. x2 = x;
  75. y2 = y;
  76. /*
  77. * user has completed the zoom window.
  78. * must be in same view as first corner
  79. */
  80. if (x1 == x2 || y1 == y2)
  81. return 0; /* ignore event */
  82. if (!In_view(pick_view, x2, y2))
  83. return 0;
  84. /*
  85. * ok, erase menu messages
  86. */
  87. Menu_msg("");
  88. /*
  89. * assign window coordinates to top,bottom,left,right
  90. */
  91. if (x1 < x2) {
  92. left = x1;
  93. right = x2;
  94. }
  95. else {
  96. left = x2;
  97. right = x1;
  98. }
  99. if (y1 < y2) {
  100. top = y1;
  101. bottom = y2;
  102. }
  103. else {
  104. top = y2;
  105. bottom = y1;
  106. }
  107. /*
  108. * Determine the the zoom window (ie, cellhd)
  109. * must copy the current view cellhd first, to preserve header info
  110. * (such as projection, zone, and other items.)
  111. * compute zoom window northings,eastings, rows, cols, and resolution
  112. */
  113. G_copy(&cellhd, &pick_view->cell.head, sizeof(cellhd));
  114. /* convert top to northing at top edge of cell
  115. * left to easting at left edge
  116. */
  117. col = view_to_col(pick_view, left);
  118. row = view_to_row(pick_view, top);
  119. cellhd.north = row_to_northing(&pick_view->cell.head, row, 0.0);
  120. cellhd.west = col_to_easting(&pick_view->cell.head, col, 0.0);
  121. /* convert bottom to northing at bottom edge of cell
  122. * right to easting at right edge
  123. */
  124. col = view_to_col(pick_view, right);
  125. row = view_to_row(pick_view, bottom);
  126. cellhd.south = row_to_northing(&pick_view->cell.head, row, 1.0);
  127. cellhd.east = col_to_easting(&pick_view->cell.head, col, 1.0);
  128. cellhd.rows = bottom - top + 1;
  129. cellhd.cols = right - left + 1;
  130. cellhd.ns_res = (cellhd.north - cellhd.south) / cellhd.rows;
  131. cellhd.ew_res = (cellhd.east - cellhd.west) / cellhd.cols;
  132. /*
  133. * Outline the zoom window on the main map
  134. * Turn previous one to grey.
  135. */
  136. if (zoom_view->cell.configured) {
  137. R_standard_color(GREY);
  138. Outline_cellhd(main_view, &zoom_view->cell.head);
  139. }
  140. R_standard_color(RED);
  141. Outline_cellhd(main_view, &cellhd);
  142. /*
  143. * zoom
  144. */
  145. if (target_flag)
  146. select_target_env();
  147. G_adjust_window_to_box(&cellhd, &zoom_view->cell.head, zoom_view->nrows,
  148. zoom_view->ncols);
  149. Configure_view(zoom_view, pick_view->cell.name, pick_view->cell.mapset,
  150. pick_view->cell.ns_res, pick_view->cell.ew_res);
  151. drawcell(zoom_view);
  152. select_current_env();
  153. display_points(1);
  154. return 1; /* pop back */
  155. }
  156. static int cancel(void)
  157. {
  158. return -1;
  159. }