source: trunk/gui/apps/vtkcontour-test @ 2293

Last change on this file since 2293 was 2293, checked in by ldelgass, 13 years ago

vtkviewer2-test needs to use a Rappture::Scene data object (for now). Also
remove send flow file menu item from vtkcontour-test (leftover from nanovis
test)

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