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

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