Changeset 5121
- Timestamp:
- Mar 11, 2015, 10:26:15 AM (9 years ago)
- Location:
- branches/uq
- Files:
-
- 4 deleted
- 56 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/uq
- Property svn:mergeinfo changed
-
branches/uq/configure
r5029 r5121 672 672 OCTAVE_VERSION_MAJOR 673 673 OCTAVE_VERSION 674 SVN_URL 674 675 SVN_VERSION 675 676 MKOCTFILE3 … … 7297 7298 7298 7299 SVN_VERSION=`svnversion $srcdir | sed 's/Unversioned directory/unknown/'` 7300 SVN_URL=`svn info $srcdir | sed -ne 's/^URL: //p'` 7299 7301 7300 7302 make_command="" … … 10135 10137 10136 10138 MAKE=${make_command} 10139 10137 10140 10138 10141 -
branches/uq/configure.in
r5029 r5121 108 108 109 109 SVN_VERSION=`svnversion $srcdir | sed 's/Unversioned directory/unknown/'` 110 SVN_URL=`svn info $srcdir | sed -ne 's/^URL: //p'` 110 111 111 112 make_command="" … … 401 402 AC_SUBST(MKOCTFILE3) 402 403 AC_SUBST(SVN_VERSION) 404 AC_SUBST(SVN_URL) 403 405 AC_SUBST(OCTAVE_VERSION) 404 406 AC_SUBST(OCTAVE_VERSION_MAJOR) -
branches/uq/examples/flow/flowtest.tcl
r4228 r5121 39 39 $f1.component.flow.particles(right).color khaki 40 40 $f1.component.flow.particles(right).position 90% 41 $f1.component.style "-color blue:red -levels 6 -opacity 1"41 $f1.component.style "-color blue:red -levels 6" 42 42 $f1.component.flow.box(one).label "Region 1" 43 43 $f1.component.flow.box(one).color cyan … … 75 75 $f2.component.flow.particles(right).color pink 76 76 $f2.component.flow.particles(right).position 90% 77 $f2.component.style "-color rainbow -levels 6 -opacity 1"77 $f2.component.style "-color rainbow -levels 6" 78 78 $f2.camera.position { 79 79 qw 1 qx 0 qy 0 qz 0 pan-x 0 pan-y 0 zoom 1.0 … … 100 100 $f3.component.flow.particles(right).color khaki 101 101 $f3.component.flow.particles(right).position 90% 102 $f3.component.style "-color blue:red -levels 6 -opacity 1"102 $f3.component.style "-color blue:red -levels 6" 103 103 $f3.component.elemtype vectors 104 104 $f3.component.elemsize 3 -
branches/uq/gui/apps/Makefile.in
r4513 r5121 24 24 copy_rappture_examples \ 25 25 encodedata \ 26 $(srcdir)/execute.tcl \ 26 27 $(srcdir)/launcher.tcl \ 27 $(srcdir)/mapviewer-test \28 28 $(srcdir)/grabdata \ 29 29 $(srcdir)/nanovis-test \ -
branches/uq/gui/apps/launcher.tcl
r5029 r5121 12 12 # rappture -builder ?-tool <toolfile>? 13 13 # rappture -tester ?-tool <toolfile>? ?-testdir <directory>? 14 # rappture -execute driver.xml ?-tool <toolfile>? 14 15 # 15 16 # The default option is "-run", which brings up the GUI used to … … 26 27 set mainscript "" 27 28 set alist "" 29 set loadlist "" 28 30 set toolxml "" 31 32 # ---------------------------------------------------------------------- 33 # Look for parameters passed into the tool session. If there are 34 # any "file" parameters, they indicate files that should be loaded 35 # for browsing or executed to get results: 36 # 37 # file(load):/path/to/run.xml 38 # file(execute):/path/to/driver.xml 39 # ---------------------------------------------------------------------- 40 set params(opt) "" 41 set params(load) "" 42 set params(execute) "" 43 set params(input) "" 44 45 if {[info exists env(TOOL_PARAMETERS)]} { 46 # if we can't find the file, wait a little 47 set ntries 25 48 while {$ntries > 0 && ![file exists $env(TOOL_PARAMETERS)]} { 49 after 200 50 incr ntries -1 51 } 52 53 if {![file exists $env(TOOL_PARAMETERS)]} { 54 # still no file after all that? then skip parameters 55 puts stderr "WARNING: can't read tool parameters in file \"$env(TOOL_PARAMETERS)\"\nFile not found." 56 57 } elseif {[catch { 58 # read the file and parse the contents 59 set fid [open $env(TOOL_PARAMETERS) r] 60 set info [read $fid] 61 close $fid 62 } result] != 0} { 63 puts stderr "WARNING: can't read tool parameters in file \"$env(TOOL_PARAMETERS)\"\n$result" 64 65 } else { 66 # parse the contents of the tool parameter file 67 foreach line [split $info \n] { 68 set line [string trim $line] 69 if {$line eq "" || [regexp {^#} $line]} { 70 continue 71 } 72 73 if {[regexp {^([a-zA-Z]+)(\(into\:)(.+)\)\:(.+)$} $line match type name path value] 74 || [regexp {^([a-zA-Z]+)(\([^)]+\))?\:(.+)} $line match type name value]} { 75 if {$type eq "file"} { 76 switch -exact -- $name { 77 "(load)" - "" { 78 lappend params(load) $value 79 set params(opt) "-load" 80 } 81 "(execute)" { 82 set params(execute) $value 83 set params(opt) "-execute" 84 } 85 "(input)" { 86 set params(input) $value 87 set params(opt) "-input" 88 } 89 "(into:" { 90 namespace eval ::Rappture { # forward decl } 91 set ::Rappture::parameters($path) $value 92 } 93 default { 94 puts stderr "WARNING: directive $name not recognized for file parameter \"$value\"" 95 } 96 } 97 } 98 } 99 } 100 } 101 } 29 102 30 103 # scan through the arguments and look for the function … … 53 126 set reqpkgs Tk 54 127 } 128 -execute { 129 # for web services and simulation cache -- don't load Tk 130 set reqpkgs "" 131 if {[llength $argv] < 1} { 132 puts stderr "error: missing driver.xml file for -execute option" 133 exit 1 134 } 135 set driverxml [lindex $argv 0] 136 set argv [lrange $argv 1 end] 137 138 if {![file readable $driverxml]} { 139 puts stderr "error: driver file \"$driverxml\" not found" 140 exit 1 141 } 142 143 set dir [file dirname [info script]] 144 set mainscript [file join $dir execute.tcl] 145 } 55 146 -tool { 56 147 set toolxml [lindex $argv 0] … … 62 153 lappend alist -tool $toolxml 63 154 } 64 -t ool - -testdir - -nosim {155 -testdir - -nosim { 65 156 lappend alist $opt [lindex $argv 0] 66 157 set argv [lrange $argv 1 end] … … 74 165 } 75 166 -load { 76 lappend alist $opt77 167 while { [llength $argv] > 0 } { 78 168 set val [lindex $argv 0] … … 80 170 break 81 171 } 82 lappend alist $val172 lappend loadlist $val 83 173 set argv [lrange $argv 1 end] 84 174 } … … 89 179 puts stderr " rappture -builder ?-tool toolFile?" 90 180 puts stderr " rappture -tester ?-auto? ?-tool toolFile? ?-testdir directory?" 181 puts stderr " rappture -execute driver.xml ?-tool toolFile?" 91 182 exit 1 92 183 } … … 95 186 } 96 187 97 # If no arguments, assume that it's the -run option 188 # If no arguments, check to see if there are any tool parameters. 189 # If not, then assume that it's the -run option. 98 190 if {$mainscript eq ""} { 99 package require RapptureGUI 100 set guidir $RapptureGUI::library 101 set mainscript [file join $guidir scripts main.tcl] 102 set reqpkgs Tk 191 switch -- $params(opt) { 192 -load { 193 # add tool parameters to the end of any files given on cmd line 194 set loadlist [concat $loadlist $params(load)] 195 set alist [concat $alist -load $loadlist] 196 197 package require RapptureGUI 198 set guidir $RapptureGUI::library 199 set mainscript [file join $guidir scripts main.tcl] 200 set reqpkgs Tk 201 } 202 -execute { 203 if {[llength $params(execute)] != 1} { 204 puts stderr "ERROR: wrong number of (execute) files in TOOL_PARAMETERS (should be only 1)" 205 exit 1 206 } 207 set driverxml [lindex $params(execute) 0] 208 if {![file readable $driverxml]} { 209 puts stderr "error: driver file \"$driverxml\" not found" 210 exit 1 211 } 212 set dir [file dirname [info script]] 213 set mainscript [file join $dir execute.tcl] 214 set reqpkgs "" 215 216 # When executing from TOOL_PARAMETERS file directives, 217 # report status, clean up, and save output to data/results. 218 # This helps the web services interface do its thing. 219 set alist [list \ 220 -output @default \ 221 -status rappture.status \ 222 -cleanup yes] 223 } 224 "" - "-input" { 225 package require RapptureGUI 226 set guidir $RapptureGUI::library 227 set mainscript [file join $guidir scripts main.tcl] 228 set reqpkgs Tk 229 230 # finalize the -input argument for "rappture -run" 231 if {$params(input) ne ""} { 232 if {![file readable $params(input)]} { 233 puts stderr "error: driver file \"$params(input)\" not found" 234 exit 1 235 } 236 set alist [concat $alist -input $params(input)] 237 } 238 239 # finalize any pending -load arguments for "rappture -run" 240 if {[llength $loadlist] > 0} { 241 set alist [concat $alist -load $loadlist] 242 } 243 } 244 default { 245 puts stderr "internal error: funny action \"$params(opt)\" inferred from TOOL_PARAMETERS" 246 exit 1 247 } 248 } 249 } else { 250 # finalize any pending -load arguments for "rappture -run" 251 if {[llength $loadlist] > 0} { 252 set alist [concat $alist -load $loadlist] 253 } 103 254 } 104 255 -
branches/uq/gui/apps/rpdiff
r3177 r5121 24 24 exec tclsh "$0" ${1+"$@"} 25 25 # tclsh executes the rest... 26 27 26 package require Rappture 28 27 … … 36 35 proc diff {path lib1 lib2} { 37 36 set knowntypes {boolean choice cloud curve field group histogram image integer loader log mesh note number periodicelement phase sequence string structure table unirect2d} 38 39 37 set type1 [$lib1 element -as type $path] 40 38 set type2 [$lib2 element -as type $path] … … 490 488 } 491 489 } 490 loader { 491 } 492 492 default { 493 error "don't know how to compare type \"$type\""493 puts stderr "ignoring \"$type1\" for \"$path\"" 494 494 } 495 495 } … … 557 557 558 558 # ====================================================================== 559 if {$argc != 2} { 559 560 if {$argc < 2} { 560 561 puts stderr "USAGE: rpdiff file1.xml file2.xml" 561 562 exit 9 … … 563 564 set lib1 [Rappture::library [lindex $argv 0]] 564 565 set lib2 [Rappture::library [lindex $argv 1]] 566 set path "output" 567 if { $argc > 2 } { 568 set arg [lindex $argv 2] 569 if { $arg == "-path" && $argc == 4 } { 570 set path [lindex $argv 3] 571 } 572 } 565 573 566 574 # compute the differences 567 set diffs [diff output$lib1 $lib2]575 set diffs [diff $path $lib1 $lib2] 568 576 569 577 if {[llength $diffs] == 0} { -
branches/uq/gui/configure
r4798 r5121 1 1 #! /bin/sh 2 2 # Guess values for system-dependent variables and create Makefiles. 3 # Generated by GNU Autoconf 2.69 for RapptureGUI 1. 4.3 # Generated by GNU Autoconf 2.69 for RapptureGUI 1.3. 4 4 # 5 5 # Report bugs to <rappture@nanohub.org>. … … 580 580 PACKAGE_NAME='RapptureGUI' 581 581 PACKAGE_TARNAME='rappturegui' 582 PACKAGE_VERSION='1. 4'583 PACKAGE_STRING='RapptureGUI 1. 4'582 PACKAGE_VERSION='1.3' 583 PACKAGE_STRING='RapptureGUI 1.3' 584 584 PACKAGE_BUGREPORT='rappture@nanohub.org' 585 585 PACKAGE_URL='' … … 1223 1223 # This message is too long to be a string in the A/UX 3.1 sh. 1224 1224 cat <<_ACEOF 1225 \`configure' configures RapptureGUI 1. 4to adapt to many kinds of systems.1225 \`configure' configures RapptureGUI 1.3 to adapt to many kinds of systems. 1226 1226 1227 1227 Usage: $0 [OPTION]... [VAR=VALUE]... … … 1289 1289 if test -n "$ac_init_help"; then 1290 1290 case $ac_init_help in 1291 short | recursive ) echo "Configuration of RapptureGUI 1. 4:";;1291 short | recursive ) echo "Configuration of RapptureGUI 1.3:";; 1292 1292 esac 1293 1293 cat <<\_ACEOF … … 1380 1380 if $ac_init_version; then 1381 1381 cat <<\_ACEOF 1382 RapptureGUI configure 1. 41382 RapptureGUI configure 1.3 1383 1383 generated by GNU Autoconf 2.69 1384 1384 … … 1435 1435 running configure, to aid debugging if configure makes a mistake. 1436 1436 1437 It was created by RapptureGUI $as_me 1. 4, which was1437 It was created by RapptureGUI $as_me 1.3, which was 1438 1438 generated by GNU Autoconf 2.69. Invocation command line was 1439 1439 … … 3685 3685 # values after options handling. 3686 3686 ac_log=" 3687 This file was extended by RapptureGUI $as_me 1. 4, which was3687 This file was extended by RapptureGUI $as_me 1.3, which was 3688 3688 generated by GNU Autoconf 2.69. Invocation command line was 3689 3689 … … 3738 3738 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" 3739 3739 ac_cs_version="\\ 3740 RapptureGUI config.status 1. 43740 RapptureGUI config.status 1.3 3741 3741 configured by $0, generated by GNU Autoconf 2.69, 3742 3742 with options \\"\$ac_cs_config\\" -
branches/uq/gui/configure.in
r4798 r5121 1 1 2 AC_INIT([RapptureGUI],[1. 4],[rappture@nanohub.org])2 AC_INIT([RapptureGUI],[1.3],[rappture@nanohub.org]) 3 3 AC_CONFIG_AUX_DIR(cf) 4 4 #------------------------------------------------------------------------ -
branches/uq/gui/pkgIndex.tcl.in
r2117 r5121 1 1 # HACK: The Img library needs to be loaded before RapptureGUI 2 # to avoid conflicts with libjpeg, libtiff, etc. 2 3 package ifneeded RapptureGUI @PACKAGE_VERSION@ [format { 4 package require Img 3 5 set dir [file normalize "%s"] 4 6 set version @PACKAGE_VERSION@ … … 12 14 package provide RapptureGUI $version 13 15 } $dir] 14 -
branches/uq/gui/scripts/Makefile.in
r5102 r5121 77 77 $(srcdir)/main.tcl \ 78 78 $(srcdir)/mainwin.tcl \ 79 $(srcdir)/map.tcl \80 $(srcdir)/mapviewer.tcl \81 79 $(srcdir)/mesh.tcl \ 82 80 $(srcdir)/meshresult.tcl \ -
branches/uq/gui/scripts/analyzer.tcl
r5102 r5121 319 319 320 320 itk_component add results { 321 Rappture::Panes $w.pane -sashwidth 1 -sashrelief solid -sashpadding {4 0} 321 Rappture::Panes $w.pane \ 322 -sashwidth 2 -sashrelief solid -sashpadding {2 0} 323 } { 324 usual 325 ignore -sashwidth -sashrelief -sashpadding 322 326 } 323 327 pack $itk_component(results) -expand yes -fill both … … 829 833 _autoLabel $xmlobj output.$item "String" counters 830 834 } 831 histogram* - curve* - field* - map*{835 histogram* - curve* - field* { 832 836 _autoLabel $xmlobj output.$item "Plot" counters 833 837 } -
branches/uq/gui/scripts/cloud.tcl
r4504 r5121 148 148 # Extract each point and add it to the points list 149 149 foreach {x y z} $line break 150 foreach axis {x y z} units $_units { 151 if { $units == "" } { 152 set value [set $axis] 153 } else { 154 set value [Rappture::Units::convert [set $axis] \ 155 -context $units -to $units -units off] 156 } 157 set $axis $value; # Set the (x/y/z) coordinate to 158 # converted value. 150 foreach axis {x y z} { 151 # Units on point coordinates are NOT supported 152 set value [set $axis] 153 # Update limits 159 154 if { ![info exists _limits($axis)] } { 160 155 set _limits($axis) [list $value $value] -
branches/uq/gui/scripts/curve.tcl
r4008 r5121 112 112 # USAGE: values ?<name>? 113 113 # 114 # Returns the xvec for the specified curve component <name>.114 # Returns the yvec for the specified curve component <name>. 115 115 # If the name is not specified, then it returns the vectors for the 116 116 # overall curve (sum of all components). -
branches/uq/gui/scripts/drawing.tcl
r4494 r5121 129 129 } 130 130 } 131 foreach {key path} { 132 toolid tool.id 133 toolname tool.name 134 toolcommand tool.execute 135 tooltitle tool.title 136 toolrevision tool.version.application.revision 137 } { 138 set str [$_xmlobj get $path] 139 if { "" != $str } { 140 set _hints($key) $str 141 } 142 } 131 143 } 132 144 -
branches/uq/gui/scripts/field.tcl
r4797 r5121 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 2 2 # ---------------------------------------------------------------------- 3 3 # COMPONENT: field - extracts data from an XML description of a field … … 25 25 # unirect2d (deprecated) 26 26 # cloud (x,y point coordinates) (deprecated) 27 # mesh 27 # mesh 28 28 # 3D Datasets 29 # vtk 29 # vtk 30 30 # unirect3d (deprecated) 31 31 # cloud (x,y,z coordinates) (deprecated) 32 # mesh 32 # mesh 33 33 # dx (FIXME: make dx-to-vtk converter work) 34 34 # ucd avs … … 41 41 # mesh 3 points-on-mesh isosurface vtkvis 42 42 # dx 3 DX volume nanovis 43 # unirect2d 2 unirect 3d + extents > 1 flow flow nanovis44 # unirect3d 3 unirect 2d + extents > 1 flow flow nanovis45 # 43 # unirect2d 2 unirect2d + extents > 1 flow flow nanovis 44 # unirect3d 3 unirect3d + extents > 1 flow flow nanovis 45 # 46 46 # With <views>, can specify which viewer for specific datasets. So it's OK 47 47 # for the same dataset to be viewed in more than one way. 48 # o Any 2D dataset can be viewed as a contour/heightmap. 48 # o Any 2D dataset can be viewed as a contour/heightmap. 49 49 # o Any 3D dataset can be viewed as a isosurface. 50 # o Any 2D dataset with vector data can be streamlines or flow. 50 # o Any 2D dataset with vector data can be streamlines or flow. 51 51 # o Any 3D uniform rectilinear dataset can be viewed as a volume. 52 52 # o Any 3D dataset with vector data can be streamlines or flow. … … 59 59 package require BLT 60 60 61 namespace eval Rappture { 62 # forward declaration 61 namespace eval Rappture { 62 # forward declaration 63 63 } 64 64 … … 68 68 private variable _limits; # maps axis name => {z0 z1} limits 69 69 private variable _field "" 70 private variable _comp2fldName ; 71 private variable _comp2type ; 72 private variable _comp2size ; 73 private variable _comp2assoc; 70 private variable _comp2fldName ; # cname => field names. 71 private variable _comp2type ; # cname => type (e.g. "vectors") 72 private variable _comp2size ; # cname => # of components in element 73 private variable _comp2assoc; # cname => association (e.g. pointdata) 74 74 private variable _fld2Components; # field name => number of components 75 75 private variable _fld2Label; # field name => label 76 76 private variable _fld2Units; # field name => units 77 private variable _hints 77 private variable _hints 78 78 private variable _viewer ""; # Hints which viewer to use 79 79 private variable _xv ""; # For 1D meshes only. Holds the points … … 83 83 private variable _alwaysConvertDX 0; 84 84 85 constructor {xmlobj path} { 86 # defined below 87 } 88 destructor { 89 # defined below 85 constructor {xmlobj path} { 86 # defined below 87 } 88 destructor { 89 # defined below 90 90 } 91 91 public method blob { cname } … … 127 127 } 128 128 public method viewer {} { 129 return $_viewer 129 return $_viewer 130 130 } 131 131 protected method Build {} 132 132 protected method _getValue {expr} 133 133 134 private variable _path ""; # Path of this object in the XML 134 private variable _path ""; # Path of this object in the XML 135 135 private variable _units "" ; # system of units for this field 136 136 private variable _zmax 0 ;# length of the device … … 144 144 private variable _comp2style ;# maps component name => style settings 145 145 private variable _comp2cntls ;# maps component name => x,y control points 146 private variable _comp2extents 147 private variable _comp2limits; 148 private variable _type "" 149 private variable _comp2flowhints 146 private variable _comp2extents 147 private variable _comp2limits; # Array of limits per component 148 private variable _type "" 149 private variable _comp2flowhints 150 150 private variable _comp2mesh 151 151 private common _counter 0 ;# counter for unique vector names 152 152 153 private method AvsToVtk { cname contents } 154 private method DicomToVtk { cname contents } 155 private method BuildPointsOnMesh { cname } 156 protected method GetAssociation { cname } 157 protected method GetTypeAndSize { cname } 158 protected method ReadVtkDataSet { cname contents } 159 private method InitHints {} 160 161 private method VerifyVtkDataSet { contents } 153 private method AvsToVtk { cname contents } 154 private method DicomToVtk { cname contents } 155 private method BuildPointsOnMesh { cname } 156 protected method GetAssociation { cname } 157 protected method GetTypeAndSize { cname } 158 protected method ReadVtkDataSet { cname contents } 159 private method InitHints {} 160 161 private method VerifyVtkDataSet { contents } 162 162 private method VectorLimits { vector vectorsize {comp -1} } 163 163 private variable _values "" … … 229 229 } 230 230 foreach name [array names _comp2mesh] { 231 232 233 231 # Data is in the form of a mesh and a vector. 232 foreach { mesh vector } $_comp2mesh($name) break 233 # Release the mesh (may be shared) 234 234 set class [$mesh info class] 235 235 ${class}::release $mesh 236 236 # Destroy the vector 237 237 blt::vector destroy $vector 238 238 } … … 285 285 # Now handle the tests. 286 286 switch -- $params(what) { 287 -name { 287 -name { 288 288 set rlist $components 289 289 } 290 -style { 290 -style { 291 291 foreach cname $components { 292 292 if { [info exists _comp2style($cname)] } { 293 lappend rlist $_comp2style($cname) 293 lappend rlist $_comp2style($cname) 294 294 } 295 295 } … … 314 314 } 315 315 if { [info exists _comp2vtk($cname)] } { 316 316 # FIXME: extract mesh from VTK file data. 317 317 if { $_comp2dims($cname) == "1D" } { 318 318 return $_xv … … 353 353 # VTK file data 354 354 if { [info exists _comp2vtk($cname)] } { 355 355 # FIXME: extract the values from the VTK file data 356 356 if { $_comp2dims($cname) == "1D" } { 357 357 return $_values … … 361 361 # Points-on-mesh 362 362 if { [info exists _comp2mesh($cname)] } { 363 363 set vector [lindex $_comp2mesh($cname) 1] 364 364 return [$vector range 0 end] 365 365 } … … 368 368 } 369 369 if {[info exists _comp2unirect2d($cname)]} { 370 return [$_comp2unirect2d($cname) values]370 return $_values 371 371 } 372 372 if {[info exists _comp2unirect3d($cname)]} { … … 389 389 } 390 390 if { [info exists _comp2vtk($cname)] } { 391 391 error "blob not implemented for VTK file data" 392 392 } 393 393 if {[info exists _comp2dx($cname)]} { … … 408 408 # USAGE: valueLimits <cname> 409 409 # 410 # Returns an array for the requested component with a list {min max} 410 # Returns an array for the requested component with a list {min max} 411 411 # representing the limits for each axis. 412 412 # ---------------------------------------------------------------------- … … 432 432 1D { 433 433 switch -- $which { 434 x - xlin { 435 set pos 0; set log 0; set axis x 436 437 xlog { 438 set pos 0; set log 1; set axis x 439 440 y - ylin - v - vlin { 441 set pos 1; set log 0; set axis y 442 443 ylog - vlog { 444 set pos 1; set log 1; set axis y 445 434 x - xlin { 435 set pos 0; set log 0; set axis x 436 } 437 xlog { 438 set pos 0; set log 1; set axis x 439 } 440 y - ylin - v - vlin { 441 set pos 1; set log 0; set axis y 442 } 443 ylog - vlog { 444 set pos 1; set log 1; set axis y 445 } 446 446 default { 447 447 error "bad axis \"$which\": should be x, xlin, xlog, y, ylin, ylog, v, vlin, vlog" … … 480 480 default { 481 481 if {[info exists _comp2limits($cname)]} { 482 array set limits $_comp2limits($cname) 483 482 array set limits $_comp2limits($cname) 483 switch -- $which { 484 484 x - xlin - xlog { 485 485 set axis x 486 486 foreach {axisMin axisMax} $limits(x) break 487 487 } 488 488 y - ylin - ylog { 489 489 set axis y 490 490 foreach {axisMin axisMax} $limits(y) break 491 491 } 492 492 z - zlin - zlog { 493 493 set axis z 494 494 foreach {axisMin axisMax} $limits(z) break 495 495 } 496 496 v - vlin - vlog { 497 497 set axis v 498 499 500 501 502 503 498 foreach {axisMin axisMax} $limits(v) break 499 } 500 default { 501 if { ![info exists limits($which)] } { 502 error "limits: unknown axis \"$which\"" 503 } 504 504 set axis v 505 506 507 505 foreach {axisMin axisMax} $limits($which) break 506 } 507 } 508 508 } else { 509 509 set axisMin 0 ;# HACK ALERT! must be OpenDX data … … 545 545 itcl::body Rappture::Field::fieldlimits {} { 546 546 foreach cname [array names _comp2limits] { 547 array set limits $_comp2limits($cname) 547 array set limits $_comp2limits($cname) 548 548 foreach fname [fieldnames $cname] { 549 549 if { ![info exists limits($fname)] } { … … 571 571 return "" 572 572 } 573 573 574 574 # ---------------------------------------------------------------------- 575 575 # USAGE: controls get ?<name>? … … 779 779 set type "" 780 780 if { ([$_field element $cname.constant] != "" && 781 782 781 [$_field element $cname.domain] != "") || 782 [$_field element $cname.xy] != "" } { 783 783 set type "1D" 784 784 } elseif { [$_field element $cname.mesh] != "" && 785 785 [$_field element $cname.values] != ""} { 786 786 set type "points-on-mesh" 787 787 } elseif { [$_field element $cname.vtk] != ""} { 788 789 790 791 792 788 set type "vtk" 789 set viewer [$_field get "about.view"] 790 if { $viewer != "" } { 791 set _viewer $viewer 792 } 793 793 } elseif {[$_field element $cname.opendx] != ""} { 794 794 global env 795 795 if { [info exists env(VTKVOLUME)] } { 796 796 set _viewer "vtkvolume" 797 } 797 } 798 798 set type "opendx" 799 799 } elseif {[$_field element $cname.dx] != ""} { … … 807 807 } elseif {[$_field element $cname.dicom] != ""} { 808 808 set type "dicom" 809 809 } 810 810 set _comp2style($cname) "" 811 811 if { $type == "" } { … … 817 817 set extents [$_field get $cname.extents] 818 818 } else { 819 set extents 1 819 set extents 1 820 820 } 821 821 set _comp2extents($cname) $extents … … 880 880 } 881 881 } elseif {$type == "points-on-mesh"} { 882 882 if { ![BuildPointsOnMesh $cname] } { 883 883 continue; # Ignore this component 884 884 } … … 981 981 return 0 982 982 } 983 # Sanity check. Verify that all components of the field have the same 983 # Sanity check. Verify that all components of the field have the same 984 984 # dimension. 985 985 set dim "" … … 998 998 # the label and units for each field will be specified there. 999 999 # 1000 # FIXME: Test that every <field><component> has the same field names, 1000 # FIXME: Test that every <field><component> has the same field names, 1001 1001 # units, components. 1002 1002 # … … 1070 1070 # isunirect2d -- 1071 1071 # 1072 # Returns if the field is a unirect2d object. 1072 # Returns if the field is a unirect2d object. 1073 1073 # 1074 1074 itcl::body Rappture::Field::isunirect2d { } { … … 1079 1079 # isunirect3d -- 1080 1080 # 1081 # Returns if the field is a unirect3d object. 1081 # Returns if the field is a unirect3d object. 1082 1082 # 1083 1083 itcl::body Rappture::Field::isunirect3d { } { … … 1088 1088 # flowhints -- 1089 1089 # 1090 # Returns the hints associated with a flow vector field. 1090 # Returns the hints associated with a flow vector field. 1091 1091 # 1092 1092 itcl::body Rappture::Field::flowhints { cname } { … … 1100 1100 # style -- 1101 1101 # 1102 # Returns the style associated with a component of the field. 1102 # Returns the style associated with a component of the field. 1103 1103 # 1104 1104 itcl::body Rappture::Field::style { cname } { … … 1137 1137 # extents -- 1138 1138 # 1139 # Returns if the field is a unirect2d object. 1139 # Returns if the field is a unirect2d object. 1140 1140 # 1141 1141 itcl::body Rappture::Field::extents {{cname -overall}} { … … 1153 1153 } 1154 1154 return $max 1155 } 1155 } 1156 1156 if { $cname == "component0"} { 1157 1157 set cname [lindex [components -name] 0] … … 1170 1170 set f [open "$tmpfile" "w"] 1171 1171 fconfigure $f -translation binary -encoding binary 1172 puts $f $contents 1172 puts $f $contents 1173 1173 close $f 1174 1174 … … 1187 1187 set dataAttrs [$dataset GetPointData] 1188 1188 if { $dataAttrs == ""} { 1189 1189 puts stderr "WARNING: No point data found in \"$_path\"" 1190 1190 rename $reader "" 1191 1191 return 0 … … 1204 1204 set f [open "$tmpfile" "w"] 1205 1205 fconfigure $f -translation binary -encoding binary 1206 puts $f $contents 1206 puts $f $contents 1207 1207 close $f 1208 1208 … … 1224 1224 set _dim 0 1225 1225 if { $xmax > $xmin } { 1226 1226 incr _dim 1227 1227 } 1228 1228 if { $ymax > $ymin } { 1229 1229 incr _dim 1230 1230 } 1231 1231 if { $zmax > $zmin } { 1232 1232 incr _dim 1233 1233 } 1234 1234 if { $_viewer == "" } { 1235 1236 1237 1238 1239 1235 if { $_dim == 2 } { 1236 set _viewer contour 1237 } else { 1238 set _viewer isosurface 1239 } 1240 1240 } 1241 1241 set _comp2dims($cname) ${_dim}D … … 1245 1245 for { set i 0 } { $i < $numPoints } { incr i } { 1246 1246 set point [$dataset GetPoint $i] 1247 $xv append [lindex $point 0] 1247 $xv append [lindex $point 0] 1248 1248 } 1249 1249 set yv [blt::vector create \#auto] … … 1262 1262 set numTuples [$array GetNumberOfTuples] 1263 1263 for { set i 0 } { $i < $numTuples } { incr i } { 1264 $yv append [$array GetComponent $i 0] 1264 $yv append [$array GetComponent $i 0] 1265 1265 } 1266 1266 $xv sort $yv 1267 1267 set _comp2xy($cname) [list $xv $yv] 1268 1268 } 1269 lappend limits x [list $xmin $xmax] 1270 lappend limits y [list $ymin $ymax] 1269 lappend limits x [list $xmin $xmax] 1270 lappend limits y [list $ymin $ymax] 1271 1271 lappend limits z [list $zmin $zmax] 1272 1272 set dataAttrs [$dataset GetPointData] 1273 1273 if { $dataAttrs == ""} { 1274 1274 puts stderr "WARNING: No point data found in \"$_path\"" 1275 1275 rename $reader "" 1276 1276 return 0 … … 1280 1280 set numArrays [$dataAttrs GetNumberOfArrays] 1281 1281 if { $numArrays > 0 } { 1282 1283 1284 1285 1282 for {set i 0} {$i < [$dataAttrs GetNumberOfArrays] } {incr i} { 1283 set array [$dataAttrs GetArray $i] 1284 set fname [$dataAttrs GetArrayName $i] 1285 foreach {min max} [$array GetRange -1] break 1286 1286 if {$i == 0} { 1287 1287 set vmin $min 1288 1288 set vmax $max 1289 1289 } 1290 1290 lappend limits $fname [list $min $max] 1291 1291 set _fld2Units($fname) "" 1292 1292 set _fld2Label($fname) $fname 1293 1293 # Let the VTK file override the <type> designated. 1294 1294 set _fld2Components($fname) [$array GetNumberOfComponents] 1295 1295 lappend _comp2fldName($cname) $fname 1296 1297 } 1298 1296 } 1297 } 1298 1299 1299 lappend limits v [list $vmin $vmax] 1300 1300 set _comp2limits($cname) $limits … … 1306 1306 # vtkdata -- 1307 1307 # 1308 # 1309 # 1308 # Returns a string representing the mesh and field data for a specific 1309 # component in the legacy VTK file format. 1310 1310 # 1311 1311 itcl::body Rappture::Field::vtkdata {cname} { … … 1313 1313 set cname "component" 1314 1314 } 1315 # DX: Convert DX to VTK 1315 # DX: Convert DX to VTK 1316 1316 if {[info exists _comp2dx($cname)]} { 1317 1317 set data $_comp2dx($cname) … … 1319 1319 return [Rappture::DxToVtk $data] 1320 1320 } 1321 # Unirect3d: isosurface 1321 # Unirect3d: isosurface 1322 1322 if {[info exists _comp2unirect3d($cname)]} { 1323 1323 return [$_comp2unirect3d($cname) vtkdata] 1324 1324 } 1325 # VTK file data: 1325 # VTK file data: 1326 1326 if { [info exists _comp2vtk($cname)] } { 1327 1327 return $_comp2vtk($cname) … … 1329 1329 # Points on mesh: Construct VTK file output. 1330 1330 if { [info exists _comp2mesh($cname)] } { 1331 1332 1331 # Data is in the form mesh and vector 1332 foreach {mesh vector} $_comp2mesh($cname) break 1333 1333 set label $cname 1334 1334 regsub -all { } $label {_} label 1335 1336 1337 1338 1335 append out "# vtk DataFile Version 3.0\n" 1336 append out "[hints label]\n" 1337 append out "ASCII\n" 1338 append out [$mesh vtkdata] 1339 1339 1340 1340 if { $_comp2assoc($cname) == "pointdata" } { … … 1377 1377 } 1378 1378 } 1379 append out [$vector range 0 end] 1379 append out [$vector range 0 end] 1380 1380 append out "\n" 1381 1381 if 0 { 1382 1382 VerifyVtkDataSet $out 1383 1383 } 1384 1384 return $out 1385 1385 } 1386 1386 error "can't find vtkdata for $cname. This method should only be called by the vtkheightmap widget" … … 1390 1390 # BuildPointsOnMesh -- 1391 1391 # 1392 # 1393 # 1394 # 1392 # Parses the field XML description to build a mesh and values vector 1393 # representing the field. Right now we handle the deprecated types 1394 # of "cloud", "unirect2d", and "unirect3d" (mostly for flows). 1395 1395 # 1396 1396 itcl::body Rappture::Field::BuildPointsOnMesh {cname} { … … 1401 1401 set path [$_field get $cname.mesh] 1402 1402 if {[$_xmlobj element $path] == ""} { 1403 1404 1403 # Unknown mesh designated. 1404 return 0 1405 1405 } 1406 1406 set viewer [$_field get "about.view"] … … 1422 1422 # Handle bizarre cases that hopefully will be deprecated. 1423 1423 if { $element == "unirect3d" } { 1424 1424 # Special case: unirect3d (should be deprecated) + flow. 1425 1425 if { [$_field element $cname.extents] != "" } { 1426 1426 set vectorsize [$_field get $cname.extents] 1427 1427 } else { 1428 set vectorsize 1 1428 set vectorsize 1 1429 1429 } 1430 1430 set _type unirect3d 1431 1431 set _dim 3 1432 1432 if { $_viewer == "" } { 1433 1433 set _viewer flowvis 1434 1434 } 1435 1436 1437 1438 1435 set _comp2dims($cname) "3D" 1436 set _comp2unirect3d($cname) \ 1437 [Rappture::Unirect3d \#auto $_xmlobj $_field $cname $vectorsize] 1438 set _comp2style($cname) [$_field get $cname.style] 1439 1439 set limits {} 1440 1440 foreach axis { x y z } { 1441 1441 lappend limits $axis [$_comp2unirect3d($cname) limits $axis] 1442 1442 } 1443 # Get the data limits 1443 # Get the data limits 1444 1444 set vector [$_comp2unirect3d($cname) valuesObj] 1445 1445 set minmax [VectorLimits $vector $vectorsize] … … 1447 1447 lappend limits v $minmax 1448 1448 set _comp2limits($cname) $limits 1449 1450 1451 1452 1453 1454 1449 if {[$_field element $cname.flow] != ""} { 1450 set _comp2flowhints($cname) \ 1451 [Rappture::FlowHints ::\#auto $_field $cname $_units] 1452 } 1453 incr _counter 1454 return 1 1455 1455 } 1456 1456 if { $element == "unirect2d" && [$_field element $cname.flow] != "" } { 1457 1457 # Special case: unirect2d (normally deprecated) + flow. 1458 1458 if { [$_field element $cname.extents] != "" } { 1459 1459 set vectorsize [$_field get $cname.extents] 1460 1460 } else { 1461 set vectorsize 1 1461 set vectorsize 1 1462 1462 } 1463 1463 set _type unirect2d 1464 1464 set _dim 2 1465 1465 if { $_viewer == "" } { 1466 1466 set _viewer "flowvis" 1467 1467 } 1468 1469 1470 1471 1472 1473 1474 1468 set _comp2dims($cname) "2D" 1469 set _comp2unirect2d($cname) \ 1470 [Rappture::Unirect2d \#auto $_xmlobj $path] 1471 set _comp2style($cname) [$_field get $cname.style] 1472 set _comp2flowhints($cname) \ 1473 [Rappture::FlowHints ::\#auto $_field $cname $_units] 1474 set _values [$_field get $cname.values] 1475 1475 set limits {} 1476 1476 foreach axis { x y z } { … … 1484 1484 blt::vector destroy $xv 1485 1485 set _comp2limits($cname) $limits 1486 1487 1486 incr _counter 1487 return 1 1488 1488 } 1489 1489 switch -- $element { 1490 1491 1490 "cloud" { 1491 set mesh [Rappture::Cloud::fetch $_xmlobj $path] 1492 1492 set _type cloud 1493 1494 1495 1493 } 1494 "mesh" { 1495 set mesh [Rappture::Mesh::fetch $_xmlobj $path] 1496 1496 set _type mesh 1497 } 1498 1497 } 1498 "unirect2d" { 1499 1499 if { $_viewer == "" } { 1500 1500 set _viewer "heightmap" 1501 1501 } 1502 1502 set mesh [Rappture::Unirect2d::fetch $_xmlobj $path] 1503 1503 set _type unirect2d 1504 1504 } 1505 1505 } 1506 1506 if { ![$mesh isvalid] } { … … 1510 1510 set _dim [$mesh dimensions] 1511 1511 if { $_dim == 3 } { 1512 set dim 0 1512 set dim 0 1513 1513 foreach axis {x y z} { 1514 1514 foreach {min max} [$mesh limits $axis] { … … 1523 1523 } 1524 1524 1525 if {$_dim == 1} { 1526 # 1D data: Create vectors for graph widget. 1527 # Is this used anywhere? 1528 # 1529 # OOPS! This is 1D data 1530 # Forget the cloud/field -- store BLT vectors 1531 # 1532 # Is there a natural growth path in generating output from 1D to 1533 # higher dimensions? If there isn't, let's kill this in favor 1534 # or explicitly using a <curve> instead. Otherwise, the features 1535 # (methods such as xmarkers) or the <curve> need to be added 1536 # to the <field>. 1537 # 1538 set xv [blt::vector create x$_counter] 1539 set yv [blt::vector create y$_counter] 1540 1541 $yv set [$mesh points] 1542 $xv seq 0 1 [$yv length] 1543 # sort x-coords in increasing order 1544 $xv sort $yv 1545 set _comp2dims($cname) "1D" 1546 set _comp2xy($cname) [list $xv $yv] 1547 incr _counter 1548 return 1 1549 } 1525 if {$_dim < 2} { 1526 puts stderr "ERROR: Can't convert 1D cloud/mesh to curve. Please use curve output for 1D meshes." 1527 return 0 1528 1529 # 1D data: Create vectors for graph widget. 1530 # The prophet tool currently outputs 1D clouds with fields 1531 # Band Structure Lab used to (see isosurface1 test in rappture-bat) 1532 # 1533 # Is there a natural growth path in generating output from 1D to 1534 # higher dimensions? If there isn't, let's kill this in favor 1535 # or explicitly using a <curve> instead. Otherwise, the features 1536 # (methods such as xmarkers) or the <curve> need to be added 1537 # to the <field>. 1538 # 1539 #set xv [blt::vector create x$_counter] 1540 #set yv [blt::vector create y$_counter] 1541 1542 # This only works with a Cloud mesh type, since the points method 1543 # is not implemented for the Mesh object 1544 #$xv set [$mesh points] 1545 # TODO: Put field values in yv 1546 #set _comp2dims($cname) "1D" 1547 #set _comp2xy($cname) [list $xv $yv] 1548 #incr _counter 1549 #return 1 1550 } 1550 1551 if {$_dim == 2} { 1551 1552 1553 1552 # 2D data: By default surface or contour plot using heightmap widget. 1553 set v [blt::vector create \#auto] 1554 $v set [$_field get $cname.values] 1554 1555 if { [$v length] == 0 } { 1555 1556 return 0 … … 1578 1579 } 1579 1580 } 1580 1581 1582 1581 set _comp2dims($cname) "[$mesh dimensions]D" 1582 set _comp2mesh($cname) [list $mesh $v] 1583 set _comp2style($cname) [$_field get $cname.style] 1583 1584 if {[$_field element $cname.flow] != ""} { 1584 1585 set _comp2flowhints($cname) \ 1585 1586 [Rappture::FlowHints ::\#auto $_field $cname $_units] 1586 1587 } 1587 1588 1588 incr _counter 1589 array unset _comp2limits $cname 1589 1590 foreach axis { x y z } { 1590 1591 lappend _comp2limits($cname) $axis [$mesh limits $axis] … … 1593 1594 lappend _comp2limits($cname) $cname $minmax 1594 1595 lappend _comp2limits($cname) v $minmax 1595 1596 } 1596 return 1 1597 } 1597 1598 if {$_dim == 3} { 1598 1599 # 3D data: By default isosurfaces plot using isosurface widget. 1599 1600 if { $_viewer == "" } { 1600 1601 set _viewer "isosurface" 1601 1602 } 1602 1603 1603 set v [blt::vector create \#auto] 1604 $v set [$_field get $cname.values] 1604 1605 if { [$v length] == 0 } { 1605 1606 return 0 … … 1639 1640 lappend _comp2limits($cname) $cname $minmax 1640 1641 lappend _comp2limits($cname) v $minmax 1641 1642 return 1 1642 1643 } 1643 1644 error "unhandled case in field dim=$_dim element=$element" … … 1731 1732 "tcoords" 2 1732 1733 "tensors" 9 1733 "vectors" 3 1734 "vectors" 3 1734 1735 } 1735 1736 set type [$_field get $cname.elemtype] 1736 1737 if { $type == "" } { 1737 1738 set type "scalars" 1738 } 1739 } 1739 1740 if { ![info exists type2components($type)] } { 1740 1741 error "unknown <elemtype> \"$type\" in field" … … 1753 1754 set _comp2assoc($cname) "pointdata" 1754 1755 return 1755 } 1756 } 1756 1757 switch -- $assoc { 1757 1758 "pointdata" - "celldata" - "fielddata" { -
branches/uq/gui/scripts/flowvisviewer.tcl
r4797 r5121 44 44 itk_option define -plotoutline plotOutline PlotOutline "" 45 45 46 private variable _volcomponents ; # Array of components found47 private variable _componentsList ; # Array of components found48 private method BuildVolumeComponents {}49 private method GetDatasetsWithComponent { cname }50 51 46 constructor { hostlist args } { 52 47 Rappture::VisViewer::constructor $hostlist … … 68 63 public method get {args} 69 64 public method isconnected {} 70 public method limits { cname}71 public method over Marker { m x }65 public method limits { tf } 66 public method overmarker { m x } 72 67 public method parameters {title args} { 73 68 # do nothing 74 69 } 75 public method r emoveDuplicateMarker { m x }70 public method rmdupmarker { m x } 76 71 public method scale {args} 77 public method update TransferFunctions {}72 public method updatetransferfuncs {} 78 73 79 74 protected method Connect {} … … 90 85 protected method ReceiveLegend { tf vmin vmax size } 91 86 protected method Rotate {option x y} 87 protected method SendDataObjs {} 92 88 protected method SendTransferFuncs {} 93 89 protected method Slice {option args} … … 135 131 private variable _serverObjs ;# maps dataobj-component to volume ID 136 132 # in the server 133 private variable _sendobjs "" ;# list of data objs to send to server 137 134 private variable _recvObjs ;# list of data objs to send to server 138 135 private variable _obj2style ;# maps dataobj-component to transfunc … … 181 178 $_dispatcher dispatch $this !legend "[itcl::code $this ResizeLegend]; list" 182 179 180 # Send dataobjs event 181 $_dispatcher register !send_dataobjs 182 $_dispatcher dispatch $this !send_dataobjs \ 183 "[itcl::code $this SendDataObjs]; list" 184 183 185 # Send transferfunctions event 184 186 $_dispatcher register !send_transfunc … … 230 232 $_arcball quaternion $q 231 233 232 set _limits(v) [list 0.0 1.0] 234 set _limits(vmin) 0.0 235 set _limits(vmax) 1.0 233 236 set _reset 1 234 237 … … 332 335 set _image(legend) [image create photo] 333 336 itk_component add legend { 334 canvas $itk_component(plotarea).legend -height 50 -highlightthickness 0 337 canvas $itk_component(plotarea).legend \ 338 -height 50 -highlightthickness 0 -background black 335 339 } { 336 340 usual … … 556 560 # ---------------------------------------------------------------------- 557 561 itcl::body Rappture::FlowvisViewer::destructor {} { 562 set _sendobjs "" ;# stop any send in progress 558 563 $_dispatcher cancel !rebuild 564 $_dispatcher cancel !send_dataobjs 559 565 $_dispatcher cancel !send_transfunc 560 566 image delete $_image(plot) … … 666 672 # ---------------------------------------------------------------------- 667 673 itcl::body Rappture::FlowvisViewer::delete {args} { 668 flow stop674 flow stop 669 675 if {[llength $args] == 0} { 670 676 set args $_dlist … … 716 722 # ---------------------------------------------------------------------- 717 723 itcl::body Rappture::FlowvisViewer::scale {args} { 718 array set styles { 719 -color BCGYR 720 -levels 6 721 -markers "" 722 -opacity 1.0 723 } 724 array unset _limits 725 array unset _volcomponents 726 foreach dataobj $args { 727 if { ![$dataobj isvalid] } { 728 continue; # Object doesn't contain valid data. 729 } 730 foreach cname [$dataobj components] { 731 if { ![info exists _volcomponents($cname)] } { 732 lappend _componentsList $cname 733 array set styles [lindex [$dataobj components -style $cname] 0] 734 set cmap [ColorsToColormap $styles(-color)] 735 set _cname2defaultcolormap($cname) $cmap 736 set _settings($cname-colormap) $styles(-color) 737 } 738 lappend _volcomponents($cname) $dataobj-$cname 739 array unset limits 740 array set limits [$dataobj valueLimits $cname] 741 set _limits($cname) $limits(v) 742 } 743 foreach axis {x y z v} { 744 foreach { min max } [$dataobj limits $axis] break 724 foreach val {xmin xmax ymin ymax vmin vmax} { 725 set _limits($val) "" 726 } 727 foreach obj $args { 728 foreach axis {x y v} { 729 730 foreach { min max } [$obj limits $axis] break 731 745 732 if {"" != $min && "" != $max} { 746 if { ![info exists _limits($axis)] } { 747 set _limits($axis) [list $min $max] 733 if {"" == $_limits(${axis}min)} { 734 set _limits(${axis}min) $min 735 set _limits(${axis}max) $max 748 736 } else { 749 foreach {amin amax} $_limits($axis) break 750 if {$min < $amin} { 751 set amin $min 737 if {$min < $_limits(${axis}min)} { 738 set _limits(${axis}min) $min 752 739 } 753 if {$max > $ amax} {754 set amax$max740 if {$max > $_limits(${axis}max)} { 741 set _limits(${axis}max) $max 755 742 } 756 set _limits($axis) [list $amin $amax]757 743 } 758 744 } 759 745 } 760 746 } 761 #BuildVolumeComponents762 747 } 763 748 … … 872 857 if { $_reportClientInfo } { 873 858 # Tell the server the viewer, hub, user and session. 874 # Do this immediately on connect before buff ering any commands859 # Do this immediately on connect before buffing any commands 875 860 global env 876 861 … … 929 914 # disconnected -- no more data sitting on server 930 915 array unset _serverObjs 916 set _sendobjs "" 917 } 918 919 # ---------------------------------------------------------------------- 920 # USAGE: SendDataObjs 921 # 922 # Used internally to send a series of volume objects off to the 923 # server. Sends each object, a little at a time, with updates in 924 # between so the interface doesn't lock up. 925 # ---------------------------------------------------------------------- 926 itcl::body Rappture::FlowvisViewer::SendDataObjs {} { 927 blt::busy hold $itk_component(hull) 928 foreach dataobj $_sendobjs { 929 foreach comp [$dataobj components] { 930 # Send the data as one huge base64-encoded mess -- yuck! 931 set data [$dataobj blob $comp] 932 set nbytes [string length $data] 933 set extents [$dataobj extents $comp] 934 935 # I have a field. Is a vector field or a volume field? 936 if { $extents == 1 } { 937 set cmd "volume data follows $nbytes $dataobj-$comp\n" 938 } else { 939 set cmd [FlowCmd $dataobj $comp $nbytes $extents] 940 if { $cmd == "" } { 941 puts stderr "no command" 942 continue 943 } 944 } 945 f { ![SendBytes $cmd] } { 946 puts stderr "can't send" 947 return 948 } 949 if { ![SendBytes $data] } { 950 puts stderr "can't send" 951 return 952 } 953 NameTransferFunc $dataobj $comp 954 set _recvObjs($dataobj-$comp) 1 955 } 956 } 957 set _sendobjs "" 958 blt::busy release $itk_component(hull) 959 960 # Turn on buffering of commands to the server. We don't want to 961 # be preempted by a server disconnect/reconnect (which automatically 962 # generates a new call to Rebuild). 963 StartBufferingCommands 964 965 # activate the proper volume 966 set _first [lindex [get] 0] 967 if { "" != $_first } { 968 set axis [$_first hints updir] 969 if {"" != $axis} { 970 SendCmd "up $axis" 971 } 972 973 if 0 { 974 set location [$_first hints camera] 975 if { $location != "" } { 976 array set _view $location 977 } 978 set _settings($this-qw) $_view(qw) 979 set _settings($this-qx) $_view(qx) 980 set _settings($this-qy) $_view(qy) 981 set _settings($this-qz) $_view(qz) 982 set _settings($this-xpan) $_view(xpan) 983 set _settings($this-ypan) $_view(ypan) 984 set _settings($this-zoom) $_view(zoom) 985 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 986 $_arcball quaternion $q 987 SendCmd "camera orient $q" 988 SendCmd "camera reset" 989 PanCamera 990 SendCmd "camera zoom $_view(zoom)" 991 } 992 # The active transfer function is by default the first component of 993 # the first data object. This assumes that the data is always 994 # successfully transferred. 995 set comp [lindex [$_first components] 0] 996 set _activeTf [lindex $_obj2style($_first-$comp) 0] 997 } 998 999 SendCmd "flow reset" 1000 StopBufferingCommands 931 1001 } 932 1002 … … 1027 1097 set h [winfo height $c] 1028 1098 set lx 10 1099 # FIXME: I don't know what I have to do this for the 2D flow 1100 # example. Otherwise the canvas background is white. 1101 # I'll get to this when we add background changes into 1102 # nanvis. 1103 $c configure -background black 1029 1104 set ly [expr {$h - 1}] 1030 if {"" == [$c find withtag colorbar]} {1105 if {"" == [$c find withtag transfunc]} { 1031 1106 $c create image 10 10 -anchor nw \ 1032 -image $_image(legend) -tags colorbar1107 -image $_image(legend) -tags transfunc 1033 1108 $c create text $lx $ly -anchor sw \ 1034 1109 -fill $itk_option(-plotforeground) -tags "limits vmin" 1035 1110 $c create text [expr {$w-$lx}] $ly -anchor se \ 1036 1111 -fill $itk_option(-plotforeground) -tags "limits vmax" 1037 $c lower colorbar 1038 $c bind colorbar <ButtonRelease-1> [itcl::code $this AddIsoMarker %x %y] 1112 $c lower transfunc 1113 $c bind transfunc <ButtonRelease-1> \ 1114 [itcl::code $this AddIsoMarker %x %y] 1039 1115 } 1040 1116 # Display the markers used by the active transfer function. 1041 1117 set tf $_obj2style($tag) 1042 foreach {vmin vmax} [limits $tf] break1043 $c itemconfigure vmin -text [format % g $vmin]1118 array set limits [limits $tf] 1119 $c itemconfigure vmin -text [format %.2g $limits(vmin)] 1044 1120 $c coords vmin $lx $ly 1045 1121 1046 $c itemconfigure vmax -text [format % g $vmax]1122 $c itemconfigure vmax -text [format %.2g $limits(vmax)] 1047 1123 $c coords vmax [expr {$w-$lx}] $ly 1048 1124 … … 1084 1160 set dataobj [lindex $parts 0] 1085 1161 set _serverObjs($tag) 0 1086 set _limits($tag) [list $values(min) $values(max)] 1162 set _limits($tag-min) $values(min); # Minimum value of the volume. 1163 set _limits($tag-max) $values(max); # Maximum value of the volume. 1087 1164 unset _recvObjs($tag) 1088 1165 if { [array size _recvObjs] == 0 } { 1089 update TransferFunctions1166 updatetransferfuncs 1090 1167 } 1091 1168 } … … 1131 1208 foreach comp [$dataobj components] { 1132 1209 set tag $dataobj-$comp 1133 set isvtk 0 1134 # FIXME: Would like to use the type method of the dataobj 1135 # but the returned value isn't well defined now 1136 if {[catch { 1137 # Send the data as one huge base64-encoded mess -- yuck! 1138 set data [$dataobj blob $comp] 1139 }]} { 1140 set data [$dataobj vtkdata $comp] 1141 set isvtk 1 1142 } 1210 # Send the data as one huge base64-encoded mess -- yuck! 1211 set data [$dataobj blob $comp] 1143 1212 set nbytes [string length $data] 1144 1213 if { $_reportClientInfo } { 1145 1214 set info {} 1146 lappend info "tool_id" [$dataobj hints toolId] 1147 lappend info "tool_name" [$dataobj hints toolName] 1148 lappend info "tool_version" [$dataobj hints toolRevision] 1149 lappend info "tool_title" [$dataobj hints toolTitle] 1215 lappend info "tool_id" [$dataobj hints toolid] 1216 lappend info "tool_name" [$dataobj hints toolname] 1217 lappend info "tool_title" [$dataobj hints tooltitle] 1218 lappend info "tool_command" [$dataobj hints toolcommand] 1219 lappend info "tool_revision" [$dataobj hints toolrevision] 1150 1220 lappend info "dataset_label" [$dataobj hints label] 1151 1221 lappend info "dataset_size" $nbytes … … 1155 1225 set extents [$dataobj extents $comp] 1156 1226 # I have a field. Is a vector field or a volume field? 1157 if { !$isvtk &&$extents == 1 } {1227 if { $extents == 1 } { 1158 1228 set cmd "volume data follows $nbytes $tag\n" 1159 1229 } else { … … 1259 1329 foreach key [array names _serverObjs *-*] { 1260 1330 if {[string match $_first-* $key]} { 1261 array set style s{1331 array set style { 1262 1332 -cutplanes 1 1263 1333 } 1264 1334 foreach {dataobj comp} [split $key -] break 1265 array set style s[lindex [$dataobj components -style $comp] 0]1266 if {$what != "-cutplanes" || $style s(-cutplanes)} {1335 array set style [lindex [$dataobj components -style $comp] 0] 1336 if {$what != "-cutplanes" || $style(-cutplanes)} { 1267 1337 lappend rlist $_serverObjs($key) 1268 1338 } … … 1324 1394 1325 1395 itcl::body Rappture::FlowvisViewer::PanCamera {} { 1396 #set x [expr ($_view(xpan)) / $_limits(xrange)] 1397 #set y [expr ($_view(ypan)) / $_limits(yrange)] 1326 1398 set x $_view(xpan) 1327 1399 set y $_view(ypan) … … 1587 1659 set tf $_activeTf 1588 1660 set _settings($this-$tf-opacity) $opacity 1589 update TransferFunctions1661 updatetransferfuncs 1590 1662 } 1591 1663 } … … 1598 1670 set tf $_activeTf 1599 1671 set _settings($this-$tf-thickness) $sval 1600 update TransferFunctions1672 updatetransferfuncs 1601 1673 } 1602 1674 } … … 1706 1778 # now. 1707 1779 # 1708 itcl::body Rappture::FlowvisViewer::NameTransferFunc { dataobj c name} {1709 array set style s{1780 itcl::body Rappture::FlowvisViewer::NameTransferFunc { dataobj comp } { 1781 array set style { 1710 1782 -color BCGYR 1711 1783 -levels 6 1784 -opacity 1.0 1712 1785 -light 40 1713 -opacity 1.01714 1786 -transp 50 1715 1787 } 1716 array set styles [lindex [$dataobj components -style $cname] 0] 1717 set _settings($this-light) $styles(-light) 1718 set _settings($this-transp) $styles(-transp) 1719 set _settings($this-opacity) [expr $styles(-opacity) * 100] 1720 set _obj2style($dataobj-$cname) $cname 1721 lappend _style2objs($cname) $dataobj $cname 1722 return $cname 1788 array set style [lindex [$dataobj components -style $comp] 0] 1789 set _settings($this-light) $style(-light) 1790 set _settings($this-transp) $style(-transp) 1791 set _settings($this-opacity) [expr $style(-opacity) * 100] 1792 set tf "$style(-color):$style(-levels):$style(-opacity)" 1793 set _obj2style($dataobj-$comp) $tf 1794 lappend _style2objs($tf) $dataobj $comp 1795 return $tf 1723 1796 } 1724 1797 … … 1733 1806 # 1734 1807 itcl::body Rappture::FlowvisViewer::ComputeTransferFunc { tf } { 1735 array set style s{1808 array set style { 1736 1809 -color BCGYR 1737 1810 -levels 6 … … 1745 1818 return 0 1746 1819 } 1747 array set style s[lindex [$dataobj components -style $comp] 0]1820 array set style [lindex [$dataobj components -style $comp] 0] 1748 1821 1749 1822 … … 1763 1836 if { ![info exists _isomarkers($tf)] } { 1764 1837 # Have to defer creation of isomarkers until we have data limits 1765 if { [info exists style s(-markers)] &&1766 [llength $style s(-markers)] > 0 } {1767 ParseMarkersOption $tf $style s(-markers)1838 if { [info exists style(-markers)] && 1839 [llength $style(-markers)] > 0 } { 1840 ParseMarkersOption $tf $style(-markers) 1768 1841 } else { 1769 ParseLevelsOption $tf $style s(-levels)1770 } 1771 } 1772 if { [info exists style s(-nonuniformcolors)] } {1773 foreach { value color } $style s(-nonuniformcolors) {1842 ParseLevelsOption $tf $style(-levels) 1843 } 1844 } 1845 if { [info exists style(-nonuniformcolors)] } { 1846 foreach { value color } $style(-nonuniformcolors) { 1774 1847 append cmap "$value [Color2RGB $color] " 1775 1848 } 1776 1849 } else { 1777 set cmap [ColorsToColormap $style s(-color)]1850 set cmap [ColorsToColormap $style(-color)] 1778 1851 } 1779 1852 set tag $this-$tf 1780 1853 if { ![info exists _settings($tag-opacity)] } { 1781 set _settings($tag-opacity) $style s(-opacity)1854 set _settings($tag-opacity) $style(-opacity) 1782 1855 } 1783 1856 set max 1.0 ;#$_settings($tag-opacity) … … 1844 1917 itcl::configbody Rappture::FlowvisViewer::plotbackground { 1845 1918 if { [isconnected] } { 1846 set color $itk_option(-plotbackground) 1847 set rgb [Color2RGB $color] 1848 SendCmd "screen bgcolor $rgb" 1849 $itk_component(legend) configure -background $color 1919 foreach {r g b} [Color2RGB $itk_option(-plotbackground)] break 1920 #fix this! 1921 #SendCmd "color background $r $g $b" 1850 1922 } 1851 1923 } … … 1856 1928 itcl::configbody Rappture::FlowvisViewer::plotforeground { 1857 1929 if { [isconnected] } { 1858 set color $itk_option(-plotforeground) 1859 set rgb [Color2RGB $color] 1860 SendCmd "volume outline color $rgb" 1861 SendCmd "grid axiscolor $rgb" 1862 SendCmd "grid linecolor $rgb" 1863 $itk_component(legend) itemconfigure labels -fill $color 1864 $itk_component(legend) itemconfigure limits -fill $color 1930 foreach {r g b} [Color2RGB $itk_option(-plotforeground)] break 1931 #fix this! 1932 #SendCmd "color background $r $g $b" 1865 1933 } 1866 1934 } … … 1896 1964 set x [expr {double($i)/($levels+1)}] 1897 1965 set m [Rappture::IsoMarker \#auto $c $this $tf] 1898 $itk_component(legend) itemconfigure labels -fill $itk_option(-plotforeground)1899 1966 $m relval $x 1900 1967 lappend _isomarkers($tf) $m … … 1903 1970 foreach x $levels { 1904 1971 set m [Rappture::IsoMarker \#auto $c $this $tf] 1905 $itk_component(legend) itemconfigure labels -fill $itk_option(-plotforeground)1906 1972 $m relval $x 1907 1973 lappend _isomarkers($tf) $m … … 1931 1997 set value [expr {$value * 0.01}] 1932 1998 set m [Rappture::IsoMarker \#auto $c $this $tf] 1933 $itk_component(legend) itemconfigure labels -fill $itk_option(-plotforeground)1934 1999 $m relval $value 1935 2000 lappend _isomarkers($tf) $m … … 1937 2002 # ${n} : Set absolute value. 1938 2003 set m [Rappture::IsoMarker \#auto $c $this $tf] 1939 $itk_component(legend) itemconfigure labels -fill $itk_option(-plotforeground)1940 2004 $m absval $value 1941 2005 lappend _isomarkers($tf) $m … … 1947 2011 # USAGE: UndateTransferFuncs 1948 2012 # ---------------------------------------------------------------------- 1949 itcl::body Rappture::FlowvisViewer::update TransferFunctions {} {2013 itcl::body Rappture::FlowvisViewer::updatetransferfuncs {} { 1950 2014 $_dispatcher event -after 100 !send_transfunc 1951 2015 } … … 1958 2022 set c $itk_component(legend) 1959 2023 set m [Rappture::IsoMarker \#auto $c $this $tf] 1960 $itk_component(legend) itemconfigure labels -fill $itk_option(-plotforeground)1961 2024 set w [winfo width $c] 1962 2025 $m relval [expr {double($x-10)/($w-20)}] 1963 2026 lappend _isomarkers($tf) $m 1964 update TransferFunctions2027 updatetransferfuncs 1965 2028 return 1 1966 2029 } 1967 2030 1968 itcl::body Rappture::FlowvisViewer::r emoveDuplicateMarker { marker x } {2031 itcl::body Rappture::FlowvisViewer::rmdupmarker { marker x } { 1969 2032 set tf [$marker transferfunc] 1970 2033 set bool 0 … … 1986 2049 } 1987 2050 set _isomarkers($tf) $list 1988 update TransferFunctions2051 updatetransferfuncs 1989 2052 } 1990 2053 return $bool 1991 2054 } 1992 2055 1993 itcl::body Rappture::FlowvisViewer::over Marker { marker x } {2056 itcl::body Rappture::FlowvisViewer::overmarker { marker x } { 1994 2057 set tf [$marker transferfunc] 1995 2058 if { [info exists _isomarkers($tf)] } { … … 2006 2069 } 2007 2070 2008 itcl::body Rappture::FlowvisViewer::limits { cname } { 2009 set _limits(v) [list 0.0 1.0] 2010 if { ![info exists _style2objs($cname)] } { 2011 puts stderr "no style2objs for $cname cname=($cname)" 2071 itcl::body Rappture::FlowvisViewer::limits { tf } { 2072 set _limits(vmin) 0.0 2073 set _limits(vmax) 1.0 2074 if { ![info exists _style2objs($tf)] } { 2075 puts stderr "no style2objs for $tf tf=($tf)" 2012 2076 return [array get _limits] 2013 2077 } 2014 2078 set min ""; set max "" 2015 foreach tag [GetDatasetsWithComponent $cname] { 2079 foreach {dataobj comp} $_style2objs($tf) { 2080 set tag $dataobj-$comp 2016 2081 if { ![info exists _serverObjs($tag)] } { 2017 2082 puts stderr "$tag not in serverObjs?" 2018 2083 continue 2019 2084 } 2020 if { ![info exists _limits($tag )] } {2085 if { ![info exists _limits($tag-min)] } { 2021 2086 puts stderr "$tag no min?" 2022 2087 continue 2023 2088 } 2024 foreach {vmin vmax} $_limits($tag) break 2025 if { $min == "" || $min > $vmin } { 2026 set min $vmin 2027 } 2028 if { $max == "" || $max < $vmax } { 2029 set max $vmax 2030 } 2031 } 2032 if { $min != "" && $max != "" } { 2033 set _limits(v) [list $min $max] 2034 set _limits($cname) [list $min $max] 2035 } 2036 return $_limits($cname) 2089 if { $min == "" || $min > $_limits($tag-min) } { 2090 set min $_limits($tag-min) 2091 } 2092 if { $max == "" || $max < $_limits($tag-max) } { 2093 set max $_limits($tag-max) 2094 } 2095 } 2096 if { $min != "" } { 2097 set _limits(vmin) $min 2098 } 2099 if { $max != "" } { 2100 set _limits(vmax) $max 2101 } 2102 return [array get _limits] 2037 2103 } 2038 2104 … … 2186 2252 } 2187 2253 2188 $inner.colormap choices insert end [GetColormapList -includeNone] 2254 $inner.colormap choices insert end \ 2255 "BCGYR" "BCGYR" \ 2256 "BGYOR" "BGYOR" \ 2257 "blue" "blue" \ 2258 "blue-to-brown" "blue-to-brown" \ 2259 "blue-to-orange" "blue-to-orange" \ 2260 "blue-to-grey" "blue-to-grey" \ 2261 "green-to-magenta" "green-to-magenta" \ 2262 "greyscale" "greyscale" \ 2263 "nanohub" "nanohub" \ 2264 "rainbow" "rainbow" \ 2265 "spectral" "spectral" \ 2266 "ROYGB" "ROYGB" \ 2267 "RYGCB" "RYGCB" \ 2268 "brown-to-blue" "brown-to-blue" \ 2269 "grey-to-blue" "grey-to-blue" \ 2270 "orange-to-blue" "orange-to-blue" \ 2271 "none" "none" 2272 2189 2273 $itk_component(colormap) value "BCGYR" 2190 2274 bind $inner.colormap <<Value>> \ … … 2497 2581 itcl::body Rappture::FlowvisViewer::SlicerTip {axis} { 2498 2582 set val [$itk_component(${axis}CutScale) get] 2583 # set val [expr {0.01*($val-50) 2584 # *($_limits(${axis}max)-$_limits(${axis}min)) 2585 # + 0.5*($_limits(${axis}max)+$_limits(${axis}min))}] 2499 2586 return "Move the [string toupper $axis] cut plane.\nCurrently: $axis = $val%" 2500 2587 } … … 2950 3037 set _settings($this-zoom) $_view(zoom) 2951 3038 } 2952 2953 # Reset global settings from dataset's settings.2954 itcl::body Rappture::FlowvisViewer::BuildVolumeComponents {} {2955 $itk_component(volcomponents) choices delete 0 end2956 foreach name $_componentsList {2957 $itk_component(volcomponents) choices insert end $name $name2958 }2959 set _current [lindex $_componentsList 0]2960 $itk_component(volcomponents) value $_current2961 }2962 2963 # Reset global settings from dataset's settings.2964 itcl::body Rappture::FlowvisViewer::GetDatasetsWithComponent { cname } {2965 if { ![info exists _volcomponents($cname)] } {2966 return ""2967 }2968 set list ""2969 foreach tag $_volcomponents($cname) {2970 if { ![info exists _serverObjs($tag)] } {2971 continue2972 }2973 lappend list $tag2974 }2975 return $list2976 } -
branches/uq/gui/scripts/gauge.tcl
r5029 r5121 44 44 itk_option define -varname varname Varname "" 45 45 itk_option define -label label Label "" 46 itk_option define -validatecommand validateCommand ValidateCommand "" 46 47 47 48 constructor {args} { # defined below } … … 115 116 -borderwidth 1 -relief flat -textvariable [itcl::scope _value] 116 117 } { 118 keep -font 117 119 rename -background -textbackground textBackground Background 118 120 } … … 247 249 } 248 250 249 if {$itk_option(-type) == "integer"} { 250 if { [scan $newval "%g" value] != 1 || int($newval) != $value } { 251 error "bad value \"$newval\": should be an integer value" 252 } 251 switch -- $itk_option(-type) { 252 integer { 253 if { [scan $newval "%g" value] != 1 || int($newval) != $value } { 254 error "bad value \"$newval\": should be an integer value" 255 } 256 } 257 } 258 259 # 260 # If there's a -validatecommand option, then invoke the code 261 # now to check the new value. 262 # 263 if {[string length $itk_option(-validatecommand)] > 0} { 264 set cmd "uplevel #0 [list $itk_option(-validatecommand) [list $newval]]" 265 set result [eval $cmd] 253 266 } 254 267 -
branches/uq/gui/scripts/imageresult.tcl
r3844 r5121 72 72 pack propagate $itk_component(hull) no 73 73 74 Rappture::Panes $itk_interior.panes -sashwidth 1 -sashrelief solid -sashpadding 2 74 Rappture::Panes $itk_interior.panes \ 75 -sashwidth 2 -sashrelief solid -sashpadding 1 76 75 77 pack $itk_interior.panes -expand yes -fill both 76 78 set main [$itk_interior.panes pane 0] -
branches/uq/gui/scripts/images/ask.png
- Property svn:executable deleted
-
branches/uq/gui/scripts/images/folder.gif
- Property svn:executable deleted
-
branches/uq/gui/scripts/images/molvis-3dorth.gif
- Property svn:executable deleted
-
branches/uq/gui/scripts/images/molvis-3dpers.gif
- Property svn:executable deleted
-
branches/uq/gui/scripts/images/popup.png
- Property svn:executable deleted
-
branches/uq/gui/scripts/isomarker.tcl
r4546 r5121 30 30 private common _normalIcon [Rappture::icon nvlegendmark] 31 31 private common _activeIcon [Rappture::icon nvlegendmark2] 32 private method EnterTick {}33 private method LeaveTick {}34 private method StartDrag { x y }35 private method ContinueDrag { x y }36 private method StopDrag { x y }37 32 38 constructor {c obj tf args} {} 39 destructor {} 40 public method transferfunc {} 41 public method activate { bool } 42 public method visible { bool } 43 public method screenpos {} 44 public method absval { {x "-get"} } 45 public method relval { {x "-get"} } 46 } 47 48 itcl::body Rappture::IsoMarker::constructor {c obj tf args} { 49 set _canvas $c 50 set _nvobj $obj 51 set _tf $tf 52 set w [winfo width $_canvas] 53 set h [winfo height $_canvas] 54 set _tick [$c create image 0 $h \ 55 -image $_normalIcon -anchor s \ 56 -tags "tick $this $obj" -state hidden] 57 set _label [$c create text 0 $h \ 58 -anchor n -fill white -font "Helvetica 8" \ 59 -tags "labels $this $obj" -state hidden] 60 $c bind $_tick <Enter> [itcl::code $this EnterTick] 61 $c bind $_tick <Leave> [itcl::code $this LeaveTick] 62 $c bind $_tick <ButtonPress-1> [itcl::code $this StartDrag %x %y] 63 $c bind $_tick <B1-Motion> [itcl::code $this ContinueDrag %x %y] 64 $c bind $_tick <ButtonRelease-1> [itcl::code $this StopDrag %x %y] 65 } 66 67 itcl::body Rappture::IsoMarker::destructor {} { 68 $_canvas delete $this 69 } 70 71 itcl::body Rappture::IsoMarker::transferfunc {} { 72 return $_tf 73 } 74 75 itcl::body Rappture::IsoMarker::activate { bool } { 76 if { $bool || $_activePress || $_activeMotion } { 77 $_canvas itemconfigure $_label -state normal 78 $_canvas itemconfigure $_tick -image $_activeIcon 79 $_canvas itemconfigure title -state hidden 80 } else { 81 $_canvas itemconfigure $_label -state hidden 82 $_canvas itemconfigure $_tick -image $_normalIcon 83 $_canvas itemconfigure title -state normal 33 constructor {c obj tf args} { 34 set _canvas $c 35 set _nvobj $obj 36 set _tf $tf 37 set w [winfo width $_canvas] 38 set h [winfo height $_canvas] 39 set _tick [$c create image 0 $h \ 40 -image $_normalIcon -anchor s \ 41 -tags "$this $obj" -state hidden] 42 set _label [$c create text 0 $h \ 43 -anchor n -fill white -font "Helvetica 8" \ 44 -tags "$this $obj" -state hidden] 45 $c bind $_tick <Enter> [itcl::code $this HandleEvent "enter"] 46 $c bind $_tick <Leave> [itcl::code $this HandleEvent "leave"] 47 $c bind $_tick <ButtonPress-1> \ 48 [itcl::code $this HandleEvent "start" %x %y] 49 $c bind $_tick <B1-Motion> \ 50 [itcl::code $this HandleEvent "update" %x %y] 51 $c bind $_tick <ButtonRelease-1> \ 52 [itcl::code $this HandleEvent "end" %x %y] 53 } 54 destructor { 55 $_canvas delete $this 56 } 57 public method transferfunc {} { 58 return $_tf 59 } 60 public method activate { bool } { 61 if { $bool || $_activePress || $_activeMotion } { 62 $_canvas itemconfigure $_label -state normal 63 $_canvas itemconfigure $_tick -image $_activeIcon 64 } else { 65 $_canvas itemconfigure $_label -state hidden 66 $_canvas itemconfigure $_tick -image $_normalIcon 67 } 68 } 69 public method visible { bool } { 70 if { $bool } { 71 absval $_value 72 $_canvas itemconfigure $_tick -state normal 73 $_canvas raise $_tick 74 } else { 75 $_canvas itemconfigure $_tick -state hidden 76 } 77 } 78 public method screenpos { } { 79 set x [relval] 80 if { $x < 0.0 } { 81 set x 0.0 82 } elseif { $x > 1.0 } { 83 set x 1.0 84 } 85 set low 10 86 set w [winfo width $_canvas] 87 set high [expr {$w - 10}] 88 set x [expr {round($x*($high - $low) + $low)}] 89 return $x 90 } 91 public method absval { {x "-get"} } { 92 if { $x != "-get" } { 93 set _value $x 94 set y 31 95 $_canvas itemconfigure $_label -text [format %.2g $_value] 96 set x [screenpos] 97 $_canvas coords $_tick $x [expr {$y+3}] 98 $_canvas coords $_label $x [expr {$y+5}] 99 } 100 return $_value 101 } 102 public method relval { {x "-get"} } { 103 if { $x == "-get" } { 104 array set limits [$_nvobj limits $_tf] 105 if { $limits(vmax) == $limits(vmin) } { 106 if { $limits(vmax) == 0.0 } { 107 set limits(vmin) 0.0 108 set limits(vmax) 1.0 109 } else { 110 set limits(vmax) [expr $limits(vmin) + 1.0] 111 } 112 } 113 return [expr {($_value-$limits(vmin))/ 114 ($limits(vmax) - $limits(vmin))}] 115 } 116 array set limits [$_nvobj limits $_tf] 117 if { $limits(vmax) == $limits(vmin) } { 118 set limits(vmin) 0.0 119 set limits(vmax) 1.0 120 } 121 if { [catch {expr $limits(vmax) - $limits(vmin)} r] != 0 } { 122 return 0.0 123 } 124 absval [expr {($x * $r) + $limits(vmin)}] 125 } 126 private method HandleEvent { option args } { 127 switch -- $option { 128 enter { 129 set _activeMotion 1 130 activate yes 131 $_canvas raise $_tick 132 } 133 leave { 134 set _activeMotion 0 135 activate no 136 } 137 start { 138 $_canvas raise $_tick 139 set _activePress 1 140 activate yes 141 $_canvas itemconfigure limits -state hidden 142 } 143 update { 144 set w [winfo width $_canvas] 145 set x [lindex $args 0] 146 relval [expr {double($x-10)/($w-20)}] 147 $_nvobj overmarker $this $x 148 $_nvobj updatetransferfuncs 149 } 150 end { 151 set x [lindex $args 0] 152 if { ![$_nvobj rmdupmarker $this $x]} { 153 eval HandleEvent update $args 154 } 155 set _activePress 0 156 activate no 157 $_canvas itemconfigure limits -state normal 158 } 159 default { 160 error "bad option \"$option\": should be start, update, end" 161 } 162 } 84 163 } 85 164 } 86 87 itcl::body Rappture::IsoMarker::visible { bool } {88 if { $bool } {89 absval $_value90 $_canvas itemconfigure $_tick -state normal91 $_canvas raise $_tick92 } else {93 $_canvas itemconfigure $_tick -state hidden94 }95 }96 97 itcl::body Rappture::IsoMarker::screenpos { } {98 set x [relval]99 if { $x < 0.0 } {100 set x 0.0101 } elseif { $x > 1.0 } {102 set x 1.0103 }104 set low 10105 set w [winfo width $_canvas]106 set high [expr {$w - 10}]107 set x [expr {round($x*($high - $low) + $low)}]108 return $x109 }110 111 itcl::body Rappture::IsoMarker::absval { {x "-get"} } {112 if { $x != "-get" } {113 set _value $x114 set y 31115 $_canvas itemconfigure $_label -text [format %g $_value]116 set x [screenpos]117 $_canvas coords $_tick $x [expr {$y+3}]118 $_canvas coords $_label $x [expr {$y+5}]119 }120 return $_value121 }122 123 itcl::body Rappture::IsoMarker::relval { {x "-get"} } {124 foreach {min max} [$_nvobj limits $_tf] break125 if { $x == "-get" } {126 if { $max == $min } {127 if { $max == 0.0 } {128 set min 0.0129 set max 1.0130 } else {131 set max [expr $min + 1.0]132 }133 }134 return [expr {($_value - $min) / ($max - $min)}]135 }136 if { $max == $min } {137 set min 0.0138 set max 1.0139 }140 if { [catch {expr $max - $min} r] != 0 } {141 return 0.0142 }143 absval [expr {($x * $r) + $min}]144 }145 146 itcl::body Rappture::IsoMarker::EnterTick {} {147 set _activeMotion 1148 activate yes149 $_canvas raise $_tick150 }151 152 itcl::body Rappture::IsoMarker::LeaveTick {} {153 set _activeMotion 0154 activate no155 }156 157 itcl::body Rappture::IsoMarker::StartDrag { x y } {158 $_canvas raise $_tick159 set _activePress 1160 activate yes161 $_canvas itemconfigure limits -state hidden162 $_canvas itemconfigure title -state hidden163 }164 165 itcl::body Rappture::IsoMarker::StopDrag { x y } {166 if { ![$_nvobj removeDuplicateMarker $this $x]} {167 ContinueDrag $x $y168 }169 set _activePress 0170 activate no171 $_canvas itemconfigure limits -state normal172 $_canvas itemconfigure title -state normal173 }174 175 itcl::body Rappture::IsoMarker::ContinueDrag { x y } {176 set w [winfo width $_canvas]177 relval [expr {double($x-10)/($w-20)}]178 $_nvobj overMarker $this $x179 $_nvobj updateTransferFunctions180 $_canvas raise $_tick181 set _activePress 1182 activate yes183 $_canvas itemconfigure limits -state hidden184 $_canvas itemconfigure title -state hidden185 }186 -
branches/uq/gui/scripts/main.tcl
r5029 r5121 93 93 value -tool tool.xml 94 94 list -load "" 95 value -input "" 95 96 value -nosim 0 96 97 } … … 103 104 incr numTries -1 104 105 if { $numTries < 0 } { 105 106 return 106 107 } 107 108 global env 108 109 set paramsFile $env(TOOL_PARAMETERS) 109 110 if { ![file readable $paramsFile] } { 110 111 111 after 500 ReadToolParmeters $numTries 112 return 112 113 } 113 114 catch { … … 138 139 } 139 140 141 set inputobj {} 142 if {$params(-input) ne ""} { 143 if {![file exists $params(-input)]} { 144 puts stderr "can't find input file: \"$params(-input)\"" 145 exit 1 146 } 147 if {[catch {Rappture::library $params(-input)} result] == 0} { 148 set inputobj $result 149 } 150 } 151 140 152 # open the XML file containing the tool parameters 141 153 if {![file exists $params(-tool)]} { … … 147 159 # run.xml files they are loading. 148 160 set pseudotool "" 149 if { 0 == [llength $loadobjs]} {161 if {[llength $loadobjs] == 0 && $inputobj eq ""} { 150 162 puts stderr "can't find tool \"$params(-tool)\"" 151 163 exit 1 … … 155 167 # if there are loaders or notes, they will still need 156 168 # examples/ and docs/ dirs from the install location 157 foreach runobj $loadobjs { 169 set check [concat $loadobjs $inputobj] 170 foreach runobj $check { 158 171 set tdir \ 159 172 [string trim [$runobj get tool.version.application.directory(tool)]] … … 367 380 if { $arrangement != "side-by-side" && 368 381 ($type == "manual" || $type == "manual-resim" || 369 382 $type == "auto" || $style == "wizard") } { 370 383 # in "auto" mode, we don't need a simulate button 371 384 $f.analyze configure -simcontrol off … … 377 390 378 391 # load previous xml runfiles 379 if { 0 != [llength $params(-load)]} {392 if {[llength $params(-load)] > 0} { 380 393 foreach runobj $loadobjs { 381 # this doesn't seem to work with loaders382 # loaders seem to get their value after this point383 # may need to tell loader elements to update its value384 $tool load $runobj385 394 $f.analyze load $runobj 386 395 } 396 # load the inputs for the very last run 397 $tool load $runobj 398 387 399 # don't need simulate button if we cannot simulate 388 400 if {$params(-nosim)} { … … 391 403 $f.analyze configure -notebookpage analyze 392 404 $win.pager current analyzer 405 } elseif {$params(-input) ne ""} { 406 $tool load $inputobj 393 407 } 394 408 puts "DONE main.tcl" 409 # let components (loaders) settle after the newly loaded runs 410 update 411 412 foreach path [array names ::Rappture::parameters] { 413 set fname $::Rappture::parameters($path) 414 if {[catch { 415 set fid [open $fname r] 416 set info [read $fid] 417 close $fid}] == 0} { 418 419 set w [$tool widgetfor $path] 420 if {$w ne ""} { 421 if {[catch {$w value [string trim $info]} result]} { 422 puts stderr "WARNING: bad tool parameter value for \"$path\"" 423 puts stderr " $result" 424 } 425 } else { 426 puts stderr "WARNING: can't find control for tool parameter: $path" 427 } 428 } 429 } 430 395 431 wm deiconify .main -
branches/uq/gui/scripts/mesh.tcl
r4798 r5121 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 2 2 3 3 # ---------------------------------------------------------------------- … … 18 18 package require Itcl 19 19 20 namespace eval Rappture { 21 # forward declaration 20 namespace eval Rappture { 21 # forward declaration 22 22 } 23 23 24 24 itcl::class Rappture::Mesh { 25 private variable _xmlobj "" ; 26 private variable _mesh "" ; 27 private variable _dim 0;# Dimension of mesh (1, 2, or 3)28 private variable _type ""; 29 private variable _axis2units; 30 private variable _axis2labels; # 31 private variable _hints 32 private variable _limits ; # Array of mesh limits. Keys are33 34 private variable _numPoints 0 ; 35 private variable _numCells 0 ;# # of cells in mesh36 private variable _vtkdata ""; 25 private variable _xmlobj "" ; # Ref to XML obj with device data 26 private variable _mesh "" ; # Lib obj representing this mesh 27 private variable _dim 0; # Dimension of mesh (1, 2, or 3) 28 private variable _type ""; # Indicates the type of mesh. 29 private variable _axis2units; # System of units for x, y, z 30 private variable _axis2labels; # 31 private variable _hints 32 private variable _limits ; # Array of mesh limits. Keys are 33 # xmin, xmax, ymin, ymax, ... 34 private variable _numPoints 0 ; # # of points in mesh 35 private variable _numCells 0 ; # # of cells in mesh 36 private variable _vtkdata ""; # Mesh in vtk file format. 37 37 private variable _isValid 0; # Indicates if the mesh is valid. 38 constructor {xmlobj path} { 39 # defined below 40 } 41 destructor { 42 # defined below 38 constructor {xmlobj path} { 39 # defined below 40 } 41 destructor { 42 # defined below 43 43 } 44 44 public method points {} … … 58 58 public method vtkdata {{what -partial}} 59 59 public method type {} { 60 60 return $_type 61 61 } 62 62 public method numpoints {} { 63 63 return $_numPoints 64 64 } 65 65 public method numcells {} { 66 67 } 68 69 private common _xp2obj ; 70 private common _obj2ref ; 71 private variable _xv 72 private variable _yv 73 private variable _zv 74 private variable _xCoords "";# For the blt contour only75 private variable _yCoords "";# For the blt contour only76 66 return $_numCells 67 } 68 69 private common _xp2obj ; # used for fetch/release ref counting 70 private common _obj2ref ; # used for fetch/release ref counting 71 private variable _xv "" 72 private variable _yv "" 73 private variable _zv "" 74 private variable _xCoords ""; # For the blt contour only 75 private variable _yCoords ""; # For the blt contour only 76 77 77 private method ReadNodesElements {path} 78 private method GetCellCount { xNum yNum zNum } 79 private method GetDimension { path } 80 private method GetDouble { path } 81 private method GetInt { path } 82 private method InitHints {} 78 private method GetDimension { path } 79 private method GetDouble { path } 80 private method GetInt { path } 81 private method InitHints {} 83 82 private method ReadGrid { path } 84 83 private method ReadUnstructuredGrid { path } … … 165 164 foreach u $units axis { x y z } { 166 165 if { $u != "" } { 167 set _axis2units($axis) $u 166 set _axis2units($axis) $u 168 167 } else { 169 set _axis2units($axis) $first 168 set _axis2units($axis) $first 170 169 } 171 170 } … … 180 179 # Meshes comes in a variety of flavors 181 180 # 182 # Dimensionality is determined from the <dimension> tag. 181 # Dimensionality is determined from the <dimension> tag. 183 182 # 184 183 # <vtk> described mesh 185 184 # <element> + <node> definitions 186 # <grid> rectangular mesh 185 # <grid> rectangular mesh 187 186 # <unstructured> homogeneous cell type mesh. 188 187 … … 190 189 set subcount 0 191 190 foreach cname [$_mesh children] { 192 193 194 195 196 } 197 191 foreach type { vtk grid unstructured } { 192 if { $cname == $type } { 193 incr subcount 194 break 195 } 196 } 198 197 } 199 198 if {[$_mesh element "node"] != "" || … … 207 206 } 208 207 if { $subcount > 1 } { 209 208 puts stderr "WARNING: too many mesh types specified for \"$path\"." 210 209 return 211 210 } 212 211 set result 0 213 212 if { [$_mesh element "vtk"] != ""} { 214 213 set result [ReadVtk $path] 215 214 } elseif {[$_mesh element "grid"] != "" } { 216 215 set result [ReadGrid $path] 217 216 } elseif {[$_mesh element "unstructured"] != "" } { 218 217 set result [ReadUnstructuredGrid $path] 219 218 } elseif {[$_mesh element "node"] != "" && [$_mesh element "element"] != ""} { 220 219 set result [ReadNodesElements $path] … … 232 231 233 232 if { $_xCoords != "" } { 234 233 blt::vector destroy $_xCoords 235 234 } 236 235 if { $_yCoords != "" } { 237 238 } 239 } 240 241 # 242 # vtkdata -- 243 # 244 # 245 # 246 # 247 # 248 # 236 blt::vector destroy $_yCoords 237 } 238 } 239 240 # 241 # vtkdata -- 242 # 243 # This is called by the field object to generate a VTK file to send to 244 # the remote render server. Returns the vtkDataSet object containing 245 # (at this point) just the mesh. The field object doesn't know (or 246 # care) what type of mesh is used. The field object will add field 247 # arrays before generating output to send to the remote render server. 249 248 # 250 249 itcl::body Rappture::Mesh::vtkdata {{what -partial}} { 251 250 if {$what == "-full"} { 252 251 append out "# vtk DataFile Version 3.0\n" 253 254 252 append out "[hints label]\n" 253 append out "ASCII\n" 255 254 append out $_vtkdata 256 255 return $out … … 341 340 itcl::body Rappture::Mesh::mesh { {type "vtk"} } { 342 341 switch $type { 343 "vtk" { 344 345 346 default { 347 348 342 "vtk" { 343 return "" 344 } 345 default { 346 error "Requested mesh type \"$type\" is unknown." 347 } 349 348 } 350 349 } … … 427 426 } 428 427 } 428 foreach {key path} { 429 toolid tool.id 430 toolname tool.name 431 toolcommand tool.execute 432 tooltitle tool.title 433 toolrevision tool.version.application.revision 434 } { 435 set str [$_xmlobj get $path] 436 if { "" != $str } { 437 set _hints($key) $str 438 } 439 } 429 440 } 430 441 … … 432 443 set string [$_xmlobj get $path.dim] 433 444 if { $string == "" } { 434 445 puts stderr "WARNING: no tag <dim> found in mesh \"$path\"." 435 446 return 0 436 447 } … … 468 479 return 0 469 480 } 470 # Create a VTK file with the mesh in it. 481 # Create a VTK file with the mesh in it. 471 482 set _vtkdata [$_xmlobj get $path.vtk] 472 483 append out "# vtk DataFile Version 3.0\n" … … 500 511 } 501 512 502 itcl::body Rappture::Mesh::GetCellCount { xNum yNum zNum } {503 set numCells 1504 if { $xNum > 0 } {505 set numCells [expr $numCells * $xNum]506 }507 if { $yNum > 0 } {508 set numCells [expr $numCells * $yNum]509 }510 if { $zNum > 0 } {511 set numCells [expr $numCells * $zNum]512 }513 return $numCells514 }515 516 513 itcl::body Rappture::Mesh::ReadGrid { path } { 517 514 set _type "grid" … … 524 521 set numCurvilinear 0 525 522 foreach axis { x y z } { 526 527 528 529 530 531 532 533 534 523 set min [$_xmlobj get "$path.grid.${axis}axis.min"] 524 set max [$_xmlobj get "$path.grid.${axis}axis.max"] 525 set num [$_xmlobj get "$path.grid.${axis}axis.numpoints"] 526 set coords [$_xmlobj get "$path.grid.${axis}coords"] 527 set dim [$_xmlobj get "$path.grid.${axis}dim"] 528 if { $min != "" && $max != "" && $num != "" && $num > 0 } { 529 set ${axis}Min $min 530 set ${axis}Max $max 531 set ${axis}Num $num 535 532 if {$min > $max} { 536 puts stderr "ERROR: grid $axis min can't be greater than max"533 puts stderr "ERROR: grid $axis axis minimum larger than maximum" 537 534 return 0 538 535 } 539 540 541 542 543 536 incr numUniform 537 } elseif { $coords != "" } { 538 incr numRectilinear 539 set ${axis}Coords $coords 540 } elseif { $dim != "" } { 544 541 set ${axis}Num $dim 545 542 incr numCurvilinear … … 548 545 set _dim [expr $numRectilinear + $numUniform + $numCurvilinear] 549 546 if { $_dim == 0 } { 550 547 # No data found. 551 548 puts stderr "WARNING: bad grid \"$path\": no data found" 552 549 return 0 553 550 } 554 551 if { $numCurvilinear > 0 } { … … 563 560 return 0 564 561 } 565 562 if { ![info exists xNum] } { 566 563 puts stderr "WARNING: bad grid \"$path\": invalid dimensions for curvilinear grid: missing <xdim> from grid description." 567 564 return 0 … … 575 572 if { [info exists zNum] } { 576 573 set _dim 3 577 578 set _numCells [ GetCellCount $xNum $yNum $zNum]579 if { ($_numPoints *3) != $numCoords } {574 set _numPoints [expr $xNum * $yNum * $zNum] 575 set _numCells [expr ($xNum > 1 ? ($xNum - 1) : 1) * ($yNum > 1 ? ($yNum - 1) : 1) * ($zNum > 1 ? ($zNum - 1) : 1)] 576 if { ($_numPoints*3) != $numCoords } { 580 577 puts stderr "WARNING: bad grid \"$path\": invalid grid: \# of points does not match dimensions <xdim> * <ydim> * <zdim>" 581 578 return 0 … … 586 583 } 587 584 $all split $xv $yv $zv 588 585 foreach axis {x y z} { 589 586 set vector [set ${axis}v] 590 587 set _limits($axis) [$vector limits] 591 592 593 594 588 } 589 append out "DATASET STRUCTURED_GRID\n" 590 append out "DIMENSIONS $xNum $yNum $zNum\n" 591 append out "POINTS $_numPoints double\n" 595 592 append out [$all range 0 end] 596 593 append out "\n" 597 594 set _vtkdata $out 598 595 } elseif { [info exists yNum] } { 599 596 set _dim 2 600 601 set _numCells [ GetCellCount $xNum $yNum 0]602 if { ($_numPoints *2) != $numCoords } {597 set _numPoints [expr $xNum * $yNum] 598 set _numCells [expr ($xNum > 1 ? ($xNum - 1) : 1) * ($yNum > 1 ? ($yNum - 1) : 1)] 599 if { ($_numPoints*2) != $numCoords } { 603 600 puts stderr "WARNING: bad grid \"$path\": \# of points does not match dimensions <xdim> * <ydim>" 604 601 return 0 … … 608 605 return 0 609 606 } 610 607 foreach axis {x y} { 611 608 set vector [set ${axis}v] 612 609 set _limits($axis) [$vector limits] 613 610 } 614 611 set _limits(z) [list 0 0] 615 612 $zv seq 0 0 [$xv length] 616 613 $all merge $xv $yv $zv 617 618 619 614 append out "DATASET STRUCTURED_GRID\n" 615 append out "DIMENSIONS $xNum $yNum 1\n" 616 append out "POINTS $_numPoints double\n" 620 617 append out [$all range 0 end] 621 618 append out "\n" 622 619 set _vtkdata $out 623 620 } else { 624 621 set _dim 1 625 622 set _numPoints $xNum 626 set _numCells [ GetCellCount $xNum 0 0]623 set _numCells [expr $xNum - 1] 627 624 if { $_numPoints != $numCoords } { 628 625 puts stderr "WARNING: bad grid \"$path\": \# of points does not match <xdim>" … … 635 632 $zv seq 0 0 [$xv length] 636 633 $all merge $xv $yv $zv 637 638 639 634 append out "DATASET STRUCTURED_GRID\n" 635 append out "DIMENSIONS $xNum 1 1\n" 636 append out "POINTS $_numPoints double\n" 640 637 append out [$all range 0 end] 641 638 append out "\n" 642 643 639 set _vtkdata $out 640 } 644 641 blt::vector destroy $all $xv $yv $zv 645 642 return 1 646 643 } 647 644 if { $numRectilinear == 0 && $numUniform > 0} { 648 # This is the special case where all axes 2D/3D are uniform. 645 # This is the special case where all axes 2D/3D are uniform. 649 646 # This results in a STRUCTURED_POINTS 650 647 if { $_dim == 1 } { 651 set xSpacing 0 652 if { $xNum > 1 } { 653 set xSpacing [expr ($xMax - $xMin) / double($xNum - 1)] 654 } 655 set _numPoints $xNum 656 set _numCells [GetCellCount $xNum 0 0] 657 append out "DATASET STRUCTURED_POINTS\n" 658 append out "DIMENSIONS $xNum 1 1\n" 659 append out "ORIGIN $xMin 0 0\n" 660 append out "SPACING $xSpacing 0 0\n" 661 set _vtkdata $out 648 if {$xNum == 1} { 649 set xSpace 0 650 } else { 651 set xSpace [expr ($xMax - $xMin) / double($xNum - 1)] 652 } 653 set _numPoints $xNum 654 set _numCells [expr $xNum - 1] 655 append out "DATASET STRUCTURED_POINTS\n" 656 append out "DIMENSIONS $xNum 1 1\n" 657 append out "ORIGIN $xMin 0 0\n" 658 append out "SPACING $xSpace 0 0\n" 659 set _vtkdata $out 662 660 set _limits(x) [list $xMin $xMax] 663 661 set _limits(y) [list 0 0] 664 662 set _limits(z) [list 0 0] 665 } elseif { $_dim == 2 } { 666 set xSpacing 0 667 set ySpacing 0 668 if { $xNum > 1 } { 669 set xSpacing [expr ($xMax - $xMin) / double($xNum - 1)] 670 } 671 if { $yNum > 1 } { 672 set ySpacing [expr ($yMax - $yMin) / double($yNum - 1)] 673 } 674 set _numPoints [expr $xNum * $yNum] 675 set _numCells [GetCellCount $xNum $yNum 0] 676 append out "DATASET STRUCTURED_POINTS\n" 677 append out "DIMENSIONS $xNum $yNum 1\n" 678 append out "ORIGIN $xMin $yMin 0\n" 679 append out "SPACING $xSpacing $ySpacing 0\n" 680 set _vtkdata $out 681 foreach axis {x y} { 682 set _limits($axis) [list [set ${axis}Min] [set ${axis}Max]] 683 } 663 } elseif { $_dim == 2 } { 664 if {$xNum == 1} { 665 set xSpace 0 666 } else { 667 set xSpace [expr ($xMax - $xMin) / double($xNum - 1)] 668 } 669 if {$yNum == 1} { 670 set ySpace 0 671 } else { 672 set ySpace [expr ($yMax - $yMin) / double($yNum - 1)] 673 } 674 set _numPoints [expr $xNum * $yNum] 675 set _numCells [expr ($xNum > 1 ? ($xNum - 1) : 1) * ($yNum > 1 ? ($yNum - 1) : 1)] 676 append out "DATASET STRUCTURED_POINTS\n" 677 append out "DIMENSIONS $xNum $yNum 1\n" 678 append out "ORIGIN $xMin $yMin 0\n" 679 append out "SPACING $xSpace $ySpace 0\n" 680 set _vtkdata $out 681 foreach axis {x y} { 682 set _limits($axis) [list [set ${axis}Min] [set ${axis}Max]] 683 } 684 684 set _limits(z) [list 0 0] 685 } elseif { $_dim == 3 } { 686 set xSpacing 0 687 set ySpacing 0 688 set zSpacing 0 689 if {$xNum > 1} { 690 set xSpacing [expr ($xMax - $xMin) / double($xNum - 1)] 691 } 692 if {$yNum > 1} { 693 set ySpacing [expr ($yMax - $yMin) / double($yNum - 1)] 694 } 695 if {$zNum > 1} { 696 set zSpacing [expr ($zMax - $zMin) / double($zNum - 1)] 697 } 698 set _numPoints [expr $xNum * $yNum * $zNum] 699 set _numCells [GetCellCount $xNum $yNum $zNum] 700 append out "DATASET STRUCTURED_POINTS\n" 701 append out "DIMENSIONS $xNum $yNum $zNum\n" 702 append out "ORIGIN $xMin $yMin $zMin\n" 703 append out "SPACING $xSpacing $ySpacing $zSpacing\n" 704 set _vtkdata $out 705 foreach axis {x y z} { 706 set _limits($axis) [list [set ${axis}Min] [set ${axis}Max]] 707 } 708 } else { 709 puts stderr "WARNING: bad grid \"$path\": bad dimension \"$_dim\"" 685 } elseif { $_dim == 3 } { 686 if {$xNum == 1} { 687 set xSpace 0 688 } else { 689 set xSpace [expr ($xMax - $xMin) / double($xNum - 1)] 690 } 691 if {$yNum == 1} { 692 set ySpace 0 693 } else { 694 set ySpace [expr ($yMax - $yMin) / double($yNum - 1)] 695 } 696 if {$zNum == 1} { 697 set zSpace 0 698 } else { 699 set zSpace [expr ($zMax - $zMin) / double($zNum - 1)] 700 } 701 set _numPoints [expr $xNum * $yNum * $zNum] 702 set _numCells [expr ($xNum > 1 ? ($xNum - 1) : 1) * ($yNum > 1 ? ($yNum - 1) : 1) * ($zNum > 1 ? ($zNum - 1) : 1)] 703 append out "DATASET STRUCTURED_POINTS\n" 704 append out "DIMENSIONS $xNum $yNum $zNum\n" 705 append out "ORIGIN $xMin $yMin $zMin\n" 706 append out "SPACING $xSpace $ySpace $zSpace\n" 707 set _vtkdata $out 708 foreach axis {x y z} { 709 set _limits($axis) [list [set ${axis}Min] [set ${axis}Max]] 710 } 711 } else { 712 puts stderr "WARNING: bad grid \"$path\": bad dimension \"$_dim\"" 710 713 return 0 711 712 714 } 715 return 1 713 716 } 714 717 # This is the hybrid case. Some axes are uniform, others are nonuniform. 715 718 set xv [blt::vector create \#auto] 716 719 if { [info exists xMin] } { 717 718 } else { 719 720 721 722 720 $xv seq $xMin $xMax $xNum 721 } else { 722 $xv set [$_xmlobj get $path.grid.xcoords] 723 set xMin [$xv min] 724 set xMax [$xv max] 725 set xNum [$xv length] 723 726 } 724 727 set yv [blt::vector create \#auto] … … 737 740 set zv [blt::vector create \#auto] 738 741 if { $_dim == 3 } { 739 740 741 742 743 744 745 746 747 } else { 748 742 if { [info exists zMin] } { 743 $zv seq $zMin $zMax $zNum 744 } else { 745 $zv set [$_xmlobj get $path.grid.zcoords] 746 set zMin [$zv min] 747 set zMax [$zv max] 748 set zNum [$zv length] 749 } 750 } else { 751 set zNum 1 749 752 } 750 753 if { $_dim == 3 } { 751 752 set _numCells [ GetCellCount $xNum $yNum $zNum]753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 754 set _numPoints [expr $xNum * $yNum * $zNum] 755 set _numCells [expr ($xNum > 1 ? ($xNum - 1) : 1) * ($yNum > 1 ? ($yNum - 1) : 1) * ($zNum > 1 ? ($zNum - 1) : 1)] 756 append out "DATASET RECTILINEAR_GRID\n" 757 append out "DIMENSIONS $xNum $yNum $zNum\n" 758 append out "X_COORDINATES $xNum double\n" 759 append out [$xv range 0 end] 760 append out "\n" 761 append out "Y_COORDINATES $yNum double\n" 762 append out [$yv range 0 end] 763 append out "\n" 764 append out "Z_COORDINATES $zNum double\n" 765 append out [$zv range 0 end] 766 append out "\n" 767 set _vtkdata $out 768 foreach axis {x y z} { 769 if { [info exists ${axis}Min] } { 770 set _limits($axis) [list [set ${axis}Min] [set ${axis}Max]] 771 } 772 } 770 773 } elseif { $_dim == 2 } { 771 772 set _numCells [ GetCellCount $xNum $yNum 0]773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 774 set _numPoints [expr $xNum * $yNum] 775 set _numCells [expr ($xNum > 1 ? ($xNum - 1) : 1) * ($yNum > 1 ? ($yNum - 1) : 1)] 776 append out "DATASET RECTILINEAR_GRID\n" 777 append out "DIMENSIONS $xNum $yNum 1\n" 778 append out "X_COORDINATES $xNum double\n" 779 append out [$xv range 0 end] 780 append out "\n" 781 append out "Y_COORDINATES $yNum double\n" 782 append out [$yv range 0 end] 783 append out "\n" 784 append out "Z_COORDINATES 1 double\n" 785 append out "0\n" 786 foreach axis {x y} { 787 if { [info exists ${axis}Min] } { 788 set _limits($axis) [list [set ${axis}Min] [set ${axis}Max]] 789 } 790 } 788 791 set _limits(z) [list 0 0] 789 792 set _vtkdata $out 790 793 } elseif { $_dim == 1 } { 791 794 set _numPoints $xNum 792 set _numCells [ GetCellCount $xNum 0 0]793 794 795 796 797 798 799 800 801 795 set _numCells [expr $xNum - 1] 796 append out "DATASET RECTILINEAR_GRID\n" 797 append out "DIMENSIONS $xNum 1 1\n" 798 append out "X_COORDINATES $xNum double\n" 799 append out [$xv range 0 end] 800 append out "\n" 801 append out "Y_COORDINATES 1 double\n" 802 append out "0\n" 803 append out "Z_COORDINATES 1 double\n" 804 append out "0\n" 802 805 if { [info exists xMin] } { 803 806 set _limits(x) [list $xMin $xMax] … … 805 808 set _limits(y) [list 0 0] 806 809 set _limits(z) [list 0 0] 807 808 } else { 809 810 set _vtkdata $out 811 } else { 812 puts stderr "WARNING: bad grid \"$path\": invalid dimension \"$_dim\"" 810 813 return 0 811 814 } 812 blt::vector destroy $xv $yv $zv 815 blt::vector destroy $xv $yv $zv 813 816 return 1 814 817 } … … 844 847 set celltypes {} 845 848 foreach { a b c } $triangles { 846 847 848 849 append data " 3 $a $b $c\n" 850 append celltypes "5\n" 851 incr _numCells 849 852 } 850 853 append out "DATASET UNSTRUCTURED_GRID\n" 851 854 append out "POINTS $_numPoints double\n" 852 855 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 853 856 append out " $x $y $z\n" 854 857 } 855 858 set count [expr $_numCells * 4] … … 876 879 set celltypes {} 877 880 foreach { a b c d } $quads { 878 879 880 881 append data " 4 $a $b $c $d\n" 882 append celltypes "9\n" 883 incr _numCells 881 884 } 882 885 append out "DATASET UNSTRUCTURED_GRID\n" 883 886 append out "POINTS $_numPoints double\n" 884 887 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 885 888 append out " $x $y $z\n" 886 889 } 887 890 set count [expr $_numCells * 5] … … 913 916 continue 914 917 } 915 916 918 append data " $numIndices $line\n" 919 incr _numCells 917 920 set count [expr $count + $numIndices + 1] 918 921 } … … 920 923 append out "POINTS $_numPoints double\n" 921 924 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 922 925 append out " $x $y $z\n" 923 926 } 924 927 append out "VERTICES $_numCells $count\n" … … 947 950 continue 948 951 } 949 950 952 append data " $numIndices $line\n" 953 incr _numCells 951 954 set count [expr $count + $numIndices + 1] 952 955 } … … 954 957 append out "POINTS $_numPoints double\n" 955 958 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 956 959 append out " $x $y $z\n" 957 960 } 958 961 append out "LINES $_numCells $count\n" … … 981 984 continue 982 985 } 983 984 986 append data " $numIndices $line\n" 987 incr _numCells 985 988 set count [expr $count + $numIndices + 1] 986 989 } … … 988 991 append out "POINTS $_numPoints double\n" 989 992 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 990 993 append out " $x $y $z\n" 991 994 } 992 995 append out "POLYGONS $_numCells $count\n" … … 1015 1018 continue 1016 1019 } 1017 1018 1020 append data " $numIndices $line\n" 1021 incr _numCells 1019 1022 set count [expr $count + $numIndices + 1] 1020 1023 } … … 1022 1025 append out "POINTS $_numPoints double\n" 1023 1026 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 1024 1027 append out " $x $y $z\n" 1025 1028 } 1026 1029 append out "TRIANGLE_STRIPS $_numCells $count\n" … … 1044 1047 set celltypes {} 1045 1048 foreach { a b c d } $tetras { 1046 1047 1048 1049 append data " 4 $a $b $c $d\n" 1050 append celltypes "10\n" 1051 incr _numCells 1049 1052 } 1050 1053 append out "DATASET UNSTRUCTURED_GRID\n" 1051 1054 append out "POINTS $_numPoints double\n" 1052 1055 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 1053 1056 append out " $x $y $z\n" 1054 1057 } 1055 1058 set count [expr $_numCells * 5] … … 1073 1076 set celltypes {} 1074 1077 foreach { a b c d e f g h } $hexas { 1075 1076 1077 1078 append data " 8 $a $b $c $d $e $f $g $h\n" 1079 append celltypes "12\n" 1080 incr _numCells 1078 1081 } 1079 1082 append out "DATASET UNSTRUCTURED_GRID\n" 1080 1083 append out "POINTS $_numPoints double\n" 1081 1084 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 1082 1085 append out " $x $y $z\n" 1083 1086 } 1084 1087 set count [expr $_numCells * 9] … … 1102 1105 set celltypes {} 1103 1106 foreach { a b c d e f } $wedges { 1104 1105 1106 1107 append data " 6 $a $b $c $d $e $f\n" 1108 append celltypes "13\n" 1109 incr _numCells 1107 1110 } 1108 1111 append out "DATASET UNSTRUCTURED_GRID\n" 1109 1112 append out "POINTS $_numPoints double\n" 1110 1113 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 1111 1114 append out " $x $y $z\n" 1112 1115 } 1113 1116 set count [expr $_numCells * 7] … … 1131 1134 set celltypes {} 1132 1135 foreach { a b c d e } $pyramids { 1133 1134 1135 1136 append data " 5 $a $b $c $d $e\n" 1137 append celltypes "14\n" 1138 incr _numCells 1136 1139 } 1137 1140 append out "DATASET UNSTRUCTURED_GRID\n" 1138 1141 append out "POINTS $_numPoints double\n" 1139 1142 foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] { 1140 1143 append out " $x $y $z\n" 1141 1144 } 1142 1145 set count [expr $_numCells * 6] … … 1150 1153 1151 1154 set _vtkdata $out 1152 return 1 1155 return 1 1153 1156 } 1154 1157 … … 1217 1220 # Step 1: Verify that there's only one cell tag of any kind. 1218 1221 set numCells 0 1219 foreach type { 1222 foreach type { 1220 1223 cells 1221 hexahedrons 1222 lines 1223 polygons 1224 pyramids 1224 hexahedrons 1225 lines 1226 polygons 1227 pyramids 1225 1228 quads 1226 tetrahedrons 1227 triangles 1229 tetrahedrons 1230 triangles 1228 1231 trianglestrips 1229 vertices 1230 wedges 1232 vertices 1233 wedges 1231 1234 } { 1232 1235 set data [$_xmlobj get $path.unstructured.$type] … … 1238 1241 set celltypes [$_xmlobj get $path.unstructured.celltypes] 1239 1242 if { $numCells == 0 && $celltypes != "" } { 1240 1243 puts stderr "WARNING: bad unstuctured grid \"$path\": no <cells> description found." 1241 1244 return 0 1242 1245 } … … 1245 1248 return 0 1246 1249 } 1247 foreach type { cells 1248 vertices lines polygons trianglestrips 1249 triangles quads 1250 tetrahedrons hexahedrons wedges pyramids } { 1250 foreach type { 1251 cells 1252 hexahedrons 1253 lines 1254 polygons 1255 pyramids 1256 quads 1257 tetrahedrons 1258 triangles 1259 trianglestrips 1260 vertices 1261 wedges 1262 } { 1251 1263 set data [$_xmlobj get $path.unstructured.$type] 1252 1264 if { $data != "" } { … … 1254 1266 } 1255 1267 } 1256 # Step 2: Allow points to be specified as <points> or 1268 # Step 2: Allow points to be specified as <points> or 1257 1269 # <xcoords>, <ycoords>, <zcoords>. Split and convert into 1258 1270 # 3 vectors, one for each coordinate. … … 1402 1414 set data {} 1403 1415 foreach cname [$_xmlobj children -type node $path] { 1404 1405 } 1416 append data "[$_xmlobj get $path.$cname]\n" 1417 } 1406 1418 Rappture::ReadPoints $data _dim points 1407 1419 if { $_dim == 2 } { 1408 1409 1410 1411 1412 1413 1414 1420 set all [blt::vector create \#auto] 1421 set xv [blt::vector create \#auto] 1422 set yv [blt::vector create \#auto] 1423 set zv [blt::vector create \#auto] 1424 $all set $points 1425 $all split $xv $yv 1426 set _numPoints [$xv length] 1415 1427 set _limits(x) [$xv limits] 1416 1428 set _limits(y) [$yv limits] 1417 1429 set _limits(z) [list 0 0] 1418 1419 1420 1421 1422 1430 # 2D Dataset. All Z coordinates are 0 1431 $zv seq 0.0 0.0 $_numPoints 1432 $all merge $xv $yv $zv 1433 set points [$all range 0 end] 1434 blt::vector destroy $all $xv $yv $zv 1423 1435 } elseif { $_dim == 3 } { 1424 1425 1426 1427 1428 1429 1430 1436 set all [blt::vector create \#auto] 1437 set xv [blt::vector create \#auto] 1438 set yv [blt::vector create \#auto] 1439 set zv [blt::vector create \#auto] 1440 $all set $points 1441 $all split $xv $yv $zv 1442 set _numPoints [$xv length] 1431 1443 set _limits(x) [$xv limits] 1432 1444 set _limits(y) [$yv limits] 1433 1445 set _limits(z) [$zv limits] 1434 1435 1436 } else { 1437 1446 set points [$all range 0 end] 1447 blt::vector destroy $all $xv $yv $zv 1448 } else { 1449 error "bad dimension \"$_dim\" for nodes mesh" 1438 1450 } 1439 1451 array set node2celltype { 1440 1441 1442 1443 1444 1452 3 5 1453 4 10 1454 8 12 1455 6 13 1456 5 14 1445 1457 } 1446 1458 set count 0 … … 1451 1463 foreach cname [$_xmlobj children -type element $path] { 1452 1464 set nodeList [$_mesh get $cname.nodes] 1453 1454 1455 1456 1457 1458 1459 1465 set numNodes [llength $nodeList] 1466 if { ![info exists node2celltype($numNodes)] } { 1467 puts stderr "WARNING: bad nodes/elements mesh \$path\": unknown number of indices \"$_numNodes\": should be 3, 4, 5, 6, or 8" 1468 return 0 1469 } 1470 set celltype $node2celltype($numNodes) 1471 append celltypes " $celltype\n" 1460 1472 if { $celltype == 12 } { 1461 1473 # Formerly used voxels instead of hexahedrons. We're converting … … 1467 1479 } 1468 1480 set nodeList $newList 1469 } 1470 1471 1472 incr count $numNodes 1473 incr count;# One extra for the VTK celltype id.1481 } 1482 append data " $numNodes $nodeList\n" 1483 incr _numCells 1484 incr count $numNodes 1485 incr count; # One extra for the VTK celltype id. 1474 1486 } 1475 1487 … … 1484 1496 append out "\n" 1485 1497 set _vtkdata $out 1486 set _isValid 1 1498 set _isValid 1 1487 1499 } 1488 1500 -
branches/uq/gui/scripts/moleculeViewer.tcl
r3844 r5121 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 2 2 # ---------------------------------------------------------------------- 3 3 # COMPONENT: MoleculeViewer - view a molecule in 3D … … 27 27 itk_option define -device device Device "" 28 28 29 constructor {tool args} { 30 # defined below 31 } 32 destructor { 33 # defined below 29 constructor {tool args} { 30 # defined below 31 } 32 destructor { 33 # defined below 34 34 } 35 35 … … 38 38 public method delete {args} 39 39 public method snap {w h} 40 public method parameters {title args} { 41 # do nothing 40 public method parameters {title args} { 41 # do nothing 42 42 } 43 43 public method emblems {option} … … 63 63 private variable _download "";# snapshot for download 64 64 } 65 65 66 66 itk::usual MoleculeViewer { 67 67 } … … 236 236 } 237 237 array set params $settings 238 238 239 239 set pos [lsearch -exact $_dlist $dataobj] 240 240 … … 243 243 error "bad value \"$dataobj\": should be Rappture::library object" 244 244 } 245 245 246 246 set emblem [$dataobj get components.molecule.about.emblems] 247 247 if {$emblem == "" || ![string is boolean $emblem] || !$emblem} { -
branches/uq/gui/scripts/molvisviewer.tcl
r4797 r5121 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 2 2 3 3 # ---------------------------------------------------------------------- … … 52 52 53 53 private variable _active; # array of active models. 54 private variable _obj2models; # array containing list of models 54 private variable _obj2models; # array containing list of models 55 55 # for each data object. 56 56 private variable _view … … 63 63 private variable _imagecache 64 64 private variable _state 65 private variable _labels 65 private variable _labels "default" 66 66 private variable _cacheid "" 67 67 private variable _cacheimage "" 68 private variable _first 69 70 private common _settings ; # Array of settings for all known 68 private variable _first "" 69 70 private common _settings ; # Array of settings for all known 71 71 # widgets 72 72 private variable _initialized … … 81 81 private variable _width 82 82 private variable _height 83 private variable _reset 1; 83 private variable _reset 1; # Restore camera settings 84 84 private variable _cell 0; # Restore camera settings 85 85 … … 96 96 } 97 97 private method BuildSettingsTab {} 98 private method DoResize {} 99 private method DoRotate {} 100 private method DoUpdate {} 101 private method EventuallyResize { w h } 102 private method EventuallyRotate { a b c } 103 private method EventuallyChangeSettings { args } 98 private method DoResize {} 99 private method DoRotate {} 100 private method DoUpdate {} 101 private method EventuallyResize { w h } 102 private method EventuallyRotate { a b c } 103 private method EventuallyChangeSettings { args } 104 104 private method GetImage { widget } 105 105 private method ReceiveImage { size cacheid frame rock } … … 107 107 private method AddImageControls { frame widget } 108 108 private method SetWaitVariable { value } { 109 set _getimage $value 109 set _getimage $value 110 110 } 111 111 private method WaitForResponse {} { … … 125 125 public method Connect {} 126 126 public method Disconnect {} 127 public method ResetView {} 127 public method ResetView {} 128 128 public method add {dataobj {options ""}} 129 129 public method delete {args} … … 132 132 public method isconnected {} 133 133 public method labels {option {model "all"}} 134 public method parameters {title args} { 135 # do nothing 134 public method parameters {title args} { 135 # do nothing 136 136 } 137 137 … … 236 236 $this-showlabels-initialized no 237 237 }] 238 238 239 239 itk_component add 3dview { 240 240 label $itk_component(plotarea).view -image $_image(plot) \ … … 294 294 Rappture::Tooltip::for $itk_component(labels) \ 295 295 "Show/hide the labels on atoms" 296 pack $itk_component(labels) -padx 2 -pady {6 2} 296 pack $itk_component(labels) -padx 2 -pady {6 2} 297 297 298 298 itk_component add rock { … … 303 303 -variable [itcl::scope _settings($this-rock)] 304 304 } 305 pack $itk_component(rock) -padx 2 -pady 2 305 pack $itk_component(rock) -padx 2 -pady 2 306 306 Rappture::Tooltip::for $itk_component(rock) "Rock model back and forth" 307 307 … … 319 319 BuildSettingsTab 320 320 321 # HACK ALERT. Initially force a requested width of the 3dview label. 321 # HACK ALERT. Initially force a requested width of the 3dview label. 322 322 323 323 # It's a chicken-and-the-egg problem. The size of the 3dview label is set … … 463 463 if { $showlabels != "" && [string is boolean $showlabels] } { 464 464 set _settings($this-showlabels) $showlabels 465 } 465 } 466 466 } 467 467 … … 567 567 -variable [itcl::scope _downloadPopup(format)] \ 568 568 -font "Arial 10 " \ 569 -value pdb 569 -value pdb 570 570 Rappture::Tooltip::for $inner.pdb \ 571 571 "Save as PDB Protein Data Bank format file." … … 573 573 -variable [itcl::scope _downloadPopup(format)] \ 574 574 -font "Arial 10 " \ 575 -value image 575 -value image 576 576 Rappture::Tooltip::for $inner.image \ 577 577 "Save as image." … … 589 589 blt::table $f \ 590 590 0,0 $f.ok \ 591 0,1 $f.cancel 591 0,1 $f.cancel 592 592 blt::table $inner \ 593 593 0,0 $inner.summary -anchor w \ … … 628 628 } else { 629 629 set inner [$popup component inner] 630 } 630 } 631 631 update 632 632 # Activate the popup and call for the output. … … 635 635 $popup activate $widget left 636 636 set bool [WaitForResponse] 637 $popup deactivate 637 $popup deactivate 638 638 if { $bool } { 639 639 return [GetImage $widget] … … 674 674 return 0 675 675 } 676 set _reset 1 676 set _reset 1 677 677 set result [VisViewer::Connect $hosts] 678 678 if { $result } { … … 684 684 set info {} 685 685 set user "???" 686 686 if { [info exists env(USER)] } { 687 687 set user $env(USER) 688 688 } 689 689 set session "???" 690 690 if { [info exists env(SESSION)] } { 691 691 set session $env(SESSION) 692 692 } 693 693 lappend info "version" "$Rappture::version" 694 694 lappend info "build" "$Rappture::build" … … 760 760 incr count 761 761 if { $cacheid != $_cacheid } { 762 array unset _imagecache 762 array unset _imagecache 763 763 set _cacheid $cacheid 764 764 } … … 798 798 "sticks" "sticks" \ 799 799 "lines" "lines" \ 800 "cartoon" "cartoon" 800 "cartoon" "cartoon" 801 801 802 802 bind $inner.rep <<Value>> [itcl::code $this Representation] … … 883 883 # Turn on buffering of commands to the server. We don't want to 884 884 # be preempted by a server disconnect/reconnect (that automatically 885 # generates a new call to Rebuild). 885 # generates a new call to Rebuild). 886 886 StartBufferingCommands 887 887 set _cell 0 … … 897 897 set dlist [get] 898 898 foreach dataobj $dlist { 899 900 901 899 if { $_first == "" } { 900 set _first $dataobj 901 } 902 902 set model [$dataobj get components.molecule.model] 903 903 if {"" == $model } { … … 906 906 set model $model$suffix 907 907 } 908 lappend _obj2models($dataobj) $model 908 lappend _obj2models($dataobj) $model 909 909 set state [$dataobj get components.molecule.state] 910 if {"" == $state} { 911 set state $_state(server) 910 if {"" == $state} { 911 set state $_state(server) 912 912 } 913 913 if { ![info exists _mlist($model)] } { # new, turn on 914 914 set _mlist($model) 2 915 915 } elseif { $_mlist($model) == 1 } { # on, leave on 916 set _mlist($model) 3 916 set _mlist($model) 3 917 917 } elseif { $_mlist($model) == 0 } { # off, turn on 918 918 set _mlist($model) 2 … … 1002 1002 set charge "" 1003 1003 if { "" == $lammpstypemap} { 1004 set atom $type 1004 set atom $type 1005 1005 } else { 1006 1006 set atom [lindex $lammpstypemap [expr {$type - 1}]] … … 1012 1012 append data3 $pdbline 1013 1013 } 1014 # only read first model 1014 # only read first model 1015 1015 if {[regexp "^ITEM: ATOMS" $lammpsline]} { 1016 1016 incr modelcount … … 1025 1025 set numBytes [string length $data3] 1026 1026 1027 # We know we're buffered here, so append the "loadpdb" 1027 # We know we're buffered here, so append the "loadpdb" 1028 1028 # command with the data payload immediately afterwards. 1029 1029 ServerCmd "loadpdb -defer follows $model $state $numBytes" … … 1057 1057 } 1058 1058 } 1059 1059 1060 1060 # enable/disable models as required (0=off->off, 1=on->off, 2=off->on, 1061 1061 # 3=on->on) … … 1074 1074 } 1075 1075 if { $_mlist($model) == 1 } { 1076 if { [info exists _model($model-newtransparency)] || 1076 if { [info exists _model($model-newtransparency)] || 1077 1077 [info exists _model($model-newrep)] } { 1078 1078 if { ![info exists _model($model-newrep)] } { … … 1118 1118 # Set or restore viewing parameters. We do this for the first 1119 1119 # model and assume this works for everything else. 1120 set w [winfo width $itk_component(3dview)] 1121 set h [winfo height $itk_component(3dview)] 1122 ServerCmd [subst { 1120 set w [winfo width $itk_component(3dview)] 1121 set h [winfo height $itk_component(3dview)] 1122 ServerCmd [subst { 1123 1123 reset 1124 1124 screen $w $h … … 1134 1134 if { $changed } { 1135 1135 # Default settings for all models. 1136 SphereScale update 1136 SphereScale update 1137 1137 StickRadius update 1138 labels update 1139 Opacity update 1140 CartoonTrace update 1138 labels update 1139 Opacity update 1140 CartoonTrace update 1141 1141 Cell update 1142 OrthoProjection update 1142 OrthoProjection update 1143 1143 Representation update 1144 1144 } … … 1188 1188 $_image(plot) configure -width $_width -height $_height 1189 1189 # Immediately invalidate cache, defer update until mapped 1190 array unset _imagecache 1190 array unset _imagecache 1191 1191 set _resizePending 0 1192 1192 } 1193 1193 1194 1194 itcl::body Rappture::MolvisViewer::EventuallyResize { w h } { 1195 1195 set _width $w … … 1203 1203 itcl::body Rappture::MolvisViewer::DoRotate {} { 1204 1204 ServerCmd "rotate $_view(a) $_view(b) $_view(c)" 1205 array unset _imagecache 1205 array unset _imagecache 1206 1206 set _rotatePending 0 1207 1207 } 1208 1208 1209 1209 itcl::body Rappture::MolvisViewer::EventuallyRotate { a b c } { 1210 set _view(a) $a 1210 set _view(a) $a 1211 1211 set _view(b) $b 1212 set _view(c) $c 1212 set _view(c) $c 1213 1213 if { !$_rotatePending } { 1214 1214 $_dispatcher event -after 100 !rotate … … 1246 1246 set _view(x) [expr $_view(x) + $dx] 1247 1247 set _view(y) [expr $_view(y) + $dy] 1248 array unset _imagecache 1248 array unset _imagecache 1249 1249 ServerCmd "pan $dx $dy" 1250 1250 return … … 1253 1253 set option "click" 1254 1254 } 1255 if { $option == "click" } { 1255 if { $option == "click" } { 1256 1256 $itk_component(3dview) configure -cursor hand1 1257 1257 } … … 1261 1261 set _view(x) [expr $_view(x) + $dx] 1262 1262 set _view(y) [expr $_view(y) + $dy] 1263 array unset _imagecache 1263 array unset _imagecache 1264 1264 ServerCmd "pan $dx $dy" 1265 1265 } … … 1294 1294 } 1295 1295 } 1296 array unset _imagecache 1296 array unset _imagecache 1297 1297 } 1298 1298 … … 1324 1324 return 1325 1325 } 1326 set _rocker(on) $_settings($this-rock) 1326 set _rocker(on) $_settings($this-rock) 1327 1327 if { $option == "step"} { 1328 1328 if { $_rocker(client) >= 10 } { … … 1554 1554 } 1555 1555 if { $option == $_mrep } { 1556 return 1556 return 1557 1557 } 1558 1558 if { $option == "update" } { 1559 1559 set option $_settings($this-model) 1560 1560 } 1561 array unset _imagecache 1561 array unset _imagecache 1562 1562 if { $option == "sticks" } { 1563 1563 set _settings($this-modelimg) [Rappture::icon lines] … … 1659 1659 return 1660 1660 } 1661 array unset _imagecache 1661 array unset _imagecache 1662 1662 if { $cell } { 1663 1663 Rappture::Tooltip::for $itk_component(ortho) \ … … 1723 1723 } 1724 1724 } 1725 1725 1726 1726 itcl::body Rappture::MolvisViewer::GetImage { widget } { 1727 1727 set token "print[incr _nextToken]" … … 1729 1729 set $var "" 1730 1730 1731 set controls $_downloadPopup(image_controls) 1731 set controls $_downloadPopup(image_controls) 1732 1732 set combo $controls.size 1733 1733 set size [$combo translate [$combo value]] … … 1751 1751 # Setup an automatic timeout procedure. 1752 1752 $_dispatcher dispatch $this !pngtimeout "set $var {} ; list" 1753 1753 1754 1754 set popup .molvisviewerimagedownload 1755 1755 if { ![winfo exists $popup] } { … … 1765 1765 1,0 $inner.please -anchor w \ 1766 1766 1,1 $inner.icon -anchor e \ 1767 2,0 $inner.cancel -cspan 2 1768 blt::table configure $inner r0 -pady 4 1769 blt::table configure $inner r2 -pady 4 1767 2,0 $inner.cancel -cspan 2 1768 blt::table configure $inner r0 -pady 4 1769 blt::table configure $inner r2 -pady 4 1770 1770 bind $inner.cancel <Return> [list $inner.cancel invoke] 1771 1771 bind $inner.cancel <KP_Enter> [list $inner.cancel invoke] … … 1775 1775 set combo $controls.bgcolor 1776 1776 set bgcolor [$combo translate [$combo value]] 1777 1777 1778 1778 $_dispatcher event -after 60000 !pngtimeout 1779 1779 WaitIcon start $inner.icon 1780 1780 grab set $inner 1781 1781 focus $inner.cancel 1782 1782 1783 1783 ServerCmd "print $token $width $height $bgcolor" 1784 1784 1785 1785 $popup activate $widget below 1786 # We wait here for either 1787 # 1) the png to be delivered or 1788 # 2) timeout or 1786 # We wait here for either 1787 # 1) the png to be delivered or 1788 # 2) timeout or 1789 1789 # 3) user cancels the operation. 1790 1790 tkwait variable $var … … 1826 1826 # 1827 1827 # Used internally to change the molecular atom scale used to render 1828 # our scene. 1829 # 1830 # Note: Only sets the specified radius for active models. If the model 1828 # our scene. 1829 # 1830 # Note: Only sets the specified radius for active models. If the model 1831 1831 # is inactive, then it overridden with the value "0.1". 1832 1832 # ---------------------------------------------------------------------- … … 1864 1864 # our scene. 1865 1865 # 1866 # Note: Only sets the specified radius for active models. If the model 1866 # Note: Only sets the specified radius for active models. If the model 1867 1867 # is inactive, then it overridden with the value "0.25". 1868 1868 # ---------------------------------------------------------------------- … … 1900 1900 # our scene. 1901 1901 # 1902 # Note: Only sets the specified transparency for active models. If the model 1902 # Note: Only sets the specified transparency for active models. If the model 1903 1903 # is inactive, then it overridden with the value "0.75". 1904 1904 # ---------------------------------------------------------------------- … … 1971 1971 # ---------------------------------------------------------------------- 1972 1972 itcl::body Rappture::MolvisViewer::CartoonTrace {option {models "all"}} { 1973 array unset _imagecache 1973 array unset _imagecache 1974 1974 set trace $_settings($this-cartoontrace) 1975 1975 if { $option == "update" } { … … 1996 1996 1997 1997 itcl::body Rappture::MolvisViewer::AddImageControls { inner widget } { 1998 label $inner.size_l -text "Size:" -font "Arial 9" 1998 label $inner.size_l -text "Size:" -font "Arial 9" 1999 1999 set _downloadPopup(image_controls) $inner 2000 2000 set img $_image(plot) … … 2006 2006 "highquality" "High Quality (2400x2400)" 2007 2007 2008 label $inner.bgcolor_l -text "Background:" -font "Arial 9" 2008 label $inner.bgcolor_l -text "Background:" -font "Arial 9" 2009 2009 Rappture::Combobox $inner.bgcolor -width 30 -editable no 2010 2010 $inner.bgcolor choices insert end \ 2011 2011 "black" "Black" \ 2012 2012 "white" "White" \ 2013 "none" "Transparent (PNG only)" 2014 2015 label $inner.format_l -text "Format:" -font "Arial 9" 2013 "none" "Transparent (PNG only)" 2014 2015 label $inner.format_l -text "Format:" -font "Arial 9" 2016 2016 Rappture::Combobox $inner.format -width 30 -editable no 2017 2017 $inner.format choices insert end \ … … 2034 2034 blt::table $f \ 2035 2035 0,0 $f.ok \ 2036 0,1 $f.cancel 2036 0,1 $f.cancel 2037 2037 2038 2038 blt::table $inner \ … … 2048 2048 $inner.bgcolor value "Black" 2049 2049 $inner.size value "Draft (400x400)" 2050 $inner.format value "PNG (Portable Network Graphics format)" 2050 $inner.format value "PNG (Portable Network Graphics format)" 2051 2051 } 2052 2052 … … 2055 2055 set w [image width $_image(plot)] 2056 2056 set h [image height $_image(plot)] 2057 } 2057 } 2058 2058 set tag "$_state(client),$_rocker(client)" 2059 2059 if { $_image(id) != "$tag" } { … … 2122 2122 } 2123 2123 2124 # Scale and translate points 2124 # Scale and translate points 2125 2125 for { set i 0 } { $i < 8 } { incr i } { 2126 2126 point${i} expr "(point${i} * scale) + origin" -
branches/uq/gui/scripts/nanovisviewer.tcl
r4798 r5121 1 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 2 2 3 # ---------------------------------------------------------------------- 3 4 # COMPONENT: nanovisviewer - 3D volume rendering … … 75 76 public method isconnected {} 76 77 public method limits { tf } 78 public method overmarker { m x } 77 79 public method parameters {title args} { 78 80 # do nothing 79 81 } 82 public method rmdupmarker { m x } 80 83 public method scale {args} 81 public method updateTransferFunctions {} 84 public method updatetransferfuncs {} 85 86 protected method Connect {} 87 protected method CurrentDatasets {{what -all}} 88 protected method Disconnect {} 89 protected method DoResize {} 90 protected method FixLegend {} 91 protected method AdjustSetting {what {value ""}} 92 protected method InitSettings { args } 93 protected method Pan {option x y} 94 protected method Rebuild {} 95 protected method ReceiveData { args } 96 protected method ReceiveImage { args } 97 protected method ReceiveLegend { tf vmin vmax size } 98 protected method Rotate {option x y} 99 protected method SendTransferFuncs {} 100 protected method Slice {option args} 101 protected method SlicerTip {axis} 102 protected method Zoom {option} 82 103 83 104 # The following methods are only used by this class. 84 85 private method AddNewMarker { x y } 86 private method AdjustSetting {what {value ""}} 105 private method AddIsoMarker { x y } 87 106 private method BuildCameraTab {} 88 107 private method BuildCutplanesTab {} 89 108 private method BuildViewTab {} 90 private method BuildVolumeComponents {}91 109 private method BuildVolumeTab {} 92 private method ComputeAlphamap { cname } 93 private method ComputeTransferFunction { cname } 94 private method Connect {} 95 private method CurrentDatasets {{what -all}} 96 private method Disconnect {} 97 private method DoResize {} 98 private method DrawLegend { cname } 99 private method EventuallyRedrawLegend { } 110 private method ResetColormap { color } 111 private method ComputeTransferFunc { tf } 100 112 private method EventuallyResize { w h } 101 private method FixLegend {} 102 private method GetAlphamap { cname color } 103 private method GetColormap { cname color } 104 private method GetDatasetsWithComponent { cname } 113 private method EventuallyResizeLegend { } 114 private method NameTransferFunc { dataobj comp } 115 private method PanCamera {} 116 private method ParseLevelsOption { tf levels } 117 private method ParseMarkersOption { tf markers } 118 private method volume { tag name } 105 119 private method GetVolumeInfo { w } 106 private method HideAllMarkers {}107 private method InitComponentSettings { cname }108 private method InitSettings { args }109 private method NameToAlphamap { name }110 private method NameTransferFunction { dataobj comp }111 private method Pan {option x y}112 private method PanCamera {}113 private method ParseLevelsOption { cname levels }114 private method ParseMarkersOption { cname markers }115 private method Rebuild {}116 private method ReceiveData { args }117 private method ReceiveImage { args }118 private method ReceiveLegend { tf vmin vmax size }119 private method RemoveMarker { x y }120 private method ResetColormap { cname color }121 private method Rotate {option x y}122 private method SendTransferFunctions {}123 private method SetObjectStyle { dataobj cname }124 120 private method SetOrientation { side } 125 private method Slice {option args}126 private method SlicerTip {axis}127 private method SwitchComponent { cname }128 private method ToggleVolume { tag name }129 private method Zoom {option}130 private method ViewToQuaternion {} {131 return [list $_view(-qw) $_view(-qx) $_view(-qy) $_view(-qz)]132 }133 121 134 122 private variable _arcball "" 135 123 136 124 private variable _dlist "" ;# list of data objects 125 private variable _allDataObjs 137 126 private variable _obj2ovride ;# maps dataobj => style override 138 127 private variable _serverDatasets ;# contains all the dataobj-component 139 128 ;# to volumes in the server 140 private variable _recvdDatasets; # list of data objs to send to server 141 private variable _dataset2style; # maps dataobj-component to transfunc 142 private variable _style2datasets; # maps tf back to list of 143 # dataobj-components using the tf. 144 145 private variable _reset 1; # Connection to server has been reset. 146 private variable _click; # Info used for rotate operations. 147 private variable _limits; # Autoscale min/max for all axes 148 private variable _view; # View params for 3D view 149 private variable _parsedFunction 150 private variable _transferFunctionEditors 151 private variable _settings 152 private variable _alphamap 153 private variable _widget 154 155 private variable _first "" ; # This is the topmost volume. 156 private variable _current ""; # Currently selected component 157 private variable _volcomponents ; # Array of components found 158 private variable _componentsList ; # Array of components found 159 private variable _cname2style 160 private variable _cname2transferFunction 161 private variable _cname2defaultcolormap 162 private variable _cname2defaultalphamap 163 129 private variable _serverTfs ;# contains all the transfer functions 130 ;# in the server. 131 private variable _recvdDatasets ;# list of data objs to send to server 132 private variable _dataset2style ;# maps dataobj-component to transfunc 133 private variable _style2datasets ;# maps tf back to list of 134 # dataobj-components using the tf. 135 136 private variable _reset 1; # Connection to server has been reset 137 private variable _click ;# info used for rotate operations 138 private variable _limits ;# autoscale min/max for all axes 139 private variable _view ;# view params for 3D view 140 private variable _isomarkers ;# array of isosurface level values 0..1 141 private variable _settings 142 # Array of transfer functions in server. If 0 the transfer has been 143 # defined but not loaded. If 1 the transfer function has been named 144 # and loaded. 145 private variable _activeTfs 146 private variable _first "" ;# This is the topmost volume. 147 148 # This 149 # indicates which isomarkers and transfer 150 # function to use when changing markers, 151 # opacity, or thickness. 164 152 common _downloadPopup ;# download options from popup 165 153 private common _hardcopy … … 188 176 $_dispatcher register !send_transfunc 189 177 $_dispatcher dispatch $this !send_transfunc \ 190 "[itcl::code $this SendTransferFunc tions]; list"178 "[itcl::code $this SendTransferFuncs]; list" 191 179 192 180 # Rebuild event … … 207 195 # Initialize the view to some default parameters. 208 196 array set _view { 209 -qw 0.853553210 -qx -0.353553211 -qy 0.353553212 -qz 0.146447213 -xpan0214 -ypan 0215 -zoom 1.0197 qw 0.853553 198 qx -0.353553 199 qy 0.353553 200 qz 0.146447 201 zoom 1.0 202 xpan 0 203 ypan 0 216 204 } 217 205 set _arcball [blt::arcball create 100 100] 218 $_arcball quaternion [ViewToQuaternion] 219 220 set _limits(v) [list 0.0 1.0] 206 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 207 $_arcball quaternion $q 208 209 set _limits(vmin) 0.0 210 set _limits(vmax) 1.0 221 211 set _reset 1 222 212 223 array set _settings { 224 -axesvisible 1 225 -background black 226 -colormap "default" 227 -cutplanesvisible 0 228 -gridvisible 0 229 -isosurfaceshading 0 230 -legendvisible 1 231 -light 40 232 -light2side 1 233 -outlinevisible 0 234 -qw 0.853553 235 -qx -0.353553 236 -qy 0.353553 237 -qz 0.146447 238 -thickness 350 239 -volume 1 240 -volumeopacity 0.5 241 -volumevisible 1 242 -xcutplaneposition 50 243 -xcutplanevisible 1 244 -xpan 0 245 -ycutplaneposition 50 246 -ycutplanevisible 1 247 -ypan 0 248 -zcutplaneposition 50 249 -zcutplanevisible 1 250 -zoom 1.0 251 } 252 array set _widget { 253 -volumeopacity 50 254 } 213 array set _settings [subst { 214 $this-qw $_view(qw) 215 $this-qx $_view(qx) 216 $this-qy $_view(qy) 217 $this-qz $_view(qz) 218 $this-zoom $_view(zoom) 219 $this-xpan $_view(xpan) 220 $this-ypan $_view(ypan) 221 $this-volume 1 222 $this-xcutplane 0 223 $this-xcutposition 0 224 $this-ycutplane 0 225 $this-ycutposition 0 226 $this-zcutplane 0 227 $this-zcutposition 0 228 }] 229 255 230 itk_component add 3dview { 256 231 label $itk_component(plotarea).view -image $_image(plot) \ … … 273 248 } 274 249 pack $itk_component(reset) -side top -padx 2 -pady 2 275 Rappture::Tooltip::for $itk_component(reset) \ 276 "Reset the view to the default zoom level" 250 Rappture::Tooltip::for $itk_component(reset) "Reset the view to the default zoom level" 277 251 278 252 itk_component add zoomin { … … 304 278 -onimage [Rappture::icon volume-on] \ 305 279 -offimage [Rappture::icon volume-off] \ 306 -command [itcl::code $this AdjustSetting -volume] \307 -variable [itcl::scope _settings( -volume)]280 -command [itcl::code $this AdjustSetting volume] \ 281 -variable [itcl::scope _settings($this-volume)] 308 282 } 309 283 $itk_component(volume) select … … 311 285 "Toggle the volume cloud on/off" 312 286 pack $itk_component(volume) -padx 2 -pady 2 313 314 itk_component add cutplane {315 Rappture::PushButton $f.cutplane \316 -onimage [Rappture::icon cutbutton] \317 -offimage [Rappture::icon cutbutton] \318 -variable [itcl::scope _settings(-cutplanesvisible)] \319 -command [itcl::code $this AdjustSetting -cutplanesvisible]320 }321 Rappture::Tooltip::for $itk_component(cutplane) \322 "Show/Hide cutplanes"323 pack $itk_component(cutplane) -padx 2 -pady 2324 287 325 288 if { [catch { … … 334 297 335 298 # Legend 299 336 300 set _image(legend) [image create photo] 337 301 itk_component add legend { … … 343 307 } 344 308 bind $itk_component(legend) <Configure> \ 345 [itcl::code $this EventuallyRedrawLegend] 346 bind $itk_component(legend) <KeyPress-Delete> \ 347 [itcl::code $this RemoveMarker %x %y] 348 bind $itk_component(legend) <Enter> \ 349 [list focus $itk_component(legend)] 309 [itcl::code $this EventuallyResizeLegend] 350 310 351 311 # Hack around the Tk panewindow. The problem is that the requested … … 426 386 image delete $_image(legend) 427 387 image delete $_image(download) 428 foreach name [array names _transferFunctionEditors] {429 itcl::delete object $_transferFunctionEditors($cname)430 }431 388 catch { blt::arcball destroy $_arcball } 432 array unset _settings 389 array unset _settings $this-* 433 390 } 434 391 … … 462 419 if {$pos < 0} { 463 420 lappend _dlist $dataobj 421 set _allDataObjs($dataobj) 1 464 422 set _obj2ovride($dataobj-color) $params(-color) 465 423 set _obj2ovride($dataobj-width) $params(-width) … … 538 496 if { $pos >= 0 } { 539 497 set _dlist [lreplace $_dlist $pos $pos] 498 array unset _limits $dataobj* 540 499 array unset _obj2ovride $dataobj-* 541 array unset _dataset2style $dataobj-*542 500 set changed 1 543 501 } … … 559 517 # ---------------------------------------------------------------------- 560 518 itcl::body Rappture::NanovisViewer::scale {args} { 561 array set styles { 562 -color BCGYR 563 -levels 6 564 -markers "" 565 } 566 array unset _limits 567 array unset _volcomponents 519 foreach val {xmin xmax ymin ymax zmin zmax vmin vmax} { 520 set _limits($val) "" 521 } 568 522 foreach dataobj $args { 569 523 if { ![$dataobj isvalid] } { 570 524 continue; # Object doesn't contain valid data. 571 525 } 572 foreach cname [$dataobj components] {573 if { ![info exists _volcomponents($cname)] } {574 lappend _componentsList $cname575 array set styles [lindex [$dataobj components -style $cname] 0]576 set cmap [ColorsToColormap $styles(-color)]577 set _cname2defaultcolormap($cname) $cmap578 set _settings($cname-colormap) $styles(-color)579 }580 lappend _volcomponents($cname) $dataobj-$cname581 array unset limits582 array set limits [$dataobj valueLimits $cname]583 set _limits($cname) $limits(v)584 }585 526 foreach axis {x y z v} { 586 527 foreach { min max } [$dataobj limits $axis] break 587 528 if {"" != $min && "" != $max} { 588 if { ![info exists _limits($axis)] } { 589 set _limits($axis) [list $min $max] 529 if {"" == $_limits(${axis}min)} { 530 set _limits(${axis}min) $min 531 set _limits(${axis}max) $max 590 532 } else { 591 foreach {amin amax} $_limits($axis) break 592 if {$min < $amin} { 593 set amin $min 533 if {$min < $_limits(${axis}min)} { 534 set _limits(${axis}min) $min 594 535 } 595 if {$max > $ amax} {596 set amax$max536 if {$max > $_limits(${axis}max)} { 537 set _limits(${axis}max) $max 597 538 } 598 set _limits($axis) [list $amin $amax]599 539 } 600 540 } 601 541 } 602 542 } 603 BuildVolumeComponents604 543 } 605 544 … … 664 603 if { $_reportClientInfo } { 665 604 # Tell the server the viewer, hub, user and session. 666 # Do this immediately on connect before buff ering any commands605 # Do this immediately on connect before buffing any commands 667 606 global env 668 607 … … 724 663 725 664 # ---------------------------------------------------------------------- 726 # USAGE: SendTransferFunctions 727 # ---------------------------------------------------------------------- 728 itcl::body Rappture::NanovisViewer::SendTransferFunctions {} { 729 foreach cname [array names _volcomponents] { 730 ComputeTransferFunction $cname 665 # USAGE: SendTransferFuncs 666 # ---------------------------------------------------------------------- 667 itcl::body Rappture::NanovisViewer::SendTransferFuncs {} { 668 if { $_first == "" } { 669 puts stderr "first not set" 670 return 671 } 672 # Ensure that the global opacity and thickness settings (in the slider 673 # settings widgets) are used for the active transfer-function. Update 674 # the values in the _settings varible. 675 set opacity [expr { double($_settings($this-opacity)) * 0.01 }] 676 # Scale values between 0.00001 and 0.01000 677 set thickness [expr {double($_settings($this-thickness)) * 0.0001}] 678 679 foreach tag [CurrentDatasets] { 680 if { ![info exists _serverDatasets($tag)] || !$_serverDatasets($tag) } { 681 # The volume hasn't reached the server yet. How did we get 682 # here? 683 puts stderr "Don't have $tag in _serverDatasets" 684 continue 685 } 686 if { ![info exists _dataset2style($tag)] } { 687 puts stderr "don't have style for volume $tag" 688 continue; # How does this happen? 689 } 690 set tf $_dataset2style($tag) 691 set _settings($this-$tf-opacity) $opacity 692 set _settings($this-$tf-thickness) $thickness 693 ComputeTransferFunc $tf 694 # FIXME: Need to the send information as to what transfer functions 695 # to update so that we only update the transfer function 696 # as necessary. Right now, all transfer functions are 697 # updated. This makes moving the isomarker slider chunky. 698 if { ![info exists _activeTfs($tf)] || !$_activeTfs($tf) } { 699 set _activeTfs($tf) 1 700 } 701 SendCmd "volume shading transfunc $tf $tag" 731 702 } 732 703 FixLegend … … 759 730 760 731 # 761 # DrawLegend -- 762 # 763 itcl::body Rappture::NanovisViewer::DrawLegend { cname } { 732 # ReceiveLegend -- 733 # 734 # The procedure is the response from the render server to each "legend" 735 # command. The server sends back a "legend" command invoked our 736 # the slave interpreter. The purpose is to collect data of the image 737 # representing the legend in the canvas. In addition, the isomarkers 738 # of the active transfer function are displayed. 739 # 740 # I don't know is this is the right place to display the isomarkers. 741 # I don't know all the different paths used to draw the plot. There's 742 # "Rebuild", "add", etc. 743 # 744 itcl::body Rappture::NanovisViewer::ReceiveLegend { tf vmin vmax size } { 745 if { ![isconnected] } { 746 return 747 } 748 set bytes [ReceiveBytes $size] 749 $_image(legend) configure -data $bytes 750 ReceiveEcho <<line "<read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>" 751 764 752 set c $itk_component(legend) 765 753 set w [winfo width $c] … … 767 755 set lx 10 768 756 set ly [expr {$h - 1}] 769 if {"" == [$c find withtag colorbar]} {757 if {"" == [$c find withtag transfunc]} { 770 758 $c create image 10 10 -anchor nw \ 771 -image $_image(legend) -tags colorbar759 -image $_image(legend) -tags transfunc 772 760 $c create text $lx $ly -anchor sw \ 773 -fill $itk_option(-plotforeground) -tags "limits textvmin"761 -fill $itk_option(-plotforeground) -tags "limits vmin" 774 762 $c create text [expr {$w-$lx}] $ly -anchor se \ 775 -fill $itk_option(-plotforeground) -tags "limits text vmax" 776 $c create text [expr {$w/2}] $ly -anchor s \ 777 -fill $itk_option(-plotforeground) -tags "limits text title" 778 $c lower colorbar 779 $c bind colorbar <ButtonRelease-1> [itcl::code $this AddNewMarker %x %y] 780 } 781 782 # Display the markers used by the current transfer function. 783 HideAllMarkers 784 $_transferFunctionEditors($cname) showMarkers $_limits($cname) 785 786 foreach {min max} $_limits($cname) break 787 $c itemconfigure vmin -text [format %g $min] 763 -fill $itk_option(-plotforeground) -tags "limits vmax" 764 $c lower transfunc 765 $c bind transfunc <ButtonRelease-1> \ 766 [itcl::code $this AddIsoMarker %x %y] 767 } 768 # Display the markers used by the active transfer function. 769 770 array set limits [limits $tf] 771 $c itemconfigure vmin -text [format %.2g $limits(min)] 788 772 $c coords vmin $lx $ly 789 773 790 $c itemconfigure vmax -text [format % g $max]774 $c itemconfigure vmax -text [format %.2g $limits(max)] 791 775 $c coords vmax [expr {$w-$lx}] $ly 792 776 793 set title [$_first hints label] 794 set units [$_first hints units] 795 if { $units != "" } { 796 set title "$title ($units)" 797 } 798 $c itemconfigure title -text $title 799 $c coords title [expr {$w/2}] $ly 777 if { [info exists _isomarkers($tf)] } { 778 foreach m $_isomarkers($tf) { 779 $m visible yes 780 } 781 } 800 782 801 783 # The colormap may have changed. Resync the slicers with the colormap. 802 InitSettings -cutplanesvisible -xcutplanevisible -ycutplanevisible \ 803 -zcutplanevisible 804 } 805 806 # 807 # 808 # ReceiveLegend -- 809 # 810 # The procedure is the response from the render server to each "legend" 811 # command. The server sends back a "legend" command invoked our 812 # the slave interpreter. The purpose is to collect data of the image 813 # representing the legend in the canvas. In addition, the 814 # active transfer function is displayed. 815 # 816 # 817 itcl::body Rappture::NanovisViewer::ReceiveLegend { cname vmin vmax size } { 818 if { ![isconnected] } { 819 return 820 } 821 set bytes [ReceiveBytes $size] 822 $_image(legend) configure -data $bytes 823 ReceiveEcho <<line "<read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>" 824 825 DrawLegend $_current 784 set datasets [CurrentDatasets -cutplanes] 785 SendCmd "volume data state $_settings($this-volume) $datasets" 786 787 # Adjust the cutplane for only the first component in the topmost volume 788 # (i.e. the first volume designated in the field). 789 set tag [lindex $datasets 0] 790 foreach axis {x y z} { 791 # Turn off cutplanes for all volumes 792 SendCmd "cutplane state 0 $axis" 793 if { $_settings($this-${axis}cutplane) } { 794 # Turn on cutplane for this particular volume and set the position 795 SendCmd "cutplane state 1 $axis $tag" 796 set pos [expr {0.01*$_settings($this-${axis}cutposition)}] 797 SendCmd "cutplane position $pos $axis $tag" 798 } 799 } 826 800 } 827 801 … … 863 837 set dataobj [lindex $parts 0] 864 838 set _serverDatasets($tag) 1 865 if { $_settings( -volumevisible) && $dataobj == $_first } {839 if { $_settings($this-volume) && $dataobj == $_first } { 866 840 SendCmd "volume state 1 $tag" 867 841 } 868 set _limits($tag) [list $info(min) $info(max)] 869 set _limits(v) [list $info(vmin) $info(vmax)] 842 set _limits($tag-min) $info(min); # Minimum value of the volume. 843 set _limits($tag-max) $info(max); # Maximum value of the volume. 844 set _limits(vmin) $info(vmin); # Overall minimum value. 845 set _limits(vmax) $info(vmax); # Overall maximum value. 870 846 871 847 unset _recvdDatasets($tag) 872 848 if { [array size _recvdDatasets] == 0 } { 873 updateTransferFunctions 849 # The active transfer function is by default the first component of 850 # the first data object. This assumes that the data is always 851 # successfully transferred. 852 updatetransferfuncs 874 853 } 875 854 } … … 895 874 StartBufferingCommands 896 875 876 # Hide all the isomarkers. Can't remove them. Have to remember the 877 # settings since the user may have created/deleted/moved markers. 878 879 foreach tf [array names _isomarkers] { 880 foreach m $_isomarkers($tf) { 881 $m visible no 882 } 883 } 884 897 885 if { $_width != $w || $_height != $h || $_reset } { 898 886 set _width $w … … 901 889 DoResize 902 890 } 903 904 891 foreach dataobj [get] { 905 892 foreach cname [$dataobj components] { … … 923 910 if { $_reportClientInfo } { 924 911 set info {} 925 lappend info "tool_id" [$dataobj hints toolId] 926 lappend info "tool_name" [$dataobj hints toolName] 927 lappend info "tool_version" [$dataobj hints toolRevision] 928 lappend info "tool_title" [$dataobj hints toolTitle] 912 lappend info "tool_id" [$dataobj hints toolid] 913 lappend info "tool_name" [$dataobj hints toolname] 914 lappend info "tool_title" [$dataobj hints tooltitle] 915 lappend info "tool_command" [$dataobj hints toolcommand] 916 lappend info "tool_revision" [$dataobj hints toolrevision] 929 917 lappend info "dataset_label" [$dataobj hints label] 930 918 lappend info "dataset_size" $nbytes … … 937 925 set _serverDatasets($tag) 0 938 926 } 939 SetObjectStyle $dataobj $cname 940 } 941 } 942 943 # Outline seems to need to be reset every update. 944 InitSettings -outlinevisible -cutplanesvisible -current 945 927 NameTransferFunc $dataobj $cname 928 } 929 } 946 930 set _first [lindex [get] 0] 947 931 if { $_reset } { … … 949 933 # Reset the camera and other view parameters 950 934 # 951 set _settings( -qw) $_view(-qw)952 set _settings( -qx) $_view(-qx)953 set _settings( -qy) $_view(-qy)954 set _settings( -qz) $_view(-qz)955 set _settings( -xpan) $_view(-xpan)956 set _settings( -ypan) $_view(-ypan)957 set _settings( -zoom) $_view(-zoom)958 959 set q [ ViewToQuaternion]935 set _settings($this-qw) $_view(qw) 936 set _settings($this-qx) $_view(qx) 937 set _settings($this-qy) $_view(qy) 938 set _settings($this-qz) $_view(qz) 939 set _settings($this-xpan) $_view(xpan) 940 set _settings($this-ypan) $_view(ypan) 941 set _settings($this-zoom) $_view(zoom) 942 943 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 960 944 $_arcball quaternion $q 961 945 SendCmd "camera orient $q" 962 946 SendCmd "camera reset" 963 947 PanCamera 964 SendCmd "camera zoom $_view(-zoom)" 948 SendCmd "camera zoom $_view(zoom)" 949 InitSettings light2side light transp isosurface grid axes 965 950 966 #cutplane state 0 all967 951 foreach axis {x y z} { 968 952 # Turn off cutplanes for all volumes 969 953 SendCmd "cutplane state 0 $axis" 970 954 } 971 972 InitSettings -light2side -light -volumeopacity \973 -isosurfaceshading -gridvisible -axesvisible \974 975 955 if {"" != $_first} { 976 956 set axis [$_first hints updir] … … 984 964 } 985 965 } 986 966 # Outline seems to need to be reset every update. 967 InitSettings outline 987 968 # nothing to send -- activate the proper ivol 988 969 SendCmd "volume state 0" … … 996 977 set cname [lindex [$_first components] 0] 997 978 if { [info exists _serverDatasets($_first-$cname)] } { 998 update TransferFunctions979 updatetransferfuncs 999 980 } 1000 981 } … … 1022 1003 set tag $_first-$cname 1023 1004 if { [info exists _serverDatasets($tag)] && $_serverDatasets($tag) } { 1024 array set style s{1005 array set style { 1025 1006 -cutplanes 1 1026 1007 } 1027 array set style s[lindex [$_first components -style $cname] 0]1028 if { $what != "-cutplanes" || $style s(-cutplanes) } {1008 array set style [lindex [$_first components -style $cname] 0] 1009 if { $what != "-cutplanes" || $style(-cutplanes) } { 1029 1010 lappend rlist $tag 1030 1011 } … … 1045 1026 switch -- $option { 1046 1027 "in" { 1047 set _view( -zoom) [expr {$_view(-zoom)*1.25}]1048 set _settings( -zoom) $_view(-zoom)1049 SendCmd "camera zoom $_view( -zoom)"1028 set _view(zoom) [expr {$_view(zoom)*1.25}] 1029 set _settings($this-zoom) $_view(zoom) 1030 SendCmd "camera zoom $_view(zoom)" 1050 1031 } 1051 1032 "out" { 1052 set _view( -zoom) [expr {$_view(-zoom)*0.8}]1053 set _settings( -zoom) $_view(-zoom)1054 SendCmd "camera zoom $_view( -zoom)"1033 set _view(zoom) [expr {$_view(zoom)*0.8}] 1034 set _settings($this-zoom) $_view(zoom) 1035 SendCmd "camera zoom $_view(zoom)" 1055 1036 } 1056 1037 "reset" { 1057 1038 array set _view { 1058 -qw 0.8535531059 -qx -0.3535531060 -qy 0.3535531061 -qz 0.1464471062 -xpan01063 -ypan01064 -zoom 1.01039 qw 0.853553 1040 qx -0.353553 1041 qy 0.353553 1042 qz 0.146447 1043 zoom 1.0 1044 xpan 0 1045 ypan 0 1065 1046 } 1066 1047 if { $_first != "" } { … … 1070 1051 } 1071 1052 } 1072 set q [ ViewToQuaternion]1053 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 1073 1054 $_arcball quaternion $q 1074 1055 SendCmd "camera orient $q" 1075 1056 SendCmd "camera reset" 1076 set _settings( -qw) $_view(-qw)1077 set _settings( -qx) $_view(-qx)1078 set _settings( -qy) $_view(-qy)1079 set _settings( -qz) $_view(-qz)1080 set _settings( -xpan) $_view(-xpan)1081 set _settings( -ypan) $_view(-ypan)1082 set _settings( -zoom) $_view(-zoom)1057 set _settings($this-qw) $_view(qw) 1058 set _settings($this-qx) $_view(qx) 1059 set _settings($this-qy) $_view(qy) 1060 set _settings($this-qz) $_view(qz) 1061 set _settings($this-xpan) $_view(xpan) 1062 set _settings($this-ypan) $_view(ypan) 1063 set _settings($this-zoom) $_view(zoom) 1083 1064 } 1084 1065 } … … 1086 1067 1087 1068 itcl::body Rappture::NanovisViewer::PanCamera {} { 1088 set x $_view(-xpan) 1089 set y $_view(-ypan) 1069 #set x [expr ($_view(xpan)) / $_limits(xrange)] 1070 #set y [expr ($_view(ypan)) / $_limits(yrange)] 1071 set x $_view(xpan) 1072 set y $_view(ypan) 1090 1073 SendCmd "camera pan $x $y" 1091 1074 } … … 1126 1109 1127 1110 set q [$_arcball rotate $x $y $_click(x) $_click(y)] 1128 foreach { _view( -qw) _view(-qx) _view(-qy) _view(-qz) } $q break1129 set _settings( -qw) $_view(-qw)1130 set _settings( -qx) $_view(-qx)1131 set _settings( -qy) $_view(-qy)1132 set _settings( -qz) $_view(-qz)1111 foreach { _view(qw) _view(qx) _view(qy) _view(qz) } $q break 1112 set _settings($this-qw) $_view(qw) 1113 set _settings($this-qx) $_view(qx) 1114 set _settings($this-qy) $_view(qy) 1115 set _settings($this-qz) $_view(qz) 1133 1116 SendCmd "camera orient $q" 1134 1117 … … 1163 1146 set x [expr $x / double($w)] 1164 1147 set y [expr $y / double($h)] 1165 set _view( -xpan) [expr $_view(-xpan) + $x]1166 set _view( -ypan) [expr $_view(-ypan) + $y]1148 set _view(xpan) [expr $_view(xpan) + $x] 1149 set _view(ypan) [expr $_view(ypan) + $y] 1167 1150 PanCamera 1168 set _settings( -xpan) $_view(-xpan)1169 set _settings( -ypan) $_view(-ypan)1151 set _settings($this-xpan) $_view(xpan) 1152 set _settings($this-ypan) $_view(ypan) 1170 1153 return 1171 1154 } … … 1180 1163 set _click(x) $x 1181 1164 set _click(y) $y 1182 set _view( -xpan) [expr $_view(-xpan) - $dx]1183 set _view( -ypan) [expr $_view(-ypan) - $dy]1165 set _view(xpan) [expr $_view(xpan) - $dx] 1166 set _view(ypan) [expr $_view(ypan) - $dy] 1184 1167 PanCamera 1185 set _settings( -xpan) $_view(-xpan)1186 set _settings( -ypan) $_view(-ypan)1168 set _settings($this-xpan) $_view(xpan) 1169 set _settings($this-ypan) $_view(ypan) 1187 1170 } 1188 1171 if { $option == "release" } { … … 1216 1199 } 1217 1200 switch -- $what { 1218 "-axesvisible" { 1219 SendCmd "axis visible $_settings($what)" 1220 } 1221 "-background" { 1222 set bgcolor [$itk_component(background) value] 1223 array set fgcolors { 1224 "black" "white" 1225 "white" "black" 1226 "grey" "black" 1227 } 1228 configure -plotbackground $bgcolor \ 1229 -plotforeground $fgcolors($bgcolor) 1230 DrawLegend $_current 1231 } 1232 "-colormap" { 1201 light { 1202 set val $_settings($this-light) 1203 set diffuse [expr {0.01*$val}] 1204 set ambient [expr {1.0-$diffuse}] 1205 set specularLevel 0.3 1206 set specularExp 90.0 1207 SendCmd "volume shading ambient $ambient" 1208 SendCmd "volume shading diffuse $diffuse" 1209 SendCmd "volume shading specularLevel $specularLevel" 1210 SendCmd "volume shading specularExp $specularExp" 1211 } 1212 light2side { 1213 set val $_settings($this-light2side) 1214 SendCmd "volume shading light2side $val" 1215 } 1216 transp { 1217 set val $_settings($this-transp) 1218 set sval [expr { 0.01 * double($val) }] 1219 SendCmd "volume shading opacity $sval" 1220 } 1221 opacity { 1222 set val $_settings($this-opacity) 1223 set sval [expr { 0.01 * double($val) }] 1224 foreach tf [array names _activeTfs] { 1225 set _settings($this-$tf-opacity) $sval 1226 set _activeTfs($tf) 0 1227 } 1228 updatetransferfuncs 1229 } 1230 thickness { 1231 if { [array names _activeTfs] > 0 } { 1232 set val $_settings($this-thickness) 1233 # Scale values between 0.00001 and 0.01000 1234 set sval [expr {0.0001*double($val)}] 1235 foreach tf [array names _activeTfs] { 1236 set _settings($this-$tf-thickness) $sval 1237 set _activeTfs($tf) 0 1238 } 1239 updatetransferfuncs 1240 } 1241 } 1242 "outline" { 1243 SendCmd "volume outline state $_settings($this-outline)" 1244 } 1245 "isosurface" { 1246 SendCmd "volume shading isosurface $_settings($this-isosurface)" 1247 } 1248 "colormap" { 1233 1249 set color [$itk_component(colormap) value] 1234 set _settings($what) $color 1235 set _settings($_current${what}) $color 1236 ResetColormap $_current $color 1237 } 1238 "-current" { 1239 set cname [$itk_component(volcomponents) value] 1240 SwitchComponent $cname 1241 } 1242 "-cutplanesvisible" { 1243 set bool $_settings($what) 1244 # We only set cutplanes on the first dataset. 1245 set datasets [CurrentDatasets -cutplanes] 1246 set tag [lindex $datasets 0] 1247 if { $bool } { 1248 foreach axis { x y z } { 1249 if { $_settings(-${axis}cutplanevisible) } { 1250 SendCmd "cutplane state 1 $axis $tag" 1251 } 1252 } 1253 } else { 1254 foreach axis { x y z } { 1255 SendCmd "cutplane state 0 $axis $tag" 1256 } 1257 } 1258 } 1259 "-gridvisible" { 1260 SendCmd "grid visible $_settings($what)" 1261 } 1262 "-isosurfaceshading" { 1263 SendCmd "volume shading isosurface $_settings($what)" 1264 } 1265 "-legendvisible" { 1266 if { $_settings($what) } { 1250 set _settings(colormap) $color 1251 # Only set the colormap on the first volume. Ignore the others. 1252 #ResetColormap $color 1253 } 1254 "grid" { 1255 SendCmd "grid visible $_settings($this-grid)" 1256 } 1257 "axes" { 1258 SendCmd "axis visible $_settings($this-axes)" 1259 } 1260 "legend" { 1261 if { $_settings($this-legend) } { 1267 1262 blt::table $itk_component(plotarea) \ 1268 1263 0,0 $itk_component(3dview) -fill both \ … … 1273 1268 } 1274 1269 } 1275 "-light" { 1276 set _settings($_current${what}) $_settings($what) 1277 set val $_settings($what) 1278 set diffuse [expr {0.01*$val}] 1279 set ambient [expr {1.0-$diffuse}] 1280 set specularLevel 0.3 1281 set specularExp 90.0 1282 foreach tag [GetDatasetsWithComponent $_current] { 1283 SendCmd "volume shading ambient $ambient $tag" 1284 SendCmd "volume shading diffuse $diffuse $tag" 1285 SendCmd "volume shading specularLevel $specularLevel $tag" 1286 SendCmd "volume shading specularExp $specularExp $tag" 1287 } 1288 } 1289 "-light2side" { 1290 set _settings($_current${what}) $_settings($what) 1291 set val $_settings($what) 1292 foreach tag [GetDatasetsWithComponent $_current] { 1293 SendCmd "volume shading light2side $val $tag" 1294 } 1295 } 1296 "-outlinevisible" { 1297 SendCmd "volume outline state $_settings($what)" 1298 } 1299 "-thickness" { 1300 set val $_settings($what) 1301 set _settings($_current${what}) $val 1302 updateTransferFunctions 1303 } 1304 "-volume" { 1305 # This is the global volume visibility control. It controls the 1306 # visibility of all the all volumes. Whenever it's changed, you 1307 # have to synchronize each of the local controls (see below) with 1308 # this. 1309 set datasets [CurrentDatasets] 1310 set bool $_settings($what) 1311 SendCmd "volume data state $bool $datasets" 1312 foreach cname $_componentsList { 1313 set _settings($cname-volumevisible) $bool 1314 } 1315 set _settings(-volumevisible) $bool 1316 } 1317 "-volumeopacity" { 1318 set _settings($what) [expr $_widget($what) * 0.01] 1319 set _settings($_current${what}) $_settings($what) 1320 1321 foreach {cmap wmap} $_cname2transferFunction($_current) break 1322 set wmap [ComputeAlphamap $_current] 1323 set _cname2transferFunction($_current) [list $cmap $wmap] 1324 SendCmd [list transfunc define $_current $cmap $wmap] 1325 } 1326 "-volumevisible" { 1327 # This is the component specific control. It changes the 1328 # visibility of only the current component. 1329 set _settings($_current${what}) $_settings($what) 1330 foreach tag [GetDatasetsWithComponent $_current] { 1331 SendCmd "volume data state $_settings($what) $tag" 1332 } 1333 } 1334 "-xcutplanevisible" - "-ycutplanevisible" - "-zcutplanevisible" { 1335 set axis [string range $what 1 1] 1336 set bool $_settings($what) 1337 # We only set cutplanes on the first dataset. 1270 "volume" { 1271 set datasets [CurrentDatasets -cutplanes] 1272 SendCmd "volume data state $_settings($this-volume) $datasets" 1273 } 1274 "xcutplane" - "ycutplane" - "zcutplane" { 1275 set axis [string range $what 0 0] 1276 set bool $_settings($this-$what) 1338 1277 set datasets [CurrentDatasets -cutplanes] 1339 1278 set tag [lindex $datasets 0] 1340 if { $_settings(-cutplanesvisible) } { 1341 SendCmd "cutplane state $bool $axis $tag" 1342 } 1279 SendCmd "cutplane state $bool $axis $tag" 1343 1280 if { $bool } { 1344 1281 $itk_component(${axis}CutScale) configure -state normal \ … … 1367 1304 set w [expr {$_width-20}] 1368 1305 set h [expr {[winfo height $itk_component(legend)]-20-$lineht}] 1369 if {$w > 0 && $h > 0 && $_first != "" } { 1370 if { [info exists _cname2transferFunction($_current)] } { 1371 SendCmd "legend $_current $w $h" 1372 } 1373 } 1374 } 1375 1376 # 1377 # NameTransferFunction -- 1306 if {$w > 0 && $h > 0 && [array names _activeTfs] > 0 && $_first != "" } { 1307 set tag [lindex [CurrentDatasets] 0] 1308 if { [info exists _dataset2style($tag)] } { 1309 SendCmd "legend $_dataset2style($tag) $w $h" 1310 } 1311 } else { 1312 # Can't do this as this will remove the items associated with the 1313 # isomarkers. 1314 1315 #$itk_component(legend) delete all 1316 } 1317 } 1318 1319 # 1320 # NameTransferFunc -- 1378 1321 # 1379 1322 # Creates a transfer function name based on the <style> settings in the … … 1383 1326 # server parses the 3D data and sends back the limits via ReceiveData.] 1384 1327 # 1385 itcl::body Rappture::NanovisViewer::NameTransferFunction { dataobj cname } { 1386 array set styles { 1328 # FIXME: The current way we generate transfer-function names completely 1329 # ignores the -markers option. The problem is that we are forced 1330 # to compute the name from an increasing complex set of values: 1331 # color, levels, marker, opacity. I think we're stuck doing it 1332 # now. 1333 # 1334 itcl::body Rappture::NanovisViewer::NameTransferFunc { dataobj cname } { 1335 array set style { 1387 1336 -color BCGYR 1388 1337 -levels 6 1338 -opacity 1.0 1389 1339 -markers "" 1390 1340 } 1391 1341 set tag $dataobj-$cname 1392 array set styles [lindex [$dataobj components -style $cname] 0] 1393 if { ![info exists _cname2transferFunction($cname)] } { 1394 # Get the colormap right now, since it doesn't change with marker 1395 # changes. 1396 set cmap [ColorsToColormap $styles(-color)] 1397 set wmap [list 0.0 0.0 1.0 1.0] 1398 set _cname2transferFunction($cname) [list $cmap $wmap] 1399 SendCmd [list transfunc define $cname $cmap $wmap] 1400 } 1401 SendCmd "volume shading transfunc $cname $tag" 1402 if { ![info exists _transferFunctionEditors($cname)] } { 1403 set _transferFunctionEditors($cname) \ 1404 [Rappture::TransferFunctionEditor ::\#auto $itk_component(legend) \ 1405 $cname \ 1406 -command [itcl::code $this updateTransferFunctions]] 1407 } 1408 set _dataset2style($tag) $cname 1409 lappend _style2datasets($cname) $tag 1410 return $cname 1411 } 1412 1413 # 1414 # ComputeTransferFunction -- 1415 # 1416 # Computes and sends the transfer function to the render server. It's 1417 # assumed that the volume data limits are known and that the global 1418 # transfer-functions slider values have been set up. Both parts are 1419 # needed to compute the relative value (location) of the marker, and 1420 # the alpha map of the transfer function. 1421 # 1422 itcl::body Rappture::NanovisViewer::ComputeTransferFunction { cname } { 1423 foreach {cmap wmap} $_cname2transferFunction($cname) break 1342 array set style [lindex [$dataobj components -style $cname] 0] 1343 set tf "$style(-color):$style(-levels):$style(-opacity)" 1344 set _dataset2style($tag) $tf 1345 lappend _style2datasets($tf) $tag 1346 return $tf 1347 } 1348 1349 # 1350 # ComputeTransferFunc -- 1351 # 1352 # Computes and sends the transfer function to the render server. It's 1353 # assumed that the volume data limits are known and that the global 1354 # transfer-functions slider values have been set up. Both parts are 1355 # needed to compute the relative value (location) of the marker, and 1356 # the alpha map of the transfer function. 1357 # 1358 itcl::body Rappture::NanovisViewer::ComputeTransferFunc { tf } { 1359 array set style { 1360 -color BCGYR 1361 -levels 6 1362 -opacity 1.0 1363 -markers "" 1364 } 1365 1366 foreach {dataobj cname} [split [lindex $_style2datasets($tf) 0] -] break 1367 array set style [lindex [$dataobj components -style $cname] 0] 1424 1368 1425 1369 # We have to parse the style attributes for a volume using this … … 1429 1373 # of the volumes (the first in the list) using the transfer-function as a 1430 1374 # reference. 1431 if { ![info exists _parsedFunction($cname)] } { 1432 array set styles { 1433 -color BCGYR 1434 -levels 6 1435 -markers "" 1436 } 1437 # Accumulate the style from all the datasets using it. 1438 foreach tag [GetDatasetsWithComponent $cname] { 1439 foreach {dataobj cname} [split [lindex $tag 0] -] break 1440 array set styles [lindex [$dataobj components -style $cname] 0] 1441 } 1442 eval $_transferFunctionEditors($cname) limits $_limits($cname) 1375 # 1376 # FIXME: The current way we generate transfer-function names completely 1377 # ignores the -markers option. The problem is that we are forced 1378 # to compute the name from an increasing complex set of values: 1379 # color, levels, marker, opacity. I think the cow's out of the 1380 # barn on this one. 1381 1382 if { ![info exists _isomarkers($tf)] } { 1443 1383 # Have to defer creation of isomarkers until we have data limits 1444 if { [info exists style s(-markers)] &&1445 [llength $style s(-markers)] > 0 } {1446 ParseMarkersOption $ cname $styles(-markers)1384 if { [info exists style(-markers)] && 1385 [llength $style(-markers)] > 0 } { 1386 ParseMarkersOption $tf $style(-markers) 1447 1387 } else { 1448 ParseLevelsOption $cname $styles(-levels) 1449 } 1450 1451 } 1452 set wmap [ComputeAlphamap $cname] 1453 set _cname2transferFunction($cname) [list $cmap $wmap] 1454 SendCmd [list transfunc define $cname $cmap $wmap] 1455 } 1456 1457 itcl::body Rappture::NanovisViewer::AddNewMarker { x y } { 1458 if { ![info exists _transferFunctionEditors($_current)] } { 1459 continue 1460 } 1461 # Add a new marker to the current transfer function 1462 $_transferFunctionEditors($_current) newMarker $x $y normal 1463 $itk_component(legend) itemconfigure labels -fill $itk_option(-plotforeground) 1464 } 1465 1466 itcl::body Rappture::NanovisViewer::RemoveMarker { x y } { 1467 if { ![info exists _transferFunctionEditors($_current)] } { 1468 continue 1469 } 1470 # Add a new marker to the current transfer function 1471 $_transferFunctionEditors($_current) deleteMarker $x $y 1388 ParseLevelsOption $tf $style(-levels) 1389 } 1390 } 1391 set cmap [ColorsToColormap $style(-color)] 1392 set tag $this-$tf 1393 if { ![info exists _settings($tag-opacity)] } { 1394 set _settings($tag-opacity) $style(-opacity) 1395 } 1396 set max 1.0 ;#$_settings($tag-opacity) 1397 1398 set isovalues {} 1399 foreach m $_isomarkers($tf) { 1400 lappend isovalues [$m relval] 1401 } 1402 # Sort the isovalues 1403 set isovalues [lsort -real $isovalues] 1404 1405 if { ![info exists _settings($tag-thickness)]} { 1406 set _settings($tag-thickness) 0.005 1407 } 1408 set delta $_settings($tag-thickness) 1409 1410 set first [lindex $isovalues 0] 1411 set last [lindex $isovalues end] 1412 set wmap "" 1413 if { $first == "" || $first != 0.0 } { 1414 lappend wmap 0.0 0.0 1415 } 1416 foreach x $isovalues { 1417 set x1 [expr {$x-$delta-0.00001}] 1418 set x2 [expr {$x-$delta}] 1419 set x3 [expr {$x+$delta}] 1420 set x4 [expr {$x+$delta+0.00001}] 1421 if { $x1 < 0.0 } { 1422 set x1 0.0 1423 } elseif { $x1 > 1.0 } { 1424 set x1 1.0 1425 } 1426 if { $x2 < 0.0 } { 1427 set x2 0.0 1428 } elseif { $x2 > 1.0 } { 1429 set x2 1.0 1430 } 1431 if { $x3 < 0.0 } { 1432 set x3 0.0 1433 } elseif { $x3 > 1.0 } { 1434 set x3 1.0 1435 } 1436 if { $x4 < 0.0 } { 1437 set x4 0.0 1438 } elseif { $x4 > 1.0 } { 1439 set x4 1.0 1440 } 1441 # add spikes in the middle 1442 lappend wmap $x1 0.0 1443 lappend wmap $x2 $max 1444 lappend wmap $x3 $max 1445 lappend wmap $x4 0.0 1446 } 1447 if { $last == "" || $last != 1.0 } { 1448 lappend wmap 1.0 0.0 1449 } 1450 SendCmd "transfunc define $tf { $cmap } { $wmap }" 1472 1451 } 1473 1452 … … 1477 1456 itcl::configbody Rappture::NanovisViewer::plotbackground { 1478 1457 if { [isconnected] } { 1479 set color $itk_option(-plotbackground) 1480 set rgb [Color2RGB $color] 1481 SendCmd "screen bgcolor $rgb" 1482 $itk_component(legend) configure -background $color 1458 foreach {r g b} [Color2RGB $itk_option(-plotbackground)] break 1459 #fix this! 1460 #SendCmd "color background $r $g $b" 1483 1461 } 1484 1462 } … … 1489 1467 itcl::configbody Rappture::NanovisViewer::plotforeground { 1490 1468 if { [isconnected] } { 1491 set color $itk_option(-plotforeground) 1492 set rgb [Color2RGB $color] 1493 SendCmd "volume outline color $rgb" 1494 SendCmd "grid axiscolor $rgb" 1495 SendCmd "grid linecolor $rgb" 1496 $itk_component(legend) itemconfigure labels -fill $color 1497 $itk_component(legend) itemconfigure limits -fill $color 1469 foreach {r g b} [Color2RGB $itk_option(-plotforeground)] break 1470 #fix this! 1471 #SendCmd "color background $r $g $b" 1498 1472 } 1499 1473 } … … 1522 1496 # marker is a relative value from 0.0 to 1.0. 1523 1497 # 1524 itcl::body Rappture::NanovisViewer::ParseLevelsOption { cnamelevels } {1498 itcl::body Rappture::NanovisViewer::ParseLevelsOption { tf levels } { 1525 1499 set c $itk_component(legend) 1526 set list {}1527 1500 regsub -all "," $levels " " levels 1528 1501 if {[string is int $levels]} { 1529 1502 for {set i 1} { $i <= $levels } {incr i} { 1530 lappend list [expr {double($i)/($levels+1)}] 1503 set x [expr {double($i)/($levels+1)}] 1504 set m [Rappture::IsoMarker \#auto $c $this $tf] 1505 $m relval $x 1506 lappend _isomarkers($tf) $m 1531 1507 } 1532 1508 } else { 1533 1509 foreach x $levels { 1534 lappend list $x 1535 } 1536 } 1537 set _parsedFunction($cname) 1 1538 $_transferFunctionEditors($cname) addMarkers $list 1539 $itk_component(legend) itemconfigure labels -fill $itk_option(-plotforeground) 1510 set m [Rappture::IsoMarker \#auto $c $this $tf] 1511 $m relval $x 1512 lappend _isomarkers($tf) $m 1513 } 1514 } 1540 1515 } 1541 1516 … … 1552 1527 # not be seen. 1553 1528 # 1554 itcl::body Rappture::NanovisViewer::ParseMarkersOption { cnamemarkers } {1529 itcl::body Rappture::NanovisViewer::ParseMarkersOption { tf markers } { 1555 1530 set c $itk_component(legend) 1556 set list {}1557 foreach { min max } $_limits($cname) break1558 1531 regsub -all "," $markers " " markers 1559 1532 foreach marker $markers { 1560 1533 set n [scan $marker "%g%s" value suffix] 1561 1534 if { $n == 2 && $suffix == "%" } { 1562 # $n% : Set relative value (0..1). 1563 lappend list [expr {$value * 0.01}] 1535 # ${n}% : Set relative value. 1536 set value [expr {$value * 0.01}] 1537 set m [Rappture::IsoMarker \#auto $c $this $tf] 1538 $m relval $value 1539 lappend _isomarkers($tf) $m 1564 1540 } else { 1565 # $n : absolute value, compute relative 1566 lappend list [expr {(double($value)-$min)/($max-$min)]} 1567 } 1568 } 1569 set _parsedFunction($cname) 1 1570 $_transferFunctionEditors($cname) addMarkers $list 1571 $itk_component(legend) itemconfigure labels -fill $itk_option(-plotforeground) 1541 # ${n} : Set absolute value. 1542 set m [Rappture::IsoMarker \#auto $c $this $tf] 1543 $m absval $value 1544 lappend _isomarkers($tf) $m 1545 } 1546 } 1572 1547 } 1573 1548 … … 1575 1550 # USAGE: UndateTransferFuncs 1576 1551 # ---------------------------------------------------------------------- 1577 itcl::body Rappture::NanovisViewer::update TransferFunctions {} {1552 itcl::body Rappture::NanovisViewer::updatetransferfuncs {} { 1578 1553 $_dispatcher event -idle !send_transfunc 1579 1554 } 1580 1555 1581 itcl::body Rappture::NanovisViewer::limits { cname } { 1556 itcl::body Rappture::NanovisViewer::AddIsoMarker { x y } { 1557 if { $_first == "" } { 1558 error "active transfer function isn't set" 1559 } 1560 set tag [lindex [CurrentDatasets] 0] 1561 set tf $_dataset2style($tag) 1562 set c $itk_component(legend) 1563 set m [Rappture::IsoMarker \#auto $c $this $tf] 1564 set w [winfo width $c] 1565 $m relval [expr {double($x-10)/($w-20)}] 1566 lappend _isomarkers($tf) $m 1567 updatetransferfuncs 1568 return 1 1569 } 1570 1571 itcl::body Rappture::NanovisViewer::rmdupmarker { marker x } { 1572 set tf [$marker transferfunc] 1573 set bool 0 1574 if { [info exists _isomarkers($tf)] } { 1575 set list {} 1576 set marker [namespace tail $marker] 1577 foreach m $_isomarkers($tf) { 1578 set sx [$m screenpos] 1579 if { $m != $marker } { 1580 if { $x >= ($sx-3) && $x <= ($sx+3) } { 1581 $marker relval [$m relval] 1582 itcl::delete object $m 1583 bell 1584 set bool 1 1585 continue 1586 } 1587 } 1588 lappend list $m 1589 } 1590 set _isomarkers($tf) $list 1591 updatetransferfuncs 1592 } 1593 return $bool 1594 } 1595 1596 itcl::body Rappture::NanovisViewer::overmarker { marker x } { 1597 set tf [$marker transferfunc] 1598 if { [info exists _isomarkers($tf)] } { 1599 set marker [namespace tail $marker] 1600 foreach m $_isomarkers($tf) { 1601 set sx [$m screenpos] 1602 if { $m != $marker } { 1603 set bool [expr { $x >= ($sx-3) && $x <= ($sx+3) }] 1604 $m activate $bool 1605 } 1606 } 1607 } 1608 return "" 1609 } 1610 1611 itcl::body Rappture::NanovisViewer::limits { tf } { 1582 1612 set _limits(min) 0.0 1583 1613 set _limits(max) 1.0 1584 if { ![info exists _style2datasets($ cname)] } {1614 if { ![info exists _style2datasets($tf)] } { 1585 1615 return [array get _limits] 1586 1616 } 1587 1617 set min ""; set max "" 1588 foreach tag [GetDatasetsWithComponent $cname]{1589 if { ![info exists _ limits($tag)] } {1618 foreach tag $_style2datasets($tf) { 1619 if { ![info exists _serverDatasets($tag)] } { 1590 1620 continue 1591 1621 } 1592 foreach {amin amax} $_limits($tag) break 1593 if { $min == "" || $min > $amin } { 1594 set min $amin 1595 } 1596 if { $max == "" || $max < $amax } { 1597 set max $amax 1622 if { ![info exists _limits($tag-min)] } { 1623 continue 1624 } 1625 if { $min == "" || $min > $_limits($tag-min) } { 1626 set min $_limits($tag-min) 1627 } 1628 if { $max == "" || $max < $_limits($tag-max) } { 1629 set max $_limits($tag-max) 1598 1630 } 1599 1631 } … … 1604 1636 set _limits(max) $max 1605 1637 } 1606 return [ list $_limits(min) $_limits(max)]1638 return [array get _limits] 1607 1639 } 1608 1640 1609 1641 1610 1642 itcl::body Rappture::NanovisViewer::BuildViewTab {} { 1643 foreach { key value } { 1644 grid 0 1645 axes 1 1646 outline 0 1647 volume 1 1648 legend 1 1649 particles 1 1650 lic 1 1651 } { 1652 set _settings($this-$key) $value 1653 } 1654 1611 1655 set fg [option get $itk_component(hull) font Font] 1612 1656 #set bfg [option get $itk_component(hull) boldFont Font] … … 1617 1661 $inner configure -borderwidth 4 1618 1662 1619 set ::Rappture::NanovisViewer::_settings( -isosurfaceshading) 01663 set ::Rappture::NanovisViewer::_settings($this-isosurface) 0 1620 1664 checkbutton $inner.isosurface \ 1621 1665 -text "Isosurface shading" \ 1622 -variable [itcl::scope _settings( -isosurfaceshading)] \1623 -command [itcl::code $this AdjustSetting -isosurfaceshading] \1666 -variable [itcl::scope _settings($this-isosurface)] \ 1667 -command [itcl::code $this AdjustSetting isosurface] \ 1624 1668 -font "Arial 9" 1625 1669 1626 1670 checkbutton $inner.axes \ 1627 1671 -text "Axes" \ 1628 -variable [itcl::scope _settings( -axesvisible)] \1629 -command [itcl::code $this AdjustSetting -axesvisible] \1672 -variable [itcl::scope _settings($this-axes)] \ 1673 -command [itcl::code $this AdjustSetting axes] \ 1630 1674 -font "Arial 9" 1631 1675 1632 1676 checkbutton $inner.grid \ 1633 1677 -text "Grid" \ 1634 -variable [itcl::scope _settings( -gridvisible)] \1635 -command [itcl::code $this AdjustSetting -gridvisible] \1678 -variable [itcl::scope _settings($this-grid)] \ 1679 -command [itcl::code $this AdjustSetting grid] \ 1636 1680 -font "Arial 9" 1637 1681 1638 1682 checkbutton $inner.outline \ 1639 1683 -text "Outline" \ 1640 -variable [itcl::scope _settings( -outlinevisible)] \1641 -command [itcl::code $this AdjustSetting -outlinevisible] \1684 -variable [itcl::scope _settings($this-outline)] \ 1685 -command [itcl::code $this AdjustSetting outline] \ 1642 1686 -font "Arial 9" 1643 1687 1644 1688 checkbutton $inner.legend \ 1645 1689 -text "Legend" \ 1646 -variable [itcl::scope _settings( -legendvisible)] \1647 -command [itcl::code $this AdjustSetting -legendvisible] \1690 -variable [itcl::scope _settings($this-legend)] \ 1691 -command [itcl::code $this AdjustSetting legend] \ 1648 1692 -font "Arial 9" 1649 1693 1650 1694 checkbutton $inner.volume \ 1651 1695 -text "Volume" \ 1652 -variable [itcl::scope _settings( -volume)] \1653 -command [itcl::code $this AdjustSetting -volume] \1696 -variable [itcl::scope _settings($this-volume)] \ 1697 -command [itcl::code $this AdjustSetting volume] \ 1654 1698 -font "Arial 9" 1655 1656 label $inner.background_l -text "Background" -font "Arial 9"1657 itk_component add background {1658 Rappture::Combobox $inner.background -width 10 -editable no1659 }1660 $inner.background choices insert end \1661 "black" "black" \1662 "white" "white" \1663 "grey" "grey"1664 1665 $itk_component(background) value $_settings(-background)1666 bind $inner.background <<Value>> \1667 [itcl::code $this AdjustSetting -background]1668 1699 1669 1700 blt::table $inner \ … … 1672 1703 2,0 $inner.outline -cspan 2 -anchor w \ 1673 1704 3,0 $inner.volume -cspan 2 -anchor w \ 1674 4,0 $inner.legend -cspan 2 -anchor w \ 1675 5,0 $inner.background_l -anchor e -pady 2 \ 1676 5,1 $inner.background -fill x \ 1705 4,0 $inner.legend -cspan 2 -anchor w 1677 1706 1678 1707 if 0 { … … 1680 1709 } 1681 1710 blt::table configure $inner r* -resize none 1682 blt::table configure $inner r 6-resize expand1711 blt::table configure $inner r5 -resize expand 1683 1712 } 1684 1713 1685 1714 itcl::body Rappture::NanovisViewer::BuildVolumeTab {} { 1715 foreach { key value } { 1716 light2side 1 1717 light 40 1718 transp 50 1719 opacity 100 1720 thickness 350 1721 } { 1722 set _settings($this-$key) $value 1723 } 1724 1686 1725 set inner [$itk_component(main) insert end \ 1687 1726 -title "Volume Settings" \ … … 1689 1728 $inner configure -borderwidth 4 1690 1729 1691 set font [option get $itk_component(hull) font Font]1692 1730 set fg [option get $itk_component(hull) font Font] 1693 1731 #set bfg [option get $itk_component(hull) boldFont Font] 1694 1732 1695 1733 checkbutton $inner.vol -text "Show volume" -font $fg \ 1696 -variable [itcl::scope _settings( -volumevisible)] \1697 -command [itcl::code $this AdjustSetting -volumevisible]1734 -variable [itcl::scope _settings($this-volume)] \ 1735 -command [itcl::code $this AdjustSetting volume] 1698 1736 label $inner.shading -text "Shading:" -font $fg 1699 1737 1700 1738 checkbutton $inner.light2side -text "Two-sided lighting" -font $fg \ 1701 -variable [itcl::scope _settings( -light2side)] \1702 -command [itcl::code $this AdjustSetting -light2side]1739 -variable [itcl::scope _settings($this-light2side)] \ 1740 -command [itcl::code $this AdjustSetting light2side] 1703 1741 1704 1742 label $inner.dim -text "Glow" -font $fg 1705 1743 ::scale $inner.light -from 0 -to 100 -orient horizontal \ 1706 -variable [itcl::scope _settings( -light)] \1744 -variable [itcl::scope _settings($this-light)] \ 1707 1745 -width 10 \ 1708 -showvalue off -command [itcl::code $this AdjustSetting -light]1746 -showvalue off -command [itcl::code $this AdjustSetting light] 1709 1747 label $inner.bright -text "Surface" -font $fg 1710 1748 1711 # Opacity1712 1749 label $inner.fog -text "Clear" -font $fg 1713 1750 ::scale $inner.transp -from 0 -to 100 -orient horizontal \ 1714 -variable [itcl::scope _ widget(-volumeopacity)] \1751 -variable [itcl::scope _settings($this-transp)] \ 1715 1752 -width 10 \ 1716 -showvalue off -command [itcl::code $this AdjustSetting -volumeopacity]1753 -showvalue off -command [itcl::code $this AdjustSetting transp] 1717 1754 label $inner.plastic -text "Opaque" -font $fg 1718 1755 1719 # Tooth thickness 1756 label $inner.clear -text "Clear" -font $fg 1757 ::scale $inner.opacity -from 0 -to 100 -orient horizontal \ 1758 -variable [itcl::scope _settings($this-opacity)] \ 1759 -width 10 \ 1760 -showvalue off -command [itcl::code $this AdjustSetting opacity] 1761 label $inner.opaque -text "Opaque" -font $fg 1762 1720 1763 label $inner.thin -text "Thin" -font $fg 1721 1764 ::scale $inner.thickness -from 0 -to 1000 -orient horizontal \ 1722 -variable [itcl::scope _settings( -thickness)] \1765 -variable [itcl::scope _settings($this-thickness)] \ 1723 1766 -width 10 \ 1724 -showvalue off -command [itcl::code $this AdjustSetting -thickness]1767 -showvalue off -command [itcl::code $this AdjustSetting thickness] 1725 1768 label $inner.thick -text "Thick" -font $fg 1726 1769 1727 # Colormap1728 1770 label $inner.colormap_l -text "Colormap" -font "Arial 9" 1729 1771 itk_component add colormap { … … 1731 1773 } 1732 1774 1733 $inner.colormap choices insert end [GetColormapList -includeDefault -includeNone] 1775 $inner.colormap choices insert end \ 1776 "BCGYR" "BCGYR" \ 1777 "BGYOR" "BGYOR" \ 1778 "blue" "blue" \ 1779 "blue-to-brown" "blue-to-brown" \ 1780 "blue-to-orange" "blue-to-orange" \ 1781 "blue-to-grey" "blue-to-grey" \ 1782 "green-to-magenta" "green-to-magenta" \ 1783 "greyscale" "greyscale" \ 1784 "nanohub" "nanohub" \ 1785 "rainbow" "rainbow" \ 1786 "spectral" "spectral" \ 1787 "ROYGB" "ROYGB" \ 1788 "RYGCB" "RYGCB" \ 1789 "brown-to-blue" "brown-to-blue" \ 1790 "grey-to-blue" "grey-to-blue" \ 1791 "orange-to-blue" "orange-to-blue" \ 1792 "none" "none" 1793 1794 $itk_component(colormap) value "BCGYR" 1734 1795 bind $inner.colormap <<Value>> \ 1735 [itcl::code $this AdjustSetting -colormap] 1736 $itk_component(colormap) value "default" 1737 set _settings(-colormap) "default" 1738 1739 # Component 1740 label $inner.volcomponents_l -text "Component" -font $font 1741 itk_component add volcomponents { 1742 Rappture::Combobox $inner.volcomponents -editable no 1743 } 1744 bind $inner.volcomponents <<Value>> \ 1745 [itcl::code $this AdjustSetting -current] 1796 [itcl::code $this AdjustSetting colormap] 1746 1797 1747 1798 blt::table $inner \ 1748 0,0 $inner.volcomponents_l -anchor e -cspan 2 \ 1749 0,2 $inner.volcomponents -cspan 3 -fill x \ 1799 0,0 $inner.vol -cspan 4 -anchor w -pady 2 \ 1750 1800 1,0 $inner.shading -cspan 4 -anchor w -pady {10 2} \ 1751 1801 2,0 $inner.light2side -cspan 4 -anchor w -pady 2 \ … … 1770 1820 $inner configure -borderwidth 4 1771 1821 1772 checkbutton $inner.visible \1773 -text "Show Cutplanes" \1774 -variable [itcl::scope _settings(-cutplanesvisible)] \1775 -command [itcl::code $this AdjustSetting -cutplanesvisible] \1776 -font "Arial 9"1777 1778 1822 # X-value slicer... 1779 1823 itk_component add xCutButton { … … 1781 1825 -onimage [Rappture::icon x-cutplane] \ 1782 1826 -offimage [Rappture::icon x-cutplane] \ 1783 -command [itcl::code $this AdjustSetting -xcutplanevisible] \1784 -variable [itcl::scope _settings( -xcutplanevisible)]1827 -command [itcl::code $this AdjustSetting xcutplane] \ 1828 -variable [itcl::scope _settings($this-xcutplane)] 1785 1829 } 1786 1830 Rappture::Tooltip::for $itk_component(xCutButton) \ 1787 1831 "Toggle the X cut plane on/off" 1788 $itk_component(xCutButton) select1789 1832 1790 1833 itk_component add xCutScale { … … 1793 1836 -borderwidth 1 -highlightthickness 0 \ 1794 1837 -command [itcl::code $this Slice move x] \ 1795 -variable [itcl::scope _settings( -xcutplaneposition)]1838 -variable [itcl::scope _settings($this-xcutposition)] 1796 1839 } { 1797 1840 usual … … 1809 1852 -onimage [Rappture::icon y-cutplane] \ 1810 1853 -offimage [Rappture::icon y-cutplane] \ 1811 -command [itcl::code $this AdjustSetting -ycutplanevisible] \1812 -variable [itcl::scope _settings( -ycutplanevisible)]1854 -command [itcl::code $this AdjustSetting ycutplane] \ 1855 -variable [itcl::scope _settings($this-ycutplane)] 1813 1856 } 1814 1857 Rappture::Tooltip::for $itk_component(yCutButton) \ 1815 1858 "Toggle the Y cut plane on/off" 1816 $itk_component(yCutButton) select1817 1859 1818 1860 itk_component add yCutScale { … … 1821 1863 -borderwidth 1 -highlightthickness 0 \ 1822 1864 -command [itcl::code $this Slice move y] \ 1823 -variable [itcl::scope _settings( -ycutplaneposition)]1865 -variable [itcl::scope _settings($this-ycutposition)] 1824 1866 } { 1825 1867 usual … … 1837 1879 -onimage [Rappture::icon z-cutplane] \ 1838 1880 -offimage [Rappture::icon z-cutplane] \ 1839 -command [itcl::code $this AdjustSetting -zcutplanevisible] \1840 -variable [itcl::scope _settings( -zcutplanevisible)]1881 -command [itcl::code $this AdjustSetting zcutplane] \ 1882 -variable [itcl::scope _settings($this-zcutplane)] 1841 1883 } 1842 1884 Rappture::Tooltip::for $itk_component(zCutButton) \ 1843 1885 "Toggle the Z cut plane on/off" 1844 $itk_component(zCutButton) select1845 1886 1846 1887 itk_component add zCutScale { … … 1849 1890 -borderwidth 1 -highlightthickness 0 \ 1850 1891 -command [itcl::code $this Slice move z] \ 1851 -variable [itcl::scope _settings( -zcutplaneposition)]1892 -variable [itcl::scope _settings($this-zcutposition)] 1852 1893 } { 1853 1894 usual … … 1856 1897 $itk_component(zCutScale) set 50 1857 1898 $itk_component(zCutScale) configure -state disabled 1899 #$itk_component(zCutScale) configure -state disabled 1858 1900 Rappture::Tooltip::for $itk_component(zCutScale) \ 1859 1901 "@[itcl::code $this SlicerTip z]" … … 1897 1939 label $inner.${tag}label -text $tag -font "Arial 9" 1898 1940 entry $inner.${tag} -font "Arial 9" -bg white \ 1899 -textvariable [itcl::scope _settings( -$tag)]1941 -textvariable [itcl::scope _settings($this-$tag)] 1900 1942 bind $inner.${tag} <Return> \ 1901 [itcl::code $this camera set -${tag}]1943 [itcl::code $this camera set ${tag}] 1902 1944 bind $inner.${tag} <KP_Enter> \ 1903 [itcl::code $this camera set -${tag}]1945 [itcl::code $this camera set ${tag}] 1904 1946 blt::table $inner \ 1905 1947 $row,0 $inner.${tag}label -anchor e -pady 2 \ … … 1950 1992 itcl::body Rappture::NanovisViewer::SlicerTip {axis} { 1951 1993 set val [$itk_component(${axis}CutScale) get] 1994 # set val [expr {0.01*($val-50) 1995 # *($_limits(${axis}max)-$_limits(${axis}min)) 1996 # + 0.5*($_limits(${axis}max)+$_limits(${axis}min))}] 1952 1997 return "Move the [string toupper $axis] cut plane.\nCurrently: $axis = $val%" 1953 1998 } … … 1970 2015 } 1971 2016 1972 itcl::body Rappture::NanovisViewer::EventuallyRe drawLegend {} {2017 itcl::body Rappture::NanovisViewer::EventuallyResizeLegend {} { 1973 2018 if { !$_resizeLegendPending } { 1974 2019 $_dispatcher event -idle !legend … … 1985 2030 } 1986 2031 "set" { 1987 set wh at[lindex $args 0]1988 set x $_settings($ what)2032 set who [lindex $args 0] 2033 set x $_settings($this-$who) 1989 2034 set code [catch { string is double $x } result] 1990 2035 if { $code != 0 || !$result } { 1991 set _settings($ what) $_view($what)2036 set _settings($this-$who) $_view($who) 1992 2037 return 1993 2038 } 1994 switch -- $wh at{1995 " -xpan" - "-ypan" {1996 set _view($wh at) $_settings($what)2039 switch -- $who { 2040 "xpan" - "ypan" { 2041 set _view($who) $_settings($this-$who) 1997 2042 PanCamera 1998 2043 } 1999 " -qx" - "-qy" - "-qz" - "-qw" {2000 set _view($wh at) $_settings($what)2001 set q [ ViewToQuaternion]2044 "qx" - "qy" - "qz" - "qw" { 2045 set _view($who) $_settings($this-$who) 2046 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 2002 2047 $_arcball quaternion $q 2003 2048 SendCmd "camera orient $q" 2004 2049 } 2005 " -zoom" {2006 set _view($wh at) $_settings($what)2007 SendCmd "camera zoom $_view( $what)"2050 "zoom" { 2051 set _view($who) $_settings($this-$who) 2052 SendCmd "camera zoom $_view(zoom)" 2008 2053 } 2009 2054 } … … 2045 2090 array set info $vol 2046 2091 set name $info(name) 2047 if { ![info exists _settings( -volumevisible-$name)] } {2048 set _settings( -volumevisible-$name) $info(hide)2092 if { ![info exists _settings($this-volume-$name)] } { 2093 set _settings($this-volume-$name) $info(hide) 2049 2094 } 2050 2095 checkbutton $inner.vol$row -text $info(label) \ 2051 -variable [itcl::scope _settings( -volumevisible-$name)] \2096 -variable [itcl::scope _settings($this-volume-$name)] \ 2052 2097 -onvalue 0 -offvalue 1 \ 2053 -command [itcl::code $this ToggleVolume $key $name] \2098 -command [itcl::code $this volume $key $name] \ 2054 2099 -font "Arial 9" 2055 2100 Rappture::Tooltip::for $inner.vol$row $info(description) 2056 2101 blt::table $inner $row,0 $inner.vol$row -anchor w 2057 if { !$_settings( -volume-$name) } {2102 if { !$_settings($this-volume-$name) } { 2058 2103 $inner.vol$row select 2059 2104 } … … 2066 2111 } 2067 2112 2068 itcl::body Rappture::NanovisViewer:: ToggleVolume { tag name } {2069 set bool $_settings( -volumevisible-$name)2070 SendCmd "volume stat e $bool $name"2113 itcl::body Rappture::NanovisViewer::volume { tag name } { 2114 set bool $_settings($this-volume-$name) 2115 SendCmd "volume statue $bool $name" 2071 2116 } 2072 2117 … … 2080 2125 bottom "0.707107 0.707107 0 0" 2081 2126 } 2082 foreach name { -qw -qx -qy -qz } value $positions($side) {2127 foreach name { qw qx qy qz } value $positions($side) { 2083 2128 set _view($name) $value 2084 2129 } 2085 set q [ ViewToQuaternion]2130 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 2086 2131 $_arcball quaternion $q 2087 2132 SendCmd "camera orient $q" 2088 2133 SendCmd "camera reset" 2089 set _view(-xpan) 0 2090 set _view(-ypan) 0 2091 set _view(-zoom) 1.0 2092 set _settings(-xpan) $_view(-xpan) 2093 set _settings(-ypan) $_view(-ypan) 2094 set _settings(-zoom) $_view(-zoom) 2095 } 2096 2097 2098 # 2099 # InitComponentSettings -- 2100 # 2101 # Initializes the volume settings for a specific component. This should 2102 # match what's used as global settings above. This is called the first 2103 # time we try to switch to a given component in SwitchComponent below. 2104 # 2105 itcl::body Rappture::NanovisViewer::InitComponentSettings { cname } { 2106 foreach {key value} { 2107 -colormap "default" 2108 -light 40 2109 -light2side 1 2110 -thickness 350 2111 -volumeopacity 1.0 2112 -volumevisible 1 2113 } { 2114 if { ![info exists _settings($cname${key})] } { 2115 # Don't override existing component settings 2116 set _settings($cname${key}) $value 2117 } 2118 } 2119 } 2120 2121 # 2122 # SwitchComponent -- 2123 # 2124 # This is called when the current component is changed by the dropdown 2125 # menu in the volume tab. It synchronizes the global volume settings 2126 # with the settings of the new current component. 2127 # 2128 itcl::body Rappture::NanovisViewer::SwitchComponent { cname } { 2129 if { ![info exists _settings($cname-light)] } { 2130 InitComponentSettings $cname 2131 } 2132 if { $_settings(-colormap) != $_settings($cname-colormap) } { 2133 set _settings(-colormap) $_settings($cname-colormap) 2134 EventuallyRedrawLegend 2135 } 2136 # _settings variables change widgets, except for colormap 2137 set _settings(-light) $_settings($cname-light) 2138 set _settings(-light2side) $_settings($cname-light2side) 2139 set _settings(-volumeopacity) $_settings($cname-volumeopacity) 2140 set _settings(-thickness) $_settings($cname-thickness) 2141 set _settings(-volumevisible) $_settings($cname-volumevisible) 2142 $itk_component(colormap) value $_settings($cname-colormap) 2143 2144 set _widget(-volumeopacity) [expr $_settings(-volumeopacity) * 100.0] 2145 2146 set _current $cname; # Reset the current component 2147 } 2148 2149 # 2150 # BuildVolumeComponents -- 2151 # 2152 # This is called from the "scale" method which is called when a new 2153 # dataset is added or deleted. It repopulates the dropdown menu of 2154 # volume component names. It sets the current component to the first 2155 # component in the list (of components found). Finally, if there is 2156 # only one component, don't display the label or the combobox in the 2157 # volume settings tab. 2158 # 2159 itcl::body Rappture::NanovisViewer::BuildVolumeComponents {} { 2160 $itk_component(volcomponents) choices delete 0 end 2161 foreach name $_componentsList { 2162 $itk_component(volcomponents) choices insert end $name $name 2163 } 2164 set _current [lindex $_componentsList 0] 2165 $itk_component(volcomponents) value $_current 2166 set parent [winfo parent $itk_component(volcomponents)] 2167 if { [llength $_componentsList] <= 1 } { 2168 # Unpack the components label and dropdown if there's only one 2169 # component. 2170 blt::table forget $parent.volcomponents_l $parent.volcomponents 2171 } else { 2172 # Pack the components label and dropdown into the table there's 2173 # more than one component to select. 2174 blt::table $parent \ 2175 0,0 $parent.volcomponents_l -anchor e -cspan 2 \ 2176 0,2 $parent.volcomponents -cspan 3 -fill x 2177 } 2178 } 2179 2180 # 2181 # GetDatasetsWithComponents -- 2182 # 2183 # Returns a list of all the datasets (known by the combination of their 2184 # data object and component name) that match the given component name. 2185 # For example, this is used where we want to change the settings of 2186 # volumes that have the current component. 2187 # 2188 itcl::body Rappture::NanovisViewer::GetDatasetsWithComponent { cname } { 2189 if { ![info exists _volcomponents($cname)] } { 2190 return "" 2191 } 2192 set list "" 2193 foreach tag $_volcomponents($cname) { 2194 if { ![info exists _serverDatasets($tag)] } { 2195 continue 2196 } 2197 lappend list $tag 2198 } 2199 return $list 2200 } 2201 2202 # 2203 # HideAllMarkers -- 2204 # 2205 # Hide all the markers in all the transfer functions. Can't simply 2206 # delete and recreate markers from the <style> since the user may have 2207 # create, deleted, or moved markers. 2208 # 2209 itcl::body Rappture::NanovisViewer::HideAllMarkers {} { 2210 foreach cname [array names _transferFunctionEditors] { 2211 $_transferFunctionEditors($cname) hideMarkers 2212 } 2213 } 2214 2215 itcl::body Rappture::NanovisViewer::GetColormap { cname color } { 2216 if { $color == "default" } { 2217 return $_cname2defaultcolormap($cname) 2218 } 2219 return [ColorsToColormap $color] 2220 } 2221 2222 itcl::body Rappture::NanovisViewer::GetAlphamap { cname name } { 2223 if { $name == "default" } { 2224 return $_cname2defaultalphamap($cname) 2225 } 2226 return [NameToAlphamap $name] 2227 } 2228 2229 itcl::body Rappture::NanovisViewer::ResetColormap { cname color } { 2230 # Get the current transfer function 2231 if { ![info exists _cname2transferFunction($cname)] } { 2232 return 2233 } 2234 foreach { cmap wmap } $_cname2transferFunction($cname) break 2235 set cmap [GetColormap $cname $color] 2236 set _cname2transferFunction($cname) [list $cmap $wmap] 2237 SendCmd [list transfunc define $cname $cmap $wmap] 2238 EventuallyRedrawLegend 2239 } 2240 2241 itcl::body Rappture::NanovisViewer::ComputeAlphamap { cname } { 2242 if { ![info exists _transferFunctionEditors($cname)] } { 2243 return [list 0.0 0.0 1.0 1.0] 2244 } 2245 if { ![info exists _settings($cname-light)] } { 2246 InitComponentSettings $cname 2247 } 2248 2249 set isovalues [$_transferFunctionEditors($cname) values] 2250 2251 # Currently using volume shading opacity to scale opacity in 2252 # the volume shader. 2253 set max $_settings($cname-volumeopacity) 2254 2255 # Use the component-wise thickness setting from the slider 2256 # settings widget 2257 # Scale values between 0.00001 and 0.01000 2258 set delta [expr {double($_settings($cname-thickness)) * 0.0001}] 2259 2260 set first [lindex $isovalues 0] 2261 set last [lindex $isovalues end] 2262 set wmap "" 2263 if { $first == "" || $first != 0.0 } { 2264 lappend wmap 0.0 0.0 2265 } 2266 foreach x $isovalues { 2267 set x1 [expr {$x-$delta-0.00001}] 2268 set x2 [expr {$x-$delta}] 2269 set x3 [expr {$x+$delta}] 2270 set x4 [expr {$x+$delta+0.00001}] 2271 if { $x1 < 0.0 } { 2272 set x1 0.0 2273 } elseif { $x1 > 1.0 } { 2274 set x1 1.0 2275 } 2276 if { $x2 < 0.0 } { 2277 set x2 0.0 2278 } elseif { $x2 > 1.0 } { 2279 set x2 1.0 2280 } 2281 if { $x3 < 0.0 } { 2282 set x3 0.0 2283 } elseif { $x3 > 1.0 } { 2284 set x3 1.0 2285 } 2286 if { $x4 < 0.0 } { 2287 set x4 0.0 2288 } elseif { $x4 > 1.0 } { 2289 set x4 1.0 2290 } 2291 # add spikes in the middle 2292 lappend wmap $x1 0.0 2293 lappend wmap $x2 $max 2294 lappend wmap $x3 $max 2295 lappend wmap $x4 0.0 2296 } 2297 if { $last == "" || $last != 1.0 } { 2298 lappend wmap 1.0 0.0 2299 } 2300 return $wmap 2301 } 2302 2303 2304 itcl::body Rappture::NanovisViewer::NameToAlphamap { name } { 2305 switch -- $name { 2306 "ramp-up" { 2307 set wmap { 2308 0.0 0.0 2309 1.0 1.0 2310 } 2311 } 2312 "ramp-down" { 2313 set wmap { 2314 0.0 1.0 2315 1.0 0.0 2316 } 2317 } 2318 "vee" { 2319 set wmap { 2320 0.0 1.0 2321 0.5 0.0 2322 1.0 1.0 2323 } 2324 } 2325 "tent-1" { 2326 set wmap { 2327 0.0 0.0 2328 0.5 1.0 2329 1.0 0.0 2330 } 2331 } 2332 "tent-2" { 2333 set wmap { 2334 0.0 0.0 2335 0.25 1.0 2336 0.5 0.0 2337 0.75 1.0 2338 1.0 0.0 2339 } 2340 } 2341 "tent-3" { 2342 set wmap { 2343 0.0 0.0 2344 0.16666 1.0 2345 0.33333 0.0 2346 0.5 1.0 2347 0.66666 0.0 2348 0.83333 1.0 2349 1.0 0.0 2350 } 2351 } 2352 "tent-4" { 2353 set wmap { 2354 0.0 0.0 2355 0.125 1.0 2356 0.25 0.0 2357 0.375 1.0 2358 0.5 0.0 2359 0.625 1.0 2360 0.75 0.0 2361 0.875 1.0 2362 1.0 0.0 2363 } 2364 } 2365 "sinusoid-1" { 2366 set wmap { 2367 0.0 0.000 0.600 0.800 2368 0.14285714285714285 0.400 0.900 1.000 2369 0.2857142857142857 0.600 1.000 1.000 2370 0.42857142857142855 0.800 1.000 1.000 2371 0.5714285714285714 0.900 0.900 0.900 2372 0.7142857142857143 0.600 0.600 0.600 2373 0.8571428571428571 0.400 0.400 0.400 2374 1.0 0.200 0.200 0.200 2375 } 2376 } 2377 "sinusoid-2" { 2378 set wmap { 2379 0.0 0.900 1.000 1.000 2380 0.1111111111111111 0.800 0.983 1.000 2381 0.2222222222222222 0.700 0.950 1.000 2382 0.3333333333333333 0.600 0.900 1.000 2383 0.4444444444444444 0.500 0.833 1.000 2384 0.5555555555555556 0.400 0.750 1.000 2385 0.6666666666666666 0.300 0.650 1.000 2386 0.7777777777777778 0.200 0.533 1.000 2387 0.8888888888888888 0.100 0.400 1.000 2388 1.0 0.000 0.250 1.000 2389 } 2390 } 2391 "sinusoid-6" { 2392 set wmap { 2393 0.0 0.200 0.100 0.000 2394 0.09090909090909091 0.400 0.187 0.000 2395 0.18181818181818182 0.600 0.379 0.210 2396 0.2727272727272727 0.800 0.608 0.480 2397 0.36363636363636365 0.850 0.688 0.595 2398 0.45454545454545453 0.950 0.855 0.808 2399 0.5454545454545454 0.800 0.993 1.000 2400 0.6363636363636364 0.600 0.973 1.000 2401 0.7272727272727273 0.400 0.940 1.000 2402 0.8181818181818182 0.200 0.893 1.000 2403 0.9090909090909091 0.000 0.667 0.800 2404 1.0 0.000 0.480 0.600 2405 } 2406 } 2407 "sinusoid-10" { 2408 set wmap { 2409 0.0 0.000 0.480 0.600 2410 0.09090909090909091 0.000 0.667 0.800 2411 0.18181818181818182 0.200 0.893 1.000 2412 0.2727272727272727 0.400 0.940 1.000 2413 0.36363636363636365 0.600 0.973 1.000 2414 0.45454545454545453 0.800 0.993 1.000 2415 0.5454545454545454 0.950 0.855 0.808 2416 0.6363636363636364 0.850 0.688 0.595 2417 0.7272727272727273 0.800 0.608 0.480 2418 0.8181818181818182 0.600 0.379 0.210 2419 0.9090909090909091 0.400 0.187 0.000 2420 1.0 0.200 0.100 0.000 2421 } 2422 } 2423 "step-2" { 2424 set wmap { 2425 0.0 0.000 0.167 1.000 2426 0.09090909090909091 0.100 0.400 1.000 2427 0.18181818181818182 0.200 0.600 1.000 2428 0.2727272727272727 0.400 0.800 1.000 2429 0.36363636363636365 0.600 0.933 1.000 2430 0.45454545454545453 0.800 1.000 1.000 2431 0.5454545454545454 1.000 1.000 0.800 2432 0.6363636363636364 1.000 0.933 0.600 2433 0.7272727272727273 1.000 0.800 0.400 2434 0.8181818181818182 1.000 0.600 0.200 2435 0.9090909090909091 1.000 0.400 0.100 2436 1.0 1.000 0.167 0.000 2437 } 2438 } 2439 "step-5" { 2440 set wmap { 2441 0.0 1.000 0.167 0.000 2442 0.09090909090909091 1.000 0.400 0.100 2443 0.18181818181818182 1.000 0.600 0.200 2444 0.2727272727272727 1.000 0.800 0.400 2445 0.36363636363636365 1.000 0.933 0.600 2446 0.45454545454545453 1.000 1.000 0.800 2447 0.5454545454545454 0.800 1.000 1.000 2448 0.6363636363636364 0.600 0.933 1.000 2449 0.7272727272727273 0.400 0.800 1.000 2450 0.8181818181818182 0.200 0.600 1.000 2451 0.9090909090909091 0.100 0.400 1.000 2452 1.0 0.000 0.167 1.000 2453 } 2454 } 2455 "step-12" { 2456 set wmap { 2457 "#EE82EE" 2458 "#4B0082" 2459 "blue" 2460 "#008000" 2461 "yellow" 2462 "#FFA500" 2463 "red" 2464 } 2465 } 2466 default { 2467 } 2468 } 2469 return "" 2470 } 2471 2472 itcl::body Rappture::NanovisViewer::SetObjectStyle { dataobj cname } { 2473 array set styles { 2474 -opacity 0.6 2475 } 2476 array set styles [lindex [$dataobj components -style $cname] 0] 2477 set _settings($cname-volumeopacity) $styles(-opacity) 2478 NameTransferFunction $dataobj $cname 2479 } 2134 set _view(xpan) 0 2135 set _view(ypan) 0 2136 set _view(zoom) 1.0 2137 set _settings($this-xpan) $_view(xpan) 2138 set _settings($this-ypan) $_view(ypan) 2139 set _settings($this-zoom) $_view(zoom) 2140 } 2141 -
branches/uq/gui/scripts/panes.tcl
r3330 r5121 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 2 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 3 2 # ---------------------------------------------------------------------- 4 3 # COMPONENT: Panes - creates a series of adjustable panes … … 9 8 # ====================================================================== 10 9 # AUTHOR: Michael McLennan, Purdue University 11 # Copyright (c) 2004-201 2HUBzero Foundation, LLC10 # Copyright (c) 2004-2015 HUBzero Foundation, LLC 12 11 # 13 12 # See the file "license.terms" for information on usage and … … 21 20 option add *Panes.sashWidth 2 widgetDefault 22 21 option add *Panes.sashPadding 4 widgetDefault 23 option add *Panes. sashCursor sb_v_double_arrow22 option add *Panes.orientation vertical widgetDefault 24 23 25 24 itcl::class Rappture::Panes { 26 25 inherit itk::Widget 27 26 28 itk_option define -sashcursor sashCursor SashCursor ""29 27 itk_option define -sashrelief sashRelief SashRelief "" 30 28 itk_option define -sashwidth sashWidth SashWidth 0 31 29 itk_option define -sashpadding sashPadding SashPadding 0 30 itk_option define -orientation orientation Orientation "" 32 31 33 32 constructor {args} { # defined below } … … 35 34 public method insert {pos args} 36 35 public method pane {pos} 37 public method visibility {pos {newval ""}}38 public method fraction {pos {newval ""}}36 public method visibility {pos args} 37 public method fraction {pos args} 39 38 public method hilite {state sash} 39 public method size {} 40 40 41 41 protected method _grab {pane X Y} … … 49 49 private variable _visibility "" ;# list of visibilities for panes 50 50 private variable _counter 0 ;# counter for auto-generated names 51 private variable _frac 0.0 ;# list of fractions 52 public variable orientation "vertical" 51 private variable _reqfrac 0.0 ;# requested fraction size of each pane 52 private variable _dragfrom 0 ;# starting coordinate of drag operation 53 private variable _dragfrac 0 ;# limit on fraction of drag operation 53 54 } 54 55 55 56 itk::usual Panes { 56 keep -background -cursor 57 keep -background -cursor -sashwidth -sashrelief 57 58 } 58 59 … … 80 81 lappend _panes $pname 81 82 lappend _visibility 1 82 set _ frac 0.583 set _reqfrac 0.5 83 84 84 85 eval itk_initialize $args … … 107 108 } { 108 109 usual 109 rename -cursor -sashcursor sashCursor SashCursor110 ignore -cursor 110 111 } 111 112 bind $itk_component($sash) <Enter> [itcl::code $this hilite on $sash] … … 116 117 } { 117 118 usual 118 rename -cursor -sashcursor sashCursor SashCursor119 119 rename -relief -sashrelief sashRelief SashRelief 120 120 ignore -borderwidth 121 121 } 122 if { $orientation == "vertical"} {122 if {$itk_option(-orientation) eq "vertical"} { 123 123 pack $itk_component(${sash}ridge) -fill x 124 $itk_component($sash) configure -cursor sb_v_double_arrow 125 $itk_component(${sash}ridge) configure -cursor sb_v_double_arrow 124 126 } else { 125 127 pack $itk_component(${sash}ridge) -fill y -side left 128 $itk_component($sash) configure -cursor sb_h_double_arrow 129 $itk_component(${sash}ridge) configure -cursor sb_h_double_arrow 126 130 } 127 131 foreach comp [list $sash ${sash}ridge] { … … 140 144 set _panes [linsert $_panes $pos $pname] 141 145 set _visibility [linsert $_visibility $pos 1] 142 set _ frac [linsert $_frac $pos $params(-fraction)]146 set _reqfrac [linsert $_reqfrac $pos $params(-fraction)] 143 147 144 148 # fix sash characteristics … … 165 169 166 170 # ---------------------------------------------------------------------- 167 # USAGE: visibility <pos> ?<newval>? 171 # USAGE: visibility <pos> ?<newval>? ?<pos> <newval> ...? 168 172 # 169 173 # Clients use this to get/set the visibility of the pane at position 170 # <pos>. 171 # ---------------------------------------------------------------------- 172 itcl::body Rappture::Panes::visibility {pos {newval ""}} { 173 if {"" == $newval} { 174 # <pos>. Can also be used to set the visibility for multiple panes 175 # if multiple <pos>/<newval> pairs are specified in the same command. 176 # ---------------------------------------------------------------------- 177 itcl::body Rappture::Panes::visibility {pos args} { 178 if {[llength $args] == 0} { 174 179 return [lindex $_visibility $pos] 175 180 } 176 if {![string is boolean $newval]} { 177 error "bad value \"$newval\": should be boolean" 178 } 179 if {$pos == "end" || ($pos >= 0 && $pos < [llength $_visibility])} { 180 set _visibility [lreplace $_visibility $pos $pos [expr {$newval}]] 181 $_dispatcher event -idle !layout 182 } else { 183 error "bad index \"$pos\": out of range" 184 } 185 } 186 187 # ---------------------------------------------------------------------- 188 # USAGE: fraction <pos> ?<newval>? 181 if {[llength $args] % 2 == 0} { 182 error "wrong # args: should be \"visibility pos ?val pos val ...?\"" 183 } 184 185 set args [linsert $args 0 $pos] 186 foreach {pos newval} $args { 187 if {![string is boolean -strict $newval]} { 188 error "bad value \"$newval\": should be boolean" 189 } 190 if {$pos eq "end" || ($pos >= 0 && $pos < [llength $_visibility])} { 191 set _visibility [lreplace $_visibility $pos $pos [expr {$newval}]] 192 $_dispatcher event -idle !layout 193 } else { 194 error "bad index \"$pos\": out of range" 195 } 196 } 197 } 198 199 # ---------------------------------------------------------------------- 200 # USAGE: fraction <pos> ?<newval>? ?<pos> <newval> ...? 189 201 # 190 202 # Clients use this to get/set the fraction of real estate associated 191 # with the pane at position <pos>. 192 # ---------------------------------------------------------------------- 193 itcl::body Rappture::Panes::fraction {pos {newval ""}} { 194 if {"" == $newval} { 195 return [lindex $_frac $pos] 196 } 197 if {![string is double $newval]} { 198 error "bad value \"$newval\": should be fraction 0-1" 199 } 200 if {$pos == "end" || ($pos >= 0 && $pos < [llength $_frac])} { 201 set len [llength $_frac] 202 set _frac [lreplace $_frac $pos $pos xxx] 203 set total 0 204 foreach f $_frac { 205 if {"xxx" != $f} { 206 set total [expr {$total+$f}] 207 } 208 } 209 for {set i 0} {$i < $len} {incr i} { 210 set f [lindex $_frac $i] 211 if {"xxx" == $f} { 212 set f $newval 213 } else { 214 set f [expr {$f/$total - $newval/double($len-1)}] 215 } 216 set _frac [lreplace $_frac $i $i $f] 217 } 218 $_dispatcher event -idle !layout 219 } else { 220 error "bad index \"$pos\": out of range" 203 # with the pane at position <pos>. Can also be used to set the 204 # fractions for multiple panes if multiple <pos>/<newval> pairs 205 # are specified in the same command. 206 # ---------------------------------------------------------------------- 207 itcl::body Rappture::Panes::fraction {pos args} { 208 if {[llength $args] == 0} { 209 return [lindex $_reqfrac $pos] 210 } 211 if {[llength $args] % 2 == 0} { 212 error "wrong # args: should be \"fraction pos ?val pos val ...?\"" 213 } 214 215 set args [linsert $args 0 $pos] 216 foreach {pos newval} $args { 217 if {![string is double -strict $newval]} { 218 error "bad value \"$newval\": should be fraction 0-1" 219 } 220 if {$pos eq "end" || ($pos >= 0 && $pos < [llength $_reqfrac])} { 221 set _reqfrac [lreplace $_reqfrac $pos $pos $newval] 222 $_dispatcher event -idle !layout 223 } else { 224 error "bad index \"$pos\": out of range" 225 } 221 226 } 222 227 } … … 230 235 itcl::body Rappture::Panes::hilite {state sash} { 231 236 switch -- $itk_option(-sashrelief) { 237 flat { 238 if {$state} { 239 $itk_component(${sash}ridge) configure -background black 240 } else { 241 $itk_component(${sash}ridge) configure -background $itk_option(-background) 242 } 243 } 232 244 sunken { 233 245 if {$state} { … … 256 268 257 269 # ---------------------------------------------------------------------- 270 # USAGE: size 271 # 272 # Returns the number of panes in this widget. That makes it easier 273 # to index the various panes, since indices run from 0 to size-1. 274 # ---------------------------------------------------------------------- 275 itcl::body Rappture::Panes::size {} { 276 return [llength $_panes] 277 } 278 279 # ---------------------------------------------------------------------- 258 280 # USAGE: _grab <pane> <X> <Y> 259 281 # … … 262 284 # ---------------------------------------------------------------------- 263 285 itcl::body Rappture::Panes::_grab {pname X Y} { 286 set pos [lsearch $_panes $pname] 287 if {$pos < 0} return 288 set frac0 [lindex $_reqfrac [expr {$pos-1}]] 289 set frac1 [lindex $_reqfrac $pos] 290 set _dragfrac [expr {$frac0+$frac1}] 291 292 if {$itk_option(-orientation) eq "vertical"} { 293 set _dragfrom $Y 294 } else { 295 set _dragfrom $X 296 } 264 297 } 265 298 … … 270 303 # ---------------------------------------------------------------------- 271 304 itcl::body Rappture::Panes::_drag {pname X Y} { 272 if { $orientation == "vertical" } { 273 set realY [expr {$Y-[winfo rooty $itk_component(hull)]}] 305 set pos [lsearch $_panes $pname] 306 if {$pos < 0} return 307 set frac [lindex $_reqfrac $pos] 308 309 if {$itk_option(-orientation) eq "vertical"} { 310 set delY [expr {$_dragfrom-$Y}] 274 311 set Ymax [winfo height $itk_component(hull)] 275 set frac [expr double($realY)/$Ymax] 312 set delta [expr {double($delY)/$Ymax}] 313 set frac [expr {$frac + $delta}] 314 set _dragfrom $Y 276 315 } else { 277 set realX [expr {$X-[winfo rootx $itk_component(hull)]}]316 set delX [expr {$_dragfrom-$X}] 278 317 set Xmax [winfo width $itk_component(hull)] 279 set frac [expr double($realX)/$Xmax] 280 } 318 set delta [expr {double($delX)/$Xmax}] 319 set frac [expr {$frac + $delta}] 320 set _dragfrom $X 321 } 322 if {$delta == 0.0} { 323 return 324 } 325 326 # set limits so the pane can't get too large or too small 281 327 if {$frac < 0.05} { 282 328 set frac 0.05 283 329 } 284 if {$frac > 0.95} { 285 set frac 0.95 286 } 287 if {[llength $_frac] == 2} { 288 set _frac [list $frac [expr {1-$frac}]] 289 } else { 290 set i [expr {[lsearch $_panes $pname]-1}] 291 if {$i >= 0} { 292 set _frac [lreplace $_frac $i $i $frac] 293 } 294 } 330 if {$frac > $_dragfrac-0.05} { 331 set frac [expr {$_dragfrac-0.05}] 332 } 333 334 # replace the fractions for this pane and the one before it 335 set prevfrac [expr {$_dragfrac-$frac}] 336 set _reqfrac [lreplace $_reqfrac [expr {$pos-1}] $pos $prevfrac $frac] 337 338 # normalize all fractions and fix the layout 295 339 _fixLayout 296 340 … … 314 358 # ---------------------------------------------------------------------- 315 359 itcl::body Rappture::Panes::_fixLayout {args} { 316 if { $orientation == "vertical" } { 360 # normalize the fractions for all panes to they add to 1.0 361 set total 0 362 foreach f $_reqfrac v $_visibility { 363 if {$v && $f > 0} { 364 set total [expr {$total + $f}] 365 } 366 } 367 if {$total == 0.0} { set total 1 } 368 369 set normfrac "" 370 foreach f $_reqfrac v $_visibility { 371 if {$v} { 372 lappend normfrac [expr {double($f)/$total}] 373 } else { 374 lappend normfrac [expr {double($f)/$total}] 375 } 376 } 377 378 # note that sash padding can be a single number or different on each side 379 if {[llength $itk_option(-sashpadding)] == 1} { 380 set pad [expr {2*$itk_option(-sashpadding)}] 381 } else { 382 set pad [expr [join $itk_option(-sashpadding) +]] 383 } 384 385 if {$itk_option(-orientation) eq "vertical"} { 317 386 set h [winfo height $itk_component(hull)] 387 set sh [expr {$itk_option(-sashwidth) + $pad}] 318 388 319 389 set plist "" 320 390 set flist "" 321 foreach p $_panes f $ _frac v $_visibility {391 foreach p $_panes f $normfrac v $_visibility { 322 392 set sash ${p}sash 323 393 if {$v} { … … 326 396 lappend flist $f 327 397 if {[info exists itk_component($sash)]} { 328 set h [expr {$h - [winfo reqheight $itk_component($sash)]}]398 set h [expr {$h - $sh}] 329 399 } 330 400 } else { … … 336 406 } 337 407 } 338 339 # normalize the fractions so they add up to 1 340 set total 0 341 foreach f $flist { set total [expr {$total+$f}] } 342 set newflist "" 343 foreach f $flist { 344 lappend newflist [expr {double($f)/$total}] 345 } 346 set flist $newflist 347 408 348 409 # lay out the various panes 349 410 set y 0 … … 351 412 set sash ${p}sash 352 413 if {[info exists itk_component($sash)]} { 353 set sh [winfo reqheight $itk_component($sash)]354 414 place $itk_component($sash) -y $y -relx 0.5 -anchor n \ 355 415 -relwidth 1.0 -height $sh … … 364 424 } else { 365 425 set w [winfo width $itk_component(hull)] 426 set sw [expr {$itk_option(-sashwidth) + $pad}] 366 427 367 428 set plist "" 368 429 set flist "" 369 foreach p $_panes f $ _frac v $_visibility {430 foreach p $_panes f $normfrac v $_visibility { 370 431 set sash ${p}sash 371 432 if {$v} { … … 374 435 lappend flist $f 375 436 if {[info exists itk_component($sash)]} { 376 set w [expr {$w - [winfo reqwidth $itk_component($sash)]}]437 set w [expr {$w - $sw}] 377 438 } 378 439 } else { … … 384 445 } 385 446 } 386 387 # normalize the fractions so they add up to 1 388 set total 0 389 foreach f $flist { set total [expr {$total+$f}] } 390 set newflist "" 391 foreach f $flist { 392 lappend newflist [expr {double($f)/$total}] 393 } 394 set flist $newflist 395 447 396 448 # lay out the various panes 397 449 set x 0 … … 399 451 set sash ${p}sash 400 452 if {[info exists itk_component($sash)]} { 401 set sw [winfo reqwidth $itk_component($sash)]402 453 place $itk_component($sash) -x $x -rely 0.5 -anchor w \ 403 454 -relheight 1.0 -width $sw … … 420 471 # ---------------------------------------------------------------------- 421 472 itcl::body Rappture::Panes::_fixSashes {args} { 422 if { $orientation == "vertical"} {473 if {$itk_option(-orientation) eq "vertical"} { 423 474 set ht [winfo pixels $itk_component(hull) $itk_option(-sashwidth)] 424 475 set bd [expr {$ht/2}] … … 426 477 set sash "${pane}sashridge" 427 478 if {[info exists itk_component($sash)]} { 428 $itk_component($sash) configure -height $ht -borderwidth $bd 429 if {$itk_option(-sashrelief) == "solid"} { 430 $itk_component($sash) configure -background black 431 } else { 432 $itk_component($sash) configure \ 433 -background $itk_option(-background) 434 } 435 pack $itk_component($sash) -pady $itk_option(-sashpadding) 479 $itk_component($sash) configure -height $ht \ 480 -borderwidth $bd -relief $itk_option(-sashrelief) 481 pack $itk_component($sash) -pady $itk_option(-sashpadding) \ 482 -side top 436 483 } 437 484 } … … 442 489 set sash "${pane}sashridge" 443 490 if {[info exists itk_component($sash)]} { 444 $itk_component($sash) configure -width $w -borderwidth $bd 445 if {$itk_option(-sashrelief) == "solid"} { 446 $itk_component($sash) configure -background black 447 } else { 448 $itk_component($sash) configure \ 449 -background $itk_option(-background) 450 } 491 $itk_component($sash) configure -width $w \ 492 -borderwidth $bd -relief $itk_option(-sashrelief) 451 493 pack $itk_component($sash) -padx $itk_option(-sashpadding) \ 452 494 -side left … … 474 516 # ---------------------------------------------------------------------- 475 517 itcl::configbody Rappture::Panes::sashpadding { 518 set count 0 519 foreach val $itk_option(-sashpadding) { 520 if {![string is integer -strict $val]} { 521 error "bad padding value \"$val\": should be integer" 522 } 523 incr count 524 } 525 if {$count < 1 || $count > 2} { 526 error "bad padding value \"$itk_option(-sashpadding)\": should be \"#\" or \"# #\"" 527 } 476 528 $_dispatcher event -idle !sashes 477 529 } 530 531 # ---------------------------------------------------------------------- 532 # CONFIGURATION OPTION: -orientation 533 # ---------------------------------------------------------------------- 534 itcl::configbody Rappture::Panes::orientation { 535 foreach pname $_panes { 536 set sash "${pname}sash" 537 if {$itk_option(-orientation) eq "vertical"} { 538 place $itk_component($pname) -x 0 -relx 0.5 -relwidth 1 \ 539 -y 0 -rely 0 -relheight 0 540 541 if {[info exists itk_component($sash)]} { 542 place $itk_component($sash) -x 0 -relx 0.5 -relwidth 1 \ 543 -y 0 -rely 0 -relheight 0 544 $itk_component($sash) configure \ 545 -cursor sb_v_double_arrow 546 547 pack $itk_component(${sash}ridge) -fill x -side top 548 $itk_component(${sash}ridge) configure \ 549 -cursor sb_v_double_arrow 550 } 551 } else { 552 place $itk_component($pname) -y 0 -rely 0.5 -relheight 1 \ 553 -x 0 -relx 0 -relwidth 0 554 555 if {[info exists itk_component($sash)]} { 556 place $itk_component($sash) -y 0 -rely 0.5 -relheight 1 \ 557 -x 0 -relx 0 -relwidth 0 558 $itk_component($sash) configure \ 559 -cursor sb_h_double_arrow 560 561 pack $itk_component(${sash}ridge) -fill y -side left 562 $itk_component(${sash}ridge) configure \ 563 -cursor sb_h_double_arrow 564 } 565 } 566 } 567 568 # fix sash characteristics 569 $_dispatcher event -idle !sashes 570 571 # make sure we fix up the layout at some point 572 $_dispatcher event -idle !layout 573 } -
branches/uq/gui/scripts/resultviewer.tcl
r4512 r5121 293 293 } 294 294 } 295 ::Rappture::Map {296 if { ![$dataobj isvalid] } {297 return; # Ignore invalid map objects.298 }299 set mode "map"300 if {![info exists _mode2widget($mode)]} {301 set servers [Rappture::VisViewer::GetServerList "geovis"]302 set w $itk_interior.$mode303 Rappture::MapViewer $w $servers304 set _mode2widget($mode) $w305 }306 }307 295 ::Rappture::Field { 308 296 if { ![$dataobj isvalid] } { … … 493 481 set dobj [Rappture::Field ::#auto $xmlobj $path] 494 482 } 495 map {496 set dobj [Rappture::Map ::#auto $xmlobj $path]497 }498 483 mesh { 499 484 set dobj [Rappture::Mesh ::#auto $xmlobj $path] -
branches/uq/gui/scripts/textentry.tcl
r4405 r5121 106 106 # the string alone. 107 107 set str [string trim [$_owner xml get $path.default]] 108 if { [info exists ::Rappture::parameters($path.default)] } {109 set fileName $::Rappture::parameters($path.default)110 catch {111 set f [open $fileName "r"]112 set contents [read $f]113 close $f114 set str $contents115 }116 }117 108 if {"" != $str} { 118 109 value $str -
branches/uq/gui/scripts/tool.tcl
r5102 r5121 36 36 public method run {args} { 37 37 sync ;# sync all widget values to XML 38 puts "Tool $_task run $args" 39 eval $_task run $args 38 39 foreach {status result} [eval $_task run $args] break 40 if {$status == 0} { 41 # move good results to the data/results directory 42 $_task save $result 43 } 44 45 return [list $status $result] 40 46 } 41 47 public method abort {} { -
branches/uq/gui/scripts/unirect2d.tcl
r4497 r5121 176 176 # ---------------------------------------------------------------------- 177 177 # method blob 178 # Returns a base64 encoded, gzipped Tcl list that represents the 179 # Tcl command and data to recreate the uniform rectangular grid 180 # on the nanovis server. 178 # Returns a Tcl list that represents the Tcl command and data to 179 # recreate the uniform rectangular grid on the nanovis server. 181 180 # ---------------------------------------------------------------------- 182 181 itcl::body Rappture::Unirect2d::blob {} { … … 189 188 # ---------------------------------------------------------------------- 190 189 # method mesh 191 # Returns a base64 encoded, gzipped Tcl list that represents the 192 # Tcl command and data to recreate the uniform rectangular grid 193 # on the nanovis server. 190 # Returns a Tcl list that represents the mesh limits and dims. 194 191 # ---------------------------------------------------------------------- 195 192 itcl::body Rappture::Unirect2d::mesh {} { -
branches/uq/gui/scripts/unirect3d.tcl
r4494 r5121 41 41 private variable _xMax 0 42 42 private variable _xMin 0 43 private variable _xNum 0; # Number of points along x-axis .43 private variable _xNum 0; # Number of points along x-axis 44 44 private variable _yMax 0 45 45 private variable _yMin 0 46 private variable _yNum 0; # Number of points along y-axis .46 private variable _yNum 0; # Number of points along y-axis 47 47 private variable _zMax 0 48 48 private variable _zMin 0 49 private variable _zNum 0; # Number of points along z-axis .50 private variable _compNum 1; # Number of components in values .51 private variable _values ""; # BLT vector containing the z-values49 private variable _zNum 0; # Number of points along z-axis 50 private variable _compNum 1; # Number of components in values 51 private variable _values ""; # BLT vector containing the values 52 52 private variable _hints 53 53 } … … 124 124 # ---------------------------------------------------------------------- 125 125 # method blob 126 # Returns a base64 encoded, gzipped Tcl list that represents the 127 # Tcl command and data to recreate the uniform rectangular grid 128 # on the nanovis server. 126 # Returns a Tcl list that represents the Tcl command and data to 127 # recreate the uniform rectangular grid on the nanovis server. 129 128 # ---------------------------------------------------------------------- 130 129 itcl::body Rappture::Unirect3d::blob {} { … … 142 141 # ---------------------------------------------------------------------- 143 142 # method mesh 144 # Returns a base64 encoded, gzipped Tcl list that represents the 145 # Tcl command and data to recreate the uniform rectangular grid 146 # on the nanovis server. 143 # Returns a Tcl list that represents the points of the uniform 144 # grid. 147 145 # ---------------------------------------------------------------------- 148 146 itcl::body Rappture::Unirect3d::mesh {} { -
branches/uq/gui/scripts/visviewer.tcl
r4512 r5121 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 2 2 3 3 # ---------------------------------------------------------------------- 4 # VisViewer - 5 # 6 # This class is the base class for the various visualization viewers 4 # VisViewer - 5 # 6 # This class is the base class for the various visualization viewers 7 7 # that use the nanoserver render farm. 8 8 # … … 22 22 23 23 private common _servers ;# array of visualization server lists 24 set _servers(geovis) "localhost:2015"25 24 set _servers(nanovis) "localhost:2000" 26 25 set _servers(pymol) "localhost:2020" … … 32 31 private common _done ; # Used to indicate status of send. 33 32 private variable _buffer ; # buffer for incoming/outgoing commands 34 private variable _initialized 33 private variable _initialized 35 34 private variable _isOpen 0 36 35 private variable _afterId -1 … … 72 71 private method SendHelper {} 73 72 private method SendHelper.old {} 74 private method WaitDialog { state } 75 76 protected method ToggleConsole {} 77 private method DebugConsole {} 78 private method BuildConsole {} 79 private method HideConsole {} 80 private method TraceComm { channel {data {}} } 81 private method SendDebugCommand {} 73 private method WaitDialog { state } 74 75 protected method ToggleConsole {} 76 private method DebugConsole {} 77 private method BuildConsole {} 78 private method HideConsole {} 79 private method TraceComm { channel {data {}} } 80 private method SendDebugCommand {} 82 81 83 82 protected method CheckConnection {} … … 86 85 protected method Connect { servers } 87 86 protected method Disconnect {} 88 protected method EnableWaitDialog { timeout } 87 protected method EnableWaitDialog { timeout } 89 88 protected method Euler2XYZ { theta phi psi } 90 89 protected method Flush {} … … 100 99 protected method SendEcho { channel {data ""} } 101 100 protected method StartBufferingCommands {} 102 protected method StartWaiting {} 101 protected method StartWaiting {} 103 102 protected method StopBufferingCommands {} 104 protected method StopWaiting {} 105 106 private method Waiting { option widget } 103 protected method StopWaiting {} 104 105 private method Waiting { option widget } 107 106 108 107 private proc CheckNameList { namelist } { … … 198 197 global env 199 198 if { [info exists env(VISRECORDER)] } { 200 201 202 203 199 set _logging 1 200 if { [file exists /tmp/recording.log] } { 201 file delete /tmp/recording.log 202 } 204 203 } 205 204 eval itk_initialize $args … … 257 256 # Connect to the visualization server (e.g. nanovis, pymolproxy). 258 257 # Creates an event callback that is triggered when we are idle 259 # (no I/O with the server) for some specified time. 258 # (no I/O with the server) for some specified time. 260 259 # 261 260 itcl::body Rappture::VisViewer::Connect { servers } { … … 280 279 set _hostname $server 281 280 fconfigure $_sid -translation binary -encoding binary 282 281 283 282 # Read back the server identification string. 284 283 if { [gets $_sid data] <= 0 } { … … 316 315 after cancel $_afterId 317 316 $_dispatcher cancel !timeout 318 catch {close $_sid} 317 catch {close $_sid} 319 318 set _sid "" 320 319 set _buffer(in) "" … … 341 340 # CheckConection -- 342 341 # 343 # This routine is called whenever we're about to send/receive data on 344 # the socket connection to the visualization server. If we're connected, 345 # then reset the timeout event. Otherwise try to reconnect to the 342 # This routine is called whenever we're about to send/receive data on 343 # the socket connection to the visualization server. If we're connected, 344 # then reset the timeout event. Otherwise try to reconnect to the 346 345 # visualization server. 347 346 # … … 399 398 } 400 399 puts -nonewline $_sid $_buffer(out) 401 flush $_sid 400 flush $_sid 402 401 set _done($this) 1; # Success 403 402 } … … 479 478 # StartWaiting -- 480 479 # 481 # Read some number of bytes from the visualization server. 480 # Read some number of bytes from the visualization server. 482 481 # 483 482 484 483 itcl::body Rappture::VisViewer::StartWaiting {} { 485 484 if { $_waitTimeout > 0 } { 486 after cancel $_afterId 485 after cancel $_afterId 487 486 set _afterId [after $_waitTimeout [itcl::code $this WaitDialog on]] 488 487 } 489 488 } 490 489 491 itcl::body Rappture::VisViewer::StopWaiting {} { 490 itcl::body Rappture::VisViewer::StopWaiting {} { 492 491 if { $_waitTimeout > 0 } { 493 492 WaitDialog off … … 495 494 } 496 495 497 itcl::body Rappture::VisViewer::EnableWaitDialog { value } { 496 itcl::body Rappture::VisViewer::EnableWaitDialog { value } { 498 497 set _waitTimeout $value 499 498 } … … 502 501 # ReceiveBytes -- 503 502 # 504 # Read some number of bytes from the visualization server. 503 # Read some number of bytes from the visualization server. 505 504 # 506 505 itcl::body Rappture::VisViewer::ReceiveBytes { size } { … … 620 619 } 621 620 622 # 621 # 623 622 # ReceiveEcho -- 624 623 # … … 643 642 } 644 643 set inner [frame $itk_component(plotarea).view.splash] 645 $inner configure -relief raised -bd 2 644 $inner configure -relief raised -bd 2 646 645 label $inner.text1 -text "Working...\nPlease wait." \ 647 -font "Arial 10" 648 label $inner.icon 646 -font "Arial 10" 647 label $inner.icon 649 648 pack $inner -expand yes -anchor c 650 649 blt::table $inner \ 651 650 0,0 $inner.text1 -anchor w \ 652 0,1 $inner.icon 651 0,1 $inner.icon 653 652 Waiting start $inner.icon 654 653 } else { … … 710 709 pack $f.send.l -side left 711 710 itk_component add command { 712 711 entry $f.send.e -background white 713 712 } { 714 713 ignore -background 715 714 } 716 715 pack $f.send.e -side left -expand yes -fill x … … 720 719 pack $f.sb -side right -fill y 721 720 itk_component add trace { 722 721 text $f.comm -wrap char -yscrollcommand "$f.sb set" -background white 723 722 } { 724 723 ignore -background 725 724 } 726 725 pack $f.comm -expand yes -fill both … … 730 729 731 730 $itk_component(trace) tag configure error -foreground red \ 732 731 -font -*-courier-medium-o-normal-*-*-120-* 733 732 $itk_component(trace) tag configure incoming -foreground blue 734 733 } … … 742 741 itcl::body Rappture::VisViewer::ToggleConsole {} { 743 742 if { $_debugConsole } { 744 743 set _debugConsole 0 745 744 } else { 746 745 set _debugConsole 1 747 746 } 748 747 DebugConsole … … 752 751 # DebugConsole -- 753 752 # 754 # Based on the value of the variable _debugConsole, turns on/off 755 # debugging. This is done by setting/unsetting a procedure that 756 # is called whenever new characters are received or sent on the 753 # Based on the value of the variable _debugConsole, turns on/off 754 # debugging. This is done by setting/unsetting a procedure that 755 # is called whenever new characters are received or sent on the 757 756 # socket to the render server. Additionally, the debug console 758 757 # is created if necessary and hidden/shown. … … 760 759 itcl::body Rappture::VisViewer::DebugConsole {} { 761 760 if { ![winfo exists .renderconsole] } { 762 761 BuildConsole 763 762 } 764 763 if { $_debugConsole } { 765 766 767 764 $this configure -sendcommand [itcl::code $this TraceComm] 765 $this configure -receivecommand [itcl::code $this TraceComm] 766 wm deiconify .renderconsole 768 767 } else { 769 770 771 768 $this configure -sendcommand "" 769 $this configure -receivecommand "" 770 wm withdraw .renderconsole 772 771 } 773 772 } … … 851 850 -title "Render Server Error" 852 851 set inner [$popup component inner] 853 label $inner.summary -text "" -anchor w 852 label $inner.summary -text "" -anchor w 854 853 855 854 Rappture::Scroller $inner.scrl \ 856 -xscrollmode auto -yscrollmode auto 855 -xscrollmode auto -yscrollmode auto 857 856 text $inner.scrl.text \ 858 857 -font "Arial 9 " -background white -relief sunken -bd 1 \ … … 863 862 blt::table $inner \ 864 863 0,0 $inner.scrl -fill both \ 865 1,0 $inner.ok 866 $inner.scrl.text tag configure normal -font "Arial 9" 867 $inner.scrl.text tag configure italic -font "Arial 9 italic" 864 1,0 $inner.ok 865 $inner.scrl.text tag configure normal -font "Arial 9" 866 $inner.scrl.text tag configure italic -font "Arial 9 italic" 868 867 $inner.scrl.text tag configure bold -font "Arial 10 bold" 869 868 $inner.scrl.text tag configure code -font "Courier 10 bold" … … 874 873 set inner [$popup component inner] 875 874 $inner.scrl.text delete 0.0 end 876 875 877 876 $inner.scrl.text configure -state normal 878 877 $inner.scrl.text insert end "The following error was reported by the render server:\n\n" bold … … 944 943 "blue-to-grey" { 945 944 return { 946 0.0 0.000 0.600 0.800 947 0.14285714285714285 0.400 0.900 1.000 948 0.2857142857142857 0.600 1.000 1.000 949 0.42857142857142855 0.800 1.000 1.000 950 0.5714285714285714 0.900 0.900 0.900 951 0.7142857142857143 0.600 0.600 0.600 952 0.8571428571428571 0.400 0.400 0.400 945 0.0 0.000 0.600 0.800 946 0.14285714285714285 0.400 0.900 1.000 947 0.2857142857142857 0.600 1.000 1.000 948 0.42857142857142855 0.800 1.000 1.000 949 0.5714285714285714 0.900 0.900 0.900 950 0.7142857142857143 0.600 0.600 0.600 951 0.8571428571428571 0.400 0.400 0.400 953 952 1.0 0.200 0.200 0.200 954 953 } 955 954 } 956 955 "white-to-blue" { 957 return { 958 0.0 0.900 1.000 1.000 959 0.1111111111111111 0.800 0.983 1.000 960 0.2222222222222222 0.700 0.950 1.000 961 0.3333333333333333 0.600 0.900 1.000 962 0.4444444444444444 0.500 0.833 1.000 963 0.5555555555555556 0.400 0.750 1.000 964 0.6666666666666666 0.300 0.650 1.000 965 0.7777777777777778 0.200 0.533 1.000 966 0.8888888888888888 0.100 0.400 1.000 956 return { 957 0.0 0.900 1.000 1.000 958 0.1111111111111111 0.800 0.983 1.000 959 0.2222222222222222 0.700 0.950 1.000 960 0.3333333333333333 0.600 0.900 1.000 961 0.4444444444444444 0.500 0.833 1.000 962 0.5555555555555556 0.400 0.750 1.000 963 0.6666666666666666 0.300 0.650 1.000 964 0.7777777777777778 0.200 0.533 1.000 965 0.8888888888888888 0.100 0.400 1.000 967 966 1.0 0.000 0.250 1.000 968 967 } … … 970 969 "brown-to-blue" { 971 970 return { 972 0.0 0.200 0.100 0.000 973 0.09090909090909091 0.400 0.187 0.000 974 0.18181818181818182 0.600 0.379 0.210 975 0.2727272727272727 0.800 0.608 0.480 976 0.36363636363636365 0.850 0.688 0.595 977 0.45454545454545453 0.950 0.855 0.808 978 0.5454545454545454 0.800 0.993 1.000 979 0.6363636363636364 0.600 0.973 1.000 980 0.7272727272727273 0.400 0.940 1.000 981 0.8181818181818182 0.200 0.893 1.000 982 0.9090909090909091 0.000 0.667 0.800 983 1.0 0.000 0.480 0.600 971 0.0 0.200 0.100 0.000 972 0.09090909090909091 0.400 0.187 0.000 973 0.18181818181818182 0.600 0.379 0.210 974 0.2727272727272727 0.800 0.608 0.480 975 0.36363636363636365 0.850 0.688 0.595 976 0.45454545454545453 0.950 0.855 0.808 977 0.5454545454545454 0.800 0.993 1.000 978 0.6363636363636364 0.600 0.973 1.000 979 0.7272727272727273 0.400 0.940 1.000 980 0.8181818181818182 0.200 0.893 1.000 981 0.9090909090909091 0.000 0.667 0.800 982 1.0 0.000 0.480 0.600 984 983 } 985 984 } 986 985 "blue-to-brown" { 987 986 return { 988 0.0 0.000 0.480 0.600 989 0.09090909090909091 0.000 0.667 0.800 990 0.18181818181818182 0.200 0.893 1.000 991 0.2727272727272727 0.400 0.940 1.000 992 0.36363636363636365 0.600 0.973 1.000 993 0.45454545454545453 0.800 0.993 1.000 994 0.5454545454545454 0.950 0.855 0.808 995 0.6363636363636364 0.850 0.688 0.595 996 0.7272727272727273 0.800 0.608 0.480 997 0.8181818181818182 0.600 0.379 0.210 998 0.9090909090909091 0.400 0.187 0.000 999 1.0 0.200 0.100 0.000 987 0.0 0.000 0.480 0.600 988 0.09090909090909091 0.000 0.667 0.800 989 0.18181818181818182 0.200 0.893 1.000 990 0.2727272727272727 0.400 0.940 1.000 991 0.36363636363636365 0.600 0.973 1.000 992 0.45454545454545453 0.800 0.993 1.000 993 0.5454545454545454 0.950 0.855 0.808 994 0.6363636363636364 0.850 0.688 0.595 995 0.7272727272727273 0.800 0.608 0.480 996 0.8181818181818182 0.600 0.379 0.210 997 0.9090909090909091 0.400 0.187 0.000 998 1.0 0.200 0.100 0.000 1000 999 } 1001 1000 } … … 1035 1034 set clist { 1036 1035 "#EE82EE" 1037 "#4B0082" 1038 "blue" 1039 "#008000" 1040 "yellow" 1041 "#FFA500" 1042 "red" 1036 "#4B0082" 1037 "blue" 1038 "#008000" 1039 "yellow" 1040 "#FFA500" 1041 "red" 1043 1042 } 1044 1043 } 1045 1044 "BGYOR" { 1046 1045 set clist { 1047 "blue" 1048 "#008000" 1049 "yellow" 1050 "#FFA500" 1051 "red" 1046 "blue" 1047 "#008000" 1048 "yellow" 1049 "#FFA500" 1050 "red" 1052 1051 } 1053 1052 } 1054 1053 "ROYGB" { 1055 1054 set clist { 1056 "red" 1057 "#FFA500" 1058 "yellow" 1059 "#008000" 1060 "blue" 1055 "red" 1056 "#FFA500" 1057 "yellow" 1058 "#008000" 1059 "blue" 1061 1060 } 1062 1061 } 1063 1062 "RYGCB" { 1064 1063 set clist { 1065 "red" 1066 "yellow" 1064 "red" 1065 "yellow" 1067 1066 "green" 1068 1067 "cyan" … … 1072 1071 "BCGYR" { 1073 1072 set clist { 1074 "blue" 1073 "blue" 1075 1074 "cyan" 1076 1075 "green" 1077 "yellow" 1078 "red" 1076 "yellow" 1077 "red" 1079 1078 } 1080 1079 } 1081 1080 "spectral" { 1082 1081 return { 1083 0.0 0.150 0.300 1.000 1084 0.1 0.250 0.630 1.000 1085 0.2 0.450 0.850 1.000 1086 0.3 0.670 0.970 1.000 1087 0.4 0.880 1.000 1.000 1088 0.5 1.000 1.000 0.750 1089 0.6 1.000 0.880 0.600 1090 0.7 1.000 0.680 0.450 1091 0.8 0.970 0.430 0.370 1092 0.9 0.850 0.150 0.196 1082 0.0 0.150 0.300 1.000 1083 0.1 0.250 0.630 1.000 1084 0.2 0.450 0.850 1.000 1085 0.3 0.670 0.970 1.000 1086 0.4 0.880 1.000 1.000 1087 0.5 1.000 1.000 0.750 1088 0.6 1.000 0.880 0.600 1089 0.7 1.000 0.680 0.450 1090 0.8 0.970 0.430 0.370 1091 0.9 0.850 0.150 0.196 1093 1092 1.0 0.650 0.000 0.130 1094 1093 } … … 1096 1095 "green-to-magenta" { 1097 1096 return { 1098 0.0 0.000 0.316 0.000 1099 0.06666666666666667 0.000 0.526 0.000 1100 0.13333333333333333 0.000 0.737 0.000 1101 0.2 0.000 0.947 0.000 1102 0.26666666666666666 0.316 1.000 0.316 1103 0.3333333333333333 0.526 1.000 0.526 1104 0.4 0.737 1.000 0.737 1105 0.4666666666666667 1.000 1.000 1.000 1106 0.5333333333333333 1.000 0.947 1.000 1107 0.6 1.000 0.737 1.000 1108 0.6666666666666666 1.000 0.526 1.000 1109 0.7333333333333333 1.000 0.316 1.000 1110 0.8 0.947 0.000 0.947 1111 0.8666666666666667 0.737 0.000 0.737 1112 0.9333333333333333 0.526 0.000 0.526 1097 0.0 0.000 0.316 0.000 1098 0.06666666666666667 0.000 0.526 0.000 1099 0.13333333333333333 0.000 0.737 0.000 1100 0.2 0.000 0.947 0.000 1101 0.26666666666666666 0.316 1.000 0.316 1102 0.3333333333333333 0.526 1.000 0.526 1103 0.4 0.737 1.000 0.737 1104 0.4666666666666667 1.000 1.000 1.000 1105 0.5333333333333333 1.000 0.947 1.000 1106 0.6 1.000 0.737 1.000 1107 0.6666666666666666 1.000 0.526 1.000 1108 0.7333333333333333 1.000 0.316 1.000 1109 0.8 0.947 0.000 0.947 1110 0.8666666666666667 0.737 0.000 0.737 1111 0.9333333333333333 0.526 0.000 0.526 1113 1112 1.0 0.316 0.000 0.316 1114 1113 } 1115 1114 } 1116 1115 "greyscale" { 1117 return { 1116 return { 1118 1117 0.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0 1119 1118 } … … 1145 1144 # 1146 1145 itcl::body Rappture::VisViewer::StartBufferingCommands { } { 1147 incr _buffering 1146 incr _buffering 1148 1147 if { $_buffering == 1 } { 1149 1148 set _outbuf "" … … 1171 1170 # 1172 1171 # Send commands off to the rendering server. If we're currently 1173 # sending data objects to the server, buffer the commands to be 1172 # sending data objects to the server, buffer the commands to be 1174 1173 # sent later. 1175 1174 # … … 1186 1185 # 1187 1186 # Send commands off to the rendering server. If we're currently 1188 # sending data objects to the server, buffer the commands to be 1187 # sending data objects to the server, buffer the commands to be 1189 1188 # sent later. 1190 1189 # -
branches/uq/gui/scripts/vtkglyphviewer.tcl
r4798 r5121 57 57 public method get {args} 58 58 public method isconnected {} 59 public method limits { colormap }60 59 public method parameters {title args} { 61 60 # do nothing … … 63 62 public method scale {args} 64 63 65 protected method Connect {}66 protected method CurrentDatasets {args}67 protected method Disconnect {}68 protected method DoResize {}69 protected method DoRotate {}70 protected method AdjustSetting {what {value ""}}71 protected method InitSettings { args }72 protected method Pan {option x y}73 protected method Pick {x y}74 protected method Rebuild {}75 protected method ReceiveDataset { args }76 protected method ReceiveImage { args }77 protected method ReceiveLegend { colormap title vmin vmax size }78 protected method Rotate {option x y}79 protected method Zoom {option}80 81 64 # The following methods are only used by this class. 65 private method AdjustSetting {what {value ""}} 82 66 private method BuildAxisTab {} 83 67 private method BuildCameraTab {} … … 88 72 private method DrawLegend {} 89 73 private method Combo { option } 74 private method Connect {} 75 private method CurrentDatasets {args} 76 private method Disconnect {} 77 private method DoResize {} 78 private method DoRotate {} 90 79 private method EnterLegend { x y } 91 80 private method EventuallyResize { w h } … … 95 84 private method GetImage { args } 96 85 private method GetVtkData { args } 86 private method InitSettings { args } 97 87 private method IsValidObject { dataobj } 98 88 private method LeaveLegend {} 99 89 private method MotionLegend { x y } 90 private method Pan {option x y} 100 91 private method PanCamera {} 92 private method Pick {x y} 93 private method QuaternionToView { q } { 94 foreach { _view(-qw) _view(-qx) _view(-qy) _view(-qz) } $q break 95 } 96 private method Rebuild {} 97 private method ReceiveDataset { args } 98 private method ReceiveImage { args } 99 private method ReceiveLegend { colormap title vmin vmax size } 101 100 private method RequestLegend {} 101 private method Rotate {option x y} 102 102 private method SetLegendTip { x y } 103 103 private method SetObjectStyle { dataobj comp } … … 105 105 private method SetCurrentColormap { color } 106 106 private method SetOrientation { side } 107 private method ViewToQuaternion {} { 108 return [list $_view(-qw) $_view(-qx) $_view(-qy) $_view(-qz)] 109 } 110 private method Zoom {option} 107 111 108 112 private variable _arcball "" … … 144 148 private variable _legendPending 0 145 149 private variable _field "" 146 private variable _colorMode "vmag"; 150 private variable _colorMode "vmag"; # Mode of colormap (vmag or scalar) 147 151 private variable _fieldNames {} 148 152 private variable _fields … … 203 207 # Initialize the view to some default parameters. 204 208 array set _view { 205 qw 0.853553206 qx -0.353553207 qy0.353553208 qz 0.146447209 zoom 1.0210 xpan 0211 ypan 0212 ortho0209 -ortho 0 210 -qw 0.853553 211 -qx -0.353553 212 -qy 0.353553 213 -qz 0.146447 214 -xpan 0 215 -ypan 0 216 -zoom 1.0 213 217 } 214 218 set _arcball [blt::arcball create 100 100] 215 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 216 $_arcball quaternion $q 219 $_arcball quaternion [ViewToQuaternion] 217 220 218 221 array set _settings [subst { … … 239 242 -glyphedges 0 240 243 -glyphlighting 1 244 -glyphnormscale 1 241 245 -glyphopacity 100 246 -glyphorient 1 242 247 -glyphoutline 0 243 248 -glyphscale 1 249 -glyphscalemode "vmag" 250 -glyphshape "arrow" 244 251 -glyphvisible 1 245 252 -glyphwireframe 0 … … 463 470 464 471 itcl::body Rappture::VtkGlyphViewer::DoRotate {} { 465 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 466 SendCmd "camera orient $q" 472 SendCmd "camera orient [ViewToQuaternion]" 467 473 set _rotatePending 0 468 474 } … … 488 494 489 495 itcl::body Rappture::VtkGlyphViewer::EventuallyRotate { q } { 490 foreach { _view(qw) _view(qx) _view(qy) _view(qz) } $q break496 QuaternionToView $q 491 497 if { !$_rotatePending } { 492 498 set _rotatePending 1 … … 833 839 array unset _data 834 840 array unset _colormaps 835 array unset _seeds836 841 array unset _dataset2style 837 842 array unset _obj2datasets … … 855 860 if { $info(-type) == "image" } { 856 861 if 0 { 857 set f [open "last.ppm" "w"] 858 puts $f $bytes 862 set f [open "last.ppm" "w"] 863 fconfigure $f -encoding binary 864 puts -nonewline $f $bytes 859 865 close $f 860 866 } … … 944 950 # Reset the camera and other view parameters 945 951 # 946 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 947 $_arcball quaternion $q 948 if {$_view(ortho)} { 952 $_arcball quaternion [ViewToQuaternion] 953 if {$_view(-ortho)} { 949 954 SendCmd "camera mode ortho" 950 955 } else { … … 956 961 InitSettings -xgrid -ygrid -zgrid -axismode \ 957 962 -axesvisible -axislabels -axisminorticks 958 foreach axis { x y z } { 959 SendCmd "axis lformat $axis %g" 960 } 963 #SendCmd "axis lformat all %g" 961 964 StopBufferingCommands 962 965 SendCmd "imgflush" … … 976 979 if 0 { 977 980 set f [open "/tmp/glyph.vtk" "w"] 978 puts $f $bytes 981 fconfigure $f -translation binary -encoding binary 982 puts -nonewline $f $bytes 979 983 close $f 980 984 } … … 982 986 if { $_reportClientInfo } { 983 987 set info {} 984 lappend info "tool_id" [$dataobj hints toolId] 985 lappend info "tool_name" [$dataobj hints toolName] 986 lappend info "tool_version" [$dataobj hints toolRevision] 987 lappend info "tool_title" [$dataobj hints toolTitle] 988 lappend info "tool_id" [$dataobj hints toolid] 989 lappend info "tool_name" [$dataobj hints toolname] 990 lappend info "tool_title" [$dataobj hints tooltitle] 991 lappend info "tool_command" [$dataobj hints toolcommand] 992 lappend info "tool_revision" [$dataobj hints toolrevision] 988 993 lappend info "dataset_label" [$dataobj hints label] 989 994 lappend info "dataset_size" $length … … 1039 1044 # These are settings that rely on a dataset being loaded. 1040 1045 InitSettings \ 1041 -glyphlighting \1042 1046 -field \ 1043 1047 -glyphedges -glyphlighting -glyphopacity \ … … 1129 1133 switch -- $option { 1130 1134 "in" { 1131 set _view( zoom) [expr {$_view(zoom)*1.25}]1132 SendCmd "camera zoom $_view( zoom)"1135 set _view(-zoom) [expr {$_view(-zoom)*1.25}] 1136 SendCmd "camera zoom $_view(-zoom)" 1133 1137 } 1134 1138 "out" { 1135 set _view( zoom) [expr {$_view(zoom)*0.8}]1136 SendCmd "camera zoom $_view( zoom)"1139 set _view(-zoom) [expr {$_view(-zoom)*0.8}] 1140 SendCmd "camera zoom $_view(-zoom)" 1137 1141 } 1138 1142 "reset" { 1139 1143 array set _view { 1140 qw0.8535531141 qx-0.3535531142 qy0.3535531143 qz0.1464471144 zoom 1.01145 xpan01146 ypan01144 -qw 0.853553 1145 -qx -0.353553 1146 -qy 0.353553 1147 -qz 0.146447 1148 -xpan 0 1149 -ypan 0 1150 -zoom 1.0 1147 1151 } 1148 1152 if { $_first != "" } { … … 1152 1156 } 1153 1157 } 1154 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 1155 $_arcball quaternion $q 1158 $_arcball quaternion [ViewToQuaternion] 1156 1159 DoRotate 1157 1160 SendCmd "camera reset" … … 1161 1164 1162 1165 itcl::body Rappture::VtkGlyphViewer::PanCamera {} { 1163 set x $_view( xpan)1164 set y $_view( ypan)1166 set x $_view(-xpan) 1167 set y $_view(-ypan) 1165 1168 SendCmd "camera pan $x $y" 1166 1169 } … … 1220 1223 itcl::body Rappture::VtkGlyphViewer::Pick {x y} { 1221 1224 foreach tag [CurrentDatasets -visible] { 1222 SendCmd NoSplash"dataset getscalar pixel $x $y $tag"1225 SendCmd "dataset getscalar pixel $x $y $tag" 1223 1226 } 1224 1227 } … … 1239 1242 set x [expr $x / double($w)] 1240 1243 set y [expr $y / double($h)] 1241 set _view( xpan) [expr $_view(xpan) + $x]1242 set _view( ypan) [expr $_view(ypan) + $y]1244 set _view(-xpan) [expr $_view(-xpan) + $x] 1245 set _view(-ypan) [expr $_view(-ypan) + $y] 1243 1246 PanCamera 1244 1247 return … … 1262 1265 set _click(x) $x 1263 1266 set _click(y) $y 1264 set _view( xpan) [expr $_view(xpan) - $dx]1265 set _view( ypan) [expr $_view(ypan) - $dy]1267 set _view(-xpan) [expr $_view(-xpan) - $dx] 1268 set _view(-ypan) [expr $_view(-ypan) - $dy] 1266 1269 PanCamera 1267 1270 } … … 1346 1349 "-cutplanevisible" { 1347 1350 set bool $_settings($what) 1348 SendCmd "cutplane visible $bool" 1351 SendCmd "cutplane visible 0" 1352 if { $bool } { 1353 foreach tag [CurrentDatasets -visible] { 1354 SendCmd "cutplane visible $bool $tag" 1355 } 1356 } 1349 1357 } 1350 1358 "-cutplanewireframe" { … … 1409 1417 "-glyphvisible" { 1410 1418 set bool $_settings($what) 1411 SendCmd "glyphs visible $bool" 1419 SendCmd "glyphs visible 0" 1420 if { $bool } { 1421 foreach tag [CurrentDatasets -visible] { 1422 SendCmd "glyphs visible $bool $tag" 1423 } 1424 } 1412 1425 if { $bool } { 1413 1426 Rappture::Tooltip::for $itk_component(glyphs) \ … … 1429 1442 "-glyphoutline" { 1430 1443 set bool $_settings($what) 1431 SendCmd "outline visible $bool" 1444 SendCmd "outline visible 0" 1445 if { $bool } { 1446 foreach tag [CurrentDatasets -visible] { 1447 SendCmd "outline visible $bool $tag" 1448 } 1449 } 1432 1450 } 1433 1451 "-glyphopacity" { … … 1436 1454 SendCmd "glyphs opacity $sval" 1437 1455 } 1456 "-glyphnormscale" { 1457 set bool $_settings($what) 1458 SendCmd "glyphs normscale $bool" 1459 } 1460 "-glyphorient" { 1461 set bool $_settings($what) 1462 SendCmd "glyphs gorient $bool {}" 1463 } 1438 1464 "-glyphscale" { 1439 1465 set val $_settings($what) … … 1441 1467 SendCmd "glyphs gscale $val" 1442 1468 } 1469 } 1470 "-glyphscalemode" { 1471 set label [$itk_component(scaleMode) value] 1472 set mode [$itk_component(scaleMode) translate $label] 1473 set _settings($what) $mode 1474 SendCmd "glyphs smode $mode {}" 1475 } 1476 "-glyphshape" { 1477 set label [$itk_component(gshape) value] 1478 set shape [$itk_component(gshape) translate $label] 1479 set _settings($what) $shape 1480 SendCmd "glyphs shape $shape" 1443 1481 } 1444 1482 "-field" { … … 1459 1497 return 1460 1498 } 1499 #if { ![info exists _limits($_curFldName)] } { 1500 # SendCmd "dataset maprange all" 1501 #} else { 1502 # SendCmd "dataset maprange explicit $_limits($_curFldName) $_curFldName" 1503 #} 1504 #SendCmd "cutplane colormode $_colorMode $_curFldName" 1461 1505 SendCmd "glyphs colormode $_colorMode $_curFldName" 1462 1506 DrawLegend … … 1544 1588 } 1545 1589 1546 itcl::body Rappture::VtkGlyphViewer::limits { dataobj } {1547 foreach { limits(xmin) limits(xmax) } [$dataobj limits x] break1548 foreach { limits(ymin) limits(ymax) } [$dataobj limits y] break1549 foreach { limits(zmin) limits(zmax) } [$dataobj limits z] break1550 foreach { limits(vmin) limits(vmax) } [$dataobj limits v] break1551 return [array get limits]1552 }1553 1554 1590 itcl::body Rappture::VtkGlyphViewer::BuildGlyphTab {} { 1555 1591 … … 1567 1603 -command [itcl::code $this AdjustSetting -glyphvisible] \ 1568 1604 -font "Arial 9" 1605 1606 label $inner.gshape_l -text "Glyph shape" -font "Arial 9" 1607 itk_component add gshape { 1608 Rappture::Combobox $inner.gshape -width 10 -editable no 1609 } 1610 $inner.gshape choices insert end \ 1611 "arrow" "arrow" \ 1612 "cone" "cone" \ 1613 "cube" "cube" \ 1614 "cylinder" "cylinder" \ 1615 "dodecahedron" "dodecahedron" \ 1616 "icosahedron" "icosahedron" \ 1617 "line" "line" \ 1618 "octahedron" "octahedron" \ 1619 "point" "point" \ 1620 "sphere" "sphere" \ 1621 "tetrahedron" "tetrahedron" 1622 1623 $itk_component(gshape) value $_settings(-glyphshape) 1624 bind $inner.gshape <<Value>> [itcl::code $this AdjustSetting -glyphshape] 1625 1626 label $inner.scaleMode_l -text "Scale by" -font "Arial 9" 1627 itk_component add scaleMode { 1628 Rappture::Combobox $inner.scaleMode -width 10 -editable no 1629 } 1630 $inner.scaleMode choices insert end \ 1631 "scalar" "Scalar" \ 1632 "vmag" "Vector magnitude" \ 1633 "vcomp" "Vector components" \ 1634 "off" "Constant size" 1635 1636 $itk_component(scaleMode) value "[$itk_component(scaleMode) label $_settings(-glyphscalemode)]" 1637 bind $inner.scaleMode <<Value>> [itcl::code $this AdjustSetting -glyphscalemode] 1638 1639 checkbutton $inner.normscale \ 1640 -text "Normalize scaling" \ 1641 -variable [itcl::scope _settings(-glyphnormscale)] \ 1642 -command [itcl::code $this AdjustSetting -glyphnormscale] \ 1643 -font "Arial 9" 1644 Rappture::Tooltip::for $inner.normscale "If enabled, field values are normalized to \[0,1\] before scaling and scale factor is relative to a default size" 1645 1646 checkbutton $inner.gorient \ 1647 -text "Orient" \ 1648 -variable [itcl::scope _settings(-glyphorient)] \ 1649 -command [itcl::code $this AdjustSetting -glyphorient] \ 1650 -font "Arial 9" 1651 Rappture::Tooltip::for $inner.gorient "Orient glyphs by vector field directions" 1569 1652 1570 1653 checkbutton $inner.wireframe \ … … 1618 1701 1619 1702 label $inner.gscale_l -text "Scale factor" -font "Arial 9" 1703 if {0} { 1620 1704 ::scale $inner.gscale -from 1 -to 100 -orient horizontal \ 1621 1705 -variable [itcl::scope _settings(-glyphscale)] \ … … 1623 1707 -showvalue off \ 1624 1708 -command [itcl::code $this AdjustSetting -glyphscale] 1709 } else { 1710 itk_component add gscale { 1711 entry $inner.gscale -font "Arial 9" -bg white \ 1712 -textvariable [itcl::scope _settings(-glyphscale)] 1713 } { 1714 ignore -font -background 1715 } 1716 bind $inner.gscale <Return> \ 1717 [itcl::code $this AdjustSetting -glyphscale] 1718 bind $inner.gscale <KP_Enter> \ 1719 [itcl::code $this AdjustSetting -glyphscale] 1720 } 1625 1721 Rappture::Tooltip::for $inner.gscale "Set scaling multiplier (or constant size)" 1626 1722 … … 1755 1851 0,0 $inner.view_l -anchor e -pady 2 \ 1756 1852 0,1 $inner.view -anchor w -pady 2 1853 blt::table configure $inner r0 -resize none 1757 1854 1758 1855 set labels { qx qy qz qw xpan ypan zoom } … … 1761 1858 label $inner.${tag}label -text $tag -font "Arial 9" 1762 1859 entry $inner.${tag} -font "Arial 9" -bg white \ 1763 -textvariable [itcl::scope _view($tag)] 1764 bind $inner.${tag} <KeyPress-Return> \ 1765 [itcl::code $this camera set ${tag}] 1860 -textvariable [itcl::scope _view(-$tag)] 1861 bind $inner.${tag} <Return> \ 1862 [itcl::code $this camera set -${tag}] 1863 bind $inner.${tag} <KP_Enter> \ 1864 [itcl::code $this camera set -${tag}] 1766 1865 blt::table $inner \ 1767 1866 $row,0 $inner.${tag}label -anchor e -pady 2 \ … … 1772 1871 checkbutton $inner.ortho \ 1773 1872 -text "Orthographic Projection" \ 1774 -variable [itcl::scope _view( ortho)] \1775 -command [itcl::code $this camera set ortho] \1873 -variable [itcl::scope _view(-ortho)] \ 1874 -command [itcl::code $this camera set -ortho] \ 1776 1875 -font "Arial 9" 1777 1876 blt::table $inner \ … … 1780 1879 incr row 1781 1880 1782 blt::table configure $inner c* r*-resize none1881 blt::table configure $inner c* -resize none 1783 1882 blt::table configure $inner c2 -resize expand 1784 1883 blt::table configure $inner r$row -resize expand … … 1949 2048 } 1950 2049 "set" { 1951 set wh o[lindex $args 0]1952 set x $_view($wh o)2050 set what [lindex $args 0] 2051 set x $_view($what) 1953 2052 set code [catch { string is double $x } result] 1954 2053 if { $code != 0 || !$result } { 1955 2054 return 1956 2055 } 1957 switch -- $wh o{1958 " ortho" {1959 if {$_view( ortho)} {2056 switch -- $what { 2057 "-ortho" { 2058 if {$_view($what)} { 1960 2059 SendCmd "camera mode ortho" 1961 2060 } else { … … 1963 2062 } 1964 2063 } 1965 " xpan" - "ypan" {2064 "-xpan" - "-ypan" { 1966 2065 PanCamera 1967 2066 } 1968 " qx" - "qy" - "qz" - "qw" {1969 set q [ list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]2067 "-qx" - "-qy" - "-qz" - "-qw" { 2068 set q [ViewToQuaternion] 1970 2069 $_arcball quaternion $q 1971 2070 EventuallyRotate $q 1972 2071 } 1973 " zoom" {1974 SendCmd "camera zoom $_view( zoom)"2072 "-zoom" { 2073 SendCmd "camera zoom $_view($what)" 1975 2074 } 1976 2075 } … … 2106 2205 2107 2206 SendCmd "glyphs add $style(-shape) $tag" 2207 set _settings(-glyphshape) $style(-shape) 2208 $itk_component(gshape) value $style(-shape) 2108 2209 SendCmd "glyphs edges $style(-edges) $tag" 2109 2210 set _settings(-glyphedges) $style(-edges) … … 2116 2217 SendCmd "glyphs gscale $style(-gscale) $tag" 2117 2218 } 2219 set _settings(-glyphnormscale) $style(-normscale) 2220 set _settings(-glyphscale) $style(-gscale) 2118 2221 2119 2222 # constant color only used if colormode set to constant … … 2122 2225 # defaults to active scalars or vectors depending on mode 2123 2226 SendCmd "glyphs gorient $style(-orientGlyphs) {} $tag" 2227 set _settings(-glyphorient) $style(-orientGlyphs) 2124 2228 SendCmd "glyphs smode $style(-scaleMode) {} $tag" 2229 set _settings(-glyphscalemode) $style(-scaleMode) 2230 $itk_component(scaleMode) value "[$itk_component(scaleMode) label $style(-scaleMode)]" 2125 2231 SendCmd "glyphs quality $style(-quality) $tag" 2126 2232 SendCmd "glyphs lighting $style(-lighting) $tag" … … 2447 2553 bottom "0.707107 0.707107 0 0" 2448 2554 } 2449 foreach name { qw qx qyqz } value $positions($side) {2555 foreach name { -qw -qx -qy -qz } value $positions($side) { 2450 2556 set _view($name) $value 2451 } 2452 set q [ list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]2557 } 2558 set q [ViewToQuaternion] 2453 2559 $_arcball quaternion $q 2454 2560 SendCmd "camera orient $q" 2455 2561 SendCmd "camera reset" 2456 set _view( xpan) 02457 set _view( ypan) 02458 set _view( zoom) 1.02459 } 2562 set _view(-xpan) 0 2563 set _view(-ypan) 0 2564 set _view(-zoom) 1.0 2565 } -
branches/uq/gui/scripts/vtkheightmapviewer.tcl
r4798 r5121 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 2 2 # ---------------------------------------------------------------------- 3 3 # COMPONENT: vtkheightmapviewer - Vtk heightmap viewer … … 58 58 public method get {args} 59 59 public method isconnected {} 60 public method limits3 { dataobj } 61 public method parameters {title args} { 62 # do nothing 60 public method parameters {title args} { 61 # do nothing 63 62 } 64 63 public method scale {args} 65 64 66 protected method CameraReset {}67 protected method Connect {}68 protected method CurrentDatasets {args}69 protected method Disconnect {}70 protected method DoResize {}71 protected method DoRotate {}72 protected method AdjustSetting {what {value ""}}73 protected method AdjustMode {}74 protected method InitSettings { args }75 protected method Pan {option x y}76 protected method Pick {x y}77 protected method Rebuild {}78 protected method ReceiveDataset { args }79 protected method ReceiveImage { args }80 protected method ReceiveLegend { colormap title min max size }81 protected method Rotate {option x y}82 protected method Zoom {option}83 84 65 # The following methods are only used by this class. 66 private method AdjustSetting {what {value ""}} 85 67 private method BuildAxisTab {} 86 68 private method BuildCameraTab {} 87 69 private method BuildColormap { name } 88 70 private method BuildContourTab {} 89 private method BuildDownloadPopup { widget command } 71 private method BuildDownloadPopup { widget command } 72 private method CameraReset {} 90 73 private method Combo { option } 74 private method Connect {} 75 private method CurrentDatasets {args} 76 private method Disconnect {} 77 private method DoResize {} 78 private method DoRotate {} 91 79 private method DrawLegend {} 92 private method EnterLegend { x y } 93 private method EventuallyRequestLegend {} 94 private method EventuallyResize { w h } 95 private method EventuallyRotate { q } 96 private method GetImage { args } 97 private method GetVtkData { args } 98 private method IsValidObject { dataobj } 80 private method EnterLegend { x y } 81 private method EventuallyRequestLegend {} 82 private method EventuallyResize { w h } 83 private method EventuallyRotate { q } 84 private method GetHeightmapScale {} 85 private method GetImage { args } 86 private method GetVtkData { args } 87 private method InitSettings { args } 88 private method IsValidObject { dataobj } 99 89 private method LeaveLegend {} 100 private method MotionLegend { x y } 90 private method MotionLegend { x y } 91 private method Pan {option x y} 101 92 private method PanCamera {} 93 private method Pick {x y} 94 private method QuaternionToView { q } { 95 foreach { _view(-qw) _view(-qx) _view(-qy) _view(-qz) } $q break 96 } 97 private method Rebuild {} 98 private method ReceiveDataset { args } 99 private method ReceiveImage { args } 100 private method ReceiveLegend { colormap title min max size } 102 101 private method RequestLegend {} 102 private method ResetAxes {} 103 private method Rotate {option x y} 103 104 private method SetCurrentColormap { color } 104 105 private method SetLegendTip { x y } 105 private method SetObjectStyle { dataobj comp } 106 private method GetHeightmapScale {} 107 private method ResetAxes {} 106 private method SetObjectStyle { dataobj comp } 108 107 private method SetOrientation { side } 109 108 private method UpdateContourList {} 109 private method ViewToQuaternion {} { 110 return [list $_view(-qw) $_view(-qx) $_view(-qy) $_view(-qz)] 111 } 112 private method Zoom {option} 110 113 111 114 private variable _arcball "" … … 113 116 private variable _obj2datasets 114 117 private variable _obj2ovride ; # maps dataobj => style override 115 private variable _comp2scale; 116 private variable _datasets ; # contains all the dataobj-component 118 private variable _comp2scale; # maps dataset to the heightmap scale. 119 private variable _datasets ; # contains all the dataobj-component 117 120 ; # datasets in the server 118 121 private variable _colormaps ; # contains all the colormaps … … 130 133 131 134 private variable _click ; # info used for rotate operations 132 private variable _limits ; # Holds overall limits for all dataobjs 135 private variable _limits ; # Holds overall limits for all dataobjs 133 136 # using the viewer. 134 137 private variable _view ; # view params for 3D view … … 155 158 private variable _rotatePending 0 156 159 private variable _legendPending 0 157 private variable _fieldNames {} 158 private variable _fields 160 private variable _fieldNames {} 161 private variable _fields 159 162 private variable _curFldName "" 160 163 private variable _curFldLabel "" … … 202 205 # Initialize the view to some default parameters. 203 206 array set _view { 204 qw 0.36205 qx 0.25206 qy 0.50207 qz 0.70208 zoom 1.0209 xpan0210 ypan0211 ortho0207 -ortho 0 208 -qw 0.36 209 -qx 0.25 210 -qy 0.50 211 -qz 0.70 212 -xpan 0 213 -ypan 0 214 -zoom 1.0 212 215 } 213 216 set _arcball [blt::arcball create 100 100] 214 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 215 $_arcball quaternion $q 217 $_arcball quaternion [ViewToQuaternion] 216 218 217 219 array set _settings { 218 -axisflymode 220 -axisflymode "static" 219 221 -axislabels 1 220 -axisminorticks 221 -axisvisible 222 -axisminorticks 1 223 -axisvisible 1 222 224 -colormap BCGYR 223 225 -colormapdiscrete 0 224 226 -colormapvisible 1 225 -edges 226 -field 227 -heightmapscale 228 -isheightmap 227 -edges 0 228 -field "Default" 229 -heightmapscale 50 230 -isheightmap 0 229 231 -isolinecolor black 230 232 -isolinesvisible 1 231 233 -legendvisible 1 232 -lighting 233 -numisolines 234 -lighting 1 235 -numisolines 10 234 236 -opacity 100 235 -outline 236 -savelighting 237 -saveopacity 238 -saveoutline 239 -stretchtofit 240 -wireframe 241 -xgrid 242 -ygrid 243 -zgrid 237 -outline 0 238 -savelighting 1 239 -saveopacity 100 240 -saveoutline 0 241 -stretchtofit 0 242 -wireframe 0 243 -xgrid 0 244 -ygrid 0 245 -zgrid 0 244 246 } 245 247 array set _changed { … … 253 255 } { 254 256 usual 255 ignore -highlightthickness -borderwidth -background 257 ignore -highlightthickness -borderwidth -background 256 258 } 257 259 … … 259 261 menu $itk_component(plotarea).menu \ 260 262 -relief flat \ 261 -tearoff no 263 -tearoff no 262 264 } { 263 265 usual … … 279 281 280 282 set _map(id) [$c create image 0 0 -anchor nw -image $_image(plot)] 281 set _map(cwidth) -1 282 set _map(cheight) -1 283 set _map(cwidth) -1 284 set _map(cheight) -1 283 285 set _map(zoom) 1.0 284 286 set _map(original) "" … … 348 350 BuildCameraTab 349 351 } errs] != 0 } { 350 352 global errorInfo 351 353 puts stderr "errs=$errs errorInfo=$errorInfo" 352 354 } 353 355 354 # Hack around the Tk panewindow. The problem is that the requested 356 # Hack around the Tk panewindow. The problem is that the requested 355 357 # size of the 3d view isn't set until an image is retrieved from 356 358 # the server. So the panewindow uses the tiny size. … … 358 360 pack forget $itk_component(view) 359 361 blt::table $itk_component(plotarea) \ 360 0,0 $itk_component(view) -fill both -reqwidth $w 362 0,0 $itk_component(view) -fill both -reqwidth $w 361 363 blt::table configure $itk_component(plotarea) c1 -resize none 362 364 … … 442 444 443 445 itcl::body Rappture::VtkHeightmapViewer::DoRotate {} { 444 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 445 SendCmd "camera orient $q" 446 SendCmd "camera orient [ViewToQuaternion]" 446 447 set _rotatePending 0 447 448 } … … 467 468 468 469 itcl::body Rappture::VtkHeightmapViewer::EventuallyRotate { q } { 469 foreach { _view(qw) _view(qx) _view(qy) _view(qz) } $q break470 QuaternionToView $q 470 471 if { !$_rotatePending } { 471 472 set _rotatePending 1 472 global rotate_delay 473 global rotate_delay 473 474 $_dispatcher event -after $rotate_delay !rotate 474 475 } … … 569 570 continue 570 571 } 571 if {[info exists _obj2ovride($dataobj-raise)] && 572 if {[info exists _obj2ovride($dataobj-raise)] && 572 573 $_obj2ovride($dataobj-raise)} { 573 574 set dlist [linsert $dlist 0 $dataobj] … … 597 598 } 598 599 return $dlist 599 } 600 } 600 601 -image { 601 602 if {[llength $args] != 2} { … … 617 618 } 618 619 619 # 620 # 620 621 # scale -- 621 622 # 622 623 # This gets called either incrementally as new simulations are 623 624 # added or all at once as a sequence of heightmaps. 624 # This accounts for all objects--even those not showing on the 625 # screen. Because of this, the limits are appropriate for all 625 # This accounts for all objects--even those not showing on the 626 # screen. Because of this, the limits are appropriate for all 626 627 # objects as the user scans through data in the ResultSet viewer. 627 628 # … … 815 816 $_dispatcher cancel !legend 816 817 # disconnected -- no more data sitting on server 817 array unset _datasets 818 array unset _data 819 array unset _colormaps 820 array unset _obj2datasets 818 array unset _datasets 819 array unset _data 820 array unset _colormaps 821 array unset _obj2datasets 821 822 global readyForNextFrame 822 823 set readyForNextFrame 1 … … 842 843 if { $info(-type) == "image" } { 843 844 if 0 { 844 set f [open "last.ppm" "w"] 845 puts $f $bytes 845 set f [open "last.ppm" "w"] 846 fconfigure $f -encoding binary 847 puts -nonewline $f $bytes 846 848 close $f 847 849 } … … 849 851 set time [clock seconds] 850 852 set date [clock format $time] 851 #puts stderr "$date: received image [image width $_image(plot)]x[image height $_image(plot)] image>" 853 #puts stderr "$date: received image [image width $_image(plot)]x[image height $_image(plot)] image>" 852 854 if { $_start > 0 } { 853 855 set finish [clock clicks -milliseconds] … … 920 922 # Turn on buffering of commands to the server. We don't want to 921 923 # be preempted by a server disconnect/reconnect (which automatically 922 # generates a new call to Rebuild). 924 # generates a new call to Rebuild). 923 925 StartBufferingCommands 924 926 925 927 if { $_width != $w || $_height != $h || $_reset } { 926 927 928 929 930 931 932 928 set _width $w 929 set _height $h 930 $_arcball resize $w $h 931 DoResize 932 if { $_settings(-stretchtofit) } { 933 AdjustSetting -stretchtofit 934 } 933 935 } 934 936 if { $_reset } { 935 936 937 937 # 938 # Reset the camera and other view parameters 939 # 938 940 InitSettings -isheightmap -background 939 941 940 942 # Setting a custom exponent and label format for axes is causing 941 # a problem with rounding. Near zero ticks aren't rounded by 943 # a problem with rounding. Near zero ticks aren't rounded by 942 944 # the %g format. The VTK CubeAxes seem to currently work best 943 # when allowed to automatically set the exponent and precision 944 # based on the axis ranges. This does tend to result in less 945 # visual clutter, so I think it is best to use the automatic 945 # when allowed to automatically set the exponent and precision 946 # based on the axis ranges. This does tend to result in less 947 # visual clutter, so I think it is best to use the automatic 946 948 # settings by default. We can test more fine-grained 947 949 # controls on the axis settings tab if necessary. 948 950 # -Leif 949 #SendCmd "axis exp 0 0 0 1" 950 951 SendCmd "axis lrot z 90" 952 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 953 $_arcball quaternion $q 951 SendCmd "axis exp 0 0 0 1" 952 953 SendCmd "axis lrot z 90" 954 $_arcball quaternion [ViewToQuaternion] 954 955 if {$_settings(-isheightmap) } { 955 if { $_view( ortho)} {956 if { $_view(-ortho)} { 956 957 SendCmd "camera mode ortho" 957 958 } else { … … 960 961 DoRotate 961 962 SendCmd "camera reset" 962 963 963 } 964 PanCamera 964 965 StopBufferingCommands 965 966 SendCmd "imgflush" … … 980 981 if { ![info exists _datasets($tag)] } { 981 982 set bytes [$dataobj vtkdata $comp] 982 if 0 { 983 if 0 { 983 984 set f [open /tmp/vtkheightmap.vtk "w"] 984 puts $f $bytes 985 fconfigure $f -translation binary -encoding binary 986 puts -nonewline $f $bytes 985 987 close $f 986 988 } 987 989 set length [string length $bytes] 988 990 if { $_reportClientInfo } { 989 991 set info {} 990 lappend info "tool_id" [$dataobj hints toolId] 991 lappend info "tool_name" [$dataobj hints toolName] 992 lappend info "tool_version" [$dataobj hints toolRevision] 993 lappend info "tool_title" [$dataobj hints toolTitle] 992 lappend info "tool_id" [$dataobj hints toolid] 993 lappend info "tool_name" [$dataobj hints toolname] 994 lappend info "tool_title" [$dataobj hints tooltitle] 995 lappend info "tool_command" [$dataobj hints toolcommand] 996 lappend info "tool_revision" [$dataobj hints toolrevision] 994 997 lappend info "dataset_label" [$dataobj hints label] 995 998 lappend info "dataset_size" $length 996 999 lappend info "dataset_tag" $tag 997 SendCmd [list "clientinfo" $info]1000 SendCmd "clientinfo [list $info]" 998 1001 } 999 1002 SendCmd "dataset add $tag data follows $length" … … 1008 1011 SendCmd "dataset visible 1 $tag" 1009 1012 } 1010 if { ![info exists _comp2scale($tag)] || 1011 1012 1013 1014 1013 if { ![info exists _comp2scale($tag)] || 1014 $_comp2scale($tag) != $scale } { 1015 SendCmd "heightmap heightscale $scale $tag" 1016 set _comp2scale($tag) $scale 1017 } 1015 1018 } 1016 1019 } 1017 1020 if { $_first != "" } { 1018 1019 1020 1021 $itk_component(field) choices delete 0 end 1022 $itk_component(fieldmenu) delete 0 end 1023 array unset _fields 1021 1024 set _curFldName "" 1022 1025 foreach cname [$_first components] { … … 1047 1050 1048 1051 if { $_reset } { 1049 SendCmd "axis tickpos outside" 1050 foreach axis { x y z } { 1051 SendCmd "axis lformat $axis %g" 1052 } 1053 1054 foreach axis { x y z } { 1052 SendCmd "axis tickpos outside" 1053 SendCmd "axis lformat all %g" 1054 1055 foreach axis { x y z } { 1055 1056 if { $axis == "z" } { 1056 1057 set label [$_first hints label] … … 1058 1059 set label [$_first hints ${axis}label] 1059 1060 } 1060 1061 1061 if { $label == "" } { 1062 if {$axis == "z"} { 1062 1063 if { [string match "component*" $_curFldName] } { 1063 1064 set label [string toupper $axis] … … 1065 1066 set label $_curFldLabel 1066 1067 } 1067 } else { 1068 set label [string toupper $axis] 1069 } 1070 } 1071 # May be a space in the axis label. 1072 SendCmd [list axis name $axis $label] 1073 1074 if {$axis == "z" && [$_first hints ${axis}units] == ""} { 1075 set units [lindex $_fields($_curFldName) 1] 1076 } else { 1077 set units [$_first hints ${axis}units] 1078 } 1079 if { $units != "" } { 1080 # May be a space in the axis units. 1081 SendCmd [list axis units $axis $units] 1082 } 1083 } 1084 # 1085 # Reset the camera and other view parameters 1086 # 1087 ResetAxes 1088 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 1089 $_arcball quaternion $q 1068 } else { 1069 set label [string toupper $axis] 1070 } 1071 } 1072 # May be a space in the axis label. 1073 SendCmd [list axis name $axis $label] 1074 1075 set units "" 1076 if {$axis == "z" && [$_first hints ${axis}units] == ""} { 1077 if {$_curFldName != ""} { 1078 set units [lindex $_fields($_curFldName) 1] 1079 } 1080 } else { 1081 set units [$_first hints ${axis}units] 1082 } 1083 if { $units != "" } { 1084 # May be a space in the axis units. 1085 SendCmd [list axis units $axis $units] 1086 } 1087 } 1088 # 1089 # Reset the camera and other view parameters 1090 # 1091 ResetAxes 1092 $_arcball quaternion [ViewToQuaternion] 1090 1093 if {$_settings(-isheightmap) } { 1091 if { $_view( ortho)} {1094 if { $_view(-ortho)} { 1092 1095 SendCmd "camera mode ortho" 1093 1096 } else { … … 1097 1100 SendCmd "camera reset" 1098 1101 } 1099 1100 1101 1102 PanCamera 1103 InitSettings -xgrid -ygrid -zgrid \ 1104 -axisvisible -axislabels -heightmapscale -field -isheightmap \ 1102 1105 -numisolines 1103 1106 if { [array size _fields] < 2 } { 1104 catch { 1105 blt::table forget $itk_component(field) $itk_component(field_l) 1106 } 1107 catch {blt::table forget $itk_component(field) $itk_component(field_l)} 1107 1108 } 1108 1109 RequestLegend … … 1110 1111 } 1111 1112 global readyForNextFrame 1112 set readyForNextFrame 0; 1113 set readyForNextFrame 0; # Don't advance to the next frame 1113 1114 1114 1115 # Actually write the commands to the server socket. If it fails, we don't … … 1128 1129 itcl::body Rappture::VtkHeightmapViewer::CurrentDatasets {args} { 1129 1130 set flag [lindex $args 0] 1130 switch -- $flag { 1131 switch -- $flag { 1131 1132 "-all" { 1132 1133 if { [llength $args] > 1 } { … … 1147 1148 set dlist [get -visible] 1148 1149 } 1149 } 1150 } 1150 1151 default { 1151 1152 set dlist $args … … 1166 1167 itcl::body Rappture::VtkHeightmapViewer::CameraReset {} { 1167 1168 array set _view { 1168 qw 0.361169 qx 0.251170 qy 0.501171 qz 0.701172 zoom 1.01173 xpan 01174 ypan 01169 -qw 0.36 1170 -qx 0.25 1171 -qy 0.50 1172 -qz 0.70 1173 -xpan 0 1174 -ypan 0 1175 -zoom 1.0 1175 1176 } 1176 1177 if { $_first != "" } { … … 1180 1181 } 1181 1182 } 1182 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 1183 $_arcball quaternion $q 1183 $_arcball quaternion [ViewToQuaternion] 1184 1184 if {$_settings(-isheightmap) } { 1185 1185 DoRotate … … 1199 1199 switch -- $option { 1200 1200 "in" { 1201 set _view( zoom) [expr {$_view(zoom)*1.25}]1202 SendCmd "camera zoom $_view( zoom)"1201 set _view(-zoom) [expr {$_view(-zoom)*1.25}] 1202 SendCmd "camera zoom $_view(-zoom)" 1203 1203 } 1204 1204 "out" { 1205 set _view( zoom) [expr {$_view(zoom)*0.8}]1206 SendCmd "camera zoom $_view( zoom)"1205 set _view(-zoom) [expr {$_view(-zoom)*0.8}] 1206 SendCmd "camera zoom $_view(-zoom)" 1207 1207 } 1208 1208 "reset" { 1209 1209 array set _view { 1210 zoom 1.01211 xpan 01212 ypan 01210 -xpan 0 1211 -ypan 0 1212 -zoom 1.0 1213 1213 } 1214 1214 SendCmd "camera reset" … … 1218 1218 1219 1219 itcl::body Rappture::VtkHeightmapViewer::PanCamera {} { 1220 set x $_view( xpan)1221 set y $_view( ypan)1220 set x $_view(-xpan) 1221 set y $_view(-ypan) 1222 1222 SendCmd "camera pan $x $y" 1223 1223 } … … 1279 1279 foreach tag [CurrentDatasets -visible] { 1280 1280 SendCmd "dataset getscalar pixel $x $y $tag" 1281 } 1281 } 1282 1282 } 1283 1283 … … 1297 1297 set x [expr $x / double($w)] 1298 1298 set y [expr $y / double($h)] 1299 set _view( xpan) [expr $_view(xpan) + $x]1300 set _view( ypan) [expr $_view(ypan) + $y]1299 set _view(-xpan) [expr $_view(-xpan) + $x] 1300 set _view(-ypan) [expr $_view(-ypan) + $y] 1301 1301 PanCamera 1302 1302 return … … 1320 1320 set _click(x) $x 1321 1321 set _click(y) $y 1322 set _view( xpan) [expr $_view(xpan) - $dx]1323 set _view( ypan) [expr $_view(ypan) - $dy]1322 set _view(-xpan) [expr $_view(-xpan) - $dx] 1323 set _view(-ypan) [expr $_view(-ypan) - $dy] 1324 1324 PanCamera 1325 1325 } … … 1381 1381 SendCmd "axis visible all $bool" 1382 1382 } 1383 "-xgrid" - "-ygrid" - "-zgrid" {1384 set axis [string tolower [string range $what 1 1]]1385 set bool $_settings($what)1386 SendCmd "axis grid $axis $bool"1387 }1388 1383 "-background" { 1389 1384 set bg [$itk_component(background) value] 1390 1391 1392 1393 "grey""black"1394 1385 array set fgcolors { 1386 "black" "white" 1387 "white" "black" 1388 "grey" "black" 1389 } 1395 1390 set fg $fgcolors($bg) 1396 1391 configure -plotbackground $bg -plotforeground $fg 1397 1392 $itk_component(view) delete "legend" 1398 1393 SendCmd "screen bgcolor [Color2RGB $bg]" 1399 1394 SendCmd "outline color [Color2RGB $fg]" 1400 1395 SendCmd "axis color all [Color2RGB $fg]" 1401 1396 DrawLegend 1402 1397 } 1403 1398 "-colormap" { … … 1406 1401 set color [$itk_component(colormap) value] 1407 1402 set _settings($what) $color 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1403 if { $color == "none" } { 1404 if { $_settings(-colormapvisible) } { 1405 SendCmd "heightmap surface 0" 1406 set _settings(-colormapvisible) 0 1407 } 1408 } else { 1409 if { !$_settings(-colormapvisible) } { 1410 SendCmd "heightmap surface 1" 1411 set _settings(-colormapvisible) 1 1412 } 1413 SetCurrentColormap $color 1419 1414 if {$_settings(-colormapdiscrete)} { 1420 1415 set numColors [expr $_settings(-numisolines) + 1] 1421 1416 SendCmd "colormap res $numColors $color" 1422 1417 } 1423 1418 } 1424 1419 StopBufferingCommands 1425 1420 EventuallyRequestLegend 1426 1421 } 1427 1422 "-colormapvisible" { … … 1466 1461 return 1467 1462 } 1468 1469 1463 set label [$_first hints label] 1464 if { $label == "" } { 1470 1465 if { [string match "component*" $_curFldName] } { 1471 1466 set label Z … … 1473 1468 set label $_curFldLabel 1474 1469 } 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1470 } 1471 # May be a space in the axis label. 1472 SendCmd [list axis name z $label] 1473 1474 if { [$_first hints zunits] == "" } { 1475 set units [lindex $_fields($_curFldName) 1] 1476 } else { 1477 set units [$_first hints zunits] 1478 } 1479 if { $units != "" } { 1480 # May be a space in the axis units. 1481 SendCmd [list axis units z $units] 1482 } 1488 1483 # Get the new limits because the field changed. 1489 1484 ResetAxes … … 1495 1490 } 1496 1491 "-heightmapscale" { 1497 1498 1499 # Have to set the datasets individually because we are 1492 if { $_settings(-isheightmap) } { 1493 set scale [GetHeightmapScale] 1494 # Have to set the datasets individually because we are 1500 1495 # tracking them in _comp2scale. 1501 1496 foreach dataset [CurrentDatasets -all] { 1502 1503 1504 1505 1506 1497 SendCmd "heightmap heightscale $scale $dataset" 1498 set _comp2scale($dataset) $scale 1499 } 1500 ResetAxes 1501 } 1507 1502 } 1508 1503 "-isheightmap" { 1509 1504 set bool $_settings($what) 1510 1505 set c $itk_component(view) 1511 1506 StartBufferingCommands … … 1524 1519 InitSettings -lighting -opacity -outline 1525 1520 set scale [GetHeightmapScale] 1526 # Have to set the datasets individually because we are 1521 # Have to set the datasets individually because we are 1527 1522 # tracking them in _comp2scale. 1528 1523 foreach dataset [CurrentDatasets -all] { … … 1530 1525 set _comp2scale($dataset) $scale 1531 1526 } 1532 1533 1534 1535 1536 1537 1538 1539 if {$_view( ortho)} {1527 if { $bool } { 1528 $itk_component(lighting) configure -state normal 1529 $itk_component(opacity) configure -state normal 1530 $itk_component(scale) configure -state normal 1531 $itk_component(opacity_l) configure -state normal 1532 $itk_component(scale_l) configure -state normal 1533 $itk_component(outline) configure -state disabled 1534 if {$_view(-ortho)} { 1540 1535 SendCmd "camera mode ortho" 1541 1536 } else { 1542 1537 SendCmd "camera mode persp" 1543 1538 } 1544 1545 1546 1547 1548 1549 1550 1539 } else { 1540 $itk_component(lighting) configure -state disabled 1541 $itk_component(opacity) configure -state disabled 1542 $itk_component(scale) configure -state disabled 1543 $itk_component(opacity_l) configure -state disabled 1544 $itk_component(scale_l) configure -state disabled 1545 $itk_component(outline) configure -state normal 1551 1546 SendCmd "camera mode image" 1552 1547 } … … 1560 1555 ResetAxes 1561 1556 if { $bool } { 1562 set q [ list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]1557 set q [ViewToQuaternion] 1563 1558 $_arcball quaternion $q 1564 SendCmd "camera orient $q" 1559 SendCmd "camera orient $q" 1565 1560 } else { 1566 1561 bind $c <ButtonPress-1> {} … … 1569 1564 } 1570 1565 Zoom reset 1571 # Fix the mouse bindings for rotation/panning and the 1566 # Fix the mouse bindings for rotation/panning and the 1572 1567 # camera mode. Ideally we'd create a bindtag for these. 1573 1568 if { $bool } { … … 1584 1579 "-isolinecolor" { 1585 1580 set color [$itk_component(isolinecolor) value] 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1581 if { $color == "none" } { 1582 if { $_settings(-isolinesvisible) } { 1583 SendCmd "heightmap isolines 0" 1584 set _settings(-isolinesvisible) 0 1585 } 1586 } else { 1587 if { !$_settings(-isolinesvisible) } { 1588 SendCmd "heightmap isolines 1" 1589 set _settings(-isolinesvisible) 1 1590 } 1591 SendCmd "heightmap isolinecolor [Color2RGB $color]" 1592 } 1593 DrawLegend 1599 1594 } 1600 1595 "-isolinesvisible" { 1601 1596 set bool $_settings($what) 1602 1597 SendCmd "heightmap isolines $bool" 1603 1598 DrawLegend 1604 1599 } 1605 1600 "-legendvisible" { 1606 1601 if { !$_settings($what) } { 1607 1608 1609 1602 $itk_component(view) delete legend 1603 } 1604 DrawLegend 1610 1605 } 1611 1606 "-lighting" { 1612 1607 if { $_settings(-isheightmap) } { 1613 1608 set _settings(-savelighting) $_settings($what) 1614 1615 1616 1617 1618 1609 set bool $_settings($what) 1610 SendCmd "heightmap lighting $bool" 1611 } else { 1612 SendCmd "heightmap lighting 0" 1613 } 1619 1614 } 1620 1615 "-numisolines" { … … 1635 1630 set _changed($what) 1 1636 1631 set val [expr $_settings($what) * 0.01] 1637 1632 if { $_settings(-isheightmap) } { 1638 1633 set _settings(-saveopacity) $_settings($what) 1639 1634 SendCmd "heightmap opacity $val" 1640 1635 } else { 1641 1636 SendCmd "heightmap opacity 1.0" 1642 1637 } 1643 1638 } 1644 1639 "-outline" { 1645 1646 1640 if { $_settings(-isheightmap) } { 1641 SendCmd "outline visible 0" 1647 1642 } else { 1648 1643 set _settings(-saveoutline) $_settings($what) … … 1650 1645 SendCmd "outline visible $bool" 1651 1646 } 1652 1647 } 1653 1648 "-stretchtofit" { 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1649 set bool $_settings($what) 1650 if { $bool } { 1651 set heightScale [GetHeightmapScale] 1652 if {$heightScale == 0} { 1653 SendCmd "camera aspect window" 1654 } else { 1655 SendCmd "camera aspect square" 1656 } 1657 } else { 1658 SendCmd "camera aspect native" 1659 } 1665 1660 Zoom reset 1666 1661 } 1667 1662 "-wireframe" { 1668 1663 set bool $_settings($what) 1669 1664 SendCmd "heightmap wireframe $bool" 1670 1665 } 1671 default { 1666 "-xgrid" - "-ygrid" - "-zgrid" { 1667 set axis [string tolower [string range $what 1 1]] 1668 set bool $_settings($what) 1669 SendCmd "axis grid $axis $bool" 1670 } 1671 default { 1672 1672 error "don't know how to fix $what" 1673 1673 } … … 1679 1679 # 1680 1680 # Request a new legend from the server. The size of the legend 1681 # is determined from the height of the canvas. 1681 # is determined from the height of the canvas. 1682 1682 # 1683 1683 # This should be called when 1684 # 1685 # 1686 # 1687 # 1688 # 1684 # 1. A new current colormap is set. 1685 # 2. Window is resized. 1686 # 3. The limits of the data have changed. (Just need a redraw). 1687 # 4. Number of isolines have changed. (Just need a redraw). 1688 # 5. Legend becomes visible (Just need a redraw). 1689 1689 # 1690 1690 itcl::body Rappture::VtkHeightmapViewer::RequestLegend {} { … … 1693 1693 set w 12 1694 1694 set lineht [font metrics $font -linespace] 1695 # color ramp height = (canvas height) - (min and max value lines) - 2 1695 # color ramp height = (canvas height) - (min and max value lines) - 2 1696 1696 set h [expr {$_height - 2 * ($lineht + 2)}] 1697 1697 set _legendHeight $h … … 1699 1699 set fname $_curFldName 1700 1700 if { [string match "component*" $fname] } { 1701 1701 set title "" 1702 1702 } else { 1703 1704 1705 1706 1707 1708 1709 1710 1703 if { [info exists _fields($fname)] } { 1704 foreach { title units } $_fields($fname) break 1705 if { $units != "" } { 1706 set title [format "%s (%s)" $title $units] 1707 } 1708 } else { 1709 set title $fname 1710 } 1711 1711 } 1712 1712 # If there's a title too, substract one more line 1713 1713 if { $title != "" } { 1714 incr h -$lineht 1714 incr h -$lineht 1715 1715 } 1716 1716 if { $h < 1 } { … … 1719 1719 # Set the legend on the first heightmap dataset. 1720 1720 if { $_currentColormap != "" } { 1721 set cmap $_currentColormap 1722 SendCmd "legend $cmap scalar $_curFldName {} $w $h 0" 1721 set cmap $_currentColormap 1722 #SendCmd "legend $cmap scalar $_curFldName {} $w $h 0" 1723 SendCmd "legend2 $cmap $w $h" 1723 1724 } 1724 1725 } … … 1773 1774 # Keep track of the colormaps that we build. 1774 1775 if { $name != "none" && ![info exists _colormaps($name)] } { 1775 BuildColormap $name 1776 BuildColormap $name 1776 1777 set _colormaps($name) 1 1777 1778 } … … 1779 1780 SendCmd "heightmap colormap $_currentColormap" 1780 1781 } 1781 1782 1782 1783 1783 # … … 1800 1800 itcl::configbody Rappture::VtkHeightmapViewer::mode { 1801 1801 switch -- $itk_option(-mode) { 1802 1803 1804 1805 1806 1807 } 1808 1809 1810 1802 "heightmap" { 1803 set _settings(-isheightmap) 1 1804 } 1805 "contour" { 1806 set _settings(-isheightmap) 0 1807 } 1808 default { 1809 error "unknown mode settings \"$itk_option(-mode)\"" 1810 } 1811 1811 } 1812 1812 if { !$_reset } { … … 1824 1824 SendCmd "screen bgcolor $rgb" 1825 1825 } 1826 1826 $itk_component(view) configure -background $itk_option(-plotbackground) 1827 1827 } 1828 1828 } … … 1835 1835 set rgb [Color2RGB $itk_option(-plotforeground)] 1836 1836 if { !$_reset } { 1837 SendCmd "axis color all $rgb" 1837 1838 SendCmd "outline color $rgb" 1838 SendCmd "axis color all $rgb" 1839 } 1840 } 1841 } 1842 1843 itcl::body Rappture::VtkHeightmapViewer::limits3 { dataobj } { 1844 lappend limits x [$dataobj limits x] 1845 lappend limits y [$dataobj limits y] 1846 if { [catch { $dataobj limits $_curFldName } vlim] != 0 } { 1847 set vlim [$dataobj limits v] 1848 } 1849 lappend limits v $vlim 1850 return $limits 1839 } 1840 } 1851 1841 } 1852 1842 … … 1874 1864 1875 1865 itk_component add lighting { 1876 1877 1878 1879 1880 1866 checkbutton $inner.lighting \ 1867 -text "Enable Lighting" \ 1868 -variable [itcl::scope _settings(-lighting)] \ 1869 -command [itcl::code $this AdjustSetting -lighting] \ 1870 -font "Arial 9" 1881 1871 } { 1882 1872 ignore -font 1883 1873 } 1884 1874 checkbutton $inner.edges \ … … 1916 1906 1917 1907 itk_component add field_l { 1918 label $inner.field_l -text "Field" -font "Arial 9" 1908 label $inner.field_l -text "Field" -font "Arial 9" 1919 1909 } { 1920 1910 ignore -font … … 1926 1916 [itcl::code $this AdjustSetting -field] 1927 1917 1928 label $inner.colormap_l -text "Colormap" -font "Arial 9" 1918 label $inner.colormap_l -text "Colormap" -font "Arial 9" 1929 1919 itk_component add colormap { 1930 1920 Rappture::Combobox $inner.colormap -width 10 -editable no … … 1935 1925 [itcl::code $this AdjustSetting -colormap] 1936 1926 1937 label $inner.isolinecolor_l -text "Isolines Color" -font "Arial 9" 1927 label $inner.isolinecolor_l -text "Isolines Color" -font "Arial 9" 1938 1928 itk_component add isolinecolor { 1939 1929 Rappture::Combobox $inner.isolinecolor -width 10 -editable no … … 1949 1939 "red" "red" \ 1950 1940 "white" "white" \ 1951 "none""none"1941 "none" "none" 1952 1942 1953 1943 $itk_component(isolinecolor) value $_settings(-isolinecolor) 1954 1944 bind $inner.isolinecolor <<Value>> \ 1955 1956 1957 label $inner.background_l -text "Background Color" -font "Arial 9" 1945 [itcl::code $this AdjustSetting -isolinecolor] 1946 1947 label $inner.background_l -text "Background Color" -font "Arial 9" 1958 1948 itk_component add background { 1959 1949 Rappture::Combobox $inner.background -width 10 -editable no … … 1962 1952 "black" "black" \ 1963 1953 "white" "white" \ 1964 "grey" "grey" 1954 "grey" "grey" 1965 1955 1966 1956 $itk_component(background) value "white" … … 2009 1999 2,0 $inner.isolinecolor_l -anchor w -pady 2 \ 2010 2000 2,1 $inner.isolinecolor -anchor w -pady 2 -fill x \ 2011 2012 2001 3,0 $inner.background_l -anchor w -pady 2 \ 2002 3,1 $inner.background -anchor w -pady 2 -fill x \ 2013 2003 4,0 $inner.numisolines_l -anchor w -pady 2 \ 2014 2004 4,1 $inner.numisolines -anchor w -pady 2 \ … … 2052 2042 -command [itcl::code $this AdjustSetting -axislabels] \ 2053 2043 -font "Arial 9" 2054 label $inner.grid_l -text "Grid" -font "Arial 9" 2044 label $inner.grid_l -text "Grid" -font "Arial 9" 2055 2045 checkbutton $inner.xgrid \ 2056 2046 -text "X" \ … … 2074 2064 -font "Arial 9" 2075 2065 2076 label $inner.mode_l -text "Mode" -font "Arial 9" 2066 label $inner.mode_l -text "Mode" -font "Arial 9" 2077 2067 2078 2068 itk_component add axisflymode { … … 2083 2073 "closest_triad" "closest" \ 2084 2074 "furthest_triad" "farthest" \ 2085 "outer_edges" "outer" 2075 "outer_edges" "outer" 2086 2076 $itk_component(axisflymode) value $_settings(-axisflymode) 2087 2077 bind $inner.mode <<Value>> [itcl::code $this AdjustSetting -axisflymode] … … 2091 2081 1,0 $inner.labels -anchor w -cspan 4 \ 2092 2082 2,0 $inner.minorticks -anchor w -cspan 4 \ 2093 2083 4,0 $inner.grid_l -anchor w \ 2094 2084 4,1 $inner.xgrid -anchor w \ 2095 2085 4,2 $inner.ygrid -anchor w \ 2096 2086 4,3 $inner.zgrid -anchor w \ 2097 2087 5,0 $inner.mode_l -anchor w -padx { 2 0 } \ 2098 5,1 $inner.mode -fill x -cspan 3 2088 5,1 $inner.mode -fill x -cspan 3 2099 2089 2100 2090 blt::table configure $inner r* c* -resize none … … 2102 2092 blt::table configure $inner r3 -height 0.125i 2103 2093 } 2104 2105 2094 2106 2095 itcl::body Rappture::VtkHeightmapViewer::BuildCameraTab {} { … … 2122 2111 0,0 $inner.view_l -anchor e -pady 2 \ 2123 2112 0,1 $inner.view -anchor w -pady 2 2113 blt::table configure $inner r0 -resize none 2124 2114 2125 2115 set labels { qx qy qz qw xpan ypan zoom } … … 2128 2118 label $inner.${tag}label -text $tag -font "Arial 9" 2129 2119 entry $inner.${tag} -font "Arial 9" -bg white \ 2130 -textvariable [itcl::scope _view( $tag)]2120 -textvariable [itcl::scope _view(-$tag)] 2131 2121 bind $inner.${tag} <Return> \ 2132 [itcl::code $this camera set ${tag}]2122 [itcl::code $this camera set -${tag}] 2133 2123 bind $inner.${tag} <KP_Enter> \ 2134 [itcl::code $this camera set ${tag}]2124 [itcl::code $this camera set -${tag}] 2135 2125 blt::table $inner \ 2136 2126 $row,0 $inner.${tag}label -anchor e -pady 2 \ … … 2141 2131 checkbutton $inner.ortho \ 2142 2132 -text "Orthographic Projection" \ 2143 -variable [itcl::scope _view( ortho)] \2144 -command [itcl::code $this camera set ortho] \2133 -variable [itcl::scope _view(-ortho)] \ 2134 -command [itcl::code $this camera set -ortho] \ 2145 2135 -font "Arial 9" 2146 2136 blt::table $inner \ … … 2149 2139 incr row 2150 2140 2151 blt::table configure $inner c* r*-resize none2141 blt::table configure $inner c* -resize none 2152 2142 blt::table configure $inner c2 -resize expand 2153 2143 blt::table configure $inner r$row -resize expand … … 2155 2145 2156 2146 # 2157 # camera -- 2147 # camera -- 2158 2148 # 2159 2149 itcl::body Rappture::VtkHeightmapViewer::camera {option args} { 2160 switch -- $option { 2150 switch -- $option { 2161 2151 "show" { 2162 2152 puts [array get _view] 2163 2153 } 2164 2154 "set" { 2165 set wh o[lindex $args 0]2166 set x $_view($wh o)2155 set what [lindex $args 0] 2156 set x $_view($what) 2167 2157 set code [catch { string is double $x } result] 2168 2158 if { $code != 0 || !$result } { 2169 2159 return 2170 2160 } 2171 switch -- $wh o{2172 " ortho" {2173 if {$_view( ortho)} {2161 switch -- $what { 2162 "-ortho" { 2163 if {$_view($what)} { 2174 2164 SendCmd "camera mode ortho" 2175 2165 } else { … … 2177 2167 } 2178 2168 } 2179 " xpan" - "ypan" {2169 "-xpan" - "-ypan" { 2180 2170 PanCamera 2181 2171 } 2182 " qx" - "qy" - "qz" - "qw" {2183 set q [ list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]2172 "-qx" - "-qy" - "-qz" - "-qw" { 2173 set q [ViewToQuaternion] 2184 2174 $_arcball quaternion $q 2185 2175 EventuallyRotate $q 2186 2176 } 2187 " zoom" {2188 SendCmd "camera zoom $_view( zoom)"2177 "-zoom" { 2178 SendCmd "camera zoom $_view($what)" 2189 2179 } 2190 2180 } … … 2206 2196 2207 2197 itcl::body Rappture::VtkHeightmapViewer::GetImage { args } { 2208 if { [image width $_image(download)] > 0 && 2198 if { [image width $_image(download)] > 0 && 2209 2199 [image height $_image(download)] > 0 } { 2210 2200 set bytes [$_image(download) data -format "jpeg -quality 100"] … … 2219 2209 -title "[Rappture::filexfer::label downloadWord] as..." 2220 2210 set inner [$popup component inner] 2221 label $inner.summary -text "" -anchor w 2211 label $inner.summary -text "" -anchor w 2222 2212 radiobutton $inner.vtk_button -text "VTK data file" \ 2223 2213 -variable [itcl::scope _downloadPopup(format)] \ 2224 2214 -font "Arial 9 " \ 2225 -value vtk 2215 -value vtk 2226 2216 Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file." 2227 2217 radiobutton $inner.image_button -text "Image File" \ 2228 2218 -variable [itcl::scope _downloadPopup(format)] \ 2229 2219 -font "Arial 9 " \ 2230 -value image 2220 -value image 2231 2221 Rappture::Tooltip::for $inner.image_button \ 2232 2222 "Save as digital image." … … 2249 2239 2,0 $inner.image_button -anchor w -cspan 2 -padx { 4 0 } \ 2250 2240 4,1 $inner.cancel -width .9i -fill y \ 2251 4,0 $inner.ok -padx 2 -width .9i -fill y 2241 4,0 $inner.ok -padx 2 -width .9i -fill y 2252 2242 blt::table configure $inner r3 -height 4 2253 2243 blt::table configure $inner r4 -pady 4 … … 2260 2250 # SetObjectStyle -- 2261 2251 # 2262 # Set the style of the heightmap/contour object. This gets calls 2252 # Set the style of the heightmap/contour object. This gets calls 2263 2253 # for each dataset once as it is loaded. It can overridden by 2264 2254 # the user controls. … … 2351 2341 #puts stderr "read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>" 2352 2342 if { [catch {DrawLegend} errs] != 0 } { 2353 2354 2343 global errorInfo 2344 puts stderr "errs=$errs errorInfo=$errorInfo" 2355 2345 } 2356 2346 } … … 2369 2359 set font "Arial 8" 2370 2360 set lineht [font metrics $font -linespace] 2371 2361 2372 2362 if { [string match "component*" $fname] } { 2373 2363 set title "" 2374 2364 } else { 2375 2376 2377 2378 2379 2380 2381 2382 2365 if { [info exists _fields($fname)] } { 2366 foreach { title units } $_fields($fname) break 2367 if { $units != "" } { 2368 set title [format "%s (%s)" $title $units] 2369 } 2370 } else { 2371 set title $fname 2372 } 2383 2373 } 2384 2374 set x [expr $w - 2] 2385 2375 if { !$_settings(-legendvisible) } { 2386 2387 2388 } 2376 $c delete legend 2377 return 2378 } 2389 2379 if { [$c find withtag "legend"] == "" } { 2390 set y 2 2391 2380 set y 2 2381 # If there's a legend title, create a text item for the title. 2392 2382 $c create text $x $y \ 2393 2383 -anchor ne \ … … 2397 2387 incr y $lineht 2398 2388 } 2399 2389 $c create text $x $y \ 2400 2390 -anchor ne \ 2401 2391 -fill $itk_option(-plotforeground) -tags "vmax legend" \ 2402 2392 -font $font 2403 2393 incr y $lineht 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2394 $c create image $x $y \ 2395 -anchor ne \ 2396 -image $_image(legend) -tags "colormap legend" 2397 $c create rectangle $x $y 1 1 \ 2398 -fill "" -outline "" -tags "sensor legend" 2399 $c create text $x [expr {$h-2}] \ 2400 -anchor se \ 2401 -fill $itk_option(-plotforeground) -tags "vmin legend" \ 2402 -font $font 2403 $c bind sensor <Enter> [itcl::code $this EnterLegend %x %y] 2404 $c bind sensor <Leave> [itcl::code $this LeaveLegend] 2405 $c bind sensor <Motion> [itcl::code $this MotionLegend %x %y] 2416 2406 } 2417 2407 $c delete isoline … … 2424 2414 # Draw the isolines on the legend. 2425 2415 array unset _isolines 2426 if { $color != "none" && [info exists _limits($_curFldName)] && 2416 if { $color != "none" && [info exists _limits($_curFldName)] && 2427 2417 $_settings(-isolinesvisible) && $_currentNumIsolines > 0 } { 2428 2418 … … 2433 2423 } 2434 2424 set tags "isoline legend" 2435 2436 2437 2438 2425 set offset [expr 2 + $lineht] 2426 if { $title != "" } { 2427 incr offset $lineht 2428 } 2439 2429 foreach value $_contourList { 2440 2430 set norm [expr 1.0 - (($value - $vmin) / $range)] … … 2444 2434 set _isolines([expr $y1 - $off]) $value 2445 2435 } 2446 2447 2436 $c create line $x1 $y1 $x2 $y1 -fill $color -tags $tags 2437 } 2448 2438 } 2449 2439 … … 2454 2444 if { [info exists _limits($_curFldName)] } { 2455 2445 foreach { vmin vmax } $_limits($_curFldName) break 2456 2457 2446 $c itemconfigure vmin -text [format %g $vmin] 2447 $c itemconfigure vmax -text [format %g $vmax] 2458 2448 } 2459 2449 set y 2 … … 2461 2451 if { $title != "" } { 2462 2452 $c itemconfigure title -text $title 2463 2464 2453 $c coords title $x $y 2454 incr y $lineht 2465 2455 } 2466 2456 $c coords vmax $x $y … … 2510 2500 set font "Arial 8" 2511 2501 set lineht [font metrics $font -linespace] 2512 2502 2513 2503 set ih [image height $_image(legend)] 2514 2504 # Subtract off the offset of the color ramp from the top of the canvas … … 2516 2506 2517 2507 if { [string match "component*" $fname] } { 2518 2508 set title "" 2519 2509 } else { 2520 2521 2522 2523 2524 2525 2526 2527 2510 if { [info exists _fields($fname)] } { 2511 foreach { title units } $_fields($fname) break 2512 if { $units != "" } { 2513 set title [format "%s (%s)" $title $units] 2514 } 2515 } else { 2516 set title $fname 2517 } 2528 2518 } 2529 2519 # If there's a legend title, increase the offset by the line height. … … 2541 2531 } 2542 2532 set color [eval format "\#%02x%02x%02x" $pixel] 2543 $_image(swatch) put black -to 0 0 23 23 2544 $_image(swatch) put $color -to 1 1 22 22 2533 $_image(swatch) put black -to 0 0 23 23 2534 $_image(swatch) put $color -to 1 1 22 22 2545 2535 2546 2536 # Compute the value of the point … … 2552 2542 set value 0.0 2553 2543 } 2554 set tipx [expr $x + 15] 2544 set tipx [expr $x + 15] 2555 2545 set tipy [expr $y - 5] 2556 2546 .rappturetooltip configure -icon $_image(swatch) … … 2560 2550 Rappture::Tooltip::text $c [format "$title %g" $value] 2561 2551 } 2562 Rappture::Tooltip::tooltip show $c +$tipx,+$tipy 2552 Rappture::Tooltip::tooltip show $c +$tipx,+$tipy 2563 2553 } 2564 2554 … … 2575 2565 # ---------------------------------------------------------------------- 2576 2566 itcl::body Rappture::VtkHeightmapViewer::Combo {option} { 2577 set c $itk_component(view) 2567 set c $itk_component(view) 2578 2568 switch -- $option { 2579 2569 post { … … 2588 2578 } 2589 2579 deactivate { 2590 $c itemconfigure title -fill $itk_option(-plotforeground) 2580 $c itemconfigure title -fill $itk_option(-plotforeground) 2591 2581 } 2592 2582 invoke { … … 2602 2592 itcl::body Rappture::VtkHeightmapViewer::GetHeightmapScale {} { 2603 2593 if { $_settings(-isheightmap) } { 2604 2605 2606 2607 } 2608 return 0 2609 } 2610 2611 itcl::body Rappture::VtkHeightmapViewer::SetOrientation { side } { 2594 set val $_settings(-heightmapscale) 2595 set sval [expr { $val >= 50 ? double($val)/50.0 : 1.0/(2.0-(double($val)/50.0)) }] 2596 return $sval 2597 } 2598 return 0 2599 } 2600 2601 itcl::body Rappture::VtkHeightmapViewer::SetOrientation { side } { 2612 2602 array set positions { 2613 2603 front "0.707107 0.707107 0 0" … … 2618 2608 bottom "0 1 0 0" 2619 2609 } 2620 foreach name { qw qx qyqz } value $positions($side) {2610 foreach name { -qw -qx -qy -qz } value $positions($side) { 2621 2611 set _view($name) $value 2622 } 2623 set q [ list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]2612 } 2613 set q [ViewToQuaternion] 2624 2614 $_arcball quaternion $q 2625 2615 SendCmd "camera orient $q" 2626 2616 SendCmd "camera reset" 2627 set _view( xpan) 02628 set _view( ypan) 02629 set _view( zoom) 1.02630 } 2631 2632 itcl::body Rappture::VtkHeightmapViewer::UpdateContourList {} { 2617 set _view(-xpan) 0 2618 set _view(-ypan) 0 2619 set _view(-zoom) 1.0 2620 } 2621 2622 itcl::body Rappture::VtkHeightmapViewer::UpdateContourList {} { 2633 2623 if {$_currentNumIsolines == 0} { 2634 2624 set _contourList "" -
branches/uq/gui/scripts/vtkimageviewer.tcl
r4798 r5121 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 2 2 # ---------------------------------------------------------------------- 3 3 # COMPONENT: vtkimageviewer - Vtk image viewer … … 58 58 public method get {args} 59 59 public method isconnected {} 60 public method limits3 { dataobj } 61 public method parameters {title args} { 62 # do nothing 60 public method parameters {title args} { 61 # do nothing 63 62 } 64 63 public method scale {args} 65 64 66 protected method Connect {}67 protected method CurrentDatasets {args}68 protected method Disconnect {}69 protected method DoResize {}70 protected method DoRotate {}71 protected method AdjustSetting {what {value ""}}72 protected method AdjustMode {}73 protected method InitSettings { args }74 protected method Pan {option x y}75 protected method Pick {x y}76 protected method Rebuild {}77 protected method ReceiveDataset { args }78 protected method ReceiveImage { args }79 protected method ReceiveLegend { colormap title min max size }80 protected method Rotate {option x y}81 protected method Zoom {option}82 83 65 # The following methods are only used by this class. 66 private method AdjustSetting {what {value ""}} 84 67 private method BuildAxisTab {} 85 68 private method BuildCameraTab {} 86 69 private method BuildColormap { name } 87 70 private method BuildImageTab {} 88 private method BuildDownloadPopup { widget command } 71 private method BuildDownloadPopup { widget command } 89 72 private method Combo { option } 73 private method Connect {} 74 private method CurrentDatasets {args} 75 private method Disconnect {} 76 private method DoResize {} 77 private method DoRotate {} 90 78 private method DrawLegend {} 91 private method EnterLegend { x y } 92 private method EventuallyRequestLegend {} 93 private method EventuallyResize { w h } 94 private method EventuallyRotate { q } 95 private method GetImage { args } 96 private method GetVtkData { args } 97 private method IsValidObject { dataobj } 79 private method EnterLegend { x y } 80 private method EventuallyRequestLegend {} 81 private method EventuallyResize { w h } 82 private method EventuallyRotate { q } 83 private method GetImage { args } 84 private method GetVtkData { args } 85 private method InitSettings { args } 86 private method IsValidObject { dataobj } 98 87 private method LeaveLegend {} 99 private method MotionLegend { x y } 88 private method MotionLegend { x y } 89 private method Pan {option x y} 100 90 private method PanCamera {} 91 private method Pick {x y} 92 private method QuaternionToView { q } { 93 foreach { _view(-qw) _view(-qx) _view(-qy) _view(-qz) } $q break 94 } 95 private method Rebuild {} 96 private method ReceiveDataset { args } 97 private method ReceiveImage { args } 98 private method ReceiveLegend { colormap title min max size } 101 99 private method RequestLegend {} 100 private method Rotate {option x y} 102 101 private method SetCurrentColormap { color } 103 102 private method SetLegendTip { x y } 104 private method SetObjectStyle { dataobj comp } 103 private method SetObjectStyle { dataobj comp } 105 104 private method SetOrientation { side } 105 private method ViewToQuaternion {} { 106 return [list $_view(-qw) $_view(-qx) $_view(-qy) $_view(-qz)] 107 } 108 private method Zoom {option} 106 109 107 110 private variable _arcball "" … … 109 112 private variable _obj2datasets 110 113 private variable _obj2ovride ; # maps dataobj => style override 111 private variable _datasets ; # contains all the dataobj-component 114 private variable _datasets ; # contains all the dataobj-component 112 115 ; # datasets in the server 113 116 private variable _colormaps ; # contains all the colormaps … … 125 128 126 129 private variable _click ; # info used for rotate operations 127 private variable _limits ; # Holds overall limits for all dataobjs 130 private variable _limits ; # Holds overall limits for all dataobjs 128 131 # using the viewer. 129 132 private variable _view ; # view params for 3D view … … 150 153 private variable _rotatePending 0 151 154 private variable _legendPending 0 152 private variable _fieldNames {} 153 private variable _fields 155 private variable _fieldNames {} 156 private variable _fields 154 157 private variable _curFldName "" 155 158 private variable _curFldLabel "" … … 197 200 # Initialize the view to some default parameters. 198 201 array set _view { 199 qw 0.36200 qx 0.25201 qy 0.50202 qz 0.70203 zoom 1.0204 xpan0205 ypan0206 ortho0202 -ortho 0 203 -qw 0.36 204 -qx 0.25 205 -qy 0.50 206 -qz 0.70 207 -xpan 0 208 -ypan 0 209 -zoom 1.0 207 210 } 208 211 set _arcball [blt::arcball create 100 100] 209 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 210 $_arcball quaternion $q 212 $_arcball quaternion [ViewToQuaternion] 211 213 212 214 array set _settings { 213 axisFlymode"static"214 axisLabels1215 axisMinorTicks1216 axisVisible1217 axisXGrid 0218 axisYGrid 0219 axisZGrid0220 backingColor white221 backingVisible 1222 colormapDiscrete 0223 field "Default"224 legendVisible0225 level 127.5226 numColors 256227 opacity 100228 outline0229 saveOpacity 100230 stretchToFit0231 view3D0232 window 255.0215 -axisflymode "static" 216 -axislabels 1 217 -axisminorticks 1 218 -axisvisible 1 219 -backingcolor white 220 -backingvisible 1 221 -colormapdiscrete 0 222 -field "Default" 223 -legendvisible 0 224 -level 127.5 225 -numcolors 256 226 -opacity 100 227 -outline 0 228 -saveopacity 100 229 -stretchtofit 0 230 -view3d 0 231 -window 255.0 232 -xgrid 0 233 -ygrid 0 234 -zgrid 0 233 235 } 234 236 array set _changed { 235 opacity0236 colormap0237 -colormap 0 238 -opacity 0 237 239 } 238 240 itk_component add view { … … 241 243 } { 242 244 usual 243 ignore -highlightthickness -borderwidth -background 245 ignore -highlightthickness -borderwidth -background 244 246 } 245 247 … … 247 249 menu $itk_component(plotarea).menu \ 248 250 -relief flat \ 249 -tearoff no 251 -tearoff no 250 252 } { 251 253 usual … … 267 269 268 270 set _map(id) [$c create image 0 0 -anchor nw -image $_image(plot)] 269 set _map(cwidth) -1 270 set _map(cheight) -1 271 set _map(cwidth) -1 272 set _map(cheight) -1 271 273 set _map(zoom) 1.0 272 274 set _map(original) "" … … 313 315 -onimage [Rappture::icon surface] \ 314 316 -offimage [Rappture::icon surface] \ 315 -variable [itcl::scope _settings( view3D)] \316 -command [itcl::code $this AdjustSetting view3D] \317 -variable [itcl::scope _settings(-view3d)] \ 318 -command [itcl::code $this AdjustSetting -view3d] \ 317 319 } 318 320 Rappture::Tooltip::for $itk_component(mode) \ … … 324 326 -onimage [Rappture::icon stretchtofit] \ 325 327 -offimage [Rappture::icon stretchtofit] \ 326 -variable [itcl::scope _settings( stretchToFit)] \327 -command [itcl::code $this AdjustSetting stretchToFit] \328 -variable [itcl::scope _settings(-stretchtofit)] \ 329 -command [itcl::code $this AdjustSetting -stretchtofit] \ 328 330 } 329 331 Rappture::Tooltip::for $itk_component(stretchtofit) \ … … 336 338 BuildCameraTab 337 339 } errs] != 0 } { 338 340 global errorInfo 339 341 puts stderr "errs=$errs errorInfo=$errorInfo" 340 342 } 341 343 342 # Hack around the Tk panewindow. The problem is that the requested 344 # Hack around the Tk panewindow. The problem is that the requested 343 345 # size of the 3d view isn't set until an image is retrieved from 344 346 # the server. So the panewindow uses the tiny size. … … 346 348 pack forget $itk_component(view) 347 349 blt::table $itk_component(plotarea) \ 348 0,0 $itk_component(view) -fill both -reqwidth $w 350 0,0 $itk_component(view) -fill both -reqwidth $w 349 351 blt::table configure $itk_component(plotarea) c1 -resize none 350 352 … … 430 432 431 433 itcl::body Rappture::VtkImageViewer::DoRotate {} { 432 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 433 SendCmd "camera orient $q" 434 SendCmd "camera orient [ViewToQuaternion]" 434 435 set _rotatePending 0 435 436 } … … 455 456 456 457 itcl::body Rappture::VtkImageViewer::EventuallyRotate { q } { 457 foreach { _view(qw) _view(qx) _view(qy) _view(qz) } $q break458 QuaternionToView $q 458 459 if { !$_rotatePending } { 459 460 set _rotatePending 1 460 global rotate_delay 461 global rotate_delay 461 462 $_dispatcher event -after $rotate_delay !rotate 462 463 } … … 557 558 continue 558 559 } 559 if {[info exists _obj2ovride($dataobj-raise)] && 560 if {[info exists _obj2ovride($dataobj-raise)] && 560 561 $_obj2ovride($dataobj-raise)} { 561 562 set dlist [linsert $dlist 0 $dataobj] … … 585 586 } 586 587 return $dlist 587 } 588 } 588 589 -image { 589 590 if {[llength $args] != 2} { … … 605 606 } 606 607 607 # 608 # 608 609 # scale -- 609 610 # 610 611 # This gets called either incrementally as new simulations are 611 612 # added or all at once as a sequence of images. 612 # This accounts for all objects--even those not showing on the 613 # screen. Because of this, the limits are appropriate for all 613 # This accounts for all objects--even those not showing on the 614 # screen. Because of this, the limits are appropriate for all 614 615 # objects as the user scans through data in the ResultSet viewer. 615 616 # … … 654 655 } 655 656 if { [array size found] > 1 } { 656 set _settings( stretchToFit) 1657 set _settings(-stretchtofit) 1 657 658 } else { 658 659 # Check if the range of the x and y axes requires that we stretch … … 663 664 if { (($xmax - $xmin) > (($ymax -$ymin) * $_maxScale)) || 664 665 ((($xmax - $xmin) * $_maxScale) < ($ymax -$ymin)) } { 665 set _settings( stretchToFit) 1666 set _settings(-stretchtofit) 1 666 667 } 667 668 } … … 803 804 $_dispatcher cancel !legend 804 805 # disconnected -- no more data sitting on server 805 array unset _datasets 806 array unset _data 807 array unset _colormaps 808 array unset _obj2datasets 806 array unset _datasets 807 array unset _data 808 array unset _colormaps 809 array unset _obj2datasets 809 810 global readyForNextFrame 810 811 set readyForNextFrame 1 … … 830 831 if { $info(-type) == "image" } { 831 832 if 0 { 832 set f [open "last.ppm" "w"] 833 puts $f $bytes 833 set f [open "last.ppm" "w"] 834 fconfigure $f -encoding binary 835 puts -nonewline $f $bytes 834 836 close $f 835 837 } … … 837 839 set time [clock seconds] 838 840 set date [clock format $time] 839 #puts stderr "$date: received image [image width $_image(plot)]x[image height $_image(plot)] image>" 841 #puts stderr "$date: received image [image width $_image(plot)]x[image height $_image(plot)] image>" 840 842 if { $_start > 0 } { 841 843 set finish [clock clicks -milliseconds] … … 908 910 # Turn on buffering of commands to the server. We don't want to 909 911 # be preempted by a server disconnect/reconnect (which automatically 910 # generates a new call to Rebuild). 912 # generates a new call to Rebuild). 911 913 StartBufferingCommands 912 914 913 915 if { $_width != $w || $_height != $h || $_reset } { 914 915 916 917 918 if { $_settings(stretchToFit) } {919 AdjustSettingstretchToFit920 916 set _width $w 917 set _height $h 918 $_arcball resize $w $h 919 DoResize 920 if { $_settings(-stretchtofit) } { 921 AdjustSetting -stretchToFit 922 } 921 923 } 922 924 if { $_reset } { 923 # 924 # Reset the camera and other view parameters 925 # 926 InitSettings view3D background 927 928 # Let's see how this goes. I think it's preferable to overloading the 929 # axis title with the exponent. 930 SendCmd "axis exp 0 0 0 1" 931 932 SendCmd "axis lrot z 90" 933 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 934 $_arcball quaternion $q 935 if {$_settings(view3D) } { 936 if { $_view(ortho)} { 925 # 926 # Reset the camera and other view parameters 927 # 928 InitSettings -view3d -background 929 930 SendCmd "axis lrot z 90" 931 $_arcball quaternion [ViewToQuaternion] 932 if {$_settings(-view3d) } { 933 if { $_view(-ortho)} { 937 934 SendCmd "camera mode ortho" 938 935 } else { … … 941 938 DoRotate 942 939 SendCmd "camera reset" 943 944 940 } 941 PanCamera 945 942 StopBufferingCommands 946 943 SendCmd "imgflush" … … 960 957 if { ![info exists _datasets($tag)] } { 961 958 set bytes [$dataobj vtkdata $comp] 962 if 0 { 959 if 0 { 963 960 set f [open /tmp/vtkimage.vtk "w"] 964 puts $f $bytes 961 fconfigure $f -translation binary -encoding binary 962 puts -nonewline $f $bytes 965 963 close $f 966 964 } 967 965 set length [string length $bytes] 968 966 if { $_reportClientInfo } { 969 967 set info {} 970 lappend info "tool_id" [$dataobj hints toolId] 971 lappend info "tool_name" [$dataobj hints toolName] 972 lappend info "tool_version" [$dataobj hints toolRevision] 973 lappend info "tool_title" [$dataobj hints toolTitle] 968 lappend info "tool_id" [$dataobj hints toolid] 969 lappend info "tool_name" [$dataobj hints toolname] 970 lappend info "tool_title" [$dataobj hints tooltitle] 971 lappend info "tool_command" [$dataobj hints toolcommand] 972 lappend info "tool_revision" [$dataobj hints toolrevision] 974 973 lappend info "dataset_label" [$dataobj hints label] 975 974 lappend info "dataset_size" $length 976 975 lappend info "dataset_tag" $tag 977 SendCmd [list "clientinfo" $info]976 SendCmd "clientinfo [list $info]" 978 977 } 979 978 SendCmd "dataset add $tag data follows $length" … … 991 990 } 992 991 if { $_first != "" } { 993 994 995 992 $itk_component(field) choices delete 0 end 993 $itk_component(fieldmenu) delete 0 end 994 array unset _fields 996 995 set _curFldName "" 997 996 foreach cname [$_first components] { … … 1019 1018 $itk_component(field) value $_curFldLabel 1020 1019 } 1021 InitSettings stretchToFitoutline1020 InitSettings -stretchtofit -outline 1022 1021 1023 1022 if { $_reset } { 1024 1023 SendCmd "axis tickpos outside" 1025 1024 #SendCmd "axis lformat all %g" 1026 1027 1025 1026 foreach axis { x y z } { 1028 1027 set label [$_first hints ${axis}label] 1029 if { $label == "" } { 1030 set label [string toupper $axis] 1031 } 1032 # May be a space in the axis label. 1033 SendCmd [list axis name $axis $label] 1034 1035 if {$axis == "z" && [$_first hints ${axis}units] == ""} { 1036 set units [lindex $_fields($_curFldName) 1] 1037 } else { 1038 set units [$_first hints ${axis}units] 1039 } 1040 if { $units != "" } { 1041 # May be a space in the axis units. 1042 SendCmd [list axis units $axis $units] 1043 } 1044 } 1045 # 1046 # Reset the camera and other view parameters 1047 # 1048 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 1049 $_arcball quaternion $q 1050 if {$_settings(view3D) } { 1051 if { $_view(ortho)} { 1028 if { $label == "" } { 1029 set label [string toupper $axis] 1030 } 1031 # May be a space in the axis label. 1032 SendCmd [list axis name $axis $label] 1033 1034 if {$axis == "z" && [$_first hints ${axis}units] == ""} { 1035 if {$_curFldName != ""} { 1036 set units [lindex $_fields($_curFldName) 1] 1037 } 1038 } else { 1039 set units [$_first hints ${axis}units] 1040 } 1041 if { $units != "" } { 1042 # May be a space in the axis units. 1043 SendCmd [list axis units $axis $units] 1044 } 1045 } 1046 # 1047 # Reset the camera and other view parameters 1048 # 1049 $_arcball quaternion [ViewToQuaternion] 1050 if {$_settings(-view3d) } { 1051 if { $_view(-ortho)} { 1052 1052 SendCmd "camera mode ortho" 1053 1053 } else { … … 1057 1057 SendCmd "camera reset" 1058 1058 } 1059 1060 InitSettings axisXGrid axisYGrid axisZGrid \1061 axisVisible axisLabels field view3D 1059 PanCamera 1060 InitSettings -xgrid -ygrid -zgrid \ 1061 -axisvisible -axislabels -field -view3d 1062 1062 if { [array size _fields] < 2 } { 1063 catch { 1064 blt::table forget $itk_component(field) $itk_component(field_l) 1065 } 1063 catch {blt::table forget $itk_component(field) $itk_component(field_l)} 1066 1064 } 1067 1065 RequestLegend … … 1069 1067 } 1070 1068 global readyForNextFrame 1071 set readyForNextFrame 0; 1069 set readyForNextFrame 0; # Don't advance to the next frame 1072 1070 1073 1071 # Actually write the commands to the server socket. If it fails, we don't … … 1087 1085 itcl::body Rappture::VtkImageViewer::CurrentDatasets {args} { 1088 1086 set flag [lindex $args 0] 1089 switch -- $flag { 1087 switch -- $flag { 1090 1088 "-all" { 1091 1089 if { [llength $args] > 1 } { … … 1106 1104 set dlist [get -visible] 1107 1105 } 1108 } 1106 } 1109 1107 default { 1110 1108 set dlist $args … … 1134 1132 switch -- $option { 1135 1133 "in" { 1136 set _view( zoom) [expr {$_view(zoom)*1.25}]1137 SendCmd "camera zoom $_view( zoom)"1134 set _view(-zoom) [expr {$_view(-zoom)*1.25}] 1135 SendCmd "camera zoom $_view(-zoom)" 1138 1136 } 1139 1137 "out" { 1140 set _view( zoom) [expr {$_view(zoom)*0.8}]1141 SendCmd "camera zoom $_view( zoom)"1138 set _view(-zoom) [expr {$_view(-zoom)*0.8}] 1139 SendCmd "camera zoom $_view(-zoom)" 1142 1140 } 1143 1141 "reset" { 1144 1142 array set _view { 1145 qw 0.361146 qx 0.251147 qy 0.501148 qz 0.701149 zoom 1.01150 xpan 01151 ypan 01143 -qw 0.36 1144 -qx 0.25 1145 -qy 0.50 1146 -qz 0.70 1147 -xpan 0 1148 -ypan 0 1149 -zoom 1.0 1152 1150 } 1153 1151 if { $_first != "" } { … … 1157 1155 } 1158 1156 } 1159 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 1160 $_arcball quaternion $q 1161 if {$_settings(view3D) } { 1157 $_arcball quaternion [ViewToQuaternion] 1158 if {$_settings(-view3d) } { 1162 1159 DoRotate 1163 1160 } … … 1168 1165 1169 1166 itcl::body Rappture::VtkImageViewer::PanCamera {} { 1170 set x $_view( xpan)1171 set y $_view( ypan)1167 set x $_view(-xpan) 1168 set y $_view(-ypan) 1172 1169 SendCmd "camera pan $x $y" 1173 1170 } … … 1229 1226 foreach tag [CurrentDatasets -visible] { 1230 1227 SendCmd "dataset getscalar pixel $x $y $tag" 1231 } 1228 } 1232 1229 } 1233 1230 … … 1247 1244 set x [expr $x / double($w)] 1248 1245 set y [expr $y / double($h)] 1249 set _view( xpan) [expr $_view(xpan) + $x]1250 set _view( ypan) [expr $_view(ypan) + $y]1246 set _view(-xpan) [expr $_view(-xpan) + $x] 1247 set _view(-ypan) [expr $_view(-ypan) + $y] 1251 1248 PanCamera 1252 1249 return … … 1270 1267 set _click(x) $x 1271 1268 set _click(y) $y 1272 set _view( xpan) [expr $_view(xpan) - $dx]1273 set _view( ypan) [expr $_view(ypan) - $dy]1269 set _view(-xpan) [expr $_view(-xpan) - $dx] 1270 set _view(-ypan) [expr $_view(-ypan) - $dy] 1274 1271 PanCamera 1275 1272 } … … 1293 1290 itcl::body Rappture::VtkImageViewer::InitSettings { args } { 1294 1291 foreach spec $args { 1295 if { [info exists _settings($_first -$spec)] } {1292 if { [info exists _settings($_first${spec})] } { 1296 1293 # Reset global setting with dataobj specific setting 1297 set _settings($spec) $_settings($_first -$spec)1294 set _settings($spec) $_settings($_first${spec}) 1298 1295 } 1299 1296 AdjustSetting $spec … … 1313 1310 } 1314 1311 switch -- $what { 1315 " axisFlymode" {1312 "-axisflymode" { 1316 1313 set mode [$itk_component(axisflymode) value] 1317 1314 set mode [$itk_component(axisflymode) translate $mode] … … 1319 1316 SendCmd "axis flymode $mode" 1320 1317 } 1321 " axisLabels" {1318 "-axislabels" { 1322 1319 set bool $_settings($what) 1323 1320 SendCmd "axis labels all $bool" 1324 1321 } 1325 " axisMinorTicks" {1322 "-axisminorticks" { 1326 1323 set bool $_settings($what) 1327 1324 SendCmd "axis minticks all $bool" 1328 1325 } 1329 " axisVisible" {1326 "-axisvisible" { 1330 1327 set bool $_settings($what) 1331 1328 SendCmd "axis visible all $bool" 1332 1329 } 1333 "axisXGrid" - "axisYGrid" - "axisZGrid" { 1334 set axis [string tolower [string range $what 4 4]] 1335 set bool $_settings($what) 1336 SendCmd "axis grid $axis $bool" 1337 } 1338 "background" { 1330 "-background" { 1339 1331 set bg [$itk_component(background) value] 1340 1341 1342 1343 "grey""black"1344 1332 array set fgcolors { 1333 "black" "white" 1334 "white" "black" 1335 "grey" "black" 1336 } 1345 1337 set fg $fgcolors($bg) 1346 1338 configure -plotbackground $bg -plotforeground $fg 1347 1339 $itk_component(view) delete "legend" 1348 1340 SendCmd "screen bgcolor [Color2RGB $bg]" 1349 1341 SendCmd "outline color [Color2RGB $fg]" 1350 1342 SendCmd "axis color all [Color2RGB $fg]" 1351 1352 } 1353 " backingColor" {1343 DrawLegend 1344 } 1345 "-backingcolor" { 1354 1346 set color [$itk_component(backingcolor) value] 1355 1356 if { $_settings(backingVisible) } {1357 1358 set _settings(backingVisible) 01359 1360 1361 if { !$_settings(backingVisible) } {1362 1363 set _settings(backingVisible) 11364 1365 1366 1367 } 1368 " backingVisible" {1369 1347 if { $color == "none" } { 1348 if { $_settings(-backingvisible) } { 1349 SendCmd "image backing 0" 1350 set _settings(-backingvisible) 0 1351 } 1352 } else { 1353 if { !$_settings(-backingvisible) } { 1354 SendCmd "image backing 1" 1355 set _settings(-backingvisible) 1 1356 } 1357 SendCmd "image color [Color2RGB $color]" 1358 } 1359 } 1360 "-backingvisible" { 1361 set bool $_settings($what) 1370 1362 SendCmd "image backing $bool" 1371 1363 } 1372 " colormap" {1364 "-colormap" { 1373 1365 set _changed($what) 1 1374 1366 StartBufferingCommands … … 1376 1368 set _settings($what) $color 1377 1369 SetCurrentColormap $color 1378 if {$_settings( colormapDiscrete)} {1379 SendCmd "colormap res $_settings( numColors) $color"1370 if {$_settings(-colormapdiscrete)} { 1371 SendCmd "colormap res $_settings(-numcolors) $color" 1380 1372 } 1381 1373 StopBufferingCommands 1382 1383 } 1384 " colormapDiscrete" {1374 EventuallyRequestLegend 1375 } 1376 "-colormapdiscrete" { 1385 1377 set bool $_settings($what) 1386 1378 StartBufferingCommands 1387 1379 if {$bool} { 1388 SendCmd "colormap res $_settings( numColors)"1380 SendCmd "colormap res $_settings(-numcolors)" 1389 1381 } else { 1390 1382 SendCmd "colormap res default" … … 1393 1385 EventuallyRequestLegend 1394 1386 } 1395 " field" {1387 "-field" { 1396 1388 set label [$itk_component(field) value] 1397 1389 set fname [$itk_component(field) translate $label] … … 1417 1409 DrawLegend 1418 1410 } 1419 " view3D" {1420 1411 "-view3d" { 1412 set bool $_settings($what) 1421 1413 set c $itk_component(view) 1422 1414 StartBufferingCommands 1423 1415 # Fix image scale: 0 for contours, 1 for images. 1424 1416 if { $bool } { 1425 set _settings( opacity) $_settings(saveOpacity)1417 set _settings(-opacity) $_settings(-saveopacity) 1426 1418 } else { 1427 set _settings( opacity) 1001428 } 1429 AdjustSetting opacity1430 1431 1432 1433 if {$_view( ortho)} {1419 set _settings(-opacity) 100 1420 } 1421 AdjustSetting -opacity 1422 if { $bool } { 1423 $itk_component(opacity) configure -state normal 1424 $itk_component(opacity_l) configure -state normal 1425 if {$_view(-ortho)} { 1434 1426 SendCmd "camera mode ortho" 1435 1427 } else { … … 1437 1429 } 1438 1430 SendCmd "camera aspect native" 1439 1440 1441 1431 } else { 1432 $itk_component(opacity) configure -state disabled 1433 $itk_component(opacity_l) configure -state disabled 1442 1434 SendCmd "camera mode image" 1443 if {$_settings( stretchToFit)} {1435 if {$_settings(-stretchtofit)} { 1444 1436 SendCmd "camera aspect window" 1445 1437 } 1446 1438 } 1447 1439 if { $bool } { 1448 set q [ list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]1440 set q [ViewToQuaternion] 1449 1441 $_arcball quaternion $q 1450 SendCmd "camera orient $q" 1442 SendCmd "camera orient $q" 1451 1443 } else { 1452 1444 bind $c <ButtonPress-1> {} … … 1455 1447 } 1456 1448 SendCmd "camera reset" 1457 # Fix the mouse bindings for rotation/panning and the 1449 # Fix the mouse bindings for rotation/panning and the 1458 1450 # camera mode. Ideally we'd create a bindtag for these. 1459 1451 if { $bool } { … … 1468 1460 StopBufferingCommands 1469 1461 } 1470 " window" {1462 "-window" { 1471 1463 set val $_settings($what) 1472 1464 SendCmd "image window $val" 1473 1465 } 1474 " level" {1466 "-level" { 1475 1467 set val $_settings($what) 1476 1468 SendCmd "image level $val" 1477 1469 } 1478 " legendVisible" {1470 "-legendvisible" { 1479 1471 if { !$_settings($what) } { 1480 1481 1482 1483 } 1484 " opacity" {1472 $itk_component(view) delete legend 1473 } 1474 DrawLegend 1475 } 1476 "-opacity" { 1485 1477 set _changed($what) 1 1486 if { $_settings(view3D) } {1487 set _settings( saveOpacity) $_settings($what)1478 if { $_settings(-view3d) } { 1479 set _settings(-saveopacity) $_settings($what) 1488 1480 set val [expr $_settings($what) * 0.01] 1489 1481 SendCmd "image opacity $val" 1490 1482 } else { 1491 1492 } 1493 } 1494 " outline" {1483 SendCmd "image opacity 1.0" 1484 } 1485 } 1486 "-outline" { 1495 1487 set bool $_settings($what) 1496 1488 SendCmd "outline visible $bool" 1497 } 1498 "stretchToFit" { 1499 set bool $_settings($what) 1500 if { $bool } { 1501 if { $_settings(view3D) } { 1502 SendCmd "camera aspect native" 1503 } else { 1504 SendCmd "camera aspect window" 1505 } 1506 } else { 1507 SendCmd "camera aspect native" 1508 } 1509 } 1510 default { 1489 } 1490 "-stretchtofit" { 1491 set bool $_settings($what) 1492 if { $bool } { 1493 if { $_settings(-view3d) } { 1494 SendCmd "camera aspect native" 1495 } else { 1496 SendCmd "camera aspect window" 1497 } 1498 } else { 1499 SendCmd "camera aspect native" 1500 } 1501 } 1502 "-xgrid" - "-ygrid" - "-zgrid" { 1503 set axis [string tolower [string range $what 1 1]] 1504 set bool $_settings($what) 1505 SendCmd "axis grid $axis $bool" 1506 } 1507 default { 1511 1508 error "don't know how to fix $what" 1512 1509 } … … 1518 1515 # 1519 1516 # Request a new legend from the server. The size of the legend 1520 # is determined from the height of the canvas. 1517 # is determined from the height of the canvas. 1521 1518 # 1522 1519 # This should be called when 1523 # 1524 # 1525 # 1526 # 1527 # 1520 # 1. A new current colormap is set. 1521 # 2. Window is resized. 1522 # 3. The limits of the data have changed. (Just need a redraw). 1523 # 4. Number of isolines have changed. (Just need a redraw). 1524 # 5. Legend becomes visible (Just need a redraw). 1528 1525 # 1529 1526 itcl::body Rappture::VtkImageViewer::RequestLegend {} { … … 1532 1529 set w 12 1533 1530 set lineht [font metrics $font -linespace] 1534 # color ramp height = (canvas height) - (min and max value lines) - 2 1531 # color ramp height = (canvas height) - (min and max value lines) - 2 1535 1532 set h [expr {$_height - 2 * ($lineht + 2)}] 1536 1533 set _legendHeight $h … … 1538 1535 set fname $_curFldName 1539 1536 if { [string match "component*" $fname] } { 1540 1537 set title "" 1541 1538 } else { 1542 1543 1544 1545 1546 1547 1548 1549 1539 if { [info exists _fields($fname)] } { 1540 foreach { title units } $_fields($fname) break 1541 if { $units != "" } { 1542 set title [format "%s (%s)" $title $units] 1543 } 1544 } else { 1545 set title $fname 1546 } 1550 1547 } 1551 1548 # If there's a title too, substract one more line 1552 1549 if { $title != "" } { 1553 incr h -$lineht 1550 incr h -$lineht 1554 1551 } 1555 1552 if { $h < 1 } { … … 1558 1555 # Set the legend on the first image dataset. 1559 1556 if { $_currentColormap != "" && $_currentColormap != "none" } { 1560 SendCmd "legend $_currentColormap scalar $_curFldName {} $w $h 0" 1557 #SendCmd "legend $_currentColormap scalar $_curFldName {} $w $h 0" 1558 SendCmd "legend2 $_currentColormap $w $h" 1561 1559 } 1562 1560 } … … 1568 1566 # Keep track of the colormaps that we build. 1569 1567 if { $name != "none" && ![info exists _colormaps($name)] } { 1570 BuildColormap $name 1568 BuildColormap $name 1571 1569 set _colormaps($name) 1 1572 1570 } … … 1595 1593 itcl::configbody Rappture::VtkImageViewer::mode { 1596 1594 switch -- $itk_option(-mode) { 1597 1598 set _settings(view3D) 11599 1600 1601 set _settings(view3D) 01602 } 1603 1604 1605 1595 "volume" { 1596 set _settings(-view3d) 1 1597 } 1598 "vtkimage" { 1599 set _settings(-view3d) 0 1600 } 1601 default { 1602 error "unknown mode settings \"$itk_option(-mode)\"" 1603 } 1606 1604 } 1607 1605 if { !$_reset } { 1608 AdjustSetting view3D1606 AdjustSetting -view3d 1609 1607 } 1610 1608 } … … 1619 1617 SendCmd "screen bgcolor $rgb" 1620 1618 } 1621 1619 $itk_component(view) configure -background $itk_option(-plotbackground) 1622 1620 } 1623 1621 } … … 1630 1628 set rgb [Color2RGB $itk_option(-plotforeground)] 1631 1629 if { !$_reset } { 1630 SendCmd "axis color all $rgb" 1632 1631 SendCmd "outline color $rgb" 1633 SendCmd "axis color all $rgb" 1634 } 1635 } 1636 } 1637 1638 itcl::body Rappture::VtkImageViewer::limits3 { dataobj } { 1639 lappend limits x [$dataobj limits x] 1640 lappend limits y [$dataobj limits y] 1641 if { [catch { $dataobj limits $_curFldName } vlim] != 0 } { 1642 set vlim [$dataobj limits v] 1643 } 1644 lappend limits v $vlim 1645 return $limits 1632 } 1633 } 1646 1634 } 1647 1635 … … 1658 1646 checkbutton $inner.legend \ 1659 1647 -text "Legend" \ 1660 -variable [itcl::scope _settings( legendVisible)] \1661 -command [itcl::code $this AdjustSetting legendVisible] \1648 -variable [itcl::scope _settings(-legendvisible)] \ 1649 -command [itcl::code $this AdjustSetting -legendvisible] \ 1662 1650 -font "Arial 9" 1663 1651 1664 1652 checkbutton $inner.outline \ 1665 1653 -text "Outline" \ 1666 -variable [itcl::scope _settings( outline)] \1667 -command [itcl::code $this AdjustSetting outline] \1654 -variable [itcl::scope _settings(-outline)] \ 1655 -command [itcl::code $this AdjustSetting -outline] \ 1668 1656 -font "Arial 9" 1669 1657 1670 1658 checkbutton $inner.backing \ 1671 1659 -text "Backing" \ 1672 -variable [itcl::scope _settings( backingVisible)] \1673 -command [itcl::code $this AdjustSetting backingVisible] \1660 -variable [itcl::scope _settings(-backingvisible)] \ 1661 -command [itcl::code $this AdjustSetting -backingvisible] \ 1674 1662 -font "Arial 9" 1675 1663 1676 1664 checkbutton $inner.stretch \ 1677 1665 -text "Stretch to fit" \ 1678 -variable [itcl::scope _settings( stretchToFit)] \1679 -command [itcl::code $this AdjustSetting stretchToFit] \1666 -variable [itcl::scope _settings(-stretchtofit)] \ 1667 -command [itcl::code $this AdjustSetting -stretchtofit] \ 1680 1668 -font "Arial 9" 1681 1669 1682 1670 checkbutton $inner.colormapDiscrete \ 1683 1671 -text "Discrete Colormap" \ 1684 -variable [itcl::scope _settings( colormapDiscrete)] \1685 -command [itcl::code $this AdjustSetting colormapDiscrete] \1672 -variable [itcl::scope _settings(-colormapdiscrete)] \ 1673 -command [itcl::code $this AdjustSetting -colormapdiscrete] \ 1686 1674 -font "Arial 9" 1687 1675 1688 1676 itk_component add field_l { 1689 label $inner.field_l -text "Field" -font "Arial 9" 1677 label $inner.field_l -text "Field" -font "Arial 9" 1690 1678 } { 1691 1679 ignore -font … … 1695 1683 } 1696 1684 bind $inner.field <<Value>> \ 1697 [itcl::code $this AdjustSetting field]1698 1699 label $inner.colormap_l -text "Colormap" -font "Arial 9" 1685 [itcl::code $this AdjustSetting -field] 1686 1687 label $inner.colormap_l -text "Colormap" -font "Arial 9" 1700 1688 itk_component add colormap { 1701 1689 Rappture::Combobox $inner.colormap -width 10 -editable no … … 1705 1693 $itk_component(colormap) value "BCGYR" 1706 1694 bind $inner.colormap <<Value>> \ 1707 [itcl::code $this AdjustSetting colormap]1708 1709 label $inner.backingcolor_l -text "Backing Color" -font "Arial 9" 1695 [itcl::code $this AdjustSetting -colormap] 1696 1697 label $inner.backingcolor_l -text "Backing Color" -font "Arial 9" 1710 1698 itk_component add backingcolor { 1711 1699 Rappture::Combobox $inner.backingcolor -width 10 -editable no … … 1721 1709 "red" "red" \ 1722 1710 "white" "white" \ 1723 "none""none"1724 1725 $itk_component(backingcolor) value "white"1711 "none" "none" 1712 1713 $itk_component(backingcolor) value $_settings(-backingcolor) 1726 1714 bind $inner.backingcolor <<Value>> \ 1727 [itcl::code $this AdjustSetting backingColor]1728 1729 label $inner.background_l -text "Background Color" -font "Arial 9" 1715 [itcl::code $this AdjustSetting -backingcolor] 1716 1717 label $inner.background_l -text "Background Color" -font "Arial 9" 1730 1718 itk_component add background { 1731 1719 Rappture::Combobox $inner.background -width 10 -editable no … … 1734 1722 "black" "black" \ 1735 1723 "white" "white" \ 1736 "grey" "grey" 1724 "grey" "grey" 1737 1725 1738 1726 $itk_component(background) value "white" 1739 bind $inner.background <<Value>> [itcl::code $this AdjustSetting background] 1727 bind $inner.background <<Value>> \ 1728 [itcl::code $this AdjustSetting -background] 1740 1729 1741 1730 itk_component add opacity_l { … … 1746 1735 itk_component add opacity { 1747 1736 ::scale $inner.opacity -from 0 -to 100 -orient horizontal \ 1748 -variable [itcl::scope _settings( opacity)] \1737 -variable [itcl::scope _settings(-opacity)] \ 1749 1738 -showvalue off \ 1750 -command [itcl::code $this AdjustSetting opacity]1739 -command [itcl::code $this AdjustSetting -opacity] 1751 1740 } 1752 1741 … … 1758 1747 itk_component add window { 1759 1748 ::scale $inner.window -from 0 -to 255 -orient horizontal \ 1760 -variable [itcl::scope _settings( window)] \1749 -variable [itcl::scope _settings(-window)] \ 1761 1750 -showvalue off \ 1762 -command [itcl::code $this AdjustSetting window]1751 -command [itcl::code $this AdjustSetting -window] 1763 1752 } 1764 1753 itk_component add level_l { … … 1769 1758 itk_component add level { 1770 1759 ::scale $inner.level -from 0 -to 255 -orient horizontal \ 1771 -variable [itcl::scope _settings( level)] \1760 -variable [itcl::scope _settings(-level)] \ 1772 1761 -showvalue off \ 1773 -command [itcl::code $this AdjustSetting level]1762 -command [itcl::code $this AdjustSetting -level] 1774 1763 } 1775 1764 … … 1784 1773 2,0 $inner.backingcolor_l -anchor w -pady 2 \ 1785 1774 2,1 $inner.backingcolor -anchor w -pady 2 -fill x \ 1786 1787 1775 3,0 $inner.background_l -anchor w -pady 2 \ 1776 3,1 $inner.background -anchor w -pady 2 -fill x \ 1788 1777 4,0 $inner.backing -anchor w -pady 2 -cspan 2 \ 1789 1778 5,0 $inner.stretch -anchor w -pady 2 -cspan 2 \ … … 1798 1787 16,1 $inner.window -fill x -pady 2 \ 1799 1788 17,0 $inner.level_l -anchor w -pady 2 \ 1800 17,1 $inner.level -fill x -pady 2 1789 17,1 $inner.level -fill x -pady 2 1801 1790 1802 1791 blt::table configure $inner r* c* -resize none … … 1816 1805 checkbutton $inner.visible \ 1817 1806 -text "Axes" \ 1818 -variable [itcl::scope _settings( axisVisible)] \1819 -command [itcl::code $this AdjustSetting axisVisible] \1807 -variable [itcl::scope _settings(-axisvisible)] \ 1808 -command [itcl::code $this AdjustSetting -axisvisible] \ 1820 1809 -font "Arial 9" 1821 1810 checkbutton $inner.labels \ 1822 1811 -text "Axis Labels" \ 1823 -variable [itcl::scope _settings( axisLabels)] \1824 -command [itcl::code $this AdjustSetting axisLabels] \1812 -variable [itcl::scope _settings(-axislabels)] \ 1813 -command [itcl::code $this AdjustSetting -axislabels] \ 1825 1814 -font "Arial 9" 1826 label $inner.grid_l -text "Grid" -font "Arial 9" 1815 label $inner.grid_l -text "Grid" -font "Arial 9" 1827 1816 checkbutton $inner.xgrid \ 1828 1817 -text "X" \ 1829 -variable [itcl::scope _settings( axisXGrid)] \1830 -command [itcl::code $this AdjustSetting axisXGrid] \1818 -variable [itcl::scope _settings(-xgrid)] \ 1819 -command [itcl::code $this AdjustSetting -xgrid] \ 1831 1820 -font "Arial 9" 1832 1821 checkbutton $inner.ygrid \ 1833 1822 -text "Y" \ 1834 -variable [itcl::scope _settings( axisYGrid)] \1835 -command [itcl::code $this AdjustSetting axisYGrid] \1823 -variable [itcl::scope _settings(-ygrid)] \ 1824 -command [itcl::code $this AdjustSetting -ygrid] \ 1836 1825 -font "Arial 9" 1837 1826 checkbutton $inner.zgrid \ 1838 1827 -text "Z" \ 1839 -variable [itcl::scope _settings( axisZGrid)] \1840 -command [itcl::code $this AdjustSetting axisZGrid] \1828 -variable [itcl::scope _settings(-zgrid)] \ 1829 -command [itcl::code $this AdjustSetting -zgrid] \ 1841 1830 -font "Arial 9" 1842 1831 checkbutton $inner.minorticks \ 1843 1832 -text "Minor Ticks" \ 1844 -variable [itcl::scope _settings( axisMinorTicks)] \1845 -command [itcl::code $this AdjustSetting axisMinorTicks] \1833 -variable [itcl::scope _settings(-axisminorticks)] \ 1834 -command [itcl::code $this AdjustSetting -axisminorticks] \ 1846 1835 -font "Arial 9" 1847 1836 1848 label $inner.mode_l -text "Mode" -font "Arial 9" 1837 label $inner.mode_l -text "Mode" -font "Arial 9" 1849 1838 1850 1839 itk_component add axisflymode { … … 1855 1844 "closest_triad" "closest" \ 1856 1845 "furthest_triad" "farthest" \ 1857 "outer_edges" "outer" 1858 $itk_component(axisflymode) value "static"1859 bind $inner.mode <<Value>> [itcl::code $this AdjustSetting axisFlymode]1846 "outer_edges" "outer" 1847 $itk_component(axisflymode) value $_settings(-axisflymode) 1848 bind $inner.mode <<Value>> [itcl::code $this AdjustSetting -axisflymode] 1860 1849 1861 1850 blt::table $inner \ … … 1863 1852 1,0 $inner.labels -anchor w -cspan 4 \ 1864 1853 2,0 $inner.minorticks -anchor w -cspan 4 \ 1865 1854 4,0 $inner.grid_l -anchor w \ 1866 1855 4,1 $inner.xgrid -anchor w \ 1867 1856 4,2 $inner.ygrid -anchor w \ 1868 1857 4,3 $inner.zgrid -anchor w \ 1869 1858 5,0 $inner.mode_l -anchor w -padx { 2 0 } \ 1870 5,1 $inner.mode -fill x -cspan 3 1859 5,1 $inner.mode -fill x -cspan 3 1871 1860 1872 1861 blt::table configure $inner r* c* -resize none … … 1874 1863 blt::table configure $inner r3 -height 0.125i 1875 1864 } 1876 1877 1865 1878 1866 itcl::body Rappture::VtkImageViewer::BuildCameraTab {} { … … 1894 1882 0,0 $inner.view_l -anchor e -pady 2 \ 1895 1883 0,1 $inner.view -anchor w -pady 2 1884 blt::table configure $inner r0 -resize none 1896 1885 1897 1886 set labels { qx qy qz qw xpan ypan zoom } … … 1900 1889 label $inner.${tag}label -text $tag -font "Arial 9" 1901 1890 entry $inner.${tag} -font "Arial 9" -bg white \ 1902 -textvariable [itcl::scope _view( $tag)]1891 -textvariable [itcl::scope _view(-$tag)] 1903 1892 bind $inner.${tag} <Return> \ 1904 [itcl::code $this camera set ${tag}]1893 [itcl::code $this camera set -${tag}] 1905 1894 bind $inner.${tag} <KP_Enter> \ 1906 [itcl::code $this camera set ${tag}]1895 [itcl::code $this camera set -${tag}] 1907 1896 blt::table $inner \ 1908 1897 $row,0 $inner.${tag}label -anchor e -pady 2 \ … … 1913 1902 checkbutton $inner.ortho \ 1914 1903 -text "Orthographic Projection" \ 1915 -variable [itcl::scope _view( ortho)] \1916 -command [itcl::code $this camera set ortho] \1904 -variable [itcl::scope _view(-ortho)] \ 1905 -command [itcl::code $this camera set -ortho] \ 1917 1906 -font "Arial 9" 1918 1907 blt::table $inner \ … … 1921 1910 incr row 1922 1911 1923 blt::table configure $inner c* r*-resize none1912 blt::table configure $inner c* -resize none 1924 1913 blt::table configure $inner c2 -resize expand 1925 1914 blt::table configure $inner r$row -resize expand … … 1927 1916 1928 1917 # 1929 # camera -- 1918 # camera -- 1930 1919 # 1931 1920 itcl::body Rappture::VtkImageViewer::camera {option args} { 1932 switch -- $option { 1921 switch -- $option { 1933 1922 "show" { 1934 1923 puts [array get _view] 1935 1924 } 1936 1925 "set" { 1937 set wh o[lindex $args 0]1938 set x $_view($wh o)1926 set what [lindex $args 0] 1927 set x $_view($what) 1939 1928 set code [catch { string is double $x } result] 1940 1929 if { $code != 0 || !$result } { 1941 1930 return 1942 1931 } 1943 switch -- $wh o{1944 " ortho" {1945 if {$_view( ortho)} {1932 switch -- $what { 1933 "-ortho" { 1934 if {$_view($what)} { 1946 1935 SendCmd "camera mode ortho" 1947 1936 } else { … … 1949 1938 } 1950 1939 } 1951 " xpan" - "ypan" {1940 "-xpan" - "-ypan" { 1952 1941 PanCamera 1953 1942 } 1954 " qx" - "qy" - "qz" - "qw" {1955 set q [ list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]1943 "-qx" - "-qy" - "-qz" - "-qw" { 1944 set q [ViewToQuaternion] 1956 1945 $_arcball quaternion $q 1957 1946 EventuallyRotate $q 1958 1947 } 1959 " zoom" {1960 SendCmd "camera zoom $_view( zoom)"1948 "-zoom" { 1949 SendCmd "camera zoom $_view($what)" 1961 1950 } 1962 1951 } … … 1978 1967 1979 1968 itcl::body Rappture::VtkImageViewer::GetImage { args } { 1980 if { [image width $_image(download)] > 0 && 1969 if { [image width $_image(download)] > 0 && 1981 1970 [image height $_image(download)] > 0 } { 1982 1971 set bytes [$_image(download) data -format "jpeg -quality 100"] … … 1991 1980 -title "[Rappture::filexfer::label downloadWord] as..." 1992 1981 set inner [$popup component inner] 1993 label $inner.summary -text "" -anchor w 1982 label $inner.summary -text "" -anchor w 1994 1983 radiobutton $inner.vtk_button -text "VTK data file" \ 1995 1984 -variable [itcl::scope _downloadPopup(format)] \ 1996 1985 -font "Arial 9 " \ 1997 -value vtk 1986 -value vtk 1998 1987 Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file." 1999 1988 radiobutton $inner.image_button -text "Image File" \ 2000 1989 -variable [itcl::scope _downloadPopup(format)] \ 2001 1990 -font "Arial 9 " \ 2002 -value image 1991 -value image 2003 1992 Rappture::Tooltip::for $inner.image_button \ 2004 1993 "Save as digital image." … … 2021 2010 2,0 $inner.image_button -anchor w -cspan 2 -padx { 4 0 } \ 2022 2011 4,1 $inner.cancel -width .9i -fill y \ 2023 4,0 $inner.ok -padx 2 -width .9i -fill y 2012 4,0 $inner.ok -padx 2 -width .9i -fill y 2024 2013 blt::table configure $inner r3 -height 4 2025 2014 blt::table configure $inner r4 -pady 4 … … 2032 2021 # SetObjectStyle -- 2033 2022 # 2034 # Set the style of the image/contour object. This gets calls 2023 # Set the style of the image/contour object. This gets calls 2035 2024 # for each dataset once as it is loaded. It can overridden by 2036 2025 # the user controls. … … 2057 2046 # the code to handle aberrant cases. 2058 2047 2059 if { $_changed( opacity) } {2060 set style(-opacity) [expr $_settings( opacity) * 0.01]2061 } 2062 if { $_changed( colormap) } {2063 set style(-color) $_settings( colormap)2048 if { $_changed(-opacity) } { 2049 set style(-opacity) [expr $_settings(-opacity) * 0.01] 2050 } 2051 if { $_changed(-colormap) } { 2052 set style(-color) $_settings(-colormap) 2064 2053 } 2065 2054 if { $_currentColormap == "" } { … … 2067 2056 } 2068 2057 if { [info exists style(-stretchtofit)] } { 2069 set _settings( stretchToFit) $style(-stretchtofit)2070 AdjustSetting stretchToFit2058 set _settings(-stretchtofit) $style(-stretchtofit) 2059 AdjustSetting -stretchToFit 2071 2060 } 2072 2061 SendCmd "outline add $tag" 2073 2062 SendCmd "outline color [Color2RGB $itk_option(-plotforeground)] $tag" 2074 SendCmd "outline visible $_settings( outline) $tag"2063 SendCmd "outline visible $_settings(-outline) $tag" 2075 2064 SendCmd "image add $tag" 2076 SetCurrentColormap $style(-color) 2065 SetCurrentColormap $style(-color) 2077 2066 set color [$itk_component(backingcolor) value] 2078 2067 SendCmd "image color [Color2RGB $color] $tag" 2079 2068 SendCmd "image opacity $style(-opacity) $tag" 2080 set _settings( opacity) [expr $style(-opacity) * 100.0]2069 set _settings(-opacity) [expr $style(-opacity) * 100.0] 2081 2070 } 2082 2071 … … 2105 2094 #puts stderr "read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>" 2106 2095 if { [catch {DrawLegend} errs] != 0 } { 2107 2108 2096 global errorInfo 2097 puts stderr "errs=$errs errorInfo=$errorInfo" 2109 2098 } 2110 2099 } … … 2123 2112 set font "Arial 8" 2124 2113 set lineht [font metrics $font -linespace] 2125 2114 2126 2115 if { [string match "component*" $fname] } { 2127 2116 set title "" 2128 2117 } else { 2129 2130 2131 2132 2133 2134 2135 2136 2118 if { [info exists _fields($fname)] } { 2119 foreach { title units } $_fields($fname) break 2120 if { $units != "" } { 2121 set title [format "%s (%s)" $title $units] 2122 } 2123 } else { 2124 set title $fname 2125 } 2137 2126 } 2138 2127 set x [expr $w - 2] 2139 if { !$_settings( legendVisible) } {2140 2141 2142 } 2128 if { !$_settings(-legendvisible) } { 2129 $c delete legend 2130 return 2131 } 2143 2132 if { [$c find withtag "legend"] == "" } { 2144 set y 2 2145 2133 set y 2 2134 # If there's a legend title, create a text item for the title. 2146 2135 $c create text $x $y \ 2147 2148 2149 -font $font 2136 -anchor ne \ 2137 -fill $itk_option(-plotforeground) -tags "title legend" \ 2138 -font $font 2150 2139 if { $title != "" } { 2151 2140 incr y $lineht 2152 2141 } 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2142 $c create text $x $y \ 2143 -anchor ne \ 2144 -fill $itk_option(-plotforeground) -tags "vmax legend" \ 2145 -font $font 2146 incr y $lineht 2147 $c create image $x $y \ 2148 -anchor ne \ 2149 -image $_image(legend) -tags "colormap legend" 2150 $c create rectangle $x $y 1 1 \ 2151 -fill "" -outline "" -tags "sensor legend" 2152 $c create text $x [expr {$h-2}] \ 2153 -anchor se \ 2154 -fill $itk_option(-plotforeground) -tags "vmin legend" \ 2155 -font $font 2156 $c bind sensor <Enter> [itcl::code $this EnterLegend %x %y] 2157 $c bind sensor <Leave> [itcl::code $this LeaveLegend] 2158 $c bind sensor <Motion> [itcl::code $this MotionLegend %x %y] 2170 2159 } 2171 2160 … … 2181 2170 if { [info exists _limits($_curFldName)] } { 2182 2171 foreach { vmin vmax } $_limits($_curFldName) break 2183 2184 2172 $c itemconfigure vmin -text [format %g $vmin] 2173 $c itemconfigure vmax -text [format %g $vmax] 2185 2174 } 2186 2175 set y 2 … … 2188 2177 if { $title != "" } { 2189 2178 $c itemconfigure title -text $title 2190 2191 2179 $c coords title $x $y 2180 incr y $lineht 2192 2181 } 2193 2182 $c coords vmax $x $y … … 2237 2226 set font "Arial 8" 2238 2227 set lineht [font metrics $font -linespace] 2239 2228 2240 2229 set ih [image height $_image(legend)] 2241 2230 # Subtract off the offset of the color ramp from the top of the canvas … … 2243 2232 2244 2233 if { [string match "component*" $fname] } { 2245 2234 set title "" 2246 2235 } else { 2247 2248 2249 2250 2251 2252 2253 2254 2236 if { [info exists _fields($fname)] } { 2237 foreach { title units } $_fields($fname) break 2238 if { $units != "" } { 2239 set title [format "%s (%s)" $title $units] 2240 } 2241 } else { 2242 set title $fname 2243 } 2255 2244 } 2256 2245 # If there's a legend title, increase the offset by the line height. … … 2268 2257 } 2269 2258 set color [eval format "\#%02x%02x%02x" $pixel] 2270 $_image(swatch) put black -to 0 0 23 23 2271 $_image(swatch) put $color -to 1 1 22 22 2259 $_image(swatch) put black -to 0 0 23 23 2260 $_image(swatch) put $color -to 1 1 22 22 2272 2261 2273 2262 # Compute the value of the point … … 2279 2268 set value 0.0 2280 2269 } 2281 set tipx [expr $x + 15] 2270 set tipx [expr $x + 15] 2282 2271 set tipy [expr $y - 5] 2283 2272 .rappturetooltip configure -icon $_image(swatch) … … 2287 2276 Rappture::Tooltip::text $c [format "$title %g" $value] 2288 2277 } 2289 Rappture::Tooltip::tooltip show $c +$tipx,+$tipy 2278 Rappture::Tooltip::tooltip show $c +$tipx,+$tipy 2290 2279 } 2291 2280 … … 2302 2291 # ---------------------------------------------------------------------- 2303 2292 itcl::body Rappture::VtkImageViewer::Combo {option} { 2304 set c $itk_component(view) 2293 set c $itk_component(view) 2305 2294 switch -- $option { 2306 2295 post { … … 2315 2304 } 2316 2305 deactivate { 2317 $c itemconfigure title -fill $itk_option(-plotforeground) 2306 $c itemconfigure title -fill $itk_option(-plotforeground) 2318 2307 } 2319 2308 invoke { 2320 2309 $itk_component(field) value $_curFldLabel 2321 AdjustSetting field2310 AdjustSetting -field 2322 2311 } 2323 2312 default { … … 2327 2316 } 2328 2317 2329 itcl::body Rappture::VtkImageViewer::SetOrientation { side } { 2318 itcl::body Rappture::VtkImageViewer::SetOrientation { side } { 2330 2319 array set positions { 2331 2320 front "0.707107 0.707107 0 0" … … 2336 2325 bottom "0 1 0 0" 2337 2326 } 2338 foreach name { qw qx qyqz } value $positions($side) {2327 foreach name { -qw -qx -qy -qz } value $positions($side) { 2339 2328 set _view($name) $value 2340 } 2341 set q [ list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]2329 } 2330 set q [ViewToQuaternion] 2342 2331 $_arcball quaternion $q 2343 2332 SendCmd "camera orient $q" 2344 2333 SendCmd "camera reset" 2345 set _view( xpan) 02346 set _view( ypan) 02347 set _view( zoom) 1.02348 } 2334 set _view(-xpan) 0 2335 set _view(-ypan) 0 2336 set _view(-zoom) 1.0 2337 } -
branches/uq/gui/scripts/vtkisosurfaceviewer.tcl
r4798 r5121 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 2 2 # ---------------------------------------------------------------------- 3 3 # COMPONENT: vtkisosurfaceviewer - Vtk 3D contour object viewer … … 7 7 # ====================================================================== 8 8 # AUTHOR: Michael McLennan, Purdue University 9 # Copyright (c) 2004-20 05 Purdue Research Foundation9 # Copyright (c) 2004-2014 HUBzero Foundation, LLC 10 10 # 11 11 # See the file "license.terms" for information on usage and … … 57 57 public method get {args} 58 58 public method isconnected {} 59 public method limits { colormap } 60 public method parameters {title args} { 61 # do nothing 59 public method parameters {title args} { 60 # do nothing 62 61 } 63 62 public method scale {args} 64 63 65 64 # The following methods are only used by this class. 66 67 65 private method AdjustSetting {what {value ""}} 68 66 private method BuildAxisTab {} … … 70 68 private method BuildColormap { name } 71 69 private method BuildCutplaneTab {} 72 private method BuildDownloadPopup { widget command } 70 private method BuildDownloadPopup { widget command } 73 71 private method BuildIsosurfaceTab {} 74 private method Combo { option }75 72 private method Connect {} 76 73 private method CurrentDatasets {args} 74 private method DisableMouseRotationBindings {} 77 75 private method Disconnect {} 78 76 private method DoChangeContourLevels {} … … 80 78 private method DoRotate {} 81 79 private method DrawLegend {} 82 private method EnterLegend { x y } 83 private method EventuallyChangeContourLevels {} 84 private method EventuallyRequestLegend {} 85 private method EventuallyResize { w h } 86 private method EventuallyRotate { q } 87 private method EventuallySetCutplane { axis args } 80 private method EnterLegend { x y } 81 private method EventuallyChangeContourLevels {} 82 private method EventuallyRequestLegend {} 83 private method EventuallyResize { w h } 84 private method EventuallyRotate { q } 85 private method EventuallySetCutplane { axis args } 88 86 private method GenerateContourList {} 89 private method GetImage { args } 90 private method GetVtkData { args } 91 private method InitSettings { args 92 private method IsValidObject { dataobj } 87 private method GetImage { args } 88 private method GetVtkData { args } 89 private method InitSettings { args } 90 private method IsValidObject { dataobj } 93 91 private method LeaveLegend {} 94 private method MotionLegend { x y } 92 private method LegendB1Motion {status x y} 93 private method LegendPointToValue { x y } 94 private method LegendProbeSingleContour { x y } 95 private method LegendRangeAction { option args } 96 private method LegendRangeValidate { widget which value } 97 private method LegendTitleAction { option } 98 private method MotionLegend { x y } 99 private method MouseOver2Which {} 95 100 private method Pan {option x y} 96 101 private method PanCamera {} 97 102 private method Pick {x y} 103 private method QuaternionToView { q } { 104 foreach { _view(-qw) _view(-qx) _view(-qy) _view(-qz) } $q break 105 } 98 106 private method Rebuild {} 99 107 private method ReceiveDataset { args } … … 103 111 private method Rotate {option x y} 104 112 private method SetCurrentColormap { color } 113 private method SetCurrentFieldName { dataobj } 105 114 private method SetLegendTip { x y } 106 private method Set ObjectStyle { dataobj comp }107 private method Set CurrentFieldName { dataobj }115 private method SetMinMaxGauges { min max } 116 private method SetObjectStyle { dataobj comp } 108 117 private method SetOrientation { side } 109 private method Slice {option args} 118 private method SetupMouseRotationBindings {} 119 private method SetupMousePanningBindings {} 120 private method SetupKeyboardBindings {} 121 private method Slice {option args} 122 private method ToggleCustomRange { args } 123 private method ViewToQuaternion {} { 124 return [list $_view(-qw) $_view(-qx) $_view(-qy) $_view(-qz)] 125 } 110 126 private method Zoom {option} 111 private method ViewToQuaternion {} {112 return [list $_view(-qw) $_view(-qx) $_view(-qy) $_view(-qz)]113 }114 127 115 128 private variable _arcball "" … … 118 131 private variable _obj2datasets 119 132 private variable _obj2ovride ; # maps dataobj => style override 120 private variable _datasets ; # contains all the dataobj-component 133 private variable _datasets ; # contains all the dataobj-component 121 134 ; # datasets in the server 122 135 private variable _colormaps ; # contains all the colormaps … … 156 169 private variable _legendPending 0 157 170 private variable _field "" 158 private variable _colorMode "scalar"; 159 private variable _fieldNames {} 160 private variable _fields 171 private variable _colorMode "scalar"; # Mode of colormap (vmag or scalar) 172 private variable _fieldNames {} 173 private variable _fields 161 174 private variable _curFldName "" 162 175 private variable _curFldLabel "" 176 177 private variable _mouseOver ""; # what called LegendRangeAction, vmin or vmax 178 private variable _customRangeClick 1; # what called ToggleCustomRange 163 179 } 164 180 … … 227 243 -xpan 0 228 244 -ypan 0 229 -zoom 1.0 245 -zoom 1.0 230 246 } 231 247 set _arcball [blt::arcball create 100 100] … … 239 255 } 240 256 array set _settings { 241 -axesvisible 1 242 -axislabelsvisible 1 243 -axismode "static" 244 -background black 245 -colormap BCGYR 246 -colormapvisible 1 247 -cutplaneedges 0 248 -cutplanelighting 1 249 -cutplaneopacity 1.0 250 -cutplanepreinterp 1 251 -cutplanesvisible 0 252 -cutplanewireframe 0 253 -field "Default" 254 -isolinecolor white 255 -isosurfaceedges 0 256 -isosurfacelighting 1 257 -isosurfaceopacity 0.6 258 -isosurfacevisible 1 259 -isosurfacewireframe 0 260 -legendvisible 1 261 -numcontours 10 262 -outline 0 263 -xcutplaneposition 50 264 -xcutplanevisible 1 265 -xgrid 0 266 -ycutplaneposition 50 267 -ycutplanevisible 1 268 -ygrid 0 269 -zcutplaneposition 50 270 -zcutplanevisible 1 271 -zgrid 0 257 -axesvisible 1 258 -axislabels 1 259 -axisminorticks 1 260 -axismode "static" 261 -background black 262 -colormap BCGYR 263 -colormapvisible 1 264 -customrange 0 265 -customrangemin 0 266 -customrangemax 1 267 -cutplaneedges 0 268 -cutplanelighting 1 269 -cutplaneopacity 1.0 270 -cutplanepreinterp 1 271 -cutplanesvisible 0 272 -cutplanewireframe 0 273 -field "Default" 274 -isolinecolor white 275 -isosurfaceedges 0 276 -isosurfacelighting 1 277 -isosurfaceopacity 0.6 278 -isosurfacevisible 1 279 -isosurfacewireframe 0 280 -legendvisible 1 281 -numcontours 10 282 -outline 0 283 -xcutplaneposition 50 284 -xcutplanevisible 1 285 -xgrid 0 286 -ycutplaneposition 50 287 -ycutplanevisible 1 288 -ygrid 0 289 -zcutplaneposition 50 290 -zcutplanevisible 1 291 -zgrid 0 272 292 } 273 293 array set _changed { 274 294 -colormap 0 295 -cutplaneedges 0 296 -cutplanelighting 0 297 -cutplaneopacity 0 298 -cutplanepreinterp 0 299 -cutplanesvisible 0 300 -cutplanewireframe 0 301 -isosurfaceedges 0 302 -isosurfacelighting 0 275 303 -isosurfaceopacity 0 276 -cutplaneopacity 0 304 -isosurfacevisible 0 305 -isosurfacewireframe 0 277 306 -numcontours 0 307 -outline 0 308 -xcutplaneposition 0 309 -xcutplanevisible 0 310 -ycutplaneposition 0 311 -ycutplanevisible 0 312 -zcutplaneposition 0 313 -zcutplanevisible 0 278 314 } 279 315 array set _widget { … … 292 328 itk_component add fieldmenu { 293 329 menu $itk_component(plotarea).menu -bg black -fg white -relief flat \ 294 -tearoff 0 330 -tearoff 0 295 331 } { 296 332 usual 297 333 ignore -background -foreground -relief -tearoff 298 334 } 335 336 # add an editor for adjusting the legend min and max values 337 itk_component add editor { 338 Rappture::Editor $itk_interior.editor \ 339 -activatecommand [itcl::code $this LegendRangeAction activate] \ 340 -validatecommand [itcl::code $this LegendRangeAction validate] \ 341 -applycommand [itcl::code $this LegendRangeAction apply] 342 } 343 299 344 set c $itk_component(view) 300 345 bind $c <Configure> [itcl::code $this EventuallyResize %w %h] … … 312 357 313 358 set _map(id) [$c create image 0 0 -anchor nw -image $_image(plot)] 314 set _map(cwidth) -1 315 set _map(cheight) -1 359 set _map(cwidth) -1 360 set _map(cheight) -1 316 361 set _map(zoom) 1.0 317 362 set _map(original) "" … … 360 405 -offimage [Rappture::icon volume-off] \ 361 406 -variable [itcl::scope _settings(-isosurfacevisible)] \ 362 -command [itcl::code $this AdjustSetting -isosurfacevisible] 407 -command [itcl::code $this AdjustSetting -isosurfacevisible] 363 408 } 364 409 $itk_component(contour) select … … 372 417 -offimage [Rappture::icon cutbutton] \ 373 418 -variable [itcl::scope _settings(-cutplanesvisible)] \ 374 -command [itcl::code $this AdjustSetting -cutplanesvisible] 419 -command [itcl::code $this AdjustSetting -cutplanesvisible] 375 420 } 376 421 Rappture::Tooltip::for $itk_component(cutplane) \ … … 387 432 puts stderr errs=$errs 388 433 } 434 389 435 # Legend 390 391 436 set _image(legend) [image create photo] 392 437 itk_component add legend { 393 canvas $itk_component(plotarea).legend -width 50 -highlightthickness 0 438 canvas $itk_component(plotarea).legend -width 50 -highlightthickness 0 394 439 } { 395 440 usual … … 398 443 } 399 444 400 # Hack around the Tk panewindow. The problem is that the requested 445 # Hack around the Tk panewindow. The problem is that the requested 401 446 # size of the 3d view isn't set until an image is retrieved from 402 447 # the server. So the panewindow uses the tiny size. … … 404 449 pack forget $itk_component(view) 405 450 blt::table $itk_component(plotarea) \ 406 0,0 $itk_component(view) -fill both -reqwidth $w 451 0,0 $itk_component(view) -fill both -reqwidth $w 407 452 blt::table configure $itk_component(plotarea) c1 -resize none 408 453 454 SetupMouseRotationBindings 455 SetupMousePanningBindings 456 SetupKeyboardBindings 457 458 459 #bind $itk_component(view) <ButtonRelease-3> \ 460 # [itcl::code $this Pick %x %y] 461 462 463 if {[string equal "x11" [tk windowingsystem]]} { 464 # Bindings for zoom via mouse 465 bind $itk_component(view) <4> [itcl::code $this Zoom out] 466 bind $itk_component(view) <5> [itcl::code $this Zoom in] 467 } 468 469 set _image(download) [image create photo] 470 471 eval itk_initialize $args 472 473 EnableWaitDialog 500 474 Connect 475 # FIXME: Removing this update breaks wizard mode (see examples/3D) 476 # However, it also allows an error in the initialization order 477 # where FieldResult::add is called from ResultViewer before this 478 # constructor is completed. 479 #update 480 } 481 482 # ---------------------------------------------------------------------- 483 # DESTRUCTOR 484 # ---------------------------------------------------------------------- 485 itcl::body Rappture::VtkIsosurfaceViewer::destructor {} { 486 Disconnect 487 image delete $_image(plot) 488 image delete $_image(download) 489 catch { blt::arcball destroy $_arcball } 490 } 491 492 itcl::body Rappture::VtkIsosurfaceViewer::SetupMouseRotationBindings {} { 409 493 # Bindings for rotation via mouse 410 494 bind $itk_component(view) <ButtonPress-1> \ … … 414 498 bind $itk_component(view) <ButtonRelease-1> \ 415 499 [itcl::code $this Rotate release %x %y] 416 500 } 501 502 itcl::body Rappture::VtkIsosurfaceViewer::DisableMouseRotationBindings {} { 503 # Bindings for rotation via mouse 504 bind $itk_component(view) <ButtonPress-1> "" 505 bind $itk_component(view) <B1-Motion> "" 506 bind $itk_component(view) <ButtonRelease-1> "" 507 } 508 509 itcl::body Rappture::VtkIsosurfaceViewer::SetupMousePanningBindings {} { 417 510 # Bindings for panning via mouse 418 511 bind $itk_component(view) <ButtonPress-2> \ … … 422 515 bind $itk_component(view) <ButtonRelease-2> \ 423 516 [itcl::code $this Pan release %x %y] 424 425 #bind $itk_component(view) <ButtonRelease-3> \ 426 # [itcl::code $this Pick %x %y] 427 517 } 518 519 itcl::body Rappture::VtkIsosurfaceViewer::SetupKeyboardBindings {} { 428 520 # Bindings for panning via keyboard 429 521 bind $itk_component(view) <KeyPress-Left> \ … … 451 543 452 544 bind $itk_component(view) <Enter> "focus $itk_component(view)" 453 454 if {[string equal "x11" [tk windowingsystem]]} {455 # Bindings for zoom via mouse456 bind $itk_component(view) <4> [itcl::code $this Zoom out]457 bind $itk_component(view) <5> [itcl::code $this Zoom in]458 }459 460 set _image(download) [image create photo]461 462 eval itk_initialize $args463 464 EnableWaitDialog 500465 Connect466 }467 468 # ----------------------------------------------------------------------469 # DESTRUCTOR470 # ----------------------------------------------------------------------471 itcl::body Rappture::VtkIsosurfaceViewer::destructor {} {472 Disconnect473 image delete $_image(plot)474 image delete $_image(download)475 catch { blt::arcball destroy $_arcball }476 545 } 477 546 … … 499 568 500 569 itcl::body Rappture::VtkIsosurfaceViewer::DoRotate {} { 501 SendCmd "camera orient [ViewToQuaternion]" 570 SendCmd "camera orient [ViewToQuaternion]" 502 571 set _rotatePending 0 503 572 } … … 523 592 524 593 itcl::body Rappture::VtkIsosurfaceViewer::EventuallyRotate { q } { 525 foreach { _view(-qw) _view(-qx) _view(-qy) _view(-qz) } $q break594 QuaternionToView $q 526 595 if { !$_rotatePending } { 527 596 set _rotatePending 1 528 global rotate_delay 597 global rotate_delay 529 598 $_dispatcher event -after $rotate_delay !rotate 530 599 } … … 543 612 if { !$_contourList(updatePending) } { 544 613 set _contourList(updatePending) 1 545 global rotate_delay 614 global rotate_delay 546 615 $_dispatcher event -after $rotate_delay !contours 547 616 } … … 588 657 } 589 658 590 591 659 # ---------------------------------------------------------------------- 592 660 # USAGE: delete ?<dataobj1> <dataobj2> ...? … … 643 711 continue 644 712 } 645 if {[info exists _obj2ovride($dataobj-raise)] && 713 if {[info exists _obj2ovride($dataobj-raise)] && 646 714 $_obj2ovride($dataobj-raise)} { 647 715 set dlist [linsert $dlist 0 $dataobj] … … 671 739 } 672 740 return $dlist 673 } 741 } 674 742 -image { 675 743 if {[llength $args] != 2} { … … 724 792 if { ![info exists _limits($fname)] } { 725 793 set _limits($fname) $lim 794 795 # set reasonable defaults for 796 # customrangevmin and customrangevmax 797 foreach {min max} $lim break 798 SetMinMaxGauges $min $max 799 set _settings(-customrangemin) $min 800 set _settings(-customrangemax) $max 801 726 802 continue 727 803 } 728 804 foreach {min max} $lim break 729 805 foreach {fmin fmax} $_limits($fname) break 806 if { ! $_settings(-customrange) } { 807 SetMinMaxGauges $fmin $fmax 808 } 730 809 if { $fmin > $min } { 731 810 set fmin $min … … 900 979 if { $info(-type) == "image" } { 901 980 if 0 { 902 set f [open "last.ppm" "w"] 903 puts $f $bytes 981 set f [open "last.ppm" "w"] 982 fconfigure $f -encoding binary 983 puts -nonewline $f $bytes 904 984 close $f 905 985 } … … 909 989 #set w [image width $_image(plot)] 910 990 #set h [image height $_image(plot)] 911 #puts stderr "$date: received image ${w}x${h} image" 991 #puts stderr "$date: received image ${w}x${h} image" 912 992 if { $_start > 0 } { 913 993 set finish [clock clicks -milliseconds] … … 980 1060 # Turn on buffering of commands to the server. We don't want to 981 1061 # be preempted by a server disconnect/reconnect (which automatically 982 # generates a new call to Rebuild). 1062 # generates a new call to Rebuild). 983 1063 StartBufferingCommands 1064 984 1065 if { $_reset } { 985 1066 set _width $w … … 990 1071 # Reset the camera and other view parameters 991 1072 $_arcball quaternion [ViewToQuaternion] 1073 InitSettings -ortho 992 1074 DoRotate 993 1075 PanCamera 994 1076 set _first "" 995 InitSettings -xgrid -ygrid -zgrid -axismode \ 996 -axesvisible -axislabelsvisible -ortho 997 SendCmd "axis lformat all %g" 998 # Too many major ticks, so turn off minor ticks 999 SendCmd "axis minticks all 0" 1077 InitSettings -background \ 1078 -xgrid -ygrid -zgrid -axismode \ 1079 -axesvisible -axislabels -axisminorticks 1080 #SendCmd "axis lformat all %g" 1000 1081 StopBufferingCommands 1001 1082 SendCmd "imgflush" … … 1015 1096 if { ![info exists _datasets($tag)] } { 1016 1097 set bytes [$dataobj vtkdata $comp] 1017 if 0 { 1018 set f [open "/tmp/isosurface.vtk" "w"] 1019 puts $f $bytes 1020 close $f 1098 if 0 { 1099 set f [open "/tmp/isosurface.vtk" "w"] 1100 fconfigure $f -translation binary -encoding binary 1101 puts -nonewline $f $bytes 1102 close $f 1021 1103 } 1022 1104 set length [string length $bytes] 1023 1105 if { $_reportClientInfo } { 1024 1106 set info {} 1025 lappend info "tool_id" [$dataobj hints toolId] 1026 lappend info "tool_name" [$dataobj hints toolName] 1027 lappend info "tool_version" [$dataobj hints toolRevision] 1028 lappend info "tool_title" [$dataobj hints toolTitle] 1107 lappend info "tool_id" [$dataobj hints toolid] 1108 lappend info "tool_name" [$dataobj hints toolname] 1109 lappend info "tool_title" [$dataobj hints tooltitle] 1110 lappend info "tool_command" [$dataobj hints toolcommand] 1111 lappend info "tool_revision" [$dataobj hints toolrevision] 1029 1112 lappend info "dataset_label" [$dataobj hints label] 1030 1113 lappend info "dataset_size" $length … … 1039 1122 lappend _obj2datasets($dataobj) $tag 1040 1123 if { [info exists _obj2ovride($dataobj-raise)] } { 1041 1124 SendCmd "contour3d visible 1 $tag" 1042 1125 } 1043 1126 } … … 1046 1129 InitSettings -cutplanesvisible -isosurfacevisible -outline 1047 1130 if { $_reset } { 1048 1131 # These are settings that rely on a dataset being loaded. 1049 1132 InitSettings \ 1050 1133 -isosurfacelighting \ 1051 1134 -field \ 1135 -range \ 1052 1136 -isosurfacevisible \ 1053 1137 -isosurfaceedges -isosurfacelighting -isosurfaceopacity \ 1054 1138 -isosurfacewireframe \ 1055 1139 -cutplanesvisible \ 1056 1057 1140 -xcutplaneposition -ycutplaneposition -zcutplaneposition \ 1141 -xcutplanevisible -ycutplanevisible -zcutplanevisible \ 1058 1142 -cutplanepreinterp -numcontours 1059 1143 1060 1144 Zoom reset 1061 1145 foreach axis { x y z } { 1062 1146 # Another problem fixed by a <view>. We looking into a data 1063 1147 # object for the name of the axes. This should be global to 1064 1148 # the viewer itself. 1065 1066 1149 set label [$_first hints ${axis}label] 1150 if { $label == "" } { 1067 1151 set label [string toupper $axis] 1068 } 1069 SendCmd [list axis name $axis $label] 1152 } 1153 # May be a space in the axis label 1154 SendCmd [list axis name $axis $label] 1070 1155 } 1071 1156 if { [array size _fields] < 2 } { 1072 catch { 1073 blt::table forget $itk_component(field) $itk_component(field_l) 1074 } 1157 catch {blt::table forget $itk_component(field) $itk_component(field_l)} 1075 1158 } 1076 1159 set _reset 0 … … 1096 1179 itcl::body Rappture::VtkIsosurfaceViewer::CurrentDatasets {args} { 1097 1180 set flag [lindex $args 0] 1098 switch -- $flag { 1181 switch -- $flag { 1099 1182 "-all" { 1100 1183 if { [llength $args] > 1 } { … … 1115 1198 set dlist [get -visible] 1116 1199 } 1117 } 1200 } 1118 1201 default { 1119 1202 set dlist $args … … 1152 1235 "reset" { 1153 1236 array set _view { 1154 -qw 0.8535531155 -qx -0.3535531156 -qy 0.3535531157 -qz 0.1464471158 -xpan 01159 -ypan 01160 -zoom 1.01237 -qw 0.853553 1238 -qx -0.353553 1239 -qy 0.353553 1240 -qz 0.146447 1241 -xpan 0 1242 -ypan 0 1243 -zoom 1.0 1161 1244 } 1162 1245 if { $_first != "" } { … … 1178 1261 SendCmd "camera pan $x $y" 1179 1262 } 1180 1181 1263 1182 1264 # ---------------------------------------------------------------------- … … 1234 1316 itcl::body Rappture::VtkIsosurfaceViewer::Pick {x y} { 1235 1317 foreach tag [CurrentDatasets -visible] { 1236 SendCmd NoSplash"dataset getscalar pixel $x $y $tag"1237 } 1318 SendCmd "dataset getscalar pixel $x $y $tag" 1319 } 1238 1320 } 1239 1321 … … 1323 1405 SendCmd "axis visible all $bool" 1324 1406 } 1325 "-axislabels visible" {1407 "-axislabels" { 1326 1408 set bool $_settings($what) 1327 1409 SendCmd "axis labels all $bool" 1410 } 1411 "-axisminorticks" { 1412 set bool $_settings($what) 1413 SendCmd "axis minticks all $bool" 1328 1414 } 1329 1415 "-axismode" { … … 1335 1421 "-background" { 1336 1422 set bgcolor [$itk_component(background) value] 1337 1338 1339 1340 "grey""black"1341 1423 array set fgcolors { 1424 "black" "white" 1425 "white" "black" 1426 "grey" "black" 1427 } 1342 1428 configure -plotbackground $bgcolor \ 1343 1344 1345 1429 -plotforeground $fgcolors($bgcolor) 1430 $itk_component(view) delete "legend" 1431 DrawLegend 1346 1432 } 1347 1433 "-cutplaneedges" { 1434 set _changed($what) 1 1348 1435 set bool $_settings($what) 1349 1436 SendCmd "cutplane edges $bool" 1350 1437 } 1351 1438 "-cutplanelighting" { 1439 set _changed($what) 1 1352 1440 set bool $_settings($what) 1353 1441 SendCmd "cutplane lighting $bool" 1354 1442 } 1355 1443 "-cutplaneopacity" { 1444 set _changed($what) 1 1356 1445 set _settings($what) [expr $_widget($what) * 0.01] 1357 1446 SendCmd "cutplane opacity $_settings($what)" 1358 1447 } 1359 1448 "-cutplanepreinterp" { 1449 set _changed($what) 1 1360 1450 set bool $_settings($what) 1361 1451 SendCmd "cutplane preinterp $bool" 1362 1452 } 1363 1453 "-cutplanesvisible" { 1454 set _changed($what) 1 1364 1455 set bool $_settings($what) 1365 1456 SendCmd "cutplane visible 0" 1366 1457 if { $bool } { 1367 1458 foreach tag [CurrentDatasets -visible] { … … 1378 1469 } 1379 1470 "-cutplanewireframe" { 1471 set _changed($what) 1 1380 1472 set bool $_settings($what) 1381 1473 SendCmd "cutplane wireframe $bool" … … 1386 1478 set color [$itk_component(colormap) value] 1387 1479 set _settings($what) $color 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1480 if { $color == "none" } { 1481 if { $_settings(-colormapvisible) } { 1482 SendCmd "contour3d colormode constant {}" 1483 set _settings(-colormapvisible) 0 1484 } 1485 } else { 1486 if { !$_settings(-colormapvisible) } { 1487 SendCmd "contour3d colormode $_colorMode $_curFldName" 1488 set _settings(-colormapvisible) 1 1489 } 1490 SetCurrentColormap $color 1491 } 1400 1492 StopBufferingCommands 1401 1493 EventuallyRequestLegend 1402 1494 } 1403 1495 "-field" { … … 1422 1514 SendCmd "dataset maprange all" 1423 1515 } else { 1424 SendCmd "dataset maprange explicit $_limits($_curFldName) $_curFldName" 1516 if { $_settings(-customrange) } { 1517 set vmin [$itk_component(min) value] 1518 set vmax [$itk_component(max) value] 1519 } else { 1520 foreach { vmin vmax } $_limits($_curFldName) break 1521 # set the min / max gauges with limits from the field 1522 # the legend's min and max text will be updated 1523 # when the legend is redrawn in DrawLegend 1524 SetMinMaxGauges $vmin $vmax 1525 } 1526 SendCmd "dataset maprange explicit $vmin $vmax $_curFldName" 1425 1527 } 1426 1528 SendCmd "cutplane colormode $_colorMode $_curFldName" … … 1432 1534 "-isolinecolor" { 1433 1535 set color [$itk_component(isolineColor) value] 1434 1435 1536 set _settings($what) $color 1537 DrawLegend 1436 1538 } 1437 1539 "-isosurfaceedges" { 1540 set _changed($what) 1 1438 1541 set bool $_settings($what) 1439 1542 SendCmd "contour3d edges $bool" 1440 1543 } 1441 1544 "-isosurfacelighting" { 1545 set _changed($what) 1 1442 1546 set bool $_settings($what) 1443 1547 SendCmd "contour3d lighting $bool" 1444 1548 } 1445 1549 "-isosurfaceopacity" { 1550 set _changed($what) 1 1446 1551 set _settings($what) [expr $_widget($what) * 0.01] 1447 1552 SendCmd "contour3d opacity $_settings($what)" 1448 1553 } 1449 1554 "-isosurfacevisible" { 1555 set _changed($what) 1 1450 1556 set bool $_settings($what) 1451 1557 SendCmd "contour3d visible 0" 1452 1558 if { $bool } { 1453 1559 foreach tag [CurrentDatasets -visible] { … … 1464 1570 } 1465 1571 "-isosurfacewireframe" { 1572 set _changed($what) 1 1466 1573 set bool $_settings($what) 1467 1574 SendCmd "contour3d wireframe $bool" 1468 1575 } 1469 1576 "-legendvisible" { 1470 1577 if { !$_settings($what) } { 1471 1578 $itk_component(view) delete legend 1472 1473 1579 } 1580 DrawLegend 1474 1581 } 1475 1582 "-numcontours" { 1583 set _changed($what) 1 1476 1584 set _settings($what) [$itk_component(numcontours) value] 1477 1585 if { $_contourList(numLevels) != $_settings($what) } { … … 1489 1597 } 1490 1598 "-outline" { 1599 set _changed($what) 1 1491 1600 set bool $_settings($what) 1492 1601 SendCmd "outline visible 0" 1493 1602 if { $bool } { 1494 1603 foreach tag [CurrentDatasets -visible] { … … 1497 1606 } 1498 1607 } 1608 "-range" { 1609 if { $_settings(-customrange) } { 1610 set vmin [$itk_component(min) value] 1611 set vmax [$itk_component(max) value] 1612 } else { 1613 foreach { vmin vmax } $_limits($_curFldName) break 1614 } 1615 GenerateContourList 1616 SendCmd [list contour3d contourlist $_contourList(values)] 1617 SendCmd "dataset maprange explicit $vmin $vmax $_curFldName" 1618 DrawLegend 1619 } 1499 1620 "-xcutplanevisible" - "-ycutplanevisible" - "-zcutplanevisible" { 1621 set _changed($what) 1 1500 1622 set axis [string tolower [string range $what 1 1]] 1501 1623 set bool $_settings($what) … … 1507 1629 -troughcolor grey82 1508 1630 } 1509 1631 SendCmd "cutplane axis $axis $bool" 1510 1632 } 1511 1633 "-xcutplaneposition" - "-ycutplaneposition" - "-zcutplaneposition" { 1634 set _changed($what) 1 1512 1635 set axis [string tolower [string range $what 1 1]] 1513 1636 set pos [expr $_settings($what) * 0.01] … … 1526 1649 } 1527 1650 1528 1529 1651 # 1530 1652 # RequestLegend -- 1531 1653 # 1532 1654 # Request a new legend from the server. The size of the legend 1533 # is determined from the height of the canvas. 1655 # is determined from the height of the canvas. 1534 1656 # 1535 1657 # This should be called when 1536 # 1537 # 1538 # 1539 # 1540 # 1658 # 1. A new current colormap is set. 1659 # 2. Window is resized. 1660 # 3. The limits of the data have changed. (Just need a redraw). 1661 # 4. Number of isolines have changed. (Just need a redraw). 1662 # 5. Legend becomes visible (Just need a redraw). 1541 1663 # 1542 1664 itcl::body Rappture::VtkIsosurfaceViewer::RequestLegend {} { … … 1554 1676 } 1555 1677 if { [string match "component*" $fname] } { 1556 1678 set title "" 1557 1679 } else { 1558 1559 1560 1561 1562 1563 1564 1565 1680 if { [info exists _fields($fname)] } { 1681 foreach { title units } $_fields($fname) break 1682 if { $units != "" } { 1683 set title [format "%s (%s)" $title $units] 1684 } 1685 } else { 1686 set title $fname 1687 } 1566 1688 } 1567 1689 # If there's a title too, subtract one more line 1568 1690 if { $title != "" } { 1569 incr h -$lineht 1570 } 1571 # Set the legend on the first heightmapdataset.1691 incr h -$lineht 1692 } 1693 # Set the legend on the first isosurface dataset. 1572 1694 if { $_currentColormap != "" } { 1573 1574 1695 set cmap $_currentColormap 1696 SendCmdNoWait "legend $cmap scalar $_curFldName {} $w $h 0" 1575 1697 } 1576 1698 } … … 1592 1714 if { [isconnected] } { 1593 1715 set rgb [Color2RGB $itk_option(-plotforeground)] 1594 1716 SendCmd "axis color all $rgb" 1595 1717 SendCmd "outline color $rgb" 1596 1718 SendCmd "cutplane color $rgb" 1597 1719 } 1598 }1599 1600 itcl::body Rappture::VtkIsosurfaceViewer::limits { dataobj } {1601 foreach { limits(xmin) limits(xmax) } [$dataobj limits x] break1602 foreach { limits(ymin) limits(ymax) } [$dataobj limits y] break1603 foreach { limits(zmin) limits(zmax) } [$dataobj limits z] break1604 foreach { limits(vmin) limits(vmax) } [$dataobj limits v] break1605 return [array get limits]1606 1720 } 1607 1721 … … 1652 1766 -font "Arial 9" 1653 1767 1654 label $inner.linecolor_l -text "Isolines" -font "Arial 9" 1768 label $inner.linecolor_l -text "Isolines" -font "Arial 9" 1655 1769 itk_component add isolineColor { 1656 1770 Rappture::Combobox $inner.linecolor -width 10 -editable 0 … … 1666 1780 "red" "red" \ 1667 1781 "white" "white" \ 1668 "none""none"1782 "none" "none" 1669 1783 1670 1784 $itk_component(isolineColor) value "white" 1671 1785 bind $inner.linecolor <<Value>> \ 1672 1673 1674 label $inner.background_l -text "Background" -font "Arial 9" 1786 [itcl::code $this AdjustSetting -isolinecolor] 1787 1788 label $inner.background_l -text "Background" -font "Arial 9" 1675 1789 itk_component add background { 1676 1790 Rappture::Combobox $inner.background -width 10 -editable 0 … … 1679 1793 "black" "black" \ 1680 1794 "white" "white" \ 1681 "grey" "grey" 1795 "grey" "grey" 1682 1796 1683 1797 $itk_component(background) value $_settings(-background) … … 1691 1805 -showvalue off \ 1692 1806 -command [itcl::code $this AdjustSetting -isosurfaceopacity] 1693 set _widget(-isosurfaceopacity) \ 1694 [expr $_settings(-isosurfaceopacity) * 100.0] 1807 $inner.opacity set [expr $_settings(-isosurfaceopacity) * 100.0] 1695 1808 1696 1809 itk_component add field_l { 1697 label $inner.field_l -text "Field" -font "Arial 9" 1810 label $inner.field_l -text "Field" -font "Arial 9" 1698 1811 } { 1699 1812 ignore -font … … 1705 1818 [itcl::code $this AdjustSetting -field] 1706 1819 1707 label $inner.colormap_l -text "Colormap" -font "Arial 9" 1820 label $inner.colormap_l -text "Colormap" -font "Arial 9" 1708 1821 itk_component add colormap { 1709 1822 Rappture::Combobox $inner.colormap -width 10 -editable 0 … … 1723 1836 bind $itk_component(numcontours) <<Value>> \ 1724 1837 [itcl::code $this AdjustSetting -numcontours] 1838 1839 1840 # add widgets for setting a custom range on the legend 1841 1842 itk_component add crange { 1843 checkbutton $inner.crange \ 1844 -text "Use Custom Range:" \ 1845 -variable [itcl::scope _settings(-customrange)] \ 1846 -command [itcl::code $this ToggleCustomRange] \ 1847 -font "Arial 9" 1848 } 1849 1850 itk_component add l_min { 1851 label $inner.l_min -text "Min" -font "Arial 9" 1852 } 1853 itk_component add min { 1854 Rappture::Gauge $inner.min -font "Arial 9" \ 1855 -validatecommand [itcl::code $this LegendRangeValidate "" vmin] 1856 } 1857 bind $itk_component(min) <<Value>> \ 1858 [itcl::code $this AdjustSetting -range] 1859 1860 itk_component add l_max { 1861 label $inner.l_max -text "Max" -font "Arial 9" 1862 } 1863 itk_component add max { 1864 Rappture::Gauge $inner.max -font "Arial 9" \ 1865 -validatecommand [itcl::code $this LegendRangeValidate "" vmax] 1866 } 1867 bind $itk_component(max) <<Value>> \ 1868 [itcl::code $this AdjustSetting -range] 1869 1870 $itk_component(min) configure -state disabled 1871 $itk_component(max) configure -state disabled 1872 1725 1873 1726 1874 blt::table $inner \ … … 1731 1879 2,0 $inner.linecolor_l -anchor w -pady 2 \ 1732 1880 2,1 $inner.linecolor -anchor w -pady 2 -fill x \ 1733 1734 1881 3,0 $inner.background_l -anchor w -pady 2 \ 1882 3,1 $inner.background -anchor w -pady 2 -fill x \ 1735 1883 4,0 $inner.numcontours_l -anchor w -pady 2 \ 1736 1884 4,1 $inner.numcontours -anchor w -pady 2 \ … … 1742 1890 10,0 $inner.opacity_l -anchor w -pady 2 \ 1743 1891 10,1 $inner.opacity -fill x -pady 2 -fill x \ 1892 11,0 $inner.crange -anchor w -pady 2 -cspan 2 \ 1893 12,0 $inner.l_min -anchor w -pady 2 \ 1894 12,1 $inner.min -anchor w -pady 2 -fill x \ 1895 13,0 $inner.l_max -anchor w -pady 2 \ 1896 13,1 $inner.max -anchor w -pady 2 -fill x \ 1744 1897 1745 1898 blt::table configure $inner r* c* -resize none 1746 blt::table configure $inner r1 1c1 -resize expand1899 blt::table configure $inner r14 c1 -resize expand 1747 1900 } 1748 1901 … … 1758 1911 1759 1912 checkbutton $inner.visible \ 1760 -text " ShowAxes" \1913 -text "Axes" \ 1761 1914 -variable [itcl::scope _settings(-axesvisible)] \ 1762 1915 -command [itcl::code $this AdjustSetting -axesvisible] \ … … 1764 1917 1765 1918 checkbutton $inner.labels \ 1766 -text " ShowAxis Labels" \1767 -variable [itcl::scope _settings(-axislabels visible)] \1768 -command [itcl::code $this AdjustSetting -axislabels visible] \1919 -text "Axis Labels" \ 1920 -variable [itcl::scope _settings(-axislabels)] \ 1921 -command [itcl::code $this AdjustSetting -axislabels] \ 1769 1922 -font "Arial 9" 1770 1771 checkbutton $inner. gridx\1772 -text " Show X Grid" \1923 label $inner.grid_l -text "Grid" -font "Arial 9" 1924 checkbutton $inner.xgrid \ 1925 -text "X" \ 1773 1926 -variable [itcl::scope _settings(-xgrid)] \ 1774 1927 -command [itcl::code $this AdjustSetting -xgrid] \ 1775 1928 -font "Arial 9" 1776 checkbutton $inner. gridy\1777 -text " Show Y Grid" \1929 checkbutton $inner.ygrid \ 1930 -text "Y" \ 1778 1931 -variable [itcl::scope _settings(-ygrid)] \ 1779 1932 -command [itcl::code $this AdjustSetting -ygrid] \ 1780 1933 -font "Arial 9" 1781 checkbutton $inner. gridz\1782 -text " Show Z Grid" \1934 checkbutton $inner.zgrid \ 1935 -text "Z" \ 1783 1936 -variable [itcl::scope _settings(-zgrid)] \ 1784 1937 -command [itcl::code $this AdjustSetting -zgrid] \ 1785 1938 -font "Arial 9" 1786 1787 label $inner.mode_l -text "Mode" -font "Arial 9" 1939 checkbutton $inner.minorticks \ 1940 -text "Minor Ticks" \ 1941 -variable [itcl::scope _settings(-axisminorticks)] \ 1942 -command [itcl::code $this AdjustSetting -axisminorticks] \ 1943 -font "Arial 9" 1944 1945 label $inner.mode_l -text "Mode" -font "Arial 9" 1788 1946 1789 1947 itk_component add axisMode { … … 1794 1952 "closest_triad" "closest" \ 1795 1953 "furthest_triad" "farthest" \ 1796 "outer_edges" "outer" 1954 "outer_edges" "outer" 1797 1955 $itk_component(axisMode) value $_settings(-axismode) 1798 1956 bind $inner.mode <<Value>> [itcl::code $this AdjustSetting -axismode] 1799 1957 1800 1958 blt::table $inner \ 1801 0,0 $inner.visible -anchor w -cspan 2 \ 1802 1,0 $inner.labels -anchor w -cspan 2 \ 1803 2,0 $inner.gridx -anchor w -cspan 2 \ 1804 3,0 $inner.gridy -anchor w -cspan 2 \ 1805 4,0 $inner.gridz -anchor w -cspan 2 \ 1806 5,0 $inner.mode_l -anchor w -cspan 2 -padx { 2 0 } \ 1807 6,0 $inner.mode -fill x -cspan 2 1959 0,0 $inner.visible -anchor w -cspan 4 \ 1960 1,0 $inner.labels -anchor w -cspan 4 \ 1961 2,0 $inner.minorticks -anchor w -cspan 4 \ 1962 4,0 $inner.grid_l -anchor w \ 1963 4,1 $inner.xgrid -anchor w \ 1964 4,2 $inner.ygrid -anchor w \ 1965 4,3 $inner.zgrid -anchor w \ 1966 5,0 $inner.mode_l -anchor w -padx { 2 0 } \ 1967 5,1 $inner.mode -fill x -cspan 3 1808 1968 1809 1969 blt::table configure $inner r* c* -resize none 1810 blt::table configure $inner r7 c1 -resize expand 1970 blt::table configure $inner r7 c6 -resize expand 1971 blt::table configure $inner r3 -height 0.125i 1811 1972 } 1812 1973 … … 1830 1991 0,0 $inner.view_l -anchor e -pady 2 \ 1831 1992 0,1 $inner.view -anchor w -pady 2 1993 blt::table configure $inner r0 -resize none 1832 1994 1833 1995 set labels { qx qy qz qw xpan ypan zoom } … … 1837 1999 entry $inner.${tag} -font "Arial 9" -bg white \ 1838 2000 -textvariable [itcl::scope _view(-$tag)] 1839 bind $inner.${tag} <KeyPress-Return> \ 1840 [itcl::code $this camera set ${tag}] 2001 bind $inner.${tag} <Return> \ 2002 [itcl::code $this camera set -${tag}] 2003 bind $inner.${tag} <KP_Enter> \ 2004 [itcl::code $this camera set -${tag}] 1841 2005 blt::table $inner \ 1842 2006 $row,0 $inner.${tag}label -anchor e -pady 2 \ … … 1855 2019 incr row 1856 2020 1857 blt::table configure $inner c* r*-resize none2021 blt::table configure $inner c* -resize none 1858 2022 blt::table configure $inner c2 -resize expand 1859 2023 blt::table configure $inner r$row -resize expand … … 1863 2027 1864 2028 set fg [option get $itk_component(hull) font Font] 1865 2029 1866 2030 set inner [$itk_component(main) insert end \ 1867 2031 -title "Cutplane Settings" \ 1868 -icon [Rappture::icon cutbutton]] 2032 -icon [Rappture::icon cutbutton]] 1869 2033 1870 2034 $inner configure -borderwidth 4 … … 1906 2070 -showvalue off \ 1907 2071 -command [itcl::code $this AdjustSetting -cutplaneopacity] 1908 set _widget(-cutplaneopacity)[expr $_settings(-cutplaneopacity) * 100.0]2072 $inner.opacity set [expr $_settings(-cutplaneopacity) * 100.0] 1909 2073 1910 2074 # X-value slicer... … … 1925 2089 -command [itcl::code $this EventuallySetCutplane x] \ 1926 2090 -variable [itcl::scope _settings(-xcutplaneposition)] \ 1927 2091 -foreground red2 -font "Arial 9 bold" 1928 2092 } { 1929 2093 usual … … 1954 2118 -command [itcl::code $this EventuallySetCutplane y] \ 1955 2119 -variable [itcl::scope _settings(-ycutplaneposition)] \ 1956 2120 -foreground green3 -font "Arial 9 bold" 1957 2121 } { 1958 2122 usual … … 1973 2137 -variable [itcl::scope _settings(-zcutplanevisible)] \ 1974 2138 } { 1975 1976 2139 usual 2140 ignore -foreground 1977 2141 } 1978 2142 Rappture::Tooltip::for $itk_component(zbutton) \ … … 1986 2150 -command [itcl::code $this EventuallySetCutplane z] \ 1987 2151 -variable [itcl::scope _settings(-zcutplaneposition)] \ 1988 2152 -foreground blue3 -font "Arial 9 bold" 1989 2153 } { 1990 2154 usual … … 2004 2168 5,0 $inner.opacity_l -anchor w -pady 2 -cspan 1 \ 2005 2169 5,1 $inner.opacity -fill x -pady 2 -cspan 3 \ 2006 6,0 $inner.xbutton 2007 7,0 $inner.ybutton 2008 8,0 $inner.zbutton 2009 6,1 $inner.xval 2010 6,2 $inner.yval 2011 6,3 $inner.zval 2170 6,0 $inner.xbutton -anchor w -padx 2 -pady 2 \ 2171 7,0 $inner.ybutton -anchor w -padx 2 -pady 2 \ 2172 8,0 $inner.zbutton -anchor w -padx 2 -pady 2 \ 2173 6,1 $inner.xval -fill y -rspan 4 \ 2174 6,2 $inner.yval -fill y -rspan 4 \ 2175 6,3 $inner.zval -fill y -rspan 4 \ 2012 2176 2013 2177 … … 2016 2180 } 2017 2181 2018 2019 2020 # 2021 # camera -- 2182 # 2183 # camera -- 2022 2184 # 2023 2185 itcl::body Rappture::VtkIsosurfaceViewer::camera {option args} { 2024 switch -- $option { 2186 switch -- $option { 2025 2187 "show" { 2026 2188 puts [array get _view] … … 2050 2212 } 2051 2213 "-zoom" { 2052 SendCmd "camera zoom $_view( -zoom)"2214 SendCmd "camera zoom $_view($what)" 2053 2215 } 2054 2216 } … … 2070 2232 2071 2233 itcl::body Rappture::VtkIsosurfaceViewer::GetImage { args } { 2072 if { [image width $_image(download)] > 0 && 2234 if { [image width $_image(download)] > 0 && 2073 2235 [image height $_image(download)] > 0 } { 2074 2236 set bytes [$_image(download) data -format "jpeg -quality 100"] … … 2083 2245 -title "[Rappture::filexfer::label downloadWord] as..." 2084 2246 set inner [$popup component inner] 2085 label $inner.summary -text "" -anchor w 2247 label $inner.summary -text "" -anchor w 2086 2248 radiobutton $inner.vtk_button -text "VTK data file" \ 2087 2249 -variable [itcl::scope _downloadPopup(format)] \ 2088 2250 -font "Arial 9 " \ 2089 -value vtk 2251 -value vtk 2090 2252 Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file." 2091 2253 radiobutton $inner.image_button -text "Image File" \ 2092 2254 -variable [itcl::scope _downloadPopup(format)] \ 2093 2255 -font "Arial 9 " \ 2094 -value image 2256 -value image 2095 2257 Rappture::Tooltip::for $inner.image_button \ 2096 2258 "Save as digital image." … … 2113 2275 2,0 $inner.image_button -anchor w -cspan 2 -padx { 4 0 } \ 2114 2276 4,1 $inner.cancel -width .9i -fill y \ 2115 4,0 $inner.ok -padx 2 -width .9i -fill y 2277 4,0 $inner.ok -padx 2 -width .9i -fill y 2116 2278 blt::table configure $inner r3 -height 4 2117 2279 blt::table configure $inner r4 -pady 4 … … 2126 2288 array set style { 2127 2289 -color BCGYR 2128 -cutplanesvisible 0 2290 -cutplaneedges 0 2291 -cutplanelighting 1 2292 -cutplaneopacity 1.0 2293 -cutplanepreinterp 1 2294 -cutplanesvisible 0 2295 -cutplanewireframe 0 2129 2296 -edgecolor black 2130 2297 -edges 0 2131 -isosurfaceopacity 0.62132 2298 -isosurfacevisible 1 2133 2299 -levels 10 2134 2300 -lighting 1 2135 2301 -linewidth 1.0 2302 -opacity 0.6 2136 2303 -outline 0 2137 2304 -wireframe 0 … … 2145 2312 array set style [$dataobj style $comp] 2146 2313 if { $dataobj != $_first || $style(-levels) == 1 } { 2147 set style(- isosurfaceopacity) 1.02314 set style(-opacity) 1.0 2148 2315 } 2149 2316 … … 2157 2324 # the code to handle aberrant cases. 2158 2325 2326 if { $_changed(-isosurfaceedges) } { 2327 set style(-edges) $_settings(-isosurfaceedges) 2328 } 2329 if { $_changed(-isosurfacelighting) } { 2330 set style(-lighting) $_settings(-isosurfacelighting) 2331 } 2159 2332 if { $_changed(-isosurfaceopacity) } { 2160 set style(-isosurfaceopacity) $_settings(-isosurfaceopacity) 2333 set style(-opacity) $_settings(-isosurfaceopacity) 2334 } 2335 if { $_changed(-isosurfacewireframe) } { 2336 set style(-wireframe) $_settings(-isosurfacewireframe) 2161 2337 } 2162 2338 if { $_changed(-numcontours) } { … … 2178 2354 set _contourList(numLevels) $style(-levels) 2179 2355 } 2180 EventuallyChangeContourLevels 2181 } 2182 set _settings(-isosurfacevisible) $style(-isosurfacevisible) 2183 set _settings(-cutplanesvisible) $style(-cutplanesvisible) 2184 set _settings(-xcutplanevisible) $style(-xcutplanevisible) 2185 set _settings(-ycutplanevisible) $style(-ycutplanevisible) 2186 set _settings(-zcutplanevisible) $style(-zcutplanevisible) 2187 set _settings(-xcutplaneposition) $style(-xcutplaneposition) 2188 set _settings(-ycutplaneposition) $style(-ycutplaneposition) 2189 set _settings(-zcutplaneposition) $style(-zcutplaneposition) 2190 2356 EventuallyChangeContourLevels 2357 } 2358 foreach setting {-outline -isosurfacevisible -cutplanesvisible \ 2359 -xcutplanevisible -ycutplanevisible -zcutplanevisible \ 2360 -xcutplaneposition -ycutplaneposition -zcutplaneposition \ 2361 -cutplaneedges -cutplanelighting -cutplaneopacity \ 2362 -cutplanepreinterp -cutplanewireframe} { 2363 if {$_changed($setting)} { 2364 # User-modified UI setting overrides style 2365 set style($setting) $_settings($setting) 2366 } else { 2367 # Set UI control to style setting (tool provided or default) 2368 set _settings($setting) $style($setting) 2369 } 2370 } 2371 2191 2372 SendCmd "cutplane add $tag" 2373 SendCmd "cutplane color [Color2RGB $itk_option(-plotforeground)] $tag" 2374 foreach axis {x y z} { 2375 set pos [expr $style(-${axis}cutplaneposition) * 0.01] 2376 set visible $style(-${axis}cutplanevisible) 2377 SendCmd "cutplane slice $axis $pos $tag" 2378 SendCmd "cutplane axis $axis $visible $tag" 2379 } 2380 SendCmd "cutplane edges $style(-cutplaneedges) $tag" 2381 SendCmd "cutplane lighting $style(-cutplanelighting) $tag" 2382 SendCmd "cutplane opacity $style(-cutplaneopacity) $tag" 2383 SendCmd "cutplane preinterp $style(-cutplanepreinterp) $tag" 2384 SendCmd "cutplane wireframe $style(-cutplanewireframe) $tag" 2192 2385 SendCmd "cutplane visible $style(-cutplanesvisible) $tag" 2193 2386 … … 2195 2388 SendCmd "outline color [Color2RGB $itk_option(-plotforeground)] $tag" 2196 2389 SendCmd "outline visible $style(-outline) $tag" 2197 set _settings(-outline) $style(-outline) 2198 2390 2199 2391 GenerateContourList 2200 2392 SendCmd [list contour3d add contourlist $_contourList(values) $tag] … … 2202 2394 SendCmd "contour3d edges $style(-edges) $tag" 2203 2395 set _settings(-isosurfaceedges) $style(-edges) 2204 #SendCmd "contour3d color [Color2RGB $s ettings(-color)] $tag"2396 #SendCmd "contour3d color [Color2RGB $style(-color)] $tag" 2205 2397 SendCmd "contour3d lighting $style(-lighting) $tag" 2206 2398 set _settings(-isosurfacelighting) $style(-lighting) 2207 2399 SendCmd "contour3d linecolor [Color2RGB $style(-edgecolor)] $tag" 2208 2400 SendCmd "contour3d linewidth $style(-linewidth) $tag" 2209 SendCmd "contour3d opacity $style(- isosurfaceopacity) $tag"2210 set _settings(-isosurfaceopacity) $style(- isosurfaceopacity)2211 SetCurrentColormap $style(-color) 2401 SendCmd "contour3d opacity $style(-opacity) $tag" 2402 set _settings(-isosurfaceopacity) $style(-opacity) 2403 SetCurrentColormap $style(-color) 2212 2404 SendCmd "contour3d wireframe $style(-wireframe) $tag" 2213 2405 set _settings(-isosurfacewireframe) $style(-wireframe) … … 2249 2441 } 2250 2442 2443 # ---------------------------------------------------------------------- 2444 # USAGE: LegendB1Motion press <x> <y> 2445 # USAGE: LegendB1Motion motion <x> <y> 2446 # USAGE: LegendB1Motion release <x> <y> 2447 # 2448 # Manage actions for Button 1 presses that happen over the legend. 2449 # Pressing mouse Button 1 on the legend sends a command to the 2450 # visualization server to show a specific isosurface. 2451 # ---------------------------------------------------------------------- 2452 itcl::body Rappture::VtkIsosurfaceViewer::LegendB1Motion { status x y } { 2453 2454 switch -- $status { 2455 "press" { 2456 DisableMouseRotationBindings 2457 LegendProbeSingleContour $x $y 2458 } 2459 "motion" { 2460 DisableMouseRotationBindings 2461 LegendProbeSingleContour $x $y 2462 } 2463 "release" { 2464 AdjustSetting -range 2465 SetupMouseRotationBindings 2466 } 2467 default { 2468 error "bad option \"$option\": should be one of press, motion, release." 2469 } 2470 } 2471 } 2472 2473 # ---------------------------------------------------------------------- 2474 # USAGE: LegendPointToValue <x> <y> 2475 # 2476 # Convert an x,y point on the legend to a numeric isosurface value. 2477 # ---------------------------------------------------------------------- 2478 itcl::body Rappture::VtkIsosurfaceViewer::LegendPointToValue { x y } { 2479 2480 set fname $_curFldName 2481 2482 set font "Arial 8" 2483 set lineht [font metrics $font -linespace] 2484 2485 set ih [image height $_image(legend)] 2486 set iy [expr $y - ($lineht + 2)] 2487 2488 # Compute the value of the point 2489 if { [info exists _limits($fname)] } { 2490 if { $_settings(-customrange) } { 2491 set vmin [$itk_component(min) value] 2492 set vmax [$itk_component(max) value] 2493 } else { 2494 foreach { vmin vmax } $_limits($fname) break 2495 } 2496 set t [expr 1.0 - (double($iy) / double($ih-1))] 2497 set value [expr $t * ($vmax - $vmin) + $vmin] 2498 } else { 2499 set value 0.0 2500 } 2501 return $value 2502 } 2503 2504 # ---------------------------------------------------------------------- 2505 # USAGE: LegendProbeSingleContour <x> <y> 2506 # 2507 # Calculate the isosurface value for the x,y point and send a commands 2508 # to the visualization server to show that isosurface. 2509 # ---------------------------------------------------------------------- 2510 itcl::body Rappture::VtkIsosurfaceViewer::LegendProbeSingleContour { x y } { 2511 2512 set value [LegendPointToValue $x $y] 2513 SendCmd [list contour3d contourlist $value] 2514 } 2515 2251 2516 # 2252 2517 # SetLegendTip -- … … 2260 2525 set font "Arial 8" 2261 2526 set lineht [font metrics $font -linespace] 2262 2527 2263 2528 set ih [image height $_image(legend)] 2264 2529 set iy [expr $y - ($lineht + 2)] 2265 2530 2266 2531 if { [string match "component*" $fname] } { 2267 2532 set title "" 2268 2533 } else { 2269 2270 2271 2272 2273 2274 2275 2276 2534 if { [info exists _fields($fname)] } { 2535 foreach { title units } $_fields($fname) break 2536 if { $units != "" } { 2537 set title [format "%s (%s)" $title $units] 2538 } 2539 } else { 2540 set title $fname 2541 } 2277 2542 } 2278 2543 # If there's a legend title, increase the offset by the line height. … … 2288 2553 } 2289 2554 set color [eval format "\#%02x%02x%02x" $pixel] 2290 $_image(swatch) put black -to 0 0 23 23 2291 $_image(swatch) put $color -to 1 1 22 22 2555 $_image(swatch) put black -to 0 0 23 23 2556 $_image(swatch) put $color -to 1 1 22 22 2292 2557 .rappturetooltip configure -icon $_image(swatch) 2293 2558 2294 2559 # Compute the value of the point 2295 if { [info exists _limits($_curFldName)] } { 2296 foreach { vmin vmax } $_limits($_curFldName) break 2297 set t [expr 1.0 - (double($iy) / double($ih-1))] 2298 set value [expr $t * ($vmax - $vmin) + $vmin] 2299 } else { 2300 set value 0.0 2301 } 2302 set tx [expr $x + 15] 2560 set value [LegendPointToValue $x $y] 2561 2562 # Setup the location of the tooltip 2563 set tx [expr $x + 15] 2303 2564 set ty [expr $y - 5] 2565 2566 # Setup the text for the tooltip 2304 2567 if { [info exists _isolines($y)] } { 2305 2568 Rappture::Tooltip::text $c [format "$title %g (isosurface)" $_isolines($y)] … … 2307 2570 Rappture::Tooltip::text $c [format "$title %g" $value] 2308 2571 } 2309 Rappture::Tooltip::tooltip show $c +$tx,+$ty 2310 } 2311 2572 2573 # Show the tooltip 2574 Rappture::Tooltip::tooltip show $c +$tx,+$ty 2575 } 2312 2576 2313 2577 # ---------------------------------------------------------------------- … … 2342 2606 2343 2607 # 2344 # ReceiveLegend -- 2345 # 2346 # 2347 # 2348 # 2608 # ReceiveLegend -- 2609 # 2610 # Invoked automatically whenever the "legend" command comes in from 2611 # the rendering server. Indicates that binary image data with the 2612 # specified <size> will follow. 2349 2613 # 2350 2614 itcl::body Rappture::VtkIsosurfaceViewer::ReceiveLegend { colormap title min max size } { 2351 # puts stderr "ReceiveLegend colormap=$colormap title=$title range=$min,$max size=$size"2615 # puts stderr "ReceiveLegend colormap=$colormap title=$title range=$min,$max size=$size" 2352 2616 set _title $title 2353 regsub {\(mag\)} $title "" _title 2617 regsub {\(mag\)} $title "" _title 2354 2618 if { [IsConnected] } { 2355 2619 set bytes [ReceiveBytes $size] … … 2360 2624 #puts stderr "read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>" 2361 2625 if { [catch {DrawLegend} errs] != 0 } { 2362 2363 2626 global errorInfo 2627 puts stderr "errs=$errs errorInfo=$errorInfo" 2364 2628 } 2365 2629 } … … 2369 2633 # DrawLegend -- 2370 2634 # 2371 # Draws the legend in the owncanvas on the right side of the plot area.2635 # Draws the legend on the canvas on the right side of the plot area. 2372 2636 # 2373 2637 itcl::body Rappture::VtkIsosurfaceViewer::DrawLegend {} { … … 2378 2642 set font "Arial 8" 2379 2643 set lineht [font metrics $font -linespace] 2380 2644 2381 2645 if { [string match "component*" $fname] } { 2382 2646 set title "" 2383 2647 } else { 2384 2385 2386 2387 2388 2389 2390 2391 2648 if { [info exists _fields($fname)] } { 2649 foreach { title units } $_fields($fname) break 2650 if { $units != "" } { 2651 set title [format "%s (%s)" $title $units] 2652 } 2653 } else { 2654 set title $fname 2655 } 2392 2656 } 2393 2657 set x [expr $w - 2] 2394 2658 if { !$_settings(-legendvisible) } { 2395 2396 2397 } 2659 $c delete legend 2660 return 2661 } 2398 2662 if { [$c find withtag "legend"] == "" } { 2399 set y 2 2400 2663 set y 2 2664 # If there's a legend title, create a text item for the title. 2401 2665 $c create text $x $y \ 2402 2403 2404 -font $font 2666 -anchor ne \ 2667 -fill $itk_option(-plotforeground) -tags "title legend" \ 2668 -font $font 2405 2669 if { $title != "" } { 2406 2670 incr y $lineht 2407 2671 } 2408 $c create text $x $y \ 2409 -anchor ne \ 2410 -fill $itk_option(-plotforeground) -tags "vmax legend" \ 2411 -font $font 2412 incr y $lineht 2413 $c create image $x $y \ 2414 -anchor ne \ 2415 -image $_image(legend) -tags "colormap legend" 2416 $c create rectangle $x $y 1 1 \ 2417 -fill "" -outline "" -tags "sensor legend" 2418 $c create text $x [expr {$h-2}] \ 2419 -anchor se \ 2420 -fill $itk_option(-plotforeground) -tags "vmin legend" \ 2421 -font $font 2422 $c bind sensor <Enter> [itcl::code $this EnterLegend %x %y] 2423 $c bind sensor <Leave> [itcl::code $this LeaveLegend] 2424 $c bind sensor <Motion> [itcl::code $this MotionLegend %x %y] 2672 $c create text $x $y \ 2673 -anchor ne \ 2674 -fill $itk_option(-plotforeground) -tags "vmax legend" \ 2675 -font $font 2676 incr y $lineht 2677 $c create image $x $y \ 2678 -anchor ne \ 2679 -image $_image(legend) -tags "colormap legend" 2680 $c create rectangle $x $y 1 1 \ 2681 -fill "" -outline "" -tags "sensor legend" 2682 $c create text $x [expr {$h-2}] \ 2683 -anchor se \ 2684 -fill $itk_option(-plotforeground) -tags "vmin legend" \ 2685 -font $font 2686 $c bind sensor <Enter> [itcl::code $this EnterLegend %x %y] 2687 $c bind sensor <Leave> [itcl::code $this LeaveLegend] 2688 $c bind sensor <Motion> [itcl::code $this MotionLegend %x %y] 2689 # $c bind sensor <ButtonPress-1> [itcl::code $this LegendB1Motion press %x %y] 2690 # $c bind sensor <B1-Motion> [itcl::code $this LegendB1Motion motion %x %y] 2691 # $c bind sensor <ButtonRelease-1> [itcl::code $this LegendB1Motion release %x %y] 2692 2425 2693 } 2426 2694 $c delete isoline … … 2435 2703 $_settings(-numcontours) > 0 } { 2436 2704 2437 foreach { vmin vmax } $_limits($_curFldName) break 2705 if { $_settings(-customrange) } { 2706 set vmin [$itk_component(min) value] 2707 set vmax [$itk_component(max) value] 2708 } else { 2709 foreach { vmin vmax } $_limits($_curFldName) break 2710 } 2438 2711 set range [expr double($vmax - $vmin)] 2439 2712 if { $range <= 0.0 } { … … 2441 2714 } 2442 2715 set tags "isoline legend" 2443 2444 2445 2446 2716 set offset [expr 2 + $lineht] 2717 if { $title != "" } { 2718 incr offset $lineht 2719 } 2447 2720 foreach value $_contourList(values) { 2448 2721 set norm [expr 1.0 - (($value - $vmin) / $range)] … … 2456 2729 } 2457 2730 2458 $c bind title <ButtonPress> [itcl::code $this Combopost]2459 $c bind title <Enter> [itcl::code $this Combo activate]2460 $c bind title <Leave> [itcl::code $this Combo deactivate]2731 $c bind title <ButtonPress> [itcl::code $this LegendTitleAction post] 2732 $c bind title <Enter> [itcl::code $this LegendTitleAction enter] 2733 $c bind title <Leave> [itcl::code $this LegendTitleAction leave] 2461 2734 # Reset the item coordinates according the current size of the plot. 2462 2735 $c itemconfigure title -text $title 2463 2736 if { [info exists _limits($_curFldName)] } { 2464 foreach { vmin vmax } $_limits($_curFldName) break 2465 $c itemconfigure vmin -text [format %g $vmin] 2466 $c itemconfigure vmax -text [format %g $vmax] 2737 if { $_settings(-customrange) } { 2738 set vmin [$itk_component(min) value] 2739 set vmax [$itk_component(max) value] 2740 } else { 2741 foreach { vmin vmax } $_limits($_curFldName) break 2742 } 2743 $c itemconfigure vmin -text [format %g $vmin] 2744 $c itemconfigure vmax -text [format %g $vmax] 2467 2745 } 2468 2746 set y 2 … … 2470 2748 if { $title != "" } { 2471 2749 $c itemconfigure title -text $title 2472 2473 2750 $c coords title $x $y 2751 incr y $lineht 2474 2752 $c raise title 2475 2753 } … … 2480 2758 $c raise sensor 2481 2759 $c coords vmin $x [expr {$h - 2}] 2482 } 2483 2484 # ---------------------------------------------------------------------- 2485 # USAGE: _dropdown post 2486 # USAGE: _dropdown unpost 2487 # USAGE: _dropdown select 2488 # 2489 # Used internally to handle the dropdown list for this combobox. The 2490 # post/unpost options are invoked when the list is posted or unposted 2491 # to manage the relief of the controlling button. The select option 2492 # is invoked whenever there is a selection from the list, to assign 2493 # the value back to the gauge. 2494 # ---------------------------------------------------------------------- 2495 itcl::body Rappture::VtkIsosurfaceViewer::Combo {option} { 2496 set c $itk_component(view) 2760 2761 $c bind vmin <ButtonPress> [itcl::code $this LegendRangeAction popup vmin] 2762 $c bind vmin <Enter> [itcl::code $this LegendRangeAction enter vmin] 2763 $c bind vmin <Leave> [itcl::code $this LegendRangeAction leave vmin] 2764 2765 $c bind vmax <ButtonPress> [itcl::code $this LegendRangeAction popup vmax] 2766 $c bind vmax <Enter> [itcl::code $this LegendRangeAction enter vmax] 2767 $c bind vmax <Leave> [itcl::code $this LegendRangeAction leave vmax] 2768 } 2769 2770 # ---------------------------------------------------------------------- 2771 # USAGE: LegendTitleAction post 2772 # USAGE: LegendTitleAction enter 2773 # USAGE: LegendTitleAction leave 2774 # USAGE: LegendTitleAction save 2775 # 2776 # Used internally to handle the dropdown list for the fields menu combobox. 2777 # The post option is invoked when the field title is pressed to launch the 2778 # dropdown. The enter option is invoked when the user mouses over the field 2779 # title. The leave option is invoked when the user moves the mouse away 2780 # from the field title. The save option is invoked whenever there is a 2781 # selection from the list, to alert the visualization server. 2782 # 2783 # ---------------------------------------------------------------------- 2784 itcl::body Rappture::VtkIsosurfaceViewer::LegendTitleAction {option} { 2785 set c $itk_component(view) 2497 2786 switch -- $option { 2498 2787 post { … … 2505 2794 tk_popup $itk_component(fieldmenu) $x $y 2506 2795 } 2507 activate{2796 enter { 2508 2797 $c itemconfigure title -fill red 2509 2798 } 2510 deactivate {2511 $c itemconfigure title -fill $itk_option(-plotforeground) 2512 } 2513 invoke {2799 leave { 2800 $c itemconfigure title -fill $itk_option(-plotforeground) 2801 } 2802 save { 2514 2803 $itk_component(field) value $_curFldLabel 2515 2804 AdjustSetting -field 2516 2805 } 2517 2806 default { 2518 error "bad option \"$option\": should be post, unpost, select" 2519 } 2807 error "bad option \"$option\": should be post, enter, leave, save" 2808 } 2809 } 2810 } 2811 2812 # ---------------------------------------------------------------------- 2813 # USAGE: LegendRangeValidate <widget> <which> <value> 2814 # 2815 # Used internally to validate a legend range min/max value. 2816 # Returns a boolean value telling if <value> was accepted (1) or rejected (0) 2817 # If the value is rejected, a tooltip/warning message is popped up 2818 # near the widget that asked for the validation, specified by <widget> 2819 # 2820 # <widget> is the widget where a tooltip/warning message should show up on 2821 # <which> is either "vmin" or "vmax". 2822 # <value> is the value to be validated. 2823 # 2824 # ---------------------------------------------------------------------- 2825 itcl::body Rappture::VtkIsosurfaceViewer::LegendRangeValidate {widget which value} { 2826 2827 #check for a valid value 2828 if {[string is double $value] != 1} { 2829 set msg "should be valid number" 2830 if {$widget != ""} { 2831 Rappture::Tooltip::cue $widget $msg 2832 } else { 2833 # error "bad value \"$value\": $msg" 2834 error $msg 2835 } 2836 return 0 2837 } 2838 2839 switch -- $which { 2840 vmin { 2841 # check for min > max 2842 if {$value > [$itk_component(max) value]} { 2843 set msg "min > max, change max first" 2844 if {$widget != ""} { 2845 Rappture::Tooltip::cue $widget $msg 2846 } else { 2847 # error "bad value \"$value\": $msg" 2848 error $msg 2849 } 2850 return 0 2851 } 2852 } 2853 vmax { 2854 # check for max < min 2855 if {$value < [$itk_component(min) value]} { 2856 set msg "max < min, change min first" 2857 if {$widget != ""} { 2858 Rappture::Tooltip::cue $widget $msg 2859 } else { 2860 # error "bad value \"$value\": $msg" 2861 error $msg 2862 } 2863 return 0 2864 } 2865 } 2866 default { 2867 error "bad option \"$which\": should be vmin, vmax" 2868 } 2869 } 2870 } 2871 2872 itcl::body Rappture::VtkIsosurfaceViewer::MouseOver2Which {} { 2873 switch -- $_mouseOver { 2874 vmin { 2875 set which min 2876 } 2877 vmax { 2878 set which max 2879 } 2880 default { 2881 error "bad _mouseOver \"$_mouseOver\": should be vmin, vmax" 2882 } 2883 } 2884 return $which 2885 } 2886 2887 # ---------------------------------------------------------------------- 2888 # USAGE: LegendRangeAction enter <which> 2889 # USAGE: LegendRangeAction leave <which> 2890 # 2891 # USAGE: LegendRangeAction popup <which> 2892 # USAGE: LegendRangeAction activate 2893 # USAGE: LegendRangeAction validate <value> 2894 # USAGE: LegendRangeAction apply <value> 2895 # 2896 # Used internally to handle the mouseover and popup entry for the field range 2897 # inputs. The enter option is invoked when the user moves the mouse over the 2898 # min or max field range. The leave option is invoked when the user moves the 2899 # mouse away from the min or max field range. The popup option is invoked when 2900 # the user click's on a field range. The popup option stores internally which 2901 # widget is requesting a popup ( in the _mouseOver variable) and calls the 2902 # activate command of the widget. The widget's activate command calls back to 2903 # this method to get the xywh dimensions of the popup editor. After the user 2904 # changes focus or sets the value in the editor, the editor calls this methods 2905 # validate and apply options to set the value. 2906 # 2907 # ---------------------------------------------------------------------- 2908 itcl::body Rappture::VtkIsosurfaceViewer::LegendRangeAction {option args} { 2909 set c $itk_component(view) 2910 2911 switch -- $option { 2912 enter { 2913 set which [lindex $args 0] 2914 $c itemconfigure $which -fill red 2915 } 2916 leave { 2917 set which [lindex $args 0] 2918 $c itemconfigure $which -fill $itk_option(-plotforeground) 2919 } 2920 popup { 2921 DisableMouseRotationBindings 2922 set which [lindex $args 0] 2923 set _mouseOver $which 2924 $itk_component(editor) activate 2925 } 2926 activate { 2927 foreach { x1 y1 x2 y2 } [$c bbox $_mouseOver] break 2928 set which [MouseOver2Which] 2929 set info(text) [$itk_component($which) value] 2930 set info(x) [expr $x1 + [winfo rootx $c]] 2931 set info(y) [expr $y1 + [winfo rooty $c]] 2932 set info(w) [expr $x2 - $x1] 2933 set info(h) [expr $y2 - $y1] 2934 return [array get info] 2935 } 2936 validate { 2937 if {[llength $args] != 1} { 2938 error "wrong # args: should be \"editor validate value\"" 2939 } 2940 2941 set value [lindex $args 0] 2942 if {[LegendRangeValidate $itk_component(editor) $_mouseOver $value] == 0} { 2943 return 0 2944 } 2945 2946 # value was good, apply it 2947 # reset the mouse rotation bindings 2948 SetupMouseRotationBindings 2949 } 2950 apply { 2951 if {[llength $args] != 1} { 2952 error "wrong # args: should be \"editor apply value\"" 2953 } 2954 set value [string trim [lindex $args 0]] 2955 2956 set which [MouseOver2Which] 2957 2958 # only set custom range if value changed 2959 if {[$itk_component($which) value] != $value} { 2960 # set the flag stating the custom range came from the legend 2961 # change the value in the gauge 2962 # turn on crange to enable the labels and gauges 2963 # call AdjustSetting -range (inside ToggleCustomRange) 2964 # to update drawing and legend 2965 set _customRangeClick 0 2966 $itk_component($which) value $value 2967 $itk_component(crange) select 2968 ToggleCustomRange 2969 } 2970 } 2971 default { 2972 error "bad option \"$option\": should be enter, leave, activate, validate, apply" 2973 } 2974 } 2975 } 2976 2977 # ---------------------------------------------------------------------- 2978 # USAGE: ToggleCustomRange 2979 # 2980 # Called whenever the custom range is turned on or off. Used to save 2981 # the custom min and custom max set by the user. When the -customrange 2982 # setting is turned on, the range min and range max gauges are set 2983 # with the last value set by the user, or the default range if no 2984 # previous min and max were set. 2985 # 2986 # When the custom range is turned on, we check how it was turned on 2987 # by querying _customRangeClick. If the variable is 1, this means 2988 # the user clicked the crange checkbutton and we should pull the 2989 # custom range values from our backup variables. If the variable is 0, 2990 # the custom range was enabled through the user manipulating the 2991 # min and max value in the legend. 2992 # 2993 # ---------------------------------------------------------------------- 2994 itcl::body Rappture::VtkIsosurfaceViewer::ToggleCustomRange {args} { 2995 if { ! $_settings(-customrange) } { 2996 # custom range was turned off 2997 2998 # disable the min/max labels and gauge widgets 2999 $itk_component(l_min) configure -state disabled 3000 $itk_component(min) configure -state disabled 3001 $itk_component(l_max) configure -state disabled 3002 $itk_component(max) configure -state disabled 3003 3004 # backup the custom range 3005 set _settings(-customrangemin) [$itk_component(min) value] 3006 set _settings(-customrangemax) [$itk_component(max) value] 3007 3008 # set the gauges to dataset's min and max 3009 foreach { vmin vmax } $_limits($_curFldName) break 3010 SetMinMaxGauges $vmin $vmax 3011 } else { 3012 # custom range was turned on 3013 3014 # enable the min/max labels and gauge widgets 3015 $itk_component(l_min) configure -state normal 3016 $itk_component(min) configure -state normal 3017 $itk_component(l_max) configure -state normal 3018 $itk_component(max) configure -state normal 3019 3020 # if the custom range is being turned on by clicking the 3021 # checkbox, restore the min and max gauges from the backup 3022 # variables. otherwise, new values for the min and max 3023 # widgets will be set later from the legend's editor. 3024 if { $_customRangeClick } { 3025 SetMinMaxGauges $_settings(-customrangemin) $_settings(-customrangemax) 3026 } 3027 3028 # reset the click flag 3029 set _customRangeClick 1 3030 } 3031 AdjustSetting -range 3032 } 3033 3034 # ---------------------------------------------------------------------- 3035 # USAGE: SetMinMaxGauges <min> <max> 3036 # 3037 # Set the min and max gauges in the correct order, avoiding the 3038 # error where you try to set the min > max before updating the max or 3039 # set the max < min before updating the min. 3040 # 3041 # There are five range cases to consider with our current range validation. 3042 # For example: 3043 # [2,3] -> [0,1] : update min first, max last 3044 # [2,3] -> [4,5] : update max first, min last 3045 # [2,3] -> [0,2.5] : update min or max first 3046 # [2,3] -> [2.5,5] : update min or max first 3047 # [2,3] -> [2.25,2.75] : update min or max first 3048 # 3049 # In 4 of the cases we can update min first and max last, so we only 3050 # need to check the case where old max < new min, where we update 3051 # max first and min last. 3052 # ---------------------------------------------------------------------- 3053 itcl::body Rappture::VtkIsosurfaceViewer::SetMinMaxGauges {min max} { 3054 3055 if { [$itk_component(max) value] < $min} { 3056 # old max < new min 3057 # shift range toward right 3058 # extend max first, then update min 3059 $itk_component(max) value $max 3060 $itk_component(min) value $min 3061 } else { 3062 # extend min first, then update max 3063 $itk_component(min) value $min 3064 $itk_component(max) value $max 2520 3065 } 2521 3066 } … … 2527 3072 # Keep track of the colormaps that we build. 2528 3073 if { ![info exists _colormaps($name)] } { 2529 BuildColormap $name 3074 BuildColormap $name 2530 3075 set _colormaps($name) 1 2531 3076 } … … 2549 3094 } 2550 3095 2551 itcl::body Rappture::VtkIsosurfaceViewer::SetOrientation { side } { 3096 itcl::body Rappture::VtkIsosurfaceViewer::SetOrientation { side } { 2552 3097 array set positions { 2553 3098 front "1 0 0 0" … … 2560 3105 foreach name { -qw -qx -qy -qz } value $positions($side) { 2561 3106 set _view($name) $value 2562 } 3107 } 2563 3108 set q [ViewToQuaternion] 2564 3109 $_arcball quaternion $q … … 2570 3115 } 2571 3116 2572 itcl::body Rappture::VtkIsosurfaceViewer::GenerateContourList {} { 3117 itcl::body Rappture::VtkIsosurfaceViewer::GenerateContourList {} { 2573 3118 if { ![info exists _limits($_curFldName)] } { 2574 3119 puts stderr "no _curFldName" … … 2576 3121 } 2577 3122 if { $_contourList(numLevels) < 1 } { 3123 # There are tools that set 0 levels to get cutplanes only 3124 #puts stderr "numLevels < 1" 2578 3125 return "" 2579 3126 } … … 2581 3128 set values $_contourList(reqValues) 2582 3129 } else { 2583 foreach { vmin vmax } $_limits($_curFldName) break 3130 # if custom range has been set, use the custom min and max 3131 # to generate contour list values 3132 if { $_settings(-customrange) } { 3133 set vmin [$itk_component(min) value] 3134 set vmax [$itk_component(max) value] 3135 } else { 3136 # use the field limits to calculate the contour list values 3137 foreach { vmin vmax } $_limits($_curFldName) break 3138 } 3139 2584 3140 set v [blt::vector create \#auto] 2585 3141 $v seq $vmin $vmax [expr $_contourList(numLevels)+2] … … 2591 3147 } 2592 3148 2593 itcl::body Rappture::VtkIsosurfaceViewer::SetCurrentFieldName { dataobj } { 3149 itcl::body Rappture::VtkIsosurfaceViewer::SetCurrentFieldName { dataobj } { 2594 3150 set _first $dataobj 2595 3151 $itk_component(field) choices delete 0 end … … 2611 3167 -activeforeground $itk_option(-plotforeground) \ 2612 3168 -font "Arial 8" \ 2613 -command [itcl::code $this Combo invoke]3169 -command [itcl::code $this LegendTitleAction save] 2614 3170 set _fields($fname) [list $label $units $components] 2615 3171 if { $_curFldName == "" } { … … 2620 3176 } 2621 3177 $itk_component(field) value $_curFldLabel 2622 if { ![info exists _limits($_curFldName)] } { 2623 SendCmd "dataset maprange all" 2624 } else { 2625 set limits $_limits($_curFldName) 3178 if { $_settings(-customrange) } { 3179 set limits [list [$itk_component(min) value] [$itk_component(max) value]] 2626 3180 SendCmd "dataset maprange explicit $limits $_curFldName" 2627 3181 if { $limits != $_currentLimits } { … … 2629 3183 EventuallyChangeContourLevels 2630 3184 } 2631 } 2632 } 3185 } else { 3186 if { ![info exists _limits($_curFldName)] } { 3187 SendCmd "dataset maprange all" 3188 } else { 3189 set limits $_limits($_curFldName) 3190 SendCmd "dataset maprange explicit $limits $_curFldName" 3191 if { $limits != $_currentLimits } { 3192 set _currentLimits $limits 3193 EventuallyChangeContourLevels 3194 } 3195 } 3196 } 3197 } -
branches/uq/gui/scripts/vtkmeshviewer.tcl
r4798 r5121 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 2 2 # ---------------------------------------------------------------------- 3 3 # COMPONENT: vtkmeshviewer - Vtk mesh viewer … … 57 57 public method get {args} 58 58 public method isconnected {} 59 public method limits { colormap}60 public method parameters {title args} { 61 # do nothing 59 public method limits { dataobj } 60 public method parameters {title args} { 61 # do nothing 62 62 } 63 63 public method scale {args} 64 64 65 protected method Connect {}66 protected method CurrentDatasets {args}67 protected method Disconnect {}68 protected method DoResize {}69 protected method DoRotate {}70 protected method AdjustSetting {what {value ""}}71 protected method InitSettings { args }72 protected method Pan {option x y}73 protected method Pick {x y}74 protected method Rebuild {}75 protected method ReceiveDataset { args }76 protected method ReceiveImage { args }77 protected method Rotate {option x y}78 protected method Zoom {option}79 80 65 # The following methods are only used by this class. 66 private method AdjustSetting {what {value ""}} 81 67 private method BuildAxisTab {} 82 68 private method BuildCameraTab {} 83 private method BuildCutawayTab {} 84 private method BuildDownloadPopup { widget command } 69 private method BuildDownloadPopup { widget command } 85 70 private method BuildPolydataTab {} 86 private method EventuallyResize { w h } 87 private method EventuallyRotate { q } 88 private method EventuallySetPolydataOpacity {} 89 private method GetImage { args } 90 private method GetVtkData { args } 91 private method IsValidObject { dataobj } 71 private method Connect {} 72 private method CurrentDatasets {args} 73 private method Disconnect {} 74 private method DoResize {} 75 private method DoRotate {} 76 private method EventuallyResize { w h } 77 private method EventuallyRotate { q } 78 private method EventuallySetPolydataOpacity {} 79 private method GetImage { args } 80 private method GetVtkData { args } 81 private method InitSettings { args } 82 private method IsValidObject { dataobj } 83 private method Pan {option x y} 92 84 private method PanCamera {} 93 private method SetObjectStyle { dataobj } 85 private method Pick {x y} 86 private method QuaternionToView { q } { 87 foreach { _view(-qw) _view(-qx) _view(-qy) _view(-qz) } $q break 88 } 89 private method Rebuild {} 90 private method ReceiveDataset { args } 91 private method ReceiveImage { args } 92 private method Rotate {option x y} 93 private method SetObjectStyle { dataobj } 94 94 private method SetOrientation { side } 95 95 private method SetPolydataOpacity {} 96 private method Slice {option args} 96 private method ViewToQuaternion {} { 97 return [list $_view(-qw) $_view(-qx) $_view(-qy) $_view(-qz)] 98 } 99 private method Zoom {option} 97 100 98 101 private variable _arcball "" 99 private variable _dlist ""; 102 private variable _dlist ""; # list of data objects 100 103 private variable _obj2datasets 101 private variable _obj2ovride; # maps dataobj => style override 102 private variable _datasets; # contains all the dataobj-component 103 # datasets in the server 104 private variable _colormaps; # contains all the colormaps 105 # in the server. 106 private variable _dataset2style; # maps dataobj-component to transfunc 107 private variable _style2datasets; # maps tf back to list of 108 # dataobj-components using the tf. 104 private variable _obj2ovride; # maps dataobj => style override 105 private variable _datasets; # contains all the dataobj-component 106 # datasets in the server 107 private variable _dataset2style; # maps dataobj-component to transfunc 108 private variable _style2datasets; # maps tf back to list of 109 # dataobj-components using the tf. 109 110 private variable _click; # info used for rotate operations 110 111 private variable _limits; # autoscale min/max for all axes … … 163 164 # Populate parser with commands handle incoming requests 164 165 # 165 $_parser alias image 166 $_parser alias dataset 166 $_parser alias image [itcl::code $this ReceiveImage] 167 $_parser alias dataset [itcl::code $this ReceiveDataset] 167 168 168 169 # Initialize the view to some default parameters. 169 170 array set _view { 170 qw 0.853553171 qx -0.353553172 qy0.353553173 qz 0.146447174 zoom 1.0175 xpan 0176 ypan 0177 ortho0171 -ortho 0 172 -qw 0.853553 173 -qx -0.353553 174 -qy 0.353553 175 -qz 0.146447 176 -xpan 0 177 -ypan 0 178 -zoom 1.0 178 179 } 179 180 set _arcball [blt::arcball create 100 100] 180 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 181 $_arcball quaternion $q 181 $_arcball quaternion [ViewToQuaternion] 182 182 183 183 set _limits(zmin) 0.0 … … 187 187 -axesvisible 1 188 188 -axislabels 1 189 -axisminorticks 1 189 190 -outline 0 190 191 -polydataedges 0 … … 193 194 -polydatavisible 1 194 195 -polydatawireframe 0 195 -xcutaway 0196 -xdirection -1197 196 -xgrid 0 198 -xposition 0199 -ycutaway 0200 -ydirection -1201 197 -ygrid 0 202 -yposition 0203 -zcutaway 0204 -zdirection -1205 198 -zgrid 0 206 -zposition 0207 199 } 208 200 array set _widget { 209 201 -polydataopacity 100 210 } 202 } 211 203 itk_component add view { 212 204 canvas $itk_component(plotarea).view \ … … 219 211 itk_component add fieldmenu { 220 212 menu $itk_component(plotarea).menu -bg black -fg white -relief flat \ 221 -tearoff no 213 -tearoff no 222 214 } { 223 215 usual … … 240 232 241 233 set _map(id) [$c create image 0 0 -anchor nw -image $_image(plot)] 242 set _map(cwidth) -1 243 set _map(cheight) -1 234 set _map(cwidth) -1 235 set _map(cheight) -1 244 236 set _map(zoom) 1.0 245 237 set _map(original) "" … … 285 277 BuildPolydataTab 286 278 BuildAxisTab 287 #BuildCutawayTab288 279 BuildCameraTab 289 280 290 # Hack around the Tk panewindow. The problem is that the requested 281 # Hack around the Tk panewindow. The problem is that the requested 291 282 # size of the 3d view isn't set until an image is retrieved from 292 283 # the server. So the panewindow uses the tiny size. … … 294 285 pack forget $itk_component(view) 295 286 blt::table $itk_component(plotarea) \ 296 0,0 $itk_component(view) -fill both -reqwidth $w 287 0,0 $itk_component(view) -fill both -reqwidth $w 297 288 blt::table configure $itk_component(plotarea) c1 -resize none 298 289 … … 304 295 bind $itk_component(view) <ButtonRelease-1> \ 305 296 [itcl::code $this Rotate release %x %y] 306 bind $itk_component(view) <Configure> \307 [itcl::code $this EventuallyResize %w %h]308 297 309 298 # Bindings for panning via mouse … … 383 372 384 373 itcl::body Rappture::VtkMeshViewer::DoRotate {} { 385 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 386 SendCmd "camera orient $q" 374 SendCmd "camera orient [ViewToQuaternion]" 387 375 set _rotatePending 0 388 376 } … … 399 387 400 388 itcl::body Rappture::VtkMeshViewer::EventuallyRotate { q } { 401 foreach { _view(qw) _view(qx) _view(qy) _view(qz) } $q break389 QuaternionToView $q 402 390 if { !$_rotatePending } { 403 391 set _rotatePending 1 … … 509 497 continue 510 498 } 511 if {[info exists _obj2ovride($dataobj-raise)] && 499 if {[info exists _obj2ovride($dataobj-raise)] && 512 500 $_obj2ovride($dataobj-raise)} { 513 501 set dlist [linsert $dlist 0 $dataobj] … … 537 525 } 538 526 return $dlist 539 } 527 } 540 528 -image { 541 529 if {[llength $args] != 2} { … … 723 711 724 712 # disconnected -- no more data sitting on server 725 array unset _datasets 726 array unset _data 727 array unset _colormaps 713 array unset _datasets 714 array unset _data 728 715 global readyForNextFrame 729 716 set readyForNextFrame 1 … … 749 736 if { $info(-type) == "image" } { 750 737 if 0 { 751 set f [open "last.ppm" "w"] 738 set f [open "last.ppm" "w"] 752 739 fconfigure $f -encoding binary 753 740 puts -nonewline $f $bytes … … 827 814 # Turn on buffering of commands to the server. We don't want to 828 815 # be preempted by a server disconnect/reconnect (which automatically 829 # generates a new call to Rebuild). 816 # generates a new call to Rebuild). 830 817 StartBufferingCommands 831 818 … … 835 822 $_arcball resize $w $h 836 823 DoResize 837 InitSettings -xgrid -ygrid -zgrid -axismode -axesvisible -axislabels 824 InitSettings -xgrid -ygrid -zgrid -axismode \ 825 -axesvisible -axislabels -axisminorticks 838 826 StopBufferingCommands 839 827 SendCmd "imgflush" … … 857 845 continue 858 846 } 847 if 0 { 848 set f [open /tmp/vtkmesh.vtk "w"] 849 fconfigure $f -translation binary -encoding binary 850 puts -nonewline $f $bytes 851 close $f 852 } 859 853 set length [string length $bytes] 860 854 if { $_reportClientInfo } { 861 855 set info {} 862 lappend info "tool_id" [$dataobj hints toolId] 863 lappend info "tool_name" [$dataobj hints toolName] 864 lappend info "tool_version" [$dataobj hints toolRevision] 865 lappend info "tool_title" [$dataobj hints toolTitle] 856 lappend info "tool_id" [$dataobj hints toolid] 857 lappend info "tool_name" [$dataobj hints toolname] 858 lappend info "tool_title" [$dataobj hints tooltitle] 859 lappend info "tool_command" [$dataobj hints toolcommand] 860 lappend info "tool_revision" [$dataobj hints toolrevision] 866 861 lappend info "dataset_label" [$dataobj hints label] 867 862 lappend info "dataset_size" $length 868 863 lappend info "dataset_tag" $tag 869 SendCmd [list "clientinfo" $info]864 SendCmd "clientinfo [list $info]" 870 865 } 871 866 SendCmd "dataset add $tag data follows $length" … … 902 897 InitSettings -polydataedges -polydatalighting -polydataopacity \ 903 898 -polydatavisible -polydatawireframe 904 905 SendCmd "axis lformat all %g" 906 # Too many major ticks, so turn off minor ticks 907 SendCmd "axis minticks all 0" 908 909 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 910 $_arcball quaternion $q 899 900 #SendCmd "axis lformat all %g" 901 902 $_arcball quaternion [ViewToQuaternion] 911 903 SendCmd "camera reset" 912 if { $_view( ortho)} {904 if { $_view(-ortho)} { 913 905 SendCmd "camera mode ortho" 914 906 } else { … … 941 933 itcl::body Rappture::VtkMeshViewer::CurrentDatasets {args} { 942 934 set flag [lindex $args 0] 943 switch -- $flag { 935 switch -- $flag { 944 936 "-all" { 945 937 if { [llength $args] > 1 } { … … 960 952 set dlist [get -visible] 961 953 } 962 } 954 } 963 955 default { 964 956 set dlist $args … … 985 977 switch -- $option { 986 978 "in" { 987 set _view( zoom) [expr {$_view(zoom)*1.25}]988 SendCmd "camera zoom $_view( zoom)"979 set _view(-zoom) [expr {$_view(-zoom)*1.25}] 980 SendCmd "camera zoom $_view(-zoom)" 989 981 } 990 982 "out" { 991 set _view( zoom) [expr {$_view(zoom)*0.8}]992 SendCmd "camera zoom $_view( zoom)"983 set _view(-zoom) [expr {$_view(-zoom)*0.8}] 984 SendCmd "camera zoom $_view(-zoom)" 993 985 } 994 986 "reset" { 995 987 array set _view { 996 qw 0.853553997 qx -0.353553998 qy 0.353553999 qz 0.1464471000 zoom 1.01001 xpan 01002 ypan0988 -qw 0.853553 989 -qx -0.353553 990 -qy 0.353553 991 -qz 0.146447 992 -xpan 0 993 -ypan 0 994 -zoom 1.0 1003 995 } 1004 996 if { $_first != "" } { … … 1008 1000 } 1009 1001 } 1010 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 1011 $_arcball quaternion $q 1002 $_arcball quaternion [ViewToQuaternion] 1012 1003 DoRotate 1013 1004 SendCmd "camera reset" … … 1017 1008 1018 1009 itcl::body Rappture::VtkMeshViewer::PanCamera {} { 1019 set x $_view( xpan)1020 set y $_view( ypan)1010 set x $_view(-xpan) 1011 set y $_view(-ypan) 1021 1012 SendCmd "camera pan $x $y" 1022 1013 } … … 1077 1068 foreach tag [CurrentDatasets -visible] { 1078 1069 SendCmd "dataset getscalar pixel $x $y $tag" 1079 } 1070 } 1080 1071 } 1081 1072 … … 1095 1086 set x [expr $x / double($w)] 1096 1087 set y [expr $y / double($h)] 1097 set _view( xpan) [expr $_view(xpan) + $x]1098 set _view( ypan) [expr $_view(ypan) + $y]1088 set _view(-xpan) [expr $_view(-xpan) + $x] 1089 set _view(-ypan) [expr $_view(-ypan) + $y] 1099 1090 PanCamera 1100 1091 return … … 1118 1109 set _click(x) $x 1119 1110 set _click(y) $y 1120 set _view( xpan) [expr $_view(xpan) - $dx]1121 set _view( ypan) [expr $_view(ypan) - $dy]1111 set _view(-xpan) [expr $_view(-xpan) - $dx] 1112 set _view(-ypan) [expr $_view(-ypan) - $dy] 1122 1113 PanCamera 1123 1114 } … … 1217 1208 SendCmd "axis flymode $mode" 1218 1209 } 1219 "-xcutaway" - "-ycutaway" - "-zcutaway" {1220 set axis [string range $what 1 1]1221 set bool $_settings($what)1222 if { $bool } {1223 set pos [expr $_settings(-${axis}position) * 0.01]1224 set dir $_settings(-${axis}direction)1225 $itk_component(${axis}CutScale) configure -state normal \1226 -troughcolor white1227 SendCmd "renderer clipplane $axis $pos $dir"1228 } else {1229 $itk_component(${axis}CutScale) configure -state disabled \1230 -troughcolor grey821231 SendCmd "renderer clipplane $axis 1 -1"1232 }1233 }1234 "-xposition" - "-yposition" - "-zposition" {1235 set axis [string range $what 1 1]1236 set pos [expr $_settings($what) * 0.01]1237 SendCmd "renderer clipplane ${axis} $pos -1"1238 }1239 "-xdirection" - "-ydirection" - "-zdirection" {1240 set axis [string range $what 1 1]1241 puts stderr "direction not implemented"1242 }1243 1210 default { 1244 1211 error "don't know how to fix $what" … … 1252 1219 itcl::configbody Rappture::VtkMeshViewer::plotbackground { 1253 1220 if { [isconnected] } { 1254 foreach {r g b} [Color2RGB $itk_option(-plotbackground)] break1255 SendCmd "screen bgcolor $r $g $b"1221 set rgb [Color2RGB $itk_option(-plotbackground)] 1222 SendCmd "screen bgcolor $rgb" 1256 1223 } 1257 1224 } … … 1262 1229 itcl::configbody Rappture::VtkMeshViewer::plotforeground { 1263 1230 if { [isconnected] } { 1264 foreach {r g b} [Color2RGB $itk_option(-plotforeground)] break1265 #fix this!1266 #SendCmd "color background $r $g $b"1231 set rgb [Color2RGB $itk_option(-plotforeground)] 1232 SendCmd "axis color all $rgb" 1233 SendCmd "outline color $rgb" 1267 1234 } 1268 1235 } … … 1278 1245 set f [open "$tmpfile" "w"] 1279 1246 fconfigure $f -translation binary -encoding binary 1280 puts $f $data 1247 puts $f $data 1281 1248 close $f 1282 1249 set reader [vtkDataSetReader $tag-xvtkDataSetReader] … … 1326 1293 -variable [itcl::scope _settings(-polydatavisible)] \ 1327 1294 -command [itcl::code $this AdjustSetting -polydatavisible] \ 1328 -font "Arial 9" -anchor w 1295 -font "Arial 9" -anchor w 1329 1296 1330 1297 checkbutton $inner.outline \ … … 1332 1299 -variable [itcl::scope _settings(-outline)] \ 1333 1300 -command [itcl::code $this AdjustSetting -outline] \ 1334 -font "Arial 9" -anchor w 1301 -font "Arial 9" -anchor w 1335 1302 1336 1303 checkbutton $inner.wireframe \ … … 1338 1305 -variable [itcl::scope _settings(-polydatawireframe)] \ 1339 1306 -command [itcl::code $this AdjustSetting -polydatawireframe] \ 1340 -font "Arial 9" -anchor w 1307 -font "Arial 9" -anchor w 1341 1308 1342 1309 checkbutton $inner.lighting \ … … 1353 1320 1354 1321 itk_component add field_l { 1355 label $inner.field_l -text "Field" -font "Arial 9" 1322 label $inner.field_l -text "Field" -font "Arial 9" 1356 1323 } { 1357 1324 ignore -font … … 1363 1330 [itcl::code $this AdjustSetting -field] 1364 1331 1365 label $inner.opacity_l -text "Opacity" -font "Arial 9" -anchor w 1332 label $inner.opacity_l -text "Opacity" -font "Arial 9" -anchor w 1366 1333 ::scale $inner.opacity -from 0 -to 100 -orient horizontal \ 1367 1334 -variable [itcl::scope _widget(-polydataopacity)] \ … … 1378 1345 4,0 $inner.edges -cspan 2 -anchor w -pady 2 \ 1379 1346 5,0 $inner.opacity_l -anchor w -pady 2 \ 1380 5,1 $inner.opacity -fill x -pady 2 1347 5,1 $inner.opacity -fill x -pady 2 1381 1348 1382 1349 blt::table configure $inner r* c* -resize none … … 1391 1358 set inner [$itk_component(main) insert end \ 1392 1359 -title "Axis Settings" \ 1393 -icon [Rappture::icon axis 1]]1360 -icon [Rappture::icon axis2]] 1394 1361 $inner configure -borderwidth 4 1395 1362 1396 1363 checkbutton $inner.visible \ 1397 -text " ShowAxes" \1364 -text "Axes" \ 1398 1365 -variable [itcl::scope _settings(-axesvisible)] \ 1399 1366 -command [itcl::code $this AdjustSetting -axesvisible] \ … … 1401 1368 1402 1369 checkbutton $inner.labels \ 1403 -text " ShowAxis Labels" \1370 -text "Axis Labels" \ 1404 1371 -variable [itcl::scope _settings(-axislabels)] \ 1405 1372 -command [itcl::code $this AdjustSetting -axislabels] \ 1406 1373 -font "Arial 9" 1407 1408 checkbutton $inner. gridx\1409 -text " Show X Grid" \1374 label $inner.grid_l -text "Grid" -font "Arial 9" 1375 checkbutton $inner.xgrid \ 1376 -text "X" \ 1410 1377 -variable [itcl::scope _settings(-xgrid)] \ 1411 1378 -command [itcl::code $this AdjustSetting -xgrid] \ 1412 1379 -font "Arial 9" 1413 checkbutton $inner. gridy\1414 -text " Show Y Grid" \1380 checkbutton $inner.ygrid \ 1381 -text "Y" \ 1415 1382 -variable [itcl::scope _settings(-ygrid)] \ 1416 1383 -command [itcl::code $this AdjustSetting -ygrid] \ 1417 1384 -font "Arial 9" 1418 checkbutton $inner. gridz\1419 -text " Show Z Grid" \1385 checkbutton $inner.zgrid \ 1386 -text "Z" \ 1420 1387 -variable [itcl::scope _settings(-zgrid)] \ 1421 1388 -command [itcl::code $this AdjustSetting -zgrid] \ 1422 1389 -font "Arial 9" 1423 1424 label $inner.mode_l -text "Mode" -font "Arial 9" 1390 checkbutton $inner.minorticks \ 1391 -text "Minor Ticks" \ 1392 -variable [itcl::scope _settings(-axisminorticks)] \ 1393 -command [itcl::code $this AdjustSetting -axisminorticks] \ 1394 -font "Arial 9" 1395 1396 label $inner.mode_l -text "Mode" -font "Arial 9" 1425 1397 1426 1398 itk_component add axismode { … … 1431 1403 "closest_triad" "closest" \ 1432 1404 "furthest_triad" "farthest" \ 1433 "outer_edges" "outer" 1405 "outer_edges" "outer" 1434 1406 $itk_component(axismode) value "static" 1435 1407 bind $inner.mode <<Value>> [itcl::code $this AdjustSetting -axismode] 1436 1408 1437 1409 blt::table $inner \ 1438 0,0 $inner.visible -anchor w -cspan 2 \ 1439 1,0 $inner.labels -anchor w -cspan 2 \ 1440 2,0 $inner.gridx -anchor w -cspan 2 \ 1441 3,0 $inner.gridy -anchor w -cspan 2 \ 1442 4,0 $inner.gridz -anchor w -cspan 2 \ 1443 5,0 $inner.mode_l -anchor w -cspan 2 -padx { 2 0 } \ 1444 6,0 $inner.mode -fill x -cspan 2 1410 0,0 $inner.visible -anchor w -cspan 4 \ 1411 1,0 $inner.labels -anchor w -cspan 4 \ 1412 2,0 $inner.minorticks -anchor w -cspan 4 \ 1413 4,0 $inner.grid_l -anchor w \ 1414 4,1 $inner.xgrid -anchor w \ 1415 4,2 $inner.ygrid -anchor w \ 1416 4,3 $inner.zgrid -anchor w \ 1417 5,0 $inner.mode_l -anchor w -padx { 2 0 } \ 1418 5,1 $inner.mode -fill x -cspan 3 1445 1419 1446 1420 blt::table configure $inner r* c* -resize none 1447 blt::table configure $inner r7 c1 -resize expand 1421 blt::table configure $inner r7 c6 -resize expand 1422 blt::table configure $inner r3 -height 0.125i 1448 1423 } 1449 1424 … … 1466 1441 0,0 $inner.view_l -anchor e -pady 2 \ 1467 1442 0,1 $inner.view -anchor w -pady 2 1443 blt::table configure $inner r0 -resize none 1468 1444 1469 1445 set labels { qx qy qz qw xpan ypan zoom } … … 1472 1448 label $inner.${tag}label -text $tag -font "Arial 9" 1473 1449 entry $inner.${tag} -font "Arial 9" -bg white \ 1474 -textvariable [itcl::scope _view($tag)] 1475 bind $inner.${tag} <KeyPress-Return> \ 1476 [itcl::code $this camera set ${tag}] 1450 -textvariable [itcl::scope _view(-$tag)] 1451 bind $inner.${tag} <Return> \ 1452 [itcl::code $this camera set -${tag}] 1453 bind $inner.${tag} <KP_Enter> \ 1454 [itcl::code $this camera set -${tag}] 1477 1455 blt::table $inner \ 1478 1456 $row,0 $inner.${tag}label -anchor e -pady 2 \ … … 1483 1461 checkbutton $inner.ortho \ 1484 1462 -text "Orthographic Projection" \ 1485 -variable [itcl::scope _view( ortho)] \1486 -command [itcl::code $this camera set ortho] \1463 -variable [itcl::scope _view(-ortho)] \ 1464 -command [itcl::code $this camera set -ortho] \ 1487 1465 -font "Arial 9" 1488 1466 blt::table $inner \ … … 1491 1469 incr row 1492 1470 1493 blt::table configure $inner c* r*-resize none1471 blt::table configure $inner c* -resize none 1494 1472 blt::table configure $inner c2 -resize expand 1495 1473 blt::table configure $inner r$row -resize expand 1496 1474 } 1497 1475 1498 itcl::body Rappture::VtkMeshViewer::BuildCutawayTab {} { 1499 1500 set fg [option get $itk_component(hull) font Font] 1501 1502 set inner [$itk_component(main) insert end \ 1503 -title "Cutaway Along Axis" \ 1504 -icon [Rappture::icon cutbutton]] 1505 1506 $inner configure -borderwidth 4 1507 1508 # X-value slicer... 1509 itk_component add xCutButton { 1510 Rappture::PushButton $inner.xbutton \ 1511 -onimage [Rappture::icon x-cutplane] \ 1512 -offimage [Rappture::icon x-cutplane] \ 1513 -command [itcl::code $this AdjustSetting -xcutaway] \ 1514 -variable [itcl::scope _settings(-xcutaway)] 1515 } 1516 Rappture::Tooltip::for $itk_component(xCutButton) \ 1517 "Toggle the X-axis cutaway on/off" 1518 1519 itk_component add xCutScale { 1520 ::scale $inner.xval -from 100 -to 0 \ 1521 -width 10 -orient vertical -showvalue yes \ 1522 -borderwidth 1 -highlightthickness 0 \ 1523 -command [itcl::code $this Slice move x] \ 1524 -variable [itcl::scope _settings(-xposition)] 1525 } { 1526 usual 1527 ignore -borderwidth -highlightthickness 1528 } 1529 # Set the default cutaway value before disabling the scale. 1530 $itk_component(xCutScale) set 100 1531 $itk_component(xCutScale) configure -state disabled 1532 Rappture::Tooltip::for $itk_component(xCutScale) \ 1533 "@[itcl::code $this Slice tooltip x]" 1534 1535 itk_component add xDirButton { 1536 Rappture::PushButton $inner.xdir \ 1537 -onimage [Rappture::icon arrow-down] \ 1538 -onvalue -1 \ 1539 -offimage [Rappture::icon arrow-up] \ 1540 -offvalue 1 \ 1541 -command [itcl::code $this AdjustSetting -xdirection] \ 1542 -variable [itcl::scope _settings(-xdirection)] 1543 } 1544 set _settings(-xdirection) -1 1545 Rappture::Tooltip::for $itk_component(xDirButton) \ 1546 "Toggle the direction of the X-axis cutaway" 1547 1548 # Y-value slicer... 1549 itk_component add yCutButton { 1550 Rappture::PushButton $inner.ybutton \ 1551 -onimage [Rappture::icon y-cutplane] \ 1552 -offimage [Rappture::icon y-cutplane] \ 1553 -command [itcl::code $this AdjustSetting -ycutaway] \ 1554 -variable [itcl::scope _settings(-ycutaway)] 1555 } 1556 Rappture::Tooltip::for $itk_component(yCutButton) \ 1557 "Toggle the Y-axis cutaway on/off" 1558 1559 itk_component add yCutScale { 1560 ::scale $inner.yval -from 100 -to 0 \ 1561 -width 10 -orient vertical -showvalue yes \ 1562 -borderwidth 1 -highlightthickness 0 \ 1563 -command [itcl::code $this Slice move y] \ 1564 -variable [itcl::scope _settings(-yposition)] 1565 } { 1566 usual 1567 ignore -borderwidth -highlightthickness 1568 } 1569 Rappture::Tooltip::for $itk_component(yCutScale) \ 1570 "@[itcl::code $this Slice tooltip y]" 1571 # Set the default cutaway value before disabling the scale. 1572 $itk_component(yCutScale) set 100 1573 $itk_component(yCutScale) configure -state disabled 1574 1575 itk_component add yDirButton { 1576 Rappture::PushButton $inner.ydir \ 1577 -onimage [Rappture::icon arrow-down] \ 1578 -onvalue -1 \ 1579 -offimage [Rappture::icon arrow-up] \ 1580 -offvalue 1 \ 1581 -command [itcl::code $this AdjustSetting -ydirection] \ 1582 -variable [itcl::scope _settings(-ydirection)] 1583 } 1584 Rappture::Tooltip::for $itk_component(yDirButton) \ 1585 "Toggle the direction of the Y-axis cutaway" 1586 set _settings(-ydirection) -1 1587 1588 # Z-value slicer... 1589 itk_component add zCutButton { 1590 Rappture::PushButton $inner.zbutton \ 1591 -onimage [Rappture::icon z-cutplane] \ 1592 -offimage [Rappture::icon z-cutplane] \ 1593 -command [itcl::code $this AdjustSetting -zcutaway] \ 1594 -variable [itcl::scope _settings(-zcutaway)] 1595 } 1596 Rappture::Tooltip::for $itk_component(zCutButton) \ 1597 "Toggle the Z-axis cutaway on/off" 1598 1599 itk_component add zCutScale { 1600 ::scale $inner.zval -from 100 -to 0 \ 1601 -width 10 -orient vertical -showvalue yes \ 1602 -borderwidth 1 -highlightthickness 0 \ 1603 -command [itcl::code $this Slice move z] \ 1604 -variable [itcl::scope _settings(-zposition)] 1605 } { 1606 usual 1607 ignore -borderwidth -highlightthickness 1608 } 1609 $itk_component(zCutScale) set 100 1610 $itk_component(zCutScale) configure -state disabled 1611 Rappture::Tooltip::for $itk_component(zCutScale) \ 1612 "@[itcl::code $this Slice tooltip z]" 1613 1614 itk_component add zDirButton { 1615 Rappture::PushButton $inner.zdir \ 1616 -onimage [Rappture::icon arrow-down] \ 1617 -onvalue -1 \ 1618 -offimage [Rappture::icon arrow-up] \ 1619 -offvalue 1 \ 1620 -command [itcl::code $this AdjustSetting -zdirection] \ 1621 -variable [itcl::scope _settings(-zdirection)] 1622 } 1623 set _settings(-zdirection) -1 1624 Rappture::Tooltip::for $itk_component(zDirButton) \ 1625 "Toggle the direction of the Z-axis cutaway" 1626 1627 blt::table $inner \ 1628 0,0 $itk_component(xCutButton) -anchor e -padx 2 -pady 2 \ 1629 1,0 $itk_component(xCutScale) -fill y \ 1630 0,1 $itk_component(yCutButton) -anchor e -padx 2 -pady 2 \ 1631 1,1 $itk_component(yCutScale) -fill y \ 1632 0,2 $itk_component(zCutButton) -anchor e -padx 2 -pady 2 \ 1633 1,2 $itk_component(zCutScale) -fill y \ 1634 1635 blt::table configure $inner r* c* -resize none 1636 blt::table configure $inner r1 c3 -resize expand 1637 } 1638 1639 # 1640 # camera -- 1476 # 1477 # camera -- 1641 1478 # 1642 1479 itcl::body Rappture::VtkMeshViewer::camera {option args} { 1643 switch -- $option { 1480 switch -- $option { 1644 1481 "show" { 1645 1482 puts [array get _view] 1646 1483 } 1647 1484 "set" { 1648 set wh o[lindex $args 0]1649 set x $_view($wh o)1485 set what [lindex $args 0] 1486 set x $_view($what) 1650 1487 set code [catch { string is double $x } result] 1651 1488 if { $code != 0 || !$result } { 1652 1489 return 1653 1490 } 1654 switch -- $wh o{1655 " ortho" {1656 if {$_view( ortho)} {1491 switch -- $what { 1492 "-ortho" { 1493 if {$_view($what)} { 1657 1494 SendCmd "camera mode ortho" 1658 1495 } else { … … 1660 1497 } 1661 1498 } 1662 " xpan" - "ypan" {1499 "-xpan" - "-ypan" { 1663 1500 PanCamera 1664 1501 } 1665 " qx" - "qy" - "qz" - "qw" {1666 set q [ list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]1502 "-qx" - "-qy" - "-qz" - "-qw" { 1503 set q [ViewToQuaternion] 1667 1504 $_arcball quaternion $q 1668 1505 EventuallyRotate $q 1669 1506 } 1670 " zoom" {1671 SendCmd "camera zoom $_view( zoom)"1507 "-zoom" { 1508 SendCmd "camera zoom $_view($what)" 1672 1509 } 1673 1510 } … … 1686 1523 1687 1524 itcl::body Rappture::VtkMeshViewer::GetImage { args } { 1688 if { [image width $_image(download)] > 0 && 1525 if { [image width $_image(download)] > 0 && 1689 1526 [image height $_image(download)] > 0 } { 1690 1527 set bytes [$_image(download) data -format "jpeg -quality 100"] … … 1699 1536 -title "[Rappture::filexfer::label downloadWord] as..." 1700 1537 set inner [$popup component inner] 1701 label $inner.summary -text "" -anchor w 1538 label $inner.summary -text "" -anchor w 1702 1539 radiobutton $inner.vtk_button -text "VTK data file" \ 1703 1540 -variable [itcl::scope _downloadPopup(format)] \ 1704 1541 -font "Helvetica 9 " \ 1705 -value vtk 1542 -value vtk 1706 1543 Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file." 1707 1544 radiobutton $inner.image_button -text "Image File" \ 1708 1545 -variable [itcl::scope _downloadPopup(format)] \ 1709 -value image 1546 -value image 1710 1547 Rappture::Tooltip::for $inner.image_button \ 1711 1548 "Save as digital image." … … 1728 1565 2,0 $inner.image_button -anchor w -cspan 2 -padx { 4 0 } \ 1729 1566 4,1 $inner.cancel -width .9i -fill y \ 1730 4,0 $inner.ok -padx 2 -width .9i -fill y 1567 4,0 $inner.ok -padx 2 -width .9i -fill y 1731 1568 blt::table configure $inner r3 -height 4 1732 1569 blt::table configure $inner r4 -pady 4 … … 1797 1634 } 1798 1635 1799 # ---------------------------------------------------------------------- 1800 # USAGE: Slice move x|y|z <newval> 1801 # 1802 # Called automatically when the user drags the slider to move the 1803 # cut plane that slices 3D data. Gets the current value from the 1804 # slider and moves the cut plane to the appropriate point in the 1805 # data set. 1806 # ---------------------------------------------------------------------- 1807 itcl::body Rappture::VtkMeshViewer::Slice {option args} { 1808 switch -- $option { 1809 "move" { 1810 set axis [lindex $args 0] 1811 set newval [lindex $args 1] 1812 if {[llength $args] != 2} { 1813 error "wrong # args: should be \"Slice move x|y|z newval\"" 1814 } 1815 set newpos [expr {0.01*$newval}] 1816 SendCmd "renderer clipplane $axis $newpos -1" 1817 } 1818 "tooltip" { 1819 set axis [lindex $args 0] 1820 set val [$itk_component(${axis}CutScale) get] 1821 return "Move the [string toupper $axis] cut plane.\nCurrently: $axis = $val%" 1822 } 1823 default { 1824 error "bad option \"$option\": should be axis, move, or tooltip" 1825 } 1826 } 1827 } 1828 1829 itcl::body Rappture::VtkMeshViewer::SetOrientation { side } { 1636 itcl::body Rappture::VtkMeshViewer::SetOrientation { side } { 1830 1637 array set positions { 1831 1638 front "1 0 0 0" … … 1836 1643 bottom "0.707107 0.707107 0 0" 1837 1644 } 1838 foreach name { qw qx qyqz } value $positions($side) {1645 foreach name { -qw -qx -qy -qz } value $positions($side) { 1839 1646 set _view($name) $value 1840 } 1841 set q [ list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]1647 } 1648 set q [ViewToQuaternion] 1842 1649 $_arcball quaternion $q 1843 1650 SendCmd "camera orient $q" 1844 1651 SendCmd "camera reset" 1845 set _view(xpan) 0 1846 set _view(ypan) 0 1847 set _view(zoom) 1.0 1848 } 1849 1652 set _view(-xpan) 0 1653 set _view(-ypan) 0 1654 set _view(-zoom) 1.0 1655 } -
branches/uq/gui/scripts/vtkstreamlinesviewer.tcl
r4798 r5121 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 2 2 # ---------------------------------------------------------------------- 3 3 # COMPONENT: vtkstreamlinesviewer - Vtk streamlines object viewer … … 57 57 public method get {args} 58 58 public method isconnected {} 59 public method parameters {title args} { 60 # do nothing 59 public method parameters {title args} { 60 # do nothing 61 61 } 62 62 public method scale {args} 63 63 64 protected method Connect {}65 protected method CurrentDatasets {args}66 protected method Disconnect {}67 protected method DoResize {}68 protected method DoReseed {}69 protected method DoRotate {}70 protected method AdjustSetting {what {value ""}}71 protected method InitSettings { args }72 protected method Pan {option x y}73 protected method Pick {x y}74 protected method Rebuild {}75 protected method ReceiveDataset { args }76 protected method ReceiveImage { args }77 protected method ReceiveLegend { colormap title vmin vmax size }78 protected method Rotate {option x y}79 protected method Zoom {option}80 81 64 # The following methods are only used by this class. 65 private method AdjustSetting {what {value ""}} 82 66 private method BuildAxisTab {} 83 67 private method BuildCameraTab {} 84 68 private method BuildColormap { name colors } 85 69 private method BuildCutplaneTab {} 86 private method BuildDownloadPopup { widget command } 70 private method BuildDownloadPopup { widget command } 87 71 private method BuildStreamsTab {} 88 72 private method BuildVolumeTab {} 89 73 private method DrawLegend {} 90 74 private method Combo { option } 91 private method EnterLegend { x y } 92 private method EventuallyResize { w h } 93 private method EventuallyReseed { numPoints } 94 private method EventuallyRotate { q } 95 private method EventuallySetCutplane { axis args } 96 private method GetImage { args } 97 private method GetVtkData { args } 98 private method IsValidObject { dataobj } 75 private method Connect {} 76 private method CurrentDatasets {args} 77 private method Disconnect {} 78 private method DoResize {} 79 private method DoReseed {} 80 private method DoRotate {} 81 private method EnterLegend { x y } 82 private method EventuallyResize { w h } 83 private method EventuallyReseed { numPoints } 84 private method EventuallyRotate { q } 85 private method EventuallySetCutplane { axis args } 86 private method GetImage { args } 87 private method GetVtkData { args } 88 private method InitSettings { args } 89 private method IsValidObject { dataobj } 99 90 private method LeaveLegend {} 100 private method MotionLegend { x y } 91 private method MotionLegend { x y } 92 private method Pan {option x y} 101 93 private method PanCamera {} 94 private method Pick {x y} 95 private method QuaternionToView { q } { 96 foreach { _view(-qw) _view(-qx) _view(-qy) _view(-qz) } $q break 97 } 98 private method Rebuild {} 99 private method ReceiveDataset { args } 100 private method ReceiveImage { args } 101 private method ReceiveLegend { colormap title vmin vmax size } 102 102 private method RequestLegend {} 103 private method Rotate {option x y} 103 104 private method SetColormap { dataobj comp } 104 105 private method ChangeColormap { dataobj comp color } 105 106 private method SetLegendTip { x y } 106 private method SetObjectStyle { dataobj comp } 107 private method Slice {option args} 107 private method SetObjectStyle { dataobj comp } 108 private method Slice {option args} 108 109 private method SetOrientation { side } 110 private method ViewToQuaternion {} { 111 return [list $_view(-qw) $_view(-qx) $_view(-qy) $_view(-qz)] 112 } 113 private method Zoom {option} 109 114 110 115 private variable _arcball "" … … 113 118 private variable _obj2datasets 114 119 private variable _obj2ovride ; # maps dataobj => style override 115 private variable _datasets ; # contains all the dataobj-component 120 private variable _datasets ; # contains all the dataobj-component 116 121 ; # datasets in the server 117 122 private variable _colormaps ; # contains all the colormaps … … 142 147 private variable _cutplanePending 0 143 148 private variable _legendPending 0 144 private variable _vectorFields 145 private variable _scalarFields 146 private variable _fields 149 private variable _vectorFields 150 private variable _scalarFields 151 private variable _fields 147 152 private variable _curFldName "" 148 153 private variable _curFldLabel "" … … 189 194 $_dispatcher register !xcutplane 190 195 $_dispatcher dispatch $this !xcutplane \ 191 "[itcl::code $this AdjustSetting cutplaneXPosition]; list"196 "[itcl::code $this AdjustSetting -cutplanexposition]; list" 192 197 193 198 # Y-Cutplane event 194 199 $_dispatcher register !ycutplane 195 200 $_dispatcher dispatch $this !ycutplane \ 196 "[itcl::code $this AdjustSetting cutplaneYPosition]; list"201 "[itcl::code $this AdjustSetting -cutplaneyposition]; list" 197 202 198 203 # Z-Cutplane event 199 204 $_dispatcher register !zcutplane 200 205 $_dispatcher dispatch $this !zcutplane \ 201 "[itcl::code $this AdjustSetting cutplaneZPosition]; list"206 "[itcl::code $this AdjustSetting -cutplanezposition]; list" 202 207 203 208 # … … 210 215 # Initialize the view to some default parameters. 211 216 array set _view { 212 qw 0.853553213 qx -0.353553214 qy0.353553215 qz 0.146447216 zoom 1.0217 xpan 0218 ypan 0219 ortho0217 -ortho 0 218 -qw 0.853553 219 -qx -0.353553 220 -qy 0.353553 221 -qz 0.146447 222 -xpan 0 223 -ypan 0 224 -zoom 1.0 220 225 } 221 226 set _arcball [blt::arcball create 100 100] 222 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 223 $_arcball quaternion $q 227 $_arcball quaternion [ViewToQuaternion] 224 228 225 229 array set _settings [subst { 226 axesVisible 1 227 axisLabelsVisible 1 228 axisMinorTicks 1 229 axisXGrid 0 230 axisYGrid 0 231 axisZGrid 0 232 cutplaneEdges 0 233 cutplaneLighting 1 234 cutplaneOpacity 100 235 cutplaneVisible 0 236 cutplaneWireframe 0 237 cutplaneXPosition 50 238 cutplaneXVisible 1 239 cutplaneYPosition 50 240 cutplaneYVisible 1 241 cutplaneZPosition 50 242 cutplaneZVisible 1 243 legendVisible 1 244 streamlinesLighting 1 245 streamlinesMode lines 246 streamlinesNumSeeds 200 247 streamlinesOpacity 100 248 streamlinesScale 1 249 streamlinesSeedsVisible 0 250 streamlinesVisible 1 251 volumeEdges 0 252 volumeLighting 1 253 volumeOpacity 40 254 volumeVisible 1 255 volumeWireframe 0 230 -axesvisible 1 231 -axislabelsvisible 1 232 -axisminorticks 1 233 -axismode "static" 234 -cutplaneedges 0 235 -cutplanelighting 1 236 -cutplaneopacity 100 237 -cutplanevisible 0 238 -cutplanewireframe 0 239 -cutplanexposition 50 240 -cutplanexvisible 1 241 -cutplaneyposition 50 242 -cutplaneyvisible 1 243 -cutplanezposition 50 244 -cutplanezvisible 1 245 -legendvisible 1 246 -streamlineslighting 1 247 -streamlinesmode lines 248 -streamlinesnumseeds 200 249 -streamlinesopacity 100 250 -streamlinesscale 1 251 -streamlinesseedsvisible 0 252 -streamlinesvisible 1 253 -volumeedges 0 254 -volumelighting 1 255 -volumeopacity 40 256 -volumevisible 1 257 -volumewireframe 0 258 -xgrid 0 259 -ygrid 0 260 -zgrid 0 256 261 }] 257 262 … … 266 271 itk_component add fieldmenu { 267 272 menu $itk_component(plotarea).menu -bg black -fg white -relief flat \ 268 -tearoff no 273 -tearoff no 269 274 } { 270 275 usual … … 286 291 287 292 set _map(id) [$c create image 0 0 -anchor nw -image $_image(plot)] 288 set _map(cwidth) -1 289 set _map(cheight) -1 293 set _map(cwidth) -1 294 set _map(cheight) -1 290 295 set _map(zoom) 1.0 291 296 set _map(original) "" … … 332 337 -onimage [Rappture::icon volume-on] \ 333 338 -offimage [Rappture::icon volume-off] \ 334 -variable [itcl::scope _settings( volumeVisible)] \335 -command [itcl::code $this AdjustSetting volumeVisible]339 -variable [itcl::scope _settings(-volumevisible)] \ 340 -command [itcl::code $this AdjustSetting -volumevisible] 336 341 } 337 342 $itk_component(volume) select … … 344 349 -onimage [Rappture::icon streamlines-on] \ 345 350 -offimage [Rappture::icon streamlines-off] \ 346 -variable [itcl::scope _settings( streamlinesVisible)] \347 -command [itcl::code $this AdjustSetting streamlinesVisible] \351 -variable [itcl::scope _settings(-streamlinesvisible)] \ 352 -command [itcl::code $this AdjustSetting -streamlinesvisible] \ 348 353 } 349 354 $itk_component(streamlines) select … … 356 361 -onimage [Rappture::icon cutbutton] \ 357 362 -offimage [Rappture::icon cutbutton] \ 358 -variable [itcl::scope _settings( cutplaneVisible)] \359 -command [itcl::code $this AdjustSetting cutplaneVisible]363 -variable [itcl::scope _settings(-cutplanevisible)] \ 364 -command [itcl::code $this AdjustSetting -cutplanevisible] 360 365 } 361 366 Rappture::Tooltip::for $itk_component(cutplane) \ … … 377 382 set _image(legend) [image create photo] 378 383 itk_component add legend { 379 canvas $itk_component(plotarea).legend -width 50 -highlightthickness 0 384 canvas $itk_component(plotarea).legend -width 50 -highlightthickness 0 380 385 } { 381 386 usual … … 384 389 } 385 390 386 # Hack around the Tk panewindow. The problem is that the requested 391 # Hack around the Tk panewindow. The problem is that the requested 387 392 # size of the 3d view isn't set until an image is retrieved from 388 393 # the server. So the panewindow uses the tiny size. … … 390 395 pack forget $itk_component(view) 391 396 blt::table $itk_component(plotarea) \ 392 0,0 $itk_component(view) -fill both -reqwidth $w 397 0,0 $itk_component(view) -fill both -reqwidth $w 393 398 blt::table configure $itk_component(plotarea) c1 -resize none 394 399 … … 400 405 bind $itk_component(view) <ButtonRelease-1> \ 401 406 [itcl::code $this Rotate release %x %y] 402 bind $itk_component(view) <Configure> \ 403 [itcl::code $this EventuallyResize %w %h] 404 405 if 0 { 406 bind $itk_component(view) <Configure> \ 407 [itcl::code $this EventuallyResize %w %h] 408 } 407 409 408 # Bindings for panning via mouse 410 409 bind $itk_component(view) <ButtonPress-2> \ … … 481 480 482 481 itcl::body Rappture::VtkStreamlinesViewer::DoRotate {} { 483 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 484 SendCmd "camera orient $q" 482 SendCmd "camera orient [ViewToQuaternion]" 485 483 set _rotatePending 0 486 484 } … … 516 514 517 515 itcl::body Rappture::VtkStreamlinesViewer::EventuallyRotate { q } { 518 foreach { _view(qw) _view(qx) _view(qy) _view(qz) } $q break516 QuaternionToView $q 519 517 if { !$_rotatePending } { 520 518 set _rotatePending 1 521 global rotate_delay 519 global rotate_delay 522 520 $_dispatcher event -after $rotate_delay !rotate 523 521 } … … 623 621 continue 624 622 } 625 if {[info exists _obj2ovride($dataobj-raise)] && 623 if {[info exists _obj2ovride($dataobj-raise)] && 626 624 $_obj2ovride($dataobj-raise)} { 627 625 set dlist [linsert $dlist 0 $dataobj] … … 651 649 } 652 650 return $dlist 653 } 651 } 654 652 -image { 655 653 if {[llength $args] != 2} { … … 793 791 set info {} 794 792 set user "???" 795 793 if { [info exists env(USER)] } { 796 794 set user $env(USER) 797 795 } 798 796 set session "???" 799 797 if { [info exists env(SESSION)] } { 800 798 set session $env(SESSION) 801 799 } 802 800 lappend info "version" "$Rappture::version" 803 801 lappend info "build" "$Rappture::build" … … 853 851 $_dispatcher cancel !legend 854 852 # disconnected -- no more data sitting on server 855 array unset _datasets 856 array unset _data 857 array unset _colormaps 858 array unset _seeds 859 array unset _dataset2style 860 array unset _obj2datasets 853 array unset _datasets 854 array unset _data 855 array unset _colormaps 856 array unset _seeds 857 array unset _dataset2style 858 array unset _obj2datasets 861 859 } 862 860 … … 878 876 if { $info(-type) == "image" } { 879 877 if 0 { 880 set f [open "last.ppm" "w"] 881 puts $f $bytes 878 set f [open "last.ppm" "w"] 879 fconfigure $f -encoding binary 880 puts -nonewline $f $bytes 882 881 close $f 883 882 } … … 885 884 set time [clock seconds] 886 885 set date [clock format $time] 887 #puts stderr "$date: received image [image width $_image(plot)]x[image height $_image(plot)] image>" 886 #puts stderr "$date: received image [image width $_image(plot)]x[image height $_image(plot)] image>" 888 887 if { $_start > 0 } { 889 888 set finish [clock clicks -milliseconds] … … 950 949 # ---------------------------------------------------------------------- 951 950 itcl::body Rappture::VtkStreamlinesViewer::Rebuild {} { 952 update953 951 set w [winfo width $itk_component(view)] 954 952 set h [winfo height $itk_component(view)] … … 966 964 set _first "" 967 965 if { $_reset } { 968 969 970 971 972 InitSettings axisXGrid axisYGrid axisZGrid axis-mode \973 axesVisible axisLabelsVisible axisMinorTicks966 set _width $w 967 set _height $h 968 $_arcball resize $w $h 969 DoResize 970 InitSettings -xgrid -ygrid -zgrid -axismode \ 971 -axesvisible -axislabelsvisible -axisminorticks 974 972 # This "imgflush" is to force an image returned before vtkvis starts 975 973 # reading a (big) dataset. This will display an empty plot with axes … … 990 988 set bytes [$dataobj vtkdata $comp] 991 989 set length [string length $bytes] 992 if 0 { 990 if 0 { 993 991 set f [open /tmp/vtkstreamlines.vtk "w"] 994 992 fconfigure $f -translation binary -encoding binary 995 puts $f $bytes993 puts -nonewline $f $bytes 996 994 close $f 997 995 } 998 996 if { $_reportClientInfo } { 999 997 set info {} 1000 lappend info "tool_id" [$dataobj hints toolId] 1001 lappend info "tool_name" [$dataobj hints toolName] 1002 lappend info "tool_version" [$dataobj hints toolRevision] 1003 lappend info "tool_title" [$dataobj hints toolTitle] 998 lappend info "tool_id" [$dataobj hints toolid] 999 lappend info "tool_name" [$dataobj hints toolname] 1000 lappend info "tool_title" [$dataobj hints tooltitle] 1001 lappend info "tool_command" [$dataobj hints toolcommand] 1002 lappend info "tool_revision" [$dataobj hints toolrevision] 1004 1003 lappend info "dataset_label" [$dataobj hints label] 1005 1004 lappend info "dataset_size" $length … … 1033 1032 } 1034 1033 } 1035 1036 1037 1034 $itk_component(field) choices delete 0 end 1035 $itk_component(fieldmenu) delete 0 end 1036 array unset _fields 1038 1037 set _curFldName "" 1039 1038 foreach cname [$_first components] { … … 1063 1062 1064 1063 if { $_reset } { 1065 InitSettings streamlinesSeedsVisible streamlinesOpacity \ 1066 streamlinesVisible streamlinesColormap \ 1067 streamlinesLighting \ 1068 streamlinesColormap field \ 1069 volumeVisible volumeEdges volumeLighting volumeOpacity \ 1070 volumeWireframe \ 1071 cutplaneVisible \ 1072 cutplaneXPosition cutplaneYPosition cutplaneZPosition \ 1073 cutplaneXVisible cutplaneYVisible cutplaneZVisible 1074 1075 # Reset the camera and other view parameters 1076 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 1077 $_arcball quaternion $q 1078 if {$_view(ortho)} { 1079 SendCmd "camera mode ortho" 1080 } else { 1081 SendCmd "camera mode persp" 1082 } 1083 DoRotate 1084 PanCamera 1064 InitSettings -streamlinesseedsvisible -streamlinesopacity \ 1065 -streamlinesvisible -streamlinescolormap \ 1066 -streamlineslighting \ 1067 -streamlinescolormap -field \ 1068 -volumevisible -volumeedges -volumelighting -volumeopacity \ 1069 -volumewireframe \ 1070 -cutplanevisible \ 1071 -cutplanexposition -cutplaneyposition -cutplanezposition \ 1072 -cutplanexvisible -cutplaneyvisible -cutplanezvisible 1073 1074 # Reset the camera and other view parameters 1075 $_arcball quaternion [ViewToQuaternion] 1076 if {$_view(-ortho)} { 1077 SendCmd "camera mode ortho" 1078 } else { 1079 SendCmd "camera mode persp" 1080 } 1081 DoRotate 1082 PanCamera 1085 1083 Zoom reset 1086 1084 SendCmd "camera reset" … … 1103 1101 itcl::body Rappture::VtkStreamlinesViewer::CurrentDatasets {args} { 1104 1102 set flag [lindex $args 0] 1105 switch -- $flag { 1103 switch -- $flag { 1106 1104 "-all" { 1107 1105 if { [llength $args] > 1 } { … … 1122 1120 set dlist [get -visible] 1123 1121 } 1124 } 1122 } 1125 1123 default { 1126 1124 set dlist $args … … 1150 1148 switch -- $option { 1151 1149 "in" { 1152 set _view( zoom) [expr {$_view(zoom)*1.25}]1153 SendCmd "camera zoom $_view( zoom)"1150 set _view(-zoom) [expr {$_view(-zoom)*1.25}] 1151 SendCmd "camera zoom $_view(-zoom)" 1154 1152 } 1155 1153 "out" { 1156 set _view( zoom) [expr {$_view(zoom)*0.8}]1157 SendCmd "camera zoom $_view( zoom)"1154 set _view(-zoom) [expr {$_view(-zoom)*0.8}] 1155 SendCmd "camera zoom $_view(-zoom)" 1158 1156 } 1159 1157 "reset" { 1160 1158 array set _view { 1161 qw 0.8535531162 qx -0.3535531163 qy 0.3535531164 qz 0.1464471165 zoom 1.01166 xpan 01167 ypan01159 -qw 0.853553 1160 -qx -0.353553 1161 -qy 0.353553 1162 -qz 0.146447 1163 -xpan 0 1164 -ypan 0 1165 -zoom 1.0 1168 1166 } 1169 1167 if { $_first != "" } { … … 1173 1171 } 1174 1172 } 1175 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 1176 $_arcball quaternion $q 1173 $_arcball quaternion [ViewToQuaternion] 1177 1174 DoRotate 1178 1175 SendCmd "camera reset" … … 1182 1179 1183 1180 itcl::body Rappture::VtkStreamlinesViewer::PanCamera {} { 1184 set x $_view( xpan)1185 set y $_view( ypan)1181 set x $_view(-xpan) 1182 set y $_view(-ypan) 1186 1183 SendCmd "camera pan $x $y" 1187 1184 } 1188 1189 1185 1190 1186 # ---------------------------------------------------------------------- … … 1243 1239 foreach tag [CurrentDatasets -visible] { 1244 1240 SendCmdNoWait "dataset getscalar pixel $x $y $tag" 1245 } 1241 } 1246 1242 } 1247 1243 … … 1261 1257 set x [expr $x / double($w)] 1262 1258 set y [expr $y / double($h)] 1263 set _view( xpan) [expr $_view(xpan) + $x]1264 set _view( ypan) [expr $_view(ypan) + $y]1259 set _view(-xpan) [expr $_view(-xpan) + $x] 1260 set _view(-ypan) [expr $_view(-ypan) + $y] 1265 1261 PanCamera 1266 1262 return … … 1284 1280 set _click(x) $x 1285 1281 set _click(y) $y 1286 set _view( xpan) [expr $_view(xpan) - $dx]1287 set _view( ypan) [expr $_view(ypan) - $dy]1282 set _view(-xpan) [expr $_view(-xpan) - $dx] 1283 set _view(-ypan) [expr $_view(-ypan) - $dy] 1288 1284 PanCamera 1289 1285 } … … 1307 1303 itcl::body Rappture::VtkStreamlinesViewer::InitSettings { args } { 1308 1304 foreach spec $args { 1309 if { [info exists _settings($_first -$spec)] } {1305 if { [info exists _settings($_first${spec})] } { 1310 1306 # Reset global setting with dataobj specific setting 1311 set _settings($spec) $_settings($_first -$spec)1307 set _settings($spec) $_settings($_first${spec}) 1312 1308 } 1313 1309 AdjustSetting $spec … … 1327 1323 } 1328 1324 switch -- $what { 1329 "volumeOpacity" { 1325 "-axesvisible" { 1326 set bool $_settings($what) 1327 SendCmd "axis visible all $bool" 1328 } 1329 "-axislabelsvisible" { 1330 set bool $_settings($what) 1331 SendCmd "axis labels all $bool" 1332 } 1333 "-axisminorticks" { 1334 set bool $_settings($what) 1335 SendCmd "axis minticks all $bool" 1336 } 1337 "-axismode" { 1338 set mode [$itk_component(axismode) value] 1339 set mode [$itk_component(axismode) translate $mode] 1340 set _settings($what) $mode 1341 SendCmd "axis flymode $mode" 1342 } 1343 "-cutplaneedges" { 1344 set bool $_settings($what) 1345 SendCmd "cutplane edges $bool" 1346 } 1347 "-cutplanevisible" { 1348 set bool $_settings($what) 1349 SendCmd "cutplane visible $bool" 1350 } 1351 "-cutplanewireframe" { 1352 set bool $_settings($what) 1353 SendCmd "cutplane wireframe $bool" 1354 } 1355 "-cutplanelighting" { 1356 set bool $_settings($what) 1357 SendCmd "cutplane lighting $bool" 1358 } 1359 "-cutplaneopacity" { 1360 set val $_settings($what) 1361 set sval [expr { 0.01 * double($val) }] 1362 SendCmd "cutplane opacity $sval" 1363 } 1364 "-cutplanexvisible" - "-cutplaneyvisible" - "-cutplanezvisible" { 1365 set axis [string range $what 9 9] 1366 set bool $_settings($what) 1367 if { $bool } { 1368 $itk_component(${axis}CutScale) configure -state normal \ 1369 -troughcolor white 1370 } else { 1371 $itk_component(${axis}CutScale) configure -state disabled \ 1372 -troughcolor grey82 1373 } 1374 SendCmd "cutplane axis $axis $bool" 1375 } 1376 "-cutplanexposition" - "-cutplaneyposition" - "-cutplanezposition" { 1377 set axis [string range $what 9 9] 1378 set pos [expr $_settings($what) * 0.01] 1379 SendCmd "cutplane slice ${axis} ${pos}" 1380 set _cutplanePending 0 1381 } 1382 "-field" { 1383 set label [$itk_component(field) value] 1384 set fname [$itk_component(field) translate $label] 1385 set _settings($what) $fname 1386 if { [info exists _fields($fname)] } { 1387 foreach { label units components } $_fields($fname) break 1388 if { $components > 1 } { 1389 set _colorMode vmag 1390 } else { 1391 set _colorMode scalar 1392 } 1393 set _curFldName $fname 1394 set _curFldLabel $label 1395 } else { 1396 puts stderr "unknown field \"$fname\"" 1397 return 1398 } 1399 # Get the new limits because the field changed. 1400 if { ![info exists _limits($_curFldName)] } { 1401 SendCmd "dataset maprange all" 1402 } else { 1403 SendCmd "dataset maprange explicit $_limits($_curFldName) $_curFldName" 1404 } 1405 SendCmd "streamlines colormode $_colorMode $_curFldName" 1406 SendCmd "cutplane colormode $_colorMode $_curFldName" 1407 DrawLegend 1408 } 1409 "-streamlinesseedsvisible" { 1410 set bool $_settings($what) 1411 SendCmd "streamlines seed visible $bool" 1412 } 1413 "-streamlinesnumseeds" { 1414 set density $_settings($what) 1415 EventuallyReseed $density 1416 } 1417 "-streamlinesvisible" { 1418 set bool $_settings($what) 1419 SendCmd "streamlines visible $bool" 1420 if { $bool } { 1421 Rappture::Tooltip::for $itk_component(streamlines) \ 1422 "Hide the streamlines" 1423 } else { 1424 Rappture::Tooltip::for $itk_component(streamlines) \ 1425 "Show the streamlines" 1426 } 1427 } 1428 "-streamlinesmode" { 1429 set mode [$itk_component(streammode) value] 1430 set _settings($what) $mode 1431 switch -- $mode { 1432 "lines" { 1433 SendCmd "streamlines lines" 1434 } 1435 "ribbons" { 1436 SendCmd "streamlines ribbons 3 0" 1437 } 1438 "tubes" { 1439 SendCmd "streamlines tubes 5 3" 1440 } 1441 } 1442 } 1443 "-streamlinescolormap" { 1444 set colormap [$itk_component(colormap) value] 1445 set _settings($what) $colormap 1446 foreach dataset [CurrentDatasets -visible $_first] { 1447 foreach {dataobj comp} [split $dataset -] break 1448 ChangeColormap $dataobj $comp $colormap 1449 } 1450 set _legendPending 1 1451 } 1452 "-streamlinesopacity" { 1453 set val $_settings($what) 1454 set sval [expr { 0.01 * double($val) }] 1455 SendCmd "streamlines opacity $sval" 1456 } 1457 "-streamlinesscale" { 1458 set val $_settings($what) 1459 set sval [expr { 0.01 * double($val) }] 1460 SendCmd "streamlines scale $sval $sval $sval" 1461 } 1462 "-streamlineslighting" { 1463 set bool $_settings($what) 1464 SendCmd "streamlines lighting $bool" 1465 } 1466 "-volumeopacity" { 1330 1467 set val $_settings($what) 1331 1468 set sval [expr { 0.01 * double($val) }] 1332 1469 SendCmd "polydata opacity $sval" 1333 1470 } 1334 " volumeWireframe" {1471 "-volumewireframe" { 1335 1472 set bool $_settings($what) 1336 1473 SendCmd "polydata wireframe $bool" 1337 1474 } 1338 " volumeVisible" {1475 "-volumevisible" { 1339 1476 set bool $_settings($what) 1340 1477 SendCmd "polydata visible $bool" … … 1347 1484 } 1348 1485 } 1349 " volumeLighting" {1486 "-volumelighting" { 1350 1487 set bool $_settings($what) 1351 1488 SendCmd "polydata lighting $bool" 1352 1489 } 1353 " volumeEdges" {1490 "-volumeedges" { 1354 1491 set bool $_settings($what) 1355 1492 SendCmd "polydata edges $bool" 1356 1493 } 1357 "axesVisible" { 1358 set bool $_settings($what) 1359 SendCmd "axis visible all $bool" 1360 } 1361 "axisLabelsVisible" { 1362 set bool $_settings($what) 1363 SendCmd "axis labels all $bool" 1364 } 1365 "axisMinorTicks" { 1366 set bool $_settings($what) 1367 SendCmd "axis minticks all $bool" 1368 } 1369 "axisXGrid" - "axisYGrid" - "axisZGrid" { 1370 set axis [string tolower [string range $what 4 4]] 1494 "-xgrid" - "-ygrid" - "-zgrid" { 1495 set axis [string range $what 1 1] 1371 1496 set bool $_settings($what) 1372 1497 SendCmd "axis grid $axis $bool" 1373 }1374 "axis-mode" {1375 set mode [$itk_component(axismode) value]1376 set mode [$itk_component(axismode) translate $mode]1377 set _settings($what) $mode1378 SendCmd "axis flymode $mode"1379 }1380 "cutplaneEdges" {1381 set bool $_settings($what)1382 SendCmd "cutplane edges $bool"1383 }1384 "cutplaneVisible" {1385 set bool $_settings($what)1386 SendCmd "cutplane visible $bool"1387 }1388 "cutplaneWireframe" {1389 set bool $_settings($what)1390 SendCmd "cutplane wireframe $bool"1391 }1392 "cutplaneLighting" {1393 set bool $_settings($what)1394 SendCmd "cutplane lighting $bool"1395 }1396 "cutplaneOpacity" {1397 set val $_settings($what)1398 set sval [expr { 0.01 * double($val) }]1399 SendCmd "cutplane opacity $sval"1400 }1401 "cutplaneXVisible" - "cutplaneYVisible" - "cutplaneZVisible" {1402 set axis [string tolower [string range $what 8 8]]1403 set bool $_settings($what)1404 if { $bool } {1405 $itk_component(${axis}CutScale) configure -state normal \1406 -troughcolor white1407 } else {1408 $itk_component(${axis}CutScale) configure -state disabled \1409 -troughcolor grey821410 }1411 SendCmd "cutplane axis $axis $bool"1412 }1413 "cutplaneXPosition" - "cutplaneYPosition" - "cutplaneZPosition" {1414 set axis [string tolower [string range $what 8 8]]1415 set pos [expr $_settings($what) * 0.01]1416 SendCmd "cutplane slice ${axis} ${pos}"1417 set _cutplanePending 01418 }1419 "streamlinesSeedsVisible" {1420 set bool $_settings($what)1421 SendCmd "streamlines seed visible $bool"1422 }1423 "streamlinesNumSeeds" {1424 set density $_settings($what)1425 EventuallyReseed $density1426 }1427 "streamlinesVisible" {1428 set bool $_settings($what)1429 SendCmd "streamlines visible $bool"1430 if { $bool } {1431 Rappture::Tooltip::for $itk_component(streamlines) \1432 "Hide the streamlines"1433 } else {1434 Rappture::Tooltip::for $itk_component(streamlines) \1435 "Show the streamlines"1436 }1437 }1438 "streamlinesMode" {1439 set mode [$itk_component(streammode) value]1440 set _settings(streamlinesMode) $mode1441 switch -- $mode {1442 "lines" {1443 SendCmd "streamlines lines"1444 }1445 "ribbons" {1446 SendCmd "streamlines ribbons 3 0"1447 }1448 "tubes" {1449 SendCmd "streamlines tubes 5 3"1450 }1451 }1452 }1453 "streamlinesColormap" {1454 set colormap [$itk_component(colormap) value]1455 set _settings(streamlinesColormap) $colormap1456 foreach dataset [CurrentDatasets -visible $_first] {1457 foreach {dataobj comp} [split $dataset -] break1458 ChangeColormap $dataobj $comp $colormap1459 }1460 set _legendPending 11461 }1462 "streamlinesOpacity" {1463 set val $_settings($what)1464 set sval [expr { 0.01 * double($val) }]1465 SendCmd "streamlines opacity $sval"1466 }1467 "streamlinesScale" {1468 set val $_settings($what)1469 set sval [expr { 0.01 * double($val) }]1470 SendCmd "streamlines scale $sval $sval $sval"1471 }1472 "streamlinesLighting" {1473 set bool $_settings($what)1474 SendCmd "streamlines lighting $bool"1475 }1476 "field" {1477 set label [$itk_component(field) value]1478 set fname [$itk_component(field) translate $label]1479 set _settings(field) $fname1480 if { [info exists _fields($fname)] } {1481 foreach { label units components } $_fields($fname) break1482 if { $components > 1 } {1483 set _colorMode vmag1484 } else {1485 set _colorMode scalar1486 }1487 set _curFldName $fname1488 set _curFldLabel $label1489 } else {1490 puts stderr "unknown field \"$fname\""1491 return1492 }1493 # Get the new limits because the field changed.1494 if { ![info exists _limits($_curFldName)] } {1495 SendCmd "dataset maprange all"1496 } else {1497 SendCmd "dataset maprange explicit $_limits($_curFldName) $_curFldName"1498 }1499 SendCmd "streamlines colormode $_colorMode $_curFldName"1500 SendCmd "cutplane colormode $_colorMode $_curFldName"1501 DrawLegend1502 1498 } 1503 1499 default { … … 1584 1580 } 1585 1581 1586 1587 1582 # 1588 1583 # BuildColormap -- … … 1594 1589 set cmap "0.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0" 1595 1590 } 1596 if { ![info exists _settings( volumeOpacity)] } {1597 set _settings( volumeOpacity) $style(-opacity)1598 } 1599 set max $_settings( volumeOpacity)1591 if { ![info exists _settings(-volumeopacity)] } { 1592 set _settings(-volumeopacity) $style(-opacity) 1593 } 1594 set max $_settings(-volumeopacity) 1600 1595 1601 1596 set wmap "0.0 1.0 1.0 1.0" … … 1608 1603 itcl::configbody Rappture::VtkStreamlinesViewer::plotbackground { 1609 1604 if { [isconnected] } { 1610 foreach {r g b} [Color2RGB $itk_option(-plotbackground)] break1611 SendCmd "screen bgcolor $r $g $b"1605 set rgb [Color2RGB $itk_option(-plotbackground)] 1606 SendCmd "screen bgcolor $rgb" 1612 1607 } 1613 1608 } … … 1618 1613 itcl::configbody Rappture::VtkStreamlinesViewer::plotforeground { 1619 1614 if { [isconnected] } { 1620 foreach {r g b} [Color2RGB $itk_option(-plotforeground)] break 1621 #fix this! 1622 #SendCmd "color background $r $g $b" 1615 set rgb [Color2RGB $itk_option(-plotforeground)] 1616 SendCmd "axis color all $rgb" 1617 SendCmd "outline color $rgb" 1618 SendCmd "cutplane color $rgb" 1623 1619 } 1624 1620 } … … 1636 1632 checkbutton $inner.volume \ 1637 1633 -text "Show Volume" \ 1638 -variable [itcl::scope _settings( volumeVisible)] \1639 -command [itcl::code $this AdjustSetting volumeVisible] \1634 -variable [itcl::scope _settings(-volumevisible)] \ 1635 -command [itcl::code $this AdjustSetting -volumevisible] \ 1640 1636 -font "Arial 9" 1641 1637 1642 1638 checkbutton $inner.wireframe \ 1643 1639 -text "Show Wireframe" \ 1644 -variable [itcl::scope _settings( volumeWireframe)] \1645 -command [itcl::code $this AdjustSetting volumeWireframe] \1640 -variable [itcl::scope _settings(-volumewireframe)] \ 1641 -command [itcl::code $this AdjustSetting -volumewireframe] \ 1646 1642 -font "Arial 9" 1647 1643 1648 1644 checkbutton $inner.lighting \ 1649 1645 -text "Enable Lighting" \ 1650 -variable [itcl::scope _settings( volumeLighting)] \1651 -command [itcl::code $this AdjustSetting volumeLighting] \1646 -variable [itcl::scope _settings(-volumelighting)] \ 1647 -command [itcl::code $this AdjustSetting -volumelighting] \ 1652 1648 -font "Arial 9" 1653 1649 1654 1650 checkbutton $inner.edges \ 1655 1651 -text "Show Edges" \ 1656 -variable [itcl::scope _settings( volumeEdges)] \1657 -command [itcl::code $this AdjustSetting volumeEdges] \1652 -variable [itcl::scope _settings(-volumeedges)] \ 1653 -command [itcl::code $this AdjustSetting -volumeedges] \ 1658 1654 -font "Arial 9" 1659 1655 1660 1656 label $inner.opacity_l -text "Opacity" -font "Arial 9" 1661 1657 ::scale $inner.opacity -from 0 -to 100 -orient horizontal \ 1662 -variable [itcl::scope _settings( volumeOpacity)] \1658 -variable [itcl::scope _settings(-volumeopacity)] \ 1663 1659 -width 10 \ 1664 1660 -showvalue off \ 1665 -command [itcl::code $this AdjustSetting volumeOpacity]1661 -command [itcl::code $this AdjustSetting -volumeopacity] 1666 1662 1667 1663 blt::table $inner \ … … 1670 1666 2,0 $inner.edges -anchor w -pady 2 -cspan 3 \ 1671 1667 3,0 $inner.opacity_l -anchor w -pady 2 \ 1672 3,1 $inner.opacity -fill x -pady 2 1668 3,1 $inner.opacity -fill x -pady 2 1673 1669 1674 1670 blt::table configure $inner r* c* -resize none 1675 1671 blt::table configure $inner r4 c1 -resize expand 1676 1672 } 1677 1678 1673 1679 1674 itcl::body Rappture::VtkStreamlinesViewer::BuildStreamsTab {} { … … 1689 1684 checkbutton $inner.streamlines \ 1690 1685 -text "Show Streamlines" \ 1691 -variable [itcl::scope _settings( streamlinesVisible)] \1692 -command [itcl::code $this AdjustSetting streamlinesVisible] \1686 -variable [itcl::scope _settings(-streamlinesvisible)] \ 1687 -command [itcl::code $this AdjustSetting -streamlinesvisible] \ 1693 1688 -font "Arial 9" 1694 1689 1695 1690 checkbutton $inner.lighting \ 1696 1691 -text "Enable Lighting" \ 1697 -variable [itcl::scope _settings( streamlinesLighting)] \1698 -command [itcl::code $this AdjustSetting streamlinesLighting] \1692 -variable [itcl::scope _settings(-streamlineslighting)] \ 1693 -command [itcl::code $this AdjustSetting -streamlineslighting] \ 1699 1694 -font "Arial 9" 1700 1695 1701 1696 checkbutton $inner.seeds \ 1702 1697 -text "Show Seeds" \ 1703 -variable [itcl::scope _settings( streamlinesSeedsVisible)] \1704 -command [itcl::code $this AdjustSetting streamlinesSeedsVisible] \1698 -variable [itcl::scope _settings(-streamlinesseedsvisible)] \ 1699 -command [itcl::code $this AdjustSetting -streamlinesseedsvisible] \ 1705 1700 -font "Arial 9" 1706 1701 1707 label $inner.mode_l -text "Mode" -font "Arial 9" 1702 label $inner.mode_l -text "Mode" -font "Arial 9" 1708 1703 itk_component add streammode { 1709 1704 Rappture::Combobox $inner.mode -width 10 -editable no … … 1712 1707 "lines" "lines" \ 1713 1708 "ribbons" "ribbons" \ 1714 "tubes" "tubes" 1715 $itk_component(streammode) value $_settings( streamlinesMode)1716 bind $inner.mode <<Value>> [itcl::code $this AdjustSetting streamlinesMode]1709 "tubes" "tubes" 1710 $itk_component(streammode) value $_settings(-streamlinesmode) 1711 bind $inner.mode <<Value>> [itcl::code $this AdjustSetting -streamlinesmode] 1717 1712 1718 1713 label $inner.opacity_l -text "Opacity" -font "Arial 9" 1719 1714 ::scale $inner.opacity -from 0 -to 100 -orient horizontal \ 1720 -variable [itcl::scope _settings( streamlinesOpacity)] \1715 -variable [itcl::scope _settings(-streamlinesopacity)] \ 1721 1716 -width 10 \ 1722 1717 -showvalue off \ 1723 -command [itcl::code $this AdjustSetting streamlinesOpacity]1718 -command [itcl::code $this AdjustSetting -streamlinesopacity] 1724 1719 1725 1720 label $inner.density_l -text "No. Seeds" -font "Arial 9" 1726 1721 ::scale $inner.density -from 1 -to 1000 -orient horizontal \ 1727 -variable [itcl::scope _settings( streamlinesNumSeeds)] \1722 -variable [itcl::scope _settings(-streamlinesnumseeds)] \ 1728 1723 -width 10 \ 1729 1724 -showvalue on \ 1730 -command [itcl::code $this AdjustSetting streamlinesNumSeeds]1725 -command [itcl::code $this AdjustSetting -streamlinesnumseeds] 1731 1726 1732 1727 label $inner.scale_l -text "Scale" -font "Arial 9" 1733 1728 ::scale $inner.scale -from 1 -to 100 -orient horizontal \ 1734 -variable [itcl::scope _settings( streamlinesScale)] \1729 -variable [itcl::scope _settings(-streamlinesscale)] \ 1735 1730 -width 10 \ 1736 1731 -showvalue off \ 1737 -command [itcl::code $this AdjustSetting streamlinesScale]1738 1739 label $inner.field_l -text "Color by" -font "Arial 9" 1732 -command [itcl::code $this AdjustSetting -streamlinesscale] 1733 1734 label $inner.field_l -text "Color by" -font "Arial 9" 1740 1735 itk_component add field { 1741 1736 Rappture::Combobox $inner.field -width 10 -editable no 1742 1737 } 1743 1738 bind $inner.field <<Value>> \ 1744 [itcl::code $this AdjustSetting field]1745 1746 label $inner.colormap_l -text "Colormap" -font "Arial 9" 1739 [itcl::code $this AdjustSetting -field] 1740 1741 label $inner.colormap_l -text "Colormap" -font "Arial 9" 1747 1742 itk_component add colormap { 1748 1743 Rappture::Combobox $inner.colormap -width 10 -editable no … … 1752 1747 $itk_component(colormap) value "BCGYR" 1753 1748 bind $inner.colormap <<Value>> \ 1754 [itcl::code $this AdjustSetting streamlinesColormap]1749 [itcl::code $this AdjustSetting -streamlinescolormap] 1755 1750 1756 1751 blt::table $inner \ … … 1783 1778 1784 1779 checkbutton $inner.visible \ 1785 -text " ShowAxes" \1786 -variable [itcl::scope _settings( axesVisible)] \1787 -command [itcl::code $this AdjustSetting axesVisible] \1780 -text "Axes" \ 1781 -variable [itcl::scope _settings(-axesvisible)] \ 1782 -command [itcl::code $this AdjustSetting -axesvisible] \ 1788 1783 -font "Arial 9" 1789 1784 1790 1785 checkbutton $inner.labels \ 1791 -text " ShowAxis Labels" \1792 -variable [itcl::scope _settings( axisLabelsVisible)] \1793 -command [itcl::code $this AdjustSetting axisLabelsVisible] \1786 -text "Axis Labels" \ 1787 -variable [itcl::scope _settings(-axislabelsvisible)] \ 1788 -command [itcl::code $this AdjustSetting -axislabelsvisible] \ 1794 1789 -font "Arial 9" 1795 1790 label $inner.grid_l -text "Grid" -font "Arial 9" 1796 1791 checkbutton $inner.xgrid \ 1797 -text " Show X Grid" \1798 -variable [itcl::scope _settings( axisXGrid)] \1799 -command [itcl::code $this AdjustSetting axisXGrid] \1792 -text "X" \ 1793 -variable [itcl::scope _settings(-xgrid)] \ 1794 -command [itcl::code $this AdjustSetting -xgrid] \ 1800 1795 -font "Arial 9" 1801 1796 checkbutton $inner.ygrid \ 1802 -text " Show Y Grid" \1803 -variable [itcl::scope _settings( axisYGrid)] \1804 -command [itcl::code $this AdjustSetting axisYGrid] \1797 -text "Y" \ 1798 -variable [itcl::scope _settings(-ygrid)] \ 1799 -command [itcl::code $this AdjustSetting -ygrid] \ 1805 1800 -font "Arial 9" 1806 1801 checkbutton $inner.zgrid \ 1807 -text " Show Z Grid" \1808 -variable [itcl::scope _settings( axisZGrid)] \1809 -command [itcl::code $this AdjustSetting axisZGrid] \1802 -text "Z" \ 1803 -variable [itcl::scope _settings(-zgrid)] \ 1804 -command [itcl::code $this AdjustSetting -zgrid] \ 1810 1805 -font "Arial 9" 1811 1806 checkbutton $inner.minorticks \ 1812 1807 -text "Minor Ticks" \ 1813 -variable [itcl::scope _settings( axisMinorTicks)] \1814 -command [itcl::code $this AdjustSetting axisMinorTicks] \1808 -variable [itcl::scope _settings(-axisminorticks)] \ 1809 -command [itcl::code $this AdjustSetting -axisminorticks] \ 1815 1810 -font "Arial 9" 1816 1811 1817 label $inner.mode_l -text "Mode" -font "Arial 9" 1812 label $inner.mode_l -text "Mode" -font "Arial 9" 1818 1813 1819 1814 itk_component add axismode { … … 1824 1819 "closest_triad" "closest" \ 1825 1820 "furthest_triad" "farthest" \ 1826 "outer_edges" "outer" 1827 $itk_component(axismode) value "static"1828 bind $inner.mode <<Value>> [itcl::code $this AdjustSetting axis-mode]1821 "outer_edges" "outer" 1822 $itk_component(axismode) value $_settings(-axismode) 1823 bind $inner.mode <<Value>> [itcl::code $this AdjustSetting -axismode] 1829 1824 1830 1825 blt::table $inner \ … … 1862 1857 0,0 $inner.view_l -anchor e -pady 2 \ 1863 1858 0,1 $inner.view -anchor w -pady 2 1859 blt::table configure $inner r0 -resize none 1864 1860 1865 1861 set labels { qx qy qz qw xpan ypan zoom } … … 1868 1864 label $inner.${tag}label -text $tag -font "Arial 9" 1869 1865 entry $inner.${tag} -font "Arial 9" -bg white \ 1870 -textvariable [itcl::scope _view($tag)] 1871 bind $inner.${tag} <KeyPress-Return> \ 1872 [itcl::code $this camera set ${tag}] 1866 -textvariable [itcl::scope _view(-$tag)] 1867 bind $inner.${tag} <Return> \ 1868 [itcl::code $this camera set -${tag}] 1869 bind $inner.${tag} <KP_Enter> \ 1870 [itcl::code $this camera set -${tag}] 1873 1871 blt::table $inner \ 1874 1872 $row,0 $inner.${tag}label -anchor e -pady 2 \ … … 1879 1877 checkbutton $inner.ortho \ 1880 1878 -text "Orthographic Projection" \ 1881 -variable [itcl::scope _view( ortho)] \1882 -command [itcl::code $this camera set ortho] \1879 -variable [itcl::scope _view(-ortho)] \ 1880 -command [itcl::code $this camera set -ortho] \ 1883 1881 -font "Arial 9" 1884 1882 blt::table $inner \ … … 1887 1885 incr row 1888 1886 1889 blt::table configure $inner c* r*-resize none1887 blt::table configure $inner c* -resize none 1890 1888 blt::table configure $inner c2 -resize expand 1891 1889 blt::table configure $inner r$row -resize expand … … 1895 1893 1896 1894 set fg [option get $itk_component(hull) font Font] 1897 1895 1898 1896 set inner [$itk_component(main) insert end \ 1899 1897 -title "Cutplane Settings" \ 1900 -icon [Rappture::icon cutbutton]] 1898 -icon [Rappture::icon cutbutton]] 1901 1899 1902 1900 $inner configure -borderwidth 4 … … 1904 1902 checkbutton $inner.visible \ 1905 1903 -text "Show Cutplanes" \ 1906 -variable [itcl::scope _settings( cutplaneVisible)] \1907 -command [itcl::code $this AdjustSetting cutplaneVisible] \1904 -variable [itcl::scope _settings(-cutplanevisible)] \ 1905 -command [itcl::code $this AdjustSetting -cutplanevisible] \ 1908 1906 -font "Arial 9" 1909 1907 1910 1908 checkbutton $inner.wireframe \ 1911 1909 -text "Show Wireframe" \ 1912 -variable [itcl::scope _settings( cutplaneWireframe)] \1913 -command [itcl::code $this AdjustSetting cutplaneWireframe] \1910 -variable [itcl::scope _settings(-cutplanewireframe)] \ 1911 -command [itcl::code $this AdjustSetting -cutplanewireframe] \ 1914 1912 -font "Arial 9" 1915 1913 1916 1914 checkbutton $inner.lighting \ 1917 1915 -text "Enable Lighting" \ 1918 -variable [itcl::scope _settings( cutplaneLighting)] \1919 -command [itcl::code $this AdjustSetting cutplaneLighting] \1916 -variable [itcl::scope _settings(-cutplanelighting)] \ 1917 -command [itcl::code $this AdjustSetting -cutplanelighting] \ 1920 1918 -font "Arial 9" 1921 1919 1922 1920 checkbutton $inner.edges \ 1923 1921 -text "Show Edges" \ 1924 -variable [itcl::scope _settings( cutplaneEdges)] \1925 -command [itcl::code $this AdjustSetting cutplaneEdges] \1922 -variable [itcl::scope _settings(-cutplaneedges)] \ 1923 -command [itcl::code $this AdjustSetting -cutplaneedges] \ 1926 1924 -font "Arial 9" 1927 1925 1928 1926 label $inner.opacity_l -text "Opacity" -font "Arial 9" 1929 1927 ::scale $inner.opacity -from 0 -to 100 -orient horizontal \ 1930 -variable [itcl::scope _settings( cutplaneOpacity)] \1928 -variable [itcl::scope _settings(-cutplaneopacity)] \ 1931 1929 -width 10 \ 1932 1930 -showvalue off \ 1933 -command [itcl::code $this AdjustSetting cutplaneOpacity]1934 $inner.opacity set $_settings( cutplaneOpacity)1931 -command [itcl::code $this AdjustSetting -cutplaneopacity] 1932 $inner.opacity set $_settings(-cutplaneopacity) 1935 1933 1936 1934 # X-value slicer... … … 1939 1937 -onimage [Rappture::icon x-cutplane-red] \ 1940 1938 -offimage [Rappture::icon x-cutplane-red] \ 1941 -command [itcl::code $this AdjustSetting cutplaneXVisible] \1942 -variable [itcl::scope _settings( cutplaneXVisible)]1939 -command [itcl::code $this AdjustSetting -cutplanexvisible] \ 1940 -variable [itcl::scope _settings(-cutplanexvisible)] 1943 1941 } 1944 1942 Rappture::Tooltip::for $itk_component(xCutButton) \ … … 1951 1949 -borderwidth 1 -highlightthickness 0 \ 1952 1950 -command [itcl::code $this EventuallySetCutplane x] \ 1953 -variable [itcl::scope _settings( cutplaneXPosition)] \1954 1951 -variable [itcl::scope _settings(-cutplanexposition)] \ 1952 -foreground red3 -font "Arial 9 bold" 1955 1953 } { 1956 1954 usual … … 1968 1966 -onimage [Rappture::icon y-cutplane-green] \ 1969 1967 -offimage [Rappture::icon y-cutplane-green] \ 1970 -command [itcl::code $this AdjustSetting cutplaneYVisible] \1971 -variable [itcl::scope _settings( cutplaneYVisible)]1968 -command [itcl::code $this AdjustSetting -cutplaneyvisible] \ 1969 -variable [itcl::scope _settings(-cutplaneyvisible)] 1972 1970 } 1973 1971 Rappture::Tooltip::for $itk_component(yCutButton) \ … … 1980 1978 -borderwidth 1 -highlightthickness 0 \ 1981 1979 -command [itcl::code $this EventuallySetCutplane y] \ 1982 -variable [itcl::scope _settings( cutplaneYPosition)] \1983 1980 -variable [itcl::scope _settings(-cutplaneyposition)] \ 1981 -foreground green3 -font "Arial 9 bold" 1984 1982 } { 1985 1983 usual … … 1997 1995 -onimage [Rappture::icon z-cutplane-blue] \ 1998 1996 -offimage [Rappture::icon z-cutplane-blue] \ 1999 -command [itcl::code $this AdjustSetting cutplaneZVisible] \2000 -variable [itcl::scope _settings( cutplaneZVisible)]1997 -command [itcl::code $this AdjustSetting -cutplanezvisible] \ 1998 -variable [itcl::scope _settings(-cutplanezvisible)] 2001 1999 } 2002 2000 Rappture::Tooltip::for $itk_component(zCutButton) \ … … 2009 2007 -borderwidth 1 -highlightthickness 0 \ 2010 2008 -command [itcl::code $this EventuallySetCutplane z] \ 2011 -variable [itcl::scope _settings( cutplaneZPosition)] \2012 2009 -variable [itcl::scope _settings(-cutplanezposition)] \ 2010 -foreground blue3 -font "Arial 9 bold" 2013 2011 } { 2014 2012 usual … … 2026 2024 3,0 $inner.opacity_l -anchor w -pady 2 -cspan 1 \ 2027 2025 3,1 $inner.opacity -fill x -pady 2 -cspan 3 \ 2028 2026 4,0 $itk_component(xCutButton) -anchor w -padx 2 -pady 2 \ 2029 2027 5,0 $itk_component(yCutButton) -anchor w -padx 2 -pady 2 \ 2030 2028 6,0 $itk_component(zCutButton) -anchor w -padx 2 -pady 2 \ … … 2038 2036 2039 2037 # 2040 # camera -- 2038 # camera -- 2041 2039 # 2042 2040 itcl::body Rappture::VtkStreamlinesViewer::camera {option args} { 2043 switch -- $option { 2041 switch -- $option { 2044 2042 "show" { 2045 2043 puts [array get _view] 2046 2044 } 2047 2045 "set" { 2048 set wh o[lindex $args 0]2049 set x $_view($wh o)2046 set what [lindex $args 0] 2047 set x $_view($what) 2050 2048 set code [catch { string is double $x } result] 2051 2049 if { $code != 0 || !$result } { 2052 2050 return 2053 2051 } 2054 switch -- $wh o{2055 " ortho" {2056 if {$_view( ortho)} {2052 switch -- $what { 2053 "-ortho" { 2054 if {$_view($what)} { 2057 2055 SendCmd "camera mode ortho" 2058 2056 } else { … … 2060 2058 } 2061 2059 } 2062 " xpan" - "ypan" {2060 "-xpan" - "-ypan" { 2063 2061 PanCamera 2064 2062 } 2065 " qx" - "qy" - "qz" - "qw" {2066 set q [ list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]2063 "-qx" - "-qy" - "-qz" - "-qw" { 2064 set q [ViewToQuaternion] 2067 2065 $_arcball quaternion $q 2068 2066 EventuallyRotate $q 2069 2067 } 2070 " zoom" {2071 SendCmd "camera zoom $_view( zoom)"2068 "-zoom" { 2069 SendCmd "camera zoom $_view($what)" 2072 2070 } 2073 2071 } … … 2089 2087 2090 2088 itcl::body Rappture::VtkStreamlinesViewer::GetImage { args } { 2091 if { [image width $_image(download)] > 0 && 2089 if { [image width $_image(download)] > 0 && 2092 2090 [image height $_image(download)] > 0 } { 2093 2091 set bytes [$_image(download) data -format "jpeg -quality 100"] … … 2102 2100 -title "[Rappture::filexfer::label downloadWord] as..." 2103 2101 set inner [$popup component inner] 2104 label $inner.summary -text "" -anchor w 2102 label $inner.summary -text "" -anchor w 2105 2103 radiobutton $inner.vtk_button -text "VTK data file" \ 2106 2104 -variable [itcl::scope _downloadPopup(format)] \ 2107 2105 -font "Helvetica 9 " \ 2108 -value vtk 2106 -value vtk 2109 2107 Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file." 2110 2108 radiobutton $inner.image_button -text "Image File" \ 2111 2109 -variable [itcl::scope _downloadPopup(format)] \ 2112 -value image 2110 -value image 2113 2111 Rappture::Tooltip::for $inner.image_button \ 2114 2112 "Save as digital image." … … 2131 2129 2,0 $inner.image_button -anchor w -cspan 2 -padx { 4 0 } \ 2132 2130 4,1 $inner.cancel -width .9i -fill y \ 2133 4,0 $inner.ok -padx 2 -width .9i -fill y 2131 4,0 $inner.ok -padx 2 -width .9i -fill y 2134 2132 blt::table configure $inner r3 -height 4 2135 2133 blt::table configure $inner r4 -pady 4 … … 2172 2170 SendCmd "polydata add $tag" 2173 2171 SendCmd "polydata colormode constant {} $tag" 2174 set _settings( volumeEdges) $settings(-edges)2175 set _settings( volumeLighting) $settings(-lighting)2176 set _settings( volumeOpacity) $settings(-opacity)2177 set _settings( volumeWireframe) $settings(-wireframe)2178 set _settings( volumeOpacity) [expr $settings(-opacity) * 100.0]2172 set _settings(-volumeedges) $settings(-edges) 2173 set _settings(-volumelighting) $settings(-lighting) 2174 set _settings(-volumeopacity) $settings(-opacity) 2175 set _settings(-volumewireframe) $settings(-wireframe) 2176 set _settings(-volumeopacity) [expr $settings(-opacity) * 100.0] 2179 2177 StopBufferingCommands 2180 2178 SetColormap $dataobj $comp … … 2198 2196 set _legendPending 0 2199 2197 set _title $title 2200 regsub {\(mag\)} $title "" _title 2198 regsub {\(mag\)} $title "" _title 2201 2199 if { [IsConnected] } { 2202 2200 set bytes [ReceiveBytes $size] … … 2225 2223 set font "Arial 8" 2226 2224 set lineht [font metrics $font -linespace] 2227 2225 2228 2226 if { [info exists _fields($fname)] } { 2229 2227 foreach { title units } $_fields($fname) break … … 2234 2232 set title $fname 2235 2233 } 2236 if { $_settings( legendVisible) } {2234 if { $_settings(-legendvisible) } { 2237 2235 set x [expr $w - 2] 2238 2236 if { [$c find withtag "legend"] == "" } { 2239 set y 2 2237 set y 2 2240 2238 $c create text $x $y \ 2241 2239 -anchor ne \ … … 2312 2310 set font "Arial 8" 2313 2311 set lineht [font metrics $font -linespace] 2314 2312 2315 2313 set imgHeight [image height $_image(legend)] 2316 2314 set coords [$c coords colormap] … … 2335 2333 } 2336 2334 set color [eval format "\#%02x%02x%02x" $pixel] 2337 $_image(swatch) put black -to 0 0 23 23 2338 $_image(swatch) put $color -to 1 1 22 22 2335 $_image(swatch) put black -to 0 0 23 23 2336 $_image(swatch) put $color -to 1 1 22 22 2339 2337 .rappturetooltip configure -icon $_image(swatch) 2340 2338 … … 2347 2345 set value 0.0 2348 2346 } 2349 set tipx [expr $x + 15] 2347 set tipx [expr $x + 15] 2350 2348 set tipy [expr $y - 5] 2351 2349 Rappture::Tooltip::text $c "$title $value" 2352 Rappture::Tooltip::tooltip show $c +$tipx,+$tipy 2350 Rappture::Tooltip::tooltip show $c +$tipx,+$tipy 2353 2351 } 2354 2352 … … 2395 2393 # ---------------------------------------------------------------------- 2396 2394 itcl::body Rappture::VtkStreamlinesViewer::Combo {option} { 2397 set c $itk_component(view) 2395 set c $itk_component(view) 2398 2396 switch -- $option { 2399 2397 post { … … 2408 2406 } 2409 2407 deactivate { 2410 $c itemconfigure title -fill white 2408 $c itemconfigure title -fill white 2411 2409 } 2412 2410 invoke { 2413 2411 $itk_component(field) value $_curFldLabel 2414 AdjustSetting field2412 AdjustSetting -field 2415 2413 } 2416 2414 default { … … 2420 2418 } 2421 2419 2422 itcl::body Rappture::VtkStreamlinesViewer::SetOrientation { side } { 2420 itcl::body Rappture::VtkStreamlinesViewer::SetOrientation { side } { 2423 2421 array set positions { 2424 2422 front "1 0 0 0" … … 2429 2427 bottom "0.707107 0.707107 0 0" 2430 2428 } 2431 foreach name { qw qx qyqz } value $positions($side) {2429 foreach name { -qw -qx -qy -qz } value $positions($side) { 2432 2430 set _view($name) $value 2433 } 2434 set q [ list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]2431 } 2432 set q [ViewToQuaternion] 2435 2433 $_arcball quaternion $q 2436 SendCmd "camera orient $q" 2434 SendCmd "camera orient $q" 2437 2435 SendCmd "camera reset" 2438 set _view( xpan) 02439 set _view( ypan) 02440 set _view( zoom) 1.02441 } 2436 set _view(-xpan) 0 2437 set _view(-ypan) 0 2438 set _view(-zoom) 1.0 2439 } -
branches/uq/gui/scripts/vtksurfaceviewer.tcl
r4798 r5121 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 2 2 # ---------------------------------------------------------------------- 3 3 # COMPONENT: vtksurfaceviewer - Vtk 3D boundary surface viewer … … 57 57 public method get {args} 58 58 public method isconnected {} 59 public method limits { colormap } 60 public method parameters {title args} { 61 # do nothing 59 public method parameters {title args} { 60 # do nothing 62 61 } 63 62 public method scale {args} 64 63 65 protected method Connect {}66 protected method CurrentDatasets {args}67 protected method Disconnect {}68 protected method DoResize {}69 protected method DoRotate {}70 protected method AdjustSetting {what {value ""}}71 protected method InitSettings { args }72 protected method Pan {option x y}73 protected method Pick {x y}74 protected method Rebuild {}75 protected method ReceiveDataset { args }76 protected method ReceiveImage { args }77 protected method ReceiveLegend { colormap title vmin vmax size }78 protected method Rotate {option x y}79 protected method Zoom {option}80 81 64 # The following methods are only used by this class. 65 private method AdjustSetting {what {value ""}} 82 66 private method BuildAxisTab {} 83 67 private method BuildCameraTab {} 84 68 private method BuildColormap { name } 85 private method BuildDownloadPopup { widget command } 69 private method BuildDownloadPopup { widget command } 86 70 private method BuildSurfaceTab {} 87 71 private method Combo { option } 72 private method Connect {} 73 private method CurrentDatasets {args} 74 private method Disconnect {} 75 private method DoResize {} 76 private method DoRotate {} 88 77 private method DrawLegend {} 89 private method EnterLegend { x y } 90 private method EventuallyResize { w h } 91 private method EventuallyRotate { q } 92 private method EventuallyRequestLegend {} 93 private method GetImage { args } 94 private method GetVtkData { args } 95 private method IsValidObject { dataobj } 78 private method EnterLegend { x y } 79 private method EventuallyRequestLegend {} 80 private method EventuallyResize { w h } 81 private method EventuallyRotate { q } 82 private method GetImage { args } 83 private method GetVtkData { args } 84 private method InitSettings { args } 85 private method IsValidObject { dataobj } 96 86 private method LeaveLegend {} 97 private method MotionLegend { x y } 87 private method MotionLegend { x y } 88 private method Pan {option x y} 98 89 private method PanCamera {} 90 private method Pick {x y} 91 private method QuaternionToView { q } { 92 foreach { _view(-qw) _view(-qx) _view(-qy) _view(-qz) } $q break 93 } 94 private method Rebuild {} 95 private method ReceiveDataset { args } 96 private method ReceiveImage { args } 97 private method ReceiveLegend { colormap title vmin vmax size } 99 98 private method RequestLegend {} 99 private method Rotate {option x y} 100 private method SetCurrentColormap { color } 100 101 private method SetLegendTip { x y } 101 private method SetObjectStyle { dataobj comp } 102 private method SetCurrentColormap { color } 102 private method SetObjectStyle { dataobj comp } 103 103 private method SetOrientation { side } 104 104 private method UpdateContourList {} 105 private method ViewToQuaternion {} { 106 return [list $_view(-qw) $_view(-qx) $_view(-qy) $_view(-qz)] 107 } 108 private method Zoom {option} 105 109 106 110 private variable _arcball "" … … 109 113 private variable _obj2datasets 110 114 private variable _obj2ovride ; # maps dataobj => style override 111 private variable _datasets ; # contains all the dataobj-component 115 private variable _datasets ; # contains all the dataobj-component 112 116 ; # datasets in the server 113 117 private variable _colormaps ; # contains all the colormaps … … 144 148 private variable _legendPending 0 145 149 private variable _field "" 146 private variable _colorMode "scalar"; 147 private variable _fieldNames {} 148 private variable _fields 150 private variable _colorMode "scalar"; # Mode of colormap (vmag or scalar) 151 private variable _fieldNames {} 152 private variable _fields 149 153 private variable _curFldName "" 150 154 private variable _curFldLabel "" … … 188 192 # Initialize the view to some default parameters. 189 193 array set _view { 190 qw 0.853553191 qx -0.353553192 qy0.353553193 qz 0.146447194 zoom 1.0195 xpan 0196 ypan 0197 ortho0194 -ortho 0 195 -qw 0.853553 196 -qx -0.353553 197 -qy 0.353553 198 -qz 0.146447 199 -xpan 0 200 -ypan 0 201 -zoom 1.0 198 202 } 199 203 set _arcball [blt::arcball create 100 100] 200 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 201 $_arcball quaternion $q 204 $_arcball quaternion [ViewToQuaternion] 202 205 203 206 array set _settings { 204 -axesvisible 1 205 -axislabelsvisible 1 206 -background black 207 -colormap BCGYR 208 -colormapvisible 1 209 -field "Default" 210 -isolinecolor white 211 -isolinesvisible 0 212 -legendvisible 1 213 -numcontours 10 214 -surfaceedges 0 215 -surfacelighting 1 216 -surfaceopacity 100 217 -outline 0 218 -surfacevisible 1 219 -surfacewireframe 0 220 -xaxisgrid 0 221 -yaxisgrid 0 222 -zaxisgrid 0 207 -axesvisible 1 208 -axislabels 1 209 -axisminorticks 1 210 -axismode "static" 211 -background black 212 -colormap BCGYR 213 -colormapvisible 1 214 -field "Default" 215 -isolinecolor white 216 -isolinesvisible 0 217 -legendvisible 1 218 -numcontours 10 219 -surfaceedges 0 220 -surfacelighting 1 221 -surfaceopacity 100 222 -outline 0 223 -surfacevisible 1 224 -surfacewireframe 0 225 -xgrid 0 226 -ygrid 0 227 -zgrid 0 223 228 } 224 229 array set _changed { … … 238 243 itk_component add fieldmenu { 239 244 menu $itk_component(plotarea).menu -bg black -fg white -relief flat \ 240 -tearoff 0 245 -tearoff 0 241 246 } { 242 247 usual … … 258 263 259 264 set _map(id) [$c create image 0 0 -anchor nw -image $_image(plot)] 260 set _map(cwidth) -1 261 set _map(cheight) -1 265 set _map(cwidth) -1 266 set _map(cheight) -1 262 267 set _map(zoom) 1.0 263 268 set _map(original) "" … … 306 311 -offimage [Rappture::icon volume-off] \ 307 312 -variable [itcl::scope _settings(-surfacevisible)] \ 308 -command [itcl::code $this AdjustSetting -surfacevisible] 313 -command [itcl::code $this AdjustSetting -surfacevisible] 309 314 } 310 315 $itk_component(surface) select 311 316 Rappture::Tooltip::for $itk_component(surface) \ 312 " Don't displaythe surface"317 "Hide the surface" 313 318 pack $itk_component(surface) -padx 2 -pady 2 314 319 … … 320 325 puts stderr errs=$errs 321 326 } 327 322 328 # Legend 323 324 329 set _image(legend) [image create photo] 325 330 itk_component add legend { 326 canvas $itk_component(plotarea).legend -width 50 -highlightthickness 0 331 canvas $itk_component(plotarea).legend -width 50 -highlightthickness 0 327 332 } { 328 333 usual … … 331 336 } 332 337 333 # Hack around the Tk panewindow. The problem is that the requested 338 # Hack around the Tk panewindow. The problem is that the requested 334 339 # size of the 3d view isn't set until an image is retrieved from 335 340 # the server. So the panewindow uses the tiny size. … … 337 342 pack forget $itk_component(view) 338 343 blt::table $itk_component(plotarea) \ 339 0,0 $itk_component(view) -fill both -reqwidth $w 344 0,0 $itk_component(view) -fill both -reqwidth $w 340 345 blt::table configure $itk_component(plotarea) c1 -resize none 341 346 … … 424 429 425 430 itcl::body Rappture::VtkSurfaceViewer::DoRotate {} { 426 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 427 SendCmd "camera orient $q" 431 SendCmd "camera orient [ViewToQuaternion]" 428 432 set _rotatePending 0 429 433 } … … 449 453 450 454 itcl::body Rappture::VtkSurfaceViewer::EventuallyRotate { q } { 451 foreach { _view(qw) _view(qx) _view(qy) _view(qz) } $q break455 QuaternionToView $q 452 456 if { !$_rotatePending } { 453 457 set _rotatePending 1 454 global rotate_delay 458 global rotate_delay 455 459 $_dispatcher event -after $rotate_delay !rotate 456 460 } … … 497 501 } 498 502 499 500 503 # ---------------------------------------------------------------------- 501 504 # USAGE: delete ?<dataobj1> <dataobj2> ...? … … 552 555 continue 553 556 } 554 if {[info exists _obj2ovride($dataobj-raise)] && 557 if {[info exists _obj2ovride($dataobj-raise)] && 555 558 $_obj2ovride($dataobj-raise)} { 556 559 set dlist [linsert $dlist 0 $dataobj] … … 580 583 } 581 584 return $dlist 582 } 585 } 583 586 -image { 584 587 if {[llength $args] != 2} { … … 782 785 # disconnected -- no more data sitting on server 783 786 set _outbuf "" 784 array unset _datasets 785 array unset _data 786 array unset _colormaps 787 array unset _seeds 788 array unset _dataset2style 789 array unset _obj2datasets 787 array unset _datasets 788 array unset _data 789 array unset _colormaps 790 array unset _dataset2style 791 array unset _obj2datasets 790 792 } 791 793 … … 807 809 if { $info(-type) == "image" } { 808 810 if 0 { 809 set f [open "last.ppm" "w"] 810 puts $f $bytes 811 set f [open "last.ppm" "w"] 812 fconfigure $f -encoding binary 813 puts -nonewline $f $bytes 811 814 close $f 812 815 } … … 816 819 #set w [image width $_image(plot)] 817 820 #set h [image height $_image(plot)] 818 #puts stderr "$date: received image ${w}x${h} image" 821 #puts stderr "$date: received image ${w}x${h} image" 819 822 if { $_start > 0 } { 820 823 set finish [clock clicks -milliseconds] … … 887 890 # Turn on buffering of commands to the server. We don't want to 888 891 # be preempted by a server disconnect/reconnect (which automatically 889 # generates a new call to Rebuild). 892 # generates a new call to Rebuild). 890 893 StartBufferingCommands 891 894 … … 895 898 $_arcball resize $w $h 896 899 DoResize 897 #898 900 # Reset the camera and other view parameters 899 # 900 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 901 $_arcball quaternion $q 902 if {$_view(ortho)} { 901 $_arcball quaternion [ViewToQuaternion] 902 if {$_view(-ortho)} { 903 903 SendCmd "camera mode ortho" 904 904 } else { … … 908 908 PanCamera 909 909 set _first "" 910 InitSettings -xaxisgrid -yaxisgrid -zaxisgrid -axismode \ 911 -axesvisible -axislabelsvisible 912 foreach axis { x y z } { 913 SendCmd "axis lformat $axis %g" 914 } 910 InitSettings -xgrid -ygrid -zgrid -axismode \ 911 -axesvisible -axislabels -axisminorticks 912 #SendCmd "axis lformat all %g" 915 913 StopBufferingCommands 916 914 SendCmd "imgflush" … … 928 926 if { ![info exists _datasets($tag)] } { 929 927 set bytes [$dataobj vtkdata $comp] 930 if 0 { 931 set f [open "/tmp/surface.vtk" "w"] 932 puts $f $bytes 933 close $f 928 if 0 { 929 set f [open "/tmp/surface.vtk" "w"] 930 fconfigure $f -translation binary -encoding binary 931 puts -nonewline $f $bytes 932 close $f 934 933 } 935 934 set length [string length $bytes] 936 935 if { $_reportClientInfo } { 937 936 set info {} 938 lappend info "tool_id" [$dataobj hints toolId] 939 lappend info "tool_name" [$dataobj hints toolName] 940 lappend info "tool_version" [$dataobj hints toolRevision] 941 lappend info "tool_title" [$dataobj hints toolTitle] 937 lappend info "tool_id" [$dataobj hints toolid] 938 lappend info "tool_name" [$dataobj hints toolname] 939 lappend info "tool_title" [$dataobj hints tooltitle] 940 lappend info "tool_command" [$dataobj hints toolcommand] 941 lappend info "tool_revision" [$dataobj hints toolrevision] 942 942 lappend info "dataset_label" [$dataobj hints label] 943 943 lappend info "dataset_size" $length … … 945 945 SendCmd "clientinfo [list $info]" 946 946 } 947 append _outbuf "dataset add $tag data follows $length\n"947 SendCmd "dataset add $tag data follows $length" 948 948 append _outbuf $bytes 949 949 set _datasets($tag) 1 … … 954 954 # Setting dataset visible enables outline 955 955 # and contour2d 956 956 SendCmd "dataset visible 1 $tag" 957 957 } 958 958 } … … 960 960 961 961 if { $_first != "" } { 962 963 964 962 $itk_component(field) choices delete 0 end 963 $itk_component(fieldmenu) delete 0 end 964 array unset _fields 965 965 set _curFldName "" 966 966 foreach cname [$_first components] { … … 990 990 InitSettings -isolinesvisible -surfacevisible -outline 991 991 if { $_reset } { 992 992 # These are settings that rely on a dataset being loaded. 993 993 InitSettings \ 994 994 -surfacelighting \ 995 995 -field \ 996 996 -surfaceedges -surfacelighting -surfaceopacity \ 997 997 -surfacewireframe \ 998 998 -numcontours 999 999 1000 1000 Zoom reset 1001 1001 foreach axis { x y z } { 1002 1002 # Another problem fixed by a <view>. We looking into a data 1003 1003 # object for the name of the axes. This should be global to 1004 1004 # the viewer itself. 1005 1006 1005 set label [$_first hints ${axis}label] 1006 if { $label == "" } { 1007 1007 set label [string toupper $axis] 1008 1009 1010 1008 } 1009 # May be a space in the axis label. 1010 SendCmd [list axis name $axis $label] 1011 1011 } 1012 1012 if { [array size _fields] < 2 } { … … 1032 1032 itcl::body Rappture::VtkSurfaceViewer::CurrentDatasets {args} { 1033 1033 set flag [lindex $args 0] 1034 switch -- $flag { 1034 switch -- $flag { 1035 1035 "-all" { 1036 1036 if { [llength $args] > 1 } { … … 1051 1051 set dlist [get -visible] 1052 1052 } 1053 } 1053 } 1054 1054 default { 1055 1055 set dlist $args … … 1079 1079 switch -- $option { 1080 1080 "in" { 1081 set _view( zoom) [expr {$_view(zoom)*1.25}]1082 SendCmd "camera zoom $_view( zoom)"1081 set _view(-zoom) [expr {$_view(-zoom)*1.25}] 1082 SendCmd "camera zoom $_view(-zoom)" 1083 1083 } 1084 1084 "out" { 1085 set _view( zoom) [expr {$_view(zoom)*0.8}]1086 SendCmd "camera zoom $_view( zoom)"1085 set _view(-zoom) [expr {$_view(-zoom)*0.8}] 1086 SendCmd "camera zoom $_view(-zoom)" 1087 1087 } 1088 1088 "reset" { 1089 1089 array set _view { 1090 qw0.8535531091 qx-0.3535531092 qy0.3535531093 qz0.1464471094 zoom 1.01095 xpan01096 ypan01090 -qw 0.853553 1091 -qx -0.353553 1092 -qy 0.353553 1093 -qz 0.146447 1094 -xpan 0 1095 -ypan 0 1096 -zoom 1.0 1097 1097 } 1098 1098 if { $_first != "" } { … … 1102 1102 } 1103 1103 } 1104 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 1105 $_arcball quaternion $q 1104 $_arcball quaternion [ViewToQuaternion] 1106 1105 DoRotate 1107 1106 SendCmd "camera reset" … … 1111 1110 1112 1111 itcl::body Rappture::VtkSurfaceViewer::PanCamera {} { 1113 set x $_view( xpan)1114 set y $_view( ypan)1112 set x $_view(-xpan) 1113 set y $_view(-ypan) 1115 1114 SendCmd "camera pan $x $y" 1116 1115 } 1117 1118 1116 1119 1117 # ---------------------------------------------------------------------- … … 1171 1169 itcl::body Rappture::VtkSurfaceViewer::Pick {x y} { 1172 1170 foreach tag [CurrentDatasets -visible] { 1173 SendCmd NoSplash"dataset getscalar pixel $x $y $tag"1174 } 1171 SendCmd "dataset getscalar pixel $x $y $tag" 1172 } 1175 1173 } 1176 1174 … … 1190 1188 set x [expr $x / double($w)] 1191 1189 set y [expr $y / double($h)] 1192 set _view( xpan) [expr $_view(xpan) + $x]1193 set _view( ypan) [expr $_view(ypan) + $y]1190 set _view(-xpan) [expr $_view(-xpan) + $x] 1191 set _view(-ypan) [expr $_view(-ypan) + $y] 1194 1192 PanCamera 1195 1193 return … … 1213 1211 set _click(x) $x 1214 1212 set _click(y) $y 1215 set _view( xpan) [expr $_view(xpan) - $dx]1216 set _view( ypan) [expr $_view(ypan) - $dy]1213 set _view(-xpan) [expr $_view(-xpan) - $dx] 1214 set _view(-ypan) [expr $_view(-ypan) - $dy] 1217 1215 PanCamera 1218 1216 } … … 1256 1254 } 1257 1255 switch -- $what { 1258 "-background" {1259 set bgcolor [$itk_component(background) value]1260 array set fgcolors {1261 "black" "white"1262 "white" "black"1263 "grey" "black"1264 }1265 configure -plotbackground $bgcolor \1266 -plotforeground $fgcolors($bgcolor)1267 $itk_component(view) delete "legend"1268 DrawLegend1269 }1270 1256 "-axesvisible" { 1271 1257 set bool $_settings($what) … … 1279 1265 set bool $_settings($what) 1280 1266 SendCmd "axis minticks all $bool" 1281 }1282 "-xaxisgrid" - "-yaxisgrid" - "-zaxisgrid" {1283 set axis [string tolower [string range $what 1 1]]1284 set bool $_settings($what)1285 SendCmd "axis grid $axis $bool"1286 1267 } 1287 1268 "-axismode" { … … 1291 1272 SendCmd "axis flymode $mode" 1292 1273 } 1274 "-background" { 1275 set bgcolor [$itk_component(background) value] 1276 array set fgcolors { 1277 "black" "white" 1278 "white" "black" 1279 "grey" "black" 1280 } 1281 configure -plotbackground $bgcolor \ 1282 -plotforeground $fgcolors($bgcolor) 1283 $itk_component(view) delete "legend" 1284 DrawLegend 1285 } 1293 1286 "-colormap" { 1294 1287 set _changed($what) 1 … … 1296 1289 set color [$itk_component(colormap) value] 1297 1290 set _settings($what) $color 1298 1299 1300 1291 if { $color == "none" } { 1292 if { $_settings(-colormapvisible) } { 1293 SendCmd "contour2d colormode constant {}" 1301 1294 SendCmd "polydata colormode constant {}" 1302 1303 1304 1305 1306 1295 set _settings(-colormapvisible) 0 1296 } 1297 } else { 1298 if { !$_settings(-colormapvisible) } { 1299 #SendCmd "contour2d colormode $_colorMode $_curFldName" 1307 1300 SendCmd "polydata colormode $_colorMode $_curFldName" 1308 1309 1310 1301 set _settings(-colormapvisible) 1 1302 } 1303 SetCurrentColormap $color 1311 1304 if {$_settings(-colormapdiscrete)} { 1312 1305 set numColors [expr $_settings(-numcontours) + 1] 1313 1306 SendCmd "colormap res $numColors $color" 1314 1307 } 1315 1308 } 1316 1309 StopBufferingCommands 1317 1310 EventuallyRequestLegend 1318 1311 } 1319 1312 "-colormapdiscrete" { … … 1333 1326 EventuallyRequestLegend 1334 1327 } 1328 "-field" { 1329 set label [$itk_component(field) value] 1330 set fname [$itk_component(field) translate $label] 1331 set _settings($what) $fname 1332 if { [info exists _fields($fname)] } { 1333 foreach { label units components } $_fields($fname) break 1334 if { $components > 1 } { 1335 set _colorMode vmag 1336 } else { 1337 set _colorMode scalar 1338 } 1339 set _curFldName $fname 1340 set _curFldLabel $label 1341 } else { 1342 puts stderr "unknown field \"$fname\"" 1343 return 1344 } 1345 SendCmd "dataset scalar $_curFldName" 1346 if { ![info exists _limits($_curFldName)] } { 1347 SendCmd "dataset maprange all" 1348 } else { 1349 SendCmd "dataset maprange explicit $_limits($_curFldName) $_curFldName" 1350 } 1351 #SendCmd "contour2d colormode $_colorMode $_curFldName" 1352 SendCmd "polydata colormode $_colorMode $_curFldName" 1353 SendCmd "camera reset" 1354 UpdateContourList 1355 DrawLegend 1356 } 1357 "-isolinecolor" { 1358 set color [$itk_component(isolineColor) value] 1359 set _settings($what) $color 1360 SendCmd "contour2d linecolor [Color2RGB $color]" 1361 DrawLegend 1362 } 1363 "-isolinesvisible" { 1364 set bool $_settings($what) 1365 SendCmd "contour2d visible $bool" 1366 DrawLegend 1367 } 1368 "-legendvisible" { 1369 if { !$_settings($what) } { 1370 $itk_component(view) delete legend 1371 } 1372 DrawLegend 1373 } 1335 1374 "-numcontours" { 1336 1375 set _settings($what) [$itk_component(numcontours) value] … … 1347 1386 } 1348 1387 } 1349 "- surfacewireframe" {1388 "-outline" { 1350 1389 set bool $_settings($what) 1351 SendCmd "polydata wireframe $bool"1352 } 1353 "- isolinesvisible" {1390 SendCmd "outline visible $bool" 1391 } 1392 "-surfaceedges" { 1354 1393 set bool $_settings($what) 1355 SendCmd "contour2d visible $bool" 1356 DrawLegend 1394 SendCmd "polydata edges $bool" 1395 } 1396 "-surfacelighting" { 1397 set bool $_settings($what) 1398 SendCmd "polydata lighting $bool" 1399 } 1400 "-surfaceopacity" { 1401 set val $_settings($what) 1402 set sval [expr { 0.01 * double($val) }] 1403 SendCmd "polydata opacity $sval" 1357 1404 } 1358 1405 "-surfacevisible" { 1359 1406 set bool $_settings($what) 1360 1407 SendCmd "polydata visible $bool" 1361 1408 if { $bool } { 1362 1409 Rappture::Tooltip::for $itk_component(surface) \ … … 1366 1413 "Show the surface" 1367 1414 } 1368 1369 } 1370 "-surface lighting" {1415 DrawLegend 1416 } 1417 "-surfacewireframe" { 1371 1418 set bool $_settings($what) 1372 SendCmd "polydata lighting $bool" 1373 } 1374 "-surfaceedges" { 1419 SendCmd "polydata wireframe $bool" 1420 } 1421 "-xgrid" - "-ygrid" - "-zgrid" { 1422 set axis [string tolower [string range $what 1 1]] 1375 1423 set bool $_settings($what) 1376 SendCmd "polydata edges $bool" 1377 } 1378 "-outline" { 1379 set bool $_settings($what) 1380 SendCmd "outline visible $bool" 1381 } 1382 "-isolinecolor" { 1383 set color [$itk_component(isolineColor) value] 1384 set _settings($what) $color 1385 SendCmd "contour2d linecolor [Color2RGB $color]" 1386 DrawLegend 1387 } 1388 "-surfaceopacity" { 1389 set val $_settings($what) 1390 set sval [expr { 0.01 * double($val) }] 1391 SendCmd "polydata opacity $sval" 1392 } 1393 "-field" { 1394 set label [$itk_component(field) value] 1395 set fname [$itk_component(field) translate $label] 1396 set _settings($what) $fname 1397 if { [info exists _fields($fname)] } { 1398 foreach { label units components } $_fields($fname) break 1399 if { $components > 1 } { 1400 set _colorMode vmag 1401 } else { 1402 set _colorMode scalar 1403 } 1404 set _curFldName $fname 1405 set _curFldLabel $label 1406 } else { 1407 puts stderr "unknown field \"$fname\"" 1408 return 1409 } 1410 SendCmd "dataset scalar $_curFldName" 1411 if { ![info exists _limits($_curFldName)] } { 1412 SendCmd "dataset maprange all" 1413 } else { 1414 SendCmd "dataset maprange explicit $_limits($_curFldName) $_curFldName" 1415 } 1416 #SendCmd "contour2d colormode $_colorMode $_curFldName" 1417 SendCmd "polydata colormode $_colorMode $_curFldName" 1418 SendCmd "camera reset" 1419 UpdateContourList 1420 DrawLegend 1421 } 1422 "-legendvisible" { 1423 if { !$_settings($what) } { 1424 $itk_component(view) delete legend 1425 } 1426 DrawLegend 1424 SendCmd "axis grid $axis $bool" 1427 1425 } 1428 1426 default { … … 1432 1430 } 1433 1431 1434 1435 1432 # 1436 1433 # RequestLegend -- 1437 1434 # 1438 1435 # Request a new legend from the server. The size of the legend 1439 # is determined from the height of the canvas. 1436 # is determined from the height of the canvas. 1440 1437 # 1441 1438 # This should be called when 1442 # 1443 # 1444 # 1445 # 1446 # 1439 # 1. A new current colormap is set. 1440 # 2. Window is resized. 1441 # 3. The limits of the data have changed. (Just need a redraw). 1442 # 4. Number of isolines have changed. (Just need a redraw). 1443 # 5. Legend becomes visible (Just need a redraw). 1447 1444 # 1448 1445 itcl::body Rappture::VtkSurfaceViewer::RequestLegend {} { … … 1460 1457 } 1461 1458 if { [string match "component*" $fname] } { 1462 1459 set title "" 1463 1460 } else { 1464 1465 1466 1467 1468 1469 1470 1471 1461 if { [info exists _fields($fname)] } { 1462 foreach { title units } $_fields($fname) break 1463 if { $units != "" } { 1464 set title [format "%s (%s)" $title $units] 1465 } 1466 } else { 1467 set title $fname 1468 } 1472 1469 } 1473 1470 # If there's a title too, subtract one more line 1474 1471 if { $title != "" } { 1475 incr h -$lineht 1472 incr h -$lineht 1476 1473 } 1477 1474 # Set the legend on the first heightmap dataset. 1478 1475 if { $_currentColormap != "" } { 1479 1480 1476 set cmap $_currentColormap 1477 SendCmdNoWait "legend $cmap scalar $_curFldName {} $w $h 0" 1481 1478 } 1482 1479 } … … 1498 1495 if { [isconnected] } { 1499 1496 set rgb [Color2RGB $itk_option(-plotforeground)] 1500 1497 SendCmd "axis color all $rgb" 1501 1498 SendCmd "outline color $rgb" 1502 1499 } 1503 }1504 1505 itcl::body Rappture::VtkSurfaceViewer::limits { dataobj } {1506 foreach { limits(xmin) limits(xmax) } [$dataobj limits x] break1507 foreach { limits(ymin) limits(ymax) } [$dataobj limits y] break1508 foreach { limits(zmin) limits(zmax) } [$dataobj limits z] break1509 foreach { limits(vmin) limits(vmax) } [$dataobj limits v] break1510 return [array get limits]1511 1500 } 1512 1501 … … 1569 1558 -font "Arial 9" 1570 1559 1571 label $inner.linecolor_l -text "Isolines" -font "Arial 9" 1560 label $inner.linecolor_l -text "Isolines" -font "Arial 9" 1572 1561 itk_component add isolineColor { 1573 1562 Rappture::Combobox $inner.linecolor -width 10 -editable 0 … … 1583 1572 "red" "red" \ 1584 1573 "white" "white" \ 1585 "none""none"1574 "none" "none" 1586 1575 1587 1576 $itk_component(isolineColor) value "white" 1588 1577 bind $inner.linecolor <<Value>> \ 1589 1590 1591 label $inner.background_l -text "Background" -font "Arial 9" 1578 [itcl::code $this AdjustSetting -isolinecolor] 1579 1580 label $inner.background_l -text "Background" -font "Arial 9" 1592 1581 itk_component add background { 1593 1582 Rappture::Combobox $inner.background -width 10 -editable 0 … … 1596 1585 "black" "black" \ 1597 1586 "white" "white" \ 1598 "grey" "grey" 1587 "grey" "grey" 1599 1588 1600 1589 $itk_component(background) value $_settings(-background) … … 1610 1599 1611 1600 itk_component add field_l { 1612 label $inner.field_l -text "Field" -font "Arial 9" 1601 label $inner.field_l -text "Field" -font "Arial 9" 1613 1602 } { 1614 1603 ignore -font … … 1620 1609 [itcl::code $this AdjustSetting -field] 1621 1610 1622 label $inner.colormap_l -text "Colormap" -font "Arial 9" 1611 label $inner.colormap_l -text "Colormap" -font "Arial 9" 1623 1612 itk_component add colormap { 1624 1613 Rappture::Combobox $inner.colormap -width 10 -editable 0 … … 1646 1635 2,0 $inner.linecolor_l -anchor w -pady 2 \ 1647 1636 2,1 $inner.linecolor -anchor w -pady 2 -fill x \ 1648 1649 1637 3,0 $inner.background_l -anchor w -pady 2 \ 1638 3,1 $inner.background -anchor w -pady 2 -fill x \ 1650 1639 4,0 $inner.numcontours_l -anchor w -pady 2 \ 1651 1640 4,1 $inner.numcontours -anchor w -pady 2 \ … … 1675 1664 1676 1665 checkbutton $inner.visible \ 1677 -text " ShowAxes" \1666 -text "Axes" \ 1678 1667 -variable [itcl::scope _settings(-axesvisible)] \ 1679 1668 -command [itcl::code $this AdjustSetting -axesvisible] \ … … 1681 1670 1682 1671 checkbutton $inner.labels \ 1683 -text " ShowAxis Labels" \1684 -variable [itcl::scope _settings(-axislabels visible)] \1685 -command [itcl::code $this AdjustSetting -axislabels visible] \1672 -text "Axis Labels" \ 1673 -variable [itcl::scope _settings(-axislabels)] \ 1674 -command [itcl::code $this AdjustSetting -axislabels] \ 1686 1675 -font "Arial 9" 1687 1688 checkbutton $inner. gridx\1689 -text " Show X Grid" \1690 -variable [itcl::scope _settings(-x axisgrid)] \1691 -command [itcl::code $this AdjustSetting -x axisgrid] \1676 label $inner.grid_l -text "Grid" -font "Arial 9" 1677 checkbutton $inner.xgrid \ 1678 -text "X" \ 1679 -variable [itcl::scope _settings(-xgrid)] \ 1680 -command [itcl::code $this AdjustSetting -xgrid] \ 1692 1681 -font "Arial 9" 1693 checkbutton $inner. gridy\1694 -text " Show Y Grid" \1695 -variable [itcl::scope _settings(-y axisgrid)] \1696 -command [itcl::code $this AdjustSetting -y axisgrid] \1682 checkbutton $inner.ygrid \ 1683 -text "Y" \ 1684 -variable [itcl::scope _settings(-ygrid)] \ 1685 -command [itcl::code $this AdjustSetting -ygrid] \ 1697 1686 -font "Arial 9" 1698 checkbutton $inner. gridz\1699 -text " Show Z Grid" \1700 -variable [itcl::scope _settings(-z axisgrid)] \1701 -command [itcl::code $this AdjustSetting -z axisgrid] \1687 checkbutton $inner.zgrid \ 1688 -text "Z" \ 1689 -variable [itcl::scope _settings(-zgrid)] \ 1690 -command [itcl::code $this AdjustSetting -zgrid] \ 1702 1691 -font "Arial 9" 1703 1704 label $inner.mode_l -text "Mode" -font "Arial 9" 1692 checkbutton $inner.minorticks \ 1693 -text "Minor Ticks" \ 1694 -variable [itcl::scope _settings(-axisminorticks)] \ 1695 -command [itcl::code $this AdjustSetting -axisminorticks] \ 1696 -font "Arial 9" 1697 1698 label $inner.mode_l -text "Mode" -font "Arial 9" 1705 1699 1706 1700 itk_component add axisMode { … … 1711 1705 "closest_triad" "closest" \ 1712 1706 "furthest_triad" "farthest" \ 1713 "outer_edges" "outer" 1714 $itk_component(axisMode) value "static"1707 "outer_edges" "outer" 1708 $itk_component(axisMode) value $_settings(-axismode) 1715 1709 bind $inner.mode <<Value>> [itcl::code $this AdjustSetting -axismode] 1716 1710 1717 1711 blt::table $inner \ 1718 0,0 $inner.visible -anchor w -cspan 2 \ 1719 1,0 $inner.labels -anchor w -cspan 2 \ 1720 2,0 $inner.gridx -anchor w -cspan 2 \ 1721 3,0 $inner.gridy -anchor w -cspan 2 \ 1722 4,0 $inner.gridz -anchor w -cspan 2 \ 1723 5,0 $inner.mode_l -anchor w -cspan 2 -padx { 2 0 } \ 1724 6,0 $inner.mode -fill x -cspan 2 1712 0,0 $inner.visible -anchor w -cspan 4 \ 1713 1,0 $inner.labels -anchor w -cspan 4 \ 1714 2,0 $inner.minorticks -anchor w -cspan 4 \ 1715 4,0 $inner.grid_l -anchor w \ 1716 4,1 $inner.xgrid -anchor w \ 1717 4,2 $inner.ygrid -anchor w \ 1718 4,3 $inner.zgrid -anchor w \ 1719 5,0 $inner.mode_l -anchor w -padx { 2 0 } \ 1720 5,1 $inner.mode -fill x -cspan 3 1725 1721 1726 1722 blt::table configure $inner r* c* -resize none 1727 blt::table configure $inner r7 c 1-resize expand1728 } 1729 1723 blt::table configure $inner r7 c6 -resize expand 1724 blt::table configure $inner r3 -height 0.125i 1725 } 1730 1726 1731 1727 itcl::body Rappture::VtkSurfaceViewer::BuildCameraTab {} { … … 1747 1743 0,0 $inner.view_l -anchor e -pady 2 \ 1748 1744 0,1 $inner.view -anchor w -pady 2 1745 blt::table configure $inner r0 -resize none 1749 1746 1750 1747 set labels { qx qy qz qw xpan ypan zoom } … … 1753 1750 label $inner.${tag}label -text $tag -font "Arial 9" 1754 1751 entry $inner.${tag} -font "Arial 9" -bg white \ 1755 -textvariable [itcl::scope _view($tag)] 1756 bind $inner.${tag} <KeyPress-Return> \ 1757 [itcl::code $this camera set ${tag}] 1752 -textvariable [itcl::scope _view(-$tag)] 1753 bind $inner.${tag} <Return> \ 1754 [itcl::code $this camera set -${tag}] 1755 bind $inner.${tag} <KP_Enter> \ 1756 [itcl::code $this camera set -${tag}] 1758 1757 blt::table $inner \ 1759 1758 $row,0 $inner.${tag}label -anchor e -pady 2 \ … … 1764 1763 checkbutton $inner.ortho \ 1765 1764 -text "Orthographic Projection" \ 1766 -variable [itcl::scope _view( ortho)] \1767 -command [itcl::code $this camera set ortho] \1765 -variable [itcl::scope _view(-ortho)] \ 1766 -command [itcl::code $this camera set -ortho] \ 1768 1767 -font "Arial 9" 1769 1768 blt::table $inner \ … … 1772 1771 incr row 1773 1772 1774 blt::table configure $inner c* r*-resize none1773 blt::table configure $inner c* -resize none 1775 1774 blt::table configure $inner c2 -resize expand 1776 1775 blt::table configure $inner r$row -resize expand … … 1778 1777 1779 1778 # 1780 # camera -- 1779 # camera -- 1781 1780 # 1782 1781 itcl::body Rappture::VtkSurfaceViewer::camera {option args} { 1783 switch -- $option { 1782 switch -- $option { 1784 1783 "show" { 1785 1784 puts [array get _view] 1786 1785 } 1787 1786 "set" { 1788 set wh o[lindex $args 0]1789 set x $_view($wh o)1787 set what [lindex $args 0] 1788 set x $_view($what) 1790 1789 set code [catch { string is double $x } result] 1791 1790 if { $code != 0 || !$result } { 1792 1791 return 1793 1792 } 1794 switch -- $wh o{1795 " ortho" {1796 if {$_view( ortho)} {1793 switch -- $what { 1794 "-ortho" { 1795 if {$_view($what)} { 1797 1796 SendCmd "camera mode ortho" 1798 1797 } else { … … 1800 1799 } 1801 1800 } 1802 " xpan" - "ypan" {1801 "-xpan" - "-ypan" { 1803 1802 PanCamera 1804 1803 } 1805 " qx" - "qy" - "qz" - "qw" {1806 set q [ list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]1804 "-qx" - "-qy" - "-qz" - "-qw" { 1805 set q [ViewToQuaternion] 1807 1806 $_arcball quaternion $q 1808 1807 EventuallyRotate $q 1809 1808 } 1810 " zoom" {1811 SendCmd "camera zoom $_view( zoom)"1809 "-zoom" { 1810 SendCmd "camera zoom $_view($what)" 1812 1811 } 1813 1812 } … … 1829 1828 1830 1829 itcl::body Rappture::VtkSurfaceViewer::GetImage { args } { 1831 if { [image width $_image(download)] > 0 && 1830 if { [image width $_image(download)] > 0 && 1832 1831 [image height $_image(download)] > 0 } { 1833 1832 set bytes [$_image(download) data -format "jpeg -quality 100"] … … 1842 1841 -title "[Rappture::filexfer::label downloadWord] as..." 1843 1842 set inner [$popup component inner] 1844 label $inner.summary -text "" -anchor w 1843 label $inner.summary -text "" -anchor w 1845 1844 radiobutton $inner.vtk_button -text "VTK data file" \ 1846 1845 -variable [itcl::scope _downloadPopup(format)] \ 1847 1846 -font "Arial 9 " \ 1848 -value vtk 1847 -value vtk 1849 1848 Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file." 1850 1849 radiobutton $inner.image_button -text "Image File" \ 1851 1850 -variable [itcl::scope _downloadPopup(format)] \ 1852 1851 -font "Arial 9 " \ 1853 -value image 1852 -value image 1854 1853 Rappture::Tooltip::for $inner.image_button \ 1855 1854 "Save as digital image." … … 1872 1871 2,0 $inner.image_button -anchor w -cspan 2 -padx { 4 0 } \ 1873 1872 4,1 $inner.cancel -width .9i -fill y \ 1874 4,0 $inner.ok -padx 2 -width .9i -fill y 1873 4,0 $inner.ok -padx 2 -width .9i -fill y 1875 1874 blt::table configure $inner r3 -height 4 1876 1875 blt::table configure $inner r4 -pady 4 … … 1899 1898 array set style [$dataobj style $comp] 1900 1899 if { $dataobj != $_first || $style(-levels) == 1 } { 1901 set style(-opacity) 1 1900 set style(-opacity) 1.0 1902 1901 } 1903 1902 … … 1933 1932 set _settings(-isolinesvisible) $style(-isolinesvisible) 1934 1933 set _settings(-surfacevisible) $style(-surfacevisible) 1935 1934 1936 1935 SendCmd "outline add $tag" 1937 1936 SendCmd "outline color [Color2RGB $itk_option(-plotforeground)] $tag" … … 1949 1948 SendCmd "polydata opacity $style(-opacity) $tag" 1950 1949 set _settings(-surfaceopacity) [expr $style(-opacity) * 100.0] 1951 SetCurrentColormap $style(-color) 1950 SetCurrentColormap $style(-color) 1952 1951 SendCmd "polydata wireframe $style(-wireframe) $tag" 1953 1952 set _settings(-surfacewireframe) $style(-wireframe) … … 2004 2003 set font "Arial 8" 2005 2004 set lineht [font metrics $font -linespace] 2006 2005 2007 2006 set ih [image height $_image(legend)] 2008 2007 set iy [expr $y - ($lineht + 2)] 2009 2008 2010 2009 if { [string match "component*" $fname] } { 2011 2010 set title "" 2012 2011 } else { 2013 2014 2015 2016 2017 2018 2019 2020 2012 if { [info exists _fields($fname)] } { 2013 foreach { title units } $_fields($fname) break 2014 if { $units != "" } { 2015 set title [format "%s (%s)" $title $units] 2016 } 2017 } else { 2018 set title $fname 2019 } 2021 2020 } 2022 2021 # If there's a legend title, increase the offset by the line height. … … 2032 2031 } 2033 2032 set color [eval format "\#%02x%02x%02x" $pixel] 2034 $_image(swatch) put black -to 0 0 23 23 2035 $_image(swatch) put $color -to 1 1 22 22 2033 $_image(swatch) put black -to 0 0 23 23 2034 $_image(swatch) put $color -to 1 1 22 22 2036 2035 .rappturetooltip configure -icon $_image(swatch) 2037 2036 … … 2044 2043 set value 0.0 2045 2044 } 2046 set tx [expr $x + 15] 2045 set tx [expr $x + 15] 2047 2046 set ty [expr $y - 5] 2048 2047 if { [info exists _isolines($y)] } { … … 2051 2050 Rappture::Tooltip::text $c [format "$title %g" $value] 2052 2051 } 2053 Rappture::Tooltip::tooltip show $c +$tx,+$ty 2054 } 2055 2056 # 2057 # ReceiveLegend -- 2058 # 2059 # 2060 # 2061 # 2052 Rappture::Tooltip::tooltip show $c +$tx,+$ty 2053 } 2054 2055 # 2056 # ReceiveLegend -- 2057 # 2058 # Invoked automatically whenever the "legend" command comes in from 2059 # the rendering server. Indicates that binary image data with the 2060 # specified <size> will follow. 2062 2061 # 2063 2062 itcl::body Rappture::VtkSurfaceViewer::ReceiveLegend { colormap title min max size } { 2064 2063 #puts stderr "ReceiveLegend colormap=$colormap title=$title range=$min,$max size=$size" 2065 2064 set _title $title 2066 regsub {\(mag\)} $title "" _title 2065 regsub {\(mag\)} $title "" _title 2067 2066 if { [IsConnected] } { 2068 2067 set bytes [ReceiveBytes $size] … … 2073 2072 #puts stderr "read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>" 2074 2073 if { [catch {DrawLegend} errs] != 0 } { 2075 2076 2074 global errorInfo 2075 puts stderr "errs=$errs errorInfo=$errorInfo" 2077 2076 } 2078 2077 } … … 2093 2092 2094 2093 if { [string match "component*" $fname] } { 2095 2094 set title "" 2096 2095 } else { 2097 2098 2099 2100 2101 2102 2103 2104 2096 if { [info exists _fields($fname)] } { 2097 foreach { title units } $_fields($fname) break 2098 if { $units != "" } { 2099 set title [format "%s (%s)" $title $units] 2100 } 2101 } else { 2102 set title $fname 2103 } 2105 2104 } 2106 2105 set x [expr $w - 2] 2107 2106 if { !$_settings(-legendvisible) } { 2108 2109 2110 } 2107 $c delete legend 2108 return 2109 } 2111 2110 if { [$c find withtag "legend"] == "" } { 2112 set y 2 2113 2111 set y 2 2112 # If there's a legend title, create a text item for the title. 2114 2113 $c create text $x $y \ 2115 2116 2117 -font $font 2114 -anchor ne \ 2115 -fill $itk_option(-plotforeground) -tags "title legend" \ 2116 -font $font 2118 2117 if { $title != "" } { 2119 2118 incr y $lineht 2120 2119 } 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2120 $c create text $x $y \ 2121 -anchor ne \ 2122 -fill $itk_option(-plotforeground) -tags "vmax legend" \ 2123 -font $font 2124 incr y $lineht 2125 $c create image $x $y \ 2126 -anchor ne \ 2127 -image $_image(legend) -tags "colormap legend" 2128 $c create rectangle $x $y 1 1 \ 2129 -fill "" -outline "" -tags "sensor legend" 2130 $c create text $x [expr {$h-2}] \ 2131 -anchor se \ 2132 -fill $itk_option(-plotforeground) -tags "vmin legend" \ 2133 -font $font 2134 $c bind sensor <Enter> [itcl::code $this EnterLegend %x %y] 2135 $c bind sensor <Leave> [itcl::code $this LeaveLegend] 2136 $c bind sensor <Motion> [itcl::code $this MotionLegend %x %y] 2138 2137 } 2139 2138 $c delete isoline … … 2154 2153 } 2155 2154 set tags "isoline legend" 2156 2157 2158 2159 2155 set offset [expr 2 + $lineht] 2156 if { $title != "" } { 2157 incr offset $lineht 2158 } 2160 2159 foreach value $_contourList { 2161 2160 set norm [expr 1.0 - (($value - $vmin) / $range)] … … 2176 2175 if { [info exists _limits($_curFldName)] } { 2177 2176 foreach { vmin vmax } $_limits($_curFldName) break 2178 2179 2177 $c itemconfigure vmin -text [format %g $vmin] 2178 $c itemconfigure vmax -text [format %g $vmax] 2180 2179 } 2181 2180 set y 2 … … 2183 2182 if { $title != "" } { 2184 2183 $c itemconfigure title -text $title 2185 2186 2184 $c coords title $x $y 2185 incr y $lineht 2187 2186 $c raise title 2188 2187 } … … 2207 2206 # ---------------------------------------------------------------------- 2208 2207 itcl::body Rappture::VtkSurfaceViewer::Combo {option} { 2209 set c $itk_component(view) 2208 set c $itk_component(view) 2210 2209 switch -- $option { 2211 2210 post { … … 2222 2221 } 2223 2222 deactivate { 2224 $c itemconfigure title -fill $itk_option(-plotforeground) 2223 $c itemconfigure title -fill $itk_option(-plotforeground) 2225 2224 } 2226 2225 invoke { … … 2240 2239 # Keep track of the colormaps that we build. 2241 2240 if { ![info exists _colormaps($name)] } { 2242 BuildColormap $name 2241 BuildColormap $name 2243 2242 set _colormaps($name) 1 2244 2243 } … … 2262 2261 } 2263 2262 2264 itcl::body Rappture::VtkSurfaceViewer::SetOrientation { side } { 2263 itcl::body Rappture::VtkSurfaceViewer::SetOrientation { side } { 2265 2264 array set positions { 2266 2265 front "1 0 0 0" … … 2271 2270 bottom "0.707107 0.707107 0 0" 2272 2271 } 2273 foreach name { qw qx qyqz } value $positions($side) {2272 foreach name { -qw -qx -qy -qz } value $positions($side) { 2274 2273 set _view($name) $value 2275 } 2276 set q [ list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]2274 } 2275 set q [ViewToQuaternion] 2277 2276 $_arcball quaternion $q 2278 2277 SendCmd "camera orient $q" 2279 2278 SendCmd "camera reset" 2280 set _view( xpan) 02281 set _view( ypan) 02282 set _view( zoom) 1.02283 } 2284 2285 itcl::body Rappture::VtkSurfaceViewer::UpdateContourList {} { 2279 set _view(-xpan) 0 2280 set _view(-ypan) 0 2281 set _view(-zoom) 1.0 2282 } 2283 2284 itcl::body Rappture::VtkSurfaceViewer::UpdateContourList {} { 2286 2285 if { ![info exists _limits($_curFldName)] } { 2287 2286 return … … 2298 2297 blt::vector destroy $v 2299 2298 } 2300 -
branches/uq/gui/scripts/vtkviewer.tcl
r4798 r5121 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 2 2 # ---------------------------------------------------------------------- 3 3 # COMPONENT: vtkviewer - Vtk drawing object viewer … … 58 58 public method isconnected {} 59 59 public method limits { dataobj } 60 public method parameters {title args} { 61 # do nothing 60 public method parameters {title args} { 61 # do nothing 62 62 } 63 63 public method scale {args} 64 64 65 protected method Connect {}66 protected method CurrentDatasets {args}67 protected method Disconnect {}68 protected method DoResize {}69 protected method DoRotate {}70 protected method AdjustSetting {what {value ""}}71 protected method InitSettings { args }72 protected method Pan {option x y}73 protected method Pick {x y}74 protected method Rebuild {}75 protected method ReceiveDataset { args }76 protected method ReceiveImage { args }77 protected method ReceiveLegend { colormap title vmin vmax size }78 protected method Rotate {option x y}79 protected method Zoom {option}80 81 65 # The following methods are only used by this class. 66 private method AdjustSetting {what {value ""}} 82 67 private method BuildAxisTab {} 83 68 private method BuildCameraTab {} 84 69 private method BuildColormap { name styles } 85 70 private method BuildCutawayTab {} 86 private method BuildDownloadPopup { widget command } 71 private method BuildDownloadPopup { widget command } 87 72 private method BuildGlyphsTab {} 88 73 private method BuildMoleculeTab {} 89 74 private method BuildPolydataTab {} 90 75 private method ChangeColormap { dataobj comp color } 76 private method Connect {} 77 private method CurrentDatasets {args} 78 private method Disconnect {} 79 private method DoResize {} 80 private method DoRotate {} 91 81 private method DrawLegend {} 92 private method EnterLegend { x y } 93 private method EventuallyResize { w h } 94 private method EventuallyRotate { q } 95 private method EventuallySetAtomScale { args } 96 private method EventuallySetBondScale { args } 97 private method EventuallySetGlyphsOpacity { args } 98 private method EventuallySetMoleculeOpacity { args } 99 private method EventuallySetMoleculeQuality { args } 100 private method EventuallySetPolydataOpacity { args } 101 private method GetImage { args } 102 private method GetVtkData { args } 103 private method IsValidObject { dataobj } 82 private method EnterLegend { x y } 83 private method EventuallyResize { w h } 84 private method EventuallyRotate { q } 85 private method EventuallySetAtomScale { args } 86 private method EventuallySetBondScale { args } 87 private method EventuallySetGlyphsOpacity { args } 88 private method EventuallySetMoleculeOpacity { args } 89 private method EventuallySetMoleculeQuality { args } 90 private method EventuallySetPolydataOpacity { args } 91 private method GetImage { args } 92 private method GetVtkData { args } 93 private method InitSettings { args } 94 private method IsValidObject { dataobj } 104 95 private method LeaveLegend {} 105 private method MotionLegend { x y } 96 private method MotionLegend { x y } 97 private method Pan {option x y} 106 98 private method PanCamera {} 99 private method Pick {x y} 100 private method QuaternionToView { q } { 101 foreach { _view(-qw) _view(-qx) _view(-qy) _view(-qz) } $q break 102 } 103 private method Rebuild {} 104 private method ReceiveDataset { args } 105 private method ReceiveImage { args } 106 private method ReceiveLegend { colormap title vmin vmax size } 107 107 private method RequestLegend {} 108 private method Rotate {option x y} 108 109 private method SetAtomScale {} 109 110 private method SetBondScale {} … … 113 114 private method SetMoleculeOpacity {} 114 115 private method SetMoleculeQuality {} 115 private method SetObjectStyle { dataobj comp } 116 private method SetObjectStyle { dataobj comp } 116 117 private method SetOpacity { dataset } 117 118 private method SetOrientation { side } 118 119 private method SetPolydataOpacity {} 119 private method Slice {option args} 120 private method Slice {option args} 121 private method ViewToQuaternion {} { 122 return [list $_view(-qw) $_view(-qx) $_view(-qy) $_view(-qz)] 123 } 124 private method Zoom {option} 120 125 121 126 private variable _arcball "" 122 private variable _dlist ""; 127 private variable _dlist ""; # list of data objects 123 128 private variable _obj2datasets 124 private variable _obj2ovride; 125 private variable _datasets; # contains all the dataobj-component126 127 private variable _colormaps; 128 129 private variable _dataset2style; 130 private variable _style2datasets; # maps tf back to list of131 129 private variable _obj2ovride; # maps dataobj => style override 130 private variable _datasets; # contains all the dataobj-component 131 # datasets in the server 132 private variable _colormaps; # contains all the colormaps 133 # in the server. 134 private variable _dataset2style; # maps dataobj-component to transfunc 135 private variable _style2datasets; # maps tf back to list of 136 # dataobj-components using the tf. 132 137 private variable _click; # info used for rotate operations 133 138 private variable _limits; # autoscale min/max for all axes … … 220 225 # Populate parser with commands handle incoming requests 221 226 # 222 $_parser alias image 223 $_parser alias dataset 224 $_parser alias legend 227 $_parser alias image [itcl::code $this ReceiveImage] 228 $_parser alias dataset [itcl::code $this ReceiveDataset] 229 $_parser alias legend [itcl::code $this ReceiveLegend] 225 230 226 231 # Initialize the view to some default parameters. 227 232 array set _view { 228 qw 0.853553229 qx -0.353553230 qy0.353553231 qz 0.146447232 zoom 1.0233 xpan 0234 ypan 0235 ortho0233 -ortho 0 234 -qw 0.853553 235 -qx -0.353553 236 -qy 0.353553 237 -qz 0.146447 238 -xpan 0 239 -ypan 0 240 -zoom 1.0 236 241 } 237 242 set _arcball [blt::arcball create 100 100] 238 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 239 $_arcball quaternion $q 243 $_arcball quaternion [ViewToQuaternion] 240 244 241 245 set _limits(zmin) 0.0 … … 243 247 244 248 array set _axis [subst { 249 labels 1 250 minorticks 1 251 visible 1 245 252 xgrid 0 246 253 ygrid 0 … … 255 262 ydirection -1 256 263 zdirection -1 257 visible 1258 labels 1259 minorticks 1260 264 }] 261 265 array set _settings [subst { 262 legend 1263 266 glyphs-edges 0 264 267 glyphs-lighting 1 … … 268 271 glyphs-visible 1 269 272 glyphs-wireframe 0 270 polydata-edges 0 271 polydata-lighting 1 272 polydata-opacity 100 273 polydata-outline 0 274 polydata-palette BCGYR 275 polydata-visible 1 276 polydata-wireframe 0 273 legend 1 274 molecule-atoms-visible 1 277 275 molecule-atomscale 0.3 276 molecule-bonds-visible 1 278 277 molecule-bondscale 0.075 279 278 molecule-bondstyle "cylinder" 280 molecule-atoms-visible 1281 molecule-bonds-visible 1282 279 molecule-edges 0 283 280 molecule-labels 0 … … 291 288 molecule-visible 1 292 289 molecule-wireframe 0 290 polydata-edges 0 291 polydata-lighting 1 292 polydata-opacity 100 293 polydata-outline 0 294 polydata-palette BCGYR 295 polydata-visible 1 296 polydata-wireframe 0 293 297 }] 294 298 itk_component add view { … … 315 319 316 320 set _map(id) [$c create image 0 0 -anchor nw -image $_image(plot)] 317 set _map(cwidth) -1 318 set _map(cheight) -1 321 set _map(cwidth) -1 322 set _map(cheight) -1 319 323 set _map(zoom) 1.0 320 324 set _map(original) "" … … 358 362 Rappture::Tooltip::for $itk_component(zoomout) "Zoom out" 359 363 360 BuildAxisTab 361 #BuildCutawayTab 362 BuildCameraTab 364 if { [catch { 365 BuildAxisTab 366 #BuildCutawayTab 367 BuildCameraTab 368 } errs] != 0 } { 369 puts stderr errs=$errs 370 } 363 371 364 372 # Legend 365 366 373 set _image(legend) [image create photo] 367 374 itk_component add legend { 368 canvas $itk_component(plotarea).legend -width 50 -highlightthickness 0 375 canvas $itk_component(plotarea).legend -width 50 -highlightthickness 0 369 376 } { 370 377 usual … … 373 380 } 374 381 375 # Hack around the Tk panewindow. The problem is that the requested 382 # Hack around the Tk panewindow. The problem is that the requested 376 383 # size of the 3d view isn't set until an image is retrieved from 377 384 # the server. So the panewindow uses the tiny size. … … 379 386 pack forget $itk_component(view) 380 387 blt::table $itk_component(plotarea) \ 381 0,0 $itk_component(view) -fill both -reqwidth $w 388 0,0 $itk_component(view) -fill both -reqwidth $w 382 389 blt::table configure $itk_component(plotarea) c1 -resize none 383 390 … … 389 396 bind $itk_component(view) <ButtonRelease-1> \ 390 397 [itcl::code $this Rotate release %x %y] 391 bind $itk_component(view) <Configure> \392 [itcl::code $this EventuallyResize %w %h]393 398 394 399 # Bindings for panning via mouse … … 468 473 469 474 itcl::body Rappture::VtkViewer::DoRotate {} { 470 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 471 SendCmd "camera orient $q" 475 SendCmd "camera orient [ViewToQuaternion]" 472 476 set _rotatePending 0 473 477 } … … 484 488 485 489 itcl::body Rappture::VtkViewer::EventuallyRotate { q } { 486 foreach { _view(qw) _view(qx) _view(qy) _view(qz) } $q break490 QuaternionToView $q 487 491 if { !$_rotatePending } { 488 492 set _rotatePending 1 … … 670 674 continue 671 675 } 672 if {[info exists _obj2ovride($dataobj-raise)] && 676 if {[info exists _obj2ovride($dataobj-raise)] && 673 677 $_obj2ovride($dataobj-raise)} { 674 678 set dlist [linsert $dlist 0 $dataobj] … … 698 702 } 699 703 return $dlist 700 } 704 } 701 705 -image { 702 706 if {[llength $args] != 2} { … … 920 924 921 925 # disconnected -- no more data sitting on server 922 array unset _datasets 923 array unset _data 924 array unset _colormaps 926 set _outbuf "" 927 array unset _datasets 928 array unset _data 929 array unset _colormaps 925 930 global readyForNextFrame 926 931 set readyForNextFrame 1 … … 946 951 if { $info(-type) == "image" } { 947 952 if 0 { 948 set f [open "last.ppm" "w"] 953 set f [open "last.ppm" "w"] 949 954 fconfigure $f -encoding binary 950 955 puts -nonewline $f $bytes … … 1024 1029 # Turn on buffering of commands to the server. We don't want to 1025 1030 # be preempted by a server disconnect/reconnect (which automatically 1026 # generates a new call to Rebuild). 1031 # generates a new call to Rebuild). 1027 1032 StartBufferingCommands 1028 1033 … … 1057 1062 continue 1058 1063 } 1064 if 0 { 1065 set f [open /tmp/vtkviewer.vtk "w"] 1066 fconfigure $f -translation binary -encoding binary 1067 puts -nonewline $f $bytes 1068 close $f 1069 } 1059 1070 set length [string length $bytes] 1060 1071 if { $_reportClientInfo } { 1061 1072 set info {} 1062 lappend info "tool_id" [$dataobj hints toolId] 1063 lappend info "tool_name" [$dataobj hints toolName] 1064 lappend info "tool_version" [$dataobj hints toolRevision] 1065 lappend info "tool_title" [$dataobj hints toolTitle] 1073 lappend info "tool_id" [$dataobj hints toolid] 1074 lappend info "tool_name" [$dataobj hints toolname] 1075 lappend info "tool_title" [$dataobj hints tooltitle] 1076 lappend info "tool_command" [$dataobj hints toolcommand] 1077 lappend info "tool_revision" [$dataobj hints toolrevision] 1066 1078 lappend info "dataset_label" [$dataobj hints label] 1067 1079 lappend info "dataset_size" $length 1068 1080 lappend info "dataset_tag" $tag 1069 SendCmd [list "clientinfo" $info]1081 SendCmd "clientinfo [list $info]" 1070 1082 } 1071 1083 SendCmd "dataset add $tag data follows $length" … … 1111 1123 if { $_haveGlyphs } { 1112 1124 InitSettings glyphs-edges glyphs-lighting glyphs-opacity \ 1113 glyphs-visible glyphs-wireframe 1125 glyphs-visible glyphs-wireframe 1114 1126 } 1115 1127 if { $_havePolydata } { 1116 1128 InitSettings polydata-edges polydata-lighting polydata-opacity \ 1117 polydata-visible polydata-wireframe 1129 polydata-visible polydata-wireframe 1118 1130 } 1119 1131 if { $_haveMolecules } { … … 1122 1134 } 1123 1135 1124 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 1125 $_arcball quaternion $q 1136 $_arcball quaternion [ViewToQuaternion] 1126 1137 SendCmd "camera reset" 1127 if { $_view( ortho)} {1138 if { $_view(-ortho)} { 1128 1139 SendCmd "camera mode ortho" 1129 1140 } else { … … 1136 1147 1137 1148 if { $_haveMolecules } { 1138 #InitSettings molecule-representation 1149 #InitSettings molecule-representation 1139 1150 } 1140 1151 set _reset 0 … … 1159 1170 itcl::body Rappture::VtkViewer::CurrentDatasets {args} { 1160 1171 set flag [lindex $args 0] 1161 switch -- $flag { 1172 switch -- $flag { 1162 1173 "-all" { 1163 1174 if { [llength $args] > 1 } { … … 1178 1189 set dlist [get -visible] 1179 1190 } 1180 } 1191 } 1181 1192 default { 1182 1193 set dlist $args … … 1206 1217 switch -- $option { 1207 1218 "in" { 1208 set _view( zoom) [expr {$_view(zoom)*1.25}]1209 SendCmd "camera zoom $_view( zoom)"1219 set _view(-zoom) [expr {$_view(-zoom)*1.25}] 1220 SendCmd "camera zoom $_view(-zoom)" 1210 1221 } 1211 1222 "out" { 1212 set _view( zoom) [expr {$_view(zoom)*0.8}]1213 SendCmd "camera zoom $_view( zoom)"1223 set _view(-zoom) [expr {$_view(-zoom)*0.8}] 1224 SendCmd "camera zoom $_view(-zoom)" 1214 1225 } 1215 1226 "reset" { 1216 1227 array set _view { 1217 qw 0.8535531218 qx -0.3535531219 qy 0.3535531220 qz 0.1464471221 zoom 1.01222 xpan 01223 ypan01228 -qw 0.853553 1229 -qx -0.353553 1230 -qy 0.353553 1231 -qz 0.146447 1232 -xpan 0 1233 -ypan 0 1234 -zoom 1.0 1224 1235 } 1225 1236 if { $_first != "" } { … … 1229 1240 } 1230 1241 } 1231 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 1232 $_arcball quaternion $q 1242 $_arcball quaternion [ViewToQuaternion] 1233 1243 DoRotate 1234 1244 SendCmd "camera reset" … … 1238 1248 1239 1249 itcl::body Rappture::VtkViewer::PanCamera {} { 1240 set x $_view( xpan)1241 set y $_view( ypan)1250 set x $_view(-xpan) 1251 set y $_view(-ypan) 1242 1252 SendCmd "camera pan $x $y" 1243 1253 } … … 1298 1308 foreach tag [CurrentDatasets -visible] { 1299 1309 SendCmd "dataset getscalar pixel $x $y $tag" 1300 } 1310 } 1301 1311 } 1302 1312 … … 1316 1326 set x [expr $x / double($w)] 1317 1327 set y [expr $y / double($h)] 1318 set _view( xpan) [expr $_view(xpan) + $x]1319 set _view( ypan) [expr $_view(ypan) + $y]1328 set _view(-xpan) [expr $_view(-xpan) + $x] 1329 set _view(-ypan) [expr $_view(-ypan) + $y] 1320 1330 PanCamera 1321 1331 return … … 1339 1349 set _click(x) $x 1340 1350 set _click(y) $y 1341 set _view( xpan) [expr $_view(xpan) - $dx]1342 set _view( ypan) [expr $_view(ypan) - $dy]1351 set _view(-xpan) [expr $_view(-xpan) - $dx] 1352 set _view(-ypan) [expr $_view(-ypan) - $dy] 1343 1353 PanCamera 1344 1354 } … … 1667 1677 set type [$dataobj type $comp] 1668 1678 if { $type == "molecule" } { 1669 SendCmd [subst {molecule rscale $_settings(molecule-rscale) $dataset 1670 molecule ascale $_settings(molecule-atomscale) $dataset 1671 molecule bscale $_settings(molecule-bondscale) $dataset 1672 molecule bstyle $_settings(molecule-bondstyle) $dataset 1673 molecule atoms $_settings(molecule-atoms-visible) $dataset 1674 molecule bonds $_settings(molecule-bonds-visible) $dataset}] 1679 StartBufferingCommands 1680 SendCmd [subst {molecule rscale $_settings(molecule-rscale) $dataset}] 1681 SendCmd [subst {molecule ascale $_settings(molecule-atomscale) $dataset}] 1682 SendCmd [subst {molecule bscale $_settings(molecule-bondscale) $dataset}] 1683 SendCmd [subst {molecule bstyle $_settings(molecule-bondstyle) $dataset}] 1684 SendCmd [subst {molecule atoms $_settings(molecule-atoms-visible) $dataset}] 1685 SendCmd [subst {molecule bonds $_settings(molecule-bonds-visible) $dataset}] 1686 StopBufferingCommands 1675 1687 } 1676 1688 } … … 1742 1754 } 1743 1755 } 1744 "axis-xposition" - "axis-yposition" - "axis-zposition" - 1756 "axis-xposition" - "axis-yposition" - "axis-zposition" - 1745 1757 "axis-xdirection" - "axis-ydirection" - "axis-zdirection" { 1746 1758 set axis [string range $what 5 5] … … 1873 1885 itcl::configbody Rappture::VtkViewer::plotbackground { 1874 1886 if { [isconnected] } { 1875 foreach {r g b} [Color2RGB $itk_option(-plotbackground)] break1876 SendCmd "screen bgcolor $r $g $b"1887 set rgb [Color2RGB $itk_option(-plotbackground)] 1888 SendCmd "screen bgcolor $rgb" 1877 1889 } 1878 1890 } … … 1883 1895 itcl::configbody Rappture::VtkViewer::plotforeground { 1884 1896 if { [isconnected] } { 1885 foreach {r g b} [Color2RGB $itk_option(-plotforeground)] break1886 #fix this!1887 #SendCmd "color background $r $g $b"1897 set rgb [Color2RGB $itk_option(-plotforeground)] 1898 SendCmd "axis color all $rgb" 1899 SendCmd "outline color $rgb" 1888 1900 } 1889 1901 } … … 1900 1912 set f [open "$tmpfile" "w"] 1901 1913 fconfigure $f -translation binary -encoding binary 1902 puts $f $data 1914 puts $f $data 1903 1915 close $f 1904 1916 set reader [vtkDataSetReader $tag-xvtkDataSetReader] … … 1994 2006 -variable [itcl::scope _settings(glyphs-visible)] \ 1995 2007 -command [itcl::code $this AdjustSetting glyphs-visible] \ 1996 -font "Arial 9" -anchor w 2008 -font "Arial 9" -anchor w 1997 2009 1998 2010 checkbutton $inner.outline \ … … 2000 2012 -variable [itcl::scope _settings(glyphs-outline)] \ 2001 2013 -command [itcl::code $this AdjustSetting glyphs-outline] \ 2002 -font "Arial 9" -anchor w 2014 -font "Arial 9" -anchor w 2003 2015 2004 2016 checkbutton $inner.wireframe \ … … 2006 2018 -variable [itcl::scope _settings(glyphs-wireframe)] \ 2007 2019 -command [itcl::code $this AdjustSetting glyphs-wireframe] \ 2008 -font "Arial 9" -anchor w 2020 -font "Arial 9" -anchor w 2009 2021 2010 2022 checkbutton $inner.lighting \ … … 2020 2032 -font "Arial 9" -anchor w 2021 2033 2022 label $inner.palette_l -text "Palette" -font "Arial 9" -anchor w 2034 label $inner.palette_l -text "Palette" -font "Arial 9" -anchor w 2023 2035 itk_component add glyphspalette { 2024 2036 Rappture::Combobox $inner.palette -width 10 -editable no … … 2029 2041 [itcl::code $this AdjustSetting glyphs-palette] 2030 2042 2031 label $inner.opacity_l -text "Opacity" -font "Arial 9" -anchor w 2043 label $inner.opacity_l -text "Opacity" -font "Arial 9" -anchor w 2032 2044 ::scale $inner.opacity -from 0 -to 100 -orient horizontal \ 2033 2045 -variable [itcl::scope _settings(glyphs-opacity)] \ … … 2046 2058 5,1 $inner.opacity -fill x -pady 2 \ 2047 2059 6,0 $inner.palette_l -anchor w -pady 2 \ 2048 6,1 $inner.palette -fill x -pady 2 2060 6,1 $inner.palette -fill x -pady 2 2049 2061 2050 2062 blt::table configure $inner r* c* -resize none … … 2066 2078 -variable [itcl::scope _settings(polydata-visible)] \ 2067 2079 -command [itcl::code $this AdjustSetting polydata-visible] \ 2068 -font "Arial 9" -anchor w 2080 -font "Arial 9" -anchor w 2069 2081 2070 2082 checkbutton $inner.outline \ … … 2072 2084 -variable [itcl::scope _settings(polydata-outline)] \ 2073 2085 -command [itcl::code $this AdjustSetting polydata-outline] \ 2074 -font "Arial 9" -anchor w 2086 -font "Arial 9" -anchor w 2075 2087 2076 2088 checkbutton $inner.wireframe \ … … 2078 2090 -variable [itcl::scope _settings(polydata-wireframe)] \ 2079 2091 -command [itcl::code $this AdjustSetting polydata-wireframe] \ 2080 -font "Arial 9" -anchor w 2092 -font "Arial 9" -anchor w 2081 2093 2082 2094 checkbutton $inner.lighting \ … … 2092 2104 -font "Arial 9" -anchor w 2093 2105 2094 label $inner.palette_l -text "Palette" -font "Arial 9" -anchor w 2106 label $inner.palette_l -text "Palette" -font "Arial 9" -anchor w 2095 2107 itk_component add meshpalette { 2096 2108 Rappture::Combobox $inner.palette -width 10 -editable no … … 2101 2113 [itcl::code $this AdjustSetting polydata-palette] 2102 2114 2103 label $inner.opacity_l -text "Opacity" -font "Arial 9" -anchor w 2115 label $inner.opacity_l -text "Opacity" -font "Arial 9" -anchor w 2104 2116 ::scale $inner.opacity -from 0 -to 100 -orient horizontal \ 2105 2117 -variable [itcl::scope _settings(polydata-opacity)] \ … … 2118 2130 5,1 $inner.opacity -fill x -pady 2 \ 2119 2131 6,0 $inner.palette_l -anchor w -pady 2 \ 2120 6,1 $inner.palette -fill x -pady 2 2132 6,1 $inner.palette -fill x -pady 2 2121 2133 2122 2134 blt::table configure $inner r* c* -resize none … … 2135 2147 2136 2148 checkbutton $inner.visible \ 2137 -text " ShowAxes" \2149 -text "Axes" \ 2138 2150 -variable [itcl::scope _axis(visible)] \ 2139 2151 -command [itcl::code $this AdjustSetting axis-visible] \ … … 2141 2153 2142 2154 checkbutton $inner.labels \ 2143 -text " ShowAxis Labels" \2155 -text "Axis Labels" \ 2144 2156 -variable [itcl::scope _axis(labels)] \ 2145 2157 -command [itcl::code $this AdjustSetting axis-labels] \ 2146 2158 -font "Arial 9" 2147 2148 checkbutton $inner. gridx\2149 -text " Show X Grid" \2159 label $inner.grid_l -text "Grid" -font "Arial 9" 2160 checkbutton $inner.xgrid \ 2161 -text "X" \ 2150 2162 -variable [itcl::scope _axis(xgrid)] \ 2151 2163 -command [itcl::code $this AdjustSetting axis-xgrid] \ 2152 2164 -font "Arial 9" 2153 checkbutton $inner. gridy\2154 -text " Show Y Grid" \2165 checkbutton $inner.ygrid \ 2166 -text "Y" \ 2155 2167 -variable [itcl::scope _axis(ygrid)] \ 2156 2168 -command [itcl::code $this AdjustSetting axis-ygrid] \ 2157 2169 -font "Arial 9" 2158 checkbutton $inner. gridz\2159 -text " Show Z Grid" \2170 checkbutton $inner.zgrid \ 2171 -text "Z" \ 2160 2172 -variable [itcl::scope _axis(zgrid)] \ 2161 2173 -command [itcl::code $this AdjustSetting axis-zgrid] \ … … 2167 2179 -font "Arial 9" 2168 2180 2169 label $inner.mode_l -text "Mode" -font "Arial 9" 2181 label $inner.mode_l -text "Mode" -font "Arial 9" 2170 2182 2171 2183 itk_component add axismode { … … 2176 2188 "closest_triad" "closest" \ 2177 2189 "furthest_triad" "farthest" \ 2178 "outer_edges" "outer" 2190 "outer_edges" "outer" 2179 2191 $itk_component(axismode) value "static" 2180 2192 bind $inner.mode <<Value>> [itcl::code $this AdjustSetting axis-mode] … … 2214 2226 0,0 $inner.view_l -anchor e -pady 2 \ 2215 2227 0,1 $inner.view -anchor w -pady 2 2228 blt::table configure $inner r0 -resize none 2216 2229 2217 2230 set labels { qx qy qz qw xpan ypan zoom } … … 2220 2233 label $inner.${tag}label -text $tag -font "Arial 9" 2221 2234 entry $inner.${tag} -font "Arial 9" -bg white \ 2222 -textvariable [itcl::scope _view($tag)] 2223 bind $inner.${tag} <KeyPress-Return> \ 2224 [itcl::code $this camera set ${tag}] 2235 -textvariable [itcl::scope _view(-$tag)] 2236 bind $inner.${tag} <Return> \ 2237 [itcl::code $this camera set -${tag}] 2238 bind $inner.${tag} <KP_Enter> \ 2239 [itcl::code $this camera set -${tag}] 2225 2240 blt::table $inner \ 2226 2241 $row,0 $inner.${tag}label -anchor e -pady 2 \ … … 2231 2246 checkbutton $inner.ortho \ 2232 2247 -text "Orthographic Projection" \ 2233 -variable [itcl::scope _view( ortho)] \2234 -command [itcl::code $this camera set ortho] \2248 -variable [itcl::scope _view(-ortho)] \ 2249 -command [itcl::code $this camera set -ortho] \ 2235 2250 -font "Arial 9" 2236 2251 blt::table $inner \ … … 2239 2254 incr row 2240 2255 2241 blt::table configure $inner c* r*-resize none2256 blt::table configure $inner c* -resize none 2242 2257 blt::table configure $inner c2 -resize expand 2243 2258 blt::table configure $inner r$row -resize expand … … 2247 2262 2248 2263 set fg [option get $itk_component(hull) font Font] 2249 2264 2250 2265 set inner [$itk_component(main) insert end \ 2251 2266 -title "Cutaway Along Axis" \ 2252 -icon [Rappture::icon cutbutton]] 2267 -icon [Rappture::icon cutbutton]] 2253 2268 2254 2269 $inner configure -borderwidth 4 … … 2290 2305 -variable [itcl::scope _axis(xdirection)] 2291 2306 } 2292 set _axis(xdirection) -1 2307 set _axis(xdirection) -1 2293 2308 Rappture::Tooltip::for $itk_component(xDirButton) \ 2294 2309 "Toggle the direction of the X-axis cutaway" … … 2332 2347 Rappture::Tooltip::for $itk_component(yDirButton) \ 2333 2348 "Toggle the direction of the Y-axis cutaway" 2334 set _axis(ydirection) -1 2349 set _axis(ydirection) -1 2335 2350 2336 2351 # Z-value slicer... … … 2369 2384 -variable [itcl::scope _axis(zdirection)] 2370 2385 } 2371 set _axis(zdirection) -1 2386 set _axis(zdirection) -1 2372 2387 Rappture::Tooltip::for $itk_component(zDirButton) \ 2373 2388 "Toggle the direction of the Z-axis cutaway" … … 2437 2452 $inner.rep choices insert end \ 2438 2453 "ballandstick" "Ball and Stick" \ 2439 "spheres" 2440 "sticks" "Sticks"\2441 "rods" 2442 "wireframe" "Wireframe" 2443 "spacefilling" "Space Filling" 2454 "spheres" "Spheres" \ 2455 "sticks" "Sticks" \ 2456 "rods" "Rods" \ 2457 "wireframe" "Wireframe" \ 2458 "spacefilling" "Space Filling" 2444 2459 2445 2460 bind $inner.rep <<Value>> \ … … 2454 2469 } 2455 2470 $inner.rscale choices insert end \ 2456 "atomic" 2457 "covalent" 2458 "van_der_waals" "VDW"\2459 "none" 2471 "atomic" "Atomic" \ 2472 "covalent" "Covalent" \ 2473 "van_der_waals" "VDW" \ 2474 "none" "Constant" 2460 2475 2461 2476 bind $inner.rscale <<Value>> \ … … 2463 2478 $inner.rscale value "Covalent" 2464 2479 2465 label $inner.palette_l -text "Palette" -font "Arial 9" 2480 label $inner.palette_l -text "Palette" -font "Arial 9" 2466 2481 itk_component add moleculepalette { 2467 2482 Rappture::Combobox $inner.palette -width 10 -editable no … … 2528 2543 16,0 $inner.quality_l -anchor w -pady {3 0} \ 2529 2544 17,0 $inner.quality -fill x -padx 2 2530 2545 2531 2546 blt::table configure $inner r* -resize none 2532 2547 blt::table configure $inner r18 -resize expand … … 2534 2549 2535 2550 # 2536 # camera -- 2551 # camera -- 2537 2552 # 2538 2553 itcl::body Rappture::VtkViewer::camera {option args} { 2539 switch -- $option { 2554 switch -- $option { 2540 2555 "show" { 2541 2556 puts [array get _view] 2542 2557 } 2543 2558 "set" { 2544 set wh o[lindex $args 0]2545 set x $_view($wh o)2559 set what [lindex $args 0] 2560 set x $_view($what) 2546 2561 set code [catch { string is double $x } result] 2547 2562 if { $code != 0 || !$result } { 2548 2563 return 2549 2564 } 2550 switch -- $wh o{2551 " ortho" {2552 if {$_view( ortho)} {2565 switch -- $what { 2566 "-ortho" { 2567 if {$_view($what)} { 2553 2568 SendCmd "camera mode ortho" 2554 2569 } else { … … 2556 2571 } 2557 2572 } 2558 " xpan" - "ypan" {2573 "-xpan" - "-ypan" { 2559 2574 PanCamera 2560 2575 } 2561 " qx" - "qy" - "qz" - "qw" {2562 set q [ list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]2576 "-qx" - "-qy" - "-qz" - "-qw" { 2577 set q [ViewToQuaternion] 2563 2578 $_arcball quaternion $q 2564 2579 EventuallyRotate $q 2565 2580 } 2566 " zoom" {2567 SendCmd "camera zoom $_view( zoom)"2581 "-zoom" { 2582 SendCmd "camera zoom $_view($what)" 2568 2583 } 2569 2584 } … … 2585 2600 2586 2601 itcl::body Rappture::VtkViewer::GetImage { args } { 2587 if { [image width $_image(download)] > 0 && 2602 if { [image width $_image(download)] > 0 && 2588 2603 [image height $_image(download)] > 0 } { 2589 2604 set bytes [$_image(download) data -format "jpeg -quality 100"] … … 2598 2613 -title "[Rappture::filexfer::label downloadWord] as..." 2599 2614 set inner [$popup component inner] 2600 label $inner.summary -text "" -anchor w 2615 label $inner.summary -text "" -anchor w 2601 2616 radiobutton $inner.vtk_button -text "VTK data file" \ 2602 2617 -variable [itcl::scope _downloadPopup(format)] \ 2603 2618 -font "Helvetica 9 " \ 2604 -value vtk 2619 -value vtk 2605 2620 Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file." 2606 2621 radiobutton $inner.image_button -text "Image File" \ 2607 2622 -variable [itcl::scope _downloadPopup(format)] \ 2608 -value image 2623 -value image 2609 2624 Rappture::Tooltip::for $inner.image_button \ 2610 2625 "Save as digital image." … … 2627 2642 2,0 $inner.image_button -anchor w -cspan 2 -padx { 4 0 } \ 2628 2643 4,1 $inner.cancel -width .9i -fill y \ 2629 4,0 $inner.ok -padx 2 -width .9i -fill y 2644 4,0 $inner.ok -padx 2 -width .9i -fill y 2630 2645 blt::table configure $inner r3 -height 4 2631 2646 blt::table configure $inner r4 -pady 4 … … 2904 2919 set font "Arial 8" 2905 2920 set lineht [font metrics $font -linespace] 2906 2921 2907 2922 if { $_settings(legend) } { 2908 2923 set x [expr $w - 2] … … 2969 2984 set font "Arial 8" 2970 2985 set lineht [font metrics $font -linespace] 2971 2986 2972 2987 set imgHeight [image height $_image(legend)] 2973 2988 set coords [$c coords colormap] … … 2983 2998 } 2984 2999 set color [eval format "\#%02x%02x%02x" $pixel] 2985 $_image(swatch) put black -to 0 0 23 23 2986 $_image(swatch) put $color -to 1 1 22 22 3000 $_image(swatch) put black -to 0 0 23 23 3001 $_image(swatch) put $color -to 1 1 22 22 2987 3002 .rappturetooltip configure -icon $_image(swatch) 2988 3003 … … 2990 3005 set t [expr 1.0 - (double($imgY) / double($imgHeight-1))] 2991 3006 set value [expr $t * ($_limits(vmax) - $_limits(vmin)) + $_limits(vmin)] 2992 set tipx [expr $x + 15] 3007 set tipx [expr $x + 15] 2993 3008 set tipy [expr $y - 5] 2994 3009 Rappture::Tooltip::text $c "$_title $value" 2995 Rappture::Tooltip::tooltip show $c +$tipx,+$tipy 3010 Rappture::Tooltip::tooltip show $c +$tipx,+$tipy 2996 3011 } 2997 3012 … … 3026 3041 } 3027 3042 3028 itcl::body Rappture::VtkViewer::SetOrientation { side } { 3043 itcl::body Rappture::VtkViewer::SetOrientation { side } { 3029 3044 array set positions { 3030 3045 front "1 0 0 0" … … 3035 3050 bottom "0.707107 0.707107 0 0" 3036 3051 } 3037 foreach name { qw qx qyqz } value $positions($side) {3052 foreach name { -qw -qx -qy -qz } value $positions($side) { 3038 3053 set _view($name) $value 3039 } 3040 set q [ list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]3054 } 3055 set q [ViewToQuaternion] 3041 3056 $_arcball quaternion $q 3042 3057 SendCmd "camera orient $q" 3043 3058 SendCmd "camera reset" 3044 set _view( xpan) 03045 set _view( ypan) 03046 set _view( zoom) 1.03047 } 3048 3049 itcl::body Rappture::VtkViewer::SetOpacity { dataset } { 3059 set _view(-xpan) 0 3060 set _view(-ypan) 0 3061 set _view(-zoom) 1.0 3062 } 3063 3064 itcl::body Rappture::VtkViewer::SetOpacity { dataset } { 3050 3065 foreach {dataobj comp} [split $dataset -] break 3051 3066 set type [$dataobj type $comp] -
branches/uq/gui/scripts/vtkvolumeviewer.tcl
r4797 r5121 1 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 2 # ---------------------------------------------------------------------- 3 # COMPONENT: vtkvolumeviewer - Vtk volume viewer 2 3 # ---------------------------------------------------------------------- 4 # COMPONENT: VtkVolumeViewer - Vtk volume viewer 4 5 # 5 6 # It connects to the Vtk server running on a rendering farm, … … 7 8 # ====================================================================== 8 9 # AUTHOR: Michael McLennan, Purdue University 9 # Copyright (c) 2004-201 4HUBzero Foundation, LLC10 # Copyright (c) 2004-2012 HUBzero Foundation, LLC 10 11 # 11 12 # See the file "license.terms" for information on usage and … … 66 67 protected method Disconnect {} 67 68 protected method DoResize {} 69 protected method DoReseed {} 68 70 protected method DoRotate {} 69 71 protected method AdjustSetting {what {value ""}} … … 84 86 private method BuildCutplaneTab {} 85 87 private method BuildDownloadPopup { widget command } 86 private method BuildViewTab {}87 88 private method BuildVolumeTab {} 88 89 private method DrawLegend {} … … 90 91 private method EnterLegend { x y } 91 92 private method EventuallyResize { w h } 93 private method EventuallyReseed { numPoints } 92 94 private method EventuallyRotate { q } 93 95 private method EventuallySetCutplane { axis args } … … 127 129 private variable _start 0 128 130 private variable _title "" 131 private variable _seeds 129 132 130 133 common _downloadPopup; # download options from popup … … 133 136 private variable _height 0 134 137 private variable _resizePending 0 138 private variable _reseedPending 0 135 139 private variable _rotatePending 0 136 140 private variable _cutplanePending 0 … … 154 158 set _serverType "vtkvis" 155 159 156 EnableWaitDialog 900157 158 160 # Rebuild event 159 161 $_dispatcher register !rebuild … … 163 165 $_dispatcher register !resize 164 166 $_dispatcher dispatch $this !resize "[itcl::code $this DoResize]; list" 167 168 # Reseed event 169 $_dispatcher register !reseed 170 $_dispatcher dispatch $this !reseed "[itcl::code $this DoReseed]; list" 165 171 166 172 # Rotate event … … 215 221 axesVisible 1 216 222 axisLabels 1 217 background black218 223 cutplaneEdges 0 219 224 cutplane-xvisible 1 … … 227 232 cutplaneWireframe 0 228 233 cutplane-opacity 100 229 legendVisible 1230 outline 0231 234 volumeLighting 1 232 235 volume-material 80 … … 334 337 335 338 if { [catch { 336 BuildViewTab337 339 BuildVolumeTab 338 340 BuildCutplaneTab … … 342 344 puts stderr errs=$errs 343 345 } 344 345 346 # Legend 347 346 348 set _image(legend) [image create photo] 347 349 itk_component add legend { … … 372 374 [itcl::code $this EventuallyResize %w %h] 373 375 376 if 0 { 377 bind $itk_component(view) <Configure> \ 378 [itcl::code $this EventuallyResize %w %h] 379 } 374 380 # Bindings for panning via mouse 375 381 bind $itk_component(view) <ButtonPress-2> \ … … 461 467 } 462 468 469 itcl::body Rappture::VtkVolumeViewer::EventuallyReseed { numPoints } { 470 set _numSeeds $numPoints 471 if { !$_reseedPending } { 472 set _reseedPending 1 473 $_dispatcher event -after 600 !reseed 474 } 475 } 476 463 477 set rotate_delay 100 464 478 … … 487 501 # ---------------------------------------------------------------------- 488 502 itcl::body Rappture::VtkVolumeViewer::add {dataobj {settings ""}} { 489 if { ![IsValidObject $dataobj] } {490 return; # Ignore invalid objects.491 }492 503 array set params { 493 504 -color auto … … 739 750 if { $_reportClientInfo } { 740 751 # Tell the server the viewer, hub, user and session. 741 # Do this immediately on connect before buff ering any commands752 # Do this immediately on connect before buffing any commands 742 753 global env 743 754 … … 797 808 $_dispatcher cancel !rebuild 798 809 $_dispatcher cancel !resize 810 $_dispatcher cancel !reseed 799 811 $_dispatcher cancel !rotate 800 812 $_dispatcher cancel !xcutplane … … 807 819 array unset _data 808 820 array unset _colormaps 821 array unset _seeds 809 822 array unset _dataset2style 810 823 array unset _obj2datasets … … 834 847 } 835 848 $_image(plot) configure -data $bytes 836 #puts stderr "[clock format [clock seconds]]: received image [image width $_image(plot)]x[image height $_image(plot)] image>" 849 set time [clock seconds] 850 set date [clock format $time] 851 #puts stderr "$date: received image [image width $_image(plot)]x[image height $_image(plot)] image>" 837 852 if { $_start > 0 } { 838 853 set finish [clock clicks -milliseconds] … … 913 928 set _legendPending 1 914 929 915 if { $_ width != $w || $_height != $h || $_reset } {930 if { $_reset } { 916 931 set _width $w 917 932 set _height $h 918 933 $_arcball resize $w $h 919 934 DoResize 920 }921 if { $_reset } {922 935 # 923 936 # Reset the camera and other view parameters … … 931 944 } 932 945 DoRotate 933 InitSettings outline background \ 934 axis-xgrid axis-ygrid axis-zgrid axisFlyMode \ 946 InitSettings axis-xgrid axis-ygrid axis-zgrid axisFlyMode \ 935 947 axesVisible axisLabels 936 948 PanCamera 937 949 } 950 set _first "" 938 951 939 952 SendCmd "imgflush" … … 953 966 if { $_reportClientInfo } { 954 967 set info {} 955 lappend info "tool_id" [$dataobj hints toolId] 956 lappend info "tool_name" [$dataobj hints toolName] 957 lappend info "tool_version" [$dataobj hints toolRevision] 958 lappend info "tool_title" [$dataobj hints toolTitle] 968 lappend info "tool_id" [$dataobj hints toolid] 969 lappend info "tool_name" [$dataobj hints toolname] 970 lappend info "tool_title" [$dataobj hints tooltitle] 971 lappend info "tool_command" [$dataobj hints toolcommand] 972 lappend info "tool_revision" [$dataobj hints toolrevision] 959 973 lappend info "dataset_label" [$dataobj hints label] 960 974 lappend info "dataset_size" $length … … 969 983 lappend _obj2datasets($dataobj) $tag 970 984 if { [info exists _obj2ovride($dataobj-raise)] } { 971 SendCmd " volumevisible 1 $tag"985 SendCmd "dataset visible 1 $tag" 972 986 } 973 987 break … … 983 997 set label [$_first hints ${axis}label] 984 998 if { $label != "" } { 985 SendCmd [list axis name $axis $label]999 SendCmd "axis name $axis $label" 986 1000 } 987 1001 set units [$_first hints ${axis}units] 988 1002 if { $units != "" } { 989 SendCmd [list axis units $axis $units]1003 SendCmd "axis units $axis $units" 990 1004 } 991 1005 } … … 1272 1286 } 1273 1287 switch -- $what { 1274 "background" {1275 set bgcolor [$itk_component(background) value]1276 array set fgcolors {1277 "black" "white"1278 "white" "black"1279 "grey" "black"1280 }1281 configure -plotbackground $bgcolor \1282 -plotforeground $fgcolors($bgcolor)1283 $itk_component(view) delete "legend"1284 DrawLegend1285 }1286 "outline" {1287 set bool $_settings($what)1288 SendCmd "outline visible 0"1289 foreach tag [CurrentDatasets -visible] {1290 SendCmd "outline visible $bool $tag"1291 }1292 }1293 "legendVisible" {1294 set bool $_settings($what)1295 set _settings($_current-$what) $bool1296 }1297 1288 "volumeVisible" { 1298 set bool $_settings( $what)1289 set bool $_settings(volumeVisible) 1299 1290 foreach dataset [CurrentDatasets -visible] { 1300 1291 SendCmd "volume visible $bool $dataset" … … 1309 1300 } 1310 1301 "volume-material" { 1311 set val $_settings( $what)1302 set val $_settings(volume-material) 1312 1303 set diffuse [expr {0.01*$val}] 1313 1304 set specular [expr {0.01*$val}] … … 1320 1311 } 1321 1312 "volumeLighting" { 1322 set bool $_settings( $what)1313 set bool $_settings(volumeLighting) 1323 1314 foreach dataset [CurrentDatasets -visible] { 1324 1315 SendCmd "volume lighting $bool $dataset" … … 1326 1317 } 1327 1318 "volume-quality" { 1328 set val $_settings( $what)1319 set val $_settings(volume-quality) 1329 1320 set val [expr {0.01*$val}] 1330 1321 foreach dataset [CurrentDatasets -visible] { … … 1333 1324 } 1334 1325 "axesVisible" { 1335 set bool $_settings( $what)1326 set bool $_settings(axesVisible) 1336 1327 SendCmd "axis visible all $bool" 1337 1328 } 1338 1329 "axisLabels" { 1339 set bool $_settings( $what)1330 set bool $_settings(axisLabels) 1340 1331 SendCmd "axis labels all $bool" 1341 1332 } … … 1406 1397 "volume-palette" { 1407 1398 set palette [$itk_component(palette) value] 1408 set _settings( $what) $palette1399 set _settings(volume-palette) $palette 1409 1400 foreach dataset [CurrentDatasets -visible $_first] { 1410 1401 foreach {dataobj comp} [split $dataset -] break … … 1413 1404 set _legendPending 1 1414 1405 } 1406 "volume-palette" { 1407 set palette [$itk_component(palette) value] 1408 set _settings(volume-palette) $palette 1409 foreach dataset [CurrentDatasets -visible $_first] { 1410 foreach {dataobj comp} [split $dataset -] break 1411 ChangeColormap $dataobj $comp $palette 1412 } 1413 set _legendPending 1 1414 } 1415 1415 "field" { 1416 1416 set label [$itk_component(field) value] 1417 1417 set fname [$itk_component(field) translate $label] 1418 set _settings( $what) $fname1418 set _settings(field) $fname 1419 1419 if { [info exists _fields($fname)] } { 1420 1420 foreach { label units components } $_fields($fname) break … … 1549 1549 itcl::configbody Rappture::VtkVolumeViewer::plotbackground { 1550 1550 if { [isconnected] } { 1551 set color $itk_option(-plotbackground) 1552 set rgb [Color2RGB $color] 1553 SendCmd "screen bgcolor $rgb" 1554 $itk_component(legend) configure -background $color 1551 foreach {r g b} [Color2RGB $itk_option(-plotbackground)] break 1552 SendCmd "screen bgcolor $r $g $b" 1555 1553 } 1556 1554 } … … 1561 1559 itcl::configbody Rappture::VtkVolumeViewer::plotforeground { 1562 1560 if { [isconnected] } { 1563 set color $itk_option(-plotforeground) 1564 set rgb [Color2RGB $color] 1565 SendCmd "axis color all $rgb" 1566 SendCmd "outline color $rgb" 1567 SendCmd "cutplane color $rgb" 1568 $itk_component(legend) itemconfigure labels -fill $color 1569 $itk_component(legend) itemconfigure limits -fill $color 1570 } 1571 } 1572 1573 itcl::body Rappture::VtkVolumeViewer::BuildViewTab {} { 1574 set font [option get $itk_component(hull) font Font] 1575 #set bfont [option get $itk_component(hull) boldFont Font] 1576 1577 set inner [$itk_component(main) insert end \ 1578 -title "View Settings" \ 1579 -icon [Rappture::icon wrench]] 1580 $inner configure -borderwidth 4 1581 1582 checkbutton $inner.axes \ 1583 -text "Axes" \ 1584 -variable [itcl::scope _settings(axesVisible)] \ 1585 -command [itcl::code $this AdjustSetting axesVisible] \ 1586 -font "Arial 9" 1587 1588 checkbutton $inner.outline \ 1589 -text "Outline" \ 1590 -variable [itcl::scope _settings(outline)] \ 1591 -command [itcl::code $this AdjustSetting outline] \ 1592 -font "Arial 9" 1593 1594 checkbutton $inner.legend \ 1595 -text "Legend" \ 1596 -variable [itcl::scope _settings(legendVisible)] \ 1597 -command [itcl::code $this AdjustSetting legendVisible] \ 1598 -font "Arial 9" 1599 1600 checkbutton $inner.volume \ 1601 -text "Volume" \ 1602 -variable [itcl::scope _settings(volumeVisible)] \ 1603 -command [itcl::code $this AdjustSetting volumeVisible] \ 1604 -font "Arial 9" 1605 1606 label $inner.background_l -text "Background" -font "Arial 9" 1607 itk_component add background { 1608 Rappture::Combobox $inner.background -width 10 -editable no 1609 } 1610 $inner.background choices insert end \ 1611 "black" "black" \ 1612 "white" "white" \ 1613 "grey" "grey" 1614 1615 $itk_component(background) value $_settings(background) 1616 bind $inner.background <<Value>> \ 1617 [itcl::code $this AdjustSetting background] 1618 1619 blt::table $inner \ 1620 0,0 $inner.axes -cspan 2 -anchor w \ 1621 1,0 $inner.outline -cspan 2 -anchor w \ 1622 2,0 $inner.volume -cspan 2 -anchor w \ 1623 3,0 $inner.legend -cspan 2 -anchor w \ 1624 4,0 $inner.background_l -anchor e -pady 2 \ 1625 4,1 $inner.background -fill x \ 1626 1627 blt::table configure $inner r* -resize none 1628 blt::table configure $inner r5 -resize expand 1561 foreach {r g b} [Color2RGB $itk_option(-plotforeground)] break 1562 #fix this! 1563 #SendCmd "color background $r $g $b" 1564 } 1629 1565 } 1630 1566 1631 1567 itcl::body Rappture::VtkVolumeViewer::BuildVolumeTab {} { 1632 set font [option get $itk_component(hull) font Font] 1633 #set bfont [option get $itk_component(hull) boldFont Font] 1568 1569 set fg [option get $itk_component(hull) font Font] 1570 #set bfg [option get $itk_component(hull) boldFont Font] 1634 1571 1635 1572 set inner [$itk_component(main) insert end \ … … 1685 1622 Rappture::Combobox $inner.palette -width 10 -editable no 1686 1623 } 1687 1688 $inner.palette choices insert end [GetColormapList] 1624 $inner.palette choices insert end \ 1625 "BCGYR" "BCGYR" \ 1626 "BGYOR" "BGYOR" \ 1627 "blue" "blue" \ 1628 "blue-to-brown" "blue-to-brown" \ 1629 "blue-to-orange" "blue-to-orange" \ 1630 "blue-to-grey" "blue-to-grey" \ 1631 "green-to-magenta" "green-to-magenta" \ 1632 "greyscale" "greyscale" \ 1633 "nanohub" "nanohub" \ 1634 "rainbow" "rainbow" \ 1635 "spectral" "spectral" \ 1636 "ROYGB" "ROYGB" \ 1637 "RYGCB" "RYGCB" \ 1638 "brown-to-blue" "brown-to-blue" \ 1639 "grey-to-blue" "grey-to-blue" \ 1640 "orange-to-blue" "orange-to-blue" 1641 1689 1642 $itk_component(palette) value "BCGYR" 1690 1643 bind $inner.palette <<Value>> \ … … 1709 1662 1710 1663 itcl::body Rappture::VtkVolumeViewer::BuildAxisTab {} { 1711 set font [option get $itk_component(hull) font Font] 1712 #set bfont [option get $itk_component(hull) boldFont Font] 1664 1665 set fg [option get $itk_component(hull) font Font] 1666 #set bfg [option get $itk_component(hull) boldFont Font] 1713 1667 1714 1668 set inner [$itk_component(main) insert end \ … … 1753 1707 "static_triad" "static" \ 1754 1708 "closest_triad" "closest" \ 1755 "furthest_triad" "f arthest" \1709 "furthest_triad" "furthest" \ 1756 1710 "outer_edges" "outer" 1757 1711 $itk_component(axismode) value "static" … … 1770 1724 blt::table configure $inner r7 c1 -resize expand 1771 1725 } 1726 1772 1727 1773 1728 itcl::body Rappture::VtkVolumeViewer::BuildCameraTab {} { … … 1807 1762 1808 1763 itcl::body Rappture::VtkVolumeViewer::BuildCutplaneTab {} { 1809 set font [option get $itk_component(hull) font Font] 1764 1765 set fg [option get $itk_component(hull) font Font] 1810 1766 1811 1767 set inner [$itk_component(main) insert end \ … … 2077 2033 set _settings(volumeLighting) $settings(-lighting) 2078 2034 SetColormap $dataobj $comp 2079 SendCmd "outline add $tag"2080 SendCmd "outline visible 0 $tag"2081 2035 } 2082 2036 -
branches/uq/gui/scripts/xylegend.tcl
r3800 r5121 85 85 private method Lower { args } 86 86 private method Raise { args } 87 private method Recolor {} 87 88 private method PopupMenu { x y } 88 89 private method Rename {} … … 158 159 delete "" 159 160 rename "" 161 recolor "" 160 162 } 161 163 foreach { but icon} $commands { … … 174 176 grid $controls.average -column 1 -row 1 -sticky w 175 177 grid $controls.rename -column 1 -row 2 -sticky w 176 grid $controls.delete -column 1 -row 3 -sticky w 178 grid $controls.recolor -column 1 -row 3 -sticky w 179 grid $controls.delete -column 1 -row 4 -sticky w 177 180 178 181 grid columnconfigure $controls 0 -weight 1 … … 393 396 set nodes [$itk_component(legend) curselection] 394 397 foreach n { hide show toggle raise lower 395 rename average difference delete } {398 rename average difference delete recolor } { 396 399 $itk_component(controls).$n configure -state disabled 397 400 } … … 411 414 } 412 415 1 { 413 foreach n { hide show toggle rename } {416 foreach n { hide show toggle rename recolor } { 414 417 $itk_component(controls).$n configure -state normal 415 418 } 416 419 } 417 420 2 { 418 foreach n { hide show toggle difference average } {421 foreach n { hide show toggle difference average recolor } { 419 422 $itk_component(controls).$n configure -state normal 420 423 } 421 424 } 422 425 default { 423 foreach n { hide show toggle average } {426 foreach n { hide show toggle average recolor } { 424 427 $itk_component(controls).$n configure -state normal 425 428 } … … 613 616 } 614 617 } 618 619 itcl::body Rappture::XyLegend::Recolor {} { 620 set nodes [$itk_component(legend) curselection] 621 if { $nodes == "" } { 622 return 623 } 624 foreach node $nodes { 625 set elem [$_tree label $node] 626 if { $_lastColorIndex == 0 } { 627 set _lastColorIndex [llength $_autocolors] 628 } 629 incr _lastColorIndex -1 630 set color [lindex $_autocolors $_lastColorIndex] 631 $_graph element configure $elem -color $color 632 set im [$itk_component(legend) entry cget $node -icon] 633 $_graph legend icon $elem $im 634 } 635 } -
branches/uq/gui/scripts/xyprint.tcl
r4511 r5121 1329 1329 close $f 1330 1330 if { [catch { $parser eval $code }] != 0 } { 1331 file delete $_settingsFile s1331 file delete $_settingsFile 1332 1332 } 1333 1333 # Now see if there's an entry for this tool/plot combination. The data -
branches/uq/gui/scripts/xyresult.tcl
r4205 r5121 249 249 } 250 250 if { $color == "auto" || $color == "autoreset" } { 251 if { $color == "autoreset" } {252 set _nextColorIndex 0253 }251 # if { $color == "autoreset" } { 252 # set _nextColorIndex 0 253 # } 254 254 set color [lindex $itk_option(-autocolors) $_nextColorIndex] 255 255 if { "" == $color} { … … 1067 1067 } 1068 1068 } 1069 incr _nextColorIndex 1069 1070 if {$_nextColorIndex >= [llength $itk_option(-autocolors)]} { 1070 1071 set _nextColorIndex 0 -
branches/uq/gui/src/RpDicomToVtk.cc
r4515 r5121 27 27 #include <stdio.h> 28 28 #include "tcl.h" 29 30 // #define RP_DICOM_TRACE 29 31 30 32 static int … … 95 97 int series = 0; 96 98 99 #ifdef RP_DICOM_TRACE 97 100 fprintf(stderr, "Num Studies: %d\n", numStudies); 101 #endif 98 102 vtkStringArray *files; 99 103 #if 0 100 104 for (int i = 0; i < numStudies; i++) { 101 105 int numSeries = sorter->GetNumberOfSeriesInStudy(i); 106 #ifdef RP_DICOM_TRACE 102 107 fprintf(stderr, "Study %d: %d series\n", i, numSeries); 108 #endif 103 109 int k = sorter->GetFirstSeriesInStudy(i); 104 110 for (int j = 0; j < numSeries; j++) { … … 144 150 #ifdef USE_VTK_DICOM_PACKAGE 145 151 vtkStringArray *ids = reader->GetStackIDs(); 152 #ifdef RP_DICOM_TRACE 146 153 for (int i = 0; i < ids->GetNumberOfValues(); i++) { 147 154 fprintf(stderr, "Stack: %s\n", ids->GetValue(i).c_str()); 148 155 } 156 #endif 149 157 vtkIntArray *fidxArray = reader->GetFileIndexArray(); 150 158 vtkDICOMMetaData *md = reader->GetMetaData(); … … 160 168 } 161 169 #endif 170 #ifdef RP_DICOM_TRACE 162 171 fprintf(stderr, "Number of data elements: %d\n", md->GetNumberOfDataElements()); 163 172 #endif 164 173 Tcl_ListObjAppendElement(interp, metaDataObj, Tcl_NewStringObj("num_files", -1)); 165 174 Tcl_ListObjAppendElement(interp, metaDataObj, Tcl_NewIntObj(md->GetNumberOfInstances())); … … 234 243 235 244 Tcl_ListObjAppendList(interp, objPtr, metaDataObj); 236 245 #ifdef RP_DICOM_TRACE 237 246 fprintf(stderr, "writing VTK\n"); 238 247 #endif 239 248 vtkSmartPointer<vtkDataSetWriter> writer = vtkSmartPointer<vtkDataSetWriter>::New(); 240 249 writer->SetInputConnection(reader->GetOutputPort()); … … 242 251 writer->WriteToOutputStringOn(); 243 252 writer->Update(); 244 253 #ifdef RP_DICOM_TRACE 245 254 fprintf(stderr, "writing VTK...done\n"); 246 255 #endif 247 256 Tcl_ListObjAppendElement(interp, objPtr, Tcl_NewStringObj("vtkdata", -1)); 248 257 -
branches/uq/gui/src/RpPdbToVtk.c
r4798 r5121 191 191 for (i = 0, hPtr = Tcl_FirstHashEntry(atomTablePtr, &iter); hPtr != NULL; 192 192 hPtr = Tcl_NextHashEntry(&iter), i++) { 193 PdbAtom *atomPtr; 194 195 atomPtr = Tcl_GetHashValue(hPtr); 193 PdbAtom *atomPtr = Tcl_GetHashValue(hPtr); 196 194 array[i] = atomPtr; 197 195 } … … 691 689 Tcl_AppendToObj(objPtr, mesg, -1); 692 690 } 691 #if 0 692 for (hPtr = Tcl_FirstHashEntry(&atomTable, &iter); hPtr != NULL; 693 hPtr = Tcl_NextHashEntry(&iter)) { 694 PdbAtom *atomPtr = Tcl_GetHashValue(hPtr); 695 fprintf(stderr, "%d %s %d connections\n", atomPtr->ordinal, 696 elements[atomPtr->number].symbol, atomPtr->numConnections); 697 } 698 #endif 693 699 sprintf(mesg, "POINT_DATA %d\n", atomTable.numEntries); 694 700 Tcl_AppendToObj(objPtr, mesg, -1); -
branches/uq/gui/src/RpReadPoints.c
r3404 r5121 88 88 return TCL_OK; 89 89 } 90 90 91 91 /* 92 92 * ReadPoints string dimVar pointsVar -
branches/uq/lang/tcl/pkgIndex.tcl.in
r4798 r5121 6 6 variable version $version 7 7 variable build "@SVN_VERSION@" 8 variable svnurl "@SVN_URL@" 8 9 variable installdir [file normalize $dir] 9 10 } -
branches/uq/lang/tcl/scripts/task.tcl
r5102 r5121 13 13 # Copyright (c) 2004-2014 HUBzero Foundation, LLC 14 14 # 15 # See the file "license.terms" for information on usage and# redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. 15 # See the file "license.terms" for information on usage and 16 # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. 16 17 # ====================================================================== 17 18 package require BLT … … 32 33 public method reset {} 33 34 public method xml {args} 35 public method save {xmlobj {name ""}} 34 36 35 37 protected method _mkdir {dir} … … 39 41 private variable _xmlobj "" ;# XML object with inputs/outputs 40 42 private variable _origxml "" ;# copy of original XML (for reset) 43 private variable _lastrun "" ;# name of last run file 41 44 private variable _installdir "" ;# installation directory for this tool 42 45 private variable _outputcb "" ;# callback for tool output … … 263 266 } 264 267 265 $_xmlobj put tool.execute $cmd 266 267 puts "cmd=$cmd" 268 # starting job... 269 _log run started 270 Rappture::rusage mark 271 272 if {0 == [string compare -nocase -length 5 $cmd "ECHO "] } { 273 set status 0; 274 set job(output) [string range $cmd 5 end] 275 } else { 276 set status [catch { 277 set ::Rappture::Task::job(control) "" 278 eval blt::bgexec \ 279 ::Rappture::Task::job(control) \ 280 -keepnewline yes \ 281 -killsignal SIGTERM \ 282 -onoutput [list [itcl::code $this _output]] \ 283 -output ::Rappture::Task::job(output) \ 284 -error ::Rappture::Task::job(error) \ 285 $cmd 286 } result] 287 288 if { $status != 0 } { 289 # We're here because the exec-ed program failed 290 set logmesg $result 291 if { $::Rappture::Task::job(control) ne "" } { 292 foreach { token pid code mesg } \ 293 $::Rappture::Task::job(control) break 294 if { $token == "EXITED" } { 295 # This means that the program exited normally but 296 # returned a non-zero exitcode. Consider this an 297 # invalid result from the program. Append the stderr 298 # from the program to the message. 299 set logmesg "Program finished: exit code is $code" 300 set result "$logmesg\n\n$::Rappture::Task::job(error)" 301 } elseif { $token == "abort" } { 302 # The user pressed the abort button. 303 set logmesg "Program terminated by user." 304 set result "$logmesg\n\n$::Rappture::Task::job(output)" 305 } else { 306 # Abnormal termination 307 set logmesg "Abnormal program termination: $mesg" 308 set result "$logmesg\n\n$::Rappture::Task::job(output)" 309 } 310 } 311 _log run failed [list $logmesg] 312 return [list $status $result] 313 } 314 } 315 # ...job is finished 316 array set times [Rappture::rusage measure] 317 318 if {[resources -jobprotocol] ne "submit"} { 319 set id [$_xmlobj get tool.id] 320 set vers [$_xmlobj get tool.version.application.revision] 321 set simulation simulation 322 if { $id ne "" && $vers ne "" } { 323 set pid [pid] 324 set simulation ${pid}_${id}_r${vers} 325 } 326 327 # need to save job info? then invoke the callback 328 if {[string length $jobstats] > 0} { 329 uplevel #0 $jobstats [list job [incr jobnum] \ 330 event $simulation start $times(start) \ 331 walltime $times(walltime) cputime $times(cputime) \ 332 status $status] 333 } 334 335 # 336 # Scan through stderr channel and look for statements that 337 # represent grid jobs that were executed. The statements 338 # look like this: 339 # 340 # MiddlewareTime: job=1 event=simulation start=3.001094 ... 341 # 342 set subjobs 0 343 while {[regexp -indices {(^|\n)MiddlewareTime:( +[a-z]+=[^ \n]+)+(\n|$)} $job(error) match]} { 344 foreach {p0 p1} $match break 345 if {[string index $job(error) $p0] == "\n"} { incr p0 } 346 347 catch {unset data} 348 array set data { 349 job 1 350 event simulation 351 start 0 352 walltime 0 353 cputime 0 354 status 0 355 } 268 $_xmlobj put tool.execute $cmd 269 270 puts "cmd=$cmd" 271 # starting job... 272 set _lastrun "" 273 _log run started 274 Rappture::rusage mark 275 276 if {0 == [string compare -nocase -length 5 $cmd "ECHO "] } { 277 set status 0; 278 set job(output) [string range $cmd 5 end] 279 } else { 280 set status [catch { 281 set ::Rappture::Task::job(control) "" 282 eval blt::bgexec \ 283 ::Rappture::Task::job(control) \ 284 -keepnewline yes \ 285 -killsignal SIGTERM \ 286 -onoutput [list [itcl::code $this _output]] \ 287 -output ::Rappture::Task::job(output) \ 288 -error ::Rappture::Task::job(error) \ 289 $cmd 290 } result] 291 292 if { $status != 0 } { 293 # We're here because the exec-ed program failed 294 set logmesg $result 295 if { $::Rappture::Task::job(control) ne "" } { 296 foreach { token pid code mesg } \ 297 $::Rappture::Task::job(control) break 298 if { $token == "EXITED" } { 299 # This means that the program exited normally but 300 # returned a non-zero exitcode. Consider this an 301 # invalid result from the program. Append the stderr 302 # from the program to the message. 303 set logmesg "Program finished: exit code is $code" 304 set result "$logmesg\n\n$::Rappture::Task::job(error)" 305 } elseif { $token == "abort" } { 306 # The user pressed the abort button. 307 set logmesg "Program terminated by user." 308 set result "$logmesg\n\n$::Rappture::Task::job(output)" 309 } else { 310 # Abnormal termination 311 set logmesg "Abnormal program termination: $mesg" 312 set result "$logmesg\n\n$::Rappture::Task::job(output)" 313 } 314 } 315 _log run failed [list $logmesg] 316 return [list $status $result] 317 } 318 } 319 # ...job is finished 320 array set times [Rappture::rusage measure] 321 322 if {[resources -jobprotocol] ne "submit"} { 323 set id [$_xmlobj get tool.id] 324 set vers [$_xmlobj get tool.version.application.revision] 325 set simulation simulation 326 if { $id ne "" && $vers ne "" } { 327 set pid [pid] 328 set simulation ${pid}_${id}_r${vers} 329 } 330 331 # need to save job info? then invoke the callback 332 if {[string length $jobstats] > 0} { 333 uplevel #0 $jobstats [list job [incr jobnum] \ 334 event $simulation start $times(start) \ 335 walltime $times(walltime) cputime $times(cputime) \ 336 status $status] 337 } 338 339 # 340 # Scan through stderr channel and look for statements that 341 # represent grid jobs that were executed. The statements 342 # look like this: 343 # 344 # MiddlewareTime: job=1 event=simulation start=3.001094 ... 345 # 346 set subjobs 0 347 while {[regexp -indices {(^|\n)MiddlewareTime:( +[a-z]+=[^ \n]+)+(\n|$)} $job(error) match]} { 348 foreach {p0 p1} $match break 349 if {[string index $job(error) $p0] == "\n"} { incr p0 } 350 351 catch {unset data} 352 array set data { 353 job 1 354 event simulation 355 start 0 356 walltime 0 357 cputime 0 358 status 0 359 } 356 360 foreach arg [lrange [string range $job(error) $p0 $p1] 1 end] { 357 361 foreach {key val} [split $arg =] break … … 413 417 } 414 418 if {[regexp {=RAPPTURE-RUN=>([^\n]+)} $result match file]} { 419 set _lastrun $file 420 415 421 set status [catch {Rappture::library $file} result] 416 422 puts "STATUS=$status" … … 427 433 } 428 434 429 # if there's a results_directory defined in the resources 430 # file, then move the run.xml file there for storage 431 set rdir "" 432 if {$resultdir eq "@default"} { 433 if {[info exists _resources(-resultdir)]} { 434 set rdir $_resources(-resultdir) 435 } else { 436 set rdir "." 437 } 438 } elseif {$resultdir ne ""} { 439 set rdir $resultdir 440 } 441 442 if {$status == 0 && $rdir ne ""} { 443 catch { 444 # file delete -force -- $file 445 if {![file exists $rdir]} { 446 _mkdir $rdir 447 } 448 set tail [file tail $file] 449 set fid [open [file join $rdir $tail] w] 450 puts $fid "<?xml version=\"1.0\"?>" 451 puts $fid [$result xml] 452 close $fid 453 } 454 } else { 455 # don't keep the file 456 # file delete -force -- $file 457 } 435 file delete -force -- $file 458 436 } else { 459 437 set status 1 … … 533 511 } 534 512 return [eval $_xmlobj $args] 513 } 514 515 # ---------------------------------------------------------------------- 516 # USAGE: save <xmlobj> ?<filename>? 517 # 518 # Used by clients to save the contents of an <xmlobj> representing 519 # a run out to the given file. If <filename> is not specified, then 520 # it uses the -resultsdir and other settings to do what Rappture 521 # would normally do with the output. 522 # ---------------------------------------------------------------------- 523 itcl::body Rappture::Task::save {xmlobj {filename ""}} { 524 if {$filename eq ""} { 525 # if there's a results_directory defined in the resources 526 # file, then move the run.xml file there for storage 527 set rdir "" 528 if {$resultdir eq "@default"} { 529 if {[info exists _resources(-resultdir)]} { 530 set rdir $_resources(-resultdir) 531 } else { 532 set rdir "." 533 } 534 } elseif {$resultdir ne ""} { 535 set rdir $resultdir 536 } 537 538 # use the runfile name generated by the last run 539 if {$_lastrun ne ""} { 540 set filename [file join $rdir $_lastrun] 541 } else { 542 set filename [file join $rdir run.xml] 543 } 544 } 545 546 # add any last-minute metadata 547 $xmlobj put output.time [clock format [clock seconds]] 548 549 $xmlobj put tool.version.rappture.version $::Rappture::version 550 $xmlobj put tool.version.rappture.revision $::Rappture::build 551 552 if {[info exists ::tcl_platform(user)]} { 553 $xmlobj put output.user $::tcl_platform(user) 554 } 555 556 # save the output 557 set rdir [file dirname $filename] 558 if {![file exists $rdir]} { 559 _mkdir $rdir 560 } 561 562 set fid [open $filename w] 563 puts $fid "<?xml version=\"1.0\"?>" 564 puts $fid [$xmlobj xml] 565 close $fid 566 567 _log output saved in $filename 535 568 } 536 569 -
branches/uq/lang/tcl/scripts/xauth.tcl
r4797 r5121 11 11 # set clientSecret [XAuth::credentials get nanoHUB.org -secret] 12 12 # 13 # XAuth::init $site $clientToken $clientSecret $username $password13 # XAuth::init $site $clientToken $clientSecret -user $username $password 14 14 # XAuth::call $site $method $params 15 15 # … … 20 20 # ====================================================================== 21 21 # AUTHOR: Michael McLennan, Purdue University 22 # Copyright (c) 2004-201 3HUBzero Foundation, LLC22 # Copyright (c) 2004-2015 HUBzero Foundation, LLC 23 23 # 24 24 # See the file "license.terms" for information on usage and … … 287 287 288 288 # ---------------------------------------------------------------------- 289 # USAGE: XAuth::init <site> <clientToken> <clientSecret> <username> <password> 290 # 291 # Should be called to initialize this library. Sends the <username> 292 # and <password> to the <site> for authentication. The <client> ID 293 # is registered with the OAuth provider to identify the application. 289 # USAGE: XAuth::init <site> <clientToken> <clientSecret> -user <u> <p> 290 # USAGE: XAuth::init <site> <clientToken> <clientSecret> -session <n> <t> 291 # 292 # Should be called to initialize this library. Can be initialized 293 # one of two ways: 294 # 295 # -user <u> <p> ...... sends username <u> and password <p> 296 # -session <n> <t> ... sends tool session number <n> and token <t> 297 # 298 # Sends the credentials to the <site> for authentication. The client 299 # token and secret are registered to identify the application. 294 300 # If successful, this call stores an authenticated session token in 295 301 # the tokens array for the <site> URL. Subsequent calls to XAuth::call 296 302 # use this token to identify the user. 297 303 # ---------------------------------------------------------------------- 298 proc XAuth::init {site clientToken clientSecret uname passw} {304 proc XAuth::init {site clientToken clientSecret args} { 299 305 variable clients 300 306 variable tokens 307 308 set option [lindex $args 0] 309 switch -- $option { 310 -user { 311 if {[llength $args] != 3} { 312 error "wrong # args: should be \"-user name password\"" 313 } 314 set uname [lindex $args 1] 315 set passw [lindex $args 2] 316 } 317 -session { 318 if {[llength $args] != 3} { 319 error "wrong # args: should be \"-session number token\"" 320 } 321 set snum [lindex $args 1] 322 set stok [lindex $args 2] 323 324 # store session info for later -- no need for oauth stuff 325 set tokens($site) [list session $snum $stok] 326 set clients($site) [list $clientToken $clientSecret] 327 return 328 } 329 default { 330 if {[llength $args] != 2} { 331 error "wrong # args: should be \"XAuth::init site token secret ?-option? arg arg\"" 332 } 333 set uname [lindex $args 0] 334 set passw [lindex $args 1] 335 } 336 } 301 337 302 338 if {![regexp {^https://} $site]} { … … 360 396 361 397 # success! store the session token for later 362 set tokens($site) [list $got(oauth_token) $got(oauth_token_secret)]398 set tokens($site) [list oauth $got(oauth_token) $got(oauth_token_secret)] 363 399 set clients($site) [list $clientToken $clientSecret] 364 400 } … … 385 421 } 386 422 foreach {clientToken clientSecret} $clients($site) break 387 foreach { userToken userSecret} $tokens($site) break423 foreach {scheme userToken userSecret} $tokens($site) break 388 424 389 425 set url $site/$method 390 set nonce [XAuth::nonce] 391 set tstamp [clock seconds] 392 393 # BE CAREFUL -- put all query parameters in alphabetical order 394 array set qparams [list \ 395 oauth_consumer_key $clientToken \ 396 oauth_nonce $nonce \ 397 oauth_signature_method "HMAC-SHA1" \ 398 oauth_timestamp $tstamp \ 399 oauth_token $userToken \ 400 oauth_version "1.0" \ 401 x_auth_mode "client_auth" \ 402 ] 403 array set qparams $params 404 405 set query "" 406 foreach key [lsort [array names qparams]] { 407 lappend query $key $qparams($key) 408 } 409 set query [eval http::formatQuery $query] 410 411 set base "POST&[urlencode $url]&[urlencode $query]" 412 set key "$clientSecret&$userSecret" 413 set sig [urlencode [base64::encode [sha1::hmac -bin -key $key $base]]] 414 415 # build the header and send the request 416 set auth [format "OAuth oauth_consumer_key=\"%s\", oauth_token=\"%s\", oauth_nonce=\"%s\", oauth_signature_method=\"HMAC-SHA1\", oauth_signature=\"%s\", oauth_timestamp=\"%s\", oauth_version=\"1.0\"" $clientToken $userToken $nonce $sig $tstamp] 417 418 return [XAuth::fetch $url -headers [list Authorization $auth] -query $query] 426 427 switch -- $scheme { 428 oauth { 429 set nonce [XAuth::nonce] 430 set tstamp [clock seconds] 431 432 # BE CAREFUL -- put all query parameters in alphabetical order 433 array set qparams [list \ 434 oauth_consumer_key $clientToken \ 435 oauth_nonce $nonce \ 436 oauth_signature_method "HMAC-SHA1" \ 437 oauth_timestamp $tstamp \ 438 oauth_token $userToken \ 439 oauth_version "1.0" \ 440 x_auth_mode "client_auth" \ 441 ] 442 array set qparams $params 443 444 set query "" 445 foreach key [lsort [array names qparams]] { 446 lappend query $key $qparams($key) 447 } 448 set query [eval http::formatQuery $query] 449 450 set base "POST&[urlencode $url]&[urlencode $query]" 451 set key "$clientSecret&$userSecret" 452 set sig [urlencode [base64::encode [sha1::hmac -bin -key $key $base]]] 453 454 # build the header and send the request 455 set auth [format "OAuth oauth_consumer_key=\"%s\", oauth_token=\"%s\", oauth_nonce=\"%s\", oauth_signature_method=\"HMAC-SHA1\", oauth_signature=\"%s\", oauth_timestamp=\"%s\", oauth_version=\"1.0\"" $clientToken $userToken $nonce $sig $tstamp] 456 set hdr [list Authorization $auth] 457 } 458 session { 459 set hdr [list sessionnum $userToken sessiontoken $userSecret] 460 set query "" 461 foreach {key val} $params { 462 lappend query $key $val 463 } 464 set query [eval http::formatQuery $query] 465 } 466 default { 467 error "internal error -- don't understand call scheme \"$scheme\"" 468 } 469 } 470 return [XAuth::fetch $url -headers $hdr -query $query] 419 471 } 420 472 … … 596 648 switch -- $option { 597 649 load { 598 set fname "~/.xauth"599 650 if {[llength $args] == 1} { 600 651 set fname [lindex $args 0] 601 } elseif {[llength $args] > 1} { 652 } elseif {[llength $args] == 0} { 653 if {[file exists ~/.xauth]} { 654 set fname "~/.xauth" 655 } else { 656 set fname "" 657 } 658 } else { 602 659 error "wrong # args: should be \"credentials load ?file?\"" 603 660 } 604 661 605 if {![file readable $fname]} { 606 error "file \"$fname\" not found" 607 } 608 set fid [open $fname r] 609 set info [read $fid] 610 close $fid 611 612 if {[catch {$parser eval $info} result]} { 613 error "error in sites file \"$fname\": $result" 662 if {$fname ne ""} { 663 if {![file readable $fname]} { 664 error "file \"$fname\" not found" 665 } 666 set fid [open $fname r] 667 set info [read $fid] 668 close $fid 669 670 if {[catch {$parser eval $info} result]} { 671 error "error in sites file \"$fname\": $result" 672 } 614 673 } 615 674 } -
branches/uq/src/core/RpEncode.cc
r4798 r5121 212 212 for (p = (unsigned const char *)buf, pend = p + size; p < pend; p++) { 213 213 if (!_base64chars[*p]) { 214 fprintf(stderr, " \"%c\" (0x%x)is not base64\n", *p, *p);214 fprintf(stderr, "%c %u is not base64\n", *p, *p); 215 215 return false; 216 216 }
Note: See TracChangeset
for help on using the changeset viewer.