mark.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. #include "globals.h"
  2. #include "local_proto.h"
  3. #include <grass/display.h>
  4. static int get_point2(double *, double *);
  5. static int keyboard(void);
  6. static int _keyboard(void);
  7. static int screen(int, int, int);
  8. static int digitizer(void);
  9. static int cancel(void);
  10. int mark(int x, int y, int button)
  11. {
  12. if (button != 1)
  13. return where(x, y);
  14. if (VIEW_MAP1->cell.configured && In_view(VIEW_MAP1, x, y))
  15. mark_point(VIEW_MAP1, x, y);
  16. else if (VIEW_MAP1_ZOOM->cell.configured && In_view(VIEW_MAP1_ZOOM, x, y))
  17. mark_point(VIEW_MAP1_ZOOM, x, y);
  18. return 0; /* return but don't quit */
  19. }
  20. int mark_point(View * view, int x, int y)
  21. {
  22. double e1, n1;
  23. double e2, n2;
  24. int row, col;
  25. char buf[100];
  26. /* convert x,y to east,north at center of cell */
  27. col = view_to_col(view, x);
  28. e1 = col_to_easting(&view->cell.head, col, 0.5);
  29. row = view_to_row(view, y);
  30. n1 = row_to_northing(&view->cell.head, row, 0.5);
  31. Curses_clear_window(MENU_WINDOW);
  32. sprintf(buf, "Point %d marked on image at", group.points.count + 1);
  33. Curses_write_window(MENU_WINDOW, 1, 1, buf);
  34. sprintf(buf, "East: %10.2f", e1);
  35. Curses_write_window(MENU_WINDOW, 3, 3, buf);
  36. sprintf(buf, "North: %10.2f", n1);
  37. Curses_write_window(MENU_WINDOW, 4, 3, buf);
  38. Curses_clear_window(INFO_WINDOW);
  39. R_standard_color(ORANGE);
  40. save_under_dot(x, y);
  41. dot(x, y);
  42. if (!get_point2(&e2, &n2)) {
  43. Curses_clear_window(MENU_WINDOW);
  44. restore_under_dot();
  45. }
  46. else {
  47. Curses_write_window(MENU_WINDOW, 7, 1, "Point located at");
  48. sprintf(buf, "East: %10.2f", e2);
  49. Curses_write_window(MENU_WINDOW, 9, 3, buf);
  50. sprintf(buf, "North: %10.2f", n2);
  51. Curses_write_window(MENU_WINDOW, 10, 3, buf);
  52. I_new_control_point(&group.points, e1, n1, e2, n2, 1);
  53. I_put_control_points(group.name, &group.points);
  54. Compute_equation();
  55. display_points(1);
  56. }
  57. release_under_dot();
  58. return 0;
  59. }
  60. static double N, E;
  61. static int get_point2(double *east, double *north)
  62. {
  63. int stat;
  64. static int use = 1;
  65. static Objects objects[] = {
  66. MENU("CANCEL", cancel, &use),
  67. INFO("Mark point on target image", &use),
  68. OTHER(screen, &use),
  69. {0}
  70. };
  71. if (from_digitizer > 0) {
  72. stat = Input_other(digitizer, "Digitizer");
  73. }
  74. else if (from_screen > 0) {
  75. set_colors(&VIEW_MAP2->cell.colors);
  76. stat = Input_pointer(objects) > 0;
  77. set_colors(&VIEW_MAP1->cell.colors);
  78. }
  79. else
  80. stat = Input_other(keyboard, "Keyboard");
  81. if (stat) {
  82. *east = E;
  83. *north = N;
  84. }
  85. return stat;
  86. }
  87. static int keyboard(void)
  88. {
  89. int ok;
  90. Curses_clear_window(INFO_WINDOW);
  91. ok = _keyboard();
  92. Curses_clear_window(INFO_WINDOW);
  93. return ok;
  94. }
  95. static int _keyboard(void)
  96. {
  97. char buf[100], buf1[100], buf2[100];
  98. while (1) {
  99. Curses_prompt_gets("Enter coordinates as east north: ", buf);
  100. G_strip(buf);
  101. if (*buf == 0) {
  102. return 0;
  103. }
  104. if (sscanf(buf, "%s %s", buf1, buf2) != 2) {
  105. Beep();
  106. continue;
  107. }
  108. /* scan for lat/lon string first as "123E 45S" passes the %lf test but is wrong */
  109. if (!(G_lon_scan(buf1, &E) && G_lat_scan(buf2, &N))) {
  110. if (sscanf(buf, "%lf %lf", &E, &N) != 2) {
  111. Beep();
  112. continue;
  113. }
  114. }
  115. Curses_clear_window(INFO_WINDOW);
  116. sprintf(buf, "East: %f\n", E);
  117. Curses_write_window(INFO_WINDOW, 2, 2, buf);
  118. sprintf(buf, "North: %f\n", N);
  119. Curses_write_window(INFO_WINDOW, 3, 2, buf);
  120. Curses_write_window(INFO_WINDOW, 5, 1, "Look ok? (y/n) ");
  121. while (1) {
  122. int c;
  123. c = Curses_getch(0);
  124. if (c == 'y' || c == 'Y')
  125. return 1;
  126. if (c == 'n' || c == 'N')
  127. break;
  128. Beep();
  129. }
  130. }
  131. return 0;
  132. }
  133. static int digitizer(void)
  134. {
  135. return digitizer_point(&E, &N);
  136. }
  137. static int screen(int x, int y, int button)
  138. {
  139. int row, col;
  140. char buf[50];
  141. View *view;
  142. if (In_view(VIEW_MAP2, x, y) && VIEW_MAP2->cell.configured)
  143. view = VIEW_MAP2;
  144. else if (In_view(VIEW_MAP2_ZOOM, x, y) && VIEW_MAP2_ZOOM->cell.configured)
  145. view = VIEW_MAP2_ZOOM;
  146. else
  147. return 0; /* ignore mouse event */
  148. col = view_to_col(view, x);
  149. E = col_to_easting(&view->cell.head, col, 0.5);
  150. row = view_to_row(view, y);
  151. N = row_to_northing(&view->cell.head, row, 0.5);
  152. if (button == 1)
  153. return 1;
  154. sprintf(buf, "East: %10.2f\n", E);
  155. Curses_write_window(INFO_WINDOW, 2, 2, buf);
  156. sprintf(buf, "North: %10.2f\n", N);
  157. Curses_write_window(INFO_WINDOW, 3, 2, buf);
  158. return 0;
  159. }
  160. static int cancel(void)
  161. {
  162. return -1;
  163. }