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

Last change on this file since 6480 was 5762, checked in by ldelgass, 9 years ago

reorder hints list

File size: 7.7 KB
Line 
1# -*- mode: tcl; indent-tabs-mode: nil -*-
2# ----------------------------------------------------------------------
3#  COMPONENT: drawing - 3D drawing of data
4# ======================================================================
5#  AUTHOR:  Michael McLennan, Purdue University
6#  Copyright (c) 2004-2012  HUBzero Foundation, LLC
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
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 _styles
38    private variable _shapes
39    private variable _labels
40    private variable _types
41    private variable _data
42    private variable _hints
43    private variable _units
44}
45
46# ----------------------------------------------------------------------
47# Constructor
48# ----------------------------------------------------------------------
49itcl::body Rappture::Drawing::constructor {xmlobj path} {
50    if {![Rappture::library isvalid $xmlobj]} {
51        error "bad value \"$xmlobj\": should be Rappture::library"
52    }
53    set _xmlobj $xmlobj
54    set _drawing [$xmlobj element -as object $path]
55    set _units [$_drawing get units]
56
57    set xunits [$xmlobj get units]
58    if {"" == $xunits || "arbitrary" == $xunits} {
59        set xunits "um"
60    }
61    # determine the overall size of the device
62    foreach elem [$_xmlobj children $path] {
63        switch -glob -- $elem {
64            # polygon is deprecated in favor of polydata
65            polygon* - polydata* {
66                set _data($elem) [$_xmlobj get $path.$elem.vtk]
67                set _data($elem) [string trim $_data($elem)]
68                set _styles($elem) [$_xmlobj get $path.$elem.about.style]
69                set _labels($elem) [$_xmlobj get $path.$elem.about.label]
70                set _types($elem) polydata
71            }
72            glyphs* {
73                set _data($elem) [$_xmlobj get $path.$elem.vtk]
74                set _data($elem) [string trim $_data($elem)]
75                set _styles($elem) [$_xmlobj get $path.$elem.about.style]
76                set _labels($elem) [$_xmlobj get $path.$elem.about.label]
77                set _shapes($elem) [$_xmlobj get $path.$elem.about.shape]
78                set _types($elem) glyphs
79            }
80            molecule* {
81                set pdbdata [$_xmlobj get $path.$elem.pdb]
82                if { $pdbdata != "" } {
83                    set contents [Rappture::PdbToVtk $pdbdata]
84                } else {
85                    set contents [$_xmlobj get $path.$elem.vtk]
86                }
87                set _data($elem) [string trim $contents]
88                set _styles($elem) [$_xmlobj get $path.$elem.about.style]
89                set _labels($elem) [$_xmlobj get $path.$elem.about.label]
90                set _types($elem) molecule
91            }
92        }
93    }
94    foreach {key path} {
95        camera  about.camera
96        color   about.color
97        group   about.group
98        label   about.label
99        type    about.type
100        xdesc   xaxis.description
101        ydesc   yaxis.description
102        zdesc   zaxis.description
103        xlabel  xaxis.label
104        ylabel  yaxis.label
105        zlabel  zaxis.label
106        xscale  xaxis.scale
107        yscale  yaxis.scale
108        zscale  zaxis.scale
109        xunits  xaxis.units
110        yunits  yaxis.units
111        zunits  zaxis.units
112        xmin    xaxis.min
113        xmax    xaxis.max
114        ymin    yaxis.min
115        ymax    yaxis.max
116        zmin    zaxis.min
117        zmax    zaxis.max
118    } {
119        set str [$_drawing get $path]
120        if {"" != $str} {
121            set _hints($key) $str
122        }
123    }
124    foreach {key path} {
125        toolid          tool.id
126        toolname        tool.name
127        toolcommand     tool.execute
128        tooltitle       tool.title
129        toolrevision    tool.version.application.revision
130    } {
131        set str [$_xmlobj get $path]
132        if { "" != $str } {
133            set _hints($key) $str
134        }
135    }
136}
137
138# ----------------------------------------------------------------------
139# Destructor
140# ----------------------------------------------------------------------
141itcl::body Rappture::Drawing::destructor {} {
142    # empty
143}
144
145#
146# label --
147#
148#       Returns the label of the named drawing element.
149#
150itcl::body Rappture::Drawing::label { elem } {
151    if { [info exists _labels($elem)] } {
152        return $_labels($elem)
153    }
154    return ""
155}
156
157#
158# type --
159#
160#       Returns the type of the named drawing element.
161#
162itcl::body Rappture::Drawing::type { elem } {
163    if { [info exists _types($elem)] } {
164        return $_types($elem)
165    }
166    return ""
167}
168
169#
170# style --
171#
172#       Returns the style string of the named drawing element.
173#
174itcl::body Rappture::Drawing::style { elem } {
175    if { [info exists _styles($elem)] } {
176        return $_styles($elem)
177    }
178    return ""
179}
180
181#
182# shape --
183#
184#       Returns the shape of the glyphs in the drawing element.
185#
186itcl::body Rappture::Drawing::shape { elem } {
187    set shape ""
188    if { [info exists _shapes($elem)] } {
189        return $_shapes($elem)
190    }
191    switch -- $shape {
192        arrow - cone - cube - cylinder - dodecahedron -
193        icosahedron - line - octahedron - sphere - tetrahedron  {
194            return $shape
195        }
196        default {
197            puts stderr "unknown glyph shape \"$shape\""
198        }
199    }
200    return ""
201}
202
203#
204# data --
205#
206#       Returns the data of the named drawing element.
207#
208itcl::body Rappture::Drawing::data { elem } {
209    if { [info exists _data($elem)] } {
210        return $_data($elem)
211    }
212    return ""
213}
214
215# ----------------------------------------------------------------------
216# method values
217#       Returns a base64 encoded, gzipped Tcl list that represents the
218#       Tcl command and data to recreate the uniform rectangular grid
219#       on the nanovis server.
220# ----------------------------------------------------------------------
221itcl::body Rappture::Drawing::values { elem } {
222    if { [info exists _data($elem)] } {
223        return $_data($elem)
224    }
225    return ""
226}
227
228itcl::body Rappture::Drawing::components { args } {
229    return [array names _data]
230}
231
232# ----------------------------------------------------------------------
233# USAGE: hints ?<keyword>?
234#
235# Returns a list of key/value pairs for various hints about plotting
236# this curve.  If a particular <keyword> is specified, then it returns
237# the hint for that <keyword>, if it exists.
238# ----------------------------------------------------------------------
239itcl::body Rappture::Drawing::hints { {keyword ""} } {
240    if 0 {
241    if {[info exists _hints(xlabel)] && "" != $_hints(xlabel)
242        && [info exists _hints(xunits)] && "" != $_hints(xunits)} {
243        set _hints(xlabel) "$_hints(xlabel) ($_hints(xunits))"
244    }
245    if {[info exists _hints(ylabel)] && "" != $_hints(ylabel)
246        && [info exists _hints(yunits)] && "" != $_hints(yunits)} {
247        set _hints(ylabel) "$_hints(ylabel) ($_hints(yunits))"
248    }
249    }
250    if {[info exists _hints(group)] && [info exists _hints(label)]} {
251        # pop-up help for each curve
252        set _hints(tooltip) $_hints(label)
253    }
254    if {$keyword != ""} {
255        if {[info exists _hints($keyword)]} {
256            return $_hints($keyword)
257        }
258        return ""
259    }
260    return [array get _hints]
261}
Note: See TracBrowser for help on using the repository browser.