maptool.tcl 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. ###############################################################
  2. # maptool.tcl - toolbar file GRASS GIS Manager map display canvas
  3. # January 2006 Michael Barton, Arizona State University
  4. # COPYRIGHT: (C) 1999 - 2006 by the GRASS Development Team
  5. #
  6. # This program is free software under the GNU General Public
  7. # License (>=v2). Read the file COPYING that comes with GRASS
  8. # for details.
  9. ###############################################################
  10. namespace eval MapToolBar {
  11. variable toolbar
  12. variable array maptools
  13. }
  14. ###############################################################################
  15. proc MapToolBar::create { tb } {
  16. global bgcolor
  17. global mon
  18. global env
  19. global tk_version
  20. global iconpath
  21. variable toolbar
  22. variable maptools
  23. set selclr #88aa88
  24. set toolbar $tb
  25. set maptools($mon) "pointer"
  26. # DISPLAY AND MONITOR SELECTION
  27. set bbox1 [ButtonBox $toolbar.bbox1 -spacing 0 ]
  28. # display
  29. $bbox1 add -image [image create photo -file "$iconpath/gui-display.gif"] \
  30. -command "MapCanvas::request_redraw $mon 0" \
  31. -highlightthickness 0 -takefocus 0 -relief link -borderwidth 1 \
  32. -highlightbackground $bgcolor -activebackground $bgcolor\
  33. -helptext [G_msg "Display active layers"]
  34. # re-render all layers
  35. $bbox1 add -image [image create photo -file "$iconpath/gui-redraw.gif"] \
  36. -command "MapCanvas::request_redraw $mon 1" \
  37. -highlightthickness 0 -takefocus 0 -relief link -borderwidth 1 \
  38. -highlightbackground $bgcolor -activebackground $bgcolor \
  39. -helptext [G_msg "Redraw all layers"]
  40. $bbox1 add -image [image create photo -file "$iconpath/module-nviz.gif"] \
  41. -command {GmGroup::nvdisplay "root"} \
  42. -highlightthickness 0 -takefocus 0 -relief link -borderwidth 1 \
  43. -highlightbackground $bgcolor -activebackground $bgcolor\
  44. -helptext [G_msg "Start NVIZ using active layers in current region"]
  45. $bbox1 add -image [image create photo -file "$iconpath/module-d.nviz.gif"] \
  46. -command "MapCanvas::dnviz $mon" \
  47. -highlightthickness 0 -takefocus 0 -relief link -borderwidth 1 \
  48. -highlightbackground $bgcolor -activebackground $bgcolor\
  49. -helptext [G_msg "Create flythough path for NVIZ"]
  50. # erase
  51. $bbox1 add -image [image create photo -file "$iconpath/gui-erase.gif"] \
  52. -command "MapCanvas::erase $mon" \
  53. -highlightthickness 0 -takefocus 0 -relief link -borderwidth 1 \
  54. -highlightbackground $bgcolor -activebackground $bgcolor\
  55. -helptext [G_msg "Erase to white"]
  56. pack $bbox1 -side left -anchor w
  57. set sep1 [Separator $toolbar.sep1 -orient vertical -background $bgcolor ]
  58. pack $sep1 -side left -fill y -padx 5 -anchor w
  59. # DISPLAY TOOLS
  60. # pointer
  61. if {$tk_version < 8.4 } {
  62. set pointer [radiobutton $tb.pointer \
  63. -image [image create photo -file "$iconpath/gui-pointer.gif"] \
  64. -command "MapCanvas::stoptool $mon; MapCanvas::pointer $mon" \
  65. -variable maptools($mon) -value pointer -relief flat \
  66. -borderwidth 1 -indicatoron false -bg $bgcolor -selectcolor $selclr \
  67. -activebackground $bgcolor -highlightbackground $bgcolor ]
  68. } else {
  69. set pointer [radiobutton $tb.pointer \
  70. -image [image create photo -file "$iconpath/gui-pointer.gif"] \
  71. -command "MapCanvas::stoptool $mon; MapCanvas::pointer $mon" \
  72. -variable maptools($mon) -value pointer \
  73. -relief flat -offrelief flat -overrelief raised \
  74. -borderwidth 1 -indicatoron false -bg $bgcolor -selectcolor $selclr \
  75. -activebackground $bgcolor -highlightbackground $bgcolor ]
  76. }
  77. DynamicHelp::register $pointer balloon [G_msg "Pointer"]
  78. # zoom in
  79. if {$tk_version < 8.4 } {
  80. set zoomin [radiobutton $tb.zoomin \
  81. -image [image create photo -file "$iconpath/gui-zoom_in.gif"] \
  82. -command "MapCanvas::stoptool $mon; MapCanvas::zoombind $mon 1" \
  83. -variable maptools($mon) -value zoomin -relief flat \
  84. -borderwidth 1 -indicatoron false -bg $bgcolor -selectcolor $selclr \
  85. -activebackground $bgcolor -highlightbackground $bgcolor ]
  86. } else {
  87. set zoomin [radiobutton $tb.zoomin \
  88. -image [image create photo -file "$iconpath/gui-zoom_in.gif"] \
  89. -command "MapCanvas::stoptool $mon; MapCanvas::zoombind $mon 1" \
  90. -variable maptools($mon) -value zoomin \
  91. -relief flat -offrelief flat -overrelief raised \
  92. -borderwidth 1 -indicatoron false -bg $bgcolor -selectcolor $selclr \
  93. -activebackground $bgcolor -highlightbackground $bgcolor ]
  94. }
  95. DynamicHelp::register $zoomin balloon [G_msg "Zoom In"]
  96. #zoom out
  97. if {$tk_version < 8.4 } {
  98. set zoomout [radiobutton $tb.zoomout \
  99. -image [image create photo -file "$iconpath/gui-zoom_out.gif"] \
  100. -command "MapCanvas::stoptool $mon; MapCanvas::zoombind $mon -1" \
  101. -variable maptools($mon) -value zoomout -relief flat \
  102. -borderwidth 1 -indicatoron false -bg $bgcolor -selectcolor $selclr \
  103. -activebackground $bgcolor -highlightbackground $bgcolor ]
  104. } else {
  105. set zoomout [radiobutton $tb.zoomout \
  106. -image [image create photo -file "$iconpath/gui-zoom_out.gif"] \
  107. -command "MapCanvas::stoptool $mon; MapCanvas::zoombind $mon -1" \
  108. -variable maptools($mon) -value zoomout \
  109. -relief flat -offrelief flat -overrelief raised \
  110. -borderwidth 1 -indicatoron false -bg $bgcolor -selectcolor $selclr \
  111. -activebackground $bgcolor -highlightbackground $bgcolor ]
  112. }
  113. DynamicHelp::register $zoomout balloon [G_msg "Zoom Out"]
  114. # pan
  115. if {$tk_version < 8.4 } {
  116. set pan [radiobutton $tb.pan \
  117. -image [image create photo -file "$iconpath/gui-pan.gif"] \
  118. -command "MapCanvas::stoptool $mon; MapCanvas::panbind $mon" \
  119. -variable maptools($mon) -value pan -relief flat \
  120. -borderwidth 1 -indicatoron false -bg $bgcolor -selectcolor $selclr \
  121. -activebackground $bgcolor -highlightbackground $bgcolor ]
  122. } else {
  123. set pan [radiobutton $tb.pan \
  124. -image [image create photo -file "$iconpath/gui-pan.gif"] \
  125. -command "MapCanvas::stoptool $mon; MapCanvas::panbind $mon" \
  126. -variable maptools($mon) -value pan \
  127. -relief flat -offrelief flat -overrelief raised \
  128. -borderwidth 1 -indicatoron false -bg $bgcolor -selectcolor $selclr \
  129. -activebackground $bgcolor -highlightbackground $bgcolor ]
  130. }
  131. DynamicHelp::register $pan balloon [G_msg "Pan"]
  132. pack $pointer $zoomin $zoomout $pan -side left -anchor w
  133. set sep2 [Separator $toolbar.sep2 -orient vertical -background $bgcolor ]
  134. pack $sep2 -side left -fill y -padx 5 -anchor w
  135. set bbox2 [ButtonBox $toolbar.bbox2 -spacing 0 ]
  136. # zoom.back
  137. $bbox2 add -image [image create photo -file "$iconpath/gui-zoom_back.gif"] \
  138. -command "MapCanvas::zoom_back $mon" \
  139. -highlightthickness 0 -takefocus 0 -relief link -borderwidth 1\
  140. -highlightbackground $bgcolor -activebackground $bgcolor \
  141. -helptext [G_msg "Return to previous zoom"]
  142. set mapzoom [menubutton $tb.mapzoom \
  143. -image [image create photo -file "$iconpath/gui-mapzoom.gif"] \
  144. -highlightthickness 0 -takefocus 0 -relief flat -borderwidth 1 \
  145. -highlightbackground $bgcolor -activebackground honeydew \
  146. -bg $bgcolor -width 32 -indicatoron 0 -direction below]
  147. DynamicHelp::register $mapzoom balloon [G_msg "Zoom to..."]
  148. # menu zooming display
  149. set zoommenu [menu $mapzoom.zm -type normal]
  150. # Could use these images along with text if -compound worked in all platforms
  151. # set zmimg [image create photo -file "$iconpath/gui-zoom_map.gif"]
  152. # set zrimg [image create photo -file "$iconpath/gui-zoom_region.gif"]
  153. # set zcimg [image create photo -file "$iconpath/gui-zoom_current.gif"]
  154. # set zdimg [image create photo -file "$iconpath/gui-zoom_default.gif"]
  155. $zoommenu add command \
  156. -label [G_msg "Zoom display to selected map"] \
  157. -command {MapCanvas::zoom_map $mon}
  158. $zoommenu add command \
  159. -label [G_msg "Zoom display to saved region"] \
  160. -command {MapCanvas::zoom_region $mon}
  161. $zoommenu add command \
  162. -label [G_msg "Save display extents to named region"] \
  163. -command {MapCanvas::save_region $mon}
  164. $zoommenu add command \
  165. -label [G_msg "Zoom display to computational region (set with g.region)"] \
  166. -command {MapCanvas::zoom_current $mon}
  167. $zoommenu add command \
  168. -label [G_msg "Zoom display to default region"] \
  169. -command {MapCanvas::zoom_default $mon}
  170. $zoommenu add command \
  171. -label [G_msg "Set computational region extents to match display"] \
  172. -command {MapCanvas::set_wind $mon "" 0}
  173. $mapzoom configure -menu $zoommenu
  174. pack $bbox2 -side left -anchor w
  175. pack $mapzoom -side left -anchor w -expand no -fill y
  176. set sep3 [Separator $toolbar.sep3 -orient vertical -background $bgcolor ]
  177. pack $sep3 -side left -fill y -padx 5 -anchor w
  178. # query
  179. if {$tk_version < 8.4 } {
  180. set query [radiobutton $tb.query \
  181. -image [image create photo -file "$iconpath/gui-query.gif"] \
  182. -command "MapCanvas::stoptool $mon; MapCanvas::querybind $mon" \
  183. -variable maptools($mon) -value query -relief flat \
  184. -borderwidth 1 -indicatoron false -bg $bgcolor -selectcolor $selclr \
  185. -activebackground $bgcolor -highlightbackground $bgcolor ]
  186. } else {
  187. set query [radiobutton $tb.query \
  188. -image [image create photo -file "$iconpath/gui-query.gif"] \
  189. -command "MapCanvas::stoptool $mon; MapCanvas::querybind $mon" \
  190. -variable maptools($mon) -value query \
  191. -relief flat -offrelief flat -overrelief raised \
  192. -borderwidth 1 -indicatoron false -bg $bgcolor -selectcolor $selclr \
  193. -activebackground $bgcolor -highlightbackground $bgcolor ]
  194. }
  195. DynamicHelp::register $query balloon [G_msg "Query"]
  196. # measure
  197. if {$tk_version < 8.4 } {
  198. set measure [radiobutton $tb.measure \
  199. -image [image create photo -file "$iconpath/gui-measure.gif"] \
  200. -command "MapCanvas::stoptool $mon; MapCanvas::measurebind $mon"\
  201. -variable maptools($mon) -value measure -relief flat \
  202. -borderwidth 1 -indicatoron false -bg $bgcolor -selectcolor $selclr \
  203. -activebackground $bgcolor -highlightbackground $bgcolor ]
  204. } else {
  205. set measure [radiobutton $tb.measure \
  206. -image [image create photo -file "$iconpath/gui-measure.gif"] \
  207. -command "MapCanvas::stoptool $mon; MapCanvas::measurebind $mon"\
  208. -variable maptools($mon) -value measure \
  209. -relief flat -offrelief flat -overrelief raised \
  210. -borderwidth 1 -indicatoron false -bg $bgcolor -selectcolor $selclr \
  211. -activebackground $bgcolor -highlightbackground $bgcolor ]
  212. }
  213. DynamicHelp::register $measure balloon [G_msg "Measure"]
  214. set bbox3 [ButtonBox $toolbar.bbox3 -spacing 0 ]
  215. $bbox3 add -image [image create photo -file "$iconpath/gui-profile.gif"] \
  216. -command "MapCanvas::stoptool $mon; MapCanvas::startprofile $mon" \
  217. -highlightthickness 0 -takefocus 0 -relief link -borderwidth 1 \
  218. -highlightbackground $bgcolor -activebackground $bgcolor \
  219. -helptext [G_msg "Create profile of raster map"]
  220. pack $query $measure -side left -anchor w
  221. pack $bbox3 -side left -anchor w
  222. set sep4 [Separator $toolbar.sep4 -orient vertical -background $bgcolor ]
  223. pack $sep4 -side left -fill y -padx 5 -anchor w
  224. # FILE & PRINT
  225. set bbox4 [ButtonBox $toolbar.bbox4 -spacing 0 ]
  226. $bbox4 add -image [image create photo -file "$iconpath/file-print.gif"] \
  227. -command "MapCanvas::printcanvas $mon" \
  228. -highlightthickness 0 -takefocus 0 -relief link -borderwidth 1 \
  229. -highlightbackground $bgcolor -activebackground $bgcolor \
  230. -helptext [G_msg "Print raster & vector maps to eps file"]
  231. set mapsave [menubutton $tb.mapsave \
  232. -image [image create photo -file "$iconpath/gui-filesave.gif"] \
  233. -highlightthickness 0 -takefocus 0 -relief flat -borderwidth 1 \
  234. -highlightbackground $bgcolor -activebackground honeydew \
  235. -bg $bgcolor -width 32 -indicatoron 0 -direction below]
  236. DynamicHelp::register $mapsave balloon [G_msg "Export display to graphics file"]
  237. pack $mapsave -side left -anchor w -expand no -fill y
  238. pack $bbox4 -side left -anchor w
  239. # menu for saving display
  240. set savefile [menu $mapsave.sf -type normal]
  241. set jpgfile [menu $savefile.jpg -type normal]
  242. $savefile add command -label "BMP*" -command {MapToolBar::savefile bmp 0}
  243. $savefile add cascade -label "JPG*" -menu $jpgfile
  244. $jpgfile add command -label [G_msg "low quality (50)"] \
  245. -command {MapToolBar::savefile jpg 50}
  246. $jpgfile add command -label [G_msg "mid quality (75)"] \
  247. -command {MapToolBar::savefile jpg 75}
  248. $jpgfile add command -label [G_msg "high quality (95)"] \
  249. -command {MapToolBar::savefile jpg 95}
  250. $jpgfile add command -label [G_msg "very high resolution (300% your current resolution)"] \
  251. -command {MapToolBar::savefile jpg 300}
  252. $savefile add command -label "PPM/PNM" -command {MapToolBar::savefile ppm 0}
  253. $savefile add command -label "PNG" -command {MapToolBar::savefile png 0}
  254. $savefile add command -label "TIF*" -command {MapToolBar::savefile tif 0}
  255. $savefile add command -label [G_msg "(* requires gdal)"] -state disabled
  256. $mapsave configure -menu $savefile
  257. set sep5 [Separator $toolbar.sep5 -orient vertical ]
  258. pack $sep5 -side left -fill y -padx 5 -anchor w
  259. # Render modes
  260. # Strict render mode
  261. # Uses previous resolution and exact boundaries
  262. if {$tk_version < 8.4 } {
  263. set strictdraw [radiobutton $tb.strictdraw \
  264. -command "MapCanvas::exploremode $mon 0" \
  265. -variable MapToolBar::explore($mon) -value strict -relief flat \
  266. -borderwidth 1 -indicatoron false -bg $bgcolor -selectcolor $selclr \
  267. -activebackground $bgcolor -highlightbackground $bgcolor ]
  268. } else {
  269. set strictdraw [radiobutton $tb.strictdraw \
  270. -command "MapCanvas::exploremode $mon 0" \
  271. -variable MapToolBar::explore($mon) -value strict \
  272. -relief flat -offrelief flat -overrelief raised \
  273. -borderwidth 1 -indicatoron false -bg $bgcolor -selectcolor $selclr \
  274. -activebackground $bgcolor -highlightbackground $bgcolor ]
  275. }
  276. DynamicHelp::register $strictdraw balloon [G_msg "Constrain map to region geometry"]
  277. icon_configure $strictdraw drawmode strict
  278. # Explore render mode
  279. # Uses resolution to match display and expanded boundaries to fill display
  280. if {$tk_version < 8.4 } {
  281. set exploredraw [radiobutton $tb.strictzoom \
  282. -command "MapCanvas::exploremode $mon 1" \
  283. -variable MapToolBar::explore($mon) -value explore -relief flat \
  284. -borderwidth 1 -indicatoron false -bg $bgcolor -selectcolor $selclr \
  285. -activebackground $bgcolor -highlightbackground $bgcolor ]
  286. } else {
  287. set exploredraw [radiobutton $tb.strictzoom \
  288. -command "MapCanvas::exploremode $mon 1" \
  289. -variable MapToolBar::explore($mon) -value explore \
  290. -relief flat -offrelief flat -overrelief raised \
  291. -borderwidth 1 -indicatoron false -bg $bgcolor -selectcolor $selclr \
  292. -activebackground $bgcolor -highlightbackground $bgcolor ]
  293. }
  294. DynamicHelp::register $exploredraw balloon [G_msg "Map fills display window"]
  295. icon_configure $exploredraw drawmode explore
  296. # This does not actually set the mode
  297. # it just starts visually in sync with the default
  298. set MapToolBar::explore($mon) strict
  299. pack $strictdraw $exploredraw -side left -anchor w
  300. }
  301. ###############################################################################
  302. # changes button on keypress
  303. proc MapToolBar::changebutton { rbname } {
  304. global mon
  305. variable maptools
  306. set maptools($mon) $rbname
  307. }
  308. ###############################################################################
  309. # procedures for saving files
  310. # save png file
  311. proc MapToolBar::savefile { type quality } {
  312. global env
  313. global mon
  314. global tmpdir
  315. set outfile($mon) $MapCanvas::outfile($mon)
  316. if { [info exists env(HOME)] } {
  317. set dir $env(HOME)
  318. set path [tk_getSaveFile -initialdir $dir \
  319. -title "Save file: do not add extension to file name"]
  320. } else {
  321. set path [tk_getSaveFile \
  322. -title "Save file: do not add extension to file name"]
  323. }
  324. set currdir [pwd]
  325. cd $tmpdir
  326. catch {file copy -force $outfile($mon) $path.ppm}
  327. cd $currdir
  328. if { $path != "" } {
  329. switch $type {
  330. "bmp" {
  331. if { [catch {exec gdal_translate $path.ppm $path.bmp -of BMP} error ]} {
  332. GmLib::errmsg $error [G_msg "Could not create BMP"]
  333. }
  334. catch {file delete $path.ppm}
  335. }
  336. "jpg" {
  337. if { $quality == 300 } {
  338. if { [catch {exec gdal_translate $path.ppm $path.jpg -of JPEG -co QUALITY=95 -outsize 300% 300% } error ]} {
  339. GmLib::errmsg $error [G_msg "Could not create JPG"]
  340. }
  341. catch {file delete $path.ppm}
  342. } else {
  343. if { [catch {exec gdal_translate $path.ppm $path.jpg -of JPEG -co QUALITY=$quality } error ]} {
  344. GmLib::errmsg $error [G_msg "Could not create JPG"]
  345. }
  346. catch {file delete $path.ppm}
  347. }
  348. }
  349. "png" {
  350. if { [catch {exec gdal_translate $path.ppm $path.png -of PNG} error ]} {
  351. GmLib::errmsg $error [G_msg "Could not create PNG"]
  352. }
  353. catch {file delete $path.ppm}
  354. }
  355. "ppm" {
  356. return
  357. }
  358. "tif" {
  359. if { [catch {exec gdal_translate $path.ppm $path.tif -of GTIFF} error ]} {
  360. GmLib::errmsg $error [G_msg "Could not create TIF"]
  361. }
  362. catch {file delete $path.ppm}
  363. }
  364. }
  365. }
  366. return
  367. }