Changeset 5121


Ignore:
Timestamp:
Mar 11, 2015, 10:26:15 AM (9 years ago)
Author:
dkearney
Message:

merging updates from 1.3 branch

looks like this branch originally came from the 1.3 branch and then had some
additions from the 1.4-pre branch and then a sync from the 1.3 branch. to get
this branch updated, I am reverting r4797 (additions from 1.4-pre branch),
reverting r4798 (additions from 1.3 branch), then merging in updates from 1.3
branch.

I fixed merge conflicts for the following files:

gui/scripts/gauge.tcl
gui/scripts/main.tcl
gui/scripts/tool.tcl
lang/tcl/scripts/task.tcl

Location:
branches/uq
Files:
4 deleted
56 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/uq

  • branches/uq/configure

    r5029 r5121  
    672672OCTAVE_VERSION_MAJOR
    673673OCTAVE_VERSION
     674SVN_URL
    674675SVN_VERSION
    675676MKOCTFILE3
     
    72977298
    72987299SVN_VERSION=`svnversion $srcdir | sed 's/Unversioned directory/unknown/'`
     7300SVN_URL=`svn info $srcdir | sed -ne 's/^URL: //p'`
    72997301
    73007302make_command=""
     
    1013510137
    1013610138MAKE=${make_command}
     10139
    1013710140
    1013810141
  • branches/uq/configure.in

    r5029 r5121  
    108108
    109109SVN_VERSION=`svnversion $srcdir | sed 's/Unversioned directory/unknown/'`
     110SVN_URL=`svn info $srcdir | sed -ne 's/^URL: //p'`
    110111
    111112make_command=""
     
    401402AC_SUBST(MKOCTFILE3)
    402403AC_SUBST(SVN_VERSION)
     404AC_SUBST(SVN_URL)
    403405AC_SUBST(OCTAVE_VERSION)
    404406AC_SUBST(OCTAVE_VERSION_MAJOR)
  • branches/uq/examples/flow/flowtest.tcl

    r4228 r5121  
    3939    $f1.component.flow.particles(right).color khaki
    4040    $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"
    4242    $f1.component.flow.box(one).label "Region 1"
    4343    $f1.component.flow.box(one).color cyan
     
    7575    $f2.component.flow.particles(right).color pink
    7676    $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"
    7878    $f2.camera.position {
    7979        qw 1 qx 0 qy 0 qz 0 pan-x 0 pan-y 0 zoom 1.0
     
    100100    $f3.component.flow.particles(right).color khaki
    101101    $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"
    103103    $f3.component.elemtype vectors
    104104    $f3.component.elemsize 3
  • branches/uq/gui/apps/Makefile.in

    r4513 r5121  
    2424                copy_rappture_examples \
    2525                encodedata \
     26                $(srcdir)/execute.tcl \
    2627                $(srcdir)/launcher.tcl \
    27                 $(srcdir)/mapviewer-test \
    2828                $(srcdir)/grabdata \
    2929                $(srcdir)/nanovis-test \
  • branches/uq/gui/apps/launcher.tcl

    r5029 r5121  
    1212#    rappture -builder ?-tool <toolfile>?
    1313#    rappture -tester ?-tool <toolfile>? ?-testdir <directory>?
     14#    rappture -execute driver.xml ?-tool <toolfile>?
    1415#
    1516#  The default option is "-run", which brings up the GUI used to
     
    2627set mainscript ""
    2728set alist ""
     29set loadlist ""
    2830set 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# ----------------------------------------------------------------------
     40set params(opt) ""
     41set params(load) ""
     42set params(execute) ""
     43set params(input) ""
     44
     45if {[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}
    29102
    30103# scan through the arguments and look for the function
     
    53126                set reqpkgs Tk
    54127            }
     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            }
    55146            -tool {
    56147                set toolxml [lindex $argv 0]
     
    62153                lappend alist -tool $toolxml
    63154            }
    64             -tool - -testdir - -nosim {
     155            -testdir - -nosim {
    65156                lappend alist $opt [lindex $argv 0]
    66157                set argv [lrange $argv 1 end]
     
    74165            }
    75166            -load {
    76                 lappend alist $opt
    77167                while { [llength $argv] > 0 } {
    78168                    set val [lindex $argv 0]
     
    80170                        break
    81171                    }
    82                     lappend alist $val
     172                    lappend loadlist $val
    83173                    set argv [lrange $argv 1 end]
    84174                }
     
    89179                puts stderr "  rappture -builder ?-tool toolFile?"
    90180                puts stderr "  rappture -tester ?-auto? ?-tool toolFile? ?-testdir directory?"
     181                puts stderr "  rappture -execute driver.xml ?-tool toolFile?"
    91182                exit 1
    92183            }
     
    95186}
    96187
    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.
    98190if {$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    }
    103254}
    104255
  • branches/uq/gui/apps/rpdiff

    r3177 r5121  
    2424exec tclsh "$0" ${1+"$@"}
    2525# tclsh executes the rest...
    26 
    2726package require Rappture
    2827
     
    3635proc diff {path lib1 lib2} {
    3736    set knowntypes {boolean choice cloud curve field group histogram image integer loader log mesh note number periodicelement phase sequence string structure table unirect2d}
    38 
    3937    set type1 [$lib1 element -as type $path]
    4038    set type2 [$lib2 element -as type $path]
     
    490488            }
    491489        }
     490        loader {
     491        }
    492492        default {
    493             error "don't know how to compare type \"$type\""
     493            puts stderr "ignoring \"$type1\" for \"$path\""
    494494        }
    495495    }
     
    557557
    558558# ======================================================================
    559 if {$argc != 2} {
     559
     560if {$argc < 2} {
    560561    puts stderr "USAGE: rpdiff file1.xml file2.xml"
    561562    exit 9
     
    563564set lib1 [Rappture::library [lindex $argv 0]]
    564565set lib2 [Rappture::library [lindex $argv 1]]
     566set path "output"
     567if { $argc > 2 } {
     568   set arg [lindex $argv 2]
     569   if { $arg == "-path" && $argc == 4 } {
     570      set path [lindex $argv 3]
     571   }
     572}
    565573
    566574# compute the differences
    567 set diffs [diff output $lib1 $lib2]
     575set diffs [diff $path $lib1 $lib2]
    568576
    569577if {[llength $diffs] == 0} {
  • branches/uq/gui/configure

    r4798 r5121  
    11#! /bin/sh
    22# 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.
    44#
    55# Report bugs to <rappture@nanohub.org>.
     
    580580PACKAGE_NAME='RapptureGUI'
    581581PACKAGE_TARNAME='rappturegui'
    582 PACKAGE_VERSION='1.4'
    583 PACKAGE_STRING='RapptureGUI 1.4'
     582PACKAGE_VERSION='1.3'
     583PACKAGE_STRING='RapptureGUI 1.3'
    584584PACKAGE_BUGREPORT='rappture@nanohub.org'
    585585PACKAGE_URL=''
     
    12231223  # This message is too long to be a string in the A/UX 3.1 sh.
    12241224  cat <<_ACEOF
    1225 \`configure' configures RapptureGUI 1.4 to adapt to many kinds of systems.
     1225\`configure' configures RapptureGUI 1.3 to adapt to many kinds of systems.
    12261226
    12271227Usage: $0 [OPTION]... [VAR=VALUE]...
     
    12891289if test -n "$ac_init_help"; then
    12901290  case $ac_init_help in
    1291      short | recursive ) echo "Configuration of RapptureGUI 1.4:";;
     1291     short | recursive ) echo "Configuration of RapptureGUI 1.3:";;
    12921292   esac
    12931293  cat <<\_ACEOF
     
    13801380if $ac_init_version; then
    13811381  cat <<\_ACEOF
    1382 RapptureGUI configure 1.4
     1382RapptureGUI configure 1.3
    13831383generated by GNU Autoconf 2.69
    13841384
     
    14351435running configure, to aid debugging if configure makes a mistake.
    14361436
    1437 It was created by RapptureGUI $as_me 1.4, which was
     1437It was created by RapptureGUI $as_me 1.3, which was
    14381438generated by GNU Autoconf 2.69.  Invocation command line was
    14391439
     
    36853685# values after options handling.
    36863686ac_log="
    3687 This file was extended by RapptureGUI $as_me 1.4, which was
     3687This file was extended by RapptureGUI $as_me 1.3, which was
    36883688generated by GNU Autoconf 2.69.  Invocation command line was
    36893689
     
    37383738ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
    37393739ac_cs_version="\\
    3740 RapptureGUI config.status 1.4
     3740RapptureGUI config.status 1.3
    37413741configured by $0, generated by GNU Autoconf 2.69,
    37423742  with options \\"\$ac_cs_config\\"
  • branches/uq/gui/configure.in

    r4798 r5121  
    11
    2 AC_INIT([RapptureGUI],[1.4],[rappture@nanohub.org])
     2AC_INIT([RapptureGUI],[1.3],[rappture@nanohub.org])
    33AC_CONFIG_AUX_DIR(cf)
    44#------------------------------------------------------------------------
  • 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.
    23package ifneeded RapptureGUI @PACKAGE_VERSION@ [format {
     4    package require Img
    35    set dir [file normalize "%s"]
    46    set version @PACKAGE_VERSION@
     
    1214    package provide RapptureGUI $version
    1315} $dir]
    14 
  • branches/uq/gui/scripts/Makefile.in

    r5102 r5121  
    7777                $(srcdir)/main.tcl \
    7878                $(srcdir)/mainwin.tcl \
    79                 $(srcdir)/map.tcl \
    80                 $(srcdir)/mapviewer.tcl \
    8179                $(srcdir)/mesh.tcl \
    8280                $(srcdir)/meshresult.tcl \
  • branches/uq/gui/scripts/analyzer.tcl

    r5102 r5121  
    319319
    320320    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
    322326    }
    323327    pack $itk_component(results) -expand yes -fill both
     
    829833                        _autoLabel $xmlobj output.$item "String" counters
    830834                    }
    831                     histogram* - curve* - field* - map* {
     835                    histogram* - curve* - field* {
    832836                        _autoLabel $xmlobj output.$item "Plot" counters
    833837                    }
  • branches/uq/gui/scripts/cloud.tcl

    r4504 r5121  
    148148        # Extract each point and add it to the points list
    149149        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
    159154            if { ![info exists _limits($axis)] } {
    160155                set _limits($axis) [list $value $value]
  • branches/uq/gui/scripts/curve.tcl

    r4008 r5121  
    112112# USAGE: values ?<name>?
    113113#
    114 # Returns the xvec for the specified curve component <name>.
     114# Returns the yvec for the specified curve component <name>.
    115115# If the name is not specified, then it returns the vectors for the
    116116# overall curve (sum of all components).
  • branches/uq/gui/scripts/drawing.tcl

    r4494 r5121  
    129129        }
    130130    }
     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    }
    131143}
    132144
  • branches/uq/gui/scripts/field.tcl

    r4797 r5121  
    1 # -*- mode: tcl; indent-tabs-mode: nil -*- 
     1# -*- mode: tcl; indent-tabs-mode: nil -*-
    22# ----------------------------------------------------------------------
    33#  COMPONENT: field - extracts data from an XML description of a field
     
    2525#       unirect2d       (deprecated)
    2626#       cloud           (x,y point coordinates) (deprecated)
    27 #       mesh 
     27#       mesh
    2828# 3D Datasets
    29 #       vtk 
     29#       vtk
    3030#       unirect3d       (deprecated)
    3131#       cloud           (x,y,z coordinates) (deprecated)
    32 #       mesh 
     32#       mesh
    3333#       dx              (FIXME: make dx-to-vtk converter work)
    3434#       ucd avs
     
    4141#       mesh        3   points-on-mesh                  isosurface      vtkvis
    4242#       dx          3   DX                              volume          nanovis
    43 #       unirect2d   2   unirect3d + extents > 1 flow    flow            nanovis
    44 #       unirect3d   3   unirect2d + extents > 1 flow    flow            nanovis
    45 #       
     43#       unirect2d   2   unirect2d + extents > 1 flow    flow            nanovis
     44#       unirect3d   3   unirect3d + extents > 1 flow    flow            nanovis
     45#
    4646# With <views>, can specify which viewer for specific datasets.  So it's OK
    4747# 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.
    4949#  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.
    5151#  o Any 3D uniform rectilinear dataset can be viewed as a volume.
    5252#  o Any 3D dataset with vector data can be streamlines or flow.
     
    5959package require BLT
    6060
    61 namespace eval Rappture { 
    62     # forward declaration 
     61namespace eval Rappture {
     62    # forward declaration
    6363}
    6464
     
    6868    private variable _limits;           # maps axis name => {z0 z1} limits
    6969    private variable _field ""
    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)
     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)
    7474    private variable _fld2Components;   # field name => number of components
    7575    private variable _fld2Label;        # field name => label
    7676    private variable _fld2Units;        # field name => units
    77     private variable _hints 
     77    private variable _hints
    7878    private variable _viewer "";        # Hints which viewer to use
    7979    private variable _xv "";            # For 1D meshes only.  Holds the points
     
    8383    private variable _alwaysConvertDX 0;
    8484
    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
    9090    }
    9191    public method blob { cname }
     
    127127    }
    128128    public method viewer {} {
    129         return $_viewer
     129        return $_viewer
    130130    }
    131131    protected method Build {}
    132132    protected method _getValue {expr}
    133133
    134     private variable _path "";          # Path of this object in the XML 
     134    private variable _path "";          # Path of this object in the XML
    135135    private variable _units ""   ;      # system of units for this field
    136136    private variable _zmax 0     ;# length of the device
     
    144144    private variable _comp2style ;# maps component name => style settings
    145145    private variable _comp2cntls ;# maps component name => x,y control points
    146     private variable _comp2extents 
    147     private variable _comp2limits;      #  Array of limits per component
    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
    150150    private variable _comp2mesh
    151151    private common _counter 0    ;# counter for unique vector names
    152152
    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 }
    162162    private method VectorLimits { vector vectorsize {comp -1} }
    163163    private variable _values ""
     
    229229    }
    230230    foreach name [array names _comp2mesh] {
    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)
     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)
    234234        set class [$mesh info class]
    235235        ${class}::release $mesh
    236         # Destroy the vector
     236        # Destroy the vector
    237237        blt::vector destroy $vector
    238238    }
     
    285285    # Now handle the tests.
    286286    switch -- $params(what) {
    287         -name { 
     287        -name {
    288288            set rlist $components
    289289        }
    290         -style { 
     290        -style {
    291291            foreach cname $components {
    292292                if { [info exists _comp2style($cname)] } {
    293                     lappend rlist $_comp2style($cname) 
     293                    lappend rlist $_comp2style($cname)
    294294                }
    295295            }
     
    314314    }
    315315    if { [info exists _comp2vtk($cname)] } {
    316         # FIXME: extract mesh from VTK file data.
     316        # FIXME: extract mesh from VTK file data.
    317317        if { $_comp2dims($cname) == "1D" } {
    318318            return $_xv
     
    353353    # VTK file data
    354354    if { [info exists _comp2vtk($cname)] } {
    355         # FIXME: extract the values from the VTK file data
     355        # FIXME: extract the values from the VTK file data
    356356        if { $_comp2dims($cname) == "1D" } {
    357357            return $_values
     
    361361    # Points-on-mesh
    362362    if { [info exists _comp2mesh($cname)] } {
    363         set vector [lindex $_comp2mesh($cname) 1]
     363        set vector [lindex $_comp2mesh($cname) 1]
    364364        return [$vector range 0 end]
    365365    }
     
    368368    }
    369369    if {[info exists _comp2unirect2d($cname)]} {
    370         return [$_comp2unirect2d($cname) values]
     370        return $_values
    371371    }
    372372    if {[info exists _comp2unirect3d($cname)]} {
     
    389389    }
    390390    if { [info exists _comp2vtk($cname)] } {
    391         error "blob not implemented for VTK file data"
     391        error "blob not implemented for VTK file data"
    392392    }
    393393    if {[info exists _comp2dx($cname)]} {
     
    408408# USAGE: valueLimits <cname>
    409409#
    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}
    411411# representing the limits for each axis.
    412412# ----------------------------------------------------------------------
     
    432432            1D {
    433433                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                    }
    446446                    default {
    447447                        error "bad axis \"$which\": should be x, xlin, xlog, y, ylin, ylog, v, vlin, vlog"
     
    480480            default {
    481481                if {[info exists _comp2limits($cname)]} {
    482                     array set limits $_comp2limits($cname)
    483                     switch -- $which {
     482                    array set limits $_comp2limits($cname)
     483                    switch -- $which {
    484484                        x - xlin - xlog {
    485485                            set axis x
    486                             foreach {axisMin axisMax} $limits(x) break
     486                            foreach {axisMin axisMax} $limits(x) break
    487487                        }
    488488                        y - ylin - ylog {
    489489                            set axis y
    490                             foreach {axisMin axisMax} $limits(y) break
     490                            foreach {axisMin axisMax} $limits(y) break
    491491                        }
    492492                        z - zlin - zlog {
    493493                            set axis z
    494                             foreach {axisMin axisMax} $limits(z) break
     494                            foreach {axisMin axisMax} $limits(z) break
    495495                        }
    496496                        v - vlin - vlog {
    497497                            set axis v
    498                             foreach {axisMin axisMax} $limits(v) break
    499                         }
    500                         default {
    501                             if { ![info exists limits($which)] } {
    502                                 error "limits: unknown axis \"$which\""
    503                             }
     498                            foreach {axisMin axisMax} $limits(v) break
     499                        }
     500                        default {
     501                            if { ![info exists limits($which)] } {
     502                                error "limits: unknown axis \"$which\""
     503                            }
    504504                            set axis v
    505                             foreach {axisMin axisMax} $limits($which) break
    506                         }
    507                     }
     505                            foreach {axisMin axisMax} $limits($which) break
     506                        }
     507                    }
    508508                } else {
    509509                    set axisMin 0  ;# HACK ALERT! must be OpenDX data
     
    545545itcl::body Rappture::Field::fieldlimits {} {
    546546    foreach cname [array names _comp2limits] {
    547         array set limits $_comp2limits($cname) 
     547        array set limits $_comp2limits($cname)
    548548        foreach fname [fieldnames $cname] {
    549549            if { ![info exists limits($fname)] } {
     
    571571    return ""
    572572}
    573  
     573
    574574# ----------------------------------------------------------------------
    575575# USAGE: controls get ?<name>?
     
    779779        set type ""
    780780        if { ([$_field element $cname.constant] != "" &&
    781               [$_field element $cname.domain] != "") ||
    782               [$_field element $cname.xy] != "" } {
     781              [$_field element $cname.domain] != "") ||
     782              [$_field element $cname.xy] != "" } {
    783783            set type "1D"
    784784        } elseif { [$_field element $cname.mesh] != "" &&
    785                    [$_field element $cname.values] != ""} {
     785                   [$_field element $cname.values] != ""} {
    786786            set type "points-on-mesh"
    787787        } elseif { [$_field element $cname.vtk] != ""} {
    788             set type "vtk"
    789             set viewer [$_field get "about.view"]
    790             if { $viewer != "" } {
    791                 set _viewer $viewer
    792             }
     788            set type "vtk"
     789            set viewer [$_field get "about.view"]
     790            if { $viewer != "" } {
     791                set _viewer $viewer
     792            }
    793793        } elseif {[$_field element $cname.opendx] != ""} {
    794794            global env
    795795            if { [info exists env(VTKVOLUME)] } {
    796796                set _viewer "vtkvolume"
    797             } 
     797            }
    798798            set type "opendx"
    799799        } elseif {[$_field element $cname.dx] != ""} {
     
    807807        } elseif {[$_field element $cname.dicom] != ""} {
    808808            set type "dicom"
    809         }
     809        }
    810810        set _comp2style($cname) ""
    811811        if { $type == "" } {
     
    817817            set extents [$_field get $cname.extents]
    818818        } else {
    819             set extents 1 
     819            set extents 1
    820820        }
    821821        set _comp2extents($cname) $extents
     
    880880            }
    881881        } elseif {$type == "points-on-mesh"} {
    882             if { ![BuildPointsOnMesh $cname] } {
     882            if { ![BuildPointsOnMesh $cname] } {
    883883                continue;               # Ignore this component
    884884            }
     
    981981        return 0
    982982    }
    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
    984984    # dimension.
    985985    set dim ""
     
    998998    #        the label and units for each field will be specified there.
    999999    #
    1000     # FIXME: Test that every <field><component> has the same field names, 
     1000    # FIXME: Test that every <field><component> has the same field names,
    10011001    #        units, components.
    10021002    #
     
    10701070# isunirect2d  --
    10711071#
    1072 # Returns if the field is a unirect2d object. 
     1072# Returns if the field is a unirect2d object.
    10731073#
    10741074itcl::body Rappture::Field::isunirect2d { } {
     
    10791079# isunirect3d  --
    10801080#
    1081 # Returns if the field is a unirect3d object. 
     1081# Returns if the field is a unirect3d object.
    10821082#
    10831083itcl::body Rappture::Field::isunirect3d { } {
     
    10881088# flowhints  --
    10891089#
    1090 # Returns the hints associated with a flow vector field. 
     1090# Returns the hints associated with a flow vector field.
    10911091#
    10921092itcl::body Rappture::Field::flowhints { cname } {
     
    11001100# style  --
    11011101#
    1102 # Returns the style associated with a component of the field. 
     1102# Returns the style associated with a component of the field.
    11031103#
    11041104itcl::body Rappture::Field::style { cname } {
     
    11371137# extents --
    11381138#
    1139 # Returns if the field is a unirect2d object. 
     1139# Returns if the field is a unirect2d object.
    11401140#
    11411141itcl::body Rappture::Field::extents {{cname -overall}} {
     
    11531153        }
    11541154        return $max
    1155     } 
     1155    }
    11561156    if { $cname == "component0"} {
    11571157        set cname [lindex [components -name] 0]
     
    11701170    set f [open "$tmpfile" "w"]
    11711171    fconfigure $f -translation binary -encoding binary
    1172     puts $f $contents 
     1172    puts $f $contents
    11731173    close $f
    11741174
     
    11871187    set dataAttrs [$dataset GetPointData]
    11881188    if { $dataAttrs == ""} {
    1189         puts stderr "WARNING: No point data found in \"$_path\""
     1189        puts stderr "WARNING: No point data found in \"$_path\""
    11901190        rename $reader ""
    11911191        return 0
     
    12041204    set f [open "$tmpfile" "w"]
    12051205    fconfigure $f -translation binary -encoding binary
    1206     puts $f $contents 
     1206    puts $f $contents
    12071207    close $f
    12081208
     
    12241224    set _dim 0
    12251225    if { $xmax > $xmin } {
    1226         incr _dim
     1226        incr _dim
    12271227    }
    12281228    if { $ymax > $ymin } {
    1229         incr _dim
     1229        incr _dim
    12301230    }
    12311231    if { $zmax > $zmin } {
    1232         incr _dim
     1232        incr _dim
    12331233    }
    12341234    if { $_viewer == "" } {
    1235         if { $_dim == 2 } {
    1236             set _viewer contour
    1237         } else {
    1238             set _viewer isosurface
    1239         }
     1235        if { $_dim == 2 } {
     1236            set _viewer contour
     1237        } else {
     1238            set _viewer isosurface
     1239        }
    12401240    }
    12411241    set _comp2dims($cname) ${_dim}D
     
    12451245        for { set i 0 } { $i < $numPoints } { incr i } {
    12461246            set point [$dataset GetPoint $i]
    1247             $xv append [lindex $point 0] 
     1247            $xv append [lindex $point 0]
    12481248        }
    12491249        set yv [blt::vector create \#auto]
     
    12621262        set numTuples [$array GetNumberOfTuples]
    12631263        for { set i 0 } { $i < $numTuples } { incr i } {
    1264             $yv append [$array GetComponent $i 0] 
     1264            $yv append [$array GetComponent $i 0]
    12651265        }
    12661266        $xv sort $yv
    12671267        set _comp2xy($cname) [list $xv $yv]
    12681268    }
    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]
    12711271    lappend limits z [list $zmin $zmax]
    12721272    set dataAttrs [$dataset GetPointData]
    12731273    if { $dataAttrs == ""} {
    1274         puts stderr "WARNING: No point data found in \"$_path\""
     1274        puts stderr "WARNING: No point data found in \"$_path\""
    12751275        rename $reader ""
    12761276        return 0
     
    12801280    set numArrays [$dataAttrs GetNumberOfArrays]
    12811281    if { $numArrays > 0 } {
    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
     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
    12861286            if {$i == 0} {
    12871287                set vmin $min
    12881288                set vmax $max
    12891289            }
    1290             lappend limits $fname [list $min $max]
     1290            lappend limits $fname [list $min $max]
    12911291            set _fld2Units($fname) ""
    1292             set _fld2Label($fname) $fname
     1292            set _fld2Label($fname) $fname
    12931293            # Let the VTK file override the <type> designated.
    12941294            set _fld2Components($fname) [$array GetNumberOfComponents]
    12951295            lappend _comp2fldName($cname) $fname
    1296         }
    1297     }
    1298    
     1296        }
     1297    }
     1298
    12991299    lappend limits v [list $vmin $vmax]
    13001300    set _comp2limits($cname) $limits
     
    13061306# vtkdata --
    13071307#
    1308 #       Returns a string representing the mesh and field data for a specific
    1309 #       component in the legacy VTK file format.
     1308#        Returns a string representing the mesh and field data for a specific
     1309#        component in the legacy VTK file format.
    13101310#
    13111311itcl::body Rappture::Field::vtkdata {cname} {
     
    13131313        set cname "component"
    13141314    }
    1315     # DX: Convert DX to VTK 
     1315    # DX: Convert DX to VTK
    13161316    if {[info exists _comp2dx($cname)]} {
    13171317        set data $_comp2dx($cname)
     
    13191319        return [Rappture::DxToVtk $data]
    13201320    }
    1321     # Unirect3d: isosurface 
     1321    # Unirect3d: isosurface
    13221322    if {[info exists _comp2unirect3d($cname)]} {
    13231323        return [$_comp2unirect3d($cname) vtkdata]
    13241324    }
    1325     # VTK file data: 
     1325    # VTK file data:
    13261326    if { [info exists _comp2vtk($cname)] } {
    13271327        return $_comp2vtk($cname)
     
    13291329    # Points on mesh:  Construct VTK file output.
    13301330    if { [info exists _comp2mesh($cname)] } {
    1331         # Data is in the form mesh and vector
    1332         foreach {mesh vector} $_comp2mesh($cname) break
     1331        # Data is in the form mesh and vector
     1332        foreach {mesh vector} $_comp2mesh($cname) break
    13331333        set label $cname
    13341334        regsub -all { } $label {_} label
    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]
     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]
    13391339
    13401340        if { $_comp2assoc($cname) == "pointdata" } {
     
    13771377            }
    13781378        }
    1379         append out [$vector range 0 end] 
     1379        append out [$vector range 0 end]
    13801380        append out "\n"
    13811381        if 0 {
    13821382            VerifyVtkDataSet $out
    13831383        }
    1384         return $out
     1384        return $out
    13851385    }
    13861386    error "can't find vtkdata for $cname. This method should only be called by the vtkheightmap widget"
     
    13901390# BuildPointsOnMesh --
    13911391#
    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).
     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).
    13951395#
    13961396itcl::body Rappture::Field::BuildPointsOnMesh {cname} {
     
    14011401    set path [$_field get $cname.mesh]
    14021402    if {[$_xmlobj element $path] == ""} {
    1403         # Unknown mesh designated.
    1404         return 0
     1403        # Unknown mesh designated.
     1404        return 0
    14051405    }
    14061406    set viewer [$_field get "about.view"]
     
    14221422    # Handle bizarre cases that hopefully will be deprecated.
    14231423    if { $element == "unirect3d" } {
    1424         # Special case: unirect3d (should be deprecated) + flow.
     1424        # Special case: unirect3d (should be deprecated) + flow.
    14251425        if { [$_field element $cname.extents] != "" } {
    14261426            set vectorsize [$_field get $cname.extents]
    14271427        } else {
    1428             set vectorsize 1 
     1428            set vectorsize 1
    14291429        }
    14301430        set _type unirect3d
    1431         set _dim 3
     1431        set _dim 3
    14321432        if { $_viewer == "" } {
    14331433            set _viewer flowvis
    14341434        }
    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]
     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]
    14391439        set limits {}
    14401440        foreach axis { x y z } {
    14411441            lappend limits $axis [$_comp2unirect3d($cname) limits $axis]
    14421442        }
    1443         # Get the data limits 
     1443        # Get the data limits
    14441444        set vector [$_comp2unirect3d($cname) valuesObj]
    14451445        set minmax [VectorLimits $vector $vectorsize]
     
    14471447        lappend limits v      $minmax
    14481448        set _comp2limits($cname) $limits
    1449         if {[$_field element $cname.flow] != ""} {
    1450             set _comp2flowhints($cname) \
    1451                 [Rappture::FlowHints ::\#auto $_field $cname $_units]
    1452         }
    1453         incr _counter
    1454         return 1
     1449        if {[$_field element $cname.flow] != ""} {
     1450            set _comp2flowhints($cname) \
     1451                [Rappture::FlowHints ::\#auto $_field $cname $_units]
     1452        }
     1453        incr _counter
     1454        return 1
    14551455    }
    14561456    if { $element == "unirect2d" && [$_field element $cname.flow] != "" } {
    1457         # Special case: unirect2d (normally deprecated) + flow.
     1457        # Special case: unirect2d (normally deprecated) + flow.
    14581458        if { [$_field element $cname.extents] != "" } {
    14591459            set vectorsize [$_field get $cname.extents]
    14601460        } else {
    1461             set vectorsize 1 
     1461            set vectorsize 1
    14621462        }
    14631463        set _type unirect2d
    1464         set _dim 2
     1464        set _dim 2
    14651465        if { $_viewer == "" } {
    14661466            set _viewer "flowvis"
    14671467        }
    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]
     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]
    14751475        set limits {}
    14761476        foreach axis { x y z } {
     
    14841484        blt::vector destroy $xv
    14851485        set _comp2limits($cname) $limits
    1486         incr _counter
    1487         return 1
     1486        incr _counter
     1487        return 1
    14881488    }
    14891489    switch -- $element {
    1490         "cloud" {
    1491             set mesh [Rappture::Cloud::fetch $_xmlobj $path]
     1490        "cloud" {
     1491            set mesh [Rappture::Cloud::fetch $_xmlobj $path]
    14921492            set _type cloud
    1493         }
    1494         "mesh" {
    1495             set mesh [Rappture::Mesh::fetch $_xmlobj $path]
     1493        }
     1494        "mesh" {
     1495            set mesh [Rappture::Mesh::fetch $_xmlobj $path]
    14961496            set _type mesh
    1497         }           
    1498         "unirect2d" {
     1497        }
     1498        "unirect2d" {
    14991499            if { $_viewer == "" } {
    15001500                set _viewer "heightmap"
    15011501            }
    1502             set mesh [Rappture::Unirect2d::fetch $_xmlobj $path]
     1502            set mesh [Rappture::Unirect2d::fetch $_xmlobj $path]
    15031503            set _type unirect2d
    1504         }
     1504        }
    15051505    }
    15061506    if { ![$mesh isvalid] } {
     
    15101510    set _dim [$mesh dimensions]
    15111511    if { $_dim == 3 } {
    1512         set dim 0 
     1512        set dim 0
    15131513        foreach axis {x y z} {
    15141514            foreach {min max} [$mesh limits $axis] {
     
    15231523    }
    15241524
    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    }
    15501551    if {$_dim == 2} {
    1551         # 2D data: By default surface or contour plot using heightmap widget.
    1552         set v [blt::vector create \#auto]
    1553         $v set [$_field get $cname.values]
     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]
    15541555        if { [$v length] == 0 } {
    15551556            return 0
     
    15781579            }
    15791580        }
    1580         set _comp2dims($cname) "[$mesh dimensions]D"
    1581         set _comp2mesh($cname) [list $mesh $v]
    1582         set _comp2style($cname) [$_field get $cname.style]
     1581        set _comp2dims($cname) "[$mesh dimensions]D"
     1582        set _comp2mesh($cname) [list $mesh $v]
     1583        set _comp2style($cname) [$_field get $cname.style]
    15831584        if {[$_field element $cname.flow] != ""} {
    15841585            set _comp2flowhints($cname) \
    15851586                [Rappture::FlowHints ::\#auto $_field $cname $_units]
    15861587        }
    1587         incr _counter
    1588         array unset _comp2limits $cname
     1588        incr _counter
     1589        array unset _comp2limits $cname
    15891590        foreach axis { x y z } {
    15901591            lappend _comp2limits($cname) $axis [$mesh limits $axis]
     
    15931594        lappend _comp2limits($cname) $cname $minmax
    15941595        lappend _comp2limits($cname) v $minmax
    1595         return 1
    1596     } 
     1596        return 1
     1597    }
    15971598    if {$_dim == 3} {
    1598         # 3D data: By default isosurfaces plot using isosurface widget.
     1599        # 3D data: By default isosurfaces plot using isosurface widget.
    15991600        if { $_viewer == "" } {
    16001601            set _viewer "isosurface"
    16011602        }
    1602         set v [blt::vector create \#auto]
    1603         $v set [$_field get $cname.values]
     1603        set v [blt::vector create \#auto]
     1604        $v set [$_field get $cname.values]
    16041605        if { [$v length] == 0 } {
    16051606            return 0
     
    16391640        lappend _comp2limits($cname) $cname $minmax
    16401641        lappend _comp2limits($cname) v $minmax
    1641         return 1
     1642        return 1
    16421643    }
    16431644    error "unhandled case in field dim=$_dim element=$element"
     
    17311732        "tcoords"              2
    17321733        "tensors"              9
    1733         "vectors"              3 
     1734        "vectors"              3
    17341735    }
    17351736    set type [$_field get $cname.elemtype]
    17361737    if { $type == "" } {
    17371738        set type "scalars"
    1738     } 
     1739    }
    17391740    if { ![info exists type2components($type)] } {
    17401741        error "unknown <elemtype> \"$type\" in field"
     
    17531754        set _comp2assoc($cname) "pointdata"
    17541755        return
    1755     } 
     1756    }
    17561757    switch -- $assoc {
    17571758        "pointdata" - "celldata" - "fielddata" {
  • branches/uq/gui/scripts/flowvisviewer.tcl

    r4797 r5121  
    4444    itk_option define -plotoutline plotOutline PlotOutline ""
    4545
    46     private variable _volcomponents   ; # Array of components found
    47     private variable _componentsList   ; # Array of components found
    48     private method BuildVolumeComponents {}
    49     private method GetDatasetsWithComponent { cname }
    50 
    5146    constructor { hostlist args } {
    5247        Rappture::VisViewer::constructor $hostlist
     
    6863    public method get {args}
    6964    public method isconnected {}
    70     public method limits { cname }
    71     public method overMarker { m x }
     65    public method limits { tf }
     66    public method overmarker { m x }
    7267    public method parameters {title args} {
    7368        # do nothing
    7469    }
    75     public method removeDuplicateMarker { m x }
     70    public method rmdupmarker { m x }
    7671    public method scale {args}
    77     public method updateTransferFunctions {}
     72    public method updatetransferfuncs {}
    7873
    7974    protected method Connect {}
     
    9085    protected method ReceiveLegend { tf vmin vmax size }
    9186    protected method Rotate {option x y}
     87    protected method SendDataObjs {}
    9288    protected method SendTransferFuncs {}
    9389    protected method Slice {option args}
     
    135131    private variable _serverObjs   ;# maps dataobj-component to volume ID
    136132                                    # in the server
     133    private variable _sendobjs ""  ;# list of data objs to send to server
    137134    private variable _recvObjs  ;# list of data objs to send to server
    138135    private variable _obj2style    ;# maps dataobj-component to transfunc
     
    181178    $_dispatcher dispatch $this !legend "[itcl::code $this ResizeLegend]; list"
    182179
     180    # Send dataobjs event
     181    $_dispatcher register !send_dataobjs
     182    $_dispatcher dispatch $this !send_dataobjs \
     183        "[itcl::code $this SendDataObjs]; list"
     184
    183185    # Send transferfunctions event
    184186    $_dispatcher register !send_transfunc
     
    230232    $_arcball quaternion $q
    231233
    232     set _limits(v) [list 0.0 1.0]
     234    set _limits(vmin) 0.0
     235    set _limits(vmax) 1.0
    233236    set _reset 1
    234237
     
    332335    set _image(legend) [image create photo]
    333336    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
    335339    } {
    336340        usual
     
    556560# ----------------------------------------------------------------------
    557561itcl::body Rappture::FlowvisViewer::destructor {} {
     562    set _sendobjs ""  ;# stop any send in progress
    558563    $_dispatcher cancel !rebuild
     564    $_dispatcher cancel !send_dataobjs
    559565    $_dispatcher cancel !send_transfunc
    560566    image delete $_image(plot)
     
    666672# ----------------------------------------------------------------------
    667673itcl::body Rappture::FlowvisViewer::delete {args} {
    668     flow stop
     674     flow stop
    669675    if {[llength $args] == 0} {
    670676        set args $_dlist
     
    716722# ----------------------------------------------------------------------
    717723itcl::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
    745732            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
    748736                } 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
    752739                    }
    753                     if {$max > $amax} {
    754                         set amax $max
     740                    if {$max > $_limits(${axis}max)} {
     741                        set _limits(${axis}max) $max
    755742                    }
    756                     set _limits($axis) [list $amin $amax]
    757743                }
    758744            }
    759745        }
    760746    }
    761     #BuildVolumeComponents
    762747}
    763748
     
    872857        if { $_reportClientInfo }  {
    873858            # Tell the server the viewer, hub, user and session.
    874             # Do this immediately on connect before buffering any commands
     859            # Do this immediately on connect before buffing any commands
    875860            global env
    876861
     
    929914    # disconnected -- no more data sitting on server
    930915    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# ----------------------------------------------------------------------
     926itcl::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
    9311001}
    9321002
     
    10271097    set h [winfo height $c]
    10281098    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
    10291104    set ly [expr {$h - 1}]
    1030     if {"" == [$c find withtag colorbar]} {
     1105    if {"" == [$c find withtag transfunc]} {
    10311106        $c create image 10 10 -anchor nw \
    1032             -image $_image(legend) -tags colorbar
     1107            -image $_image(legend) -tags transfunc
    10331108        $c create text $lx $ly -anchor sw \
    10341109            -fill $itk_option(-plotforeground) -tags "limits vmin"
    10351110        $c create text [expr {$w-$lx}] $ly -anchor se \
    10361111            -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]
    10391115    }
    10401116    # Display the markers used by the active transfer function.
    10411117    set tf $_obj2style($tag)
    1042     foreach {vmin vmax} [limits $tf] break
    1043     $c itemconfigure vmin -text [format %g $vmin]
     1118    array set limits [limits $tf]
     1119    $c itemconfigure vmin -text [format %.2g $limits(vmin)]
    10441120    $c coords vmin $lx $ly
    10451121
    1046     $c itemconfigure vmax -text [format %g $vmax]
     1122    $c itemconfigure vmax -text [format %.2g $limits(vmax)]
    10471123    $c coords vmax [expr {$w-$lx}] $ly
    10481124
     
    10841160    set dataobj [lindex $parts 0]
    10851161    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.
    10871164    unset _recvObjs($tag)
    10881165    if { [array size _recvObjs] == 0 } {
    1089         updateTransferFunctions
     1166        updatetransferfuncs
    10901167    }
    10911168}
     
    11311208        foreach comp [$dataobj components] {
    11321209            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]
    11431212            set nbytes [string length $data]
    11441213            if { $_reportClientInfo }  {
    11451214                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]
    11501220                lappend info "dataset_label" [$dataobj hints label]
    11511221                lappend info "dataset_size"  $nbytes
     
    11551225            set extents [$dataobj extents $comp]
    11561226            # I have a field. Is a vector field or a volume field?
    1157             if { !$isvtk && $extents == 1 } {
     1227            if { $extents == 1 } {
    11581228                set cmd "volume data follows $nbytes $tag\n"
    11591229            } else {
     
    12591329    foreach key [array names _serverObjs *-*] {
    12601330        if {[string match $_first-* $key]} {
    1261             array set styles {
     1331            array set style {
    12621332                -cutplanes 1
    12631333            }
    12641334            foreach {dataobj comp} [split $key -] break
    1265             array set styles [lindex [$dataobj components -style $comp] 0]
    1266             if {$what != "-cutplanes" || $styles(-cutplanes)} {
     1335            array set style [lindex [$dataobj components -style $comp] 0]
     1336            if {$what != "-cutplanes" || $style(-cutplanes)} {
    12671337                lappend rlist $_serverObjs($key)
    12681338            }
     
    13241394
    13251395itcl::body Rappture::FlowvisViewer::PanCamera {} {
     1396    #set x [expr ($_view(xpan)) / $_limits(xrange)]
     1397    #set y [expr ($_view(ypan)) / $_limits(yrange)]
    13261398    set x $_view(xpan)
    13271399    set y $_view(ypan)
     
    15871659                set tf $_activeTf
    15881660                set _settings($this-$tf-opacity) $opacity
    1589                 updateTransferFunctions
     1661                updatetransferfuncs
    15901662            }
    15911663        }
     
    15981670                set tf $_activeTf
    15991671                set _settings($this-$tf-thickness) $sval
    1600                 updateTransferFunctions
     1672                updatetransferfuncs
    16011673            }
    16021674        }
     
    17061778#              now.
    17071779#
    1708 itcl::body Rappture::FlowvisViewer::NameTransferFunc { dataobj cname } {
    1709     array set styles {
     1780itcl::body Rappture::FlowvisViewer::NameTransferFunc { dataobj comp } {
     1781    array set style {
    17101782        -color BCGYR
    17111783        -levels 6
     1784        -opacity 1.0
    17121785        -light 40
    1713         -opacity 1.0
    17141786        -transp 50
    17151787    }
    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
    17231796}
    17241797
     
    17331806#
    17341807itcl::body Rappture::FlowvisViewer::ComputeTransferFunc { tf } {
    1735     array set styles {
     1808    array set style {
    17361809        -color BCGYR
    17371810        -levels 6
     
    17451818        return 0
    17461819    }
    1747     array set styles [lindex [$dataobj components -style $comp] 0]
     1820    array set style [lindex [$dataobj components -style $comp] 0]
    17481821
    17491822
     
    17631836    if { ![info exists _isomarkers($tf)] } {
    17641837        # Have to defer creation of isomarkers until we have data limits
    1765         if { [info exists styles(-markers)] &&
    1766              [llength $styles(-markers)] > 0  } {
    1767             ParseMarkersOption $tf $styles(-markers)
     1838        if { [info exists style(-markers)] &&
     1839             [llength $style(-markers)] > 0  } {
     1840            ParseMarkersOption $tf $style(-markers)
    17681841        } else {
    1769             ParseLevelsOption $tf $styles(-levels)
    1770         }
    1771     }
    1772     if { [info exists styles(-nonuniformcolors)] } {
    1773         foreach { value color } $styles(-nonuniformcolors) {
     1842            ParseLevelsOption $tf $style(-levels)
     1843        }
     1844    }
     1845    if { [info exists style(-nonuniformcolors)] } {
     1846        foreach { value color } $style(-nonuniformcolors) {
    17741847            append cmap "$value [Color2RGB $color] "
    17751848        }
    17761849    } else {
    1777         set cmap [ColorsToColormap $styles(-color)]
     1850        set cmap [ColorsToColormap $style(-color)]
    17781851    }
    17791852    set tag $this-$tf
    17801853    if { ![info exists _settings($tag-opacity)] } {
    1781         set _settings($tag-opacity) $styles(-opacity)
     1854        set _settings($tag-opacity) $style(-opacity)
    17821855    }
    17831856    set max 1.0 ;#$_settings($tag-opacity)
     
    18441917itcl::configbody Rappture::FlowvisViewer::plotbackground {
    18451918    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"
    18501922    }
    18511923}
     
    18561928itcl::configbody Rappture::FlowvisViewer::plotforeground {
    18571929    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"
    18651933    }
    18661934}
     
    18961964            set x [expr {double($i)/($levels+1)}]
    18971965            set m [Rappture::IsoMarker \#auto $c $this $tf]
    1898             $itk_component(legend) itemconfigure labels -fill $itk_option(-plotforeground)
    18991966            $m relval $x
    19001967            lappend _isomarkers($tf) $m
     
    19031970        foreach x $levels {
    19041971            set m [Rappture::IsoMarker \#auto $c $this $tf]
    1905             $itk_component(legend) itemconfigure labels -fill $itk_option(-plotforeground)
    19061972            $m relval $x
    19071973            lappend _isomarkers($tf) $m
     
    19311997            set value [expr {$value * 0.01}]
    19321998            set m [Rappture::IsoMarker \#auto $c $this $tf]
    1933             $itk_component(legend) itemconfigure labels -fill $itk_option(-plotforeground)
    19341999            $m relval $value
    19352000            lappend _isomarkers($tf) $m
     
    19372002            # ${n} : Set absolute value.
    19382003            set m [Rappture::IsoMarker \#auto $c $this $tf]
    1939             $itk_component(legend) itemconfigure labels -fill $itk_option(-plotforeground)
    19402004            $m absval $value
    19412005            lappend _isomarkers($tf) $m
     
    19472011# USAGE: UndateTransferFuncs
    19482012# ----------------------------------------------------------------------
    1949 itcl::body Rappture::FlowvisViewer::updateTransferFunctions {} {
     2013itcl::body Rappture::FlowvisViewer::updatetransferfuncs {} {
    19502014    $_dispatcher event -after 100 !send_transfunc
    19512015}
     
    19582022    set c $itk_component(legend)
    19592023    set m [Rappture::IsoMarker \#auto $c $this $tf]
    1960     $itk_component(legend) itemconfigure labels -fill $itk_option(-plotforeground)
    19612024    set w [winfo width $c]
    19622025    $m relval [expr {double($x-10)/($w-20)}]
    19632026    lappend _isomarkers($tf) $m
    1964     updateTransferFunctions
     2027    updatetransferfuncs
    19652028    return 1
    19662029}
    19672030
    1968 itcl::body Rappture::FlowvisViewer::removeDuplicateMarker { marker x } {
     2031itcl::body Rappture::FlowvisViewer::rmdupmarker { marker x } {
    19692032    set tf [$marker transferfunc]
    19702033    set bool 0
     
    19862049        }
    19872050        set _isomarkers($tf) $list
    1988         updateTransferFunctions
     2051        updatetransferfuncs
    19892052    }
    19902053    return $bool
    19912054}
    19922055
    1993 itcl::body Rappture::FlowvisViewer::overMarker { marker x } {
     2056itcl::body Rappture::FlowvisViewer::overmarker { marker x } {
    19942057    set tf [$marker transferfunc]
    19952058    if { [info exists _isomarkers($tf)] } {
     
    20062069}
    20072070
    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)"
     2071itcl::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)"
    20122076        return [array get _limits]
    20132077    }
    20142078    set min ""; set max ""
    2015     foreach tag [GetDatasetsWithComponent $cname] {
     2079    foreach {dataobj comp} $_style2objs($tf) {
     2080        set tag $dataobj-$comp
    20162081        if { ![info exists _serverObjs($tag)] } {
    20172082            puts stderr "$tag not in serverObjs?"
    20182083            continue
    20192084        }
    2020         if { ![info exists _limits($tag)] } {
     2085        if { ![info exists _limits($tag-min)] } {
    20212086            puts stderr "$tag no min?"
    20222087            continue
    20232088        }
    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]
    20372103}
    20382104
     
    21862252    }
    21872253
    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
    21892273    $itk_component(colormap) value "BCGYR"
    21902274    bind $inner.colormap <<Value>> \
     
    24972581itcl::body Rappture::FlowvisViewer::SlicerTip {axis} {
    24982582    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))}]
    24992586    return "Move the [string toupper $axis] cut plane.\nCurrently:  $axis = $val%"
    25002587}
     
    29503037    set _settings($this-zoom) $_view(zoom)
    29513038}
    2952 
    2953 # Reset global settings from dataset's settings.
    2954 itcl::body Rappture::FlowvisViewer::BuildVolumeComponents {} {
    2955     $itk_component(volcomponents) choices delete 0 end
    2956     foreach name $_componentsList {
    2957         $itk_component(volcomponents) choices insert end $name $name
    2958     }
    2959     set _current [lindex $_componentsList 0]
    2960     $itk_component(volcomponents) value $_current
    2961 }
    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             continue
    2972         }
    2973         lappend list $tag
    2974     }
    2975     return $list
    2976 }
  • branches/uq/gui/scripts/gauge.tcl

    r5029 r5121  
    4444    itk_option define -varname varname Varname ""
    4545    itk_option define -label label Label ""
     46    itk_option define -validatecommand validateCommand ValidateCommand ""
    4647
    4748    constructor {args} { # defined below }
     
    115116            -borderwidth 1 -relief flat -textvariable [itcl::scope _value]
    116117    } {
     118        keep -font
    117119        rename -background -textbackground textBackground Background
    118120    }
     
    247249    }
    248250
    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]
    253266    }
    254267
  • branches/uq/gui/scripts/imageresult.tcl

    r3844 r5121  
    7272    pack propagate $itk_component(hull) no
    7373
    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
    7577    pack $itk_interior.panes -expand yes -fill both
    7678    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  
    3030    private common   _normalIcon [Rappture::icon nvlegendmark]
    3131    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 }
    3732
    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        }
    84163    }
    85164}
    86 
    87 itcl::body Rappture::IsoMarker::visible { bool } {
    88     if { $bool } {
    89         absval $_value
    90         $_canvas itemconfigure $_tick -state normal
    91         $_canvas raise $_tick
    92     } else {
    93         $_canvas itemconfigure $_tick -state hidden
    94     }
    95 }
    96 
    97 itcl::body Rappture::IsoMarker::screenpos { } {
    98     set x [relval]
    99     if { $x < 0.0 } {
    100         set x 0.0
    101     } elseif { $x > 1.0 } {
    102         set x 1.0
    103     }
    104     set low 10
    105     set w [winfo width $_canvas]
    106     set high [expr {$w  - 10}]
    107     set x [expr {round($x*($high - $low) + $low)}]
    108     return $x
    109 }
    110 
    111 itcl::body Rappture::IsoMarker::absval { {x "-get"} } {
    112     if { $x != "-get" } {
    113         set _value $x
    114         set y 31
    115         $_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 $_value
    121 }
    122 
    123 itcl::body Rappture::IsoMarker::relval  { {x "-get"} } {
    124     foreach {min max} [$_nvobj limits $_tf] break
    125     if { $x == "-get" } {
    126         if { $max == $min } {
    127             if { $max == 0.0 } {
    128                 set min 0.0
    129                 set max 1.0
    130             } 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.0
    138         set max 1.0
    139     }
    140     if { [catch {expr $max - $min} r] != 0 } {
    141         return 0.0
    142     }           
    143     absval [expr {($x * $r) + $min}]
    144 }
    145 
    146 itcl::body Rappture::IsoMarker::EnterTick {} {
    147     set _activeMotion 1
    148     activate yes
    149     $_canvas raise $_tick
    150 }
    151 
    152 itcl::body Rappture::IsoMarker::LeaveTick {} {
    153     set _activeMotion 0
    154     activate no
    155 }
    156 
    157 itcl::body Rappture::IsoMarker::StartDrag { x y } {
    158     $_canvas raise $_tick
    159     set _activePress 1
    160     activate yes
    161     $_canvas itemconfigure limits -state hidden
    162     $_canvas itemconfigure title -state hidden
    163 }
    164 
    165 itcl::body Rappture::IsoMarker::StopDrag { x y } {
    166     if { ![$_nvobj removeDuplicateMarker $this $x]} {
    167         ContinueDrag $x $y
    168     }
    169     set _activePress 0
    170     activate no
    171     $_canvas itemconfigure limits -state normal
    172     $_canvas itemconfigure title -state normal
    173 }
    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 $x
    179     $_nvobj updateTransferFunctions
    180     $_canvas raise $_tick
    181     set _activePress 1
    182     activate yes
    183     $_canvas itemconfigure limits -state hidden
    184     $_canvas itemconfigure title -state hidden
    185 }
    186 
  • branches/uq/gui/scripts/main.tcl

    r5029 r5121  
    9393    value -tool tool.xml
    9494    list  -load ""
     95    value -input ""
    9596    value -nosim 0
    9697}
     
    103104    incr numTries -1
    104105    if { $numTries < 0 } {
    105         return
     106        return
    106107    }
    107108    global env
    108109    set paramsFile $env(TOOL_PARAMETERS)
    109110    if { ![file readable $paramsFile] } {
    110         after 500 ReadToolParmeters $numTries
    111         return
     111        after 500 ReadToolParmeters $numTries
     112        return
    112113    }
    113114    catch {
     
    138139}
    139140
     141set inputobj {}
     142if {$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
    140152# open the XML file containing the tool parameters
    141153if {![file exists $params(-tool)]} {
     
    147159    # run.xml files they are loading.
    148160    set pseudotool ""
    149     if {0 == [llength $loadobjs]} {
     161    if {[llength $loadobjs] == 0 && $inputobj eq ""} {
    150162        puts stderr "can't find tool \"$params(-tool)\""
    151163        exit 1
     
    155167    # if there are loaders or notes, they will still need
    156168    # examples/ and docs/ dirs from the install location
    157     foreach runobj $loadobjs {
     169    set check [concat $loadobjs $inputobj]
     170    foreach runobj $check {
    158171        set tdir \
    159172            [string trim [$runobj get tool.version.application.directory(tool)]]
     
    367380    if { $arrangement != "side-by-side" &&
    368381            ($type == "manual" || $type == "manual-resim" ||
    369              $type == "auto" || $style == "wizard") } {
     382             $type == "auto" || $style == "wizard") } {
    370383        # in "auto" mode, we don't need a simulate button
    371384        $f.analyze configure -simcontrol off
     
    377390
    378391# load previous xml runfiles
    379 if {0 != [llength $params(-load)]} {
     392if {[llength $params(-load)] > 0} {
    380393    foreach runobj $loadobjs {
    381         # this doesn't seem to work with loaders
    382         # loaders seem to get their value after this point
    383         # may need to tell loader elements to update its value
    384         $tool load $runobj
    385394        $f.analyze load $runobj
    386395    }
     396    # load the inputs for the very last run
     397    $tool load $runobj
     398
    387399    # don't need simulate button if we cannot simulate
    388400    if {$params(-nosim)} {
     
    391403    $f.analyze configure -notebookpage analyze
    392404    $win.pager current analyzer
     405} elseif {$params(-input) ne ""} {
     406    $tool load $inputobj
    393407}
    394408puts "DONE main.tcl"
     409# let components (loaders) settle after the newly loaded runs
     410update
     411
     412foreach 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
    395431wm deiconify .main
  • branches/uq/gui/scripts/mesh.tcl

    r4798 r5121  
    1 # -*- mode: tcl; indent-tabs-mode: nil -*- 
     1# -*- mode: tcl; indent-tabs-mode: nil -*-
    22
    33# ----------------------------------------------------------------------
     
    1818package require Itcl
    1919
    20 namespace eval Rappture { 
    21     # forward declaration 
     20namespace eval Rappture {
     21    # forward declaration
    2222}
    2323
    2424itcl::class Rappture::Mesh {
    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.
     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.
    3737    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
    4343    }
    4444    public method points {}
     
    5858    public method vtkdata {{what -partial}}
    5959    public method type {} {
    60         return $_type
     60        return $_type
    6161    }
    6262    public method numpoints {} {
    63         return $_numPoints
     63        return $_numPoints
    6464    }
    6565    public method numcells {} {
    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    
     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
    7777    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 {}
    8382    private method ReadGrid { path }
    8483    private method ReadUnstructuredGrid { path }
     
    165164    foreach u $units axis { x y z } {
    166165        if { $u != "" } {
    167             set _axis2units($axis) $u 
     166            set _axis2units($axis) $u
    168167        } else {
    169             set _axis2units($axis) $first 
     168            set _axis2units($axis) $first
    170169        }
    171170    }
     
    180179    # Meshes comes in a variety of flavors
    181180    #
    182     # Dimensionality is determined from the <dimension> tag. 
     181    # Dimensionality is determined from the <dimension> tag.
    183182    #
    184183    # <vtk> described mesh
    185184    # <element> +  <node> definitions
    186     # <grid>            rectangular mesh 
     185    # <grid>            rectangular mesh
    187186    # <unstructured>    homogeneous cell type mesh.
    188187
     
    190189    set subcount 0
    191190    foreach cname [$_mesh children] {
    192         foreach type { vtk grid unstructured } {
    193             if { $cname == $type } {
    194                 incr subcount
    195                 break
    196             }
    197         }
     191        foreach type { vtk grid unstructured } {
     192            if { $cname == $type } {
     193                incr subcount
     194                break
     195            }
     196        }
    198197    }
    199198    if {[$_mesh element "node"] != "" ||
     
    207206    }
    208207    if { $subcount > 1 } {
    209         puts stderr "WARNING: too many mesh types specified for \"$path\"."
     208        puts stderr "WARNING: too many mesh types specified for \"$path\"."
    210209        return
    211210    }
    212211    set result 0
    213212    if { [$_mesh element "vtk"] != ""} {
    214         set result [ReadVtk $path]
     213        set result [ReadVtk $path]
    215214    } elseif {[$_mesh element "grid"] != "" } {
    216         set result [ReadGrid $path]
     215        set result [ReadGrid $path]
    217216    } elseif {[$_mesh element "unstructured"] != "" } {
    218         set result [ReadUnstructuredGrid $path]
     217        set result [ReadUnstructuredGrid $path]
    219218    } elseif {[$_mesh element "node"] != "" && [$_mesh element "element"] != ""} {
    220219        set result [ReadNodesElements $path]
     
    232231
    233232    if { $_xCoords != "" } {
    234         blt::vector destroy $_xCoords
     233        blt::vector destroy $_xCoords
    235234    }
    236235    if { $_yCoords != "" } {
    237         blt::vector destroy $_yCoords
    238     }
    239 }
    240 
    241 #
    242 # vtkdata -- 
    243 #
    244 #       This is called by the field object to generate a VTK file to send to
    245 #       the remote render server.  Returns the vtkDataSet object containing
    246 #       (at this point) just the mesh.  The field object doesn't know (or
    247 #       care) what type of mesh is used.  The field object will add field
    248 #       arrays before generating output to send to the remote render server.
     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.
    249248#
    250249itcl::body Rappture::Mesh::vtkdata {{what -partial}} {
    251250    if {$what == "-full"} {
    252251        append out "# vtk DataFile Version 3.0\n"
    253         append out "[hints label]\n"
    254         append out "ASCII\n"
     252        append out "[hints label]\n"
     253        append out "ASCII\n"
    255254        append out $_vtkdata
    256255        return $out
     
    341340itcl::body Rappture::Mesh::mesh { {type "vtk"} } {
    342341    switch $type {
    343         "vtk" {
    344             return ""
    345         }
    346         default {
    347             error "Requested mesh type \"$type\" is unknown."
    348         }
     342        "vtk" {
     343            return ""
     344        }
     345        default {
     346            error "Requested mesh type \"$type\" is unknown."
     347        }
    349348    }
    350349}
     
    427426        }
    428427    }
     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    }
    429440}
    430441
     
    432443    set string [$_xmlobj get $path.dim]
    433444    if { $string == "" } {
    434         puts stderr "WARNING: no tag <dim> found in mesh \"$path\"."
     445        puts stderr "WARNING: no tag <dim> found in mesh \"$path\"."
    435446        return 0
    436447    }
     
    468479        return 0
    469480    }
    470     # Create a VTK file with the mesh in it. 
     481    # Create a VTK file with the mesh in it.
    471482    set _vtkdata [$_xmlobj get $path.vtk]
    472483    append out "# vtk DataFile Version 3.0\n"
     
    500511}
    501512
    502 itcl::body Rappture::Mesh::GetCellCount { xNum yNum zNum } {
    503     set numCells 1
    504     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 $numCells
    514 }
    515 
    516513itcl::body Rappture::Mesh::ReadGrid { path } {
    517514    set _type "grid"
     
    524521    set numCurvilinear 0
    525522    foreach axis { x y z } {
    526         set min    [$_xmlobj get "$path.grid.${axis}axis.min"]
    527         set max    [$_xmlobj get "$path.grid.${axis}axis.max"]
    528         set num    [$_xmlobj get "$path.grid.${axis}axis.numpoints"]
    529         set coords [$_xmlobj get "$path.grid.${axis}coords"]
    530         set dim    [$_xmlobj get "$path.grid.${axis}dim"]
    531         if { $min != "" && $max != "" && $num != "" && $num > 0 } {
    532             set ${axis}Min $min
    533             set ${axis}Max $max
    534             set ${axis}Num $num
     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
    535532            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"
    537534                return 0
    538535            }
    539             incr numUniform
    540         } elseif { $coords != "" } {
    541             incr numRectilinear
    542             set ${axis}Coords $coords
    543         } elseif { $dim != "" } {
     536            incr numUniform
     537        } elseif { $coords != "" } {
     538            incr numRectilinear
     539            set ${axis}Coords $coords
     540        } elseif { $dim != "" } {
    544541            set ${axis}Num $dim
    545542            incr numCurvilinear
     
    548545    set _dim [expr $numRectilinear + $numUniform + $numCurvilinear]
    549546    if { $_dim == 0 } {
    550         # No data found.
     547        # No data found.
    551548        puts stderr "WARNING: bad grid \"$path\": no data found"
    552         return 0
     549        return 0
    553550    }
    554551    if { $numCurvilinear > 0 } {
     
    563560            return 0
    564561        }
    565         if { ![info exists xNum] } {
     562        if { ![info exists xNum] } {
    566563            puts stderr "WARNING: bad grid \"$path\": invalid dimensions for curvilinear grid: missing <xdim> from grid description."
    567564            return 0
     
    575572        if { [info exists zNum] } {
    576573            set _dim 3
    577             set _numPoints [expr $xNum * $yNum * $zNum]
    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 } {
    580577                puts stderr "WARNING: bad grid \"$path\": invalid grid: \# of points does not match dimensions <xdim> * <ydim> * <zdim>"
    581578                return 0
     
    586583            }
    587584            $all split $xv $yv $zv
    588             foreach axis {x y z} {
     585            foreach axis {x y z} {
    589586                set vector [set ${axis}v]
    590587                set _limits($axis) [$vector limits]
    591             }
    592             append out "DATASET STRUCTURED_GRID\n"
    593             append out "DIMENSIONS $xNum $yNum $zNum\n"
    594             append out "POINTS $_numPoints double\n"
     588            }
     589            append out "DATASET STRUCTURED_GRID\n"
     590            append out "DIMENSIONS $xNum $yNum $zNum\n"
     591            append out "POINTS $_numPoints double\n"
    595592            append out [$all range 0 end]
    596593            append out "\n"
    597             set _vtkdata $out
     594            set _vtkdata $out
    598595        } elseif { [info exists yNum] } {
    599596            set _dim 2
    600             set _numPoints [expr $xNum * $yNum]
    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 } {
    603600                puts stderr "WARNING: bad grid \"$path\": \# of points does not match dimensions <xdim> * <ydim>"
    604601                return 0
     
    608605                return 0
    609606            }
    610             foreach axis {x y} {
     607            foreach axis {x y} {
    611608                set vector [set ${axis}v]
    612609                set _limits($axis) [$vector limits]
    613             }
     610            }
    614611            set _limits(z) [list 0 0]
    615612            $zv seq 0 0 [$xv length]
    616613            $all merge $xv $yv $zv
    617             append out "DATASET STRUCTURED_GRID\n"
    618             append out "DIMENSIONS $xNum $yNum 1\n"
    619             append out "POINTS $_numPoints double\n"
     614            append out "DATASET STRUCTURED_GRID\n"
     615            append out "DIMENSIONS $xNum $yNum 1\n"
     616            append out "POINTS $_numPoints double\n"
    620617            append out [$all range 0 end]
    621618            append out "\n"
    622             set _vtkdata $out
     619            set _vtkdata $out
    623620        } else {
    624621            set _dim 1
    625622            set _numPoints $xNum
    626             set _numCells [GetCellCount $xNum 0 0]
     623            set _numCells [expr $xNum - 1]
    627624            if { $_numPoints != $numCoords } {
    628625                puts stderr "WARNING: bad grid \"$path\": \# of points does not match <xdim>"
     
    635632            $zv seq 0 0 [$xv length]
    636633            $all merge $xv $yv $zv
    637             append out "DATASET STRUCTURED_GRID\n"
    638             append out "DIMENSIONS $xNum 1 1\n"
    639             append out "POINTS $_numPoints double\n"
     634            append out "DATASET STRUCTURED_GRID\n"
     635            append out "DIMENSIONS $xNum 1 1\n"
     636            append out "POINTS $_numPoints double\n"
    640637            append out [$all range 0 end]
    641638            append out "\n"
    642             set _vtkdata $out
    643         }
     639            set _vtkdata $out
     640        }
    644641        blt::vector destroy $all $xv $yv $zv
    645         return 1
     642        return 1
    646643    }
    647644    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.
    649646        # This results in a STRUCTURED_POINTS
    650647        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
    662660            set _limits(x) [list $xMin $xMax]
    663661            set _limits(y) [list 0 0]
    664662            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            }
    684684            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\""
    710713            return 0
    711         }
    712         return 1
     714        }
     715        return 1
    713716    }
    714717    # This is the hybrid case.  Some axes are uniform, others are nonuniform.
    715718    set xv [blt::vector create \#auto]
    716719    if { [info exists xMin] } {
    717         $xv seq $xMin $xMax $xNum
    718     } else {
    719         $xv set [$_xmlobj get $path.grid.xcoords]
    720         set xMin [$xv min]
    721         set xMax [$xv max]
    722         set xNum [$xv length]
     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]
    723726    }
    724727    set yv [blt::vector create \#auto]
     
    737740    set zv [blt::vector create \#auto]
    738741    if { $_dim == 3 } {
    739         if { [info exists zMin] } {
    740             $zv seq $zMin $zMax $zNum
    741         }  else {
    742             $zv set [$_xmlobj get $path.grid.zcoords]
    743             set zMin [$zv min]
    744             set zMax [$zv max]
    745             set zNum [$zv length]
    746         }
    747     } else {
    748         set zNum 1
     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
    749752    }
    750753    if { $_dim == 3 } {
    751         set _numPoints [expr $xNum * $yNum * $zNum]
    752         set _numCells [GetCellCount $xNum $yNum $zNum]
    753         append out "DATASET RECTILINEAR_GRID\n"
    754         append out "DIMENSIONS $xNum $yNum $zNum\n"
    755         append out "X_COORDINATES $xNum double\n"
    756         append out [$xv range 0 end]
    757         append out "\n"
    758         append out "Y_COORDINATES $yNum double\n"
    759         append out [$yv range 0 end]
    760         append out "\n"
    761         append out "Z_COORDINATES $zNum double\n"
    762         append out [$zv range 0 end]
    763         append out "\n"
    764         set _vtkdata $out
    765         foreach axis {x y z} {
    766             if { [info exists ${axis}Min] } {
    767                 set _limits($axis) [list [set ${axis}Min] [set ${axis}Max]]
    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        }
    770773    } elseif { $_dim == 2 } {
    771         set _numPoints [expr $xNum * $yNum]
    772         set _numCells [GetCellCount $xNum $yNum 0]
    773         append out "DATASET RECTILINEAR_GRID\n"
    774         append out "DIMENSIONS $xNum $yNum 1\n"
    775         append out "X_COORDINATES $xNum double\n"
    776         append out [$xv range 0 end]
    777         append out "\n"
    778         append out "Y_COORDINATES $yNum double\n"
    779         append out [$yv range 0 end]
    780         append out "\n"
    781         append out "Z_COORDINATES 1 double\n"
    782         append out "0\n"
    783         foreach axis {x y} {
    784             if { [info exists ${axis}Min] } {
    785                 set _limits($axis) [list [set ${axis}Min] [set ${axis}Max]]
    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        }
    788791        set _limits(z) [list 0 0]
    789         set _vtkdata $out
     792        set _vtkdata $out
    790793    } elseif { $_dim == 1 } {
    791794        set _numPoints $xNum
    792         set _numCells [GetCellCount $xNum 0 0]
    793         append out "DATASET RECTILINEAR_GRID\n"
    794         append out "DIMENSIONS $xNum 1 1\n"
    795         append out "X_COORDINATES $xNum double\n"
    796         append out [$xv range 0 end]
    797         append out "\n"
    798         append out "Y_COORDINATES 1 double\n"
    799         append out "0\n"
    800         append out "Z_COORDINATES 1 double\n"
    801         append out "0\n"
     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"
    802805        if { [info exists xMin] } {
    803806            set _limits(x) [list $xMin $xMax]
     
    805808        set _limits(y) [list 0 0]
    806809        set _limits(z) [list 0 0]
    807         set _vtkdata $out
    808     } else {
    809         puts stderr "WARNING: bad grid \"$path\": invalid dimension \"$_dim\""
     810        set _vtkdata $out
     811    } else {
     812        puts stderr "WARNING: bad grid \"$path\": invalid dimension \"$_dim\""
    810813        return 0
    811814    }
    812     blt::vector destroy $xv $yv $zv 
     815    blt::vector destroy $xv $yv $zv
    813816    return 1
    814817}
     
    844847    set celltypes {}
    845848    foreach { a b c } $triangles {
    846         append data " 3 $a $b $c\n"
    847         append celltypes "5\n"
    848         incr _numCells
     849        append data " 3 $a $b $c\n"
     850        append celltypes "5\n"
     851        incr _numCells
    849852    }
    850853    append out "DATASET UNSTRUCTURED_GRID\n"
    851854    append out "POINTS $_numPoints double\n"
    852855    foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] {
    853         append out " $x $y $z\n"
     856        append out " $x $y $z\n"
    854857    }
    855858    set count [expr $_numCells * 4]
     
    876879    set celltypes {}
    877880    foreach { a b c d } $quads {
    878         append data " 4 $a $b $c $d\n"
    879         append celltypes "9\n"
    880         incr _numCells
     881        append data " 4 $a $b $c $d\n"
     882        append celltypes "9\n"
     883        incr _numCells
    881884    }
    882885    append out "DATASET UNSTRUCTURED_GRID\n"
    883886    append out "POINTS $_numPoints double\n"
    884887    foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] {
    885         append out " $x $y $z\n"
     888        append out " $x $y $z\n"
    886889    }
    887890    set count [expr $_numCells * 5]
     
    913916            continue
    914917        }
    915         append data " $numIndices $line\n"
    916         incr _numCells
     918        append data " $numIndices $line\n"
     919        incr _numCells
    917920        set count [expr $count + $numIndices + 1]
    918921    }
     
    920923    append out "POINTS $_numPoints double\n"
    921924    foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] {
    922         append out " $x $y $z\n"
     925        append out " $x $y $z\n"
    923926    }
    924927    append out "VERTICES $_numCells $count\n"
     
    947950            continue
    948951        }
    949         append data " $numIndices $line\n"
    950         incr _numCells
     952        append data " $numIndices $line\n"
     953        incr _numCells
    951954        set count [expr $count + $numIndices + 1]
    952955    }
     
    954957    append out "POINTS $_numPoints double\n"
    955958    foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] {
    956         append out " $x $y $z\n"
     959        append out " $x $y $z\n"
    957960    }
    958961    append out "LINES $_numCells $count\n"
     
    981984            continue
    982985        }
    983         append data " $numIndices $line\n"
    984         incr _numCells
     986        append data " $numIndices $line\n"
     987        incr _numCells
    985988        set count [expr $count + $numIndices + 1]
    986989    }
     
    988991    append out "POINTS $_numPoints double\n"
    989992    foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] {
    990         append out " $x $y $z\n"
     993        append out " $x $y $z\n"
    991994    }
    992995    append out "POLYGONS $_numCells $count\n"
     
    10151018            continue
    10161019        }
    1017         append data " $numIndices $line\n"
    1018         incr _numCells
     1020        append data " $numIndices $line\n"
     1021        incr _numCells
    10191022        set count [expr $count + $numIndices + 1]
    10201023    }
     
    10221025    append out "POINTS $_numPoints double\n"
    10231026    foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] {
    1024         append out " $x $y $z\n"
     1027        append out " $x $y $z\n"
    10251028    }
    10261029    append out "TRIANGLE_STRIPS $_numCells $count\n"
     
    10441047    set celltypes {}
    10451048    foreach { a b c d } $tetras {
    1046         append data " 4 $a $b $c $d\n"
    1047         append celltypes "10\n"
    1048         incr _numCells
     1049        append data " 4 $a $b $c $d\n"
     1050        append celltypes "10\n"
     1051        incr _numCells
    10491052    }
    10501053    append out "DATASET UNSTRUCTURED_GRID\n"
    10511054    append out "POINTS $_numPoints double\n"
    10521055    foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] {
    1053         append out " $x $y $z\n"
     1056        append out " $x $y $z\n"
    10541057    }
    10551058    set count [expr $_numCells * 5]
     
    10731076    set celltypes {}
    10741077    foreach { a b c d e f g h } $hexas {
    1075         append data " 8 $a $b $c $d $e $f $g $h\n"
    1076         append celltypes "12\n"
    1077         incr _numCells
     1078        append data " 8 $a $b $c $d $e $f $g $h\n"
     1079        append celltypes "12\n"
     1080        incr _numCells
    10781081    }
    10791082    append out "DATASET UNSTRUCTURED_GRID\n"
    10801083    append out "POINTS $_numPoints double\n"
    10811084    foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] {
    1082         append out " $x $y $z\n"
     1085        append out " $x $y $z\n"
    10831086    }
    10841087    set count [expr $_numCells * 9]
     
    11021105    set celltypes {}
    11031106    foreach { a b c d e f } $wedges {
    1104         append data " 6 $a $b $c $d $e $f\n"
    1105         append celltypes "13\n"
    1106         incr _numCells
     1107        append data " 6 $a $b $c $d $e $f\n"
     1108        append celltypes "13\n"
     1109        incr _numCells
    11071110    }
    11081111    append out "DATASET UNSTRUCTURED_GRID\n"
    11091112    append out "POINTS $_numPoints double\n"
    11101113    foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] {
    1111         append out " $x $y $z\n"
     1114        append out " $x $y $z\n"
    11121115    }
    11131116    set count [expr $_numCells * 7]
     
    11311134    set celltypes {}
    11321135    foreach { a b c d e } $pyramids {
    1133         append data " 5 $a $b $c $d $e\n"
    1134         append celltypes "14\n"
    1135         incr _numCells
     1136        append data " 5 $a $b $c $d $e\n"
     1137        append celltypes "14\n"
     1138        incr _numCells
    11361139    }
    11371140    append out "DATASET UNSTRUCTURED_GRID\n"
    11381141    append out "POINTS $_numPoints double\n"
    11391142    foreach x [$xv range 0 end] y [$yv range 0 end] z [$zv range 0 end] {
    1140         append out " $x $y $z\n"
     1143        append out " $x $y $z\n"
    11411144    }
    11421145    set count [expr $_numCells * 6]
     
    11501153
    11511154    set _vtkdata $out
    1152     return 1 
     1155    return 1
    11531156}
    11541157
     
    12171220    # Step 1: Verify that there's only one cell tag of any kind.
    12181221    set numCells 0
    1219     foreach type { 
     1222    foreach type {
    12201223        cells
    1221         hexahedrons 
    1222         lines 
    1223         polygons 
    1224         pyramids 
     1224        hexahedrons
     1225        lines
     1226        polygons
     1227        pyramids
    12251228        quads
    1226         tetrahedrons 
    1227         triangles 
     1229        tetrahedrons
     1230        triangles
    12281231        trianglestrips
    1229         vertices 
    1230         wedges 
     1232        vertices
     1233        wedges
    12311234    } {
    12321235        set data [$_xmlobj get $path.unstructured.$type]
     
    12381241    set celltypes [$_xmlobj get $path.unstructured.celltypes]
    12391242    if { $numCells == 0 && $celltypes != "" } {
    1240         puts stderr "WARNING: bad unstuctured grid \"$path\": no <cells> description found."
     1243        puts stderr "WARNING: bad unstuctured grid \"$path\": no <cells> description found."
    12411244        return 0
    12421245    }
     
    12451248        return 0
    12461249    }
    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    } {
    12511263        set data [$_xmlobj get $path.unstructured.$type]
    12521264        if { $data != "" } {
     
    12541266        }
    12551267    }
    1256     # Step 2: Allow points to be specified as <points> or 
     1268    # Step 2: Allow points to be specified as <points> or
    12571269    #         <xcoords>, <ycoords>, <zcoords>.  Split and convert into
    12581270    #         3 vectors, one for each coordinate.
     
    14021414    set data {}
    14031415    foreach cname [$_xmlobj children -type node $path] {
    1404         append data "[$_xmlobj get $path.$cname]\n"
    1405     }   
     1416        append data "[$_xmlobj get $path.$cname]\n"
     1417    }
    14061418    Rappture::ReadPoints $data _dim points
    14071419    if { $_dim == 2 } {
    1408         set all [blt::vector create \#auto]
    1409         set xv [blt::vector create \#auto]
    1410         set yv [blt::vector create \#auto]
    1411         set zv [blt::vector create \#auto]
    1412         $all set $points
    1413         $all split $xv $yv
    1414         set _numPoints [$xv length]
     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]
    14151427        set _limits(x) [$xv limits]
    14161428        set _limits(y) [$yv limits]
    14171429        set _limits(z) [list 0 0]
    1418         # 2D Dataset. All Z coordinates are 0
    1419         $zv seq 0.0 0.0 $_numPoints
    1420         $all merge $xv $yv $zv
    1421         set points [$all range 0 end]
    1422         blt::vector destroy $all $xv $yv $zv
     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
    14231435    } elseif { $_dim == 3 } {
    1424         set all [blt::vector create \#auto]
    1425         set xv [blt::vector create \#auto]
    1426         set yv [blt::vector create \#auto]
    1427         set zv [blt::vector create \#auto]
    1428         $all set $points
    1429         $all split $xv $yv $zv
    1430         set _numPoints [$xv length]
     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]
    14311443        set _limits(x) [$xv limits]
    14321444        set _limits(y) [$yv limits]
    14331445        set _limits(z) [$zv limits]
    1434         set points [$all range 0 end]
    1435         blt::vector destroy $all $xv $yv $zv
    1436     } else {
    1437         error "bad dimension \"$_dim\" for nodes mesh"
     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"
    14381450    }
    14391451    array set node2celltype {
    1440         3 5
    1441         4 10
    1442         8 12
    1443         6 13
    1444         5 14
     1452        3 5
     1453        4 10
     1454        8 12
     1455        6 13
     1456        5 14
    14451457    }
    14461458    set count 0
     
    14511463    foreach cname [$_xmlobj children -type element $path] {
    14521464        set nodeList [$_mesh get $cname.nodes]
    1453         set numNodes [llength $nodeList]
    1454         if { ![info exists node2celltype($numNodes)] } {
    1455             puts stderr "WARNING: bad nodes/elements mesh \$path\": unknown number of indices \"$_numNodes\": should be 3, 4, 5, 6, or 8"
    1456             return 0
    1457         }
    1458         set celltype $node2celltype($numNodes)
    1459         append celltypes "  $celltype\n"
     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"
    14601472        if { $celltype == 12 } {
    14611473            # Formerly used voxels instead of hexahedrons. We're converting
     
    14671479            }
    14681480            set nodeList $newList
    1469         } 
    1470         append data "  $numNodes $nodeList\n"
    1471         incr _numCells
    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.
    14741486    }
    14751487
     
    14841496    append out "\n"
    14851497    set _vtkdata $out
    1486     set _isValid 1 
     1498    set _isValid 1
    14871499}
    14881500
  • branches/uq/gui/scripts/moleculeViewer.tcl

    r3844 r5121  
    1 # -*- mode: tcl; indent-tabs-mode: nil -*- 
     1# -*- mode: tcl; indent-tabs-mode: nil -*-
    22# ----------------------------------------------------------------------
    33#  COMPONENT: MoleculeViewer - view a molecule in 3D
     
    2727    itk_option define -device device Device ""
    2828
    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
    3434    }
    3535
     
    3838    public method delete {args}
    3939    public method snap {w h}
    40     public method parameters {title args} { 
    41         # do nothing 
     40    public method parameters {title args} {
     41        # do nothing
    4242    }
    4343    public method emblems {option}
     
    6363    private variable _download "";# snapshot for download
    6464}
    65                                                                                
     65
    6666itk::usual MoleculeViewer {
    6767}
     
    236236    }
    237237    array set params $settings
    238  
     238
    239239    set pos [lsearch -exact $_dlist $dataobj]
    240240
     
    243243            error "bad value \"$dataobj\": should be Rappture::library object"
    244244        }
    245    
     245
    246246        set emblem [$dataobj get components.molecule.about.emblems]
    247247        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 -*-
    22
    33# ----------------------------------------------------------------------
     
    5252
    5353    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
    5555                                        # for each data object.
    5656    private variable _view
     
    6363    private variable _imagecache
    6464    private variable _state
    65     private variable _labels  "default"
     65    private variable _labels "default"
    6666    private variable _cacheid ""
    6767    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
    7171                                        # widgets
    7272    private variable _initialized
     
    8181    private variable _width
    8282    private variable _height
    83     private variable _reset 1;          # Restore camera settings
     83    private variable _reset 1;          # Restore camera settings
    8484    private variable _cell 0;           # Restore camera settings
    8585
     
    9696    }
    9797    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 }
    104104    private method GetImage { widget }
    105105    private method ReceiveImage { size cacheid frame rock }
     
    107107    private method AddImageControls { frame widget }
    108108    private method SetWaitVariable { value } {
    109         set _getimage $value 
     109        set _getimage $value
    110110    }
    111111    private method WaitForResponse {} {
     
    125125    public method Connect {}
    126126    public method Disconnect {}
    127     public method ResetView {} 
     127    public method ResetView {}
    128128    public method add {dataobj {options ""}}
    129129    public method delete {args}
     
    132132    public method isconnected {}
    133133    public method labels {option {model "all"}}
    134     public method parameters {title args} { 
    135         # do nothing 
     134    public method parameters {title args} {
     135        # do nothing
    136136    }
    137137
     
    236236        $this-showlabels-initialized no
    237237    }]
    238    
     238
    239239    itk_component add 3dview {
    240240        label $itk_component(plotarea).view -image $_image(plot) \
     
    294294    Rappture::Tooltip::for $itk_component(labels) \
    295295        "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}
    297297
    298298    itk_component add rock {
     
    303303            -variable [itcl::scope _settings($this-rock)]
    304304    }
    305     pack $itk_component(rock) -padx 2 -pady 2 
     305    pack $itk_component(rock) -padx 2 -pady 2
    306306    Rappture::Tooltip::for $itk_component(rock) "Rock model back and forth"
    307307
     
    319319    BuildSettingsTab
    320320
    321     # HACK ALERT. Initially force a requested width of the 3dview label. 
     321    # HACK ALERT. Initially force a requested width of the 3dview label.
    322322
    323323    # It's a chicken-and-the-egg problem.  The size of the 3dview label is set
     
    463463            if { $showlabels != "" && [string is boolean $showlabels] } {
    464464                set _settings($this-showlabels) $showlabels
    465             } 
     465            }
    466466        }
    467467
     
    567567                    -variable [itcl::scope _downloadPopup(format)] \
    568568                    -font "Arial 10 " \
    569                     -value pdb 
     569                    -value pdb
    570570                Rappture::Tooltip::for $inner.pdb \
    571571                    "Save as PDB Protein Data Bank format file."
     
    573573                    -variable [itcl::scope _downloadPopup(format)] \
    574574                    -font "Arial 10 " \
    575                     -value image 
     575                    -value image
    576576                Rappture::Tooltip::for $inner.image \
    577577                    "Save as image."
     
    589589                blt::table $f \
    590590                    0,0 $f.ok \
    591                     0,1 $f.cancel 
     591                    0,1 $f.cancel
    592592                blt::table $inner \
    593593                    0,0 $inner.summary -anchor w \
     
    628628                    } else {
    629629                        set inner [$popup component inner]
    630                     }                   
     630                    }
    631631                    update
    632632                    # Activate the popup and call for the output.
     
    635635                    $popup activate $widget left
    636636                    set bool [WaitForResponse]
    637                     $popup deactivate 
     637                    $popup deactivate
    638638                    if { $bool } {
    639639                        return [GetImage $widget]
     
    674674        return 0
    675675    }
    676     set _reset 1 
     676    set _reset 1
    677677    set result [VisViewer::Connect $hosts]
    678678    if { $result } {
     
    684684            set info {}
    685685            set user "???"
    686             if { [info exists env(USER)] } {
     686            if { [info exists env(USER)] } {
    687687                set user $env(USER)
    688             }
     688            }
    689689            set session "???"
    690             if { [info exists env(SESSION)] } {
     690            if { [info exists env(SESSION)] } {
    691691                set session $env(SESSION)
    692             }
     692            }
    693693            lappend info "version" "$Rappture::version"
    694694            lappend info "build" "$Rappture::build"
     
    760760    incr count
    761761    if { $cacheid != $_cacheid } {
    762         array unset _imagecache 
     762        array unset _imagecache
    763763        set _cacheid $cacheid
    764764    }
     
    798798        "sticks"      "sticks"          \
    799799        "lines"       "lines"           \
    800         "cartoon"     "cartoon"         
     800        "cartoon"     "cartoon"
    801801
    802802    bind $inner.rep <<Value>> [itcl::code $this Representation]
     
    883883    # Turn on buffering of commands to the server.  We don't want to
    884884    # be preempted by a server disconnect/reconnect (that automatically
    885     # generates a new call to Rebuild).   
     885    # generates a new call to Rebuild).
    886886    StartBufferingCommands
    887887    set _cell 0
     
    897897    set dlist [get]
    898898    foreach dataobj $dlist {
    899         if { $_first == "" } {
    900             set _first $dataobj
    901         }
     899        if { $_first == "" } {
     900            set _first $dataobj
     901        }
    902902        set model [$dataobj get components.molecule.model]
    903903        if {"" == $model } {
     
    906906            set model $model$suffix
    907907        }
    908         lappend _obj2models($dataobj) $model 
     908        lappend _obj2models($dataobj) $model
    909909        set state [$dataobj get components.molecule.state]
    910         if {"" == $state} { 
    911             set state $_state(server) 
     910        if {"" == $state} {
     911            set state $_state(server)
    912912        }
    913913        if { ![info exists _mlist($model)] } {  # new, turn on
    914914            set _mlist($model) 2
    915915        } elseif { $_mlist($model) == 1 } {     # on, leave on
    916             set _mlist($model) 3 
     916            set _mlist($model) 3
    917917        } elseif { $_mlist($model) == 0 } {     # off, turn on
    918918            set _mlist($model) 2
     
    10021002                        set charge     ""
    10031003                        if { "" == $lammpstypemap} {
    1004                             set atom $type 
     1004                            set atom $type
    10051005                        } else {
    10061006                            set atom [lindex $lammpstypemap [expr {$type - 1}]]
     
    10121012                        append data3 $pdbline
    10131013                    }
    1014                     # only read first model 
     1014                    # only read first model
    10151015                    if {[regexp "^ITEM: ATOMS" $lammpsline]} {
    10161016                      incr modelcount
     
    10251025                    set numBytes [string length $data3]
    10261026
    1027                     # We know we're buffered here, so append the "loadpdb" 
     1027                    # We know we're buffered here, so append the "loadpdb"
    10281028                    # command with the data payload immediately afterwards.
    10291029                    ServerCmd "loadpdb -defer follows $model $state $numBytes"
     
    10571057        }
    10581058    }
    1059        
     1059
    10601060    # enable/disable models as required (0=off->off, 1=on->off, 2=off->on,
    10611061    # 3=on->on)
     
    10741074        }
    10751075        if { $_mlist($model) == 1 } {
    1076             if {  [info exists _model($model-newtransparency)] || 
     1076            if {  [info exists _model($model-newtransparency)] ||
    10771077                  [info exists _model($model-newrep)] } {
    10781078                if { ![info exists _model($model-newrep)] } {
     
    11181118        # Set or restore viewing parameters.  We do this for the first
    11191119        # 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 {
    11231123            reset
    11241124            screen $w $h
     
    11341134    if { $changed } {
    11351135        # Default settings for all models.
    1136         SphereScale update 
     1136        SphereScale update
    11371137        StickRadius update
    1138         labels update 
    1139         Opacity update 
    1140         CartoonTrace update 
     1138        labels update
     1139        Opacity update
     1140        CartoonTrace update
    11411141        Cell update
    1142         OrthoProjection update 
     1142        OrthoProjection update
    11431143        Representation update
    11441144    }
     
    11881188    $_image(plot) configure -width $_width -height $_height
    11891189    # Immediately invalidate cache, defer update until mapped
    1190     array unset _imagecache 
     1190    array unset _imagecache
    11911191    set _resizePending 0
    11921192}
    1193    
     1193
    11941194itcl::body Rappture::MolvisViewer::EventuallyResize { w h } {
    11951195    set _width $w
     
    12031203itcl::body Rappture::MolvisViewer::DoRotate {} {
    12041204    ServerCmd "rotate $_view(a) $_view(b) $_view(c)"
    1205     array unset _imagecache 
     1205    array unset _imagecache
    12061206    set _rotatePending 0
    12071207}
    1208    
     1208
    12091209itcl::body Rappture::MolvisViewer::EventuallyRotate { a b c } {
    1210     set _view(a) $a 
     1210    set _view(a) $a
    12111211    set _view(b) $b
    1212     set _view(c) $c 
     1212    set _view(c) $c
    12131213    if { !$_rotatePending } {
    12141214        $_dispatcher event -after 100 !rotate
     
    12461246        set _view(x) [expr $_view(x) + $dx]
    12471247        set _view(y) [expr $_view(y) + $dy]
    1248         array unset _imagecache 
     1248        array unset _imagecache
    12491249        ServerCmd "pan $dx $dy"
    12501250        return
     
    12531253        set option "click"
    12541254    }
    1255     if { $option == "click" } { 
     1255    if { $option == "click" } {
    12561256        $itk_component(3dview) configure -cursor hand1
    12571257    }
     
    12611261        set _view(x) [expr $_view(x) + $dx]
    12621262        set _view(y) [expr $_view(y) + $dy]
    1263         array unset _imagecache 
     1263        array unset _imagecache
    12641264        ServerCmd "pan $dx $dy"
    12651265    }
     
    12941294        }
    12951295    }
    1296     array unset _imagecache 
     1296    array unset _imagecache
    12971297}
    12981298
     
    13241324        return
    13251325    }
    1326     set _rocker(on) $_settings($this-rock) 
     1326    set _rocker(on) $_settings($this-rock)
    13271327    if { $option == "step"} {
    13281328        if { $_rocker(client) >= 10 } {
     
    15541554    }
    15551555    if { $option == $_mrep } {
    1556         return 
     1556        return
    15571557    }
    15581558    if { $option == "update" } {
    15591559        set option $_settings($this-model)
    15601560    }
    1561     array unset _imagecache 
     1561    array unset _imagecache
    15621562    if { $option == "sticks" } {
    15631563        set _settings($this-modelimg) [Rappture::icon lines]
     
    16591659        return
    16601660    }
    1661     array unset _imagecache 
     1661    array unset _imagecache
    16621662    if { $cell } {
    16631663        Rappture::Tooltip::for $itk_component(ortho) \
     
    17231723    }
    17241724}
    1725            
     1725
    17261726itcl::body Rappture::MolvisViewer::GetImage { widget } {
    17271727    set token "print[incr _nextToken]"
     
    17291729    set $var ""
    17301730
    1731     set controls $_downloadPopup(image_controls) 
     1731    set controls $_downloadPopup(image_controls)
    17321732    set combo $controls.size
    17331733    set size [$combo translate [$combo value]]
     
    17511751    # Setup an automatic timeout procedure.
    17521752    $_dispatcher dispatch $this !pngtimeout "set $var {} ; list"
    1753    
     1753
    17541754    set popup .molvisviewerimagedownload
    17551755    if { ![winfo exists $popup] } {
     
    17651765            1,0 $inner.please -anchor w \
    17661766            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
    17701770        bind $inner.cancel <Return> [list $inner.cancel invoke]
    17711771        bind $inner.cancel <KP_Enter> [list $inner.cancel invoke]
     
    17751775    set combo $controls.bgcolor
    17761776    set bgcolor [$combo translate [$combo value]]
    1777    
     1777
    17781778    $_dispatcher event -after 60000 !pngtimeout
    17791779    WaitIcon start $inner.icon
    17801780    grab set $inner
    17811781    focus $inner.cancel
    1782    
     1782
    17831783    ServerCmd "print $token $width $height $bgcolor"
    17841784
    17851785    $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
    17891789    #  3) user cancels the operation.
    17901790    tkwait variable $var
     
    18261826#
    18271827# 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
    18311831#       is inactive, then it overridden with the value "0.1".
    18321832# ----------------------------------------------------------------------
     
    18641864# our scene.
    18651865#
    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
    18671867#       is inactive, then it overridden with the value "0.25".
    18681868# ----------------------------------------------------------------------
     
    19001900# our scene.
    19011901#
    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
    19031903#       is inactive, then it overridden with the value "0.75".
    19041904# ----------------------------------------------------------------------
     
    19711971# ----------------------------------------------------------------------
    19721972itcl::body Rappture::MolvisViewer::CartoonTrace {option {models "all"}} {
    1973     array unset _imagecache 
     1973    array unset _imagecache
    19741974    set trace $_settings($this-cartoontrace)
    19751975    if { $option == "update" } {
     
    19961996
    19971997itcl::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"
    19991999    set _downloadPopup(image_controls) $inner
    20002000    set img $_image(plot)
     
    20062006        "highquality"  "High Quality (2400x2400)"
    20072007
    2008     label $inner.bgcolor_l -text "Background:" -font "Arial 9" 
     2008    label $inner.bgcolor_l -text "Background:" -font "Arial 9"
    20092009    Rappture::Combobox $inner.bgcolor -width 30 -editable no
    20102010    $inner.bgcolor choices insert end \
    20112011        "black"  "Black" \
    20122012        "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"
    20162016    Rappture::Combobox $inner.format -width 30 -editable no
    20172017    $inner.format choices insert end \
     
    20342034    blt::table $f \
    20352035        0,0 $f.ok  \
    2036         0,1 $f.cancel 
     2036        0,1 $f.cancel
    20372037
    20382038    blt::table $inner \
     
    20482048    $inner.bgcolor value "Black"
    20492049    $inner.size value "Draft (400x400)"
    2050     $inner.format value  "PNG (Portable Network Graphics format)" 
     2050    $inner.format value  "PNG (Portable Network Graphics format)"
    20512051}
    20522052
     
    20552055        set w [image width $_image(plot)]
    20562056        set h [image height $_image(plot)]
    2057     } 
     2057    }
    20582058    set tag "$_state(client),$_rocker(client)"
    20592059    if { $_image(id) != "$tag" } {
     
    21222122    }
    21232123
    2124     # Scale and translate points 
     2124    # Scale and translate points
    21252125    for { set i 0 } { $i < 8 } { incr i } {
    21262126        point${i} expr "(point${i} * scale) + origin"
  • branches/uq/gui/scripts/nanovisviewer.tcl

    r4798 r5121  
    11# -*- mode: tcl; indent-tabs-mode: nil -*-
     2
    23# ----------------------------------------------------------------------
    34#  COMPONENT: nanovisviewer - 3D volume rendering
     
    7576    public method isconnected {}
    7677    public method limits { tf }
     78    public method overmarker { m x }
    7779    public method parameters {title args} {
    7880        # do nothing
    7981    }
     82    public method rmdupmarker { m x }
    8083    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}
    82103
    83104    # 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 }
    87106    private method BuildCameraTab {}
    88107    private method BuildCutplanesTab {}
    89108    private method BuildViewTab {}
    90     private method BuildVolumeComponents {}
    91109    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 }
    100112    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 }
    105119    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 }
    124120    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     }
    133121
    134122    private variable _arcball ""
    135123
    136124    private variable _dlist ""     ;# list of data objects
     125    private variable _allDataObjs
    137126    private variable _obj2ovride   ;# maps dataobj => style override
    138127    private variable _serverDatasets   ;# contains all the dataobj-component
    139128                                   ;# 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.
    164152    common _downloadPopup          ;# download options from popup
    165153    private common _hardcopy
     
    188176    $_dispatcher register !send_transfunc
    189177    $_dispatcher dispatch $this !send_transfunc \
    190         "[itcl::code $this SendTransferFunctions]; list"
     178        "[itcl::code $this SendTransferFuncs]; list"
    191179
    192180    # Rebuild event
     
    207195    # Initialize the view to some default parameters.
    208196    array set _view {
    209         -qw      0.853553
    210         -qx      -0.353553
    211         -qy      0.353553
    212         -qz      0.146447
    213         -xpan    0
    214         -ypan    0
    215         -zoom    1.0
     197        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
    216204    }
    217205    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
    221211    set _reset 1
    222212
    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
    255230    itk_component add 3dview {
    256231        label $itk_component(plotarea).view -image $_image(plot) \
     
    273248    }
    274249    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"
    277251
    278252    itk_component add zoomin {
     
    304278            -onimage [Rappture::icon volume-on] \
    305279            -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)]
    308282    }
    309283    $itk_component(volume) select
     
    311285        "Toggle the volume cloud on/off"
    312286    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 2
    324287
    325288    if { [catch {
     
    334297
    335298    # Legend
     299
    336300    set _image(legend) [image create photo]
    337301    itk_component add legend {
     
    343307    }
    344308    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]
    350310
    351311    # Hack around the Tk panewindow.  The problem is that the requested
     
    426386    image delete $_image(legend)
    427387    image delete $_image(download)
    428     foreach name [array names _transferFunctionEditors] {
    429         itcl::delete object $_transferFunctionEditors($cname)
    430     }
    431388    catch { blt::arcball destroy $_arcball }
    432     array unset _settings
     389    array unset _settings $this-*
    433390}
    434391
     
    462419    if {$pos < 0} {
    463420        lappend _dlist $dataobj
     421        set _allDataObjs($dataobj) 1
    464422        set _obj2ovride($dataobj-color) $params(-color)
    465423        set _obj2ovride($dataobj-width) $params(-width)
     
    538496        if { $pos >= 0 } {
    539497            set _dlist [lreplace $_dlist $pos $pos]
     498            array unset _limits $dataobj*
    540499            array unset _obj2ovride $dataobj-*
    541             array unset _dataset2style $dataobj-*
    542500            set changed 1
    543501        }
     
    559517# ----------------------------------------------------------------------
    560518itcl::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    }
    568522    foreach dataobj $args {
    569523        if { ![$dataobj isvalid] } {
    570524            continue;                     # Object doesn't contain valid data.
    571525        }
    572         foreach cname [$dataobj components] {
    573             if { ![info exists _volcomponents($cname)] } {
    574                 lappend _componentsList $cname
    575                 array set styles [lindex [$dataobj components -style $cname] 0]
    576                 set cmap [ColorsToColormap $styles(-color)]
    577                 set _cname2defaultcolormap($cname) $cmap
    578                 set _settings($cname-colormap) $styles(-color)
    579             }
    580             lappend _volcomponents($cname) $dataobj-$cname
    581             array unset limits
    582             array set limits [$dataobj valueLimits $cname]
    583             set _limits($cname) $limits(v)
    584         }
    585526        foreach axis {x y z v} {
    586527            foreach { min max } [$dataobj limits $axis] break
    587528            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
    590532                } 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
    594535                    }
    595                     if {$max > $amax} {
    596                         set amax $max
     536                    if {$max > $_limits(${axis}max)} {
     537                        set _limits(${axis}max) $max
    597538                    }
    598                     set _limits($axis) [list $amin $amax]
    599539                }
    600540            }
    601541        }
    602542    }
    603     BuildVolumeComponents
    604543}
    605544
     
    664603        if { $_reportClientInfo }  {
    665604            # Tell the server the viewer, hub, user and session.
    666             # Do this immediately on connect before buffering any commands
     605            # Do this immediately on connect before buffing any commands
    667606            global env
    668607
     
    724663
    725664# ----------------------------------------------------------------------
    726 # USAGE: SendTransferFunctions
    727 # ----------------------------------------------------------------------
    728 itcl::body Rappture::NanovisViewer::SendTransferFunctions {} {
    729     foreach cname [array names _volcomponents] {
    730         ComputeTransferFunction $cname
     665# USAGE: SendTransferFuncs
     666# ----------------------------------------------------------------------
     667itcl::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"
    731702    }
    732703    FixLegend
     
    759730
    760731#
    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#
     744itcl::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
    764752    set c $itk_component(legend)
    765753    set w [winfo width $c]
     
    767755    set lx 10
    768756    set ly [expr {$h - 1}]
    769     if {"" == [$c find withtag colorbar]} {
     757    if {"" == [$c find withtag transfunc]} {
    770758        $c create image 10 10 -anchor nw \
    771             -image $_image(legend) -tags colorbar
     759            -image $_image(legend) -tags transfunc
    772760        $c create text $lx $ly -anchor sw \
    773             -fill $itk_option(-plotforeground) -tags "limits text vmin"
     761            -fill $itk_option(-plotforeground) -tags "limits vmin"
    774762        $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)]
    788772    $c coords vmin $lx $ly
    789773
    790     $c itemconfigure vmax -text [format %g $max]
     774    $c itemconfigure vmax -text [format %.2g $limits(max)]
    791775    $c coords vmax [expr {$w-$lx}] $ly
    792776
    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    }
    800782
    801783    # 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    }
    826800}
    827801
     
    863837    set dataobj [lindex $parts 0]
    864838    set _serverDatasets($tag) 1
    865     if { $_settings(-volumevisible) && $dataobj == $_first } {
     839    if { $_settings($this-volume) && $dataobj == $_first } {
    866840        SendCmd "volume state 1 $tag"
    867841    }
    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.
    870846
    871847    unset _recvdDatasets($tag)
    872848    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
    874853    }
    875854}
     
    895874    StartBufferingCommands
    896875
     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
    897885    if { $_width != $w || $_height != $h || $_reset } {
    898886        set _width $w
     
    901889        DoResize
    902890    }
    903 
    904891    foreach dataobj [get] {
    905892        foreach cname [$dataobj components] {
     
    923910                if { $_reportClientInfo }  {
    924911                    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]
    929917                    lappend info "dataset_label" [$dataobj hints label]
    930918                    lappend info "dataset_size"  $nbytes
     
    937925                set _serverDatasets($tag) 0
    938926            }
    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    }
    946930    set _first [lindex [get] 0]
    947931    if { $_reset } {
     
    949933        # Reset the camera and other view parameters
    950934        #
    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)]
    960944        $_arcball quaternion $q
    961945        SendCmd "camera orient $q"
    962946        SendCmd "camera reset"
    963947        PanCamera
    964         SendCmd "camera zoom $_view(-zoom)"
     948        SendCmd "camera zoom $_view(zoom)"
     949        InitSettings light2side light transp isosurface grid axes
    965950       
    966         #cutplane state 0 all
    967951        foreach axis {x y z} {
    968952            # Turn off cutplanes for all volumes
    969953            SendCmd "cutplane state 0 $axis"
    970954        }
    971 
    972         InitSettings -light2side -light -volumeopacity \
    973             -isosurfaceshading -gridvisible -axesvisible \
    974 
    975955        if {"" != $_first} {
    976956            set axis [$_first hints updir]
     
    984964        }
    985965    }
    986 
     966    # Outline seems to need to be reset every update.
     967    InitSettings outline
    987968    # nothing to send -- activate the proper ivol
    988969    SendCmd "volume state 0"
     
    996977        set cname [lindex [$_first components] 0]
    997978        if { [info exists _serverDatasets($_first-$cname)] } {
    998             updateTransferFunctions
     979            updatetransferfuncs
    999980        }
    1000981    }
     
    10221003        set tag $_first-$cname
    10231004        if { [info exists _serverDatasets($tag)] && $_serverDatasets($tag) } {
    1024             array set styles {
     1005            array set style {
    10251006                -cutplanes 1
    10261007            }
    1027             array set styles [lindex [$_first components -style $cname] 0]
    1028             if { $what != "-cutplanes" || $styles(-cutplanes) } {
     1008            array set style [lindex [$_first components -style $cname] 0]
     1009            if { $what != "-cutplanes" || $style(-cutplanes) } {
    10291010                lappend rlist $tag
    10301011            }
     
    10451026    switch -- $option {
    10461027        "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)"
    10501031        }
    10511032        "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)"
    10551036        }
    10561037        "reset" {
    10571038            array set _view {
    1058                 -qw      0.853553
    1059                 -qx      -0.353553
    1060                 -qy      0.353553
    1061                 -qz      0.146447
    1062                 -xpan    0
    1063                 -ypan    0
    1064                 -zoom    1.0
     1039                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
    10651046            }
    10661047            if { $_first != "" } {
     
    10701051                }
    10711052            }
    1072             set q [ViewToQuaternion]         
     1053            set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    10731054            $_arcball quaternion $q
    10741055            SendCmd "camera orient $q"
    10751056            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)
    10831064        }
    10841065    }
     
    10861067
    10871068itcl::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)
    10901073    SendCmd "camera pan $x $y"
    10911074}
     
    11261109
    11271110                set q [$_arcball rotate $x $y $_click(x) $_click(y)]
    1128                 foreach { _view(-qw) _view(-qx) _view(-qy) _view(-qz) } $q break
    1129                 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)
    11331116                SendCmd "camera orient $q"
    11341117
     
    11631146        set x [expr $x / double($w)]
    11641147        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]
    11671150        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)
    11701153        return
    11711154    }
     
    11801163        set _click(x) $x
    11811164        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]
    11841167        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)
    11871170    }
    11881171    if { $option == "release" } {
     
    12161199    }
    12171200    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" {
    12331249            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) } {
    12671262                blt::table $itk_component(plotarea) \
    12681263                    0,0 $itk_component(3dview) -fill both \
     
    12731268            }
    12741269        }
    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)
    13381277            set datasets [CurrentDatasets -cutplanes]
    13391278            set tag [lindex $datasets 0]
    1340             if { $_settings(-cutplanesvisible) } {
    1341                 SendCmd "cutplane state $bool $axis $tag"
    1342             }
     1279            SendCmd "cutplane state $bool $axis $tag"
    13431280            if { $bool } {
    13441281                $itk_component(${axis}CutScale) configure -state normal \
     
    13671304    set w [expr {$_width-20}]
    13681305    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 --
    13781321#
    13791322#       Creates a transfer function name based on the <style> settings in the
     
    13831326#       server parses the 3D data and sends back the limits via ReceiveData.]
    13841327#
    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#
     1334itcl::body Rappture::NanovisViewer::NameTransferFunc { dataobj cname } {
     1335    array set style {
    13871336        -color BCGYR
    13881337        -levels 6
     1338        -opacity 1.0
    13891339        -markers ""
    13901340    }
    13911341    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#
     1358itcl::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]
    14241368
    14251369    # We have to parse the style attributes for a volume using this
     
    14291373    # of the volumes (the first in the list) using the transfer-function as a
    14301374    # 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)] } {
    14431383        # Have to defer creation of isomarkers until we have data limits
    1444         if { [info exists styles(-markers)] &&
    1445              [llength $styles(-markers)] > 0 } {
    1446             ParseMarkersOption $cname $styles(-markers)
     1384        if { [info exists style(-markers)] &&
     1385             [llength $style(-markers)] > 0 } {
     1386            ParseMarkersOption $tf $style(-markers)
    14471387        } 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 }"
    14721451}
    14731452
     
    14771456itcl::configbody Rappture::NanovisViewer::plotbackground {
    14781457    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"
    14831461    }
    14841462}
     
    14891467itcl::configbody Rappture::NanovisViewer::plotforeground {
    14901468    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"
    14981472    }
    14991473}
     
    15221496# marker is a relative value from 0.0 to 1.0.
    15231497#
    1524 itcl::body Rappture::NanovisViewer::ParseLevelsOption { cname levels } {
     1498itcl::body Rappture::NanovisViewer::ParseLevelsOption { tf levels } {
    15251499    set c $itk_component(legend)
    1526     set list {}
    15271500    regsub -all "," $levels " " levels
    15281501    if {[string is int $levels]} {
    15291502        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
    15311507        }
    15321508    } else {
    15331509        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    }
    15401515}
    15411516
     
    15521527#       not be seen.
    15531528#
    1554 itcl::body Rappture::NanovisViewer::ParseMarkersOption { cname markers } {
     1529itcl::body Rappture::NanovisViewer::ParseMarkersOption { tf markers } {
    15551530    set c $itk_component(legend)
    1556     set list {}
    1557     foreach { min max } $_limits($cname) break
    15581531    regsub -all "," $markers " " markers
    15591532    foreach marker $markers {
    15601533        set n [scan $marker "%g%s" value suffix]
    15611534        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
    15641540        } 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    }
    15721547}
    15731548
     
    15751550# USAGE: UndateTransferFuncs
    15761551# ----------------------------------------------------------------------
    1577 itcl::body Rappture::NanovisViewer::updateTransferFunctions {} {
     1552itcl::body Rappture::NanovisViewer::updatetransferfuncs {} {
    15781553    $_dispatcher event -idle !send_transfunc
    15791554}
    15801555
    1581 itcl::body Rappture::NanovisViewer::limits { cname } {
     1556itcl::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
     1571itcl::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
     1596itcl::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
     1611itcl::body Rappture::NanovisViewer::limits { tf } {
    15821612    set _limits(min) 0.0
    15831613    set _limits(max) 1.0
    1584     if { ![info exists _style2datasets($cname)] } {
     1614    if { ![info exists _style2datasets($tf)] } {
    15851615        return [array get _limits]
    15861616    }
    15871617    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)] } {
    15901620            continue
    15911621        }
    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)
    15981630        }
    15991631    }
     
    16041636        set _limits(max) $max
    16051637    }
    1606     return [list $_limits(min) $_limits(max)]
     1638    return [array get _limits]
    16071639}
    16081640
    16091641
    16101642itcl::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
    16111655    set fg [option get $itk_component(hull) font Font]
    16121656    #set bfg [option get $itk_component(hull) boldFont Font]
     
    16171661    $inner configure -borderwidth 4
    16181662
    1619     set ::Rappture::NanovisViewer::_settings(-isosurfaceshading) 0
     1663    set ::Rappture::NanovisViewer::_settings($this-isosurface) 0
    16201664    checkbutton $inner.isosurface \
    16211665        -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] \
    16241668        -font "Arial 9"
    16251669
    16261670    checkbutton $inner.axes \
    16271671        -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] \
    16301674        -font "Arial 9"
    16311675
    16321676    checkbutton $inner.grid \
    16331677        -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] \
    16361680        -font "Arial 9"
    16371681
    16381682    checkbutton $inner.outline \
    16391683        -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] \
    16421686        -font "Arial 9"
    16431687
    16441688    checkbutton $inner.legend \
    16451689        -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] \
    16481692        -font "Arial 9"
    16491693
    16501694    checkbutton $inner.volume \
    16511695        -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] \
    16541698        -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 no
    1659     }
    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]
    16681699
    16691700    blt::table $inner \
     
    16721703        2,0 $inner.outline  -cspan 2 -anchor w \
    16731704        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
    16771706
    16781707    if 0 {
     
    16801709    }
    16811710    blt::table configure $inner r* -resize none
    1682     blt::table configure $inner r6 -resize expand
     1711    blt::table configure $inner r5 -resize expand
    16831712}
    16841713
    16851714itcl::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
    16861725    set inner [$itk_component(main) insert end \
    16871726        -title "Volume Settings" \
     
    16891728    $inner configure -borderwidth 4
    16901729
    1691     set font [option get $itk_component(hull) font Font]
    16921730    set fg [option get $itk_component(hull) font Font]
    16931731    #set bfg [option get $itk_component(hull) boldFont Font]
    16941732
    16951733    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]
    16981736    label $inner.shading -text "Shading:" -font $fg
    16991737
    17001738    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]
    17031741
    17041742    label $inner.dim -text "Glow" -font $fg
    17051743    ::scale $inner.light -from 0 -to 100 -orient horizontal \
    1706         -variable [itcl::scope _settings(-light)] \
     1744        -variable [itcl::scope _settings($this-light)] \
    17071745        -width 10 \
    1708         -showvalue off -command [itcl::code $this AdjustSetting -light]
     1746        -showvalue off -command [itcl::code $this AdjustSetting light]
    17091747    label $inner.bright -text "Surface" -font $fg
    17101748
    1711     # Opacity
    17121749    label $inner.fog -text "Clear" -font $fg
    17131750    ::scale $inner.transp -from 0 -to 100 -orient horizontal \
    1714         -variable [itcl::scope _widget(-volumeopacity)] \
     1751        -variable [itcl::scope _settings($this-transp)] \
    17151752        -width 10 \
    1716         -showvalue off -command [itcl::code $this AdjustSetting -volumeopacity]
     1753        -showvalue off -command [itcl::code $this AdjustSetting transp]
    17171754    label $inner.plastic -text "Opaque" -font $fg
    17181755
    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
    17201763    label $inner.thin -text "Thin" -font $fg
    17211764    ::scale $inner.thickness -from 0 -to 1000 -orient horizontal \
    1722         -variable [itcl::scope _settings(-thickness)] \
     1765        -variable [itcl::scope _settings($this-thickness)] \
    17231766        -width 10 \
    1724         -showvalue off -command [itcl::code $this AdjustSetting -thickness]
     1767        -showvalue off -command [itcl::code $this AdjustSetting thickness]
    17251768    label $inner.thick -text "Thick" -font $fg
    17261769
    1727     # Colormap
    17281770    label $inner.colormap_l -text "Colormap" -font "Arial 9"
    17291771    itk_component add colormap {
     
    17311773    }
    17321774
    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"
    17341795    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]
    17461797
    17471798    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 \
    17501800        1,0 $inner.shading -cspan 4 -anchor w -pady {10 2} \
    17511801        2,0 $inner.light2side -cspan 4 -anchor w -pady 2 \
     
    17701820    $inner configure -borderwidth 4
    17711821
    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    
    17781822    # X-value slicer...
    17791823    itk_component add xCutButton {
     
    17811825            -onimage [Rappture::icon x-cutplane] \
    17821826            -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)]
    17851829    }
    17861830    Rappture::Tooltip::for $itk_component(xCutButton) \
    17871831        "Toggle the X cut plane on/off"
    1788     $itk_component(xCutButton) select
    17891832
    17901833    itk_component add xCutScale {
     
    17931836            -borderwidth 1 -highlightthickness 0 \
    17941837            -command [itcl::code $this Slice move x] \
    1795             -variable [itcl::scope _settings(-xcutplaneposition)]
     1838            -variable [itcl::scope _settings($this-xcutposition)]
    17961839    } {
    17971840        usual
     
    18091852            -onimage [Rappture::icon y-cutplane] \
    18101853            -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)]
    18131856    }
    18141857    Rappture::Tooltip::for $itk_component(yCutButton) \
    18151858        "Toggle the Y cut plane on/off"
    1816     $itk_component(yCutButton) select
    18171859
    18181860    itk_component add yCutScale {
     
    18211863            -borderwidth 1 -highlightthickness 0 \
    18221864            -command [itcl::code $this Slice move y] \
    1823             -variable [itcl::scope _settings(-ycutplaneposition)]
     1865            -variable [itcl::scope _settings($this-ycutposition)]
    18241866    } {
    18251867        usual
     
    18371879            -onimage [Rappture::icon z-cutplane] \
    18381880            -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)]
    18411883    }
    18421884    Rappture::Tooltip::for $itk_component(zCutButton) \
    18431885        "Toggle the Z cut plane on/off"
    1844     $itk_component(zCutButton) select
    18451886
    18461887    itk_component add zCutScale {
     
    18491890            -borderwidth 1 -highlightthickness 0 \
    18501891            -command [itcl::code $this Slice move z] \
    1851             -variable [itcl::scope _settings(-zcutplaneposition)]
     1892            -variable [itcl::scope _settings($this-zcutposition)]
    18521893    } {
    18531894        usual
     
    18561897    $itk_component(zCutScale) set 50
    18571898    $itk_component(zCutScale) configure -state disabled
     1899    #$itk_component(zCutScale) configure -state disabled
    18581900    Rappture::Tooltip::for $itk_component(zCutScale) \
    18591901        "@[itcl::code $this SlicerTip z]"
     
    18971939        label $inner.${tag}label -text $tag -font "Arial 9"
    18981940        entry $inner.${tag} -font "Arial 9"  -bg white \
    1899             -textvariable [itcl::scope _settings(-$tag)]
     1941            -textvariable [itcl::scope _settings($this-$tag)]
    19001942        bind $inner.${tag} <Return> \
    1901             [itcl::code $this camera set -${tag}]
     1943            [itcl::code $this camera set ${tag}]
    19021944        bind $inner.${tag} <KP_Enter> \
    1903             [itcl::code $this camera set -${tag}]
     1945            [itcl::code $this camera set ${tag}]
    19041946        blt::table $inner \
    19051947            $row,0 $inner.${tag}label -anchor e -pady 2 \
     
    19501992itcl::body Rappture::NanovisViewer::SlicerTip {axis} {
    19511993    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))}]
    19521997    return "Move the [string toupper $axis] cut plane.\nCurrently:  $axis = $val%"
    19531998}
     
    19702015}
    19712016
    1972 itcl::body Rappture::NanovisViewer::EventuallyRedrawLegend {} {
     2017itcl::body Rappture::NanovisViewer::EventuallyResizeLegend {} {
    19732018    if { !$_resizeLegendPending } {
    19742019        $_dispatcher event -idle !legend
     
    19852030        }
    19862031        "set" {
    1987             set what [lindex $args 0]
    1988             set x $_settings($what)
     2032            set who [lindex $args 0]
     2033            set x $_settings($this-$who)
    19892034            set code [catch { string is double $x } result]
    19902035            if { $code != 0 || !$result } {
    1991                 set _settings($what) $_view($what)
     2036                set _settings($this-$who) $_view($who)
    19922037                return
    19932038            }
    1994             switch -- $what {
    1995                 "-xpan" - "-ypan" {
    1996                     set _view($what) $_settings($what)
     2039            switch -- $who {
     2040                "xpan" - "ypan" {
     2041                    set _view($who) $_settings($this-$who)
    19972042                    PanCamera
    19982043                }
    1999                 "-qx" - "-qy" - "-qz" - "-qw" {
    2000                     set _view($what) $_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)]
    20022047                    $_arcball quaternion $q
    20032048                    SendCmd "camera orient $q"
    20042049                }
    2005                 "-zoom" {
    2006                     set _view($what) $_settings($what)
    2007                     SendCmd "camera zoom $_view($what)"
     2050                "zoom" {
     2051                    set _view($who) $_settings($this-$who)
     2052                    SendCmd "camera zoom $_view(zoom)"
    20082053                }
    20092054            }
     
    20452090        array set info $vol
    20462091        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)
    20492094        }
    20502095        checkbutton $inner.vol$row -text $info(label) \
    2051             -variable [itcl::scope _settings(-volumevisible-$name)] \
     2096            -variable [itcl::scope _settings($this-volume-$name)] \
    20522097            -onvalue 0 -offvalue 1 \
    2053             -command [itcl::code $this ToggleVolume $key $name] \
     2098            -command [itcl::code $this volume $key $name] \
    20542099            -font "Arial 9"
    20552100        Rappture::Tooltip::for $inner.vol$row $info(description)
    20562101        blt::table $inner $row,0 $inner.vol$row -anchor w
    2057         if { !$_settings(-volume-$name) } {
     2102        if { !$_settings($this-volume-$name) } {
    20582103            $inner.vol$row select
    20592104        }
     
    20662111}
    20672112
    2068 itcl::body Rappture::NanovisViewer::ToggleVolume { tag name } {
    2069     set bool $_settings(-volumevisible-$name)
    2070     SendCmd "volume state $bool $name"
     2113itcl::body Rappture::NanovisViewer::volume { tag name } {
     2114    set bool $_settings($this-volume-$name)
     2115    SendCmd "volume statue $bool $name"
    20712116}
    20722117
     
    20802125        bottom "0.707107 0.707107 0 0"
    20812126    }
    2082     foreach name { -qw -qx -qy -qz } value $positions($side) {
     2127    foreach name { qw qx qy qz } value $positions($side) {
    20832128        set _view($name) $value
    20842129    }
    2085     set q [ViewToQuaternion]
     2130    set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    20862131    $_arcball quaternion $q
    20872132    SendCmd "camera orient $q"
    20882133    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 -*-
    32# ----------------------------------------------------------------------
    43#  COMPONENT: Panes - creates a series of adjustable panes
     
    98# ======================================================================
    109#  AUTHOR:  Michael McLennan, Purdue University
    11 #  Copyright (c) 2004-2012  HUBzero Foundation, LLC
     10#  Copyright (c) 2004-2015  HUBzero Foundation, LLC
    1211#
    1312#  See the file "license.terms" for information on usage and
     
    2120option add *Panes.sashWidth 2 widgetDefault
    2221option add *Panes.sashPadding 4 widgetDefault
    23 option add *Panes.sashCursor sb_v_double_arrow
     22option add *Panes.orientation vertical widgetDefault
    2423
    2524itcl::class Rappture::Panes {
    2625    inherit itk::Widget
    2726
    28     itk_option define -sashcursor sashCursor SashCursor ""
    2927    itk_option define -sashrelief sashRelief SashRelief ""
    3028    itk_option define -sashwidth sashWidth SashWidth 0
    3129    itk_option define -sashpadding sashPadding SashPadding 0
     30    itk_option define -orientation orientation Orientation ""
    3231
    3332    constructor {args} { # defined below }
     
    3534    public method insert {pos args}
    3635    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}
    3938    public method hilite {state sash}
     39    public method size {}
    4040
    4141    protected method _grab {pane X Y}
     
    4949    private variable _visibility ""  ;# list of visibilities for panes
    5050    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
    5354}
    5455
    5556itk::usual Panes {
    56     keep -background -cursor
     57    keep -background -cursor -sashwidth -sashrelief
    5758}
    5859
     
    8081    lappend _panes $pname
    8182    lappend _visibility 1
    82     set _frac 0.5
     83    set _reqfrac 0.5
    8384
    8485    eval itk_initialize $args
     
    107108    } {
    108109        usual
    109         rename -cursor -sashcursor sashCursor SashCursor
     110        ignore -cursor
    110111    }
    111112    bind $itk_component($sash) <Enter> [itcl::code $this hilite on $sash]
     
    116117    } {
    117118        usual
    118         rename -cursor -sashcursor sashCursor SashCursor
    119119        rename -relief -sashrelief sashRelief SashRelief
    120120        ignore -borderwidth
    121121    }
    122     if { $orientation == "vertical" } {
     122    if {$itk_option(-orientation) eq "vertical"} {
    123123        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
    124126    } else {
    125127        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
    126130    }
    127131    foreach comp [list $sash ${sash}ridge] {
     
    140144    set _panes [linsert $_panes $pos $pname]
    141145    set _visibility [linsert $_visibility $pos 1]
    142     set _frac [linsert $_frac $pos $params(-fraction)]
     146    set _reqfrac [linsert $_reqfrac $pos $params(-fraction)]
    143147
    144148    # fix sash characteristics
     
    165169
    166170# ----------------------------------------------------------------------
    167 # USAGE: visibility <pos> ?<newval>?
     171# USAGE: visibility <pos> ?<newval>? ?<pos> <newval> ...?
    168172#
    169173# 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# ----------------------------------------------------------------------
     177itcl::body Rappture::Panes::visibility {pos args} {
     178    if {[llength $args] == 0} {
    174179        return [lindex $_visibility $pos]
    175180    }
    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> ...?
    189201#
    190202# 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# ----------------------------------------------------------------------
     207itcl::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        }
    221226    }
    222227}
     
    230235itcl::body Rappture::Panes::hilite {state sash} {
    231236    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      }
    232244      sunken {
    233245        if {$state} {
     
    256268
    257269# ----------------------------------------------------------------------
     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# ----------------------------------------------------------------------
     275itcl::body Rappture::Panes::size {} {
     276    return [llength $_panes]
     277}
     278
     279# ----------------------------------------------------------------------
    258280# USAGE: _grab <pane> <X> <Y>
    259281#
     
    262284# ----------------------------------------------------------------------
    263285itcl::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    }
    264297}
    265298
     
    270303# ----------------------------------------------------------------------
    271304itcl::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}]
    274311        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
    276315    } else {
    277         set realX [expr {$X-[winfo rootx $itk_component(hull)]}]
     316        set delX [expr {$_dragfrom-$X}]
    278317        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
    281327    if {$frac < 0.05} {
    282328        set frac 0.05
    283329    }
    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
    295339    _fixLayout
    296340
     
    314358# ----------------------------------------------------------------------
    315359itcl::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"} {
    317386        set h [winfo height $itk_component(hull)]
     387        set sh [expr {$itk_option(-sashwidth) + $pad}]
    318388
    319389        set plist ""
    320390        set flist ""
    321         foreach p $_panes f $_frac v $_visibility {
     391        foreach p $_panes f $normfrac v $_visibility {
    322392            set sash ${p}sash
    323393            if {$v} {
     
    326396                lappend flist $f
    327397                if {[info exists itk_component($sash)]} {
    328                     set h [expr {$h - [winfo reqheight $itk_component($sash)]}]
     398                    set h [expr {$h - $sh}]
    329399                }
    330400            } else {
     
    336406            }
    337407        }
    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
    348409        # lay out the various panes
    349410        set y 0
     
    351412            set sash ${p}sash
    352413            if {[info exists itk_component($sash)]} {
    353                 set sh [winfo reqheight $itk_component($sash)]
    354414                place $itk_component($sash) -y $y -relx 0.5 -anchor n \
    355415                    -relwidth 1.0 -height $sh
     
    364424    } else {
    365425        set w [winfo width $itk_component(hull)]
     426        set sw [expr {$itk_option(-sashwidth) + $pad}]
    366427
    367428        set plist ""
    368429        set flist ""
    369         foreach p $_panes f $_frac v $_visibility {
     430        foreach p $_panes f $normfrac v $_visibility {
    370431            set sash ${p}sash
    371432            if {$v} {
     
    374435                lappend flist $f
    375436                if {[info exists itk_component($sash)]} {
    376                     set w [expr {$w - [winfo reqwidth $itk_component($sash)]}]
     437                    set w [expr {$w - $sw}]
    377438                }
    378439            } else {
     
    384445            }
    385446        }
    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
    396448        # lay out the various panes
    397449        set x 0
     
    399451            set sash ${p}sash
    400452            if {[info exists itk_component($sash)]} {
    401                 set sw [winfo reqwidth $itk_component($sash)]
    402453                place $itk_component($sash) -x $x -rely 0.5 -anchor w \
    403454                    -relheight 1.0 -width $sw
     
    420471# ----------------------------------------------------------------------
    421472itcl::body Rappture::Panes::_fixSashes {args} {
    422     if { $orientation == "vertical" } {
     473    if {$itk_option(-orientation) eq "vertical"} {
    423474        set ht [winfo pixels $itk_component(hull) $itk_option(-sashwidth)]
    424475        set bd [expr {$ht/2}]
     
    426477            set sash "${pane}sashridge"
    427478            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
    436483            }
    437484        }
     
    442489            set sash "${pane}sashridge"
    443490            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)
    451493                pack $itk_component($sash) -padx $itk_option(-sashpadding) \
    452494                    -side left
     
    474516# ----------------------------------------------------------------------
    475517itcl::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    }
    476528    $_dispatcher event -idle !sashes
    477529}
     530
     531# ----------------------------------------------------------------------
     532# CONFIGURATION OPTION: -orientation
     533# ----------------------------------------------------------------------
     534itcl::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  
    293293            }
    294294        }
    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.$mode
    303                 Rappture::MapViewer $w $servers
    304                 set _mode2widget($mode) $w
    305             }
    306         }
    307295        ::Rappture::Field {
    308296            if { ![$dataobj isvalid] } {
     
    493481            set dobj [Rappture::Field ::#auto $xmlobj $path]
    494482        }
    495         map {
    496             set dobj [Rappture::Map ::#auto $xmlobj $path]
    497         }
    498483        mesh {
    499484            set dobj [Rappture::Mesh ::#auto $xmlobj $path]
  • branches/uq/gui/scripts/textentry.tcl

    r4405 r5121  
    106106    # the string alone.
    107107    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 $f
    114             set str $contents
    115         }
    116     }
    117108    if {"" != $str} {
    118109        value $str
  • branches/uq/gui/scripts/tool.tcl

    r5102 r5121  
    3636    public method run {args} {
    3737        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]
    4046    }
    4147    public method abort {} {
  • branches/uq/gui/scripts/unirect2d.tcl

    r4497 r5121  
    176176# ----------------------------------------------------------------------
    177177# 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.
    181180# ----------------------------------------------------------------------
    182181itcl::body Rappture::Unirect2d::blob {} {
     
    189188# ----------------------------------------------------------------------
    190189# 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.
    194191# ----------------------------------------------------------------------
    195192itcl::body Rappture::Unirect2d::mesh {} {
  • branches/uq/gui/scripts/unirect3d.tcl

    r4494 r5121  
    4141    private variable _xMax       0
    4242    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
    4444    private variable _yMax       0
    4545    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
    4747    private variable _zMax       0
    4848    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-values
     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 values
    5252    private variable _hints
    5353}
     
    124124# ----------------------------------------------------------------------
    125125# 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.
    129128# ----------------------------------------------------------------------
    130129itcl::body Rappture::Unirect3d::blob {} {
     
    142141# ----------------------------------------------------------------------
    143142# 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.
    147145# ----------------------------------------------------------------------
    148146itcl::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 -*-
    22
    33# ----------------------------------------------------------------------
    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
    77#  that use the nanoserver render farm.
    88#
     
    2222
    2323    private common _servers         ;# array of visualization server lists
    24     set _servers(geovis)  "localhost:2015"
    2524    set _servers(nanovis) "localhost:2000"
    2625    set _servers(pymol)   "localhost:2020"
     
    3231    private common _done            ;   # Used to indicate status of send.
    3332    private variable _buffer        ;   # buffer for incoming/outgoing commands
    34     private variable _initialized 
     33    private variable _initialized
    3534    private variable _isOpen 0
    3635    private variable _afterId -1
     
    7271    private method SendHelper {}
    7372    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 {}
    8281
    8382    protected method CheckConnection {}
     
    8685    protected method Connect { servers }
    8786    protected method Disconnect {}
    88     protected method EnableWaitDialog { timeout } 
     87    protected method EnableWaitDialog { timeout }
    8988    protected method Euler2XYZ { theta phi psi }
    9089    protected method Flush {}
     
    10099    protected method SendEcho { channel {data ""} }
    101100    protected method StartBufferingCommands {}
    102     protected method StartWaiting {} 
     101    protected method StartWaiting {}
    103102    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 }
    107106
    108107    private proc CheckNameList { namelist }  {
     
    198197    global env
    199198    if { [info exists env(VISRECORDER)] } {
    200         set _logging 1
    201         if { [file exists /tmp/recording.log] } {
    202             file delete /tmp/recording.log
    203         }
     199        set _logging 1
     200        if { [file exists /tmp/recording.log] } {
     201            file delete /tmp/recording.log
     202        }
    204203    }
    205204    eval itk_initialize $args
     
    257256#    Connect to the visualization server (e.g. nanovis, pymolproxy).
    258257#    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.
    260259#
    261260itcl::body Rappture::VisViewer::Connect { servers } {
     
    280279        set _hostname $server
    281280        fconfigure $_sid -translation binary -encoding binary
    282        
     281
    283282        # Read back the server identification string.
    284283        if { [gets $_sid data] <= 0 } {
     
    316315    after cancel $_afterId
    317316    $_dispatcher cancel !timeout
    318     catch {close $_sid} 
     317    catch {close $_sid}
    319318    set _sid ""
    320319    set _buffer(in) ""
     
    341340# CheckConection --
    342341#
    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
    346345#   visualization server.
    347346#
     
    399398    }
    400399    puts -nonewline $_sid $_buffer(out)
    401     flush $_sid 
     400    flush $_sid
    402401    set _done($this) 1;                 # Success
    403402}
     
    479478# StartWaiting --
    480479#
    481 #    Read some number of bytes from the visualization server. 
     480#    Read some number of bytes from the visualization server.
    482481#
    483482
    484483itcl::body Rappture::VisViewer::StartWaiting {} {
    485484    if { $_waitTimeout > 0 } {
    486         after cancel $_afterId 
     485        after cancel $_afterId
    487486        set _afterId [after $_waitTimeout [itcl::code $this WaitDialog on]]
    488487    }
    489488}
    490489
    491 itcl::body Rappture::VisViewer::StopWaiting {} { 
     490itcl::body Rappture::VisViewer::StopWaiting {} {
    492491    if { $_waitTimeout > 0 } {
    493492        WaitDialog off
     
    495494}
    496495
    497 itcl::body Rappture::VisViewer::EnableWaitDialog { value } { 
     496itcl::body Rappture::VisViewer::EnableWaitDialog { value } {
    498497    set _waitTimeout $value
    499498}
     
    502501# ReceiveBytes --
    503502#
    504 #    Read some number of bytes from the visualization server. 
     503#    Read some number of bytes from the visualization server.
    505504#
    506505itcl::body Rappture::VisViewer::ReceiveBytes { size } {
     
    620619}
    621620
    622 # 
     621#
    623622# ReceiveEcho --
    624623#
     
    643642        }
    644643        set inner [frame $itk_component(plotarea).view.splash]
    645         $inner configure -relief raised -bd 2 
     644        $inner configure -relief raised -bd 2
    646645        label $inner.text1 -text "Working...\nPlease wait." \
    647             -font "Arial 10" 
    648         label $inner.icon 
     646            -font "Arial 10"
     647        label $inner.icon
    649648        pack $inner -expand yes -anchor c
    650649        blt::table $inner \
    651650            0,0 $inner.text1 -anchor w \
    652             0,1 $inner.icon 
     651            0,1 $inner.icon
    653652        Waiting start $inner.icon
    654653    } else {
     
    710709    pack $f.send.l -side left
    711710    itk_component add command {
    712         entry $f.send.e -background white
     711        entry $f.send.e -background white
    713712    } {
    714         ignore -background
     713        ignore -background
    715714    }
    716715    pack $f.send.e -side left -expand yes -fill x
     
    720719    pack $f.sb -side right -fill y
    721720    itk_component add trace {
    722         text $f.comm -wrap char -yscrollcommand "$f.sb set" -background white
     721        text $f.comm -wrap char -yscrollcommand "$f.sb set" -background white
    723722    } {
    724         ignore -background
     723        ignore -background
    725724    }
    726725    pack $f.comm -expand yes -fill both
     
    730729
    731730    $itk_component(trace) tag configure error -foreground red \
    732         -font -*-courier-medium-o-normal-*-*-120-*
     731        -font -*-courier-medium-o-normal-*-*-120-*
    733732    $itk_component(trace) tag configure incoming -foreground blue
    734733}
     
    742741itcl::body Rappture::VisViewer::ToggleConsole {} {
    743742    if { $_debugConsole } {
    744         set _debugConsole 0
     743        set _debugConsole 0
    745744    } else {
    746         set _debugConsole 1
     745        set _debugConsole 1
    747746    }
    748747    DebugConsole
     
    752751# DebugConsole --
    753752#
    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
    757756#    socket to the render server.  Additionally, the debug console
    758757#    is created if necessary and hidden/shown.
     
    760759itcl::body Rappture::VisViewer::DebugConsole {} {
    761760    if { ![winfo exists .renderconsole] } {
    762         BuildConsole
     761        BuildConsole
    763762    }
    764763    if { $_debugConsole } {
    765         $this configure -sendcommand [itcl::code $this TraceComm]
    766         $this configure -receivecommand [itcl::code $this TraceComm]
    767         wm deiconify .renderconsole
     764        $this configure -sendcommand [itcl::code $this TraceComm]
     765        $this configure -receivecommand [itcl::code $this TraceComm]
     766        wm deiconify .renderconsole
    768767    } else {
    769         $this configure -sendcommand ""
    770         $this configure -receivecommand ""
    771         wm withdraw .renderconsole
     768        $this configure -sendcommand ""
     769        $this configure -receivecommand ""
     770        wm withdraw .renderconsole
    772771    }
    773772}
     
    851850                -title "Render Server Error"
    852851            set inner [$popup component inner]
    853             label $inner.summary -text "" -anchor w 
     852            label $inner.summary -text "" -anchor w
    854853
    855854            Rappture::Scroller $inner.scrl \
    856                 -xscrollmode auto -yscrollmode auto 
     855                -xscrollmode auto -yscrollmode auto
    857856            text $inner.scrl.text \
    858857                -font "Arial 9 " -background white -relief sunken -bd 1 \
     
    863862            blt::table $inner \
    864863                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"
    868867            $inner.scrl.text tag configure bold -font "Arial 10 bold"
    869868            $inner.scrl.text tag configure code -font "Courier 10 bold"
     
    874873        set inner [$popup component inner]
    875874        $inner.scrl.text delete 0.0 end
    876        
     875
    877876        $inner.scrl.text configure -state normal
    878877        $inner.scrl.text insert end "The following error was reported by the render server:\n\n" bold
     
    944943        "blue-to-grey" {
    945944            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
    953952                1.0                     0.200 0.200 0.200
    954953            }
    955954        }
    956955        "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
    967966                1.0                     0.000 0.250 1.000
    968967            }
     
    970969        "brown-to-blue" {
    971970            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
    984983            }
    985984        }
    986985        "blue-to-brown" {
    987986            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
    1000999            }
    10011000        }
     
    10351034            set clist {
    10361035                "#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"
    10431042            }
    10441043        }
    10451044        "BGYOR" {
    10461045            set clist {
    1047                 "blue" 
    1048                 "#008000" 
    1049                 "yellow" 
    1050                 "#FFA500" 
    1051                 "red" 
     1046                "blue"
     1047                "#008000"
     1048                "yellow"
     1049                "#FFA500"
     1050                "red"
    10521051            }
    10531052        }
    10541053        "ROYGB" {
    10551054            set clist {
    1056                 "red" 
    1057                 "#FFA500" 
    1058                 "yellow" 
    1059                 "#008000" 
    1060                 "blue" 
     1055                "red"
     1056                "#FFA500"
     1057                "yellow"
     1058                "#008000"
     1059                "blue"
    10611060            }
    10621061        }
    10631062        "RYGCB" {
    10641063            set clist {
    1065                 "red" 
    1066                 "yellow" 
     1064                "red"
     1065                "yellow"
    10671066                "green"
    10681067                "cyan"
     
    10721071        "BCGYR" {
    10731072            set clist {
    1074                 "blue" 
     1073                "blue"
    10751074                "cyan"
    10761075                "green"
    1077                 "yellow" 
    1078                 "red" 
     1076                "yellow"
     1077                "red"
    10791078            }
    10801079        }
    10811080        "spectral" {
    10821081            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
    10931092                1.0 0.650 0.000 0.130
    10941093            }
     
    10961095        "green-to-magenta" {
    10971096            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
    11131112                1.0 0.316 0.000 0.316
    11141113            }
    11151114        }
    11161115        "greyscale" {
    1117             return { 
     1116            return {
    11181117                0.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0
    11191118            }
     
    11451144#
    11461145itcl::body Rappture::VisViewer::StartBufferingCommands { } {
    1147     incr _buffering 
     1146    incr _buffering
    11481147    if { $_buffering == 1 } {
    11491148        set _outbuf ""
     
    11711170#
    11721171#       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
    11741173#       sent later.
    11751174#
     
    11861185#
    11871186#       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
    11891188#       sent later.
    11901189#
  • branches/uq/gui/scripts/vtkglyphviewer.tcl

    r4798 r5121  
    5757    public method get {args}
    5858    public method isconnected {}
    59     public method limits { colormap }
    6059    public method parameters {title args} {
    6160        # do nothing
     
    6362    public method scale {args}
    6463
    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 
    8164    # The following methods are only used by this class.
     65    private method AdjustSetting {what {value ""}}
    8266    private method BuildAxisTab {}
    8367    private method BuildCameraTab {}
     
    8872    private method DrawLegend {}
    8973    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 {}
    9079    private method EnterLegend { x y }
    9180    private method EventuallyResize { w h }
     
    9584    private method GetImage { args }
    9685    private method GetVtkData { args }
     86    private method InitSettings { args  }
    9787    private method IsValidObject { dataobj }
    9888    private method LeaveLegend {}
    9989    private method MotionLegend { x y }
     90    private method Pan {option x y}
    10091    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 }
    101100    private method RequestLegend {}
     101    private method Rotate {option x y}
    102102    private method SetLegendTip { x y }
    103103    private method SetObjectStyle { dataobj comp }
     
    105105    private method SetCurrentColormap { color }
    106106    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}
    107111
    108112    private variable _arcball ""
     
    144148    private variable _legendPending 0
    145149    private variable _field      ""
    146     private variable _colorMode "vmag"; #  Mode of colormap (vmag or scalar)
     150    private variable _colorMode "vmag"; #  Mode of colormap (vmag or scalar)
    147151    private variable _fieldNames {}
    148152    private variable _fields
     
    203207    # Initialize the view to some default parameters.
    204208    array set _view {
    205         qw              0.853553
    206         qx              -0.353553
    207         qy              0.353553
    208         qz              0.146447
    209         zoom            1.0
    210         xpan            0
    211         ypan            0
    212         ortho           0
     209        -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
    213217    }
    214218    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]
    217220
    218221    array set _settings [subst {
     
    239242        -glyphedges             0
    240243        -glyphlighting          1
     244        -glyphnormscale         1
    241245        -glyphopacity           100
     246        -glyphorient            1
    242247        -glyphoutline           0
    243248        -glyphscale             1
     249        -glyphscalemode         "vmag"
     250        -glyphshape             "arrow"
    244251        -glyphvisible           1
    245252        -glyphwireframe         0
     
    463470
    464471itcl::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]"
    467473    set _rotatePending 0
    468474}
     
    488494
    489495itcl::body Rappture::VtkGlyphViewer::EventuallyRotate { q } {
    490     foreach { _view(qw) _view(qx) _view(qy) _view(qz) } $q break
     496    QuaternionToView $q
    491497    if { !$_rotatePending } {
    492498        set _rotatePending 1
     
    833839    array unset _data
    834840    array unset _colormaps
    835     array unset _seeds
    836841    array unset _dataset2style
    837842    array unset _obj2datasets
     
    855860    if { $info(-type) == "image" } {
    856861        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
    859865            close $f
    860866        }
     
    944950        # Reset the camera and other view parameters
    945951        #
    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)} {
    949954            SendCmd "camera mode ortho"
    950955        } else {
     
    956961        InitSettings -xgrid -ygrid -zgrid -axismode \
    957962            -axesvisible -axislabels -axisminorticks
    958         foreach axis { x y z } {
    959             SendCmd "axis lformat $axis %g"
    960         }
     963        #SendCmd "axis lformat all %g"
    961964        StopBufferingCommands
    962965        SendCmd "imgflush"
     
    976979                if 0 {
    977980                    set f [open "/tmp/glyph.vtk" "w"]
    978                     puts $f $bytes
     981                    fconfigure $f -translation binary -encoding binary
     982                    puts -nonewline $f $bytes
    979983                    close $f
    980984                }
     
    982986                if { $_reportClientInfo }  {
    983987                    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]
    988993                    lappend info "dataset_label" [$dataobj hints label]
    989994                    lappend info "dataset_size"  $length
     
    10391044        # These are settings that rely on a dataset being loaded.
    10401045        InitSettings \
    1041             -glyphlighting \
    10421046            -field \
    10431047            -glyphedges -glyphlighting -glyphopacity \
     
    11291133    switch -- $option {
    11301134        "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)"
    11331137        }
    11341138        "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)"
    11371141        }
    11381142        "reset" {
    11391143            array set _view {
    1140                 qw     0.853553
    1141                 qx     -0.353553
    1142                 qy     0.353553
    1143                 qz     0.146447
    1144                 zoom   1.0
    1145                 xpan   0
    1146                 ypan   0
     1144                -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
    11471151            }
    11481152            if { $_first != "" } {
     
    11521156                }
    11531157            }
    1154             set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    1155             $_arcball quaternion $q
     1158            $_arcball quaternion [ViewToQuaternion]
    11561159            DoRotate
    11571160            SendCmd "camera reset"
     
    11611164
    11621165itcl::body Rappture::VtkGlyphViewer::PanCamera {} {
    1163     set x $_view(xpan)
    1164     set y $_view(ypan)
     1166    set x $_view(-xpan)
     1167    set y $_view(-ypan)
    11651168    SendCmd "camera pan $x $y"
    11661169}
     
    12201223itcl::body Rappture::VtkGlyphViewer::Pick {x y} {
    12211224    foreach tag [CurrentDatasets -visible] {
    1222         SendCmdNoSplash "dataset getscalar pixel $x $y $tag"
     1225        SendCmd "dataset getscalar pixel $x $y $tag"
    12231226    }
    12241227}
     
    12391242            set x [expr $x / double($w)]
    12401243            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]
    12431246            PanCamera
    12441247            return
     
    12621265            set _click(x) $x
    12631266            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]
    12661269            PanCamera
    12671270        }
     
    13461349        "-cutplanevisible" {
    13471350            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            }
    13491357        }
    13501358        "-cutplanewireframe" {
     
    14091417        "-glyphvisible" {
    14101418            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            }
    14121425            if { $bool } {
    14131426                Rappture::Tooltip::for $itk_component(glyphs) \
     
    14291442        "-glyphoutline" {
    14301443            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            }
    14321450        }
    14331451        "-glyphopacity" {
     
    14361454            SendCmd "glyphs opacity $sval"
    14371455        }
     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        }
    14381464        "-glyphscale" {
    14391465            set val $_settings($what)
     
    14411467                SendCmd "glyphs gscale $val"
    14421468            }
     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"
    14431481        }
    14441482        "-field" {
     
    14591497                return
    14601498            }
     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"
    14611505            SendCmd "glyphs colormode $_colorMode $_curFldName"
    14621506            DrawLegend
     
    15441588}
    15451589
    1546 itcl::body Rappture::VtkGlyphViewer::limits { dataobj } {
    1547     foreach { limits(xmin) limits(xmax) } [$dataobj limits x] break
    1548     foreach { limits(ymin) limits(ymax) } [$dataobj limits y] break
    1549     foreach { limits(zmin) limits(zmax) } [$dataobj limits z] break
    1550     foreach { limits(vmin) limits(vmax) } [$dataobj limits v] break
    1551     return [array get limits]
    1552 }
    1553 
    15541590itcl::body Rappture::VtkGlyphViewer::BuildGlyphTab {} {
    15551591
     
    15671603        -command [itcl::code $this AdjustSetting -glyphvisible] \
    15681604        -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"
    15691652
    15701653    checkbutton $inner.wireframe \
     
    16181701
    16191702    label $inner.gscale_l -text "Scale factor" -font "Arial 9"
     1703    if {0} {
    16201704    ::scale $inner.gscale -from 1 -to 100 -orient horizontal \
    16211705        -variable [itcl::scope _settings(-glyphscale)] \
     
    16231707        -showvalue off \
    16241708        -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    }
    16251721    Rappture::Tooltip::for $inner.gscale "Set scaling multiplier (or constant size)"
    16261722
     
    17551851        0,0 $inner.view_l -anchor e -pady 2 \
    17561852        0,1 $inner.view -anchor w -pady 2
     1853    blt::table configure $inner r0 -resize none
    17571854
    17581855    set labels { qx qy qz qw xpan ypan zoom }
     
    17611858        label $inner.${tag}label -text $tag -font "Arial 9"
    17621859        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}]
    17661865        blt::table $inner \
    17671866            $row,0 $inner.${tag}label -anchor e -pady 2 \
     
    17721871    checkbutton $inner.ortho \
    17731872        -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] \
    17761875        -font "Arial 9"
    17771876    blt::table $inner \
     
    17801879    incr row
    17811880
    1782     blt::table configure $inner c* r* -resize none
     1881    blt::table configure $inner c* -resize none
    17831882    blt::table configure $inner c2 -resize expand
    17841883    blt::table configure $inner r$row -resize expand
     
    19492048        }
    19502049        "set" {
    1951             set who [lindex $args 0]
    1952             set x $_view($who)
     2050            set what [lindex $args 0]
     2051            set x $_view($what)
    19532052            set code [catch { string is double $x } result]
    19542053            if { $code != 0 || !$result } {
    19552054                return
    19562055            }
    1957             switch -- $who {
    1958                 "ortho" {
    1959                     if {$_view(ortho)} {
     2056            switch -- $what {
     2057                "-ortho" {
     2058                    if {$_view($what)} {
    19602059                        SendCmd "camera mode ortho"
    19612060                    } else {
     
    19632062                    }
    19642063                }
    1965                 "xpan" - "ypan" {
     2064                "-xpan" - "-ypan" {
    19662065                    PanCamera
    19672066                }
    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]
    19702069                    $_arcball quaternion $q
    19712070                    EventuallyRotate $q
    19722071                }
    1973                 "zoom" {
    1974                     SendCmd "camera zoom $_view(zoom)"
     2072                "-zoom" {
     2073                    SendCmd "camera zoom $_view($what)"
    19752074                }
    19762075             }
     
    21062205
    21072206    SendCmd "glyphs add $style(-shape) $tag"
     2207    set _settings(-glyphshape) $style(-shape)
     2208    $itk_component(gshape) value $style(-shape)
    21082209    SendCmd "glyphs edges $style(-edges) $tag"
    21092210    set _settings(-glyphedges) $style(-edges)
     
    21162217        SendCmd "glyphs gscale $style(-gscale) $tag"
    21172218    }
     2219    set _settings(-glyphnormscale) $style(-normscale)
     2220    set _settings(-glyphscale) $style(-gscale)
    21182221
    21192222    # constant color only used if colormode set to constant
     
    21222225    # defaults to active scalars or vectors depending on mode
    21232226    SendCmd "glyphs gorient $style(-orientGlyphs) {} $tag"
     2227    set _settings(-glyphorient) $style(-orientGlyphs)
    21242228    SendCmd "glyphs smode $style(-scaleMode) {} $tag"
     2229    set _settings(-glyphscalemode) $style(-scaleMode)
     2230    $itk_component(scaleMode) value "[$itk_component(scaleMode) label $style(-scaleMode)]"
    21252231    SendCmd "glyphs quality $style(-quality) $tag"
    21262232    SendCmd "glyphs lighting $style(-lighting) $tag"
     
    24472553        bottom "0.707107 0.707107 0 0"
    24482554    }
    2449     foreach name { qw qx qy qz } value $positions($side) {
     2555    foreach name { -qw -qx -qy -qz } value $positions($side) {
    24502556        set _view($name) $value
    2451     } 
    2452     set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
     2557    }
     2558    set q [ViewToQuaternion]
    24532559    $_arcball quaternion $q
    24542560    SendCmd "camera orient $q"
    24552561    SendCmd "camera reset"
    2456     set _view(xpan) 0
    2457     set _view(ypan) 0
    2458     set _view(zoom) 1.0
    2459 }
     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 -*-
    22# ----------------------------------------------------------------------
    33#  COMPONENT: vtkheightmapviewer - Vtk heightmap viewer
     
    5858    public method get {args}
    5959    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
    6362    }
    6463    public method scale {args}
    6564
    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 
    8465    # The following methods are only used by this class.
     66    private method AdjustSetting {what {value ""}}
    8567    private method BuildAxisTab {}
    8668    private method BuildCameraTab {}
    8769    private method BuildColormap { name }
    8870    private method BuildContourTab {}
    89     private method BuildDownloadPopup { widget command }
     71    private method BuildDownloadPopup { widget command }
     72    private method CameraReset {}
    9073    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 {}
    9179    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 }
    9989    private method LeaveLegend {}
    100     private method MotionLegend { x y }
     90    private method MotionLegend { x y }
     91    private method Pan {option x y}
    10192    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 }
    102101    private method RequestLegend {}
     102    private method ResetAxes {}
     103    private method Rotate {option x y}
    103104    private method SetCurrentColormap { color }
    104105    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 }
    108107    private method SetOrientation { side }
    109108    private method UpdateContourList {}
     109    private method ViewToQuaternion {} {
     110        return [list $_view(-qw) $_view(-qx) $_view(-qy) $_view(-qz)]
     111    }
     112    private method Zoom {option}
    110113
    111114    private variable _arcball ""
     
    113116    private variable _obj2datasets
    114117    private variable _obj2ovride   ;    # maps dataobj => style override
    115     private variable _comp2scale;       # maps dataset to the heightmap scale.
    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
    117120                                   ;    # datasets in the server
    118121    private variable _colormaps    ;    # contains all the colormaps
     
    130133
    131134    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
    133136                                        # using the viewer.
    134137    private variable _view         ;    # view params for 3D view
     
    155158    private variable _rotatePending 0
    156159    private variable _legendPending 0
    157     private variable _fieldNames {} 
    158     private variable _fields 
     160    private variable _fieldNames {}
     161    private variable _fields
    159162    private variable _curFldName ""
    160163    private variable _curFldLabel ""
     
    202205    # Initialize the view to some default parameters.
    203206    array set _view {
    204         qw      0.36
    205         qx      0.25
    206         qy      0.50
    207         qz      0.70
    208         zoom    1.0
    209         xpan    0
    210         ypan    0
    211         ortho   0
     207        -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
    212215    }
    213216    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]
    216218
    217219    array set _settings {
    218         -axisflymode            "static"
     220        -axisflymode            "static"
    219221        -axislabels             1
    220         -axisminorticks         1
    221         -axisvisible            1
     222        -axisminorticks         1
     223        -axisvisible            1
    222224        -colormap               BCGYR
    223225        -colormapdiscrete       0
    224226        -colormapvisible        1
    225         -edges                  0
    226         -field                  "Default"
    227         -heightmapscale         50
    228         -isheightmap            0
     227        -edges                  0
     228        -field                  "Default"
     229        -heightmapscale         50
     230        -isheightmap            0
    229231        -isolinecolor           black
    230232        -isolinesvisible        1
    231233        -legendvisible          1
    232         -lighting               1
    233         -numisolines            10
     234        -lighting               1
     235        -numisolines            10
    234236        -opacity                100
    235         -outline                0
    236         -savelighting           1
    237         -saveopacity            100
    238         -saveoutline            0
    239         -stretchtofit           0
    240         -wireframe              0
    241         -xgrid                  0
    242         -ygrid                  0
    243         -zgrid                  0
     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
    244246    }
    245247    array set _changed {
     
    253255    } {
    254256        usual
    255         ignore -highlightthickness -borderwidth -background 
     257        ignore -highlightthickness -borderwidth -background
    256258    }
    257259
     
    259261        menu $itk_component(plotarea).menu \
    260262            -relief flat \
    261             -tearoff no 
     263            -tearoff no
    262264    } {
    263265        usual
     
    279281
    280282    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
    283285    set _map(zoom) 1.0
    284286    set _map(original) ""
     
    348350        BuildCameraTab
    349351    } errs] != 0 } {
    350         global errorInfo
     352        global errorInfo
    351353        puts stderr "errs=$errs errorInfo=$errorInfo"
    352354    }
    353355
    354     # Hack around the Tk panewindow.  The problem is that the requested 
     356    # Hack around the Tk panewindow.  The problem is that the requested
    355357    # size of the 3d view isn't set until an image is retrieved from
    356358    # the server.  So the panewindow uses the tiny size.
     
    358360    pack forget $itk_component(view)
    359361    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
    361363    blt::table configure $itk_component(plotarea) c1 -resize none
    362364
     
    442444
    443445itcl::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]"
    446447    set _rotatePending 0
    447448}
     
    467468
    468469itcl::body Rappture::VtkHeightmapViewer::EventuallyRotate { q } {
    469     foreach { _view(qw) _view(qx) _view(qy) _view(qz) } $q break
     470    QuaternionToView $q
    470471    if { !$_rotatePending } {
    471472        set _rotatePending 1
    472         global rotate_delay 
     473        global rotate_delay
    473474        $_dispatcher event -after $rotate_delay !rotate
    474475    }
     
    569570                    continue
    570571                }
    571                 if {[info exists _obj2ovride($dataobj-raise)] && 
     572                if {[info exists _obj2ovride($dataobj-raise)] &&
    572573                    $_obj2ovride($dataobj-raise)} {
    573574                    set dlist [linsert $dlist 0 $dataobj]
     
    597598            }
    598599            return $dlist
    599         }           
     600        }
    600601        -image {
    601602            if {[llength $args] != 2} {
     
    617618}
    618619
    619 # 
     620#
    620621# scale  --
    621622#
    622623#       This gets called either incrementally as new simulations are
    623624#       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
    626627#       objects as the user scans through data in the ResultSet viewer.
    627628#
     
    815816    $_dispatcher cancel !legend
    816817    # 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
    821822    global readyForNextFrame
    822823    set readyForNextFrame 1
     
    842843    if { $info(-type) == "image" } {
    843844        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
    846848            close $f
    847849        }
     
    849851        set time [clock seconds]
    850852        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>"
    852854        if { $_start > 0 } {
    853855            set finish [clock clicks -milliseconds]
     
    920922    # Turn on buffering of commands to the server.  We don't want to
    921923    # be preempted by a server disconnect/reconnect (which automatically
    922     # generates a new call to Rebuild).   
     924    # generates a new call to Rebuild).
    923925    StartBufferingCommands
    924926
    925927    if { $_width != $w || $_height != $h || $_reset } {
    926         set _width $w
    927         set _height $h
    928         $_arcball resize $w $h
    929         DoResize
    930         if { $_settings(-stretchtofit) } {
    931             AdjustSetting -stretchtofit
    932         }
     928        set _width $w
     929        set _height $h
     930        $_arcball resize $w $h
     931        DoResize
     932        if { $_settings(-stretchtofit) } {
     933            AdjustSetting -stretchtofit
     934        }
    933935    }
    934936    if { $_reset } {
    935         #
    936         # Reset the camera and other view parameters
    937         #
     937        #
     938        # Reset the camera and other view parameters
     939        #
    938940        InitSettings -isheightmap -background
    939941
    940942        # 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
    942944        # 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
    946948        # settings by default.  We can test more fine-grained
    947949        # controls on the axis settings tab if necessary.
    948950        # -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]
    954955        if {$_settings(-isheightmap) } {
    955             if { $_view(ortho)} {
     956            if { $_view(-ortho)} {
    956957                SendCmd "camera mode ortho"
    957958            } else {
     
    960961            DoRotate
    961962            SendCmd "camera reset"
    962         }
    963         PanCamera
     963        }
     964        PanCamera
    964965        StopBufferingCommands
    965966        SendCmd "imgflush"
     
    980981            if { ![info exists _datasets($tag)] } {
    981982                set bytes [$dataobj vtkdata $comp]
    982                 if 0 {
     983                if 0 {
    983984                    set f [open /tmp/vtkheightmap.vtk "w"]
    984                     puts $f $bytes
     985                    fconfigure $f -translation binary -encoding binary
     986                    puts -nonewline $f $bytes
    985987                    close $f
    986                 }
     988                }
    987989                set length [string length $bytes]
    988990                if { $_reportClientInfo }  {
    989991                    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]
    994997                    lappend info "dataset_label" [$dataobj hints label]
    995998                    lappend info "dataset_size"  $length
    996999                    lappend info "dataset_tag"   $tag
    997                     SendCmd [list "clientinfo" $info]
     1000                    SendCmd "clientinfo [list $info]"
    9981001                }
    9991002                SendCmd "dataset add $tag data follows $length"
     
    10081011                SendCmd "dataset visible 1 $tag"
    10091012            }
    1010             if { ![info exists _comp2scale($tag)] ||
    1011                 $_comp2scale($tag) != $scale } {
    1012                 SendCmd "heightmap heightscale $scale $tag"
    1013                 set _comp2scale($tag) $scale
    1014             }
     1013            if { ![info exists _comp2scale($tag)] ||
     1014                $_comp2scale($tag) != $scale } {
     1015                SendCmd "heightmap heightscale $scale $tag"
     1016                set _comp2scale($tag) $scale
     1017            }
    10151018        }
    10161019    }
    10171020    if { $_first != ""  } {
    1018         $itk_component(field) choices delete 0 end
    1019         $itk_component(fieldmenu) delete 0 end
    1020         array unset _fields
     1021        $itk_component(field) choices delete 0 end
     1022        $itk_component(fieldmenu) delete 0 end
     1023        array unset _fields
    10211024        set _curFldName ""
    10221025        foreach cname [$_first components] {
     
    10471050
    10481051    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 } {
    10551056            if { $axis == "z" } {
    10561057                set label [$_first hints label]
     
    10581059                set label [$_first hints ${axis}label]
    10591060            }
    1060             if { $label == "" } {
    1061                 if {$axis == "z"} {
     1061            if { $label == "" } {
     1062                if {$axis == "z"} {
    10621063                    if { [string match "component*" $_curFldName] } {
    10631064                        set label [string toupper $axis]
     
    10651066                        set label $_curFldLabel
    10661067                    }
    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]
    10901093        if {$_settings(-isheightmap) } {
    1091             if { $_view(ortho)} {
     1094            if { $_view(-ortho)} {
    10921095                SendCmd "camera mode ortho"
    10931096            } else {
     
    10971100            SendCmd "camera reset"
    10981101        }
    1099         PanCamera
    1100         InitSettings -xgrid -ygrid -zgrid \
    1101             -axisvisible -axislabels -heightmapscale -field -isheightmap \
     1102        PanCamera
     1103        InitSettings -xgrid -ygrid -zgrid \
     1104            -axisvisible -axislabels -heightmapscale -field -isheightmap \
    11021105            -numisolines
    11031106        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)}
    11071108        }
    11081109        RequestLegend
     
    11101111    }
    11111112    global readyForNextFrame
    1112     set readyForNextFrame 0;            # Don't advance to the next frame
     1113    set readyForNextFrame 0;                # Don't advance to the next frame
    11131114
    11141115    # Actually write the commands to the server socket.  If it fails, we don't
     
    11281129itcl::body Rappture::VtkHeightmapViewer::CurrentDatasets {args} {
    11291130    set flag [lindex $args 0]
    1130     switch -- $flag { 
     1131    switch -- $flag {
    11311132        "-all" {
    11321133            if { [llength $args] > 1 } {
     
    11471148                set dlist [get -visible]
    11481149            }
    1149         }           
     1150        }
    11501151        default {
    11511152            set dlist $args
     
    11661167itcl::body Rappture::VtkHeightmapViewer::CameraReset {} {
    11671168    array set _view {
    1168         qw      0.36
    1169         qx      0.25
    1170         qy      0.50
    1171         qz      0.70
    1172         zoom    1.0
    1173         xpan    0
    1174         ypan    0
     1169        -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
    11751176    }
    11761177    if { $_first != "" } {
     
    11801181        }
    11811182    }
    1182     set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    1183     $_arcball quaternion $q
     1183    $_arcball quaternion [ViewToQuaternion]
    11841184    if {$_settings(-isheightmap) } {
    11851185        DoRotate
     
    11991199    switch -- $option {
    12001200        "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)"
    12031203        }
    12041204        "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)"
    12071207        }
    12081208        "reset" {
    12091209            array set _view {
    1210                 zoom    1.0
    1211                 xpan    0
    1212                 ypan    0
     1210                -xpan    0
     1211                -ypan    0
     1212                -zoom    1.0
    12131213            }
    12141214            SendCmd "camera reset"
     
    12181218
    12191219itcl::body Rappture::VtkHeightmapViewer::PanCamera {} {
    1220     set x $_view(xpan)
    1221     set y $_view(ypan)
     1220    set x $_view(-xpan)
     1221    set y $_view(-ypan)
    12221222    SendCmd "camera pan $x $y"
    12231223}
     
    12791279    foreach tag [CurrentDatasets -visible] {
    12801280        SendCmd "dataset getscalar pixel $x $y $tag"
    1281     } 
     1281    }
    12821282}
    12831283
     
    12971297            set x [expr $x / double($w)]
    12981298            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]
    13011301            PanCamera
    13021302            return
     
    13201320            set _click(x) $x
    13211321            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]
    13241324            PanCamera
    13251325        }
     
    13811381            SendCmd "axis visible all $bool"
    13821382        }
    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         }
    13881383        "-background" {
    13891384            set bg [$itk_component(background) value]
    1390             array set fgcolors {
    1391                 "black" "white"
    1392                 "white" "black"
    1393                 "grey"  "black"
    1394             }
     1385            array set fgcolors {
     1386                "black" "white"
     1387                "white" "black"
     1388                "grey"  "black"
     1389            }
    13951390            set fg $fgcolors($bg)
    13961391            configure -plotbackground $bg -plotforeground $fg
    1397             $itk_component(view) delete "legend"
     1392            $itk_component(view) delete "legend"
    13981393            SendCmd "screen bgcolor [Color2RGB $bg]"
    13991394            SendCmd "outline color [Color2RGB $fg]"
    14001395            SendCmd "axis color all [Color2RGB $fg]"
    1401             DrawLegend
     1396            DrawLegend
    14021397        }
    14031398        "-colormap" {
     
    14061401            set color [$itk_component(colormap) value]
    14071402            set _settings($what) $color
    1408             if { $color == "none" } {
    1409                 if { $_settings(-colormapvisible) } {
    1410                     SendCmd "heightmap surface 0"
    1411                     set _settings(-colormapvisible) 0
    1412                 }
    1413             } else {
    1414                 if { !$_settings(-colormapvisible) } {
    1415                     SendCmd "heightmap surface 1"
    1416                     set _settings(-colormapvisible) 1
    1417                 }
    1418                 SetCurrentColormap $color
     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
    14191414                if {$_settings(-colormapdiscrete)} {
    14201415                    set numColors [expr $_settings(-numisolines) + 1]
    14211416                    SendCmd "colormap res $numColors $color"
    14221417                }
    1423             }
     1418            }
    14241419            StopBufferingCommands
    1425             EventuallyRequestLegend
     1420            EventuallyRequestLegend
    14261421        }
    14271422        "-colormapvisible" {
     
    14661461                return
    14671462            }
    1468             set label [$_first hints label]
    1469             if { $label == "" } {
     1463            set label [$_first hints label]
     1464            if { $label == "" } {
    14701465                if { [string match "component*" $_curFldName] } {
    14711466                    set label Z
     
    14731468                    set label $_curFldLabel
    14741469                }
    1475             }
    1476             # May be a space in the axis label.
    1477             SendCmd [list axis name z $label]
    1478 
    1479             if { [$_first hints zunits] == "" } {
    1480                 set units [lindex $_fields($_curFldName) 1]
    1481             } else {
    1482                 set units [$_first hints zunits]
    1483             }
    1484             if { $units != "" } {
    1485                 # May be a space in the axis units.
    1486                 SendCmd [list axis units z $units]
    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            }
    14881483            # Get the new limits because the field changed.
    14891484            ResetAxes
     
    14951490        }
    14961491        "-heightmapscale" {
    1497             if { $_settings(-isheightmap) } {
    1498                 set scale [GetHeightmapScale]
    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
    15001495                # tracking them in _comp2scale.
    15011496                foreach dataset [CurrentDatasets -all] {
    1502                     SendCmd "heightmap heightscale $scale $dataset"
    1503                     set _comp2scale($dataset) $scale
    1504                 }
    1505                 ResetAxes
    1506             }
     1497                    SendCmd "heightmap heightscale $scale $dataset"
     1498                    set _comp2scale($dataset) $scale
     1499                }
     1500                ResetAxes
     1501            }
    15071502        }
    15081503        "-isheightmap" {
    1509             set bool $_settings($what)
     1504            set bool $_settings($what)
    15101505            set c $itk_component(view)
    15111506            StartBufferingCommands
     
    15241519            InitSettings -lighting -opacity -outline
    15251520            set scale [GetHeightmapScale]
    1526             # Have to set the datasets individually because we are 
     1521            # Have to set the datasets individually because we are
    15271522            # tracking them in _comp2scale.
    15281523            foreach dataset [CurrentDatasets -all] {
     
    15301525                set _comp2scale($dataset) $scale
    15311526            }
    1532             if { $bool } {
    1533                 $itk_component(lighting) configure -state normal
    1534                 $itk_component(opacity) configure -state normal
    1535                 $itk_component(scale) configure -state normal
    1536                 $itk_component(opacity_l) configure -state normal
    1537                 $itk_component(scale_l) configure -state normal
    1538                 $itk_component(outline) configure -state disabled
    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)} {
    15401535                    SendCmd "camera mode ortho"
    15411536                } else {
    15421537                    SendCmd "camera mode persp"
    15431538                }
    1544             } else {
    1545                 $itk_component(lighting) configure -state disabled
    1546                 $itk_component(opacity) configure -state disabled
    1547                 $itk_component(scale) configure -state disabled
    1548                 $itk_component(opacity_l) configure -state disabled
    1549                 $itk_component(scale_l) configure -state disabled
    1550                 $itk_component(outline) configure -state normal
     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
    15511546                SendCmd "camera mode image"
    15521547            }
     
    15601555            ResetAxes
    15611556            if { $bool } {
    1562                 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
     1557                set q [ViewToQuaternion]
    15631558                $_arcball quaternion $q
    1564                 SendCmd "camera orient $q" 
     1559                SendCmd "camera orient $q"
    15651560            } else {
    15661561                bind $c <ButtonPress-1> {}
     
    15691564            }
    15701565            Zoom reset
    1571             # Fix the mouse bindings for rotation/panning and the 
     1566            # Fix the mouse bindings for rotation/panning and the
    15721567            # camera mode. Ideally we'd create a bindtag for these.
    15731568            if { $bool } {
     
    15841579        "-isolinecolor" {
    15851580            set color [$itk_component(isolinecolor) value]
    1586             if { $color == "none" } {
    1587                 if { $_settings(-isolinesvisible) } {
    1588                     SendCmd "heightmap isolines 0"
    1589                     set _settings(-isolinesvisible) 0
    1590                 }
    1591             } else {
    1592                 if { !$_settings(-isolinesvisible) } {
    1593                     SendCmd "heightmap isolines 1"
    1594                     set _settings(-isolinesvisible) 1
    1595                 }
    1596                 SendCmd "heightmap isolinecolor [Color2RGB $color]"
    1597             }
    1598             DrawLegend
     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
    15991594        }
    16001595        "-isolinesvisible" {
    1601             set bool $_settings($what)
     1596            set bool $_settings($what)
    16021597            SendCmd "heightmap isolines $bool"
    1603             DrawLegend
     1598            DrawLegend
    16041599        }
    16051600        "-legendvisible" {
    16061601            if { !$_settings($what) } {
    1607                 $itk_component(view) delete legend
    1608             }
    1609             DrawLegend
     1602                $itk_component(view) delete legend
     1603            }
     1604            DrawLegend
    16101605        }
    16111606        "-lighting" {
    1612             if { $_settings(-isheightmap) } {
     1607            if { $_settings(-isheightmap) } {
    16131608                set _settings(-savelighting) $_settings($what)
    1614                 set bool $_settings($what)
    1615                 SendCmd "heightmap lighting $bool"
    1616             } else {
    1617                 SendCmd "heightmap lighting 0"
    1618             }
     1609                set bool $_settings($what)
     1610                SendCmd "heightmap lighting $bool"
     1611            } else {
     1612                SendCmd "heightmap lighting 0"
     1613            }
    16191614        }
    16201615        "-numisolines" {
     
    16351630            set _changed($what) 1
    16361631            set val [expr $_settings($what) * 0.01]
    1637             if { $_settings(-isheightmap) } {
     1632            if { $_settings(-isheightmap) } {
    16381633                set _settings(-saveopacity) $_settings($what)
    16391634                SendCmd "heightmap opacity $val"
    16401635            } else {
    1641                 SendCmd "heightmap opacity 1.0"
     1636                SendCmd "heightmap opacity 1.0"
    16421637            }
    16431638        }
    16441639        "-outline" {
    1645             if { $_settings(-isheightmap) } {
    1646                 SendCmd "outline visible 0"
     1640            if { $_settings(-isheightmap) } {
     1641                SendCmd "outline visible 0"
    16471642            } else {
    16481643                set _settings(-saveoutline) $_settings($what)
     
    16501645                SendCmd "outline visible $bool"
    16511646            }
    1652         }
     1647        }
    16531648        "-stretchtofit" {
    1654             set bool $_settings($what)
    1655             if { $bool } {
    1656                 set heightScale [GetHeightmapScale]
    1657                 if {$heightScale == 0} {
    1658                     SendCmd "camera aspect window"
    1659                 } else {
    1660                     SendCmd "camera aspect square"
    1661                 }
    1662             } else {
    1663                 SendCmd "camera aspect native"
    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            }
    16651660            Zoom reset
    1666         }
     1661        }
    16671662        "-wireframe" {
    16681663            set bool $_settings($what)
    16691664            SendCmd "heightmap wireframe $bool"
    16701665        }
    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 {
    16721672            error "don't know how to fix $what"
    16731673        }
     
    16791679#
    16801680#       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.
    16821682#
    16831683# This should be called when
    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).
     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).
    16891689#
    16901690itcl::body Rappture::VtkHeightmapViewer::RequestLegend {} {
     
    16931693    set w 12
    16941694    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
    16961696    set h [expr {$_height - 2 * ($lineht + 2)}]
    16971697    set _legendHeight $h
     
    16991699    set fname $_curFldName
    17001700    if { [string match "component*" $fname] } {
    1701         set title ""
     1701        set title ""
    17021702    } else {
    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         }
     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        }
    17111711    }
    17121712    # If there's a title too, substract one more line
    17131713    if { $title != "" } {
    1714         incr h -$lineht 
     1714        incr h -$lineht
    17151715    }
    17161716    if { $h < 1 } {
     
    17191719    # Set the legend on the first heightmap dataset.
    17201720    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"
    17231724    }
    17241725}
     
    17731774    # Keep track of the colormaps that we build.
    17741775    if { $name != "none" && ![info exists _colormaps($name)] } {
    1775         BuildColormap $name 
     1776        BuildColormap $name
    17761777        set _colormaps($name) 1
    17771778    }
     
    17791780    SendCmd "heightmap colormap $_currentColormap"
    17801781}
    1781 
    17821782
    17831783#
     
    18001800itcl::configbody Rappture::VtkHeightmapViewer::mode {
    18011801    switch -- $itk_option(-mode) {
    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         }
     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        }
    18111811    }
    18121812    if { !$_reset } {
     
    18241824            SendCmd "screen bgcolor $rgb"
    18251825        }
    1826         $itk_component(view) configure -background $itk_option(-plotbackground)
     1826        $itk_component(view) configure -background $itk_option(-plotbackground)
    18271827    }
    18281828}
     
    18351835        set rgb [Color2RGB $itk_option(-plotforeground)]
    18361836        if { !$_reset } {
     1837            SendCmd "axis color all $rgb"
    18371838            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    }
    18511841}
    18521842
     
    18741864
    18751865    itk_component add lighting {
    1876         checkbutton $inner.lighting \
    1877             -text "Enable Lighting" \
    1878             -variable [itcl::scope _settings(-lighting)] \
    1879             -command [itcl::code $this AdjustSetting -lighting] \
    1880             -font "Arial 9"
     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"
    18811871    } {
    1882         ignore -font
     1872        ignore -font
    18831873    }
    18841874    checkbutton $inner.edges \
     
    19161906
    19171907    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"
    19191909    } {
    19201910        ignore -font
     
    19261916        [itcl::code $this AdjustSetting -field]
    19271917
    1928     label $inner.colormap_l -text "Colormap" -font "Arial 9" 
     1918    label $inner.colormap_l -text "Colormap" -font "Arial 9"
    19291919    itk_component add colormap {
    19301920        Rappture::Combobox $inner.colormap -width 10 -editable no
     
    19351925        [itcl::code $this AdjustSetting -colormap]
    19361926
    1937     label $inner.isolinecolor_l -text "Isolines Color" -font "Arial 9" 
     1927    label $inner.isolinecolor_l -text "Isolines Color" -font "Arial 9"
    19381928    itk_component add isolinecolor {
    19391929        Rappture::Combobox $inner.isolinecolor -width 10 -editable no
     
    19491939        "red"                "red"              \
    19501940        "white"              "white"            \
    1951         "none"               "none"
     1941        "none"               "none"
    19521942
    19531943    $itk_component(isolinecolor) value $_settings(-isolinecolor)
    19541944    bind $inner.isolinecolor <<Value>> \
    1955         [itcl::code $this AdjustSetting -isolinecolor]
    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"
    19581948    itk_component add background {
    19591949        Rappture::Combobox $inner.background -width 10 -editable no
     
    19621952        "black"              "black"            \
    19631953        "white"              "white"            \
    1964         "grey"               "grey"             
     1954        "grey"               "grey"
    19651955
    19661956    $itk_component(background) value "white"
     
    20091999        2,0 $inner.isolinecolor_l  -anchor w -pady 2  \
    20102000        2,1 $inner.isolinecolor    -anchor w -pady 2 -fill x  \
    2011         3,0 $inner.background_l -anchor w -pady 2 \
    2012         3,1 $inner.background -anchor w -pady 2  -fill x \
     2001        3,0 $inner.background_l -anchor w -pady 2 \
     2002        3,1 $inner.background -anchor w -pady 2  -fill x \
    20132003        4,0 $inner.numisolines_l -anchor w -pady 2 \
    20142004        4,1 $inner.numisolines -anchor w -pady 2 \
     
    20522042        -command [itcl::code $this AdjustSetting -axislabels] \
    20532043        -font "Arial 9"
    2054     label $inner.grid_l -text "Grid" -font "Arial 9" 
     2044    label $inner.grid_l -text "Grid" -font "Arial 9"
    20552045    checkbutton $inner.xgrid \
    20562046        -text "X" \
     
    20742064        -font "Arial 9"
    20752065
    2076     label $inner.mode_l -text "Mode" -font "Arial 9" 
     2066    label $inner.mode_l -text "Mode" -font "Arial 9"
    20772067
    20782068    itk_component add axisflymode {
     
    20832073        "closest_triad"   "closest" \
    20842074        "furthest_triad"  "farthest" \
    2085         "outer_edges"     "outer"         
     2075        "outer_edges"     "outer"
    20862076    $itk_component(axisflymode) value $_settings(-axisflymode)
    20872077    bind $inner.mode <<Value>> [itcl::code $this AdjustSetting -axisflymode]
     
    20912081        1,0 $inner.labels  -anchor w -cspan 4 \
    20922082        2,0 $inner.minorticks  -anchor w -cspan 4 \
    2093         4,0 $inner.grid_l  -anchor w \
     2083        4,0 $inner.grid_l  -anchor w \
    20942084        4,1 $inner.xgrid   -anchor w \
    20952085        4,2 $inner.ygrid   -anchor w \
    20962086        4,3 $inner.zgrid   -anchor w \
    20972087        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
    20992089
    21002090    blt::table configure $inner r* c* -resize none
     
    21022092    blt::table configure $inner r3 -height 0.125i
    21032093}
    2104 
    21052094
    21062095itcl::body Rappture::VtkHeightmapViewer::BuildCameraTab {} {
     
    21222111        0,0 $inner.view_l -anchor e -pady 2 \
    21232112        0,1 $inner.view -anchor w -pady 2
     2113    blt::table configure $inner r0 -resize none
    21242114
    21252115    set labels { qx qy qz qw xpan ypan zoom }
     
    21282118        label $inner.${tag}label -text $tag -font "Arial 9"
    21292119        entry $inner.${tag} -font "Arial 9"  -bg white \
    2130             -textvariable [itcl::scope _view($tag)]
     2120            -textvariable [itcl::scope _view(-$tag)]
    21312121        bind $inner.${tag} <Return> \
    2132             [itcl::code $this camera set ${tag}]
     2122            [itcl::code $this camera set -${tag}]
    21332123        bind $inner.${tag} <KP_Enter> \
    2134             [itcl::code $this camera set ${tag}]
     2124            [itcl::code $this camera set -${tag}]
    21352125        blt::table $inner \
    21362126            $row,0 $inner.${tag}label -anchor e -pady 2 \
     
    21412131    checkbutton $inner.ortho \
    21422132        -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] \
    21452135        -font "Arial 9"
    21462136    blt::table $inner \
     
    21492139    incr row
    21502140
    2151     blt::table configure $inner c* r* -resize none
     2141    blt::table configure $inner c* -resize none
    21522142    blt::table configure $inner c2 -resize expand
    21532143    blt::table configure $inner r$row -resize expand
     
    21552145
    21562146#
    2157 #  camera -- 
     2147#  camera --
    21582148#
    21592149itcl::body Rappture::VtkHeightmapViewer::camera {option args} {
    2160     switch -- $option { 
     2150    switch -- $option {
    21612151        "show" {
    21622152            puts [array get _view]
    21632153        }
    21642154        "set" {
    2165             set who [lindex $args 0]
    2166             set x $_view($who)
     2155            set what [lindex $args 0]
     2156            set x $_view($what)
    21672157            set code [catch { string is double $x } result]
    21682158            if { $code != 0 || !$result } {
    21692159                return
    21702160            }
    2171             switch -- $who {
    2172                 "ortho" {
    2173                     if {$_view(ortho)} {
     2161            switch -- $what {
     2162                "-ortho" {
     2163                    if {$_view($what)} {
    21742164                        SendCmd "camera mode ortho"
    21752165                    } else {
     
    21772167                    }
    21782168                }
    2179                 "xpan" - "ypan" {
     2169                "-xpan" - "-ypan" {
    21802170                    PanCamera
    21812171                }
    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]
    21842174                    $_arcball quaternion $q
    21852175                    EventuallyRotate $q
    21862176                }
    2187                 "zoom" {
    2188                     SendCmd "camera zoom $_view(zoom)"
     2177                "-zoom" {
     2178                    SendCmd "camera zoom $_view($what)"
    21892179                }
    21902180            }
     
    22062196
    22072197itcl::body Rappture::VtkHeightmapViewer::GetImage { args } {
    2208     if { [image width $_image(download)] > 0 && 
     2198    if { [image width $_image(download)] > 0 &&
    22092199         [image height $_image(download)] > 0 } {
    22102200        set bytes [$_image(download) data -format "jpeg -quality 100"]
     
    22192209        -title "[Rappture::filexfer::label downloadWord] as..."
    22202210    set inner [$popup component inner]
    2221     label $inner.summary -text "" -anchor w 
     2211    label $inner.summary -text "" -anchor w
    22222212    radiobutton $inner.vtk_button -text "VTK data file" \
    22232213        -variable [itcl::scope _downloadPopup(format)] \
    22242214        -font "Arial 9 " \
    2225         -value vtk 
     2215        -value vtk
    22262216    Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file."
    22272217    radiobutton $inner.image_button -text "Image File" \
    22282218        -variable [itcl::scope _downloadPopup(format)] \
    22292219        -font "Arial 9 " \
    2230         -value image 
     2220        -value image
    22312221    Rappture::Tooltip::for $inner.image_button \
    22322222        "Save as digital image."
     
    22492239        2,0 $inner.image_button -anchor w -cspan 2 -padx { 4 0 } \
    22502240        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
    22522242    blt::table configure $inner r3 -height 4
    22532243    blt::table configure $inner r4 -pady 4
     
    22602250# SetObjectStyle --
    22612251#
    2262 #       Set the style of the heightmap/contour object.  This gets calls 
     2252#       Set the style of the heightmap/contour object.  This gets calls
    22632253#       for each dataset once as it is loaded.  It can overridden by
    22642254#       the user controls.
     
    23512341        #puts stderr "read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>"
    23522342        if { [catch {DrawLegend} errs] != 0 } {
    2353             global errorInfo
    2354             puts stderr "errs=$errs errorInfo=$errorInfo"
     2343            global errorInfo
     2344            puts stderr "errs=$errs errorInfo=$errorInfo"
    23552345        }
    23562346    }
     
    23692359    set font "Arial 8"
    23702360    set lineht [font metrics $font -linespace]
    2371    
     2361
    23722362    if { [string match "component*" $fname] } {
    2373         set title ""
     2363        set title ""
    23742364    } else {
    2375         if { [info exists _fields($fname)] } {
    2376             foreach { title units } $_fields($fname) break
    2377             if { $units != "" } {
    2378                 set title [format "%s (%s)" $title $units]
    2379             }
    2380         } else {
    2381             set title $fname
    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        }
    23832373    }
    23842374    set x [expr $w - 2]
    23852375    if { !$_settings(-legendvisible) } {
    2386         $c delete legend
    2387         return
    2388     } 
     2376        $c delete legend
     2377        return
     2378    }
    23892379    if { [$c find withtag "legend"] == "" } {
    2390         set y 2
    2391         # If there's a legend title, create a text item for the title.
     2380        set y 2
     2381        # If there's a legend title, create a text item for the title.
    23922382        $c create text $x $y \
    23932383            -anchor ne \
     
    23972387            incr y $lineht
    23982388        }
    2399         $c create text $x $y \
     2389        $c create text $x $y \
    24002390            -anchor ne \
    24012391            -fill $itk_option(-plotforeground) -tags "vmax legend" \
    24022392            -font $font
    24032393        incr y $lineht
    2404         $c create image $x $y \
    2405             -anchor ne \
    2406             -image $_image(legend) -tags "colormap legend"
    2407         $c create rectangle $x $y 1 1 \
    2408             -fill "" -outline "" -tags "sensor legend"
    2409         $c create text $x [expr {$h-2}] \
    2410             -anchor se \
    2411             -fill $itk_option(-plotforeground) -tags "vmin legend" \
    2412             -font $font
    2413         $c bind sensor <Enter> [itcl::code $this EnterLegend %x %y]
    2414         $c bind sensor <Leave> [itcl::code $this LeaveLegend]
    2415         $c bind sensor <Motion> [itcl::code $this MotionLegend %x %y]
     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]
    24162406    }
    24172407    $c delete isoline
     
    24242414    # Draw the isolines on the legend.
    24252415    array unset _isolines
    2426     if { $color != "none"  && [info exists _limits($_curFldName)] && 
     2416    if { $color != "none"  && [info exists _limits($_curFldName)] &&
    24272417         $_settings(-isolinesvisible) && $_currentNumIsolines > 0 } {
    24282418
     
    24332423        }
    24342424        set tags "isoline legend"
    2435         set offset [expr 2 + $lineht]
    2436         if { $title != "" } {
    2437             incr offset $lineht
    2438         }
     2425        set offset [expr 2 + $lineht]
     2426        if { $title != "" } {
     2427            incr offset $lineht
     2428        }
    24392429        foreach value $_contourList {
    24402430            set norm [expr 1.0 - (($value - $vmin) / $range)]
     
    24442434                set _isolines([expr $y1 - $off]) $value
    24452435            }
    2446             $c create line $x1 $y1 $x2 $y1 -fill $color -tags $tags
    2447         }
     2436            $c create line $x1 $y1 $x2 $y1 -fill $color -tags $tags
     2437        }
    24482438    }
    24492439
     
    24542444    if { [info exists _limits($_curFldName)] } {
    24552445        foreach { vmin vmax } $_limits($_curFldName) break
    2456         $c itemconfigure vmin -text [format %g $vmin]
    2457         $c itemconfigure vmax -text [format %g $vmax]
     2446        $c itemconfigure vmin -text [format %g $vmin]
     2447        $c itemconfigure vmax -text [format %g $vmax]
    24582448    }
    24592449    set y 2
     
    24612451    if { $title != "" } {
    24622452        $c itemconfigure title -text $title
    2463         $c coords title $x $y
    2464         incr y $lineht
     2453        $c coords title $x $y
     2454        incr y $lineht
    24652455    }
    24662456    $c coords vmax $x $y
     
    25102500    set font "Arial 8"
    25112501    set lineht [font metrics $font -linespace]
    2512    
     2502
    25132503    set ih [image height $_image(legend)]
    25142504    # Subtract off the offset of the color ramp from the top of the canvas
     
    25162506
    25172507    if { [string match "component*" $fname] } {
    2518         set title ""
     2508        set title ""
    25192509    } else {
    2520         if { [info exists _fields($fname)] } {
    2521             foreach { title units } $_fields($fname) break
    2522             if { $units != "" } {
    2523                 set title [format "%s (%s)" $title $units]
    2524             }
    2525         } else {
    2526             set title $fname
    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        }
    25282518    }
    25292519    # If there's a legend title, increase the offset by the line height.
     
    25412531    }
    25422532    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
    25452535
    25462536    # Compute the value of the point
     
    25522542        set value 0.0
    25532543    }
    2554     set tipx [expr $x + 15] 
     2544    set tipx [expr $x + 15]
    25552545    set tipy [expr $y - 5]
    25562546    .rappturetooltip configure -icon $_image(swatch)
     
    25602550        Rappture::Tooltip::text $c [format "$title %g" $value]
    25612551    }
    2562     Rappture::Tooltip::tooltip show $c +$tipx,+$tipy   
     2552    Rappture::Tooltip::tooltip show $c +$tipx,+$tipy
    25632553}
    25642554
     
    25752565# ----------------------------------------------------------------------
    25762566itcl::body Rappture::VtkHeightmapViewer::Combo {option} {
    2577     set c $itk_component(view) 
     2567    set c $itk_component(view)
    25782568    switch -- $option {
    25792569        post {
     
    25882578        }
    25892579        deactivate {
    2590             $c itemconfigure title -fill $itk_option(-plotforeground) 
     2580            $c itemconfigure title -fill $itk_option(-plotforeground)
    25912581        }
    25922582        invoke {
     
    26022592itcl::body Rappture::VtkHeightmapViewer::GetHeightmapScale {} {
    26032593    if {  $_settings(-isheightmap) } {
    2604         set val $_settings(-heightmapscale)
    2605         set sval [expr { $val >= 50 ? double($val)/50.0 : 1.0/(2.0-(double($val)/50.0)) }]
    2606         return $sval
    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
     2601itcl::body Rappture::VtkHeightmapViewer::SetOrientation { side } {
    26122602    array set positions {
    26132603        front  "0.707107 0.707107 0 0"
     
    26182608        bottom "0 1 0 0"
    26192609    }
    2620     foreach name { qw qx qy qz } value $positions($side) {
     2610    foreach name { -qw -qx -qy -qz } value $positions($side) {
    26212611        set _view($name) $value
    2622     } 
    2623     set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
     2612    }
     2613    set q [ViewToQuaternion]
    26242614    $_arcball quaternion $q
    26252615    SendCmd "camera orient $q"
    26262616    SendCmd "camera reset"
    2627     set _view(xpan) 0
    2628     set _view(ypan) 0
    2629     set _view(zoom) 1.0
    2630 }
    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
     2622itcl::body Rappture::VtkHeightmapViewer::UpdateContourList {} {
    26332623    if {$_currentNumIsolines == 0} {
    26342624        set _contourList ""
  • branches/uq/gui/scripts/vtkimageviewer.tcl

    r4798 r5121  
    1 # -*- mode: tcl; indent-tabs-mode: nil -*- 
     1# -*- mode: tcl; indent-tabs-mode: nil -*-
    22# ----------------------------------------------------------------------
    33#  COMPONENT: vtkimageviewer - Vtk image viewer
     
    5858    public method get {args}
    5959    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
    6362    }
    6463    public method scale {args}
    6564
    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 
    8365    # The following methods are only used by this class.
     66    private method AdjustSetting {what {value ""}}
    8467    private method BuildAxisTab {}
    8568    private method BuildCameraTab {}
    8669    private method BuildColormap { name }
    8770    private method BuildImageTab {}
    88     private method BuildDownloadPopup { widget command } 
     71    private method BuildDownloadPopup { widget command }
    8972    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 {}
    9078    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 }
    9887    private method LeaveLegend {}
    99     private method MotionLegend { x y }
     88    private method MotionLegend { x y }
     89    private method Pan {option x y}
    10090    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 }
    10199    private method RequestLegend {}
     100    private method Rotate {option x y}
    102101    private method SetCurrentColormap { color }
    103102    private method SetLegendTip { x y }
    104     private method SetObjectStyle { dataobj comp } 
     103    private method SetObjectStyle { dataobj comp }
    105104    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}
    106109
    107110    private variable _arcball ""
     
    109112    private variable _obj2datasets
    110113    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
    112115                                   ;    # datasets in the server
    113116    private variable _colormaps    ;    # contains all the colormaps
     
    125128
    126129    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
    128131                                        # using the viewer.
    129132    private variable _view         ;    # view params for 3D view
     
    150153    private variable _rotatePending 0
    151154    private variable _legendPending 0
    152     private variable _fieldNames {} 
    153     private variable _fields 
     155    private variable _fieldNames {}
     156    private variable _fields
    154157    private variable _curFldName ""
    155158    private variable _curFldLabel ""
     
    197200    # Initialize the view to some default parameters.
    198201    array set _view {
    199         qw      0.36
    200         qx      0.25
    201         qy      0.50
    202         qz      0.70
    203         zoom    1.0
    204         xpan    0
    205         ypan    0
    206         ortho   0
     202        -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
    207210    }
    208211    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]
    211213
    212214    array set _settings {
    213         axisFlymode             "static"
    214         axisLabels              1
    215         axisMinorTicks          1
    216         axisVisible             1
    217         axisXGrid               0
    218         axisYGrid               0
    219         axisZGrid               0
    220         backingColor            white
    221         backingVisible          1
    222         colormapDiscrete        0
    223         field                   "Default"
    224         legendVisible           0
    225         level                   127.5
    226         numColors               256
    227         opacity                 100
    228         outline                 0
    229         saveOpacity             100
    230         stretchToFit            0
    231         view3D                  0
    232         window                  255.0
     215        -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
    233235    }
    234236    array set _changed {
    235         opacity                 0
    236         colormap                0
     237        -colormap               0
     238        -opacity                0
    237239    }
    238240    itk_component add view {
     
    241243    } {
    242244        usual
    243         ignore -highlightthickness -borderwidth -background 
     245        ignore -highlightthickness -borderwidth -background
    244246    }
    245247
     
    247249        menu $itk_component(plotarea).menu \
    248250            -relief flat \
    249             -tearoff no 
     251            -tearoff no
    250252    } {
    251253        usual
     
    267269
    268270    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
    271273    set _map(zoom) 1.0
    272274    set _map(original) ""
     
    313315            -onimage [Rappture::icon surface] \
    314316            -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] \
    317319    }
    318320    Rappture::Tooltip::for $itk_component(mode) \
     
    324326            -onimage [Rappture::icon stretchtofit] \
    325327            -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] \
    328330    }
    329331    Rappture::Tooltip::for $itk_component(stretchtofit) \
     
    336338        BuildCameraTab
    337339    } errs] != 0 } {
    338         global errorInfo
     340        global errorInfo
    339341        puts stderr "errs=$errs errorInfo=$errorInfo"
    340342    }
    341343
    342     # Hack around the Tk panewindow.  The problem is that the requested 
     344    # Hack around the Tk panewindow.  The problem is that the requested
    343345    # size of the 3d view isn't set until an image is retrieved from
    344346    # the server.  So the panewindow uses the tiny size.
     
    346348    pack forget $itk_component(view)
    347349    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
    349351    blt::table configure $itk_component(plotarea) c1 -resize none
    350352
     
    430432
    431433itcl::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]"
    434435    set _rotatePending 0
    435436}
     
    455456
    456457itcl::body Rappture::VtkImageViewer::EventuallyRotate { q } {
    457     foreach { _view(qw) _view(qx) _view(qy) _view(qz) } $q break
     458    QuaternionToView $q
    458459    if { !$_rotatePending } {
    459460        set _rotatePending 1
    460         global rotate_delay 
     461        global rotate_delay
    461462        $_dispatcher event -after $rotate_delay !rotate
    462463    }
     
    557558                    continue
    558559                }
    559                 if {[info exists _obj2ovride($dataobj-raise)] && 
     560                if {[info exists _obj2ovride($dataobj-raise)] &&
    560561                    $_obj2ovride($dataobj-raise)} {
    561562                    set dlist [linsert $dlist 0 $dataobj]
     
    585586            }
    586587            return $dlist
    587         }           
     588        }
    588589        -image {
    589590            if {[llength $args] != 2} {
     
    605606}
    606607
    607 # 
     608#
    608609# scale  --
    609610#
    610611#       This gets called either incrementally as new simulations are
    611612#       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
    614615#       objects as the user scans through data in the ResultSet viewer.
    615616#
     
    654655    }
    655656    if { [array size found] > 1 } {
    656         set _settings(stretchToFit) 1
     657        set _settings(-stretchtofit) 1
    657658    } else {
    658659        # Check if the range of the x and y axes requires that we stretch
     
    663664        if { (($xmax - $xmin) > (($ymax -$ymin) * $_maxScale)) ||
    664665             ((($xmax - $xmin) * $_maxScale) < ($ymax -$ymin)) } {
    665             set _settings(stretchToFit) 1
     666            set _settings(-stretchtofit) 1
    666667        }
    667668    }
     
    803804    $_dispatcher cancel !legend
    804805    # 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
    809810    global readyForNextFrame
    810811    set readyForNextFrame 1
     
    830831    if { $info(-type) == "image" } {
    831832        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
    834836            close $f
    835837        }
     
    837839        set time [clock seconds]
    838840        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>"
    840842        if { $_start > 0 } {
    841843            set finish [clock clicks -milliseconds]
     
    908910    # Turn on buffering of commands to the server.  We don't want to
    909911    # be preempted by a server disconnect/reconnect (which automatically
    910     # generates a new call to Rebuild).   
     912    # generates a new call to Rebuild).
    911913    StartBufferingCommands
    912914
    913915    if { $_width != $w || $_height != $h || $_reset } {
    914         set _width $w
    915         set _height $h
    916         $_arcball resize $w $h
    917         DoResize
    918         if { $_settings(stretchToFit) } {
    919             AdjustSetting stretchToFit
    920         }
     916        set _width $w
     917        set _height $h
     918        $_arcball resize $w $h
     919        DoResize
     920        if { $_settings(-stretchtofit) } {
     921            AdjustSetting -stretchToFit
     922        }
    921923    }
    922924    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)} {
    937934                SendCmd "camera mode ortho"
    938935            } else {
     
    941938            DoRotate
    942939            SendCmd "camera reset"
    943         }
    944         PanCamera
     940        }
     941        PanCamera
    945942        StopBufferingCommands
    946943        SendCmd "imgflush"
     
    960957            if { ![info exists _datasets($tag)] } {
    961958                set bytes [$dataobj vtkdata $comp]
    962                 if 0 {
     959                if 0 {
    963960                    set f [open /tmp/vtkimage.vtk "w"]
    964                     puts $f $bytes
     961                    fconfigure $f -translation binary -encoding binary
     962                    puts -nonewline $f $bytes
    965963                    close $f
    966                 }
     964                }
    967965                set length [string length $bytes]
    968966                if { $_reportClientInfo }  {
    969967                    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]
    974973                    lappend info "dataset_label" [$dataobj hints label]
    975974                    lappend info "dataset_size"  $length
    976975                    lappend info "dataset_tag"   $tag
    977                     SendCmd [list "clientinfo" $info]
     976                    SendCmd "clientinfo [list $info]"
    978977                }
    979978                SendCmd "dataset add $tag data follows $length"
     
    991990    }
    992991    if { $_first != ""  } {
    993         $itk_component(field) choices delete 0 end
    994         $itk_component(fieldmenu) delete 0 end
    995         array unset _fields
     992        $itk_component(field) choices delete 0 end
     993        $itk_component(fieldmenu) delete 0 end
     994        array unset _fields
    996995        set _curFldName ""
    997996        foreach cname [$_first components] {
     
    10191018        $itk_component(field) value $_curFldLabel
    10201019    }
    1021     InitSettings stretchToFit outline
     1020    InitSettings -stretchtofit -outline
    10221021
    10231022    if { $_reset } {
    1024         SendCmd "axis tickpos outside"
     1023        SendCmd "axis tickpos outside"
    10251024        #SendCmd "axis lformat all %g"
    1026        
    1027         foreach axis { x y z } {
     1025
     1026        foreach axis { x y z } {
    10281027            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)} {
    10521052                SendCmd "camera mode ortho"
    10531053            } else {
     
    10571057            SendCmd "camera reset"
    10581058        }
    1059         PanCamera
    1060         InitSettings axisXGrid axisYGrid axisZGrid \
    1061             axisVisible axisLabels field view3D
     1059        PanCamera
     1060        InitSettings -xgrid -ygrid -zgrid \
     1061            -axisvisible -axislabels -field -view3d
    10621062        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)}
    10661064        }
    10671065        RequestLegend
     
    10691067    }
    10701068    global readyForNextFrame
    1071     set readyForNextFrame 0;            # Don't advance to the next frame
     1069    set readyForNextFrame 0;                # Don't advance to the next frame
    10721070
    10731071    # Actually write the commands to the server socket.  If it fails, we don't
     
    10871085itcl::body Rappture::VtkImageViewer::CurrentDatasets {args} {
    10881086    set flag [lindex $args 0]
    1089     switch -- $flag { 
     1087    switch -- $flag {
    10901088        "-all" {
    10911089            if { [llength $args] > 1 } {
     
    11061104                set dlist [get -visible]
    11071105            }
    1108         }           
     1106        }
    11091107        default {
    11101108            set dlist $args
     
    11341132    switch -- $option {
    11351133        "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)"
    11381136        }
    11391137        "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)"
    11421140        }
    11431141        "reset" {
    11441142            array set _view {
    1145                 qw      0.36
    1146                 qx      0.25
    1147                 qy      0.50
    1148                 qz      0.70
    1149                 zoom    1.0
    1150                 xpan    0
    1151                 ypan    0
     1143                -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
    11521150            }
    11531151            if { $_first != "" } {
     
    11571155                }
    11581156            }
    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) } {
    11621159                DoRotate
    11631160            }
     
    11681165
    11691166itcl::body Rappture::VtkImageViewer::PanCamera {} {
    1170     set x $_view(xpan)
    1171     set y $_view(ypan)
     1167    set x $_view(-xpan)
     1168    set y $_view(-ypan)
    11721169    SendCmd "camera pan $x $y"
    11731170}
     
    12291226    foreach tag [CurrentDatasets -visible] {
    12301227        SendCmd "dataset getscalar pixel $x $y $tag"
    1231     } 
     1228    }
    12321229}
    12331230
     
    12471244            set x [expr $x / double($w)]
    12481245            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]
    12511248            PanCamera
    12521249            return
     
    12701267            set _click(x) $x
    12711268            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]
    12741271            PanCamera
    12751272        }
     
    12931290itcl::body Rappture::VtkImageViewer::InitSettings { args } {
    12941291    foreach spec $args {
    1295         if { [info exists _settings($_first-$spec)] } {
     1292        if { [info exists _settings($_first${spec})] } {
    12961293            # Reset global setting with dataobj specific setting
    1297             set _settings($spec) $_settings($_first-$spec)
     1294            set _settings($spec) $_settings($_first${spec})
    12981295        }
    12991296        AdjustSetting $spec
     
    13131310    }
    13141311    switch -- $what {
    1315         "axisFlymode" {
     1312        "-axisflymode" {
    13161313            set mode [$itk_component(axisflymode) value]
    13171314            set mode [$itk_component(axisflymode) translate $mode]
     
    13191316            SendCmd "axis flymode $mode"
    13201317        }
    1321         "axisLabels" {
     1318        "-axislabels" {
    13221319            set bool $_settings($what)
    13231320            SendCmd "axis labels all $bool"
    13241321        }
    1325         "axisMinorTicks" {
     1322        "-axisminorticks" {
    13261323            set bool $_settings($what)
    13271324            SendCmd "axis minticks all $bool"
    13281325        }
    1329         "axisVisible" {
     1326        "-axisvisible" {
    13301327            set bool $_settings($what)
    13311328            SendCmd "axis visible all $bool"
    13321329        }
    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" {
    13391331            set bg [$itk_component(background) value]
    1340             array set fgcolors {
    1341                 "black" "white"
    1342                 "white" "black"
    1343                 "grey"  "black"
    1344             }
     1332            array set fgcolors {
     1333                "black" "white"
     1334                "white" "black"
     1335                "grey"  "black"
     1336            }
    13451337            set fg $fgcolors($bg)
    13461338            configure -plotbackground $bg -plotforeground $fg
    1347             $itk_component(view) delete "legend"
     1339            $itk_component(view) delete "legend"
    13481340            SendCmd "screen bgcolor [Color2RGB $bg]"
    13491341            SendCmd "outline color [Color2RGB $fg]"
    13501342            SendCmd "axis color all [Color2RGB $fg]"
    1351             DrawLegend
    1352         }
    1353         "backingColor" {
     1343            DrawLegend
     1344        }
     1345        "-backingcolor" {
    13541346            set color [$itk_component(backingcolor) value]
    1355             if { $color == "none" } {
    1356                 if { $_settings(backingVisible) } {
    1357                     SendCmd "image backing 0"
    1358                     set _settings(backingVisible) 0
    1359                 }
    1360             } else {
    1361                 if { !$_settings(backingVisible) } {
    1362                     SendCmd "image backing 1"
    1363                     set _settings(backingVisible) 1
    1364                 }
    1365                 SendCmd "image color [Color2RGB $color]"
    1366             }
    1367         }
    1368         "backingVisible" {
    1369             set bool $_settings($what)
     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)
    13701362            SendCmd "image backing $bool"
    13711363        }
    1372         "colormap" {
     1364        "-colormap" {
    13731365            set _changed($what) 1
    13741366            StartBufferingCommands
     
    13761368            set _settings($what) $color
    13771369            SetCurrentColormap $color
    1378             if {$_settings(colormapDiscrete)} {
    1379                  SendCmd "colormap res $_settings(numColors) $color"
     1370            if {$_settings(-colormapdiscrete)} {
     1371                 SendCmd "colormap res $_settings(-numcolors) $color"
    13801372            }
    13811373            StopBufferingCommands
    1382             EventuallyRequestLegend
    1383         }
    1384         "colormapDiscrete" {
     1374            EventuallyRequestLegend
     1375        }
     1376        "-colormapdiscrete" {
    13851377            set bool $_settings($what)
    13861378            StartBufferingCommands
    13871379            if {$bool} {
    1388                 SendCmd "colormap res $_settings(numColors)"
     1380                SendCmd "colormap res $_settings(-numcolors)"
    13891381            } else {
    13901382                SendCmd "colormap res default"
     
    13931385            EventuallyRequestLegend
    13941386        }
    1395         "field" {
     1387        "-field" {
    13961388            set label [$itk_component(field) value]
    13971389            set fname [$itk_component(field) translate $label]
     
    14171409            DrawLegend
    14181410        }
    1419         "view3D" {
    1420             set bool $_settings($what)
     1411        "-view3d" {
     1412            set bool $_settings($what)
    14211413            set c $itk_component(view)
    14221414            StartBufferingCommands
    14231415            # Fix image scale: 0 for contours, 1 for images.
    14241416            if { $bool } {
    1425                 set _settings(opacity) $_settings(saveOpacity)
     1417                set _settings(-opacity) $_settings(-saveopacity)
    14261418            } else {
    1427                 set _settings(opacity) 100
    1428             }
    1429             AdjustSetting opacity
    1430             if { $bool } {
    1431                 $itk_component(opacity) configure -state normal
    1432                 $itk_component(opacity_l) configure -state normal
    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)} {
    14341426                    SendCmd "camera mode ortho"
    14351427                } else {
     
    14371429                }
    14381430                SendCmd "camera aspect native"
    1439             } else {
    1440                 $itk_component(opacity) configure -state disabled
    1441                 $itk_component(opacity_l) configure -state disabled
     1431            } else {
     1432                $itk_component(opacity) configure -state disabled
     1433                $itk_component(opacity_l) configure -state disabled
    14421434                SendCmd "camera mode image"
    1443                 if {$_settings(stretchToFit)} {
     1435                if {$_settings(-stretchtofit)} {
    14441436                    SendCmd "camera aspect window"
    14451437                }
    14461438            }
    14471439            if { $bool } {
    1448                 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
     1440                set q [ViewToQuaternion]
    14491441                $_arcball quaternion $q
    1450                 SendCmd "camera orient $q" 
     1442                SendCmd "camera orient $q"
    14511443            } else {
    14521444                bind $c <ButtonPress-1> {}
     
    14551447            }
    14561448            SendCmd "camera reset"
    1457             # Fix the mouse bindings for rotation/panning and the 
     1449            # Fix the mouse bindings for rotation/panning and the
    14581450            # camera mode. Ideally we'd create a bindtag for these.
    14591451            if { $bool } {
     
    14681460            StopBufferingCommands
    14691461        }
    1470         "window" {
     1462        "-window" {
    14711463            set val $_settings($what)
    14721464            SendCmd "image window $val"
    14731465        }
    1474         "level" {
     1466        "-level" {
    14751467            set val $_settings($what)
    14761468            SendCmd "image level $val"
    14771469        }
    1478         "legendVisible" {
     1470        "-legendvisible" {
    14791471            if { !$_settings($what) } {
    1480                 $itk_component(view) delete legend
    1481             }
    1482             DrawLegend
    1483         }
    1484         "opacity" {
     1472                $itk_component(view) delete legend
     1473            }
     1474            DrawLegend
     1475        }
     1476        "-opacity" {
    14851477            set _changed($what) 1
    1486             if { $_settings(view3D) } {
    1487                 set _settings(saveOpacity) $_settings($what)
     1478            if { $_settings(-view3d) } {
     1479                set _settings(-saveopacity) $_settings($what)
    14881480                set val [expr $_settings($what) * 0.01]
    14891481                SendCmd "image opacity $val"
    14901482            } else {
    1491                 SendCmd "image opacity 1.0"
    1492             }
    1493         }
    1494         "outline" {
     1483                SendCmd "image opacity 1.0"
     1484            }
     1485        }
     1486        "-outline" {
    14951487            set bool $_settings($what)
    14961488            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 {
    15111508            error "don't know how to fix $what"
    15121509        }
     
    15181515#
    15191516#       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.
    15211518#
    15221519# This should be called when
    1523 #       1.  A new current colormap is set.
    1524 #       2.  Window is resized.
    1525 #       3.  The limits of the data have changed.  (Just need a redraw).
    1526 #       4.  Number of isolines have changed. (Just need a redraw).
    1527 #       5.  Legend becomes visible (Just need a redraw).
     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).
    15281525#
    15291526itcl::body Rappture::VtkImageViewer::RequestLegend {} {
     
    15321529    set w 12
    15331530    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
    15351532    set h [expr {$_height - 2 * ($lineht + 2)}]
    15361533    set _legendHeight $h
     
    15381535    set fname $_curFldName
    15391536    if { [string match "component*" $fname] } {
    1540         set title ""
     1537        set title ""
    15411538    } else {
    1542         if { [info exists _fields($fname)] } {
    1543             foreach { title units } $_fields($fname) break
    1544             if { $units != "" } {
    1545                 set title [format "%s (%s)" $title $units]
    1546             }
    1547         } else {
    1548             set title $fname
    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        }
    15501547    }
    15511548    # If there's a title too, substract one more line
    15521549    if { $title != "" } {
    1553         incr h -$lineht 
     1550        incr h -$lineht
    15541551    }
    15551552    if { $h < 1 } {
     
    15581555    # Set the legend on the first image dataset.
    15591556    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"
    15611559    }
    15621560}
     
    15681566    # Keep track of the colormaps that we build.
    15691567    if { $name != "none" && ![info exists _colormaps($name)] } {
    1570         BuildColormap $name 
     1568        BuildColormap $name
    15711569        set _colormaps($name) 1
    15721570    }
     
    15951593itcl::configbody Rappture::VtkImageViewer::mode {
    15961594    switch -- $itk_option(-mode) {
    1597         "volume" {
    1598             set _settings(view3D) 1
    1599         }
    1600         "vtkimage" {
    1601             set _settings(view3D) 0
    1602         }
    1603         default {
    1604             error "unknown mode settings \"$itk_option(-mode)\""
    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        }
    16061604    }
    16071605    if { !$_reset } {
    1608         AdjustSetting view3D
     1606        AdjustSetting -view3d
    16091607    }
    16101608}
     
    16191617            SendCmd "screen bgcolor $rgb"
    16201618        }
    1621         $itk_component(view) configure -background $itk_option(-plotbackground)
     1619        $itk_component(view) configure -background $itk_option(-plotbackground)
    16221620    }
    16231621}
     
    16301628        set rgb [Color2RGB $itk_option(-plotforeground)]
    16311629        if { !$_reset } {
     1630            SendCmd "axis color all $rgb"
    16321631            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    }
    16461634}
    16471635
     
    16581646    checkbutton $inner.legend \
    16591647        -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] \
    16621650        -font "Arial 9"
    16631651
    16641652    checkbutton $inner.outline \
    16651653        -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] \
    16681656        -font "Arial 9"
    16691657
    16701658    checkbutton $inner.backing \
    16711659        -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] \
    16741662        -font "Arial 9"
    16751663
    16761664    checkbutton $inner.stretch \
    16771665        -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] \
    16801668        -font "Arial 9"
    16811669
    16821670    checkbutton $inner.colormapDiscrete \
    16831671        -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] \
    16861674        -font "Arial 9"
    16871675
    16881676    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"
    16901678    } {
    16911679        ignore -font
     
    16951683    }
    16961684    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"
    17001688    itk_component add colormap {
    17011689        Rappture::Combobox $inner.colormap -width 10 -editable no
     
    17051693    $itk_component(colormap) value "BCGYR"
    17061694    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"
    17101698    itk_component add backingcolor {
    17111699        Rappture::Combobox $inner.backingcolor -width 10 -editable no
     
    17211709        "red"                "red"              \
    17221710        "white"              "white"            \
    1723         "none"               "none"
    1724 
    1725     $itk_component(backingcolor) value "white"
     1711        "none"               "none"
     1712
     1713    $itk_component(backingcolor) value $_settings(-backingcolor)
    17261714    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"
    17301718    itk_component add background {
    17311719        Rappture::Combobox $inner.background -width 10 -editable no
     
    17341722        "black"              "black"            \
    17351723        "white"              "white"            \
    1736         "grey"               "grey"             
     1724        "grey"               "grey"
    17371725
    17381726    $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]
    17401729
    17411730    itk_component add opacity_l {
     
    17461735    itk_component add opacity {
    17471736        ::scale $inner.opacity -from 0 -to 100 -orient horizontal \
    1748             -variable [itcl::scope _settings(opacity)] \
     1737            -variable [itcl::scope _settings(-opacity)] \
    17491738            -showvalue off \
    1750             -command [itcl::code $this AdjustSetting opacity]
     1739            -command [itcl::code $this AdjustSetting -opacity]
    17511740    }
    17521741
     
    17581747    itk_component add window {
    17591748        ::scale $inner.window -from 0 -to 255 -orient horizontal \
    1760             -variable [itcl::scope _settings(window)] \
     1749            -variable [itcl::scope _settings(-window)] \
    17611750            -showvalue off \
    1762             -command [itcl::code $this AdjustSetting window]
     1751            -command [itcl::code $this AdjustSetting -window]
    17631752    }
    17641753    itk_component add level_l {
     
    17691758    itk_component add level {
    17701759        ::scale $inner.level -from 0 -to 255 -orient horizontal \
    1771             -variable [itcl::scope _settings(level)] \
     1760            -variable [itcl::scope _settings(-level)] \
    17721761            -showvalue off \
    1773             -command [itcl::code $this AdjustSetting level]
     1762            -command [itcl::code $this AdjustSetting -level]
    17741763    }
    17751764
     
    17841773        2,0 $inner.backingcolor_l  -anchor w -pady 2  \
    17851774        2,1 $inner.backingcolor    -anchor w -pady 2 -fill x  \
    1786         3,0 $inner.background_l -anchor w -pady 2 \
    1787         3,1 $inner.background -anchor w -pady 2  -fill x \
     1775        3,0 $inner.background_l -anchor w -pady 2 \
     1776        3,1 $inner.background -anchor w -pady 2  -fill x \
    17881777        4,0 $inner.backing -anchor w -pady 2 -cspan 2 \
    17891778        5,0 $inner.stretch    -anchor w -pady 2 -cspan 2 \
     
    17981787        16,1 $inner.window   -fill x   -pady 2 \
    17991788        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
    18011790
    18021791    blt::table configure $inner r* c* -resize none
     
    18161805    checkbutton $inner.visible \
    18171806        -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] \
    18201809        -font "Arial 9"
    18211810    checkbutton $inner.labels \
    18221811        -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] \
    18251814        -font "Arial 9"
    1826     label $inner.grid_l -text "Grid" -font "Arial 9" 
     1815    label $inner.grid_l -text "Grid" -font "Arial 9"
    18271816    checkbutton $inner.xgrid \
    18281817        -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] \
    18311820        -font "Arial 9"
    18321821    checkbutton $inner.ygrid \
    18331822        -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] \
    18361825        -font "Arial 9"
    18371826    checkbutton $inner.zgrid \
    18381827        -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] \
    18411830        -font "Arial 9"
    18421831    checkbutton $inner.minorticks \
    18431832        -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] \
    18461835        -font "Arial 9"
    18471836
    1848     label $inner.mode_l -text "Mode" -font "Arial 9" 
     1837    label $inner.mode_l -text "Mode" -font "Arial 9"
    18491838
    18501839    itk_component add axisflymode {
     
    18551844        "closest_triad"   "closest" \
    18561845        "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]
    18601849
    18611850    blt::table $inner \
     
    18631852        1,0 $inner.labels  -anchor w -cspan 4 \
    18641853        2,0 $inner.minorticks  -anchor w -cspan 4 \
    1865         4,0 $inner.grid_l  -anchor w \
     1854        4,0 $inner.grid_l  -anchor w \
    18661855        4,1 $inner.xgrid   -anchor w \
    18671856        4,2 $inner.ygrid   -anchor w \
    18681857        4,3 $inner.zgrid   -anchor w \
    18691858        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
    18711860
    18721861    blt::table configure $inner r* c* -resize none
     
    18741863    blt::table configure $inner r3 -height 0.125i
    18751864}
    1876 
    18771865
    18781866itcl::body Rappture::VtkImageViewer::BuildCameraTab {} {
     
    18941882        0,0 $inner.view_l -anchor e -pady 2 \
    18951883        0,1 $inner.view -anchor w -pady 2
     1884    blt::table configure $inner r0 -resize none
    18961885
    18971886    set labels { qx qy qz qw xpan ypan zoom }
     
    19001889        label $inner.${tag}label -text $tag -font "Arial 9"
    19011890        entry $inner.${tag} -font "Arial 9"  -bg white \
    1902             -textvariable [itcl::scope _view($tag)]
     1891            -textvariable [itcl::scope _view(-$tag)]
    19031892        bind $inner.${tag} <Return> \
    1904             [itcl::code $this camera set ${tag}]
     1893            [itcl::code $this camera set -${tag}]
    19051894        bind $inner.${tag} <KP_Enter> \
    1906             [itcl::code $this camera set ${tag}]
     1895            [itcl::code $this camera set -${tag}]
    19071896        blt::table $inner \
    19081897            $row,0 $inner.${tag}label -anchor e -pady 2 \
     
    19131902    checkbutton $inner.ortho \
    19141903        -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] \
    19171906        -font "Arial 9"
    19181907    blt::table $inner \
     
    19211910    incr row
    19221911
    1923     blt::table configure $inner c* r* -resize none
     1912    blt::table configure $inner c* -resize none
    19241913    blt::table configure $inner c2 -resize expand
    19251914    blt::table configure $inner r$row -resize expand
     
    19271916
    19281917#
    1929 #  camera -- 
     1918#  camera --
    19301919#
    19311920itcl::body Rappture::VtkImageViewer::camera {option args} {
    1932     switch -- $option { 
     1921    switch -- $option {
    19331922        "show" {
    19341923            puts [array get _view]
    19351924        }
    19361925        "set" {
    1937             set who [lindex $args 0]
    1938             set x $_view($who)
     1926            set what [lindex $args 0]
     1927            set x $_view($what)
    19391928            set code [catch { string is double $x } result]
    19401929            if { $code != 0 || !$result } {
    19411930                return
    19421931            }
    1943             switch -- $who {
    1944                 "ortho" {
    1945                     if {$_view(ortho)} {
     1932            switch -- $what {
     1933                "-ortho" {
     1934                    if {$_view($what)} {
    19461935                        SendCmd "camera mode ortho"
    19471936                    } else {
     
    19491938                    }
    19501939                }
    1951                 "xpan" - "ypan" {
     1940                "-xpan" - "-ypan" {
    19521941                    PanCamera
    19531942                }
    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]
    19561945                    $_arcball quaternion $q
    19571946                    EventuallyRotate $q
    19581947                }
    1959                 "zoom" {
    1960                     SendCmd "camera zoom $_view(zoom)"
     1948                "-zoom" {
     1949                    SendCmd "camera zoom $_view($what)"
    19611950                }
    19621951            }
     
    19781967
    19791968itcl::body Rappture::VtkImageViewer::GetImage { args } {
    1980     if { [image width $_image(download)] > 0 && 
     1969    if { [image width $_image(download)] > 0 &&
    19811970         [image height $_image(download)] > 0 } {
    19821971        set bytes [$_image(download) data -format "jpeg -quality 100"]
     
    19911980        -title "[Rappture::filexfer::label downloadWord] as..."
    19921981    set inner [$popup component inner]
    1993     label $inner.summary -text "" -anchor w 
     1982    label $inner.summary -text "" -anchor w
    19941983    radiobutton $inner.vtk_button -text "VTK data file" \
    19951984        -variable [itcl::scope _downloadPopup(format)] \
    19961985        -font "Arial 9 " \
    1997         -value vtk 
     1986        -value vtk
    19981987    Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file."
    19991988    radiobutton $inner.image_button -text "Image File" \
    20001989        -variable [itcl::scope _downloadPopup(format)] \
    20011990        -font "Arial 9 " \
    2002         -value image 
     1991        -value image
    20031992    Rappture::Tooltip::for $inner.image_button \
    20041993        "Save as digital image."
     
    20212010        2,0 $inner.image_button -anchor w -cspan 2 -padx { 4 0 } \
    20222011        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
    20242013    blt::table configure $inner r3 -height 4
    20252014    blt::table configure $inner r4 -pady 4
     
    20322021# SetObjectStyle --
    20332022#
    2034 #       Set the style of the image/contour object.  This gets calls 
     2023#       Set the style of the image/contour object.  This gets calls
    20352024#       for each dataset once as it is loaded.  It can overridden by
    20362025#       the user controls.
     
    20572046    # the code to handle aberrant cases.
    20582047
    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)
    20642053    }
    20652054    if { $_currentColormap == "" } {
     
    20672056    }
    20682057    if { [info exists style(-stretchtofit)] } {
    2069         set _settings(stretchToFit) $style(-stretchtofit)
    2070         AdjustSetting stretchToFit
     2058        set _settings(-stretchtofit) $style(-stretchtofit)
     2059        AdjustSetting -stretchToFit
    20712060    }
    20722061    SendCmd "outline add $tag"
    20732062    SendCmd "outline color [Color2RGB $itk_option(-plotforeground)] $tag"
    2074     SendCmd "outline visible $_settings(outline) $tag"
     2063    SendCmd "outline visible $_settings(-outline) $tag"
    20752064    SendCmd "image add $tag"
    2076     SetCurrentColormap $style(-color) 
     2065    SetCurrentColormap $style(-color)
    20772066    set color [$itk_component(backingcolor) value]
    20782067    SendCmd "image color [Color2RGB $color] $tag"
    20792068    SendCmd "image opacity $style(-opacity) $tag"
    2080     set _settings(opacity) [expr $style(-opacity) * 100.0]
     2069    set _settings(-opacity) [expr $style(-opacity) * 100.0]
    20812070}
    20822071
     
    21052094        #puts stderr "read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>"
    21062095        if { [catch {DrawLegend} errs] != 0 } {
    2107             global errorInfo
    2108             puts stderr "errs=$errs errorInfo=$errorInfo"
     2096            global errorInfo
     2097            puts stderr "errs=$errs errorInfo=$errorInfo"
    21092098        }
    21102099    }
     
    21232112    set font "Arial 8"
    21242113    set lineht [font metrics $font -linespace]
    2125    
     2114
    21262115    if { [string match "component*" $fname] } {
    2127         set title ""
     2116        set title ""
    21282117    } else {
    2129         if { [info exists _fields($fname)] } {
    2130             foreach { title units } $_fields($fname) break
    2131             if { $units != "" } {
    2132                 set title [format "%s (%s)" $title $units]
    2133             }
    2134         } else {
    2135             set title $fname
    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        }
    21372126    }
    21382127    set x [expr $w - 2]
    2139     if { !$_settings(legendVisible) } {
    2140         $c delete legend
    2141         return
    2142     } 
     2128    if { !$_settings(-legendvisible) } {
     2129        $c delete legend
     2130        return
     2131    }
    21432132    if { [$c find withtag "legend"] == "" } {
    2144         set y 2
    2145         # If there's a legend title, create a text item for the title.
     2133        set y 2
     2134        # If there's a legend title, create a text item for the title.
    21462135        $c create text $x $y \
    2147             -anchor ne \
    2148             -fill $itk_option(-plotforeground) -tags "title legend" \
    2149             -font $font
     2136            -anchor ne \
     2137            -fill $itk_option(-plotforeground) -tags "title legend" \
     2138            -font $font
    21502139        if { $title != "" } {
    21512140            incr y $lineht
    21522141        }
    2153         $c create text $x $y \
    2154             -anchor ne \
    2155             -fill $itk_option(-plotforeground) -tags "vmax legend" \
    2156             -font $font
    2157         incr y $lineht
    2158         $c create image $x $y \
    2159             -anchor ne \
    2160             -image $_image(legend) -tags "colormap legend"
    2161         $c create rectangle $x $y 1 1 \
    2162             -fill "" -outline "" -tags "sensor legend"
    2163         $c create text $x [expr {$h-2}] \
    2164             -anchor se \
    2165             -fill $itk_option(-plotforeground) -tags "vmin legend" \
    2166             -font $font
    2167         $c bind sensor <Enter> [itcl::code $this EnterLegend %x %y]
    2168         $c bind sensor <Leave> [itcl::code $this LeaveLegend]
    2169         $c bind sensor <Motion> [itcl::code $this MotionLegend %x %y]
     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]
    21702159    }
    21712160
     
    21812170    if { [info exists _limits($_curFldName)] } {
    21822171        foreach { vmin vmax } $_limits($_curFldName) break
    2183         $c itemconfigure vmin -text [format %g $vmin]
    2184         $c itemconfigure vmax -text [format %g $vmax]
     2172        $c itemconfigure vmin -text [format %g $vmin]
     2173        $c itemconfigure vmax -text [format %g $vmax]
    21852174    }
    21862175    set y 2
     
    21882177    if { $title != "" } {
    21892178        $c itemconfigure title -text $title
    2190         $c coords title $x $y
    2191         incr y $lineht
     2179        $c coords title $x $y
     2180        incr y $lineht
    21922181    }
    21932182    $c coords vmax $x $y
     
    22372226    set font "Arial 8"
    22382227    set lineht [font metrics $font -linespace]
    2239    
     2228
    22402229    set ih [image height $_image(legend)]
    22412230    # Subtract off the offset of the color ramp from the top of the canvas
     
    22432232
    22442233    if { [string match "component*" $fname] } {
    2245         set title ""
     2234        set title ""
    22462235    } else {
    2247         if { [info exists _fields($fname)] } {
    2248             foreach { title units } $_fields($fname) break
    2249             if { $units != "" } {
    2250                 set title [format "%s (%s)" $title $units]
    2251             }
    2252         } else {
    2253             set title $fname
    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        }
    22552244    }
    22562245    # If there's a legend title, increase the offset by the line height.
     
    22682257    }
    22692258    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
    22722261
    22732262    # Compute the value of the point
     
    22792268        set value 0.0
    22802269    }
    2281     set tipx [expr $x + 15] 
     2270    set tipx [expr $x + 15]
    22822271    set tipy [expr $y - 5]
    22832272    .rappturetooltip configure -icon $_image(swatch)
     
    22872276        Rappture::Tooltip::text $c [format "$title %g" $value]
    22882277    }
    2289     Rappture::Tooltip::tooltip show $c +$tipx,+$tipy   
     2278    Rappture::Tooltip::tooltip show $c +$tipx,+$tipy
    22902279}
    22912280
     
    23022291# ----------------------------------------------------------------------
    23032292itcl::body Rappture::VtkImageViewer::Combo {option} {
    2304     set c $itk_component(view) 
     2293    set c $itk_component(view)
    23052294    switch -- $option {
    23062295        post {
     
    23152304        }
    23162305        deactivate {
    2317             $c itemconfigure title -fill $itk_option(-plotforeground) 
     2306            $c itemconfigure title -fill $itk_option(-plotforeground)
    23182307        }
    23192308        invoke {
    23202309            $itk_component(field) value $_curFldLabel
    2321             AdjustSetting field
     2310            AdjustSetting -field
    23222311        }
    23232312        default {
     
    23272316}
    23282317
    2329 itcl::body Rappture::VtkImageViewer::SetOrientation { side } { 
     2318itcl::body Rappture::VtkImageViewer::SetOrientation { side } {
    23302319    array set positions {
    23312320        front  "0.707107 0.707107 0 0"
     
    23362325        bottom "0 1 0 0"
    23372326    }
    2338     foreach name { qw qx qy qz } value $positions($side) {
     2327    foreach name { -qw -qx -qy -qz } value $positions($side) {
    23392328        set _view($name) $value
    2340     } 
    2341     set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
     2329    }
     2330    set q [ViewToQuaternion]
    23422331    $_arcball quaternion $q
    23432332    SendCmd "camera orient $q"
    23442333    SendCmd "camera reset"
    2345     set _view(xpan) 0
    2346     set _view(ypan) 0
    2347     set _view(zoom) 1.0
    2348 }
     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 -*-
    22# ----------------------------------------------------------------------
    33#  COMPONENT: vtkisosurfaceviewer - Vtk 3D contour object viewer
     
    77# ======================================================================
    88#  AUTHOR:  Michael McLennan, Purdue University
    9 #  Copyright (c) 2004-2005  Purdue Research Foundation
     9#  Copyright (c) 2004-2014  HUBzero Foundation, LLC
    1010#
    1111#  See the file "license.terms" for information on usage and
     
    5757    public method get {args}
    5858    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
    6261    }
    6362    public method scale {args}
    6463
    6564    # The following methods are only used by this class.
    66 
    6765    private method AdjustSetting {what {value ""}}
    6866    private method BuildAxisTab {}
     
    7068    private method BuildColormap { name }
    7169    private method BuildCutplaneTab {}
    72     private method BuildDownloadPopup { widget command } 
     70    private method BuildDownloadPopup { widget command }
    7371    private method BuildIsosurfaceTab {}
    74     private method Combo { option }
    7572    private method Connect {}
    7673    private method CurrentDatasets {args}
     74    private method DisableMouseRotationBindings {}
    7775    private method Disconnect {}
    7876    private method DoChangeContourLevels {}
     
    8078    private method DoRotate {}
    8179    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 }
    8886    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 }
    9391    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 {}
    95100    private method Pan {option x y}
    96101    private method PanCamera {}
    97102    private method Pick {x y}
     103    private method QuaternionToView { q } {
     104        foreach { _view(-qw) _view(-qx) _view(-qy) _view(-qz) } $q break
     105    }
    98106    private method Rebuild {}
    99107    private method ReceiveDataset { args }
     
    103111    private method Rotate {option x y}
    104112    private method SetCurrentColormap { color }
     113    private method SetCurrentFieldName { dataobj }
    105114    private method SetLegendTip { x y }
    106     private method SetObjectStyle { dataobj comp }
    107     private method SetCurrentFieldName { dataobj }
     115    private method SetMinMaxGauges { min max }
     116    private method SetObjectStyle { dataobj comp }
    108117    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    }
    110126    private method Zoom {option}
    111     private method ViewToQuaternion {} {
    112         return [list $_view(-qw) $_view(-qx) $_view(-qy) $_view(-qz)]
    113     }
    114127
    115128    private variable _arcball ""
     
    118131    private variable _obj2datasets
    119132    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
    121134                                   ;    # datasets in the server
    122135    private variable _colormaps    ;    # contains all the colormaps
     
    156169    private variable _legendPending 0
    157170    private variable _field      ""
    158     private variable _colorMode "scalar";       #  Mode of colormap (vmag or 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
    161174    private variable _curFldName ""
    162175    private variable _curFldLabel ""
     176
     177    private variable _mouseOver "";     # what called LegendRangeAction, vmin or vmax
     178    private variable _customRangeClick 1;   # what called ToggleCustomRange
    163179}
    164180
     
    227243        -xpan            0
    228244        -ypan            0
    229         -zoom            1.0 
     245        -zoom            1.0
    230246    }
    231247    set _arcball [blt::arcball create 100 100]
     
    239255    }
    240256    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
    272292    }
    273293    array set _changed {
    274294        -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
    275303        -isosurfaceopacity       0
    276         -cutplaneopacity         0
     304        -isosurfacevisible       0
     305        -isosurfacewireframe     0
    277306        -numcontours             0
     307        -outline                 0
     308        -xcutplaneposition       0
     309        -xcutplanevisible        0
     310        -ycutplaneposition       0
     311        -ycutplanevisible        0
     312        -zcutplaneposition       0
     313        -zcutplanevisible        0
    278314    }
    279315    array set _widget {
     
    292328    itk_component add fieldmenu {
    293329        menu $itk_component(plotarea).menu -bg black -fg white -relief flat \
    294             -tearoff 0 
     330            -tearoff 0
    295331    } {
    296332        usual
    297333        ignore -background -foreground -relief -tearoff
    298334    }
     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
    299344    set c $itk_component(view)
    300345    bind $c <Configure> [itcl::code $this EventuallyResize %w %h]
     
    312357
    313358    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
    316361    set _map(zoom) 1.0
    317362    set _map(original) ""
     
    360405            -offimage [Rappture::icon volume-off] \
    361406            -variable [itcl::scope _settings(-isosurfacevisible)] \
    362             -command [itcl::code $this AdjustSetting -isosurfacevisible] 
     407            -command [itcl::code $this AdjustSetting -isosurfacevisible]
    363408    }
    364409    $itk_component(contour) select
     
    372417            -offimage [Rappture::icon cutbutton] \
    373418            -variable [itcl::scope _settings(-cutplanesvisible)] \
    374             -command [itcl::code $this AdjustSetting -cutplanesvisible] 
     419            -command [itcl::code $this AdjustSetting -cutplanesvisible]
    375420    }
    376421    Rappture::Tooltip::for $itk_component(cutplane) \
     
    387432        puts stderr errs=$errs
    388433    }
     434
    389435    # Legend
    390 
    391436    set _image(legend) [image create photo]
    392437    itk_component add legend {
    393         canvas $itk_component(plotarea).legend -width 50 -highlightthickness 0 
     438        canvas $itk_component(plotarea).legend -width 50 -highlightthickness 0
    394439    } {
    395440        usual
     
    398443    }
    399444
    400     # Hack around the Tk panewindow.  The problem is that the requested 
     445    # Hack around the Tk panewindow.  The problem is that the requested
    401446    # size of the 3d view isn't set until an image is retrieved from
    402447    # the server.  So the panewindow uses the tiny size.
     
    404449    pack forget $itk_component(view)
    405450    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
    407452    blt::table configure $itk_component(plotarea) c1 -resize none
    408453
     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# ----------------------------------------------------------------------
     485itcl::body Rappture::VtkIsosurfaceViewer::destructor {} {
     486    Disconnect
     487    image delete $_image(plot)
     488    image delete $_image(download)
     489    catch { blt::arcball destroy $_arcball }
     490}
     491
     492itcl::body Rappture::VtkIsosurfaceViewer::SetupMouseRotationBindings {} {
    409493    # Bindings for rotation via mouse
    410494    bind $itk_component(view) <ButtonPress-1> \
     
    414498    bind $itk_component(view) <ButtonRelease-1> \
    415499        [itcl::code $this Rotate release %x %y]
    416 
     500}
     501
     502itcl::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
     509itcl::body Rappture::VtkIsosurfaceViewer::SetupMousePanningBindings {} {
    417510    # Bindings for panning via mouse
    418511    bind $itk_component(view) <ButtonPress-2> \
     
    422515    bind $itk_component(view) <ButtonRelease-2> \
    423516        [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
     519itcl::body Rappture::VtkIsosurfaceViewer::SetupKeyboardBindings {} {
    428520    # Bindings for panning via keyboard
    429521    bind $itk_component(view) <KeyPress-Left> \
     
    451543
    452544    bind $itk_component(view) <Enter> "focus $itk_component(view)"
    453 
    454     if {[string equal "x11" [tk windowingsystem]]} {
    455         # Bindings for zoom via mouse
    456         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 $args
    463 
    464     EnableWaitDialog 500
    465     Connect
    466 }
    467 
    468 # ----------------------------------------------------------------------
    469 # DESTRUCTOR
    470 # ----------------------------------------------------------------------
    471 itcl::body Rappture::VtkIsosurfaceViewer::destructor {} {
    472     Disconnect
    473     image delete $_image(plot)
    474     image delete $_image(download)
    475     catch { blt::arcball destroy $_arcball }
    476545}
    477546
     
    499568
    500569itcl::body Rappture::VtkIsosurfaceViewer::DoRotate {} {
    501     SendCmd "camera orient [ViewToQuaternion]" 
     570    SendCmd "camera orient [ViewToQuaternion]"
    502571    set _rotatePending 0
    503572}
     
    523592
    524593itcl::body Rappture::VtkIsosurfaceViewer::EventuallyRotate { q } {
    525     foreach { _view(-qw) _view(-qx) _view(-qy) _view(-qz) } $q break
     594    QuaternionToView $q
    526595    if { !$_rotatePending } {
    527596        set _rotatePending 1
    528         global rotate_delay 
     597        global rotate_delay
    529598        $_dispatcher event -after $rotate_delay !rotate
    530599    }
     
    543612    if { !$_contourList(updatePending) } {
    544613        set _contourList(updatePending) 1
    545         global rotate_delay 
     614        global rotate_delay
    546615        $_dispatcher event -after $rotate_delay !contours
    547616    }
     
    588657}
    589658
    590 
    591659# ----------------------------------------------------------------------
    592660# USAGE: delete ?<dataobj1> <dataobj2> ...?
     
    643711                    continue
    644712                }
    645                 if {[info exists _obj2ovride($dataobj-raise)] && 
     713                if {[info exists _obj2ovride($dataobj-raise)] &&
    646714                    $_obj2ovride($dataobj-raise)} {
    647715                    set dlist [linsert $dlist 0 $dataobj]
     
    671739            }
    672740            return $dlist
    673         }           
     741        }
    674742        -image {
    675743            if {[llength $args] != 2} {
     
    724792            if { ![info exists _limits($fname)] } {
    725793                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
    726802                continue
    727803            }
    728804            foreach {min max} $lim break
    729805            foreach {fmin fmax} $_limits($fname) break
     806            if { ! $_settings(-customrange) } {
     807                SetMinMaxGauges $fmin $fmax
     808            }
    730809            if { $fmin > $min } {
    731810                set fmin $min
     
    900979    if { $info(-type) == "image" } {
    901980        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
    904984            close $f
    905985        }
     
    909989        #set w [image width $_image(plot)]
    910990        #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"
    912992        if { $_start > 0 } {
    913993            set finish [clock clicks -milliseconds]
     
    9801060    # Turn on buffering of commands to the server.  We don't want to
    9811061    # be preempted by a server disconnect/reconnect (which automatically
    982     # generates a new call to Rebuild).   
     1062    # generates a new call to Rebuild).
    9831063    StartBufferingCommands
     1064
    9841065    if { $_reset } {
    9851066        set _width $w
     
    9901071        # Reset the camera and other view parameters
    9911072        $_arcball quaternion [ViewToQuaternion]
     1073        InitSettings -ortho
    9921074        DoRotate
    9931075        PanCamera
    9941076        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"
    10001081        StopBufferingCommands
    10011082        SendCmd "imgflush"
     
    10151096            if { ![info exists _datasets($tag)] } {
    10161097                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
    10211103                }
    10221104                set length [string length $bytes]
    10231105                if { $_reportClientInfo }  {
    10241106                    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]
    10291112                    lappend info "dataset_label" [$dataobj hints label]
    10301113                    lappend info "dataset_size"  $length
     
    10391122            lappend _obj2datasets($dataobj) $tag
    10401123            if { [info exists _obj2ovride($dataobj-raise)] } {
    1041                 SendCmd "contour3d visible 1 $tag"
     1124                SendCmd "contour3d visible 1 $tag"
    10421125            }
    10431126        }
     
    10461129    InitSettings -cutplanesvisible -isosurfacevisible -outline
    10471130    if { $_reset } {
    1048         # These are settings that rely on a dataset being loaded.
     1131        # These are settings that rely on a dataset being loaded.
    10491132        InitSettings \
    10501133            -isosurfacelighting \
    10511134            -field \
     1135            -range \
    10521136            -isosurfacevisible \
    10531137            -isosurfaceedges -isosurfacelighting -isosurfaceopacity \
    1054             -isosurfacewireframe \
     1138            -isosurfacewireframe \
    10551139            -cutplanesvisible \
    1056             -xcutplaneposition -ycutplaneposition -zcutplaneposition \
    1057             -xcutplanevisible -ycutplanevisible -zcutplanevisible \
     1140            -xcutplaneposition -ycutplaneposition -zcutplaneposition \
     1141            -xcutplanevisible -ycutplanevisible -zcutplanevisible \
    10581142            -cutplanepreinterp -numcontours
    10591143
    10601144        Zoom reset
    1061         foreach axis { x y z } {
     1145        foreach axis { x y z } {
    10621146            # Another problem fixed by a <view>. We looking into a data
    10631147            # object for the name of the axes. This should be global to
    10641148            # the viewer itself.
    1065             set label [$_first hints ${axis}label]
    1066             if { $label == "" } {
     1149            set label [$_first hints ${axis}label]
     1150            if { $label == "" } {
    10671151                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]
    10701155        }
    10711156        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)}
    10751158        }
    10761159        set _reset 0
     
    10961179itcl::body Rappture::VtkIsosurfaceViewer::CurrentDatasets {args} {
    10971180    set flag [lindex $args 0]
    1098     switch -- $flag { 
     1181    switch -- $flag {
    10991182        "-all" {
    11001183            if { [llength $args] > 1 } {
     
    11151198                set dlist [get -visible]
    11161199            }
    1117         }           
     1200        }
    11181201        default {
    11191202            set dlist $args
     
    11521235        "reset" {
    11531236            array set _view {
    1154                 -qw     0.853553
    1155                 -qx     -0.353553
    1156                 -qy     0.353553
    1157                 -qz     0.146447
    1158                 -xpan   0
    1159                 -ypan   0
    1160                 -zoom   1.0
     1237                -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
    11611244            }
    11621245            if { $_first != "" } {
     
    11781261    SendCmd "camera pan $x $y"
    11791262}
    1180 
    11811263
    11821264# ----------------------------------------------------------------------
     
    12341316itcl::body Rappture::VtkIsosurfaceViewer::Pick {x y} {
    12351317    foreach tag [CurrentDatasets -visible] {
    1236         SendCmdNoSplash "dataset getscalar pixel $x $y $tag"
    1237     } 
     1318        SendCmd "dataset getscalar pixel $x $y $tag"
     1319    }
    12381320}
    12391321
     
    13231405            SendCmd "axis visible all $bool"
    13241406        }
    1325         "-axislabelsvisible" {
     1407        "-axislabels" {
    13261408            set bool $_settings($what)
    13271409            SendCmd "axis labels all $bool"
     1410        }
     1411        "-axisminorticks" {
     1412            set bool $_settings($what)
     1413            SendCmd "axis minticks all $bool"
    13281414        }
    13291415        "-axismode" {
     
    13351421        "-background" {
    13361422            set bgcolor [$itk_component(background) value]
    1337             array set fgcolors {
    1338                 "black" "white"
    1339                 "white" "black"
    1340                 "grey"  "black"
    1341             }
     1423            array set fgcolors {
     1424                "black" "white"
     1425                "white" "black"
     1426                "grey"  "black"
     1427            }
    13421428            configure -plotbackground $bgcolor \
    1343                 -plotforeground $fgcolors($bgcolor)
    1344             $itk_component(view) delete "legend"
    1345             DrawLegend
     1429                -plotforeground $fgcolors($bgcolor)
     1430            $itk_component(view) delete "legend"
     1431            DrawLegend
    13461432        }
    13471433        "-cutplaneedges" {
     1434            set _changed($what) 1
    13481435            set bool $_settings($what)
    13491436            SendCmd "cutplane edges $bool"
    13501437        }
    13511438        "-cutplanelighting" {
     1439            set _changed($what) 1
    13521440            set bool $_settings($what)
    13531441            SendCmd "cutplane lighting $bool"
    13541442        }
    13551443        "-cutplaneopacity" {
     1444            set _changed($what) 1
    13561445            set _settings($what) [expr $_widget($what) * 0.01]
    13571446            SendCmd "cutplane opacity $_settings($what)"
    13581447        }
    13591448        "-cutplanepreinterp" {
     1449            set _changed($what) 1
    13601450            set bool $_settings($what)
    13611451            SendCmd "cutplane preinterp $bool"
    13621452        }
    13631453        "-cutplanesvisible" {
     1454            set _changed($what) 1
    13641455            set bool $_settings($what)
    1365             SendCmd "cutplane visible 0"
     1456            SendCmd "cutplane visible 0"
    13661457            if { $bool } {
    13671458                foreach tag [CurrentDatasets -visible] {
     
    13781469        }
    13791470        "-cutplanewireframe" {
     1471            set _changed($what) 1
    13801472            set bool $_settings($what)
    13811473            SendCmd "cutplane wireframe $bool"
     
    13861478            set color [$itk_component(colormap) value]
    13871479            set _settings($what) $color
    1388             if { $color == "none" } {
    1389                 if { $_settings(-colormapvisible) } {
    1390                     SendCmd "contour3d colormode constant {}"
    1391                     set _settings(-colormapvisible) 0
    1392                 }
    1393             } else {
    1394                 if { !$_settings(-colormapvisible) } {
    1395                     SendCmd "contour3d colormode $_colorMode $_curFldName"
    1396                     set _settings(-colormapvisible) 1
    1397                 }
    1398                 SetCurrentColormap $color
    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            }
    14001492            StopBufferingCommands
    1401             EventuallyRequestLegend
     1493            EventuallyRequestLegend
    14021494        }
    14031495        "-field" {
     
    14221514                SendCmd "dataset maprange all"
    14231515            } 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"
    14251527            }
    14261528            SendCmd "cutplane colormode $_colorMode $_curFldName"
     
    14321534        "-isolinecolor" {
    14331535            set color [$itk_component(isolineColor) value]
    1434             set _settings($what) $color
    1435             DrawLegend
     1536            set _settings($what) $color
     1537            DrawLegend
    14361538        }
    14371539        "-isosurfaceedges" {
     1540            set _changed($what) 1
    14381541            set bool $_settings($what)
    1439             SendCmd "contour3d edges $bool"
     1542            SendCmd "contour3d edges $bool"
    14401543        }
    14411544        "-isosurfacelighting" {
     1545            set _changed($what) 1
    14421546            set bool $_settings($what)
    1443             SendCmd "contour3d lighting $bool"
     1547            SendCmd "contour3d lighting $bool"
    14441548        }
    14451549        "-isosurfaceopacity" {
     1550            set _changed($what) 1
    14461551            set _settings($what) [expr $_widget($what) * 0.01]
    1447             SendCmd "contour3d opacity $_settings($what)"
     1552            SendCmd "contour3d opacity $_settings($what)"
    14481553        }
    14491554        "-isosurfacevisible" {
     1555            set _changed($what) 1
    14501556            set bool $_settings($what)
    1451             SendCmd "contour3d visible 0"
     1557            SendCmd "contour3d visible 0"
    14521558            if { $bool } {
    14531559                foreach tag [CurrentDatasets -visible] {
     
    14641570        }
    14651571        "-isosurfacewireframe" {
     1572            set _changed($what) 1
    14661573            set bool $_settings($what)
    1467             SendCmd "contour3d wireframe $bool"
     1574            SendCmd "contour3d wireframe $bool"
    14681575        }
    14691576        "-legendvisible" {
    14701577            if { !$_settings($what) } {
    14711578                $itk_component(view) delete legend
    1472             }
    1473             DrawLegend
     1579            }
     1580            DrawLegend
    14741581        }
    14751582        "-numcontours" {
     1583            set _changed($what) 1
    14761584            set _settings($what) [$itk_component(numcontours) value]
    14771585            if { $_contourList(numLevels) != $_settings($what) } {
     
    14891597        }
    14901598        "-outline" {
     1599            set _changed($what) 1
    14911600            set bool $_settings($what)
    1492             SendCmd "outline visible 0"
     1601            SendCmd "outline visible 0"
    14931602            if { $bool } {
    14941603                foreach tag [CurrentDatasets -visible] {
     
    14971606            }
    14981607        }
     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        }
    14991620        "-xcutplanevisible" - "-ycutplanevisible" - "-zcutplanevisible" {
     1621            set _changed($what) 1
    15001622            set axis [string tolower [string range $what 1 1]]
    15011623            set bool $_settings($what)
     
    15071629                    -troughcolor grey82
    15081630            }
    1509             SendCmd "cutplane axis $axis $bool"
     1631            SendCmd "cutplane axis $axis $bool"
    15101632        }
    15111633        "-xcutplaneposition" - "-ycutplaneposition" - "-zcutplaneposition" {
     1634            set _changed($what) 1
    15121635            set axis [string tolower [string range $what 1 1]]
    15131636            set pos [expr $_settings($what) * 0.01]
     
    15261649}
    15271650
    1528 
    15291651#
    15301652# RequestLegend --
    15311653#
    15321654#       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.
    15341656#
    15351657# This should be called when
    1536 #       1.  A new current colormap is set.
    1537 #       2.  Window is resized.
    1538 #       3.  The limits of the data have changed.  (Just need a redraw).
    1539 #       4.  Number of isolines have changed. (Just need a redraw).
    1540 #       5.  Legend becomes visible (Just need a redraw).
     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).
    15411663#
    15421664itcl::body Rappture::VtkIsosurfaceViewer::RequestLegend {} {
     
    15541676    }
    15551677    if { [string match "component*" $fname] } {
    1556         set title ""
     1678        set title ""
    15571679    } else {
    1558         if { [info exists _fields($fname)] } {
    1559             foreach { title units } $_fields($fname) break
    1560             if { $units != "" } {
    1561                 set title [format "%s (%s)" $title $units]
    1562             }
    1563         } else {
    1564             set title $fname
    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        }
    15661688    }
    15671689    # If there's a title too, subtract one more line
    15681690    if { $title != "" } {
    1569         incr h -$lineht 
    1570     }
    1571     # Set the legend on the first heightmap dataset.
     1691        incr h -$lineht
     1692    }
     1693    # Set the legend on the first isosurface dataset.
    15721694    if { $_currentColormap != ""  } {
    1573         set cmap $_currentColormap
    1574         SendCmdNoWait "legend $cmap scalar $_curFldName {} $w $h 0"
     1695        set cmap $_currentColormap
     1696        SendCmdNoWait "legend $cmap scalar $_curFldName {} $w $h 0"
    15751697    }
    15761698}
     
    15921714    if { [isconnected] } {
    15931715        set rgb [Color2RGB $itk_option(-plotforeground)]
    1594         SendCmd "axis color all $rgb"
     1716        SendCmd "axis color all $rgb"
    15951717        SendCmd "outline color $rgb"
    15961718        SendCmd "cutplane color $rgb"
    15971719    }
    1598 }
    1599 
    1600 itcl::body Rappture::VtkIsosurfaceViewer::limits { dataobj } {
    1601     foreach { limits(xmin) limits(xmax) } [$dataobj limits x] break
    1602     foreach { limits(ymin) limits(ymax) } [$dataobj limits y] break
    1603     foreach { limits(zmin) limits(zmax) } [$dataobj limits z] break
    1604     foreach { limits(vmin) limits(vmax) } [$dataobj limits v] break
    1605     return [array get limits]
    16061720}
    16071721
     
    16521766        -font "Arial 9"
    16531767
    1654     label $inner.linecolor_l -text "Isolines" -font "Arial 9" 
     1768    label $inner.linecolor_l -text "Isolines" -font "Arial 9"
    16551769    itk_component add isolineColor {
    16561770        Rappture::Combobox $inner.linecolor -width 10 -editable 0
     
    16661780        "red"                "red"              \
    16671781        "white"              "white"            \
    1668         "none"               "none"
     1782        "none"               "none"
    16691783
    16701784    $itk_component(isolineColor) value "white"
    16711785    bind $inner.linecolor <<Value>> \
    1672         [itcl::code $this AdjustSetting -isolinecolor]
    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"
    16751789    itk_component add background {
    16761790        Rappture::Combobox $inner.background -width 10 -editable 0
     
    16791793        "black"              "black"            \
    16801794        "white"              "white"            \
    1681         "grey"               "grey"             
     1795        "grey"               "grey"
    16821796
    16831797    $itk_component(background) value $_settings(-background)
     
    16911805        -showvalue off \
    16921806        -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]
    16951808
    16961809    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"
    16981811    } {
    16991812        ignore -font
     
    17051818        [itcl::code $this AdjustSetting -field]
    17061819
    1707     label $inner.colormap_l -text "Colormap" -font "Arial 9" 
     1820    label $inner.colormap_l -text "Colormap" -font "Arial 9"
    17081821    itk_component add colormap {
    17091822        Rappture::Combobox $inner.colormap -width 10 -editable 0
     
    17231836    bind $itk_component(numcontours) <<Value>> \
    17241837        [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
    17251873
    17261874    blt::table $inner \
     
    17311879        2,0 $inner.linecolor_l  -anchor w -pady 2  \
    17321880        2,1 $inner.linecolor    -anchor w -pady 2 -fill x  \
    1733         3,0 $inner.background_l -anchor w -pady 2 \
    1734         3,1 $inner.background -anchor w -pady 2  -fill x \
     1881        3,0 $inner.background_l -anchor w -pady 2 \
     1882        3,1 $inner.background -anchor w -pady 2  -fill x \
    17351883        4,0 $inner.numcontours_l -anchor w -pady 2 \
    17361884        4,1 $inner.numcontours -anchor w -pady 2 \
     
    17421890        10,0 $inner.opacity_l -anchor w -pady 2 \
    17431891        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 \
    17441897
    17451898    blt::table configure $inner r* c* -resize none
    1746     blt::table configure $inner r11 c1 -resize expand
     1899    blt::table configure $inner r14 c1 -resize expand
    17471900}
    17481901
     
    17581911
    17591912    checkbutton $inner.visible \
    1760         -text "Show Axes" \
     1913        -text "Axes" \
    17611914        -variable [itcl::scope _settings(-axesvisible)] \
    17621915        -command [itcl::code $this AdjustSetting -axesvisible] \
     
    17641917
    17651918    checkbutton $inner.labels \
    1766         -text "Show Axis Labels" \
    1767         -variable [itcl::scope _settings(-axislabelsvisible)] \
    1768         -command [itcl::code $this AdjustSetting -axislabelsvisible] \
     1919        -text "Axis Labels" \
     1920        -variable [itcl::scope _settings(-axislabels)] \
     1921        -command [itcl::code $this AdjustSetting -axislabels] \
    17691922        -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" \
    17731926        -variable [itcl::scope _settings(-xgrid)] \
    17741927        -command [itcl::code $this AdjustSetting -xgrid] \
    17751928        -font "Arial 9"
    1776     checkbutton $inner.gridy \
    1777         -text "Show Y Grid" \
     1929    checkbutton $inner.ygrid \
     1930        -text "Y" \
    17781931        -variable [itcl::scope _settings(-ygrid)] \
    17791932        -command [itcl::code $this AdjustSetting -ygrid] \
    17801933        -font "Arial 9"
    1781     checkbutton $inner.gridz \
    1782         -text "Show Z Grid" \
     1934    checkbutton $inner.zgrid \
     1935        -text "Z" \
    17831936        -variable [itcl::scope _settings(-zgrid)] \
    17841937        -command [itcl::code $this AdjustSetting -zgrid] \
    17851938        -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"
    17881946
    17891947    itk_component add axisMode {
     
    17941952        "closest_triad"   "closest" \
    17951953        "furthest_triad"  "farthest" \
    1796         "outer_edges"     "outer"         
     1954        "outer_edges"     "outer"
    17971955    $itk_component(axisMode) value $_settings(-axismode)
    17981956    bind $inner.mode <<Value>> [itcl::code $this AdjustSetting -axismode]
    17991957
    18001958    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
    18081968
    18091969    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
    18111972}
    18121973
     
    18301991        0,0 $inner.view_l -anchor e -pady 2 \
    18311992        0,1 $inner.view -anchor w -pady 2
     1993    blt::table configure $inner r0 -resize none
    18321994
    18331995    set labels { qx qy qz qw xpan ypan zoom }
     
    18371999        entry $inner.${tag} -font "Arial 9"  -bg white \
    18382000            -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}]
    18412005        blt::table $inner \
    18422006            $row,0 $inner.${tag}label -anchor e -pady 2 \
     
    18552019    incr row
    18562020
    1857     blt::table configure $inner c* r* -resize none
     2021    blt::table configure $inner c* -resize none
    18582022    blt::table configure $inner c2 -resize expand
    18592023    blt::table configure $inner r$row -resize expand
     
    18632027
    18642028    set fg [option get $itk_component(hull) font Font]
    1865    
     2029
    18662030    set inner [$itk_component(main) insert end \
    18672031        -title "Cutplane Settings" \
    1868         -icon [Rappture::icon cutbutton]] 
     2032        -icon [Rappture::icon cutbutton]]
    18692033
    18702034    $inner configure -borderwidth 4
     
    19062070        -showvalue off \
    19072071        -command [itcl::code $this AdjustSetting -cutplaneopacity]
    1908     set _widget(-cutplaneopacity) [expr $_settings(-cutplaneopacity) * 100.0]
     2072    $inner.opacity set [expr $_settings(-cutplaneopacity) * 100.0]
    19092073
    19102074    # X-value slicer...
     
    19252089            -command [itcl::code $this EventuallySetCutplane x] \
    19262090            -variable [itcl::scope _settings(-xcutplaneposition)] \
    1927             -foreground red2 -font "Arial 9 bold"
     2091            -foreground red2 -font "Arial 9 bold"
    19282092    } {
    19292093        usual
     
    19542118            -command [itcl::code $this EventuallySetCutplane y] \
    19552119            -variable [itcl::scope _settings(-ycutplaneposition)] \
    1956             -foreground green3 -font "Arial 9 bold"
     2120            -foreground green3 -font "Arial 9 bold"
    19572121    } {
    19582122        usual
     
    19732137            -variable [itcl::scope _settings(-zcutplanevisible)] \
    19742138    } {
    1975         usual
    1976         ignore -foreground
     2139        usual
     2140        ignore -foreground
    19772141    }
    19782142    Rappture::Tooltip::for $itk_component(zbutton) \
     
    19862150            -command [itcl::code $this EventuallySetCutplane z] \
    19872151            -variable [itcl::scope _settings(-zcutplaneposition)] \
    1988             -foreground blue3 -font "Arial 9 bold"
     2152            -foreground blue3 -font "Arial 9 bold"
    19892153    } {
    19902154        usual
     
    20042168        5,0 $inner.opacity_l            -anchor w -pady 2 -cspan 1 \
    20052169        5,1 $inner.opacity              -fill x   -pady 2 -cspan 3 \
    2006         6,0 $inner.xbutton              -anchor w -padx 2 -pady 2 \
    2007         7,0 $inner.ybutton              -anchor w -padx 2 -pady 2 \
    2008         8,0 $inner.zbutton              -anchor w -padx 2 -pady 2 \
    2009         6,1 $inner.xval                 -fill y -rspan 4 \
    2010         6,2 $inner.yval                 -fill y -rspan 4 \
    2011         6,3 $inner.zval                 -fill y -rspan 4 \
     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 \
    20122176
    20132177
     
    20162180}
    20172181
    2018 
    2019 
    2020 #
    2021 #  camera --
     2182#
     2183#  camera --
    20222184#
    20232185itcl::body Rappture::VtkIsosurfaceViewer::camera {option args} {
    2024     switch -- $option { 
     2186    switch -- $option {
    20252187        "show" {
    20262188            puts [array get _view]
     
    20502212                }
    20512213                "-zoom" {
    2052                     SendCmd "camera zoom $_view(-zoom)"
     2214                    SendCmd "camera zoom $_view($what)"
    20532215                }
    20542216             }
     
    20702232
    20712233itcl::body Rappture::VtkIsosurfaceViewer::GetImage { args } {
    2072     if { [image width $_image(download)] > 0 && 
     2234    if { [image width $_image(download)] > 0 &&
    20732235         [image height $_image(download)] > 0 } {
    20742236        set bytes [$_image(download) data -format "jpeg -quality 100"]
     
    20832245        -title "[Rappture::filexfer::label downloadWord] as..."
    20842246    set inner [$popup component inner]
    2085     label $inner.summary -text "" -anchor w 
     2247    label $inner.summary -text "" -anchor w
    20862248    radiobutton $inner.vtk_button -text "VTK data file" \
    20872249        -variable [itcl::scope _downloadPopup(format)] \
    20882250        -font "Arial 9 " \
    2089         -value vtk 
     2251        -value vtk
    20902252    Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file."
    20912253    radiobutton $inner.image_button -text "Image File" \
    20922254        -variable [itcl::scope _downloadPopup(format)] \
    20932255        -font "Arial 9 " \
    2094         -value image 
     2256        -value image
    20952257    Rappture::Tooltip::for $inner.image_button \
    20962258        "Save as digital image."
     
    21132275        2,0 $inner.image_button -anchor w -cspan 2 -padx { 4 0 } \
    21142276        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
    21162278    blt::table configure $inner r3 -height 4
    21172279    blt::table configure $inner r4 -pady 4
     
    21262288    array set style {
    21272289        -color                  BCGYR
    2128         -cutplanesvisible       0
     2290        -cutplaneedges          0
     2291        -cutplanelighting       1
     2292        -cutplaneopacity        1.0
     2293        -cutplanepreinterp      1
     2294        -cutplanesvisible       0
     2295        -cutplanewireframe      0
    21292296        -edgecolor              black
    21302297        -edges                  0
    2131         -isosurfaceopacity      0.6
    21322298        -isosurfacevisible      1
    21332299        -levels                 10
    21342300        -lighting               1
    21352301        -linewidth              1.0
     2302        -opacity                0.6
    21362303        -outline                0
    21372304        -wireframe              0
     
    21452312    array set style [$dataobj style $comp]
    21462313    if { $dataobj != $_first || $style(-levels) == 1 } {
    2147         set style(-isosurfaceopacity) 1.0
     2314        set style(-opacity) 1.0
    21482315    }
    21492316
     
    21572324    # the code to handle aberrant cases.
    21582325
     2326    if { $_changed(-isosurfaceedges) } {
     2327        set style(-edges) $_settings(-isosurfaceedges)
     2328    }
     2329    if { $_changed(-isosurfacelighting) } {
     2330        set style(-lighting) $_settings(-isosurfacelighting)
     2331    }
    21592332    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)
    21612337    }
    21622338    if { $_changed(-numcontours) } {
     
    21782354            set _contourList(numLevels) $style(-levels)
    21792355        }
    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
    21912372    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"
    21922385    SendCmd "cutplane visible $style(-cutplanesvisible) $tag"
    21932386
     
    21952388    SendCmd "outline color [Color2RGB $itk_option(-plotforeground)] $tag"
    21962389    SendCmd "outline visible $style(-outline) $tag"
    2197     set _settings(-outline) $style(-outline)
    2198  
     2390
    21992391    GenerateContourList
    22002392    SendCmd [list contour3d add contourlist $_contourList(values) $tag]
     
    22022394    SendCmd "contour3d edges $style(-edges) $tag"
    22032395    set _settings(-isosurfaceedges) $style(-edges)
    2204     #SendCmd "contour3d color [Color2RGB $settings(-color)] $tag"
     2396    #SendCmd "contour3d color [Color2RGB $style(-color)] $tag"
    22052397    SendCmd "contour3d lighting $style(-lighting) $tag"
    22062398    set _settings(-isosurfacelighting) $style(-lighting)
    22072399    SendCmd "contour3d linecolor [Color2RGB $style(-edgecolor)] $tag"
    22082400    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)
    22122404    SendCmd "contour3d wireframe $style(-wireframe) $tag"
    22132405    set _settings(-isosurfacewireframe) $style(-wireframe)
     
    22492441}
    22502442
     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# ----------------------------------------------------------------------
     2452itcl::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# ----------------------------------------------------------------------
     2478itcl::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# ----------------------------------------------------------------------
     2510itcl::body Rappture::VtkIsosurfaceViewer::LegendProbeSingleContour { x y } {
     2511
     2512    set value [LegendPointToValue $x $y]
     2513    SendCmd [list contour3d contourlist $value]
     2514}
     2515
    22512516#
    22522517# SetLegendTip --
     
    22602525    set font "Arial 8"
    22612526    set lineht [font metrics $font -linespace]
    2262    
     2527
    22632528    set ih [image height $_image(legend)]
    22642529    set iy [expr $y - ($lineht + 2)]
    22652530
    22662531    if { [string match "component*" $fname] } {
    2267         set title ""
     2532        set title ""
    22682533    } else {
    2269         if { [info exists _fields($fname)] } {
    2270             foreach { title units } $_fields($fname) break
    2271             if { $units != "" } {
    2272                 set title [format "%s (%s)" $title $units]
    2273             }
    2274         } else {
    2275             set title $fname
    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        }
    22772542    }
    22782543    # If there's a legend title, increase the offset by the line height.
     
    22882553    }
    22892554    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
    22922557    .rappturetooltip configure -icon $_image(swatch)
    22932558
    22942559    # 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]
    23032564    set ty [expr $y - 5]
     2565
     2566    # Setup the text for the tooltip
    23042567    if { [info exists _isolines($y)] } {
    23052568        Rappture::Tooltip::text $c [format "$title %g (isosurface)" $_isolines($y)]
     
    23072570        Rappture::Tooltip::text $c [format "$title %g" $value]
    23082571    }
    2309     Rappture::Tooltip::tooltip show $c +$tx,+$ty   
    2310 }
    2311 
     2572
     2573    # Show the tooltip
     2574    Rappture::Tooltip::tooltip show $c +$tx,+$ty
     2575}
    23122576
    23132577# ----------------------------------------------------------------------
     
    23422606
    23432607#
    2344 # ReceiveLegend -- 
    2345 #
    2346 #       Invoked automatically whenever the "legend" command comes in from
    2347 #       the rendering server.  Indicates that binary image data with the
    2348 #       specified <size> will follow.
     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.
    23492613#
    23502614itcl::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"
    23522616    set _title $title
    2353     regsub {\(mag\)} $title "" _title 
     2617    regsub {\(mag\)} $title "" _title
    23542618    if { [IsConnected] } {
    23552619        set bytes [ReceiveBytes $size]
     
    23602624        #puts stderr "read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>"
    23612625        if { [catch {DrawLegend} errs] != 0 } {
    2362             global errorInfo
    2363             puts stderr "errs=$errs errorInfo=$errorInfo"
     2626            global errorInfo
     2627            puts stderr "errs=$errs errorInfo=$errorInfo"
    23642628        }
    23652629    }
     
    23692633# DrawLegend --
    23702634#
    2371 #       Draws the legend in the own canvas on the right side of the plot area.
     2635#       Draws the legend on the canvas on the right side of the plot area.
    23722636#
    23732637itcl::body Rappture::VtkIsosurfaceViewer::DrawLegend {} {
     
    23782642    set font "Arial 8"
    23792643    set lineht [font metrics $font -linespace]
    2380    
     2644
    23812645    if { [string match "component*" $fname] } {
    2382         set title ""
     2646        set title ""
    23832647    } else {
    2384         if { [info exists _fields($fname)] } {
    2385             foreach { title units } $_fields($fname) break
    2386             if { $units != "" } {
    2387                 set title [format "%s (%s)" $title $units]
    2388             }
    2389         } else {
    2390             set title $fname
    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        }
    23922656    }
    23932657    set x [expr $w - 2]
    23942658    if { !$_settings(-legendvisible) } {
    2395         $c delete legend
    2396         return
    2397     } 
     2659        $c delete legend
     2660        return
     2661    }
    23982662    if { [$c find withtag "legend"] == "" } {
    2399         set y 2
    2400         # If there's a legend title, create a text item for the title.
     2663        set y 2
     2664        # If there's a legend title, create a text item for the title.
    24012665        $c create text $x $y \
    2402             -anchor ne \
    2403             -fill $itk_option(-plotforeground) -tags "title legend" \
    2404             -font $font
     2666            -anchor ne \
     2667            -fill $itk_option(-plotforeground) -tags "title legend" \
     2668            -font $font
    24052669        if { $title != "" } {
    24062670            incr y $lineht
    24072671        }
    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
    24252693    }
    24262694    $c delete isoline
     
    24352703         $_settings(-numcontours) > 0 } {
    24362704
    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        }
    24382711        set range [expr double($vmax - $vmin)]
    24392712        if { $range <= 0.0 } {
     
    24412714        }
    24422715        set tags "isoline legend"
    2443         set offset [expr 2 + $lineht]
    2444         if { $title != "" } {
    2445             incr offset $lineht
    2446         }
     2716        set offset [expr 2 + $lineht]
     2717        if { $title != "" } {
     2718            incr offset $lineht
     2719        }
    24472720        foreach value $_contourList(values) {
    24482721            set norm [expr 1.0 - (($value - $vmin) / $range)]
     
    24562729    }
    24572730
    2458     $c bind title <ButtonPress> [itcl::code $this Combo post]
    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]
    24612734    # Reset the item coordinates according the current size of the plot.
    24622735    $c itemconfigure title -text $title
    24632736    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]
    24672745    }
    24682746    set y 2
     
    24702748    if { $title != "" } {
    24712749        $c itemconfigure title -text $title
    2472         $c coords title $x $y
    2473         incr y $lineht
     2750        $c coords title $x $y
     2751        incr y $lineht
    24742752        $c raise title
    24752753    }
     
    24802758    $c raise sensor
    24812759    $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# ----------------------------------------------------------------------
     2784itcl::body Rappture::VtkIsosurfaceViewer::LegendTitleAction {option} {
     2785    set c $itk_component(view)
    24972786    switch -- $option {
    24982787        post {
     
    25052794            tk_popup $itk_component(fieldmenu) $x $y
    25062795        }
    2507         activate {
     2796        enter {
    25082797            $c itemconfigure title -fill red
    25092798        }
    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 {
    25142803            $itk_component(field) value $_curFldLabel
    25152804            AdjustSetting -field
    25162805        }
    25172806        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# ----------------------------------------------------------------------
     2825itcl::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
     2872itcl::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# ----------------------------------------------------------------------
     2908itcl::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# ----------------------------------------------------------------------
     2994itcl::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# ----------------------------------------------------------------------
     3053itcl::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
    25203065    }
    25213066}
     
    25273072    # Keep track of the colormaps that we build.
    25283073    if { ![info exists _colormaps($name)] } {
    2529         BuildColormap $name 
     3074        BuildColormap $name
    25303075        set _colormaps($name) 1
    25313076    }
     
    25493094}
    25503095
    2551 itcl::body Rappture::VtkIsosurfaceViewer::SetOrientation { side } { 
     3096itcl::body Rappture::VtkIsosurfaceViewer::SetOrientation { side } {
    25523097    array set positions {
    25533098        front "1 0 0 0"
     
    25603105    foreach name { -qw -qx -qy -qz } value $positions($side) {
    25613106        set _view($name) $value
    2562     } 
     3107    }
    25633108    set q [ViewToQuaternion]
    25643109    $_arcball quaternion $q
     
    25703115}
    25713116
    2572 itcl::body Rappture::VtkIsosurfaceViewer::GenerateContourList {} { 
     3117itcl::body Rappture::VtkIsosurfaceViewer::GenerateContourList {} {
    25733118    if { ![info exists _limits($_curFldName)] } {
    25743119        puts stderr "no _curFldName"
     
    25763121    }
    25773122    if { $_contourList(numLevels) < 1 } {
     3123        # There are tools that set 0 levels to get cutplanes only
     3124        #puts stderr "numLevels < 1"
    25783125        return ""
    25793126    }
     
    25813128        set values $_contourList(reqValues)
    25823129    } 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
    25843140        set v [blt::vector create \#auto]
    25853141        $v seq $vmin $vmax [expr $_contourList(numLevels)+2]
     
    25913147}
    25923148
    2593 itcl::body Rappture::VtkIsosurfaceViewer::SetCurrentFieldName { dataobj } { 
     3149itcl::body Rappture::VtkIsosurfaceViewer::SetCurrentFieldName { dataobj } {
    25943150    set _first $dataobj
    25953151    $itk_component(field) choices delete 0 end
     
    26113167                -activeforeground $itk_option(-plotforeground) \
    26123168                -font "Arial 8" \
    2613                 -command [itcl::code $this Combo invoke]
     3169                -command [itcl::code $this LegendTitleAction save]
    26143170            set _fields($fname) [list $label $units $components]
    26153171            if { $_curFldName == "" } {
     
    26203176    }
    26213177    $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]]
    26263180        SendCmd "dataset maprange explicit $limits $_curFldName"
    26273181        if { $limits != $_currentLimits } {
     
    26293183            EventuallyChangeContourLevels
    26303184        }
    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 -*-
    22# ----------------------------------------------------------------------
    33#  COMPONENT: vtkmeshviewer - Vtk mesh viewer
     
    5757    public method get {args}
    5858    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
    6262    }
    6363    public method scale {args}
    6464
    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 
    8065    # The following methods are only used by this class.
     66    private method AdjustSetting {what {value ""}}
    8167    private method BuildAxisTab {}
    8268    private method BuildCameraTab {}
    83     private method BuildCutawayTab {}
    84     private method BuildDownloadPopup { widget command }
     69    private method BuildDownloadPopup { widget command }
    8570    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}
    9284    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 }
    9494    private method SetOrientation { side }
    9595    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}
    97100
    98101    private variable _arcball ""
    99     private variable _dlist "";         # list of data objects
     102    private variable _dlist "";         # list of data objects
    100103    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.
    109110    private variable _click;            # info used for rotate operations
    110111    private variable _limits;           # autoscale min/max for all axes
     
    163164    # Populate parser with commands handle incoming requests
    164165    #
    165     $_parser alias image    [itcl::code $this ReceiveImage]
    166     $_parser alias dataset  [itcl::code $this ReceiveDataset]
     166    $_parser alias image [itcl::code $this ReceiveImage]
     167    $_parser alias dataset [itcl::code $this ReceiveDataset]
    167168
    168169    # Initialize the view to some default parameters.
    169170    array set _view {
    170         qw              0.853553
    171         qx              -0.353553
    172         qy              0.353553
    173         qz              0.146447
    174         zoom            1.0
    175         xpan            0
    176         ypan            0
    177         ortho           0
     171        -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
    178179    }
    179180    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]
    182182
    183183    set _limits(zmin) 0.0
     
    187187        -axesvisible            1
    188188        -axislabels             1
     189        -axisminorticks         1
    189190        -outline                0
    190191        -polydataedges          0
     
    193194        -polydatavisible        1
    194195        -polydatawireframe      0
    195         -xcutaway               0
    196         -xdirection             -1
    197196        -xgrid                  0
    198         -xposition              0
    199         -ycutaway               0
    200         -ydirection             -1
    201197        -ygrid                  0
    202         -yposition              0
    203         -zcutaway               0
    204         -zdirection             -1
    205198        -zgrid                  0
    206         -zposition              0
    207199    }
    208200    array set _widget {
    209201        -polydataopacity        100
    210     }       
     202    }
    211203    itk_component add view {
    212204        canvas $itk_component(plotarea).view \
     
    219211    itk_component add fieldmenu {
    220212        menu $itk_component(plotarea).menu -bg black -fg white -relief flat \
    221             -tearoff no 
     213            -tearoff no
    222214    } {
    223215        usual
     
    240232
    241233    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
    244236    set _map(zoom) 1.0
    245237    set _map(original) ""
     
    285277    BuildPolydataTab
    286278    BuildAxisTab
    287     #BuildCutawayTab
    288279    BuildCameraTab
    289280
    290     # Hack around the Tk panewindow.  The problem is that the requested 
     281    # Hack around the Tk panewindow.  The problem is that the requested
    291282    # size of the 3d view isn't set until an image is retrieved from
    292283    # the server.  So the panewindow uses the tiny size.
     
    294285    pack forget $itk_component(view)
    295286    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
    297288    blt::table configure $itk_component(plotarea) c1 -resize none
    298289
     
    304295    bind $itk_component(view) <ButtonRelease-1> \
    305296        [itcl::code $this Rotate release %x %y]
    306     bind $itk_component(view) <Configure> \
    307         [itcl::code $this EventuallyResize %w %h]
    308297
    309298    # Bindings for panning via mouse
     
    383372
    384373itcl::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]"
    387375    set _rotatePending 0
    388376}
     
    399387
    400388itcl::body Rappture::VtkMeshViewer::EventuallyRotate { q } {
    401     foreach { _view(qw) _view(qx) _view(qy) _view(qz) } $q break
     389    QuaternionToView $q
    402390    if { !$_rotatePending } {
    403391        set _rotatePending 1
     
    509497                    continue
    510498                }
    511                 if {[info exists _obj2ovride($dataobj-raise)] && 
     499                if {[info exists _obj2ovride($dataobj-raise)] &&
    512500                    $_obj2ovride($dataobj-raise)} {
    513501                    set dlist [linsert $dlist 0 $dataobj]
     
    537525            }
    538526            return $dlist
    539         }           
     527        }
    540528        -image {
    541529            if {[llength $args] != 2} {
     
    723711
    724712    # 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
    728715    global readyForNextFrame
    729716    set readyForNextFrame 1
     
    749736    if { $info(-type) == "image" } {
    750737        if 0 {
    751             set f [open "last.ppm" "w"] 
     738            set f [open "last.ppm" "w"]
    752739            fconfigure $f -encoding binary
    753740            puts -nonewline $f $bytes
     
    827814    # Turn on buffering of commands to the server.  We don't want to
    828815    # be preempted by a server disconnect/reconnect (which automatically
    829     # generates a new call to Rebuild).   
     816    # generates a new call to Rebuild).
    830817    StartBufferingCommands
    831818
     
    835822        $_arcball resize $w $h
    836823        DoResize
    837         InitSettings -xgrid -ygrid -zgrid -axismode -axesvisible -axislabels
     824        InitSettings -xgrid -ygrid -zgrid -axismode \
     825            -axesvisible -axislabels -axisminorticks
    838826        StopBufferingCommands
    839827        SendCmd "imgflush"
     
    857845                continue
    858846            }
     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            }
    859853            set length [string length $bytes]
    860854            if { $_reportClientInfo }  {
    861855                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]
    866861                lappend info "dataset_label" [$dataobj hints label]
    867862                lappend info "dataset_size"  $length
    868863                lappend info "dataset_tag"   $tag
    869                 SendCmd [list "clientinfo" $info]
     864                SendCmd "clientinfo [list $info]"
    870865            }
    871866            SendCmd "dataset add $tag data follows $length"
     
    902897        InitSettings -polydataedges -polydatalighting -polydataopacity \
    903898            -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]
    911903        SendCmd "camera reset"
    912         if { $_view(ortho)} {
     904        if { $_view(-ortho)} {
    913905            SendCmd "camera mode ortho"
    914906        } else {
     
    941933itcl::body Rappture::VtkMeshViewer::CurrentDatasets {args} {
    942934    set flag [lindex $args 0]
    943     switch -- $flag { 
     935    switch -- $flag {
    944936        "-all" {
    945937            if { [llength $args] > 1 } {
     
    960952                set dlist [get -visible]
    961953            }
    962         }           
     954        }
    963955        default {
    964956            set dlist $args
     
    985977    switch -- $option {
    986978        "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)"
    989981        }
    990982        "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)"
    993985        }
    994986        "reset" {
    995987            array set _view {
    996                 qw      0.853553
    997                 qx      -0.353553
    998                 qy      0.353553
    999                 qz      0.146447
    1000                 zoom    1.0
    1001                 xpan    0
    1002                 ypan    0
     988                -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
    1003995            }
    1004996            if { $_first != "" } {
     
    10081000                }
    10091001            }
    1010             set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    1011             $_arcball quaternion $q
     1002            $_arcball quaternion [ViewToQuaternion]
    10121003            DoRotate
    10131004            SendCmd "camera reset"
     
    10171008
    10181009itcl::body Rappture::VtkMeshViewer::PanCamera {} {
    1019     set x $_view(xpan)
    1020     set y $_view(ypan)
     1010    set x $_view(-xpan)
     1011    set y $_view(-ypan)
    10211012    SendCmd "camera pan $x $y"
    10221013}
     
    10771068    foreach tag [CurrentDatasets -visible] {
    10781069        SendCmd "dataset getscalar pixel $x $y $tag"
    1079     } 
     1070    }
    10801071}
    10811072
     
    10951086            set x [expr $x / double($w)]
    10961087            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]
    10991090            PanCamera
    11001091            return
     
    11181109            set _click(x) $x
    11191110            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]
    11221113            PanCamera
    11231114        }
     
    12171208            SendCmd "axis flymode $mode"
    12181209        }
    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 white
    1227                 SendCmd "renderer clipplane $axis $pos $dir"
    1228             } else {
    1229                 $itk_component(${axis}CutScale) configure -state disabled \
    1230                     -troughcolor grey82
    1231                 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         }
    12431210        default {
    12441211            error "don't know how to fix $what"
     
    12521219itcl::configbody Rappture::VtkMeshViewer::plotbackground {
    12531220    if { [isconnected] } {
    1254         foreach {r g b} [Color2RGB $itk_option(-plotbackground)] break
    1255         SendCmd "screen bgcolor $r $g $b"
     1221        set rgb [Color2RGB $itk_option(-plotbackground)]
     1222        SendCmd "screen bgcolor $rgb"
    12561223    }
    12571224}
     
    12621229itcl::configbody Rappture::VtkMeshViewer::plotforeground {
    12631230    if { [isconnected] } {
    1264         foreach {r g b} [Color2RGB $itk_option(-plotforeground)] break
    1265         #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"
    12671234    }
    12681235}
     
    12781245        set f [open "$tmpfile" "w"]
    12791246        fconfigure $f -translation binary -encoding binary
    1280         puts $f $data 
     1247        puts $f $data
    12811248        close $f
    12821249        set reader [vtkDataSetReader $tag-xvtkDataSetReader]
     
    13261293        -variable [itcl::scope _settings(-polydatavisible)] \
    13271294        -command [itcl::code $this AdjustSetting -polydatavisible] \
    1328         -font "Arial 9" -anchor w 
     1295        -font "Arial 9" -anchor w
    13291296
    13301297    checkbutton $inner.outline \
     
    13321299        -variable [itcl::scope _settings(-outline)] \
    13331300        -command [itcl::code $this AdjustSetting -outline] \
    1334         -font "Arial 9" -anchor w 
     1301        -font "Arial 9" -anchor w
    13351302
    13361303    checkbutton $inner.wireframe \
     
    13381305        -variable [itcl::scope _settings(-polydatawireframe)] \
    13391306        -command [itcl::code $this AdjustSetting -polydatawireframe] \
    1340         -font "Arial 9" -anchor w 
     1307        -font "Arial 9" -anchor w
    13411308
    13421309    checkbutton $inner.lighting \
     
    13531320
    13541321    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"
    13561323    } {
    13571324        ignore -font
     
    13631330        [itcl::code $this AdjustSetting -field]
    13641331
    1365     label $inner.opacity_l -text "Opacity" -font "Arial 9" -anchor w 
     1332    label $inner.opacity_l -text "Opacity" -font "Arial 9" -anchor w
    13661333    ::scale $inner.opacity -from 0 -to 100 -orient horizontal \
    13671334        -variable [itcl::scope _widget(-polydataopacity)] \
     
    13781345        4,0 $inner.edges     -cspan 2  -anchor w -pady 2 \
    13791346        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
    13811348
    13821349    blt::table configure $inner r* c* -resize none
     
    13911358    set inner [$itk_component(main) insert end \
    13921359        -title "Axis Settings" \
    1393         -icon [Rappture::icon axis1]]
     1360        -icon [Rappture::icon axis2]]
    13941361    $inner configure -borderwidth 4
    13951362
    13961363    checkbutton $inner.visible \
    1397         -text "Show Axes" \
     1364        -text "Axes" \
    13981365        -variable [itcl::scope _settings(-axesvisible)] \
    13991366        -command [itcl::code $this AdjustSetting -axesvisible] \
     
    14011368
    14021369    checkbutton $inner.labels \
    1403         -text "Show Axis Labels" \
     1370        -text "Axis Labels" \
    14041371        -variable [itcl::scope _settings(-axislabels)] \
    14051372        -command [itcl::code $this AdjustSetting -axislabels] \
    14061373        -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" \
    14101377        -variable [itcl::scope _settings(-xgrid)] \
    14111378        -command [itcl::code $this AdjustSetting -xgrid] \
    14121379        -font "Arial 9"
    1413     checkbutton $inner.gridy \
    1414         -text "Show Y Grid" \
     1380    checkbutton $inner.ygrid \
     1381        -text "Y" \
    14151382        -variable [itcl::scope _settings(-ygrid)] \
    14161383        -command [itcl::code $this AdjustSetting -ygrid] \
    14171384        -font "Arial 9"
    1418     checkbutton $inner.gridz \
    1419         -text "Show Z Grid" \
     1385    checkbutton $inner.zgrid \
     1386        -text "Z" \
    14201387        -variable [itcl::scope _settings(-zgrid)] \
    14211388        -command [itcl::code $this AdjustSetting -zgrid] \
    14221389        -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"
    14251397
    14261398    itk_component add axismode {
     
    14311403        "closest_triad"   "closest" \
    14321404        "furthest_triad"  "farthest" \
    1433         "outer_edges"     "outer"         
     1405        "outer_edges"     "outer"
    14341406    $itk_component(axismode) value "static"
    14351407    bind $inner.mode <<Value>> [itcl::code $this AdjustSetting -axismode]
    14361408
    14371409    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
    14451419
    14461420    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
    14481423}
    14491424
     
    14661441        0,0 $inner.view_l -anchor e -pady 2 \
    14671442        0,1 $inner.view -anchor w -pady 2
     1443    blt::table configure $inner r0 -resize none
    14681444
    14691445    set labels { qx qy qz qw xpan ypan zoom }
     
    14721448        label $inner.${tag}label -text $tag -font "Arial 9"
    14731449        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}]
    14771455        blt::table $inner \
    14781456            $row,0 $inner.${tag}label -anchor e -pady 2 \
     
    14831461    checkbutton $inner.ortho \
    14841462        -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] \
    14871465        -font "Arial 9"
    14881466    blt::table $inner \
     
    14911469    incr row
    14921470
    1493     blt::table configure $inner c* r* -resize none
     1471    blt::table configure $inner c* -resize none
    14941472    blt::table configure $inner c2 -resize expand
    14951473    blt::table configure $inner r$row -resize expand
    14961474}
    14971475
    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 --
    16411478#
    16421479itcl::body Rappture::VtkMeshViewer::camera {option args} {
    1643     switch -- $option { 
     1480    switch -- $option {
    16441481        "show" {
    16451482            puts [array get _view]
    16461483        }
    16471484        "set" {
    1648             set who [lindex $args 0]
    1649             set x $_view($who)
     1485            set what [lindex $args 0]
     1486            set x $_view($what)
    16501487            set code [catch { string is double $x } result]
    16511488            if { $code != 0 || !$result } {
    16521489                return
    16531490            }
    1654             switch -- $who {
    1655                 "ortho" {
    1656                     if {$_view(ortho)} {
     1491            switch -- $what {
     1492                "-ortho" {
     1493                    if {$_view($what)} {
    16571494                        SendCmd "camera mode ortho"
    16581495                    } else {
     
    16601497                    }
    16611498                }
    1662                 "xpan" - "ypan" {
     1499                "-xpan" - "-ypan" {
    16631500                    PanCamera
    16641501                }
    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]
    16671504                    $_arcball quaternion $q
    16681505                    EventuallyRotate $q
    16691506                }
    1670                 "zoom" {
    1671                     SendCmd "camera zoom $_view(zoom)"
     1507                "-zoom" {
     1508                    SendCmd "camera zoom $_view($what)"
    16721509                }
    16731510            }
     
    16861523
    16871524itcl::body Rappture::VtkMeshViewer::GetImage { args } {
    1688     if { [image width $_image(download)] > 0 && 
     1525    if { [image width $_image(download)] > 0 &&
    16891526         [image height $_image(download)] > 0 } {
    16901527        set bytes [$_image(download) data -format "jpeg -quality 100"]
     
    16991536        -title "[Rappture::filexfer::label downloadWord] as..."
    17001537    set inner [$popup component inner]
    1701     label $inner.summary -text "" -anchor w 
     1538    label $inner.summary -text "" -anchor w
    17021539    radiobutton $inner.vtk_button -text "VTK data file" \
    17031540        -variable [itcl::scope _downloadPopup(format)] \
    17041541        -font "Helvetica 9 " \
    1705         -value vtk 
     1542        -value vtk
    17061543    Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file."
    17071544    radiobutton $inner.image_button -text "Image File" \
    17081545        -variable [itcl::scope _downloadPopup(format)] \
    1709         -value image 
     1546        -value image
    17101547    Rappture::Tooltip::for $inner.image_button \
    17111548        "Save as digital image."
     
    17281565        2,0 $inner.image_button -anchor w -cspan 2 -padx { 4 0 } \
    17291566        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
    17311568    blt::table configure $inner r3 -height 4
    17321569    blt::table configure $inner r4 -pady 4
     
    17971634}
    17981635
    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 } {
     1636itcl::body Rappture::VtkMeshViewer::SetOrientation { side } {
    18301637    array set positions {
    18311638        front "1 0 0 0"
     
    18361643        bottom "0.707107 0.707107 0 0"
    18371644    }
    1838     foreach name { qw qx qy qz } value $positions($side) {
     1645    foreach name { -qw -qx -qy -qz } value $positions($side) {
    18391646        set _view($name) $value
    1840     } 
    1841     set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
     1647    }
     1648    set q [ViewToQuaternion]
    18421649    $_arcball quaternion $q
    18431650    SendCmd "camera orient $q"
    18441651    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 -*-
    22# ----------------------------------------------------------------------
    33#  COMPONENT: vtkstreamlinesviewer - Vtk streamlines object viewer
     
    5757    public method get {args}
    5858    public method isconnected {}
    59     public method parameters {title args} { 
    60         # do nothing 
     59    public method parameters {title args} {
     60        # do nothing
    6161    }
    6262    public method scale {args}
    6363
    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 
    8164    # The following methods are only used by this class.
     65    private method AdjustSetting {what {value ""}}
    8266    private method BuildAxisTab {}
    8367    private method BuildCameraTab {}
    8468    private method BuildColormap { name colors }
    8569    private method BuildCutplaneTab {}
    86     private method BuildDownloadPopup { widget command } 
     70    private method BuildDownloadPopup { widget command }
    8771    private method BuildStreamsTab {}
    8872    private method BuildVolumeTab {}
    8973    private method DrawLegend {}
    9074    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 }
    9990    private method LeaveLegend {}
    100     private method MotionLegend { x y }
     91    private method MotionLegend { x y }
     92    private method Pan {option x y}
    10193    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 }
    102102    private method RequestLegend {}
     103    private method Rotate {option x y}
    103104    private method SetColormap { dataobj comp }
    104105    private method ChangeColormap { dataobj comp color }
    105106    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}
    108109    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}
    109114
    110115    private variable _arcball ""
     
    113118    private variable _obj2datasets
    114119    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
    116121                                   ;    # datasets in the server
    117122    private variable _colormaps    ;    # contains all the colormaps
     
    142147    private variable _cutplanePending 0
    143148    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
    147152    private variable _curFldName ""
    148153    private variable _curFldLabel ""
     
    189194    $_dispatcher register !xcutplane
    190195    $_dispatcher dispatch $this !xcutplane \
    191         "[itcl::code $this AdjustSetting cutplaneXPosition]; list"
     196        "[itcl::code $this AdjustSetting -cutplanexposition]; list"
    192197
    193198    # Y-Cutplane event
    194199    $_dispatcher register !ycutplane
    195200    $_dispatcher dispatch $this !ycutplane \
    196         "[itcl::code $this AdjustSetting cutplaneYPosition]; list"
     201        "[itcl::code $this AdjustSetting -cutplaneyposition]; list"
    197202
    198203    # Z-Cutplane event
    199204    $_dispatcher register !zcutplane
    200205    $_dispatcher dispatch $this !zcutplane \
    201         "[itcl::code $this AdjustSetting cutplaneZPosition]; list"
     206        "[itcl::code $this AdjustSetting -cutplanezposition]; list"
    202207
    203208    #
     
    210215    # Initialize the view to some default parameters.
    211216    array set _view {
    212         qw              0.853553
    213         qx              -0.353553
    214         qy              0.353553
    215         qz              0.146447
    216         zoom            1.0
    217         xpan            0
    218         ypan            0
    219         ortho           0
     217        -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
    220225    }
    221226    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]
    224228
    225229    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
    256261    }]
    257262
     
    266271    itk_component add fieldmenu {
    267272        menu $itk_component(plotarea).menu -bg black -fg white -relief flat \
    268             -tearoff no 
     273            -tearoff no
    269274    } {
    270275        usual
     
    286291
    287292    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
    290295    set _map(zoom) 1.0
    291296    set _map(original) ""
     
    332337            -onimage [Rappture::icon volume-on] \
    333338            -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]
    336341    }
    337342    $itk_component(volume) select
     
    344349            -onimage [Rappture::icon streamlines-on] \
    345350            -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] \
    348353    }
    349354    $itk_component(streamlines) select
     
    356361            -onimage [Rappture::icon cutbutton] \
    357362            -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]
    360365    }
    361366    Rappture::Tooltip::for $itk_component(cutplane) \
     
    377382    set _image(legend) [image create photo]
    378383    itk_component add legend {
    379         canvas $itk_component(plotarea).legend -width 50 -highlightthickness 0 
     384        canvas $itk_component(plotarea).legend -width 50 -highlightthickness 0
    380385    } {
    381386        usual
     
    384389    }
    385390
    386     # Hack around the Tk panewindow.  The problem is that the requested 
     391    # Hack around the Tk panewindow.  The problem is that the requested
    387392    # size of the 3d view isn't set until an image is retrieved from
    388393    # the server.  So the panewindow uses the tiny size.
     
    390395    pack forget $itk_component(view)
    391396    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
    393398    blt::table configure $itk_component(plotarea) c1 -resize none
    394399
     
    400405    bind $itk_component(view) <ButtonRelease-1> \
    401406        [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
    409408    # Bindings for panning via mouse
    410409    bind $itk_component(view) <ButtonPress-2> \
     
    481480
    482481itcl::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]"
    485483    set _rotatePending 0
    486484}
     
    516514
    517515itcl::body Rappture::VtkStreamlinesViewer::EventuallyRotate { q } {
    518     foreach { _view(qw) _view(qx) _view(qy) _view(qz) } $q break
     516    QuaternionToView $q
    519517    if { !$_rotatePending } {
    520518        set _rotatePending 1
    521         global rotate_delay 
     519        global rotate_delay
    522520        $_dispatcher event -after $rotate_delay !rotate
    523521    }
     
    623621                    continue
    624622                }
    625                 if {[info exists _obj2ovride($dataobj-raise)] && 
     623                if {[info exists _obj2ovride($dataobj-raise)] &&
    626624                    $_obj2ovride($dataobj-raise)} {
    627625                    set dlist [linsert $dlist 0 $dataobj]
     
    651649            }
    652650            return $dlist
    653         }           
     651        }
    654652        -image {
    655653            if {[llength $args] != 2} {
     
    793791            set info {}
    794792            set user "???"
    795             if { [info exists env(USER)] } {
     793            if { [info exists env(USER)] } {
    796794                set user $env(USER)
    797             }
     795            }
    798796            set session "???"
    799             if { [info exists env(SESSION)] } {
     797            if { [info exists env(SESSION)] } {
    800798                set session $env(SESSION)
    801             }
     799            }
    802800            lappend info "version" "$Rappture::version"
    803801            lappend info "build" "$Rappture::build"
     
    853851    $_dispatcher cancel !legend
    854852    # 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
    861859}
    862860
     
    878876    if { $info(-type) == "image" } {
    879877        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
    882881            close $f
    883882        }
     
    885884        set time [clock seconds]
    886885        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>"
    888887        if { $_start > 0 } {
    889888            set finish [clock clicks -milliseconds]
     
    950949# ----------------------------------------------------------------------
    951950itcl::body Rappture::VtkStreamlinesViewer::Rebuild {} {
    952     update
    953951    set w [winfo width $itk_component(view)]
    954952    set h [winfo height $itk_component(view)]
     
    966964    set _first ""
    967965    if { $_reset } {
    968         set _width $w
    969         set _height $h
    970         $_arcball resize $w $h
    971         DoResize
    972         InitSettings axisXGrid axisYGrid axisZGrid axis-mode \
    973             axesVisible axisLabelsVisible axisMinorTicks
     966        set _width $w
     967        set _height $h
     968        $_arcball resize $w $h
     969        DoResize
     970        InitSettings -xgrid -ygrid -zgrid -axismode \
     971            -axesvisible -axislabelsvisible -axisminorticks
    974972        # This "imgflush" is to force an image returned before vtkvis starts
    975973        # reading a (big) dataset.  This will display an empty plot with axes
     
    990988                set bytes [$dataobj vtkdata $comp]
    991989                set length [string length $bytes]
    992                 if 0 {
     990                if 0 {
    993991                    set f [open /tmp/vtkstreamlines.vtk "w"]
    994992                    fconfigure $f -translation binary -encoding binary
    995                     puts $f $bytes
     993                    puts -nonewline $f $bytes
    996994                    close $f
    997                 }
     995                }
    998996                if { $_reportClientInfo }  {
    999997                    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]
    10041003                    lappend info "dataset_label" [$dataobj hints label]
    10051004                    lappend info "dataset_size"  $length
     
    10331032            }
    10341033        }
    1035         $itk_component(field) choices delete 0 end
    1036         $itk_component(fieldmenu) delete 0 end
    1037         array unset _fields
     1034        $itk_component(field) choices delete 0 end
     1035        $itk_component(fieldmenu) delete 0 end
     1036        array unset _fields
    10381037        set _curFldName ""
    10391038        foreach cname [$_first components] {
     
    10631062
    10641063    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
    10851083        Zoom reset
    10861084        SendCmd "camera reset"
     
    11031101itcl::body Rappture::VtkStreamlinesViewer::CurrentDatasets {args} {
    11041102    set flag [lindex $args 0]
    1105     switch -- $flag { 
     1103    switch -- $flag {
    11061104        "-all" {
    11071105            if { [llength $args] > 1 } {
     
    11221120                set dlist [get -visible]
    11231121            }
    1124         }           
     1122        }
    11251123        default {
    11261124            set dlist $args
     
    11501148    switch -- $option {
    11511149        "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)"
    11541152        }
    11551153        "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)"
    11581156        }
    11591157        "reset" {
    11601158            array set _view {
    1161                 qw      0.853553
    1162                 qx      -0.353553
    1163                 qy      0.353553
    1164                 qz      0.146447
    1165                 zoom    1.0
    1166                 xpan    0
    1167                 ypan    0
     1159                -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
    11681166            }
    11691167            if { $_first != "" } {
     
    11731171                }
    11741172            }
    1175             set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    1176             $_arcball quaternion $q
     1173            $_arcball quaternion [ViewToQuaternion]
    11771174            DoRotate
    11781175            SendCmd "camera reset"
     
    11821179
    11831180itcl::body Rappture::VtkStreamlinesViewer::PanCamera {} {
    1184     set x $_view(xpan)
    1185     set y $_view(ypan)
     1181    set x $_view(-xpan)
     1182    set y $_view(-ypan)
    11861183    SendCmd "camera pan $x $y"
    11871184}
    1188 
    11891185
    11901186# ----------------------------------------------------------------------
     
    12431239    foreach tag [CurrentDatasets -visible] {
    12441240        SendCmdNoWait "dataset getscalar pixel $x $y $tag"
    1245     } 
     1241    }
    12461242}
    12471243
     
    12611257            set x [expr $x / double($w)]
    12621258            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]
    12651261            PanCamera
    12661262            return
     
    12841280            set _click(x) $x
    12851281            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]
    12881284            PanCamera
    12891285        }
     
    13071303itcl::body Rappture::VtkStreamlinesViewer::InitSettings { args } {
    13081304    foreach spec $args {
    1309         if { [info exists _settings($_first-$spec)] } {
     1305        if { [info exists _settings($_first${spec})] } {
    13101306            # Reset global setting with dataobj specific setting
    1311             set _settings($spec) $_settings($_first-$spec)
     1307            set _settings($spec) $_settings($_first${spec})
    13121308        }
    13131309        AdjustSetting $spec
     
    13271323    }
    13281324    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" {
    13301467            set val $_settings($what)
    13311468            set sval [expr { 0.01 * double($val) }]
    13321469            SendCmd "polydata opacity $sval"
    13331470        }
    1334         "volumeWireframe" {
     1471        "-volumewireframe" {
    13351472            set bool $_settings($what)
    13361473            SendCmd "polydata wireframe $bool"
    13371474        }
    1338         "volumeVisible" {
     1475        "-volumevisible" {
    13391476            set bool $_settings($what)
    13401477            SendCmd "polydata visible $bool"
     
    13471484            }
    13481485        }
    1349         "volumeLighting" {
     1486        "-volumelighting" {
    13501487            set bool $_settings($what)
    13511488            SendCmd "polydata lighting $bool"
    13521489        }
    1353         "volumeEdges" {
     1490        "-volumeedges" {
    13541491            set bool $_settings($what)
    13551492            SendCmd "polydata edges $bool"
    13561493        }
    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]
    13711496            set bool $_settings($what)
    13721497            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) $mode
    1378             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 white
    1407             } else {
    1408                 $itk_component(${axis}CutScale) configure -state disabled \
    1409                     -troughcolor grey82
    1410             }
    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 0
    1418         }
    1419         "streamlinesSeedsVisible" {
    1420             set bool $_settings($what)
    1421             SendCmd "streamlines seed visible $bool"
    1422         }
    1423         "streamlinesNumSeeds" {
    1424             set density $_settings($what)
    1425             EventuallyReseed $density
    1426         }
    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) $mode
    1441             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) $colormap
    1456             foreach dataset [CurrentDatasets -visible $_first] {
    1457                 foreach {dataobj comp} [split $dataset -] break
    1458                 ChangeColormap $dataobj $comp $colormap
    1459             }
    1460             set _legendPending 1
    1461         }
    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) $fname
    1480             if { [info exists _fields($fname)] } {
    1481                 foreach { label units components } $_fields($fname) break
    1482                 if { $components > 1 } {
    1483                     set _colorMode vmag
    1484                 } else {
    1485                     set _colorMode scalar
    1486                 }
    1487                 set _curFldName $fname
    1488                 set _curFldLabel $label
    1489             } else {
    1490                 puts stderr "unknown field \"$fname\""
    1491                 return
    1492             }
    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             DrawLegend
    15021498        }
    15031499        default {
     
    15841580}
    15851581
    1586 
    15871582#
    15881583# BuildColormap --
     
    15941589        set cmap "0.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0"
    15951590    }
    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)
    16001595
    16011596    set wmap "0.0 1.0 1.0 1.0"
     
    16081603itcl::configbody Rappture::VtkStreamlinesViewer::plotbackground {
    16091604    if { [isconnected] } {
    1610         foreach {r g b} [Color2RGB $itk_option(-plotbackground)] break
    1611         SendCmd "screen bgcolor $r $g $b"
     1605        set rgb [Color2RGB $itk_option(-plotbackground)]
     1606        SendCmd "screen bgcolor $rgb"
    16121607    }
    16131608}
     
    16181613itcl::configbody Rappture::VtkStreamlinesViewer::plotforeground {
    16191614    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"
    16231619    }
    16241620}
     
    16361632    checkbutton $inner.volume \
    16371633        -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] \
    16401636        -font "Arial 9"
    16411637
    16421638    checkbutton $inner.wireframe \
    16431639        -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] \
    16461642        -font "Arial 9"
    16471643
    16481644    checkbutton $inner.lighting \
    16491645        -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] \
    16521648        -font "Arial 9"
    16531649
    16541650    checkbutton $inner.edges \
    16551651        -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] \
    16581654        -font "Arial 9"
    16591655
    16601656    label $inner.opacity_l -text "Opacity" -font "Arial 9"
    16611657    ::scale $inner.opacity -from 0 -to 100 -orient horizontal \
    1662         -variable [itcl::scope _settings(volumeOpacity)] \
     1658        -variable [itcl::scope _settings(-volumeopacity)] \
    16631659        -width 10 \
    16641660        -showvalue off \
    1665         -command [itcl::code $this AdjustSetting volumeOpacity]
     1661        -command [itcl::code $this AdjustSetting -volumeopacity]
    16661662
    16671663    blt::table $inner \
     
    16701666        2,0 $inner.edges     -anchor w -pady 2 -cspan 3 \
    16711667        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
    16731669
    16741670    blt::table configure $inner r* c* -resize none
    16751671    blt::table configure $inner r4 c1 -resize expand
    16761672}
    1677 
    16781673
    16791674itcl::body Rappture::VtkStreamlinesViewer::BuildStreamsTab {} {
     
    16891684    checkbutton $inner.streamlines \
    16901685        -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] \
    16931688        -font "Arial 9"
    1694    
     1689
    16951690    checkbutton $inner.lighting \
    16961691        -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] \
    16991694        -font "Arial 9"
    17001695
    17011696    checkbutton $inner.seeds \
    17021697        -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] \
    17051700        -font "Arial 9"
    17061701
    1707     label $inner.mode_l -text "Mode" -font "Arial 9" 
     1702    label $inner.mode_l -text "Mode" -font "Arial 9"
    17081703    itk_component add streammode {
    17091704        Rappture::Combobox $inner.mode -width 10 -editable no
     
    17121707        "lines"    "lines" \
    17131708        "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]
    17171712
    17181713    label $inner.opacity_l -text "Opacity" -font "Arial 9"
    17191714    ::scale $inner.opacity -from 0 -to 100 -orient horizontal \
    1720         -variable [itcl::scope _settings(streamlinesOpacity)] \
     1715        -variable [itcl::scope _settings(-streamlinesopacity)] \
    17211716        -width 10 \
    17221717        -showvalue off \
    1723         -command [itcl::code $this AdjustSetting streamlinesOpacity]
     1718        -command [itcl::code $this AdjustSetting -streamlinesopacity]
    17241719
    17251720    label $inner.density_l -text "No. Seeds" -font "Arial 9"
    17261721    ::scale $inner.density -from 1 -to 1000 -orient horizontal \
    1727         -variable [itcl::scope _settings(streamlinesNumSeeds)] \
     1722        -variable [itcl::scope _settings(-streamlinesnumseeds)] \
    17281723        -width 10 \
    17291724        -showvalue on \
    1730         -command [itcl::code $this AdjustSetting streamlinesNumSeeds]
     1725        -command [itcl::code $this AdjustSetting -streamlinesnumseeds]
    17311726
    17321727    label $inner.scale_l -text "Scale" -font "Arial 9"
    17331728    ::scale $inner.scale -from 1 -to 100 -orient horizontal \
    1734         -variable [itcl::scope _settings(streamlinesScale)] \
     1729        -variable [itcl::scope _settings(-streamlinesscale)] \
    17351730        -width 10 \
    17361731        -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"
    17401735    itk_component add field {
    17411736        Rappture::Combobox $inner.field -width 10 -editable no
    17421737    }
    17431738    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"
    17471742    itk_component add colormap {
    17481743        Rappture::Combobox $inner.colormap -width 10 -editable no
     
    17521747    $itk_component(colormap) value "BCGYR"
    17531748    bind $inner.colormap <<Value>> \
    1754         [itcl::code $this AdjustSetting streamlinesColormap]
     1749        [itcl::code $this AdjustSetting -streamlinescolormap]
    17551750
    17561751    blt::table $inner \
     
    17831778
    17841779    checkbutton $inner.visible \
    1785         -text "Show Axes" \
    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] \
    17881783        -font "Arial 9"
    17891784
    17901785    checkbutton $inner.labels \
    1791         -text "Show Axis 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] \
    17941789        -font "Arial 9"
    1795 
     1790    label $inner.grid_l -text "Grid" -font "Arial 9"
    17961791    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] \
    18001795        -font "Arial 9"
    18011796    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] \
    18051800        -font "Arial 9"
    18061801    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] \
    18101805        -font "Arial 9"
    18111806    checkbutton $inner.minorticks \
    18121807        -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] \
    18151810        -font "Arial 9"
    18161811
    1817     label $inner.mode_l -text "Mode" -font "Arial 9" 
     1812    label $inner.mode_l -text "Mode" -font "Arial 9"
    18181813
    18191814    itk_component add axismode {
     
    18241819        "closest_triad"   "closest" \
    18251820        "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]
    18291824
    18301825    blt::table $inner \
     
    18621857        0,0 $inner.view_l -anchor e -pady 2 \
    18631858        0,1 $inner.view -anchor w -pady 2
     1859    blt::table configure $inner r0 -resize none
    18641860
    18651861    set labels { qx qy qz qw xpan ypan zoom }
     
    18681864        label $inner.${tag}label -text $tag -font "Arial 9"
    18691865        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}]
    18731871        blt::table $inner \
    18741872            $row,0 $inner.${tag}label -anchor e -pady 2 \
     
    18791877    checkbutton $inner.ortho \
    18801878        -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] \
    18831881        -font "Arial 9"
    18841882    blt::table $inner \
     
    18871885    incr row
    18881886
    1889     blt::table configure $inner c* r* -resize none
     1887    blt::table configure $inner c* -resize none
    18901888    blt::table configure $inner c2 -resize expand
    18911889    blt::table configure $inner r$row -resize expand
     
    18951893
    18961894    set fg [option get $itk_component(hull) font Font]
    1897    
     1895
    18981896    set inner [$itk_component(main) insert end \
    18991897        -title "Cutplane Settings" \
    1900         -icon [Rappture::icon cutbutton]] 
     1898        -icon [Rappture::icon cutbutton]]
    19011899
    19021900    $inner configure -borderwidth 4
     
    19041902    checkbutton $inner.visible \
    19051903        -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] \
    19081906        -font "Arial 9"
    19091907
    19101908    checkbutton $inner.wireframe \
    19111909        -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] \
    19141912        -font "Arial 9"
    19151913
    19161914    checkbutton $inner.lighting \
    19171915        -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] \
    19201918        -font "Arial 9"
    19211919
    19221920    checkbutton $inner.edges \
    19231921        -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] \
    19261924        -font "Arial 9"
    19271925
    19281926    label $inner.opacity_l -text "Opacity" -font "Arial 9"
    19291927    ::scale $inner.opacity -from 0 -to 100 -orient horizontal \
    1930         -variable [itcl::scope _settings(cutplaneOpacity)] \
     1928        -variable [itcl::scope _settings(-cutplaneopacity)] \
    19311929        -width 10 \
    19321930        -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)
    19351933
    19361934    # X-value slicer...
     
    19391937            -onimage [Rappture::icon x-cutplane-red] \
    19401938            -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)]
    19431941    }
    19441942    Rappture::Tooltip::for $itk_component(xCutButton) \
     
    19511949            -borderwidth 1 -highlightthickness 0 \
    19521950            -command [itcl::code $this EventuallySetCutplane x] \
    1953             -variable [itcl::scope _settings(cutplaneXPosition)] \
    1954             -foreground red3 -font "Arial 9 bold"
     1951            -variable [itcl::scope _settings(-cutplanexposition)] \
     1952            -foreground red3 -font "Arial 9 bold"
    19551953    } {
    19561954        usual
     
    19681966            -onimage [Rappture::icon y-cutplane-green] \
    19691967            -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)]
    19721970    }
    19731971    Rappture::Tooltip::for $itk_component(yCutButton) \
     
    19801978            -borderwidth 1 -highlightthickness 0 \
    19811979            -command [itcl::code $this EventuallySetCutplane y] \
    1982             -variable [itcl::scope _settings(cutplaneYPosition)] \
    1983             -foreground green3 -font "Arial 9 bold"
     1980            -variable [itcl::scope _settings(-cutplaneyposition)] \
     1981            -foreground green3 -font "Arial 9 bold"
    19841982    } {
    19851983        usual
     
    19971995            -onimage [Rappture::icon z-cutplane-blue] \
    19981996            -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)]
    20011999    }
    20022000    Rappture::Tooltip::for $itk_component(zCutButton) \
     
    20092007            -borderwidth 1 -highlightthickness 0 \
    20102008            -command [itcl::code $this EventuallySetCutplane z] \
    2011             -variable [itcl::scope _settings(cutplaneZPosition)] \
    2012             -foreground blue3 -font "Arial 9 bold"
     2009            -variable [itcl::scope _settings(-cutplanezposition)] \
     2010            -foreground blue3 -font "Arial 9 bold"
    20132011    } {
    20142012        usual
     
    20262024        3,0 $inner.opacity_l            -anchor w -pady 2 -cspan 1 \
    20272025        3,1 $inner.opacity              -fill x   -pady 2 -cspan 3 \
    2028         4,0 $itk_component(xCutButton)  -anchor w -padx 2 -pady 2 \
     2026        4,0 $itk_component(xCutButton)  -anchor w -padx 2 -pady 2 \
    20292027        5,0 $itk_component(yCutButton)  -anchor w -padx 2 -pady 2 \
    20302028        6,0 $itk_component(zCutButton)  -anchor w -padx 2 -pady 2 \
     
    20382036
    20392037#
    2040 #  camera -- 
     2038#  camera --
    20412039#
    20422040itcl::body Rappture::VtkStreamlinesViewer::camera {option args} {
    2043     switch -- $option { 
     2041    switch -- $option {
    20442042        "show" {
    20452043            puts [array get _view]
    20462044        }
    20472045        "set" {
    2048             set who [lindex $args 0]
    2049             set x $_view($who)
     2046            set what [lindex $args 0]
     2047            set x $_view($what)
    20502048            set code [catch { string is double $x } result]
    20512049            if { $code != 0 || !$result } {
    20522050                return
    20532051            }
    2054             switch -- $who {
    2055                 "ortho" {
    2056                     if {$_view(ortho)} {
     2052            switch -- $what {
     2053                "-ortho" {
     2054                    if {$_view($what)} {
    20572055                        SendCmd "camera mode ortho"
    20582056                    } else {
     
    20602058                    }
    20612059                }
    2062                 "xpan" - "ypan" {
     2060                "-xpan" - "-ypan" {
    20632061                    PanCamera
    20642062                }
    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]
    20672065                    $_arcball quaternion $q
    20682066                    EventuallyRotate $q
    20692067                }
    2070                 "zoom" {
    2071                     SendCmd "camera zoom $_view(zoom)"
     2068                "-zoom" {
     2069                    SendCmd "camera zoom $_view($what)"
    20722070                }
    20732071            }
     
    20892087
    20902088itcl::body Rappture::VtkStreamlinesViewer::GetImage { args } {
    2091     if { [image width $_image(download)] > 0 && 
     2089    if { [image width $_image(download)] > 0 &&
    20922090         [image height $_image(download)] > 0 } {
    20932091        set bytes [$_image(download) data -format "jpeg -quality 100"]
     
    21022100        -title "[Rappture::filexfer::label downloadWord] as..."
    21032101    set inner [$popup component inner]
    2104     label $inner.summary -text "" -anchor w 
     2102    label $inner.summary -text "" -anchor w
    21052103    radiobutton $inner.vtk_button -text "VTK data file" \
    21062104        -variable [itcl::scope _downloadPopup(format)] \
    21072105        -font "Helvetica 9 " \
    2108         -value vtk 
     2106        -value vtk
    21092107    Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file."
    21102108    radiobutton $inner.image_button -text "Image File" \
    21112109        -variable [itcl::scope _downloadPopup(format)] \
    2112         -value image 
     2110        -value image
    21132111    Rappture::Tooltip::for $inner.image_button \
    21142112        "Save as digital image."
     
    21312129        2,0 $inner.image_button -anchor w -cspan 2 -padx { 4 0 } \
    21322130        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
    21342132    blt::table configure $inner r3 -height 4
    21352133    blt::table configure $inner r4 -pady 4
     
    21722170    SendCmd "polydata add $tag"
    21732171    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]
    21792177    StopBufferingCommands
    21802178    SetColormap $dataobj $comp
     
    21982196    set _legendPending 0
    21992197    set _title $title
    2200     regsub {\(mag\)} $title "" _title 
     2198    regsub {\(mag\)} $title "" _title
    22012199    if { [IsConnected] } {
    22022200        set bytes [ReceiveBytes $size]
     
    22252223    set font "Arial 8"
    22262224    set lineht [font metrics $font -linespace]
    2227    
     2225
    22282226    if { [info exists _fields($fname)] } {
    22292227        foreach { title units } $_fields($fname) break
     
    22342232        set title $fname
    22352233    }
    2236     if { $_settings(legendVisible) } {
     2234    if { $_settings(-legendvisible) } {
    22372235        set x [expr $w - 2]
    22382236        if { [$c find withtag "legend"] == "" } {
    2239             set y 2 
     2237            set y 2
    22402238            $c create text $x $y \
    22412239                -anchor ne \
     
    23122310    set font "Arial 8"
    23132311    set lineht [font metrics $font -linespace]
    2314    
     2312
    23152313    set imgHeight [image height $_image(legend)]
    23162314    set coords [$c coords colormap]
     
    23352333    }
    23362334    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
    23392337    .rappturetooltip configure -icon $_image(swatch)
    23402338
     
    23472345        set value 0.0
    23482346    }
    2349     set tipx [expr $x + 15] 
     2347    set tipx [expr $x + 15]
    23502348    set tipy [expr $y - 5]
    23512349    Rappture::Tooltip::text $c "$title $value"
    2352     Rappture::Tooltip::tooltip show $c +$tipx,+$tipy   
     2350    Rappture::Tooltip::tooltip show $c +$tipx,+$tipy
    23532351}
    23542352
     
    23952393# ----------------------------------------------------------------------
    23962394itcl::body Rappture::VtkStreamlinesViewer::Combo {option} {
    2397     set c $itk_component(view) 
     2395    set c $itk_component(view)
    23982396    switch -- $option {
    23992397        post {
     
    24082406        }
    24092407        deactivate {
    2410             $c itemconfigure title -fill white 
     2408            $c itemconfigure title -fill white
    24112409        }
    24122410        invoke {
    24132411            $itk_component(field) value $_curFldLabel
    2414             AdjustSetting field
     2412            AdjustSetting -field
    24152413        }
    24162414        default {
     
    24202418}
    24212419
    2422 itcl::body Rappture::VtkStreamlinesViewer::SetOrientation { side } { 
     2420itcl::body Rappture::VtkStreamlinesViewer::SetOrientation { side } {
    24232421    array set positions {
    24242422        front "1 0 0 0"
     
    24292427        bottom "0.707107 0.707107 0 0"
    24302428    }
    2431     foreach name { qw qx qy qz } value $positions($side) {
     2429    foreach name { -qw -qx -qy -qz } value $positions($side) {
    24322430        set _view($name) $value
    2433     } 
    2434     set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
     2431    }
     2432    set q [ViewToQuaternion]
    24352433    $_arcball quaternion $q
    2436     SendCmd "camera orient $q" 
     2434    SendCmd "camera orient $q"
    24372435    SendCmd "camera reset"
    2438     set _view(xpan) 0
    2439     set _view(ypan) 0
    2440     set _view(zoom) 1.0
    2441 }
     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 -*-
    22# ----------------------------------------------------------------------
    33#  COMPONENT: vtksurfaceviewer - Vtk 3D boundary surface viewer
     
    5757    public method get {args}
    5858    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
    6261    }
    6362    public method scale {args}
    6463
    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 
    8164    # The following methods are only used by this class.
     65    private method AdjustSetting {what {value ""}}
    8266    private method BuildAxisTab {}
    8367    private method BuildCameraTab {}
    8468    private method BuildColormap { name }
    85     private method BuildDownloadPopup { widget command } 
     69    private method BuildDownloadPopup { widget command }
    8670    private method BuildSurfaceTab {}
    8771    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 {}
    8877    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 }
    9686    private method LeaveLegend {}
    97     private method MotionLegend { x y }
     87    private method MotionLegend { x y }
     88    private method Pan {option x y}
    9889    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 }
    9998    private method RequestLegend {}
     99    private method Rotate {option x y}
     100    private method SetCurrentColormap { color }
    100101    private method SetLegendTip { x y }
    101     private method SetObjectStyle { dataobj comp }
    102     private method SetCurrentColormap { color }
     102    private method SetObjectStyle { dataobj comp }
    103103    private method SetOrientation { side }
    104104    private method UpdateContourList {}
     105    private method ViewToQuaternion {} {
     106        return [list $_view(-qw) $_view(-qx) $_view(-qy) $_view(-qz)]
     107    }
     108    private method Zoom {option}
    105109
    106110    private variable _arcball ""
     
    109113    private variable _obj2datasets
    110114    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
    112116                                   ;    # datasets in the server
    113117    private variable _colormaps    ;    # contains all the colormaps
     
    144148    private variable _legendPending 0
    145149    private variable _field      ""
    146     private variable _colorMode "scalar";       #  Mode of colormap (vmag or 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
    149153    private variable _curFldName ""
    150154    private variable _curFldLabel ""
     
    188192    # Initialize the view to some default parameters.
    189193    array set _view {
    190         qw              0.853553
    191         qx              -0.353553
    192         qy              0.353553
    193         qz              0.146447
    194         zoom            1.0
    195         xpan            0
    196         ypan            0
    197         ortho           0
     194        -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
    198202    }
    199203    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]
    202205
    203206    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
    223228    }
    224229    array set _changed {
     
    238243    itk_component add fieldmenu {
    239244        menu $itk_component(plotarea).menu -bg black -fg white -relief flat \
    240             -tearoff 0 
     245            -tearoff 0
    241246    } {
    242247        usual
     
    258263
    259264    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
    262267    set _map(zoom) 1.0
    263268    set _map(original) ""
     
    306311            -offimage [Rappture::icon volume-off] \
    307312            -variable [itcl::scope _settings(-surfacevisible)] \
    308             -command [itcl::code $this AdjustSetting -surfacevisible] 
     313            -command [itcl::code $this AdjustSetting -surfacevisible]
    309314    }
    310315    $itk_component(surface) select
    311316    Rappture::Tooltip::for $itk_component(surface) \
    312         "Don't display the surface"
     317        "Hide the surface"
    313318    pack $itk_component(surface) -padx 2 -pady 2
    314319
     
    320325        puts stderr errs=$errs
    321326    }
     327
    322328    # Legend
    323 
    324329    set _image(legend) [image create photo]
    325330    itk_component add legend {
    326         canvas $itk_component(plotarea).legend -width 50 -highlightthickness 0 
     331        canvas $itk_component(plotarea).legend -width 50 -highlightthickness 0
    327332    } {
    328333        usual
     
    331336    }
    332337
    333     # Hack around the Tk panewindow.  The problem is that the requested 
     338    # Hack around the Tk panewindow.  The problem is that the requested
    334339    # size of the 3d view isn't set until an image is retrieved from
    335340    # the server.  So the panewindow uses the tiny size.
     
    337342    pack forget $itk_component(view)
    338343    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
    340345    blt::table configure $itk_component(plotarea) c1 -resize none
    341346
     
    424429
    425430itcl::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]"
    428432    set _rotatePending 0
    429433}
     
    449453
    450454itcl::body Rappture::VtkSurfaceViewer::EventuallyRotate { q } {
    451     foreach { _view(qw) _view(qx) _view(qy) _view(qz) } $q break
     455    QuaternionToView $q
    452456    if { !$_rotatePending } {
    453457        set _rotatePending 1
    454         global rotate_delay 
     458        global rotate_delay
    455459        $_dispatcher event -after $rotate_delay !rotate
    456460    }
     
    497501}
    498502
    499 
    500503# ----------------------------------------------------------------------
    501504# USAGE: delete ?<dataobj1> <dataobj2> ...?
     
    552555                    continue
    553556                }
    554                 if {[info exists _obj2ovride($dataobj-raise)] && 
     557                if {[info exists _obj2ovride($dataobj-raise)] &&
    555558                    $_obj2ovride($dataobj-raise)} {
    556559                    set dlist [linsert $dlist 0 $dataobj]
     
    580583            }
    581584            return $dlist
    582         }           
     585        }
    583586        -image {
    584587            if {[llength $args] != 2} {
     
    782785    # disconnected -- no more data sitting on server
    783786    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
    790792}
    791793
     
    807809    if { $info(-type) == "image" } {
    808810        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
    811814            close $f
    812815        }
     
    816819        #set w [image width $_image(plot)]
    817820        #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"
    819822        if { $_start > 0 } {
    820823            set finish [clock clicks -milliseconds]
     
    887890    # Turn on buffering of commands to the server.  We don't want to
    888891    # be preempted by a server disconnect/reconnect (which automatically
    889     # generates a new call to Rebuild).   
     892    # generates a new call to Rebuild).
    890893    StartBufferingCommands
    891894
     
    895898        $_arcball resize $w $h
    896899        DoResize
    897         #
    898900        # 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)} {
    903903            SendCmd "camera mode ortho"
    904904        } else {
     
    908908        PanCamera
    909909        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"
    915913        StopBufferingCommands
    916914        SendCmd "imgflush"
     
    928926            if { ![info exists _datasets($tag)] } {
    929927                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
    934933                }
    935934                set length [string length $bytes]
    936935                if { $_reportClientInfo }  {
    937936                    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]
    942942                    lappend info "dataset_label" [$dataobj hints label]
    943943                    lappend info "dataset_size"  $length
     
    945945                    SendCmd "clientinfo [list $info]"
    946946                }
    947                 append _outbuf "dataset add $tag data follows $length\n"
     947                SendCmd "dataset add $tag data follows $length"
    948948                append _outbuf $bytes
    949949                set _datasets($tag) 1
     
    954954                # Setting dataset visible enables outline
    955955                # and contour2d
    956                 SendCmd "dataset visible 1 $tag"
     956                SendCmd "dataset visible 1 $tag"
    957957            }
    958958        }
     
    960960
    961961    if { $_first != "" } {
    962         $itk_component(field) choices delete 0 end
    963         $itk_component(fieldmenu) delete 0 end
    964         array unset _fields
     962        $itk_component(field) choices delete 0 end
     963        $itk_component(fieldmenu) delete 0 end
     964        array unset _fields
    965965        set _curFldName ""
    966966        foreach cname [$_first components] {
     
    990990    InitSettings -isolinesvisible -surfacevisible -outline
    991991    if { $_reset } {
    992         # These are settings that rely on a dataset being loaded.
     992        # These are settings that rely on a dataset being loaded.
    993993        InitSettings \
    994994            -surfacelighting \
    995995            -field \
    996996            -surfaceedges -surfacelighting -surfaceopacity \
    997             -surfacewireframe \
     997            -surfacewireframe \
    998998            -numcontours
    999999
    10001000        Zoom reset
    1001         foreach axis { x y z } {
     1001        foreach axis { x y z } {
    10021002            # Another problem fixed by a <view>. We looking into a data
    10031003            # object for the name of the axes. This should be global to
    10041004            # the viewer itself.
    1005             set label [$_first hints ${axis}label]
    1006             if { $label == "" } {
     1005            set label [$_first hints ${axis}label]
     1006            if { $label == "" } {
    10071007                set label [string toupper $axis]
    1008             }
    1009             # May be a space in the axis label.
    1010             SendCmd [list axis name $axis $label]
     1008            }
     1009            # May be a space in the axis label.
     1010            SendCmd [list axis name $axis $label]
    10111011        }
    10121012        if { [array size _fields] < 2 } {
     
    10321032itcl::body Rappture::VtkSurfaceViewer::CurrentDatasets {args} {
    10331033    set flag [lindex $args 0]
    1034     switch -- $flag { 
     1034    switch -- $flag {
    10351035        "-all" {
    10361036            if { [llength $args] > 1 } {
     
    10511051                set dlist [get -visible]
    10521052            }
    1053         }           
     1053        }
    10541054        default {
    10551055            set dlist $args
     
    10791079    switch -- $option {
    10801080        "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)"
    10831083        }
    10841084        "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)"
    10871087        }
    10881088        "reset" {
    10891089            array set _view {
    1090                 qw     0.853553
    1091                 qx     -0.353553
    1092                 qy     0.353553
    1093                 qz     0.146447
    1094                 zoom   1.0
    1095                 xpan   0
    1096                 ypan   0
     1090                -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
    10971097            }
    10981098            if { $_first != "" } {
     
    11021102                }
    11031103            }
    1104             set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    1105             $_arcball quaternion $q
     1104            $_arcball quaternion [ViewToQuaternion]
    11061105            DoRotate
    11071106            SendCmd "camera reset"
     
    11111110
    11121111itcl::body Rappture::VtkSurfaceViewer::PanCamera {} {
    1113     set x $_view(xpan)
    1114     set y $_view(ypan)
     1112    set x $_view(-xpan)
     1113    set y $_view(-ypan)
    11151114    SendCmd "camera pan $x $y"
    11161115}
    1117 
    11181116
    11191117# ----------------------------------------------------------------------
     
    11711169itcl::body Rappture::VtkSurfaceViewer::Pick {x y} {
    11721170    foreach tag [CurrentDatasets -visible] {
    1173         SendCmdNoSplash "dataset getscalar pixel $x $y $tag"
    1174     } 
     1171        SendCmd "dataset getscalar pixel $x $y $tag"
     1172    }
    11751173}
    11761174
     
    11901188            set x [expr $x / double($w)]
    11911189            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]
    11941192            PanCamera
    11951193            return
     
    12131211            set _click(x) $x
    12141212            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]
    12171215            PanCamera
    12181216        }
     
    12561254    }
    12571255    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             DrawLegend
    1269         }
    12701256        "-axesvisible" {
    12711257            set bool $_settings($what)
     
    12791265            set bool $_settings($what)
    12801266            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"
    12861267        }
    12871268        "-axismode" {
     
    12911272            SendCmd "axis flymode $mode"
    12921273        }
     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        }
    12931286        "-colormap" {
    12941287            set _changed($what) 1
     
    12961289            set color [$itk_component(colormap) value]
    12971290            set _settings($what) $color
    1298             if { $color == "none" } {
    1299                 if { $_settings(-colormapvisible) } {
    1300                     SendCmd "contour2d colormode constant {}"
     1291            if { $color == "none" } {
     1292                if { $_settings(-colormapvisible) } {
     1293                    SendCmd "contour2d colormode constant {}"
    13011294                    SendCmd "polydata colormode constant {}"
    1302                     set _settings(-colormapvisible) 0
    1303                 }
    1304             } else {
    1305                 if { !$_settings(-colormapvisible) } {
    1306                     #SendCmd "contour2d colormode $_colorMode $_curFldName"
     1295                    set _settings(-colormapvisible) 0
     1296                }
     1297            } else {
     1298                if { !$_settings(-colormapvisible) } {
     1299                    #SendCmd "contour2d colormode $_colorMode $_curFldName"
    13071300                    SendCmd "polydata colormode $_colorMode $_curFldName"
    1308                     set _settings(-colormapvisible) 1
    1309                 }
    1310                 SetCurrentColormap $color
     1301                    set _settings(-colormapvisible) 1
     1302                }
     1303                SetCurrentColormap $color
    13111304                if {$_settings(-colormapdiscrete)} {
    13121305                    set numColors [expr $_settings(-numcontours) + 1]
    13131306                    SendCmd "colormap res $numColors $color"
    13141307                }
    1315             }
     1308            }
    13161309            StopBufferingCommands
    1317             EventuallyRequestLegend
     1310            EventuallyRequestLegend
    13181311        }
    13191312        "-colormapdiscrete" {
     
    13331326            EventuallyRequestLegend
    13341327        }
     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        }
    13351374        "-numcontours" {
    13361375            set _settings($what) [$itk_component(numcontours) value]
     
    13471386            }
    13481387        }
    1349         "-surfacewireframe" {
     1388        "-outline" {
    13501389            set bool $_settings($what)
    1351             SendCmd "polydata wireframe $bool"
    1352         }
    1353         "-isolinesvisible" {
     1390            SendCmd "outline visible $bool"
     1391        }
     1392        "-surfaceedges" {
    13541393            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"
    13571404        }
    13581405        "-surfacevisible" {
    13591406            set bool $_settings($what)
    1360             SendCmd "polydata visible $bool"
     1407            SendCmd "polydata visible $bool"
    13611408            if { $bool } {
    13621409                Rappture::Tooltip::for $itk_component(surface) \
     
    13661413                    "Show the surface"
    13671414            }
    1368             DrawLegend
    1369         }
    1370         "-surfacelighting" {
     1415            DrawLegend
     1416        }
     1417        "-surfacewireframe" {
    13711418            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]]
    13751423            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"
    14271425        }
    14281426        default {
     
    14321430}
    14331431
    1434 
    14351432#
    14361433# RequestLegend --
    14371434#
    14381435#       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.
    14401437#
    14411438# This should be called when
    1442 #       1.  A new current colormap is set.
    1443 #       2.  Window is resized.
    1444 #       3.  The limits of the data have changed.  (Just need a redraw).
    1445 #       4.  Number of isolines have changed. (Just need a redraw).
    1446 #       5.  Legend becomes visible (Just need a redraw).
     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).
    14471444#
    14481445itcl::body Rappture::VtkSurfaceViewer::RequestLegend {} {
     
    14601457    }
    14611458    if { [string match "component*" $fname] } {
    1462         set title ""
     1459        set title ""
    14631460    } else {
    1464         if { [info exists _fields($fname)] } {
    1465             foreach { title units } $_fields($fname) break
    1466             if { $units != "" } {
    1467                 set title [format "%s (%s)" $title $units]
    1468             }
    1469         } else {
    1470             set title $fname
    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        }
    14721469    }
    14731470    # If there's a title too, subtract one more line
    14741471    if { $title != "" } {
    1475         incr h -$lineht 
     1472        incr h -$lineht
    14761473    }
    14771474    # Set the legend on the first heightmap dataset.
    14781475    if { $_currentColormap != ""  } {
    1479         set cmap $_currentColormap
    1480         SendCmdNoWait "legend $cmap scalar $_curFldName {} $w $h 0"
     1476        set cmap $_currentColormap
     1477        SendCmdNoWait "legend $cmap scalar $_curFldName {} $w $h 0"
    14811478    }
    14821479}
     
    14981495    if { [isconnected] } {
    14991496        set rgb [Color2RGB $itk_option(-plotforeground)]
    1500         SendCmd "axis color all $rgb"
     1497        SendCmd "axis color all $rgb"
    15011498        SendCmd "outline color $rgb"
    15021499    }
    1503 }
    1504 
    1505 itcl::body Rappture::VtkSurfaceViewer::limits { dataobj } {
    1506     foreach { limits(xmin) limits(xmax) } [$dataobj limits x] break
    1507     foreach { limits(ymin) limits(ymax) } [$dataobj limits y] break
    1508     foreach { limits(zmin) limits(zmax) } [$dataobj limits z] break
    1509     foreach { limits(vmin) limits(vmax) } [$dataobj limits v] break
    1510     return [array get limits]
    15111500}
    15121501
     
    15691558        -font "Arial 9"
    15701559
    1571     label $inner.linecolor_l -text "Isolines" -font "Arial 9" 
     1560    label $inner.linecolor_l -text "Isolines" -font "Arial 9"
    15721561    itk_component add isolineColor {
    15731562        Rappture::Combobox $inner.linecolor -width 10 -editable 0
     
    15831572        "red"                "red"              \
    15841573        "white"              "white"            \
    1585         "none"               "none"
     1574        "none"               "none"
    15861575
    15871576    $itk_component(isolineColor) value "white"
    15881577    bind $inner.linecolor <<Value>> \
    1589         [itcl::code $this AdjustSetting -isolinecolor]
    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"
    15921581    itk_component add background {
    15931582        Rappture::Combobox $inner.background -width 10 -editable 0
     
    15961585        "black"              "black"            \
    15971586        "white"              "white"            \
    1598         "grey"               "grey"             
     1587        "grey"               "grey"
    15991588
    16001589    $itk_component(background) value $_settings(-background)
     
    16101599
    16111600    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"
    16131602    } {
    16141603        ignore -font
     
    16201609        [itcl::code $this AdjustSetting -field]
    16211610
    1622     label $inner.colormap_l -text "Colormap" -font "Arial 9" 
     1611    label $inner.colormap_l -text "Colormap" -font "Arial 9"
    16231612    itk_component add colormap {
    16241613        Rappture::Combobox $inner.colormap -width 10 -editable 0
     
    16461635        2,0 $inner.linecolor_l  -anchor w -pady 2  \
    16471636        2,1 $inner.linecolor    -anchor w -pady 2 -fill x  \
    1648         3,0 $inner.background_l -anchor w -pady 2 \
    1649         3,1 $inner.background -anchor w -pady 2  -fill x \
     1637        3,0 $inner.background_l -anchor w -pady 2 \
     1638        3,1 $inner.background -anchor w -pady 2  -fill x \
    16501639        4,0 $inner.numcontours_l -anchor w -pady 2 \
    16511640        4,1 $inner.numcontours -anchor w -pady 2 \
     
    16751664
    16761665    checkbutton $inner.visible \
    1677         -text "Show Axes" \
     1666        -text "Axes" \
    16781667        -variable [itcl::scope _settings(-axesvisible)] \
    16791668        -command [itcl::code $this AdjustSetting -axesvisible] \
     
    16811670
    16821671    checkbutton $inner.labels \
    1683         -text "Show Axis Labels" \
    1684         -variable [itcl::scope _settings(-axislabelsvisible)] \
    1685         -command [itcl::code $this AdjustSetting -axislabelsvisible] \
     1672        -text "Axis Labels" \
     1673        -variable [itcl::scope _settings(-axislabels)] \
     1674        -command [itcl::code $this AdjustSetting -axislabels] \
    16861675        -font "Arial 9"
    1687 
    1688     checkbutton $inner.gridx \
    1689         -text "Show X Grid" \
    1690         -variable [itcl::scope _settings(-xaxisgrid)] \
    1691         -command [itcl::code $this AdjustSetting -xaxisgrid] \
     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] \
    16921681        -font "Arial 9"
    1693     checkbutton $inner.gridy \
    1694         -text "Show Y Grid" \
    1695         -variable [itcl::scope _settings(-yaxisgrid)] \
    1696         -command [itcl::code $this AdjustSetting -yaxisgrid] \
     1682    checkbutton $inner.ygrid \
     1683        -text "Y" \
     1684        -variable [itcl::scope _settings(-ygrid)] \
     1685        -command [itcl::code $this AdjustSetting -ygrid] \
    16971686        -font "Arial 9"
    1698     checkbutton $inner.gridz \
    1699         -text "Show Z Grid" \
    1700         -variable [itcl::scope _settings(-zaxisgrid)] \
    1701         -command [itcl::code $this AdjustSetting -zaxisgrid] \
     1687    checkbutton $inner.zgrid \
     1688        -text "Z" \
     1689        -variable [itcl::scope _settings(-zgrid)] \
     1690        -command [itcl::code $this AdjustSetting -zgrid] \
    17021691        -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"
    17051699
    17061700    itk_component add axisMode {
     
    17111705        "closest_triad"   "closest" \
    17121706        "furthest_triad"  "farthest" \
    1713         "outer_edges"     "outer"         
    1714     $itk_component(axisMode) value "static"
     1707        "outer_edges"     "outer"
     1708    $itk_component(axisMode) value $_settings(-axismode)
    17151709    bind $inner.mode <<Value>> [itcl::code $this AdjustSetting -axismode]
    17161710
    17171711    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
    17251721
    17261722    blt::table configure $inner r* c* -resize none
    1727     blt::table configure $inner r7 c1 -resize expand
    1728 }
    1729 
     1723    blt::table configure $inner r7 c6 -resize expand
     1724    blt::table configure $inner r3 -height 0.125i
     1725}
    17301726
    17311727itcl::body Rappture::VtkSurfaceViewer::BuildCameraTab {} {
     
    17471743        0,0 $inner.view_l -anchor e -pady 2 \
    17481744        0,1 $inner.view -anchor w -pady 2
     1745    blt::table configure $inner r0 -resize none
    17491746
    17501747    set labels { qx qy qz qw xpan ypan zoom }
     
    17531750        label $inner.${tag}label -text $tag -font "Arial 9"
    17541751        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}]
    17581757        blt::table $inner \
    17591758            $row,0 $inner.${tag}label -anchor e -pady 2 \
     
    17641763    checkbutton $inner.ortho \
    17651764        -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] \
    17681767        -font "Arial 9"
    17691768    blt::table $inner \
     
    17721771    incr row
    17731772
    1774     blt::table configure $inner c* r* -resize none
     1773    blt::table configure $inner c* -resize none
    17751774    blt::table configure $inner c2 -resize expand
    17761775    blt::table configure $inner r$row -resize expand
     
    17781777
    17791778#
    1780 #  camera -- 
     1779#  camera --
    17811780#
    17821781itcl::body Rappture::VtkSurfaceViewer::camera {option args} {
    1783     switch -- $option { 
     1782    switch -- $option {
    17841783        "show" {
    17851784            puts [array get _view]
    17861785        }
    17871786        "set" {
    1788             set who [lindex $args 0]
    1789             set x $_view($who)
     1787            set what [lindex $args 0]
     1788            set x $_view($what)
    17901789            set code [catch { string is double $x } result]
    17911790            if { $code != 0 || !$result } {
    17921791                return
    17931792            }
    1794             switch -- $who {
    1795                 "ortho" {
    1796                     if {$_view(ortho)} {
     1793            switch -- $what {
     1794                "-ortho" {
     1795                    if {$_view($what)} {
    17971796                        SendCmd "camera mode ortho"
    17981797                    } else {
     
    18001799                    }
    18011800                }
    1802                 "xpan" - "ypan" {
     1801                "-xpan" - "-ypan" {
    18031802                    PanCamera
    18041803                }
    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]
    18071806                    $_arcball quaternion $q
    18081807                    EventuallyRotate $q
    18091808                }
    1810                 "zoom" {
    1811                     SendCmd "camera zoom $_view(zoom)"
     1809                "-zoom" {
     1810                    SendCmd "camera zoom $_view($what)"
    18121811                }
    18131812             }
     
    18291828
    18301829itcl::body Rappture::VtkSurfaceViewer::GetImage { args } {
    1831     if { [image width $_image(download)] > 0 && 
     1830    if { [image width $_image(download)] > 0 &&
    18321831         [image height $_image(download)] > 0 } {
    18331832        set bytes [$_image(download) data -format "jpeg -quality 100"]
     
    18421841        -title "[Rappture::filexfer::label downloadWord] as..."
    18431842    set inner [$popup component inner]
    1844     label $inner.summary -text "" -anchor w 
     1843    label $inner.summary -text "" -anchor w
    18451844    radiobutton $inner.vtk_button -text "VTK data file" \
    18461845        -variable [itcl::scope _downloadPopup(format)] \
    18471846        -font "Arial 9 " \
    1848         -value vtk 
     1847        -value vtk
    18491848    Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file."
    18501849    radiobutton $inner.image_button -text "Image File" \
    18511850        -variable [itcl::scope _downloadPopup(format)] \
    18521851        -font "Arial 9 " \
    1853         -value image 
     1852        -value image
    18541853    Rappture::Tooltip::for $inner.image_button \
    18551854        "Save as digital image."
     
    18721871        2,0 $inner.image_button -anchor w -cspan 2 -padx { 4 0 } \
    18731872        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
    18751874    blt::table configure $inner r3 -height 4
    18761875    blt::table configure $inner r4 -pady 4
     
    18991898    array set style [$dataobj style $comp]
    19001899    if { $dataobj != $_first || $style(-levels) == 1 } {
    1901         set style(-opacity) 1
     1900        set style(-opacity) 1.0
    19021901    }
    19031902
     
    19331932    set _settings(-isolinesvisible) $style(-isolinesvisible)
    19341933    set _settings(-surfacevisible) $style(-surfacevisible)
    1935  
     1934
    19361935    SendCmd "outline add $tag"
    19371936    SendCmd "outline color [Color2RGB $itk_option(-plotforeground)] $tag"
     
    19491948    SendCmd "polydata opacity $style(-opacity) $tag"
    19501949    set _settings(-surfaceopacity) [expr $style(-opacity) * 100.0]
    1951     SetCurrentColormap $style(-color) 
     1950    SetCurrentColormap $style(-color)
    19521951    SendCmd "polydata wireframe $style(-wireframe) $tag"
    19531952    set _settings(-surfacewireframe) $style(-wireframe)
     
    20042003    set font "Arial 8"
    20052004    set lineht [font metrics $font -linespace]
    2006    
     2005
    20072006    set ih [image height $_image(legend)]
    20082007    set iy [expr $y - ($lineht + 2)]
    20092008
    20102009    if { [string match "component*" $fname] } {
    2011         set title ""
     2010        set title ""
    20122011    } else {
    2013         if { [info exists _fields($fname)] } {
    2014             foreach { title units } $_fields($fname) break
    2015             if { $units != "" } {
    2016                 set title [format "%s (%s)" $title $units]
    2017             }
    2018         } else {
    2019             set title $fname
    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        }
    20212020    }
    20222021    # If there's a legend title, increase the offset by the line height.
     
    20322031    }
    20332032    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
    20362035    .rappturetooltip configure -icon $_image(swatch)
    20372036
     
    20442043        set value 0.0
    20452044    }
    2046     set tx [expr $x + 15] 
     2045    set tx [expr $x + 15]
    20472046    set ty [expr $y - 5]
    20482047    if { [info exists _isolines($y)] } {
     
    20512050        Rappture::Tooltip::text $c [format "$title %g" $value]
    20522051    }
    2053     Rappture::Tooltip::tooltip show $c +$tx,+$ty   
    2054 }
    2055 
    2056 #
    2057 # ReceiveLegend -- 
    2058 #
    2059 #       Invoked automatically whenever the "legend" command comes in from
    2060 #       the rendering server.  Indicates that binary image data with the
    2061 #       specified <size> will follow.
     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.
    20622061#
    20632062itcl::body Rappture::VtkSurfaceViewer::ReceiveLegend { colormap title min max size } {
    20642063    #puts stderr "ReceiveLegend colormap=$colormap title=$title range=$min,$max size=$size"
    20652064    set _title $title
    2066     regsub {\(mag\)} $title "" _title 
     2065    regsub {\(mag\)} $title "" _title
    20672066    if { [IsConnected] } {
    20682067        set bytes [ReceiveBytes $size]
     
    20732072        #puts stderr "read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>"
    20742073        if { [catch {DrawLegend} errs] != 0 } {
    2075             global errorInfo
    2076             puts stderr "errs=$errs errorInfo=$errorInfo"
     2074            global errorInfo
     2075            puts stderr "errs=$errs errorInfo=$errorInfo"
    20772076        }
    20782077    }
     
    20932092
    20942093    if { [string match "component*" $fname] } {
    2095         set title ""
     2094        set title ""
    20962095    } else {
    2097         if { [info exists _fields($fname)] } {
    2098             foreach { title units } $_fields($fname) break
    2099             if { $units != "" } {
    2100                 set title [format "%s (%s)" $title $units]
    2101             }
    2102         } else {
    2103             set title $fname
    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        }
    21052104    }
    21062105    set x [expr $w - 2]
    21072106    if { !$_settings(-legendvisible) } {
    2108         $c delete legend
    2109         return
    2110     } 
     2107        $c delete legend
     2108        return
     2109    }
    21112110    if { [$c find withtag "legend"] == "" } {
    2112         set y 2
    2113         # If there's a legend title, create a text item for the title.
     2111        set y 2
     2112        # If there's a legend title, create a text item for the title.
    21142113        $c create text $x $y \
    2115             -anchor ne \
    2116             -fill $itk_option(-plotforeground) -tags "title legend" \
    2117             -font $font
     2114            -anchor ne \
     2115            -fill $itk_option(-plotforeground) -tags "title legend" \
     2116            -font $font
    21182117        if { $title != "" } {
    21192118            incr y $lineht
    21202119        }
    2121         $c create text $x $y \
    2122             -anchor ne \
    2123             -fill $itk_option(-plotforeground) -tags "vmax legend" \
    2124             -font $font
    2125         incr y $lineht
    2126         $c create image $x $y \
    2127             -anchor ne \
    2128             -image $_image(legend) -tags "colormap legend"
    2129         $c create rectangle $x $y 1 1 \
    2130             -fill "" -outline "" -tags "sensor legend"
    2131         $c create text $x [expr {$h-2}] \
    2132             -anchor se \
    2133             -fill $itk_option(-plotforeground) -tags "vmin legend" \
    2134             -font $font
    2135         $c bind sensor <Enter> [itcl::code $this EnterLegend %x %y]
    2136         $c bind sensor <Leave> [itcl::code $this LeaveLegend]
    2137         $c bind sensor <Motion> [itcl::code $this MotionLegend %x %y]
     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]
    21382137    }
    21392138    $c delete isoline
     
    21542153        }
    21552154        set tags "isoline legend"
    2156         set offset [expr 2 + $lineht]
    2157         if { $title != "" } {
    2158             incr offset $lineht
    2159         }
     2155        set offset [expr 2 + $lineht]
     2156        if { $title != "" } {
     2157            incr offset $lineht
     2158        }
    21602159        foreach value $_contourList {
    21612160            set norm [expr 1.0 - (($value - $vmin) / $range)]
     
    21762175    if { [info exists _limits($_curFldName)] } {
    21772176        foreach { vmin vmax } $_limits($_curFldName) break
    2178         $c itemconfigure vmin -text [format %g $vmin]
    2179         $c itemconfigure vmax -text [format %g $vmax]
     2177        $c itemconfigure vmin -text [format %g $vmin]
     2178        $c itemconfigure vmax -text [format %g $vmax]
    21802179    }
    21812180    set y 2
     
    21832182    if { $title != "" } {
    21842183        $c itemconfigure title -text $title
    2185         $c coords title $x $y
    2186         incr y $lineht
     2184        $c coords title $x $y
     2185        incr y $lineht
    21872186        $c raise title
    21882187    }
     
    22072206# ----------------------------------------------------------------------
    22082207itcl::body Rappture::VtkSurfaceViewer::Combo {option} {
    2209     set c $itk_component(view) 
     2208    set c $itk_component(view)
    22102209    switch -- $option {
    22112210        post {
     
    22222221        }
    22232222        deactivate {
    2224             $c itemconfigure title -fill $itk_option(-plotforeground) 
     2223            $c itemconfigure title -fill $itk_option(-plotforeground)
    22252224        }
    22262225        invoke {
     
    22402239    # Keep track of the colormaps that we build.
    22412240    if { ![info exists _colormaps($name)] } {
    2242         BuildColormap $name 
     2241        BuildColormap $name
    22432242        set _colormaps($name) 1
    22442243    }
     
    22622261}
    22632262
    2264 itcl::body Rappture::VtkSurfaceViewer::SetOrientation { side } { 
     2263itcl::body Rappture::VtkSurfaceViewer::SetOrientation { side } {
    22652264    array set positions {
    22662265        front "1 0 0 0"
     
    22712270        bottom "0.707107 0.707107 0 0"
    22722271    }
    2273     foreach name { qw qx qy qz } value $positions($side) {
     2272    foreach name { -qw -qx -qy -qz } value $positions($side) {
    22742273        set _view($name) $value
    2275     } 
    2276     set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
     2274    }
     2275    set q [ViewToQuaternion]
    22772276    $_arcball quaternion $q
    22782277    SendCmd "camera orient $q"
    22792278    SendCmd "camera reset"
    2280     set _view(xpan) 0
    2281     set _view(ypan) 0
    2282     set _view(zoom) 1.0
    2283 }
    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
     2284itcl::body Rappture::VtkSurfaceViewer::UpdateContourList {} {
    22862285    if { ![info exists _limits($_curFldName)] } {
    22872286        return
     
    22982297    blt::vector destroy $v
    22992298}
    2300 
  • branches/uq/gui/scripts/vtkviewer.tcl

    r4798 r5121  
    1 # -*- mode: tcl; indent-tabs-mode: nil -*- 
     1# -*- mode: tcl; indent-tabs-mode: nil -*-
    22# ----------------------------------------------------------------------
    33#  COMPONENT: vtkviewer - Vtk drawing object viewer
     
    5858    public method isconnected {}
    5959    public method limits { dataobj }
    60     public method parameters {title args} { 
    61         # do nothing 
     60    public method parameters {title args} {
     61        # do nothing
    6262    }
    6363    public method scale {args}
    6464
    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 
    8165    # The following methods are only used by this class.
     66    private method AdjustSetting {what {value ""}}
    8267    private method BuildAxisTab {}
    8368    private method BuildCameraTab {}
    8469    private method BuildColormap { name styles }
    8570    private method BuildCutawayTab {}
    86     private method BuildDownloadPopup { widget command } 
     71    private method BuildDownloadPopup { widget command }
    8772    private method BuildGlyphsTab {}
    8873    private method BuildMoleculeTab {}
    8974    private method BuildPolydataTab {}
    9075    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 {}
    9181    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 }
    10495    private method LeaveLegend {}
    105     private method MotionLegend { x y }
     96    private method MotionLegend { x y }
     97    private method Pan {option x y}
    10698    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 }
    107107    private method RequestLegend {}
     108    private method Rotate {option x y}
    108109    private method SetAtomScale {}
    109110    private method SetBondScale {}
     
    113114    private method SetMoleculeOpacity {}
    114115    private method SetMoleculeQuality {}
    115     private method SetObjectStyle { dataobj comp } 
     116    private method SetObjectStyle { dataobj comp }
    116117    private method SetOpacity { dataset }
    117118    private method SetOrientation { side }
    118119    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}
    120125
    121126    private variable _arcball ""
    122     private variable _dlist "";         # list of data objects
     127    private variable _dlist "";         # list of data objects
    123128    private variable _obj2datasets
    124     private variable _obj2ovride;       # maps dataobj => style override
    125     private variable _datasets;         # contains all the dataobj-component
    126                                         # datasets in the server
    127     private variable _colormaps;        # contains all the colormaps
    128                                         # in the server.
    129     private variable _dataset2style;    # maps dataobj-component to transfunc
    130     private variable _style2datasets;   # maps tf back to list of
    131                                         # dataobj-components using the tf.
     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.
    132137    private variable _click;            # info used for rotate operations
    133138    private variable _limits;           # autoscale min/max for all axes
     
    220225    # Populate parser with commands handle incoming requests
    221226    #
    222     $_parser alias image    [itcl::code $this ReceiveImage]
    223     $_parser alias dataset  [itcl::code $this ReceiveDataset]
    224     $_parser alias legend   [itcl::code $this ReceiveLegend]
     227    $_parser alias image [itcl::code $this ReceiveImage]
     228    $_parser alias dataset [itcl::code $this ReceiveDataset]
     229    $_parser alias legend [itcl::code $this ReceiveLegend]
    225230
    226231    # Initialize the view to some default parameters.
    227232    array set _view {
    228         qw              0.853553
    229         qx              -0.353553
    230         qy              0.353553
    231         qz              0.146447
    232         zoom            1.0
    233         xpan            0
    234         ypan            0
    235         ortho           0
     233        -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
    236241    }
    237242    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]
    240244
    241245    set _limits(zmin) 0.0
     
    243247
    244248    array set _axis [subst {
     249        labels          1
     250        minorticks      1
     251        visible         1
    245252        xgrid           0
    246253        ygrid           0
     
    255262        ydirection      -1
    256263        zdirection      -1
    257         visible         1
    258         labels          1
    259         minorticks      1
    260264    }]
    261265    array set _settings [subst {
    262         legend                  1
    263266        glyphs-edges            0
    264267        glyphs-lighting         1
     
    268271        glyphs-visible          1
    269272        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
    277275        molecule-atomscale      0.3
     276        molecule-bonds-visible  1
    278277        molecule-bondscale      0.075
    279278        molecule-bondstyle      "cylinder"
    280         molecule-atoms-visible  1
    281         molecule-bonds-visible  1
    282279        molecule-edges          0
    283280        molecule-labels         0
     
    291288        molecule-visible        1
    292289        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
    293297    }]
    294298    itk_component add view {
     
    315319
    316320    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
    319323    set _map(zoom) 1.0
    320324    set _map(original) ""
     
    358362    Rappture::Tooltip::for $itk_component(zoomout) "Zoom out"
    359363
    360     BuildAxisTab
    361     #BuildCutawayTab
    362     BuildCameraTab
     364    if { [catch {
     365        BuildAxisTab
     366        #BuildCutawayTab
     367        BuildCameraTab
     368    } errs] != 0 } {
     369        puts stderr errs=$errs
     370    }
    363371
    364372    # Legend
    365 
    366373    set _image(legend) [image create photo]
    367374    itk_component add legend {
    368         canvas $itk_component(plotarea).legend -width 50 -highlightthickness 0 
     375        canvas $itk_component(plotarea).legend -width 50 -highlightthickness 0
    369376    } {
    370377        usual
     
    373380    }
    374381
    375     # Hack around the Tk panewindow.  The problem is that the requested 
     382    # Hack around the Tk panewindow.  The problem is that the requested
    376383    # size of the 3d view isn't set until an image is retrieved from
    377384    # the server.  So the panewindow uses the tiny size.
     
    379386    pack forget $itk_component(view)
    380387    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
    382389    blt::table configure $itk_component(plotarea) c1 -resize none
    383390
     
    389396    bind $itk_component(view) <ButtonRelease-1> \
    390397        [itcl::code $this Rotate release %x %y]
    391     bind $itk_component(view) <Configure> \
    392         [itcl::code $this EventuallyResize %w %h]
    393398
    394399    # Bindings for panning via mouse
     
    468473
    469474itcl::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]"
    472476    set _rotatePending 0
    473477}
     
    484488
    485489itcl::body Rappture::VtkViewer::EventuallyRotate { q } {
    486     foreach { _view(qw) _view(qx) _view(qy) _view(qz) } $q break
     490    QuaternionToView $q
    487491    if { !$_rotatePending } {
    488492        set _rotatePending 1
     
    670674                    continue
    671675                }
    672                 if {[info exists _obj2ovride($dataobj-raise)] && 
     676                if {[info exists _obj2ovride($dataobj-raise)] &&
    673677                    $_obj2ovride($dataobj-raise)} {
    674678                    set dlist [linsert $dlist 0 $dataobj]
     
    698702            }
    699703            return $dlist
    700         }           
     704        }
    701705        -image {
    702706            if {[llength $args] != 2} {
     
    920924
    921925    # 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
    925930    global readyForNextFrame
    926931    set readyForNextFrame 1
     
    946951    if { $info(-type) == "image" } {
    947952        if 0 {
    948             set f [open "last.ppm" "w"] 
     953            set f [open "last.ppm" "w"]
    949954            fconfigure $f -encoding binary
    950955            puts -nonewline $f $bytes
     
    10241029    # Turn on buffering of commands to the server.  We don't want to
    10251030    # be preempted by a server disconnect/reconnect (which automatically
    1026     # generates a new call to Rebuild).   
     1031    # generates a new call to Rebuild).
    10271032    StartBufferingCommands
    10281033
     
    10571062                    continue
    10581063                }
     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                }
    10591070                set length [string length $bytes]
    10601071                if { $_reportClientInfo }  {
    10611072                    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]
    10661078                    lappend info "dataset_label" [$dataobj hints label]
    10671079                    lappend info "dataset_size"  $length
    10681080                    lappend info "dataset_tag"   $tag
    1069                     SendCmd [list "clientinfo" $info]
     1081                    SendCmd "clientinfo [list $info]"
    10701082                }
    10711083                SendCmd "dataset add $tag data follows $length"
     
    11111123        if { $_haveGlyphs } {
    11121124            InitSettings glyphs-edges glyphs-lighting glyphs-opacity \
    1113                 glyphs-visible glyphs-wireframe 
     1125                glyphs-visible glyphs-wireframe
    11141126        }
    11151127        if { $_havePolydata } {
    11161128            InitSettings polydata-edges polydata-lighting polydata-opacity \
    1117                 polydata-visible polydata-wireframe 
     1129                polydata-visible polydata-wireframe
    11181130        }
    11191131        if { $_haveMolecules } {
     
    11221134        }
    11231135
    1124         set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    1125         $_arcball quaternion $q
     1136        $_arcball quaternion [ViewToQuaternion]
    11261137        SendCmd "camera reset"
    1127         if { $_view(ortho)} {
     1138        if { $_view(-ortho)} {
    11281139            SendCmd "camera mode ortho"
    11291140        } else {
     
    11361147
    11371148    if { $_haveMolecules } {
    1138         #InitSettings molecule-representation 
     1149        #InitSettings molecule-representation
    11391150    }
    11401151    set _reset 0
     
    11591170itcl::body Rappture::VtkViewer::CurrentDatasets {args} {
    11601171    set flag [lindex $args 0]
    1161     switch -- $flag { 
     1172    switch -- $flag {
    11621173        "-all" {
    11631174            if { [llength $args] > 1 } {
     
    11781189                set dlist [get -visible]
    11791190            }
    1180         }           
     1191        }
    11811192        default {
    11821193            set dlist $args
     
    12061217    switch -- $option {
    12071218        "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)"
    12101221        }
    12111222        "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)"
    12141225        }
    12151226        "reset" {
    12161227            array set _view {
    1217                 qw      0.853553
    1218                 qx      -0.353553
    1219                 qy      0.353553
    1220                 qz      0.146447
    1221                 zoom    1.0
    1222                 xpan    0
    1223                 ypan    0
     1228                -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
    12241235            }
    12251236            if { $_first != "" } {
     
    12291240                }
    12301241            }
    1231             set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    1232             $_arcball quaternion $q
     1242            $_arcball quaternion [ViewToQuaternion]
    12331243            DoRotate
    12341244            SendCmd "camera reset"
     
    12381248
    12391249itcl::body Rappture::VtkViewer::PanCamera {} {
    1240     set x $_view(xpan)
    1241     set y $_view(ypan)
     1250    set x $_view(-xpan)
     1251    set y $_view(-ypan)
    12421252    SendCmd "camera pan $x $y"
    12431253}
     
    12981308    foreach tag [CurrentDatasets -visible] {
    12991309        SendCmd "dataset getscalar pixel $x $y $tag"
    1300     } 
     1310    }
    13011311}
    13021312
     
    13161326            set x [expr $x / double($w)]
    13171327            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]
    13201330            PanCamera
    13211331            return
     
    13391349            set _click(x) $x
    13401350            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]
    13431353            PanCamera
    13441354        }
     
    16671677                set type [$dataobj type $comp]
    16681678                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
    16751687                }
    16761688            }
     
    17421754            }
    17431755        }
    1744         "axis-xposition" - "axis-yposition" - "axis-zposition" - 
     1756        "axis-xposition" - "axis-yposition" - "axis-zposition" -
    17451757        "axis-xdirection" - "axis-ydirection" - "axis-zdirection" {
    17461758            set axis [string range $what 5 5]
     
    18731885itcl::configbody Rappture::VtkViewer::plotbackground {
    18741886    if { [isconnected] } {
    1875         foreach {r g b} [Color2RGB $itk_option(-plotbackground)] break
    1876         SendCmd "screen bgcolor $r $g $b"
     1887        set rgb [Color2RGB $itk_option(-plotbackground)]
     1888        SendCmd "screen bgcolor $rgb"
    18771889    }
    18781890}
     
    18831895itcl::configbody Rappture::VtkViewer::plotforeground {
    18841896    if { [isconnected] } {
    1885         foreach {r g b} [Color2RGB $itk_option(-plotforeground)] break
    1886         #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"
    18881900    }
    18891901}
     
    19001912            set f [open "$tmpfile" "w"]
    19011913            fconfigure $f -translation binary -encoding binary
    1902             puts $f $data 
     1914            puts $f $data
    19031915            close $f
    19041916            set reader [vtkDataSetReader $tag-xvtkDataSetReader]
     
    19942006        -variable [itcl::scope _settings(glyphs-visible)] \
    19952007        -command [itcl::code $this AdjustSetting glyphs-visible] \
    1996         -font "Arial 9" -anchor w 
     2008        -font "Arial 9" -anchor w
    19972009
    19982010    checkbutton $inner.outline \
     
    20002012        -variable [itcl::scope _settings(glyphs-outline)] \
    20012013        -command [itcl::code $this AdjustSetting glyphs-outline] \
    2002         -font "Arial 9" -anchor w 
     2014        -font "Arial 9" -anchor w
    20032015
    20042016    checkbutton $inner.wireframe \
     
    20062018        -variable [itcl::scope _settings(glyphs-wireframe)] \
    20072019        -command [itcl::code $this AdjustSetting glyphs-wireframe] \
    2008         -font "Arial 9" -anchor w 
     2020        -font "Arial 9" -anchor w
    20092021
    20102022    checkbutton $inner.lighting \
     
    20202032        -font "Arial 9" -anchor w
    20212033
    2022     label $inner.palette_l -text "Palette" -font "Arial 9" -anchor w 
     2034    label $inner.palette_l -text "Palette" -font "Arial 9" -anchor w
    20232035    itk_component add glyphspalette {
    20242036        Rappture::Combobox $inner.palette -width 10 -editable no
     
    20292041        [itcl::code $this AdjustSetting glyphs-palette]
    20302042
    2031     label $inner.opacity_l -text "Opacity" -font "Arial 9" -anchor w 
     2043    label $inner.opacity_l -text "Opacity" -font "Arial 9" -anchor w
    20322044    ::scale $inner.opacity -from 0 -to 100 -orient horizontal \
    20332045        -variable [itcl::scope _settings(glyphs-opacity)] \
     
    20462058        5,1 $inner.opacity   -fill x   -pady 2 \
    20472059        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
    20492061
    20502062    blt::table configure $inner r* c* -resize none
     
    20662078        -variable [itcl::scope _settings(polydata-visible)] \
    20672079        -command [itcl::code $this AdjustSetting polydata-visible] \
    2068         -font "Arial 9" -anchor w 
     2080        -font "Arial 9" -anchor w
    20692081
    20702082    checkbutton $inner.outline \
     
    20722084        -variable [itcl::scope _settings(polydata-outline)] \
    20732085        -command [itcl::code $this AdjustSetting polydata-outline] \
    2074         -font "Arial 9" -anchor w 
     2086        -font "Arial 9" -anchor w
    20752087
    20762088    checkbutton $inner.wireframe \
     
    20782090        -variable [itcl::scope _settings(polydata-wireframe)] \
    20792091        -command [itcl::code $this AdjustSetting polydata-wireframe] \
    2080         -font "Arial 9" -anchor w 
     2092        -font "Arial 9" -anchor w
    20812093
    20822094    checkbutton $inner.lighting \
     
    20922104        -font "Arial 9" -anchor w
    20932105
    2094     label $inner.palette_l -text "Palette" -font "Arial 9" -anchor w 
     2106    label $inner.palette_l -text "Palette" -font "Arial 9" -anchor w
    20952107    itk_component add meshpalette {
    20962108        Rappture::Combobox $inner.palette -width 10 -editable no
     
    21012113        [itcl::code $this AdjustSetting polydata-palette]
    21022114
    2103     label $inner.opacity_l -text "Opacity" -font "Arial 9" -anchor w 
     2115    label $inner.opacity_l -text "Opacity" -font "Arial 9" -anchor w
    21042116    ::scale $inner.opacity -from 0 -to 100 -orient horizontal \
    21052117        -variable [itcl::scope _settings(polydata-opacity)] \
     
    21182130        5,1 $inner.opacity   -fill x   -pady 2 \
    21192131        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
    21212133
    21222134    blt::table configure $inner r* c* -resize none
     
    21352147
    21362148    checkbutton $inner.visible \
    2137         -text "Show Axes" \
     2149        -text "Axes" \
    21382150        -variable [itcl::scope _axis(visible)] \
    21392151        -command [itcl::code $this AdjustSetting axis-visible] \
     
    21412153
    21422154    checkbutton $inner.labels \
    2143         -text "Show Axis Labels" \
     2155        -text "Axis Labels" \
    21442156        -variable [itcl::scope _axis(labels)] \
    21452157        -command [itcl::code $this AdjustSetting axis-labels] \
    21462158        -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" \
    21502162        -variable [itcl::scope _axis(xgrid)] \
    21512163        -command [itcl::code $this AdjustSetting axis-xgrid] \
    21522164        -font "Arial 9"
    2153     checkbutton $inner.gridy \
    2154         -text "Show Y Grid" \
     2165    checkbutton $inner.ygrid \
     2166        -text "Y" \
    21552167        -variable [itcl::scope _axis(ygrid)] \
    21562168        -command [itcl::code $this AdjustSetting axis-ygrid] \
    21572169        -font "Arial 9"
    2158     checkbutton $inner.gridz \
    2159         -text "Show Z Grid" \
     2170    checkbutton $inner.zgrid \
     2171        -text "Z" \
    21602172        -variable [itcl::scope _axis(zgrid)] \
    21612173        -command [itcl::code $this AdjustSetting axis-zgrid] \
     
    21672179        -font "Arial 9"
    21682180
    2169     label $inner.mode_l -text "Mode" -font "Arial 9" 
     2181    label $inner.mode_l -text "Mode" -font "Arial 9"
    21702182
    21712183    itk_component add axismode {
     
    21762188        "closest_triad"   "closest" \
    21772189        "furthest_triad"  "farthest" \
    2178         "outer_edges"     "outer"         
     2190        "outer_edges"     "outer"
    21792191    $itk_component(axismode) value "static"
    21802192    bind $inner.mode <<Value>> [itcl::code $this AdjustSetting axis-mode]
     
    22142226        0,0 $inner.view_l -anchor e -pady 2 \
    22152227        0,1 $inner.view -anchor w -pady 2
     2228    blt::table configure $inner r0 -resize none
    22162229
    22172230    set labels { qx qy qz qw xpan ypan zoom }
     
    22202233        label $inner.${tag}label -text $tag -font "Arial 9"
    22212234        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}]
    22252240        blt::table $inner \
    22262241            $row,0 $inner.${tag}label -anchor e -pady 2 \
     
    22312246    checkbutton $inner.ortho \
    22322247        -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] \
    22352250        -font "Arial 9"
    22362251    blt::table $inner \
     
    22392254    incr row
    22402255
    2241     blt::table configure $inner c* r* -resize none
     2256    blt::table configure $inner c* -resize none
    22422257    blt::table configure $inner c2 -resize expand
    22432258    blt::table configure $inner r$row -resize expand
     
    22472262
    22482263    set fg [option get $itk_component(hull) font Font]
    2249    
     2264
    22502265    set inner [$itk_component(main) insert end \
    22512266        -title "Cutaway Along Axis" \
    2252         -icon [Rappture::icon cutbutton]] 
     2267        -icon [Rappture::icon cutbutton]]
    22532268
    22542269    $inner configure -borderwidth 4
     
    22902305            -variable [itcl::scope _axis(xdirection)]
    22912306    }
    2292     set _axis(xdirection) -1 
     2307    set _axis(xdirection) -1
    22932308    Rappture::Tooltip::for $itk_component(xDirButton) \
    22942309        "Toggle the direction of the X-axis cutaway"
     
    23322347    Rappture::Tooltip::for $itk_component(yDirButton) \
    23332348        "Toggle the direction of the Y-axis cutaway"
    2334     set _axis(ydirection) -1 
     2349    set _axis(ydirection) -1
    23352350
    23362351    # Z-value slicer...
     
    23692384            -variable [itcl::scope _axis(zdirection)]
    23702385    }
    2371     set _axis(zdirection) -1 
     2386    set _axis(zdirection) -1
    23722387    Rappture::Tooltip::for $itk_component(zDirButton) \
    23732388        "Toggle the direction of the Z-axis cutaway"
     
    24372452    $inner.rep choices insert end \
    24382453        "ballandstick"  "Ball and Stick" \
    2439         "spheres"       "Spheres"        \
    2440         "sticks"        "Sticks"        \
    2441         "rods"          "Rods"           \
    2442         "wireframe"     "Wireframe"      \
    2443         "spacefilling"  "Space Filling" 
     2454        "spheres"       "Spheres"        \
     2455        "sticks"        "Sticks"        \
     2456        "rods"          "Rods"           \
     2457        "wireframe"     "Wireframe"      \
     2458        "spacefilling"  "Space Filling"
    24442459
    24452460    bind $inner.rep <<Value>> \
     
    24542469    }
    24552470    $inner.rscale choices insert end \
    2456         "atomic"        "Atomic"   \
    2457         "covalent"      "Covalent" \
    2458         "van_der_waals" "VDW"      \
    2459         "none"          "Constant"
     2471        "atomic"        "Atomic"   \
     2472        "covalent"      "Covalent" \
     2473        "van_der_waals" "VDW"      \
     2474        "none"          "Constant"
    24602475
    24612476    bind $inner.rscale <<Value>> \
     
    24632478    $inner.rscale value "Covalent"
    24642479
    2465     label $inner.palette_l -text "Palette" -font "Arial 9" 
     2480    label $inner.palette_l -text "Palette" -font "Arial 9"
    24662481    itk_component add moleculepalette {
    24672482        Rappture::Combobox $inner.palette -width 10 -editable no
     
    25282543        16,0 $inner.quality_l   -anchor w -pady {3 0} \
    25292544        17,0 $inner.quality     -fill x    -padx 2
    2530    
     2545
    25312546    blt::table configure $inner r* -resize none
    25322547    blt::table configure $inner r18 -resize expand
     
    25342549
    25352550#
    2536 #  camera -- 
     2551#  camera --
    25372552#
    25382553itcl::body Rappture::VtkViewer::camera {option args} {
    2539     switch -- $option { 
     2554    switch -- $option {
    25402555        "show" {
    25412556            puts [array get _view]
    25422557        }
    25432558        "set" {
    2544             set who [lindex $args 0]
    2545             set x $_view($who)
     2559            set what [lindex $args 0]
     2560            set x $_view($what)
    25462561            set code [catch { string is double $x } result]
    25472562            if { $code != 0 || !$result } {
    25482563                return
    25492564            }
    2550             switch -- $who {
    2551                 "ortho" {
    2552                     if {$_view(ortho)} {
     2565            switch -- $what {
     2566                "-ortho" {
     2567                    if {$_view($what)} {
    25532568                        SendCmd "camera mode ortho"
    25542569                    } else {
     
    25562571                    }
    25572572                }
    2558                 "xpan" - "ypan" {
     2573                "-xpan" - "-ypan" {
    25592574                    PanCamera
    25602575                }
    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]
    25632578                    $_arcball quaternion $q
    25642579                    EventuallyRotate $q
    25652580                }
    2566                 "zoom" {
    2567                     SendCmd "camera zoom $_view(zoom)"
     2581                "-zoom" {
     2582                    SendCmd "camera zoom $_view($what)"
    25682583                }
    25692584            }
     
    25852600
    25862601itcl::body Rappture::VtkViewer::GetImage { args } {
    2587     if { [image width $_image(download)] > 0 && 
     2602    if { [image width $_image(download)] > 0 &&
    25882603         [image height $_image(download)] > 0 } {
    25892604        set bytes [$_image(download) data -format "jpeg -quality 100"]
     
    25982613        -title "[Rappture::filexfer::label downloadWord] as..."
    25992614    set inner [$popup component inner]
    2600     label $inner.summary -text "" -anchor w 
     2615    label $inner.summary -text "" -anchor w
    26012616    radiobutton $inner.vtk_button -text "VTK data file" \
    26022617        -variable [itcl::scope _downloadPopup(format)] \
    26032618        -font "Helvetica 9 " \
    2604         -value vtk 
     2619        -value vtk
    26052620    Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file."
    26062621    radiobutton $inner.image_button -text "Image File" \
    26072622        -variable [itcl::scope _downloadPopup(format)] \
    2608         -value image 
     2623        -value image
    26092624    Rappture::Tooltip::for $inner.image_button \
    26102625        "Save as digital image."
     
    26272642        2,0 $inner.image_button -anchor w -cspan 2 -padx { 4 0 } \
    26282643        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
    26302645    blt::table configure $inner r3 -height 4
    26312646    blt::table configure $inner r4 -pady 4
     
    29042919    set font "Arial 8"
    29052920    set lineht [font metrics $font -linespace]
    2906    
     2921
    29072922    if { $_settings(legend) } {
    29082923        set x [expr $w - 2]
     
    29692984    set font "Arial 8"
    29702985    set lineht [font metrics $font -linespace]
    2971    
     2986
    29722987    set imgHeight [image height $_image(legend)]
    29732988    set coords [$c coords colormap]
     
    29832998    }
    29842999    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
    29873002    .rappturetooltip configure -icon $_image(swatch)
    29883003
     
    29903005    set t [expr 1.0 - (double($imgY) / double($imgHeight-1))]
    29913006    set value [expr $t * ($_limits(vmax) - $_limits(vmin)) + $_limits(vmin)]
    2992     set tipx [expr $x + 15] 
     3007    set tipx [expr $x + 15]
    29933008    set tipy [expr $y - 5]
    29943009    Rappture::Tooltip::text $c "$_title $value"
    2995     Rappture::Tooltip::tooltip show $c +$tipx,+$tipy   
     3010    Rappture::Tooltip::tooltip show $c +$tipx,+$tipy
    29963011}
    29973012
     
    30263041}
    30273042
    3028 itcl::body Rappture::VtkViewer::SetOrientation { side } { 
     3043itcl::body Rappture::VtkViewer::SetOrientation { side } {
    30293044    array set positions {
    30303045        front "1 0 0 0"
     
    30353050        bottom "0.707107 0.707107 0 0"
    30363051    }
    3037     foreach name { qw qx qy qz } value $positions($side) {
     3052    foreach name { -qw -qx -qy -qz } value $positions($side) {
    30383053        set _view($name) $value
    3039     } 
    3040     set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
     3054    }
     3055    set q [ViewToQuaternion]
    30413056    $_arcball quaternion $q
    30423057    SendCmd "camera orient $q"
    30433058    SendCmd "camera reset"
    3044     set _view(xpan) 0
    3045     set _view(ypan) 0
    3046     set _view(zoom) 1.0
    3047 }
    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
     3064itcl::body Rappture::VtkViewer::SetOpacity { dataset } {
    30503065    foreach {dataobj comp} [split $dataset -] break
    30513066    set type [$dataobj type $comp]
  • branches/uq/gui/scripts/vtkvolumeviewer.tcl

    r4797 r5121  
    11# -*- mode: tcl; indent-tabs-mode: nil -*-
    2 # ----------------------------------------------------------------------
    3 #  COMPONENT: vtkvolumeviewer - Vtk volume viewer
     2
     3# ----------------------------------------------------------------------
     4#  COMPONENT: VtkVolumeViewer - Vtk volume viewer
    45#
    56#  It connects to the Vtk server running on a rendering farm,
     
    78# ======================================================================
    89#  AUTHOR:  Michael McLennan, Purdue University
    9 #  Copyright (c) 2004-2014  HUBzero Foundation, LLC
     10#  Copyright (c) 2004-2012  HUBzero Foundation, LLC
    1011#
    1112#  See the file "license.terms" for information on usage and
     
    6667    protected method Disconnect {}
    6768    protected method DoResize {}
     69    protected method DoReseed {}
    6870    protected method DoRotate {}
    6971    protected method AdjustSetting {what {value ""}}
     
    8486    private method BuildCutplaneTab {}
    8587    private method BuildDownloadPopup { widget command }
    86     private method BuildViewTab {}
    8788    private method BuildVolumeTab {}
    8889    private method DrawLegend {}
     
    9091    private method EnterLegend { x y }
    9192    private method EventuallyResize { w h }
     93    private method EventuallyReseed { numPoints }
    9294    private method EventuallyRotate { q }
    9395    private method EventuallySetCutplane { axis args }
     
    127129    private variable _start 0
    128130    private variable _title ""
     131    private variable _seeds
    129132
    130133    common _downloadPopup;              # download options from popup
     
    133136    private variable _height 0
    134137    private variable _resizePending 0
     138    private variable _reseedPending 0
    135139    private variable _rotatePending 0
    136140    private variable _cutplanePending 0
     
    154158    set _serverType "vtkvis"
    155159
    156     EnableWaitDialog 900
    157 
    158160    # Rebuild event
    159161    $_dispatcher register !rebuild
     
    163165    $_dispatcher register !resize
    164166    $_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"
    165171
    166172    # Rotate event
     
    215221        axesVisible             1
    216222        axisLabels              1
    217         background              black
    218223        cutplaneEdges           0
    219224        cutplane-xvisible       1
     
    227232        cutplaneWireframe       0
    228233        cutplane-opacity        100
    229         legendVisible           1
    230         outline                 0
    231234        volumeLighting          1
    232235        volume-material         80
     
    334337
    335338    if { [catch {
    336         BuildViewTab
    337339        BuildVolumeTab
    338340        BuildCutplaneTab
     
    342344        puts stderr errs=$errs
    343345    }
    344 
    345346    # Legend
     347
    346348    set _image(legend) [image create photo]
    347349    itk_component add legend {
     
    372374        [itcl::code $this EventuallyResize %w %h]
    373375
     376    if 0 {
     377    bind $itk_component(view) <Configure> \
     378        [itcl::code $this EventuallyResize %w %h]
     379    }
    374380    # Bindings for panning via mouse
    375381    bind $itk_component(view) <ButtonPress-2> \
     
    461467}
    462468
     469itcl::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
    463477set rotate_delay 100
    464478
     
    487501# ----------------------------------------------------------------------
    488502itcl::body Rappture::VtkVolumeViewer::add {dataobj {settings ""}} {
    489     if { ![IsValidObject $dataobj] } {
    490         return;                         # Ignore invalid objects.
    491     }
    492503    array set params {
    493504        -color auto
     
    739750        if { $_reportClientInfo }  {
    740751            # Tell the server the viewer, hub, user and session.
    741             # Do this immediately on connect before buffering any commands
     752            # Do this immediately on connect before buffing any commands
    742753            global env
    743754
     
    797808    $_dispatcher cancel !rebuild
    798809    $_dispatcher cancel !resize
     810    $_dispatcher cancel !reseed
    799811    $_dispatcher cancel !rotate
    800812    $_dispatcher cancel !xcutplane
     
    807819    array unset _data
    808820    array unset _colormaps
     821    array unset _seeds
    809822    array unset _dataset2style
    810823    array unset _obj2datasets
     
    834847        }
    835848        $_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>"       
    837852        if { $_start > 0 } {
    838853            set finish [clock clicks -milliseconds]
     
    913928    set _legendPending 1
    914929
    915     if { $_width != $w || $_height != $h || $_reset } {
     930    if { $_reset } {
    916931        set _width $w
    917932        set _height $h
    918933        $_arcball resize $w $h
    919934        DoResize
    920     }
    921     if { $_reset } {
    922935        #
    923936        # Reset the camera and other view parameters
     
    931944        }
    932945        DoRotate
    933         InitSettings outline background \
    934             axis-xgrid axis-ygrid axis-zgrid axisFlyMode \
     946        InitSettings axis-xgrid axis-ygrid axis-zgrid axisFlyMode \
    935947            axesVisible axisLabels
    936948        PanCamera
    937949    }
     950    set _first ""
    938951
    939952    SendCmd "imgflush"
     
    953966                if { $_reportClientInfo }  {
    954967                    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]
    959973                    lappend info "dataset_label" [$dataobj hints label]
    960974                    lappend info "dataset_size"  $length
     
    969983            lappend _obj2datasets($dataobj) $tag
    970984            if { [info exists _obj2ovride($dataobj-raise)] } {
    971                 SendCmd "volume visible 1 $tag"
     985                SendCmd "dataset visible 1 $tag"
    972986            }
    973987            break
     
    983997            set label [$_first hints ${axis}label]
    984998            if { $label != "" } {
    985                 SendCmd [list axis name $axis $label]
     999                SendCmd "axis name $axis $label"
    9861000            }
    9871001            set units [$_first hints ${axis}units]
    9881002            if { $units != "" } {
    989                 SendCmd [list axis units $axis $units]
     1003                SendCmd "axis units $axis $units"
    9901004            }
    9911005        }
     
    12721286    }
    12731287    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             DrawLegend
    1285         }
    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) $bool
    1296         }
    12971288        "volumeVisible" {
    1298             set bool $_settings($what)
     1289            set bool $_settings(volumeVisible)
    12991290            foreach dataset [CurrentDatasets -visible] {
    13001291                SendCmd "volume visible $bool $dataset"
     
    13091300        }
    13101301        "volume-material" {
    1311             set val $_settings($what)
     1302            set val $_settings(volume-material)
    13121303            set diffuse [expr {0.01*$val}]
    13131304            set specular [expr {0.01*$val}]
     
    13201311        }
    13211312        "volumeLighting" {
    1322             set bool $_settings($what)
     1313            set bool $_settings(volumeLighting)
    13231314            foreach dataset [CurrentDatasets -visible] {
    13241315                SendCmd "volume lighting $bool $dataset"
     
    13261317        }
    13271318        "volume-quality" {
    1328             set val $_settings($what)
     1319            set val $_settings(volume-quality)
    13291320            set val [expr {0.01*$val}]
    13301321            foreach dataset [CurrentDatasets -visible] {
     
    13331324        }
    13341325        "axesVisible" {
    1335             set bool $_settings($what)
     1326            set bool $_settings(axesVisible)
    13361327            SendCmd "axis visible all $bool"
    13371328        }
    13381329        "axisLabels" {
    1339             set bool $_settings($what)
     1330            set bool $_settings(axisLabels)
    13401331            SendCmd "axis labels all $bool"
    13411332        }
     
    14061397        "volume-palette" {
    14071398            set palette [$itk_component(palette) value]
    1408             set _settings($what) $palette
     1399            set _settings(volume-palette) $palette
    14091400            foreach dataset [CurrentDatasets -visible $_first] {
    14101401                foreach {dataobj comp} [split $dataset -] break
     
    14131404            set _legendPending 1
    14141405        }
     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        }
    14151415        "field" {
    14161416            set label [$itk_component(field) value]
    14171417            set fname [$itk_component(field) translate $label]
    1418             set _settings($what) $fname
     1418            set _settings(field) $fname
    14191419            if { [info exists _fields($fname)] } {
    14201420                foreach { label units components } $_fields($fname) break
     
    15491549itcl::configbody Rappture::VtkVolumeViewer::plotbackground {
    15501550    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"
    15551553    }
    15561554}
     
    15611559itcl::configbody Rappture::VtkVolumeViewer::plotforeground {
    15621560    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    }
    16291565}
    16301566
    16311567itcl::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]
    16341571
    16351572    set inner [$itk_component(main) insert end \
     
    16851622        Rappture::Combobox $inner.palette -width 10 -editable no
    16861623    }
    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
    16891642    $itk_component(palette) value "BCGYR"
    16901643    bind $inner.palette <<Value>> \
     
    17091662
    17101663itcl::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]
    17131667
    17141668    set inner [$itk_component(main) insert end \
     
    17531707        "static_triad"    "static" \
    17541708        "closest_triad"   "closest" \
    1755         "furthest_triad"  "farthest" \
     1709        "furthest_triad"  "furthest" \
    17561710        "outer_edges"     "outer"         
    17571711    $itk_component(axismode) value "static"
     
    17701724    blt::table configure $inner r7 c1 -resize expand
    17711725}
     1726
    17721727
    17731728itcl::body Rappture::VtkVolumeViewer::BuildCameraTab {} {
     
    18071762
    18081763itcl::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]
    18101766   
    18111767    set inner [$itk_component(main) insert end \
     
    20772033    set _settings(volumeLighting) $settings(-lighting)
    20782034    SetColormap $dataobj $comp
    2079     SendCmd "outline add $tag"
    2080     SendCmd "outline visible 0 $tag"
    20812035}
    20822036
  • branches/uq/gui/scripts/xylegend.tcl

    r3800 r5121  
    8585    private method Lower { args }
    8686    private method Raise { args }
     87    private method Recolor {}
    8788    private method PopupMenu { x y }
    8889    private method Rename {}
     
    158159        delete ""
    159160        rename ""
     161        recolor ""
    160162    }
    161163    foreach { but icon} $commands {
     
    174176    grid $controls.average    -column 1 -row 1 -sticky w
    175177    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
    177180
    178181    grid columnconfigure $controls 0  -weight 1
     
    393396    set nodes [$itk_component(legend) curselection]
    394397    foreach n { hide show toggle raise lower
    395         rename average difference delete } {
     398        rename average difference delete recolor } {
    396399        $itk_component(controls).$n configure -state disabled
    397400    }
     
    411414        }
    412415        1 {
    413             foreach n { hide show toggle rename } {
     416            foreach n { hide show toggle rename recolor } {
    414417                $itk_component(controls).$n configure -state normal
    415418            }
    416419        }
    417420        2 {
    418             foreach n { hide show toggle difference average } {
     421            foreach n { hide show toggle difference average recolor } {
    419422                $itk_component(controls).$n configure -state normal
    420423            }
    421424        }
    422425        default {
    423             foreach n { hide show toggle average } {
     426            foreach n { hide show toggle average recolor } {
    424427                $itk_component(controls).$n configure -state normal
    425428            }
     
    613616    }
    614617}
     618
     619itcl::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  
    13291329    close $f
    13301330    if { [catch { $parser eval $code }] != 0 } {
    1331         file delete $_settingsFiles
     1331        file delete $_settingsFile
    13321332    }
    13331333    # Now see if there's an entry for this tool/plot combination.  The data
  • branches/uq/gui/scripts/xyresult.tcl

    r4205 r5121  
    249249    }
    250250    if { $color == "auto" || $color == "autoreset" } {
    251         if { $color == "autoreset" } {
    252             set _nextColorIndex 0
    253         }
     251#        if { $color == "autoreset" } {
     252#            set _nextColorIndex 0
     253#        }
    254254        set color [lindex $itk_option(-autocolors) $_nextColorIndex]
    255255        if { "" == $color} {
     
    10671067        }
    10681068    }
     1069        incr _nextColorIndex
    10691070    if {$_nextColorIndex >= [llength $itk_option(-autocolors)]} {
    10701071        set _nextColorIndex 0
  • branches/uq/gui/src/RpDicomToVtk.cc

    r4515 r5121  
    2727#include <stdio.h>
    2828#include "tcl.h"
     29
     30// #define RP_DICOM_TRACE
    2931
    3032static int
     
    9597    int series = 0;
    9698
     99#ifdef RP_DICOM_TRACE
    97100    fprintf(stderr, "Num Studies: %d\n", numStudies);
     101#endif
    98102    vtkStringArray *files;
    99103#if 0
    100104    for (int i = 0; i < numStudies; i++) {
    101105        int numSeries = sorter->GetNumberOfSeriesInStudy(i);
     106#ifdef RP_DICOM_TRACE
    102107        fprintf(stderr, "Study %d: %d series\n", i, numSeries);
     108#endif
    103109        int k = sorter->GetFirstSeriesInStudy(i);
    104110        for (int j = 0; j < numSeries; j++) {
     
    144150#ifdef USE_VTK_DICOM_PACKAGE
    145151    vtkStringArray *ids = reader->GetStackIDs();
     152#ifdef RP_DICOM_TRACE
    146153    for (int i = 0; i < ids->GetNumberOfValues(); i++) {
    147154        fprintf(stderr, "Stack: %s\n", ids->GetValue(i).c_str());
    148155    }
     156#endif
    149157    vtkIntArray *fidxArray = reader->GetFileIndexArray();
    150158    vtkDICOMMetaData *md = reader->GetMetaData();
     
    160168    }
    161169#endif
     170#ifdef RP_DICOM_TRACE
    162171    fprintf(stderr, "Number of data elements: %d\n", md->GetNumberOfDataElements());
    163 
     172#endif
    164173    Tcl_ListObjAppendElement(interp, metaDataObj, Tcl_NewStringObj("num_files", -1));
    165174    Tcl_ListObjAppendElement(interp, metaDataObj, Tcl_NewIntObj(md->GetNumberOfInstances()));
     
    234243
    235244    Tcl_ListObjAppendList(interp, objPtr, metaDataObj);
    236 
     245#ifdef RP_DICOM_TRACE
    237246    fprintf(stderr, "writing VTK\n");
    238 
     247#endif
    239248    vtkSmartPointer<vtkDataSetWriter> writer = vtkSmartPointer<vtkDataSetWriter>::New();
    240249    writer->SetInputConnection(reader->GetOutputPort());
     
    242251    writer->WriteToOutputStringOn();
    243252    writer->Update();
    244 
     253#ifdef RP_DICOM_TRACE
    245254    fprintf(stderr, "writing VTK...done\n");
    246 
     255#endif
    247256    Tcl_ListObjAppendElement(interp, objPtr, Tcl_NewStringObj("vtkdata", -1));
    248257
  • branches/uq/gui/src/RpPdbToVtk.c

    r4798 r5121  
    191191    for (i = 0, hPtr = Tcl_FirstHashEntry(atomTablePtr, &iter); hPtr != NULL;
    192192         hPtr = Tcl_NextHashEntry(&iter), i++) {
    193         PdbAtom *atomPtr;
    194 
    195         atomPtr = Tcl_GetHashValue(hPtr);
     193        PdbAtom *atomPtr = Tcl_GetHashValue(hPtr);
    196194        array[i] = atomPtr;
    197195    }
     
    691689        Tcl_AppendToObj(objPtr, mesg, -1);
    692690    }
     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
    693699    sprintf(mesg, "POINT_DATA %d\n", atomTable.numEntries);
    694700    Tcl_AppendToObj(objPtr, mesg, -1);
  • branches/uq/gui/src/RpReadPoints.c

    r3404 r5121  
    8888    return TCL_OK;
    8989}
    90    
     90
    9191/*
    9292 *  ReadPoints string dimVar pointsVar
  • branches/uq/lang/tcl/pkgIndex.tcl.in

    r4798 r5121  
    66        variable version $version
    77        variable build "@SVN_VERSION@"
     8        variable svnurl "@SVN_URL@"
    89        variable installdir [file normalize $dir]
    910    }
  • branches/uq/lang/tcl/scripts/task.tcl

    r5102 r5121  
    1313#  Copyright (c) 2004-2014  HUBzero Foundation, LLC
    1414#
    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.
    1617# ======================================================================
    1718package require BLT
     
    3233    public method reset {}
    3334    public method xml {args}
     35    public method save {xmlobj {name ""}}
    3436
    3537    protected method _mkdir {dir}
     
    3941    private variable _xmlobj ""      ;# XML object with inputs/outputs
    4042    private variable _origxml ""     ;# copy of original XML (for reset)
     43    private variable _lastrun ""     ;# name of last run file
    4144    private variable _installdir ""  ;# installation directory for this tool
    4245    private variable _outputcb ""    ;# callback for tool output
     
    263266        }
    264267
    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                }
    356360                foreach arg [lrange [string range $job(error) $p0 $p1] 1 end] {
    357361                    foreach {key val} [split $arg =] break
     
    413417        }
    414418        if {[regexp {=RAPPTURE-RUN=>([^\n]+)} $result match file]} {
     419            set _lastrun $file
     420
    415421            set status [catch {Rappture::library $file} result]
    416422            puts "STATUS=$status"
     
    427433            }
    428434
    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
    458436        } else {
    459437            set status 1
     
    533511    }
    534512    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# ----------------------------------------------------------------------
     523itcl::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
    535568}
    536569
  • branches/uq/lang/tcl/scripts/xauth.tcl

    r4797 r5121  
    1111#    set clientSecret [XAuth::credentials get nanoHUB.org -secret]
    1212#
    13 #    XAuth::init $site $clientToken $clientSecret $username $password
     13#    XAuth::init $site $clientToken $clientSecret -user $username $password
    1414#    XAuth::call $site $method $params
    1515#
     
    2020# ======================================================================
    2121#  AUTHOR:  Michael McLennan, Purdue University
    22 #  Copyright (c) 2004-2013  HUBzero Foundation, LLC
     22#  Copyright (c) 2004-2015  HUBzero Foundation, LLC
    2323#
    2424#  See the file "license.terms" for information on usage and
     
    287287
    288288# ----------------------------------------------------------------------
    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.
    294300# If successful, this call stores an authenticated session token in
    295301# the tokens array for the <site> URL.  Subsequent calls to XAuth::call
    296302# use this token to identify the user.
    297303# ----------------------------------------------------------------------
    298 proc XAuth::init {site clientToken clientSecret uname passw} {
     304proc XAuth::init {site clientToken clientSecret args} {
    299305    variable clients
    300306    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    }
    301337
    302338    if {![regexp {^https://} $site]} {
     
    360396
    361397    # 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)]
    363399    set clients($site) [list $clientToken $clientSecret]
    364400}
     
    385421    }
    386422    foreach {clientToken clientSecret} $clients($site) break
    387     foreach {userToken userSecret} $tokens($site) break
     423    foreach {scheme userToken userSecret} $tokens($site) break
    388424
    389425    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]
    419471}
    420472
     
    596648    switch -- $option {
    597649        load {
    598             set fname "~/.xauth"
    599650            if {[llength $args] == 1} {
    600651                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 {
    602659                error "wrong # args: should be \"credentials load ?file?\""
    603660            }
    604661
    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                }
    614673            }
    615674        }
  • branches/uq/src/core/RpEncode.cc

    r4798 r5121  
    212212    for (p = (unsigned const char *)buf, pend = p + size; p < pend; p++) {
    213213        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);
    215215            return false;
    216216        }
Note: See TracChangeset for help on using the changeset viewer.