1 | # -*- mode: tcl; indent-tabs-mode: nil -*- |
---|
2 | |
---|
3 | # ---------------------------------------------------------------------- |
---|
4 | # COMPONENT: drawing - 3D drawing of data |
---|
5 | # ====================================================================== |
---|
6 | # AUTHOR: Michael McLennan, Purdue University |
---|
7 | # Copyright (c) 2004-2012 HUBzero Foundation, LLC |
---|
8 | # |
---|
9 | # See the file "license.terms" for information on usage and |
---|
10 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
11 | # ====================================================================== |
---|
12 | package require Itcl |
---|
13 | package require BLT |
---|
14 | |
---|
15 | namespace eval Rappture { |
---|
16 | # forward declaration |
---|
17 | } |
---|
18 | |
---|
19 | itcl::class Rappture::Drawing { |
---|
20 | private variable _drawing |
---|
21 | private variable _xmlobj |
---|
22 | private variable _styles |
---|
23 | private variable _shapes |
---|
24 | private variable _labels |
---|
25 | private variable _types |
---|
26 | private variable _data |
---|
27 | private variable _hints |
---|
28 | private variable _units |
---|
29 | |
---|
30 | constructor {xmlobj path} { |
---|
31 | # defined below |
---|
32 | } |
---|
33 | destructor { |
---|
34 | # defined below |
---|
35 | } |
---|
36 | |
---|
37 | public method label { elem } |
---|
38 | public method type { elem } |
---|
39 | public method style { elem } |
---|
40 | public method shape { elem } |
---|
41 | public method values { elem } |
---|
42 | public method data { elem } |
---|
43 | public method hints {{keyword ""}} |
---|
44 | public method components { args } |
---|
45 | } |
---|
46 | |
---|
47 | # ---------------------------------------------------------------------- |
---|
48 | # Constructor |
---|
49 | # ---------------------------------------------------------------------- |
---|
50 | itcl::body Rappture::Drawing::constructor {xmlobj path} { |
---|
51 | package require vtk |
---|
52 | if {![Rappture::library isvalid $xmlobj]} { |
---|
53 | error "bad value \"$xmlobj\": should be Rappture::library" |
---|
54 | } |
---|
55 | set _xmlobj $xmlobj |
---|
56 | set _drawing [$xmlobj element -as object $path] |
---|
57 | set _units [$_drawing get units] |
---|
58 | |
---|
59 | set xunits [$xmlobj get units] |
---|
60 | if {"" == $xunits || "arbitrary" == $xunits} { |
---|
61 | set xunits "um" |
---|
62 | } |
---|
63 | # determine the overall size of the device |
---|
64 | foreach elem [$_xmlobj children $path] { |
---|
65 | switch -glob -- $elem { |
---|
66 | # polygon is deprecated in favor of polydata |
---|
67 | polygon* - polydata* { |
---|
68 | set _data($elem) [$_xmlobj get $path.$elem.vtk] |
---|
69 | set _data($elem) [string trim $_data($elem)] |
---|
70 | set _styles($elem) [$_xmlobj get $path.$elem.about.style] |
---|
71 | set _labels($elem) [$_xmlobj get $path.$elem.about.label] |
---|
72 | set _types($elem) polydata |
---|
73 | } |
---|
74 | glyphs* { |
---|
75 | set _data($elem) [$_xmlobj get $path.$elem.vtk] |
---|
76 | set _data($elem) [string trim $_data($elem)] |
---|
77 | set _styles($elem) [$_xmlobj get $path.$elem.about.style] |
---|
78 | set _labels($elem) [$_xmlobj get $path.$elem.about.label] |
---|
79 | set _shapes($elem) [$_xmlobj get $path.$elem.about.shape] |
---|
80 | set _types($elem) glyphs |
---|
81 | } |
---|
82 | molecule* { |
---|
83 | set pdbdata [$_xmlobj get $path.$elem.pdb] |
---|
84 | if { $pdbdata != "" } { |
---|
85 | set contents [Rappture::PdbToVtk $pdbdata] |
---|
86 | } else { |
---|
87 | set contents [$_xmlobj get $path.$elem.vtk] |
---|
88 | } |
---|
89 | set _data($elem) [string trim $contents] |
---|
90 | set _styles($elem) [$_xmlobj get $path.$elem.about.style] |
---|
91 | set _labels($elem) [$_xmlobj get $path.$elem.about.label] |
---|
92 | set _types($elem) molecule |
---|
93 | } |
---|
94 | } |
---|
95 | } |
---|
96 | foreach {key path} { |
---|
97 | group about.group |
---|
98 | label about.label |
---|
99 | color about.color |
---|
100 | camera about.camera |
---|
101 | type about.type |
---|
102 | xlabel xaxis.label |
---|
103 | xdesc xaxis.description |
---|
104 | xunits xaxis.units |
---|
105 | xscale xaxis.scale |
---|
106 | xmin xaxis.min |
---|
107 | xmax xaxis.max |
---|
108 | ylabel yaxis.label |
---|
109 | ydesc yaxis.description |
---|
110 | yunits yaxis.units |
---|
111 | yscale yaxis.scale |
---|
112 | ymin yaxis.min |
---|
113 | ymax yaxis.max |
---|
114 | zlabel zaxis.label |
---|
115 | zdesc zaxis.description |
---|
116 | zunits zaxis.units |
---|
117 | zscale zaxis.scale |
---|
118 | zmin zaxis.min |
---|
119 | zmax zaxis.max |
---|
120 | } { |
---|
121 | set str [$_drawing get $path] |
---|
122 | if {"" != $str} { |
---|
123 | set _hints($key) $str |
---|
124 | } |
---|
125 | } |
---|
126 | foreach {key} { axisorder } { |
---|
127 | set str [$_drawing get $key] |
---|
128 | if {"" != $str} { |
---|
129 | set _hints($key) $str |
---|
130 | } |
---|
131 | } |
---|
132 | } |
---|
133 | |
---|
134 | # ---------------------------------------------------------------------- |
---|
135 | # Destructor |
---|
136 | # ---------------------------------------------------------------------- |
---|
137 | itcl::body Rappture::Drawing::destructor {} { |
---|
138 | # empty |
---|
139 | } |
---|
140 | |
---|
141 | # |
---|
142 | # label -- |
---|
143 | # |
---|
144 | # Returns the label of the named drawing element. |
---|
145 | # |
---|
146 | itcl::body Rappture::Drawing::label { elem } { |
---|
147 | if { [info exists _labels($elem)] } { |
---|
148 | return $_labels($elem) |
---|
149 | } |
---|
150 | return "" |
---|
151 | } |
---|
152 | |
---|
153 | # |
---|
154 | # type -- |
---|
155 | # |
---|
156 | # Returns the type of the named drawing element. |
---|
157 | # |
---|
158 | itcl::body Rappture::Drawing::type { elem } { |
---|
159 | if { [info exists _types($elem)] } { |
---|
160 | return $_types($elem) |
---|
161 | } |
---|
162 | return "" |
---|
163 | } |
---|
164 | |
---|
165 | # |
---|
166 | # style -- |
---|
167 | # |
---|
168 | # Returns the style string of the named drawing element. |
---|
169 | # |
---|
170 | itcl::body Rappture::Drawing::style { elem } { |
---|
171 | if { [info exists _styles($elem)] } { |
---|
172 | return $_styles($elem) |
---|
173 | } |
---|
174 | return "" |
---|
175 | } |
---|
176 | |
---|
177 | # |
---|
178 | # shape -- |
---|
179 | # |
---|
180 | # Returns the shape of the glyphs in the drawing element. |
---|
181 | # |
---|
182 | itcl::body Rappture::Drawing::shape { elem } { |
---|
183 | set shape "" |
---|
184 | if { [info exists _shapes($elem)] } { |
---|
185 | return $_shapes($elem) |
---|
186 | } |
---|
187 | switch -- $shape { |
---|
188 | arrow - cone - cube - cylinder - dodecahedron - |
---|
189 | icosahedron - line - octahedron - sphere - tetrahedron { |
---|
190 | return $shape |
---|
191 | } |
---|
192 | default { |
---|
193 | puts stderr "unknown glyph shape \"$shape\"" |
---|
194 | } |
---|
195 | } |
---|
196 | return "" |
---|
197 | } |
---|
198 | |
---|
199 | # |
---|
200 | # data -- |
---|
201 | # |
---|
202 | # Returns the data of the named drawing element. |
---|
203 | # |
---|
204 | itcl::body Rappture::Drawing::data { elem } { |
---|
205 | if { [info exists _data($elem)] } { |
---|
206 | return $_data($elem) |
---|
207 | } |
---|
208 | return "" |
---|
209 | } |
---|
210 | |
---|
211 | # ---------------------------------------------------------------------- |
---|
212 | # method values |
---|
213 | # Returns a base64 encoded, gzipped Tcl list that represents the |
---|
214 | # Tcl command and data to recreate the uniform rectangular grid |
---|
215 | # on the nanovis server. |
---|
216 | # ---------------------------------------------------------------------- |
---|
217 | itcl::body Rappture::Drawing::values { elem } { |
---|
218 | if { [info exists _data($elem)] } { |
---|
219 | return $_data($elem) |
---|
220 | } |
---|
221 | return "" |
---|
222 | } |
---|
223 | |
---|
224 | itcl::body Rappture::Drawing::components { args } { |
---|
225 | return [array names _data] |
---|
226 | } |
---|
227 | |
---|
228 | # ---------------------------------------------------------------------- |
---|
229 | # USAGE: hints ?<keyword>? |
---|
230 | # |
---|
231 | # Returns a list of key/value pairs for various hints about plotting |
---|
232 | # this curve. If a particular <keyword> is specified, then it returns |
---|
233 | # the hint for that <keyword>, if it exists. |
---|
234 | # ---------------------------------------------------------------------- |
---|
235 | itcl::body Rappture::Drawing::hints { {keyword ""} } { |
---|
236 | if 0 { |
---|
237 | if {[info exists _hints(xlabel)] && "" != $_hints(xlabel) |
---|
238 | && [info exists _hints(xunits)] && "" != $_hints(xunits)} { |
---|
239 | set _hints(xlabel) "$_hints(xlabel) ($_hints(xunits))" |
---|
240 | } |
---|
241 | if {[info exists _hints(ylabel)] && "" != $_hints(ylabel) |
---|
242 | && [info exists _hints(yunits)] && "" != $_hints(yunits)} { |
---|
243 | set _hints(ylabel) "$_hints(ylabel) ($_hints(yunits))" |
---|
244 | } |
---|
245 | } |
---|
246 | if {[info exists _hints(group)] && [info exists _hints(label)]} { |
---|
247 | # pop-up help for each curve |
---|
248 | set _hints(tooltip) $_hints(label) |
---|
249 | } |
---|
250 | if {$keyword != ""} { |
---|
251 | if {[info exists _hints($keyword)]} { |
---|
252 | return $_hints($keyword) |
---|
253 | } |
---|
254 | return "" |
---|
255 | } |
---|
256 | return [array get _hints] |
---|
257 | } |
---|