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

Last change on this file since 1140 was 1014, checked in by gah, 16 years ago

nanovisviewer method changed to _send

  • Property svn:executable set to *
File size: 12.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    namespace eval Rappture::NanovisViewer [list $widgets(nanovis) _send $cmd]
130    $widgets(command) delete 0 end
131}
132
133# ----------------------------------------------------------------------
134# USAGE: karl_send_command <cmd>
135#
136# Used internally in this script (not from command prompt)
137# ----------------------------------------------------------------------
138proc karl_send_command {cmd} {
139    global widgets
140
141    namespace eval Rappture::NanovisViewer [list $widgets(nanovis) _send $cmd]
142#    $widgets(command) delete 0 end
143}
144
145# ----------------------------------------------------------------------
146# USAGE: reset
147#
148# Used internally to reset the connection to the rendering server.
149# Discards all data and resets the widget connection to the server.
150# ----------------------------------------------------------------------
151proc reset {} {
152    global widgets
153    $widgets(nanovis) delete
154    $widgets(nanovis) disconnect
155    $widgets(comm) configure -state normal
156    $widgets(comm) delete 1.0 end
157    $widgets(comm) configure -state disabled
158}
159
160# ----------------------------------------------------------------------
161# USAGE: show_comm <channel> <data>
162#
163# Invoked automatically whenever there is communication between
164# the rendering widget and the server.  Eavesdrops on the communication
165# and posts the commands in a text viewer.
166# ----------------------------------------------------------------------
167proc show_comm {channel {data ""}} {
168    global widgets
169
170    $widgets(comm) configure -state normal
171    switch -- $channel {
172        closed {
173            $widgets(comm) insert end "--CLOSED--\n" error
174        }
175        <<line {
176            $widgets(comm) insert end $data incoming "\n" incoming
177            images_refresh
178        }
179        >>line {
180            $widgets(comm) insert end $data outgoing "\n" outgoing
181        }
182        error {
183            $widgets(comm) insert end $data error "\n" error
184        }
185        default {
186            $widgets(comm) insert end "$data\n"
187        }
188    }
189    $widgets(comm) configure -state disabled
190    $widgets(comm) see end
191}
192
193# ----------------------------------------------------------------------
194# USAGE: karl_activate_flow
195#
196# ----------------------------------------------------------------------
197proc karl_activate_flow {} {
198
199        global img_storage_dir
200        puts "Preparing images..."
201
202        # sequence of commands to initilize flow visualization go here
203        karl_send_command {test}
204        karl_send_command {flow vectorid 0}
205        karl_send_command {flow particle visible on}
206
207        set renderserver render05
208        set img_storage_dir [exec ssh $renderserver mktemp -d /tmp/animation.XXXXXX]
209        karl_send_command "flow capture 117 $img_storage_dir"
210}
211
212# ----------------------------------------------------------------------
213# USAGE: karl_flow_movie
214#
215# ----------------------------------------------------------------------
216proc karl_flow_movie {} {
217
218        global img_storage_dir
219        set renderserver render05
220
221
222        if {0} {
223                # create animated gif:
224                puts "creating animated gif..."
225                exec ssh $renderserver convert -delay 20 -loop 0 $img_storage_dir/image*.bmp $img_storage_dir/animated_flow.gif
226        } else {
227                # create mpeg movie:
228                puts "creating mpeg movie in $img_storage_dir"
229               
230                exec ssh $renderserver "cd $img_storage_dir && mogrify -format jpg *.bmp && ffmpeg -i image%03d.jpg flow_movie.mpg 2>/dev/null && rm *.jpg"
231        }
232
233        # Now present the .mpg or .gif file to the user to download
234        ## ??
235
236        return
237
238        # Finally, delete the temporary animation directory we have created
239        exec ssh $renderserver rmdir $img_storage_dir
240}
241
242# ----------------------------------------------------------------------
243# TOPLEVEL FOR IMAGES
244# ----------------------------------------------------------------------
245# USAGE: images_save
246#
247# Invoked when the user presses the "Save As..." button on the
248# images panel.  Saves the current image in a file, which can be
249# examined by some external program.
250# ----------------------------------------------------------------------
251proc images_save {} {
252    global widgets images
253
254    set imh [$widgets(nanovis) get -image $images(which)]
255
256    set file [tk_getSaveFile -title "Save Image File" \
257        -defaultextension .jpg -filetypes {{{JPEG files} .jpg} {{All Files} *}}]
258
259    if {"" != $file} {
260        set cmds {
261            $imh write $file -format jpeg
262        }
263        if {[catch $cmds err]} {
264            tk_messageBox -icon error -message "Oops!  Save failed:\n$err"
265        }
266    }
267}
268
269# ----------------------------------------------------------------------
270# USAGE: images_refresh
271#
272# Invoked automatically whenever there is a change in the 3dview/legend
273# controls on the images panel.  Updates the image being shown based
274# on the current selection.
275# ----------------------------------------------------------------------
276proc images_refresh {} {
277    global widgets images
278    set c $widgets(viewer)
279
280    set w [winfo width $c]
281    set h [winfo height $c]
282
283    set imh [$widgets(nanovis) get -image $images(which)]
284    set iw [image width $imh]
285    set ih [image height $imh]
286
287    $c coords image [expr {$w/2}] [expr {$h/2}]
288    $c itemconfigure image -image $imh
289    $c coords outline [expr {$w/2-$iw/2}] [expr {$h/2-$ih/2}] \
290        [expr {$w/2+$iw/2}] [expr {$h/2+$ih/2}]
291}
292
293toplevel .images
294wm title .images "nanoVIS: Images"
295wm withdraw .images
296wm protocol .images WM_DELETE_WINDOW {wm withdraw .images}
297
298frame .images.cntls
299pack .images.cntls -side bottom -fill x
300button .images.cntls.save -text "Save As..." -command images_save
301pack .images.cntls.save -side right -padx 4
302radiobutton .images.cntls.3dview -text "3D View" -variable images(which) \
303    -value "3dview" -command images_refresh
304pack .images.cntls.3dview -side top -anchor w
305radiobutton .images.cntls.legend -text "Legend" -variable images(which) \
306    -value "legend" -command images_refresh
307pack .images.cntls.legend -side top -anchor w
308set images(which) "3dview"
309
310canvas .images.viewer -background black -width 500 -height 500
311pack .images.viewer -expand yes -fill both
312bind .images.viewer <Configure> images_refresh
313set widgets(viewer) .images.viewer
314
315$widgets(viewer) create image 0 0 -anchor c \
316    -image [image create photo] -tags image
317$widgets(viewer) create rectangle 0 0 1 1 -width 2 -outline red -fill "" \
318    -tags outline
319
320
321# ----------------------------------------------------------------------
322# MAIN WINDOW
323# ----------------------------------------------------------------------
324menu .mbar
325menu .mbar.file
326.mbar.file add command -label "Send file..." -underline 0 -command send_file
327.mbar.file add command -label "Reset" -underline 0 -command reset
328.mbar.file add separator
329.mbar.file add command -label "Exit" -underline 1 -command exit
330.mbar add cascade -label "File" -underline 0 -menu .mbar.file
331
332menu .mbar.view
333.mbar.view add command -label "Images..." -underline 0 \
334    -command {wm deiconify .images}
335.mbar add cascade -label "View" -underline 0 -menu .mbar.view
336
337menu .mbar.flow
338.mbar.flow add command -label "Activate Flow" -command {karl_activate_flow}
339.mbar.flow add command -label "Capture Flow Movie" -command {karl_flow_movie}
340.mbar add cascade -label "Flow" -underline 0 -menu .mbar.flow
341
342
343
344. configure -menu .mbar
345
346
347Rappture::Panes .main -sashwidth 4 -sashrelief raised -sashpadding 4 \
348    -width 6i -height 4i
349pack .main -expand yes -fill both
350
351set f [.main pane 0]
352Rappture::Field3DResult $f.viewer
353pack $f.viewer -expand yes -fill both
354set widgets(nanovis) [$f.viewer component renderer]
355
356puts stderr [winfo class $widgets(nanovis)]
357
358$f.viewer component renderer configure \
359    -sendcommand show_comm \
360    -receivecommand show_comm
361
362set f [.main insert end -fraction 0.5]
363frame $f.send
364pack $f.send -side bottom -fill x
365label $f.send.l -text "Send:"
366pack $f.send.l -side left
367set widgets(command) [entry $f.send.e]
368pack $f.send.e -side left -expand yes -fill x
369bind $f.send.e <KeyPress-Return> send_command
370
371scrollbar $f.sb -orient vertical -command "$f.comm yview"
372pack $f.sb -side right -fill y
373text $f.comm -wrap char -yscrollcommand "$f.sb set"
374pack $f.comm -expand yes -fill both
375set widgets(comm) $f.comm
376
377$widgets(comm) tag configure error -foreground red \
378    -font -*-courier-medium-o-normal-*-*-120-*
379$widgets(comm) tag configure incoming -foreground blue
Note: See TracBrowser for help on using the repository browser.