1 | #!/bin/sh |
---|
2 | # -*- mode: Tcl -*- |
---|
3 | # ---------------------------------------------------------------------- |
---|
4 | # TEST PROGRAM for VtkViewer |
---|
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 |
---|
14 | # Copyright (c) 2004-2012 HUBzero Foundation, LLC |
---|
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` ; \ |
---|
21 | exec $bindir/wish "$0" "$@" |
---|
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::Drawing |
---|
75 | |
---|
76 | constructor {args} { |
---|
77 | Rappture::Drawing::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 data {args} { |
---|
90 | return $_data |
---|
91 | } |
---|
92 | public method vtkdata {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 type {args} { |
---|
102 | return $_type |
---|
103 | } |
---|
104 | public method shape {args} { |
---|
105 | return "sphere" |
---|
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 as PolyData"] |
---|
122 | if {"" != $file && [catch { |
---|
123 | set fid [open $file r] |
---|
124 | fconfigure $fid -translation binary -encoding binary |
---|
125 | set info [read $fid] |
---|
126 | close $fid |
---|
127 | }] == 0} { |
---|
128 | set obj [visData #auto $info "polydata"] |
---|
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] |
---|
145 | fconfigure $fid -translation binary -encoding binary |
---|
146 | set info [read $fid] |
---|
147 | close $fid |
---|
148 | }] == 0} { |
---|
149 | set obj [visData #auto $info "streamlines"] |
---|
150 | $widgets(vtkviewer) add $obj |
---|
151 | } |
---|
152 | } |
---|
153 | |
---|
154 | # ---------------------------------------------------------------------- |
---|
155 | # USAGE: send_glyphs_file |
---|
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 send_glyphs_file {} { |
---|
161 | global widgets |
---|
162 | |
---|
163 | set file [tk_getOpenFile -title "Open VTK File as Glyphs"] |
---|
164 | if {"" != $file && [catch { |
---|
165 | set fid [open $file r] |
---|
166 | fconfigure $fid -translation binary |
---|
167 | set info [read $fid] |
---|
168 | close $fid |
---|
169 | }] == 0} { |
---|
170 | set obj [visData #auto $info "glyphs"] |
---|
171 | $widgets(vtkviewer) add $obj |
---|
172 | } |
---|
173 | } |
---|
174 | |
---|
175 | # ---------------------------------------------------------------------- |
---|
176 | # USAGE: send_molecule_file |
---|
177 | # |
---|
178 | # Prompts the user for a text file, and then sends the text within |
---|
179 | # that file along to the rendering widget. |
---|
180 | # ---------------------------------------------------------------------- |
---|
181 | proc send_molecule_file {} { |
---|
182 | global widgets |
---|
183 | |
---|
184 | set file [tk_getOpenFile -title "Open VTK File as Molecule"] |
---|
185 | if {"" != $file && [catch { |
---|
186 | set fid [open $file r] |
---|
187 | fconfigure $fid -translation binary |
---|
188 | set info [read $fid] |
---|
189 | close $fid |
---|
190 | }] == 0} { |
---|
191 | set obj [visData #auto $info "molecule"] |
---|
192 | $widgets(vtkviewer) add $obj |
---|
193 | } |
---|
194 | } |
---|
195 | |
---|
196 | # ---------------------------------------------------------------------- |
---|
197 | # USAGE: load_script |
---|
198 | # |
---|
199 | # Prompts the user for a text file, and then sends the text within |
---|
200 | # that file along to the rendering widget. |
---|
201 | # ---------------------------------------------------------------------- |
---|
202 | proc load_script {} { |
---|
203 | global widgets |
---|
204 | |
---|
205 | set file [tk_getOpenFile -title "Open Command File"] |
---|
206 | if {"" != $file && [catch { |
---|
207 | set fid [open $file r] |
---|
208 | fconfigure $fid -translation binary |
---|
209 | set info [read $fid] |
---|
210 | close $fid |
---|
211 | }] == 0} { |
---|
212 | |
---|
213 | $widgets(command) insert 0 $info |
---|
214 | send_command |
---|
215 | } |
---|
216 | } |
---|
217 | |
---|
218 | # ---------------------------------------------------------------------- |
---|
219 | # USAGE: send_command |
---|
220 | # |
---|
221 | # Invoked automatically whenever the user enters a command and |
---|
222 | # presses <Return>. Sends the command along to the rendering |
---|
223 | # widget. |
---|
224 | # ---------------------------------------------------------------------- |
---|
225 | proc send_command {} { |
---|
226 | global widgets |
---|
227 | global last_command |
---|
228 | |
---|
229 | set cmd [$widgets(command) get] |
---|
230 | |
---|
231 | if {[string length $cmd] > 0} { |
---|
232 | set last_command $cmd |
---|
233 | } else { |
---|
234 | set cmd $last_command |
---|
235 | } |
---|
236 | namespace eval Rappture::VtkViewer [list $widgets(vtkviewer) SendCmd $cmd] |
---|
237 | $widgets(command) delete 0 end |
---|
238 | } |
---|
239 | |
---|
240 | # ---------------------------------------------------------------------- |
---|
241 | # USAGE: reset |
---|
242 | # |
---|
243 | # Used internally to reset the connection to the rendering server. |
---|
244 | # Discards all data and resets the widget connection to the server. |
---|
245 | # ---------------------------------------------------------------------- |
---|
246 | proc reset {} { |
---|
247 | global widgets |
---|
248 | $widgets(vtkviewer) delete |
---|
249 | $widgets(vtkviewer) disconnect |
---|
250 | $widgets(comm) configure -state normal |
---|
251 | $widgets(comm) delete 1.0 end |
---|
252 | $widgets(comm) configure -state disabled |
---|
253 | } |
---|
254 | |
---|
255 | # ---------------------------------------------------------------------- |
---|
256 | # USAGE: show_comm <channel> <data> |
---|
257 | # |
---|
258 | # Invoked automatically whenever there is communication between |
---|
259 | # the rendering widget and the server. Eavesdrops on the communication |
---|
260 | # and posts the commands in a text viewer. |
---|
261 | # ---------------------------------------------------------------------- |
---|
262 | proc show_comm {channel {data ""}} { |
---|
263 | global widgets |
---|
264 | |
---|
265 | $widgets(comm) configure -state normal |
---|
266 | switch -- $channel { |
---|
267 | closed { |
---|
268 | $widgets(comm) insert end "--CLOSED--\n" error |
---|
269 | } |
---|
270 | <<line { |
---|
271 | $widgets(comm) insert end $data incoming "\n" incoming |
---|
272 | images_refresh |
---|
273 | } |
---|
274 | >>line { |
---|
275 | $widgets(comm) insert end $data outgoing "\n" outgoing |
---|
276 | } |
---|
277 | error { |
---|
278 | $widgets(comm) insert end $data error "\n" error |
---|
279 | } |
---|
280 | default { |
---|
281 | $widgets(comm) insert end "$data\n" |
---|
282 | } |
---|
283 | } |
---|
284 | $widgets(comm) configure -state disabled |
---|
285 | $widgets(comm) see end |
---|
286 | } |
---|
287 | |
---|
288 | # ---------------------------------------------------------------------- |
---|
289 | # USAGE: activate_flow |
---|
290 | # |
---|
291 | # ---------------------------------------------------------------------- |
---|
292 | proc activate_flow {} { |
---|
293 | global widgets |
---|
294 | # global img_storage_dir |
---|
295 | # "flow capture 117 $img_storage_dir" |
---|
296 | |
---|
297 | set info {flow vectorid 0 |
---|
298 | flow particle visible on |
---|
299 | flow lic on |
---|
300 | flow capture 100} |
---|
301 | |
---|
302 | $widgets(command) insert 0 $info |
---|
303 | send_command |
---|
304 | |
---|
305 | } |
---|
306 | |
---|
307 | # ---------------------------------------------------------------------- |
---|
308 | # TOPLEVEL FOR IMAGES |
---|
309 | # ---------------------------------------------------------------------- |
---|
310 | # USAGE: images_save |
---|
311 | # |
---|
312 | # Invoked when the user presses the "Save As..." button on the |
---|
313 | # images panel. Saves the current image in a file, which can be |
---|
314 | # examined by some external program. |
---|
315 | # ---------------------------------------------------------------------- |
---|
316 | proc images_save {} { |
---|
317 | global widgets images |
---|
318 | |
---|
319 | set imh [$widgets(vtkviewer) get -image $images(which)] |
---|
320 | |
---|
321 | set file [tk_getSaveFile -title "Save Image File" \ |
---|
322 | -defaultextension .jpg -filetypes {{{JPEG files} .jpg} {{All Files} *}}] |
---|
323 | |
---|
324 | if {"" != $file} { |
---|
325 | set cmds { |
---|
326 | $imh write $file -format jpeg |
---|
327 | } |
---|
328 | if {[catch $cmds err]} { |
---|
329 | tk_messageBox -icon error -message "Oops! Save failed:\n$err" |
---|
330 | } |
---|
331 | } |
---|
332 | } |
---|
333 | |
---|
334 | # ---------------------------------------------------------------------- |
---|
335 | # USAGE: images_refresh |
---|
336 | # |
---|
337 | # Invoked automatically whenever there is a change in the view/legend |
---|
338 | # controls on the images panel. Updates the image being shown based |
---|
339 | # on the current selection. |
---|
340 | # ---------------------------------------------------------------------- |
---|
341 | proc images_refresh {} { |
---|
342 | global widgets images |
---|
343 | set c $widgets(viewer) |
---|
344 | |
---|
345 | set w [winfo width $c] |
---|
346 | set h [winfo height $c] |
---|
347 | |
---|
348 | set imh [$widgets(vtkviewer) get -image $images(which)] |
---|
349 | set iw [image width $imh] |
---|
350 | set ih [image height $imh] |
---|
351 | |
---|
352 | $c coords image [expr {$w/2}] [expr {$h/2}] |
---|
353 | $c itemconfigure image -image $imh |
---|
354 | $c coords outline [expr {$w/2-$iw/2}] [expr {$h/2-$ih/2}] \ |
---|
355 | [expr {$w/2+$iw/2}] [expr {$h/2+$ih/2}] |
---|
356 | } |
---|
357 | |
---|
358 | toplevel .images |
---|
359 | wm title .images "Vtkviewer: Images" |
---|
360 | wm withdraw .images |
---|
361 | wm protocol .images WM_DELETE_WINDOW {wm withdraw .images} |
---|
362 | |
---|
363 | frame .images.cntls |
---|
364 | pack .images.cntls -side bottom -fill x |
---|
365 | button .images.cntls.save -text "Save As..." -command images_save |
---|
366 | pack .images.cntls.save -side right -padx 4 |
---|
367 | radiobutton .images.cntls.view -text "3D View" -variable images(which) \ |
---|
368 | -value "view" -command images_refresh |
---|
369 | pack .images.cntls.view -side top -anchor w |
---|
370 | radiobutton .images.cntls.legend -text "Legend" -variable images(which) \ |
---|
371 | -value "legend" -command images_refresh |
---|
372 | pack .images.cntls.legend -side top -anchor w |
---|
373 | set images(which) "view" |
---|
374 | |
---|
375 | canvas .images.viewer -background black -width 500 -height 500 |
---|
376 | pack .images.viewer -expand yes -fill both |
---|
377 | bind .images.viewer <Configure> images_refresh |
---|
378 | set widgets(viewer) .images.viewer |
---|
379 | |
---|
380 | $widgets(viewer) create image 0 0 -anchor c \ |
---|
381 | -image [image create photo] -tags image |
---|
382 | $widgets(viewer) create rectangle 0 0 1 1 -width 2 -outline red -fill "" \ |
---|
383 | -tags outline |
---|
384 | |
---|
385 | |
---|
386 | # ---------------------------------------------------------------------- |
---|
387 | # MAIN WINDOW |
---|
388 | # ---------------------------------------------------------------------- |
---|
389 | menu .mbar |
---|
390 | menu .mbar.file |
---|
391 | .mbar.file add command -label "Send VTK File..." -underline 0 -command send_file |
---|
392 | .mbar.file add command -label "Send VTK File as Streamlines..." -underline 0 -command send_streamlines_file |
---|
393 | .mbar.file add command -label "Send VTK File as Glyphs..." -underline 0 -command send_glyphs_file |
---|
394 | .mbar.file add command -label "Send VTK File as Molecule..." -underline 0 -command send_molecule_file |
---|
395 | .mbar.file add command -label "Load script..." -underline 0 -command load_script |
---|
396 | .mbar.file add command -label "Reset" -underline 0 -command reset |
---|
397 | .mbar.file add separator |
---|
398 | .mbar.file add command -label "Exit" -underline 1 -command exit |
---|
399 | .mbar add cascade -label "File" -underline 0 -menu .mbar.file |
---|
400 | |
---|
401 | menu .mbar.view |
---|
402 | .mbar.view add command -label "Images..." -underline 0 \ |
---|
403 | -command {wm deiconify .images} |
---|
404 | .mbar add cascade -label "View" -underline 0 -menu .mbar.view |
---|
405 | |
---|
406 | . configure -menu .mbar |
---|
407 | |
---|
408 | |
---|
409 | Rappture::Panes .main -sashwidth 4 -sashrelief raised -sashpadding 4 \ |
---|
410 | -width 6i -height 4i |
---|
411 | pack .main -expand yes -fill both |
---|
412 | |
---|
413 | set f [.main pane 0] |
---|
414 | set servers [Rappture::VisViewer::GetServerList "vtkvis"] |
---|
415 | Rappture::VtkViewer $f.viewer $servers |
---|
416 | pack $f.viewer -expand yes -fill both |
---|
417 | set widgets(vtkviewer) $f.viewer |
---|
418 | |
---|
419 | $f.viewer configure \ |
---|
420 | -sendcommand show_comm \ |
---|
421 | -receivecommand show_comm |
---|
422 | |
---|
423 | set f [.main insert end -fraction 0.5] |
---|
424 | frame $f.send |
---|
425 | pack $f.send -side bottom -fill x |
---|
426 | label $f.send.l -text "Send:" |
---|
427 | pack $f.send.l -side left |
---|
428 | set widgets(command) [entry $f.send.e] |
---|
429 | pack $f.send.e -side left -expand yes -fill x |
---|
430 | bind $f.send.e <KeyPress-Return> send_command |
---|
431 | |
---|
432 | scrollbar $f.sb -orient vertical -command "$f.comm yview" |
---|
433 | pack $f.sb -side right -fill y |
---|
434 | text $f.comm -wrap char -yscrollcommand "$f.sb set" |
---|
435 | pack $f.comm -expand yes -fill both |
---|
436 | set widgets(comm) $f.comm |
---|
437 | |
---|
438 | $widgets(comm) tag configure error -foreground red \ |
---|
439 | -font -*-courier-medium-o-normal-*-*-120-* |
---|
440 | $widgets(comm) tag configure incoming -foreground blue |
---|