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

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