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