$Application ExitOnReturnOn

set kw(vtkTemp1) [$Application GetMainWindow]
set kw(vtkTemp44) [$kw(vtkTemp1) GetMainView]

if {[info exists argc]} { 
    set argcm1 [expr $argc - 1]
    for {set i 0} {$i < $argcm1} {incr i} {
        if {[lindex $argv $i] == "-D" && $i < $argcm1} {
		set DataDir [lindex $argv [expr $i + 1]]
        }
        if {[lindex $argv $i] == "-UC" && $i < $argcm1} {
            set rmui [$kw(vtkTemp44) GetRenderModuleUI]
            catch {$rmui SetCompositeThreshold 0}
        }
    }
} 


# This test is to see if the bounds menu gets updated properly
# when the input menu is changed.

# Create a text file. "out.txt" is a special name
if { [catch {set fp [open "out.txt" w]}] != 0 } {
  $Application SetExitStatus 2
  $Application Exit
  exit
}

set pv(vtkTemp90) [$kw(vtkTemp1) GetPVSource GlyphSources Arrow0]
set pv(vtkTemp94) [$kw(vtkTemp1) GetPVSource GlyphSources Cone0]
set pv(vtkTemp98) [$kw(vtkTemp1) GetPVSource GlyphSources Sphere0]


set kw(vtkTemp99) [$kw(vtkTemp1) CreatePVSource SphereSource]
$kw(vtkTemp99) AcceptCallback
set kw(vtkTemp167) [$kw(vtkTemp1) CreatePVSource SphereSource]
set kw(vtkTemp177) [$kw(vtkTemp167) GetPVWidget {Center}]
$kw(vtkTemp177) SetValue 1.5 0 0
set kw(vtkTemp182) [$kw(vtkTemp167) GetPVWidget {Radius}]
$kw(vtkTemp182) SetValue 1.0
set kw(vtkTemp185) [$kw(vtkTemp167) GetPVWidget {Theta Resolution}]
$kw(vtkTemp185) SetValue 32
set kw(vtkTemp194) [$kw(vtkTemp167) GetPVWidget {Phi Resolution}]
$kw(vtkTemp194) SetValue 24
$kw(vtkTemp167) AcceptCallback
$kw(vtkTemp1) ResetCameraCallback

set kw(vtkTemp209) [$kw(vtkTemp1) CreatePVSource Clip]

$kw(vtkTemp44) SetBackgroundColor 1.000000 0.000000 0.501961

set BoundsDisplay [$kw(vtkTemp209) GetPVWidget {Input Bounds}]
puts $fp [[$BoundsDisplay GetWidget] GetBounds]

$kw(vtkTemp209) AcceptCallback
set kw(vtkTemp216) [$kw(vtkTemp209) GetPVWidget {Clip Function}]
set kw(vtkTemp217) [$kw(vtkTemp216) GetPVWidget {Plane}]
$kw(vtkTemp217) SetNormal -0.04923 0.99878 0.00259
$kw(vtkTemp209) AcceptCallback
[$kw(vtkTemp209) GetPVOutput] DrawSurface
set kw(vtkTemp215) [$kw(vtkTemp209) GetPVWidget {Input}]
[$kw(vtkTemp215) GetCurrentValue] SetVisibility 1
$kw(vtkTemp215) SetCurrentValue $kw(vtkTemp99)

puts $fp [[$BoundsDisplay GetWidget] GetBounds]
close $fp

source $DataDir/Utility/rtText.tcl
pvFileTest $DataDir/Baseline/BoundsDisplay.txt
file delete -force out.txt
if {[$Application GetExitStatus]} {
  $Application Exit
}


# might as well do the image comparison.
$kw(vtkTemp209) AcceptCallback


# Retrace
update
$Application StopRecordingScript
[ $Application GetMainWindow ] DeleteAllSources
# Source the trace to regenerate the sources.
if {[catch {set channel [open test.tmp w]}] == 0 } {
   close $channel
   file delete -force test.tmp
   source "[$Application GetTraceFileName]"
}

# Fix the size of the image.
set RenWin1 [[[$Application GetMainWindow] GetMainView] GetRenderWindow]
$RenWin1 SetSize 300 300
$RenWin1 Render
update

for {set i  1} {$i < [expr $argc - 1]} {incr i} {
    if {[lindex $argv $i] == "-C"} {
	source [lindex $argv [expr $i + 1]]
	$Application SetExitStatus [CompareImage [[$Application GetMainWindow] GetMainView]]
    }
}

$kw(vtkTemp44) SetBackgroundColor 0 0 0
 
$Application Exit





