source: trunk/gui/apps/flowvis-test @ 1312

Last change on this file since 1312 was 1312, checked in by dkearney, 15 years ago

fix up flow capture command to automatically create a file name and remove it after use.
updated nvscripts to not send filename for capture command.
added proper destructor to AVTranslate object.

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