source: branches/1.3/gui/apps/vtkglyphs-test @ 3805

Last change on this file since 3805 was 3805, checked in by ldelgass, 11 years ago

Update vtk test apps from trunk

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