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

Last change on this file since 4288 was 4002, checked in by gah, 11 years ago

remove dead code

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