source: branches/blt4/gui/apps/nanovis-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: 12.6 KB
Line 
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#\
19bindir=`dirname $0` ; \
20exec $bindir/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
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(nanovis) add $obj
111    }
112}
113
114# ----------------------------------------------------------------------
115# USAGE: send_flow_file
116#
117# Prompts the user for a text file, and then sends the text within
118# that file along to the rendering widget.
119# ----------------------------------------------------------------------
120proc send_flow_file {} {
121    global widgets
122
123    set file [tk_getOpenFile -title "Open Command File"]
124    if {"" != $file && [catch {
125            set fid [open $file r]
126            fconfigure $fid -translation binary
127            set info [read $fid]
128            close $fid
129          }] == 0} {
130        set _data [Rappture::encoding::encode -as zb64 $info ]
131        set _data "flow data follows [string length $_data]\n$_data"
132        $widgets(command) insert 0 $_data
133        send_command
134    }
135}
136
137# ----------------------------------------------------------------------
138# USAGE: load_script
139#
140# Prompts the user for a text file, and then sends the text within
141# that file along to the rendering widget.
142# ----------------------------------------------------------------------
143proc load_script {} {
144    global widgets
145
146    set file [tk_getOpenFile -title "Open Command File"]
147    if {"" != $file && [catch {
148            set fid [open $file r]
149            fconfigure $fid -translation binary
150            set info [read $fid]
151            close $fid
152          }] == 0} {
153
154        $widgets(command) insert 0 $info
155        send_command
156    }
157}
158
159# ----------------------------------------------------------------------
160# USAGE: send_command
161#
162# Invoked automatically whenever the user enters a command and
163# presses <Return>.  Sends the command along to the rendering
164# widget.
165# ----------------------------------------------------------------------
166proc send_command {} {
167    global widgets
168    global last_command
169
170    set cmd [$widgets(command) get]
171
172    if {[string length $cmd] > 0} {
173        set last_command $cmd
174    } else {
175        set cmd $last_command
176    }
177    namespace eval Rappture::NanovisViewer [list $widgets(nanovis) SendCmd $cmd]
178    $widgets(command) delete 0 end
179}
180
181# ----------------------------------------------------------------------
182# USAGE: reset
183#
184# Used internally to reset the connection to the rendering server.
185# Discards all data and resets the widget connection to the server.
186# ----------------------------------------------------------------------
187proc reset {} {
188    global widgets
189    $widgets(nanovis) delete
190    $widgets(nanovis) disconnect
191    $widgets(comm) configure -state normal
192    $widgets(comm) delete 1.0 end
193    $widgets(comm) configure -state disabled
194}
195
196# ----------------------------------------------------------------------
197# USAGE: show_comm <channel> <data>
198#
199# Invoked automatically whenever there is communication between
200# the rendering widget and the server.  Eavesdrops on the communication
201# and posts the commands in a text viewer.
202# ----------------------------------------------------------------------
203proc show_comm {channel {data ""}} {
204    global widgets
205
206    $widgets(comm) configure -state normal
207    switch -- $channel {
208        closed {
209            $widgets(comm) insert end "--CLOSED--\n" error
210        }
211        <<line {
212            $widgets(comm) insert end $data incoming "\n" incoming
213            images_refresh
214        }
215        >>line {
216            $widgets(comm) insert end $data outgoing "\n" outgoing
217        }
218        error {
219            $widgets(comm) insert end $data error "\n" error
220        }
221        default {
222            $widgets(comm) insert end "$data\n"
223        }
224    }
225    $widgets(comm) configure -state disabled
226    $widgets(comm) see end
227}
228
229# ----------------------------------------------------------------------
230# USAGE: activate_flow
231#
232# ----------------------------------------------------------------------
233proc activate_flow {} {
234    global widgets
235    # global img_storage_dir
236    # "flow capture 117 $img_storage_dir"
237
238    set info {flow vectorid 0
239              flow particle visible on
240              flow lic on
241              flow capture 100}
242
243    $widgets(command) insert 0 $info
244    send_command
245
246}
247
248# ----------------------------------------------------------------------
249# TOPLEVEL FOR IMAGES
250# ----------------------------------------------------------------------
251# USAGE: images_save
252#
253# Invoked when the user presses the "Save As..." button on the
254# images panel.  Saves the current image in a file, which can be
255# examined by some external program.
256# ----------------------------------------------------------------------
257proc images_save {} {
258    global widgets images
259
260    set imh [$widgets(nanovis) get -image $images(which)]
261
262    set file [tk_getSaveFile -title "Save Image File" \
263        -defaultextension .jpg -filetypes {{{JPEG files} .jpg} {{All Files} *}}]
264
265    if {"" != $file} {
266        set cmds {
267            $imh write $file -format jpeg
268        }
269        if {[catch $cmds err]} {
270            tk_messageBox -icon error -message "Oops!  Save failed:\n$err"
271        }
272    }
273}
274
275# ----------------------------------------------------------------------
276# USAGE: images_refresh
277#
278# Invoked automatically whenever there is a change in the 3dview/legend
279# controls on the images panel.  Updates the image being shown based
280# on the current selection.
281# ----------------------------------------------------------------------
282proc images_refresh {} {
283    global widgets images
284    set c $widgets(viewer)
285
286    set w [winfo width $c]
287    set h [winfo height $c]
288
289    set imh [$widgets(nanovis) get -image $images(which)]
290    set iw [image width $imh]
291    set ih [image height $imh]
292
293    $c coords image [expr {$w/2}] [expr {$h/2}]
294    $c itemconfigure image -image $imh
295    $c coords outline [expr {$w/2-$iw/2}] [expr {$h/2-$ih/2}] \
296        [expr {$w/2+$iw/2}] [expr {$h/2+$ih/2}]
297}
298
299toplevel .images
300wm title .images "nanoVIS: Images"
301wm withdraw .images
302wm protocol .images WM_DELETE_WINDOW {wm withdraw .images}
303
304frame .images.cntls
305pack .images.cntls -side bottom -fill x
306button .images.cntls.save -text "Save As..." -command images_save
307pack .images.cntls.save -side right -padx 4
308radiobutton .images.cntls.3dview -text "3D View" -variable images(which) \
309    -value "3dview" -command images_refresh
310pack .images.cntls.3dview -side top -anchor w
311radiobutton .images.cntls.legend -text "Legend" -variable images(which) \
312    -value "legend" -command images_refresh
313pack .images.cntls.legend -side top -anchor w
314set images(which) "3dview"
315
316canvas .images.viewer -background black -width 500 -height 500
317pack .images.viewer -expand yes -fill both
318bind .images.viewer <Configure> images_refresh
319set widgets(viewer) .images.viewer
320
321$widgets(viewer) create image 0 0 -anchor c \
322    -image [image create photo] -tags image
323$widgets(viewer) create rectangle 0 0 1 1 -width 2 -outline red -fill "" \
324    -tags outline
325
326
327# ----------------------------------------------------------------------
328# MAIN WINDOW
329# ----------------------------------------------------------------------
330menu .mbar
331menu .mbar.file
332.mbar.file add command -label "Send Volume File..." -underline 0 -command send_file
333.mbar.file add command -label "Send Flow File..." -underline 0 -command send_flow_file
334.mbar.file add command -label "Load script..." -underline 0 -command load_script
335.mbar.file add command -label "Reset" -underline 0 -command reset
336.mbar.file add separator
337.mbar.file add command -label "Exit" -underline 1 -command exit
338.mbar add cascade -label "File" -underline 0 -menu .mbar.file
339
340menu .mbar.view
341.mbar.view add command -label "Images..." -underline 0 \
342    -command {wm deiconify .images}
343.mbar add cascade -label "View" -underline 0 -menu .mbar.view
344
345menu .mbar.flow
346.mbar.flow add command -label "Activate Flow" -command {activate_flow}
347.mbar add cascade -label "Flow" -underline 0 -menu .mbar.flow
348
349
350
351. configure -menu .mbar
352
353
354Rappture::Panes .main -sashwidth 4 -sashrelief raised -sashpadding 4 \
355    -width 6i -height 4i
356pack .main -expand yes -fill both
357
358set f [.main pane 0]
359set servers [Rappture::VisViewer::GetServerList "nanovis"]
360Rappture::NanovisViewer $f.viewer $servers
361pack $f.viewer -expand yes -fill both
362set widgets(nanovis) $f.viewer
363
364puts stderr [winfo class $widgets(nanovis)]
365
366$f.viewer configure \
367    -sendcommand show_comm \
368    -receivecommand show_comm
369
370set f [.main insert end -fraction 0.5]
371frame $f.send
372pack $f.send -side bottom -fill x
373label $f.send.l -text "Send:"
374pack $f.send.l -side left
375set widgets(command) [entry $f.send.e]
376pack $f.send.e -side left -expand yes -fill x
377bind $f.send.e <KeyPress-Return> send_command
378
379scrollbar $f.sb -orient vertical -command "$f.comm yview"
380pack $f.sb -side right -fill y
381text $f.comm -wrap char -yscrollcommand "$f.sb set"
382pack $f.comm -expand yes -fill both
383set widgets(comm) $f.comm
384
385$widgets(comm) tag configure error -foreground red \
386    -font -*-courier-medium-o-normal-*-*-120-*
387$widgets(comm) tag configure incoming -foreground blue
Note: See TracBrowser for help on using the repository browser.