[1] | 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 | #\ |
---|
| 23 | exec wish "$0" $* |
---|
| 24 | # ---------------------------------------------------------------------- |
---|
| 25 | # wish executes everything from here on... |
---|
| 26 | |
---|
| 27 | package require Rappture |
---|
| 28 | |
---|
| 29 | option add *MainWin.mode web startupFile |
---|
| 30 | option add *MainWin.borderWidth 0 startupFile |
---|
| 31 | option add *MainWin.anchor center startupFile |
---|
| 32 | |
---|
| 33 | # "web site" look |
---|
| 34 | option 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 |
---|
| 41 | option add *MainWin.bgScript "" startupFile |
---|
| 42 | option add *MainWin.bgColor white startupFile |
---|
| 43 | |
---|
| 44 | image 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 | # |
---|
| 50 | set toolfile "tool.xml" |
---|
| 51 | set configfile "config.xml" |
---|
| 52 | |
---|
| 53 | while {[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 |
---|
[6] | 84 | set lib [Rappture::library -std library.xml] |
---|
[1] | 85 | |
---|
| 86 | # open the XML file containing the tool parameters |
---|
| 87 | if {![file exists $toolfile]} { |
---|
| 88 | puts stderr "tool file \"$toolfile\" doesn't exist" |
---|
| 89 | exit 1 |
---|
| 90 | } |
---|
[6] | 91 | set tool [Rappture::library $toolfile] |
---|
[1] | 92 | |
---|
| 93 | # open the XML file containing the configuration for this application |
---|
| 94 | if {![file exists $configfile]} { |
---|
| 95 | puts stderr "config file \"$configfile\" doesn't exist" |
---|
| 96 | exit 1 |
---|
| 97 | } |
---|
[6] | 98 | set config [Rappture::library $configfile] |
---|
[1] | 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 | # ---------------------------------------------------------------------- |
---|
| 104 | cd [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 | # ---------------------------------------------------------------------- |
---|
| 112 | proc 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 | # ---------------------------------------------------------------------- |
---|
| 123 | wm withdraw . |
---|
| 124 | Rappture::MainWin .main -borderwidth 0 |
---|
| 125 | |
---|
| 126 | #.main configure -title [$config get title] |
---|
| 127 | |
---|
| 128 | # build everything inside this main window |
---|
| 129 | set win [.main component app] |
---|
| 130 | $win configure -background #a6a6a6 |
---|
| 131 | |
---|
| 132 | frame $win.input -borderwidth 12 -relief flat |
---|
| 133 | pack $win.input -side left -expand yes -fill both -padx {0 5} |
---|
| 134 | |
---|
| 135 | frame $win.output -borderwidth 12 -relief flat |
---|
| 136 | pack $win.output -side left -expand yes -fill both -padx {5 0} |
---|
| 137 | |
---|
| 138 | # make an arrow that goes from input to output side |
---|
| 139 | label $win.arrow -borderwidth 0 -image in2out |
---|
| 140 | place $win.arrow -y 2 -anchor n |
---|
| 141 | bind $win.input <Configure> [list align_arrow $win] |
---|
| 142 | proc align_arrow {win} { |
---|
| 143 | place $win.arrow -x [expr {[winfo width $win.input]+5}] |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | # ---------------------------------------------------------------------- |
---|
| 147 | # INPUT AREA |
---|
| 148 | # ---------------------------------------------------------------------- |
---|
| 149 | set w $win.input |
---|
[6] | 150 | set dfirst "" |
---|
| 151 | set dlist [$config children -type structure controls] |
---|
| 152 | if {"" != $dlist} { |
---|
| 153 | foreach dname $dlist { |
---|
| 154 | set obj [$config element -flavor object controls.$dname] |
---|
[1] | 155 | set name [$obj get label] |
---|
| 156 | set devs($name) $obj |
---|
| 157 | } |
---|
| 158 | set devlist [lsort [array names devs]] |
---|
| 159 | |
---|
[6] | 160 | if {[array size devs] > 1} { |
---|
[1] | 161 | frame $w.devsel |
---|
| 162 | pack $w.devsel -side top -fill x |
---|
| 163 | label $w.devsel.l -text "Device:" |
---|
| 164 | pack $w.devsel.l -side left |
---|
| 165 | Rappture::Combobox $w.devsel.dev -width 30 -editable no |
---|
| 166 | pack $w.devsel.dev -side left |
---|
| 167 | bind $w.devsel.dev <<Value>> main_device_select |
---|
| 168 | |
---|
| 169 | foreach name $devlist { |
---|
| 170 | $w.devsel.dev choices insert end $devs($name) $name |
---|
| 171 | } |
---|
| 172 | $w.devsel.dev value [lindex $devlist 0] |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | set first [lindex $devlist 0] |
---|
[6] | 176 | set dfirst $devs($first) |
---|
[1] | 177 | Rappture::DeviceViewer1D $w.device -device $devs($first) \ |
---|
| 178 | -tool $tool -library $lib |
---|
| 179 | pack $w.device -expand yes -fill both |
---|
| 180 | |
---|
| 181 | bind $w.device <<Edit>> [list $win.output.analyze reset] |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | # ---------------------------------------------------------------------- |
---|
| 185 | # OUTPUT AREA |
---|
| 186 | # ---------------------------------------------------------------------- |
---|
| 187 | set w $win.output |
---|
| 188 | Rappture::Analyzer $w.analyze -holdwindow $win.input \ |
---|
[6] | 189 | -tool $tool -analysis [$config element -flavor object analysis] \ |
---|
| 190 | -device $dfirst |
---|
[1] | 191 | pack $w.analyze -expand yes -fill both |
---|
| 192 | |
---|
| 193 | # ---------------------------------------------------------------------- |
---|
| 194 | # HOOK UP ANY CONTROLS CALLED OUT IN CONFIG.XML |
---|
| 195 | # ---------------------------------------------------------------------- |
---|
[6] | 196 | foreach access [$config children -type access controls] { |
---|
| 197 | set name [$config get controls.$access] |
---|
[1] | 198 | switch -glob -- $name { |
---|
[6] | 199 | parameters.ambient* - structure* { |
---|
[1] | 200 | $win.input.device controls add $name |
---|
| 201 | } |
---|
| 202 | } |
---|
| 203 | } |
---|