1 | # -*- mode: tcl; indent-tabs-mode: nil -*- |
---|
2 | # ---------------------------------------------------------------------- |
---|
3 | # COMPONENT: analyzer - output area for Rappture |
---|
4 | # |
---|
5 | # This widget acts as the output side of a Rappture application. |
---|
6 | # When the input has changed, it displays a Simulate button that |
---|
7 | # launches the simulation. When a simulation is running, this |
---|
8 | # area shows status. When it is finished, the results appear |
---|
9 | # in place of the button, according to the specs in the <analyze> |
---|
10 | # XML data. |
---|
11 | # ====================================================================== |
---|
12 | # AUTHOR: Michael McLennan, Purdue University |
---|
13 | # Copyright (c) 2004-2012 HUBzero Foundation, LLC |
---|
14 | # |
---|
15 | # See the file "license.terms" for information on usage and |
---|
16 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
17 | # ====================================================================== |
---|
18 | package require Itk |
---|
19 | |
---|
20 | option add *Analyzer.width 3.5i widgetDefault |
---|
21 | option add *Analyzer.height 4i widgetDefault |
---|
22 | option add *Analyzer.simControl "auto" widgetDefault |
---|
23 | option add *Analyzer.simControlBackground "" widgetDefault |
---|
24 | option add *Analyzer.simControlOutline gray widgetDefault |
---|
25 | option add *Analyzer.simControlActiveBackground #ffffcc widgetDefault |
---|
26 | option add *Analyzer.simControlActiveOutline black widgetDefault |
---|
27 | option add *Analyzer.notebookpage "about" widgetDefault |
---|
28 | |
---|
29 | option add *Analyzer.font \ |
---|
30 | -*-helvetica-medium-r-normal-*-12-* widgetDefault |
---|
31 | option add *Analyzer.codeFont \ |
---|
32 | -*-courier-medium-r-normal-*-12-* widgetDefault |
---|
33 | option add *Analyzer.textFont \ |
---|
34 | -*-helvetica-medium-r-normal-*-12-* widgetDefault |
---|
35 | option add *Analyzer.boldTextFont \ |
---|
36 | -*-helvetica-bold-r-normal-*-12-* widgetDefault |
---|
37 | |
---|
38 | itcl::class Rappture::Analyzer { |
---|
39 | inherit itk::Widget |
---|
40 | |
---|
41 | itk_option define -codefont codeFont Font "" |
---|
42 | itk_option define -textfont textFont Font "" |
---|
43 | itk_option define -boldtextfont boldTextFont Font "" |
---|
44 | itk_option define -simcontrol simControl SimControl "" |
---|
45 | itk_option define -simcontroloutline simControlOutline Background "" |
---|
46 | itk_option define -simcontrolbackground simControlBackground Background "" |
---|
47 | itk_option define -simcontrolactiveoutline simControlActiveOutline Background "" |
---|
48 | itk_option define -simcontrolactivebackground simControlActiveBackground Background "" |
---|
49 | itk_option define -holdwindow holdWindow HoldWindow "" |
---|
50 | itk_option define -notebookpage notebookPage NotebookPage "" |
---|
51 | |
---|
52 | constructor {tool args} { |
---|
53 | # defined below |
---|
54 | } |
---|
55 | destructor { |
---|
56 | # defined below |
---|
57 | } |
---|
58 | |
---|
59 | public method simulate {args} |
---|
60 | public method reset {{when -eventually}} |
---|
61 | public method load {xmlobj} |
---|
62 | public method clear {{xmlobj "all"}} |
---|
63 | public method download {option args} |
---|
64 | |
---|
65 | protected method _plot {args} |
---|
66 | protected method _reorder {comps} |
---|
67 | protected method _autoLabel {xmlobj path title cntVar} |
---|
68 | protected method _fixResult {} |
---|
69 | protected method _fixResultSet {args} |
---|
70 | protected method _fixSize {} |
---|
71 | protected method _fixSimControl {} |
---|
72 | protected method _fixNotebook {} |
---|
73 | protected method _simState {state args} |
---|
74 | protected method _simOutput {message} |
---|
75 | protected method _resultTooltip {} |
---|
76 | protected method _isPdbTrajectory {data} |
---|
77 | protected method _isLammpsTrajectory {data} |
---|
78 | protected method _pdbToSequence {xmlobj path id child data} |
---|
79 | protected method _lammpsToSequence {xmlobj path id child data} |
---|
80 | protected method _trajToSequence {xmlobj {path ""}} |
---|
81 | |
---|
82 | private variable _tool "" ;# belongs to this tool |
---|
83 | private variable _appName "" ;# Name of application |
---|
84 | private variable _control "manual" ;# start mode |
---|
85 | private variable _resultset "" ;# ResultSet object with all results |
---|
86 | private variable _pages 0 ;# number of pages for result sets |
---|
87 | private variable _label2page ;# maps output label => result set |
---|
88 | private variable _label2desc ;# maps output label => description |
---|
89 | private variable _label2item ;# maps output label => output.xxx item |
---|
90 | private variable _lastlabel "" ;# label of last example loaded |
---|
91 | private variable _plotlist "" ;# items currently being plotted |
---|
92 | private variable _lastPlot |
---|
93 | private common job ;# array var used for blt::bgexec jobs |
---|
94 | } |
---|
95 | |
---|
96 | itk::usual Analyzer { |
---|
97 | keep -background -cursor foreground -font |
---|
98 | } |
---|
99 | |
---|
100 | # ---------------------------------------------------------------------- |
---|
101 | # CONSTRUCTOR |
---|
102 | # ---------------------------------------------------------------------- |
---|
103 | itcl::body Rappture::Analyzer::constructor {tool args} { |
---|
104 | set _tool $tool |
---|
105 | |
---|
106 | # use this to store all simulation results |
---|
107 | set _resultset [Rappture::ResultSet ::\#auto] |
---|
108 | $_resultset notify add $this [itcl::code $this _fixResultSet] |
---|
109 | |
---|
110 | # widget settings... |
---|
111 | itk_option add hull.width hull.height |
---|
112 | pack propagate $itk_component(hull) no |
---|
113 | |
---|
114 | frame $itk_interior.simol -borderwidth 1 -relief flat |
---|
115 | pack $itk_interior.simol -fill x |
---|
116 | |
---|
117 | itk_component add simbg { |
---|
118 | frame $itk_interior.simol.simbg -borderwidth 0 |
---|
119 | } { |
---|
120 | usual |
---|
121 | rename -background -simcontrolcolor simControlColor Color |
---|
122 | } |
---|
123 | pack $itk_component(simbg) -expand yes -fill both |
---|
124 | |
---|
125 | set simtxt [string trim [$tool xml get tool.action.label]] |
---|
126 | if {"" == $simtxt} { |
---|
127 | set simtxt "Simulate" |
---|
128 | } |
---|
129 | itk_component add simulate { |
---|
130 | button $itk_component(simbg).simulate -text $simtxt \ |
---|
131 | -command [itcl::code $this simulate] |
---|
132 | } { |
---|
133 | usual |
---|
134 | rename -highlightbackground -simcontrolcolor simControlColor Color |
---|
135 | } |
---|
136 | pack $itk_component(simulate) -side left -padx 4 -pady 4 |
---|
137 | |
---|
138 | # BE CAREFUL: Shift focus when we click on "Simulate". |
---|
139 | # This shifts focus away from input widgets and causes them to |
---|
140 | # finalize and log any pending changes. A better way would be |
---|
141 | # to have the "sync" operation finalize/sync, but this works |
---|
142 | # for now. |
---|
143 | bind $itk_component(simulate) <ButtonPress> {focus %W} |
---|
144 | |
---|
145 | # if there's a hub url, then add "About" and "Questions" links |
---|
146 | set _appName [$_tool xml get tool.id] |
---|
147 | set url [Rappture::Tool::resources -huburl] |
---|
148 | if {"" != $url && "" != $_appName} { |
---|
149 | itk_component add hubcntls { |
---|
150 | frame $itk_component(simbg).hubcntls |
---|
151 | } { |
---|
152 | usual |
---|
153 | rename -background -simcontrolcolor simControlColor Color |
---|
154 | } |
---|
155 | pack $itk_component(hubcntls) -side right -padx 4 |
---|
156 | |
---|
157 | itk_component add icon { |
---|
158 | label $itk_component(hubcntls).icon -image [Rappture::icon ask] \ |
---|
159 | -highlightthickness 0 |
---|
160 | } { |
---|
161 | usual |
---|
162 | ignore -highlightthickness |
---|
163 | rename -background -simcontrolcolor simControlColor Color |
---|
164 | } |
---|
165 | pack $itk_component(icon) -side left |
---|
166 | |
---|
167 | itk_component add about { |
---|
168 | button $itk_component(hubcntls).about -text "About this tool" \ |
---|
169 | -command [list Rappture::filexfer::webpage \ |
---|
170 | "$url/tools/$_appName"] |
---|
171 | } { |
---|
172 | usual |
---|
173 | ignore -font |
---|
174 | rename -background -simcontrolcolor simControlColor Color |
---|
175 | rename -highlightbackground -simcontrolcolor simControlColor Color |
---|
176 | } |
---|
177 | pack $itk_component(about) -side top -anchor w |
---|
178 | |
---|
179 | itk_component add questions { |
---|
180 | button $itk_component(hubcntls).questions -text Questions? \ |
---|
181 | -command [list Rappture::filexfer::webpage \ |
---|
182 | "$url/resources/$_appName/questions"] |
---|
183 | } { |
---|
184 | usual |
---|
185 | ignore -font |
---|
186 | rename -background -simcontrolcolor simControlColor Color |
---|
187 | rename -highlightbackground -simcontrolcolor simControlColor Color |
---|
188 | } |
---|
189 | pack $itk_component(questions) -side top -anchor w |
---|
190 | } |
---|
191 | |
---|
192 | itk_component add simstatus { |
---|
193 | text $itk_component(simbg).simstatus -borderwidth 0 \ |
---|
194 | -highlightthickness 0 -height 1 -width 1 -wrap none \ |
---|
195 | -state disabled |
---|
196 | } { |
---|
197 | usual |
---|
198 | ignore -highlightthickness |
---|
199 | rename -background -simcontrolcolor simControlColor Color |
---|
200 | rename -font -textfont textFont Font |
---|
201 | } |
---|
202 | pack $itk_component(simstatus) -side left -expand yes -fill x |
---|
203 | |
---|
204 | $itk_component(simstatus) tag configure popup \ |
---|
205 | -underline 1 -foreground blue |
---|
206 | |
---|
207 | $itk_component(simstatus) tag bind popup \ |
---|
208 | <Enter> {%W configure -cursor center_ptr} |
---|
209 | $itk_component(simstatus) tag bind popup \ |
---|
210 | <Leave> {%W configure -cursor ""} |
---|
211 | $itk_component(simstatus) tag bind popup \ |
---|
212 | <ButtonPress> {after idle {Rappture::Tooltip::tooltip show %W}} |
---|
213 | |
---|
214 | |
---|
215 | itk_component add notebook { |
---|
216 | Rappture::Notebook $itk_interior.nb |
---|
217 | } |
---|
218 | pack $itk_interior.nb -expand yes -fill both |
---|
219 | |
---|
220 | # ------------------------------------------------------------------ |
---|
221 | # ABOUT PAGE |
---|
222 | # ------------------------------------------------------------------ |
---|
223 | set w [$itk_component(notebook) insert end about] |
---|
224 | |
---|
225 | Rappture::Scroller $w.info -xscrollmode off -yscrollmode auto |
---|
226 | pack $w.info -expand yes -fill both -padx 4 -pady 20 |
---|
227 | itk_component add toolinfo { |
---|
228 | text $w.info.text -width 1 -height 1 -wrap word \ |
---|
229 | -borderwidth 0 -highlightthickness 0 |
---|
230 | } { |
---|
231 | usual |
---|
232 | ignore -borderwidth -relief |
---|
233 | rename -font -textfont textFont Font |
---|
234 | } |
---|
235 | $w.info contents $w.info.text |
---|
236 | |
---|
237 | # ------------------------------------------------------------------ |
---|
238 | # SIMULATION PAGE |
---|
239 | # ------------------------------------------------------------------ |
---|
240 | set w [$itk_component(notebook) insert end simulate] |
---|
241 | frame $w.cntls |
---|
242 | pack $w.cntls -side bottom -fill x -pady 12 |
---|
243 | frame $w.cntls.sep -background black -height 1 |
---|
244 | pack $w.cntls.sep -side top -fill x |
---|
245 | |
---|
246 | itk_component add abort { |
---|
247 | button $w.cntls.abort -text "Abort" \ |
---|
248 | -command [itcl::code $_tool abort] |
---|
249 | } |
---|
250 | pack $itk_component(abort) -side left -expand yes -padx 4 -pady 4 |
---|
251 | |
---|
252 | Rappture::Scroller $w.info -xscrollmode auto -yscrollmode auto |
---|
253 | pack $w.info -expand yes -fill both -padx 4 -pady 4 |
---|
254 | itk_component add runinfo { |
---|
255 | text $w.info.text -width 1 -height 1 -wrap none \ |
---|
256 | -borderwidth 0 -highlightthickness 0 \ |
---|
257 | -state disabled |
---|
258 | } { |
---|
259 | usual |
---|
260 | ignore -borderwidth -relief |
---|
261 | rename -font -codefont codeFont Font |
---|
262 | } |
---|
263 | $w.info contents $w.info.text |
---|
264 | |
---|
265 | itk_component add progress { |
---|
266 | Rappture::Progress $w.progress |
---|
267 | } |
---|
268 | |
---|
269 | # ------------------------------------------------------------------ |
---|
270 | # ANALYZE PAGE |
---|
271 | # ------------------------------------------------------------------ |
---|
272 | set w [$itk_component(notebook) insert end analyze] |
---|
273 | |
---|
274 | frame $w.top |
---|
275 | pack $w.top -side top -fill x -pady 8 |
---|
276 | label $w.top.l -text "Result:" -font $itk_option(-font) |
---|
277 | pack $w.top.l -side left |
---|
278 | |
---|
279 | itk_component add viewselector { |
---|
280 | Rappture::Combobox $w.top.sel -width 10 -editable no |
---|
281 | } { |
---|
282 | usual |
---|
283 | rename -font -textfont textFont Font |
---|
284 | } |
---|
285 | pack $itk_component(viewselector) -side left -expand yes -fill x |
---|
286 | bind $itk_component(viewselector) <<Value>> [itcl::code $this _fixResult] |
---|
287 | bind $itk_component(viewselector) <Enter> \ |
---|
288 | [itcl::code $this download coming] |
---|
289 | |
---|
290 | Rappture::Tooltip::for $itk_component(viewselector) \ |
---|
291 | "@[itcl::code $this _resultTooltip]" |
---|
292 | |
---|
293 | $itk_component(viewselector) choices insert end \ |
---|
294 | --- "---" |
---|
295 | |
---|
296 | itk_component add download { |
---|
297 | button $w.top.dl -image [Rappture::icon download] -anchor e \ |
---|
298 | -borderwidth 1 -relief flat -overrelief raised \ |
---|
299 | -command [itcl::code $this download start $w.top.dl] |
---|
300 | } |
---|
301 | pack $itk_component(download) -side right -padx {4 0} |
---|
302 | bind $itk_component(download) <Enter> \ |
---|
303 | [itcl::code $this download coming] |
---|
304 | |
---|
305 | $itk_component(viewselector) choices insert end \ |
---|
306 | @download [Rappture::filexfer::label download] |
---|
307 | |
---|
308 | if {[Rappture::filexfer::enabled]} { |
---|
309 | Rappture::Tooltip::for $itk_component(download) "Downloads the current result to a new web browser window on your desktop. From there, you can easily print or save results. |
---|
310 | |
---|
311 | NOTE: Your web browser must allow pop-ups from this site. If your output does not appear, look for a 'pop-up blocked' message and enable pop-ups." |
---|
312 | } else { |
---|
313 | Rappture::Tooltip::for $itk_component(download) "Saves the current result to a file on your desktop." |
---|
314 | } |
---|
315 | |
---|
316 | itk_component add results { |
---|
317 | Rappture::Panes $w.pane -sashwidth 1 -sashrelief solid -sashpadding {4 0} |
---|
318 | } |
---|
319 | pack $itk_component(results) -expand yes -fill both |
---|
320 | set f [$itk_component(results) pane 0] |
---|
321 | |
---|
322 | itk_component add resultpages { |
---|
323 | Rappture::Notebook $f.nb |
---|
324 | } |
---|
325 | pack $itk_component(resultpages) -expand yes -fill both |
---|
326 | |
---|
327 | set f [$itk_component(results) insert end -fraction 0.1] |
---|
328 | itk_component add resultselector { |
---|
329 | Rappture::ResultSelector $f.rsel -resultset $_resultset \ |
---|
330 | -settingscommand [itcl::code $this _plot] |
---|
331 | } |
---|
332 | pack $itk_component(resultselector) -expand yes -fill both |
---|
333 | bind $itk_component(resultselector) <<Layout>> [itcl::code $this _fixSize] |
---|
334 | bind $itk_component(results) <Configure> [itcl::code $this _fixSize] |
---|
335 | |
---|
336 | eval itk_initialize $args |
---|
337 | |
---|
338 | $itk_component(runinfo) tag configure ERROR -foreground red |
---|
339 | $itk_component(runinfo) tag configure text -font $itk_option(-textfont) |
---|
340 | |
---|
341 | # |
---|
342 | # Load up tool info on the first page. |
---|
343 | # |
---|
344 | $itk_component(toolinfo) tag configure title \ |
---|
345 | -font $itk_option(-boldtextfont) |
---|
346 | |
---|
347 | set mesg [string trim [$tool xml get tool.title]] |
---|
348 | if {"" != $mesg} { |
---|
349 | $itk_component(toolinfo) insert end $mesg title |
---|
350 | $itk_component(toolinfo) insert end "\n\n" |
---|
351 | } |
---|
352 | |
---|
353 | set mesg [string trim [$tool xml get tool.about]] |
---|
354 | if {"" != $mesg} { |
---|
355 | $itk_component(toolinfo) insert end $mesg |
---|
356 | } |
---|
357 | $itk_component(toolinfo) configure -state disabled |
---|
358 | $itk_component(notebook) current about |
---|
359 | |
---|
360 | # tool can run on "manual" (default) or "auto" |
---|
361 | set cntl [string trim [$tool xml get tool.control]] |
---|
362 | if {"" == $cntl} { |
---|
363 | set cntl [string trim [$tool xml get tool.control.type]] |
---|
364 | } |
---|
365 | if {"" != $cntl} { |
---|
366 | set _control $cntl |
---|
367 | } |
---|
368 | |
---|
369 | # reset everything to a clean state |
---|
370 | reset |
---|
371 | } |
---|
372 | |
---|
373 | # ---------------------------------------------------------------------- |
---|
374 | # DESTRUCTOR |
---|
375 | # ---------------------------------------------------------------------- |
---|
376 | itcl::body Rappture::Analyzer::destructor {} { |
---|
377 | after cancel [itcl::code $this simulate] |
---|
378 | $_resultset notify remove $this |
---|
379 | itcl::delete object $_resultset |
---|
380 | } |
---|
381 | |
---|
382 | # ---------------------------------------------------------------------- |
---|
383 | # USAGE: simulate ?-ifneeded? |
---|
384 | # USAGE: simulate ?<path1> <value1> <path2> <value2> ...? |
---|
385 | # |
---|
386 | # Kicks off the simulator by executing the tool.command associated |
---|
387 | # with the tool. If any arguments are specified, they are used to |
---|
388 | # set parameters for the simulation. While the simulation is running, |
---|
389 | # it shows status. When the simulation is finished, it switches |
---|
390 | # automatically to "analyze" mode and shows the results. |
---|
391 | # ---------------------------------------------------------------------- |
---|
392 | itcl::body Rappture::Analyzer::simulate {args} { |
---|
393 | if {$args == "-ifneeded"} { |
---|
394 | # check to see if simulation is really needed |
---|
395 | $_tool sync |
---|
396 | if {[$_resultset contains [$_tool xml object]] |
---|
397 | && ![string equal $_control "manual-resim"]} { |
---|
398 | # not needed -- show results and return |
---|
399 | $itk_component(notebook) current analyze |
---|
400 | return |
---|
401 | } |
---|
402 | set args "" |
---|
403 | } |
---|
404 | |
---|
405 | # simulation is needed -- go to simulation page |
---|
406 | $itk_component(notebook) current simulate |
---|
407 | |
---|
408 | # no progress messages yet |
---|
409 | pack forget $itk_component(progress) |
---|
410 | lappend args -output [itcl::code $this _simOutput] |
---|
411 | |
---|
412 | _simState off |
---|
413 | $itk_component(runinfo) configure -state normal |
---|
414 | $itk_component(runinfo) delete 1.0 end |
---|
415 | $itk_component(runinfo) insert end "Running simulation...\n\n" text |
---|
416 | $itk_component(runinfo) configure -state disabled |
---|
417 | |
---|
418 | # if the hold window is set, then put up a busy cursor |
---|
419 | if {$itk_option(-holdwindow) != ""} { |
---|
420 | blt::busy hold $itk_option(-holdwindow) |
---|
421 | raise $itk_component(hull) |
---|
422 | } |
---|
423 | |
---|
424 | # execute the job |
---|
425 | foreach {status result} [eval $_tool run $args] break |
---|
426 | |
---|
427 | # if job was aborted, then allow simulation again |
---|
428 | if {$result == "ABORT"} { |
---|
429 | _simState on "Aborted" |
---|
430 | } |
---|
431 | |
---|
432 | # load results from run.xml into analyzer |
---|
433 | if {$status == 0 && $result != "ABORT"} { |
---|
434 | set status [catch {load $result} result] |
---|
435 | } |
---|
436 | |
---|
437 | # back to normal |
---|
438 | if {$itk_option(-holdwindow) != ""} { |
---|
439 | blt::busy release $itk_option(-holdwindow) |
---|
440 | } |
---|
441 | $itk_component(abort) configure -state disabled |
---|
442 | |
---|
443 | if {$status != 0} { |
---|
444 | $itk_component(runinfo) configure -state normal |
---|
445 | $itk_component(runinfo) delete 1.0 end |
---|
446 | $itk_component(runinfo) insert end "Problem launching job:\n\n" text |
---|
447 | _simOutput $result |
---|
448 | $itk_component(runinfo) configure -state disabled |
---|
449 | $itk_component(runinfo) see 1.0 |
---|
450 | |
---|
451 | # Try to create a support ticket for this error. |
---|
452 | # It may be a real problem. |
---|
453 | if {[Rappture::bugreport::shouldReport for jobs]} { |
---|
454 | set ::errorInfo "\n\n== RAPPTURE INPUT ==\n[$_tool xml xml]" |
---|
455 | Rappture::bugreport::register "Problem launching job:\n$result" |
---|
456 | Rappture::bugreport::attachment [$_tool xml xml] |
---|
457 | Rappture::bugreport::send |
---|
458 | } |
---|
459 | } else { |
---|
460 | $itk_component(notebook) current analyze |
---|
461 | } |
---|
462 | |
---|
463 | # do this last -- after _simOutput above |
---|
464 | pack forget $itk_component(progress) |
---|
465 | } |
---|
466 | |
---|
467 | # ---------------------------------------------------------------------- |
---|
468 | # USAGE: reset ?-eventually|-now? |
---|
469 | # |
---|
470 | # Used to reset the analyzer whenever the input to a simulation has |
---|
471 | # changed. Sets the mode back to "simulate", so the user has to |
---|
472 | # simulate again to see the output. If the <start> option is set |
---|
473 | # to "auto", the simulation is invoked immediately. |
---|
474 | # ---------------------------------------------------------------------- |
---|
475 | itcl::body Rappture::Analyzer::reset {{when -eventually}} { |
---|
476 | if {$when == "-eventually"} { |
---|
477 | after cancel [list catch [itcl::code $this reset -now]] |
---|
478 | after idle [list catch [itcl::code $this reset -now]] |
---|
479 | return |
---|
480 | } |
---|
481 | |
---|
482 | # check to see if simulation is really needed |
---|
483 | $_tool sync |
---|
484 | if {![$_resultset contains [$_tool xml object]] |
---|
485 | || [string equal $_control "manual-resim"]} { |
---|
486 | # if control mode is "auto", then simulate right away |
---|
487 | if {[string match auto* $_control]} { |
---|
488 | # auto control -- don't need button |
---|
489 | pack forget $itk_interior.simol |
---|
490 | |
---|
491 | after cancel [itcl::code $this simulate] |
---|
492 | after idle [itcl::code $this simulate] |
---|
493 | } else { |
---|
494 | _simState on "new input parameters" |
---|
495 | } |
---|
496 | } else { |
---|
497 | _simState off |
---|
498 | } |
---|
499 | } |
---|
500 | |
---|
501 | # ---------------------------------------------------------------------- |
---|
502 | # USAGE: load <xmlobj> |
---|
503 | # |
---|
504 | # Loads the data from the given <xmlobj> into the appropriate results |
---|
505 | # sets. If necessary, new results sets are created to store the data. |
---|
506 | # ---------------------------------------------------------------------- |
---|
507 | itcl::body Rappture::Analyzer::load {xmlobj} { |
---|
508 | # only show the last result? then clear first |
---|
509 | if {[string trim [$_tool xml get tool.analyzer]] == "last"} { |
---|
510 | clear |
---|
511 | } |
---|
512 | $_resultset add $xmlobj |
---|
513 | |
---|
514 | # NOTE: Adding will trigger a !change event on the ResultSet |
---|
515 | # object, which will trigger calls to _fixResultSet to add |
---|
516 | # the results to display. |
---|
517 | } |
---|
518 | |
---|
519 | # ---------------------------------------------------------------------- |
---|
520 | # USAGE: clear ?<xmlobj>? |
---|
521 | # |
---|
522 | # Discards one or more results previously loaded into the analyzer. |
---|
523 | # If an <xmlobj> is specified, then that one result is cleared. |
---|
524 | # Otherwise, all results are cleared. |
---|
525 | # ---------------------------------------------------------------------- |
---|
526 | itcl::body Rappture::Analyzer::clear {{xmlobj "all"}} { |
---|
527 | if {$xmlobj eq "" || $xmlobj eq "all"} { |
---|
528 | $_resultset clear |
---|
529 | } else { |
---|
530 | $_resultset clear $xmlobj |
---|
531 | } |
---|
532 | |
---|
533 | # NOTE: Clearing will trigger a !change event on the ResultSet |
---|
534 | # object, which will trigger calls to _fixResultSet to clean up |
---|
535 | # the results being displayed. |
---|
536 | } |
---|
537 | |
---|
538 | # ---------------------------------------------------------------------- |
---|
539 | # USAGE: download coming |
---|
540 | # USAGE: download controls <downloadCommand> |
---|
541 | # USAGE: download start ?widget? |
---|
542 | # USAGE: download now ?widget? |
---|
543 | # |
---|
544 | # Spools the current result so the user can download it. |
---|
545 | # ---------------------------------------------------------------------- |
---|
546 | itcl::body Rappture::Analyzer::download {option args} { |
---|
547 | set title [$itk_component(viewselector) value] |
---|
548 | set page [$itk_component(viewselector) translate $title] |
---|
549 | |
---|
550 | switch -- $option { |
---|
551 | coming { |
---|
552 | # |
---|
553 | # Warn result that a download is coming, in case |
---|
554 | # it needs to take a screen snap. |
---|
555 | # |
---|
556 | if {![regexp {^(|@download|---)$} $page]} { |
---|
557 | set f [$itk_component(resultpages) page $page] |
---|
558 | $f.rviewer download coming |
---|
559 | } |
---|
560 | } |
---|
561 | controls { |
---|
562 | # no controls for this download yet |
---|
563 | return "" |
---|
564 | } |
---|
565 | start { |
---|
566 | set widget $itk_component(download) |
---|
567 | if {[llength $args] > 0} { |
---|
568 | set widget [lindex $args 0] |
---|
569 | if {[catch {winfo class $widget}]} { |
---|
570 | set widget $itk_component(download) |
---|
571 | } |
---|
572 | } |
---|
573 | # |
---|
574 | # See if this download has any controls. If so, then |
---|
575 | # post them now and let the user continue the download |
---|
576 | # after selecting a file format. |
---|
577 | # |
---|
578 | if {$page != ""} { |
---|
579 | set ext "" |
---|
580 | set f [$itk_component(resultpages) page $page] |
---|
581 | set arg [itcl::code $this download now $widget] |
---|
582 | set popup [$f.rviewer download controls $arg] |
---|
583 | if {"" != $popup} { |
---|
584 | $popup activate $widget below |
---|
585 | } else { |
---|
586 | download now $widget |
---|
587 | } |
---|
588 | } else { |
---|
589 | # this shouldn't happen |
---|
590 | set file error.html |
---|
591 | set data "<h1>Not Found</h1>There is no result selected." |
---|
592 | } |
---|
593 | } |
---|
594 | now { |
---|
595 | set widget $itk_component(download) |
---|
596 | if {[llength $args] > 0} { |
---|
597 | set widget [lindex $args 0] |
---|
598 | if {[catch {winfo class $widget}]} { |
---|
599 | set widget $itk_component(download) |
---|
600 | } |
---|
601 | } |
---|
602 | # |
---|
603 | # Perform the actual download. |
---|
604 | # |
---|
605 | if {$page != ""} { |
---|
606 | set ext "" |
---|
607 | set f [$itk_component(resultpages) page $page] |
---|
608 | set item [$itk_component(viewselector) value] |
---|
609 | set result [$f.rviewer download now $widget $_appName $item] |
---|
610 | if { $result == "" } { |
---|
611 | return; # User cancelled the download. |
---|
612 | } |
---|
613 | foreach {ext data} $result break |
---|
614 | if {"" == $ext} { |
---|
615 | if {"" != $widget} { |
---|
616 | Rappture::Tooltip::cue $widget \ |
---|
617 | "Can't download this result." |
---|
618 | } |
---|
619 | return |
---|
620 | } |
---|
621 | regsub -all {[\ -\/\:-\@\{-\~]} $title {} title |
---|
622 | set file "$title$ext" |
---|
623 | } else { |
---|
624 | # this shouldn't happen |
---|
625 | set file error.html |
---|
626 | set data "<h1>Not Found</h1>There is no result selected." |
---|
627 | } |
---|
628 | |
---|
629 | Rappture::Logger::log download [$itk_component(viewselector) value] |
---|
630 | set mesg [Rappture::filexfer::download $data $file] |
---|
631 | if {[string length $mesg] > 0} { |
---|
632 | Rappture::Tooltip::cue $widget $mesg |
---|
633 | } |
---|
634 | } |
---|
635 | default { |
---|
636 | error "bad option \"$option\": should be coming, controls, now, start" |
---|
637 | } |
---|
638 | } |
---|
639 | } |
---|
640 | |
---|
641 | # ---------------------------------------------------------------------- |
---|
642 | # USAGE: _plot ?<index> <options> <index> <options>...? |
---|
643 | # |
---|
644 | # Used internally to update the plot shown in the current result |
---|
645 | # viewer whenever the resultselector settings have changed. Causes the |
---|
646 | # desired results to show up on screen. |
---|
647 | # ---------------------------------------------------------------------- |
---|
648 | itcl::body Rappture::Analyzer::_plot {args} { |
---|
649 | set _plotlist $args |
---|
650 | |
---|
651 | set page [$itk_component(viewselector) value] |
---|
652 | set page [$itk_component(viewselector) translate $page] |
---|
653 | if {"" != $page} { |
---|
654 | set f [$itk_component(resultpages) page $page] |
---|
655 | $f.rviewer plot clear |
---|
656 | foreach {index opts} $_plotlist { |
---|
657 | $f.rviewer plot add $index $opts |
---|
658 | } |
---|
659 | } |
---|
660 | } |
---|
661 | |
---|
662 | # ---------------------------------------------------------------------- |
---|
663 | # USAGE: _reorder <compList> |
---|
664 | # |
---|
665 | # Used internally to change the order of a series of output components |
---|
666 | # found in the <output> section. Moves the <log> elements to the end |
---|
667 | # and returns the updated list. |
---|
668 | # ---------------------------------------------------------------------- |
---|
669 | itcl::body Rappture::Analyzer::_reorder {comps} { |
---|
670 | set i 0 |
---|
671 | set max [llength $comps] |
---|
672 | while {$i < $max} { |
---|
673 | set c [lindex $comps $i] |
---|
674 | if {[string match log* $c]} { |
---|
675 | set comps [lreplace $comps $i $i] |
---|
676 | lappend comps $c |
---|
677 | incr max -1 |
---|
678 | } else { |
---|
679 | incr i |
---|
680 | } |
---|
681 | } |
---|
682 | return $comps |
---|
683 | } |
---|
684 | |
---|
685 | # ---------------------------------------------------------------------- |
---|
686 | # USAGE: _autoLabel <xmlobj> <path> <title> <cntVar> |
---|
687 | # |
---|
688 | # Used internally to check for an about.label property at the <path> |
---|
689 | # in <xmlobj>. If this object doesn't have a label, then one is |
---|
690 | # supplied using the given <title>. The <cntVar> is an array of |
---|
691 | # counters in the calling scopes for titles that have been used |
---|
692 | # in the past. This is used to create titles like "Plot #2" the |
---|
693 | # second time it is encountered. |
---|
694 | # |
---|
695 | # The <xmlobj> is updated so that the label is inserted directly in |
---|
696 | # the tree. |
---|
697 | # ---------------------------------------------------------------------- |
---|
698 | itcl::body Rappture::Analyzer::_autoLabel {xmlobj path title cntVar} { |
---|
699 | upvar $cntVar counters |
---|
700 | |
---|
701 | set group [$xmlobj get $path.about.group] |
---|
702 | set label [$xmlobj get $path.about.label] |
---|
703 | if {"" == $label} { |
---|
704 | # no label -- make one up using the title specified |
---|
705 | if {![info exists counters($group-$title)]} { |
---|
706 | set counters($group-$title) 1 |
---|
707 | set label $title |
---|
708 | } else { |
---|
709 | set label "$title (#[incr counters($group-$title)])" |
---|
710 | } |
---|
711 | $xmlobj put $path.about.label $label |
---|
712 | } else { |
---|
713 | # handle the case of two identical labels in <output> |
---|
714 | if {![info exists counters($group-$label)]} { |
---|
715 | set counters($group-$label) 1 |
---|
716 | } else { |
---|
717 | set label "$label (#[incr counters($group-$label)])" |
---|
718 | $xmlobj put $path.about.label $label |
---|
719 | } |
---|
720 | } |
---|
721 | return $label |
---|
722 | } |
---|
723 | |
---|
724 | # ---------------------------------------------------------------------- |
---|
725 | # USAGE: _fixResult |
---|
726 | # |
---|
727 | # Used internally to change the result page being displayed whenever |
---|
728 | # the user selects a page from the results combobox. |
---|
729 | # ---------------------------------------------------------------------- |
---|
730 | itcl::body Rappture::Analyzer::_fixResult {} { |
---|
731 | set name [$itk_component(viewselector) value] |
---|
732 | set page "" |
---|
733 | if {"" != $name} { |
---|
734 | set page [$itk_component(viewselector) translate $name] |
---|
735 | } |
---|
736 | if {$page == "@download"} { |
---|
737 | # put the combobox back to its last value |
---|
738 | $itk_component(viewselector) component entry configure -state normal |
---|
739 | $itk_component(viewselector) component entry delete 0 end |
---|
740 | $itk_component(viewselector) component entry insert end $_lastlabel |
---|
741 | $itk_component(viewselector) component entry configure -state disabled |
---|
742 | # perform the actual download |
---|
743 | download start $itk_component(download) |
---|
744 | } elseif {$page == "---"} { |
---|
745 | # put the combobox back to its last value |
---|
746 | $itk_component(viewselector) component entry configure -state normal |
---|
747 | $itk_component(viewselector) component entry delete 0 end |
---|
748 | $itk_component(viewselector) component entry insert end $_lastlabel |
---|
749 | $itk_component(viewselector) component entry configure -state disabled |
---|
750 | } elseif {$page != ""} { |
---|
751 | set _lastlabel $name |
---|
752 | set win [winfo toplevel $itk_component(hull)] |
---|
753 | $itk_component(resultpages) current $page |
---|
754 | set f [$itk_component(resultpages) page $page] |
---|
755 | |
---|
756 | # We don't want to replot if we're using an existing viewer with the |
---|
757 | # the same list of objects to plot. So track the viewer and the list. |
---|
758 | if { ![info exists _lastPlot($f)] || $_plotlist != $_lastPlot($f) } { |
---|
759 | set _lastPlot($f) $_plotlist |
---|
760 | blt::busy hold $win |
---|
761 | $f.rviewer plot clear |
---|
762 | eval $f.rviewer plot add $_plotlist |
---|
763 | blt::busy release [winfo toplevel $itk_component(hull)] |
---|
764 | } |
---|
765 | Rappture::Logger::log output $_label2item($name) |
---|
766 | Rappture::Tooltip::for $itk_component(viewselector) \ |
---|
767 | "@[itcl::code $this _resultTooltip]" -log $_label2item($name) |
---|
768 | } |
---|
769 | } |
---|
770 | |
---|
771 | # ---------------------------------------------------------------------- |
---|
772 | # USAGE: _fixResultSet ?<eventData>...? |
---|
773 | # |
---|
774 | # Used internally to react to changes within the ResultSet. When a |
---|
775 | # result is added, a new result viewer is created for the object. |
---|
776 | # When all results are cleared, the viewers are deleted. |
---|
777 | # ---------------------------------------------------------------------- |
---|
778 | itcl::body Rappture::Analyzer::_fixResultSet {args} { |
---|
779 | array set eventData $args |
---|
780 | switch -- $eventData(op) { |
---|
781 | add { |
---|
782 | set xmlobj $eventData(what) |
---|
783 | |
---|
784 | # Detect molecule elements that contain trajectory data |
---|
785 | # and convert to sequences. |
---|
786 | _trajToSequence $xmlobj output |
---|
787 | |
---|
788 | # Go through the analysis and find all result sets. |
---|
789 | set haveresults 0 |
---|
790 | foreach item [_reorder [$xmlobj children output]] { |
---|
791 | switch -glob -- $item { |
---|
792 | log* { |
---|
793 | _autoLabel $xmlobj output.$item "Output Log" counters |
---|
794 | } |
---|
795 | number* { |
---|
796 | _autoLabel $xmlobj output.$item "Number" counters |
---|
797 | } |
---|
798 | integer* { |
---|
799 | _autoLabel $xmlobj output.$item "Integer" counters |
---|
800 | } |
---|
801 | string* { |
---|
802 | _autoLabel $xmlobj output.$item "String" counters |
---|
803 | } |
---|
804 | histogram* - curve* - field* { |
---|
805 | _autoLabel $xmlobj output.$item "Plot" counters |
---|
806 | } |
---|
807 | drawing* { |
---|
808 | _autoLabel $xmlobj output.$item "Drawing" counters |
---|
809 | } |
---|
810 | structure* { |
---|
811 | _autoLabel $xmlobj output.$item "Structure" counters |
---|
812 | } |
---|
813 | table* { |
---|
814 | _autoLabel $xmlobj output.$item "Energy Levels" counters |
---|
815 | } |
---|
816 | sequence* { |
---|
817 | _autoLabel $xmlobj output.$item "Sequence" counters |
---|
818 | } |
---|
819 | } |
---|
820 | set label [$xmlobj get output.$item.about.group] |
---|
821 | if {"" == $label} { |
---|
822 | set label [$xmlobj get output.$item.about.label] |
---|
823 | } |
---|
824 | |
---|
825 | set hidden [$xmlobj get output.$item.hide] |
---|
826 | set hidden [expr {"" != $hidden && $hidden}] |
---|
827 | |
---|
828 | if {"" != $label && !$hidden} { |
---|
829 | set haveresults 1 |
---|
830 | } |
---|
831 | } |
---|
832 | |
---|
833 | # if there are any valid results, add them to the resultset |
---|
834 | if {$haveresults} { |
---|
835 | set index [$_resultset get simnum $xmlobj] |
---|
836 | |
---|
837 | # add each result to a result viewer |
---|
838 | foreach item [_reorder [$xmlobj children output]] { |
---|
839 | set label [$xmlobj get output.$item.about.group] |
---|
840 | if {"" == $label} { |
---|
841 | set label [$xmlobj get output.$item.about.label] |
---|
842 | } |
---|
843 | set hidden [$xmlobj get output.$item.hide] |
---|
844 | if { $hidden == "" } { |
---|
845 | set hidden 0 |
---|
846 | } |
---|
847 | if {"" != $label && !$hidden} { |
---|
848 | if {![info exists _label2page($label)]} { |
---|
849 | set name "page[incr _pages]" |
---|
850 | set page [$itk_component(resultpages) \ |
---|
851 | insert end $name] |
---|
852 | set _label2page($label) $page |
---|
853 | set _label2item($label) output.$item |
---|
854 | set _label2desc($label) \ |
---|
855 | [$xmlobj get output.$item.about.description] |
---|
856 | Rappture::ResultViewer $page.rviewer |
---|
857 | pack $page.rviewer -expand yes -fill both -pady 4 |
---|
858 | |
---|
859 | set end [$itk_component(viewselector) \ |
---|
860 | choices index -value ---] |
---|
861 | if {$end < 0} { |
---|
862 | set end "end" |
---|
863 | } |
---|
864 | $itk_component(viewselector) choices insert $end \ |
---|
865 | $name $label |
---|
866 | } |
---|
867 | |
---|
868 | # add/replace the latest result into this viewer |
---|
869 | set page $_label2page($label) |
---|
870 | |
---|
871 | if {![info exists reset($page)]} { |
---|
872 | $page.rviewer clear $index |
---|
873 | set reset($page) 1 |
---|
874 | } |
---|
875 | $page.rviewer add $index $xmlobj output.$item |
---|
876 | } |
---|
877 | } |
---|
878 | } |
---|
879 | |
---|
880 | # show the first page by default |
---|
881 | set max [$itk_component(viewselector) choices size] |
---|
882 | for {set i 0} {$i < $max} {incr i} { |
---|
883 | set first [$itk_component(viewselector) choices get -label $i] |
---|
884 | if {$first != ""} { |
---|
885 | set page [$itk_component(viewselector) choices get -value $i] |
---|
886 | set char [string index $page 0] |
---|
887 | if {$char != "@" && $char != "-"} { |
---|
888 | $itk_component(resultpages) current $page |
---|
889 | $itk_component(viewselector) value $first |
---|
890 | set _lastlabel $first |
---|
891 | break |
---|
892 | } |
---|
893 | } |
---|
894 | } |
---|
895 | } |
---|
896 | clear { |
---|
897 | if {$eventData(what) ne "all"} { |
---|
898 | # delete this result from all viewers |
---|
899 | array set params $eventData(what) |
---|
900 | foreach label [array names _label2page] { |
---|
901 | set page $_label2page($label) |
---|
902 | $page.rviewer clear $params(simnum) |
---|
903 | } |
---|
904 | } |
---|
905 | |
---|
906 | if {[$_resultset size] == 0} { |
---|
907 | # reset the size of the controls area |
---|
908 | set ht [winfo height $itk_component(results)] |
---|
909 | set cntlht [$itk_component(resultselector) size -controlarea] |
---|
910 | set frac [expr {double($cntlht)/$ht}] |
---|
911 | $itk_component(results) fraction end $frac |
---|
912 | |
---|
913 | foreach label [array names _label2page] { |
---|
914 | set page $_label2page($label) |
---|
915 | destroy $page.rviewer |
---|
916 | } |
---|
917 | $itk_component(resultpages) delete -all |
---|
918 | set _pages 0 |
---|
919 | |
---|
920 | $itk_component(viewselector) value "" |
---|
921 | $itk_component(viewselector) choices delete 0 end |
---|
922 | catch {unset _label2page} |
---|
923 | catch {unset _label2item} |
---|
924 | catch {unset _label2desc} |
---|
925 | set _plotlist "" |
---|
926 | |
---|
927 | $itk_component(viewselector) choices insert end --- "---" |
---|
928 | $itk_component(viewselector) choices insert end \ |
---|
929 | @download [Rappture::filexfer::label download] |
---|
930 | set _lastlabel "" |
---|
931 | } |
---|
932 | |
---|
933 | # fix Simulate button state |
---|
934 | reset |
---|
935 | } |
---|
936 | default { |
---|
937 | error "don't know how to handle op \"$eventData(op)\"" |
---|
938 | } |
---|
939 | } |
---|
940 | } |
---|
941 | |
---|
942 | # ---------------------------------------------------------------------- |
---|
943 | # USAGE: _fixSize |
---|
944 | # |
---|
945 | # Used internally to change the size of the result set area whenever |
---|
946 | # a new control appears. Adjusts the size available for the result |
---|
947 | # set up to some maximum. |
---|
948 | # ---------------------------------------------------------------------- |
---|
949 | itcl::body Rappture::Analyzer::_fixSize {} { |
---|
950 | set ht [winfo height $itk_component(results)] |
---|
951 | if {$ht <= 1} { set ht [winfo reqheight $itk_component(results)] } |
---|
952 | set cntlht [$itk_component(resultselector) size -controlarea] |
---|
953 | set frac [expr {double($cntlht)/$ht}] |
---|
954 | |
---|
955 | if {$frac < 0.4} { |
---|
956 | $itk_component(results) fraction end $frac |
---|
957 | } |
---|
958 | _fixSimControl |
---|
959 | } |
---|
960 | |
---|
961 | # ---------------------------------------------------------------------- |
---|
962 | # USAGE: _simState <boolean> ?<message>? ?<settings>? |
---|
963 | # |
---|
964 | # Used internally to change the "Simulation" button on or off. |
---|
965 | # If the <boolean> is on, then any <message> and <settings> are |
---|
966 | # displayed as well. If the <boolean> is off, then only display |
---|
967 | # the message. The <message> is a note to the user about |
---|
968 | # what will be simulated, and the <settings> are a list of |
---|
969 | # tool parameter settings of the form {path1 val1 path2 val2 ...}. |
---|
970 | # When these are in place, the next Simulate operation will use |
---|
971 | # these settings. This helps fill in missing data values. |
---|
972 | # ---------------------------------------------------------------------- |
---|
973 | itcl::body Rappture::Analyzer::_simState {state args} { |
---|
974 | if {$state} { |
---|
975 | $itk_interior.simol configure \ |
---|
976 | -background $itk_option(-simcontrolactiveoutline) |
---|
977 | configure -simcontrolcolor $itk_option(-simcontrolactivebackground) |
---|
978 | |
---|
979 | $itk_component(abort) configure -state disabled |
---|
980 | $itk_component(simulate) configure -state normal \ |
---|
981 | -command [itcl::code $this simulate] |
---|
982 | |
---|
983 | # |
---|
984 | # If there's a special message, then put it up next to the button. |
---|
985 | # |
---|
986 | set mesg [lindex $args 0] |
---|
987 | if {"" != $mesg} { |
---|
988 | $itk_component(simstatus) configure -state normal |
---|
989 | $itk_component(simstatus) delete 1.0 end |
---|
990 | $itk_component(simstatus) insert end $mesg |
---|
991 | |
---|
992 | # |
---|
993 | # If there are any settings, then install them in the |
---|
994 | # "Simulate" button. Also, pop them up as a tooltip |
---|
995 | # for the message. |
---|
996 | # |
---|
997 | set settings [lindex $args 1] |
---|
998 | if {[llength $settings] > 0} { |
---|
999 | $itk_component(simulate) configure \ |
---|
1000 | -command [eval itcl::code $this simulate $settings] |
---|
1001 | |
---|
1002 | set details "" |
---|
1003 | foreach {path val} $settings { |
---|
1004 | set str [string trim [$_tool xml get $path.about.label]] |
---|
1005 | if {"" == $str} { |
---|
1006 | set str [$_tool xml element -as id $path] |
---|
1007 | } |
---|
1008 | append details "$str = $val\n" |
---|
1009 | } |
---|
1010 | set details [string trim $details] |
---|
1011 | |
---|
1012 | Rappture::Tooltip::for $itk_component(simstatus) $details |
---|
1013 | $itk_component(simstatus) insert end " " |
---|
1014 | $itk_component(simstatus) insert end "(details...)" popup |
---|
1015 | } |
---|
1016 | $itk_component(simstatus) configure -state disabled |
---|
1017 | } |
---|
1018 | } else { |
---|
1019 | if {"" != $itk_option(-simcontrolbackground)} { |
---|
1020 | set simcbg $itk_option(-simcontrolbackground) |
---|
1021 | } else { |
---|
1022 | set simcbg $itk_option(-background) |
---|
1023 | } |
---|
1024 | $itk_interior.simol configure \ |
---|
1025 | -background $itk_option(-simcontroloutline) |
---|
1026 | configure -simcontrolcolor $simcbg |
---|
1027 | |
---|
1028 | $itk_component(simulate) configure -state disabled |
---|
1029 | $itk_component(abort) configure -state normal |
---|
1030 | |
---|
1031 | $itk_component(simstatus) configure -state normal |
---|
1032 | $itk_component(simstatus) delete 1.0 end |
---|
1033 | set mesg [lindex $args 0] |
---|
1034 | if {"" != $mesg} { |
---|
1035 | $itk_component(simstatus) insert end $mesg |
---|
1036 | } |
---|
1037 | $itk_component(simstatus) configure -state disabled |
---|
1038 | } |
---|
1039 | } |
---|
1040 | |
---|
1041 | # ---------------------------------------------------------------------- |
---|
1042 | # USAGE: _simOutput <message> |
---|
1043 | # |
---|
1044 | # Invoked automatically whenever output comes in while running the |
---|
1045 | # tool. Extracts any =RAPPTURE-???=> messages from the output and |
---|
1046 | # sends the output to the display. For example, any |
---|
1047 | # =RAPPTURE-PROGRESS=> message pops up the progress meter and updates |
---|
1048 | # it to show the latest progress message. This is useful for |
---|
1049 | # long-running tools, to let the user know how much longer the |
---|
1050 | # simulation will take. |
---|
1051 | # ---------------------------------------------------------------------- |
---|
1052 | itcl::body Rappture::Analyzer::_simOutput {message} { |
---|
1053 | # |
---|
1054 | # Scan through and pick out any =RAPPTURE-PROGRESS=> messages first. |
---|
1055 | # |
---|
1056 | while {[regexp -indices \ |
---|
1057 | {=RAPPTURE-PROGRESS=> *([-+]?[0-9]+) +([^\n]*)(\n|$)} $message \ |
---|
1058 | match percent mesg]} { |
---|
1059 | |
---|
1060 | foreach {i0 i1} $percent break |
---|
1061 | set percent [string range $message $i0 $i1] |
---|
1062 | |
---|
1063 | foreach {i0 i1} $mesg break |
---|
1064 | set mesg [string range $message $i0 $i1] |
---|
1065 | |
---|
1066 | pack $itk_component(progress) -fill x -padx 10 -pady 10 |
---|
1067 | $itk_component(progress) settings -percent $percent -message $mesg |
---|
1068 | |
---|
1069 | foreach {i0 i1} $match break |
---|
1070 | set message [string replace $message $i0 $i1] |
---|
1071 | } |
---|
1072 | |
---|
1073 | # |
---|
1074 | # Break up the remaining lines according to =RAPPTURE-ERROR=> messages. |
---|
1075 | # Show errors in a special color. |
---|
1076 | # |
---|
1077 | $itk_component(runinfo) configure -state normal |
---|
1078 | |
---|
1079 | while {[regexp -indices \ |
---|
1080 | {=RAPPTURE-([a-zA-Z]+)=>([^\n]*)(\n|$)} $message \ |
---|
1081 | match type mesg]} { |
---|
1082 | |
---|
1083 | foreach {i0 i1} $match break |
---|
1084 | set first [string range $message 0 [expr {$i0-1}]] |
---|
1085 | if {[string length $first] > 0} { |
---|
1086 | $itk_component(runinfo) insert end $first |
---|
1087 | $itk_component(runinfo) insert end \n |
---|
1088 | } |
---|
1089 | |
---|
1090 | foreach {t0 t1} $type break |
---|
1091 | set type [string range $message $t0 $t1] |
---|
1092 | foreach {m0 m1} $mesg break |
---|
1093 | set mesg [string range $message $m0 $m1] |
---|
1094 | if {[string length $mesg] > 0 && $type != "RUN"} { |
---|
1095 | $itk_component(runinfo) insert end $mesg $type |
---|
1096 | $itk_component(runinfo) insert end \n $type |
---|
1097 | } |
---|
1098 | |
---|
1099 | set message [string range $message [expr {$i1+1}] end] |
---|
1100 | } |
---|
1101 | |
---|
1102 | if {[string length $message] > 0} { |
---|
1103 | $itk_component(runinfo) insert end $message |
---|
1104 | if {[$itk_component(runinfo) get end-2char] != "\n"} { |
---|
1105 | $itk_component(runinfo) insert end "\n" |
---|
1106 | } |
---|
1107 | $itk_component(runinfo) see end |
---|
1108 | } |
---|
1109 | $itk_component(runinfo) configure -state disabled |
---|
1110 | } |
---|
1111 | |
---|
1112 | # ---------------------------------------------------------------------- |
---|
1113 | # USAGE: _resultTooltip |
---|
1114 | # |
---|
1115 | # Used internally to build the tooltip string displayed for the |
---|
1116 | # result selector. If the current page has an associated description, |
---|
1117 | # then it is displayed beneath the result. |
---|
1118 | # |
---|
1119 | # Returns the string for the tooltip. |
---|
1120 | # ---------------------------------------------------------------------- |
---|
1121 | itcl::body Rappture::Analyzer::_resultTooltip {} { |
---|
1122 | set tip "" |
---|
1123 | set name [$itk_component(viewselector) value] |
---|
1124 | if {[info exists _label2desc($name)] && |
---|
1125 | [string length $_label2desc($name)] > 0} { |
---|
1126 | append tip "$_label2desc($name)\n\n" |
---|
1127 | } |
---|
1128 | if {[array size _label2page] > 1} { |
---|
1129 | append tip "Use this control to display other output results." |
---|
1130 | } |
---|
1131 | return $tip |
---|
1132 | } |
---|
1133 | |
---|
1134 | # ---------------------------------------------------------------------- |
---|
1135 | # USAGE: _fixSimControl |
---|
1136 | # |
---|
1137 | # Used internally to add or remove the simulation control at the |
---|
1138 | # top of the analysis area. This is controlled by the -simcontrol |
---|
1139 | # option. |
---|
1140 | # ---------------------------------------------------------------------- |
---|
1141 | itcl::body Rappture::Analyzer::_fixSimControl {} { |
---|
1142 | switch -- $itk_option(-simcontrol) { |
---|
1143 | on { |
---|
1144 | pack $itk_interior.simol -fill x -before $itk_interior.nb |
---|
1145 | } |
---|
1146 | off { |
---|
1147 | pack forget $itk_interior.simol |
---|
1148 | } |
---|
1149 | auto { |
---|
1150 | # |
---|
1151 | # If we have two or more radiodials, then there is a |
---|
1152 | # chance of encountering a combination of parameters |
---|
1153 | # with no data, requiring simulation. |
---|
1154 | # |
---|
1155 | if {[$itk_component(resultselector) size -controls] >= 2} { |
---|
1156 | pack $itk_interior.simol -fill x -before $itk_interior.nb |
---|
1157 | } else { |
---|
1158 | pack forget $itk_interior.simol |
---|
1159 | } |
---|
1160 | } |
---|
1161 | default { |
---|
1162 | error "bad value \"$itk_option(-simcontrol)\": should be on, off, auto" |
---|
1163 | } |
---|
1164 | } |
---|
1165 | } |
---|
1166 | |
---|
1167 | # ---------------------------------------------------------------------- |
---|
1168 | # USAGE: _fixNotebook |
---|
1169 | # |
---|
1170 | # Used internally to switch the active notebook page |
---|
1171 | # ---------------------------------------------------------------------- |
---|
1172 | itcl::body Rappture::Analyzer::_fixNotebook {} { |
---|
1173 | switch -- $itk_option(-notebookpage) { |
---|
1174 | about { |
---|
1175 | $itk_component(notebook) current about |
---|
1176 | } |
---|
1177 | simulate { |
---|
1178 | $itk_component(notebook) current simulate |
---|
1179 | } |
---|
1180 | analyze { |
---|
1181 | $itk_component(notebook) current analyze |
---|
1182 | } |
---|
1183 | default { |
---|
1184 | error "bad value \"$itk_option(-notebookpage)\": should be about, simulate, analyze" |
---|
1185 | } |
---|
1186 | } |
---|
1187 | } |
---|
1188 | |
---|
1189 | # ---------------------------------------------------------------------- |
---|
1190 | # USAGE: _isPdbTrajectory <data> |
---|
1191 | # |
---|
1192 | # Used internally to determine whether pdb or lammps data represents a |
---|
1193 | # trajectory rather than a single frame |
---|
1194 | # ---------------------------------------------------------------------- |
---|
1195 | itcl::body Rappture::Analyzer::_isPdbTrajectory {data} { |
---|
1196 | if { [llength $data] == 0 } { |
---|
1197 | return 0 |
---|
1198 | } |
---|
1199 | set nModels 0 |
---|
1200 | foreach line $data { |
---|
1201 | if { [string match "MODEL*" $line] } { |
---|
1202 | incr nModels |
---|
1203 | if { $nModels > 1 } { |
---|
1204 | # Stop if more than one model found. No need to count them |
---|
1205 | # all. |
---|
1206 | return 1 |
---|
1207 | } |
---|
1208 | } |
---|
1209 | } |
---|
1210 | return 0 |
---|
1211 | } |
---|
1212 | |
---|
1213 | # ---------------------------------------------------------------------- |
---|
1214 | # USAGE: _isLammpsTrajectory <data> |
---|
1215 | # |
---|
1216 | # Used internally to determine whether pdb or lammps data represents a |
---|
1217 | # trajectory rather than a single frame |
---|
1218 | # ---------------------------------------------------------------------- |
---|
1219 | itcl::body Rappture::Analyzer::_isLammpsTrajectory { data } { |
---|
1220 | if { [llength $data] == 0 } { |
---|
1221 | return 0 |
---|
1222 | } |
---|
1223 | set nModels 0 |
---|
1224 | foreach line $data { |
---|
1225 | if { [regexp {^[\t ]*ITEM:[ \t]+TIMESTEP} $line] } { |
---|
1226 | incr nModels |
---|
1227 | if { $nModels > 1 } { |
---|
1228 | # Stop if more than one model found. No need to count them |
---|
1229 | # all. |
---|
1230 | return 1 |
---|
1231 | } |
---|
1232 | } |
---|
1233 | } |
---|
1234 | return 0 |
---|
1235 | } |
---|
1236 | |
---|
1237 | # ---------------------------------------------------------------------- |
---|
1238 | # USAGE: _pdbToSequence <xmlobj> ?<path>? |
---|
1239 | # |
---|
1240 | # If the molecule element is a trajectory, delete the original |
---|
1241 | # and create a sequence of individual molecules. |
---|
1242 | # Used internally to detect any molecule output elements that contain |
---|
1243 | # trajectory data. Trajectories will be converted into sequences of |
---|
1244 | # individual molecules. All other elements will be unaffected. Scans |
---|
1245 | # the entire xml tree if a starting path is not specified. |
---|
1246 | # ---------------------------------------------------------------------- |
---|
1247 | itcl::body Rappture::Analyzer::_pdbToSequence {xmlobj path id child data} { |
---|
1248 | |
---|
1249 | set seqLabel [$xmlobj get ${child}.about.label] |
---|
1250 | set descr [$xmlobj get ${child}.about.description] |
---|
1251 | set formula [$xmlobj get ${child}.components.molecule.formula] |
---|
1252 | $xmlobj remove $child |
---|
1253 | |
---|
1254 | set sequence $path.sequence($id) |
---|
1255 | $xmlobj put ${sequence}.about.label $seqLabel |
---|
1256 | $xmlobj put ${sequence}.about.description $descr |
---|
1257 | $xmlobj put ${sequence}.index.label "Frame" |
---|
1258 | |
---|
1259 | set frameNum 0 |
---|
1260 | set numLines [llength $data] |
---|
1261 | for { set i 0 } { $i < $numLines } { incr i } { |
---|
1262 | set line [lindex $data $i] |
---|
1263 | set line [string trim $line] |
---|
1264 | set contents {} |
---|
1265 | if { [string match "MODEL*" $line] } { |
---|
1266 | # Save the contents until we get an ENDMDL record. |
---|
1267 | for {} { $i < $numLines } { incr i } { |
---|
1268 | set line [lindex $data $i] |
---|
1269 | set line [string trim $line] |
---|
1270 | if { $line == "" } { |
---|
1271 | continue; # Skip blank lines. |
---|
1272 | } |
---|
1273 | if { [string match "ENDMDL*" $line] } { |
---|
1274 | break; |
---|
1275 | } |
---|
1276 | append contents $line\n |
---|
1277 | } |
---|
1278 | set frame ${sequence}.element($frameNum) |
---|
1279 | $xmlobj put ${frame}.index $frameNum |
---|
1280 | |
---|
1281 | set molecule ${frame}.structure.components.molecule |
---|
1282 | $xmlobj put ${molecule}.pdb $contents |
---|
1283 | $xmlobj put ${molecule}.formula $formula |
---|
1284 | incr frameNum |
---|
1285 | } |
---|
1286 | } |
---|
1287 | } |
---|
1288 | |
---|
1289 | # ---------------------------------------------------------------------- |
---|
1290 | # USAGE: _lammpsToSequence <xmlobj> ?<path>? |
---|
1291 | # |
---|
1292 | # If the molecule element is a trajectory, delete the original |
---|
1293 | # and create a sequence of individual molecules. |
---|
1294 | # Used internally to detect any molecule output elements that contain |
---|
1295 | # trajectory data. Trajectories will be converted into sequences of |
---|
1296 | # individual molecules. All other elements will be unaffected. Scans |
---|
1297 | # the entire xml tree if a starting path is not specified. |
---|
1298 | # ---------------------------------------------------------------------- |
---|
1299 | itcl::body Rappture::Analyzer::_lammpsToSequence {xmlobj path id child data} { |
---|
1300 | |
---|
1301 | set seqLabel [$xmlobj get ${child}.about.label] |
---|
1302 | set descr [$xmlobj get ${child}.about.description] |
---|
1303 | set typemap [$xmlobj get ${child}.components.molecule.lammpstypemap] |
---|
1304 | $xmlobj remove $child |
---|
1305 | |
---|
1306 | set sequence ${path}.sequence($id) |
---|
1307 | $xmlobj put ${sequence}.about.label $seqLabel |
---|
1308 | $xmlobj put ${sequence}.about.description $descr |
---|
1309 | $xmlobj put ${sequence}.index.label "Frame" |
---|
1310 | |
---|
1311 | set frameNum 0 |
---|
1312 | set frameContents "" |
---|
1313 | set inModel 0 |
---|
1314 | foreach line $data { |
---|
1315 | set line [string trim $line] |
---|
1316 | if { $line == "" } { |
---|
1317 | continue; # Skip blank lines |
---|
1318 | } |
---|
1319 | if {[regexp {^[\t ]*ITEM:[ \t]+ATOMS} $line] } { |
---|
1320 | if { $inModel && $frameContents != "" } { |
---|
1321 | set frame ${sequence}.element($frameNum) |
---|
1322 | $xmlobj put ${frame}.index $frameNum |
---|
1323 | |
---|
1324 | set molecule ${frame}.structure.components.molecule |
---|
1325 | $xmlobj put ${molecule}.lammps $frameContents |
---|
1326 | $xmlobj put ${molecule}.lammpstypemap $typemap |
---|
1327 | |
---|
1328 | incr frameNum |
---|
1329 | set frameContents "" |
---|
1330 | } |
---|
1331 | set inModel 1 |
---|
1332 | } elseif { [scan $line "%d %d %f %f %f" a b c d e] == 5 } { |
---|
1333 | if { !$inModel } { |
---|
1334 | puts stderr "found \"$line\" without previous \"ITEM: ATOMS\"" |
---|
1335 | set inModel 1 |
---|
1336 | } |
---|
1337 | append frameContents $line\n |
---|
1338 | } |
---|
1339 | } |
---|
1340 | if { $frameContents != "" } { |
---|
1341 | set frame ${sequence}.element($frameNum) |
---|
1342 | $xmlobj put ${frame}.index $frameNum |
---|
1343 | |
---|
1344 | set molecule ${frame}.structure.components.molecule |
---|
1345 | $xmlobj put ${molecule}.lammps $frameContents |
---|
1346 | $xmlobj put ${molecule}.lammpstypemap $typemap |
---|
1347 | } |
---|
1348 | } |
---|
1349 | |
---|
1350 | # ---------------------------------------------------------------------- |
---|
1351 | # USAGE: _trajToSequence <xmlobj> ?<path>? |
---|
1352 | # |
---|
1353 | # Check for PDB and LAMMPS trajectories in molecule data and rewrite |
---|
1354 | # the individual models as a sequence of molecules. Used internally |
---|
1355 | # to detect any molecule output elements that contain trajectory data. |
---|
1356 | # Trajectories will be converted into sequences of individual molecules. |
---|
1357 | # All other elements will be unaffected. Scans the entire xml tree if a |
---|
1358 | # starting path is not specified. |
---|
1359 | # |
---|
1360 | # ---------------------------------------------------------------------- |
---|
1361 | itcl::body Rappture::Analyzer::_trajToSequence {xmlobj {path ""}} { |
---|
1362 | # Remove leading dot from path, if present. |
---|
1363 | if { [string index $path 0] == "." } { |
---|
1364 | set path [string range $path 1 end] |
---|
1365 | } |
---|
1366 | # Otherwise check each child. |
---|
1367 | foreach child [$xmlobj children $path] { |
---|
1368 | set current ${path}.${child} |
---|
1369 | if { [string match "structure*" $child] } { |
---|
1370 | set isTraj [$xmlobj get ${current}.components.molecule.trajectory] |
---|
1371 | if { $isTraj == "" || !$isTraj } { |
---|
1372 | continue; # Not a trajectory. |
---|
1373 | } |
---|
1374 | # Look for trajectory if molecule element found. Check both pdb |
---|
1375 | # data and lammps data. |
---|
1376 | set type [$xmlobj element -as type $current] |
---|
1377 | set id [$xmlobj element -as id $current] |
---|
1378 | set pdbdata [$xmlobj get ${current}.components.molecule.pdb] |
---|
1379 | set lammpsdata [$xmlobj get ${current}.components.molecule.lammps] |
---|
1380 | if { $pdbdata != "" && $lammpsdata != "" } { |
---|
1381 | puts stderr \ |
---|
1382 | "found both <pdb> and <lammps> elements: picking pdb" |
---|
1383 | } |
---|
1384 | set pdbdata [split $pdbdata \n] |
---|
1385 | set lammpsdata [split $lammpsdata \n] |
---|
1386 | if { [_isPdbTrajectory $pdbdata] } { |
---|
1387 | _pdbToSequence $xmlobj $path $id $current $pdbdata |
---|
1388 | } elseif { [_isLammpsTrajectory $lammpsdata] } { |
---|
1389 | _lammpsToSequence $xmlobj $path $id $current $lammpsdata |
---|
1390 | } |
---|
1391 | continue |
---|
1392 | } |
---|
1393 | if 0 { |
---|
1394 | # Recurse over all child nodes. |
---|
1395 | _trajToSequence $xmlobj $current |
---|
1396 | } |
---|
1397 | } |
---|
1398 | } |
---|
1399 | |
---|
1400 | # ---------------------------------------------------------------------- |
---|
1401 | # CONFIGURATION OPTION: -simcontrol |
---|
1402 | # |
---|
1403 | # Controls whether or not the Simulate button is showing. In some |
---|
1404 | # cases, it is not needed. |
---|
1405 | # ---------------------------------------------------------------------- |
---|
1406 | itcl::configbody Rappture::Analyzer::simcontrol { |
---|
1407 | _fixSimControl |
---|
1408 | } |
---|
1409 | |
---|
1410 | # ---------------------------------------------------------------------- |
---|
1411 | # CONFIGURATION OPTION: -notebookpage |
---|
1412 | # |
---|
1413 | # Controls which page of the analyzer notebook is shown. It is |
---|
1414 | # particularly needed when using rerun, when you don't want to |
---|
1415 | # "simulate -ifneeded" because an actual simulation might be |
---|
1416 | # kicked off due to differences between tool.xml and run.xml |
---|
1417 | # ---------------------------------------------------------------------- |
---|
1418 | itcl::configbody Rappture::Analyzer::notebookpage { |
---|
1419 | _fixNotebook |
---|
1420 | } |
---|