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

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