source: branches/uq/gui/scripts/unirect3d.tcl @ 5121

Last change on this file since 5121 was 5121, checked in by dkearney, 10 years ago

merging updates from 1.3 branch

looks like this branch originally came from the 1.3 branch and then had some
additions from the 1.4-pre branch and then a sync from the 1.3 branch. to get
this branch updated, I am reverting r4797 (additions from 1.4-pre branch),
reverting r4798 (additions from 1.3 branch), then merging in updates from 1.3
branch.

I fixed merge conflicts for the following files:

gui/scripts/gauge.tcl
gui/scripts/main.tcl
gui/scripts/tool.tcl
lang/tcl/scripts/task.tcl

File size: 10.0 KB
Line 
1# -*- mode: tcl; indent-tabs-mode: nil -*-
2
3# ----------------------------------------------------------------------
4#  COMPONENT: unirect3d - represents a uniform rectangular 2-D mesh.
5#
6#  This object represents one field in an XML description of a device.
7#  It simplifies the process of extracting data vectors that represent
8#  the field.
9# ======================================================================
10#  AUTHOR:  Michael McLennan, Purdue University
11#  Copyright (c) 2004-2012  HUBzero Foundation, LLC
12#
13#  See the file "license.terms" for information on usage and
14#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
15# ======================================================================
16package require Itcl
17package require BLT
18
19namespace eval Rappture { # forward declaration }
20
21itcl::class Rappture::Unirect3d {
22    constructor {xmlobj field cname {extents 1}} { # defined below }
23    destructor { # defined below }
24
25    public method limits {axis}
26    public method blob {}
27    public method mesh {}
28    public method values {}
29    public method valuesObj {}
30    public method units { axis }
31    public method label { axis }
32    public method hints {{keyword ""}}
33    public method order {} {
34        return _axisOrder;
35    }
36    private method GetString { obj path varName }
37    private method GetValue { obj path varName }
38    private method GetSize { obj path varName }
39
40    private variable _axisOrder  "x y z"
41    private variable _xMax       0
42    private variable _xMin       0
43    private variable _xNum       0;     # Number of points along x-axis
44    private variable _yMax       0
45    private variable _yMin       0
46    private variable _yNum       0;     # Number of points along y-axis
47    private variable _zMax       0
48    private variable _zMin       0
49    private variable _zNum       0;     # Number of points along z-axis
50    private variable _compNum    1;     # Number of components in values
51    private variable _values     "";    # BLT vector containing the values
52    private variable _hints
53}
54
55# ----------------------------------------------------------------------
56# Constructor
57# ----------------------------------------------------------------------
58itcl::body Rappture::Unirect3d::constructor {xmlobj field cname {extents 1}} {
59    if {![Rappture::library isvalid $xmlobj]} {
60        error "bad value \"$xmlobj\": should be Rappture::library"
61    }
62    set path [$field get $cname.mesh]
63    set m [$xmlobj element -as object $path]
64    GetValue $m "xaxis.max" _xMax
65    GetValue $m "xaxis.min" _xMin
66    GetValue $m "yaxis.max" _yMax
67    GetValue $m "yaxis.min" _yMin
68    GetValue $m "zaxis.max" _zMax
69    GetValue $m "zaxis.min" _zMin
70    GetSize $m "xaxis.numpoints" _xNum
71    GetSize $m "yaxis.numpoints" _yNum
72    GetSize $m "zaxis.numpoints" _zNum
73    set _compNum $extents
74    foreach {key path} {
75        group   about.group
76        label   about.label
77        color   about.color
78        style   about.style
79        type    about.type
80        xlabel  xaxis.label
81        xdesc   xaxis.description
82        xunits  xaxis.units
83        xscale  xaxis.scale
84        ylabel  yaxis.label
85        ydesc   yaxis.description
86        yunits  yaxis.units
87        yscale  yaxis.scale
88        zlabel  zaxis.label
89        zdesc   zaxis.description
90        zunits  zaxis.units
91        zscale  zaxis.scale
92        order   about.axisorder
93    } {
94        set str [$m get $path]
95        if {"" != $str} {
96            set _hints($key) $str
97        }
98    }
99    foreach {key} { axisorder } {
100        set str [$field get $cname.$key]
101        if {"" != $str} {
102            set _hints($key) $str
103        }
104    }
105    itcl::delete object $m
106
107    set _values [blt::vector create #auto]
108    $_values set [$field get "$cname.values"]
109    set n [expr $_xNum * $_yNum * $_zNum * $_compNum]
110    if { [$_values length] != $n } {
111        error "wrong \# of values in \"$cname.values\": expected $n values, got [$_values length]"
112    }
113}
114
115# ----------------------------------------------------------------------
116# Destructor
117# ----------------------------------------------------------------------
118itcl::body Rappture::Unirect3d::destructor {} {
119    if { $_values != "" } {
120        blt::vector destroy $_values
121    }
122}
123
124# ----------------------------------------------------------------------
125# method blob
126#       Returns a Tcl list that represents the Tcl command and data to
127#       recreate the uniform rectangular grid on the nanovis server.
128# ----------------------------------------------------------------------
129itcl::body Rappture::Unirect3d::blob {} {
130    lappend data "unirect3d"
131    lappend data "xmin" $_xMin "xmax" $_xMax "xnum" $_xNum
132    lappend data "ymin" $_yMin "ymax" $_yMax "ynum" $_yNum
133    lappend data "zmin" $_zMin "zmax" $_zMax "znum" $_zNum
134    lappend data "axisorder" $_axisOrder
135    if { [$_values length] > 0 } {
136        lappend data "values" [$_values range 0 end]
137    }
138    return $data
139}
140
141# ----------------------------------------------------------------------
142# method mesh
143#       Returns a Tcl list that represents the points  of the uniform
144#       grid.
145# ----------------------------------------------------------------------
146itcl::body Rappture::Unirect3d::mesh {} {
147    set dx [expr {($_xMax - $_xMin) / double($_xNum)}]
148    set dy [expr {($_yMax - $_yMin) / double($_yNum)}]
149    set dz [expr {($_zMax - $_zMin) / double($_zNum)}]
150    foreach {a b c} $_axisOrder break
151    for { set i 0 } { $i < [set _${a}Num] } { incr i } {
152        set v1 [expr {[set _${a}Min] + (double($i) * [set d${a}])}]
153        for { set j 0 } { $j < [set _${b}Num] } { incr j } {
154            set v2 [expr {[set _${b}Min] + (double($i) * [set d${b}])}]
155            for { set k 0 } { $k < [set _${c}Num] } { incr k } {
156                set v3 [expr {[set _${c}Min] + (double($i) * [set d${c}])}]
157                lappend data $v1 $v2 $v3
158            }
159        }
160    }
161    return $data
162}
163
164# ----------------------------------------------------------------------
165# method values
166#       Returns a Tcl list that represents the field values
167# ----------------------------------------------------------------------
168itcl::body Rappture::Unirect3d::values {} {
169    if { [$_values length] > 0 } {
170        return [$_values range 0 end]
171    }
172    return ""
173}
174
175# ----------------------------------------------------------------------
176# method valuesObj
177#       Returns a BLT vector that represents the field values
178# ----------------------------------------------------------------------
179itcl::body Rappture::Unirect3d::valuesObj {} {
180    return $_values
181}
182
183# ----------------------------------------------------------------------
184# method limits <axis>
185#       Returns a list {min max} representing the limits for the
186#       specified axis.
187# ----------------------------------------------------------------------
188itcl::body Rappture::Unirect3d::limits {which} {
189    set min ""
190    set max ""
191
192    switch -- $which {
193        x - xlin - xlog {
194            set min $_xMin
195            set max $_xMax
196        }
197        y - ylin - ylog {
198            set min $_yMin
199            set max $_yMax
200        }
201        z - zlin - zlog {
202            set min $_zMin
203            set max $_zMax
204        }
205        v - vlin - vlog {
206            if { [$_values length] > 0 } {
207               set min [blt::vector expr min($_values)]
208               set max [blt::vector expr max($_values)]
209            } else {
210                set min 0.0
211                set max 1.0
212            }
213        }
214        default {
215            error "unknown axis description \"$which\""
216        }
217    }
218    return [list $min $max]
219}
220
221#
222# units --
223#
224#       Returns the units of the given axis.
225#
226itcl::body Rappture::Unirect3d::units { axis } {
227    if { [info exists _hints({$axis}units)] } {
228        return $_hints(${axis}units)
229    }
230    return ""
231}
232
233#
234# label --
235#
236#       Returns the label of the given axis.
237#
238itcl::body Rappture::Unirect3d::label { axis } {
239    if { [info exists _hints({$axis}label)] } {
240        return $_hints(${axis}label)
241    }
242    return ""
243}
244
245# ----------------------------------------------------------------------
246# USAGE: hints ?<keyword>?
247#
248# Returns a list of key/value pairs for various hints about plotting
249# this curve.  If a particular <keyword> is specified, then it returns
250# the hint for that <keyword>, if it exists.
251# ----------------------------------------------------------------------
252itcl::body Rappture::Unirect3d::hints {{keyword ""}} {
253    if {[info exists _hints(xlabel)] && "" != $_hints(xlabel)
254        && [info exists _hints(xunits)] && "" != $_hints(xunits)} {
255        set _hints(xlabel) "$_hints(xlabel) ($_hints(xunits))"
256    }
257    if {[info exists _hints(ylabel)] && "" != $_hints(ylabel)
258        && [info exists _hints(yunits)] && "" != $_hints(yunits)} {
259        set _hints(ylabel) "$_hints(ylabel) ($_hints(yunits))"
260    }
261    if {[info exists _hints(zlabel)] && "" != $_hints(zlabel)
262        && [info exists _hints(zunits)] && "" != $_hints(zunits)} {
263        set _hints(ylabel) "$_hints(zlabel) ($_hints(zunits))"
264    }
265
266    if {[info exists _hints(group)] && [info exists _hints(label)]} {
267        # pop-up help for each curve
268        set _hints(tooltip) $_hints(label)
269    }
270    if {$keyword != ""} {
271        if {[info exists _hints($keyword)]} {
272            return $_hints($keyword)
273        }
274        return ""
275    }
276    return [array get _hints]
277}
278
279itcl::body Rappture::Unirect3d::GetSize { obj path varName } {
280    set string [$obj get $path]
281    if { [scan $string "%d" value] != 1 || $value < 0 } {
282        puts stderr "can't get size \"$string\" of \"$path\""
283        return
284    }
285    upvar $varName size
286    set size $value
287}
288
289itcl::body Rappture::Unirect3d::GetValue { obj path varName } {
290    set string [$obj get $path]
291    if { [scan $string "%g" value] != 1 } {
292        puts stderr "can't get value \"$string\" of \"$path\""
293        return
294    }
295    upvar $varName number
296    set number $value
297}
298
299itcl::body Rappture::Unirect3d::GetString { obj path varName } {
300    set string [$obj get $path]
301    if { $string == "" } {
302        puts stderr "can't get string \"$string\" of \"$path\""
303        return
304    }
305    upvar $varName str
306    set str $string
307}
Note: See TracBrowser for help on using the repository browser.