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