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

Last change on this file since 807 was 807, checked in by dkearney, 17 years ago

adjusted nanovis-test to always send gzip mime encoded data to nanovis server. took out the dx regular expression check. this allows transfer function and camera commands for non-dx data to be sent in the same manner as dx data.

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