source: trunk/gui/apps/driver @ 10

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

Massive changes across the entire toolkit. Rearranged the
XML description to agree better with new documentation and
conventions.

Added a small start of Rappture.interface and Rappture.number
in the python directory. This is the new way of doing Rappture--
by declaring variables directly in the program, not using XML
directly at all.

File size: 9.4 KB
Line 
1#!/bin/sh
2# ----------------------------------------------------------------------
3#  USER INTERFACE DRIVER
4#
5#  This driver program loads a tool description from a tool.xml file,
6#  and a UI configuration from a config.xml file, and produces a
7#  user interface automatically to drive an application.  The user
8#  can set up input, click and button to launch a tool, and browse
9#  through output.
10#
11#  RUN AS FOLLOWS:
12#    driver ?-tool <toolfile>? ?-config <configfile>?
13#
14#  If the <toolfile> is not specified, this program looks for a
15#  file called "tool.xml" in the current directory.  If the <configfile>
16#  is not specified, it looks for "config.xml" in the current directory.
17#
18# ======================================================================
19#  AUTHOR:  Michael McLennan, Purdue University
20#  Copyright (c) 2004  Purdue Research Foundation, West Lafayette, IN
21# ======================================================================
22#\
23exec wish "$0" $*
24# ----------------------------------------------------------------------
25# wish executes everything from here on...
26
27package require Rappture
28
29option add *MainWin.mode desktop startupFile
30option add *MainWin.borderWidth 0 startupFile
31option add *MainWin.anchor center startupFile
32
33# "web site" look
34option add *MainWin.bgScript {
35    rectangle 0 0 200 <h> -outline "" -fill #5880BB
36    rectangle 200 0 300 <h> -outline "" -fill #425F8B
37    rectangle 300 0 <w> <h> -outline "" -fill #324565
38} startupFile
39
40# "clean" look
41option add *MainWin.bgScript "" startupFile
42option add *MainWin.bgColor white startupFile
43option add *Tooltip.background white
44
45image create photo in2out \
46    -file [file join $Rappture::installdir scripts images in2out.gif]
47
48#
49# Process command line args to get the names of files to load...
50#
51set toolfile "tool.xml"
52set configfile "config.xml"
53
54while {[llength $argv] > 0} {
55    set first [lindex $argv 0]
56    set argv [lrange $argv 1 end]
57
58    switch -- $first {
59        -tool {
60            if {[llength $argv] > 0} {
61                set toolfile [lindex $argv 0]
62                set argv [lrange $argv 1 end]
63            } else {
64                puts stderr "$argv0: missing value for -tool"
65                exit 1
66            }
67        }
68        -config {
69            if {[llength $argv] > 0} {
70                set configfile [lindex $argv 0]
71                set argv [lrange $argv 1 end]
72            } else {
73                puts stderr "$argv0: missing value for -tool"
74                exit 1
75            }
76        }
77        default {
78            puts stderr "usage: $argv0 ?-tool file? ?-config file?"
79            exit 1
80        }
81    }
82}
83
84# open the XML file containing the material library
85set lib [Rappture::library -std library.xml]
86                                                                               
87# open the XML file containing the tool parameters
88if {![file exists $toolfile]} {
89    puts stderr "tool file \"$toolfile\" doesn't exist"
90    exit 1
91}
92set tool [Rappture::library $toolfile]
93                                                                               
94# open the XML file containing the configuration for this application
95if {![file exists $configfile]} {
96    puts stderr "config file \"$configfile\" doesn't exist"
97    exit 1
98}
99set config [Rappture::library $configfile]
100
101# ----------------------------------------------------------------------
102# From here on, run in the directory containing the tool.xml file,
103# so driver.xml files, etc., are created there
104# ----------------------------------------------------------------------
105cd [file dirname $toolfile]
106
107# ----------------------------------------------------------------------
108# USAGE: main_device_select
109#
110# Invoked automatically when a user selects a new device from the
111# "Devices:" combobox.  Plugs the new device into the device viewer.
112# ----------------------------------------------------------------------
113proc main_device_select {} {
114    set win [.main component app]
115    set val [$win.input.devsel.dev value]
116    set val [$win.input.devsel.dev translate $val]
117    $win.input.device configure -device $val
118    $win.output.analyze configure -device $val
119}
120
121# ----------------------------------------------------------------------
122# MAIN WINDOW
123# ----------------------------------------------------------------------
124wm withdraw .
125Rappture::MainWin .main -borderwidth 0
126
127.main configure -title [$config get title]
128
129# build everything inside this main window
130set win [.main component app]
131#$win configure -background #a6a6a6
132
133frame $win.input -borderwidth 12 -relief flat
134pack $win.input -side left -expand yes -fill both -padx {0 5}
135
136frame $win.output -borderwidth 12 -relief flat
137pack $win.output -side left -expand yes -fill both -padx {5 0}
138
139# make an arrow that goes from input to output side
140#label $win.arrow -borderwidth 0 -image in2out
141#place $win.arrow -y 2 -anchor n
142#bind $win.input <Configure> [list align_arrow $win]
143#proc align_arrow {win} {
144#    place $win.arrow -x [expr {[winfo width $win.input]+5}]
145#}
146
147# ----------------------------------------------------------------------
148# INPUT AREA
149# ----------------------------------------------------------------------
150set w $win.input
151set dfirst ""
152set dlist [$config children -type structure controls]
153if {"" != $dlist} {
154    foreach dname $dlist {
155        set obj [$config element -flavor object controls.$dname]
156        set name [$obj get label]
157        set devs($name) $obj
158    }
159    set devlist [lsort [array names devs]]
160
161    if {[array size devs] > 1} {
162        frame $w.devsel
163        pack $w.devsel -side top -fill x
164        label $w.devsel.l -text "Device:"
165        pack $w.devsel.l -side left
166        Rappture::Combobox $w.devsel.dev -width 30 -editable no
167        pack $w.devsel.dev -side left
168        bind $w.devsel.dev <<Value>> main_device_select
169
170        foreach name $devlist {
171            $w.devsel.dev choices insert end $devs($name) $name
172        }
173        $w.devsel.dev value [lindex $devlist 0]
174    }
175
176    set first [lindex $devlist 0]
177    set dfirst $devs($first)
178    set tags [$dfirst children components]
179    set i [lsearch $tags label]
180    if {$i >= 0} {set tags [lreplace $tags $i $i]}
181
182    if {$tags == "molecule"} {
183        Rappture::MoleculeViewer $w.device -device $devs($first) \
184            -library $lib
185    } else {
186        Rappture::DeviceViewer1D $w.device -device $devs($first) \
187            -tool $tool -library $lib
188    }
189    pack $w.device -expand yes -fill both
190
191    bind $w.device <<Edit>> [list $win.output.analyze reset]
192}
193
194# ----------------------------------------------------------------------
195# OUTPUT AREA
196# ----------------------------------------------------------------------
197set w $win.output
198Rappture::Analyzer $w.analyze -holdwindow $win.input \
199    -tool $tool -analysis [$config element -flavor object analysis] \
200    -device $dfirst
201pack $w.analyze -expand yes -fill both
202
203# ----------------------------------------------------------------------
204# HOOK UP ANY CONTROLS CALLED OUT IN CONFIG.XML
205# ----------------------------------------------------------------------
206proc controls_add {container libObj path} {
207    set presets ""
208    foreach pre [$libObj children -type preset $path] {
209        lappend presets \
210            [$libObj get $path.$pre.value] \
211            [$libObj get $path.$pre.label]
212    }
213
214    set type Rappture::Gauge
215    set units [$libObj get $path.units]
216    if {$units != ""} {
217        set desc [Rappture::Units::description $units]
218        if {[string match temperature* $desc]} {
219            set type Rappture::TemperatureGauge
220        }
221    }
222
223    set counter 0
224    set w "$container.gauge[incr counter]"
225    while {[winfo exists $w]} {
226        set w "$container.gauge[incr counter]"
227    }
228
229    # create the widget
230    $type $w -units $units -presets $presets
231    pack $w -side top -anchor w
232#    bind $w <<Value>> [itcl::code $this _controlSet $w $libObj $path]
233
234    set min [$libObj get $path.min]
235    if {"" != $min} { $w configure -minvalue $min }
236
237    set max [$libObj get $path.max]
238    if {"" != $max} { $w configure -maxvalue $max }
239
240    set str [$libObj get $path.default]
241    if {$str != ""} { $w value $str }
242
243    if {$type == "Rappture::Gauge" && "" != $min && "" != $max} {
244        set color [$libObj get $path.color]
245        if {$color == ""} {
246            set color blue
247        }
248        if {$units != ""} {
249            set min [Rappture::Units::convert $min -to $units -units off]
250            set max [Rappture::Units::convert $max -to $units -units off]
251        }
252        $w configure -spectrum [Rappture::Spectrum ::#auto [list \
253            $min white $max $color] -units $units]
254    }
255
256    set str [$libObj get $path.label]
257    if {$str != ""} {
258        set help [$libObj get $path.help]
259        if {"" != $help} {
260            append str "\n$help"
261        }
262        if {$units != ""} {
263            set desc [Rappture::Units::description $units]
264            append str "\n(units of $desc)"
265        }
266        Rappture::Tooltip::for $w $str
267    }
268
269    set str [$libObj get $path.icon]
270    if {$str != ""} {
271        $w configure -image [image create photo -data $str]
272    }
273}
274
275if {[winfo exists $win.input.device]} {
276    foreach access [$config children -type access controls] {
277        set name [$config get controls.$access]
278        switch -glob -- $name {
279            input.(ambient)* - structure* {
280                $win.input.device controls add $name
281            }
282        }
283    }
284} else {
285    foreach access [$config children -type access controls] {
286        set name [$config get controls.$access]
287        controls_add $win.input $tool $name
288    }
289    $w.analyze simulate
290}
Note: See TracBrowser for help on using the repository browser.