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

Last change on this file since 1783 was 1492, checked in by gah, 15 years ago

update for flowvisviewer: speed controls, arrows, volume checkbutton

  • Property svn:executable set to *
File size: 11.6 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    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# ----------------------------------------------------------------------
99proc 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# ----------------------------------------------------------------------
121proc 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# ----------------------------------------------------------------------
144proc 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# ----------------------------------------------------------------------
165proc 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# ----------------------------------------------------------------------
181proc 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# ----------------------------------------------------------------------
211proc 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# ----------------------------------------------------------------------
232proc 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# ----------------------------------------------------------------------
257proc 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
274toplevel .images
275wm title .images "flowVIS: Images"
276wm withdraw .images
277wm protocol .images WM_DELETE_WINDOW {wm withdraw .images}
278
279frame .images.cntls
280pack .images.cntls -side bottom -fill x
281button .images.cntls.save -text "Save As..." -command images_save
282pack .images.cntls.save -side right -padx 4
283radiobutton .images.cntls.3dview -text "3D View" -variable images(which) \
284    -value "3dview" -command images_refresh
285pack .images.cntls.3dview -side top -anchor w
286radiobutton .images.cntls.legend -text "Legend" -variable images(which) \
287    -value "legend" -command images_refresh
288pack .images.cntls.legend -side top -anchor w
289set images(which) "3dview"
290
291canvas .images.viewer -background black -width 500 -height 700
292pack .images.viewer -expand yes -fill both
293bind .images.viewer <Configure> images_refresh
294set 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# ----------------------------------------------------------------------
305menu .mbar
306menu .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
314menu .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
319menu .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
328Rappture::Panes .main -sashwidth 4 -sashrelief raised -sashpadding 4 \
329    -width 6i -height 4.75i
330pack .main -expand yes -fill both
331
332set f [.main pane 0]
333set servers [Rappture::VisViewer::GetServerList "nanovis"]
334Rappture::FlowvisViewer $f.viewer $servers
335pack $f.viewer -expand yes -fill both
336set widgets(flowvis) $f.viewer
337
338puts stderr [winfo class $widgets(flowvis)]
339
340$f.viewer configure \
341    -sendcommand show_comm \
342    -receivecommand show_comm
343
344set f [.main insert end -fraction 0.5]
345frame $f.send
346pack $f.send -side bottom -fill x
347label $f.send.l -text "Send:"
348pack $f.send.l -side left
349set widgets(command) [entry $f.send.e]
350pack $f.send.e -side left -expand yes -fill x
351bind $f.send.e <KeyPress-Return> send_command
352
353scrollbar $f.sb -orient vertical -command "$f.comm yview"
354pack $f.sb -side right -fill y
355text $f.comm -wrap char -yscrollcommand "$f.sb set"
356pack $f.comm -expand yes -fill both
357set 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
Note: See TracBrowser for help on using the repository browser.