source: trunk/gui/apps/vtkheightmap-test @ 3933

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

Fixes for vtkvis test apps, add test for glyph viewer

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