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 | # Don't erase program error messages. |
---|
446 | # $itk_component(runinfo) delete 1.0 end |
---|
447 | $itk_component(runinfo) insert end "\n\nProblem launching job:\n\n" text |
---|
448 | _simOutput $result |
---|
449 | $itk_component(runinfo) configure -state disabled |
---|
450 | $itk_component(runinfo) see 1.0 |
---|
451 | |
---|
452 | # Try to create a support ticket for this error. |
---|
453 | # It may be a real problem. |
---|
454 | if {[Rappture::bugreport::shouldReport for jobs]} { |
---|
455 | set ::errorInfo "\n\n== RAPPTURE INPUT ==\n[$_tool xml xml]" |
---|
456 | Rappture::bugreport::register "Problem launching job:\n$result" |
---|
457 | Rappture::bugreport::attachment [$_tool xml xml] |
---|
458 | Rappture::bugreport::send |
---|
459 | } |
---|
460 | } else { |
---|
461 | $itk_component(notebook) current analyze |
---|
462 | } |
---|
463 | |
---|
464 | # do this last -- after _simOutput above |
---|
465 | pack forget $itk_component(progress) |
---|
466 | } |
---|
467 | |
---|
468 | # ---------------------------------------------------------------------- |
---|
469 | # USAGE: reset ?-eventually|-now? |
---|
470 | # |
---|
471 | # Used to reset the analyzer whenever the input to a simulation has |
---|
472 | # changed. Sets the mode back to "simulate", so the user has to |
---|
473 | # simulate again to see the output. If the <start> option is set |
---|
474 | # to "auto", the simulation is invoked immediately. |
---|
475 | # ---------------------------------------------------------------------- |
---|
476 | itcl::body Rappture::Analyzer::reset {{when -eventually}} { |
---|
477 | if {$when == "-eventually"} { |
---|
478 | after cancel [list catch [itcl::code $this reset -now]] |
---|
479 | after idle [list catch [itcl::code $this reset -now]] |
---|
480 | return |
---|
481 | } |
---|
482 | |
---|
483 | # check to see if simulation is really needed |
---|
484 | $_tool sync |
---|
485 | if {![$_resultset contains [$_tool xml object]] |
---|
486 | || [string equal $_control "manual-resim"]} { |
---|
487 | # if control mode is "auto", then simulate right away |
---|
488 | if {[string match auto* $_control]} { |
---|
489 | # auto control -- don't need button |
---|
490 | pack forget $itk_interior.simol |
---|
491 | |
---|
492 | after cancel [itcl::code $this simulate] |
---|
493 | after idle [itcl::code $this simulate] |
---|
494 | } else { |
---|
495 | _simState on "new input parameters" |
---|
496 | } |
---|
497 | } else { |
---|
498 | _simState off |
---|
499 | } |
---|
500 | } |
---|
501 | |
---|
502 | # ---------------------------------------------------------------------- |
---|
503 | # USAGE: load <xmlobj> |
---|
504 | # |
---|
505 | # Loads the data from the given <xmlobj> into the appropriate results |
---|
506 | # sets. If necessary, new results sets are created to store the data. |
---|
507 | # ---------------------------------------------------------------------- |
---|
508 | itcl::body Rappture::Analyzer::load {xmlobj} { |
---|
509 | # only show the last result? then clear first |
---|
510 | if {[string trim [$_tool xml get tool.analyzer]] == "last"} { |
---|
511 | clear |
---|
512 | } |
---|
513 | $_resultset add $xmlobj |
---|
514 | |
---|
515 | # NOTE: Adding will trigger a !change event on the ResultSet |
---|
516 | # object, which will trigger calls to _fixResultSet to add |
---|
517 | # the results to display. |
---|
518 | } |
---|
519 | |
---|
520 | # ---------------------------------------------------------------------- |
---|
521 | # USAGE: clear ?<xmlobj>? |
---|
522 | # |
---|
523 | # Discards one or more results previously loaded into the analyzer. |
---|
524 | # If an <xmlobj> is specified, then that one result is cleared. |
---|
525 | # Otherwise, all results are cleared. |
---|
526 | # ---------------------------------------------------------------------- |
---|
527 | itcl::body Rappture::Analyzer::clear {{xmlobj "all"}} { |
---|
528 | if {$xmlobj eq "" || $xmlobj eq "all"} { |
---|
529 | $_resultset clear |
---|
530 | } else { |
---|
531 | $_resultset clear $xmlobj |
---|
532 | } |
---|
533 | |
---|
534 | # NOTE: Clearing will trigger a !change event on the ResultSet |
---|
535 | # object, which will trigger calls to _fixResultSet to clean up |
---|
536 | # the results being displayed. |
---|
537 | } |
---|
538 | |
---|
539 | # ---------------------------------------------------------------------- |
---|
540 | # USAGE: download coming |
---|
541 | # USAGE: download controls <downloadCommand> |
---|
542 | # USAGE: download start ?widget? |
---|
543 | # USAGE: download now ?widget? |
---|
544 | # |
---|
545 | # Spools the current result so the user can download it. |
---|
546 | # ---------------------------------------------------------------------- |
---|
547 | itcl::body Rappture::Analyzer::download {option args} { |
---|
548 | set title [$itk_component(viewselector) value] |
---|
549 | set page [$itk_component(viewselector) translate $title] |
---|
550 | |
---|
551 | switch -- $option { |
---|
552 | coming { |
---|
553 | # |
---|
554 | # Warn result that a download is coming, in case |
---|
555 | # it needs to take a screen snap. |
---|
556 | # |
---|
557 | if {![regexp {^(|@download|---)$} $page]} { |
---|
558 | set f [$itk_component(resultpages) page $page] |
---|
559 | $f.rviewer download coming |
---|
560 | } |
---|
561 | } |
---|
562 | controls { |
---|
563 | # no controls for this download yet |
---|
564 | return "" |
---|
565 | } |
---|
566 | start { |
---|
567 | set widget $itk_component(download) |
---|
568 | if {[llength $args] > 0} { |
---|
569 | set widget [lindex $args 0] |
---|
570 | if {[catch {winfo class $widget}]} { |
---|
571 | set widget $itk_component(download) |
---|
572 | } |
---|
573 | } |
---|
574 | # |
---|
575 | # See if this download has any controls. If so, then |
---|
576 | # post them now and let the user continue the download |
---|
577 | # after selecting a file format. |
---|
578 | # |
---|
579 | if {$page != ""} { |
---|
580 | set ext "" |
---|
581 | set f [$itk_component(resultpages) page $page] |
---|
582 | set arg [itcl::code $this download now $widget] |
---|
583 | set popup [$f.rviewer download controls $arg] |
---|
584 | if {"" != $popup} { |
---|
585 | $popup activate $widget below |
---|
586 | } else { |
---|
587 | download now $widget |
---|
588 | } |
---|
589 | } else { |
---|
590 | # this shouldn't happen |
---|
591 | set file error.html |
---|
592 | set data "<h1>Not Found</h1>There is no result selected." |
---|
593 | } |
---|
594 | } |
---|
595 | now { |
---|
596 | set widget $itk_component(download) |
---|
597 | if {[llength $args] > 0} { |
---|
598 | set widget [lindex $args 0] |
---|
599 | if {[catch {winfo class $widget}]} { |
---|
600 | set widget $itk_component(download) |
---|
601 | } |
---|
602 | } |
---|
603 | # |
---|
604 | # Perform the actual download. |
---|
605 | # |
---|
606 | if {$page != ""} { |
---|
607 | set ext "" |
---|
608 | set f [$itk_component(resultpages) page $page] |
---|
609 | set item [$itk_component(viewselector) value] |
---|
610 | set result [$f.rviewer download now $widget $_appName $item] |
---|
611 | if { $result == "" } { |
---|
612 | return; # User cancelled the download. |
---|
613 | } |
---|
614 | foreach {ext data} $result break |
---|
615 | if {"" == $ext} { |
---|
616 | if {"" != $widget} { |
---|
617 | Rappture::Tooltip::cue $widget \ |
---|
618 | "Can't download this result." |
---|
619 | } |
---|
620 | return |
---|
621 | } |
---|
622 | regsub -all {[\ -\/\:-\@\{-\~]} $title {} title |
---|
623 | set file "$title$ext" |
---|
624 | } else { |
---|
625 | # this shouldn't happen |
---|
626 | set file error.html |
---|
627 | set data "<h1>Not Found</h1>There is no result selected." |
---|
628 | } |
---|
629 | |
---|
630 | Rappture::Logger::log download [$itk_component(viewselector) value] |
---|
631 | set mesg [Rappture::filexfer::download $data $file] |
---|
632 | if {[string length $mesg] > 0} { |
---|
633 | Rappture::Tooltip::cue $widget $mesg |
---|
634 | } |
---|
635 | } |
---|
636 | default { |
---|
637 | error "bad option \"$option\": should be coming, controls, now, start" |
---|
638 | } |
---|
639 | } |
---|
640 | } |
---|
641 | |
---|
642 | # ---------------------------------------------------------------------- |
---|
643 | # USAGE: _plot ?<index> <options> <index> <options>...? |
---|
644 | # |
---|
645 | # Used internally to update the plot shown in the current result |
---|
646 | # viewer whenever the resultselector settings have changed. Causes the |
---|
647 | # desired results to show up on screen. |
---|
648 | # ---------------------------------------------------------------------- |
---|
649 | itcl::body Rappture::Analyzer::_plot {args} { |
---|
650 | set _plotlist $args |
---|
651 | |
---|
652 | set page [$itk_component(viewselector) value] |
---|
653 | set page [$itk_component(viewselector) translate $page] |
---|
654 | if {"" != $page} { |
---|
655 | set f [$itk_component(resultpages) page $page] |
---|
656 | $f.rviewer plot clear |
---|
657 | foreach {index opts} $_plotlist { |
---|
658 | $f.rviewer plot add $index $opts |
---|
659 | } |
---|
660 | } |
---|
661 | } |
---|
662 | |
---|
663 | # ---------------------------------------------------------------------- |
---|
664 | # USAGE: _reorder <compList> |
---|
665 | # |
---|
666 | # Used internally to change the order of a series of output components |
---|
667 | # found in the <output> section. Moves the <log> elements to the end |
---|
668 | # and returns the updated list. |
---|
669 | # ---------------------------------------------------------------------- |
---|
670 | itcl::body Rappture::Analyzer::_reorder {comps} { |
---|
671 | set i 0 |
---|
672 | set max [llength $comps] |
---|
673 | while {$i < $max} { |
---|
674 | set c [lindex $comps $i] |
---|
675 | if {[string match log* $c]} { |
---|
676 | set comps [lreplace $comps $i $i] |
---|
677 | lappend comps $c |
---|
678 | incr max -1 |
---|
679 | } else { |
---|
680 | incr i |
---|
681 | } |
---|
682 | } |
---|
683 | return $comps |
---|
684 | } |
---|
685 | |
---|
686 | # ---------------------------------------------------------------------- |
---|
687 | # USAGE: _autoLabel <xmlobj> <path> <title> <cntVar> |
---|
688 | # |
---|
689 | # Used internally to check for an about.label property at the <path> |
---|
690 | # in <xmlobj>. If this object doesn't have a label, then one is |
---|
691 | # supplied using the given <title>. The <cntVar> is an array of |
---|
692 | # counters in the calling scopes for titles that have been used |
---|
693 | # in the past. This is used to create titles like "Plot #2" the |
---|
694 | # second time it is encountered. |
---|
695 | # |
---|
696 | # The <xmlobj> is updated so that the label is inserted directly in |
---|
697 | # the tree. |
---|
698 | # ---------------------------------------------------------------------- |
---|
699 | itcl::body Rappture::Analyzer::_autoLabel {xmlobj path title cntVar} { |
---|
700 | upvar $cntVar counters |
---|
701 | |
---|
702 | set group [$xmlobj get $path.about.group] |
---|
703 | set label [$xmlobj get $path.about.label] |
---|
704 | if {"" == $label} { |
---|
705 | # no label -- make one up using the title specified |
---|
706 | if {![info exists counters($group-$title)]} { |
---|
707 | set counters($group-$title) 1 |
---|
708 | set label $title |
---|
709 | } else { |
---|
710 | set label "$title (#[incr counters($group-$title)])" |
---|
711 | } |
---|
712 | $xmlobj put $path.about.label $label |
---|
713 | } else { |
---|
714 | # handle the case of two identical labels in <output> |
---|
715 | if {![info exists counters($group-$label)]} { |
---|
716 | set counters($group-$label) 1 |
---|
717 | } else { |
---|
718 | set label "$label (#[incr counters($group-$label)])" |
---|
719 | $xmlobj put $path.about.label $label |
---|
720 | } |
---|
721 | } |
---|
722 | return $label |
---|
723 | } |
---|
724 | |
---|
725 | # ---------------------------------------------------------------------- |
---|
726 | # USAGE: _fixResult |
---|
727 | # |
---|
728 | # Used internally to change the result page being displayed whenever |
---|
729 | # the user selects a page from the results combobox. |
---|
730 | # ---------------------------------------------------------------------- |
---|
731 | itcl::body Rappture::Analyzer::_fixResult {} { |
---|
732 | set name [$itk_component(viewselector) value] |
---|
733 | set page "" |
---|
734 | if {"" != $name} { |
---|
735 | set page [$itk_component(viewselector) translate $name] |
---|
736 | } |
---|
737 | if {$page == "@download"} { |
---|
738 | # put the combobox back to its last value |
---|
739 | $itk_component(viewselector) component entry configure -state normal |
---|
740 | $itk_component(viewselector) component entry delete 0 end |
---|
741 | $itk_component(viewselector) component entry insert end $_lastlabel |
---|
742 | $itk_component(viewselector) component entry configure -state disabled |
---|
743 | # perform the actual download |
---|
744 | download start $itk_component(download) |
---|
745 | } elseif {$page == "---"} { |
---|
746 | # put the combobox back to its last value |
---|
747 | $itk_component(viewselector) component entry configure -state normal |
---|
748 | $itk_component(viewselector) component entry delete 0 end |
---|
749 | $itk_component(viewselector) component entry insert end $_lastlabel |
---|
750 | $itk_component(viewselector) component entry configure -state disabled |
---|
751 | } elseif {$page != ""} { |
---|
752 | set _lastlabel $name |
---|
753 | set win [winfo toplevel $itk_component(hull)] |
---|
754 | $itk_component(resultpages) current $page |
---|
755 | set f [$itk_component(resultpages) page $page] |
---|
756 | |
---|
757 | # We don't want to replot if we're using an existing viewer with the |
---|
758 | # the same list of objects to plot. So track the viewer and the list. |
---|
759 | if { ![info exists _lastPlot($f)] || $_plotlist != $_lastPlot($f) } { |
---|
760 | set _lastPlot($f) $_plotlist |
---|
761 | blt::busy hold $win |
---|
762 | $f.rviewer plot clear |
---|
763 | eval $f.rviewer plot add $_plotlist |
---|
764 | blt::busy release [winfo toplevel $itk_component(hull)] |
---|
765 | } |
---|
766 | Rappture::Logger::log output $_label2item($name) |
---|
767 | Rappture::Tooltip::for $itk_component(viewselector) \ |
---|
768 | "@[itcl::code $this _resultTooltip]" -log $_label2item($name) |
---|
769 | } |
---|
770 | } |
---|
771 | |
---|
772 | # ---------------------------------------------------------------------- |
---|
773 | # USAGE: _fixResultSet ?<eventData>...? |
---|
774 | # |
---|
775 | # Used internally to react to changes within the ResultSet. When a |
---|
776 | # result is added, a new result viewer is created for the object. |
---|
777 | # When all results are cleared, the viewers are deleted. |
---|
778 | # ---------------------------------------------------------------------- |
---|
779 | itcl::body Rappture::Analyzer::_fixResultSet {args} { |
---|
780 | array set eventData $args |
---|
781 | switch -- $eventData(op) { |
---|
782 | add { |
---|
783 | set xmlobj $eventData(what) |
---|
784 | |
---|
785 | # Detect molecule elements that contain trajectory data |
---|
786 | # and convert to sequences. |
---|
787 | _trajToSequence $xmlobj output |
---|
788 | |
---|
789 | # Go through the analysis and find all result sets. |
---|
790 | set haveresults 0 |
---|
791 | foreach item [_reorder [$xmlobj children output]] { |
---|
792 | switch -glob -- $item { |
---|
793 | log* { |
---|
794 | _autoLabel $xmlobj output.$item "Output Log" counters |
---|
795 | } |
---|
796 | number* { |
---|
797 | _autoLabel $xmlobj output.$item "Number" counters |
---|
798 | } |
---|
799 | integer* { |
---|
800 | _autoLabel $xmlobj output.$item "Integer" counters |
---|
801 | } |
---|
802 | mesh* { |
---|
803 | _autoLabel $xmlobj output.$item "Mesh" counters |
---|
804 | } |
---|
805 | string* { |
---|
806 | _autoLabel $xmlobj output.$item "String" counters |
---|
807 | } |
---|
808 | histogram* - curve* - field* { |
---|
809 | _autoLabel $xmlobj output.$item "Plot" counters |
---|
810 | } |
---|
811 | drawing* { |
---|
812 | _autoLabel $xmlobj output.$item "Drawing" counters |
---|
813 | } |
---|
814 | structure* { |
---|
815 | _autoLabel $xmlobj output.$item "Structure" counters |
---|
816 | } |
---|
817 | table* { |
---|
818 | _autoLabel $xmlobj output.$item "Energy Levels" counters |
---|
819 | } |
---|
820 | sequence* { |
---|
821 | _autoLabel $xmlobj output.$item "Sequence" counters |
---|
822 | } |
---|
823 | } |
---|
824 | set label [$xmlobj get output.$item.about.group] |
---|
825 | if {"" == $label} { |
---|
826 | set label [$xmlobj get output.$item.about.label] |
---|
827 | } |
---|
828 | |
---|
829 | set hidden [$xmlobj get output.$item.hide] |
---|
830 | set hidden [expr {"" != $hidden && $hidden}] |
---|
831 | |
---|
832 | if {"" != $label && !$hidden} { |
---|
833 | set haveresults 1 |
---|
834 | } |
---|
835 | } |
---|
836 | |
---|
837 | # if there are any valid results, add them to the resultset |
---|
838 | if {$haveresults} { |
---|
839 | set index [$_resultset get simnum $xmlobj] |
---|
840 | |
---|
841 | # add each result to a result viewer |
---|
842 | foreach item [_reorder [$xmlobj children output]] { |
---|
843 | set label [$xmlobj get output.$item.about.group] |
---|
844 | if {"" == $label} { |
---|
845 | set label [$xmlobj get output.$item.about.label] |
---|
846 | } |
---|
847 | set hidden [$xmlobj get output.$item.hide] |
---|
848 | if { $hidden == "" } { |
---|
849 | set hidden 0 |
---|
850 | } |
---|
851 | if {"" != $label && !$hidden} { |
---|
852 | if {![info exists _label2page($label)]} { |
---|
853 | set name "page[incr _pages]" |
---|
854 | set page [$itk_component(resultpages) \ |
---|
855 | insert end $name] |
---|
856 | set _label2page($label) $page |
---|
857 | set _label2item($label) output.$item |
---|
858 | set _label2desc($label) \ |
---|
859 | [$xmlobj get output.$item.about.description] |
---|
860 | Rappture::ResultViewer $page.rviewer |
---|
861 | pack $page.rviewer -expand yes -fill both -pady 4 |
---|
862 | |
---|
863 | set end [$itk_component(viewselector) \ |
---|
864 | choices index -value ---] |
---|
865 | if {$end < 0} { |
---|
866 | set end "end" |
---|
867 | } |
---|
868 | $itk_component(viewselector) choices insert $end \ |
---|
869 | $name $label |
---|
870 | } |
---|
871 | |
---|
872 | # add/replace the latest result into this viewer |
---|
873 | set page $_label2page($label) |
---|
874 | |
---|
875 | if {![info exists reset($page)]} { |
---|
876 | $page.rviewer clear $index |
---|
877 | set reset($page) 1 |
---|
878 | } |
---|
879 | $page.rviewer add $index $xmlobj output.$item |
---|
880 | } |
---|
881 | } |
---|
882 | } |
---|
883 | |
---|
884 | # show the first page by default |
---|
885 | set max [$itk_component(viewselector) choices size] |
---|
886 | for {set i 0} {$i < $max} {incr i} { |
---|
887 | set first [$itk_component(viewselector) choices get -label $i] |
---|
888 | if {$first != ""} { |
---|
889 | set page [$itk_component(viewselector) choices get -value $i] |
---|
890 | set char [string index $page 0] |
---|
891 | if {$char != "@" && $char != "-"} { |
---|
892 | $itk_component(resultpages) current $page |
---|
893 | $itk_component(viewselector) value $first |
---|
894 | set _lastlabel $first |
---|
895 | break |
---|
896 | } |
---|
897 | } |
---|
898 | } |
---|
899 | } |
---|
900 | clear { |
---|
901 | if {$eventData(what) ne "all"} { |
---|
902 | # delete this result from all viewers |
---|
903 | array set params $eventData(what) |
---|
904 | foreach label [array names _label2page] { |
---|
905 | set page $_label2page($label) |
---|
906 | $page.rviewer clear $params(simnum) |
---|
907 | } |
---|
908 | } |
---|
909 | |
---|
910 | if {[$_resultset size] == 0} { |
---|
911 | # reset the size of the controls area |
---|
912 | set ht [winfo height $itk_component(results)] |
---|
913 | set cntlht [$itk_component(resultselector) size -controlarea] |
---|
914 | set frac [expr {double($cntlht)/$ht}] |
---|
915 | $itk_component(results) fraction end $frac |
---|
916 | |
---|
917 | foreach label [array names _label2page] { |
---|
918 | set page $_label2page($label) |
---|
919 | destroy $page.rviewer |
---|
920 | } |
---|
921 | $itk_component(resultpages) delete -all |
---|
922 | set _pages 0 |
---|
923 | |
---|
924 | $itk_component(viewselector) value "" |
---|
925 | $itk_component(viewselector) choices delete 0 end |
---|
926 | catch {unset _label2page} |
---|
927 | catch {unset _label2item} |
---|
928 | catch {unset _label2desc} |
---|
929 | set _plotlist "" |
---|
930 | |
---|
931 | $itk_component(viewselector) choices insert end --- "---" |
---|
932 | $itk_component(viewselector) choices insert end \ |
---|
933 | @download [Rappture::filexfer::label download] |
---|
934 | set _lastlabel "" |
---|
935 | } |
---|
936 | |
---|
937 | # fix Simulate button state |
---|
938 | reset |
---|
939 | } |
---|
940 | default { |
---|
941 | error "don't know how to handle op \"$eventData(op)\"" |
---|
942 | } |
---|
943 | } |
---|
944 | } |
---|
945 | |
---|
946 | # ---------------------------------------------------------------------- |
---|
947 | # USAGE: _fixSize |
---|
948 | # |
---|
949 | # Used internally to change the size of the result set area whenever |
---|
950 | # a new control appears. Adjusts the size available for the result |
---|
951 | # set up to some maximum. |
---|
952 | # ---------------------------------------------------------------------- |
---|
953 | itcl::body Rappture::Analyzer::_fixSize {} { |
---|
954 | set ht [winfo height $itk_component(results)] |
---|
955 | if {$ht <= 1} { set ht [winfo reqheight $itk_component(results)] } |
---|
956 | set cntlht [$itk_component(resultselector) size -controlarea] |
---|
957 | set frac [expr {double($cntlht)/$ht}] |
---|
958 | |
---|
959 | if {$frac < 0.4} { |
---|
960 | $itk_component(results) fraction end $frac |
---|
961 | } |
---|
962 | _fixSimControl |
---|
963 | } |
---|
964 | |
---|
965 | # ---------------------------------------------------------------------- |
---|
966 | # USAGE: _simState <boolean> ?<message>? ?<settings>? |
---|
967 | # |
---|
968 | # Used internally to change the "Simulation" button on or off. |
---|
969 | # If the <boolean> is on, then any <message> and <settings> are |
---|
970 | # displayed as well. If the <boolean> is off, then only display |
---|
971 | # the message. The <message> is a note to the user about |
---|
972 | # what will be simulated, and the <settings> are a list of |
---|
973 | # tool parameter settings of the form {path1 val1 path2 val2 ...}. |
---|
974 | # When these are in place, the next Simulate operation will use |
---|
975 | # these settings. This helps fill in missing data values. |
---|
976 | # ---------------------------------------------------------------------- |
---|
977 | itcl::body Rappture::Analyzer::_simState {state args} { |
---|
978 | if {$state} { |
---|
979 | $itk_interior.simol configure \ |
---|
980 | -background $itk_option(-simcontrolactiveoutline) |
---|
981 | configure -simcontrolcolor $itk_option(-simcontrolactivebackground) |
---|
982 | |
---|
983 | $itk_component(abort) configure -state disabled |
---|
984 | $itk_component(simulate) configure -state normal \ |
---|
985 | -command [itcl::code $this simulate] |
---|
986 | |
---|
987 | # |
---|
988 | # If there's a special message, then put it up next to the button. |
---|
989 | # |
---|
990 | set mesg [lindex $args 0] |
---|
991 | if {"" != $mesg} { |
---|
992 | $itk_component(simstatus) configure -state normal |
---|
993 | $itk_component(simstatus) delete 1.0 end |
---|
994 | $itk_component(simstatus) insert end $mesg |
---|
995 | |
---|
996 | # |
---|
997 | # If there are any settings, then install them in the |
---|
998 | # "Simulate" button. Also, pop them up as a tooltip |
---|
999 | # for the message. |
---|
1000 | # |
---|
1001 | set settings [lindex $args 1] |
---|
1002 | if {[llength $settings] > 0} { |
---|
1003 | $itk_component(simulate) configure \ |
---|
1004 | -command [eval itcl::code $this simulate $settings] |
---|
1005 | |
---|
1006 | set details "" |
---|
1007 | foreach {path val} $settings { |
---|
1008 | set str [string trim [$_tool xml get $path.about.label]] |
---|
1009 | if {"" == $str} { |
---|
1010 | set str [$_tool xml element -as id $path] |
---|
1011 | } |
---|
1012 | append details "$str = $val\n" |
---|
1013 | } |
---|
1014 | set details [string trim $details] |
---|
1015 | |
---|
1016 | Rappture::Tooltip::for $itk_component(simstatus) $details |
---|
1017 | $itk_component(simstatus) insert end " " |
---|
1018 | $itk_component(simstatus) insert end "(details...)" popup |
---|
1019 | } |
---|
1020 | $itk_component(simstatus) configure -state disabled |
---|
1021 | } |
---|
1022 | } else { |
---|
1023 | if {"" != $itk_option(-simcontrolbackground)} { |
---|
1024 | set simcbg $itk_option(-simcontrolbackground) |
---|
1025 | } else { |
---|
1026 | set simcbg $itk_option(-background) |
---|
1027 | } |
---|
1028 | $itk_interior.simol configure \ |
---|
1029 | -background $itk_option(-simcontroloutline) |
---|
1030 | configure -simcontrolcolor $simcbg |
---|
1031 | |
---|
1032 | $itk_component(simulate) configure -state disabled |
---|
1033 | $itk_component(abort) configure -state normal |
---|
1034 | |
---|
1035 | $itk_component(simstatus) configure -state normal |
---|
1036 | $itk_component(simstatus) delete 1.0 end |
---|
1037 | set mesg [lindex $args 0] |
---|
1038 | if {"" != $mesg} { |
---|
1039 | $itk_component(simstatus) insert end $mesg |
---|
1040 | } |
---|
1041 | $itk_component(simstatus) configure -state disabled |
---|
1042 | } |
---|
1043 | } |
---|
1044 | |
---|
1045 | # ---------------------------------------------------------------------- |
---|
1046 | # USAGE: _simOutput <message> |
---|
1047 | # |
---|
1048 | # Invoked automatically whenever output comes in while running the |
---|
1049 | # tool. Extracts any =RAPPTURE-???=> messages from the output and |
---|
1050 | # sends the output to the display. For example, any |
---|
1051 | # =RAPPTURE-PROGRESS=> message pops up the progress meter and updates |
---|
1052 | # it to show the latest progress message. This is useful for |
---|
1053 | # long-running tools, to let the user know how much longer the |
---|
1054 | # simulation will take. |
---|
1055 | # ---------------------------------------------------------------------- |
---|
1056 | itcl::body Rappture::Analyzer::_simOutput {message} { |
---|
1057 | # |
---|
1058 | # Scan through and pick out any =RAPPTURE-PROGRESS=> messages first. |
---|
1059 | # |
---|
1060 | while {[regexp -indices \ |
---|
1061 | {=RAPPTURE-PROGRESS=> *([-+]?[0-9]+) +([^\n]*)(\n|$)} $message \ |
---|
1062 | match percent mesg]} { |
---|
1063 | |
---|
1064 | foreach {i0 i1} $percent break |
---|
1065 | set percent [string range $message $i0 $i1] |
---|
1066 | |
---|
1067 | foreach {i0 i1} $mesg break |
---|
1068 | set mesg [string range $message $i0 $i1] |
---|
1069 | |
---|
1070 | pack $itk_component(progress) -fill x -padx 10 -pady 10 |
---|
1071 | $itk_component(progress) settings -percent $percent -message $mesg |
---|
1072 | |
---|
1073 | foreach {i0 i1} $match break |
---|
1074 | set message [string replace $message $i0 $i1] |
---|
1075 | } |
---|
1076 | |
---|
1077 | # |
---|
1078 | # Break up the remaining lines according to =RAPPTURE-ERROR=> messages. |
---|
1079 | # Show errors in a special color. |
---|
1080 | # |
---|
1081 | $itk_component(runinfo) configure -state normal |
---|
1082 | |
---|
1083 | while {[regexp -indices \ |
---|
1084 | {=RAPPTURE-([a-zA-Z]+)=>([^\n]*)(\n|$)} $message \ |
---|
1085 | match type mesg]} { |
---|
1086 | |
---|
1087 | foreach {i0 i1} $match break |
---|
1088 | set first [string range $message 0 [expr {$i0-1}]] |
---|
1089 | if {[string length $first] > 0} { |
---|
1090 | $itk_component(runinfo) insert end $first |
---|
1091 | $itk_component(runinfo) insert end \n |
---|
1092 | } |
---|
1093 | |
---|
1094 | foreach {t0 t1} $type break |
---|
1095 | set type [string range $message $t0 $t1] |
---|
1096 | foreach {m0 m1} $mesg break |
---|
1097 | set mesg [string range $message $m0 $m1] |
---|
1098 | if {[string length $mesg] > 0 && $type != "RUN"} { |
---|
1099 | $itk_component(runinfo) insert end $mesg $type |
---|
1100 | $itk_component(runinfo) insert end \n $type |
---|
1101 | } |
---|
1102 | |
---|
1103 | set message [string range $message [expr {$i1+1}] end] |
---|
1104 | } |
---|
1105 | |
---|
1106 | if {[string length $message] > 0} { |
---|
1107 | $itk_component(runinfo) insert end $message |
---|
1108 | if {[$itk_component(runinfo) get end-2char] != "\n"} { |
---|
1109 | $itk_component(runinfo) insert end "\n" |
---|
1110 | } |
---|
1111 | $itk_component(runinfo) see end |
---|
1112 | } |
---|
1113 | $itk_component(runinfo) configure -state disabled |
---|
1114 | } |
---|
1115 | |
---|
1116 | # ---------------------------------------------------------------------- |
---|
1117 | # USAGE: _resultTooltip |
---|
1118 | # |
---|
1119 | # Used internally to build the tooltip string displayed for the |
---|
1120 | # result selector. If the current page has an associated description, |
---|
1121 | # then it is displayed beneath the result. |
---|
1122 | # |
---|
1123 | # Returns the string for the tooltip. |
---|
1124 | # ---------------------------------------------------------------------- |
---|
1125 | itcl::body Rappture::Analyzer::_resultTooltip {} { |
---|
1126 | set tip "" |
---|
1127 | set name [$itk_component(viewselector) value] |
---|
1128 | if {[info exists _label2desc($name)] && |
---|
1129 | [string length $_label2desc($name)] > 0} { |
---|
1130 | append tip "$_label2desc($name)\n\n" |
---|
1131 | } |
---|
1132 | if {[array size _label2page] > 1} { |
---|
1133 | append tip "Use this control to display other output results." |
---|
1134 | } |
---|
1135 | return $tip |
---|
1136 | } |
---|
1137 | |
---|
1138 | # ---------------------------------------------------------------------- |
---|
1139 | # USAGE: _fixSimControl |
---|
1140 | # |
---|
1141 | # Used internally to add or remove the simulation control at the |
---|
1142 | # top of the analysis area. This is controlled by the -simcontrol |
---|
1143 | # option. |
---|
1144 | # ---------------------------------------------------------------------- |
---|
1145 | itcl::body Rappture::Analyzer::_fixSimControl {} { |
---|
1146 | switch -- $itk_option(-simcontrol) { |
---|
1147 | on { |
---|
1148 | pack $itk_interior.simol -fill x -before $itk_interior.nb |
---|
1149 | } |
---|
1150 | off { |
---|
1151 | pack forget $itk_interior.simol |
---|
1152 | } |
---|
1153 | auto { |
---|
1154 | # |
---|
1155 | # If we have two or more radiodials, then there is a |
---|
1156 | # chance of encountering a combination of parameters |
---|
1157 | # with no data, requiring simulation. |
---|
1158 | # |
---|
1159 | if {[$itk_component(resultselector) size -controls] >= 2} { |
---|
1160 | pack $itk_interior.simol -fill x -before $itk_interior.nb |
---|
1161 | } else { |
---|
1162 | pack forget $itk_interior.simol |
---|
1163 | } |
---|
1164 | } |
---|
1165 | default { |
---|
1166 | error "bad value \"$itk_option(-simcontrol)\": should be on, off, auto" |
---|
1167 | } |
---|
1168 | } |
---|
1169 | } |
---|
1170 | |
---|
1171 | # ---------------------------------------------------------------------- |
---|
1172 | # USAGE: _fixNotebook |
---|
1173 | # |
---|
1174 | # Used internally to switch the active notebook page |
---|
1175 | # ---------------------------------------------------------------------- |
---|
1176 | itcl::body Rappture::Analyzer::_fixNotebook {} { |
---|
1177 | switch -- $itk_option(-notebookpage) { |
---|
1178 | about { |
---|
1179 | $itk_component(notebook) current about |
---|
1180 | } |
---|
1181 | simulate { |
---|
1182 | $itk_component(notebook) current simulate |
---|
1183 | } |
---|
1184 | analyze { |
---|
1185 | $itk_component(notebook) current analyze |
---|
1186 | } |
---|
1187 | default { |
---|
1188 | error "bad value \"$itk_option(-notebookpage)\": should be about, simulate, analyze" |
---|
1189 | } |
---|
1190 | } |
---|
1191 | } |
---|
1192 | |
---|
1193 | # ---------------------------------------------------------------------- |
---|
1194 | # USAGE: _isPdbTrajectory <data> |
---|
1195 | # |
---|
1196 | # Used internally to determine whether pdb or lammps data represents a |
---|
1197 | # trajectory rather than a single frame |
---|
1198 | # ---------------------------------------------------------------------- |
---|
1199 | itcl::body Rappture::Analyzer::_isPdbTrajectory {data} { |
---|
1200 | if { [llength $data] == 0 } { |
---|
1201 | return 0 |
---|
1202 | } |
---|
1203 | set nModels 0 |
---|
1204 | foreach line $data { |
---|
1205 | if { [string match "MODEL*" $line] } { |
---|
1206 | incr nModels |
---|
1207 | if { $nModels > 1 } { |
---|
1208 | # Stop if more than one model found. No need to count them |
---|
1209 | # all. |
---|
1210 | return 1 |
---|
1211 | } |
---|
1212 | } |
---|
1213 | } |
---|
1214 | return 0 |
---|
1215 | } |
---|
1216 | |
---|
1217 | # ---------------------------------------------------------------------- |
---|
1218 | # USAGE: _isLammpsTrajectory <data> |
---|
1219 | # |
---|
1220 | # Used internally to determine whether pdb or lammps data represents a |
---|
1221 | # trajectory rather than a single frame |
---|
1222 | # ---------------------------------------------------------------------- |
---|
1223 | itcl::body Rappture::Analyzer::_isLammpsTrajectory { data } { |
---|
1224 | if { [llength $data] == 0 } { |
---|
1225 | return 0 |
---|
1226 | } |
---|
1227 | set nModels 0 |
---|
1228 | foreach line $data { |
---|
1229 | if { [regexp {^[\t ]*ITEM:[ \t]+TIMESTEP} $line] } { |
---|
1230 | incr nModels |
---|
1231 | if { $nModels > 1 } { |
---|
1232 | # Stop if more than one model found. No need to count them |
---|
1233 | # all. |
---|
1234 | return 1 |
---|
1235 | } |
---|
1236 | } |
---|
1237 | } |
---|
1238 | return 0 |
---|
1239 | } |
---|
1240 | |
---|
1241 | # ---------------------------------------------------------------------- |
---|
1242 | # USAGE: _pdbToSequence <xmlobj> ?<path>? |
---|
1243 | # |
---|
1244 | # If the molecule element is a trajectory, delete the original |
---|
1245 | # and create a sequence of individual molecules. |
---|
1246 | # Used internally to detect any molecule output elements that contain |
---|
1247 | # trajectory data. Trajectories will be converted into sequences of |
---|
1248 | # individual molecules. All other elements will be unaffected. Scans |
---|
1249 | # the entire xml tree if a starting path is not specified. |
---|
1250 | # ---------------------------------------------------------------------- |
---|
1251 | itcl::body Rappture::Analyzer::_pdbToSequence {xmlobj path id child data} { |
---|
1252 | |
---|
1253 | set seqLabel [$xmlobj get ${child}.about.label] |
---|
1254 | set descr [$xmlobj get ${child}.about.description] |
---|
1255 | set formula [$xmlobj get ${child}.components.molecule.formula] |
---|
1256 | $xmlobj remove $child |
---|
1257 | |
---|
1258 | set sequence $path.sequence($id) |
---|
1259 | $xmlobj put ${sequence}.about.label $seqLabel |
---|
1260 | $xmlobj put ${sequence}.about.description $descr |
---|
1261 | $xmlobj put ${sequence}.index.label "Frame" |
---|
1262 | |
---|
1263 | set frameNum 0 |
---|
1264 | set numLines [llength $data] |
---|
1265 | for { set i 0 } { $i < $numLines } { incr i } { |
---|
1266 | set line [lindex $data $i] |
---|
1267 | set line [string trim $line] |
---|
1268 | set contents {} |
---|
1269 | if { [string match "MODEL*" $line] } { |
---|
1270 | # Save the contents until we get an ENDMDL record. |
---|
1271 | for {} { $i < $numLines } { incr i } { |
---|
1272 | set line [lindex $data $i] |
---|
1273 | set line [string trim $line] |
---|
1274 | if { $line == "" } { |
---|
1275 | continue; # Skip blank lines. |
---|
1276 | } |
---|
1277 | if { [string match "ENDMDL*" $line] } { |
---|
1278 | break; |
---|
1279 | } |
---|
1280 | append contents $line\n |
---|
1281 | } |
---|
1282 | set frame ${sequence}.element($frameNum) |
---|
1283 | $xmlobj put ${frame}.index $frameNum |
---|
1284 | |
---|
1285 | set molecule ${frame}.structure.components.molecule |
---|
1286 | $xmlobj put ${molecule}.pdb $contents |
---|
1287 | $xmlobj put ${molecule}.formula $formula |
---|
1288 | incr frameNum |
---|
1289 | } |
---|
1290 | } |
---|
1291 | } |
---|
1292 | |
---|
1293 | # ---------------------------------------------------------------------- |
---|
1294 | # USAGE: _lammpsToSequence <xmlobj> ?<path>? |
---|
1295 | # |
---|
1296 | # If the molecule element is a trajectory, delete the original |
---|
1297 | # and create a sequence of individual molecules. |
---|
1298 | # Used internally to detect any molecule output elements that contain |
---|
1299 | # trajectory data. Trajectories will be converted into sequences of |
---|
1300 | # individual molecules. All other elements will be unaffected. Scans |
---|
1301 | # the entire xml tree if a starting path is not specified. |
---|
1302 | # ---------------------------------------------------------------------- |
---|
1303 | itcl::body Rappture::Analyzer::_lammpsToSequence {xmlobj path id child data} { |
---|
1304 | |
---|
1305 | set seqLabel [$xmlobj get ${child}.about.label] |
---|
1306 | set descr [$xmlobj get ${child}.about.description] |
---|
1307 | set typemap [$xmlobj get ${child}.components.molecule.lammpstypemap] |
---|
1308 | $xmlobj remove $child |
---|
1309 | |
---|
1310 | set sequence ${path}.sequence($id) |
---|
1311 | $xmlobj put ${sequence}.about.label $seqLabel |
---|
1312 | $xmlobj put ${sequence}.about.description $descr |
---|
1313 | $xmlobj put ${sequence}.index.label "Frame" |
---|
1314 | |
---|
1315 | set frameNum 0 |
---|
1316 | set frameContents "" |
---|
1317 | set inModel 0 |
---|
1318 | foreach line $data { |
---|
1319 | set line [string trim $line] |
---|
1320 | if { $line == "" } { |
---|
1321 | continue; # Skip blank lines |
---|
1322 | } |
---|
1323 | if {[regexp {^[\t ]*ITEM:[ \t]+ATOMS} $line] } { |
---|
1324 | if { $inModel && $frameContents != "" } { |
---|
1325 | set frame ${sequence}.element($frameNum) |
---|
1326 | $xmlobj put ${frame}.index $frameNum |
---|
1327 | |
---|
1328 | set molecule ${frame}.structure.components.molecule |
---|
1329 | $xmlobj put ${molecule}.lammps $frameContents |
---|
1330 | $xmlobj put ${molecule}.lammpstypemap $typemap |
---|
1331 | |
---|
1332 | incr frameNum |
---|
1333 | set frameContents "" |
---|
1334 | } |
---|
1335 | set inModel 1 |
---|
1336 | } elseif { [scan $line "%d %d %f %f %f" a b c d e] == 5 } { |
---|
1337 | if { !$inModel } { |
---|
1338 | puts stderr "found \"$line\" without previous \"ITEM: ATOMS\"" |
---|
1339 | set inModel 1 |
---|
1340 | } |
---|
1341 | append frameContents $line\n |
---|
1342 | } |
---|
1343 | } |
---|
1344 | if { $frameContents != "" } { |
---|
1345 | set frame ${sequence}.element($frameNum) |
---|
1346 | $xmlobj put ${frame}.index $frameNum |
---|
1347 | |
---|
1348 | set molecule ${frame}.structure.components.molecule |
---|
1349 | $xmlobj put ${molecule}.lammps $frameContents |
---|
1350 | $xmlobj put ${molecule}.lammpstypemap $typemap |
---|
1351 | } |
---|
1352 | } |
---|
1353 | |
---|
1354 | # ---------------------------------------------------------------------- |
---|
1355 | # USAGE: _trajToSequence <xmlobj> ?<path>? |
---|
1356 | # |
---|
1357 | # Check for PDB and LAMMPS trajectories in molecule data and rewrite |
---|
1358 | # the individual models as a sequence of molecules. Used internally |
---|
1359 | # to detect any molecule output elements that contain trajectory data. |
---|
1360 | # Trajectories will be converted into sequences of individual molecules. |
---|
1361 | # All other elements will be unaffected. Scans the entire xml tree if a |
---|
1362 | # starting path is not specified. |
---|
1363 | # |
---|
1364 | # ---------------------------------------------------------------------- |
---|
1365 | itcl::body Rappture::Analyzer::_trajToSequence {xmlobj {path ""}} { |
---|
1366 | # Remove leading dot from path, if present. |
---|
1367 | if { [string index $path 0] == "." } { |
---|
1368 | set path [string range $path 1 end] |
---|
1369 | } |
---|
1370 | # Otherwise check each child. |
---|
1371 | foreach child [$xmlobj children $path] { |
---|
1372 | set current ${path}.${child} |
---|
1373 | if { [string match "structure*" $child] } { |
---|
1374 | set isTraj [$xmlobj get ${current}.components.molecule.trajectory] |
---|
1375 | if { $isTraj == "" || !$isTraj } { |
---|
1376 | continue; # Not a trajectory. |
---|
1377 | } |
---|
1378 | # Look for trajectory if molecule element found. Check both pdb |
---|
1379 | # data and lammps data. |
---|
1380 | set type [$xmlobj element -as type $current] |
---|
1381 | set id [$xmlobj element -as id $current] |
---|
1382 | set pdbdata [$xmlobj get ${current}.components.molecule.pdb] |
---|
1383 | set lammpsdata [$xmlobj get ${current}.components.molecule.lammps] |
---|
1384 | if { $pdbdata != "" && $lammpsdata != "" } { |
---|
1385 | puts stderr \ |
---|
1386 | "found both <pdb> and <lammps> elements: picking pdb" |
---|
1387 | } |
---|
1388 | set pdbdata [split $pdbdata \n] |
---|
1389 | set lammpsdata [split $lammpsdata \n] |
---|
1390 | if { [_isPdbTrajectory $pdbdata] } { |
---|
1391 | _pdbToSequence $xmlobj $path $id $current $pdbdata |
---|
1392 | } elseif { [_isLammpsTrajectory $lammpsdata] } { |
---|
1393 | _lammpsToSequence $xmlobj $path $id $current $lammpsdata |
---|
1394 | } |
---|
1395 | continue |
---|
1396 | } |
---|
1397 | if 0 { |
---|
1398 | # Recurse over all child nodes. |
---|
1399 | _trajToSequence $xmlobj $current |
---|
1400 | } |
---|
1401 | } |
---|
1402 | } |
---|
1403 | |
---|
1404 | # ---------------------------------------------------------------------- |
---|
1405 | # CONFIGURATION OPTION: -simcontrol |
---|
1406 | # |
---|
1407 | # Controls whether or not the Simulate button is showing. In some |
---|
1408 | # cases, it is not needed. |
---|
1409 | # ---------------------------------------------------------------------- |
---|
1410 | itcl::configbody Rappture::Analyzer::simcontrol { |
---|
1411 | _fixSimControl |
---|
1412 | } |
---|
1413 | |
---|
1414 | # ---------------------------------------------------------------------- |
---|
1415 | # CONFIGURATION OPTION: -notebookpage |
---|
1416 | # |
---|
1417 | # Controls which page of the analyzer notebook is shown. It is |
---|
1418 | # particularly needed when using rerun, when you don't want to |
---|
1419 | # "simulate -ifneeded" because an actual simulation might be |
---|
1420 | # kicked off due to differences between tool.xml and run.xml |
---|
1421 | # ---------------------------------------------------------------------- |
---|
1422 | itcl::configbody Rappture::Analyzer::notebookpage { |
---|
1423 | _fixNotebook |
---|
1424 | } |
---|