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

Last change on this file since 906 was 906, checked in by kostmo, 16 years ago

preliminary automation of movie generation

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