cmd.tcl 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. ##########################################################################
  2. # cmd.tcl - command 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 GmCmd {
  12. variable array opt # cmd current options
  13. variable count 1
  14. variable array tree # mon
  15. variable array lfile # command
  16. variable array lfilemask # command
  17. variable optlist
  18. variable array dup # layer
  19. }
  20. proc GmCmd::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 "cmd:$count"
  30. set frm [ frame .cmdicon$count]
  31. set check [checkbutton $frm.check \
  32. -variable GmCmd::opt($count,1,_check) \
  33. -height 1 -padx 0 -width 0]
  34. image create photo cico -file "$iconpath/gui-cmd.gif"
  35. set ico [label $frm.ico -image cico -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 "cmd $count" \
  46. -window $frm \
  47. -drawcross auto
  48. set opt($count,1,_check) 1
  49. set dup($count) 0
  50. set opt($count,1,opacity) 1.0
  51. set opt($count,1,cmd) ""
  52. set opt($count,1,mod) 1
  53. set optlist { _check opacity cmd}
  54. foreach key $optlist {
  55. set opt($count,0,$key) $opt($count,1,$key)
  56. }
  57. # create files in tmp diretory for layer output
  58. set mappid [pid]
  59. if {[catch {set lfile($count) [exec g.tempfile pid=$mappid]} error]} {
  60. GmLib::errmsg $error [G_msg "Error creating tempfile"]
  61. }
  62. set lfilemask($count) $lfile($count)
  63. append lfile($count) ".ppm"
  64. append lfilemask($count) ".pgm"
  65. incr count
  66. return $node
  67. }
  68. proc GmCmd::set_option { node key value } {
  69. variable opt
  70. set id [GmTree::node_id $node]
  71. set opt($id,1,$key) $value
  72. }
  73. # display cmd options
  74. proc GmCmd::options { id frm } {
  75. variable opt
  76. # Panel heading
  77. set row [ frame $frm.heading ]
  78. Label $row.a -text "Enter any GRASS command" \
  79. -fg MediumBlue
  80. pack $row.a -side left
  81. pack $row -side top -fill both -expand yes
  82. #opacity
  83. set row [ frame $frm.opc]
  84. Label $row.a -text [G_msg "Opaque "]
  85. scale $row.b -from 1.0 -to 0.0 -showvalue 1 \
  86. -orient horizontal -length 300 -resolution 0.01 -fg "#656565"\
  87. -variable GmCmd::opt($id,1,opacity)
  88. Label $row.c -text [G_msg " Transparent"]
  89. pack $row.a $row.b $row.c -side left
  90. pack $row -side top -fill both -expand yes
  91. # cmd name
  92. set row [ frame $frm.name ]
  93. Label $row.a -text [G_msg "Command:"]
  94. Entry $row.b -width 50 -text "$opt($id,1,cmd)" \
  95. -textvariable GmCmd::opt($id,1,cmd)
  96. pack $row.a $row.b -side left
  97. pack $row -side top -fill both -expand yes
  98. }
  99. proc GmCmd::save { tree depth node } {
  100. variable opt
  101. variable optlist
  102. set id [GmTree::node_id $node]
  103. foreach key $optlist {
  104. GmTree::rc_write $depth "$key $opt($id,1,$key)"
  105. }
  106. }
  107. proc GmCmd::display { node mod} {
  108. global mon
  109. variable optlist
  110. variable lfile
  111. variable lfilemask
  112. variable opt
  113. variable rasttype
  114. variable tree
  115. set tree($mon) $GmTree::tree($mon)
  116. set id [GmTree::node_id $node]
  117. # If we are told dirty (for zoom) force dirty
  118. # Don't remove a dirty from a previous unrendered zoom
  119. if {$mod} {set opt($id,1,mod) 1}
  120. if { $opt($id,1,cmd) == "" } { return }
  121. set cmd $opt($id,1,cmd)
  122. # Decide whether to run, run command, and copy files to temp
  123. GmCommonLayer::display_command [namespace current] $id $cmd
  124. }
  125. proc GmCmd::duplicate { tree parent node id} {
  126. variable optlist
  127. variable lfile
  128. variable lfilemask
  129. variable opt
  130. variable count
  131. variable dup
  132. global iconpath
  133. set node "cmd:$count"
  134. set dup($count) 1
  135. set frm [ frame .cmdicon$count]
  136. set check [checkbutton $frm.check \
  137. -variable GmCmd::opt($count,1,_check) \
  138. -height 1 -padx 0 -width 0]
  139. image create photo cico -file "$iconpath/gui-cmd.gif"
  140. set ico [label $frm.ico -image cico -bd 1 -relief raised]
  141. bind $ico <ButtonPress-1> "GmTree::selectn $tree $node"
  142. pack $check $ico -side left
  143. #insert new layer
  144. if {[$tree selection get] != "" } {
  145. set sellayer [$tree index [$tree selection get]]
  146. } else {
  147. set sellayer "end"
  148. }
  149. $tree insert $sellayer $parent $node \
  150. -text "cmd $count" \
  151. -window $frm \
  152. -drawcross auto
  153. set opt($count,1,opacity) $opt($id,1,opacity)
  154. set optlist { _check cmd}
  155. foreach key $optlist {
  156. set opt($count,1,$key) $opt($id,1,$key)
  157. set opt($count,0,$key) $opt($count,1,$key)
  158. }
  159. set id $count
  160. # create files in tmp directory for layer output
  161. set mappid [pid]
  162. if {[catch {set lfile($count) [exec g.tempfile pid=$mappid]} error]} {
  163. GmLib::errmsg $error [G_msg "Error creating tempfile"]
  164. }
  165. set lfilemask($count) $lfile($count)
  166. append lfile($count) ".ppm"
  167. append lfilemask($count) ".pgm"
  168. incr count
  169. return $node
  170. }