source: trunk/gui/scripts/drawing.tcl @ 3081

Last change on this file since 3081 was 3081, checked in by gah, 12 years ago

add molecule element to vtkviewer

File size: 9.4 KB
Line 
1
2# ----------------------------------------------------------------------
3#  COMPONENT: drawing - 2D drawing of data
4# ======================================================================
5#  AUTHOR:  Michael McLennan, Purdue University
6#  Copyright (c) 2004-2007  Purdue Research Foundation
7#
8#  See the file "license.terms" for information on usage and
9#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
10# ======================================================================
11package require Itcl
12package require BLT
13
14namespace eval Rappture {
15    # forward declaration
16}
17
18itcl::class Rappture::Drawing {
19    constructor {xmlobj path} {
20        # defined below
21    }
22    destructor {
23        # defined below
24    }
25    public method limits {axis}
26    public method label { elem }
27    public method type { elem }
28    public method style { elem }
29    public method shape { elem }
30    public method values { elem }
31    public method data { elem }
32    public method hints {{keyword ""}}
33    public method components { args }
34
35    private variable _drawing
36    private variable _xmlobj
37    private variable _actors
38    private variable _styles
39    private variable _shapes
40    private variable _labels
41    private variable _types
42    private variable _data
43    private variable _hints
44    private variable _units
45    private variable _limits
46}
47
48# ----------------------------------------------------------------------
49# Constructor
50# ----------------------------------------------------------------------
51itcl::body Rappture::Drawing::constructor {xmlobj path} {
52    package require vtk
53    if {![Rappture::library isvalid $xmlobj]} {
54        error "bad value \"$xmlobj\": should be Rappture::library"
55    }
56    set _xmlobj $xmlobj
57    set _drawing [$xmlobj element -as object $path]
58    set _units [$_drawing get units]
59
60    set xunits [$xmlobj get units]
61    if {"" == $xunits || "arbitrary" == $xunits} {
62        set xunits "um"
63    }
64    array set _limits {
65        xMin 0
66        xMax 0
67        yMin 0
68        yMax 0
69        zMin 0
70        zMax 0
71    }
72    # determine the overall size of the device
73    foreach elem [$_xmlobj children $path] {
74        switch -glob -- $elem {
75            polygon* {
76                set _data($elem) [$_xmlobj get $path.$elem.vtk]
77                set _data($elem) [string trim $_data($elem)]
78                set _styles($elem) [$_xmlobj get $path.$elem.about.style]
79                set _labels($elem) [$_xmlobj get $path.$elem.about.label]
80                set _types($elem) polydata
81            }
82            streamlines* {
83                set _data($elem) [$_xmlobj get $path.$elem.vtk]
84                set _data($elem) [string trim $_data($elem)]
85                set _styles($elem) [$_xmlobj get $path.$elem.about.style]
86                set _labels($elem) [$_xmlobj get $path.$elem.about.label]
87                set _types($elem) streamlines
88            }
89            glyphs* {
90                set _data($elem) [$_xmlobj get $path.$elem.vtk]
91                set _data($elem) [string trim $_data($elem)]
92                set _styles($elem) [$_xmlobj get $path.$elem.about.style]
93                set _labels($elem) [$_xmlobj get $path.$elem.about.label]
94                set _shapes($elem) [$_xmlobj get $path.$elem.about.shape]
95                set _types($elem) glyphs
96            }
97            molecule* {
98                set _data($elem) [$_xmlobj get $path.$elem.vtk]
99                set _data($elem) [string trim $_data($elem)]
100                set _styles($elem) [$_xmlobj get $path.$elem.about.style]
101                set _labels($elem) [$_xmlobj get $path.$elem.about.label]
102                set _types($elem) molecule
103            }
104        }
105    }
106    foreach {key path} {
107        group   about.group
108        label   about.label
109        color   about.color
110        camera  about.camera
111        type    about.type
112        xlabel  xaxis.label
113        xdesc   xaxis.description
114        xunits  xaxis.units
115        xscale  xaxis.scale
116        xmin    xaxis.min
117        xmax    xaxis.max
118        ylabel  yaxis.label
119        ydesc   yaxis.description
120        yunits  yaxis.units
121        yscale  yaxis.scale
122        ymin    yaxis.min
123        ymax    yaxis.max
124        zlabel  zaxis.label
125        zdesc   zaxis.description
126        zunits  zaxis.units
127        zscale  zaxis.scale
128        zmin    zaxis.min
129        zmax    zaxis.max
130    } {
131        set str [$_drawing get $path]
132        if {"" != $str} {
133            set _hints($key) $str
134        }
135    }
136    foreach {key} { axisorder } {
137        set str [$_drawing get $key]
138        if {"" != $str} {
139            set _hints($key) $str
140        }
141    }
142}
143
144# ----------------------------------------------------------------------
145# Destructor
146# ----------------------------------------------------------------------
147itcl::body Rappture::Drawing::destructor {} {
148    # empty
149}
150
151#
152# label --
153#
154#       Returns the label of the named drawing element.
155#
156itcl::body Rappture::Drawing::label { elem } {
157    if { [info exists _labels($elem)] } {
158        return $_labels($elem)
159    }
160    return ""
161}
162
163#
164# type --
165#
166#       Returns the type of the named drawing element.
167#
168itcl::body Rappture::Drawing::type { elem } {
169    if { [info exists _types($elem)] } {
170        return $_types($elem)
171    }
172    return ""
173}
174
175#
176# style --
177#
178#       Returns the style string of the named drawing element.
179#
180itcl::body Rappture::Drawing::style { elem } {
181    if { [info exists _styles($elem)] } {
182        return $_styles($elem)
183    }
184    return ""
185}
186
187#
188# shape --
189#
190#       Returns the shape of the glyphs in the drawing element.
191#
192itcl::body Rappture::Drawing::shape { elem } {
193    set shape ""
194    if { [info exists _shapes($elem)] } {
195        return $_shapes($elem)
196    }
197    switch -- $shape {
198        arrow - cone - cube - cylinder - dodecahedron -
199        icosahedron - line - octahedron - sphere - tetrahedron  {
200            return $shape
201        }
202        default {
203            puts stderr "unknown glyph shape \"$shape\""
204        }
205    }
206    return ""
207}
208
209#
210# data --
211#
212#       Returns the data of the named drawing element.
213#
214itcl::body Rappture::Drawing::data { elem } {
215    if { [info exists _data($elem)] } {
216        return $_data($elem)
217    }
218    return ""
219}
220
221# ----------------------------------------------------------------------
222# method values
223#       Returns a base64 encoded, gzipped Tcl list that represents the
224#       Tcl command and data to recreate the uniform rectangular grid
225#       on the nanovis server.
226# ----------------------------------------------------------------------
227itcl::body Rappture::Drawing::values { elem } {
228    if { [info exists _data($elem)] } {
229        return $_data($elem)
230    }
231    return ""
232}
233
234itcl::body Rappture::Drawing::components { args } {
235    return [array names _data]
236}
237
238# ----------------------------------------------------------------------
239# method limits <axis>
240#       Returns a list {min max} representing the limits for the
241#       specified axis.
242# ----------------------------------------------------------------------
243itcl::body Rappture::Drawing::limits {which} {
244    set min ""
245    set max ""
246    foreach key [array names _data] {
247        set actor $_actors($key)
248        foreach key { xMin xMax yMin yMax zMin zMax} value [$actor GetBounds] {
249            set _limits($key) $value
250        }
251        break
252    }   
253   
254    foreach key [array names _actors] {
255        set actor $_actors($key)
256        foreach { xMin xMax yMin yMax zMin zMax} [$actor GetBounds] break
257        if { $xMin < $_limits(xMin) } {
258            set _limits(xMin) $xMin
259        }
260        if { $xMax > $_limits(xMax) } {
261            set _limits(xMax) $xMax
262        }
263        if { $yMin < $_limits(yMin) } {
264            set _limits(yMin) $yMin
265        }
266        if { $yMax > $_limits(yMax) } {
267            set _limits(yMax) $yMax
268        }
269        if { $zMin < $_limits(zMin) } {
270            set _limits(zMin) $zMin
271        }
272        if { $zMax > $_limits(zMax) } {
273            set _limits(zMax) $zMax
274        }
275    }
276    switch -- $which {
277        x {
278            set min $_limits(xMin)
279            set max $_limits(xMax)
280            set axis "xaxis"
281        }
282        y {
283            set min $_limits(yMin)
284            set max $_limits(yMax)
285            set axis "yaxis"
286        }
287        v - z {
288            set min $_limits(zMin)
289            set max $_limits(zMax)
290            set axis "zaxis"
291        }
292        default {
293            error "unknown axis description \"$which\""
294        }
295    }
296    return [list $min $max]
297}
298
299
300# ----------------------------------------------------------------------
301# USAGE: hints ?<keyword>?
302#
303# Returns a list of key/value pairs for various hints about plotting
304# this curve.  If a particular <keyword> is specified, then it returns
305# the hint for that <keyword>, if it exists.
306# ----------------------------------------------------------------------
307itcl::body Rappture::Drawing::hints { {keyword ""} } {
308    if 0 {
309    if {[info exists _hints(xlabel)] && "" != $_hints(xlabel)
310        && [info exists _hints(xunits)] && "" != $_hints(xunits)} {
311        set _hints(xlabel) "$_hints(xlabel) ($_hints(xunits))"
312    }
313    if {[info exists _hints(ylabel)] && "" != $_hints(ylabel)
314        && [info exists _hints(yunits)] && "" != $_hints(yunits)} {
315        set _hints(ylabel) "$_hints(ylabel) ($_hints(yunits))"
316    }
317    }
318    if {[info exists _hints(group)] && [info exists _hints(label)]} {
319        # pop-up help for each curve
320        set _hints(tooltip) $_hints(label)
321    }
322    if {$keyword != ""} {
323        if {[info exists _hints($keyword)]} {
324            return $_hints($keyword)
325        }
326        return ""
327    }
328    return [array get _hints]
329}
330
Note: See TracBrowser for help on using the repository browser.