- Timestamp:
- Jul 27, 2012 11:38:19 AM (12 years ago)
- Location:
- trunk/gui/scripts
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/vtkviewer.tcl
r3118 r3121 69 69 protected method DoResize {} 70 70 protected method DoRotate {} 71 private method DoUpdate {} 71 72 protected method AdjustSetting {what {value ""}} 72 73 protected method FixSettings { args } … … 88 89 private method BuildDownloadPopup { widget command } 89 90 private method BuildVolumeTab {} 91 private method BuildMoleculeTab {} 90 92 private method ConvertToVtkData { dataobj comp } 91 93 private method DrawLegend {} … … 93 95 private method EventuallyResize { w h } 94 96 private method EventuallyRotate { q } 97 private method EventuallyChangeSettings { args } 95 98 private method GetImage { args } 96 99 private method GetVtkData { args } … … 127 130 private variable _style; # Array of current component styles. 128 131 private variable _initialStyle; # Array of initial component styles. 129 private variable _volume130 132 private variable _axis 131 133 private variable _reset 1 ;# indicates if camera needs to be reset … … 145 147 private variable _resizePending 0 146 148 private variable _rotatePending 0 149 private variable _updatePending 0; 147 150 private variable _outline 148 151 } … … 167 170 $_dispatcher register !resize 168 171 $_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" 169 176 170 177 # Rotate event … … 223 230 labels 1 224 231 }] 225 array set _volume [subst {226 edges 0227 lighting 1228 opacity 40229 visible 1230 wireframe 0231 palette rainbow232 }]233 232 array set _settings [subst { 234 233 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 235 250 }] 236 251 … … 304 319 puts stderr "errs=$errs" 305 320 } 321 puts stderr "BuildMoleculeTab" 322 if { [catch { BuildMoleculeTab } errs ] != 0 } { 323 global errorInfo 324 puts stderr "errs=$errs\nerrorInfo=$errorInfo" 325 } 306 326 BuildAxisTab 307 BuildCutawayTab327 #BuildCutawayTab 308 328 BuildCameraTab 309 329 … … 448 468 } 449 469 470 itcl::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 484 itcl::body Rappture::VtkViewer::EventuallyChangeSettings { args } { 485 if { !$_updatePending } { 486 $_dispatcher event -after 250 !update 487 set _updatePending 1 488 } 489 } 490 450 491 # ---------------------------------------------------------------------- 451 492 # USAGE: add <dataobj> ?<settings>? … … 876 917 SendCmd "camera mode persp" 877 918 } 919 878 920 DoRotate 879 921 PanCamera … … 935 977 } 936 978 } 979 } 980 if { $_haveMolecules } { 981 FixSettings molecule-radius molecule-representation 937 982 } 938 983 SendCmd "dataset maprange visible" … … 1178 1223 switch -- $what { 1179 1224 "volume-opacity" { 1180 set val $_ volume(opacity)1225 set val $_settings(volume-opacity) 1181 1226 set sval [expr { 0.01 * double($val) }] 1182 1227 foreach dataset [CurrentDatasets -visible $_first] { 1183 1228 foreach { dataobj comp } [split $dataset -] break 1184 1229 set type [$dataobj type $comp] 1185 if { $type != "" && $type != "glyphs" } {1230 if { $type == "polydata" } { 1186 1231 SendCmd "$type opacity $sval $dataset" 1187 1232 } … … 1189 1234 } 1190 1235 "volume-wireframe" { 1191 set bool $_ volume(wireframe)1236 set bool $_settings(volume-wireframe) 1192 1237 foreach dataset [CurrentDatasets -visible $_first] { 1193 1238 foreach { dataobj comp } [split $dataset -] break 1194 1239 set type [$dataobj type $comp] 1195 if { $type != "" } {1240 if { $type == "polydata" } { 1196 1241 SendCmd "$type wireframe $bool $dataset" 1197 1242 } … … 1199 1244 } 1200 1245 "volume-visible" { 1201 set bool $_ volume(visible)1246 set bool $_settings(volume-visible) 1202 1247 foreach dataset [CurrentDatasets -visible $_first] { 1203 1248 foreach { dataobj comp } [split $dataset -] break 1204 1249 set type [$dataobj type $comp] 1205 if { $type != "" } {1250 if { $type == "polydata" } { 1206 1251 SendCmd "$type visible $bool $dataset" 1207 1252 } … … 1209 1254 } 1210 1255 "volume-lighting" { 1211 set bool $_ volume(lighting)1256 set bool $_settings(volume-lighting) 1212 1257 foreach dataset [CurrentDatasets -visible $_first] { 1213 1258 foreach { dataobj comp } [split $dataset -] break 1214 1259 set type [$dataobj type $comp] 1215 if { $type != "" } {1260 if { $type == "polydata" } { 1216 1261 SendCmd "$type lighting $bool $dataset" 1217 1262 } … … 1219 1264 } 1220 1265 "volume-edges" { 1221 set bool $_ volume(edges)1266 set bool $_settings(volume-edges) 1222 1267 foreach dataset [CurrentDatasets -visible $_first] { 1223 1268 foreach { dataobj comp } [split $dataset -] break 1224 1269 set type [$dataobj type $comp] 1225 if { $type != "" } {1270 if { $type == "polydata" } { 1226 1271 SendCmd "$type edges $bool $dataset" 1227 1272 } … … 1233 1278 foreach dataset [CurrentDatasets -visible $_first] { 1234 1279 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 } 1236 1284 } 1237 1285 set _legendPending 1 1238 1286 } 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 } 1239 1388 "axis-visible" { 1240 1389 set bool $_axis(visible) … … 1370 1519 } 1371 1520 "molecule" { 1372 #SendCmd "molecule colormap $name $tag"1521 SendCmd "molecule colormap $name $tag" 1373 1522 } 1374 1523 } … … 1709 1858 checkbutton $inner.volume \ 1710 1859 -text "Show Volume" \ 1711 -variable [itcl::scope _ volume(visible)] \1860 -variable [itcl::scope _settings(volume-visible)] \ 1712 1861 -command [itcl::code $this AdjustSetting volume-visible] \ 1713 1862 -font "Arial 9" … … 1715 1864 checkbutton $inner.wireframe \ 1716 1865 -text "Show Wireframe" \ 1717 -variable [itcl::scope _ volume(wireframe)] \1866 -variable [itcl::scope _settings(volume-wireframe)] \ 1718 1867 -command [itcl::code $this AdjustSetting volume-wireframe] \ 1719 1868 -font "Arial 9" … … 1721 1870 checkbutton $inner.lighting \ 1722 1871 -text "Enable Lighting" \ 1723 -variable [itcl::scope _ volume(lighting)] \1872 -variable [itcl::scope _settings(volume-lighting)] \ 1724 1873 -command [itcl::code $this AdjustSetting volume-lighting] \ 1725 1874 -font "Arial 9" … … 1727 1876 checkbutton $inner.edges \ 1728 1877 -text "Show Edges" \ 1729 -variable [itcl::scope _ volume(edges)] \1878 -variable [itcl::scope _settings(volume-edges)] \ 1730 1879 -command [itcl::code $this AdjustSetting volume-edges] \ 1731 1880 -font "Arial 9" 1732 1881 1733 1882 label $inner.palette_l -text "Palette" -font "Arial 9" 1734 itk_component add palette {1883 itk_component add volumepalette { 1735 1884 Rappture::Combobox $inner.palette -width 10 -editable no 1736 1885 } … … 1753 1902 "orange-to-blue" "orange-to-blue" 1754 1903 1755 $itk_component( palette) value "BCGYR"1904 $itk_component(volumepalette) value "BCGYR" 1756 1905 bind $inner.palette <<Value>> \ 1757 1906 [itcl::code $this AdjustSetting volume-palette] … … 1759 1908 label $inner.opacity_l -text "Opacity" -font "Arial 9" 1760 1909 ::scale $inner.opacity -from 0 -to 100 -orient horizontal \ 1761 -variable [itcl::scope _ volume(opacity)] \1910 -variable [itcl::scope _settings(volume-opacity)] \ 1762 1911 -width 10 \ 1763 1912 -showvalue off \ … … 2020 2169 } 2021 2170 2022 2171 itcl::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 } 2023 2315 2024 2316 # … … 2186 2478 -wireframe 0 2187 2479 -lighting 1 2188 -radiiscale van_der_waals2189 2480 -visible 1 2190 2481 } … … 2193 2484 SendCmd "molecule opacity $settings(-opacity) $tag" 2194 2485 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" 2196 2491 set _haveMolecules 1 2197 2492 } else { … … 2209 2504 SendCmd "polydata add $tag" 2210 2505 SendCmd "polydata visible $settings(-visible) $tag" 2211 set _ volume(visible) $settings(-visible)2506 set _settings(volume-visible) $settings(-visible) 2212 2507 SendCmd "polydata edges $settings(-edges) $tag" 2213 set _ volume(edges) $settings(-edges)2508 set _settings(volume-edges) $settings(-edges) 2214 2509 SendCmd "polydata color [Color2RGB $settings(-color)] $tag" 2215 2510 SendCmd "polydata lighting $settings(-lighting) $tag" 2216 set _ volume(lighting) $settings(-lighting)2511 set _settings(volume-lighting) $settings(-lighting) 2217 2512 SendCmd "polydata linecolor [Color2RGB $settings(-edgecolor)] $tag" 2218 2513 SendCmd "polydata linewidth $settings(-linewidth) $tag" 2219 2514 SendCmd "polydata opacity $settings(-opacity) $tag" 2220 set _ volume(opacity) $settings(-opacity)2515 set _settings(volume-opacity) $settings(-opacity) 2221 2516 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] 2225 2520 SetColormap $dataobj $comp 2226 2521 } … … 2389 2684 } 2390 2685 } 2686
Note: See TracChangeset
for help on using the changeset viewer.