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

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

fixes for drawingentry

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