source: trunk/gui/scripts/unirect2d.tcl @ 1373

Last change on this file since 1373 was 1373, checked in by gah, 12 years ago

First pass at changes to visualization widgets.

nanovisview.tcl use png icons.
visviewer.tcl change to sidebar layout
molvisviewer.tcl use png icons, fixed for sidebar layout.
heightmapviewer.tcl use png icons, fixed for sidebar layout.
flowvisviewer.tcl use png icons, fixed for sidebar layout.

resultviewer.tcl recognize flow data
field.tcl recognize unirect3d mesh.
field3dresult.tcl load FlowvisViewer? component description.
panes.tcl added horizontal panes. Need cursor fix. Must specify

correct cursor from options.

unirect2d.tcl added "axisorder" tag to specify order of field data.

Changed name to Unirect2d from UniRect2d.

unirect3d.tcl added "axisorder" tag to specify order of field data.

Right now, this is a test platform for me for flow
visualizations.

File size: 7.3 KB
Line 
1
2# ----------------------------------------------------------------------
3#  COMPONENT: unirect2d - represents a uniform rectangular 2-D mesh.
4#
5#  This object represents one field in an XML description of a device.
6#  It simplifies the process of extracting data vectors that represent
7#  the field.
8# ======================================================================
9#  AUTHOR:  Michael McLennan, Purdue University
10#  Copyright (c) 2004-2005  Purdue Research Foundation
11#
12#  See the file "license.terms" for information on usage and
13#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14# ======================================================================
15package require Itcl
16package require BLT
17
18namespace eval Rappture { # forward declaration }
19
20itcl::class Rappture::Unirect2d {
21    constructor {xmlobj field cname} { # defined below }
22    destructor { # defined below }
23
24    public method limits {axis}
25    public method blob {}
26    public method mesh {}
27    public method values {}
28    public method hints {{keyword ""}}
29
30    private variable _xmax 0
31    private variable _xmin 0
32    private variable _xnum 0
33    private variable _ymax 0
34    private variable _ymin 0
35    private variable _ynum 0
36    private variable _values "";        # BLT vector containing the z-values
37    private variable _hints
38}
39
40# ----------------------------------------------------------------------
41# Constructor
42# ----------------------------------------------------------------------
43itcl::body Rappture::Unirect2d::constructor {xmlobj field cname} {
44    if {![Rappture::library isvalid $xmlobj]} {
45        error "bad value \"$xmlobj\": should be Rappture::library"
46    }
47    set path [$field get $cname.mesh]
48
49    set mobj [$xmlobj element -as object $path]
50    set _xmin [$mobj get "xaxis.min"]
51    set _xmax [$mobj get "xaxis.max"]
52    set _xnum [$mobj get "xaxis.numpoints"]
53    set _ymin [$mobj get "yaxis.min"]
54    set _ymax [$mobj get "yaxis.max"]
55    set _ynum [$mobj get "yaxis.numpoints"]
56   
57    foreach {key path} {
58        group   about.group
59        label   about.label
60        color   about.color
61        style   about.style
62        type    about.type
63        xlabel  xaxis.label
64        xdesc   xaxis.description
65        xunits  xaxis.units
66        xscale  xaxis.scale
67        xmin    xaxis.min
68        xmax    xaxis.max
69        ylabel  yaxis.label
70        ydesc   yaxis.description
71        yunits  yaxis.units
72        yscale  yaxis.scale
73        ymin    yaxis.min
74        ymax    yaxis.max
75    } {
76        set str [$mobj get $path]
77        if {"" != $str} {
78            set _hints($key) $str
79        }
80    }
81    foreach {key} { extents axisorder } {
82        set str [$field get $cname.$key]
83        if {"" != $str} {
84            set _hints($key) $str
85        }
86    }
87    itcl::delete object $mobj
88   
89    set _values [blt::vector create \#auto]
90    set values [$field get "$cname.values"]
91    if { $values == "" } {
92        set values [$field get "$cname.zvalues"]
93    }
94    $_values set $values
95}
96
97# ----------------------------------------------------------------------
98# Destructor
99# ----------------------------------------------------------------------
100itcl::body Rappture::Unirect2d::destructor {} {
101    if { $_values != "" } {
102        blt::vector destroy $_values
103    }
104}
105
106# ----------------------------------------------------------------------
107# method blob
108#       Returns a base64 encoded, gzipped Tcl list that represents the
109#       Tcl command and data to recreate the uniform rectangular grid
110#       on the nanovis server.
111# ----------------------------------------------------------------------
112itcl::body Rappture::Unirect2d::blob {} {
113    set data "unirect2d"
114    lappend data "xmin" $_xmin "xmax" $_xmax "xnum" $_xnum
115    lappend data "ymin" $_ymin "ymax" $_ymax "ynum" $_ynum
116    lappend data "xmin" $_xmin "ymin" $_ymin "xmax" $_xmax "ymax" $_ymax
117    foreach key { axisorder extents xunits yunits units } {
118        set hint [hints $key]
119        if { $hint != "" } {
120            lappend data $key $hint
121        }
122    }
123    if { [$_values length] > 0 } {
124        lappend data "values" [$_values range 0 end]
125    }
126    return [Rappture::encoding::encode -as zb64 $data]
127}
128
129# ----------------------------------------------------------------------
130# method mesh
131#       Returns a base64 encoded, gzipped Tcl list that represents the
132#       Tcl command and data to recreate the uniform rectangular grid
133#       on the nanovis server.
134# ----------------------------------------------------------------------
135itcl::body Rappture::Unirect2d::mesh {} {
136    set dx [expr {($_xmax - $_xmin) / double($_xnum)}]
137    set dy [expr {($_ymax - $_ymin) / double($_ynum)}]
138    for { set i 0 } { $i < $_xnum } { incr i } {
139        set x [expr {$_xmin + (double($i) * $dx)}]
140        for { set j 0 } { $j < $_ynum } { incr j } {
141            set y [expr {$_ymin + (double($i) * $dy)}]
142            lappend data $x $y
143        }
144    }
145    return $data
146}
147
148# ----------------------------------------------------------------------
149# method values
150#       Returns a base64 encoded, gzipped Tcl list that represents the
151#       Tcl command and data to recreate the uniform rectangular grid
152#       on the nanovis server.
153# ----------------------------------------------------------------------
154itcl::body Rappture::Unirect2d::values {} {
155    if { [$_values length] > 0 } {
156        return [$_values range 0 end]
157    }
158    return ""
159}
160
161# ----------------------------------------------------------------------
162# method limits <axis>
163#       Returns a list {min max} representing the limits for the
164#       specified axis.
165# ----------------------------------------------------------------------
166itcl::body Rappture::Unirect2d::limits {which} {
167    set min ""
168    set max ""
169
170    switch -- $which {
171        x - xlin - xlog {
172            set min $_xmin
173            set max $_xmax
174            set axis "xaxis"
175        }
176        y - ylin - ylog {
177            set min $_ymin
178            set max $_ymax
179            set axis "yaxis"
180        }
181        v - vlin - vlog - z - zlin - zlog {
182            if { [$_values length] > 0 } {
183               set min [blt::vector expr min($_values)]
184               set max [blt::vector expr max($_values)]
185            } else {
186                set min 0.0
187                set max 1.0
188            }
189            set axis "zaxis"
190        }
191        default {
192            error "unknown axis description \"$which\""
193        }
194    }
195#     set val [$_field get $axis.min]
196#     if {"" != $val && "" != $min} {
197#         if {$val > $min} {
198#             # tool specified this min -- don't go any lower
199#             set min $val
200#         }
201#     }
202#     set val [$_field get $axis.max]
203#     if {"" != $val && "" != $max} {
204#         if {$val < $max} {
205#             # tool specified this max -- don't go any higher
206#             set max $val
207#         }
208#     }
209
210    return [list $min $max]
211}
212
213
214# ----------------------------------------------------------------------
215# USAGE: hints ?<keyword>?
216#
217# Returns a list of key/value pairs for various hints about plotting
218# this curve.  If a particular <keyword> is specified, then it returns
219# the hint for that <keyword>, if it exists.
220# ----------------------------------------------------------------------
221itcl::body Rappture::Unirect2d::hints { {keyword ""} } {
222    if {[info exists _hints(xlabel)] && "" != $_hints(xlabel)
223        && [info exists _hints(xunits)] && "" != $_hints(xunits)} {
224        set _hints(xlabel) "$_hints(xlabel) ($_hints(xunits))"
225    }
226    if {[info exists _hints(ylabel)] && "" != $_hints(ylabel)
227        && [info exists _hints(yunits)] && "" != $_hints(yunits)} {
228        set _hints(ylabel) "$_hints(ylabel) ($_hints(yunits))"
229    }
230   
231    if {[info exists _hints(group)] && [info exists _hints(label)]} {
232        # pop-up help for each curve
233        set _hints(tooltip) $_hints(label)
234    }
235    if {$keyword != ""} {
236        if {[info exists _hints($keyword)]} {
237            return $_hints($keyword)
238        }
239        return ""
240    }
241    return [array get _hints]
242}
Note: See TracBrowser for help on using the repository browser.