Changeset 2464 for trunk


Ignore:
Timestamp:
Sep 3, 2011 1:35:37 PM (13 years ago)
Author:
gah
Message:

add stream controls to vtkviewer

Location:
trunk/gui/scripts
Files:
2 added
4 edited

Legend:

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

    r2385 r2464  
    2929    }
    3030    public method limits {axis}
     31    public method label { elem }
     32    public method type { elem }
    3133    public method style { elem }
    3234    public method values { elem }
     
    3941    private variable _actors
    4042    private variable _styles
     43    private variable _labels
     44    private variable _types
    4145    private variable _data
    4246    private variable _hints
     
    7377            polygon* {
    7478                set _data($elem) [$_xmlobj get $path.$elem.vtk]
     79                set _styles($elem) [$_xmlobj get $path.$elem.about.style]
     80                set _labels($elem) [$_xmlobj get $path.$elem.about.label]
     81                set _types($elem) polydata
     82            }
     83            streamlines* {
     84                set _data($elem) [$_xmlobj get $path.$elem.vtk]
     85                set _styles($elem) [$_xmlobj get $path.$elem.about.style]
     86                set _labels($elem) [$_xmlobj get $path.$elem.about.label]
     87                set _types($elem) streamlines
    7588            }
    7689        }
     
    121134}
    122135
    123 # ----------------------------------------------------------------------
    124 # method style
    125 #       Returns a base64 encoded, gzipped Tcl list that represents the
    126 #       Tcl command and data to recreate the uniform rectangular grid
    127 #       on the nanovis server.
    128 # ----------------------------------------------------------------------
     136#
     137# label --
     138#
     139#       Returns the label of the named drawing element.
     140#
     141itcl::body Rappture::Drawing::label { elem } {
     142    if { [info exists _labels($elem)] } {
     143        return $_labels($elem)
     144    }
     145    return ""
     146}
     147
     148#
     149# type --
     150#
     151#       Returns the type of the named drawing element.
     152#
     153itcl::body Rappture::Drawing::type { elem } {
     154    if { [info exists _types($elem)] } {
     155        return $_types($elem)
     156    }
     157    return ""
     158}
     159
     160#
     161# style --
     162#
     163#       Returns the style string of the named drawing element.
     164#
    129165itcl::body Rappture::Drawing::style { elem } {
    130166    if { [info exists _styles($elem)] } {
     
    134170}
    135171
    136 # ----------------------------------------------------------------------
    137 # method data
    138 #       Returns a base64 encoded, gzipped Tcl list that represents the
    139 #       Tcl command and data to recreate the uniform rectangular grid
    140 #       on the nanovis server.
    141 # ----------------------------------------------------------------------
     172#
     173# data --
     174#
     175#       Returns the data of the named drawing element.
     176#
    142177itcl::body Rappture::Drawing::data { elem } {
    143178    if { [info exists _data($elem)] } {
  • trunk/gui/scripts/sidebarframe.tcl

    r1694 r2464  
    4444    public method select {which}
    4545    public method pop {what}
     46    public method enable { which }
     47    public method disable { which }
    4648
    4749    protected method _toggleTab {which}
    4850    protected method _sash {op x}
    4951    protected method _fixLayout {args}
     52    protected method TabIndex { which }
    5053
    5154    private variable _dispatcher ""  ;# dispatcher for !events
     
    400403
    401404# ----------------------------------------------------------------------
     405# USAGE: disable <which>
     406#
     407# Pops open the sidebar and selects the specified panel.  The <which>
     408# argument can be a panel index, name, or title.
     409# ----------------------------------------------------------------------
     410itcl::body Rappture::SidebarFrame::disable {which} {
     411    set index [TabIndex $which]
     412    set tab [$itk_component(tabs) get $index]
     413    $itk_component(tabs) tab configure $tab -state disabled
     414}
     415
     416
     417# ----------------------------------------------------------------------
     418# USAGE: enable <which>
     419#
     420# Pops open the sidebar and selects the specified panel.  The <which>
     421# argument can be a panel index, name, or title.
     422# ----------------------------------------------------------------------
     423itcl::body Rappture::SidebarFrame::enable {which} {
     424    set index [TabIndex $which]
     425    set tab [$itk_component(tabs) get $index]
     426    $itk_component(tabs) tab configure $tab -state normal
     427}
     428
     429# ----------------------------------------------------------------------
     430# USAGE: TabIndex <which>
     431#
     432# Pops open the sidebar and selects the specified panel.  The <which>
     433# argument can be a panel index, name, or title.
     434# ----------------------------------------------------------------------
     435itcl::body Rappture::SidebarFrame::TabIndex {which} {
     436    set pname ""
     437    switch -glob -- $which {
     438        [0-9]* {
     439            set pname [lindex $_panels(all) $which]
     440        }
     441        panel[0-9]* {
     442            if {[info exists itk_component($which)]} {
     443                set pname $which
     444            }
     445        }
     446        default {
     447            foreach p $_panels(all) {
     448                if {[string equal $_panels($p-title) $which]} {
     449                    set pname $p
     450                    break
     451                }
     452            }
     453        }
     454    }
     455    if {$pname == ""} {
     456        error "bad panel name \"$which\": should be panel id, title, or index"
     457    }
     458    set n [$itk_component(tabs) index -name $pname]
     459    return $n
     460}
     461
     462# ----------------------------------------------------------------------
    402463# USAGE: _toggleTab <which>
    403464#
     
    527588    }
    528589}
     590
  • trunk/gui/scripts/visviewer.tcl

    r2395 r2464  
    3434    # server when idle timeout is reached.
    3535    private variable _idleTimeout 43200000; # 12 hours
    36     #private variable _idleTimeout 5000;    # 5 seconds
     36    #private variable _idleTimeout 10000;    # 5 seconds
    3737    #private variable _idleTimeout 0;       # No timeout
    3838
     
    266266#
    267267itcl::body Rappture::VisViewer::IsConnected {} {
    268     return [expr {"" != $_sid}]
     268    if { $_sid == "" } {
     269        return 0
     270    }
     271    if { [eof $_sid] } {
     272        set _sid ""
     273        return 0
     274    }
     275    return 1
    269276}
    270277
     
    278285#
    279286itcl::body Rappture::VisViewer::CheckConnection {} {
     287    $_dispatcher cancel !timeout
     288    if { $_idleTimeout > 0 } {
     289        $_dispatcher event -after $_idleTimeout !timeout
     290    }
    280291    if { [IsConnected] } {
    281         if { [eof $_sid] } {
    282             error "unexpected eof on socket"
    283         } else {
    284             $_dispatcher cancel !timeout
    285             if { $_idleTimeout > 0 } {
    286                 $_dispatcher event -after $_idleTimeout !timeout
    287             }
    288             return 1
    289         }
     292        return 1
     293    }
     294    if { $_sid != "" } {
     295        fileevent $_sid writable ""
    290296    }
    291297    # If we aren't connected, assume it's because the connection to the
     
    332338    puts -nonewline $_sid $_buffer(out)
    333339    flush $_sid
    334     set _done($this) 1;     # Success
     340    set _done($this) 1;                 # Success
    335341}
    336342
  • trunk/gui/scripts/vtkviewer.tcl

    r2426 r2464  
    8080    # The following methods are only used by this class.
    8181    private method BuildCameraTab {}
    82     private method BuildViewTab {}
     82    private method BuildVolumeTab {}
     83    private method BuildStreamsTab {}
    8384    private method BuildAxisTab {}
    8485    private method BuildColormap { colormap dataobj comp }
     
    114115    private variable _reset 1      ;# indicates if camera needs to be reset
    115116                                    # to starting position.
    116 
     117    private variable _haveStreams 0
    117118    # Array of transfer functions in server.  If 0 the transfer has been
    118119    # defined but not loaded.  If 1 the transfer function has been named
     
    185186    array set _settings [subst {
    186187        $this-axes              1
     188        $this-seeds             1
     189        $this-streamlines       1
    187190        $this-edges             1
    188191        $this-lighting          1
     
    259262    Rappture::Tooltip::for $itk_component(zoomout) "Zoom out"
    260263
    261     BuildViewTab
    262     BuildAxisTab
    263     BuildCameraTab
     264    if { [catch {
     265        BuildVolumeTab
     266        BuildAxisTab
     267        BuildStreamsTab
     268        BuildCameraTab
     269    } errs] != 0 } {
     270        puts stderr err=$errs
     271    }
    264272
    265273    # Hack around the Tk panewindow.  The problem is that the requested
     
    539547    foreach dataobj $args {
    540548        array set bounds [limits $dataobj]
     549 puts stderr bounds=[array get bounds]
    541550        if {![info exists _limits(xmin)] || $_limits(xmin) > $bounds(xmin)} {
    542551            set _limits(xmin) $bounds(xmin)
     
    803812    set _limits(vmax) ""
    804813    set _first ""
     814    set _haveStreams 0
    805815    foreach dataobj [get -objects] {
    806816        if { [info exists _obj2ovride($dataobj-raise)] &&  $_first == "" } {
     
    852862    FixSettings axes
    853863    FixSettings edges
     864    FixSettings seeds
     865    FixSettings streamlines
    854866    FixSettings axismode
    855867
     868    if { !$_haveStreams } {
     869        $itk_component(main) disable "Streams Settings"
     870    }
    856871    if {"" != $_first} {
    857872        set location [$_first hints camera]
     
    10491064        }
    10501065        "drag" {
     1066            if { ![info exists _click(x)] } {
     1067                set _click(x) $x
     1068            }
     1069            if { ![info exists _click(y)] } {
     1070                set _click(y) $y
     1071            }
    10511072            set w [winfo width $itk_component(view)]
    10521073            set h [winfo height $itk_component(view)]
     
    10771098# ----------------------------------------------------------------------
    10781099itcl::body Rappture::VtkViewer::FixSettings {what {value ""}} {
     1100    if { ![isconnected] } {
     1101        return
     1102    }
    10791103    switch -- $what {
    10801104        "opacity" {
    1081             if {[isconnected]} {
    1082                 set val $_settings($this-opacity)
    1083                 set sval [expr { 0.01 * double($val) }]
    1084                 foreach dataset [CurrentDatasets -visible $_first] {
    1085                     SendCmd "polydata opacity $sval $dataset"
    1086                 }
     1105            set val $_settings($this-opacity)
     1106            set sval [expr { 0.01 * double($val) }]
     1107            foreach dataset [CurrentDatasets -visible $_first] {
     1108                SendCmd "polydata opacity $sval $dataset"
     1109            }
     1110        }
     1111        "wireframe" {
     1112            set bool $_settings($this-wireframe)
     1113            foreach dataset [CurrentDatasets -visible $_first] {
     1114                SendCmd "polydata wireframe $bool $dataset"
    10871115            }
    10881116        }
    1089         "wireframe" {
    1090             if {[isconnected]} {
    1091                 set bool $_settings($this-wireframe)
    1092                 foreach dataset [CurrentDatasets -visible $_first] {
    1093                     SendCmd "polydata wireframe $bool $dataset"
    1094                 }
     1117        "volume" {
     1118            set bool $_settings($this-volume)
     1119            foreach dataset [CurrentDatasets -visible $_first] {
     1120                SendCmd "polydata visible $bool $dataset"
    10951121            }
    10961122        }
    1097         "volume" {
    1098             if {[isconnected]} {
    1099                 set bool $_settings($this-volume)
    1100                 foreach dataset [CurrentDatasets -visible $_first] {
    1101                     SendCmd "polydata visible $bool $dataset"
    1102                 }
     1123        "lighting" {
     1124            set bool $_settings($this-lighting)
     1125            foreach dataset [CurrentDatasets -visible $_first] {
     1126                SendCmd "polydata lighting $bool $dataset"
    11031127            }
    11041128        }
    1105         "lighting" {
    1106             if {[isconnected]} {
    1107                 set bool $_settings($this-lighting)
    1108                 foreach dataset [CurrentDatasets -visible $_first] {
    1109                     SendCmd "polydata lighting $bool $dataset"
    1110                 }
    1111             }
    1112         }
    11131129        "grid-x" {
    1114             if {[isconnected]} {
    1115                 set bool $_settings($this-grid-x)
    1116                 SendCmd "axis grid x $bool"
    1117             }
     1130            set bool $_settings($this-grid-x)
     1131            SendCmd "axis grid x $bool"
    11181132        }
    11191133        "grid-y" {
    1120             if {[isconnected]} {
    1121                 set bool $_settings($this-grid-y)
    1122                 SendCmd "axis grid y $bool"
    1123             }
     1134            set bool $_settings($this-grid-y)
     1135            SendCmd "axis grid y $bool"
    11241136        }
    11251137        "grid-z" {
    1126             if {[isconnected]} {
    1127                 set bool $_settings($this-grid-z)
    1128                 SendCmd "axis grid z $bool"
    1129             }
     1138            set bool $_settings($this-grid-z)
     1139            SendCmd "axis grid z $bool"
     1140        }
     1141        "axes" {
     1142            set bool $_settings($this-axes)
     1143            SendCmd "axis visible all $bool"
     1144        }
     1145        "axismode" {
     1146            set mode [$itk_component(axismode) value]
     1147            set mode [$itk_component(axismode) translate $mode]
     1148            SendCmd "axis flymode $mode"
    11301149        }
    11311150        "edges" {
    1132             if {[isconnected]} {
    1133                 set bool $_settings($this-edges)
    1134                 foreach dataset [CurrentDatasets -visible $_first] {
     1151            set bool $_settings($this-edges)
     1152            foreach dataset [CurrentDatasets -visible $_first] {
     1153                foreach {dataobj comp} [split $dataset -] break
     1154                if { [$dataobj type $comp] != "streamlines" } {
    11351155                    SendCmd "polydata edges $bool $dataset"
    11361156                }
    11371157            }
    11381158        }
    1139         "axes" {
    1140             if { [isconnected] } {
    1141                 set bool $_settings($this-axes)
    1142                 SendCmd "axis visible all $bool"
     1159        "seeds" {
     1160            set bool $_settings($this-seeds)
     1161            foreach dataset [CurrentDatasets -visible $_first] {
     1162                foreach {dataobj comp} [split $dataset -] break
     1163                if { [$dataobj type $comp] == "streamlines" } {
     1164                    SendCmd "streamlines seed visible $bool $dataset"
     1165                }
     1166            }
     1167        }
     1168        "streamlines" {
     1169            set bool $_settings($this-streamlines)
     1170            foreach dataset [CurrentDatasets -visible $_first] {
     1171                foreach {dataobj comp} [split $dataset -] break
     1172                if { [$dataobj type $comp] == "streamlines" } {
     1173                    if { $bool } {
     1174                        SendCmd "streamlines add $dataset"
     1175                    } else {
     1176                        SendCmd "streamlines delete $dataset"
     1177                    }
     1178                }
    11431179            }
    11441180        }
    1145         "axismode" {
    1146             if { [isconnected] } {
    1147                 set mode [$itk_component(axismode) value]
    1148                 set mode [$itk_component(axismode) translate $mode]
    1149                 SendCmd "axis flymode $mode"
     1181        "streammode" {
     1182            set mode [$itk_component(streammode) value]
     1183            foreach dataset [CurrentDatasets -visible $_first] {
     1184                foreach {dataobj comp} [split $dataset -] break
     1185                if { [$dataobj type $comp] == "streamlines" } {
     1186                    switch -- $mode {
     1187                        "lines" {
     1188                            SendCmd "streamlines lines $dataset"
     1189                        }
     1190                        "ribbons" {
     1191                            SendCmd "streamlines ribbons 3.0 20 $dataset"
     1192                        }
     1193                        "tubes" {
     1194                            SendCmd "streamlines tubes 20 10 $dataset"
     1195                        }
     1196                    }
     1197                }
    11501198            }
    11511199        }
     
    12791327}
    12801328
    1281 
    1282 itcl::body Rappture::VtkViewer::BuildViewTab {} {
     1329itcl::body Rappture::VtkViewer::BuildVolumeTab {} {
    12831330
    12841331    set fg [option get $itk_component(hull) font Font]
     
    12861333
    12871334    set inner [$itk_component(main) insert end \
    1288         -title "View Settings" \
    1289         -icon [Rappture::icon wrench]]
     1335        -title "Volume Settings" \
     1336        -icon [Rappture::icon volume-on]]
    12901337    $inner configure -borderwidth 4
     1338
     1339    checkbutton $inner.volume \
     1340        -text "Visible" \
     1341        -variable [itcl::scope _settings($this-volume)] \
     1342        -command [itcl::code $this FixSettings volume] \
     1343        -font "Arial 9"
    12911344
    12921345    checkbutton $inner.wireframe \
     
    12961349        -font "Arial 9"
    12971350
    1298     checkbutton $inner.axes \
    1299         -text "Axes" \
    1300         -variable [itcl::scope _settings($this-axes)] \
    1301         -command [itcl::code $this FixSettings axes] \
    1302         -font "Arial 9"
    1303 
    1304     checkbutton $inner.volume \
    1305         -text "Volume" \
    1306         -variable [itcl::scope _settings($this-volume)] \
    1307         -command [itcl::code $this FixSettings volume] \
    1308         -font "Arial 9"
    1309 
    13101351    checkbutton $inner.lighting \
    13111352        -text "Lighting" \
     
    13201361        -font "Arial 9"
    13211362
    1322     label $inner.clear -text "Clear" -font "Arial 9"
     1363    label $inner.opacity_l -text "Opacity" -font "Arial 9"
    13231364    ::scale $inner.opacity -from 0 -to 100 -orient horizontal \
    13241365        -variable [itcl::scope _settings($this-opacity)] \
    13251366        -width 10 \
    13261367        -showvalue off -command [itcl::code $this FixSettings opacity]
    1327     label $inner.opaque -text "Opaque" -font "Arial 9"
    13281368
    13291369    blt::table $inner \
    1330         0,0 $inner.axes -columnspan 4 -anchor w -pady 2 \
    1331         1,0 $inner.volume -columnspan 4 -anchor w -pady 2 \
    1332         2,0 $inner.wireframe -columnspan 4 -anchor w -pady 2 \
    1333         3,0 $inner.lighting  -columnspan 4 -anchor w \
    1334         4,0 $inner.edges -columnspan 4 -anchor w -pady 2 \
    1335         6,0 $inner.clear -anchor e -pady 2 \
    1336         6,1 $inner.opacity -columnspan 2 -pady 2 -fill x\
    1337         6,3 $inner.opaque -anchor w -pady 2
     1370        0,0 $inner.volume -columnspan 4 -anchor w -pady 2 \
     1371        1,0 $inner.wireframe -columnspan 4 -anchor w -pady 2 \
     1372        2,0 $inner.lighting  -columnspan 4 -anchor w \
     1373        3,0 $inner.edges -columnspan 4 -anchor w -pady 2 \
     1374        4,0 $inner.opacity_l -anchor w -pady 2 \
     1375        5,0 $inner.opacity -columnspan 2 -pady 2 -fill x
    13381376
    13391377    blt::table configure $inner r* -resize none
    1340     blt::table configure $inner r7 -resize expand
    1341 }
    1342 
    1343 itcl::body Rappture::VtkViewer::BuildAxisTab {} {
     1378    blt::table configure $inner r6 -resize expand
     1379}
     1380
     1381
     1382itcl::body Rappture::VtkViewer::BuildStreamsTab {} {
    13441383
    13451384    set fg [option get $itk_component(hull) font Font]
     
    13471386
    13481387    set inner [$itk_component(main) insert end \
     1388        -title "Streams Settings" \
     1389        -icon [Rappture::icon stream]]
     1390    $inner configure -borderwidth 4
     1391
     1392    checkbutton $inner.streamlines \
     1393        -text "Visible" \
     1394        -variable [itcl::scope _settings($this-streamlines)] \
     1395        -command [itcl::code $this FixSettings streamlines] \
     1396        -font "Arial 9"
     1397
     1398    checkbutton $inner.seeds \
     1399        -text "Show seeds" \
     1400        -variable [itcl::scope _settings($this-seeds)] \
     1401        -command [itcl::code $this FixSettings seeds] \
     1402        -font "Arial 9"
     1403
     1404    label $inner.streammode -text "Mode" \
     1405        -font "Arial 9"
     1406
     1407    itk_component add streammode {
     1408        Rappture::Combobox $inner.streammode_combo -width 10 -editable no
     1409    }
     1410    $inner.streammode_combo choices insert end \
     1411        "lines"    "lines" \
     1412        "ribbons"   "ribbons" \
     1413        "tubes"     "tubes"
     1414    $itk_component(streammode) value "lines"
     1415    bind $inner.streammode_combo <<Value>> \
     1416        [itcl::code $this FixSettings streammode]
     1417
     1418    label $inner.opacity_l -text "Opacity" -font "Arial 9"
     1419    ::scale $inner.opacity -from 0 -to 100 -orient horizontal \
     1420        -variable [itcl::scope _settings($this-opacity)] \
     1421        -width 10 \
     1422        -showvalue off -command [itcl::code $this FixSettings opacity]
     1423
     1424    blt::table $inner \
     1425        0,0 $inner.streamlines -columnspan 4 -anchor w -pady 2 \
     1426        1,0 $inner.seeds -columnspan 4 -anchor w -pady 2 \
     1427        2,0 $inner.streammode -anchor w -pady 2 \
     1428        2,1 $inner.streammode_combo -cspan 3 -anchor w -pady 2 \
     1429        3,0 $inner.opacity_l -pady 2 -fill x\
     1430        4,0 $inner.opacity -columnspan 2 -pady 2 -fill x
     1431
     1432    blt::table configure $inner r* -resize none
     1433    blt::table configure $inner r5 -resize expand
     1434}
     1435
     1436itcl::body Rappture::VtkViewer::BuildAxisTab {} {
     1437
     1438    set fg [option get $itk_component(hull) font Font]
     1439    #set bfg [option get $itk_component(hull) boldFont Font]
     1440
     1441    set inner [$itk_component(main) insert end \
    13491442        -title "Axis Settings" \
    1350         -icon [Rappture::icon cog]]
     1443        -icon [Rappture::icon axis1]]
    13511444    $inner configure -borderwidth 4
    13521445
     
    15591652
    15601653itcl::body Rappture::VtkViewer::SetObjectStyle { dataobj comp } {
    1561     array set props {
    1562         -color \#6666FF
    1563         -edgevisibility 1
    1564         -edgecolor black
    1565         -linewidth 1.0
    1566         -opacity 1.0
    1567         -wireframe 0
    1568         -lighting 1
    1569     }
    15701654    # Parse style string.
     1655    set tag $dataobj-$comp
     1656    set type [$dataobj type $comp]
     1657    if { $type == "streamlines" } {
     1658        array set props {
     1659            -color \#808080
     1660            -edgevisibility 0
     1661            -edgecolor black
     1662            -linewidth 1.0
     1663            -opacity 0.4
     1664            -wireframe 0
     1665            -lighting 1
     1666            -seeds 1
     1667            -seedcolor white
     1668        }
     1669        SendCmd "streamlines add $tag"
     1670        SendCmd "streamlines seed visible off"
     1671        set _haveStreams 1
     1672    } else {
     1673        array set props {
     1674            -color \#6666FF
     1675            -edgevisibility 1
     1676            -edgecolor black
     1677            -linewidth 1.0
     1678            -opacity 1.0
     1679            -wireframe 0
     1680            -lighting 1
     1681        }
     1682    }
    15711683    set style [$dataobj style $comp]
    1572     set tag $dataobj-$comp
    15731684    array set props $style
     1685
     1686    SendCmd "polydata edges $props(-edgevisibility) $tag"
    15741687    SendCmd "polydata color [Color2RGB $props(-color)] $tag"
    1575     SendCmd "polydata edges $props(-edgevisibility) $tag"
    15761688    SendCmd "polydata lighting $props(-lighting) $tag"
    15771689    SendCmd "polydata linecolor [Color2RGB $props(-edgecolor)] $tag"
Note: See TracChangeset for help on using the changeset viewer.