barscale.tcl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. ##########################################################################
  2. # barscale.tcl - barscale layer options file for GRASS GIS Manager
  3. # March 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. ##########################################################################
  11. namespace eval GmBarscale {
  12. variable array opt # barscale current options
  13. variable count 1
  14. variable array lfile # scale
  15. variable array lfilemask # scale
  16. variable optlist
  17. variable first
  18. variable array dup # layer
  19. variable placement #LabelEntry widget for scale bar placment coordinates
  20. };
  21. ###############################################################################
  22. # create new barscale layer
  23. proc GmBarscale::create { tree parent } {
  24. variable opt
  25. variable count
  26. variable lfile
  27. variable lfilemask
  28. variable optlist
  29. variable first
  30. variable dup
  31. variable can
  32. global mon
  33. global iconpath
  34. set node "barscale:$count"
  35. set frm [ frame .barscaleicon$count]
  36. set check [checkbutton $frm.check \
  37. -variable GmBarscale::opt($count,1,_check) \
  38. -height 1 -padx 0 -width 0]
  39. image create photo scaleico -file "$iconpath/module-d.barscale.gif"
  40. set ico [label $frm.ico -image scaleico -bd 1 -relief raised]
  41. bind $ico <ButtonPress-1> "GmTree::selectn $tree $node"
  42. pack $check $ico -side left
  43. #insert new layer
  44. if {[$tree selection get] != "" } {
  45. set sellayer [$tree index [$tree selection get]]
  46. } else {
  47. set sellayer "end"
  48. }
  49. $tree insert $sellayer $parent $node \
  50. -text "scale $count"\
  51. -window $frm \
  52. -drawcross auto
  53. set opt($count,1,_check) 1
  54. set dup($count) 0
  55. set opt($count,1,opacity) 1.0
  56. set opt($count,1,tcolor) \#000000
  57. set opt($count,1,bcolor) \#FFFFFF
  58. set opt($count,1,bcolor_none) 0
  59. set opt($count,1,font) ""
  60. set opt($count,1,line) 0
  61. set opt($count,1,at) "2,2"
  62. set opt($count,1,feet) 0
  63. set opt($count,1,top) 0
  64. set opt($count,1,arrow) 0
  65. set opt($count,1,scale) 0
  66. set opt($count,1,mod) 1
  67. set opt($count,1,mouseset) 0
  68. set first 1
  69. set optlist { _check opacity bcolor bcolor_none font tcolor at feet line top arrow scale mouseset}
  70. foreach key $optlist {
  71. set opt($count,0,$key) $opt($count,1,$key)
  72. }
  73. # create files in tmp diretory for layer output
  74. set mappid [pid]
  75. if {[catch {set lfile($count) [exec g.tempfile pid=$mappid]} error]} {
  76. GmLib::errmsg $error [G_msg "Error creating tempfile"]
  77. }
  78. set lfilemask($count) $lfile($count)
  79. append lfile($count) ".ppm"
  80. append lfilemask($count) ".pgm"
  81. incr count
  82. return $node
  83. };
  84. ###############################################################################
  85. proc GmBarscale::set_option { node key value } {
  86. variable opt
  87. set id [GmTree::node_id $node]
  88. set opt($id,1,$key) $value
  89. };
  90. ###############################################################################
  91. proc GmBarscale::mouseset { id } {
  92. # use mouse to set scalebar placement coordinates
  93. global mon pctentry
  94. variable placement
  95. if { $GmBarscale::opt($id,1,mouseset) == 1 } {
  96. set pctentry $GmBarscale::placement
  97. } else {
  98. set pctentry ""
  99. }
  100. };
  101. ##########################################################################
  102. proc GmBarscale::set_font { id } {
  103. variable opt
  104. if {$GmBarscale::opt($id,1,font) != "" } {
  105. set Gm::dfont $GmBarscale::opt($id,1,font)
  106. }
  107. Gm::defaultfont dbarscale
  108. tkwait variable Gm::dfont
  109. set GmBarscale::opt($id,1,font) $Gm::dfont
  110. set Gm::dfont ""
  111. };
  112. ###############################################################################
  113. # barscale options
  114. proc GmBarscale::options { id frm } {
  115. variable opt
  116. variable placement
  117. global bgcolor
  118. global iconpath
  119. global mon
  120. # Panel heading
  121. set row [ frame $frm.heading1 ]
  122. Label $row.a -text [G_msg "Display scale and north arrow"] \
  123. -fg MediumBlue
  124. pack $row.a -side left
  125. pack $row -side top -fill both -expand yes
  126. #opacity
  127. set row [ frame $frm.opc]
  128. Label $row.a -text [G_msg "Opaque "]
  129. scale $row.b -from 1.0 -to 0.0 -showvalue 1 \
  130. -orient horizontal -length 300 -resolution 0.01 -fg "#656565"\
  131. -variable GmBarscale::opt($id,1,opacity)
  132. Label $row.c -text [G_msg " Transparent"]
  133. pack $row.a $row.b $row.c -side left
  134. pack $row -side top -fill both -expand yes
  135. # at1
  136. set row [ frame $frm.at1 ]
  137. Label $row.a -text [G_msg "Scale placement: 0-100% from top left of display"]
  138. pack $row.a -side left
  139. pack $row -side top -fill both -expand yes
  140. # at2
  141. set row [ frame $frm.at2 ]
  142. Label $row.a -text [G_msg "\t enter x,y of scale/arrow upper left corner"]
  143. set placement [LabelEntry $row.b -width 8 \
  144. -textvariable GmBarscale::opt($id,1,at)]
  145. Label $row.c -text [G_msg " "]
  146. Button $row.d -text [G_msg "Help"] \
  147. -image [image create photo -file "$iconpath/gui-help.gif"] \
  148. -command "spawn g.manual --q d.barscale" \
  149. -background $bgcolor \
  150. -helptext [G_msg "Help"]
  151. pack $row.a $row.b $row.c $row.d -side left
  152. pack $row -side top -fill both -expand yes
  153. # at3
  154. set row [ frame $frm.at3 ]
  155. Label $row.a -text [G_msg "\t "]
  156. checkbutton $row.b -text [G_msg "place with mouse"] \
  157. -variable GmBarscale::opt($id,1,mouseset) \
  158. -command "GmBarscale::mouseset $id"
  159. pack $row.a $row.b -side left
  160. pack $row -side top -fill both -expand yes
  161. # color
  162. set row [ frame $frm.color ]
  163. Label $row.a -text [G_msg "Scale appearance: text color"]
  164. SelectColor $row.b -type menubutton -variable GmBarscale::opt($id,1,tcolor)
  165. Label $row.c -text [G_msg " font "]
  166. Button $row.d -image [image create photo -file "$iconpath/gui-font.gif"] \
  167. -highlightthickness 0 -takefocus 0 -relief raised -borderwidth 1 \
  168. -helptext [G_msg "select font for text"] \
  169. -command "GmBarscale::set_font $id"
  170. pack $row.a $row.b $row.c $row.d -side left
  171. pack $row -side top -fill both -expand yes
  172. # background
  173. set row [ frame $frm.background ]
  174. Label $row.a -text [G_msg "\tbackground color "]
  175. SelectColor $row.b -type menubutton -variable GmBarscale::opt($id,1,bcolor)
  176. Label $row.c -text " "
  177. checkbutton $row.d -text [G_msg "transparent background"] \
  178. -variable GmBarscale::opt($id,1,bcolor_none)
  179. pack $row.a $row.b $row.c $row.d -side left
  180. pack $row -side top -fill both -expand yes
  181. # arrow or scale only
  182. set row [ frame $frm.arrow ]
  183. Label $row.a -text "\t "
  184. checkbutton $row.b -text [G_msg "display N. arrow only"] \
  185. -variable GmBarscale::opt($id,1,arrow)
  186. checkbutton $row.c -text [G_msg "display scale only"] \
  187. -variable GmBarscale::opt($id,1,scale)
  188. pack $row.a $row.b $row.c -side left
  189. pack $row -side top -fill both -expand yes
  190. # text on top
  191. set row [ frame $frm.textontop ]
  192. Label $row.a -text "\t "
  193. checkbutton $row.b -text [G_msg "text on top of scale, instead of to right"] \
  194. -variable GmBarscale::opt($id,1,top)
  195. pack $row.a $row.b -side left
  196. pack $row -side top -fill both -expand yes
  197. # scale options
  198. set row [ frame $frm.opts ]
  199. Label $row.a -text "\t "
  200. checkbutton $row.b -text [G_msg "line scale instead of bar"] \
  201. -variable GmBarscale::opt($id,1,line)
  202. checkbutton $row.c -text [G_msg "use feet/miles instead of meters"] \
  203. -variable GmBarscale::opt($id,1,feet)
  204. pack $row.a $row.b $row.c -side left
  205. pack $row -side top -fill both -expand yes
  206. };
  207. ###############################################################################
  208. # save barscale layer node to grc file
  209. proc GmBarscale::save { tree depth node } {
  210. variable opt
  211. variable optlist
  212. global mon
  213. set id [GmTree::node_id $node]
  214. foreach key $optlist {
  215. GmTree::rc_write $depth "$key $opt($id,1,$key)"
  216. }
  217. };
  218. ###############################################################################
  219. # render and composite barscale layer
  220. proc GmBarscale::display { node mod } {
  221. global mon
  222. global env
  223. variable optlist
  224. variable lfile
  225. variable lfilemask
  226. variable opt
  227. variable tree
  228. variable dup
  229. variable count
  230. variable first
  231. set line ""
  232. set input ""
  233. set cmd ""
  234. set tree($mon) $GmTree::tree($mon)
  235. set id [GmTree::node_id $node]
  236. # If we are told dirty (for zoom) force dirty
  237. # Don't remove a dirty from a previous unrendered zoom
  238. if {$mod} {set opt($id,1,mod) 1}
  239. # set hex colors to rgb
  240. set tcolor [GmLib::color $opt($id,1,tcolor)]
  241. set bcolor [GmLib::color $opt($id,1,bcolor)]
  242. # no background color
  243. if { $opt($id,1,bcolor_none) == 1 } {
  244. set bcolor "none"
  245. }
  246. set cmd "d.barscale tcolor=$tcolor bcolor=$bcolor at=$opt($id,1,at)"
  247. # line scale
  248. if { $opt($id,1,line) != 0 } {
  249. append cmd " -l"
  250. }
  251. # text on top
  252. if { $opt($id,1,top) != 0 } {
  253. append cmd " -t"
  254. }
  255. # english units
  256. if { $opt($id,1,feet) != 0} {
  257. append cmd " -f"
  258. }
  259. # arrow only
  260. if { $opt($id,1,arrow) != 0 } {
  261. append cmd " -n"
  262. }
  263. # scale only
  264. if { $opt($id,1,scale) != 0 } {
  265. append cmd " -s"
  266. }
  267. # check value of GRASS_FONT variable prior to display
  268. if {![catch {set env(GRASS_FONT)}]} {
  269. set currfont $env(GRASS_FONT)
  270. } else {
  271. set currfont "romans"
  272. }
  273. # set grass font environmental variable to user selection"
  274. if { $GmBarscale::opt($id,1,font) != ""} {
  275. set env(GRASS_FONT) $GmBarscale::opt($id,1,font)
  276. }
  277. # Decide whether to run, run command, and copy files to temp
  278. GmCommonLayer::display_command [namespace current] $id $cmd
  279. # set grass font environmental variable to whatever it was when we started
  280. # this lets different text layers have different fonts
  281. set env(GRASS_FONT) $currfont
  282. };
  283. ###############################################################################
  284. #duplicate barscale layer
  285. proc GmBarscale::duplicate { tree parent node id } {
  286. variable optlist
  287. variable lfile
  288. variable lfilemask
  289. variable opt
  290. variable count
  291. variable dup
  292. variable first
  293. global iconpath
  294. set node "barscale:$count"
  295. set dup($count) 1
  296. set frm [ frame .barscaleicon$count]
  297. set check [checkbutton $frm.check \
  298. -variable GmBarscale::opt($count,1,_check) \
  299. -height 1 -padx 0 -width 0]
  300. image create photo scaleico -file "$iconpath/module-d.barscale.gif"
  301. set ico [label $frm.ico -image scaleico -bd 1 -relief raised]
  302. bind $ico <ButtonPress-1> "GmTree::selectn $tree $node"
  303. pack $check $ico -side left
  304. #insert new layer
  305. if {[$tree selection get] != "" } {
  306. set sellayer [$tree index [$tree selection get]]
  307. } else {
  308. set sellayer "end"
  309. }
  310. $tree insert $sellayer $parent $node \
  311. -text "scale $count" \
  312. -window $frm \
  313. -drawcross auto
  314. set opt($count,1,opacity) $opt($id,1,opacity)
  315. set first 1
  316. foreach key $optlist {
  317. set opt($count,1,$key) $opt($id,1,$key)
  318. set opt($count,0,$key) $opt($count,1,$key)
  319. }
  320. set id $count
  321. # create files in tmp directory for layer output
  322. set mappid [pid]
  323. if {[catch {set lfile($count) [exec g.tempfile pid=$mappid]} error]} {
  324. GmLib::errmsg $error [G_msg "Error creating tempfile"]
  325. }
  326. set lfilemask($count) $lfile($count)
  327. append lfile($count) ".ppm"
  328. append lfilemask($count) ".pgm"
  329. incr count
  330. return $node
  331. }