Changeset 11 for trunk/gui/apps/driver


Ignore:
Timestamp:
May 30, 2005 9:33:49 PM (19 years ago)
Author:
mmc
Message:

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:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/apps/driver

    r9 r11  
    44#
    55#  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.
     6#  and produces a user interface automatically to drive an application.
     7#  The user can set up input, click and button to launch a tool, and
     8#  browse through output.
    109#
    1110#  RUN AS FOLLOWS:
    12 #    driver ?-tool <toolfile>? ?-config <configfile>?
     11#    driver ?-tool <toolfile>?
    1312#
    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.
     13#  If the <toolfile> is not specified, it defaults to "tool.xml" in
     14#  the current working directory.
    1715#
    1816# ======================================================================
     
    4240option add *MainWin.bgColor white startupFile
    4341option add *Tooltip.background white
    44 
    45 image create photo in2out \
    46     -file [file join $Rappture::installdir scripts images in2out.gif]
     42option add *Editor.background white
     43option add *Gauge.textBackground white
     44option add *TemperatureGauge.textBackground white
    4745
    4846#
    4947# Process command line args to get the names of files to load...
    5048#
    51 set toolfile "tool.xml"
    52 set configfile "config.xml"
    53 
    54 while {[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     }
     49Rappture::getopts argv params {
     50    value -tool tool.xml
    8251}
    8352
    84 # open the XML file containing the material library
    85 set lib [Rappture::library -std library.xml]
    86                                                                                
    8753# open the XML file containing the tool parameters
    88 if {![file exists $toolfile]} {
    89     puts stderr "tool file \"$toolfile\" doesn't exist"
     54if {![file exists $params(-tool)]} {
     55    puts stderr "can't find tool \"$params(-tool)\""
    9056    exit 1
    9157}
    92 set tool [Rappture::library $toolfile]
    93                                                                                
    94 # open the XML file containing the configuration for this application
    95 if {![file exists $configfile]} {
    96     puts stderr "config file \"$configfile\" doesn't exist"
    97     exit 1
     58set xmlobj [Rappture::library $params(-tool)]
     59
     60set installdir [file dirname $params(-tool)]
     61if {"." == $installdir} {
     62    set installdir [pwd]
    9863}
    99 set config [Rappture::library $configfile]
    10064
    101 # ----------------------------------------------------------------------
    102 # From here on, run in the directory containing the tool.xml file,
    103 # so driver.xml files, etc., are created there
    104 # ----------------------------------------------------------------------
    105 cd [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 # ----------------------------------------------------------------------
    113 proc 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 }
     65set tool [Rappture::Tool ::#auto $xmlobj $installdir]
    12066
    12167# ----------------------------------------------------------------------
     
    12470wm withdraw .
    12571Rappture::MainWin .main -borderwidth 0
     72.main configure -title [$tool xml get tool.title]
     73wm withdraw .main
    12674
    127 .main configure -title [$config get title]
     75#
     76# The main window has a pager that acts as a notebook for the
     77# various parts.  This notebook as at least two pages--an input
     78# page and an output (analysis) page.  If there are <phase>'s
     79# for input, then there are more pages in the notebook.
     80#
     81set win [.main component app]
     82Rappture::Pager $win.pager
     83pack $win.pager -expand yes -fill both
    12884
    129 # build everything inside this main window
    130 set win [.main component app]
    131 #$win configure -background #a6a6a6
     85set phases [$tool xml children -type phase input]
     86if {[llength $phases] > 0} {
     87    set plist ""
     88    foreach name $phases {
     89        lappend plist input.$name
     90    }
     91    set phases $plist
     92} else {
     93    set phases input
     94}
    13295
    133 frame $win.input -borderwidth 12 -relief flat
    134 pack $win.input -side left -expand yes -fill both -padx {0 5}
     96foreach comp $phases {
     97    set title [$tool xml get $comp.about.label]
     98    if {$title == ""} {
     99        set title "Input #auto"
     100    }
     101    $win.pager insert end -name $comp -title $title
    135102
    136 frame $win.output -borderwidth 12 -relief flat
    137 pack $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 # ----------------------------------------------------------------------
    150 set w $win.input
    151 set dfirst ""
    152 set dlist [$config children -type structure controls]
    153 if {"" != $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]
     103    #
     104    # Build the page of input controls for this phase.
     105    #
     106    set f [$win.pager page $comp]
     107    Rappture::Page $f.cntls $tool $comp
     108    pack $f.cntls -expand yes -fill both
    192109}
    193110
     
    195112# OUTPUT AREA
    196113# ----------------------------------------------------------------------
    197 set w $win.output
    198 Rappture::Analyzer $w.analyze -holdwindow $win.input \
    199     -tool $tool -analysis [$config element -flavor object analysis] \
    200     -device $dfirst
    201 pack $w.analyze -expand yes -fill both
     114$win.pager insert end -name analyzer -title "Results"
     115set f [$win.pager page analyzer]
     116$win.pager page analyzer -command [list $f.analyze simulate -ifneeded]
     117
     118Rappture::Analyzer $f.analyze $tool -simcontrol auto
     119pack $f.analyze -expand yes -fill both
     120
     121$tool configure -analyzer $f.analyze
    202122
    203123# ----------------------------------------------------------------------
    204 # HOOK UP ANY CONTROLS CALLED OUT IN CONFIG.XML
     124# Finalize the arrangement
    205125# ----------------------------------------------------------------------
    206 proc 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     }
     126if {[llength [$win.pager page]] == 2} {
     127    set style [$xmlobj get tool.layout]
     128    set screenw [winfo screenwidth .]
    213129
    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     }
     130    update idletasks
     131    set w0 [winfo reqwidth [$win.pager page @0]]
     132    set w1 [winfo reqwidth [$win.pager page @1]]
    222133
    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]
     134    # if only two windows and they're small enough, put them up side-by-side
     135    if {$w0+$w1 < $screenw && $style != "wizard"} {
     136        $win.pager configure -arrangement side-by-side
     137        $f.analyze configure -holdwindow [$win.pager page @0] -simcontrol on
    272138    }
    273139}
    274 
    275 if {[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 }
     140wm deiconify .main
Note: See TracChangeset for help on using the changeset viewer.