Changeset 4208


Ignore:
Timestamp:
Mar 6, 2014, 1:05:05 PM (11 years ago)
Author:
ldelgass
Message:

Merge trunk version of heightmap viewer for stretch-to-fit settings

Location:
branches/1.3/gui/scripts
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.3/gui/scripts/vtkheightmapviewer.tcl

    r3844 r4208  
    6464    public method scale {args}
    6565
     66    protected method CameraReset {}
    6667    protected method Connect {}
    6768    protected method CurrentDatasets {args}
     
    124125    private variable _currentOpacity ""
    125126
     127    private variable _maxScale 100;     # This is the # of times the x-axis
     128                                        # and y-axis ranges can differ before
     129                                        # automatically turning on
     130                                        # -stretchtofit
     131
    126132    private variable _click        ;    # info used for rotate operations
    127133    private variable _limits       ;    # Holds overall limits for all dataobjs
     
    154160    private variable _curFldName ""
    155161    private variable _curFldLabel ""
    156     private variable _colorMode "vmag";#  Mode of colormap (vmag or scalar)
     162    private variable _colorMode "scalar";#  Mode of colormap (vmag or scalar)
    157163}
    158164
     
    283289            -highlightthickness 0 \
    284290            -image [Rappture::icon reset-view] \
    285             -command [itcl::code $this Zoom reset]
     291            -command [itcl::code $this CameraReset]
    286292    } {
    287293        usual
    288294        ignore -highlightthickness
    289295    }
    290     pack $itk_component(reset) -side top -padx 2 -pady 2
     296    pack $itk_component(reset) -side top -padx 2 -pady { 2 0 }
    291297    Rappture::Tooltip::for $itk_component(reset) "Reset the view to the default zoom level"
    292298
     
    300306        ignore -highlightthickness
    301307    }
    302     pack $itk_component(zoomin) -side top -padx 2 -pady 2
     308    pack $itk_component(zoomin) -side top -padx 2 -pady { 2 0 }
    303309    Rappture::Tooltip::for $itk_component(zoomin) "Zoom in"
    304310
     
    312318        ignore -highlightthickness
    313319    }
    314     pack $itk_component(zoomout) -side top -padx 2 -pady 2
     320    pack $itk_component(zoomout) -side top -padx 2 -pady { 2 0 }
    315321    Rappture::Tooltip::for $itk_component(zoomout) "Zoom out"
    316322
     
    324330    Rappture::Tooltip::for $itk_component(mode) \
    325331        "Toggle the surface/contour on/off"
    326     pack $itk_component(mode) -padx 2 -pady 2
     332    pack $itk_component(mode) -padx 2 -pady { 2 0 }
     333
     334    itk_component add stretchtofit {
     335        Rappture::PushButton $f.stretchtofit \
     336            -onimage [Rappture::icon stretchtofit] \
     337            -offimage [Rappture::icon stretchtofit] \
     338            -variable [itcl::scope _settings(stretchToFit)] \
     339            -command [itcl::code $this AdjustSetting stretchToFit] \
     340    }
     341    Rappture::Tooltip::for $itk_component(stretchtofit) \
     342        "Stretch plot to fit window on/off"
     343    pack $itk_component(stretchtofit) -padx 2 -pady 2
    327344
    328345    if { [catch {
     
    629646            }
    630647            set _limits($axis) [list $amin $amax]
     648            set units [$dataobj hints ${axis}units]
     649            set found($units) 1
    631650        }
    632651        foreach { fname lim } [$dataobj fieldlimits] {
     
    644663            }
    645664            set _limits($fname) [list $fmin $fmax]
     665        }
     666    }
     667    if { [array size found] > 1 } {
     668        set _settings(stretchToFit) 1
     669    } else {
     670        # Check if the range of the x and y axes requires that we stretch
     671        # the contour to fit the plotting area.  This can happen when the
     672        # x and y scales differ greatly (> 100x)
     673        foreach {xmin xmax} $_limits(x) break
     674        foreach {ymin ymax} $_limits(y) break
     675        if { (($xmax - $xmin) > (($ymax -$ymin) * $_maxScale)) ||
     676             ((($xmax - $xmin) * $_maxScale) < ($ymax -$ymin)) } {
     677            set _settings(stretchToFit) 1
    646678        }
    647679    }
     
    723755        if { $_reportClientInfo }  {
    724756            # Tell the server the viewer, hub, user and session.
    725             # Do this immediately on connect before buffing any commands
     757            # Do this immediately on connect before buffering any commands
    726758            global env
    727759
     
    10101042       
    10111043        foreach axis { x y z } {
    1012             set label [$_first hints ${axis}label]
     1044            if { $axis == "z" } {
     1045                set label [$_first hints label]
     1046            } else {
     1047                set label [$_first hints ${axis}label]
     1048            }
    10131049            if { $label == "" } {
    10141050                if {$axis == "z"} {
     
    11151151}
    11161152
     1153itcl::body Rappture::VtkHeightmapViewer::CameraReset {} {
     1154    array set _view {
     1155        qw      0.36
     1156        qx      0.25
     1157        qy      0.50
     1158        qz      0.70
     1159        zoom    1.0
     1160        xpan    0
     1161        ypan    0
     1162    }
     1163    if { $_first != "" } {
     1164        set location [$_first hints camera]
     1165        if { $location != "" } {
     1166            array set _view $location
     1167        }
     1168    }
     1169    set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
     1170    $_arcball quaternion $q
     1171    if {$_settings(isHeightmap) } {
     1172        DoRotate
     1173    }
     1174    SendCmd "camera reset"
     1175}
     1176
    11171177# ----------------------------------------------------------------------
    11181178# USAGE: Zoom in
     
    11351195        "reset" {
    11361196            array set _view {
    1137                 qw      0.36
    1138                 qx      0.25
    1139                 qy      0.50
    1140                 qz      0.70
    11411197                zoom    1.0
    11421198                xpan    0
    11431199                ypan    0
    1144             }
    1145             if { $_first != "" } {
    1146                 set location [$_first hints camera]
    1147                 if { $location != "" } {
    1148                     array set _view $location
    1149                 }
    1150             }
    1151             set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    1152             $_arcball quaternion $q
    1153             if {$_settings(isHeightmap) } {
    1154                 DoRotate
    11551200            }
    11561201            SendCmd "camera reset"
     
    14101455                return
    14111456            }
    1412             set label [$_first hints zlabel]
     1457            set label [$_first hints label]
    14131458            if { $label == "" } {
    14141459                if { [string match "component*" $_curFldName] } {
     
    14341479            SendCmd "dataset scalar $_curFldName"
    14351480            SendCmd "heightmap colormode scalar $_curFldName"
    1436             SendCmd "camera reset"
     1481            Zoom reset
    14371482            UpdateContourList
    14381483            DrawLegend
     
    15141559                bind $c <ButtonRelease-1> {}
    15151560            }
    1516             SendCmd "camera reset"
     1561            Zoom reset
    15171562            # Fix the mouse bindings for rotation/panning and the
    15181563            # camera mode. Ideally we'd create a bindtag for these.
     
    16101655                SendCmd "camera aspect native"
    16111656            }
     1657            Zoom reset
    16121658        }
    16131659        "wireframe" {
     
    16601706        incr h -$lineht
    16611707    }
    1662     if { $h < 1} {
     1708    if { $h < 1 } {
    16631709        return
    16641710    }
     
    16671713        set cmap $_currentColormap
    16681714        SendCmd "legend $cmap scalar $_curFldName {} $w $h 0"
    1669         #SendCmd "heightmap colormode scalar $_curFldName"
    1670         #SendCmd "dataset scalar $_curFldName"
    16711715    }
    16721716}
     
    17201764itcl::body Rappture::VtkHeightmapViewer::SetCurrentColormap { name } {
    17211765    # Keep track of the colormaps that we build.
    1722     if { ![info exists _colormaps($name)] } {
     1766    if { $name != "none" && ![info exists _colormaps($name)] } {
    17231767        BuildColormap $name
    17241768        set _colormaps($name) 1
     
    19582002    itk_component add numisolines {
    19592003        Rappture::Spinint $inner.numisolines \
    1960             -min 1 -max 50 -font "arial 9"
     2004            -min 0 -max 50 -font "arial 9"
    19612005    }
    19622006    $itk_component(numisolines) value $_settings(numIsolines)
     
    20482092        "static_triad"    "static" \
    20492093        "closest_triad"   "closest" \
    2050         "furthest_triad"  "furthest" \
     2094        "furthest_triad"  "farthest" \
    20512095        "outer_edges"     "outer"         
    20522096    $itk_component(axisflymode) value "static"
     
    22642308        $itk_component(colormap) value $style(-color)
    22652309    }
     2310    if { [info exists style(-stretchtofit)] } {
     2311        set _settings(stretchToFit) $style(-stretchtofit)
     2312        AdjustSetting stretchToFit
     2313    }
    22662314    set _currentOpacity $style(-opacity)
    22672315    if { $_currentNumIsolines != $style(-levels) } {
     
    22842332    SendCmd "heightmap isolinecolor [Color2RGB $color] $tag"
    22852333    SendCmd "heightmap lighting $_settings(isHeightmap) $tag"
     2334    SendCmd "heightmap isolines $_settings(isolinesVisible) $tag"
     2335    SendCmd "heightmap surface $_settings(colormapVisible) $tag"
    22862336}
    22872337
     
    23792429
    23802430    # Draw the isolines on the legend.
     2431    array unset _isolines
    23812432    if { $color != "none"  && [info exists _limits($_curFldName)] &&
    23822433         $_settings(isolinesVisible) && $_currentNumIsolines > 0 } {
     
    24222473    incr y $lineht
    24232474    $c coords colormap $x $y
    2424     set ix [image width $_image(legend)]
    2425     set ih [image height $_image(legend)]
    24262475    $c coords sensor [expr $x - $iw] $y $x [expr $y + $ih]
    24272476    $c raise sensor
     
    25632612        return $sval
    25642613    }
    2565     set sval 0
     2614    return 0
    25662615}
    25672616
     
    25882637
    25892638itcl::body Rappture::VtkHeightmapViewer::UpdateContourList {} {
     2639    if {$_currentNumIsolines == 0} {
     2640        set _contourList ""
     2641        return
     2642    }
    25902643    if { ![info exists _limits($_curFldName)] } {
    25912644        return
Note: See TracChangeset for help on using the changeset viewer.