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