Changeset 11 for trunk/gui/scripts/analyzer.tcl
- Timestamp:
- May 30, 2005, 9:33:49 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/analyzer.tcl
r9 r11 10 10 # ====================================================================== 11 11 # AUTHOR: Michael McLennan, Purdue University 12 # Copyright (c) 2004 Purdue Research Foundation, West Lafayette, IN 12 # Copyright (c) 2004-2005 13 # Purdue Research Foundation, West Lafayette, IN 13 14 # ====================================================================== 14 15 package require Itk 15 package require BLT 16 16 17 option add *Analyzer.width 5i widgetDefault 18 option add *Analyzer.height 5i widgetDefault 19 option add *Analyzer.simControl "auto" widgetDefault 20 option add *Analyzer.simControlBackground "" widgetDefault 21 option add *Analyzer.simControlOutline gray widgetDefault 22 option add *Analyzer.simControlActiveBackground #ffffcc widgetDefault 23 option add *Analyzer.simControlActiveOutline black widgetDefault 24 25 option add *Analyzer.font \ 26 -*-helvetica-medium-r-normal-*-*-120-* widgetDefault 17 27 option add *Analyzer.textFont \ 18 28 -*-helvetica-medium-r-normal-*-*-120-* widgetDefault 29 option add *Analyzer.boldTextFont \ 30 -*-helvetica-bold-r-normal-*-*-120-* widgetDefault 19 31 20 32 itcl::class Rappture::Analyzer { 21 33 inherit itk::Widget 22 34 23 itk_option define -tool tool Tool "" 24 itk_option define -device device Device "" 25 itk_option define -analysis analysis Analysis "" 35 itk_option define -textfont textFont Font "" 36 itk_option define -boldtextfont boldTextFont Font "" 37 itk_option define -simcontrol simControl SimControl "" 38 itk_option define -simcontroloutline simControlOutline Background "" 39 itk_option define -simcontrolbackground simControlBackground Background "" 40 itk_option define -simcontrolactiveoutline simControlActiveOutline Background "" 41 itk_option define -simcontrolactivebackground simControlActiveBackground Background "" 26 42 itk_option define -holdwindow holdWindow HoldWindow "" 27 43 28 constructor { args} { # defined below }44 constructor {tool args} { # defined below } 29 45 destructor { # defined below } 30 46 31 public method simulate { }47 public method simulate {args} 32 48 public method reset {} 33 49 public method load {file} 34 50 public method clear {} 51 52 protected method _plot {args} 53 protected method _reorder {comps} 54 protected method _autoLabel {xmlobj path title cntVar} 35 55 protected method _fixResult {} 36 37 private variable _run "" ;# results from last run 56 protected method _fixSize {} 57 protected method _fixSimControl {} 58 protected method _simState {state args} 59 60 private variable _tool "" ;# belongs to this tool 38 61 private variable _control "manual" ;# start mode 39 private variable _widgets ;# maps analyze section => widget 62 private variable _runs "" ;# list of XML objects with results 63 private variable _pages 0 ;# number of pages for result sets 64 private variable _label2page ;# maps output label => result set 65 private variable _plotlist "" ;# items currently being plotted 40 66 41 67 private common job ;# array var used for blt::bgexec jobs … … 49 75 # CONSTRUCTOR 50 76 # ---------------------------------------------------------------------- 51 itcl::body Rappture::Analyzer::constructor {args} { 77 itcl::body Rappture::Analyzer::constructor {tool args} { 78 set _tool $tool 79 80 itk_option add hull.width hull.height 81 pack propagate $itk_component(hull) no 82 83 frame $itk_interior.simol -borderwidth 1 -relief flat 84 pack $itk_interior.simol -fill x 85 86 frame $itk_interior.simol.simbg -borderwidth 0 87 pack $itk_interior.simol.simbg -expand yes -fill both 88 89 itk_component add simulate { 90 button $itk_interior.simol.simbg.simulate -text "Simulate" \ 91 -command [itcl::code $this simulate] 92 } 93 pack $itk_component(simulate) -side left -padx 4 -pady 4 94 95 itk_component add simstatus { 96 text $itk_interior.simol.simbg.simstatus -borderwidth 0 \ 97 -highlightthickness 0 -height 1 -width 1 -wrap none \ 98 -state disabled 99 } { 100 usual 101 ignore -highlightthickness 102 rename -font -textfont textFont Font 103 } 104 pack $itk_component(simstatus) -side left -expand yes -fill x 105 106 $itk_component(simstatus) tag configure popup \ 107 -underline 1 -foreground blue 108 109 $itk_component(simstatus) tag bind popup \ 110 <Enter> {%W configure -cursor center_ptr} 111 $itk_component(simstatus) tag bind popup \ 112 <Leave> {%W configure -cursor ""} 113 $itk_component(simstatus) tag bind popup \ 114 <ButtonPress> {after idle {Rappture::Tooltip::tooltip show %W}} 115 116 52 117 itk_component add notebook { 53 118 Rappture::Notebook $itk_interior.nb 54 119 } 55 120 pack $itk_interior.nb -expand yes -fill both 121 122 # ------------------------------------------------------------------ 123 # ABOUT PAGE 124 # ------------------------------------------------------------------ 125 set w [$itk_component(notebook) insert end about] 126 127 Rappture::Scroller $w.info -xscrollmode off -yscrollmode auto 128 pack $w.info -expand yes -fill both -padx 4 -pady 20 129 itk_component add toolinfo { 130 text $w.info.text -width 1 -height 1 -wrap word \ 131 -borderwidth 0 -highlightthickness 0 132 } { 133 usual 134 ignore -borderwidth -relief 135 rename -font -textfont textFont Font 136 } 137 $w.info contents $w.info.text 56 138 57 139 # ------------------------------------------------------------------ … … 60 142 set w [$itk_component(notebook) insert end simulate] 61 143 frame $w.cntls 62 pack $w.cntls -side top -fill x -padx {20 2} 63 64 itk_component add simulate { 65 button $w.cntls.sim -text "Simulate" \ 66 -command [itcl::code $this simulate] 67 } 68 pack $itk_component(simulate) -side left 69 70 itk_component add status { 71 label $w.cntls.info -width 1 -text "" -anchor w 72 } { 73 usual 74 rename -font -textfont textFont Font 75 } 76 pack $itk_component(status) -side left -expand yes -fill both 144 pack $w.cntls -side bottom -fill x -pady 12 145 frame $w.cntls.sep -background black -height 1 146 pack $w.cntls.sep -side top -fill x 147 148 itk_component add abort { 149 button $w.cntls.abort -text "Abort" \ 150 -command [itcl::code $_tool abort] 151 } 152 pack $itk_component(abort) -side left -expand yes -padx 4 -pady 4 77 153 78 154 Rappture::Scroller $w.info -xscrollmode off -yscrollmode auto 79 pack $w.info -expand yes -fill both -padx {20 2} -pady {20 2}80 itk_component add info {155 pack $w.info -expand yes -fill both -padx 4 -pady 4 156 itk_component add runinfo { 81 157 text $w.info.text -width 1 -height 1 -wrap word \ 82 158 -borderwidth 0 -highlightthickness 0 \ … … 94 170 set w [$itk_component(notebook) insert end analyze] 95 171 172 frame $w.top 173 pack $w.top -side top -fill x -pady 8 174 label $w.top.l -text "Result:" -font $itk_option(-font) 175 pack $w.top.l -side left 176 96 177 itk_component add resultselector { 97 Rappture::Combobox $w. sel -width 30 -editable no178 Rappture::Combobox $w.top.sel -width 50 -editable no 98 179 } { 99 180 usual 100 181 rename -font -textfont textFont Font 101 182 } 102 pack $itk_component(resultselector) -side top -fill x -padx {20 2}183 pack $itk_component(resultselector) -side left -expand yes -fill x 103 184 bind $itk_component(resultselector) <<Value>> [itcl::code $this _fixResult] 104 185 105 186 itk_component add results { 106 Rappture::Notebook $w.nb 107 } 108 pack $itk_component(results) -expand yes -fill both -pady 4 187 Rappture::Panes $w.pane 188 } 189 pack $itk_component(results) -expand yes -fill both 190 set f [$itk_component(results) pane 0] 191 192 itk_component add resultpages { 193 Rappture::Notebook $f.nb 194 } 195 pack $itk_component(resultpages) -expand yes -fill both 196 197 set f [$itk_component(results) insert end -fraction 0.1] 198 itk_component add resultset { 199 Rappture::ResultSet $f.rset \ 200 -clearcommand [itcl::code $this clear] \ 201 -settingscommand [itcl::code $this _plot] \ 202 -promptcommand [itcl::code $this _simState] 203 } 204 pack $itk_component(resultset) -expand yes -fill both 205 bind $itk_component(resultset) <<Control>> [itcl::code $this _fixSize] 109 206 110 207 eval itk_initialize $args 208 209 # 210 # Load up tool info on the first page. 211 # 212 $itk_component(toolinfo) tag configure title \ 213 -font $itk_option(-boldtextfont) 214 215 set mesg [$tool xml get tool.title] 216 if {"" != $mesg} { 217 $itk_component(toolinfo) insert end $mesg title 218 $itk_component(toolinfo) insert end "\n\n" 219 } 220 221 set mesg [$tool xml get tool.about] 222 if {"" != $mesg} { 223 $itk_component(toolinfo) insert end $mesg 224 } 225 $itk_component(toolinfo) configure -state disabled 226 $itk_component(notebook) current about 227 228 # reset everything to a clean state 111 229 reset 230 231 # tool can run on "manual" (default) or "auto" 232 set cntl [$tool xml get tool.control] 233 if {"" != $cntl} { 234 set _control $cntl 235 } 112 236 } 113 237 … … 116 240 # ---------------------------------------------------------------------- 117 241 itcl::body Rappture::Analyzer::destructor {} { 118 if {$_run != ""} { 119 itcl::delete object $_run 120 } 121 } 122 123 # ---------------------------------------------------------------------- 124 # USAGE: simulate 125 # 126 # If the simulation page is showing, this kicks off the simulator 127 # by executing the tool.command associated with the -tool. While 128 # the simulation is running, it shows status. When the simulation is 129 # finished, it switches automatically to "analyze" mode and shows 130 # the results. 131 # ---------------------------------------------------------------------- 132 itcl::body Rappture::Analyzer::simulate {} { 133 if {[$itk_component(notebook) current] == "simulate"} { 134 $itk_component(status) configure -text "Running simulation..." 135 $itk_component(simulate) configure -text "Abort" \ 136 -command {set ::Rappture::Analyzer::job(control) abort} 137 138 set job(control) "" 139 set job(error) "" 140 141 # if the hold window is set, then put up a busy cursor 142 if {$itk_option(-holdwindow) != ""} { 143 blt::busy hold $itk_option(-holdwindow) 144 raise $itk_component(hull) 145 update 146 } 147 148 # write out the driver.xml file for the tool 149 set status [catch { 150 set fid [open driver.xml w] 151 puts $fid "<?xml version=\"1.0\"?>" 152 set xml [$itk_option(-tool) xml] 153 if {$itk_option(-device) != ""} { 154 set xml2 [$itk_option(-device) xml] 155 regsub -all {&} $xml2 {\\\&} xml2 156 regsub {</run>} $xml "$xml2</run>" xml 242 foreach obj $_runs { 243 itcl::delete object $obj 244 } 245 after cancel [itcl::code $this simulate] 246 } 247 248 # ---------------------------------------------------------------------- 249 # USAGE: simulate ?-ifneeded? 250 # USAGE: simulate ?<path1> <value1> <path2> <value2> ...? 251 # 252 # Kicks off the simulator by executing the tool.command associated 253 # with the tool. If any arguments are specified, they are used to 254 # set parameters for the simulation. While the simulation is running, 255 # it shows status. When the simulation is finished, it switches 256 # automatically to "analyze" mode and shows the results. 257 # ---------------------------------------------------------------------- 258 itcl::body Rappture::Analyzer::simulate {args} { 259 if {$args == "-ifneeded"} { 260 # check to see if simulation is really needed 261 $_tool sync 262 if {[$itk_component(resultset) contains [$_tool xml object]]} { 263 # not needed -- show results and return 264 $itk_component(notebook) current analyze 265 return 266 } 267 set args "" 268 } 269 270 # simulation is needed -- go to simulation page 271 $itk_component(notebook) current simulate 272 273 _simState off 274 $itk_component(runinfo) configure -state normal 275 $itk_component(runinfo) delete 1.0 end 276 $itk_component(runinfo) insert end "Running simulation..." 277 $itk_component(runinfo) configure -state disabled 278 279 # if the hold window is set, then put up a busy cursor 280 if {$itk_option(-holdwindow) != ""} { 281 blt::busy hold $itk_option(-holdwindow) 282 raise $itk_component(hull) 283 update 284 } 285 286 # execute the job 287 foreach {status result} [eval $_tool run $args] break 288 289 # if job was aborted, then allow simulation again 290 if {$result == "ABORT"} { 291 _simState on "Aborted" 292 } 293 294 # read back the results from run.xml 295 if {$status == 0 && $result != "ABORT"} { 296 if {[regexp {=RAPPTURE-RUN=>([^\n]+)} $result match file]} { 297 set status [catch {load $file} msg] 298 if {$status != 0} { 299 set result $msg 157 300 } 158 puts $fid $xml159 close $fid160 } result]161 162 # execute the tool using the path from the tool description163 if {$status == 0} {164 set cmd [$itk_option(-tool) get tool.command]165 166 set status [catch {eval blt::bgexec \167 ::Rappture::Analyzer::job(control) \168 -output ::Rappture::Analyzer::job(output) \169 -error ::Rappture::Analyzer::job(error) $cmd} result]170 }171 172 # read back the results from run.xml173 if {$status == 0} {174 set status [catch {load run.xml} result]175 }176 177 # back to normal178 if {$itk_option(-holdwindow) != ""} {179 blt::busy release $itk_option(-holdwindow)180 }181 $itk_component(status) configure -text ""182 $itk_component(simulate) configure -text "Simulate" \183 -command [itcl::code $this simulate]184 185 # if anything went wrong, tell the user; otherwise, analyze186 if {[regexp {^KILLED} $job(control)]} {187 # job aborted -- do nothing188 } elseif {$status != 0} {189 $itk_component(info) configure -state normal190 $itk_component(info) delete 1.0 end191 $itk_component(info) insert end "Problem launching job:\n"192 if {[string length $job(error)] > 0} {193 $itk_component(info) insert end $job(error)194 } else {195 $itk_component(info) insert end $result196 }197 $itk_component(info) configure -state disabled198 301 } else { 199 $itk_component(notebook) current analyze 200 } 302 set status 1 303 set result "Can't find result file in output:\n\n$result" 304 } 305 } 306 307 # back to normal 308 if {$itk_option(-holdwindow) != ""} { 309 blt::busy release $itk_option(-holdwindow) 310 } 311 $itk_component(abort) configure -state disabled 312 313 if {$status != 0} { 314 $itk_component(runinfo) configure -state normal 315 $itk_component(runinfo) delete 1.0 end 316 $itk_component(runinfo) insert end "Problem launching job:\n\n" 317 $itk_component(runinfo) insert end $result 318 $itk_component(runinfo) configure -state disabled 319 } else { 320 $itk_component(notebook) current analyze 201 321 } 202 322 } … … 211 331 # ---------------------------------------------------------------------- 212 332 itcl::body Rappture::Analyzer::reset {} { 213 $itk_component(notebook) current simulate 214 215 # if control mode is "auto", then simulate right away 216 if {[string match auto* $_control]} { 217 simulate 333 # check to see if simulation is really needed 334 $_tool sync 335 if {![$itk_component(resultset) contains [$_tool xml object]]} { 336 # if control mode is "auto", then simulate right away 337 if {[string match auto* $_control]} { 338 # auto control -- don't need button 339 pack forget $itk_interior.simol 340 341 after cancel [itcl::code $this simulate] 342 after idle [itcl::code $this simulate] 343 } else { 344 _simState on "new input parameters" 345 } 346 } else { 347 _simState off 218 348 } 219 349 } … … 222 352 # USAGE: load <file> 223 353 # 224 # Used to reset the analyzer whenever the input to a simulation has 225 # changed. Sets the mode back to "simulate", so the user has to 226 # simulate again to see the output. 354 # Loads the data from the given <file> into the appropriate results 355 # sets. If necessary, new results sets are created to store the data. 227 356 # ---------------------------------------------------------------------- 228 357 itcl::body Rappture::Analyzer::load {file} { 229 # clear any old results230 if {$_run != ""} {231 itcl::delete object $_run232 set _run ""233 }234 235 358 # try to load new results from the given file 236 set _run [Rappture::library $file] 237 238 # go through the analysis and create widgets to display results 239 foreach item [array names _widgets] { 240 $_widgets($item) configure -output $_run 241 } 359 set xmlobj [Rappture::library $file] 360 lappend _runs $xmlobj 361 362 # go through the analysis and find all result sets 363 set haveresults 0 364 foreach item [_reorder [$xmlobj children output]] { 365 switch -glob -- $item { 366 log* { 367 _autoLabel $xmlobj output.$item "Output Log" counters 368 } 369 curve* - field* { 370 _autoLabel $xmlobj output.$item "Plot" counters 371 } 372 table* { 373 _autoLabel $xmlobj output.$item "Energy Levels" counters 374 } 375 } 376 set label [$xmlobj get output.$item.about.label] 377 378 if {"" != $label} { 379 set haveresults 1 380 } 381 } 382 383 # if there are any valid results, add them to the resultset 384 if {$haveresults} { 385 set size [$itk_component(resultset) size] 386 set op [$itk_component(resultset) add $xmlobj] 387 388 # add each result to a result viewer 389 foreach item [_reorder [$xmlobj children output]] { 390 set label [$xmlobj get output.$item.about.label] 391 392 if {"" != $label} { 393 if {![info exists _label2page($label)]} { 394 set name "page[incr _pages]" 395 set page [$itk_component(resultpages) insert end $name] 396 set _label2page($label) $page 397 Rappture::ResultViewer $page.rviewer 398 pack $page.rviewer -expand yes -fill both -pady 4 399 400 $itk_component(resultselector) choices insert end \ 401 $name $label 402 403 # 404 # NOTE: 405 # 406 # If this result is showing up late in the game, then 407 # we must fill the resultviewer with a series of blank 408 # entries, so the latest result will align with (have 409 # the same index as) results in all other viewers. 410 # 411 for {set i 0} {$i < $size} {incr i} { 412 $page.rviewer add $xmlobj "" 413 } 414 } 415 416 # add/replace the latest result into this viewer 417 set page $_label2page($label) 418 eval $page.rviewer $op [list $xmlobj output.$item] 419 } 420 } 421 } 422 423 # if there is only one result page, take down the selector 424 set w [$itk_component(notebook) page analyze] 425 if {[$itk_component(resultselector) choices size] <= 1} { 426 pack forget $w.top 427 } else { 428 pack $w.top -before $itk_component(results) -side top -fill x 429 } 430 431 # show the first page by default 432 set first [$itk_component(resultselector) choices get -label 0] 433 if {$first != ""} { 434 $itk_component(resultpages) current page1 435 $itk_component(resultselector) value $first 436 } 437 } 438 439 # ---------------------------------------------------------------------- 440 # USAGE: clear 441 # 442 # Discards all results previously loaded into the analyzer. 443 # ---------------------------------------------------------------------- 444 itcl::body Rappture::Analyzer::clear {} { 445 foreach obj $_runs { 446 itcl::delete object $obj 447 } 448 set _runs "" 449 450 foreach label [array names _label2page] { 451 set page $_label2page($label) 452 $page.rviewer clear 453 } 454 455 $itk_component(resultset) clear 456 $itk_component(results) fraction end 0.1 457 458 _simState on 459 _fixSimControl 460 } 461 462 # ---------------------------------------------------------------------- 463 # USAGE: _plot ?<index> <options> <index> <options>...? 464 # 465 # Used internally to update the plot shown in the current result 466 # viewer whenever the resultset settings have changed. Causes the 467 # desired results to show up on screen. 468 # ---------------------------------------------------------------------- 469 itcl::body Rappture::Analyzer::_plot {args} { 470 set _plotlist $args 471 472 set page [$itk_component(resultselector) value] 473 set page [$itk_component(resultselector) translate $page] 474 set f [$itk_component(resultpages) page $page] 475 $f.rviewer plot clear 476 foreach {index opts} $_plotlist { 477 $f.rviewer plot add $index $opts 478 } 479 } 480 481 # ---------------------------------------------------------------------- 482 # USAGE: _reorder 483 # 484 # Used internally to change the order of a series of output components 485 # found in the <output> section. Moves the <log> elements to the end 486 # and returns the updated list. 487 # ---------------------------------------------------------------------- 488 itcl::body Rappture::Analyzer::_reorder {comps} { 489 set i 0 490 set max [llength $comps] 491 while {$i < $max} { 492 set c [lindex $comps $i] 493 if {[string match log* $c]} { 494 set comps [lreplace $comps $i $i] 495 lappend comps $c 496 incr max -1 497 } else { 498 incr i 499 } 500 } 501 return $comps 502 } 503 504 # ---------------------------------------------------------------------- 505 # USAGE: _autoLabel <xmlobj> <path> <title> <cntVar> 506 # 507 # Used internally to check for an about.label property at the <path> 508 # in <xmlobj>. If this object doesn't have a label, then one is 509 # supplied using the given <title>. The <cntVar> is an array of 510 # counters in the calling scopes for titles that have been used 511 # in the past. This is used to create titles like "Plot #2" the 512 # second time it is encountered. 513 # 514 # The <xmlobj> is updated so that the label is inserted directly in 515 # the tree. 516 # ---------------------------------------------------------------------- 517 itcl::body Rappture::Analyzer::_autoLabel {xmlobj path title cntVar} { 518 upvar $cntVar counters 519 520 set label [$xmlobj get $path.about.label] 521 if {"" == $label} { 522 # no label -- make one up using the title specified 523 if {![info exists counters($title)]} { 524 set counters($title) 1 525 set label $title 526 } else { 527 set label "$title #[incr counters($title)]" 528 } 529 $xmlobj put $path.about.label $label 530 } else { 531 # handle the case of two identical labels in <output> 532 if {![info exists counters($label)]} { 533 set counters($label) 1 534 } else { 535 set label "$label #[incr counters($label)]" 536 $xmlobj put $path.about.label $label 537 } 538 } 539 return $label 242 540 } 243 541 … … 251 549 set page [$itk_component(resultselector) value] 252 550 set page [$itk_component(resultselector) translate $page] 253 $itk_component(results) current $page 254 } 255 256 # ---------------------------------------------------------------------- 257 # CONFIGURATION OPTION: -tool 258 # 259 # Set to the Rappture::library object representing the tool being 260 # run in this analyzer. 261 # ---------------------------------------------------------------------- 262 itcl::configbody Rappture::Analyzer::tool { 263 if {![Rappture::library isvalid $itk_option(-tool)]} { 264 error "bad value \"$itk_option(-tool)\": should be Rappture::library" 265 } 266 267 $itk_component(info) configure -state normal 268 $itk_component(info) delete 1.0 end 269 $itk_component(info) insert end [$itk_option(-tool) get tool.about] 270 $itk_component(info) configure -state disabled 271 } 272 273 # ---------------------------------------------------------------------- 274 # CONFIGURATION OPTION: -device 275 # 276 # Set to the Rappture::library object representing the device being 277 # run in this analyzer. 278 # ---------------------------------------------------------------------- 279 itcl::configbody Rappture::Analyzer::device { 280 if {$itk_option(-device) != "" 281 && ![Rappture::library isvalid $itk_option(-device)]} { 282 error "bad value \"$itk_option(-device)\": should be Rappture::library" 283 } 284 reset 285 } 286 287 # ---------------------------------------------------------------------- 288 # CONFIGURATION OPTION: -analysis 289 # 290 # Set to the Rappture::library object representing the analysis that 291 # should be shown in this analyzer. 292 # ---------------------------------------------------------------------- 293 itcl::configbody Rappture::Analyzer::analysis { 294 if {![Rappture::library isvalid $itk_option(-analysis)]} { 295 error "bad value \"$itk_option(-analysis)\": should be Rappture::library" 296 } 297 set _control [$itk_option(-analysis) get control] 298 299 # go through the analysis and create widgets to display results 300 $itk_component(results) delete -all 301 catch {unset _widgets} 302 303 set counter 0 304 foreach item [$itk_option(-analysis) children] { 305 switch -glob -- $item { 306 xyplot* { 307 set name "page[incr counter]" 308 set label [$itk_option(-analysis) get $item.label] 309 if {$label == ""} { set label $name } 310 311 set page [$itk_component(results) insert end $name] 312 $itk_component(resultselector) choices insert end \ 313 $name $label 314 315 set _widgets($item) [Rappture::Xyplot $page.#auto \ 316 -layout [$itk_option(-analysis) element -flavor object $item]] 317 pack $_widgets($item) -expand yes -fill both 551 $itk_component(resultpages) current $page 552 553 set f [$itk_component(resultpages) page $page] 554 $f.rviewer plot clear 555 eval $f.rviewer plot add $_plotlist 556 } 557 558 # ---------------------------------------------------------------------- 559 # USAGE: _fixSize 560 # 561 # Used internally to change the size of the result set area whenever 562 # a new control appears. Adjusts the size available for the result 563 # set up to some maximum. 564 # ---------------------------------------------------------------------- 565 itcl::body Rappture::Analyzer::_fixSize {} { 566 set f [$itk_component(results) fraction end] 567 if {$f < 0.4} { 568 $itk_component(results) fraction end [expr {$f+0.15}] 569 } 570 _fixSimControl 571 } 572 573 # ---------------------------------------------------------------------- 574 # USAGE: _simState <boolean> ?<message>? ?<settings>? 575 # 576 # Used internally to change the "Simulation" button on or off. 577 # If the <boolean> is on, then any <message> and <settings> are 578 # displayed as well. The <message> is a note to the user about 579 # what will be simulated, and the <settings> are a list of 580 # tool parameter settings of the form {path1 val1 path2 val2 ...}. 581 # When these are in place, the next Simulate operation will use 582 # these settings. This helps fill in missing data values. 583 # ---------------------------------------------------------------------- 584 itcl::body Rappture::Analyzer::_simState {state args} { 585 if {$state} { 586 $itk_interior.simol configure \ 587 -background $itk_option(-simcontrolactiveoutline) 588 $itk_interior.simol.simbg configure \ 589 -background $itk_option(-simcontrolactivebackground) 590 $itk_component(simulate) configure \ 591 -highlightbackground $itk_option(-simcontrolactivebackground) 592 $itk_component(simstatus) configure \ 593 -background $itk_option(-simcontrolactivebackground) 594 595 $itk_component(abort) configure -state disabled 596 $itk_component(simulate) configure -state normal \ 597 -command [itcl::code $this simulate] 598 599 # 600 # If there's a special message, then put it up next to the button. 601 # 602 set mesg [lindex $args 0] 603 if {"" != $mesg} { 604 $itk_component(simstatus) configure -state normal 605 $itk_component(simstatus) delete 1.0 end 606 $itk_component(simstatus) insert end $mesg 607 608 # 609 # If there are any settings, then install them in the 610 # "Simulate" button. Also, pop them up as a tooltip 611 # for the message. 612 # 613 set settings [lindex $args 1] 614 if {[llength $settings] > 0} { 615 $itk_component(simulate) configure \ 616 -command [eval itcl::code $this simulate $settings] 617 618 set details "" 619 foreach {path val} $settings { 620 set str [$_tool xml get $path.about.label] 621 if {"" == $str} { 622 set str [$_tool xml element -as id $path] 623 } 624 append details "$str = $val\n" 625 } 626 set details [string trim $details] 627 628 Rappture::Tooltip::for $itk_component(simstatus) $details 629 $itk_component(simstatus) insert end " " 630 $itk_component(simstatus) insert end "(details...)" popup 318 631 } 319 elevels* { 320 set name "page[incr counter]" 321 322 set page [$itk_component(results) insert end $name] 323 $itk_component(resultselector) choices insert end \ 324 $name "Energy Levels" 325 326 set _widgets($item) [Rappture::EnergyLevels $page.#auto \ 327 -layout [$itk_option(-analysis) element -flavor object $item]] 328 pack $_widgets($item) -expand yes -fill both 632 $itk_component(simstatus) configure -state disabled 633 } 634 } else { 635 if {"" != $itk_option(-simcontrolbackground)} { 636 set simcbg $itk_option(-simcontrolbackground) 637 } else { 638 set simcbg $itk_option(-background) 639 } 640 $itk_interior.simol configure \ 641 -background $itk_option(-simcontroloutline) 642 $itk_interior.simol.simbg configure -background $simcbg 643 $itk_component(simulate) configure -highlightbackground $simcbg 644 $itk_component(simstatus) configure -background $simcbg 645 646 $itk_component(simulate) configure -state disabled 647 $itk_component(abort) configure -state normal 648 649 $itk_component(simstatus) configure -state normal 650 $itk_component(simstatus) delete 1.0 end 651 $itk_component(simstatus) configure -state disabled 652 Rappture::Tooltip::for $itk_component(simstatus) "" 653 } 654 } 655 656 # ---------------------------------------------------------------------- 657 # USAGE: _fixSimControl 658 # 659 # Used internally to add or remove the simulation control at the 660 # top of the analysis area. This is controlled by the -simcontrol 661 # option. 662 # ---------------------------------------------------------------------- 663 itcl::body Rappture::Analyzer::_fixSimControl {} { 664 switch -- $itk_option(-simcontrol) { 665 on { 666 pack $itk_interior.simol -fill x -before $itk_interior.nb 667 } 668 off { 669 pack forget $itk_interior.simol 670 } 671 auto { 672 # 673 # If we have two or more radiodials, then there is a 674 # chance of encountering a combination of parameters 675 # with no data, requiring simulation. 676 # 677 if {[$itk_component(resultset) size -controls] >= 2} { 678 pack $itk_interior.simol -fill x -before $itk_interior.nb 679 } else { 680 pack forget $itk_interior.simol 329 681 } 330 682 } 331 } 332 333 # if there is only one page, take down the selector 334 if {[$itk_component(resultselector) choices size] <= 1} { 335 pack forget $itk_component(resultselector) 336 } else { 337 pack $itk_component(resultselector) -before $itk_component(results) \ 338 -side top -fill x -padx {20 2} 339 } 340 341 # show the first page by default 342 set first [$itk_component(resultselector) choices get -label 0] 343 if {$first != ""} { 344 $itk_component(results) current page1 345 $itk_component(resultselector) value $first 346 } 347 } 683 default { 684 error "bad value \"$itk_option(-simcontrol)\": should be on, off, auto" 685 } 686 } 687 } 688 689 # ---------------------------------------------------------------------- 690 # CONFIGURATION OPTION: -simcontrol 691 # 692 # Controls whether or not the Simulate button is showing. In some 693 # cases, it is not needed. 694 # ---------------------------------------------------------------------- 695 itcl::configbody Rappture::Analyzer::simcontrol { 696 _fixSimControl 697 }
Note: See TracChangeset
for help on using the changeset viewer.