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

Last change on this file since 855 was 855, checked in by kostmo, 17 years ago

Added single-line command history

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