Changeset 3655 for branches/1.2


Ignore:
Timestamp:
May 15, 2013 2:02:33 PM (8 years ago)
Author:
gah
Message:

fix assorted automatic tickets: bad data in curve, more trim space, move image creation before errors in constructor

Location:
branches/1.2/gui/scripts
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/1.2/gui/scripts/curve.tcl

    r3330 r3655  
    276276        if { "" != $xydata} {
    277277            set tmp [blt::vector create \#auto]
    278             $tmp set $xydata
    279             $tmp split $xv $yv
     278            # Protect against invalid data in $xydata.
     279            catch {
     280                $tmp set $xydata
     281                $tmp split $xv $yv
     282            }
    280283            blt::vector destroy $tmp
    281284        } else {
  • branches/1.2/gui/scripts/main.tcl

    r3646 r3655  
    124124    # examples/ and docs/ dirs from the install location
    125125    foreach runobj $loadobjs {
    126         set tdir [$runobj get tool.version.application.directory(tool)]
     126        set tdir \
     127            [string trim [$runobj get tool.version.application.directory(tool)]]
    127128        if {[file isdirectory $tdir] && \
    128129            [file exists $tdir/tool.xml]} {
     
    221222# Add a place for about/questions in the breadcrumbs area of this pager.
    222223#
    223 set app [$tool xml get tool.id]
     224set app [string trim [$tool xml get tool.id]]
    224225set url [Rappture::Tool::resources -huburl]
    225226if {"" != $url && "" != $app} {
     
    279280# adjust the title of the page here.
    280281# to adjust the button text, look in analyzer.tcl
    281 set simtxt [$xmlobj get tool.action.label]
     282set simtxt [string trim [$xmlobj get tool.action.label]]
    282283if {"" == $simtxt} {
    283284    set simtxt "Simulate"
     
    308309    $f.analyze configure -simcontrol off
    309310} elseif {[llength [$win.pager page]] == 2} {
    310     set style [$xmlobj get tool.layout]
     311    set style [string trim [$xmlobj get tool.layout]]
    311312    set screenw [winfo screenwidth .]
    312313
  • branches/1.2/gui/scripts/vtkheightmapviewer.tcl

    r3652 r3655  
    2525option add *VtkHeightmapViewer.plotForeground white widgetDefault
    2626option add *VtkHeightmapViewer.font \
    27 -*-helvetica-medium-r-normal-*-12-* widgetDefault
     27    -*-helvetica-medium-r-normal-*-12-* widgetDefault
    2828
    2929# must use this name -- plugs into Rappture::resources::load
    3030proc VtkHeightmapViewer_init_resources {} {
    31 Rappture::resources::register \
    32 vtkvis_server Rappture::VtkHeightmapViewer::SetServerList
     31    Rappture::resources::register \
     32        vtkvis_server Rappture::VtkHeightmapViewer::SetServerList
    3333}
    3434
    3535itcl::class Rappture::VtkHeightmapViewer {
    36 inherit Rappture::VisViewer
    37 
    38 itk_option define -plotforeground plotForeground Foreground ""
    39 itk_option define -plotbackground plotBackground Background ""
    40 itk_option define -mode mode Mode "contour"
    41 
    42 constructor { hostlist args } {
    43 Rappture::VisViewer::constructor $hostlist
    44 } {
    45 # defined below
    46 }
    47 destructor {
    48 # defined below
    49 }
    50 public proc SetServerList { namelist } {
    51 Rappture::VisViewer::SetServerList "vtkvis" $namelist
    52 }
    53 public method add {dataobj {settings ""}}
    54 public method camera {option args}
    55 public method delete {args}
    56 public method disconnect {}
    57 public method download {option args}
    58 public method get {args}
    59 public method isconnected {}
    60 public method limits3 { dataobj }
    61 public method parameters {title args} {
    62 # do nothing
    63 }
    64 public method scale {args}
    65 
    66 protected method Connect {}
    67 protected method CurrentDatasets {args}
    68 protected method Disconnect {}
    69 protected method DoResize {}
    70 protected method DoRotate {}
    71 protected method AdjustSetting {what {value ""}}
    72 protected method AdjustMode {}
    73 protected method InitSettings { args  }
    74 protected method Pan {option x y}
    75 protected method Pick {x y}
    76 protected method Rebuild {}
    77 protected method ReceiveDataset { args }
    78 protected method ReceiveImage { args }
    79 protected method ReceiveLegend { colormap title min max size }
    80 protected method Rotate {option x y}
    81 protected method Zoom {option}
    82 
    83 # The following methods are only used by this class.
    84 private method BuildAxisTab {}
    85 private method BuildCameraTab {}
    86 private method BuildColormap { name }
    87 private method BuildContourTab {}
    88 private method BuildDownloadPopup { widget command }
    89 private method Combo { option }
    90 private method ConvertToVtkData { dataobj comp }
    91 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 }
    99 private method LeaveLegend {}
    100 private method MotionLegend { x y }
    101 private method PanCamera {}
    102 private method RequestLegend {}
    103 private method SetCurrentColormap { color }
    104 private method SetLegendTip { x y }
    105 private method SetObjectStyle { dataobj comp }
    106 private method GetHeightmapScale {}
    107 private method ResetAxes {}
    108 private method SetOrientation { side }
    109 
    110 private variable _arcball ""
    111 private variable _dlist ""     ;    # list of data objects
    112 private variable _obj2datasets
    113 private variable _obj2ovride   ;    # maps dataobj => style override
    114 private variable _comp2scale;   # maps dataset to the heightmap scale.
    115 private variable _datasets     ;    # contains all the dataobj-component
    116                            ;    # datasets in the server
    117 private variable _colormaps    ;    # contains all the colormaps
    118                            ;    # in the server.
    119 
    120 # The name of the current colormap used.  The colormap is global to all
    121 # heightmaps displayed.
    122 private variable _currentColormap "" ;   
    123 private variable _currentNumIsolines "" ;   
    124 private variable _currentOpacity "" ;   
    125 
    126 private variable _click        ;    # info used for rotate operations
    127 private variable _limits       ;    # Holds overall limits for all dataobjs
    128                                 # using the viewer.
    129 private variable _view         ;    # view params for 3D view
    130 private variable _settings
    131 private variable _changed
    132 private variable _initialStyle "";  # First found style in dataobjects.
    133 private variable _reset 1;          # Indicates if camera needs to be reset
    134                                 # to starting position.
    135 private variable _beforeConnect 1;  # Indicates if camera needs to be reset
    136                                 # to starting position.
    137 
    138 private variable _first ""     ;    # This is the topmost dataset.
    139 private variable _start 0
    140 private variable _isolines
    141 
    142 common _downloadPopup;              # download options from popup
    143 private common _hardcopy
    144 private variable _width 0
    145 private variable _height 0
    146 private variable _legendWidth 0
    147 private variable _legendHeight 0
    148 private variable _resizePending 0
    149 private variable _rotatePending 0
    150 private variable _legendPending 0
    151 private variable _fieldNames {}
    152 private variable _fields
    153 private variable _curFldName ""
    154 private variable _curFldLabel ""
    155 private variable _colorMode "vmag";#  Mode of colormap (vmag or scalar)
     36    inherit Rappture::VisViewer
     37
     38    itk_option define -plotforeground plotForeground Foreground ""
     39    itk_option define -plotbackground plotBackground Background ""
     40    itk_option define -mode mode Mode "contour"
     41
     42    constructor { hostlist args } {
     43        Rappture::VisViewer::constructor $hostlist
     44    } {
     45        # defined below
     46    }
     47    destructor {
     48        # defined below
     49    }
     50    public proc SetServerList { namelist } {
     51        Rappture::VisViewer::SetServerList "vtkvis" $namelist
     52    }
     53    public method add {dataobj {settings ""}}
     54    public method camera {option args}
     55    public method delete {args}
     56    public method disconnect {}
     57    public method download {option args}
     58    public method get {args}
     59    public method isconnected {}
     60    public method limits3 { dataobj }
     61    public method parameters {title args} {
     62        # do nothing
     63    }
     64    public method scale {args}
     65
     66    protected method Connect {}
     67    protected method CurrentDatasets {args}
     68    protected method Disconnect {}
     69    protected method DoResize {}
     70    protected method DoRotate {}
     71    protected method AdjustSetting {what {value ""}}
     72    protected method AdjustMode {}
     73    protected method InitSettings { args  }
     74    protected method Pan {option x y}
     75    protected method Pick {x y}
     76    protected method Rebuild {}
     77    protected method ReceiveDataset { args }
     78    protected method ReceiveImage { args }
     79    protected method ReceiveLegend { colormap title min max size }
     80    protected method Rotate {option x y}
     81    protected method Zoom {option}
     82
     83    # The following methods are only used by this class.
     84    private method BuildAxisTab {}
     85    private method BuildCameraTab {}
     86    private method BuildColormap { name }
     87    private method BuildContourTab {}
     88    private method BuildDownloadPopup { widget command }
     89    private method Combo { option }
     90    private method ConvertToVtkData { dataobj comp }
     91    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 }
     99    private method LeaveLegend {}
     100    private method MotionLegend { x y }
     101    private method PanCamera {}
     102    private method RequestLegend {}
     103    private method SetCurrentColormap { color }
     104    private method SetLegendTip { x y }
     105    private method SetObjectStyle { dataobj comp }
     106    private method GetHeightmapScale {}
     107    private method ResetAxes {}
     108    private method SetOrientation { side }
     109
     110    private variable _arcball ""
     111    private variable _dlist ""     ;    # list of data objects
     112    private variable _obj2datasets
     113    private variable _obj2ovride   ;    # maps dataobj => style override
     114    private variable _comp2scale;       # maps dataset to the heightmap scale.
     115    private variable _datasets     ;    # contains all the dataobj-component
     116                                   ;    # datasets in the server
     117    private variable _colormaps    ;    # contains all the colormaps
     118                                   ;    # in the server.
     119
     120    # The name of the current colormap used.  The colormap is global to all
     121    # heightmaps displayed.
     122    private variable _currentColormap ""
     123    private variable _currentNumIsolines -1
     124    private variable _currentOpacity ""
     125
     126    private variable _click        ;    # info used for rotate operations
     127    private variable _limits       ;    # Holds overall limits for all dataobjs
     128                                        # using the viewer.
     129    private variable _view         ;    # view params for 3D view
     130    private variable _settings
     131    private variable _changed
     132    private variable _initialStyle "";  # First found style in dataobjects.
     133    private variable _reset 1;          # Indicates if camera needs to be reset
     134                                        # to starting position.
     135    private variable _beforeConnect 1;  # Indicates if camera needs to be reset
     136                                        # to starting position.
     137
     138    private variable _first ""     ;    # This is the topmost dataset.
     139    private variable _start 0
     140    private variable _isolines
     141
     142    common _downloadPopup;              # download options from popup
     143    private common _hardcopy
     144    private variable _width 0
     145    private variable _height 0
     146    private variable _legendWidth 0
     147    private variable _legendHeight 0
     148    private variable _resizePending 0
     149    private variable _rotatePending 0
     150    private variable _legendPending 0
     151    private variable _fieldNames {}
     152    private variable _fields
     153    private variable _curFldName ""
     154    private variable _curFldLabel ""
     155    private variable _colorMode "vmag";#  Mode of colormap (vmag or scalar)
    156156}
    157157
    158158itk::usual VtkHeightmapViewer {
    159 keep -background -foreground -cursor -font
    160 keep -plotbackground -plotforeground -mode
     159    keep -background -foreground -cursor -font
     160    keep -plotbackground -plotforeground -mode
    161161}
    162162
     
    165165# ----------------------------------------------------------------------
    166166itcl::body Rappture::VtkHeightmapViewer::constructor {hostlist args} {
    167 set _serverType "vtkvis"
    168 
    169 EnableWaitDialog 900
    170 # Rebuild event
    171 $_dispatcher register !rebuild
    172 $_dispatcher dispatch $this !rebuild "[itcl::code $this Rebuild]; list"
    173 
    174 # Resize event
    175 $_dispatcher register !resize
    176 $_dispatcher dispatch $this !resize "[itcl::code $this DoResize]; list"
    177 
    178 # Rotate event
    179 $_dispatcher register !rotate
    180 $_dispatcher dispatch $this !rotate "[itcl::code $this DoRotate]; list"
    181 
    182 # Legend event
    183 $_dispatcher register !legend
    184 $_dispatcher dispatch $this !legend "[itcl::code $this RequestLegend]; list"
    185 
    186 #
    187 # Populate parser with commands handle incoming requests
    188 #
    189 $_parser alias image [itcl::code $this ReceiveImage]
    190 $_parser alias dataset [itcl::code $this ReceiveDataset]
    191 $_parser alias legend [itcl::code $this ReceiveLegend]
    192 
    193 # Initialize the view to some default parameters.
    194 array set _view {
    195 qw      0.36
    196 qx      0.25
    197 qy      0.50
    198 qz      0.70
    199 zoom    1.0
    200 xpan    0
    201 ypan    0
    202 ortho   1
    203 }
    204 set _arcball [blt::arcball create 100 100]
    205 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    206 $_arcball quaternion $q
    207 
    208 array set _settings {
    209 axisFlymode             "static"
    210 axisMinorTicks          1
    211 stretchToFit            0
    212 axisLabels              1
    213 axisVisible             1
    214 axisXGrid               0
    215 axisYGrid               0
    216 axisZGrid               0
    217 colormapVisible         1
    218 colormapDiscrete        0
    219 edges                   0
    220 field                   "Default"
    221 heightmapScale          50
    222 isHeightmap             0
    223 isolineColor            black
    224 isolinesVisible         1
    225 legendVisible           1
    226 lighting                1
    227 saveLighting            1
    228 numIsolines             10
    229 opacity                 100
    230 outline                 0
    231 wireframe               0
    232 saveOpacity             100
    233 saveOutline             0
    234 }
    235 array set _changed {
    236 opacity                 0
    237 colormap                0
    238 numIsolines             0
    239 }
    240 itk_component add view {
    241 canvas $itk_component(plotarea).view \
    242     -highlightthickness 0 -borderwidth 0
    243 } {
    244 usual
    245 ignore -highlightthickness -borderwidth -background
    246 }
    247 
    248 itk_component add fieldmenu {
    249 menu $itk_component(plotarea).menu \
    250     -relief flat \
    251     -tearoff no
    252 } {
    253 usual
    254 ignore -background -foreground -relief -tearoff
    255 }
    256 set c $itk_component(view)
    257 bind $c <Configure> [itcl::code $this EventuallyResize %w %h]
    258 bind $c <4> [itcl::code $this Zoom in 0.25]
    259 bind $c <5> [itcl::code $this Zoom out 0.25]
    260 bind $c <KeyPress-Left>  [list %W xview scroll 10 units]
    261 bind $c <KeyPress-Right> [list %W xview scroll -10 units]
    262 bind $c <KeyPress-Up>    [list %W yview scroll 10 units]
    263 bind $c <KeyPress-Down>  [list %W yview scroll -10 units]
    264 bind $c <Enter> "focus %W"
    265 bind $c <Control-F1> [itcl::code $this ToggleConsole]
    266 
    267 # Fix the scrollregion in case we go off screen
    268 $c configure -scrollregion [$c bbox all]
    269 
    270 set _map(id) [$c create image 0 0 -anchor nw -image $_image(plot)]
    271 set _map(cwidth) -1
    272 set _map(cheight) -1
    273 set _map(zoom) 1.0
    274 set _map(original) ""
    275 
    276 set f [$itk_component(main) component controls]
    277 itk_component add reset {
    278 button $f.reset -borderwidth 1 -padx 1 -pady 1 \
    279     -highlightthickness 0 \
    280     -image [Rappture::icon reset-view] \
    281     -command [itcl::code $this Zoom reset]
    282 } {
    283 usual
    284 ignore -highlightthickness
    285 }
    286 pack $itk_component(reset) -side top -padx 2 -pady 2
    287 Rappture::Tooltip::for $itk_component(reset) "Reset the view to the default zoom level"
    288 
    289 itk_component add zoomin {
    290 button $f.zin -borderwidth 1 -padx 1 -pady 1 \
    291     -highlightthickness 0 \
    292     -image [Rappture::icon zoom-in] \
    293     -command [itcl::code $this Zoom in]
    294 } {
    295 usual
    296 ignore -highlightthickness
    297 }
    298 pack $itk_component(zoomin) -side top -padx 2 -pady 2
    299 Rappture::Tooltip::for $itk_component(zoomin) "Zoom in"
    300 
    301 itk_component add zoomout {
    302 button $f.zout -borderwidth 1 -padx 1 -pady 1 \
    303     -highlightthickness 0 \
    304     -image [Rappture::icon zoom-out] \
    305     -command [itcl::code $this Zoom out]
    306 } {
    307 usual
    308 ignore -highlightthickness
    309 }
    310 pack $itk_component(zoomout) -side top -padx 2 -pady 2
    311 Rappture::Tooltip::for $itk_component(zoomout) "Zoom out"
    312 
    313 itk_component add mode {
    314 Rappture::PushButton $f.mode \
    315     -onimage [Rappture::icon surface] \
    316     -offimage [Rappture::icon surface] \
    317     -variable [itcl::scope _settings(isHeightmap)] \
    318     -command [itcl::code $this AdjustSetting isHeightmap] \
    319 }
    320 Rappture::Tooltip::for $itk_component(mode) \
    321 "Toggle the surface/contour on/off"
    322 pack $itk_component(mode) -padx 2 -pady 2
    323 
    324 if { [catch {
    325 BuildContourTab
    326 BuildAxisTab
    327 BuildCameraTab
    328 } errs] != 0 } {
    329 global errorInfo
    330 puts stderr "errs=$errs errorInfo=$errorInfo"
    331 }
    332 set _image(legend) [image create photo]
    333 
    334 # Hack around the Tk panewindow.  The problem is that the requested
    335 # size of the 3d view isn't set until an image is retrieved from
    336 # the server.  So the panewindow uses the tiny size.
    337 set w 10000
    338 pack forget $itk_component(view)
    339 blt::table $itk_component(plotarea) \
    340 0,0 $itk_component(view) -fill both -reqwidth $w
    341 blt::table configure $itk_component(plotarea) c1 -resize none
    342 
    343 # Bindings for panning via mouse
    344 bind $itk_component(view) <ButtonPress-2> \
    345 [itcl::code $this Pan click %x %y]
    346 bind $itk_component(view) <B2-Motion> \
    347 [itcl::code $this Pan drag %x %y]
    348 bind $itk_component(view) <ButtonRelease-2> \
    349 [itcl::code $this Pan release %x %y]
    350 
    351 #bind $itk_component(view) <ButtonRelease-3> \
    352 #    [itcl::code $this Pick %x %y]
    353 
    354 # Bindings for panning via keyboard
    355 bind $itk_component(view) <KeyPress-Left> \
    356 [itcl::code $this Pan set -10 0]
    357 bind $itk_component(view) <KeyPress-Right> \
    358 [itcl::code $this Pan set 10 0]
    359 bind $itk_component(view) <KeyPress-Up> \
    360 [itcl::code $this Pan set 0 -10]
    361 bind $itk_component(view) <KeyPress-Down> \
    362 [itcl::code $this Pan set 0 10]
    363 bind $itk_component(view) <Shift-KeyPress-Left> \
    364 [itcl::code $this Pan set -2 0]
    365 bind $itk_component(view) <Shift-KeyPress-Right> \
    366 [itcl::code $this Pan set 2 0]
    367 bind $itk_component(view) <Shift-KeyPress-Up> \
    368 [itcl::code $this Pan set 0 -2]
    369 bind $itk_component(view) <Shift-KeyPress-Down> \
    370 [itcl::code $this Pan set 0 2]
    371 
    372 # Bindings for zoom via keyboard
    373 bind $itk_component(view) <KeyPress-Prior> \
    374 [itcl::code $this Zoom out]
    375 bind $itk_component(view) <KeyPress-Next> \
    376 [itcl::code $this Zoom in]
    377 
    378 bind $itk_component(view) <Enter> "focus $itk_component(view)"
    379 
    380 if {[string equal "x11" [tk windowingsystem]]} {
    381 # Bindings for zoom via mouse
    382 bind $itk_component(view) <4> [itcl::code $this Zoom out]
    383 bind $itk_component(view) <5> [itcl::code $this Zoom in]
    384 }
    385 
    386 set _image(download) [image create photo]
    387 
    388 eval itk_initialize $args
    389 Connect
    390 set _beforeConnect 0
     167    set _serverType "vtkvis"
     168
     169    EnableWaitDialog 900
     170    # Rebuild event
     171    $_dispatcher register !rebuild
     172    $_dispatcher dispatch $this !rebuild "[itcl::code $this Rebuild]; list"
     173
     174    # Resize event
     175    $_dispatcher register !resize
     176    $_dispatcher dispatch $this !resize "[itcl::code $this DoResize]; list"
     177
     178    # Rotate event
     179    $_dispatcher register !rotate
     180    $_dispatcher dispatch $this !rotate "[itcl::code $this DoRotate]; list"
     181
     182    # Legend event
     183    $_dispatcher register !legend
     184    $_dispatcher dispatch $this !legend "[itcl::code $this RequestLegend]; list"
     185
     186    #
     187    # Populate parser with commands handle incoming requests
     188    #
     189    $_parser alias image [itcl::code $this ReceiveImage]
     190    $_parser alias dataset [itcl::code $this ReceiveDataset]
     191    $_parser alias legend [itcl::code $this ReceiveLegend]
     192
     193    # Create image for legend colorbar.
     194    set _image(legend) [image create photo]
     195
     196    # Initialize the view to some default parameters.
     197    array set _view {
     198        qw      0.36
     199        qx      0.25
     200        qy      0.50
     201        qz      0.70
     202        zoom    1.0
     203        xpan    0
     204        ypan    0
     205        ortho   0
     206    }
     207    set _arcball [blt::arcball create 100 100]
     208    set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
     209    $_arcball quaternion $q
     210
     211    array set _settings {
     212        axisFlymode             "static"
     213        axisMinorTicks          1
     214        stretchToFit            0
     215        axisLabels              1
     216        axisVisible             1
     217        axisXGrid               0
     218        axisYGrid               0
     219        axisZGrid               0
     220        colormapVisible         1
     221        colormapDiscrete        0
     222        edges                   0
     223        field                   "Default"
     224        heightmapScale          50
     225        isHeightmap             0
     226        isolineColor            black
     227        isolinesVisible         1
     228        legendVisible           1
     229        lighting                1
     230        saveLighting            1
     231        numIsolines             10
     232        opacity                 100
     233        outline                 0
     234        wireframe               0
     235        saveOpacity             100
     236        saveOutline             0
     237    }
     238    array set _changed {
     239        opacity                 0
     240        colormap                0
     241        numIsolines             0
     242    }
     243    itk_component add view {
     244        canvas $itk_component(plotarea).view \
     245            -highlightthickness 0 -borderwidth 0
     246    } {
     247        usual
     248        ignore -highlightthickness -borderwidth -background
     249    }
     250
     251    itk_component add fieldmenu {
     252        menu $itk_component(plotarea).menu \
     253            -relief flat \
     254            -tearoff no
     255    } {
     256        usual
     257        ignore -background -foreground -relief -tearoff
     258    }
     259    set c $itk_component(view)
     260    bind $c <Configure> [itcl::code $this EventuallyResize %w %h]
     261    bind $c <4> [itcl::code $this Zoom in 0.25]
     262    bind $c <5> [itcl::code $this Zoom out 0.25]
     263    bind $c <KeyPress-Left>  [list %W xview scroll 10 units]
     264    bind $c <KeyPress-Right> [list %W xview scroll -10 units]
     265    bind $c <KeyPress-Up>    [list %W yview scroll 10 units]
     266    bind $c <KeyPress-Down>  [list %W yview scroll -10 units]
     267    bind $c <Enter> "focus %W"
     268    bind $c <Control-F1> [itcl::code $this ToggleConsole]
     269
     270    # Fix the scrollregion in case we go off screen
     271    $c configure -scrollregion [$c bbox all]
     272
     273    set _map(id) [$c create image 0 0 -anchor nw -image $_image(plot)]
     274    set _map(cwidth) -1
     275    set _map(cheight) -1
     276    set _map(zoom) 1.0
     277    set _map(original) ""
     278
     279    set f [$itk_component(main) component controls]
     280    itk_component add reset {
     281        button $f.reset -borderwidth 1 -padx 1 -pady 1 \
     282            -highlightthickness 0 \
     283            -image [Rappture::icon reset-view] \
     284            -command [itcl::code $this Zoom reset]
     285    } {
     286        usual
     287        ignore -highlightthickness
     288    }
     289    pack $itk_component(reset) -side top -padx 2 -pady 2
     290    Rappture::Tooltip::for $itk_component(reset) "Reset the view to the default zoom level"
     291
     292    itk_component add zoomin {
     293        button $f.zin -borderwidth 1 -padx 1 -pady 1 \
     294            -highlightthickness 0 \
     295            -image [Rappture::icon zoom-in] \
     296            -command [itcl::code $this Zoom in]
     297    } {
     298        usual
     299        ignore -highlightthickness
     300    }
     301    pack $itk_component(zoomin) -side top -padx 2 -pady 2
     302    Rappture::Tooltip::for $itk_component(zoomin) "Zoom in"
     303
     304    itk_component add zoomout {
     305        button $f.zout -borderwidth 1 -padx 1 -pady 1 \
     306            -highlightthickness 0 \
     307            -image [Rappture::icon zoom-out] \
     308            -command [itcl::code $this Zoom out]
     309    } {
     310        usual
     311        ignore -highlightthickness
     312    }
     313    pack $itk_component(zoomout) -side top -padx 2 -pady 2
     314    Rappture::Tooltip::for $itk_component(zoomout) "Zoom out"
     315
     316    itk_component add mode {
     317        Rappture::PushButton $f.mode \
     318            -onimage [Rappture::icon surface] \
     319            -offimage [Rappture::icon surface] \
     320            -variable [itcl::scope _settings(isHeightmap)] \
     321            -command [itcl::code $this AdjustSetting isHeightmap] \
     322    }
     323    Rappture::Tooltip::for $itk_component(mode) \
     324        "Toggle the surface/contour on/off"
     325    pack $itk_component(mode) -padx 2 -pady 2
     326
     327    if { [catch {
     328        BuildContourTab
     329        BuildAxisTab
     330        BuildCameraTab
     331    } errs] != 0 } {
     332        global errorInfo
     333        puts stderr "errs=$errs errorInfo=$errorInfo"
     334    }
     335
     336    # Hack around the Tk panewindow.  The problem is that the requested
     337    # size of the 3d view isn't set until an image is retrieved from
     338    # the server.  So the panewindow uses the tiny size.
     339    set w 10000
     340    pack forget $itk_component(view)
     341    blt::table $itk_component(plotarea) \
     342        0,0 $itk_component(view) -fill both -reqwidth $w
     343    blt::table configure $itk_component(plotarea) c1 -resize none
     344
     345    # Bindings for panning via mouse
     346    bind $itk_component(view) <ButtonPress-2> \
     347        [itcl::code $this Pan click %x %y]
     348    bind $itk_component(view) <B2-Motion> \
     349        [itcl::code $this Pan drag %x %y]
     350    bind $itk_component(view) <ButtonRelease-2> \
     351        [itcl::code $this Pan release %x %y]
     352
     353    #bind $itk_component(view) <ButtonRelease-3> \
     354    #    [itcl::code $this Pick %x %y]
     355
     356    # Bindings for panning via keyboard
     357    bind $itk_component(view) <KeyPress-Left> \
     358        [itcl::code $this Pan set -10 0]
     359    bind $itk_component(view) <KeyPress-Right> \
     360        [itcl::code $this Pan set 10 0]
     361    bind $itk_component(view) <KeyPress-Up> \
     362        [itcl::code $this Pan set 0 -10]
     363    bind $itk_component(view) <KeyPress-Down> \
     364        [itcl::code $this Pan set 0 10]
     365    bind $itk_component(view) <Shift-KeyPress-Left> \
     366        [itcl::code $this Pan set -2 0]
     367    bind $itk_component(view) <Shift-KeyPress-Right> \
     368        [itcl::code $this Pan set 2 0]
     369    bind $itk_component(view) <Shift-KeyPress-Up> \
     370        [itcl::code $this Pan set 0 -2]
     371    bind $itk_component(view) <Shift-KeyPress-Down> \
     372        [itcl::code $this Pan set 0 2]
     373
     374    # Bindings for zoom via keyboard
     375    bind $itk_component(view) <KeyPress-Prior> \
     376        [itcl::code $this Zoom out]
     377    bind $itk_component(view) <KeyPress-Next> \
     378        [itcl::code $this Zoom in]
     379
     380    bind $itk_component(view) <Enter> "focus $itk_component(view)"
     381
     382    if {[string equal "x11" [tk windowingsystem]]} {
     383        # Bindings for zoom via mouse
     384        bind $itk_component(view) <4> [itcl::code $this Zoom out]
     385        bind $itk_component(view) <5> [itcl::code $this Zoom in]
     386    }
     387
     388    set _image(download) [image create photo]
     389
     390    eval itk_initialize $args
     391    Connect
     392    set _beforeConnect 0
    391393}
    392394
     
    395397# ----------------------------------------------------------------------
    396398itcl::body Rappture::VtkHeightmapViewer::destructor {} {
    397 Disconnect
    398 image delete $_image(plot)
    399 image delete $_image(download)
    400 catch { blt::arcball destroy $_arcball }
     399    Disconnect
     400    image delete $_image(plot)
     401    image delete $_image(download)
     402    catch { blt::arcball destroy $_arcball }
    401403}
    402404
    403405itcl::body Rappture::VtkHeightmapViewer::DoResize {} {
    404 if { $_width < 2 } {
    405 set _width 500
    406 }
    407 if { $_height < 2 } {
    408 set _height 500
    409 }
    410 set _start [clock clicks -milliseconds]
    411 SendCmd "screen size [expr $_width - 20] $_height"
    412 
    413 set font "Arial 8"
    414 set lh [font metrics $font -linespace]
    415 set h [expr {$_height - 2 * ($lh + 2)}]
    416 if { $h != $_legendHeight } {
    417 EventuallyRequestLegend
    418 } else {
    419 DrawLegend
    420 }
    421 set _resizePending 0
     406    if { $_width < 2 } {
     407        set _width 500
     408    }
     409    if { $_height < 2 } {
     410        set _height 500
     411    }
     412    set _start [clock clicks -milliseconds]
     413    SendCmd "screen size [expr $_width - 20] $_height"
     414
     415    set font "Arial 8"
     416    set lh [font metrics $font -linespace]
     417    set h [expr {$_height - 2 * ($lh + 2)}]
     418    if { $h != $_legendHeight } {
     419        EventuallyRequestLegend
     420    } else {
     421        DrawLegend
     422    }
     423    set _resizePending 0
    422424}
    423425
    424426itcl::body Rappture::VtkHeightmapViewer::DoRotate {} {
    425 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    426 SendCmd "camera orient $q"
    427 set _rotatePending 0
     427    set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
     428    SendCmd "camera orient $q"
     429    set _rotatePending 0
    428430}
    429431
    430432itcl::body Rappture::VtkHeightmapViewer::EventuallyRequestLegend {} {
    431 if { !$_legendPending } {
    432 set _legendPending 1
    433 $_dispatcher event -idle !legend
    434 }
     433    if { !$_legendPending } {
     434        set _legendPending 1
     435        $_dispatcher event -idle !legend
     436    }
    435437}
    436438
    437439itcl::body Rappture::VtkHeightmapViewer::EventuallyResize { w h } {
    438 set _width $w
    439 set _height $h
    440 $_arcball resize $w $h
    441 if { !$_resizePending } {
    442 set _resizePending 1
    443 $_dispatcher event -after 250 !resize
    444 }
     440    set _width $w
     441    set _height $h
     442    $_arcball resize $w $h
     443    if { !$_resizePending } {
     444        set _resizePending 1
     445        $_dispatcher event -after 250 !resize
     446    }
    445447}
    446448
     
    448450
    449451itcl::body Rappture::VtkHeightmapViewer::EventuallyRotate { q } {
    450 foreach { _view(qw) _view(qx) _view(qy) _view(qz) } $q break
    451 if { !$_rotatePending } {
    452 set _rotatePending 1
    453 global rotate_delay
    454 $_dispatcher event -after $rotate_delay !rotate
    455 }
     452    foreach { _view(qw) _view(qx) _view(qy) _view(qz) } $q break
     453    if { !$_rotatePending } {
     454        set _rotatePending 1
     455        global rotate_delay
     456        $_dispatcher event -after $rotate_delay !rotate
     457    }
    456458}
    457459
     
    464466# ----------------------------------------------------------------------
    465467itcl::body Rappture::VtkHeightmapViewer::add {dataobj {settings ""}} {
    466 if { ![$dataobj isvalid] } {
    467 return;                         # Object doesn't contain valid data.
    468 }
    469 array set params {
    470 -color auto
    471 -width 1
    472 -linestyle solid
    473 -brightness 0
    474 -raise 0
    475 -description ""
    476 -param ""
    477 -type ""
    478 }
    479 array set params $settings
    480 set params(-description) ""
    481 set params(-param) ""
    482 foreach {opt val} $settings {
    483 if {![info exists params($opt)]} {
    484     error "bad setting \"$opt\": should be [join [lsort [array names params]] {, }]"
    485 }
    486 set params($opt) $val
    487 }
    488 if {$params(-color) == "auto" || $params(-color) == "autoreset"} {
    489 # can't handle -autocolors yet
    490 set params(-color) white
    491 }
    492 set pos [lsearch -exact $dataobj $_dlist]
    493 if {$pos < 0} {
    494 lappend _dlist $dataobj
    495 }
    496 set _obj2ovride($dataobj-color) $params(-color)
    497 set _obj2ovride($dataobj-width) $params(-width)
    498 set _obj2ovride($dataobj-raise) $params(-raise)
    499 $_dispatcher event -idle !rebuild
     468    if { ![$dataobj isvalid] } {
     469        return;                         # Object doesn't contain valid data.
     470    }
     471    array set params {
     472        -color auto
     473        -width 1
     474        -linestyle solid
     475        -brightness 0
     476        -raise 0
     477        -description ""
     478        -param ""
     479        -type ""
     480    }
     481    array set params $settings
     482    set params(-description) ""
     483    set params(-param) ""
     484    foreach {opt val} $settings {
     485        if {![info exists params($opt)]} {
     486            error "bad setting \"$opt\": should be [join [lsort [array names params]] {, }]"
     487        }
     488        set params($opt) $val
     489    }
     490    if {$params(-color) == "auto" || $params(-color) == "autoreset"} {
     491        # can't handle -autocolors yet
     492        set params(-color) white
     493    }
     494    set pos [lsearch -exact $dataobj $_dlist]
     495    if {$pos < 0} {
     496        lappend _dlist $dataobj
     497    }
     498    set _obj2ovride($dataobj-color) $params(-color)
     499    set _obj2ovride($dataobj-width) $params(-width)
     500    set _obj2ovride($dataobj-raise) $params(-raise)
     501    $_dispatcher event -idle !rebuild
    500502}
    501503
     
    510512# ----------------------------------------------------------------------
    511513itcl::body Rappture::VtkHeightmapViewer::delete {args} {
    512 if { [llength $args] == 0} {
    513 set args $_dlist
    514 }
    515 # Delete all specified dataobjs
    516 set changed 0
    517 foreach dataobj $args {
    518 set pos [lsearch -exact $_dlist $dataobj]
    519 if { $pos < 0 } {
    520     continue;                   # Don't know anything about it.
    521 }
    522 # Remove it from the dataobj list.
    523 set _dlist [lreplace $_dlist $pos $pos]
    524 array unset _obj2ovride $dataobj-*
    525 array unset _settings $dataobj-*
    526 # Append to the end of the dataobj list.
    527 #lappend _dlist $dataobj
    528 set changed 1
    529 }
    530 # If anything changed, then rebuild the plot
    531 if { $changed } {
    532 $_dispatcher event -idle !rebuild
    533 }
     514    if { [llength $args] == 0} {
     515        set args $_dlist
     516    }
     517    # Delete all specified dataobjs
     518    set changed 0
     519    foreach dataobj $args {
     520        set pos [lsearch -exact $_dlist $dataobj]
     521        if { $pos < 0 } {
     522            continue;                   # Don't know anything about it.
     523        }
     524        # Remove it from the dataobj list.
     525        set _dlist [lreplace $_dlist $pos $pos]
     526        array unset _obj2ovride $dataobj-*
     527        array unset _settings $dataobj-*
     528        # Append to the end of the dataobj list.
     529        #lappend _dlist $dataobj
     530        set changed 1
     531    }
     532    # If anything changed, then rebuild the plot
     533    if { $changed } {
     534        $_dispatcher event -idle !rebuild
     535    }
    534536}
    535537
     
    544546# ----------------------------------------------------------------------
    545547itcl::body Rappture::VtkHeightmapViewer::get {args} {
    546 if {[llength $args] == 0} {
    547 set args "-objects"
    548 }
    549 set op [lindex $args 0]
    550 switch -- $op {
    551 "-objects" {
    552     # put the dataobj list in order according to -raise options
    553     set dlist {}
    554     foreach dataobj $_dlist {
    555         if { ![IsValidObject $dataobj] } {
    556             continue
    557         }
    558         if {[info exists _obj2ovride($dataobj-raise)] &&
    559             $_obj2ovride($dataobj-raise)} {
    560             set dlist [linsert $dlist 0 $dataobj]
    561         } else {
    562             lappend dlist $dataobj
    563         }
    564     }
    565     return $dlist
    566 }
    567 "-visible" {
    568     set dlist {}
    569     foreach dataobj $_dlist {
    570         if { ![IsValidObject $dataobj] } {
    571             continue
    572         }
    573         if { ![info exists _obj2ovride($dataobj-raise)] } {
    574             # No setting indicates that the object isn't visible.
    575             continue
    576         }
    577         # Otherwise use the -raise parameter to put the object to
    578         # the front of the list.
    579         if { $_obj2ovride($dataobj-raise) } {
    580             set dlist [linsert $dlist 0 $dataobj]
    581         } else {
    582             lappend dlist $dataobj
    583         }
    584     }
    585     return $dlist
    586 }           
    587 -image {
    588     if {[llength $args] != 2} {
    589         error "wrong # args: should be \"get -image view\""
    590     }
    591     switch -- [lindex $args end] {
    592         view {
    593             return $_image(plot)
    594         }
    595         default {
    596             error "bad image name \"[lindex $args end]\": should be view"
    597         }
    598     }
    599 }
    600 default {
    601     error "bad option \"$op\": should be -objects or -image"
    602 }
    603 }
     548    if {[llength $args] == 0} {
     549        set args "-objects"
     550    }
     551    set op [lindex $args 0]
     552    switch -- $op {
     553        "-objects" {
     554            # put the dataobj list in order according to -raise options
     555            set dlist {}
     556            foreach dataobj $_dlist {
     557                if { ![IsValidObject $dataobj] } {
     558                    continue
     559                }
     560                if {[info exists _obj2ovride($dataobj-raise)] &&
     561                    $_obj2ovride($dataobj-raise)} {
     562                    set dlist [linsert $dlist 0 $dataobj]
     563                } else {
     564                    lappend dlist $dataobj
     565                }
     566            }
     567            return $dlist
     568        }
     569        "-visible" {
     570            set dlist {}
     571            foreach dataobj $_dlist {
     572                if { ![IsValidObject $dataobj] } {
     573                    continue
     574                }
     575                if { ![info exists _obj2ovride($dataobj-raise)] } {
     576                    # No setting indicates that the object isn't visible.
     577                    continue
     578                }
     579                # Otherwise use the -raise parameter to put the object to
     580                # the front of the list.
     581                if { $_obj2ovride($dataobj-raise) } {
     582                    set dlist [linsert $dlist 0 $dataobj]
     583                } else {
     584                    lappend dlist $dataobj
     585                }
     586            }
     587            return $dlist
     588        }           
     589        -image {
     590            if {[llength $args] != 2} {
     591                error "wrong # args: should be \"get -image view\""
     592            }
     593            switch -- [lindex $args end] {
     594                view {
     595                    return $_image(plot)
     596                }
     597                default {
     598                    error "bad image name \"[lindex $args end]\": should be view"
     599                }
     600            }
     601        }
     602        default {
     603            error "bad option \"$op\": should be -objects or -image"
     604        }
     605    }
    604606}
    605607
     
    614616#
    615617itcl::body Rappture::VtkHeightmapViewer::scale {args} {
    616 foreach dataobj $args {
    617 if { ![$dataobj isvalid] } {
    618     continue;                   # Object doesn't contain valid data.
    619 }
    620 foreach axis { x y } {
    621     set lim [$dataobj limits $axis]
    622     if { ![info exists _limits($axis)] } {
    623         set _limits($axis) $lim
    624         continue
    625     }
    626     foreach {min max} $lim break
    627     foreach {amin amax} $_limits($axis) break
    628     if { $amin > $min } {
    629         set amin $min
    630     }
    631     if { $amax < $max } {
    632         set amax $max
    633     }
    634     set _limits($axis) [list $amin $amax]
    635 }
    636 foreach { fname lim } [$dataobj fieldlimits] {
    637     if { ![info exists _limits($fname)] } {
    638         set _limits($fname) $lim
    639         continue
    640     }
    641     foreach {min max} $lim break
    642     foreach {fmin fmax} $_limits($fname) break
    643     if { $fmin > $min } {
    644         set fmin $min
    645     }
    646     if { $fmax < $max } {
    647         set fmax $max
    648     }
    649     set _limits($fname) [list $fmin $fmax]
    650 }
    651 }
     618    foreach dataobj $args {
     619        if { ![$dataobj isvalid] } {
     620            continue;                   # Object doesn't contain valid data.
     621        }
     622        foreach axis { x y } {
     623            set lim [$dataobj limits $axis]
     624            if { ![info exists _limits($axis)] } {
     625                set _limits($axis) $lim
     626                continue
     627            }
     628            foreach {min max} $lim break
     629            foreach {amin amax} $_limits($axis) break
     630            if { $amin > $min } {
     631                set amin $min
     632            }
     633            if { $amax < $max } {
     634                set amax $max
     635            }
     636            set _limits($axis) [list $amin $amax]
     637        }
     638        foreach { fname lim } [$dataobj fieldlimits] {
     639            if { ![info exists _limits($fname)] } {
     640                set _limits($fname) $lim
     641                continue
     642            }
     643            foreach {min max} $lim break
     644            foreach {fmin fmax} $_limits($fname) break
     645            if { $fmin > $min } {
     646                set fmin $min
     647            }
     648            if { $fmax < $max } {
     649                set fmax $max
     650            }
     651            set _limits($fname) [list $fmin $fmax]
     652        }
     653    }
    652654}
    653655
     
    663665# ----------------------------------------------------------------------
    664666itcl::body Rappture::VtkHeightmapViewer::download {option args} {
    665 switch $option {
    666 coming {
    667     if {[catch {
    668         blt::winop snap $itk_component(plotarea) $_image(download)
    669     }]} {
    670         $_image(download) configure -width 1 -height 1
    671         $_image(download) put #000000
    672     }
    673 }
    674 controls {
    675     set popup .vtkviewerdownload
    676     if { ![winfo exists .vtkviewerdownload] } {
    677         set inner [BuildDownloadPopup $popup [lindex $args 0]]
    678     } else {
    679         set inner [$popup component inner]
    680     }
    681     set _downloadPopup(image_controls) $inner.image_frame
    682     set num [llength [get]]
    683     set num [expr {($num == 1) ? "1 result" : "$num results"}]
    684     set word [Rappture::filexfer::label downloadWord]
    685     $inner.summary configure -text "$word $num in the following format:"
    686     update idletasks            ;# Fix initial sizes
    687     return $popup
    688 }
    689 now {
    690     set popup .vtkviewerdownload
    691     if {[winfo exists .vtkviewerdownload]} {
    692         $popup deactivate
    693     }
    694     switch -- $_downloadPopup(format) {
    695         "image" {
    696             return [$this GetImage [lindex $args 0]]
    697         }
    698         "vtk" {
    699             return [$this GetVtkData [lindex $args 0]]
    700         }
    701     }
    702     return ""
    703 }
    704 default {
    705     error "bad option \"$option\": should be coming, controls, now"
    706 }
    707 }
     667    switch $option {
     668        coming {
     669            if {[catch {
     670                blt::winop snap $itk_component(plotarea) $_image(download)
     671            }]} {
     672                $_image(download) configure -width 1 -height 1
     673                $_image(download) put #000000
     674            }
     675        }
     676        controls {
     677            set popup .vtkviewerdownload
     678            if { ![winfo exists .vtkviewerdownload] } {
     679                set inner [BuildDownloadPopup $popup [lindex $args 0]]
     680            } else {
     681                set inner [$popup component inner]
     682            }
     683            set _downloadPopup(image_controls) $inner.image_frame
     684            set num [llength [get]]
     685            set num [expr {($num == 1) ? "1 result" : "$num results"}]
     686            set word [Rappture::filexfer::label downloadWord]
     687            $inner.summary configure -text "$word $num in the following format:"
     688            update idletasks            ;# Fix initial sizes
     689            return $popup
     690        }
     691        now {
     692            set popup .vtkviewerdownload
     693            if {[winfo exists .vtkviewerdownload]} {
     694                $popup deactivate
     695            }
     696            switch -- $_downloadPopup(format) {
     697                "image" {
     698                    return [$this GetImage [lindex $args 0]]
     699                }
     700                "vtk" {
     701                    return [$this GetVtkData [lindex $args 0]]
     702                }
     703            }
     704            return ""
     705        }
     706        default {
     707            error "bad option \"$option\": should be coming, controls, now"
     708        }
     709    }
    708710}
    709711
     
    716718# ----------------------------------------------------------------------
    717719itcl::body Rappture::VtkHeightmapViewer::Connect {} {
    718 global readyForNextFrame
    719 set readyForNextFrame 1
    720 set _reset 1
    721 set _hosts [GetServerList "vtkvis"]
    722 if { "" == $_hosts } {
    723 return 0
    724 }
    725 set result [VisViewer::Connect $_hosts]
    726 if { $result } {
    727 set w [winfo width $itk_component(view)]
    728 set h [winfo height $itk_component(view)]
    729 EventuallyResize $w $h
    730 }
    731 return $result
     720    global readyForNextFrame
     721    set readyForNextFrame 1
     722    set _reset 1
     723    set _hosts [GetServerList "vtkvis"]
     724    if { "" == $_hosts } {
     725        return 0
     726    }
     727    set result [VisViewer::Connect $_hosts]
     728    if { $result } {
     729        set w [winfo width $itk_component(view)]
     730        set h [winfo height $itk_component(view)]
     731        EventuallyResize $w $h
     732    }
     733    return $result
    732734}
    733735
     
    738740#
    739741itcl::body Rappture::VtkHeightmapViewer::isconnected {} {
    740 return [VisViewer::IsConnected]
     742    return [VisViewer::IsConnected]
    741743}
    742744
     
    745747#
    746748itcl::body Rappture::VtkHeightmapViewer::disconnect {} {
    747 Disconnect
    748 set _reset 1
     749    Disconnect
     750    set _reset 1
    749751}
    750752
     
    756758#
    757759itcl::body Rappture::VtkHeightmapViewer::Disconnect {} {
    758 VisViewer::Disconnect
    759 
    760 $_dispatcher cancel !rebuild
    761 $_dispatcher cancel !resize
    762 $_dispatcher cancel !rotate
    763 $_dispatcher cancel !legend
    764 # disconnected -- no more data sitting on server
    765 array unset _datasets
    766 array unset _data
    767 array unset _colormaps
    768 array unset _obj2datasets
    769 global readyForNextFrame
    770 set readyForNextFrame 1
     760    VisViewer::Disconnect
     761
     762    $_dispatcher cancel !rebuild
     763    $_dispatcher cancel !resize
     764    $_dispatcher cancel !rotate
     765    $_dispatcher cancel !legend
     766    # disconnected -- no more data sitting on server
     767    array unset _datasets
     768    array unset _data
     769    array unset _colormaps
     770    array unset _obj2datasets
     771    global readyForNextFrame
     772    set readyForNextFrame 1
    771773}
    772774
     
    779781# ----------------------------------------------------------------------
    780782itcl::body Rappture::VtkHeightmapViewer::ReceiveImage { args } {
    781 global readyForNextFrame
    782 set readyForNextFrame 1
    783 array set info {
    784 -token "???"
    785 -bytes 0
    786 -type image
    787 }
    788 array set info $args
    789 set bytes [ReceiveBytes $info(-bytes)]
    790 if { $info(-type) == "image" } {
    791 if 0 {
    792     set f [open "last.ppm" "w"]
    793     puts $f $bytes
    794     close $f
    795 }
    796 $_image(plot) configure -data $bytes
    797 set time [clock seconds]
    798 set date [clock format $time]
    799 #puts stderr "$date: received image [image width $_image(plot)]x[image height $_image(plot)] image>"       
    800 if { $_start > 0 } {
    801     set finish [clock clicks -milliseconds]
    802     #puts stderr "round trip time [expr $finish -$_start] milliseconds"
    803     set _start 0
    804 }
    805 } elseif { $info(type) == "print" } {
    806 set tag $this-print-$info(-token)
    807 set _hardcopy($tag) $bytes
    808 }
     783    global readyForNextFrame
     784    set readyForNextFrame 1
     785    array set info {
     786        -token "???"
     787        -bytes 0
     788        -type image
     789    }
     790    array set info $args
     791    set bytes [ReceiveBytes $info(-bytes)]
     792    if { $info(-type) == "image" } {
     793        if 0 {
     794            set f [open "last.ppm" "w"]
     795            puts $f $bytes
     796            close $f
     797        }
     798        $_image(plot) configure -data $bytes
     799        set time [clock seconds]
     800        set date [clock format $time]
     801        #puts stderr "$date: received image [image width $_image(plot)]x[image height $_image(plot)] image>"       
     802        if { $_start > 0 } {
     803            set finish [clock clicks -milliseconds]
     804            #puts stderr "round trip time [expr $finish -$_start] milliseconds"
     805            set _start 0
     806        }
     807    } elseif { $info(type) == "print" } {
     808        set tag $this-print-$info(-token)
     809        set _hardcopy($tag) $bytes
     810    }
    809811}
    810812
     
    813815#
    814816itcl::body Rappture::VtkHeightmapViewer::ReceiveDataset { args } {
    815 if { ![isconnected] } {
    816 return
    817 }
    818 set option [lindex $args 0]
    819 switch -- $option {
    820 "scalar" {
    821     set option [lindex $args 1]
     817    if { ![isconnected] } {
     818        return
     819    }
     820    set option [lindex $args 0]
    822821    switch -- $option {
    823         "world" {
    824             foreach { x y z value tag } [lrange $args 2 end] break
    825         }
    826         "pixel" {
    827             foreach { x y value tag } [lrange $args 2 end] break
    828         }
    829     }
    830 }
    831 "vector" {
    832     set option [lindex $args 1]
    833     switch -- $option {
    834         "world" {
    835             foreach { x y z vx vy vz tag } [lrange $args 2 end] break
    836         }
    837         "pixel" {
    838             foreach { x y vx vy vz tag } [lrange $args 2 end] break
    839         }
    840     }
    841 }
    842 "names" {
    843     foreach { name } [lindex $args 1] {
    844         #puts stderr "Dataset: $name"
    845     }
    846 }
    847 default {
    848     error "unknown dataset option \"$option\" from server"
    849 }
    850 }
     822        "scalar" {
     823            set option [lindex $args 1]
     824            switch -- $option {
     825                "world" {
     826                    foreach { x y z value tag } [lrange $args 2 end] break
     827                }
     828                "pixel" {
     829                    foreach { x y value tag } [lrange $args 2 end] break
     830                }
     831            }
     832        }
     833        "vector" {
     834            set option [lindex $args 1]
     835            switch -- $option {
     836                "world" {
     837                    foreach { x y z vx vy vz tag } [lrange $args 2 end] break
     838                }
     839                "pixel" {
     840                    foreach { x y vx vy vz tag } [lrange $args 2 end] break
     841                }
     842            }
     843        }
     844        "names" {
     845            foreach { name } [lindex $args 1] {
     846                #puts stderr "Dataset: $name"
     847            }
     848        }
     849        default {
     850            error "unknown dataset option \"$option\" from server"
     851        }
     852    }
    851853}
    852854
     
    859861# ----------------------------------------------------------------------
    860862itcl::body Rappture::VtkHeightmapViewer::Rebuild {} {
    861 set w [winfo width $itk_component(view)]
    862 set h [winfo height $itk_component(view)]
    863 if { $w < 2 || $h < 2 } {
    864 $_dispatcher event -idle !rebuild
    865 return
    866 }
    867 
    868 if { $_reset && $_reportClientInfo }  {
    869 # Tell the server the name of the tool, the version, and dataset
    870 # that we are rendering.  Have to do it here because we don't know
    871 # what data objects are using the renderer until be get here.
    872 global env
    873 
    874 set info {}
    875 set user "???"
    876 if { [info exists env(USER)] } {
    877     set user $env(USER)
    878 }
    879 set session "???"
    880 if { [info exists env(SESSION)] } {
    881     set session $env(SESSION)
    882 }
    883 lappend info "hub" [exec hostname]
    884 lappend info "client" "vtkheightmapviewer"
    885 lappend info "user" $user
    886 lappend info "session" $session
    887 SendCmd "clientinfo [list $info]"
    888 }
    889 
    890 # Turn on buffering of commands to the server.  We don't want to
    891 # be preempted by a server disconnect/reconnect (which automatically
    892 # generates a new call to Rebuild).   
    893 StartBufferingCommands
    894 
    895 if { $_width != $w || $_height != $h || $_reset } {
    896 set _width $w
    897 set _height $h
    898 $_arcball resize $w $h
    899 DoResize
    900 if { $_settings(stretchToFit) } {
    901     AdjustSetting stretchToFit
    902 }
    903 }
    904 if { $_reset } {
    905 InitSettings isHeightmap background
    906 #
    907 # Reset the camera and other view parameters
    908 #
    909 SendCmd "axis color all [Color2RGB $itk_option(-plotforeground)]"
    910 
    911 # Let's see how this goes.  I think it's preferable to overloading the
    912 # axis title with the exponent.
    913 SendCmd "axis exp 0 0 0 1"
    914 
    915 SendCmd "axis lrot z 90"
    916 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    917 $_arcball quaternion $q
    918 if {$_settings(isHeightmap) } {
    919     if { $_view(ortho)} {
    920         SendCmd "camera mode ortho"
    921     } else {
    922         SendCmd "camera mode persp"
    923     }
    924     DoRotate
    925     SendCmd "camera reset"
    926 }
    927 PanCamera
    928 StopBufferingCommands
    929 SendCmd "imgflush"
    930 StartBufferingCommands
    931 }
    932 
    933 set _first ""
    934 # Start off with no datasets are visible.
    935 SendCmd "dataset visible 0"
    936 set scale [GetHeightmapScale]
    937 foreach dataobj [get -objects] {
    938 if { [info exists _obj2ovride($dataobj-raise)] &&  $_first == "" } {
    939     set _first $dataobj
    940 }
    941 set _obj2datasets($dataobj) ""
    942 foreach comp [$dataobj components] {
    943     set tag $dataobj-$comp
    944     if { ![info exists _datasets($tag)] } {
    945         set bytes [$dataobj vtkdata $comp]
    946         if 0 {
    947             set f [open /tmp/vtkheightmap.vtk "w"]
    948             puts $f $bytes
    949             close $f
    950         }
    951         set length [string length $bytes]
    952         if { $_reportClientInfo }  {
    953             set info {}
    954             lappend info "tool_id"       [$dataobj hints toolId]
    955             lappend info "tool_name"     [$dataobj hints toolName]
    956             lappend info "tool_version"  [$dataobj hints toolRevision]
    957             lappend info "tool_title"    [$dataobj hints toolTitle]
    958             lappend info "dataset_label" [$dataobj hints label]
    959             lappend info "dataset_size"  $length
    960             lappend info "dataset_tag"   $tag
    961             SendCmd [list "clientinfo" $info]
    962         }
    963         SendCmd "dataset add $tag data follows $length"
    964         append _outbuf $bytes
    965         set _datasets($tag) 1
    966         SetObjectStyle $dataobj $comp
    967     }
    968     lappend _obj2datasets($dataobj) $tag
    969     if { [info exists _obj2ovride($dataobj-raise)] } {
    970         # Setting dataset visible enables outline
    971         # and heightmap
    972         SendCmd "dataset visible 1 $tag"
    973     }
    974     if { ![info exists _comp2scale($tag)] ||
    975         $_comp2scale($tag) != $scale } {
    976         SendCmd "heightmap heightscale $scale $tag"
    977         set _comp2scale($tag) $scale
    978     }
    979 }
    980 }
    981 if { $_first != ""  } {
    982 $itk_component(field) choices delete 0 end
    983 $itk_component(fieldmenu) delete 0 end
    984 array unset _fields
    985 set _curFldName ""
    986 foreach cname [$_first components] {
    987     foreach fname [$_first fieldnames $cname] {
    988         if { [info exists _fields($fname)] } {
    989             continue
    990         }
    991         foreach { label units components } \
    992             [$_first fieldinfo $fname] break
    993         $itk_component(field) choices insert end "$fname" "$label"
    994         $itk_component(fieldmenu) add radiobutton -label "$label" \
    995             -value $label -variable [itcl::scope _curFldLabel] \
    996             -selectcolor red \
    997             -activebackground $itk_option(-plotbackground) \
    998             -activeforeground $itk_option(-plotforeground) \
    999             -font "Arial 8" \
    1000             -command [itcl::code $this Combo invoke]
    1001         set _fields($fname) [list $label $units $components]
    1002         if { $_curFldName == "" } {
    1003             set _curFldName $fname
    1004             set _curFldLabel $label
    1005         }
    1006     }
    1007 }
    1008 $itk_component(field) value $_curFldLabel
    1009 }
    1010 InitSettings stretchToFit outline
    1011 
    1012 if { $_reset } {
    1013 SendCmd "axis tickpos outside"
    1014 foreach axis { x y z } {
    1015     SendCmd "axis lformat $axis %g"
    1016 }
    1017 
    1018 foreach axis { x y z } {
    1019     set label [$_first hints ${axis}label]
    1020     if { $label == "" } {
    1021         if {$axis == "z"} {
    1022             if { [string match "component*" $_curFldName] } {
    1023                 set label [string toupper $axis]
    1024             } else {
    1025                 set label $_curFldLabel
    1026             }
    1027         } else {
    1028             set label [string toupper $axis]
    1029         }
    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         set units [lindex $_fields($_curFldName) 1]
    1036     } else {
    1037         set units [$_first hints ${axis}units]
    1038     }
    1039     if { $units != "" } {
    1040         # May be a space in the axis units.
    1041         SendCmd [list axis units $axis $units]
    1042     }
    1043 }
    1044 #
    1045 # Reset the camera and other view parameters
    1046 #
    1047 SendCmd "axis color all [Color2RGB $itk_option(-plotforeground)]"
    1048 SendCmd "outline color [Color2RGB $itk_option(-plotforeground)]"
    1049 ResetAxes
    1050 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    1051 $_arcball quaternion $q
    1052 if {$_settings(isHeightmap) } {
    1053     if { $_view(ortho)} {
    1054         SendCmd "camera mode ortho"
    1055     } else {
    1056         SendCmd "camera mode persp"
    1057     }
    1058     DoRotate
    1059     SendCmd "camera reset"
    1060 }
    1061 PanCamera
    1062 InitSettings axisXGrid axisYGrid axisZGrid \
    1063     axisVisible axisLabels
    1064 InitSettings heightmapScale field isHeightmap
    1065 if { [array size _fields] < 2 } {
    1066     catch {
    1067         blt::table forget $itk_component(field) $itk_component(field_l)
    1068     }
    1069 }
    1070 RequestLegend
    1071 set _reset 0
    1072 }
    1073 global readyForNextFrame
    1074 set readyForNextFrame 0;                # Don't advance to the next frame
    1075 
    1076 # Actually write the commands to the server socket.  If it fails, we don't
    1077 # care.  We're finished here.
    1078 blt::busy hold $itk_component(hull)
    1079 StopBufferingCommands
    1080 blt::busy release $itk_component(hull)
     863    set w [winfo width $itk_component(view)]
     864    set h [winfo height $itk_component(view)]
     865    if { $w < 2 || $h < 2 } {
     866        $_dispatcher event -idle !rebuild
     867        return
     868    }
     869
     870    if { $_reset && $_reportClientInfo }  {
     871        # Tell the server the name of the tool, the version, and dataset
     872        # that we are rendering.  Have to do it here because we don't know
     873        # what data objects are using the renderer until be get here.
     874        global env
     875
     876        set info {}
     877        set user "???"
     878        if { [info exists env(USER)] } {
     879            set user $env(USER)
     880        }
     881        set session "???"
     882        if { [info exists env(SESSION)] } {
     883            set session $env(SESSION)
     884        }
     885        lappend info "hub" [exec hostname]
     886        lappend info "client" "vtkheightmapviewer"
     887        lappend info "user" $user
     888        lappend info "session" $session
     889        SendCmd "clientinfo [list $info]"
     890    }
     891
     892    # Turn on buffering of commands to the server.  We don't want to
     893    # be preempted by a server disconnect/reconnect (which automatically
     894    # generates a new call to Rebuild).   
     895    StartBufferingCommands
     896
     897    if { $_width != $w || $_height != $h || $_reset } {
     898        set _width $w
     899        set _height $h
     900        $_arcball resize $w $h
     901        DoResize
     902        if { $_settings(stretchToFit) } {
     903            AdjustSetting stretchToFit
     904        }
     905    }
     906    if { $_reset } {
     907        InitSettings isHeightmap background
     908        #
     909        # Reset the camera and other view parameters
     910        #
     911        SendCmd "axis color all [Color2RGB $itk_option(-plotforeground)]"
     912
     913        # Let's see how this goes.  I think it's preferable to overloading the
     914        # axis title with the exponent.
     915        SendCmd "axis exp 0 0 0 1"
     916
     917        SendCmd "axis lrot z 90"
     918        set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
     919        $_arcball quaternion $q
     920        if {$_settings(isHeightmap) } {
     921            if { $_view(ortho)} {
     922                SendCmd "camera mode ortho"
     923            } else {
     924                SendCmd "camera mode persp"
     925            }
     926            DoRotate
     927            SendCmd "camera reset"
     928        }
     929        PanCamera
     930        StopBufferingCommands
     931        SendCmd "imgflush"
     932        StartBufferingCommands
     933    }
     934
     935    set _first ""
     936    # Start off with no datasets are visible.
     937    SendCmd "dataset visible 0"
     938    set scale [GetHeightmapScale]
     939    foreach dataobj [get -objects] {
     940        if { [info exists _obj2ovride($dataobj-raise)] &&  $_first == "" } {
     941            set _first $dataobj
     942        }
     943        set _obj2datasets($dataobj) ""
     944        foreach comp [$dataobj components] {
     945            set tag $dataobj-$comp
     946            if { ![info exists _datasets($tag)] } {
     947                set bytes [$dataobj vtkdata $comp]
     948                if 0 {
     949                    set f [open /tmp/vtkheightmap.vtk "w"]
     950                    puts $f $bytes
     951                    close $f
     952                }
     953                set length [string length $bytes]
     954                if { $_reportClientInfo }  {
     955                    set info {}
     956                    lappend info "tool_id"       [$dataobj hints toolId]
     957                    lappend info "tool_name"     [$dataobj hints toolName]
     958                    lappend info "tool_version"  [$dataobj hints toolRevision]
     959                    lappend info "tool_title"    [$dataobj hints toolTitle]
     960                    lappend info "dataset_label" [$dataobj hints label]
     961                    lappend info "dataset_size"  $length
     962                    lappend info "dataset_tag"   $tag
     963                    SendCmd [list "clientinfo" $info]
     964                }
     965                SendCmd "dataset add $tag data follows $length"
     966                append _outbuf $bytes
     967                set _datasets($tag) 1
     968                SetObjectStyle $dataobj $comp
     969            }
     970            lappend _obj2datasets($dataobj) $tag
     971            if { [info exists _obj2ovride($dataobj-raise)] } {
     972                # Setting dataset visible enables outline
     973                # and heightmap
     974                SendCmd "dataset visible 1 $tag"
     975            }
     976            if { ![info exists _comp2scale($tag)] ||
     977                $_comp2scale($tag) != $scale } {
     978                SendCmd "heightmap heightscale $scale $tag"
     979                set _comp2scale($tag) $scale
     980            }
     981        }
     982    }
     983    if { $_first != ""  } {
     984        $itk_component(field) choices delete 0 end
     985        $itk_component(fieldmenu) delete 0 end
     986        array unset _fields
     987        set _curFldName ""
     988        foreach cname [$_first components] {
     989            foreach fname [$_first fieldnames $cname] {
     990                if { [info exists _fields($fname)] } {
     991                    continue
     992                }
     993                foreach { label units components } \
     994                    [$_first fieldinfo $fname] break
     995                $itk_component(field) choices insert end "$fname" "$label"
     996                $itk_component(fieldmenu) add radiobutton -label "$label" \
     997                    -value $label -variable [itcl::scope _curFldLabel] \
     998                    -selectcolor red \
     999                    -activebackground $itk_option(-plotbackground) \
     1000                    -activeforeground $itk_option(-plotforeground) \
     1001                    -font "Arial 8" \
     1002                    -command [itcl::code $this Combo invoke]
     1003                set _fields($fname) [list $label $units $components]
     1004                if { $_curFldName == "" } {
     1005                    set _curFldName $fname
     1006                    set _curFldLabel $label
     1007                }
     1008            }
     1009        }
     1010        $itk_component(field) value $_curFldLabel
     1011    }
     1012    InitSettings stretchToFit outline
     1013
     1014    if { $_reset } {
     1015        SendCmd "axis tickpos outside"
     1016        foreach axis { x y z } {
     1017            SendCmd "axis lformat $axis %g"
     1018        }
     1019
     1020        foreach axis { x y z } {
     1021            set label [$_first hints ${axis}label]
     1022            if { $label == "" } {
     1023                if {$axis == "z"} {
     1024                    if { [string match "component*" $_curFldName] } {
     1025                        set label [string toupper $axis]
     1026                    } else {
     1027                        set label $_curFldLabel
     1028                    }
     1029                } else {
     1030                    set label [string toupper $axis]
     1031                }
     1032            }
     1033            # May be a space in the axis label.
     1034            SendCmd [list axis name $axis $label]
     1035
     1036            if {$axis == "z" && [$_first hints ${axis}units] == ""} {
     1037                set units [lindex $_fields($_curFldName) 1]
     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        SendCmd "axis color all [Color2RGB $itk_option(-plotforeground)]"
     1050        SendCmd "outline color [Color2RGB $itk_option(-plotforeground)]"
     1051        ResetAxes
     1052        set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
     1053        $_arcball quaternion $q
     1054        if {$_settings(isHeightmap) } {
     1055            if { $_view(ortho)} {
     1056                SendCmd "camera mode ortho"
     1057            } else {
     1058                SendCmd "camera mode persp"
     1059            }
     1060            DoRotate
     1061            SendCmd "camera reset"
     1062        }
     1063        PanCamera
     1064        InitSettings axisXGrid axisYGrid axisZGrid \
     1065            axisVisible axisLabels
     1066        InitSettings heightmapScale field isHeightmap
     1067        if { [array size _fields] < 2 } {
     1068            catch {
     1069                blt::table forget $itk_component(field) $itk_component(field_l)
     1070            }
     1071        }
     1072        RequestLegend
     1073        set _reset 0
     1074    }
     1075    global readyForNextFrame
     1076    set readyForNextFrame 0;            # Don't advance to the next frame
     1077
     1078    # Actually write the commands to the server socket.  If it fails, we don't
     1079    # care.  We're finished here.
     1080    blt::busy hold $itk_component(hull)
     1081    StopBufferingCommands
     1082    blt::busy release $itk_component(hull)
    10811083}
    10821084
     
    10891091# ----------------------------------------------------------------------
    10901092itcl::body Rappture::VtkHeightmapViewer::CurrentDatasets {args} {
    1091 set flag [lindex $args 0]
    1092 switch -- $flag {
    1093 "-all" {
    1094     if { [llength $args] > 1 } {
    1095         error "CurrentDatasets: can't specify dataobj after \"-all\""
    1096     }
    1097     set dlist [get -objects]
    1098 }
    1099 "-visible" {
    1100     if { [llength $args] > 1 } {
    1101         set dlist {}
    1102         set args [lrange $args 1 end]
    1103         foreach dataobj $args {
    1104             if { [info exists _obj2ovride($dataobj-raise)] } {
    1105                 lappend dlist $dataobj
    1106             }
    1107         }
    1108     } else {
    1109         set dlist [get -visible]
    1110     }
    1111 }           
    1112 default {
    1113     set dlist $args
    1114 }
    1115 }
    1116 set rlist ""
    1117 foreach dataobj $dlist {
    1118 foreach comp [$dataobj components] {
    1119     set tag $dataobj-$comp
    1120     if { [info exists _datasets($tag)] && $_datasets($tag) } {
    1121         lappend rlist $tag
    1122     }
    1123 }
    1124 }
    1125 return $rlist
     1093    set flag [lindex $args 0]
     1094    switch -- $flag {
     1095        "-all" {
     1096            if { [llength $args] > 1 } {
     1097                error "CurrentDatasets: can't specify dataobj after \"-all\""
     1098            }
     1099            set dlist [get -objects]
     1100        }
     1101        "-visible" {
     1102            if { [llength $args] > 1 } {
     1103                set dlist {}
     1104                set args [lrange $args 1 end]
     1105                foreach dataobj $args {
     1106                    if { [info exists _obj2ovride($dataobj-raise)] } {
     1107                        lappend dlist $dataobj
     1108                    }
     1109                }
     1110            } else {
     1111                set dlist [get -visible]
     1112            }
     1113        }           
     1114        default {
     1115            set dlist $args
     1116        }
     1117    }
     1118    set rlist ""
     1119    foreach dataobj $dlist {
     1120        foreach comp [$dataobj components] {
     1121            set tag $dataobj-$comp
     1122            if { [info exists _datasets($tag)] && $_datasets($tag) } {
     1123                lappend rlist $tag
     1124            }
     1125        }
     1126    }
     1127    return $rlist
    11261128}
    11271129
     
    11351137# ----------------------------------------------------------------------
    11361138itcl::body Rappture::VtkHeightmapViewer::Zoom {option} {
    1137 switch -- $option {
    1138 "in" {
    1139     set _view(zoom) [expr {$_view(zoom)*1.25}]
    1140     SendCmd "camera zoom $_view(zoom)"
    1141 }
    1142 "out" {
    1143     set _view(zoom) [expr {$_view(zoom)*0.8}]
    1144     SendCmd "camera zoom $_view(zoom)"
    1145 }
    1146 "reset" {
    1147     array set _view {
    1148         qw      0.36
    1149         qx      0.25
    1150         qy      0.50
    1151         qz      0.70
    1152         zoom    1.0
    1153         xpan    0
    1154         ypan    0
    1155     }
    1156     if { $_first != "" } {
    1157         set location [$_first hints camera]
    1158         if { $location != "" } {
    1159             array set _view $location
    1160         }
    1161     }
    1162     set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    1163     $_arcball quaternion $q
    1164     if {$_settings(isHeightmap) } {
    1165         DoRotate
    1166     }
    1167     SendCmd "camera reset"
    1168 }
    1169 }
     1139    switch -- $option {
     1140        "in" {
     1141            set _view(zoom) [expr {$_view(zoom)*1.25}]
     1142            SendCmd "camera zoom $_view(zoom)"
     1143        }
     1144        "out" {
     1145            set _view(zoom) [expr {$_view(zoom)*0.8}]
     1146            SendCmd "camera zoom $_view(zoom)"
     1147        }
     1148        "reset" {
     1149            array set _view {
     1150                qw      0.36
     1151                qx      0.25
     1152                qy      0.50
     1153                qz      0.70
     1154                zoom    1.0
     1155                xpan    0
     1156                ypan    0
     1157            }
     1158            if { $_first != "" } {
     1159                set location [$_first hints camera]
     1160                if { $location != "" } {
     1161                    array set _view $location
     1162                }
     1163            }
     1164            set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
     1165            $_arcball quaternion $q
     1166            if {$_settings(isHeightmap) } {
     1167                DoRotate
     1168            }
     1169            SendCmd "camera reset"
     1170        }
     1171    }
    11701172}
    11711173
    11721174itcl::body Rappture::VtkHeightmapViewer::PanCamera {} {
    1173 set x $_view(xpan)
    1174 set y $_view(ypan)
    1175 SendCmd "camera pan $x $y"
     1175    set x $_view(xpan)
     1176    set y $_view(ypan)
     1177    SendCmd "camera pan $x $y"
    11761178}
    11771179
     
    11861188# ----------------------------------------------------------------------
    11871189itcl::body Rappture::VtkHeightmapViewer::Rotate {option x y} {
    1188 switch -- $option {
    1189 "click" {
    1190     $itk_component(view) configure -cursor fleur
    1191     set _click(x) $x
    1192     set _click(y) $y
    1193 }
    1194 "drag" {
    1195     if {[array size _click] == 0} {
    1196         Rotate click $x $y
    1197     } else {
    1198         set w [winfo width $itk_component(view)]
    1199         set h [winfo height $itk_component(view)]
    1200         if {$w <= 0 || $h <= 0} {
    1201             return
    1202         }
    1203 
    1204         if {[catch {
    1205             # this fails sometimes for no apparent reason
    1206             set dx [expr {double($x-$_click(x))/$w}]
    1207             set dy [expr {double($y-$_click(y))/$h}]
    1208         }]} {
    1209             return
    1210         }
    1211         if { $dx == 0 && $dy == 0 } {
    1212             return
    1213         }
    1214         set q [$_arcball rotate $x $y $_click(x) $_click(y)]
    1215         EventuallyRotate $q
    1216         set _click(x) $x
    1217         set _click(y) $y
    1218     }
    1219 }
    1220 "release" {
    1221     Rotate drag $x $y
    1222     $itk_component(view) configure -cursor ""
    1223     catch {unset _click}
    1224 }
    1225 default {
    1226     error "bad option \"$option\": should be click, drag, release"
    1227 }
    1228 }
     1190    switch -- $option {
     1191        "click" {
     1192            $itk_component(view) configure -cursor fleur
     1193            set _click(x) $x
     1194            set _click(y) $y
     1195        }
     1196        "drag" {
     1197            if {[array size _click] == 0} {
     1198                Rotate click $x $y
     1199            } else {
     1200                set w [winfo width $itk_component(view)]
     1201                set h [winfo height $itk_component(view)]
     1202                if {$w <= 0 || $h <= 0} {
     1203                    return
     1204                }
     1205
     1206                if {[catch {
     1207                    # this fails sometimes for no apparent reason
     1208                    set dx [expr {double($x-$_click(x))/$w}]
     1209                    set dy [expr {double($y-$_click(y))/$h}]
     1210                }]} {
     1211                    return
     1212                }
     1213                if { $dx == 0 && $dy == 0 } {
     1214                    return
     1215                }
     1216                set q [$_arcball rotate $x $y $_click(x) $_click(y)]
     1217                EventuallyRotate $q
     1218                set _click(x) $x
     1219                set _click(y) $y
     1220            }
     1221        }
     1222        "release" {
     1223            Rotate drag $x $y
     1224            $itk_component(view) configure -cursor ""
     1225            catch {unset _click}
     1226        }
     1227        default {
     1228            error "bad option \"$option\": should be click, drag, release"
     1229        }
     1230    }
    12291231}
    12301232
    12311233itcl::body Rappture::VtkHeightmapViewer::Pick {x y} {
    1232 foreach tag [CurrentDatasets -visible] {
    1233 SendCmd "dataset getscalar pixel $x $y $tag"
    1234 }
     1234    foreach tag [CurrentDatasets -visible] {
     1235        SendCmd "dataset getscalar pixel $x $y $tag"
     1236    }
    12351237}
    12361238
     
    12441246# ----------------------------------------------------------------------
    12451247itcl::body Rappture::VtkHeightmapViewer::Pan {option x y} {
    1246 switch -- $option {
    1247 "set" {
    1248     set w [winfo width $itk_component(view)]
    1249     set h [winfo height $itk_component(view)]
    1250     set x [expr $x / double($w)]
    1251     set y [expr $y / double($h)]
    1252     set _view(xpan) [expr $_view(xpan) + $x]
    1253     set _view(ypan) [expr $_view(ypan) + $y]
    1254     PanCamera
    1255     return
    1256 }
    1257 "click" {
    1258     set _click(x) $x
    1259     set _click(y) $y
    1260     $itk_component(view) configure -cursor hand1
    1261 }
    1262 "drag" {
    1263     if { ![info exists _click(x)] } {
    1264         set _click(x) $x
    1265     }
    1266     if { ![info exists _click(y)] } {
    1267         set _click(y) $y
    1268     }
    1269     set w [winfo width $itk_component(view)]
    1270     set h [winfo height $itk_component(view)]
    1271     set dx [expr ($_click(x) - $x)/double($w)]
    1272     set dy [expr ($_click(y) - $y)/double($h)]
    1273     set _click(x) $x
    1274     set _click(y) $y
    1275     set _view(xpan) [expr $_view(xpan) - $dx]
    1276     set _view(ypan) [expr $_view(ypan) - $dy]
    1277     PanCamera
    1278 }
    1279 "release" {
    1280     Pan drag $x $y
    1281     $itk_component(view) configure -cursor ""
    1282 }
    1283 default {
    1284     error "unknown option \"$option\": should set, click, drag, or release"
    1285 }
    1286 }
     1248    switch -- $option {
     1249        "set" {
     1250            set w [winfo width $itk_component(view)]
     1251            set h [winfo height $itk_component(view)]
     1252            set x [expr $x / double($w)]
     1253            set y [expr $y / double($h)]
     1254            set _view(xpan) [expr $_view(xpan) + $x]
     1255            set _view(ypan) [expr $_view(ypan) + $y]
     1256            PanCamera
     1257            return
     1258        }
     1259        "click" {
     1260            set _click(x) $x
     1261            set _click(y) $y
     1262            $itk_component(view) configure -cursor hand1
     1263        }
     1264        "drag" {
     1265            if { ![info exists _click(x)] } {
     1266                set _click(x) $x
     1267            }
     1268            if { ![info exists _click(y)] } {
     1269                set _click(y) $y
     1270            }
     1271            set w [winfo width $itk_component(view)]
     1272            set h [winfo height $itk_component(view)]
     1273            set dx [expr ($_click(x) - $x)/double($w)]
     1274            set dy [expr ($_click(y) - $y)/double($h)]
     1275            set _click(x) $x
     1276            set _click(y) $y
     1277            set _view(xpan) [expr $_view(xpan) - $dx]
     1278            set _view(ypan) [expr $_view(ypan) - $dy]
     1279            PanCamera
     1280        }
     1281        "release" {
     1282            Pan drag $x $y
     1283            $itk_component(view) configure -cursor ""
     1284        }
     1285        default {
     1286            error "unknown option \"$option\": should set, click, drag, or release"
     1287        }
     1288    }
    12871289}
    12881290
     
    12951297# ----------------------------------------------------------------------
    12961298itcl::body Rappture::VtkHeightmapViewer::InitSettings { args } {
    1297 foreach spec $args {
    1298 if { [info exists _settings($_first-$spec)] } {
    1299     # Reset global setting with dataobj specific setting
    1300     set _settings($spec) $_settings($_first-$spec)
    1301 }
    1302 AdjustSetting $spec
    1303 }
     1299    foreach spec $args {
     1300        if { [info exists _settings($_first-$spec)] } {
     1301            # Reset global setting with dataobj specific setting
     1302            set _settings($spec) $_settings($_first-$spec)
     1303        }
     1304        AdjustSetting $spec
     1305    }
    13041306}
    13051307
     
    13121314#
    13131315itcl::body Rappture::VtkHeightmapViewer::AdjustSetting {what {value ""}} {
    1314 if { $_beforeConnect } {
    1315 return
    1316 }
    1317 switch -- $what {
    1318 "axisFlymode" {
    1319     set mode [$itk_component(axisflymode) value]
    1320     set mode [$itk_component(axisflymode) translate $mode]
    1321     set _settings($what) $mode
    1322     SendCmd "axis flymode $mode"
    1323 }
    1324 "axisLabels" {
    1325     set bool $_settings(axisLabels)
    1326     SendCmd "axis labels all $bool"
    1327 }
    1328 "axisMinorTicks" {
    1329     set bool $_settings(axisMinorTicks)
    1330     foreach axis { x y z } {
    1331         SendCmd "axis minticks ${axis} $bool"
    1332     }
    1333 }
    1334 "axisVisible" {
    1335     set bool $_settings(axisVisible)
    1336     SendCmd "axis visible all $bool"
    1337 }
    1338 "axisXGrid" - "axisYGrid" - "axisZGrid" {
    1339     set axis [string tolower [string range $what 4 4]]
    1340     set bool $_settings($what)
    1341     SendCmd "axis grid $axis $bool"
    1342 }
    1343 "background" {
    1344     set bgcolor [$itk_component(background) value]
    1345     array set fgcolors {
    1346         "black" "white"
    1347         "white" "black"
    1348         "grey"  "black"
    1349     }
    1350     configure -plotbackground $bgcolor \
    1351         -plotforeground $fgcolors($bgcolor)
    1352     $itk_component(view) delete "legend"
    1353     DrawLegend
    1354 }
    1355 "colormap" {
    1356     set _changed(colormap) 1
    1357     StartBufferingCommands
    1358     set color [$itk_component(colormap) value]
    1359     set _settings(colormap) $color
    1360     if { $color == "none" } {
    1361         if { $_settings(colormapVisible) } {
    1362             SendCmd "heightmap surface 0"
    1363             set _settings(colormapVisible) 0
    1364         }
    1365     } else {
    1366         if { !$_settings(colormapVisible) } {
    1367             SendCmd "heightmap surface 1"
    1368             set _settings(colormapVisible) 1
    1369         }
    1370         SetCurrentColormap $color
    1371         if {$_settings(colormapDiscrete)} {
    1372             set numColors [expr $_settings(numIsolines) - 1]
    1373             SendCmd "colormap res $numColors $color"
    1374         }
    1375     }
    1376     StopBufferingCommands
    1377     EventuallyRequestLegend
    1378 }
    1379 "colormapVisible" {
    1380     set bool $_settings($what)
    1381     SendCmd "heightmap surface $bool"
    1382 }
    1383 "colormapDiscrete" {
    1384     set bool $_settings($what)
    1385     set numColors [expr $_settings(numIsolines) - 1]
    1386     StartBufferingCommands
    1387     if {$bool} {
    1388         SendCmd "colormap res $numColors"
    1389         # Discrete colormap requires preinterp on
    1390         SendCmd "heightmap preinterp on"
    1391     } else {
    1392         SendCmd "colormap res default"
    1393         # FIXME: add setting for preinterp (default on)
    1394         SendCmd "heightmap preinterp on"
    1395     }
    1396     StopBufferingCommands
    1397     EventuallyRequestLegend
    1398 }
    1399 "edges" {
    1400     set bool $_settings(edges)
    1401     SendCmd "heightmap edges $bool"
    1402 }
    1403 "field" {
    1404     set label [$itk_component(field) value]
    1405     set fname [$itk_component(field) translate $label]
    1406     set _settings(field) $fname
    1407     if { [info exists _fields($fname)] } {
    1408         foreach { label units components } $_fields($fname) break
    1409         if { $components > 1 } {
    1410             set _colorMode vmag
    1411         } else {
    1412             set _colorMode scalar
    1413         }
    1414         set _curFldName $fname
    1415         set _curFldLabel $label
    1416     } else {
    1417         puts stderr "unknown field \"$fname\""
    1418         return
    1419     }
    1420     set label [$_first hints zlabel]
    1421     if { $label == "" } {
    1422         if { [string match "component*" $_curFldName] } {
    1423             set label Z
    1424         } else {
    1425             set label $_curFldLabel
    1426         }
    1427     }
    1428     # May be a space in the axis label.
    1429     SendCmd [list axis name z $label]
    1430 
    1431     if { [$_first hints zunits] == "" } {
    1432         set units [lindex $_fields($_curFldName) 1]
    1433     } else {
    1434         set units [$_first hints zunits]
    1435     }
    1436     if { $units != "" } {
    1437         # May be a space in the axis units.
    1438         SendCmd [list axis units z $units]
    1439     }
    1440     # Get the new limits because the field changed.
    1441     ResetAxes
    1442     SendCmd "dataset scalar $_curFldName"
    1443     SendCmd "heightmap colormode scalar $_curFldName"
    1444     SendCmd "camera reset"
    1445     DrawLegend
    1446 }
    1447 "heightmapScale" {
    1448     if { $_settings(isHeightmap) } {
    1449         set scale [GetHeightmapScale]
    1450         # Have to set the datasets individually because we are
    1451         # tracking them in _comp2scale.
    1452         foreach dataset [CurrentDatasets -all] {
    1453             SendCmd "heightmap heightscale $scale $dataset"
    1454             set _comp2scale($dataset) $scale
    1455         }
    1456         ResetAxes
    1457     }
    1458 }
    1459 "isHeightmap" {
    1460     set bool $_settings(isHeightmap)
    1461     set c $itk_component(view)
    1462     StartBufferingCommands
    1463     # Fix heightmap scale: 0 for contours, 1 for heightmaps.
    1464     if { $bool } {
    1465         set _settings(heightmapScale) 50
    1466         set _settings(opacity) $_settings(saveOpacity)
    1467         set _settings(lighting) $_settings(saveLighting)
    1468         set _settings(outline) 0
    1469     } else {
    1470         set _settings(heightmapScale) 0
    1471         set _settings(lighting) 0
    1472         set _settings(opacity) 100
    1473         set _settings(outline)  $_settings(saveOutline)
    1474     }
    1475     AdjustSetting lighting
    1476     AdjustSetting opacity
    1477     AdjustSetting outline
    1478     set scale [GetHeightmapScale]
    1479     # Have to set the datasets individually because we are
    1480     # tracking them in _comp2scale.
    1481     foreach dataset [CurrentDatasets -all] {
    1482         SendCmd "heightmap heightscale $scale $dataset"
    1483         set _comp2scale($dataset) $scale
    1484     }
    1485     if { $bool } {
    1486         $itk_component(lighting) configure -state normal
    1487         $itk_component(opacity) configure -state normal
    1488         $itk_component(scale) configure -state normal
    1489         $itk_component(opacity_l) configure -state normal
    1490         $itk_component(scale_l) configure -state normal
    1491         $itk_component(outline) configure -state disabled
    1492         if {$_view(ortho)} {
    1493             SendCmd "camera mode ortho"
    1494         } else {
    1495             SendCmd "camera mode persp"
    1496         }
    1497     } else {
    1498         $itk_component(lighting) configure -state disabled
    1499         $itk_component(opacity) configure -state disabled
    1500         $itk_component(scale) configure -state disabled
    1501         $itk_component(opacity_l) configure -state disabled
    1502         $itk_component(scale_l) configure -state disabled
    1503         $itk_component(outline) configure -state normal
    1504         SendCmd "camera mode image"
    1505     }
    1506     if {$_settings(stretchToFit)} {
    1507         if {$scale == 0} {
    1508             SendCmd "camera aspect window"
    1509         } else {
    1510             SendCmd "camera aspect square"
    1511         }
    1512     }
    1513     ResetAxes
    1514     if { $bool } {
    1515         set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    1516         $_arcball quaternion $q
    1517         SendCmd "camera orient $q"
    1518     } else {
    1519         bind $c <ButtonPress-1> {}
    1520         bind $c <B1-Motion> {}
    1521         bind $c <ButtonRelease-1> {}
    1522     }
    1523     SendCmd "camera reset"
    1524     # Fix the mouse bindings for rotation/panning and the
    1525     # camera mode. Ideally we'd create a bindtag for these.
    1526     if { $bool } {
    1527         # Bindings for rotation via mouse
    1528         bind $c <ButtonPress-1> \
    1529             [itcl::code $this Rotate click %x %y]
    1530         bind $c <B1-Motion> \
    1531             [itcl::code $this Rotate drag %x %y]
    1532         bind $c <ButtonRelease-1> \
    1533             [itcl::code $this Rotate release %x %y]
    1534     }
    1535     StopBufferingCommands
    1536 }
    1537 "isolineColor" {
    1538     set color [$itk_component(isolinecolor) value]
    1539     if { $color == "none" } {
    1540         if { $_settings(isolinesVisible) } {
    1541             SendCmd "heightmap isolines 0"
    1542             set _settings(isolinesVisible) 0
    1543         }
    1544     } else {
    1545         if { !$_settings(isolinesVisible) } {
    1546             SendCmd "heightmap isolines 1"
    1547             set _settings(isolinesVisible) 1
    1548         }
    1549         SendCmd "heightmap isolinecolor [Color2RGB $color]"
    1550     }
    1551     DrawLegend
    1552 }
    1553 "isolinesVisible" {
    1554     set bool $_settings($what)
    1555     SendCmd "heightmap isolines $bool"
    1556     DrawLegend
    1557 }
    1558 "legendVisible" {
    1559     if { !$_settings($what) } {
    1560         $itk_component(view) delete legend
    1561     }
    1562     DrawLegend
    1563 }
    1564 "lighting" {
    1565     if { $_settings(isHeightmap) } {
    1566         set _settings(saveLighting) $_settings(lighting)
    1567         set bool $_settings($what)
    1568         SendCmd "heightmap lighting $bool"
    1569     } else {
    1570         SendCmd "heightmap lighting 0"
    1571     }
    1572 }
    1573 "numIsolines" {
    1574     set _changed(numIsolines) 1
    1575     set _settings(numIsolines) [$itk_component(numisolines) value]
    1576     set _currentNumIsolines $_settings(numIsolines)
    1577     SendCmd "heightmap numcontours $_settings(numIsolines)"
    1578     if {$_settings(colormapDiscrete)} {
    1579         set numColors [expr $_settings(numIsolines) - 1]
    1580         SendCmd "colormap res $numColors"
    1581         EventuallyRequestLegend
    1582     } else {
    1583         DrawLegend
    1584     }
    1585 }
    1586 "opacity" {
    1587     set _changed(opacity) 1
    1588     if { $_settings(isHeightmap) } {
    1589         set _settings(saveOpacity) $_settings(opacity)
    1590         set val $_settings(opacity)
    1591         set sval [expr { 0.01 * double($val) }]
    1592         SendCmd "heightmap opacity $sval"
    1593     } else {
    1594         SendCmd "heightmap opacity 1"
    1595     }
    1596 }
    1597 "outline" {
    1598     if { $_settings(isHeightmap) } {
    1599         SendCmd "outline visible 0"
    1600     } else {
    1601         set _settings(saveOutline) $_settings(outline)
    1602         set bool $_settings(outline)
    1603         SendCmd "outline visible $bool"
    1604     }
    1605 }
    1606 "stretchToFit" {
    1607     set bool $_settings($what)
    1608     if { $bool } {
    1609         set heightScale [GetHeightmapScale]
    1610         if {$heightScale == 0} {
    1611             SendCmd "camera aspect window"
    1612         } else {
    1613             SendCmd "camera aspect square"
    1614         }
    1615     } else {
    1616         SendCmd "camera aspect native"
    1617     }
    1618 }
    1619 "wireframe" {
    1620     set bool $_settings($what)
    1621     SendCmd "heightmap wireframe $bool"
    1622 }
    1623 default {
    1624     error "don't know how to fix $what"
    1625 }
    1626 }
     1316    if { $_beforeConnect } {
     1317        return
     1318    }
     1319    switch -- $what {
     1320        "axisFlymode" {
     1321            set mode [$itk_component(axisflymode) value]
     1322            set mode [$itk_component(axisflymode) translate $mode]
     1323            set _settings($what) $mode
     1324            SendCmd "axis flymode $mode"
     1325        }
     1326        "axisLabels" {
     1327            set bool $_settings(axisLabels)
     1328            SendCmd "axis labels all $bool"
     1329        }
     1330        "axisMinorTicks" {
     1331            set bool $_settings(axisMinorTicks)
     1332            foreach axis { x y z } {
     1333                SendCmd "axis minticks ${axis} $bool"
     1334            }
     1335        }
     1336        "axisVisible" {
     1337            set bool $_settings(axisVisible)
     1338            SendCmd "axis visible all $bool"
     1339        }
     1340        "axisXGrid" - "axisYGrid" - "axisZGrid" {
     1341            set axis [string tolower [string range $what 4 4]]
     1342            set bool $_settings($what)
     1343            SendCmd "axis grid $axis $bool"
     1344        }
     1345        "background" {
     1346            set bgcolor [$itk_component(background) value]
     1347            array set fgcolors {
     1348                "black" "white"
     1349                "white" "black"
     1350                "grey"  "black"
     1351            }
     1352            configure -plotbackground $bgcolor \
     1353                -plotforeground $fgcolors($bgcolor)
     1354            $itk_component(view) delete "legend"
     1355            DrawLegend
     1356        }
     1357        "colormap" {
     1358            set _changed(colormap) 1
     1359            StartBufferingCommands
     1360            set color [$itk_component(colormap) value]
     1361            set _settings(colormap) $color
     1362            if { $color == "none" } {
     1363                if { $_settings(colormapVisible) } {
     1364                    SendCmd "heightmap surface 0"
     1365                    set _settings(colormapVisible) 0
     1366                }
     1367            } else {
     1368                if { !$_settings(colormapVisible) } {
     1369                    SendCmd "heightmap surface 1"
     1370                    set _settings(colormapVisible) 1
     1371                }
     1372                SetCurrentColormap $color
     1373                if {$_settings(colormapDiscrete)} {
     1374                    set numColors [expr $_settings(numIsolines) - 1]
     1375                    SendCmd "colormap res $numColors $color"
     1376                }
     1377            }
     1378            StopBufferingCommands
     1379            EventuallyRequestLegend
     1380        }
     1381        "colormapVisible" {
     1382            set bool $_settings($what)
     1383            SendCmd "heightmap surface $bool"
     1384        }
     1385        "colormapDiscrete" {
     1386            set bool $_settings($what)
     1387            set numColors [expr $_settings(numIsolines) - 1]
     1388            StartBufferingCommands
     1389            if {$bool} {
     1390                SendCmd "colormap res $numColors"
     1391                # Discrete colormap requires preinterp on
     1392                SendCmd "heightmap preinterp on"
     1393            } else {
     1394                SendCmd "colormap res default"
     1395                # FIXME: add setting for preinterp (default on)
     1396                SendCmd "heightmap preinterp on"
     1397            }
     1398            StopBufferingCommands
     1399            EventuallyRequestLegend
     1400        }
     1401        "edges" {
     1402            set bool $_settings(edges)
     1403            SendCmd "heightmap edges $bool"
     1404        }
     1405        "field" {
     1406            set label [$itk_component(field) value]
     1407            set fname [$itk_component(field) translate $label]
     1408            set _settings(field) $fname
     1409            if { [info exists _fields($fname)] } {
     1410                foreach { label units components } $_fields($fname) break
     1411                if { $components > 1 } {
     1412                    set _colorMode vmag
     1413                } else {
     1414                    set _colorMode scalar
     1415                }
     1416                set _curFldName $fname
     1417                set _curFldLabel $label
     1418            } else {
     1419                puts stderr "unknown field \"$fname\""
     1420                return
     1421            }
     1422            set label [$_first hints zlabel]
     1423            if { $label == "" } {
     1424                if { [string match "component*" $_curFldName] } {
     1425                    set label Z
     1426                } else {
     1427                    set label $_curFldLabel
     1428                }
     1429            }
     1430            # May be a space in the axis label.
     1431            SendCmd [list axis name z $label]
     1432
     1433            if { [$_first hints zunits] == "" } {
     1434                set units [lindex $_fields($_curFldName) 1]
     1435            } else {
     1436                set units [$_first hints zunits]
     1437            }
     1438            if { $units != "" } {
     1439                # May be a space in the axis units.
     1440                SendCmd [list axis units z $units]
     1441            }
     1442            # Get the new limits because the field changed.
     1443            ResetAxes
     1444            SendCmd "dataset scalar $_curFldName"
     1445            SendCmd "heightmap colormode scalar $_curFldName"
     1446            SendCmd "camera reset"
     1447            DrawLegend
     1448        }
     1449        "heightmapScale" {
     1450            if { $_settings(isHeightmap) } {
     1451                set scale [GetHeightmapScale]
     1452                # Have to set the datasets individually because we are
     1453                # tracking them in _comp2scale.
     1454                foreach dataset [CurrentDatasets -all] {
     1455                    SendCmd "heightmap heightscale $scale $dataset"
     1456                    set _comp2scale($dataset) $scale
     1457                }
     1458                ResetAxes
     1459            }
     1460        }
     1461        "isHeightmap" {
     1462            set bool $_settings(isHeightmap)
     1463            set c $itk_component(view)
     1464            StartBufferingCommands
     1465            # Fix heightmap scale: 0 for contours, 1 for heightmaps.
     1466            if { $bool } {
     1467                set _settings(heightmapScale) 50
     1468                set _settings(opacity) $_settings(saveOpacity)
     1469                set _settings(lighting) $_settings(saveLighting)
     1470                set _settings(outline) 0
     1471            } else {
     1472                set _settings(heightmapScale) 0
     1473                set _settings(lighting) 0
     1474                set _settings(opacity) 100
     1475                set _settings(outline)  $_settings(saveOutline)
     1476            }
     1477            AdjustSetting lighting
     1478            AdjustSetting opacity
     1479            AdjustSetting outline
     1480            set scale [GetHeightmapScale]
     1481            # Have to set the datasets individually because we are
     1482            # tracking them in _comp2scale.
     1483            foreach dataset [CurrentDatasets -all] {
     1484                SendCmd "heightmap heightscale $scale $dataset"
     1485                set _comp2scale($dataset) $scale
     1486            }
     1487            if { $bool } {
     1488                $itk_component(lighting) configure -state normal
     1489                $itk_component(opacity) configure -state normal
     1490                $itk_component(scale) configure -state normal
     1491                $itk_component(opacity_l) configure -state normal
     1492                $itk_component(scale_l) configure -state normal
     1493                $itk_component(outline) configure -state disabled
     1494                if {$_view(ortho)} {
     1495                    SendCmd "camera mode ortho"
     1496                } else {
     1497                    SendCmd "camera mode persp"
     1498                }
     1499            } else {
     1500                $itk_component(lighting) configure -state disabled
     1501                $itk_component(opacity) configure -state disabled
     1502                $itk_component(scale) configure -state disabled
     1503                $itk_component(opacity_l) configure -state disabled
     1504                $itk_component(scale_l) configure -state disabled
     1505                $itk_component(outline) configure -state normal
     1506                SendCmd "camera mode image"
     1507            }
     1508            if {$_settings(stretchToFit)} {
     1509                if {$scale == 0} {
     1510                    SendCmd "camera aspect window"
     1511                } else {
     1512                    SendCmd "camera aspect square"
     1513                }
     1514            }
     1515            ResetAxes
     1516            if { $bool } {
     1517                set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
     1518                $_arcball quaternion $q
     1519                SendCmd "camera orient $q"
     1520            } else {
     1521                bind $c <ButtonPress-1> {}
     1522                bind $c <B1-Motion> {}
     1523                bind $c <ButtonRelease-1> {}
     1524            }
     1525            SendCmd "camera reset"
     1526            # Fix the mouse bindings for rotation/panning and the
     1527            # camera mode. Ideally we'd create a bindtag for these.
     1528            if { $bool } {
     1529                # Bindings for rotation via mouse
     1530                bind $c <ButtonPress-1> \
     1531                    [itcl::code $this Rotate click %x %y]
     1532                bind $c <B1-Motion> \
     1533                    [itcl::code $this Rotate drag %x %y]
     1534                bind $c <ButtonRelease-1> \
     1535                    [itcl::code $this Rotate release %x %y]
     1536            }
     1537            StopBufferingCommands
     1538        }
     1539        "isolineColor" {
     1540            set color [$itk_component(isolinecolor) value]
     1541            if { $color == "none" } {
     1542                if { $_settings(isolinesVisible) } {
     1543                    SendCmd "heightmap isolines 0"
     1544                    set _settings(isolinesVisible) 0
     1545                }
     1546            } else {
     1547                if { !$_settings(isolinesVisible) } {
     1548                    SendCmd "heightmap isolines 1"
     1549                    set _settings(isolinesVisible) 1
     1550                }
     1551                SendCmd "heightmap isolinecolor [Color2RGB $color]"
     1552            }
     1553            DrawLegend
     1554        }
     1555        "isolinesVisible" {
     1556            set bool $_settings($what)
     1557            SendCmd "heightmap isolines $bool"
     1558            DrawLegend
     1559        }
     1560        "legendVisible" {
     1561            if { !$_settings($what) } {
     1562                $itk_component(view) delete legend
     1563            }
     1564            DrawLegend
     1565        }
     1566        "lighting" {
     1567            if { $_settings(isHeightmap) } {
     1568                set _settings(saveLighting) $_settings(lighting)
     1569                set bool $_settings($what)
     1570                SendCmd "heightmap lighting $bool"
     1571            } else {
     1572                SendCmd "heightmap lighting 0"
     1573            }
     1574        }
     1575        "numIsolines" {
     1576            set _changed(numIsolines) 1
     1577            set _settings(numIsolines) [$itk_component(numisolines) value]
     1578            set _currentNumIsolines $_settings(numIsolines)
     1579            SendCmd "heightmap numcontours $_settings(numIsolines)"
     1580            if {$_settings(colormapDiscrete)} {
     1581                set numColors [expr $_settings(numIsolines) - 1]
     1582                SendCmd "colormap res $numColors"
     1583                EventuallyRequestLegend
     1584            } else {
     1585                DrawLegend
     1586            }
     1587        }
     1588        "opacity" {
     1589            set _changed(opacity) 1
     1590            if { $_settings(isHeightmap) } {
     1591                set _settings(saveOpacity) $_settings(opacity)
     1592                set val $_settings(opacity)
     1593                set sval [expr { 0.01 * double($val) }]
     1594                SendCmd "heightmap opacity $sval"
     1595            } else {
     1596                SendCmd "heightmap opacity 1"
     1597            }
     1598        }
     1599        "outline" {
     1600            if { $_settings(isHeightmap) } {
     1601                SendCmd "outline visible 0"
     1602            } else {
     1603                set _settings(saveOutline) $_settings(outline)
     1604                set bool $_settings(outline)
     1605                SendCmd "outline visible $bool"
     1606            }
     1607        }
     1608        "stretchToFit" {
     1609            set bool $_settings($what)
     1610            if { $bool } {
     1611                set heightScale [GetHeightmapScale]
     1612                if {$heightScale == 0} {
     1613                    SendCmd "camera aspect window"
     1614                } else {
     1615                    SendCmd "camera aspect square"
     1616                }
     1617            } else {
     1618                SendCmd "camera aspect native"
     1619            }
     1620        }
     1621        "wireframe" {
     1622            set bool $_settings($what)
     1623            SendCmd "heightmap wireframe $bool"
     1624        }
     1625        default {
     1626            error "don't know how to fix $what"
     1627        }
     1628    }
    16271629}
    16281630
     
    18051807
    18061808    set inner [$itk_component(main) insert end \
    1807         -title "Contour/Surface Settings" \
    1808         -icon [Rappture::icon contour2]]
     1809                   -title "Contour/Surface Settings" \
     1810                   -icon [Rappture::icon contour2]]
    18091811    $inner configure -borderwidth 4
    18101812
     
    20032005
    20042006    set inner [$itk_component(main) insert end \
    2005         -title "Axis Settings" \
    2006         -icon [Rappture::icon axis2]]
     2007                   -title "Axis Settings" \
     2008                   -icon [Rappture::icon axis2]]
    20072009    $inner configure -borderwidth 4
    20082010
     
    20722074itcl::body Rappture::VtkHeightmapViewer::BuildCameraTab {} {
    20732075    set inner [$itk_component(main) insert end \
    2074         -title "Camera Settings" \
    2075         -icon [Rappture::icon camera]]
     2076                   -title "Camera Settings" \
     2077                   -icon [Rappture::icon camera]]
    20762078    $inner configure -borderwidth 4
    20772079
     
    21112113        -font "Arial 9"
    21122114    blt::table $inner \
    2113             $row,0 $inner.ortho -cspan 2 -anchor w -pady 2
     2115        $row,0 $inner.ortho -cspan 2 -anchor w -pady 2
    21142116    blt::table configure $inner r$row -resize none
    21152117    incr row
     
    23042306    if { [isconnected] } {
    23052307        set bytes [ReceiveBytes $size]
    2306         if { ![info exists _image(legend)] } {
    2307             set _image(legend) [image create photo]
    2308         }
    23092308        $_image(legend) configure -data $bytes
    23102309        #puts stderr "read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>"
     
    23502349        # If there's a legend title, create a text item for the title.
    23512350        $c create text $x $y \
    2352                 -anchor ne \
    2353                 -fill $itk_option(-plotforeground) -tags "title legend" \
    2354                 -font $font
     2351            -anchor ne \
     2352            -fill $itk_option(-plotforeground) -tags "title legend" \
     2353            -font $font
    23552354        $c create text $x $y \
    23562355            -anchor ne \
Note: See TracChangeset for help on using the changeset viewer.