[2511] | 1 | #!/bin/sh |
---|
| 2 | # -*- mode: Tcl -*- |
---|
| 3 | # ---------------------------------------------------------------------- |
---|
| 4 | # TEST PROGRAM for VtkStreamlinesViewer |
---|
| 5 | # |
---|
| 6 | # This program is a test harness for the VtkVis visualization |
---|
| 7 | # engine. It allows you to monitor the commands being sent back |
---|
| 8 | # and forth between a standard Rappture application and the VtkVis |
---|
| 9 | # server. You can also send your own commands to the server, to |
---|
| 10 | # debug new features. |
---|
| 11 | # |
---|
| 12 | # ====================================================================== |
---|
| 13 | # AUTHOR: Michael McLennan, Purdue University |
---|
[3177] | 14 | # Copyright (c) 2004-2012 HUBzero Foundation, LLC |
---|
[2511] | 15 | # |
---|
| 16 | # See the file "license.terms" for information on usage and |
---|
| 17 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
| 18 | # ====================================================================== |
---|
| 19 | #\ |
---|
| 20 | bindir=`dirname $0` ; \ |
---|
[2789] | 21 | exec $bindir/wish "$0" "$@" |
---|
[2511] | 22 | # ---------------------------------------------------------------------- |
---|
| 23 | # wish executes everything from here on... |
---|
| 24 | |
---|
| 25 | set installdir [file root $argv0] |
---|
| 26 | set libdir [file join $installdir "lib"] |
---|
| 27 | |
---|
| 28 | lappend auto_path $libdir $libdir/vtk $libdir/vtk/tcl |
---|
| 29 | |
---|
| 30 | package require Itcl |
---|
| 31 | package require Rappture |
---|
| 32 | package require RapptureGUI |
---|
| 33 | |
---|
| 34 | option add *comm.font -*-courier-medium-r-normal-*-*-120-* |
---|
| 35 | option add *Menu.tearOff off |
---|
| 36 | |
---|
| 37 | option add *Tooltip.background white |
---|
| 38 | option add *Editor.background white |
---|
| 39 | option add *Gauge.textBackground white |
---|
| 40 | option add *TemperatureGauge.textBackground white |
---|
| 41 | option add *Switch.textBackground white |
---|
| 42 | option add *Progress.barColor #ffffcc |
---|
| 43 | option add *Balloon.titleBackground #6666cc |
---|
| 44 | option add *Balloon.titleForeground white |
---|
| 45 | option add *Balloon*Label.font -*-helvetica-medium-r-normal-*-*-120-* |
---|
| 46 | option add *Balloon*Radiobutton.font -*-helvetica-medium-r-normal-*-*-120-* |
---|
| 47 | option add *Balloon*Checkbutton.font -*-helvetica-medium-r-normal-*-*-120-* |
---|
| 48 | option add *ResultSet.controlbarBackground #6666cc |
---|
| 49 | option add *ResultSet.controlbarForeground white |
---|
| 50 | option add *ResultSet.activeControlBackground #ccccff |
---|
| 51 | option add *ResultSet.activeControlForeground black |
---|
| 52 | option add *Radiodial.length 3i |
---|
| 53 | option add *BugReport*banner*foreground white |
---|
| 54 | option add *BugReport*banner*background #a9a9a9 |
---|
| 55 | option add *BugReport*banner*highlightBackground #a9a9a9 |
---|
| 56 | option add *BugReport*banner*font -*-helvetica-bold-r-normal-*-*-180-* |
---|
| 57 | |
---|
| 58 | # fix the "grab" command to support a stack of grab windows |
---|
| 59 | #Rappture::grab::init |
---|
| 60 | |
---|
| 61 | # ---------------------------------------------------------------------- |
---|
| 62 | # LOAD RESOURCE SETTINGS |
---|
| 63 | # |
---|
| 64 | # Try to load the $SESSIONDIR/resources file, which contains |
---|
| 65 | # middleware settings, such as the application name and the |
---|
| 66 | # filexfer settings. |
---|
| 67 | # ---------------------------------------------------------------------- |
---|
| 68 | Rappture::resources::load |
---|
| 69 | |
---|
| 70 | # ---------------------------------------------------------------------- |
---|
| 71 | # Fake data object for sending VTK data file... |
---|
| 72 | # ---------------------------------------------------------------------- |
---|
| 73 | itcl::class visData { |
---|
| 74 | inherit Rappture::Field |
---|
| 75 | |
---|
| 76 | constructor {args} { |
---|
| 77 | Rappture::Field::constructor [Rappture::library standard] "" |
---|
| 78 | } { |
---|
| 79 | set _data [lindex $args 0] |
---|
| 80 | set _type [lindex $args 1] |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | public method components {args} { |
---|
| 84 | if {[llength $args] == 0} { |
---|
| 85 | return "one" |
---|
| 86 | } |
---|
| 87 | return "" |
---|
| 88 | } |
---|
| 89 | public method blob {args} { |
---|
| 90 | return $_data |
---|
| 91 | } |
---|
| 92 | public method data {args} { |
---|
| 93 | return $_data |
---|
| 94 | } |
---|
| 95 | public method values {args} { |
---|
| 96 | return $_data |
---|
| 97 | } |
---|
| 98 | public method hints {args} { |
---|
| 99 | return "" |
---|
| 100 | } |
---|
| 101 | public method style {args} { |
---|
| 102 | return "" |
---|
| 103 | } |
---|
| 104 | public method type {args} { |
---|
| 105 | return $_type |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | private variable _data "" |
---|
| 109 | private variable _type "" |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | # ---------------------------------------------------------------------- |
---|
| 113 | # USAGE: send_file |
---|
| 114 | # |
---|
| 115 | # Prompts the user for a text file, and then sends the text within |
---|
| 116 | # that file along to the rendering widget. |
---|
| 117 | # ---------------------------------------------------------------------- |
---|
| 118 | proc send_file {} { |
---|
| 119 | global widgets |
---|
| 120 | |
---|
| 121 | set file [tk_getOpenFile -title "Open VTK File"] |
---|
| 122 | if {"" != $file && [catch { |
---|
| 123 | set fid [open $file r] |
---|
[2687] | 124 | fconfigure $fid -translation binary -encoding binary |
---|
[2511] | 125 | set info [read $fid] |
---|
| 126 | close $fid |
---|
| 127 | }] == 0} { |
---|
| 128 | set obj [visData #auto $info "vtk"] |
---|
| 129 | $widgets(vtkviewer) add $obj |
---|
| 130 | } |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | # ---------------------------------------------------------------------- |
---|
| 134 | # USAGE: send_streamlines_file |
---|
| 135 | # |
---|
| 136 | # Prompts the user for a text file, and then sends the text within |
---|
| 137 | # that file along to the rendering widget. |
---|
| 138 | # ---------------------------------------------------------------------- |
---|
| 139 | proc send_streamlines_file {} { |
---|
| 140 | global widgets |
---|
| 141 | |
---|
| 142 | set file [tk_getOpenFile -title "Open VTK File as Streamlines"] |
---|
| 143 | if {"" != $file && [catch { |
---|
| 144 | set fid [open $file r] |
---|
[2687] | 145 | fconfigure $fid -translation binary -encoding binary |
---|
[2511] | 146 | set info [read $fid] |
---|
| 147 | close $fid |
---|
| 148 | }] == 0} { |
---|
| 149 | set obj [visData #auto $info "vtkstreamlines"] |
---|
| 150 | $widgets(vtkviewer) add $obj |
---|
| 151 | } |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | # ---------------------------------------------------------------------- |
---|
| 155 | # USAGE: load_script |
---|
| 156 | # |
---|
| 157 | # Prompts the user for a text file, and then sends the text within |
---|
| 158 | # that file along to the rendering widget. |
---|
| 159 | # ---------------------------------------------------------------------- |
---|
| 160 | proc load_script {} { |
---|
| 161 | global widgets |
---|
| 162 | |
---|
| 163 | set file [tk_getOpenFile -title "Open Command File"] |
---|
| 164 | if {"" != $file && [catch { |
---|
| 165 | set fid [open $file r] |
---|
[2687] | 166 | fconfigure $fid -translation binary -encoding binary |
---|
[2511] | 167 | set info [read $fid] |
---|
| 168 | close $fid |
---|
| 169 | }] == 0} { |
---|
| 170 | |
---|
| 171 | $widgets(command) insert 0 $info |
---|
| 172 | send_command |
---|
| 173 | } |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | # ---------------------------------------------------------------------- |
---|
| 177 | # USAGE: send_command |
---|
| 178 | # |
---|
| 179 | # Invoked automatically whenever the user enters a command and |
---|
| 180 | # presses <Return>. Sends the command along to the rendering |
---|
| 181 | # widget. |
---|
| 182 | # ---------------------------------------------------------------------- |
---|
| 183 | proc send_command {} { |
---|
| 184 | global widgets |
---|
| 185 | global last_command |
---|
| 186 | |
---|
| 187 | set cmd [$widgets(command) get] |
---|
| 188 | |
---|
| 189 | if {[string length $cmd] > 0} { |
---|
| 190 | set last_command $cmd |
---|
| 191 | } else { |
---|
| 192 | set cmd $last_command |
---|
| 193 | } |
---|
| 194 | namespace eval Rappture::VtkStreamlinesViewer [list $widgets(vtkviewer) SendCmd $cmd] |
---|
| 195 | $widgets(command) delete 0 end |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | # ---------------------------------------------------------------------- |
---|
| 199 | # USAGE: reset |
---|
| 200 | # |
---|
| 201 | # Used internally to reset the connection to the rendering server. |
---|
| 202 | # Discards all data and resets the widget connection to the server. |
---|
| 203 | # ---------------------------------------------------------------------- |
---|
| 204 | proc reset {} { |
---|
| 205 | global widgets |
---|
| 206 | $widgets(vtkviewer) delete |
---|
| 207 | $widgets(vtkviewer) disconnect |
---|
| 208 | $widgets(comm) configure -state normal |
---|
| 209 | $widgets(comm) delete 1.0 end |
---|
| 210 | $widgets(comm) configure -state disabled |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | # ---------------------------------------------------------------------- |
---|
| 214 | # USAGE: show_comm <channel> <data> |
---|
| 215 | # |
---|
| 216 | # Invoked automatically whenever there is communication between |
---|
| 217 | # the rendering widget and the server. Eavesdrops on the communication |
---|
| 218 | # and posts the commands in a text viewer. |
---|
| 219 | # ---------------------------------------------------------------------- |
---|
| 220 | proc show_comm {channel {data ""}} { |
---|
| 221 | global widgets |
---|
| 222 | |
---|
| 223 | $widgets(comm) configure -state normal |
---|
| 224 | switch -- $channel { |
---|
| 225 | closed { |
---|
| 226 | $widgets(comm) insert end "--CLOSED--\n" error |
---|
| 227 | } |
---|
| 228 | <<line { |
---|
| 229 | $widgets(comm) insert end $data incoming "\n" incoming |
---|
| 230 | images_refresh |
---|
| 231 | } |
---|
| 232 | >>line { |
---|
| 233 | $widgets(comm) insert end $data outgoing "\n" outgoing |
---|
| 234 | } |
---|
| 235 | error { |
---|
| 236 | $widgets(comm) insert end $data error "\n" error |
---|
| 237 | } |
---|
| 238 | default { |
---|
| 239 | $widgets(comm) insert end "$data\n" |
---|
| 240 | } |
---|
| 241 | } |
---|
| 242 | $widgets(comm) configure -state disabled |
---|
| 243 | $widgets(comm) see end |
---|
| 244 | } |
---|
| 245 | |
---|
| 246 | # ---------------------------------------------------------------------- |
---|
| 247 | # USAGE: activate_flow |
---|
| 248 | # |
---|
| 249 | # ---------------------------------------------------------------------- |
---|
| 250 | proc activate_flow {} { |
---|
| 251 | global widgets |
---|
| 252 | # global img_storage_dir |
---|
| 253 | # "flow capture 117 $img_storage_dir" |
---|
| 254 | |
---|
| 255 | set info {flow vectorid 0 |
---|
| 256 | flow particle visible on |
---|
| 257 | flow lic on |
---|
| 258 | flow capture 100} |
---|
| 259 | |
---|
| 260 | $widgets(command) insert 0 $info |
---|
| 261 | send_command |
---|
| 262 | |
---|
| 263 | } |
---|
| 264 | |
---|
| 265 | # ---------------------------------------------------------------------- |
---|
| 266 | # TOPLEVEL FOR IMAGES |
---|
| 267 | # ---------------------------------------------------------------------- |
---|
| 268 | # USAGE: images_save |
---|
| 269 | # |
---|
| 270 | # Invoked when the user presses the "Save As..." button on the |
---|
| 271 | # images panel. Saves the current image in a file, which can be |
---|
| 272 | # examined by some external program. |
---|
| 273 | # ---------------------------------------------------------------------- |
---|
| 274 | proc images_save {} { |
---|
| 275 | global widgets images |
---|
| 276 | |
---|
| 277 | set imh [$widgets(vtkviewer) get -image $images(which)] |
---|
| 278 | |
---|
| 279 | set file [tk_getSaveFile -title "Save Image File" \ |
---|
| 280 | -defaultextension .jpg -filetypes {{{JPEG files} .jpg} {{All Files} *}}] |
---|
| 281 | |
---|
| 282 | if {"" != $file} { |
---|
| 283 | set cmds { |
---|
| 284 | $imh write $file -format jpeg |
---|
| 285 | } |
---|
| 286 | if {[catch $cmds err]} { |
---|
| 287 | tk_messageBox -icon error -message "Oops! Save failed:\n$err" |
---|
| 288 | } |
---|
| 289 | } |
---|
| 290 | } |
---|
| 291 | |
---|
| 292 | # ---------------------------------------------------------------------- |
---|
| 293 | # USAGE: images_refresh |
---|
| 294 | # |
---|
| 295 | # Invoked automatically whenever there is a change in the view/legend |
---|
| 296 | # controls on the images panel. Updates the image being shown based |
---|
| 297 | # on the current selection. |
---|
| 298 | # ---------------------------------------------------------------------- |
---|
| 299 | proc images_refresh {} { |
---|
| 300 | global widgets images |
---|
| 301 | set c $widgets(viewer) |
---|
| 302 | |
---|
| 303 | set w [winfo width $c] |
---|
| 304 | set h [winfo height $c] |
---|
| 305 | |
---|
| 306 | set imh [$widgets(vtkviewer) get -image $images(which)] |
---|
| 307 | set iw [image width $imh] |
---|
| 308 | set ih [image height $imh] |
---|
| 309 | |
---|
| 310 | $c coords image [expr {$w/2}] [expr {$h/2}] |
---|
| 311 | $c itemconfigure image -image $imh |
---|
| 312 | $c coords outline [expr {$w/2-$iw/2}] [expr {$h/2-$ih/2}] \ |
---|
| 313 | [expr {$w/2+$iw/2}] [expr {$h/2+$ih/2}] |
---|
| 314 | } |
---|
| 315 | |
---|
| 316 | toplevel .images |
---|
| 317 | wm title .images "Vtkviewer: Images" |
---|
| 318 | wm withdraw .images |
---|
| 319 | wm protocol .images WM_DELETE_WINDOW {wm withdraw .images} |
---|
| 320 | |
---|
| 321 | frame .images.cntls |
---|
| 322 | pack .images.cntls -side bottom -fill x |
---|
| 323 | button .images.cntls.save -text "Save As..." -command images_save |
---|
| 324 | pack .images.cntls.save -side right -padx 4 |
---|
| 325 | radiobutton .images.cntls.view -text "3D View" -variable images(which) \ |
---|
| 326 | -value "view" -command images_refresh |
---|
| 327 | pack .images.cntls.view -side top -anchor w |
---|
| 328 | radiobutton .images.cntls.legend -text "Legend" -variable images(which) \ |
---|
| 329 | -value "legend" -command images_refresh |
---|
| 330 | pack .images.cntls.legend -side top -anchor w |
---|
| 331 | set images(which) "view" |
---|
| 332 | |
---|
| 333 | canvas .images.viewer -background black -width 500 -height 500 |
---|
| 334 | pack .images.viewer -expand yes -fill both |
---|
| 335 | bind .images.viewer <Configure> images_refresh |
---|
| 336 | set widgets(viewer) .images.viewer |
---|
| 337 | |
---|
| 338 | $widgets(viewer) create image 0 0 -anchor c \ |
---|
| 339 | -image [image create photo] -tags image |
---|
| 340 | $widgets(viewer) create rectangle 0 0 1 1 -width 2 -outline red -fill "" \ |
---|
| 341 | -tags outline |
---|
| 342 | |
---|
| 343 | |
---|
| 344 | # ---------------------------------------------------------------------- |
---|
| 345 | # MAIN WINDOW |
---|
| 346 | # ---------------------------------------------------------------------- |
---|
| 347 | menu .mbar |
---|
| 348 | menu .mbar.file |
---|
| 349 | .mbar.file add command -label "Send VTK File..." -underline 0 -command send_file |
---|
| 350 | .mbar.file add command -label "Send VTK File as Streamlines..." -underline 0 -command send_streamlines_file |
---|
| 351 | .mbar.file add command -label "Load script..." -underline 0 -command load_script |
---|
| 352 | .mbar.file add command -label "Reset" -underline 0 -command reset |
---|
| 353 | .mbar.file add separator |
---|
| 354 | .mbar.file add command -label "Exit" -underline 1 -command exit |
---|
| 355 | .mbar add cascade -label "File" -underline 0 -menu .mbar.file |
---|
| 356 | |
---|
| 357 | menu .mbar.view |
---|
| 358 | .mbar.view add command -label "Images..." -underline 0 \ |
---|
| 359 | -command {wm deiconify .images} |
---|
| 360 | .mbar add cascade -label "View" -underline 0 -menu .mbar.view |
---|
| 361 | |
---|
| 362 | . configure -menu .mbar |
---|
| 363 | |
---|
| 364 | |
---|
| 365 | Rappture::Panes .main -sashwidth 4 -sashrelief raised -sashpadding 4 \ |
---|
| 366 | -width 6i -height 4i |
---|
| 367 | pack .main -expand yes -fill both |
---|
| 368 | |
---|
| 369 | set f [.main pane 0] |
---|
| 370 | set servers [Rappture::VisViewer::GetServerList "vtkvis"] |
---|
| 371 | Rappture::VtkStreamlinesViewer $f.viewer $servers |
---|
| 372 | pack $f.viewer -expand yes -fill both |
---|
| 373 | set widgets(vtkviewer) $f.viewer |
---|
| 374 | |
---|
| 375 | $f.viewer configure \ |
---|
| 376 | -sendcommand show_comm \ |
---|
| 377 | -receivecommand show_comm |
---|
| 378 | |
---|
| 379 | set f [.main insert end -fraction 0.5] |
---|
| 380 | frame $f.send |
---|
| 381 | pack $f.send -side bottom -fill x |
---|
| 382 | label $f.send.l -text "Send:" |
---|
| 383 | pack $f.send.l -side left |
---|
| 384 | set widgets(command) [entry $f.send.e] |
---|
| 385 | pack $f.send.e -side left -expand yes -fill x |
---|
| 386 | bind $f.send.e <KeyPress-Return> send_command |
---|
| 387 | |
---|
| 388 | scrollbar $f.sb -orient vertical -command "$f.comm yview" |
---|
| 389 | pack $f.sb -side right -fill y |
---|
| 390 | text $f.comm -wrap char -yscrollcommand "$f.sb set" |
---|
| 391 | pack $f.comm -expand yes -fill both |
---|
| 392 | set widgets(comm) $f.comm |
---|
| 393 | |
---|
| 394 | $widgets(comm) tag configure error -foreground red \ |
---|
| 395 | -font -*-courier-medium-o-normal-*-*-120-* |
---|
| 396 | $widgets(comm) tag configure incoming -foreground blue |
---|