Ignore:
Timestamp:
Jul 17, 2014 1:44:41 PM (10 years ago)
Author:
ldelgass
Message:

sync with mesh viewer in 1.3 branch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/vtkmeshviewer.tcl

    r4421 r4535  
    8686    private method EventuallyResize { w h }
    8787    private method EventuallyRotate { q }
    88     private method EventuallySetPolydataOpacity { args }
     88    private method EventuallySetPolydataOpacity {}
    8989    private method GetImage { args }
    9090    private method GetVtkData { args }
     
    9292    private method PanCamera {}
    9393    private method SetObjectStyle { dataobj }
    94     private method SetOpacity { dataset }
    9594    private method SetOrientation { side }
    9695    private method SetPolydataOpacity {}
     
    112111    private variable _view;             # view params for 3D view
    113112    private variable _settings
     113    private variable _widget
    114114    private variable _style;            # Array of current component styles.
    115115    private variable _initialStyle;     # Array of initial component styles.
    116     private variable _axis
    117116    private variable _reset 1;          # Indicates that server was reset and
    118117                                        # needs to be reinitialized.
    119118
    120     private variable _first ""     ;# This is the topmost dataset.
     119    private variable _first "";         # This is the topmost dataset.
    121120    private variable _start 0
    122121    private variable _title ""
    123122
    124     common _downloadPopup          ;# download options from popup
     123    common _downloadPopup;              # download options from popup
    125124    private common _hardcopy
    126125    private variable _width 0
     
    130129    private variable _polydataOpacityPending 0
    131130    private variable _rotateDelay 150
     131    private variable _opacityDelay 150
    132132}
    133133
     
    184184    set _limits(zmax) 1.0
    185185
    186     array set _axis [subst {
    187         xgrid           0
    188         ygrid           0
    189         zgrid           0
    190         xcutaway        0
    191         ycutaway        0
    192         zcutaway        0
    193         xposition       0
    194         yposition       0
    195         zposition       0
    196         xdirection      -1
    197         ydirection      -1
    198         zdirection      -1
    199         visible         1
    200         labels          1
    201     }]
    202     array set _settings [subst {
    203         outline                 0
    204         polydata-edges          0
    205         polydata-lighting       1
    206         polydata-opacity        100
    207         polydata-visible        1
    208         polydata-wireframe      0
    209     }]
     186    array set _settings {
     187        -axesvisible            1
     188        -axislabels             1
     189        -outline                0
     190        -polydataedges          0
     191        -polydatalighting       1
     192        -polydataopacity        1.0
     193        -polydatavisible        1
     194        -polydatawireframe      0
     195        -xcutaway               0
     196        -xdirection             -1
     197        -xgrid                  0
     198        -xposition              0
     199        -ycutaway               0
     200        -ydirection             -1
     201        -ygrid                  0
     202        -yposition              0
     203        -zcutaway               0
     204        -zdirection             -1
     205        -zgrid                  0
     206        -zposition              0
     207    }
     208    array set _widget {
     209        -polydataopacity        100
     210    }       
    210211    itk_component add view {
    211212        canvas $itk_component(plotarea).view \
     
    407408itcl::body Rappture::VtkMeshViewer::SetPolydataOpacity {} {
    408409    set _polydataOpacityPending 0
    409     foreach dataset [CurrentDatasets -visible $_first] {
    410         SetOpacity $dataset
    411     }
    412 }
    413 
    414 itcl::body Rappture::VtkMeshViewer::EventuallySetPolydataOpacity { args } {
     410    set val $_settings(-polydataopacity)
     411    SendCmd "polydata opacity $val"
     412}
     413
     414itcl::body Rappture::VtkMeshViewer::EventuallySetPolydataOpacity {} {
    415415    if { !$_polydataOpacityPending } {
    416416        set _polydataOpacityPending 1
    417         $_dispatcher event -after $_scaleDelay !polydataOpacity
     417        $_dispatcher event -after $_opacityDelay !polydataOpacity
    418418    }
    419419}
     
    478478        set _dlist [lreplace $_dlist $pos $pos]
    479479        array unset _obj2ovride $dataobj-*
    480         array unset _settings $dataobj-*
    481480        set changed 1
    482481    }
     
    832831        $_arcball resize $w $h
    833832        DoResize
    834         InitSettings axis-xgrid axis-ygrid axis-zgrid axis-mode \
    835             axis-visible axis-labels
    836  
     833        InitSettings -xgrid -ygrid -zgrid -axismode -axesvisible -axislabels
    837834        StopBufferingCommands
    838835        SendCmd "imgflush"
     
    876873        if { [info exists _obj2ovride($dataobj-raise)] } {
    877874            SendCmd "dataset visible 1 $tag"
    878             SetOpacity $tag
     875            EventuallySetPolydataOpacity
    879876        }
    880877    }
     
    896893        }
    897894    }
    898     InitSettings outline
     895    InitSettings -outline
    899896    if { $_reset } {
    900897        # These are settings that rely on a dataset being loaded.
    901         InitSettings polydata-edges polydata-lighting polydata-opacity \
    902             polydata-visible polydata-wireframe
     898        InitSettings -polydataedges -polydatalighting -polydataopacity \
     899            -polydatavisible -polydatawireframe
    903900 
     901        SendCmd "axis lformat all %g"
     902        # Too many major ticks, so turn off minor ticks
     903        SendCmd "axis minticks all 0"
     904
    904905        set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
    905906        $_arcball quaternion $q
     
    11521153    }
    11531154    switch -- $what {
    1154         "outline" {
    1155             set bool $_settings(outline)
    1156             foreach dataset [CurrentDatasets -visible $_first] {
     1155        "-outline" {
     1156            set bool $_settings($what)
     1157            # Only display a outline for the currently visible sets.
     1158            SendCmd "outline visible 0"
     1159            foreach dataset [CurrentDatasets -visible] {
    11571160                SendCmd "outline visible $bool $dataset"
    11581161            }
    11591162        }
    1160         "polydata-opacity" {
    1161             foreach dataset [CurrentDatasets -visible $_first] {
    1162                 SetOpacity $dataset
    1163             }
    1164         }
    1165         "polydata-wireframe" {
    1166             set bool $_settings(polydata-wireframe)
    1167             foreach dataset [CurrentDatasets -visible $_first] {
    1168                 SendCmd "polydata wireframe $bool $dataset"
    1169             }
    1170         }
    1171         "polydata-visible" {
    1172             set bool $_settings(polydata-visible)
    1173             foreach dataset [CurrentDatasets -visible $_first] {
     1163        "-polydataopacity" {
     1164            EventuallySetPolydataOpacity
     1165        }
     1166        "-polydatawireframe" {
     1167            set bool $_settings($what)
     1168            SendCmd "polydata wireframe $bool"
     1169        }
     1170        "-polydatavisible" {
     1171            set bool $_settings($what)
     1172            # Only change visibility of data sets marked "visible".
     1173            foreach dataset [CurrentDatasets -visible] {
    11741174                SendCmd "polydata visible $bool $dataset"
    11751175            }
    11761176        }
    1177         "polydata-lighting" {
    1178             set bool $_settings(polydata-lighting)
    1179             foreach dataset [CurrentDatasets -visible $_first] {
    1180                 SendCmd "polydata lighting $bool $dataset"
    1181             }
    1182         }
    1183         "polydata-edges" {
    1184             set bool $_settings(polydata-edges)
    1185             foreach dataset [CurrentDatasets -visible $_first] {
    1186                 SendCmd "polydata edges $bool $dataset"
    1187             }
    1188         }
    1189         "axis-visible" {
    1190             set bool $_axis(visible)
     1177        "-polydatalighting" {
     1178            set bool $_settings($what)
     1179            SendCmd "polydata lighting $bool"
     1180        }
     1181        "-polydataedges" {
     1182            set bool $_settings($what)
     1183            SendCmd "polydata edges $bool"
     1184        }
     1185        "-axesvisible" {
     1186            set bool $_settings($what)
    11911187            SendCmd "axis visible all $bool"
    11921188        }
    1193         "axis-labels" {
    1194             set bool $_axis(labels)
     1189        "-axislabels" {
     1190            set bool $_settings($what)
    11951191            SendCmd "axis labels all $bool"
    11961192        }
    1197         "axis-xgrid" {
    1198             set bool $_axis(xgrid)
     1193        "-xgrid" {
     1194            set bool $_settings($what)
    11991195            SendCmd "axis grid x $bool"
    12001196        }
    1201         "axis-ygrid" {
    1202             set bool $_axis(ygrid)
     1197        "-ygrid" {
     1198            set bool $_settings($what)
    12031199            SendCmd "axis grid y $bool"
    12041200        }
    1205         "axis-zgrid" {
    1206             set bool $_axis(zgrid)
     1201        "-zgrid" {
     1202            set bool $_settings($what)
    12071203            SendCmd "axis grid z $bool"
    12081204        }
    1209         "axis-mode" {
     1205        "-axismode" {
    12101206            set mode [$itk_component(axismode) value]
    12111207            set mode [$itk_component(axismode) translate $mode]
    12121208            SendCmd "axis flymode $mode"
    12131209        }
    1214         "axis-xcutaway" - "axis-ycutaway" - "axis-zcutaway" {
    1215             set axis [string range $what 5 5]
    1216             set bool $_axis(${axis}cutaway)
     1210        "-xcutaway" - "-ycutaway" - "-zcutaway" {
     1211            set axis [string range $what 1 1]
     1212            set bool $_settings($what)
    12171213            if { $bool } {
    1218                 set pos [expr $_axis(${axis}position) * 0.01]
    1219                 set dir $_axis(${axis}direction)
     1214                set pos [expr $_settings(-${axis}position) * 0.01]
     1215                set dir $_settings(-${axis}direction)
    12201216                $itk_component(${axis}CutScale) configure -state normal \
    12211217                    -troughcolor white
     
    12271223            }
    12281224        }
    1229         "axis-xposition" - "axis-yposition" - "axis-zposition" -
    1230         "axis-xdirection" - "axis-ydirection" - "axis-zdirection" {
    1231             set axis [string range $what 5 5]
    1232             #set dir $_axis(${axis}direction)
    1233             set pos [expr $_axis(${axis}position) * 0.01]
     1225        "-xposition" - "-yposition" - "-zposition" {
     1226            set axis [string range $what 1 1]
     1227            set pos [expr $_settings($what) * 0.01]
    12341228            SendCmd "renderer clipplane ${axis} $pos -1"
     1229        }
     1230        "-xdirection" - "-ydirection" - "-zdirection" {
     1231            set axis [string range $what 1 1]
     1232            puts stderr "direction not implemented"
    12351233        }
    12361234        default {
     
    13171315    checkbutton $inner.mesh \
    13181316        -text "Show Mesh" \
    1319         -variable [itcl::scope _settings(polydata-visible)] \
    1320         -command [itcl::code $this AdjustSetting polydata-visible] \
     1317        -variable [itcl::scope _settings(-polydatavisible)] \
     1318        -command [itcl::code $this AdjustSetting -polydatavisible] \
    13211319        -font "Arial 9" -anchor w
    13221320
    13231321    checkbutton $inner.outline \
    13241322        -text "Show Outline" \
    1325         -variable [itcl::scope _settings(outline)] \
    1326         -command [itcl::code $this AdjustSetting outline] \
     1323        -variable [itcl::scope _settings(-outline)] \
     1324        -command [itcl::code $this AdjustSetting -outline] \
    13271325        -font "Arial 9" -anchor w
    13281326
    13291327    checkbutton $inner.wireframe \
    13301328        -text "Show Wireframe" \
    1331         -variable [itcl::scope _settings(polydata-wireframe)] \
    1332         -command [itcl::code $this AdjustSetting polydata-wireframe] \
     1329        -variable [itcl::scope _settings(-polydatawireframe)] \
     1330        -command [itcl::code $this AdjustSetting -polydatawireframe] \
    13331331        -font "Arial 9" -anchor w
    13341332
    13351333    checkbutton $inner.lighting \
    13361334        -text "Enable Lighting" \
    1337         -variable [itcl::scope _settings(polydata-lighting)] \
    1338         -command [itcl::code $this AdjustSetting polydata-lighting] \
     1335        -variable [itcl::scope _settings(-polydatalighting)] \
     1336        -command [itcl::code $this AdjustSetting -polydatalighting] \
    13391337        -font "Arial 9" -anchor w
    13401338
    13411339    checkbutton $inner.edges \
    13421340        -text "Show Edges" \
    1343         -variable [itcl::scope _settings(polydata-edges)] \
    1344         -command [itcl::code $this AdjustSetting polydata-edges] \
     1341        -variable [itcl::scope _settings(-polydataedges)] \
     1342        -command [itcl::code $this AdjustSetting -polydataedges] \
    13451343        -font "Arial 9" -anchor w
    13461344
     
    13541352    }
    13551353    bind $inner.field <<Value>> \
    1356         [itcl::code $this AdjustSetting field]
     1354        [itcl::code $this AdjustSetting -field]
    13571355
    13581356    label $inner.opacity_l -text "Opacity" -font "Arial 9" -anchor w
    13591357    ::scale $inner.opacity -from 0 -to 100 -orient horizontal \
    1360         -variable [itcl::scope _settings(polydata-opacity)] \
     1358        -variable [itcl::scope _widget(-polydataopacity)] \
    13611359        -width 10 \
    13621360        -showvalue off \
    1363         -command [itcl::code $this AdjustSetting polydata-opacity]
    1364     $inner.opacity set $_settings(polydata-opacity)
     1361        -command [itcl::code $this AdjustSetting -polydataopacity]
     1362    $inner.opacity set [expr $_settings(-polydataopacity) * 100.0]
    13651363
    13661364    blt::table $inner \
     
    13891387    checkbutton $inner.visible \
    13901388        -text "Show Axes" \
    1391         -variable [itcl::scope _axis(visible)] \
    1392         -command [itcl::code $this AdjustSetting axis-visible] \
     1389        -variable [itcl::scope _settings(-axesvisible)] \
     1390        -command [itcl::code $this AdjustSetting -axesvisible] \
    13931391        -font "Arial 9"
    13941392
    13951393    checkbutton $inner.labels \
    13961394        -text "Show Axis Labels" \
    1397         -variable [itcl::scope _axis(labels)] \
    1398         -command [itcl::code $this AdjustSetting axis-labels] \
     1395        -variable [itcl::scope _settings(-axislabels)] \
     1396        -command [itcl::code $this AdjustSetting -axislabels] \
    13991397        -font "Arial 9"
    14001398
    14011399    checkbutton $inner.gridx \
    14021400        -text "Show X Grid" \
    1403         -variable [itcl::scope _axis(xgrid)] \
    1404         -command [itcl::code $this AdjustSetting axis-xgrid] \
     1401        -variable [itcl::scope _settings(-xgrid)] \
     1402        -command [itcl::code $this AdjustSetting -xgrid] \
    14051403        -font "Arial 9"
    14061404    checkbutton $inner.gridy \
    14071405        -text "Show Y Grid" \
    1408         -variable [itcl::scope _axis(ygrid)] \
    1409         -command [itcl::code $this AdjustSetting axis-ygrid] \
     1406        -variable [itcl::scope _settings(-ygrid)] \
     1407        -command [itcl::code $this AdjustSetting -ygrid] \
    14101408        -font "Arial 9"
    14111409    checkbutton $inner.gridz \
    14121410        -text "Show Z Grid" \
    1413         -variable [itcl::scope _axis(zgrid)] \
    1414         -command [itcl::code $this AdjustSetting axis-zgrid] \
     1411        -variable [itcl::scope _settings(-zgrid)] \
     1412        -command [itcl::code $this AdjustSetting -zgrid] \
    14151413        -font "Arial 9"
    14161414
     
    14261424        "outer_edges"     "outer"         
    14271425    $itk_component(axismode) value "static"
    1428     bind $inner.mode <<Value>> [itcl::code $this AdjustSetting axis-mode]
     1426    bind $inner.mode <<Value>> [itcl::code $this AdjustSetting -axismode]
    14291427
    14301428    blt::table $inner \
     
    15041502            -onimage [Rappture::icon x-cutplane] \
    15051503            -offimage [Rappture::icon x-cutplane] \
    1506             -command [itcl::code $this AdjustSetting axis-xcutaway] \
    1507             -variable [itcl::scope _axis(xcutaway)]
     1504            -command [itcl::code $this AdjustSetting -xcutaway] \
     1505            -variable [itcl::scope _settings(-xcutaway)]
    15081506    }
    15091507    Rappture::Tooltip::for $itk_component(xCutButton) \
     
    15151513            -borderwidth 1 -highlightthickness 0 \
    15161514            -command [itcl::code $this Slice move x] \
    1517             -variable [itcl::scope _axis(xposition)]
     1515            -variable [itcl::scope _settings(-xposition)]
    15181516    } {
    15191517        usual
     
    15321530            -offimage [Rappture::icon arrow-up] \
    15331531            -offvalue 1 \
    1534             -command [itcl::code $this AdjustSetting axis-xdirection] \
    1535             -variable [itcl::scope _axis(xdirection)]
    1536     }
    1537     set _axis(xdirection) -1
     1532            -command [itcl::code $this AdjustSetting -xdirection] \
     1533            -variable [itcl::scope _settings(-xdirection)]
     1534    }
     1535    set _settings(-xdirection) -1
    15381536    Rappture::Tooltip::for $itk_component(xDirButton) \
    15391537        "Toggle the direction of the X-axis cutaway"
     
    15441542            -onimage [Rappture::icon y-cutplane] \
    15451543            -offimage [Rappture::icon y-cutplane] \
    1546             -command [itcl::code $this AdjustSetting axis-ycutaway] \
    1547             -variable [itcl::scope _axis(ycutaway)]
     1544            -command [itcl::code $this AdjustSetting -ycutaway] \
     1545            -variable [itcl::scope _settings(-ycutaway)]
    15481546    }
    15491547    Rappture::Tooltip::for $itk_component(yCutButton) \
     
    15551553            -borderwidth 1 -highlightthickness 0 \
    15561554            -command [itcl::code $this Slice move y] \
    1557             -variable [itcl::scope _axis(yposition)]
     1555            -variable [itcl::scope _settings(-yposition)]
    15581556    } {
    15591557        usual
     
    15721570            -offimage [Rappture::icon arrow-up] \
    15731571            -offvalue 1 \
    1574             -command [itcl::code $this AdjustSetting axis-ydirection] \
    1575             -variable [itcl::scope _axis(ydirection)]
     1572            -command [itcl::code $this AdjustSetting -ydirection] \
     1573            -variable [itcl::scope _settings(-ydirection)]
    15761574    }
    15771575    Rappture::Tooltip::for $itk_component(yDirButton) \
    15781576        "Toggle the direction of the Y-axis cutaway"
    1579     set _axis(ydirection) -1
     1577    set _settings(-ydirection) -1
    15801578
    15811579    # Z-value slicer...
     
    15841582            -onimage [Rappture::icon z-cutplane] \
    15851583            -offimage [Rappture::icon z-cutplane] \
    1586             -command [itcl::code $this AdjustSetting axis-zcutaway] \
    1587             -variable [itcl::scope _axis(zcutaway)]
     1584            -command [itcl::code $this AdjustSetting -zcutaway] \
     1585            -variable [itcl::scope _settings(-zcutaway)]
    15881586    }
    15891587    Rappture::Tooltip::for $itk_component(zCutButton) \
     
    15951593            -borderwidth 1 -highlightthickness 0 \
    15961594            -command [itcl::code $this Slice move z] \
    1597             -variable [itcl::scope _axis(zposition)]
     1595            -variable [itcl::scope _settings(-zposition)]
    15981596    } {
    15991597        usual
     
    16111609            -offimage [Rappture::icon arrow-up] \
    16121610            -offvalue 1 \
    1613             -command [itcl::code $this AdjustSetting axis-zdirection] \
    1614             -variable [itcl::scope _axis(zdirection)]
    1615     }
    1616     set _axis(zdirection) -1
     1611            -command [itcl::code $this AdjustSetting -zdirection] \
     1612            -variable [itcl::scope _settings(-zdirection)]
     1613    }
     1614    set _settings(-zdirection) -1
    16171615    Rappture::Tooltip::for $itk_component(zDirButton) \
    16181616        "Toggle the direction of the Z-axis cutaway"
     
    17331731    set tag $dataobj
    17341732    set type [$dataobj type]
    1735     set color [$dataobj hints color]
    1736     set style [$dataobj hints style]
    1737     if { $dataobj != $_first } {
    1738         set settings(-wireframe) 1
    1739     }
    1740 
    1741     array set settings {
     1733
     1734    array set style {
    17421735        -cloudstyle mesh
    17431736        -color white
     
    17511744        -wireframe 0
    17521745    }
     1746    if { $dataobj != $_first } {
     1747        set style(-wireframe) 1
     1748    }
    17531749    if {$type == "cloud"} {
    1754         set settings(-cloudstyle) points
    1755         set settings(-edges) 0
    1756         set settings(-edgecolor) white
    1757     }
    1758     array set settings $style
    1759     if {$color != ""} {
    1760         set settings(-color) $color
     1750        set style(-cloudstyle) points
     1751        set style(-edges) 0
     1752        set style(-edgecolor) white
     1753    }
     1754    array set style [$dataobj hints style]
     1755
     1756    if {[$dataobj hints color] != ""} {
     1757        set style(-color) [$dataobj hints color]
    17611758    }
    17621759    SendCmd "outline add $tag"
    1763     SendCmd "outline color [Color2RGB $settings(-color)] $tag"
    1764     SendCmd "outline visible $settings(-outline) $tag"
    1765     set _settings(outline) $settings(-outline)
     1760    SendCmd "outline color [Color2RGB $style(-color)] $tag"
     1761    SendCmd "outline visible $style(-outline) $tag"
     1762    set _settings(-outline) $style(-outline)
    17661763
    17671764    SendCmd "polydata add $tag"
    1768     SendCmd "polydata visible $settings(-visible) $tag"
    1769     SendCmd "polydata cloudstyle $settings(-cloudstyle) $tag"
    1770     set _settings(polydata-visible) $settings(-visible)
    1771     SendCmd "polydata edges $settings(-edges) $tag"
    1772     set _settings(polydata-edges) $settings(-edges)
    1773     SendCmd "polydata color [Color2RGB $settings(-color)] $tag"
    1774     #SendCmd "polydata colormode constant {} $tag"
    1775     SendCmd "polydata lighting $settings(-lighting) $tag"
    1776     set _settings(polydata-lighting) $settings(-lighting)
    1777     SendCmd "polydata linecolor [Color2RGB $settings(-edgecolor)] $tag"
    1778     SendCmd "polydata linewidth $settings(-linewidth) $tag"
    1779     SendCmd "polydata opacity $settings(-opacity) $tag"
    1780     set _settings(polydata-opacity) [expr 100.0 * $settings(-opacity)]
    1781     SendCmd "polydata wireframe $settings(-wireframe) $tag"
    1782     set _settings(polydata-wireframe) $settings(-wireframe)
     1765    SendCmd "polydata visible $style(-visible) $tag"
     1766    set _settings(-polydatavisible) $style(-visible)
     1767    SendCmd "polydata cloudstyle $style(-cloudstyle) $tag"
     1768    SendCmd "polydata edges $style(-edges) $tag"
     1769    set _settings(-polydataedges) $style(-edges)
     1770    SendCmd "polydata color [Color2RGB $style(-color)] $tag"
     1771    SendCmd "polydata lighting $style(-lighting) $tag"
     1772    set _settings(-polydatalighting) $style(-lighting)
     1773    SendCmd "polydata linecolor [Color2RGB $style(-edgecolor)] $tag"
     1774    SendCmd "polydata linewidth $style(-linewidth) $tag"
     1775    SendCmd "polydata opacity $style(-opacity) $tag"
     1776    set _settings(-polydataopacity) $style(-opacity)
     1777    set _widget(-polydataopacity) [expr 100.0 * $style(-opacity)]
     1778    SendCmd "polydata wireframe $style(-wireframe) $tag"
     1779    set _settings(-polydatawireframe) $style(-wireframe)
    17831780    set havePolyData 1
    17841781}
     
    18421839}
    18431840
    1844 itcl::body Rappture::VtkMeshViewer::SetOpacity { dataset } {
    1845     set val $_settings(polydata-opacity)
    1846     set sval [expr { 0.01 * double($val) }]
    1847     if { !$_obj2ovride($dataset-raise) } {
    1848         # This is wrong.  Need to figure out why raise isn't set with 1
    1849         #set sval [expr $sval * .6]
    1850     }
    1851     SendCmd "polydata opacity $sval $dataset"
    1852 }
Note: See TracChangeset for help on using the changeset viewer.