source: trunk/gui/apps/vtkviewer-test @ 2399

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

Rename vtkviewer2-test to vtkviewer-test

  • Property svn:executable set to *
File size: 11.7 KB
Line 
1#!/bin/sh
2# ----------------------------------------------------------------------
3#  TEST PROGRAM for VtkViewer
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    inherit Rappture::Drawing
74
75    constructor {args} {
76        Rappture::Scene::constructor [Rappture::library standard] ""
77    } {
78        set _data [lindex $args 0]
79    }
80
81    public method components {args} {
82        if {[llength $args] == 0} {
83            return "one"
84        }
85        return ""
86    }
87    public method data {args} {
88        return $_data
89    }
90    public method values {args} {
91        return $_data
92    }
93    public method hints {args} {
94        return ""
95    }
96
97    private variable _data ""
98}
99
100# ----------------------------------------------------------------------
101# USAGE: send_file
102#
103# Prompts the user for a text file, and then sends the text within
104# that file along to the rendering widget.
105# ----------------------------------------------------------------------
106proc send_file {} {
107    global widgets
108
109    set file [tk_getOpenFile -title "Open VTK File"]
110    if {"" != $file && [catch {
111            set fid [open $file r]
112            fconfigure $fid -translation binary
113            set info [read $fid]
114            close $fid
115          }] == 0} {
116        set obj [visData #auto $info]
117        $widgets(vtkviewer) add $obj
118    }
119}
120
121# ----------------------------------------------------------------------
122# USAGE: load_script
123#
124# Prompts the user for a text file, and then sends the text within
125# that file along to the rendering widget.
126# ----------------------------------------------------------------------
127proc load_script {} {
128    global widgets
129
130    set file [tk_getOpenFile -title "Open Command File"]
131    if {"" != $file && [catch {
132            set fid [open $file r]
133            fconfigure $fid -translation binary
134            set info [read $fid]
135            close $fid
136          }] == 0} {
137
138        $widgets(command) insert 0 $info
139        send_command
140    }
141}
142
143# ----------------------------------------------------------------------
144# USAGE: send_command
145#
146# Invoked automatically whenever the user enters a command and
147# presses <Return>.  Sends the command along to the rendering
148# widget.
149# ----------------------------------------------------------------------
150proc send_command {} {
151    global widgets
152    global last_command
153
154    set cmd [$widgets(command) get]
155
156    if {[string length $cmd] > 0} {
157        set last_command $cmd
158    } else {
159        set cmd $last_command
160    }
161    namespace eval Rappture::VtkViewer [list $widgets(vtkviewer) SendCmd $cmd]
162    $widgets(command) delete 0 end
163}
164
165# ----------------------------------------------------------------------
166# USAGE: reset
167#
168# Used internally to reset the connection to the rendering server.
169# Discards all data and resets the widget connection to the server.
170# ----------------------------------------------------------------------
171proc reset {} {
172    global widgets
173    $widgets(vtkviewer) delete
174    $widgets(vtkviewer) disconnect
175    $widgets(comm) configure -state normal
176    $widgets(comm) delete 1.0 end
177    $widgets(comm) configure -state disabled
178}
179
180# ----------------------------------------------------------------------
181# USAGE: show_comm <channel> <data>
182#
183# Invoked automatically whenever there is communication between
184# the rendering widget and the server.  Eavesdrops on the communication
185# and posts the commands in a text viewer.
186# ----------------------------------------------------------------------
187proc show_comm {channel {data ""}} {
188    global widgets
189
190    $widgets(comm) configure -state normal
191    switch -- $channel {
192        closed {
193            $widgets(comm) insert end "--CLOSED--\n" error
194        }
195        <<line {
196            $widgets(comm) insert end $data incoming "\n" incoming
197            images_refresh
198        }
199        >>line {
200            $widgets(comm) insert end $data outgoing "\n" outgoing
201        }
202        error {
203            $widgets(comm) insert end $data error "\n" error
204        }
205        default {
206            $widgets(comm) insert end "$data\n"
207        }
208    }
209    $widgets(comm) configure -state disabled
210    $widgets(comm) see end
211}
212
213# ----------------------------------------------------------------------
214# USAGE: activate_flow
215#
216# ----------------------------------------------------------------------
217proc activate_flow {} {
218    global widgets
219    # global img_storage_dir
220    # "flow capture 117 $img_storage_dir"
221
222    set info {flow vectorid 0
223              flow particle visible on
224              flow lic on
225              flow capture 100}
226
227    $widgets(command) insert 0 $info
228    send_command
229
230}
231
232# ----------------------------------------------------------------------
233# TOPLEVEL FOR IMAGES
234# ----------------------------------------------------------------------
235# USAGE: images_save
236#
237# Invoked when the user presses the "Save As..." button on the
238# images panel.  Saves the current image in a file, which can be
239# examined by some external program.
240# ----------------------------------------------------------------------
241proc images_save {} {
242    global widgets images
243
244    set imh [$widgets(vtkviewer) get -image $images(which)]
245
246    set file [tk_getSaveFile -title "Save Image File" \
247        -defaultextension .jpg -filetypes {{{JPEG files} .jpg} {{All Files} *}}]
248
249    if {"" != $file} {
250        set cmds {
251            $imh write $file -format jpeg
252        }
253        if {[catch $cmds err]} {
254            tk_messageBox -icon error -message "Oops!  Save failed:\n$err"
255        }
256    }
257}
258
259# ----------------------------------------------------------------------
260# USAGE: images_refresh
261#
262# Invoked automatically whenever there is a change in the view/legend
263# controls on the images panel.  Updates the image being shown based
264# on the current selection.
265# ----------------------------------------------------------------------
266proc images_refresh {} {
267    global widgets images
268    set c $widgets(viewer)
269
270    set w [winfo width $c]
271    set h [winfo height $c]
272
273    set imh [$widgets(vtkviewer) get -image $images(which)]
274    set iw [image width $imh]
275    set ih [image height $imh]
276
277    $c coords image [expr {$w/2}] [expr {$h/2}]
278    $c itemconfigure image -image $imh
279    $c coords outline [expr {$w/2-$iw/2}] [expr {$h/2-$ih/2}] \
280        [expr {$w/2+$iw/2}] [expr {$h/2+$ih/2}]
281}
282
283toplevel .images
284wm title .images "Vtkviewer: Images"
285wm withdraw .images
286wm protocol .images WM_DELETE_WINDOW {wm withdraw .images}
287
288frame .images.cntls
289pack .images.cntls -side bottom -fill x
290button .images.cntls.save -text "Save As..." -command images_save
291pack .images.cntls.save -side right -padx 4
292radiobutton .images.cntls.view -text "3D View" -variable images(which) \
293    -value "view" -command images_refresh
294pack .images.cntls.view -side top -anchor w
295radiobutton .images.cntls.legend -text "Legend" -variable images(which) \
296    -value "legend" -command images_refresh
297pack .images.cntls.legend -side top -anchor w
298set images(which) "view"
299
300canvas .images.viewer -background black -width 500 -height 500
301pack .images.viewer -expand yes -fill both
302bind .images.viewer <Configure> images_refresh
303set widgets(viewer) .images.viewer
304
305$widgets(viewer) create image 0 0 -anchor c \
306    -image [image create photo] -tags image
307$widgets(viewer) create rectangle 0 0 1 1 -width 2 -outline red -fill "" \
308    -tags outline
309
310
311# ----------------------------------------------------------------------
312# MAIN WINDOW
313# ----------------------------------------------------------------------
314menu .mbar
315menu .mbar.file
316.mbar.file add command -label "Send VTK File..." -underline 0 -command send_file
317.mbar.file add command -label "Load script..." -underline 0 -command load_script
318.mbar.file add command -label "Reset" -underline 0 -command reset
319.mbar.file add separator
320.mbar.file add command -label "Exit" -underline 1 -command exit
321.mbar add cascade -label "File" -underline 0 -menu .mbar.file
322
323menu .mbar.view
324.mbar.view add command -label "Images..." -underline 0 \
325    -command {wm deiconify .images}
326.mbar add cascade -label "View" -underline 0 -menu .mbar.view
327
328. configure -menu .mbar
329
330
331Rappture::Panes .main -sashwidth 4 -sashrelief raised -sashpadding 4 \
332    -width 6i -height 4i
333pack .main -expand yes -fill both
334
335set f [.main pane 0]
336set servers [Rappture::VisViewer::GetServerList "vtkvis"]
337Rappture::VtkViewer $f.viewer $servers
338pack $f.viewer -expand yes -fill both
339set widgets(vtkviewer) $f.viewer
340
341puts stderr [winfo class $widgets(vtkviewer)]
342
343$f.viewer configure \
344    -sendcommand show_comm \
345    -receivecommand show_comm
346
347set f [.main insert end -fraction 0.5]
348frame $f.send
349pack $f.send -side bottom -fill x
350label $f.send.l -text "Send:"
351pack $f.send.l -side left
352set widgets(command) [entry $f.send.e]
353pack $f.send.e -side left -expand yes -fill x
354bind $f.send.e <KeyPress-Return> send_command
355
356scrollbar $f.sb -orient vertical -command "$f.comm yview"
357pack $f.sb -side right -fill y
358text $f.comm -wrap char -yscrollcommand "$f.sb set"
359pack $f.comm -expand yes -fill both
360set widgets(comm) $f.comm
361
362$widgets(comm) tag configure error -foreground red \
363    -font -*-courier-medium-o-normal-*-*-120-*
364$widgets(comm) tag configure incoming -foreground blue
Note: See TracBrowser for help on using the repository browser.