Changeset 22
- Timestamp:
- Jul 16, 2005 2:31:32 PM (18 years ago)
- Location:
- trunk
- Files:
-
- 8 added
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/apps/driver
r17 r22 25 25 package require Rappture 26 26 27 option add *MainWin.mode webstartupFile27 option add *MainWin.mode desktop startupFile 28 28 option add *MainWin.borderWidth 0 startupFile 29 option add *MainWin.anchor nwstartupFile29 option add *MainWin.anchor center startupFile 30 30 31 31 # "web site" look … … 129 129 pack $f.analyze -expand yes -fill both 130 130 131 $tool configure -analyzer $f.analyze131 $tool notify add analyzer * [list $f.analyze reset] 132 132 133 133 # ---------------------------------------------------------------------- … … 147 147 $f.analyze configure -holdwindow [$win.pager page @0] 148 148 149 if {[$tool xml get tool.control] == "auto"} { 149 set type [$tool xml get tool.control] 150 if {$type == ""} { 151 set type [$tool xml get tool.control.type] 152 } 153 154 if {$type == "auto"} { 150 155 # in "auto" mode, we don't need a simulate button 151 156 $f.analyze configure -simcontrol off -
trunk/gui/scripts/analyzer.tcl
r17 r22 228 228 # tool can run on "manual" (default) or "auto" 229 229 set cntl [$tool xml get tool.control] 230 if {"" == $cntl} { 231 set cntl [$tool xml get tool.control.type] 232 } 230 233 if {"" != $cntl} { 231 234 set _control $cntl … … 369 372 curve* - field* { 370 373 _autoLabel $xmlobj output.$item "Plot" counters 374 } 375 structure* { 376 _autoLabel $xmlobj output.$item "Structure" counters 371 377 } 372 378 table* { -
trunk/gui/scripts/booleanentry.tcl
r13 r22 14 14 inherit itk::Widget 15 15 16 constructor { xmlobjpath args} { # defined below }16 constructor {owner path args} { # defined below } 17 17 18 18 public method value {args} … … 23 23 protected method _newValue {} 24 24 25 private variable _ xmlobj "" ;# XML containing description25 private variable _owner "" ;# thing managing this control 26 26 private variable _path "" ;# path in XML to this number 27 27 } … … 37 37 # CONSTRUCTOR 38 38 # ---------------------------------------------------------------------- 39 itcl::body Rappture::BooleanEntry::constructor { xmlobjpath args} {40 if { ![Rappture::library isvalid $xmlobj]} {41 error "bad value \"$xmlobj\": should be Rappture::library"39 itcl::body Rappture::BooleanEntry::constructor {owner path args} { 40 if {[catch {$owner isa Rappture::ControlOwner} valid] != 0 || !$valid} { 41 error "bad object \"$owner\": should be Rappture::ControlOwner" 42 42 } 43 set _ xmlobj $xmlobj43 set _owner $owner 44 44 set _path $path 45 45 … … 54 54 bind $itk_component(switch) <<Value>> [itcl::code $this _newValue] 55 55 56 set color [$ xmlobjget $path.about.color]56 set color [$_owner xml get $path.about.color] 57 57 if {$color != ""} { 58 58 $itk_component(switch) configure -oncolor $color … … 60 60 61 61 # if the control has an icon, plug it in 62 set str [$ xmlobjget $path.about.icon]62 set str [$_owner xml get $path.about.icon] 63 63 if {$str != ""} { 64 64 $itk_component(switch) configure -onimage \ … … 71 71 # Assign the default value to this widget, if there is one. 72 72 # 73 set str [$ xmlobjget $path.default]73 set str [$_owner xml get $path.default] 74 74 if {"" != $str != ""} { $itk_component(switch) value $str } 75 75 } … … 118 118 # ---------------------------------------------------------------------- 119 119 itcl::body Rappture::BooleanEntry::label {} { 120 set label [$_ xmlobjget $_path.about.label]120 set label [$_owner xml get $_path.about.label] 121 121 if {"" == $label} { 122 122 set label "Boolean" … … 134 134 # ---------------------------------------------------------------------- 135 135 itcl::body Rappture::BooleanEntry::tooltip {} { 136 set str [$_ xmlobjget $_path.about.description]136 set str [$_owner xml get $_path.about.description] 137 137 138 set units [$_ xmlobjget $_path.units]139 set min [$_ xmlobjget $_path.min]140 set max [$_ xmlobjget $_path.max]138 set units [$_owner xml get $_path.units] 139 set min [$_owner xml get $_path.min] 140 set max [$_owner xml get $_path.max] 141 141 142 142 if {$units != "" || $min != "" || $max != ""} { -
trunk/gui/scripts/choiceentry.tcl
r11 r22 14 14 inherit itk::Widget 15 15 16 constructor {xmlobj path args} { # defined below } 16 constructor {owner path args} { # defined below } 17 destructor { # defined below } 17 18 18 19 public method value {args} … … 21 22 public method tooltip {} 22 23 24 protected method _rebuild {} 23 25 protected method _newValue {} 24 26 protected method _tooltip {} 25 27 26 private variable _ xmlobj "" ;# XML containing description28 private variable _owner "" ;# thing managing this control 27 29 private variable _path "" ;# path in XML to this number 28 30 } … … 38 40 # CONSTRUCTOR 39 41 # ---------------------------------------------------------------------- 40 itcl::body Rappture::ChoiceEntry::constructor { xmlobjpath args} {41 if { ![Rappture::library isvalid $xmlobj]} {42 error "bad value \"$xmlobj\": should be Rappture::library"43 } 44 set _ xmlobj $xmlobj42 itcl::body Rappture::ChoiceEntry::constructor {owner path args} { 43 if {[catch {$owner isa Rappture::ControlOwner} valid] != 0 || !$valid} { 44 error "bad object \"$owner\": should be Rappture::ControlOwner" 45 } 46 set _owner $owner 45 47 set _path $path 46 48 … … 57 59 eval itk_initialize $args 58 60 59 # 60 # Plug in the various choices for this widget. 61 # 62 # plug in the various options for the choice 63 set max 10 64 foreach cname [$xmlobj children -type option $path] { 65 set str [string trim [$xmlobj get $path.$cname.label]] 66 if {"" != $str} { 67 $itk_component(choice) choices insert end $path.$cname $str 68 set len [string length $str] 69 if {$len > $max} { set max $len } 70 } 71 } 72 $itk_component(choice) configure -width $max 73 74 # 75 # Assign the default value to this widget, if there is one. 76 # 77 set str [$xmlobj get $path.default] 78 if {"" != $str != ""} { $itk_component(choice) value $str } 61 _rebuild 62 } 63 64 # ---------------------------------------------------------------------- 65 # DESTRUCTOR 66 # ---------------------------------------------------------------------- 67 itcl::body Rappture::ChoiceEntry::destructor {} { 68 $_owner notify remove $this 79 69 } 80 70 … … 122 112 # ---------------------------------------------------------------------- 123 113 itcl::body Rappture::ChoiceEntry::label {} { 124 set label [$_ xmlobjget $_path.about.label]114 set label [$_owner xml get $_path.about.label] 125 115 if {"" == $label} { 126 116 set label "Number" … … 143 133 144 134 # ---------------------------------------------------------------------- 135 # USAGE: _rebuild 136 # 137 # Used internally to rebuild the contents of this choice widget 138 # whenever something that it depends on changes. Scans through the 139 # information in the XML spec and builds a list of choices for the 140 # widget. 141 # ---------------------------------------------------------------------- 142 itcl::body Rappture::ChoiceEntry::_rebuild {} { 143 # get rid of any existing choices 144 $itk_component(choice) choices delete 0 end 145 146 # 147 # Plug in the various options for the choice. 148 # 149 set max 10 150 foreach cname [$_owner xml children -type option $_path] { 151 set path [string trim [$_owner xml get $_path.$cname.path]] 152 if {"" != $path} { 153 # look for the input element controlling this path 154 set found 0 155 foreach cntl [Rappture::entities [$_owner xml object] "input"] { 156 set len [string length $cntl] 157 if {[string equal -length $len $cntl $path]} { 158 set found 1 159 break 160 } 161 } 162 if {$found} { 163 # 164 # Choice comes from a list of matching entities at 165 # a particular XML path. Use the <label> as a template 166 # for each item on the path. 167 # 168 $_owner notify add $this $cntl [itcl::code $this _rebuild] 169 170 set label [string trim [$_owner xml get $_path.$cname.about.label]] 171 if {"" == $label} { 172 set label "%type #%n" 173 } 174 175 set ppath [Rappture::LibraryObj::path2list $path] 176 set leading [join [lrange $ppath 0 end-1] .] 177 set tail [lindex $ppath end] 178 set n 1 179 foreach ccname [$_owner xml children $leading] { 180 if {[string match $tail $ccname]} { 181 set subst(%n) $n 182 set subst(%type) [$_owner xml element -as type $leading.$ccname] 183 set subst(%id) [$_owner xml element -as id $leading.$ccname] 184 foreach detail [$_owner xml children $leading.$ccname] { 185 set subst(%$detail) [$_owner xml get $leading.$ccname.$detail] 186 } 187 set str [string map [array get subst] $label] 188 $itk_component(choice) choices insert end \ 189 $leading.$ccname $str 190 incr n 191 } 192 } 193 $itk_component(choice) value "" 194 } else { 195 puts "can't find controlling entity for path \"$path\"" 196 } 197 } else { 198 # 199 # Choice is an ordinary LABEL. 200 # Add the label as-is into the list of choices. 201 # 202 set str [string trim [$_owner xml get $_path.$cname.about.label]] 203 if {"" != $str} { 204 $itk_component(choice) choices insert end $_path.$cname $str 205 set len [string length $str] 206 if {$len > $max} { set max $len } 207 } 208 } 209 } 210 $itk_component(choice) configure -width $max 211 212 # 213 # Assign the default value to this widget, if there is one. 214 # 215 set str [$_owner xml get $_path.default] 216 if {"" != $str} { $itk_component(choice) value $str } 217 } 218 219 # ---------------------------------------------------------------------- 145 220 # USAGE: _newValue 146 221 # … … 160 235 # ---------------------------------------------------------------------- 161 236 itcl::body Rappture::ChoiceEntry::_tooltip {} { 162 set tip [string trim [$_ xmlobjget $_path.about.description]]237 set tip [string trim [$_owner xml get $_path.about.description]] 163 238 164 239 # get the description for the current choice, if there is one … … 170 245 171 246 if {$path != ""} { 172 set desc [$_ xmlobjget $path.description]247 set desc [$_owner xml get $path.description] 173 248 if {[string length $desc] > 0} { 174 249 append tip "\n$desc" -
trunk/gui/scripts/controls.tcl
r13 r22 23 23 constructor {owner args} { # defined below } 24 24 25 public method insert {pos xmlobjpath}25 public method insert {pos path} 26 26 public method delete {first {last ""}} 27 27 public method index {name} … … 56 56 57 57 # ---------------------------------------------------------------------- 58 # USAGE: insert <pos> < xmlobj> <path>58 # USAGE: insert <pos> <path> 59 59 # 60 60 # Clients use this to insert a control into this panel. The control 61 61 # is inserted into the list at position <pos>, which can be an integer 62 62 # starting from 0 or the keyword "end". Information about the control 63 # is taken from the <xmlobj> object at thespecified <path>.63 # is taken from the specified <path>. 64 64 # 65 65 # Returns a name that can be used to identify the control in other 66 66 # methods. 67 67 # ---------------------------------------------------------------------- 68 itcl::body Rappture::Controls::insert {pos xmlobjpath} {68 itcl::body Rappture::Controls::insert {pos path} { 69 69 if {"end" == $pos} { 70 70 set pos [llength $_controls] … … 76 76 set name "control$_counter" 77 77 78 set _name2info($name-xmlobj) $xmlobj79 78 set _name2info($name-path) $path 80 79 set _name2info($name-label) "" 81 80 set _name2info($name-value) [set w $itk_interior.v$name] 82 81 83 set type [$ xmlobjelement -as type $path]82 set type [$_owner xml element -as type $path] 84 83 switch -- $type { 85 84 choice { 86 Rappture::ChoiceEntry $w $ xmlobj$path85 Rappture::ChoiceEntry $w $_owner $path 87 86 bind $w <<Value>> [itcl::code $this _controlChanged $path] 88 87 } 89 88 group { 90 Rappture::GroupEntry $w $ xmlobj$path89 Rappture::GroupEntry $w $_owner $path 91 90 } 92 91 loader { 93 Rappture::Loader $w $ xmlobj$path -tool [$_owner tool]92 Rappture::Loader $w $_owner $path -tool [$_owner tool] 94 93 bind $w <<Value>> [itcl::code $this _controlChanged $path] 95 94 } 96 95 number { 97 Rappture::NumberEntry $w $xmlobj $path 96 Rappture::NumberEntry $w $_owner $path 97 bind $w <<Value>> [itcl::code $this _controlChanged $path] 98 } 99 integer { 100 Rappture::IntegerEntry $w $_owner $path 98 101 bind $w <<Value>> [itcl::code $this _controlChanged $path] 99 102 } 100 103 boolean { 101 Rappture::BooleanEntry $w $ xmlobj$path104 Rappture::BooleanEntry $w $_owner $path 102 105 bind $w <<Value>> [itcl::code $this _controlChanged $path] 103 106 } 104 107 string { 105 Rappture::TextEntry $w $xmlobj $path 106 bind $w <<Value>> [itcl::code $this _controlChanged $path] 108 Rappture::TextEntry $w $_owner $path 109 bind $w <<Value>> [itcl::code $this _controlChanged $path] 110 } 111 control { 112 set label [$_owner xml get $path.label] 113 if {"" == $label} { set label "Simulate" } 114 set service [$_owner xml get $path.service] 115 button $w -text $label -command [list $service run] 107 116 } 108 117 default { … … 110 119 } 111 120 } 112 $_owner widgetfor $path $w 113 114 # make a label for this control 115 set label [$w label] 116 if {"" != $label} { 117 set _name2info($name-label) $itk_interior.l$name 118 set font [option get $itk_component(hull) labelFont Font] 119 label $_name2info($name-label) -text [_formatLabel $label] \ 120 -font $font 121 } 122 123 # register the tooltip for this control 124 set tip [$w tooltip] 125 if {"" != $tip} { 126 Rappture::Tooltip::for $w $tip 127 128 # add the tooltip to the label too, if there is one 129 if {$_name2info($name-label) != ""} { 130 Rappture::Tooltip::for $_name2info($name-label) $tip 121 122 if {$type != "control"} { 123 $_owner widgetfor $path $w 124 125 # make a label for this control 126 set label [$w label] 127 if {"" != $label} { 128 set _name2info($name-label) $itk_interior.l$name 129 set font [option get $itk_component(hull) labelFont Font] 130 label $_name2info($name-label) -text [_formatLabel $label] \ 131 -font $font 132 } 133 134 # register the tooltip for this control 135 set tip [$w tooltip] 136 if {"" != $tip} { 137 Rappture::Tooltip::for $w $tip 138 139 # add the tooltip to the label too, if there is one 140 if {$_name2info($name-label) != ""} { 141 Rappture::Tooltip::for $_name2info($name-label) $tip 142 } 131 143 } 132 144 } … … 169 181 destroy $_name2info($name-value) 170 182 } 171 unset _name2info($name-xmlobj)172 183 unset _name2info($name-path) 173 184 unset _name2info($name-label) … … 197 208 198 209 # ---------------------------------------------------------------------- 199 # USAGE: control ?-label|-value|- xmlobj|-path? ?<name>|@n?210 # USAGE: control ?-label|-value|-path? ?<name>|@n? 200 211 # 201 212 # Clients use this to get information about controls. With no args, it 202 213 # returns a list of all control names. Otherwise, it returns the frame 203 214 # associated with a control name. The -label option requests the label 204 # widget instead of the value widget. The -xmlobj option requests the 205 # XML object associated with the control, and the -path option requests 206 # the path within the XML that the control affects. 215 # widget instead of the value widget. The -path option requests the 216 # path within the XML that the control affects. 207 217 # ---------------------------------------------------------------------- 208 218 itcl::body Rappture::Controls::control {args} { … … 213 223 flag switch -value default 214 224 flag switch -label 215 flag switch -xmlobj216 225 flag switch -path 217 226 } -
trunk/gui/scripts/deviceEditor.tcl
r13 r22 15 15 option add *DeviceEditor.width 5i widgetDefault 16 16 option add *DeviceEditor.height 5i widgetDefault 17 option add *DeviceEditor.autoCleanUp yes widgetDefault 17 18 18 19 itcl::class Rappture::DeviceEditor { 19 inherit itk::Widget 20 inherit itk::Widget Rappture::ControlOwner 20 21 21 constructor {owner args} { # defined below } 22 itk_option define -autocleanup autoCleanUp AutoCleanUp 1 23 24 constructor {owner args} { 25 Rappture::ControlOwner::constructor $owner 26 } { # defined below } 22 27 23 28 public method value {args} 24 25 # used for syncing embedded widgets26 public method widgetfor {path {widget ""}}27 public method changed {path}28 public method sync {}29 public method tool {}30 29 31 30 protected method _redraw {} 32 31 protected method _type {xmlobj} 33 32 34 private variable _owner "" ;# owner containing this editor 35 private variable _xmlobj "" ;# XML <structure> object 36 private variable _path2widget ;# maps path => widget in this editor 33 private variable _current "" ;# active device editor 37 34 } 38 35 … … 44 41 # ---------------------------------------------------------------------- 45 42 itcl::body Rappture::DeviceEditor::constructor {owner args} { 46 set _owner $owner47 48 43 itk_option add hull.width hull.height 49 44 pack propagate $itk_component(hull) no … … 81 76 82 77 if {[llength $args] == 1} { 83 # delete any existing object84 78 if {$_xmlobj != ""} { 85 itcl::delete object $_xmlobj 79 if {$itk_option(-autocleanup)} { 80 # delete any existing object 81 itcl::delete object $_xmlobj 82 } 86 83 set _xmlobj "" 87 84 } 85 88 86 set newval [lindex $args 0] 89 87 if {$newval != ""} { … … 108 106 109 107 # ---------------------------------------------------------------------- 110 # USAGE: widgetfor <path> ?<widget>?111 #112 # Used by embedded widgets such as a Controls panel to register the113 # various controls associated with this page. That way, this editor114 # knows what widgets to look at when syncing itself to the underlying115 # XML data.116 # ----------------------------------------------------------------------117 itcl::body Rappture::DeviceEditor::widgetfor {path {widget ""}} {118 # if this is a query operation, then look for the path119 if {"" == $widget} {120 if {[info exists _path2widget($path)]} {121 return $_path2widget($path)122 }123 return ""124 }125 126 # otherwise, associate the path with the given widget127 if {[info exists _path2widget($path)]} {128 error "$path already associated with widget $_path2widget($path)"129 }130 set _path2widget($path) $widget131 }132 133 # ----------------------------------------------------------------------134 # USAGE: changed <path>135 #136 # Invoked automatically by the various widgets associated with this137 # editor whenever their value changes. If this tool has a -analyzer,138 # then it is notified that input has changed, so it can reset itself139 # for a new analysis.140 # ----------------------------------------------------------------------141 itcl::body Rappture::DeviceEditor::changed {path} {142 if {"" != $_owner} {143 $_owner changed $path144 }145 }146 147 # ----------------------------------------------------------------------148 # USAGE: sync149 #150 # Used by descendents such as a Controls panel to register the151 # various controls associated with this page. That way, this Tool152 # knows what widgets to look at when syncing itself to the underlying153 # XML data.154 # ----------------------------------------------------------------------155 itcl::body Rappture::DeviceEditor::sync {} {156 foreach path [array names _path2widget] {157 $_xmlobj put $path.current [$_path2widget($path) value]158 }159 }160 161 # ----------------------------------------------------------------------162 # USAGE: tool163 #164 # Clients use this to figure out which tool is associated with165 # this object. Returns the tool containing this editor.166 # ----------------------------------------------------------------------167 itcl::body Rappture::Tool::tool {} {168 return [$_owner tool]169 }170 171 # ----------------------------------------------------------------------172 108 # USAGE: _redraw 173 109 # … … 178 114 # ---------------------------------------------------------------------- 179 115 itcl::body Rappture::DeviceEditor::_redraw {} { 116 if {$_current != ""} { 117 $_current configure -device "" 118 set _current "" 119 } 180 120 switch -- [_type $_xmlobj] { 181 121 molecule { … … 187 127 $p.mol configure -device $_xmlobj 188 128 $itk_component(editors) current molecule 129 130 set _current $p.mol 189 131 } 190 132 device1D { … … 196 138 $p.dev configure -device $_xmlobj 197 139 $itk_component(editors) current device1D 140 141 set _current $p.dev 198 142 } 199 143 } -
trunk/gui/scripts/deviceViewer1D.tcl
r18 r22 27 27 itk_option define -device device Device "" 28 28 29 constructor { toolargs} { # defined below }29 constructor {owner args} { # defined below } 30 30 destructor { # defined below } 31 31 … … 42 42 protected method _controlSet {widget libObj path} 43 43 44 private variable _ tool "" ;# tool controlling this viewer44 private variable _owner "" ;# thing managing this control 45 45 private variable _device "" ;# XML library with <structure> 46 46 private variable _tab2fields ;# maps tab name => list of fields … … 57 57 # CONSTRUCTOR 58 58 # ---------------------------------------------------------------------- 59 itcl::body Rappture::DeviceViewer1D::constructor { toolargs} {60 set _ tool $tool59 itcl::body Rappture::DeviceViewer1D::constructor {owner args} { 60 set _owner $owner 61 61 62 62 itk_option add hull.width hull.height … … 271 271 set t $itk_component(top) 272 272 if {![winfo exists $t.cntls]} { 273 Rappture::Controls $t.cntls $_ tool273 Rappture::Controls $t.cntls $_owner 274 274 pack $t.cntls -expand yes -fill both 275 275 } 276 $t.cntls insert end $_deviceparameters.$cname276 $t.cntls insert end parameters.$cname 277 277 } 278 278 } … … 591 591 592 592 $_marker(fobj) controls put $_marker(path) $value 593 $_ toolchanged $_marker(path)593 $_owner changed $_marker(path) 594 594 event generate $itk_component(hull) <<Edit>> 595 595 -
trunk/gui/scripts/gauge.tcl
r17 r22 15 15 package require BLT 16 16 17 option add *Gauge. width 30 widgetDefault18 option add *Gauge. height 20 widgetDefault17 option add *Gauge.sampleWidth 30 widgetDefault 18 option add *Gauge.sampleHeight 20 widgetDefault 19 19 option add *Gauge.valuePosition "right" widgetDefault 20 20 option add *Gauge.textBackground #cccccc widgetDefault … … 26 26 itk_option define -editable editable Editable "" 27 27 itk_option define -spectrum spectrum Spectrum "" 28 itk_option define -type type Type "real" 28 29 itk_option define -units units Units "" 29 30 itk_option define -minvalue minValue MinValue "" … … 32 33 itk_option define -valueposition valuePosition ValuePosition "" 33 34 itk_option define -image image Image "" 34 itk_option define - width widthWidth 035 itk_option define - height heightHeight 035 itk_option define -samplewidth sampleWidth SampleWidth 0 36 itk_option define -sampleheight sampleHeight SampleHeight 0 36 37 37 38 constructor {args} { # defined below } … … 39 40 public method value {args} 40 41 public method edit {option} 42 public method bump {delta} 41 43 42 44 protected method _redraw {} … … 45 47 protected method _editor {option args} 46 48 protected method _presets {option} 49 protected method _layout {} 47 50 48 51 private variable _value 0 ;# value for this widget 52 53 blt::bitmap define GaugeArrow-up { 54 #define up_width 8 55 #define up_height 4 56 static unsigned char up_bits[] = { 57 0x10, 0x38, 0x7c, 0xfe}; 58 } 59 blt::bitmap define GaugeArrow-down { 60 #define arrow_width 8 61 #define arrow_height 4 62 static unsigned char arrow_bits[] = { 63 0xfe, 0x7c, 0x38, 0x10}; 64 } 49 65 50 66 blt::bitmap define GaugeArrow { … … 117 133 bind $itk_component(value) <ButtonPress> \ 118 134 [itcl::code $this _editor popup] 135 136 137 itk_component add spinner { 138 frame $itk_component(vframe).spinner 139 } 140 141 itk_component add spinup { 142 button $itk_component(spinner).up -bitmap GaugeArrow-up \ 143 -borderwidth 1 -relief raised -highlightthickness 0 \ 144 -command [itcl::code $this bump 1] 145 } { 146 usual 147 ignore -borderwidth -highlightthickness 148 } 149 pack $itk_component(spinup) -side top -expand yes -fill both 150 151 itk_component add spindn { 152 button $itk_component(spinner).down -bitmap GaugeArrow-down \ 153 -borderwidth 1 -relief raised -highlightthickness 0 \ 154 -command [itcl::code $this bump -1] 155 } { 156 usual 157 ignore -borderwidth -highlightthickness 158 } 159 pack $itk_component(spindn) -side bottom -expand yes -fill both 160 119 161 120 162 itk_component add presets { … … 199 241 } 200 242 201 if {![string is double -strict $nv]} { 202 error "Should be a real number" 243 switch -- $itk_option(-type) { 244 integer { 245 if {![string is integer -strict $nv]} { 246 error "Should be an integer value" 247 } 248 } 249 real { 250 if {![string is double -strict $nv]} { 251 error "Should be a real number" 252 } 253 } 203 254 } 204 255 … … 249 300 250 301 # ---------------------------------------------------------------------- 302 # USAGE: bump <delta> 303 # 304 # Changes the current value up/down by the <delta> value. Used 305 # internally by the up/down spinner buttons when the value is 306 # -type integer. 307 # ---------------------------------------------------------------------- 308 itcl::body Rappture::Gauge::bump {delta} { 309 set val $_value 310 if {$val == ""} { 311 set val 0 312 } 313 value [expr {$val+$delta}] 314 } 315 316 # ---------------------------------------------------------------------- 251 317 # USAGE: _redraw 252 318 # … … 287 353 # ---------------------------------------------------------------------- 288 354 itcl::body Rappture::Gauge::_resize {} { 289 if {$itk_option(-width) > 0} { 290 set w $itk_option(-width) 291 } else { 292 if {$itk_option(-image) != ""} { 293 set w [expr {[image width $itk_option(-image)]+4}] 355 set w 0 356 set h 0 357 358 if {"" != $itk_option(-image) || "" != $itk_option(-spectrum)} { 359 if {$itk_option(-samplewidth) > 0} { 360 set w $itk_option(-samplewidth) 294 361 } else { 295 set w [winfo reqheight $itk_component(value)]296 }297 }298 299 if {$itk_option(-height) > 0} {300 set h $itk_option(-height)301 } else { 302 if {$itk_option(- image) != ""} {303 set h [expr {[image height $itk_option(-image)]+4}]362 if {$itk_option(-image) != ""} { 363 set w [expr {[image width $itk_option(-image)]+4}] 364 } else { 365 set w [winfo reqheight $itk_component(value)] 366 } 367 } 368 369 if {$itk_option(-sampleheight) > 0} { 370 set h $itk_option(-sampleheight) 304 371 } else { 305 set h [winfo reqheight $itk_component(value)] 306 } 307 } 308 309 $itk_component(icon) configure -width $w -height $h 372 if {$itk_option(-image) != ""} { 373 set h [expr {[image height $itk_option(-image)]+4}] 374 } else { 375 set h [winfo reqheight $itk_component(value)] 376 } 377 } 378 } 379 380 if {$w > 0 && $h > 0} { 381 $itk_component(icon) configure -width $w -height $h 382 } 310 383 } 311 384 … … 420 493 421 494 # ---------------------------------------------------------------------- 495 # USAGE: _layout 496 # 497 # Used internally to fix the layout of widgets whenever there is a 498 # change in the options that affect layout. Puts the value in the 499 # proper position according to the -valueposition option. Also, 500 # adds or removes the icon if it needs to be shown. 501 # ---------------------------------------------------------------------- 502 itcl::body Rappture::Gauge::_layout {} { 503 foreach w [pack slaves $itk_component(hull)] { 504 pack forget $w 505 } 506 507 array set side2anchor { 508 left e 509 right w 510 top s 511 bottom n 512 } 513 set pos $itk_option(-valueposition) 514 pack $itk_component(vframe) -side $pos \ 515 -expand yes -fill both -ipadx 2 516 $itk_component(value) configure -anchor $side2anchor($pos) 517 518 if {"" != $itk_option(-image) || "" != $itk_option(-spectrum)} { 519 pack $itk_component(icon) -side $pos 520 } 521 } 522 523 # ---------------------------------------------------------------------- 422 524 # CONFIGURATION OPTION: -editable 423 525 # ---------------------------------------------------------------------- … … 440 542 error "bad option \"$itk_option(-spectrum)\": should be Rappture::Spectrum object" 441 543 } 544 _layout 442 545 _redraw 443 546 } … … 452 555 } 453 556 _resize 557 _layout 454 558 $itk_component(icon) itemconfigure bimage -image $itk_option(-image) 455 559 } … … 469 573 # ---------------------------------------------------------------------- 470 574 itcl::configbody Rappture::Gauge::valueposition { 471 array set side2anchor {472 left e473 right w474 top s475 bottom n476 }477 575 set pos $itk_option(-valueposition) 478 if {![info exists side2anchor($pos)]} { 479 error "bad value \"$pos\": should be [join [lsort [array names side2anchor]] {, }]" 480 } 481 pack $itk_component(vframe) -before $itk_component(icon) \ 482 -side $pos -expand yes -fill both -ipadx 2 483 $itk_component(value) configure -anchor $side2anchor($pos) 576 set opts {left right top bottom} 577 if {[lsearch -exact $opts $pos] < 0} { 578 error "bad value \"$pos\": should be [join $opts {, }]" 579 } 580 _layout 484 581 } 485 582 … … 496 593 set s "right" 497 594 } 498 pack $itk_component(presets) -before $itk_component(value) \499 595 set first [lindex [pack slaves $itk_component(vframe)] 0] 596 pack $itk_component(presets) -before $first -side $s -fill y 500 597 501 598 $itk_component(presetlist) delete 0 end … … 503 600 } 504 601 } 602 603 # ---------------------------------------------------------------------- 604 # CONFIGURATION OPTION: -type 605 # ---------------------------------------------------------------------- 606 itcl::configbody Rappture::Gauge::type { 607 switch -- $itk_option(-type) { 608 integer { 609 set first [lindex [pack slaves $itk_component(vframe)] 0] 610 if {$first == $itk_component(presets)} { 611 pack $itk_component(spinner) -after $first -side left -fill y 612 } else { 613 pack $itk_component(spinner) -before $first -side right -fill y 614 } 615 } 616 real { 617 pack forget $itk_component(spinner) 618 } 619 default { 620 error "bad number type \"$itk_option(-type)\": should be integer or real" 621 } 622 } 623 } -
trunk/gui/scripts/groupentry.tcl
r11 r22 15 15 inherit itk::Widget 16 16 17 constructor { xmlobjpath args} { # defined below }17 constructor {owner path args} { # defined below } 18 18 19 19 public method value {args} … … 22 22 public method tooltip {} 23 23 24 private variable _ xmlobj "" ;# XML containing description24 private variable _owner "" ;# thing managing this control 25 25 private variable _path "" ;# path in XML to this number 26 26 } … … 36 36 # CONSTRUCTOR 37 37 # ---------------------------------------------------------------------- 38 itcl::body Rappture::GroupEntry::constructor { xmlobjpath args} {39 if { ![Rappture::library isvalid $xmlobj]} {40 error "bad value \"$xmlobj\": should be Rappture::library"38 itcl::body Rappture::GroupEntry::constructor {owner path args} { 39 if {[catch {$owner isa Rappture::ControlOwner} valid] != 0 || !$valid} { 40 error "bad object \"$owner\": should be Rappture::ControlOwner" 41 41 } 42 set _ xmlobj $xmlobj42 set _owner $owner 43 43 set _path $path 44 44 … … 67 67 # ---------------------------------------------------------------------- 68 68 itcl::body Rappture::GroupEntry::label {} { 69 return [$_ xmlobjget $_path.about.label]69 return [$_owner xml get $_path.about.label] 70 70 } 71 71 … … 79 79 # ---------------------------------------------------------------------- 80 80 itcl::body Rappture::GroupEntry::tooltip {} { 81 return [$_ xmlobjget $_path.about.description]81 return [$_owner xml get $_path.about.description] 82 82 } -
trunk/gui/scripts/loader.tcl
r17 r22 19 19 itk_option define -tool tool Tool "" 20 20 21 constructor { xmlobjpath args} { # defined below }21 constructor {owner path args} { # defined below } 22 22 23 23 public method value {args} … … 29 29 protected method _tooltip {} 30 30 31 private variable _ xmlobj "" ;# XML containing description31 private variable _owner "" ;# thing managing this control 32 32 private variable _path "" ;# path in XML to this loader 33 33 } … … 43 43 # CONSTRUCTOR 44 44 # ---------------------------------------------------------------------- 45 itcl::body Rappture::Loader::constructor { xmlobjpath args} {46 if { ![Rappture::library isvalid $xmlobj]} {47 error "bad value \"$xmlobj\": should be Rappture::library"48 } 49 set _ xmlobj $xmlobj45 itcl::body Rappture::Loader::constructor {owner path args} { 46 if {[catch {$owner isa Rappture::ControlOwner} valid] != 0 || !$valid} { 47 error "bad object \"$owner\": should be Rappture::ControlOwner" 48 } 49 set _owner $owner 50 50 set _path $path 51 51 … … 65 65 # the combobox. 66 66 # 67 set defval [$ xmlobjget $path.default]67 set defval [$_owner xml get $path.default] 68 68 69 69 set flist "" 70 foreach comp [$ xmlobjchildren -type example $path] {71 lappend flist [$ xmlobjget $path.$comp]70 foreach comp [$_owner xml children -type example $path] { 71 lappend flist [$_owner xml get $path.$comp] 72 72 } 73 73 … … 103 103 104 104 if {[string equal $defval [file tail $fname]]} { 105 $ xmlobjput $path.default $label105 $_owner xml put $path.default $label 106 106 } 107 107 } … … 116 116 # Assign the default value to this widget, if there is one. 117 117 # 118 set str [$ xmlobjget $path.default]118 set str [$_owner xml get $path.default] 119 119 if {$str != ""} { after 500 [itcl::code $this value $str] } 120 120 } … … 163 163 # ---------------------------------------------------------------------- 164 164 itcl::body Rappture::Loader::label {} { 165 set label [$_ xmlobjget $_path.about.label]165 set label [$_owner xml get $_path.about.label] 166 166 if {"" == $label} { 167 167 set label "Example" … … 208 208 # ---------------------------------------------------------------------- 209 209 itcl::body Rappture::Loader::_tooltip {} { 210 set str [string trim [$_ xmlobjget $_path.about.description]]210 set str [string trim [$_owner xml get $_path.about.description]] 211 211 212 212 # get the description for the current choice, if there is one -
trunk/gui/scripts/moleculeViewer.tcl
r11 r22 13 13 package require vtk 14 14 package require vtkinteraction 15 package require BLT 15 16 16 17 option add *MoleculeViewer.width 4i widgetDefault … … 18 19 option add *MoleculeViewer.backdrop black widgetDefault 19 20 21 blt::bitmap define MoleculeViewer-reset { 22 #define reset_width 12 23 #define reset_height 12 24 static unsigned char reset_bits[] = { 25 0x00, 0x00, 0x00, 0x00, 0xfc, 0x03, 0x04, 0x02, 0x04, 0x02, 0x04, 0x02, 26 0x04, 0x02, 0x04, 0x02, 0x04, 0x02, 0xfc, 0x03, 0x00, 0x00, 0x00, 0x00}; 27 } 28 29 blt::bitmap define MoleculeViewer-zoomin { 30 #define zoomin_width 12 31 #define zoomin_height 12 32 static unsigned char zoomin_bits[] = { 33 0x7c, 0x00, 0x82, 0x00, 0x11, 0x01, 0x11, 0x01, 0x7d, 0x01, 0x11, 0x01, 34 0x11, 0x01, 0x82, 0x03, 0xfc, 0x07, 0x80, 0x0f, 0x00, 0x0f, 0x00, 0x06}; 35 } 36 37 blt::bitmap define MoleculeViewer-zoomout { 38 #define zoomout_width 12 39 #define zoomout_height 12 40 static unsigned char zoomout_bits[] = { 41 0x7c, 0x00, 0x82, 0x00, 0x01, 0x01, 0x01, 0x01, 0x7d, 0x01, 0x01, 0x01, 42 0x01, 0x01, 0x82, 0x03, 0xfc, 0x07, 0x80, 0x0f, 0x00, 0x0f, 0x00, 0x06}; 43 } 44 45 blt::bitmap define MoleculeViewer-atoms { 46 #define atoms_width 12 47 #define atoms_height 12 48 static unsigned char atoms_bits[] = { 49 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x02, 0x4c, 0x02, 0xc8, 0x03, 50 0x48, 0x02, 0x48, 0x02, 0x5c, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 51 } 52 20 53 itcl::class Rappture::MoleculeViewer { 21 54 inherit itk::Widget … … 28 61 29 62 protected method _render {} 63 protected method _zoom {option} 64 protected method _move {option x y} 65 protected method _3dView {theta phi} 66 protected method _fixLabels {{option position}} 30 67 protected method _color2rgb {color} 31 68 32 69 private variable _tool "" ;# tool containing this viewer 33 70 private variable _actors "" ;# list of actors in renderer 71 private variable _label2atom ;# maps 2D text actor => underlying atom 72 private variable _view ;# view params for 3D view 73 private variable _limits ;# limits of x/y/z axes 74 private variable _click ;# info used for _move operations 34 75 } 35 76 … … 61 102 $this-map SetInput [$this-sphere GetOutput] 62 103 104 vtkCoordinate $this-xyzconv 105 $this-xyzconv SetCoordinateSystemToWorld 106 107 set _view(theta) 0 108 set _view(phi) 0 109 110 itk_component add controls { 111 frame $itk_interior.cntls 112 } { 113 usual 114 rename -background -controlbackground controlBackground Background 115 } 116 pack $itk_component(controls) -side right -fill y 117 118 itk_component add reset { 119 button $itk_component(controls).reset \ 120 -borderwidth 1 -padx 1 -pady 1 \ 121 -bitmap MoleculeViewer-reset \ 122 -command [itcl::code $this _zoom reset] 123 } { 124 usual 125 ignore -borderwidth 126 rename -highlightbackground -controlbackground controlBackground Background 127 } 128 pack $itk_component(reset) -padx 4 -pady 4 129 Rappture::Tooltip::for $itk_component(reset) "Reset the view to the default zoom level" 130 131 itk_component add zoomin { 132 button $itk_component(controls).zin \ 133 -borderwidth 1 -padx 1 -pady 1 \ 134 -bitmap MoleculeViewer-zoomin \ 135 -command [itcl::code $this _zoom in] 136 } { 137 usual 138 ignore -borderwidth 139 rename -highlightbackground -controlbackground controlBackground Background 140 } 141 pack $itk_component(zoomin) -padx 4 -pady 4 142 Rappture::Tooltip::for $itk_component(zoomin) "Zoom in" 143 144 itk_component add zoomout { 145 button $itk_component(controls).zout \ 146 -borderwidth 1 -padx 1 -pady 1 \ 147 -bitmap MoleculeViewer-zoomout \ 148 -command [itcl::code $this _zoom out] 149 } { 150 usual 151 ignore -borderwidth 152 rename -highlightbackground -controlbackground controlBackground Background 153 } 154 pack $itk_component(zoomout) -padx 4 -pady 4 155 Rappture::Tooltip::for $itk_component(zoomout) "Zoom out" 156 157 itk_component add labels { 158 label $itk_component(controls).labels \ 159 -borderwidth 1 -padx 1 -pady 1 \ 160 -bitmap MoleculeViewer-atoms 161 } { 162 usual 163 ignore -borderwidth 164 rename -highlightbackground -controlbackground controlBackground Background 165 } 166 pack $itk_component(labels) -padx 4 -pady 8 -ipadx 1 -ipady 1 167 Rappture::Tooltip::for $itk_component(labels) "Show/hide the labels on atoms" 168 bind $itk_component(labels) <ButtonPress> \ 169 [itcl::code $this _fixLabels toggle] 170 171 # 172 # RENDERING AREA 173 # 174 itk_component add area { 175 frame $itk_interior.area 176 } 177 pack $itk_component(area) -expand yes -fill both 178 bind $itk_component(area) <Configure> \ 179 [itcl::code $this _fixLabels] 180 63 181 itk_component add renderer { 64 vtkTkRenderWidget $itk_ interior.ren -rw $this-renWin182 vtkTkRenderWidget $itk_component(area).ren -rw $this-renWin 65 183 } { 66 184 } … … 68 186 69 187 eval itk_initialize $args 188 189 # prevent interactions -- use our own 190 blt::busy hold $itk_component(area) -cursor left_ptr 191 bind $itk_component(area)_Busy <ButtonPress> \ 192 [itcl::code $this _move click %x %y] 193 bind $itk_component(area)_Busy <B1-Motion> \ 194 [itcl::code $this _move drag %x %y] 195 bind $itk_component(area)_Busy <ButtonRelease> \ 196 [itcl::code $this _move release %x %y] 197 198 _fixLabels on 70 199 } 71 200 … … 79 208 rename $this-sphere "" 80 209 rename $this-map "" 210 rename $this-xyzconv "" 81 211 } 82 212 … … 93 223 } 94 224 set _actors "" 225 catch {unset _label2atom} 226 227 foreach lim {xmin xmax ymin ymax zmin zmax} { 228 set _limits($lim) "" 229 } 95 230 96 231 if {$itk_option(-device) != ""} { … … 104 239 regsub {,} $xyz {} xyz 105 240 106 set aname "::actor[incr counter]" 241 # update overall limits for molecules along all axes 242 foreach axis {x y z} val $xyz { 243 if {"" == $_limits(${axis}min)} { 244 set _limits(${axis}min) $val 245 set _limits(${axis}max) $val 246 } else { 247 if {$val < $_limits(${axis}min)} { 248 set _limits(${axis}min) $val 249 } 250 if {$val > $_limits(${axis}max)} { 251 set _limits(${axis}max) $val 252 } 253 } 254 } 255 256 # create an actor for each atom 257 set aname $this-actor[incr counter] 107 258 vtkActor $aname 108 259 $aname SetMapper $this-map … … 121 272 122 273 lappend _actors $aname 123 } 274 275 # create a label for each atom 276 set lname $this-label$counter 277 vtkTextActor $lname 278 $lname SetInput "$counter $symbol" 279 $lname ScaledTextOff 280 281 set tprop [$lname GetTextProperty] 282 $tprop SetJustificationToCentered 283 $tprop SetVerticalJustificationToCentered 284 $tprop ShadowOn 285 $tprop SetColor 1 1 1 286 287 set _label2atom($lname) $aname 288 lappend _actors $lname 289 } 290 if {[$itk_component(labels) cget -relief] == "sunken"} { 291 _fixLabels on 292 } 293 after cancel [list catch [itcl::code $this _zoom reset]] 294 after 200 [list catch [itcl::code $this _zoom reset]] 124 295 } 125 296 $this-ren ResetCamera 297 $this-renWin Render 298 } 299 300 # ---------------------------------------------------------------------- 301 # USAGE: _zoom in 302 # USAGE: _zoom out 303 # USAGE: _zoom reset 304 # 305 # Called automatically when the user clicks on one of the zoom 306 # controls for this widget. Changes the zoom for the current view. 307 # ---------------------------------------------------------------------- 308 itcl::body Rappture::MoleculeViewer::_zoom {option} { 309 switch -- $option { 310 in { 311 [$this-ren GetActiveCamera] Zoom 1.25 312 _fixLabels 313 $this-renWin Render 314 } 315 out { 316 [$this-ren GetActiveCamera] Zoom 0.8 317 _fixLabels 318 $this-renWin Render 319 } 320 reset { 321 [$this-ren GetActiveCamera] SetViewAngle 30 322 $this-ren ResetCamera 323 [$this-ren GetActiveCamera] Zoom 1.25 324 _3dView 45 45 325 $this-renWin Render 326 327 after cancel [list catch [itcl::code $this _fixLabels]] 328 after 2000 [list catch [itcl::code $this _fixLabels]] 329 } 330 } 331 } 332 333 # ---------------------------------------------------------------------- 334 # USAGE: _move click <x> <y> 335 # USAGE: _move drag <x> <y> 336 # USAGE: _move release <x> <y> 337 # 338 # Called automatically when the user clicks/drags/releases in the 339 # plot area. Moves the plot according to the user's actions. 340 # ---------------------------------------------------------------------- 341 itcl::body Rappture::MoleculeViewer::_move {option x y} { 342 switch -- $option { 343 click { 344 blt::busy configure $itk_component(area) -cursor fleur 345 set _click(x) $x 346 set _click(y) $y 347 set _click(theta) $_view(theta) 348 set _click(phi) $_view(phi) 349 } 350 drag { 351 if {[array size _click] == 0} { 352 _move click $x $y 353 } else { 354 set w [winfo width $itk_component(renderer)] 355 set h [winfo height $itk_component(renderer)] 356 set dx [expr {double($x-$_click(x))/$w}] 357 set dy [expr {double($y-$_click(y))/$h}] 358 359 # 360 # Rotate the camera in 3D 361 # 362 set theta [expr {$_view(theta) - $dy*180}] 363 if {$theta < 2} { set theta 2 } 364 if {$theta > 178} { set theta 178 } 365 set phi [expr {$_view(phi) - $dx*360}] 366 367 _3dView $theta $phi 368 _fixLabels 369 $this-renWin Render 370 371 set _click(x) $x 372 set _click(y) $y 373 } 374 } 375 release { 376 _move drag $x $y 377 blt::busy configure $itk_component(area) -cursor left_ptr 378 catch {unset _click} 379 } 380 default { 381 error "bad option \"$option\": should be click, drag, release" 382 } 383 } 384 } 385 386 # ---------------------------------------------------------------------- 387 # USAGE: _3dView <theta> <phi> 388 # 389 # Used internally to change the position of the camera for 3D data 390 # sets. Sets the camera according to the angles <theta> (angle from 391 # the z-axis) and <phi> (angle from the x-axis in the x-y plane). 392 # Both angles are in degrees. 393 # ---------------------------------------------------------------------- 394 itcl::body Rappture::MoleculeViewer::_3dView {theta phi} { 395 set deg2rad 0.0174532927778 396 set xn [expr {sin($theta*$deg2rad)*cos($phi*$deg2rad)}] 397 set yn [expr {sin($theta*$deg2rad)*sin($phi*$deg2rad)}] 398 set zn [expr {cos($theta*$deg2rad)}] 399 400 set xm [expr {0.5*($_limits(xmax)+$_limits(xmin))}] 401 set ym [expr {0.5*($_limits(ymax)+$_limits(ymin))}] 402 set zm [expr {0.5*($_limits(zmax)+$_limits(zmin))}] 403 404 set cam [$this-ren GetActiveCamera] 405 set zoom [$cam GetViewAngle] 406 $cam SetViewAngle 30 407 408 $cam SetFocalPoint $xm $ym $zm 409 $cam SetPosition [expr {$xm-$xn}] [expr {$ym-$yn}] [expr {$zm+$zn}] 410 $cam ComputeViewPlaneNormal 411 $cam SetViewUp 0 0 1 ;# z-dir is up 412 $cam OrthogonalizeViewUp 413 $this-ren ResetCamera 414 $cam SetViewAngle $zoom 415 416 # fix up the labels so they sit over the new atom positions 417 _fixLabels 418 419 set _view(theta) $theta 420 set _view(phi) $phi 421 } 422 423 # ---------------------------------------------------------------------- 424 # USAGE: _fixLabels on 425 # USAGE: _fixLabels off 426 # USAGE: _fixLabels toggle 427 # USAGE: _fixLabels position 428 # 429 # Used internally to turn labels associated with atoms on/off, and to 430 # update the positions of the labels so they sit on top of each atom. 431 # ---------------------------------------------------------------------- 432 itcl::body Rappture::MoleculeViewer::_fixLabels {{option position}} { 433 switch -- $option { 434 on { 435 set state 1 436 } 437 off { 438 set state 0 439 } 440 toggle { 441 if {[$itk_component(labels) cget -relief] == "sunken"} { 442 set state 0 443 } else { 444 set state 1 445 } 446 } 447 position { 448 foreach lname [array names _label2atom] { 449 set aname $_label2atom($lname) 450 set xyz [$aname GetPosition] 451 eval $this-xyzconv SetValue $xyz 452 set xy [$this-xyzconv GetComputedViewportValue $this-ren] 453 eval $lname SetDisplayPosition $xy 454 } 455 return 456 } 457 default { 458 error "bad option \"$option\": should be on, off, toggle, position" 459 } 460 } 461 462 if {$state} { 463 $itk_component(labels) configure -relief sunken 464 foreach lname [array names _label2atom] { 465 catch {$this-ren AddActor2D $lname} 466 } 467 _fixLabels position 468 } else { 469 $itk_component(labels) configure -relief raised 470 foreach lname [array names _label2atom] { 471 catch {$this-ren RemoveActor $lname} 472 } 473 } 126 474 $this-renWin Render 127 475 } … … 159 507 after idle [itcl::code $this _render] 160 508 } 161 162 #package require Rappture163 #Rappture::MoleculeViewer .e164 #pack .e -expand yes -fill both165 #166 #set dev [Rappture::library {<?xml version="1.0"?>167 #<structure>168 #<components>169 #<molecule id="Aspirin">170 # <formula>???</formula>171 # <info>Aspirin molecule</info>172 # <atom id="1">173 # <symbol>C</symbol>174 # <xyz>-1.892 -0.992 -1.578</xyz>175 # </atom>176 # <atom id="2">177 # <symbol>C</symbol>178 # <xyz>-1.370 -2.149 -0.990</xyz>179 # </atom>180 # <atom id="3">181 # <symbol>C</symbol>182 # <xyz>-0.079 -2.146 -0.464</xyz>183 # </atom>184 # <atom id="4">185 # <symbol>C</symbol>186 # <xyz>0.708 -0.986 -0.521</xyz>187 # </atom>188 # <atom id="5">189 # <symbol>C</symbol>190 # <xyz>0.203 0.156 -1.196</xyz>191 # </atom>192 # <atom id="6">193 # <symbol>C</symbol>194 # <xyz>-1.108 0.161 -1.654</xyz>195 # </atom>196 # <atom id="7">197 # <symbol>C</symbol>198 # <xyz>2.085 -1.030 0.104</xyz>199 # </atom>200 # <atom id="8">201 # <symbol>O</symbol>202 # <xyz>2.533 -2.034 0.636</xyz>203 # </atom>204 # <atom id="9">205 # <symbol>O</symbol>206 # <xyz>2.879 0.025 0.112</xyz>207 # </atom>208 # <atom id="10">209 # <symbol>O</symbol>210 # <xyz>0.753 1.334 -1.084</xyz>211 # </atom>212 # <atom id="11">213 # <symbol>C</symbol>214 # <xyz>0.668 2.025 0.034</xyz>215 # </atom>216 # <atom id="12">217 # <symbol>O</symbol>218 # <xyz>1.300 3.063 0.152</xyz>219 # </atom>220 # <atom id="13">221 # <symbol>C</symbol>222 # <xyz>-0.243 1.577 1.144</xyz>223 # </atom>224 # <atom id="14">225 # <symbol>H</symbol>226 # <xyz>-2.879 -0.962 -1.985</xyz>227 # </atom>228 # <atom id="15">229 # <symbol>H</symbol>230 # <xyz>-1.988 -3.037 -0.955</xyz>231 # </atom>232 # <atom id="16">233 # <symbol>H</symbol>234 # <xyz>0.300 -3.063 -0.005</xyz>235 # </atom>236 # <atom id="17">237 # <symbol>H</symbol>238 # <xyz>-1.489 1.084 -2.059</xyz>239 # </atom>240 # <atom id="18">241 # <symbol>H</symbol>242 # <xyz>2.566 0.782 -0.326</xyz>243 # </atom>244 # <atom id="19">245 # <symbol>H</symbol>246 # <xyz>-0.761 0.636 0.933</xyz>247 # </atom>248 # <atom id="20">249 # <symbol>H</symbol>250 # <xyz>-1.009 2.349 1.290</xyz>251 # </atom>252 # <atom id="21">253 # <symbol>H</symbol>254 # <xyz>0.346 1.435 2.059</xyz>255 # </atom>256 #</molecule>257 #</components>258 #</structure>}]259 # add connectivity at some point...260 #CONECT 1 2 6 14261 #CONECT 2 1 3 15262 #CONECT 3 2 4 16263 #CONECT 4 3 5 7264 #CONECT 5 4 6 10265 #CONECT 6 1 5 17266 #CONECT 7 4 8 9267 #CONECT 8 7268 #CONECT 9 7 18269 #CONECT 10 5 11270 #CONECT 11 10 12 13271 #CONECT 12 11272 #CONECT 13 11 19 20 21273 #CONECT 14 1274 #CONECT 15 2275 #CONECT 16 3276 #CONECT 17 6277 #CONECT 18 9278 #CONECT 19 13279 #CONECT 20 13280 #CONECT 21 13281 282 #.e configure -device $dev -
trunk/gui/scripts/numberentry.tcl
r11 r22 14 14 inherit itk::Widget 15 15 16 constructor { xmlobjpath args} { # defined below }16 constructor {owner path args} { # defined below } 17 17 18 18 public method value {args} … … 23 23 protected method _newValue {} 24 24 25 private variable _ xmlobj "" ;# XML containing description25 private variable _owner "" ;# thing managing this control 26 26 private variable _path "" ;# path in XML to this number 27 27 } … … 37 37 # CONSTRUCTOR 38 38 # ---------------------------------------------------------------------- 39 itcl::body Rappture::NumberEntry::constructor { xmlobjpath args} {40 if { ![Rappture::library isvalid $xmlobj]} {41 error "bad value \"$xmlobj\": should be Rappture::library"42 } 43 set _ xmlobj $xmlobj39 itcl::body Rappture::NumberEntry::constructor {owner path args} { 40 if {[catch {$owner isa Rappture::ControlOwner} valid] != 0 || !$valid} { 41 error "bad object \"$owner\": should be Rappture::ControlOwner" 42 } 43 set _owner $owner 44 44 set _path $path 45 45 … … 48 48 # 49 49 set presets "" 50 foreach pre [$ xmlobjchildren -type preset $path] {50 foreach pre [$_owner xml children -type preset $path] { 51 51 lappend presets \ 52 [$ xmlobjget $path.$pre.value] \53 [$ xmlobjget $path.$pre.label]52 [$_owner xml get $path.$pre.value] \ 53 [$_owner xml get $path.$pre.label] 54 54 } 55 55 56 56 set class Rappture::Gauge 57 set units [$ xmlobjget $path.units]57 set units [$_owner xml get $path.units] 58 58 if {$units != ""} { 59 59 set desc [Rappture::Units::description $units] … … 73 73 bind $itk_component(gauge) <<Value>> [itcl::code $this _newValue] 74 74 75 set min [$ xmlobjget $path.min]75 set min [$_owner xml get $path.min] 76 76 if {"" != $min} { $itk_component(gauge) configure -minvalue $min } 77 77 78 set max [$ xmlobjget $path.max]78 set max [$_owner xml get $path.max] 79 79 if {"" != $max} { $itk_component(gauge) configure -maxvalue $max } 80 80 81 81 if {$class == "Rappture::Gauge" && "" != $min && "" != $max} { 82 set color [$ xmlobjget $path.color]82 set color [$_owner xml get $path.color] 83 83 if {$color == ""} { 84 84 set color blue … … 94 94 95 95 # if the control has an icon, plug it in 96 set str [$ xmlobjget $path.about.icon]96 set str [$_owner xml get $path.about.icon] 97 97 if {$str != ""} { 98 98 $itk_component(gauge) configure -image [image create photo -data $str] … … 104 104 # Assign the default value to this widget, if there is one. 105 105 # 106 set str [$ xmlobjget $path.default]106 set str [$_owner xml get $path.default] 107 107 if {"" != $str != ""} { $itk_component(gauge) value $str } 108 108 } … … 151 151 # ---------------------------------------------------------------------- 152 152 itcl::body Rappture::NumberEntry::label {} { 153 set label [$_ xmlobjget $_path.about.label]153 set label [$_owner xml get $_path.about.label] 154 154 if {"" == $label} { 155 155 set label "Number" … … 167 167 # ---------------------------------------------------------------------- 168 168 itcl::body Rappture::NumberEntry::tooltip {} { 169 set str [$_ xmlobjget $_path.about.description]170 171 set units [$_ xmlobjget $_path.units]172 set min [$_ xmlobjget $_path.min]173 set max [$_ xmlobjget $_path.max]169 set str [$_owner xml get $_path.about.description] 170 171 set units [$_owner xml get $_path.units] 172 set min [$_owner xml get $_path.min] 173 set max [$_owner xml get $_path.max] 174 174 175 175 if {$units != "" || $min != "" || $max != ""} { -
trunk/gui/scripts/page.tcl
r11 r22 17 17 inherit itk::Widget 18 18 19 constructor { toolpath args} { # defined below }19 constructor {owner path args} { # defined below } 20 20 21 21 protected method _buildGroup {frame xmlobj path} 22 23 private variable _tool "" ;# tool controlling this page 22 protected method _link {xmlobj path widget path2} 23 24 private variable _owner "" ;# thing managing this page 24 25 } 25 26 … … 30 31 # CONSTRUCTOR 31 32 # ---------------------------------------------------------------------- 32 itcl::body Rappture::Page::constructor { toolpath args} {33 if {[catch {$ tool isa Rappture::Tool} valid] || !$valid} {34 error "object \"$ tool\" is not a Rappture Tool"35 } 36 set _ tool $tool37 set xmlobj [$ toolxml object]33 itcl::body Rappture::Page::constructor {owner path args} { 34 if {[catch {$owner isa Rappture::ControlOwner} valid] || !$valid} { 35 error "object \"$owner\" is not a Rappture::ControlOwner" 36 } 37 set _owner $owner 38 set xmlobj [$owner xml object] 38 39 39 40 set type [$xmlobj element -as type $path] … … 56 57 # ---------------------------------------------------------------------- 57 58 itcl::body Rappture::Page::_buildGroup {frame xmlobj path} { 59 frame $frame.results 60 pack $frame.results -side right -fill y 61 58 62 set deveditor "" 59 63 60 64 # 61 # Scan through all input elements in this group and look 62 # for a <loader>. Add those first, at the top of the group. 65 # Scan through all remaining input elements. If there is an 66 # ambient group, then add its children to the device editor, 67 # if there is one. 63 68 # 64 69 set num 0 65 foreach cname [$xmlobj children $path] { 66 if {[$xmlobj element -as type $path.$cname] == "loader"} { 70 set clist [$xmlobj children $path] 71 while {[llength $clist] > 0} { 72 set cname [lindex $clist 0] 73 set clist [lrange $clist 1 end] 74 75 set type [$xmlobj element -as type $path.$cname] 76 if {$type == "about"} { 77 continue 78 } 79 80 if {$type == "loader"} { 81 # 82 # Add <loader>'s at the top of the page. 83 # 67 84 if {![winfo exists $frame.loaders]} { 68 85 frame $frame.loaders … … 74 91 } 75 92 set w "$frame.loaders.l[incr num]" 76 Rappture::Controls $w $_ tool93 Rappture::Controls $w $_owner 77 94 pack $w -fill x 78 $w insert end $xmlobj $path.$cname 79 } 80 } 81 82 # 83 # Scan through all input elements and look for any top-level 84 # <structure> elements. Create these next. 85 # 86 set num 0 87 foreach cname [$xmlobj children $path] { 88 if {[$xmlobj element -as type $path.$cname] == "structure"} { 95 $w insert end $path.$cname 96 } elseif {$type == "structure"} { 97 # 98 # Add <structure>'s as the central element of the page. 99 # 89 100 set w "$frame.device[incr num]" 90 Rappture::DeviceEditor $w $_ tool101 Rappture::DeviceEditor $w $_owner 91 102 pack $w -expand yes -fill both 92 $_tool widgetfor $path.$cname $w 103 $_owner widgetfor $path.$cname $w 104 bind $w <<Value>> [list $_owner changed $path.$cname] 93 105 94 106 if {"" == $deveditor} { … … 101 113 if {[string length $val] > 0} { 102 114 $w value $val 115 $xmlobj put $path.$cname.current $val 103 116 } else { 104 117 set obj [$xmlobj element -as object $path.$cname.default] 105 118 $w value $obj 106 } 107 } 108 } 109 } 110 111 # 112 # Scan through all remaining input elements. If there is an 113 # ambient group, then add its children to the device editor, 114 # if there is one. 115 # 116 foreach cname [$xmlobj children $path] { 117 if {[string match "about*" $cname]} { 118 continue 119 } 120 121 if {[$_tool widgetfor $path.$cname] == ""} { 119 $xmlobj put $path.$cname.current $obj 120 } 121 } 122 123 # if there's a link, then set up a callback to load from it 124 set link [$xmlobj get $path.$cname.link] 125 if {"" != $link} { 126 $_owner notify add $this $link \ 127 [itcl::code $this _link $xmlobj $link $w $path.$cname] 128 } 129 } elseif {$type == "tool"} { 130 set service [Rappture::Service ::#auto $_owner $path.$cname] 131 # 132 # Scan through all extra inputs associated with this subtool 133 # and create corresponding inputs in the top-level tool. 134 # Then, add the input names to the list being processed here, 135 # so that we'll create the controls during subsequent passes 136 # through the loop. 137 # 138 set extra "" 139 foreach obj [$service input] { 140 set cname [$obj element] 141 $xmlobj copy $path.$cname from $obj "" 142 lappend extra $cname 143 } 144 145 # 146 # If there's a control for this service, then add it 147 # to the end of the extra controls added above. 148 # 149 foreach obj [$service control] { 150 set cname [$obj element] 151 $xmlobj copy $path.$cname from $obj "" 152 $xmlobj put $path.$cname.service $service 153 lappend extra $cname 154 } 155 if {[llength $extra] > 0} { 156 set clist [eval linsert [list $clist] 0 $extra] 157 } 158 159 # 160 # Scan through all outputs associated with this subtool 161 # and create any corresponding feedback widgets. 162 # 163 foreach obj [$service output] { 164 set cname [$obj element] 165 $xmlobj copy $cname from $obj "" 166 167 # pick a good size based on output type 168 set w $frame.results.result[incr num] 169 set type [$obj element -as type] 170 switch -- $type { 171 number - integer - boolean - choice { 172 Rappture::ResultViewer $w -width 0 -height 0 173 pack $w -fill x -padx 4 -pady 4 174 } 175 default { 176 Rappture::ResultViewer $w -width 4i -height 4i 177 pack $w -expand yes -fill both -padx 4 -pady 4 178 } 179 } 180 $service output for $obj $w 181 } 182 } else { 122 183 # create a control panel, if necessary 123 184 if {![winfo exists $frame.cntls]} { 124 Rappture::Controls $frame.cntls $_ tool125 pack $frame.cntls -fill x 185 Rappture::Controls $frame.cntls $_owner 186 pack $frame.cntls -fill x -pady 4 126 187 } 127 188 … … 132 193 set w [$deveditor component top] 133 194 } else { 134 set c [$frame.cntls insert end $xmlobj $path.$cname] 135 set w [$frame.cntls control $c] 195 if {[catch {$frame.cntls insert end $path.$cname} c]} { 196 error $c "$c\n (while building control for $path.$cname)" 197 } else { 198 set w [$frame.cntls control $c] 199 } 136 200 } 137 201 _buildGroup $w $xmlobj $path.$cname 138 202 } else { 139 $frame.cntls insert end $xmlobj $path.$cname 203 if {[catch {$frame.cntls insert end $path.$cname} c]} { 204 error $c "$c\n (while building control for $path.$cname)" 205 } 140 206 } 141 207 } 142 208 } 143 209 } 210 211 itcl::body Rappture::Page::_link {xmlobj path w path2} { 212 if {"" != [$xmlobj element -as type $path.current]} { 213 set val [$xmlobj get $path.current] 214 if {[string length $val] > 0} { 215 $w value $val 216 $xmlobj put $path.current $val 217 } else { 218 set obj [$xmlobj element -as object $path.current] 219 $w value $obj 220 $xmlobj put $path.current $obj 221 } 222 } 223 $_owner changed $path2 224 } -
trunk/gui/scripts/pager.tcl
r11 r22 82 82 83 83 itk_component add next { 84 button $itk_component(controls).next - width 6 -text "Next >" \84 button $itk_component(controls).next -text "Next >" \ 85 85 -command [itcl::code $this current next>] 86 86 } … … 88 88 89 89 itk_component add back { 90 button $itk_component(controls).back - width 6 -text "< Back" \90 button $itk_component(controls).back -text "< Back" \ 91 91 -command [itcl::code $this current <back] 92 92 } … … 169 169 # [itcl::code $_dispatcher event -idle !fixsize] 170 170 171 # the number of pages affects the arrangment -- force an update 172 configure -arrangement $itk_option(-arrangement) 173 171 174 $_dispatcher event -idle !layout 172 175 … … 204 207 } 205 208 set _pages [lreplace $_pages $first $last] 209 210 # the number of pages affects the arrangment -- force an update 211 configure -arrangement $itk_option(-arrangement) 206 212 207 213 $_dispatcher event -idle !layout -
trunk/gui/scripts/resultviewer.tcl
r16 r22 13 13 package require Itk 14 14 15 option add *ResultViewer.width 4i widgetDefault16 option add *ResultViewer.height 4i widgetDefault17 18 15 itcl::class Rappture::ResultViewer { 19 16 inherit itk::Widget 20 17 18 itk_option define -width width Width 4i 19 itk_option define -height height Height 4i 21 20 itk_option define -colors colors Colors "" 22 21 itk_option define -clearcommand clearCommand ClearCommand "" … … 28 27 public method add {index xmlobj path} 29 28 public method clear {{index ""}} 29 public method value {xmlobj} 30 30 31 31 public method plot {option args} … … 50 50 # ---------------------------------------------------------------------- 51 51 itcl::body Rappture::ResultViewer::constructor {args} { 52 option add hull.width hull.height53 pack propagate $itk_component(hull) no54 55 52 # create a dispatcher for events 56 53 Rappture::dispatcher _dispatcher … … 80 77 # ---------------------------------------------------------------------- 81 78 itcl::body Rappture::ResultViewer::add {index xmlobj path} { 82 if {$path != ""} { 83 set dobj [_xml2data $xmlobj $path] 84 } else { 85 set dobj "" 86 } 79 set dobj [_xml2data $xmlobj $path] 87 80 88 81 # … … 124 117 } 125 118 set _dataslots "" 119 } 120 } 121 122 # ---------------------------------------------------------------------- 123 # USAGE: value <xmlobj> 124 # 125 # Convenience method for showing a single value. Loads the value 126 # into the widget via add/clear, then immediately plots the value. 127 # This makes the widget consistent with other widgets, such as 128 # the DeviceEditor, etc. 129 # ---------------------------------------------------------------------- 130 itcl::body Rappture::ResultViewer::value {xmlobj} { 131 clear 132 if {"" != $xmlobj} { 133 add 0 $xmlobj "" 134 plot add 0 "" 126 135 } 127 136 } … … 245 254 } 246 255 } 256 structure { 257 set mode "structure" 258 if {![info exists _mode2widget($mode)]} { 259 set w $itk_interior.struct 260 Rappture::DeviceResult $w 261 set _mode2widget($mode) $w 262 } 263 } 264 number - integer - boolean - choice { 265 set mode "value" 266 if {![info exists _mode2widget($mode)]} { 267 set w $itk_interior.value 268 Rappture::ValueResult $w 269 set _mode2widget($mode) $w 270 } 271 } 247 272 } 248 273 } … … 317 342 return [$xmlobj element -as object $path] 318 343 } 344 structure { 345 return [$xmlobj element -as object $path] 346 } 347 number - integer - boolean - choice { 348 return [$xmlobj element -as object $path] 349 } 319 350 time - status { 320 351 return "" … … 323 354 error "don't know how to plot <$type> data" 324 355 } 356 357 # ---------------------------------------------------------------------- 358 # CONFIGURATION OPTION: -width 359 # ---------------------------------------------------------------------- 360 itcl::configbody Rappture::ResultViewer::width { 361 set w [winfo pixels $itk_component(hull) $itk_option(-width)] 362 set h [winfo pixels $itk_component(hull) $itk_option(-height)] 363 if {$w == 0 || $h == 0} { 364 pack propagate $itk_component(hull) yes 365 } else { 366 component hull configure -width $w -height $h 367 pack propagate $itk_component(hull) no 368 } 369 } 370 371 # ---------------------------------------------------------------------- 372 # CONFIGURATION OPTION: -height 373 # ---------------------------------------------------------------------- 374 itcl::configbody Rappture::ResultViewer::height { 375 set h [winfo pixels $itk_component(hull) $itk_option(-height)] 376 set w [winfo pixels $itk_component(hull) $itk_option(-width)] 377 if {$w == 0 || $h == 0} { 378 pack propagate $itk_component(hull) yes 379 } else { 380 component hull configure -width $w -height $h 381 pack propagate $itk_component(hull) no 382 } 383 } -
trunk/gui/scripts/tempgauge.tcl
r11 r22 11 11 package require Itk 12 12 13 option add *TemperatureGauge. width 30 widgetDefault14 option add *TemperatureGauge. height0 widgetDefault13 option add *TemperatureGauge.sampleWidth 30 widgetDefault 14 option add *TemperatureGauge.sampleHeight 20 widgetDefault 15 15 option add *TemperatureGauge.textBackground #cccccc widgetDefault 16 16 option add *TemperatureGauge.valuePosition "right" widgetDefault … … 115 115 # ---------------------------------------------------------------------- 116 116 itcl::body Rappture::TemperatureGauge::_resize {} { 117 if {$itk_option(- width) > 0} {118 set w $itk_option(- width)117 if {$itk_option(-samplewidth) > 0} { 118 set w $itk_option(-samplewidth) 119 119 } else { 120 120 set w [winfo reqheight $itk_component(value)] … … 124 124 } 125 125 126 if {$itk_option(- height) > 0} {127 set h $itk_option(- height)126 if {$itk_option(-sampleheight) > 0} { 127 set h $itk_option(-sampleheight) 128 128 } else { 129 129 if {$itk_option(-image) != ""} { -
trunk/gui/scripts/textentry.tcl
r17 r22 22 22 -*-helvetica-medium-r-normal-*-*-100-* widgetDefault 23 23 24 # 25 # Tk text widget doesn't honor Ctrl-V by default. Get rid 26 # of the default binding so that Ctrl-V works for <<Paste>> 27 # as expected. 28 # 29 bind Text <Control-KeyPress-v> {} 30 24 31 itcl::class Rappture::TextEntry { 25 32 inherit itk::Widget … … 29 36 itk_option define -height height Height 0 30 37 31 constructor { xmlobjpath args} { # defined below }38 constructor {owner path args} { # defined below } 32 39 33 40 public method value {args} … … 40 47 41 48 private variable _dispatcher "" ;# dispatcher for !events 42 private variable _ xmlobj "" ;# XML containing description49 private variable _owner "" ;# thing managing this control 43 50 private variable _path "" ;# path in XML to this number 44 51 … … 53 60 # CONSTRUCTOR 54 61 # ---------------------------------------------------------------------- 55 itcl::body Rappture::TextEntry::constructor { xmlobjpath args} {56 if { ![Rappture::library isvalid $xmlobj]} {57 error "bad value \"$xmlobj\": should be Rappture::library"58 } 59 set _ xmlobj $xmlobj62 itcl::body Rappture::TextEntry::constructor {owner path args} { 63 if {[catch {$owner isa Rappture::ControlOwner} valid] != 0 || !$valid} { 64 error "bad object \"$owner\": should be Rappture::ControlOwner" 65 } 66 set _owner $owner 60 67 set _path $path 61 68 … … 64 71 $_dispatcher dispatch $this !layout "[itcl::code $this _layout]; list" 65 72 66 set _size [$ xmlobjget $path.size]67 68 set hints [$ xmlobjget $path.about.hints]73 set _size [$_owner xml get $path.size] 74 75 set hints [$_owner xml get $path.about.hints] 69 76 if {[string length $hints] > 0} { 70 77 itk_component add hints { … … 80 87 eval itk_initialize $args 81 88 82 set str [$ xmlobjget $path.default]89 set str [$_owner xml get $path.default] 83 90 if {"" != $str} { value $str } 84 91 } … … 160 167 # ---------------------------------------------------------------------- 161 168 itcl::body Rappture::TextEntry::label {} { 162 set label [$_ xmlobjget $_path.about.label]169 set label [$_owner xml get $_path.about.label] 163 170 if {"" == $label} { 164 171 set label "String" … … 176 183 # ---------------------------------------------------------------------- 177 184 itcl::body Rappture::TextEntry::tooltip {} { 178 set str [$_ xmlobjget $_path.about.description]185 set str [$_owner xml get $_path.about.description] 179 186 return [string trim $str] 180 187 } -
trunk/gui/scripts/tool.tcl
r17 r22 16 16 17 17 itcl::class Rappture::Tool { 18 public variable analyzer ""18 inherit Rappture::ControlOwner 19 19 20 constructor {xmlobj installdir args} { # defined below } 20 constructor {xmlobj installdir args} { 21 Rappture::ControlOwner::constructor "" 22 } { # defined below } 21 23 22 24 public method installdir {} { return $_installdir } 23 public method xml {args}24 25 25 public method load {xmlobj}26 26 public method run {args} 27 27 public method abort {} 28 28 29 public method widgetfor {path {widget ""}}30 public method changed {path}31 public method sync {}32 public method tool {}33 34 private variable _xmlobj "" ;# XML overall <run> object35 29 private variable _installdir "" ;# installation directory for this tool 36 private variable _path2widget ;# maps path => widget on this page37 38 30 private common job ;# array var used for blt::bgexec jobs 39 31 } … … 54 46 55 47 eval configure $args 56 }57 58 # ----------------------------------------------------------------------59 # USAGE: xml <subcommand> ?<arg> <arg> ...?60 # USAGE: xml object61 #62 # Used by clients to manipulate the underlying XML data for this63 # tool. The <subcommand> can be any operation supported by a64 # Rappture::library object. Clients can also request the XML object65 # directly by using the "object" subcommand.66 # ----------------------------------------------------------------------67 itcl::body Rappture::Tool::xml {args} {68 if {"object" == $args} {69 return $_xmlobj70 }71 return [eval $_xmlobj $args]72 48 } 73 49 … … 152 128 set job(control) "abort" 153 129 } 154 155 # ----------------------------------------------------------------------156 # USAGE: widgetfor <path> ?<widget>?157 #158 # Used by embedded widgets such as a Controls panel to register the159 # various controls associated with this page. That way, this Tool160 # knows what widgets to look at when syncing itself to the underlying161 # XML data.162 # ----------------------------------------------------------------------163 itcl::body Rappture::Tool::widgetfor {path {widget ""}} {164 # if this is a query operation, then look for the path165 if {"" == $widget} {166 if {[info exists _path2widget($path)]} {167 return $_path2widget($path)168 }169 return ""170 }171 172 # otherwise, associate the path with the given widget173 if {[info exists _path2widget($path)]} {174 error "$path already associated with widget $_path2widget($path)"175 }176 set _path2widget($path) $widget177 }178 179 # ----------------------------------------------------------------------180 # USAGE: load <xmlobj>181 #182 # Loads the contents of a Rappture <xmlobj> into the controls183 # associated with this tool.184 # ----------------------------------------------------------------------185 itcl::body Rappture::Tool::load {newobj} {186 if {![Rappture::library isvalid $newobj]} {187 error "\"$newobj\" is not a Rappture::library"188 }189 190 foreach path [array names _path2widget] {191 if {"" != [$newobj element -as type $path.current]} {192 set val [$newobj get $path.current]193 if {[string length $val] > 0194 || [llength [$newobj children $path.current]] == 0} {195 $_path2widget($path) value $val196 } else {197 set obj [$newobj element -as object $path.current]198 $_path2widget($path) value $obj199 }200 }201 }202 }203 204 # ----------------------------------------------------------------------205 # USAGE: changed <path>206 #207 # Invoked automatically by the various widgets associated with this208 # tool whenever their value changes. If this tool has a -analyzer,209 # then it is notified that input has changed, so it can reset itself210 # for a new analysis.211 # ----------------------------------------------------------------------212 itcl::body Rappture::Tool::changed {path} {213 if {"" != $analyzer} {214 $analyzer reset215 }216 }217 218 # ----------------------------------------------------------------------219 # USAGE: sync220 #221 # Used by descendents such as a Controls panel to register the222 # various controls associated with this page. That way, this Tool223 # knows what widgets to look at when syncing itself to the underlying224 # XML data.225 # ----------------------------------------------------------------------226 itcl::body Rappture::Tool::sync {} {227 foreach path [array names _path2widget] {228 $_xmlobj put $path.current [$_path2widget($path) value]229 }230 }231 232 # ----------------------------------------------------------------------233 # USAGE: tool234 #235 # Clients use this to figure out which tool is associated with236 # this object. Since this is a tool, it returns itself.237 # ----------------------------------------------------------------------238 itcl::body Rappture::Tool::tool {} {239 return $this240 } -
trunk/lib/library.xml
r9 r22 49 49 <scale>1.0</scale> 50 50 </atom> 51 <atom id="Au"> 52 <color>#cccc00</color> 53 <scale>1.5</scale> 54 </atom> 55 <atom id="AU"> 56 <color>#cccc00</color> 57 <scale>1.5</scale> 58 </atom> 51 59 </elements> 52 60 <materials> -
trunk/python/Rappture/library.py
r11 r22 165 165 # if there's a value, then add it to the node 166 166 if isinstance(value, library): 167 node.appendChild(value.node )167 node.appendChild(value.node.cloneNode(1)) 168 168 elif isinstance(value, minidom.Node): 169 169 node.appendChild(value) -
trunk/tcl/scripts/library.tcl
r13 r22 127 127 } 128 128 structure { 129 # add this to the return list with the right flavor 130 if {$params(-as) == "component"} { 131 lappend rlist $cpath 132 } else { 133 lappend rlist [$xmlobj element -as $params(-as) $cpath] 134 } 135 129 136 if {[$xmlobj element $cpath.current.parameters] != ""} { 130 137 lappend queue $cpath.current.parameters … … 163 170 public method get {{path ""}} 164 171 public method put {args} 172 public method copy {path from args} 165 173 public method remove {{path ""}} 166 174 public method xml {} … … 169 177 public proc value {libobj path} 170 178 179 public proc path2list {path} 171 180 protected method find {path} 172 protected method path2list {path}173 181 protected method node2name {node} 174 182 protected method node2comp {node} … … 515 523 } 516 524 return "" 525 } 526 527 # ---------------------------------------------------------------------- 528 # USAGE: copy <path> from ?<xmlobj>? <path> 529 # 530 # Clients use this to copy the value from one xmlobj/path to another. 531 # If the <xmlobj> is not specified, it is assumed to be the same as 532 # the current object. 533 # ---------------------------------------------------------------------- 534 itcl::body Rappture::LibraryObj::copy {path from args} { 535 if {[llength $args] == 1} { 536 set xmlobj $this 537 set fpath [lindex $args 0] 538 } elseif {[llength $args] == 2} { 539 set xmlobj [lindex $args 0] 540 set fpath [lindex $args 1] 541 } else { 542 error "wrong # args: should be \"copy path from ?xmlobj? path\"" 543 } 544 if {$from != "from"} { 545 error "bad syntax: should be \"copy path from ?xmlobj? path\"" 546 } 547 548 if {[llength [$xmlobj children $fpath]] == 0} { 549 set val [$xmlobj get $fpath] 550 put $path $val 551 } else { 552 set obj [$xmlobj element -as object $fpath] 553 put $path $obj 554 itcl::delete object $obj 555 } 517 556 } 518 557
Note: See TracChangeset
for help on using the changeset viewer.