source: branches/uq/gui/apps/vtkvolume-test @ 5679

Last change on this file since 5679 was 5679, checked in by ldelgass, 9 years ago

Full merge 1.3 branch to uq branch to sync. Fixed partial subdirectory merge
by removing mergeinfo from lang/python/Rappture directory.

  • Property svn:executable set to *
File size: 12.0 KB
Line 
1#!/bin/sh
2# -*- mode: Tcl -*-
3# ----------------------------------------------------------------------
4#  TEST PROGRAM for VtkVolumeViewer
5#
6#  This program is a test harness for the VtkVis visualization
7#  engine.  It allows you to monitor the commands being sent back
8#  and forth between a standard Rappture application and the VtkVis
9#  server.  You can also send your own commands to the server, to
10#  debug new features.
11#
12# ======================================================================
13#  AUTHOR:  Michael McLennan, Purdue University
14#  Copyright (c) 2004-2012  HUBzero Foundation, LLC
15#
16#  See the file "license.terms" for information on usage and
17#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
18# ======================================================================
19#\
20bindir=`dirname $0` ; \
21. $bindir/rappture.env ; \
22exec $bindir/wish "$0" "$@"
23# ----------------------------------------------------------------------
24# wish executes everything from here on...
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 VTK data file...
67# ----------------------------------------------------------------------
68itcl::class visData {
69    inherit Rappture::Field
70
71    constructor {args} {
72        Rappture::Field::constructor [Rappture::library standard] ""
73    } {
74        set _data [lindex $args 0]
75        GetTypeAndSize $_cname
76        GetAssociation $_cname
77        ReadVtkDataSet $_cname $_data
78        set _type [lindex $args 1]
79    }
80
81    public method components {args} {
82        Rappture::getopts args params {
83            flag what -name default
84            flag what -dimensions
85            flag what -style
86            flag what -particles
87            flag what -flow
88            flag what -box
89        }
90        if { $params(what) == "-dimensions" } {
91            return "${_dim}D"
92        }
93        if {[llength $args] == 0} {
94            return "one"
95        }
96        return ""
97    }
98    public method isvalid {} {
99        return 1
100    }
101    public method data {args} {
102        return $_data
103    }
104    public method vtkdata {args} {
105        return $_data
106    }
107    public method values {args} {
108        return $_data
109    }
110    public method style {args} {
111        return ""
112    }
113    public method hints {args} {
114        return ""
115    }
116    public method type {args} {
117        return $_type
118    }
119    public method viewer {args} {
120        return "vtkvolume"
121    }
122
123    private variable _cname "one"
124    private variable _data ""
125    private variable _type ""
126}
127
128# ----------------------------------------------------------------------
129# USAGE: send_file
130#
131# Prompts the user for a text file, and then sends the text within
132# that file along to the rendering widget.
133# ----------------------------------------------------------------------
134proc send_file {} {
135    global widgets
136
137    set file [tk_getOpenFile -title "Open VTK File"]
138    if {"" != $file && [catch {
139            set fid [open $file r]
140            fconfigure $fid -translation binary -encoding binary
141            set info [read $fid]
142            close $fid
143          }] == 0} {
144        set obj [visData #auto $info "vtkvolume"]
145        $widgets(vtkvolumeviewer) add $obj
146        $widgets(vtkvolumeviewer) scale $obj
147    }
148}
149
150# ----------------------------------------------------------------------
151# USAGE: load_script
152#
153# Prompts the user for a text file, and then sends the text within
154# that file along to the rendering widget.
155# ----------------------------------------------------------------------
156proc load_script {} {
157    global widgets
158
159    set file [tk_getOpenFile -title "Open Command File"]
160    if {"" != $file && [catch {
161            set fid [open $file r]
162            fconfigure $fid -translation binary
163            set info [read $fid]
164            close $fid
165          }] == 0} {
166
167        $widgets(command) insert 0 $info
168        send_command
169    }
170}
171
172# ----------------------------------------------------------------------
173# USAGE: send_command
174#
175# Invoked automatically whenever the user enters a command and
176# presses <Return>.  Sends the command along to the rendering
177# widget.
178# ----------------------------------------------------------------------
179proc send_command {} {
180    global widgets
181    global last_command
182
183    set cmd [$widgets(command) get]
184
185    if {[string length $cmd] > 0} {
186        set last_command $cmd
187    } else {
188        set cmd $last_command
189    }
190    namespace eval Rappture::VtkVolumeViewer [list $widgets(vtkvolumeviewer) SendCmd $cmd]
191    $widgets(command) delete 0 end
192}
193
194# ----------------------------------------------------------------------
195# USAGE: reset
196#
197# Used internally to reset the connection to the rendering server.
198# Discards all data and resets the widget connection to the server.
199# ----------------------------------------------------------------------
200proc reset {} {
201    global widgets
202    $widgets(vtkvolumeviewer) delete
203    $widgets(vtkvolumeviewer) disconnect
204    $widgets(comm) configure -state normal
205    $widgets(comm) delete 1.0 end
206    $widgets(comm) configure -state disabled
207}
208
209# ----------------------------------------------------------------------
210# USAGE: show_comm <channel> <data>
211#
212# Invoked automatically whenever there is communication between
213# the rendering widget and the server.  Eavesdrops on the communication
214# and posts the commands in a text viewer.
215# ----------------------------------------------------------------------
216proc show_comm {channel {data ""}} {
217    global widgets
218
219    $widgets(comm) configure -state normal
220    switch -- $channel {
221        closed {
222            $widgets(comm) insert end "--CLOSED--\n" error
223        }
224        <<line {
225            $widgets(comm) insert end $data incoming "\n" incoming
226            images_refresh
227        }
228        >>line {
229            $widgets(comm) insert end $data outgoing "\n" outgoing
230        }
231        error {
232            $widgets(comm) insert end $data error "\n" error
233        }
234        default {
235            $widgets(comm) insert end "$data\n"
236        }
237    }
238    $widgets(comm) configure -state disabled
239    $widgets(comm) see end
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(vtkvolumeviewer) 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 view/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(vtkvolumeviewer) 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 "Vtkvolumeviewer: 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.view -text "3D View" -variable images(which) \
303    -value "view" -command images_refresh
304pack .images.cntls.view -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) "view"
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 VTK File..." -underline 0 -command send_file
327.mbar.file add command -label "Load script..." -underline 0 -command load_script
328.mbar.file add command -label "Reset" -underline 0 -command reset
329.mbar.file add separator
330.mbar.file add command -label "Exit" -underline 1 -command exit
331.mbar add cascade -label "File" -underline 0 -menu .mbar.file
332
333menu .mbar.view
334.mbar.view add command -label "Images..." -underline 0 \
335    -command {wm deiconify .images}
336.mbar add cascade -label "View" -underline 0 -menu .mbar.view
337
338. configure -menu .mbar
339
340
341Rappture::Panes .main -sashwidth 4 -sashrelief raised -sashpadding 4 \
342    -width 6i -height 4i
343pack .main -expand yes -fill both
344
345set f [.main pane 0]
346set servers [Rappture::VisViewer::GetServerList "vtkvis"]
347Rappture::VtkVolumeViewer $f.viewer $servers
348pack $f.viewer -expand yes -fill both
349set widgets(vtkvolumeviewer) $f.viewer
350
351$f.viewer 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.