frames.tcl 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. ##########################################################################
  2. # frames.tcl - display frames 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 GmDframe {
  12. variable array opt # frame current options
  13. variable count 1
  14. variable array tree # mon
  15. variable array lfile # frame
  16. variable array lfilemask # frame
  17. variable optlist
  18. variable first
  19. variable array dup # layer
  20. }
  21. proc GmDframe::create { tree parent } {
  22. variable opt
  23. variable count
  24. variable lfile
  25. variable lfilemask
  26. variable optlist
  27. variable first
  28. variable dup
  29. global mon
  30. global iconpath
  31. set node "dframe:$count"
  32. set frm [ frame .dframeicon$count]
  33. set check [checkbutton $frm.check \
  34. -variable GmDframe::opt($count,1,_check) \
  35. -height 1 -padx 0 -width 0]
  36. image create photo dfrmico -file "$iconpath/module-d.frame.gif"
  37. set ico [label $frm.ico -image dfrmico -bd 1 -relief raised]
  38. pack $check $ico -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 "frame $count"\
  47. -window $frm \
  48. -drawcross auto
  49. set opt($count,1,_check) 1
  50. set dup($count) 0
  51. set opt($count,1,frame) ""
  52. set opt($count,1,erase) 0
  53. set opt($count,1,create) 1
  54. set opt($count,1,select) 0
  55. set opt($count,1,at) "50,100,0,50"
  56. set opt($count,1,mod) 1
  57. set first 1
  58. set optlist { _check frame erase create select at }
  59. foreach key $optlist {
  60. set opt($count,0,$key) $opt($count,1,$key)
  61. }
  62. # create files in tmp diretory for layer output
  63. set mappid [pid]
  64. if {[catch {set lfile($count) [exec g.tempfile pid=$mappid]} error]} {
  65. GmLib::errmsg $error [G_msg "Error creating tempfile"]
  66. }
  67. set lfilemask($count) $lfile($count)
  68. append lfile($count) ".ppm"
  69. append lfilemask($count) ".pgm"
  70. incr count
  71. return $node
  72. }
  73. proc GmDframe::set_option { node key value } {
  74. variable opt
  75. set id [GmTree::node_id $node]
  76. set opt($id,1,$key) $value
  77. }
  78. # frame options
  79. proc GmDframe::options { id frm } {
  80. variable opt
  81. global bgcolor
  82. global iconpath
  83. # Panel heading
  84. set row [ frame $frm.heading1 ]
  85. Label $row.a -text [G_msg "Divide map display into frames for displaying multiple maps"] \
  86. -fg MediumBlue
  87. pack $row.a -side left
  88. pack $row -side top -fill both -expand yes
  89. # create, select, or erase frames
  90. set row [ frame $frm.cats ]
  91. checkbutton $row.a -text [G_msg "create and select frame"] -variable \
  92. GmDframe::opt($id,1,create)
  93. checkbutton $row.b -text [G_msg "select frame"] -variable \
  94. GmDframe::opt($id,1,select)
  95. checkbutton $row.c -text [G_msg "remove all frames "] -variable \
  96. GmDframe::opt($id,1,erase)
  97. Button $row.d -text [G_msg "Help"] \
  98. -image [image create photo -file "$iconpath/gui-help.gif"] \
  99. -command "spawn g.manual --q d.frame" \
  100. -background $bgcolor \
  101. -helptext [G_msg "Help"]
  102. pack $row.a $row.b $row.c $row.d -side left
  103. pack $row -side top -fill both -expand yes
  104. # frame name
  105. set row [ frame $frm.frame ]
  106. Label $row.a -text [G_msg "Frame name (optional): "]
  107. LabelEntry $row.b -textvariable GmDframe::opt($id,1,frame) -width 40
  108. pack $row.a $row.b -side left
  109. pack $row -side top -fill both -expand yes
  110. # place frame1
  111. set row [ frame $frm.at1 ]
  112. Label $row.a -text [G_msg "Set frame borders at 0-100% from lower left corner of display "]
  113. pack $row.a -side left
  114. pack $row -side top -fill both -expand yes
  115. # place frame2
  116. set row [ frame $frm.at2 ]
  117. Label $row.a -text [G_msg " set borders (bottom,top,left,right): "]
  118. LabelEntry $row.b -textvariable GmDframe::opt($id,1,at) -width 25
  119. pack $row.a $row.b -side left
  120. pack $row -side top -fill both -expand yes
  121. }
  122. proc GmDframe::save { tree depth node } {
  123. variable opt
  124. variable optlist
  125. set id [GmTree::node_id $node]
  126. foreach key $optlist {
  127. GmTree::rc_write $depth "$key $opt($id,1,$key)"
  128. }
  129. }
  130. proc GmDframe::display { node mod } {
  131. global mon
  132. variable optlist
  133. variable lfile
  134. variable lfilemask
  135. variable opt
  136. variable tree
  137. variable dup
  138. variable count
  139. variable first
  140. set tree($mon) $GmTree::tree($mon)
  141. set id [GmTree::node_id $node]
  142. # If we are told dirty (for zoom) force dirty
  143. # Don't remove a dirty from a previous unrendered zoom
  144. if {$mod} {set opt($id,1,mod) 1}
  145. if { $opt($id,1,create) == 0 && $opt($id,1,select) == 0 && $opt($id,1,erase) == 0 } { return }
  146. if { $opt($id,1,at) == "" } { return }
  147. set cmd "d.frame"
  148. # create
  149. if { $opt($id,1,create) == 1 } {
  150. append cmd " -c"
  151. }
  152. # select
  153. if { $opt($id,1,select) == 1 } {
  154. append cmd " -s"
  155. }
  156. # erase and remove
  157. if { $opt($id,1,erase) == 1 } {
  158. append cmd " -e"
  159. }
  160. # frame name
  161. if { $opt($id,1,frame) != "" } {
  162. append cmd " frame=$opt($id,1,frame)"
  163. }
  164. # frame placement
  165. if { $opt($id,1,at) != "" } {
  166. append cmd " at=$opt($id,1,at)"
  167. }
  168. # check to see if options have changed
  169. foreach key $optlist {
  170. if {$opt($id,0,$key) != $opt($id,1,$key)} {
  171. set opt($id,1,mod) 1
  172. set opt($id,0,$key) $opt($id,1,$key)
  173. }
  174. }
  175. # Decide whether to run, run command, and copy files to temp
  176. GmCommonLayer::display_command [namespace current] $id $cmd
  177. }
  178. proc GmDframe::duplicate { tree parent node id } {
  179. variable optlist
  180. variable lfile
  181. variable lfilemask
  182. variable opt
  183. variable count
  184. variable dup
  185. global iconpath
  186. global first
  187. set node "dframe:$count"
  188. set dup($count) 1
  189. set frm [ frame .dframeicon$count]
  190. set check [checkbutton $frm.check \
  191. -variable GmDframe::opt($count,1,_check) \
  192. -height 1 -padx 0 -width 0]
  193. image create photo dfrmico -file "$iconpath/module-d.frame.gif"
  194. set ico [label $frm.ico -image dfrmico -bd 1 -relief raised]
  195. pack $check $ico -side left
  196. #insert new layer
  197. if {[$tree selection get] != "" } {
  198. set sellayer [$tree index [$tree selection get]]
  199. } else {
  200. set sellayer "end"
  201. }
  202. if { $opt($id,1,frame) == ""} {
  203. $tree insert $sellayer $parent $node \
  204. -text "frame $count" \
  205. -window $frm \
  206. -drawcross auto
  207. } else {
  208. $tree insert $sellayer $parent $node \
  209. -text "$opt($id,1,frame)" \
  210. -window $frm \
  211. -drawcross auto
  212. }
  213. set optlist { _check frame erase create select at }
  214. foreach key $optlist {
  215. set opt($count,1,$key) $opt($id,1,$key)
  216. set opt($count,0,$key) $opt($count,1,$key)
  217. }
  218. set id $count
  219. # create files in tmp directory for layer output
  220. set mappid [pid]
  221. if {[catch {set lfile($count) [exec g.tempfile pid=$mappid]} error]} {
  222. GmLib::errmsg $error [G_msg "Error creating tempfile"]
  223. }
  224. set lfilemask($count) $lfile($count)
  225. append lfile($count) ".ppm"
  226. append lfilemask($count) ".pgm"
  227. incr count
  228. return $node
  229. }