labels.tcl 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. ##########################################################################
  2. # labels.tcl - vector labels 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 GmLabels {
  12. variable array opt # labels current options
  13. variable count 1
  14. variable array tree # mon
  15. variable array lfile # labels
  16. variable array lfilemask # labels
  17. variable optlist
  18. variable array dup # layer
  19. }
  20. proc GmLabels::create { tree parent } {
  21. variable opt
  22. variable count
  23. variable lfile
  24. variable lfilemask
  25. variable optlist
  26. variable dup
  27. global mon
  28. global iconpath
  29. set node "labels:$count"
  30. set frm [ frame .labelsicon$count]
  31. set check [checkbutton $frm.check \
  32. -variable GmLabels::opt($count,1,_check) \
  33. -height 1 -padx 0 -width 0]
  34. image create photo labels_ico -file "$iconpath/module-d.labels.gif"
  35. set ico [label $frm.ico -image labels_ico -bd 1 -relief raised]
  36. bind $ico <ButtonPress-1> "GmTree::selectn $tree $node"
  37. pack $check $ico -side left
  38. #insert new layer
  39. if {[$tree selection get] != "" } {
  40. set sellayer [$tree index [$tree selection get]]
  41. } else {
  42. set sellayer "end"
  43. }
  44. $tree insert $sellayer $parent $node \
  45. -text "labels $count" \
  46. -window $frm \
  47. -drawcross auto
  48. set opt($count,1,_check) 1
  49. set dup($count) 0
  50. set opt($count,1,map) ""
  51. set opt($count,1,opacity) 1.0
  52. set opt($count,1,minreg) ""
  53. set opt($count,1,maxreg) ""
  54. set opt($count,1,ignore_rot) 0
  55. set opt($count,1,mod) 1
  56. set optlist { _check map opacity minreg maxreg}
  57. foreach key $optlist {
  58. set opt($count,0,$key) $opt($count,1,$key)
  59. }
  60. # create files in tmp diretory for layer output
  61. set mappid [pid]
  62. if {[catch {set lfile($count) [exec g.tempfile pid=$mappid]} error]} {
  63. GmLib::errmsg $error [G_msg "Error creating tempfile"]
  64. }
  65. set lfilemask($count) $lfile($count)
  66. append lfile($count) ".ppm"
  67. append lfilemask($count) ".pgm"
  68. incr count
  69. return $node
  70. }
  71. proc GmLabels::set_option { node key value } {
  72. variable opt
  73. set id [GmTree::node_id $node]
  74. set opt($id,1,$key) $value
  75. }
  76. proc GmLabels::select_labels { id } {
  77. set m [GSelect paint/labels title [G_msg "Labels for vectors"] parent "."]
  78. if { $m != "" } {
  79. set GmLabels::opt($id,1,map) $m
  80. GmTree::autonamel $m
  81. }
  82. }
  83. # display labels options
  84. proc GmLabels::options { id frm } {
  85. variable opt
  86. global bgcolor
  87. global iconpath
  88. # Panel heading
  89. set row [ frame $frm.heading ]
  90. Label $row.a -text [G_msg "Display labels for vector objects (created with v.label)"] \
  91. -fg MediumBlue
  92. pack $row.a -side left
  93. pack $row -side top -fill both -expand yes
  94. #opacity
  95. set row [ frame $frm.opc]
  96. Label $row.a -text [G_msg "Opaque "]
  97. scale $row.b -from 1.0 -to 0.0 -showvalue 1 \
  98. -orient horizontal -length 300 -resolution 0.01 -fg "#656565"\
  99. -variable GmLabels::opt($id,1,opacity)
  100. Label $row.c -text [G_msg " Transparent"]
  101. pack $row.a $row.b $row.c -side left
  102. pack $row -side top -fill both -expand yes
  103. # labels name
  104. set row [ frame $frm.name ]
  105. Label $row.a -text [G_msg "Labels file:"]
  106. Button $row.b -image [image create photo -file "$iconpath/module-d.labels.gif"] \
  107. -highlightthickness 0 -takefocus 0 -relief raised -borderwidth 1 \
  108. -helptext [G_msg "labels file to display"] \
  109. -command "GmLabels::select_labels $id"
  110. Entry $row.c -width 40 -text "$opt($id,1,map)" \
  111. -textvariable GmLabels::opt($id,1,map)
  112. Label $row.d -text " "
  113. Button $row.e -text [G_msg "Help"] \
  114. -image [image create photo -file "$iconpath/gui-help.gif"] \
  115. -command "spawn g.manual --q d.labels" \
  116. -background $bgcolor \
  117. -helptext [G_msg "Help"]
  118. pack $row.a $row.b $row.c $row.d $row.e -side left
  119. pack $row -side top -fill both -expand yes
  120. # display only in limited region size range
  121. set row [ frame $frm.region ]
  122. Label $row.a -text [G_msg "Display constraints:"]
  123. LabelEntry $row.b -label [G_msg "min"] -textvariable GmLabels::opt($id,1,minreg) \
  124. -width 8
  125. LabelEntry $row.c -label [G_msg "max"] -textvariable GmLabels::opt($id,1,maxreg) \
  126. -width 8
  127. Label $row.d -text [G_msg "region size"]
  128. pack $row.a $row.b $row.c $row.d -side left
  129. pack $row -side top -fill both -expand yes
  130. # ignore rotation
  131. set row [ frame $frm.ignore_rot ]
  132. checkbutton $row.a -text [G_msg " ignore rotation setting and draw horizontally"] -variable \
  133. GmLabels::opt($id,1,ignore_rot)
  134. pack $row.a -side left
  135. pack $row -side top -fill both -expand yes
  136. # launch v.label
  137. set row [ frame $frm.vlabel ]
  138. Label $row.a -text [G_msg "Launch v.label to create labels file"]
  139. Button $row.b -text [G_msg "v.label"] \
  140. -command "execute v.label"
  141. pack $row.a $row.b -side left
  142. pack $row -side top -fill both -expand yes
  143. }
  144. proc GmLabels::save { tree depth node } {
  145. variable opt
  146. variable optlist
  147. set id [GmTree::node_id $node]
  148. foreach key $optlist {
  149. GmTree::rc_write $depth "$key $opt($id,1,$key)"
  150. }
  151. }
  152. proc GmLabels::display { node mod } {
  153. global mon
  154. variable optlist
  155. variable lfile
  156. variable lfilemask
  157. variable opt
  158. variable tree
  159. variable dup
  160. variable count
  161. set tree($mon) $GmTree::tree($mon)
  162. set id [GmTree::node_id $node]
  163. # If we are told dirty (for zoom) force dirty
  164. # Don't remove a dirty from a previous unrendered zoom
  165. if {$mod} {set opt($id,1,mod) 1}
  166. if { ! ( $opt($id,1,_check) ) } { return }
  167. if { $opt($id,1,map) == "" } { return }
  168. set cmd "d.labels labels=$opt($id,1,map)"
  169. if { $opt($id,1,minreg) != "" } {
  170. append cmd " minreg=$opt($id,1,minreg)"
  171. }
  172. if { $opt($id,1,maxreg) != "" } {
  173. append cmd " maxreg=$opt($id,1,maxreg)"
  174. }
  175. # Decide whether to run, run command, and copy files to temp
  176. GmCommonLayer::display_command [namespace current] $id $cmd
  177. }
  178. proc GmLabels::query { node } {
  179. puts "Query not supported for Paint labels layer"
  180. }
  181. proc GmLabels::duplicate { tree parent node id } {
  182. variable optlist
  183. variable lfile
  184. variable lfilemask
  185. variable opt
  186. variable count
  187. variable dup
  188. global iconpath
  189. set node "labels:$count"
  190. set dup($count) 1
  191. set frm [ frame .labelsicon$count]
  192. set check [checkbutton $frm.check \
  193. -variable GmLabels::opt($count,1,_check) \
  194. -height 1 -padx 0 -width 0]
  195. image create photo labels_ico -file "$iconpath/module-d.labels.gif"
  196. set ico [label $frm.ico -image labels_ico -bd 1 -relief raised]
  197. bind $ico <ButtonPress-1> "GmTree::selectn $tree $node"
  198. pack $check $ico -side left
  199. #insert new layer
  200. if {[$tree selection get] != "" } {
  201. set sellayer [$tree index [$tree selection get]]
  202. } else {
  203. set sellayer "end"
  204. }
  205. if { $opt($id,1,map) == ""} {
  206. $tree insert $sellayer $parent $node \
  207. -text "labels $count" \
  208. -window $frm \
  209. -drawcross auto
  210. } else {
  211. $tree insert $sellayer $parent $node \
  212. -text "$opt($id,1,map)" \
  213. -window $frm \
  214. -drawcross auto
  215. }
  216. set opt($count,1,opacity) $opt($id,1,opacity)
  217. set optlist { _check map minreg maxreg}
  218. foreach key $optlist {
  219. set opt($count,1,$key) $opt($id,1,$key)
  220. set opt($count,0,$key) $opt($count,1,$key)
  221. }
  222. set id $count
  223. # create files in tmp directory for layer output
  224. set mappid [pid]
  225. if {[catch {set lfile($count) [exec g.tempfile pid=$mappid]} error]} {
  226. GmLib::errmsg $error [G_msg "Error creating tempfile"]
  227. }
  228. set lfilemask($count) $lfile($count)
  229. append lfile($count) ".ppm"
  230. append lfilemask($count) ".pgm"
  231. incr count
  232. return $node
  233. }