source: branches/blt4/gui/apps/flowvis-test @ 1897

Last change on this file since 1897 was 1897, checked in by gah, 14 years ago

re-merge with latest trunk changes

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