maptext.tcl 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. ###############################################################
  2. # maptext.tcl - TclTk canvas postscript text layer options file for GRASS GIS Manager
  3. # February 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 GmCtext {
  12. variable array opt # ctext options
  13. variable placement #entry widget for x,y coordinates
  14. variable count 1
  15. variable optlist
  16. }
  17. proc GmCtext::create { tree parent } {
  18. variable opt
  19. variable count
  20. variable dup
  21. variable optlist
  22. global iconpath
  23. global env
  24. set node "ctext:$count"
  25. set frm [ frame .ctexticon$count]
  26. set check [checkbutton $frm.check \
  27. -variable GmCtext::opt($count,1,_check) \
  28. -height 1 -padx 0 -width 0]
  29. image create photo ctico -file "$iconpath/gui-maptext.gif"
  30. set ico [label $frm.ico -image ctico -bd 1 -relief raised]
  31. bind $ico <ButtonPress-1> "GmTree::selectn $tree $node"
  32. pack $check $ico -side left
  33. #insert new layer
  34. if {[$tree selection get] != "" } {
  35. set sellayer [$tree index [$tree selection get]]
  36. } else {
  37. set sellayer "end"
  38. }
  39. $tree insert $sellayer $parent $node \
  40. -text "PS text layer $count"\
  41. -window $frm \
  42. -drawcross auto
  43. set opt($count,1,_check) 1
  44. set opt($count,1,opacity) 1.0
  45. set opt($count,1,text) ""
  46. set opt($count,1,at) "100,100"
  47. set opt($count,1,font) "times 12"
  48. set opt($count,1,fill) \#000000
  49. set opt($count,1,width) 100
  50. set opt($count,1,anchor) "center_left"
  51. set opt($count,1,justify) "left"
  52. set opt($count,1,coordinates) "pixels"
  53. set opt($count,1,mouseset) 0
  54. set optlist { _check opacity text at font fill width anchor justify coordinates mouseset}
  55. foreach key $optlist {
  56. set opt($count,0,$key) $opt($count,1,$key)
  57. }
  58. incr count
  59. return $node
  60. }
  61. ###############################################################################
  62. proc GmCtext::select_font { id frm } {
  63. global mon
  64. variable opt
  65. set fon [SelectFont $frm.fontset -type dialog -sampletext [G_msg "This is font sample text."] -title [G_msg "Select label font"]]
  66. if { $fon != "" } {set opt($id,1,font) $fon}
  67. }
  68. ###############################################################################
  69. proc GmCtext::set_option { node key value } {
  70. variable opt
  71. set id [GmTree::node_id $node]
  72. set opt($id,1,$key) $value
  73. }
  74. ###############################################################################
  75. proc GmCtext::mouseset { id } {
  76. # use mouse to set scalebar placement coordinates
  77. global mon pctentry pixelentry geogentry
  78. variable placement
  79. if { $GmCtext::opt($id,1,mouseset) == 1} {
  80. if {$GmCtext::opt($id,1,coordinates) == "pixels"} {
  81. set pixelentry $GmCtext::placement
  82. } else {
  83. set pixelentry ""
  84. }
  85. if {$GmCtext::opt($id,1,coordinates) == "percent"} {
  86. set pctentry $GmCtext::placement
  87. } else {
  88. set pctentry ""
  89. }
  90. if {$GmCtext::opt($id,1,coordinates) == "geographic"} {
  91. set geogentry $GmCtext::placement
  92. } else {
  93. set geogentry ""
  94. }
  95. }
  96. }
  97. ###############################################################################
  98. # ctext options
  99. proc GmCtext::options { id frm } {
  100. variable opt
  101. variable placement
  102. global iconpath
  103. # Panel heading
  104. set row [ frame $frm.heading ]
  105. Label $row.a -text [G_msg "Create postscript text object (for postscript eps, pdf, and print output only)"] \
  106. -fg MediumBlue
  107. pack $row.a -side left
  108. pack $row -side top -fill both -expand yes
  109. # text
  110. set row [ frame $frm.text ]
  111. Label $row.a -text [G_msg "Text to display:"]
  112. LabelEntry $row.b -textvariable GmCtext::opt($id,1,text) -width 45
  113. pack $row.a $row.b -side left
  114. pack $row -side top -fill both -expand yes
  115. # coordinates1
  116. set row [ frame $frm.east_north ]
  117. set placement [LabelEntry $row.a -label [G_msg "Text placement: x,y coordinates (from upper left) "] \
  118. -textvariable GmCtext::opt($id,1,at) -width 24]
  119. pack $row.a -side left
  120. pack $row -side top -fill both -expand yes
  121. # coordinates2
  122. set row [ frame $frm.textcoord2 ]
  123. Label $row.a -text [G_msg " coordinate type for text placement "]
  124. ComboBox $row.b -padx 2 -width 10 -textvariable GmCtext::opt($id,1,coordinates) \
  125. -values {"pixels" "percent" "geographic" } -modifycmd "GmCtext::mouseset $id"
  126. checkbutton $row.c -text [G_msg "place with mouse"] \
  127. -variable GmCtext::opt($id,1,mouseset) \
  128. -command "GmCtext::mouseset $id"
  129. pack $row.a $row.b $row.c -side left
  130. pack $row -side top -fill both -expand yes
  131. # text options1
  132. set row [ frame $frm.textopt1 ]
  133. Label $row.a -text [G_msg " align text with coordinate point "]
  134. ComboBox $row.b -padx 2 -width 12 -textvariable GmCtext::opt($id,1,anchor) \
  135. -values {"lower_left" "bottom_center" "lower_right" "center_left" "center"
  136. "center_right" "upper_left" "top_center" "upper_right" }
  137. pack $row.a $row.b -side left
  138. pack $row -side top -fill both -expand yes
  139. # text options2
  140. set row [ frame $frm.textopt2 ]
  141. Label $row.a -text [G_msg " justification"]
  142. ComboBox $row.b -padx 2 -width 7 -textvariable GmCtext::opt($id,1,justify) \
  143. -values {"left" "center" "right"}
  144. Label $row.c -text [G_msg " line width"]
  145. LabelEntry $row.d -textvariable GmCtext::opt($id,1,width) -width 5
  146. pack $row.a $row.b $row.c $row.d -side left
  147. pack $row -side top -fill both -expand yes
  148. # select font
  149. set row [ frame $frm.font ]
  150. Label $row.a -text [G_msg "Font:"]
  151. Button $row.b -image [image create photo -file "$iconpath/gui-font.gif"] \
  152. -highlightthickness 0 -takefocus 0 -relief raised -borderwidth 1 \
  153. -helptext [G_msg "select font for text"] \
  154. -command "GmCtext::select_font $id $frm"
  155. Entry $row.c -width 15 -text "$opt($id,1,font)" \
  156. -textvariable GmCtext::opt($id,1,font)
  157. Label $row.d -text [G_msg " color"]
  158. SelectColor $row.e -type menubutton -variable GmCtext::opt($id,1,fill)
  159. pack $row.a $row.b $row.c $row.d $row.e -side left
  160. pack $row -side top -fill both -expand yes
  161. }
  162. ###############################################################################
  163. proc GmCtext::save { tree depth node } {
  164. variable opt
  165. variable optlist
  166. set id [GmTree::node_id $node]
  167. foreach key $optlist {
  168. GmTree::rc_write $depth "$key $opt($id,1,$key)"
  169. }
  170. }
  171. ###############################################################################
  172. proc GmCtext::display { node } {
  173. variable opt
  174. variable tree
  175. variable can
  176. global mon
  177. set tree($mon) $GmTree::tree($mon)
  178. set id [GmTree::node_id $node]
  179. set canvas_w($mon) $MapCanvas::canvas_w($mon)
  180. set canvas_h($mon) $MapCanvas::canvas_h($mon)
  181. set can($mon) $MapCanvas::can($mon)
  182. if {$opt($id,1,_check) == 0 } { return }
  183. if { $opt($id,1,text) == "" } { return }
  184. switch $opt($id,1,anchor) {
  185. "lower_left" { set anchor "sw"}
  186. "bottom_center" { set anchor "s" }
  187. "lower_right" { set anchor "se"}
  188. "center_left" { set anchor "w" }
  189. "center" { set anchor "center" }
  190. "center_right" { set anchor "e" }
  191. "upper_left" { set anchor "nw"}
  192. "top_center" { set anchor "n" }
  193. "upper_right" { set anchor "ne"}
  194. }
  195. set xcoord [lindex [split $opt($id,1,at) ","] 0]
  196. set ycoord [lindex [split $opt($id,1,at) ","] 1]
  197. if {$opt($id,1,coordinates) == "geographic"} {
  198. set xcoord [MapCanvas::mape2scrx $mon $xcoord]
  199. set ycoord [MapCanvas::mapn2scry $mon $ycoord]
  200. $can($mon) create text $xcoord $ycoord \
  201. -anchor $anchor \
  202. -justify $opt($id,1,justify) \
  203. -width $opt($id,1,width) \
  204. -fill $opt($id,1,fill) \
  205. -font $opt($id,1,font) \
  206. -text $opt($id,1,text)
  207. } elseif {$opt($id,1,coordinates) == "percent"} {
  208. set xpct [expr ($xcoord/100.0) * $canvas_w($mon)]
  209. set ypct [expr ($ycoord/100.0) * $canvas_h($mon)]
  210. $can($mon) create text $xpct $ypct \
  211. -anchor $anchor \
  212. -justify $opt($id,1,justify) \
  213. -width $opt($id,1,width) \
  214. -fill $opt($id,1,fill) \
  215. -font $opt($id,1,font) \
  216. -text $opt($id,1,text)
  217. } else {
  218. $can($mon) create text $xcoord $ycoord \
  219. -anchor $anchor \
  220. -justify $opt($id,1,justify) \
  221. -width $opt($id,1,width) \
  222. -fill $opt($id,1,fill) \
  223. -font $opt($id,1,font) \
  224. -text $opt($id,1,text)
  225. }
  226. }
  227. ###############################################################################
  228. proc GmCtext::duplicate { tree parent node id } {
  229. variable opt
  230. variable count
  231. variable dup
  232. variable optlist
  233. global iconpath
  234. set node "ctext:$count"
  235. set frm [ frame .ctexticon$count]
  236. set check [checkbutton $frm.check \
  237. -variable GmCtext::opt($count,1,_check) \
  238. -height 1 -padx 0 -width 0]
  239. image create photo ctico -file "$iconpath/gui-maptext.gif"
  240. set ico [label $frm.ico -image ctico -bd 1 -relief raised]
  241. bind $ico <ButtonPress-1> "GmTree::selectn $tree $node"
  242. pack $check $ico -side left
  243. #insert new layer
  244. if {[$tree selection get] != "" } {
  245. set sellayer [$tree index [$tree selection get]]
  246. } else {
  247. set sellayer "end"
  248. }
  249. $tree insert $sellayer $parent $node \
  250. -text "PS text layer $count"\
  251. -window $frm \
  252. -drawcross auto
  253. set opt($count,1,opacity) $opt($id,1,opacity)
  254. set first 1
  255. foreach key $optlist {
  256. set opt($count,1,$key) $opt($id,1,$key)
  257. set opt($count,0,$key) $opt($count,1,$key)
  258. }
  259. incr count
  260. return $node
  261. }