1 | #!/bin/sh |
---|
2 | # -*- mode: Tcl -*- |
---|
3 | # ---------------------------------------------------------------------- |
---|
4 | # TEST PROGRAM for VtkGlyphViewer |
---|
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 | . $bindir/rappture.env ; \ |
---|
22 | exec $bindir/wish "$0" "$@" |
---|
23 | # ---------------------------------------------------------------------- |
---|
24 | # wish executes everything from here on... |
---|
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 VTK data file... |
---|
67 | # ---------------------------------------------------------------------- |
---|
68 | itcl::class visData { |
---|
69 | inherit Rappture::Field |
---|
70 | |
---|
71 | constructor {args} { |
---|
72 | Rappture::Field::constructor [Rappture::library standard] "" |
---|
73 | } { |
---|
74 | set _data [lindex $args 0] |
---|
75 | GetTypeAndSize $_cname |
---|
76 | GetAssociation $_cname |
---|
77 | ReadVtkDataSet $_cname $_data |
---|
78 | set _type [lindex $args 1] |
---|
79 | } |
---|
80 | |
---|
81 | public method components {args} { |
---|
82 | Rappture::getopts args params { |
---|
83 | flag what -name default |
---|
84 | flag what -dimensions |
---|
85 | flag what -style |
---|
86 | flag what -particles |
---|
87 | flag what -flow |
---|
88 | flag what -box |
---|
89 | } |
---|
90 | if { $params(what) == "-dimensions" } { |
---|
91 | return "${_dim}D" |
---|
92 | } |
---|
93 | if {[llength $args] == 0} { |
---|
94 | return $_cname |
---|
95 | } |
---|
96 | return "" |
---|
97 | } |
---|
98 | public method isvalid {} { |
---|
99 | return 1 |
---|
100 | } |
---|
101 | public method data {args} { |
---|
102 | return $_data |
---|
103 | } |
---|
104 | public method vtkdata {args} { |
---|
105 | return $_data |
---|
106 | } |
---|
107 | public method values {args} { |
---|
108 | return $_data |
---|
109 | } |
---|
110 | public method style {args} { |
---|
111 | return "" |
---|
112 | } |
---|
113 | public method hints {args} { |
---|
114 | return "" |
---|
115 | } |
---|
116 | public method type {args} { |
---|
117 | return $_type |
---|
118 | } |
---|
119 | public method viewer {args} { |
---|
120 | return "glyphs" |
---|
121 | } |
---|
122 | public method shape {args} { |
---|
123 | return "arrow" |
---|
124 | } |
---|
125 | |
---|
126 | private variable _cname "one" |
---|
127 | private variable _data "" |
---|
128 | private variable _type "" |
---|
129 | } |
---|
130 | |
---|
131 | # ---------------------------------------------------------------------- |
---|
132 | # USAGE: send_file |
---|
133 | # |
---|
134 | # Prompts the user for a text file, and then sends the text within |
---|
135 | # that file along to the rendering widget. |
---|
136 | # ---------------------------------------------------------------------- |
---|
137 | proc send_file {} { |
---|
138 | global widgets |
---|
139 | |
---|
140 | set file [tk_getOpenFile -title "Open VTK File"] |
---|
141 | if {"" != $file && [catch { |
---|
142 | set fid [open $file r] |
---|
143 | fconfigure $fid -translation binary |
---|
144 | set info [read $fid] |
---|
145 | close $fid |
---|
146 | }] == 0} { |
---|
147 | set obj [visData #auto $info "vtk"] |
---|
148 | $widgets(vtkglyphviewer) add $obj |
---|
149 | $widgets(vtkglyphviewer) scale $obj |
---|
150 | } |
---|
151 | } |
---|
152 | |
---|
153 | # ---------------------------------------------------------------------- |
---|
154 | # USAGE: load_script |
---|
155 | # |
---|
156 | # Prompts the user for a text file, and then sends the text within |
---|
157 | # that file along to the rendering widget. |
---|
158 | # ---------------------------------------------------------------------- |
---|
159 | proc load_script {} { |
---|
160 | global widgets |
---|
161 | |
---|
162 | set file [tk_getOpenFile -title "Open Command File"] |
---|
163 | if {"" != $file && [catch { |
---|
164 | set fid [open $file r] |
---|
165 | fconfigure $fid -translation binary |
---|
166 | set info [read $fid] |
---|
167 | close $fid |
---|
168 | }] == 0} { |
---|
169 | |
---|
170 | $widgets(command) insert 0 $info |
---|
171 | send_command |
---|
172 | } |
---|
173 | } |
---|
174 | |
---|
175 | # ---------------------------------------------------------------------- |
---|
176 | # USAGE: send_command |
---|
177 | # |
---|
178 | # Invoked automatically whenever the user enters a command and |
---|
179 | # presses <Return>. Sends the command along to the rendering |
---|
180 | # widget. |
---|
181 | # ---------------------------------------------------------------------- |
---|
182 | proc send_command {} { |
---|
183 | global widgets |
---|
184 | global last_command |
---|
185 | |
---|
186 | set cmd [$widgets(command) get] |
---|
187 | |
---|
188 | if {[string length $cmd] > 0} { |
---|
189 | set last_command $cmd |
---|
190 | } else { |
---|
191 | set cmd $last_command |
---|
192 | } |
---|
193 | namespace eval Rappture::VtkGlyphViewer [list $widgets(vtkglyphviewer) SendCmd $cmd] |
---|
194 | $widgets(command) delete 0 end |
---|
195 | } |
---|
196 | |
---|
197 | # ---------------------------------------------------------------------- |
---|
198 | # USAGE: reset |
---|
199 | # |
---|
200 | # Used internally to reset the connection to the rendering server. |
---|
201 | # Discards all data and resets the widget connection to the server. |
---|
202 | # ---------------------------------------------------------------------- |
---|
203 | proc reset {} { |
---|
204 | global widgets |
---|
205 | $widgets(vtkglyphviewer) delete |
---|
206 | $widgets(vtkglyphviewer) disconnect |
---|
207 | $widgets(comm) configure -state normal |
---|
208 | $widgets(comm) delete 1.0 end |
---|
209 | $widgets(comm) configure -state disabled |
---|
210 | } |
---|
211 | |
---|
212 | # ---------------------------------------------------------------------- |
---|
213 | # USAGE: show_comm <channel> <data> |
---|
214 | # |
---|
215 | # Invoked automatically whenever there is communication between |
---|
216 | # the rendering widget and the server. Eavesdrops on the communication |
---|
217 | # and posts the commands in a text viewer. |
---|
218 | # ---------------------------------------------------------------------- |
---|
219 | proc show_comm {channel {data ""}} { |
---|
220 | global widgets |
---|
221 | |
---|
222 | $widgets(comm) configure -state normal |
---|
223 | switch -- $channel { |
---|
224 | closed { |
---|
225 | $widgets(comm) insert end "--CLOSED--\n" error |
---|
226 | } |
---|
227 | <<line { |
---|
228 | $widgets(comm) insert end $data incoming "\n" incoming |
---|
229 | images_refresh |
---|
230 | } |
---|
231 | >>line { |
---|
232 | $widgets(comm) insert end $data outgoing "\n" outgoing |
---|
233 | } |
---|
234 | error { |
---|
235 | $widgets(comm) insert end $data error "\n" error |
---|
236 | } |
---|
237 | default { |
---|
238 | $widgets(comm) insert end "$data\n" |
---|
239 | } |
---|
240 | } |
---|
241 | $widgets(comm) configure -state disabled |
---|
242 | $widgets(comm) see end |
---|
243 | } |
---|
244 | |
---|
245 | # ---------------------------------------------------------------------- |
---|
246 | # TOPLEVEL FOR IMAGES |
---|
247 | # ---------------------------------------------------------------------- |
---|
248 | # USAGE: images_save |
---|
249 | # |
---|
250 | # Invoked when the user presses the "Save As..." button on the |
---|
251 | # images panel. Saves the current image in a file, which can be |
---|
252 | # examined by some external program. |
---|
253 | # ---------------------------------------------------------------------- |
---|
254 | proc images_save {} { |
---|
255 | global widgets images |
---|
256 | |
---|
257 | set imh [$widgets(vtkglyphviewer) get -image $images(which)] |
---|
258 | |
---|
259 | set file [tk_getSaveFile -title "Save Image File" \ |
---|
260 | -defaultextension .jpg -filetypes {{{JPEG files} .jpg} {{All Files} *}}] |
---|
261 | |
---|
262 | if {"" != $file} { |
---|
263 | set cmds { |
---|
264 | $imh write $file -format jpeg |
---|
265 | } |
---|
266 | if {[catch $cmds err]} { |
---|
267 | tk_messageBox -icon error -message "Oops! Save failed:\n$err" |
---|
268 | } |
---|
269 | } |
---|
270 | } |
---|
271 | |
---|
272 | # ---------------------------------------------------------------------- |
---|
273 | # USAGE: images_refresh |
---|
274 | # |
---|
275 | # Invoked automatically whenever there is a change in the view/legend |
---|
276 | # controls on the images panel. Updates the image being shown based |
---|
277 | # on the current selection. |
---|
278 | # ---------------------------------------------------------------------- |
---|
279 | proc images_refresh {} { |
---|
280 | global widgets images |
---|
281 | set c $widgets(viewer) |
---|
282 | |
---|
283 | set w [winfo width $c] |
---|
284 | set h [winfo height $c] |
---|
285 | |
---|
286 | set imh [$widgets(vtkglyphviewer) get -image $images(which)] |
---|
287 | set iw [image width $imh] |
---|
288 | set ih [image height $imh] |
---|
289 | |
---|
290 | $c coords image [expr {$w/2}] [expr {$h/2}] |
---|
291 | $c itemconfigure image -image $imh |
---|
292 | $c coords outline [expr {$w/2-$iw/2}] [expr {$h/2-$ih/2}] \ |
---|
293 | [expr {$w/2+$iw/2}] [expr {$h/2+$ih/2}] |
---|
294 | } |
---|
295 | |
---|
296 | toplevel .images |
---|
297 | wm title .images "VtkGlyphViewer: Images" |
---|
298 | wm withdraw .images |
---|
299 | wm protocol .images WM_DELETE_WINDOW {wm withdraw .images} |
---|
300 | |
---|
301 | frame .images.cntls |
---|
302 | pack .images.cntls -side bottom -fill x |
---|
303 | button .images.cntls.save -text "Save As..." -command images_save |
---|
304 | pack .images.cntls.save -side right -padx 4 |
---|
305 | radiobutton .images.cntls.view -text "3D View" -variable images(which) \ |
---|
306 | -value "view" -command images_refresh |
---|
307 | pack .images.cntls.view -side top -anchor w |
---|
308 | radiobutton .images.cntls.legend -text "Legend" -variable images(which) \ |
---|
309 | -value "legend" -command images_refresh |
---|
310 | pack .images.cntls.legend -side top -anchor w |
---|
311 | set images(which) "view" |
---|
312 | |
---|
313 | canvas .images.viewer -background black -width 500 -height 500 |
---|
314 | pack .images.viewer -expand yes -fill both |
---|
315 | bind .images.viewer <Configure> images_refresh |
---|
316 | set widgets(viewer) .images.viewer |
---|
317 | |
---|
318 | $widgets(viewer) create image 0 0 -anchor c \ |
---|
319 | -image [image create photo] -tags image |
---|
320 | $widgets(viewer) create rectangle 0 0 1 1 -width 2 -outline red -fill "" \ |
---|
321 | -tags outline |
---|
322 | |
---|
323 | |
---|
324 | # ---------------------------------------------------------------------- |
---|
325 | # MAIN WINDOW |
---|
326 | # ---------------------------------------------------------------------- |
---|
327 | menu .mbar |
---|
328 | menu .mbar.file |
---|
329 | .mbar.file add command -label "Send VTK File..." -underline 0 -command send_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 | . configure -menu .mbar |
---|
342 | |
---|
343 | |
---|
344 | Rappture::Panes .main -sashwidth 4 -sashrelief raised -sashpadding 4 \ |
---|
345 | -width 6i -height 4i |
---|
346 | pack .main -expand yes -fill both |
---|
347 | |
---|
348 | set f [.main pane 0] |
---|
349 | set servers [Rappture::VisViewer::GetServerList "vtkvis"] |
---|
350 | Rappture::VtkGlyphViewer $f.viewer $servers |
---|
351 | pack $f.viewer -expand yes -fill both |
---|
352 | set widgets(vtkglyphviewer) $f.viewer |
---|
353 | |
---|
354 | $f.viewer configure \ |
---|
355 | -sendcommand show_comm \ |
---|
356 | -receivecommand show_comm |
---|
357 | |
---|
358 | set f [.main insert end -fraction 0.5] |
---|
359 | frame $f.send |
---|
360 | pack $f.send -side bottom -fill x |
---|
361 | label $f.send.l -text "Send:" |
---|
362 | pack $f.send.l -side left |
---|
363 | set widgets(command) [entry $f.send.e] |
---|
364 | pack $f.send.e -side left -expand yes -fill x |
---|
365 | bind $f.send.e <KeyPress-Return> send_command |
---|
366 | |
---|
367 | scrollbar $f.sb -orient vertical -command "$f.comm yview" |
---|
368 | pack $f.sb -side right -fill y |
---|
369 | text $f.comm -wrap char -yscrollcommand "$f.sb set" |
---|
370 | pack $f.comm -expand yes -fill both |
---|
371 | set widgets(comm) $f.comm |
---|
372 | |
---|
373 | $widgets(comm) tag configure error -foreground red \ |
---|
374 | -font -*-courier-medium-o-normal-*-*-120-* |
---|
375 | $widgets(comm) tag configure incoming -foreground blue |
---|