Changeset 3121 for trunk/gui


Ignore:
Timestamp:
Jul 27, 2012 11:38:19 AM (12 years ago)
Author:
gah
Message:

Added molecule settings tab.

Segregated volume (polydata) and molecule settings for opacity,
visibility, edges, wireframe, palette, etc.

Location:
trunk/gui/scripts
Files:
1 added
1 edited

Legend:

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

    r3118 r3121  
    6969    protected method DoResize {}
    7070    protected method DoRotate {}
     71    private method DoUpdate {}
    7172    protected method AdjustSetting {what {value ""}}
    7273    protected method FixSettings { args  }
     
    8889    private method BuildDownloadPopup { widget command }
    8990    private method BuildVolumeTab {}
     91    private method BuildMoleculeTab {}
    9092    private method ConvertToVtkData { dataobj comp }
    9193    private method DrawLegend {}
     
    9395    private method EventuallyResize { w h }
    9496    private method EventuallyRotate { q }
     97    private method EventuallyChangeSettings { args }
    9598    private method GetImage { args }
    9699    private method GetVtkData { args }
     
    127130    private variable _style;            # Array of current component styles.
    128131    private variable _initialStyle;     # Array of initial component styles.
    129     private variable _volume
    130132    private variable _axis
    131133    private variable _reset 1      ;# indicates if camera needs to be reset
     
    145147    private variable _resizePending 0
    146148    private variable _rotatePending 0
     149    private variable _updatePending 0;
    147150    private variable _outline
    148151}
     
    167170    $_dispatcher register !resize
    168171    $_dispatcher dispatch $this !resize "[itcl::code $this DoResize]; list"
     172
     173    # Update state event
     174    $_dispatcher register !update
     175    $_dispatcher dispatch $this !update "[itcl::code $this DoUpdate]; list"
    169176
    170177    # Rotate event
     
    223230        labels          1
    224231    }]
    225     array set _volume [subst {
    226         edges           0
    227         lighting        1
    228         opacity         40
    229         visible         1
    230         wireframe       0
    231         palette         rainbow
    232     }]
    233232    array set _settings [subst {
    234233        legend          1
     234        molecule-atomscale      0.5
     235        molecule-bondscale      0.2
     236        molecule-atomradius     "Van der Waals"
     237        molecule-representation  "ball and stick"
     238        molecule-edges           0
     239        molecule-lighting        1
     240        molecule-opacity         40
     241        molecule-visible         1
     242        molecule-wireframe       0
     243        molecule-palette        rainbow
     244        volume-edges           0
     245        volume-lighting        1
     246        volume-opacity         40
     247        volume-visible         1
     248        volume-wireframe       0
     249        volume-palette          rainbow
    235250    }]
    236251
     
    304319        puts stderr "errs=$errs"
    305320    }
     321    puts stderr "BuildMoleculeTab"
     322    if { [catch { BuildMoleculeTab } errs ]  != 0 } {
     323        global errorInfo
     324        puts stderr "errs=$errs\nerrorInfo=$errorInfo"
     325    }
    306326    BuildAxisTab
    307     BuildCutawayTab
     327    #BuildCutawayTab
    308328    BuildCameraTab
    309329
     
    448468}
    449469
     470itcl::body Rappture::VtkViewer::DoUpdate { } {
     471    foreach dataset [CurrentDatasets -visible $_first] {
     472        foreach { dataobj comp } [split $dataset -] break
     473        set type [$dataobj type $comp]
     474        if { $type == "molecule" } {
     475            set val [expr $_settings(molecule-atomscale) * 0.1]
     476            SendCmd "molecule ascale $val $dataset"
     477            set val [expr $_settings(molecule-bondscale) * 0.1]
     478            SendCmd "molecule bscale $val $dataset"
     479        }
     480    }
     481    set _updatePending 0
     482}
     483
     484itcl::body Rappture::VtkViewer::EventuallyChangeSettings { args } {
     485    if { !$_updatePending } {
     486        $_dispatcher event -after 250 !update
     487        set _updatePending 1
     488    }
     489}
     490
    450491# ----------------------------------------------------------------------
    451492# USAGE: add <dataobj> ?<settings>?
     
    876917        SendCmd "camera mode persp"
    877918    }
     919
    878920    DoRotate
    879921    PanCamera
     
    935977            }
    936978        }
     979    }
     980    if { $_haveMolecules } {
     981        FixSettings molecule-radius molecule-representation
    937982    }
    938983    SendCmd "dataset maprange visible"
     
    11781223    switch -- $what {
    11791224        "volume-opacity" {
    1180             set val $_volume(opacity)
     1225            set val $_settings(volume-opacity)
    11811226            set sval [expr { 0.01 * double($val) }]
    11821227            foreach dataset [CurrentDatasets -visible $_first] {
    11831228                foreach { dataobj comp } [split $dataset -] break
    11841229                set type [$dataobj type $comp]
    1185                 if { $type != "" && $type != "glyphs" } {
     1230                if { $type == "polydata" } {
    11861231                    SendCmd "$type opacity $sval $dataset"
    11871232                }
     
    11891234        }
    11901235        "volume-wireframe" {
    1191             set bool $_volume(wireframe)
     1236            set bool $_settings(volume-wireframe)
    11921237            foreach dataset [CurrentDatasets -visible $_first] {
    11931238                foreach { dataobj comp } [split $dataset -] break
    11941239                set type [$dataobj type $comp]
    1195                 if { $type != "" } {
     1240                if { $type == "polydata" } {
    11961241                    SendCmd "$type wireframe $bool $dataset"
    11971242                }
     
    11991244        }
    12001245        "volume-visible" {
    1201             set bool $_volume(visible)
     1246            set bool $_settings(volume-visible)
    12021247            foreach dataset [CurrentDatasets -visible $_first] {
    12031248                foreach { dataobj comp } [split $dataset -] break
    12041249                set type [$dataobj type $comp]
    1205                 if { $type != "" } {
     1250                if { $type == "polydata" } {
    12061251                    SendCmd "$type visible $bool $dataset"
    12071252                }
     
    12091254        }
    12101255        "volume-lighting" {
    1211             set bool $_volume(lighting)
     1256            set bool $_settings(volume-lighting)
    12121257            foreach dataset [CurrentDatasets -visible $_first] {
    12131258                foreach { dataobj comp } [split $dataset -] break
    12141259                set type [$dataobj type $comp]
    1215                 if { $type != "" } {
     1260                if { $type == "polydata" } {
    12161261                    SendCmd "$type lighting $bool $dataset"
    12171262                }
     
    12191264        }
    12201265        "volume-edges" {
    1221             set bool $_volume(edges)
     1266            set bool $_settings(volume-edges)
    12221267            foreach dataset [CurrentDatasets -visible $_first] {
    12231268                foreach { dataobj comp } [split $dataset -] break
    12241269                set type [$dataobj type $comp]
    1225                 if { $type != "" } {
     1270                if { $type == "polydata" } {
    12261271                    SendCmd "$type edges $bool $dataset"
    12271272                }
     
    12331278            foreach dataset [CurrentDatasets -visible $_first] {
    12341279                foreach {dataobj comp} [split $dataset -] break
    1235                 ChangeColormap $dataobj $comp $palette
     1280                set type [$dataobj type $comp]
     1281                if { $type == "polydata" } {
     1282                    ChangeColormap $dataobj $comp $palette
     1283                }
    12361284            }
    12371285            set _legendPending 1
    12381286        }
     1287        "molecule-opacity" {
     1288            set val $_settings(molecule-opacity)
     1289            set sval [expr { 0.01 * double($val) }]
     1290            foreach dataset [CurrentDatasets -visible $_first] {
     1291                foreach { dataobj comp } [split $dataset -] break
     1292                set type [$dataobj type $comp]
     1293                if { $type == "molecule" } {
     1294                    SendCmd "molecule opacity $sval $dataset"
     1295                }
     1296            }
     1297        }
     1298        "molecule-wireframe" {
     1299            set bool $_settings(molecule-wireframe)
     1300            foreach dataset [CurrentDatasets -visible $_first] {
     1301                foreach { dataobj comp } [split $dataset -] break
     1302                set type [$dataobj type $comp]
     1303                if { $type == "molecule" } {
     1304                    SendCmd "molecule wireframe $bool $dataset"
     1305                }
     1306            }
     1307        }
     1308        "molecule-visible" {
     1309            set bool $_settings(molecule-visible)
     1310            foreach dataset [CurrentDatasets -visible $_first] {
     1311                foreach { dataobj comp } [split $dataset -] break
     1312                set type [$dataobj type $comp]
     1313                if { $type == "molecule" } {
     1314                    SendCmd "molecule visible $bool $dataset"
     1315                }
     1316            }
     1317        }
     1318        "molecule-lighting" {
     1319            set bool $_settings(molecule-lighting)
     1320            foreach dataset [CurrentDatasets -visible $_first] {
     1321                foreach { dataobj comp } [split $dataset -] break
     1322                set type [$dataobj type $comp]
     1323                if { $type == "molecule" } {
     1324                    SendCmd "molecule lighting $bool $dataset"
     1325                }
     1326            }
     1327        }
     1328        "molecule-edges" {
     1329            set bool $_settings(molecule-edges)
     1330            foreach dataset [CurrentDatasets -visible $_first] {
     1331                foreach { dataobj comp } [split $dataset -] break
     1332                set type [$dataobj type $comp]
     1333                if { $type == "molecule" } {
     1334                    SendCmd "molecule edges $bool $dataset"
     1335                }
     1336            }
     1337        }
     1338        "molecule-palette" {
     1339            set palette [$itk_component(moleculepalette) value]
     1340            set _settings(molecule-palette) $palette
     1341            foreach dataset [CurrentDatasets -visible $_first] {
     1342                foreach {dataobj comp} [split $dataset -] break
     1343                set type [$dataobj type $comp]
     1344                if { $type == "molecule" } {
     1345                    ChangeColormap $dataobj $comp $palette
     1346                }
     1347            }
     1348            set _legendPending 1
     1349        }
     1350        "molecule-radius" {
     1351            set value [$itk_component(atomradius) value]
     1352            set value [$itk_component(atomradius) translate $value]
     1353            foreach dataset [CurrentDatasets -visible $_first] {
     1354                foreach {dataobj comp} [split $dataset -] break
     1355                set type [$dataobj type $comp]
     1356                if { $type == "molecule" } {
     1357                    SendCmd "molecule rscale $value $dataset"
     1358                }
     1359            }
     1360        }
     1361        "molecule-representation" {
     1362            set value [$itk_component(representation) value]
     1363            set value [$itk_component(representation) translate $value]
     1364            foreach dataset [CurrentDatasets -visible $_first] {
     1365                foreach {dataobj comp} [split $dataset -] break
     1366                set type [$dataobj type $comp]
     1367                if { $type == "molecule" } {
     1368                    switch -- $value {
     1369                        "ballandstick" {
     1370                            SendCmd "molecule atoms 1 $dataset"
     1371                            SendCmd "molecule bonds 1 $dataset"
     1372                        }
     1373                        "spheres" {
     1374                            SendCmd "molecule atoms 1 $dataset"
     1375                            SendCmd "molecule bonds 0 $dataset"
     1376                        }
     1377                        "sticks" - "lines" {
     1378                            SendCmd "molecule atoms 0 $dataset"
     1379                            SendCmd "molecule bonds 1 $dataset"
     1380                        }
     1381                        default {
     1382                            error "unknown representation $value"
     1383                        }
     1384                    }
     1385                }
     1386            }
     1387        }
    12391388        "axis-visible" {
    12401389            set bool $_axis(visible)
     
    13701519            }
    13711520            "molecule" {
    1372                 #SendCmd "molecule colormap $name $tag"
     1521                SendCmd "molecule colormap $name $tag"
    13731522            }
    13741523        }
     
    17091858    checkbutton $inner.volume \
    17101859        -text "Show Volume" \
    1711         -variable [itcl::scope _volume(visible)] \
     1860        -variable [itcl::scope _settings(volume-visible)] \
    17121861        -command [itcl::code $this AdjustSetting volume-visible] \
    17131862        -font "Arial 9"
     
    17151864    checkbutton $inner.wireframe \
    17161865        -text "Show Wireframe" \
    1717         -variable [itcl::scope _volume(wireframe)] \
     1866        -variable [itcl::scope _settings(volume-wireframe)] \
    17181867        -command [itcl::code $this AdjustSetting volume-wireframe] \
    17191868        -font "Arial 9"
     
    17211870    checkbutton $inner.lighting \
    17221871        -text "Enable Lighting" \
    1723         -variable [itcl::scope _volume(lighting)] \
     1872        -variable [itcl::scope _settings(volume-lighting)] \
    17241873        -command [itcl::code $this AdjustSetting volume-lighting] \
    17251874        -font "Arial 9"
     
    17271876    checkbutton $inner.edges \
    17281877        -text "Show Edges" \
    1729         -variable [itcl::scope _volume(edges)] \
     1878        -variable [itcl::scope _settings(volume-edges)] \
    17301879        -command [itcl::code $this AdjustSetting volume-edges] \
    17311880        -font "Arial 9"
    17321881
    17331882    label $inner.palette_l -text "Palette" -font "Arial 9"
    1734     itk_component add palette {
     1883    itk_component add volumepalette {
    17351884        Rappture::Combobox $inner.palette -width 10 -editable no
    17361885    }
     
    17531902        "orange-to-blue"     "orange-to-blue"   
    17541903
    1755     $itk_component(palette) value "BCGYR"
     1904    $itk_component(volumepalette) value "BCGYR"
    17561905    bind $inner.palette <<Value>> \
    17571906        [itcl::code $this AdjustSetting volume-palette]
     
    17591908    label $inner.opacity_l -text "Opacity" -font "Arial 9"
    17601909    ::scale $inner.opacity -from 0 -to 100 -orient horizontal \
    1761         -variable [itcl::scope _volume(opacity)] \
     1910        -variable [itcl::scope _settings(volume-opacity)] \
    17621911        -width 10 \
    17631912        -showvalue off \
     
    20202169}
    20212170
    2022 
     2171itcl::body Rappture::VtkViewer::BuildMoleculeTab {} {
     2172    set fg [option get $itk_component(hull) font Font]
     2173
     2174    set inner [$itk_component(main) insert end \
     2175        -title "Molecule Settings" \
     2176        -icon [Rappture::icon molecule]]
     2177    $inner configure -borderwidth 4
     2178
     2179    checkbutton $inner.molecule \
     2180        -text "Show Molecule" \
     2181        -variable [itcl::scope _settings(molecule-visible)] \
     2182        -command [itcl::code $this AdjustSetting molecule-visible] \
     2183        -font "Arial 9"
     2184
     2185    checkbutton $inner.label \
     2186        -text "Show Atom Labels" \
     2187        -variable [itcl::scope _settings(molecule-labels)] \
     2188        -font "Arial 9"
     2189
     2190    checkbutton $inner.wireframe \
     2191        -text "Show Wireframe" \
     2192        -variable [itcl::scope _settings(molecule-wireframe)] \
     2193        -command [itcl::code $this AdjustSetting molecule-wireframe] \
     2194        -font "Arial 9"
     2195
     2196    checkbutton $inner.lighting \
     2197        -text "Enable Lighting" \
     2198        -variable [itcl::scope _settings(molecule-lighting)] \
     2199        -command [itcl::code $this AdjustSetting molecule-lighting] \
     2200        -font "Arial 9"
     2201
     2202    checkbutton $inner.edges \
     2203        -text "Show Edges" \
     2204        -variable [itcl::scope _settings(molecule-edges)] \
     2205        -command [itcl::code $this AdjustSetting molecule-edges] \
     2206        -font "Arial 9"
     2207
     2208    label $inner.rep_l -text "Molecule Representation" \
     2209        -font "Arial 9"
     2210
     2211    itk_component add representation {
     2212        Rappture::Combobox $inner.rep -width 20 -editable no
     2213    }
     2214    $inner.rep choices insert end \
     2215        "ballandstick"  "ball and stick" \
     2216        "spheres"       "spheres"         \
     2217        "sticks"        "sticks"          \
     2218        "lines"         "lines"           
     2219
     2220    bind $inner.rep <<Value>> \
     2221        [itcl::code $this AdjustSetting molecule-representation]
     2222    $inner.rep value "ball and stick"
     2223
     2224    label $inner.palette_l -text "Palette" -font "Arial 9"
     2225    itk_component add moleculepalette {
     2226        Rappture::Combobox $inner.palette -width 10 -editable no
     2227    }
     2228    $inner.palette choices insert end \
     2229        "BCGYR"              "BCGYR"            \
     2230        "BGYOR"              "BGYOR"            \
     2231        "blue"               "blue"             \
     2232        "blue-to-brown"      "blue-to-brown"    \
     2233        "blue-to-orange"     "blue-to-orange"   \
     2234        "blue-to-grey"       "blue-to-grey"     \
     2235        "green-to-magenta"   "green-to-magenta" \
     2236        "greyscale"          "greyscale"        \
     2237        "nanohub"            "nanohub"          \
     2238        "rainbow"            "rainbow"          \
     2239        "spectral"           "spectral"         \
     2240        "ROYGB"              "ROYGB"            \
     2241        "RYGCB"              "RYGCB"            \
     2242        "brown-to-blue"      "brown-to-blue"    \
     2243        "grey-to-blue"       "grey-to-blue"     \
     2244        "orange-to-blue"     "orange-to-blue"   
     2245
     2246    $itk_component(moleculepalette) value "BCGYR"
     2247    bind $inner.palette <<Value>> \
     2248        [itcl::code $this AdjustSetting molecule-palette]
     2249
     2250    ::scale $inner.atomscale -width 10 -font "Arial 9" \
     2251        -from 0.1 -to 2.0 -resolution 0.005 -label "Atom Scale" \
     2252        -showvalue true -orient horizontal \
     2253        -command [itcl::code $this EventuallyChangeSettings] \
     2254        -variable [itcl::scope _settings(molecule-atomscale)]
     2255    $inner.atomscale set $_settings(molecule-atomscale)
     2256    Rappture::Tooltip::for $inner.atomscale \
     2257        "Adjust scale of atoms (spheres or balls). 1.0 is the full VDW radius."
     2258
     2259    ::scale $inner.bondscale -width 10 -font "Arial 9" \
     2260        -from 0.1 -to 1.0 -resolution 0.0025 -label "Bond Scale" \
     2261        -showvalue true -orient horizontal \
     2262        -command [itcl::code $this EventuallyChangeSettings] \
     2263        -variable [itcl::scope _settings(molecule-bondscale)]
     2264    Rappture::Tooltip::for $inner.bondscale \
     2265        "Adjust scale of bonds (sticks)."
     2266    $inner.bondscale set $_settings(molecule-bondscale)
     2267
     2268    checkbutton $inner.labels -text "Show labels on atoms" \
     2269        -command [itcl::code $this labels update] \
     2270        -variable [itcl::scope _settings(molecule-labels)] \
     2271        -font "Arial 9"
     2272    Rappture::Tooltip::for $inner.labels \
     2273        "Display atom symbol and serial number."
     2274
     2275    checkbutton $inner.rock -text "Rock molecule back and forth" \
     2276        -variable [itcl::scope _settings(molecule-rock)] \
     2277        -font "Arial 9"
     2278    Rappture::Tooltip::for $inner.rock \
     2279        "Rotate the object back and forth around the y-axis."
     2280
     2281    checkbutton $inner.cell -text "Parallelepiped" \
     2282        -font "Arial 9"
     2283    $inner.cell select
     2284
     2285    label $inner.atomradius_l -text "Radius Scaling Method" \
     2286        -font "Arial 9"
     2287    itk_component add atomradius {
     2288        Rappture::Combobox $inner.atomradius -width 20 -editable no
     2289    }
     2290    $inner.atomradius choices insert end \
     2291        "van_der_waals"  "Van der Waals" \
     2292        "covalent"      "Covalent"      \
     2293        "atomic"        "Atomic"        \
     2294        "none"          "None"         
     2295    bind $inner.atomradius <<Value>> \
     2296        [itcl::code $this AdjustSetting molecule-radius]
     2297    $inner.atomradius value "Van der Waals"
     2298    label $inner.spacer
     2299    blt::table $inner \
     2300        0,0 $inner.molecule -anchor w -pady {1 0} \
     2301        2,0 $inner.wireframe -anchor w -pady {1 0} \
     2302        4,0 $inner.edges -anchor w -pady {1 0} \
     2303        6,0 $inner.atomradius_l -anchor w -pady 2 \
     2304        7,0 $inner.atomradius -anchor w -pady {1 0} \
     2305        9,0 $inner.rep_l -anchor w -pady { 2 0 } \
     2306        10,0 $inner.rep -anchor w  \
     2307        11,0 $inner.atomscale -fill x -pady {3 0} \
     2308        12,0 $inner.bondscale -fill x -pady {1 0} \
     2309        13,0 $inner.palette_l -anchor w -pady 2 \
     2310        14,0 $inner.palette   -fill x   -pady 2 
     2311
     2312    blt::table configure $inner r* -resize none
     2313    blt::table configure $inner r15 -resize expand
     2314}
    20232315
    20242316#
     
    21862478            -wireframe 0
    21872479            -lighting 1
    2188             -radiiscale van_der_waals
    21892480            -visible 1
    21902481        }
     
    21932484        SendCmd "molecule opacity $settings(-opacity) $tag"
    21942485        SendCmd "molecule visible $settings(-visible) $tag"
    2195         SendCmd "molecule rscale $settings(-radiiscale) $tag"
     2486        SendCmd "molecule rscale $_settings(molecule-atomradius) $tag"
     2487        set val [expr $_settings(molecule-atomscale) * 0.1]
     2488        SendCmd "molecule ascale $val $tag"
     2489        set val [expr $_settings(molecule-bondscale) * 0.1]
     2490        SendCmd "molecule bscale $val $tag"
    21962491        set _haveMolecules 1
    21972492    } else {
     
    22092504        SendCmd "polydata add $tag"
    22102505        SendCmd "polydata visible $settings(-visible) $tag"
    2211         set _volume(visible) $settings(-visible)
     2506        set _settings(volume-visible) $settings(-visible)
    22122507        SendCmd "polydata edges $settings(-edges) $tag"
    2213         set _volume(edges) $settings(-edges)
     2508        set _settings(volume-edges) $settings(-edges)
    22142509        SendCmd "polydata color [Color2RGB $settings(-color)] $tag"
    22152510        SendCmd "polydata lighting $settings(-lighting) $tag"
    2216         set _volume(lighting) $settings(-lighting)
     2511        set _settings(volume-lighting) $settings(-lighting)
    22172512        SendCmd "polydata linecolor [Color2RGB $settings(-edgecolor)] $tag"
    22182513        SendCmd "polydata linewidth $settings(-linewidth) $tag"
    22192514        SendCmd "polydata opacity $settings(-opacity) $tag"
    2220         set _volume(opacity) $settings(-opacity)
     2515        set _settings(volume-opacity) $settings(-opacity)
    22212516        SendCmd "polydata wireframe $settings(-wireframe) $tag"
    2222         set _volume(wireframe) $settings(-wireframe)
    2223     }
    2224     set _volume(opacity) [expr $settings(-opacity) * 100.0]
     2517        set _settings(volume-wireframe) $settings(-wireframe)
     2518    }
     2519    set _settings(volume-opacity) [expr $settings(-opacity) * 100.0]
    22252520    SetColormap $dataobj $comp
    22262521}
     
    23892684    }
    23902685}
     2686
Note: See TracChangeset for help on using the changeset viewer.