Changeset 2966 for branches/blt4/gui/scripts/resultviewer.tcl
- Timestamp:
- Apr 13, 2012 12:04:37 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/blt4/gui/scripts/resultviewer.tcl
r2745 r2966 36 36 protected method _plotAdd {xmlobj {settings ""}} 37 37 protected method _fixScale {args} 38 protected proc _xml2data {xmlobj path} 38 protected method _xml2data {xmlobj path} 39 protected method _cleanIndex {index} 39 40 40 41 private variable _dispatcher "" ;# dispatchers for !events … … 42 43 private variable _mode2widget ;# maps plotting mode => widget 43 44 private variable _dataslots "" ;# list of all data objects in this widget 45 private variable _xml2data ;# maps xmlobj => data obj in _dataslots 44 46 } 45 47 … … 79 81 # ---------------------------------------------------------------------- 80 82 itcl::body Rappture::ResultViewer::add {index xmlobj path} { 83 set index [_cleanIndex $index] 81 84 set dobj [_xml2data $xmlobj $path] 82 85 … … 96 99 97 100 # ---------------------------------------------------------------------- 98 # USAGE: clear ?<index>? 99 # 100 # Clears one or all results in this result viewer. 101 # USAGE: clear ?<index>|<xmlobj>? 102 # 103 # Clears one or all results in this result viewer. If a particular 104 # <index> is specified, then all data objects at that index are 105 # deleted. If a particular <xmlobj> is specified, then all data 106 # objects related to that <xmlobj> are removed--regardless of whether 107 # they reside at one or more indices. 101 108 # ---------------------------------------------------------------------- 102 109 itcl::body Rappture::ResultViewer::clear {{index ""}} { 103 if { "" != $index} {110 if {$index ne ""} { 104 111 # clear one result 105 if {$index >= 0 && $index < [llength $_dataslots]} { 106 set slot [lindex $_dataslots $index] 107 foreach dobj $slot { 112 if {[catch {_cleanIndex $index} i] == 0} { 113 if {$i >= 0 && $i < [llength $_dataslots]} { 114 set slot [lindex $_dataslots $i] 115 foreach dobj $slot { 116 itcl::delete object $dobj 117 } 118 set _dataslots [lreplace $_dataslots $i $i ""] 119 $_dispatcher event -idle !scale 120 } 121 } else { 122 foreach key [array names _xml2data $index-*] { 123 set dobj $_xml2data($key) 124 125 # search for and remove all references to this data object 126 for {set n 0} {$n < [llength $_dataslots]} {incr n} { 127 set slot [lindex $_dataslots $n] 128 set pos [lsearch -exact $slot $dobj] 129 if {$pos >= 0} { 130 set slot [lreplace $slot $pos $pos] 131 set _dataslots [lreplace $_dataslots $n $n $slot] 132 $_dispatcher event -idle !scale 133 } 134 } 135 136 # destroy the object and forget it 108 137 itcl::delete object $dobj 109 }110 set _dataslots [lreplace $_dataslots $index $index ""]138 unset _xml2data($key) 139 } 111 140 } 112 141 } else { … … 119 148 } 120 149 set _dataslots "" 150 catch {unset _xml2data} 121 151 } 122 152 } … … 139 169 140 170 # ---------------------------------------------------------------------- 141 # USAGE: plot add ?< index> <settings> <index> <settings> ...?171 # USAGE: plot add ?<simnum> <settings> <simnum> <settings> ...? 142 172 # USAGE: plot clear 143 173 # … … 145 175 # command clears the current viewer. Data is still stored in the 146 176 # widget, but the results are not shown on screen. The "plot add" 147 # command adds the data at the specified <index> to the plot. If 177 # command adds the data at the specified <simnum> to the plot. Each 178 # <simnum> is the simulation number, like "#1", "#2", "#3", etc. If 148 179 # the optional <settings> are specified, then they are applied 149 180 # to the plot; otherwise, default settings are used. … … 158 189 continue 159 190 } 191 192 set index [_cleanIndex $index] 160 193 set reset "-color autoreset" 161 194 set slot [lindex $_dataslots $index] … … 263 296 set mode "contour" 264 297 if {![info exists _mode2widget($mode)]} { 298 global env 265 299 if { [$dataobj isunirect2d] } { 266 300 if { [$dataobj hints type] == "contour" } { … … 271 305 set resultMode "heightmap" 272 306 } 307 } elseif { [info exists env(VTKCONTOUR)] } { 308 set resultMode "vtkcontour" 273 309 } else { 274 310 set resultMode "vtk" … … 292 328 set fmt "vtk" 293 329 } 294 "opendx" - "dx" - "points-on-mesh" { 330 "points-on-mesh" { 331 set mesh [$dataobj mesh] 332 set fmt [expr {("" != $mesh) ? "vtk" : "nanovis"}] 333 set extents [$dataobj extents] 334 if { $extents > 1 } { 335 set fmt "flowvis" 336 } 337 } 338 "opendx" - "dx" { 295 339 set fmt "nanovis" 296 340 set extents [$dataobj extents] … … 464 508 # ---------------------------------------------------------------------- 465 509 itcl::body Rappture::ResultViewer::_xml2data {xmlobj path} { 510 if {[info exists _xml2data($xmlobj-$path)]} { 511 return $_xml2data($xmlobj-$path) 512 } 513 466 514 set type [$xmlobj element -as type $path] 467 515 switch -- $type { 468 516 curve { 469 return[Rappture::Curve ::#auto $xmlobj $path]517 set dobj [Rappture::Curve ::#auto $xmlobj $path] 470 518 } 471 519 datatable { 472 return[Rappture::DataTable ::#auto $xmlobj $path]520 set dobj [Rappture::DataTable ::#auto $xmlobj $path] 473 521 } 474 522 histogram { 475 return[Rappture::Histogram ::#auto $xmlobj $path]523 set dobj [Rappture::Histogram ::#auto $xmlobj $path] 476 524 } 477 525 field { 478 return[Rappture::Field ::#auto $xmlobj $path]526 set dobj [Rappture::Field ::#auto $xmlobj $path] 479 527 } 480 528 mesh { 481 return[Rappture::Mesh ::#auto $xmlobj $path]529 set dobj [Rappture::Mesh ::#auto $xmlobj $path] 482 530 } 483 531 table { 484 return[Rappture::Table ::#auto $xmlobj $path]532 set dobj [Rappture::Table ::#auto $xmlobj $path] 485 533 } 486 534 image { 487 return[Rappture::Image ::#auto $xmlobj $path]535 set dobj [Rappture::Image ::#auto $xmlobj $path] 488 536 } 489 537 sequence { 490 return[Rappture::Sequence ::#auto $xmlobj $path]538 set dobj [Rappture::Sequence ::#auto $xmlobj $path] 491 539 } 492 540 string - log { 493 return[$xmlobj element -as object $path]541 set dobj [$xmlobj element -as object $path] 494 542 } 495 543 structure { 496 return[$xmlobj element -as object $path]544 set dobj [$xmlobj element -as object $path] 497 545 } 498 546 number - integer - boolean - choice { 499 return[$xmlobj element -as object $path]547 set dobj [$xmlobj element -as object $path] 500 548 } 501 549 drawing3d - drawing { 502 return[Rappture::Drawing ::#auto $xmlobj $path]550 set dobj [Rappture::Drawing ::#auto $xmlobj $path] 503 551 } 504 552 time - status { 505 return "" 506 } 507 } 508 error "don't know how to plot <$type> data path=$path" 553 set dobj "" 554 } 555 default { 556 error "don't know how to plot <$type> data path=$path" 557 } 558 } 559 560 # store the mapping xmlobj=>dobj so we can find this result later 561 if {$dobj ne ""} { 562 set _xml2data($xmlobj-$path) $dobj 563 } 564 return $dobj 565 } 566 567 # ---------------------------------------------------------------------- 568 # USAGE: _cleanIndex <index> 569 # 570 # Used internally to create a data object for the data at the 571 # specified <path> in the <xmlobj>. 572 # ---------------------------------------------------------------------- 573 itcl::body Rappture::ResultViewer::_cleanIndex {index} { 574 if {[regexp {^#([0-9]+)} $index match num]} { 575 return [expr {$num-1}] ;# start from 0 instead of 1 576 } elseif {[string is integer -strict $index]} { 577 return $index 578 } 579 error "bad plot index \"$index\": should be 0,1,2,... or #1,#2,#3,..." 509 580 } 510 581
Note: See TracChangeset
for help on using the changeset viewer.