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

Last change on this file since 3582 was 3330, checked in by gah, 11 years ago

merge (by hand) with Rappture1.2 branch

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