source: trunk/gui/scripts/table.tcl @ 11

Last change on this file since 11 was 11, checked in by mmc, 19 years ago

Major reorganization of the entire package. The config.xml file
is now irrelevant. All the action is in the tool.xml file. The
main program now organizes all input into 1) side-by-side pages,
2) input/result (wizard-style) pages, or 3) a series of wizard-
style pages. The <input> can have <phase> parts representing
the various pages.

Added a new ContourResult? widget based on Swaroop's vtk plotting
code.

Also, added easymesh and showmesh to the "tools" directory.
We need these for Eric Polizzi's code.

File size: 6.7 KB
Line 
1# ----------------------------------------------------------------------
2#  COMPONENT: table - extracts data from an XML description of a table
3#
4#  This object represents one table in an XML description of a device.
5#  It simplifies the process of extracting data representing columns
6#  in the table.
7# ======================================================================
8#  AUTHOR:  Michael McLennan, Purdue University
9#  Copyright (c) 2004-2005
10#  Purdue Research Foundation, West Lafayette, IN
11# ======================================================================
12package require Itcl
13package require BLT
14
15namespace eval Rappture { # forward declaration }
16
17itcl::class Rappture::Table {
18    constructor {libobj path} { # defined below }
19    destructor { # defined below }
20
21    public method rows {}
22    public method columns {{pattern *}}
23    public method vectors {{what -overall}}
24    public method hints {{key ""}}
25
26    protected method _build {}
27
28    private variable _units ""   ;# system of units for this table
29    private variable _limits     ;# maps slab name => {z0 z1} limits
30    private variable _zmax 0     ;# length of the device
31
32    private variable _table ""   ;# lib obj representing this table
33    private variable _tree ""    ;# BLT tree used to contain table data
34
35    private common _counter 0    ;# counter for unique vector names
36}
37
38# ----------------------------------------------------------------------
39# CONSTRUCTOR
40# ----------------------------------------------------------------------
41itcl::body Rappture::Table::constructor {libobj path} {
42    if {![Rappture::library isvalid $libobj]} {
43        error "bad value \"$libobj\": should be LibraryObj"
44    }
45    set _table [$libobj element -as object $path]
46    set _units [$_table get units]
47
48    # determine the overall size of the device
49    set z0 [set z1 0]
50    foreach elem [$_device children recipe] {
51        switch -glob -- $elem {
52            slab* - molecule* {
53                if {![regexp {[0-9]$} $elem]} {
54                    set elem "${elem}0"
55                }
56                set tval [$_device get recipe.$elem.thickness]
57                set tval [Rappture::Units::convert $tval \
58                    -context um -to um -units off]
59                set z1 [expr {$z0+$tval}]
60                set _limits($elem) [list $z0 $z1]
61
62                set z0 $z1
63            }
64        }
65    }
66    set _zmax $z1
67
68    # build up vectors for various components of the table
69    _build
70}
71
72# ----------------------------------------------------------------------
73# DESTRUCTOR
74# ----------------------------------------------------------------------
75itcl::body Rappture::Table::destructor {} {
76    itcl::delete object $_table
77    # don't destroy the _device! we don't own it!
78
79    foreach name [array names _comp2vecs] {
80        eval blt::vector destroy $_comp2vecs($name)
81    }
82}
83
84# ----------------------------------------------------------------------
85# USAGE: components ?<pattern>?
86#
87# Returns a list of names for the various components of this table.
88# If the optional glob-style <pattern> is specified, then it returns
89# only the component names matching the pattern.
90# ----------------------------------------------------------------------
91itcl::body Rappture::Table::components {{pattern *}} {
92    set rlist ""
93    foreach name [array names _comp2vecs] {
94        if {[string match $pattern $name]} {
95            lappend rlist $name
96        }
97    }
98    return $rlist
99}
100
101# ----------------------------------------------------------------------
102# USAGE: vectors ?<name>?
103#
104# Returns a list {xvec yvec} for the specified table component <name>.
105# If the name is not specified, then it returns the vectors for the
106# overall table (sum of all components).
107# ----------------------------------------------------------------------
108itcl::body Rappture::Table::vectors {{what -overall}} {
109    if {[info exists _comp2vecs($what)]} {
110        return $_comp2vecs($what)
111    }
112    error "bad option \"$what\": should be [join [lsort [array names _comp2vecs]] {, }]"
113}
114
115# ----------------------------------------------------------------------
116# USAGE: hints ?<keyword>?
117#
118# Returns a list of key/value pairs for various hints about plotting
119# this table.  If a particular <keyword> is specified, then it returns
120# the hint for that <keyword>, if it exists.
121# ----------------------------------------------------------------------
122itcl::body Rappture::Table::hints {{keyword ""}} {
123    foreach key {label scale color units restrict} {
124        set str [$_table get $key]
125        if {"" != $str} {
126            set hints($key) $str
127        }
128    }
129
130    if {$keyword != ""} {
131        if {[info exists hints($keyword)]} {
132            return $hints($keyword)
133        }
134        return ""
135    }
136    return [array get hints]
137}
138
139# ----------------------------------------------------------------------
140# USAGE: _build
141#
142# Used internally to build up the vector representation for the
143# table when the object is first constructed, or whenever the table
144# data changes.  Discards any existing vectors and builds everything
145# from scratch.
146# ----------------------------------------------------------------------
147itcl::body Rappture::Table::_build {} {
148    # discard any existing data
149    foreach name [array names _comp2vecs] {
150        eval blt::vector destroy $_comp2vecs($name)
151    }
152    catch {unset _comp2vecs}
153
154    #
155    # Scan through the components of the table and create
156    # vectors for each part.
157    #
158    foreach cname [$_table children -type component] {
159        set xv ""
160        set yv ""
161
162        set val [$_table get $cname.constant]
163        if {$val != ""} {
164            set domain [$_table get $cname.domain]
165            if {$domain == "" || ![info exists _limits($domain)]} {
166                set z0 0
167                set z1 $_zmax
168            } else {
169                foreach {z0 z1} $_limits($domain) { break }
170            }
171            set xv [blt::vector create x$_counter]
172            $xv append $z0 $z1
173
174            if {$_units != ""} {
175                set val [Rappture::Units::convert $val \
176                    -context $_units -to $_units -units off]
177            }
178            set yv [blt::vector create y$_counter]
179            $yv append $val $val
180
181            set zm [expr {0.5*($z0+$z1)}]
182        } else {
183            set xydata [$_table get $cname.xy]
184            if {"" != $xydata} {
185                set xv [blt::vector create x$_counter]
186                set yv [blt::vector create y$_counter]
187
188                foreach line [split $xydata \n] {
189                    if {[scan $line {%g %g} xval yval] == 2} {
190                        $xv append $xval
191                        $yv append $yval
192                    }
193                }
194            }
195        }
196
197        if {$xv != "" && $yv != ""} {
198            set _comp2vecs($cname) [list $xv $yv]
199            incr _counter
200        }
201    }
202}
Note: See TracBrowser for help on using the repository browser.