gridline.tcl 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. ##########################################################################
  2. # grid.tcl - grid and line overlay layer options file for GRASS GIS Manager
  3. # COPYRIGHT: (C) 1999 - 2006 by the GRASS Development Team
  4. #
  5. # This program is free software under the GNU General Public
  6. # License (>=v2). Read the file COPYING that comes with GRASS
  7. # for details.
  8. #
  9. ##########################################################################
  10. namespace eval GmGridline {
  11. variable array opt # grid current options
  12. variable count 1
  13. variable array tree # mon
  14. variable array lfile # raster
  15. variable array lfilemask # raster
  16. variable optlist
  17. variable first
  18. variable array dup # vector
  19. }
  20. proc GmGridline::create { tree parent } {
  21. variable opt
  22. variable count
  23. variable lfile
  24. variable lfilemask
  25. variable optlist
  26. variable first
  27. variable dup
  28. global mon
  29. global iconpath
  30. set node "gridline:$count"
  31. set frm [ frame .gridicon$count]
  32. set check [checkbutton $frm.check \
  33. -variable GmGridline::opt($count,1,_check) \
  34. -height 1 -padx 0 -width 0]
  35. image create photo gico -file "$iconpath/module-d.grid.gif"
  36. set gdico [label $frm.gdico -image gico -bd 1 -relief raised]
  37. bind $gdico <ButtonPress-1> "GmTree::selectn $tree $node"
  38. pack $check $gdico -side left
  39. #insert new layer
  40. if {[$tree selection get] != "" } {
  41. set sellayer [$tree index [$tree selection get]]
  42. } else {
  43. set sellayer "end"
  44. }
  45. $tree insert $sellayer $parent $node \
  46. -text "gridline $count"\
  47. -window $frm \
  48. -drawcross auto
  49. set opt($count,1,_check) 1
  50. set dup($count) 0
  51. set opt($count,1,opacity) 1.0
  52. set opt($count,1,gridline) "gridline"
  53. set opt($count,1,gridcolor) \#AAAAAA
  54. set opt($count,1,gridborder) \#000000
  55. set opt($count,1,gridsize) 1000
  56. set opt($count,1,gridorigin) "0,0"
  57. set opt($count,1,griddraw) 1
  58. set opt($count,1,gridgeod) 0
  59. set opt($count,1,borderdraw) 1
  60. set opt($count,1,textdraw) 1
  61. set opt($count,1,textcolor) #AAAAAA
  62. set opt($count,1,font) ""
  63. set opt($count,1,fontsize) 9
  64. set opt($count,1,rhumbdraw) 0
  65. set opt($count,1,rhumbcoor) ""
  66. set opt($count,1,rhumbcolor) "black"
  67. set opt($count,1,geoddraw) 0
  68. set opt($count,1,geodcoor) ""
  69. set opt($count,1,geodcolor) "black"
  70. set opt($count,1,geodtxtcolor) "none"
  71. set first 1
  72. set opt($count,1,mod) 1
  73. set optlist { _check opacity gridcolor gridborder gridsize gridorigin griddraw gridgeod \
  74. borderdraw textdraw textcolor font fontsize rhumbdraw rhumbcoor geoddraw \
  75. geodcoor geodcolor geodtxtcolor}
  76. foreach key $optlist {
  77. set opt($count,0,$key) $opt($count,1,$key)
  78. }
  79. # create files in tmp diretory for layer output
  80. set mappid [pid]
  81. if {[catch {set lfile($count) [exec g.tempfile pid=$mappid]} error]} {
  82. GmLib::errmsg $error [G_msg "Error creating tempfile"]
  83. }
  84. set lfilemask($count) $lfile($count)
  85. append lfile($count) ".ppm"
  86. append lfilemask($count) ".pgm"
  87. incr count
  88. return $node
  89. }
  90. proc GmGridline::set_option { node key value } {
  91. variable opt
  92. set id [GmTree::node_id $node]
  93. set opt($id,1,$key) $value
  94. }
  95. ##########################################################################
  96. proc GmGridline::set_font { id } {
  97. variable opt
  98. if {$GmGridline::opt($id,1,font) != "" } {
  99. set Gm::dfont $GmGridline::opt($id,1,font)
  100. }
  101. Gm::defaultfont dgrid
  102. tkwait variable Gm::dfont
  103. set GmGridline::opt($id,1,font) $Gm::dfont
  104. set Gm::dfont ""
  105. }
  106. ##########################################################################
  107. # display gridline options
  108. proc GmGridline::options { id frm } {
  109. variable opt
  110. global bgcolor
  111. global iconpath
  112. # Panel heading
  113. set row [ frame $frm.heading1 ]
  114. Label $row.a -text [G_msg "Display grid lines, and geodesic lines or rhumblines"] \
  115. -fg MediumBlue
  116. pack $row.a -side left
  117. pack $row -side top -fill both -expand yes
  118. #opacity
  119. set row [ frame $frm.opc]
  120. Label $row.a -text [G_msg "Opaque "]
  121. scale $row.b -from 1.0 -to 0.0 -showvalue 1 \
  122. -orient horizontal -length 300 -resolution 0.01 -fg "#656565"\
  123. -variable GmGridline::opt($id,1,opacity)
  124. Label $row.c -text [G_msg " Transparent"]
  125. pack $row.a $row.b $row.c -side left
  126. pack $row -side top -fill both -expand yes
  127. # grid options 1
  128. set row [ frame $frm.grid1 ]
  129. Label $row.a -text [G_msg "Grid options: "]
  130. checkbutton $row.b -text [G_msg "draw grid"] -variable GmGridline::opt($id,1,griddraw)
  131. checkbutton $row.c -text [G_msg "geodetic grid "] -variable GmGridline::opt($id,1,gridgeod)
  132. SelectColor $row.d -type menubutton -variable GmGridline::opt($id,1,gridcolor)
  133. Label $row.e -text [G_msg "grid color "]
  134. Button $row.f -text [G_msg "Help"] \
  135. -image [image create photo -file "$iconpath/gui-help.gif"] \
  136. -command "spawn g.manual --q d.grid" \
  137. -background $bgcolor \
  138. -helptext [G_msg "Help for grids"]
  139. pack $row.a $row.b $row.c $row.d $row.e $row.f -side left
  140. pack $row -side top -fill both -expand yes
  141. # grid options 4
  142. set row [ frame $frm.grid4 ]
  143. Label $row.a -text [G_msg " grid size (map units)"]
  144. LabelEntry $row.b -textvariable GmGridline::opt($id,1,gridsize) -width 7
  145. Label $row.c -text [G_msg " grid origin (east, north)"]
  146. LabelEntry $row.d -textvariable GmGridline::opt($id,1,gridorigin) -width 15
  147. pack $row.a $row.b $row.c $row.d -side left
  148. pack $row -side top -fill both -expand yes
  149. # grid options 2
  150. set row [ frame $frm.grid2 ]
  151. Label $row.a -text " "
  152. checkbutton $row.b -text [G_msg "draw border text "] -variable GmGridline::opt($id,1,textdraw)
  153. SelectColor $row.c -type menubutton -variable GmGridline::opt($id,1,textcolor)
  154. Label $row.d -text [G_msg "text color "]
  155. Button $row.e -image [image create photo -file "$iconpath/gui-font.gif"] \
  156. -highlightthickness 0 -takefocus 0 -relief raised -borderwidth 1 \
  157. -helptext [G_msg "select font for text"] \
  158. -command "GmGridline::set_font $id"
  159. Label $row.f -text [G_msg "text font "]
  160. Label $row.g -text [G_msg " text size"]
  161. SpinBox $row.h -range {1 72 1} -textvariable GmGridline::opt($id,1,fontsize) \
  162. -width 2 -helptext [G_msg "Grid text size in points"]
  163. pack $row.a $row.b $row.c $row.d $row.e $row.f $row.g $row.h -side left
  164. pack $row -side top -fill both -expand yes
  165. # grid options 3
  166. set row [ frame $frm.grid3 ]
  167. Label $row.a -text " "
  168. checkbutton $row.b -text [G_msg "draw grid border "] -variable GmGridline::opt($id,1,borderdraw)
  169. SelectColor $row.c -type menubutton -variable GmGridline::opt($id,1,gridborder)
  170. Label $row.d -text [G_msg "border color "]
  171. pack $row.a $row.b $row.c $row.d -side left
  172. pack $row -side top -fill both -expand yes
  173. set row [ frame $frm.line ]
  174. Label $row.a -text [G_msg "Geodesic and rhumblines for latlong locations only"]
  175. pack $row.a -side left
  176. pack $row -side top -fill both -expand yes
  177. # geodesic line options 1
  178. set row [ frame $frm.geod1 ]
  179. Label $row.a -text " "
  180. checkbutton $row.b -text [G_msg "draw geodesic line"] -variable GmGridline::opt($id,1,geoddraw)
  181. Button $row.c -text [G_msg "Help"] \
  182. -image [image create photo -file "$iconpath/gui-help.gif"] \
  183. -command "spawn g.manual --q d.geodesic" \
  184. -background $bgcolor \
  185. -helptext [G_msg "Help for geodesic lines"]
  186. Label $row.d -text [G_msg " line color"]
  187. ComboBox $row.e -padx 2 -width 7 -textvariable GmGridline::opt($id,1,geodcolor) \
  188. -values {"white" "grey" "gray" "black" "brown" "red" "orange" \
  189. "yellow" "green" "aqua" "cyan" "indigo" "blue" "purple" "violet" "magenta"}
  190. Label $row.f -text [G_msg " text color"]
  191. ComboBox $row.g -padx 2 -width 7 -textvariable GmGridline::opt($id,1,geodtxtcolor) \
  192. -values {"white" "grey" "gray" "black" "brown" "red" "orange" \
  193. "yellow" "green" "aqua" "cyan" "indigo" "blue" "purple" "violet" "magenta"}
  194. pack $row.a $row.b $row.c $row.d $row.e $row.f $row.g -side left
  195. pack $row -side top -fill both -expand yes
  196. # geodesic line options 2
  197. set row [ frame $frm.geod2 ]
  198. Label $row.a -text [G_msg " line endpoints (x1,y1,x2,y2)"]
  199. LabelEntry $row.b -textvariable GmGridline::opt($id,1,geodcoor) -width 35
  200. pack $row.a $row.b -side left
  201. pack $row -side top -fill both -expand yes
  202. # rhumbline options 1
  203. set row [ frame $frm.rhumb1 ]
  204. Label $row.a -text " "
  205. checkbutton $row.b -text [G_msg "draw rhumbline"] -variable GmGridline::opt($id,1,rhumbdraw)
  206. Button $row.c -text [G_msg "Help"] \
  207. -image [image create photo -file "$iconpath/gui-help.gif"] \
  208. -command "spawn g.manual --q d.rhumbline" \
  209. -background $bgcolor \
  210. -helptext [G_msg "Help for rhumblines"]
  211. Label $row.d -text [G_msg " line color"]
  212. ComboBox $row.e -padx 2 -width 7 -textvariable GmGridline::opt($id,1,rhumbcolor) \
  213. -values {"white" "grey" "gray" "black" "brown" "red" "orange" \
  214. "yellow" "green" "aqua" "cyan" "indigo" "blue" "purple" "violet" "magenta"}
  215. pack $row.a $row.b $row.c $row.d $row.e -side left
  216. pack $row -side top -fill both -expand yes
  217. # rhumbline options 2
  218. set row [ frame $frm.rhumb2 ]
  219. Label $row.a -text [G_msg " line endpoints (x1,y1,x2,y2)"]
  220. LabelEntry $row.b -textvariable GmGridline::opt($id,1,rhumbcoor) -width 35
  221. pack $row.a $row.b -side left
  222. pack $row -side top -fill both -expand yes
  223. }
  224. ##########################################################################
  225. proc GmGridline::save { tree depth node } {
  226. variable opt
  227. variable optlist
  228. set id [GmTree::node_id $node]
  229. foreach key $optlist {
  230. GmTree::rc_write $depth "$key $opt($id,1,$key)"
  231. }
  232. }
  233. ##########################################################################
  234. proc GmGridline::display { node mod } {
  235. global mon
  236. global env
  237. variable optlist
  238. variable lfile
  239. variable lfilemask
  240. variable opt
  241. variable tree
  242. variable dup
  243. variable count
  244. variable first
  245. set tree($mon) $GmTree::tree($mon)
  246. set id [GmTree::node_id $node]
  247. # If we are told dirty (for zoom) force dirty
  248. # Don't remove a dirty from a previous unrendered zoom
  249. if {$mod} {set opt($id,1,mod) 1}
  250. set cmd ""
  251. set cmd2 ""
  252. set cmd3 ""
  253. if { ! ( $opt($id,1,_check) ) } { return }
  254. # set hex colors to rgb
  255. set gridcolor [GmLib::color $opt($id,1,gridcolor)]
  256. set gridborder [GmLib::color $opt($id,1,gridborder)]
  257. set txtcolor [GmLib::color $opt($id,1,textcolor)]
  258. # d.grid command
  259. if { $opt($id,1,griddraw) || $opt($id,1,borderdraw) } {
  260. set cmd "d.grid size=$opt($id,1,gridsize) origin=$opt($id,1,gridorigin) \
  261. color=$gridcolor bordercolor=$gridborder textcolor=$txtcolor \
  262. fontsize=$opt($id,1,fontsize)"
  263. }
  264. if { $opt($id,1,gridgeod) && $cmd != "" } {append cmd " -g"}
  265. if { !$opt($id,1,griddraw) && $cmd != "" } {append cmd " -n"}
  266. if { !$opt($id,1,borderdraw) && $cmd != "" } {append cmd " -b"}
  267. if { !$opt($id,1,textdraw) && $cmd != "" } {append cmd " -t"}
  268. # d.geodesic command
  269. if { $opt($id,1,geoddraw) } {
  270. set cmd2 "d.geodesic coor=$opt($id,1,geodcoor) \
  271. lcolor=$opt($id,1,geodcolor) \
  272. tcolor=$opt($id,1,geodtxtcolor)"
  273. }
  274. # d.rhumbline command
  275. if { $opt($id,1,rhumbdraw) } {
  276. set cmd3 "d.rhumbline coor=$opt($id,1,rhumbcoor) \
  277. lcolor=$opt($id,1,rhumbcolor) "
  278. }
  279. # check value of GRASS_FONT variable prior to display
  280. if {![catch {set env(GRASS_FONT)}]} {
  281. set currfont $env(GRASS_FONT)
  282. } else {
  283. set currfont "romans"
  284. }
  285. # set grass font environmental variable to user selection"
  286. if { $GmGridline::opt($id,1,font) != ""} {
  287. set env(GRASS_FONT) $GmGridline::opt($id,1,font)
  288. }
  289. # Decide whether to run, run command, and copy files to temp
  290. GmCommonLayer::display_commands [namespace current] $id [list $cmd $cmd2 $cmd3]
  291. # set grass font environmental variable to whatever it was when we started
  292. # this lets different text layers have different fonts
  293. set env(GRASS_FONT) $currfont
  294. }
  295. ##########################################################################
  296. proc GmGridline::duplicate { tree parent node id } {
  297. variable optlist
  298. variable lfile
  299. variable lfilemask
  300. variable opt
  301. variable count
  302. variable dup
  303. variable first
  304. global iconpath
  305. set node "gridline:$count"
  306. set dup($count) 1
  307. set frm [ frame .gridlineicon$count]
  308. set check [checkbutton $frm.check \
  309. -variable GmGridline::opt($count,1,_check) \
  310. -height 1 -padx 0 -width 0]
  311. image create photo gico -file "$iconpath/module-d.grid.gif"
  312. set gdico [label $frm.gdico -image gico -bd 1 -relief raised]
  313. pack $check $gdico -side left
  314. #insert new layer
  315. if {[$tree selection get] != "" } {
  316. set sellayer [$tree index [$tree selection get]]
  317. } else {
  318. set sellayer "end"
  319. }
  320. $tree insert $sellayer $parent $node \
  321. -text "gridline $count"\
  322. -window $frm \
  323. -drawcross auto
  324. set opt($count,1,opacity) $opt($id,1,opacity)
  325. set optlist { _check gridcolor gridborder gridsize gridorigin griddraw gridgeod \
  326. borderdraw textdraw rhumbdraw rhumbcoor geoddraw geodcoor geodcolor \
  327. geodtxtcolor}
  328. foreach key $optlist {
  329. set opt($count,1,$key) $opt($id,1,$key)
  330. set opt($count,0,$key) $opt($count,1,$key)
  331. }
  332. # create files in tmp directory for layer output
  333. set mappid [pid]
  334. if {[catch {set lfile($count) [exec g.tempfile pid=$mappid]} error]} {
  335. GmLib::errmsg $error [G_msg "Error creating tempfile"]
  336. }
  337. set lfilemask($count) $lfile($count)
  338. append lfile($count) ".ppm"
  339. append lfilemask($count) ".pgm"
  340. incr count
  341. return $node
  342. }