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

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

Development of animation script

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