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

Last change on this file since 2464 was 2464, checked in by gah, 13 years ago

add stream controls to vtkviewer

File size: 8.2 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        }
90    }
91    foreach {key path} {
92        group   about.group
93        label   about.label
94        color   about.color
95        camera  about.camera
96        type    about.type
97        xlabel  xaxis.label
98        xdesc   xaxis.description
99        xunits  xaxis.units
100        xscale  xaxis.scale
101        xmin    xaxis.min
102        xmax    xaxis.max
103        ylabel  yaxis.label
104        ydesc   yaxis.description
105        yunits  yaxis.units
106        yscale  yaxis.scale
107        ymin    yaxis.min
108        ymax    yaxis.max
109        zlabel  zaxis.label
110        zdesc   zaxis.description
111        zunits  zaxis.units
112        zscale  zaxis.scale
113        zmin    zaxis.min
114        zmax    zaxis.max
115    } {
116        set str [$_drawing get $path]
117        if {"" != $str} {
118            set _hints($key) $str
119        }
120    }
121    foreach {key} { axisorder } {
122        set str [$_drawing get $key]
123        if {"" != $str} {
124            set _hints($key) $str
125        }
126    }
127}
128
129# ----------------------------------------------------------------------
130# Destructor
131# ----------------------------------------------------------------------
132itcl::body Rappture::Drawing::destructor {} {
133    # empty
134}
135
136#
137# label --
138#
139#       Returns the label of the named drawing element.
140#
141itcl::body Rappture::Drawing::label { elem } {
142    if { [info exists _labels($elem)] } {
143        return $_labels($elem)
144    }
145    return ""
146}
147
148#
149# type --
150#
151#       Returns the type of the named drawing element.
152#
153itcl::body Rappture::Drawing::type { elem } {
154    if { [info exists _types($elem)] } {
155        return $_types($elem)
156    }
157    return ""
158}
159
160#
161# style --
162#
163#       Returns the style string of the named drawing element.
164#
165itcl::body Rappture::Drawing::style { elem } {
166    if { [info exists _styles($elem)] } {
167        return $_styles($elem)
168    }
169    return ""
170}
171
172#
173# data --
174#
175#       Returns the data of the named drawing element.
176#
177itcl::body Rappture::Drawing::data { elem } {
178    if { [info exists _data($elem)] } {
179        return $_data($elem)
180    }
181    return ""
182}
183
184# ----------------------------------------------------------------------
185# method values
186#       Returns a base64 encoded, gzipped Tcl list that represents the
187#       Tcl command and data to recreate the uniform rectangular grid
188#       on the nanovis server.
189# ----------------------------------------------------------------------
190itcl::body Rappture::Drawing::values { elem } {
191    if { [info exists _data($elem)] } {
192        return $_data($elem)
193    }
194    return ""
195}
196
197itcl::body Rappture::Drawing::components { args } {
198    return [array names _data]
199}
200
201# ----------------------------------------------------------------------
202# method limits <axis>
203#       Returns a list {min max} representing the limits for the
204#       specified axis.
205# ----------------------------------------------------------------------
206itcl::body Rappture::Drawing::limits {which} {
207    set min ""
208    set max ""
209    foreach key [array names _data] {
210        set actor $_actors($key)
211        foreach key { xMin xMax yMin yMax zMin zMax} value [$actor GetBounds] {
212            set _limits($key) $value
213        }
214        break
215    }   
216   
217    foreach key [array names _actors] {
218        set actor $_actors($key)
219        foreach { xMin xMax yMin yMax zMin zMax} [$actor GetBounds] break
220        if { $xMin < $_limits(xMin) } {
221            set _limits(xMin) $xMin
222        }
223        if { $xMax > $_limits(xMax) } {
224            set _limits(xMax) $xMax
225        }
226        if { $yMin < $_limits(yMin) } {
227            set _limits(yMin) $yMin
228        }
229        if { $yMax > $_limits(yMax) } {
230            set _limits(yMax) $yMax
231        }
232        if { $zMin < $_limits(zMin) } {
233            set _limits(zMin) $zMin
234        }
235        if { $zMax > $_limits(zMax) } {
236            set _limits(zMax) $zMax
237        }
238    }
239    switch -- $which {
240        x {
241            set min $_limits(xMin)
242            set max $_limits(xMax)
243            set axis "xaxis"
244        }
245        y {
246            set min $_limits(yMin)
247            set max $_limits(yMax)
248            set axis "yaxis"
249        }
250        v - z {
251            set min $_limits(zMin)
252            set max $_limits(zMax)
253            set axis "zaxis"
254        }
255        default {
256            error "unknown axis description \"$which\""
257        }
258    }
259    return [list $min $max]
260}
261
262
263# ----------------------------------------------------------------------
264# USAGE: hints ?<keyword>?
265#
266# Returns a list of key/value pairs for various hints about plotting
267# this curve.  If a particular <keyword> is specified, then it returns
268# the hint for that <keyword>, if it exists.
269# ----------------------------------------------------------------------
270itcl::body Rappture::Drawing::hints { {keyword ""} } {
271    if 0 {
272    if {[info exists _hints(xlabel)] && "" != $_hints(xlabel)
273        && [info exists _hints(xunits)] && "" != $_hints(xunits)} {
274        set _hints(xlabel) "$_hints(xlabel) ($_hints(xunits))"
275    }
276    if {[info exists _hints(ylabel)] && "" != $_hints(ylabel)
277        && [info exists _hints(yunits)] && "" != $_hints(yunits)} {
278        set _hints(ylabel) "$_hints(ylabel) ($_hints(yunits))"
279    }
280    }
281    if {[info exists _hints(group)] && [info exists _hints(label)]} {
282        # pop-up help for each curve
283        set _hints(tooltip) $_hints(label)
284    }
285    if {$keyword != ""} {
286        if {[info exists _hints($keyword)]} {
287            return $_hints($keyword)
288        }
289        return ""
290    }
291    return [array get _hints]
292}
293
Note: See TracBrowser for help on using the repository browser.