source: trunk/gui/apps/nanovis-test @ 2415

Last change on this file since 2415 was 2415, checked in by ldelgass, 13 years ago

Add emacs mode hints to shell scripts that exec tclsh/wish, so that emacs will
use Tcl mode instead of Shell-script mode when loading them.

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