1 | # ---------------------------------------------------------------------- |
---|
2 | # COMPONENT: deviceEditor - general-purpose device editor |
---|
3 | # |
---|
4 | # This widget takes a <structure> description and chooses a specific |
---|
5 | # editor appropriate for the contents of the structure. If the |
---|
6 | # <structure> contains a molecule, then it chooses a MoleculeViewer. |
---|
7 | # If it contains a 1D device, then it chooses a deviceViewer1D. |
---|
8 | # ====================================================================== |
---|
9 | # AUTHOR: Michael McLennan, Purdue University |
---|
10 | # Copyright (c) 2004-2005 Purdue Research Foundation |
---|
11 | # |
---|
12 | # See the file "license.terms" for information on usage and |
---|
13 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
14 | # ====================================================================== |
---|
15 | package require Itk |
---|
16 | |
---|
17 | option add *DeviceEditor.autoCleanUp yes widgetDefault |
---|
18 | |
---|
19 | itcl::class Rappture::DeviceEditor { |
---|
20 | inherit itk::Widget Rappture::ControlOwner |
---|
21 | |
---|
22 | itk_option define -autocleanup autoCleanUp AutoCleanUp 1 |
---|
23 | |
---|
24 | constructor {owner args} { |
---|
25 | Rappture::ControlOwner::constructor $owner |
---|
26 | } { # defined below } |
---|
27 | |
---|
28 | public method value {args} |
---|
29 | public method download {option args} |
---|
30 | public method add {dataobj {settings ""}} |
---|
31 | public method delete {args} |
---|
32 | public method parameters {title args} { # do nothing } |
---|
33 | |
---|
34 | protected method _redraw {} |
---|
35 | protected method _type {xmlobj} |
---|
36 | |
---|
37 | private variable _current "" ;# active device editor |
---|
38 | |
---|
39 | public common _molvisHosts "" |
---|
40 | |
---|
41 | public proc setMolvisServer {namelist} { |
---|
42 | if {[regexp {^[a-zA-Z0-9\.]+:[0-9]+(,[a-zA-Z0-9\.]+:[0-9]+)*$} $namelist match]} { |
---|
43 | set _molvisHosts $namelist |
---|
44 | } else { |
---|
45 | error "bad visualization server address \"$namelist\": should be host:port,host:port,..." |
---|
46 | } |
---|
47 | } |
---|
48 | } |
---|
49 | |
---|
50 | itk::usual DeviceEditor { |
---|
51 | } |
---|
52 | |
---|
53 | # ---------------------------------------------------------------------- |
---|
54 | # CONSTRUCTOR |
---|
55 | # ---------------------------------------------------------------------- |
---|
56 | itcl::body Rappture::DeviceEditor::constructor {owner args} { |
---|
57 | itk_component add top { |
---|
58 | frame $itk_interior.top |
---|
59 | } |
---|
60 | pack $itk_component(top) -fill x |
---|
61 | |
---|
62 | eval itk_initialize $args |
---|
63 | } |
---|
64 | |
---|
65 | |
---|
66 | # ---------------------------------------------------------------------- |
---|
67 | # USAGE: value ?-check? ?<newval>? |
---|
68 | # |
---|
69 | # Clients use this to query/set the value for this widget. With |
---|
70 | # no args, it returns the current value for the widget. If the |
---|
71 | # <newval> is specified, it sets the value of the widget and |
---|
72 | # sends a <<Value>> event. If the -check flag is included, the |
---|
73 | # new value is not actually applied, but just checked for correctness. |
---|
74 | # ---------------------------------------------------------------------- |
---|
75 | itcl::body Rappture::DeviceEditor::value {args} { |
---|
76 | set onlycheck 0 |
---|
77 | set i [lsearch -exact $args -check] |
---|
78 | if {$i >= 0} { |
---|
79 | set onlycheck 1 |
---|
80 | set args [lreplace $args $i $i] |
---|
81 | } |
---|
82 | |
---|
83 | if {[llength $args] == 1} { |
---|
84 | if {$_xmlobj != ""} { |
---|
85 | if {$itk_option(-autocleanup)} { |
---|
86 | # delete any existing object |
---|
87 | itcl::delete object $_xmlobj |
---|
88 | } |
---|
89 | set _xmlobj "" |
---|
90 | } |
---|
91 | |
---|
92 | set newval [lindex $args 0] |
---|
93 | if {$newval != ""} { |
---|
94 | if {$onlycheck} { |
---|
95 | return |
---|
96 | } |
---|
97 | if {![Rappture::library isvalid $newval]} { |
---|
98 | error "bad value \"$newval\": should be Rappture::Library" |
---|
99 | } |
---|
100 | set _xmlobj $newval |
---|
101 | } |
---|
102 | _redraw |
---|
103 | $_current configure -device $_xmlobj |
---|
104 | event generate $itk_component(hull) <<Value>> |
---|
105 | |
---|
106 | } elseif {[llength $args] == 0} { |
---|
107 | sync ;# querying -- must sync controls with the value |
---|
108 | } else { |
---|
109 | error "wrong # args: should be \"value ?-check? ?newval?\"" |
---|
110 | } |
---|
111 | return $_xmlobj |
---|
112 | } |
---|
113 | |
---|
114 | # ---------------------------------------------------------------------- |
---|
115 | # USAGE: add <dataobj> ?<settings>? |
---|
116 | # |
---|
117 | # Clients use this to add a data object to the plot. The optional |
---|
118 | # <settings> are used to configure the plot. Allowed settings are |
---|
119 | # -color, -brightness, -width, -linestyle, and -raise. Only |
---|
120 | # -brightness and -raise do anything. |
---|
121 | # ---------------------------------------------------------------------- |
---|
122 | itcl::body Rappture::DeviceEditor::add {dataobj {settings ""}} { |
---|
123 | set _xmlobj $dataobj |
---|
124 | if {"" == $_current} { # Make sure viewer instance exists |
---|
125 | _redraw |
---|
126 | } |
---|
127 | eval $_current add $dataobj [list $settings] |
---|
128 | } |
---|
129 | |
---|
130 | # ---------------------------------------------------------------------- |
---|
131 | # USAGE: delete ?<dataobj> <dataobj> ...? |
---|
132 | # |
---|
133 | # Clients use this to delete a dataobj from the plot. If no dataobjs |
---|
134 | # are specified, then all dataobjs are deleted. |
---|
135 | # ---------------------------------------------------------------------- |
---|
136 | itcl::body Rappture::DeviceEditor::delete {args} { |
---|
137 | if {"" != $_current} { |
---|
138 | eval $_current delete $args |
---|
139 | set _xmlobj [lindex [$_current get] end] |
---|
140 | } |
---|
141 | } |
---|
142 | |
---|
143 | # ---------------------------------------------------------------------- |
---|
144 | # USAGE: download coming |
---|
145 | # USAGE: download controls <downloadCommand> |
---|
146 | # USAGE: download now |
---|
147 | # |
---|
148 | # Clients use this method to create a downloadable representation |
---|
149 | # of the plot. Returns a list of the form {ext string}, where |
---|
150 | # "ext" is the file extension (indicating the type of data) and |
---|
151 | # "string" is the data itself. |
---|
152 | # ---------------------------------------------------------------------- |
---|
153 | itcl::body Rappture::DeviceEditor::download {option args} { |
---|
154 | if {"" != $_current} { |
---|
155 | return [eval $_current download $option $args] |
---|
156 | } |
---|
157 | return "" |
---|
158 | } |
---|
159 | |
---|
160 | # ---------------------------------------------------------------------- |
---|
161 | # USAGE: _redraw |
---|
162 | # |
---|
163 | # Used internally to load new device data into the appropriate |
---|
164 | # editor. If the editor needs to be created, it is created and |
---|
165 | # activated within this widget. Then, the data is loaded into |
---|
166 | # the editor. |
---|
167 | # ---------------------------------------------------------------------- |
---|
168 | itcl::body Rappture::DeviceEditor::_redraw {} { |
---|
169 | if {$_current != ""} { |
---|
170 | $_current configure -device "" |
---|
171 | set _current "" |
---|
172 | } |
---|
173 | switch -- [_type $_xmlobj] { |
---|
174 | molecule { |
---|
175 | if { ![winfo exists $itk_component(hull).mol] } { |
---|
176 | catch { |
---|
177 | destroy $itk_component(hull).dev |
---|
178 | } |
---|
179 | set servers [Rappture::VisViewer::GetServerList "pymol"] |
---|
180 | if { "" != $servers } { |
---|
181 | Rappture::MolvisViewer $itk_component(hull).mol $servers |
---|
182 | } else { |
---|
183 | Rappture::MoleculeViewer $itk_component(hull).mol $this |
---|
184 | } |
---|
185 | pack $itk_component(hull).mol -expand yes -fill both |
---|
186 | } |
---|
187 | set _current $itk_component(hull).mol |
---|
188 | } |
---|
189 | device1D { |
---|
190 | if { ![winfo exists $itk_component(hull).dev] } { |
---|
191 | catch { |
---|
192 | destroy $itk_component(hull).mol |
---|
193 | } |
---|
194 | Rappture::DeviceViewer1D $itk_component(hull).dev $this |
---|
195 | pack $itk_component(hull).dev -expand yes -fill both |
---|
196 | } |
---|
197 | set _current $itk_component(hull).dev |
---|
198 | } |
---|
199 | } |
---|
200 | } |
---|
201 | |
---|
202 | # ---------------------------------------------------------------------- |
---|
203 | # USAGE: _type <xmlobj> |
---|
204 | # |
---|
205 | # Used internally to determine the type of the device data stored |
---|
206 | # within the <xmlobj>. Returns a name such as "molecule" or |
---|
207 | # "device1D" indicating the type of editor that should be used to |
---|
208 | # display the data. |
---|
209 | # ---------------------------------------------------------------------- |
---|
210 | itcl::body Rappture::DeviceEditor::_type {xmlobj} { |
---|
211 | if {$xmlobj == ""} { |
---|
212 | return "" |
---|
213 | } |
---|
214 | if {[llength [$xmlobj children -type molecule components]] > 0} { |
---|
215 | return "molecule" |
---|
216 | } |
---|
217 | return "device1D" |
---|
218 | } |
---|