1 | # ---------------------------------------------------------------------- |
---|
2 | # COMPONENT: analyzer - output area for Rappture |
---|
3 | # |
---|
4 | # This widget acts as the output side of a Rappture application. |
---|
5 | # When the input has changed, it displays a Simulate button that |
---|
6 | # launches the simulation. When a simulation is running, this |
---|
7 | # area shows status. When it is finished, the results appear |
---|
8 | # in place of the button, according to the specs in the <analyze> |
---|
9 | # XML data. |
---|
10 | # ====================================================================== |
---|
11 | # AUTHOR: Michael McLennan, Purdue University |
---|
12 | # Copyright (c) 2004-2005 |
---|
13 | # Purdue Research Foundation, West Lafayette, IN |
---|
14 | # ====================================================================== |
---|
15 | package require Itk |
---|
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 |
---|
27 | option add *Analyzer.textFont \ |
---|
28 | -*-helvetica-medium-r-normal-*-*-120-* widgetDefault |
---|
29 | option add *Analyzer.boldTextFont \ |
---|
30 | -*-helvetica-bold-r-normal-*-*-120-* widgetDefault |
---|
31 | |
---|
32 | itcl::class Rappture::Analyzer { |
---|
33 | inherit itk::Widget |
---|
34 | |
---|
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 "" |
---|
42 | itk_option define -holdwindow holdWindow HoldWindow "" |
---|
43 | |
---|
44 | constructor {tool args} { # defined below } |
---|
45 | destructor { # defined below } |
---|
46 | |
---|
47 | public method simulate {args} |
---|
48 | public method reset {} |
---|
49 | public method load {file} |
---|
50 | public method clear {} |
---|
51 | |
---|
52 | protected method _plot {args} |
---|
53 | protected method _reorder {comps} |
---|
54 | protected method _autoLabel {xmlobj path title cntVar} |
---|
55 | protected method _fixResult {} |
---|
56 | protected method _fixSize {} |
---|
57 | protected method _fixSimControl {} |
---|
58 | protected method _simState {state args} |
---|
59 | |
---|
60 | private variable _tool "" ;# belongs to this tool |
---|
61 | private variable _control "manual" ;# start mode |
---|
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 |
---|
66 | |
---|
67 | private common job ;# array var used for blt::bgexec jobs |
---|
68 | } |
---|
69 | |
---|
70 | itk::usual Analyzer { |
---|
71 | keep -background -cursor foreground -font |
---|
72 | } |
---|
73 | |
---|
74 | # ---------------------------------------------------------------------- |
---|
75 | # CONSTRUCTOR |
---|
76 | # ---------------------------------------------------------------------- |
---|
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 | |
---|
117 | itk_component add notebook { |
---|
118 | Rappture::Notebook $itk_interior.nb |
---|
119 | } |
---|
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 |
---|
138 | |
---|
139 | # ------------------------------------------------------------------ |
---|
140 | # SIMULATION PAGE |
---|
141 | # ------------------------------------------------------------------ |
---|
142 | set w [$itk_component(notebook) insert end simulate] |
---|
143 | frame $w.cntls |
---|
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 |
---|
153 | |
---|
154 | Rappture::Scroller $w.info -xscrollmode off -yscrollmode auto |
---|
155 | pack $w.info -expand yes -fill both -padx 4 -pady 4 |
---|
156 | itk_component add runinfo { |
---|
157 | text $w.info.text -width 1 -height 1 -wrap word \ |
---|
158 | -borderwidth 0 -highlightthickness 0 \ |
---|
159 | -state disabled |
---|
160 | } { |
---|
161 | usual |
---|
162 | ignore -borderwidth -relief |
---|
163 | rename -font -textfont textFont Font |
---|
164 | } |
---|
165 | $w.info contents $w.info.text |
---|
166 | |
---|
167 | # ------------------------------------------------------------------ |
---|
168 | # ANALYZE PAGE |
---|
169 | # ------------------------------------------------------------------ |
---|
170 | set w [$itk_component(notebook) insert end analyze] |
---|
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 | |
---|
177 | itk_component add resultselector { |
---|
178 | Rappture::Combobox $w.top.sel -width 50 -editable no |
---|
179 | } { |
---|
180 | usual |
---|
181 | rename -font -textfont textFont Font |
---|
182 | } |
---|
183 | pack $itk_component(resultselector) -side left -expand yes -fill x |
---|
184 | bind $itk_component(resultselector) <<Value>> [itcl::code $this _fixResult] |
---|
185 | |
---|
186 | itk_component add results { |
---|
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] |
---|
206 | |
---|
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 | # tool can run on "manual" (default) or "auto" |
---|
229 | set cntl [$tool xml get tool.control] |
---|
230 | if {"" != $cntl} { |
---|
231 | set _control $cntl |
---|
232 | } |
---|
233 | |
---|
234 | # reset everything to a clean state |
---|
235 | reset |
---|
236 | } |
---|
237 | |
---|
238 | # ---------------------------------------------------------------------- |
---|
239 | # DESTRUCTOR |
---|
240 | # ---------------------------------------------------------------------- |
---|
241 | itcl::body Rappture::Analyzer::destructor {} { |
---|
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 |
---|
300 | } |
---|
301 | } else { |
---|
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 |
---|
321 | } |
---|
322 | } |
---|
323 | |
---|
324 | # ---------------------------------------------------------------------- |
---|
325 | # USAGE: reset |
---|
326 | # |
---|
327 | # Used to reset the analyzer whenever the input to a simulation has |
---|
328 | # changed. Sets the mode back to "simulate", so the user has to |
---|
329 | # simulate again to see the output. If the <start> option is set |
---|
330 | # to "auto", the simulation is invoked immediately. |
---|
331 | # ---------------------------------------------------------------------- |
---|
332 | itcl::body Rappture::Analyzer::reset {} { |
---|
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 |
---|
348 | } |
---|
349 | } |
---|
350 | |
---|
351 | # ---------------------------------------------------------------------- |
---|
352 | # USAGE: load <file> |
---|
353 | # |
---|
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. |
---|
356 | # ---------------------------------------------------------------------- |
---|
357 | itcl::body Rappture::Analyzer::load {file} { |
---|
358 | # try to load new results from the given file |
---|
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.group] |
---|
377 | if {"" == $label} { |
---|
378 | set label [$xmlobj get output.$item.about.label] |
---|
379 | } |
---|
380 | |
---|
381 | set hidden [$xmlobj get output.$item.hide] |
---|
382 | set hidden [expr {"" != $hidden && $hidden}] |
---|
383 | |
---|
384 | if {"" != $label && !$hidden} { |
---|
385 | set haveresults 1 |
---|
386 | } |
---|
387 | } |
---|
388 | |
---|
389 | # if there are any valid results, add them to the resultset |
---|
390 | if {$haveresults} { |
---|
391 | set size [$itk_component(resultset) size] |
---|
392 | set index [$itk_component(resultset) add $xmlobj] |
---|
393 | |
---|
394 | # add each result to a result viewer |
---|
395 | foreach item [_reorder [$xmlobj children output]] { |
---|
396 | set label [$xmlobj get output.$item.about.group] |
---|
397 | if {"" == $label} { |
---|
398 | set label [$xmlobj get output.$item.about.label] |
---|
399 | } |
---|
400 | |
---|
401 | set hidden [$xmlobj get output.$item.hide] |
---|
402 | set hidden [expr {"" != $hidden && $hidden}] |
---|
403 | |
---|
404 | if {"" != $label && !$hidden} { |
---|
405 | if {![info exists _label2page($label)]} { |
---|
406 | set name "page[incr _pages]" |
---|
407 | set page [$itk_component(resultpages) insert end $name] |
---|
408 | set _label2page($label) $page |
---|
409 | Rappture::ResultViewer $page.rviewer |
---|
410 | pack $page.rviewer -expand yes -fill both -pady 4 |
---|
411 | |
---|
412 | $itk_component(resultselector) choices insert end \ |
---|
413 | $name $label |
---|
414 | } |
---|
415 | |
---|
416 | # add/replace the latest result into this viewer |
---|
417 | set page $_label2page($label) |
---|
418 | |
---|
419 | if {![info exists reset($page)]} { |
---|
420 | $page.rviewer clear $index |
---|
421 | set reset($page) 1 |
---|
422 | } |
---|
423 | $page.rviewer add $index $xmlobj output.$item |
---|
424 | } |
---|
425 | } |
---|
426 | } |
---|
427 | |
---|
428 | # if there is only one result page, take down the selector |
---|
429 | set w [$itk_component(notebook) page analyze] |
---|
430 | if {[$itk_component(resultselector) choices size] <= 1} { |
---|
431 | pack forget $w.top |
---|
432 | } else { |
---|
433 | pack $w.top -before $itk_component(results) -side top -fill x |
---|
434 | } |
---|
435 | |
---|
436 | # show the first page by default |
---|
437 | set first [$itk_component(resultselector) choices get -label 0] |
---|
438 | if {$first != ""} { |
---|
439 | set page [$itk_component(resultselector) choices get -value 0] |
---|
440 | $itk_component(resultpages) current $page |
---|
441 | $itk_component(resultselector) value $first |
---|
442 | } |
---|
443 | } |
---|
444 | |
---|
445 | # ---------------------------------------------------------------------- |
---|
446 | # USAGE: clear |
---|
447 | # |
---|
448 | # Discards all results previously loaded into the analyzer. |
---|
449 | # ---------------------------------------------------------------------- |
---|
450 | itcl::body Rappture::Analyzer::clear {} { |
---|
451 | foreach obj $_runs { |
---|
452 | itcl::delete object $obj |
---|
453 | } |
---|
454 | set _runs "" |
---|
455 | |
---|
456 | $itk_component(resultset) clear |
---|
457 | $itk_component(results) fraction end 0.1 |
---|
458 | |
---|
459 | foreach label [array names _label2page] { |
---|
460 | set page $_label2page($label) |
---|
461 | $page.rviewer clear |
---|
462 | } |
---|
463 | $itk_component(resultselector) value "" |
---|
464 | $itk_component(resultselector) choices delete 0 end |
---|
465 | catch {unset _label2page} |
---|
466 | set _plotlist "" |
---|
467 | |
---|
468 | # |
---|
469 | # HACK ALERT!! |
---|
470 | # The following statement should be in place, but it causes |
---|
471 | # vtk to dump core. Leave it out until we can fix the core dump. |
---|
472 | # In the mean time, we leak memory... |
---|
473 | # |
---|
474 | #$itk_component(resultpages) delete -all |
---|
475 | #set _pages 0 |
---|
476 | |
---|
477 | _simState on |
---|
478 | _fixSimControl |
---|
479 | reset |
---|
480 | } |
---|
481 | |
---|
482 | # ---------------------------------------------------------------------- |
---|
483 | # USAGE: _plot ?<index> <options> <index> <options>...? |
---|
484 | # |
---|
485 | # Used internally to update the plot shown in the current result |
---|
486 | # viewer whenever the resultset settings have changed. Causes the |
---|
487 | # desired results to show up on screen. |
---|
488 | # ---------------------------------------------------------------------- |
---|
489 | itcl::body Rappture::Analyzer::_plot {args} { |
---|
490 | set _plotlist $args |
---|
491 | |
---|
492 | set page [$itk_component(resultselector) value] |
---|
493 | set page [$itk_component(resultselector) translate $page] |
---|
494 | set f [$itk_component(resultpages) page $page] |
---|
495 | $f.rviewer plot clear |
---|
496 | foreach {index opts} $_plotlist { |
---|
497 | $f.rviewer plot add $index $opts |
---|
498 | } |
---|
499 | } |
---|
500 | |
---|
501 | # ---------------------------------------------------------------------- |
---|
502 | # USAGE: _reorder <compList> |
---|
503 | # |
---|
504 | # Used internally to change the order of a series of output components |
---|
505 | # found in the <output> section. Moves the <log> elements to the end |
---|
506 | # and returns the updated list. |
---|
507 | # ---------------------------------------------------------------------- |
---|
508 | itcl::body Rappture::Analyzer::_reorder {comps} { |
---|
509 | set i 0 |
---|
510 | set max [llength $comps] |
---|
511 | while {$i < $max} { |
---|
512 | set c [lindex $comps $i] |
---|
513 | if {[string match log* $c]} { |
---|
514 | set comps [lreplace $comps $i $i] |
---|
515 | lappend comps $c |
---|
516 | incr max -1 |
---|
517 | } else { |
---|
518 | incr i |
---|
519 | } |
---|
520 | } |
---|
521 | return $comps |
---|
522 | } |
---|
523 | |
---|
524 | # ---------------------------------------------------------------------- |
---|
525 | # USAGE: _autoLabel <xmlobj> <path> <title> <cntVar> |
---|
526 | # |
---|
527 | # Used internally to check for an about.label property at the <path> |
---|
528 | # in <xmlobj>. If this object doesn't have a label, then one is |
---|
529 | # supplied using the given <title>. The <cntVar> is an array of |
---|
530 | # counters in the calling scopes for titles that have been used |
---|
531 | # in the past. This is used to create titles like "Plot #2" the |
---|
532 | # second time it is encountered. |
---|
533 | # |
---|
534 | # The <xmlobj> is updated so that the label is inserted directly in |
---|
535 | # the tree. |
---|
536 | # ---------------------------------------------------------------------- |
---|
537 | itcl::body Rappture::Analyzer::_autoLabel {xmlobj path title cntVar} { |
---|
538 | upvar $cntVar counters |
---|
539 | |
---|
540 | set group [$xmlobj get $path.about.group] |
---|
541 | set label [$xmlobj get $path.about.label] |
---|
542 | if {"" == $label} { |
---|
543 | # no label -- make one up using the title specified |
---|
544 | if {![info exists counters($group-$title)]} { |
---|
545 | set counters($group-$title) 1 |
---|
546 | set label $title |
---|
547 | } else { |
---|
548 | set label "$title (#[incr counters($group-$title)])" |
---|
549 | } |
---|
550 | $xmlobj put $path.about.label $label |
---|
551 | } else { |
---|
552 | # handle the case of two identical labels in <output> |
---|
553 | if {![info exists counters($group-$label)]} { |
---|
554 | set counters($group-$label) 1 |
---|
555 | } else { |
---|
556 | set label "$label (#[incr counters($group-$label)])" |
---|
557 | $xmlobj put $path.about.label $label |
---|
558 | } |
---|
559 | } |
---|
560 | return $label |
---|
561 | } |
---|
562 | |
---|
563 | # ---------------------------------------------------------------------- |
---|
564 | # USAGE: _fixResult |
---|
565 | # |
---|
566 | # Used internally to change the result page being displayed whenever |
---|
567 | # the user selects a page from the results combobox. |
---|
568 | # ---------------------------------------------------------------------- |
---|
569 | itcl::body Rappture::Analyzer::_fixResult {} { |
---|
570 | set page [$itk_component(resultselector) value] |
---|
571 | set page [$itk_component(resultselector) translate $page] |
---|
572 | if {$page != ""} { |
---|
573 | $itk_component(resultpages) current $page |
---|
574 | |
---|
575 | set f [$itk_component(resultpages) page $page] |
---|
576 | $f.rviewer plot clear |
---|
577 | eval $f.rviewer plot add $_plotlist |
---|
578 | } |
---|
579 | } |
---|
580 | |
---|
581 | # ---------------------------------------------------------------------- |
---|
582 | # USAGE: _fixSize |
---|
583 | # |
---|
584 | # Used internally to change the size of the result set area whenever |
---|
585 | # a new control appears. Adjusts the size available for the result |
---|
586 | # set up to some maximum. |
---|
587 | # ---------------------------------------------------------------------- |
---|
588 | itcl::body Rappture::Analyzer::_fixSize {} { |
---|
589 | set f [$itk_component(results) fraction end] |
---|
590 | if {$f < 0.4} { |
---|
591 | $itk_component(results) fraction end [expr {$f+0.15}] |
---|
592 | } |
---|
593 | _fixSimControl |
---|
594 | } |
---|
595 | |
---|
596 | # ---------------------------------------------------------------------- |
---|
597 | # USAGE: _simState <boolean> ?<message>? ?<settings>? |
---|
598 | # |
---|
599 | # Used internally to change the "Simulation" button on or off. |
---|
600 | # If the <boolean> is on, then any <message> and <settings> are |
---|
601 | # displayed as well. The <message> is a note to the user about |
---|
602 | # what will be simulated, and the <settings> are a list of |
---|
603 | # tool parameter settings of the form {path1 val1 path2 val2 ...}. |
---|
604 | # When these are in place, the next Simulate operation will use |
---|
605 | # these settings. This helps fill in missing data values. |
---|
606 | # ---------------------------------------------------------------------- |
---|
607 | itcl::body Rappture::Analyzer::_simState {state args} { |
---|
608 | if {$state} { |
---|
609 | $itk_interior.simol configure \ |
---|
610 | -background $itk_option(-simcontrolactiveoutline) |
---|
611 | $itk_interior.simol.simbg configure \ |
---|
612 | -background $itk_option(-simcontrolactivebackground) |
---|
613 | $itk_component(simulate) configure \ |
---|
614 | -highlightbackground $itk_option(-simcontrolactivebackground) |
---|
615 | $itk_component(simstatus) configure \ |
---|
616 | -background $itk_option(-simcontrolactivebackground) |
---|
617 | |
---|
618 | $itk_component(abort) configure -state disabled |
---|
619 | $itk_component(simulate) configure -state normal \ |
---|
620 | -command [itcl::code $this simulate] |
---|
621 | |
---|
622 | # |
---|
623 | # If there's a special message, then put it up next to the button. |
---|
624 | # |
---|
625 | set mesg [lindex $args 0] |
---|
626 | if {"" != $mesg} { |
---|
627 | $itk_component(simstatus) configure -state normal |
---|
628 | $itk_component(simstatus) delete 1.0 end |
---|
629 | $itk_component(simstatus) insert end $mesg |
---|
630 | |
---|
631 | # |
---|
632 | # If there are any settings, then install them in the |
---|
633 | # "Simulate" button. Also, pop them up as a tooltip |
---|
634 | # for the message. |
---|
635 | # |
---|
636 | set settings [lindex $args 1] |
---|
637 | if {[llength $settings] > 0} { |
---|
638 | $itk_component(simulate) configure \ |
---|
639 | -command [eval itcl::code $this simulate $settings] |
---|
640 | |
---|
641 | set details "" |
---|
642 | foreach {path val} $settings { |
---|
643 | set str [$_tool xml get $path.about.label] |
---|
644 | if {"" == $str} { |
---|
645 | set str [$_tool xml element -as id $path] |
---|
646 | } |
---|
647 | append details "$str = $val\n" |
---|
648 | } |
---|
649 | set details [string trim $details] |
---|
650 | |
---|
651 | Rappture::Tooltip::for $itk_component(simstatus) $details |
---|
652 | $itk_component(simstatus) insert end " " |
---|
653 | $itk_component(simstatus) insert end "(details...)" popup |
---|
654 | } |
---|
655 | $itk_component(simstatus) configure -state disabled |
---|
656 | } |
---|
657 | } else { |
---|
658 | if {"" != $itk_option(-simcontrolbackground)} { |
---|
659 | set simcbg $itk_option(-simcontrolbackground) |
---|
660 | } else { |
---|
661 | set simcbg $itk_option(-background) |
---|
662 | } |
---|
663 | $itk_interior.simol configure \ |
---|
664 | -background $itk_option(-simcontroloutline) |
---|
665 | $itk_interior.simol.simbg configure -background $simcbg |
---|
666 | $itk_component(simulate) configure -highlightbackground $simcbg |
---|
667 | $itk_component(simstatus) configure -background $simcbg |
---|
668 | |
---|
669 | $itk_component(simulate) configure -state disabled |
---|
670 | $itk_component(abort) configure -state normal |
---|
671 | |
---|
672 | $itk_component(simstatus) configure -state normal |
---|
673 | $itk_component(simstatus) delete 1.0 end |
---|
674 | $itk_component(simstatus) configure -state disabled |
---|
675 | Rappture::Tooltip::for $itk_component(simstatus) "" |
---|
676 | } |
---|
677 | } |
---|
678 | |
---|
679 | # ---------------------------------------------------------------------- |
---|
680 | # USAGE: _fixSimControl |
---|
681 | # |
---|
682 | # Used internally to add or remove the simulation control at the |
---|
683 | # top of the analysis area. This is controlled by the -simcontrol |
---|
684 | # option. |
---|
685 | # ---------------------------------------------------------------------- |
---|
686 | itcl::body Rappture::Analyzer::_fixSimControl {} { |
---|
687 | switch -- $itk_option(-simcontrol) { |
---|
688 | on { |
---|
689 | pack $itk_interior.simol -fill x -before $itk_interior.nb |
---|
690 | } |
---|
691 | off { |
---|
692 | pack forget $itk_interior.simol |
---|
693 | } |
---|
694 | auto { |
---|
695 | # |
---|
696 | # If we have two or more radiodials, then there is a |
---|
697 | # chance of encountering a combination of parameters |
---|
698 | # with no data, requiring simulation. |
---|
699 | # |
---|
700 | if {[$itk_component(resultset) size -controls] >= 2} { |
---|
701 | pack $itk_interior.simol -fill x -before $itk_interior.nb |
---|
702 | } else { |
---|
703 | pack forget $itk_interior.simol |
---|
704 | } |
---|
705 | } |
---|
706 | default { |
---|
707 | error "bad value \"$itk_option(-simcontrol)\": should be on, off, auto" |
---|
708 | } |
---|
709 | } |
---|
710 | } |
---|
711 | |
---|
712 | # ---------------------------------------------------------------------- |
---|
713 | # CONFIGURATION OPTION: -simcontrol |
---|
714 | # |
---|
715 | # Controls whether or not the Simulate button is showing. In some |
---|
716 | # cases, it is not needed. |
---|
717 | # ---------------------------------------------------------------------- |
---|
718 | itcl::configbody Rappture::Analyzer::simcontrol { |
---|
719 | _fixSimControl |
---|
720 | } |
---|