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

Last change on this file since 2385 was 2385, checked in by gah, 13 years ago
File size: 7.7 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 style { elem }
32    public method values { elem }
33    public method data { elem }
34    public method hints {{keyword ""}}
35    public method components { args }
36
37    private variable _drawing
38    private variable _xmlobj
39    private variable _actors
40    private variable _styles
41    private variable _data
42    private variable _hints
43    private variable _units
44    private variable _limits
45}
46
47# ----------------------------------------------------------------------
48# Constructor
49# ----------------------------------------------------------------------
50itcl::body Rappture::Drawing::constructor {xmlobj path} {
51    if {![Rappture::library isvalid $xmlobj]} {
52        error "bad value \"$xmlobj\": should be Rappture::library"
53    }
54    set _xmlobj $xmlobj
55    set _drawing [$xmlobj element -as object $path]
56    set _units [$_drawing get units]
57
58    set xunits [$xmlobj get units]
59    if {"" == $xunits || "arbitrary" == $xunits} {
60        set xunits "um"
61    }
62    array set _limits {
63        xMin 0
64        xMax 0
65        yMin 0
66        yMax 0
67        zMin 0
68        zMax 0
69    }
70    # determine the overall size of the device
71    foreach elem [$_xmlobj children $path] {
72        switch -glob -- $elem {
73            polygon* {
74                set _data($elem) [$_xmlobj get $path.$elem.vtk]
75            }
76        }
77    }
78    foreach {key path} {
79        group   about.group
80        label   about.label
81        color   about.color
82        camera  about.camera
83        type    about.type
84        xlabel  xaxis.label
85        xdesc   xaxis.description
86        xunits  xaxis.units
87        xscale  xaxis.scale
88        xmin    xaxis.min
89        xmax    xaxis.max
90        ylabel  yaxis.label
91        ydesc   yaxis.description
92        yunits  yaxis.units
93        yscale  yaxis.scale
94        ymin    yaxis.min
95        ymax    yaxis.max
96        zlabel  zaxis.label
97        zdesc   zaxis.description
98        zunits  zaxis.units
99        zscale  zaxis.scale
100        zmin    zaxis.min
101        zmax    zaxis.max
102    } {
103        set str [$_drawing get $path]
104        if {"" != $str} {
105            set _hints($key) $str
106        }
107    }
108    foreach {key} { axisorder } {
109        set str [$_drawing get $key]
110        if {"" != $str} {
111            set _hints($key) $str
112        }
113    }
114}
115
116# ----------------------------------------------------------------------
117# Destructor
118# ----------------------------------------------------------------------
119itcl::body Rappture::Drawing::destructor {} {
120    # empty
121}
122
123# ----------------------------------------------------------------------
124# method style
125#       Returns a base64 encoded, gzipped Tcl list that represents the
126#       Tcl command and data to recreate the uniform rectangular grid
127#       on the nanovis server.
128# ----------------------------------------------------------------------
129itcl::body Rappture::Drawing::style { elem } {
130    if { [info exists _styles($elem)] } {
131        return $_styles($elem)
132    }
133    return ""
134}
135
136# ----------------------------------------------------------------------
137# method data
138#       Returns a base64 encoded, gzipped Tcl list that represents the
139#       Tcl command and data to recreate the uniform rectangular grid
140#       on the nanovis server.
141# ----------------------------------------------------------------------
142itcl::body Rappture::Drawing::data { elem } {
143    if { [info exists _data($elem)] } {
144        return $_data($elem)
145    }
146    return ""
147}
148
149# ----------------------------------------------------------------------
150# method values
151#       Returns a base64 encoded, gzipped Tcl list that represents the
152#       Tcl command and data to recreate the uniform rectangular grid
153#       on the nanovis server.
154# ----------------------------------------------------------------------
155itcl::body Rappture::Drawing::values { elem } {
156    if { [info exists _data($elem)] } {
157        return $_data($elem)
158    }
159    return ""
160}
161
162itcl::body Rappture::Drawing::components { args } {
163    return [array names _data]
164}
165
166# ----------------------------------------------------------------------
167# method limits <axis>
168#       Returns a list {min max} representing the limits for the
169#       specified axis.
170# ----------------------------------------------------------------------
171itcl::body Rappture::Drawing::limits {which} {
172    set min ""
173    set max ""
174    foreach key [array names _data] {
175        set actor $_actors($key)
176        foreach key { xMin xMax yMin yMax zMin zMax} value [$actor GetBounds] {
177            set _limits($key) $value
178        }
179        break
180    }   
181   
182    foreach key [array names _actors] {
183        set actor $_actors($key)
184        foreach { xMin xMax yMin yMax zMin zMax} [$actor GetBounds] break
185        if { $xMin < $_limits(xMin) } {
186            set _limits(xMin) $xMin
187        }
188        if { $xMax > $_limits(xMax) } {
189            set _limits(xMax) $xMax
190        }
191        if { $yMin < $_limits(yMin) } {
192            set _limits(yMin) $yMin
193        }
194        if { $yMax > $_limits(yMax) } {
195            set _limits(yMax) $yMax
196        }
197        if { $zMin < $_limits(zMin) } {
198            set _limits(zMin) $zMin
199        }
200        if { $zMax > $_limits(zMax) } {
201            set _limits(zMax) $zMax
202        }
203    }
204    switch -- $which {
205        x {
206            set min $_limits(xMin)
207            set max $_limits(xMax)
208            set axis "xaxis"
209        }
210        y {
211            set min $_limits(yMin)
212            set max $_limits(yMax)
213            set axis "yaxis"
214        }
215        v - z {
216            set min $_limits(zMin)
217            set max $_limits(zMax)
218            set axis "zaxis"
219        }
220        default {
221            error "unknown axis description \"$which\""
222        }
223    }
224    return [list $min $max]
225}
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# ----------------------------------------------------------------------
235itcl::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}
258
Note: See TracBrowser for help on using the repository browser.