main.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /****************************************************************************
  2. *
  3. * MODULE: d.zoom
  4. * AUTHOR(S): Michael Shapiro (USACERL) (original contributor)
  5. * Radim Blazek <radim.blazek gmail.com>,
  6. * Stephan Holl <sholl gmx net>,
  7. * Huidae Cho <grass4u gmail.com>,
  8. * Florian Goessmann <florian wallweg39.de>,
  9. * Glynn Clements <glynn gclements.plus.com>,
  10. * Hamish Bowman <hamish_b yahoo.com>,
  11. * Markus Neteler <neteler itc.it>,
  12. * Paul Kelly <paul-grass stjohnspoint.co.uk>
  13. * PURPOSE: interactively change the current region using the mouse
  14. * COPYRIGHT: (C) 2002-2006 by the GRASS Development Team
  15. *
  16. * This program is free software under the GNU General Public
  17. * License (>=v2). Read the file COPYING that comes with GRASS
  18. * for details.
  19. *
  20. *****************************************************************************/
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <grass/gis.h>
  24. #include <grass/display.h>
  25. #include <grass/vector.h>
  26. #include "local_proto.h"
  27. #include <grass/glocale.h>
  28. char *cmd;
  29. char **rast, **vect, **list;
  30. int nrasts, nvects, nlists;
  31. double U_east, U_west, U_south, U_north;
  32. int main(int argc, char **argv)
  33. {
  34. int stat;
  35. #ifdef QUIET
  36. struct Flag *quiet;
  37. #endif
  38. struct Flag *full, *hand, *pan, *last;
  39. struct Option *rmap, *vmap, *zoom;
  40. struct GModule *module;
  41. double magnify;
  42. int i, first = 1;
  43. char *map;
  44. double ux1, uy1, ux2, uy2;
  45. struct Cell_head window, defwin, currwin, tmpwin;
  46. /* Initialize globals */
  47. rast = vect = NULL;
  48. nrasts = nvects = 0;
  49. /* Initialize the GIS calls */
  50. G_gisinit(argv[0]);
  51. module = G_define_module();
  52. G_add_keyword(_("display"));
  53. G_add_keyword(_("zoom"));
  54. module->description =
  55. _("Allows the user to change the current geographic "
  56. "region settings interactively, with a mouse.");
  57. rast = NULL;
  58. vect = NULL;
  59. rmap = G_define_option();
  60. rmap->key = "rast";
  61. rmap->type = TYPE_STRING;
  62. rmap->multiple = YES;
  63. rmap->required = NO;
  64. rmap->gisprompt = "old,cell,raster";
  65. rmap->description = _("Name of raster map");
  66. vmap = G_define_option();
  67. vmap->key = "vector";
  68. vmap->type = TYPE_STRING;
  69. vmap->multiple = YES;
  70. vmap->required = NO;
  71. vmap->gisprompt = "old,dig,vector";
  72. vmap->description = _("Name of vector map");
  73. zoom = G_define_option();
  74. zoom->key = "zoom";
  75. zoom->type = TYPE_DOUBLE;
  76. zoom->required = NO;
  77. zoom->answer = "0.75";
  78. zoom->options = "0.001-1000.0";
  79. zoom->description = _("Magnification: >1.0 zooms in, <1.0 zooms out");
  80. #ifdef QUIET
  81. quiet = G_define_flag();
  82. quiet->key = 'q';
  83. quiet->description = "Quiet";
  84. #endif
  85. full = G_define_flag();
  86. full->key = 'f';
  87. full->description = _("Full menu (zoom + pan) & Quit menu");
  88. pan = G_define_flag();
  89. pan->key = 'p';
  90. pan->description = _("Pan mode");
  91. hand = G_define_flag();
  92. hand->key = 'h';
  93. hand->description = _("Handheld mode");
  94. last = G_define_flag();
  95. last->key = 'r';
  96. last->description = _("Return to previous zoom");
  97. if (G_parser(argc, argv))
  98. exit(EXIT_FAILURE);
  99. if ((full->answer + pan->answer + hand->answer) > 1)
  100. G_fatal_error(_("Please choose only one mode of operation"));
  101. sscanf(zoom->answer, "%lf", &magnify);
  102. #ifdef QUIET
  103. /* if map was found in monitor: */
  104. if (rast || vect)
  105. quiet->answer = 1;
  106. #endif
  107. cmd = NULL;
  108. rast = rmap->answers;
  109. vect = vmap->answers;
  110. if (rast) {
  111. struct Cell_head window;
  112. for (i = 0; rast[i]; i++) ;
  113. nrasts = i;
  114. for (i = 0; i < nrasts; i++) {
  115. Rast_get_cellhd(rast[i], "", &window);
  116. {
  117. if (first) {
  118. first = 0;
  119. U_east = window.east;
  120. U_west = window.west;
  121. U_south = window.south;
  122. U_north = window.north;
  123. }
  124. else {
  125. if (window.east > U_east)
  126. U_east = window.east;
  127. if (window.west < U_west)
  128. U_west = window.west;
  129. if (window.south < U_south)
  130. U_south = window.south;
  131. if (window.north > U_north)
  132. U_north = window.north;
  133. }
  134. }
  135. }
  136. }
  137. if (vect) {
  138. struct Map_info Map;
  139. struct bound_box box;
  140. for (i = 0; vect[i]; i++) ;
  141. nvects = i;
  142. for (i = 0; i < nvects; i++) {
  143. if (Vect_open_old(&Map, vect[i], "") >= 2) {
  144. Vect_get_map_box(&Map, &box);
  145. if (first) {
  146. first = 0;
  147. U_east = box.E;
  148. U_west = box.W;
  149. U_south = box.S;
  150. U_north = box.N;
  151. }
  152. else {
  153. if (box.E > U_east)
  154. U_east = box.E;
  155. if (box.W < U_west)
  156. U_west = box.W;
  157. if (box.S < U_south)
  158. U_south = box.S;
  159. if (box.N > U_north)
  160. U_north = box.N;
  161. }
  162. }
  163. }
  164. }
  165. #ifdef BOUNDARY
  166. if (!first) {
  167. /*
  168. if(U_east == U_west)
  169. {
  170. U_east += 100;
  171. U_west -= 100;
  172. }
  173. if(U_south == U_north)
  174. {
  175. U_south -= 100;
  176. U_north += 100;
  177. }
  178. */
  179. U_east += 0.05 * (U_east - U_west);
  180. U_west -= 0.05 * (U_east - U_west);
  181. U_south -= 0.05 * (U_north - U_south);
  182. U_north += 0.05 * (U_north - U_south);
  183. }
  184. #endif
  185. if (R_open_driver() != 0)
  186. G_fatal_error(_("No graphics device selected"));
  187. D_setup(0);
  188. if (!hand->answer) {
  189. fprintf(stderr, _("%d raster%s, %d vector%s\n"),
  190. nrasts, (nrasts > 1 ? "s" : ""),
  191. nvects, (nvects > 1 ? "s" : ""));
  192. }
  193. if (last->answer) { /* restoring temporary region */
  194. map = G_find_file("windows", "previous_zoom", "");
  195. if (!map)
  196. G_fatal_error(_("No previous zoom available"));
  197. G__get_window(&tmpwin, "windows", "previous_zoom", map);
  198. G_message(_("Returning to previous zoom"));
  199. ux1 = tmpwin.east;
  200. ux2 = tmpwin.west;
  201. uy1 = tmpwin.north;
  202. uy2 = tmpwin.south;
  203. set_win(&tmpwin, ux1, uy1, ux2, uy2, hand->answer);
  204. exit(0);
  205. }
  206. /* Do the zoom */
  207. G_get_window(&window);
  208. /* Save current region before it is changed */
  209. G__put_window(&window, "windows", "previous_zoom");
  210. G_get_window(&currwin);
  211. G_get_default_window(&defwin);
  212. if (full->answer == 1)
  213. stat = zoomwindow(&window, 1, magnify);
  214. else if (pan->answer == 1)
  215. do_pan(&window);
  216. else {
  217. if (hand->answer == 0)
  218. make_window_box(&window, magnify, 0, 0);
  219. else
  220. make_window_box(&window, magnify, 0, 1);
  221. }
  222. if (full->answer) {
  223. quit(&defwin, &currwin); /* calling the quit menu function */
  224. }
  225. R_close_driver();
  226. G_message(_("Zooming complete."));
  227. exit(stat);
  228. }