source: trunk/gui/apps/driver @ 7

Last change on this file since 7 was 7, checked in by mmc, 16 years ago

Created an initial EnergyLevels? viewer and MoleculeViewer?. The
MoleculeViewer? is integrated into the driver, but the EnergyLevels?
is not. The material library file contains some new properties
for the appearance of atoms, and the MoleculeViewer? uses this.
Both energyLevels.tcl and moleculeViewer.tcl still have some
driver code at the bottom of the files, so you can run them as
a single file, by themselves, for testing. This code should be
removed when we get further along.

File size: 7.2 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 web 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
43
44image create photo in2out \
45    -file [file join $Rappture::installdir scripts images in2out.gif]
46
47#
48# Process command line args to get the names of files to load...
49#
50set toolfile "tool.xml"
51set configfile "config.xml"
52
53while {[llength $argv] > 0} {
54    set first [lindex $argv 0]
55    set argv [lrange $argv 1 end]
56
57    switch -- $first {
58        -tool {
59            if {[llength $argv] > 0} {
60                set toolfile [lindex $argv 0]
61                set argv [lrange $argv 1 end]
62            } else {
63                puts stderr "$argv0: missing value for -tool"
64                exit 1
65            }
66        }
67        -config {
68            if {[llength $argv] > 0} {
69                set configfile [lindex $argv 0]
70                set argv [lrange $argv 1 end]
71            } else {
72                puts stderr "$argv0: missing value for -tool"
73                exit 1
74            }
75        }
76        default {
77            puts stderr "usage: $argv0 ?-tool file? ?-config file?"
78            exit 1
79        }
80    }
81}
82
83# open the XML file containing the material library
84set lib [Rappture::library -std library.xml]
85                                                                               
86# open the XML file containing the tool parameters
87if {![file exists $toolfile]} {
88    puts stderr "tool file \"$toolfile\" doesn't exist"
89    exit 1
90}
91set tool [Rappture::library $toolfile]
92                                                                               
93# open the XML file containing the configuration for this application
94if {![file exists $configfile]} {
95    puts stderr "config file \"$configfile\" doesn't exist"
96    exit 1
97}
98set config [Rappture::library $configfile]
99
100# ----------------------------------------------------------------------
101# From here on, run in the directory containing the tool.xml file,
102# so driver.xml files, etc., are created there
103# ----------------------------------------------------------------------
104cd [file dirname $toolfile]
105
106# ----------------------------------------------------------------------
107# USAGE: main_device_select
108#
109# Invoked automatically when a user selects a new device from the
110# "Devices:" combobox.  Plugs the new device into the device viewer.
111# ----------------------------------------------------------------------
112proc main_device_select {} {
113    set win [.main component app]
114    set val [$win.input.devsel.dev value]
115    set val [$win.input.devsel.dev translate $val]
116    $win.input.device configure -device $val
117    $win.output.analyze configure -device $val
118}
119
120# ----------------------------------------------------------------------
121# MAIN WINDOW
122# ----------------------------------------------------------------------
123wm withdraw .
124Rappture::MainWin .main -borderwidth 0
125
126#.main configure -title [$config get title]
127
128# build everything inside this main window
129set win [.main component app]
130$win configure -background #a6a6a6
131
132frame $win.input -borderwidth 12 -relief flat
133pack $win.input -side left -expand yes -fill both -padx {0 5}
134
135frame $win.output -borderwidth 12 -relief flat
136pack $win.output -side left -expand yes -fill both -padx {5 0}
137
138# make an arrow that goes from input to output side
139label $win.arrow -borderwidth 0 -image in2out
140place $win.arrow -y 2 -anchor n
141bind $win.input <Configure> [list align_arrow $win]
142proc align_arrow {win} {
143    place $win.arrow -x [expr {[winfo width $win.input]+5}]
144}
145
146# ----------------------------------------------------------------------
147# INPUT AREA
148# ----------------------------------------------------------------------
149set w $win.input
150set dfirst ""
151set dlist [$config children -type structure controls]
152puts "device: $dlist"
153if {"" != $dlist} {
154    foreach dname $dlist {
155        set obj [$config element -flavor object controls.$dname]
156        set name [$obj get label]
157puts " => $name = $obj"
158        set devs($name) $obj
159    }
160    set devlist [lsort [array names devs]]
161
162    if {[array size devs] > 1} {
163        frame $w.devsel
164        pack $w.devsel -side top -fill x
165        label $w.devsel.l -text "Device:"
166        pack $w.devsel.l -side left
167        Rappture::Combobox $w.devsel.dev -width 30 -editable no
168        pack $w.devsel.dev -side left
169        bind $w.devsel.dev <<Value>> main_device_select
170
171        foreach name $devlist {
172            $w.devsel.dev choices insert end $devs($name) $name
173        }
174        $w.devsel.dev value [lindex $devlist 0]
175    }
176
177    set first [lindex $devlist 0]
178    set dfirst $devs($first)
179    set tags [$dfirst children]
180    set i [lsearch $tags label]
181    if {$i >= 0} {set tags [lreplace $tags $i $i]}
182
183puts "first device: tags = $tags"
184    if {$tags == "molecule"} {
185        Rappture::MoleculeViewer $w.device -device $devs($first) \
186            -library $lib
187    } else {
188        Rappture::DeviceViewer1D $w.device -device $devs($first) \
189            -tool $tool -library $lib
190    }
191    pack $w.device -expand yes -fill both
192
193    bind $w.device <<Edit>> [list $win.output.analyze reset]
194}
195
196# ----------------------------------------------------------------------
197# OUTPUT AREA
198# ----------------------------------------------------------------------
199set w $win.output
200Rappture::Analyzer $w.analyze -holdwindow $win.input \
201    -tool $tool -analysis [$config element -flavor object analysis] \
202    -device $dfirst
203pack $w.analyze -expand yes -fill both
204
205# ----------------------------------------------------------------------
206# HOOK UP ANY CONTROLS CALLED OUT IN CONFIG.XML
207# ----------------------------------------------------------------------
208foreach access [$config children -type access controls] {
209    set name [$config get controls.$access]
210    switch -glob -- $name {
211        parameters.ambient* - structure* {
212##            $win.input.device controls add $name
213        }
214    }
215}
Note: See TracBrowser for help on using the repository browser.