$Application ExitOnReturnOn

set pv(vtkTemp1) [$Application GetMainWindow]
set pv(vtkTemp43) [$pv(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 [$pv(vtkTemp43) GetRenderModuleUI]
            catch {$rmui SetCompositeThreshold 0}
        }
    }
} 


# The intent of this test is to generate a trace
# and source it to show that the trace worked.

$pv(vtkTemp43) SetBackgroundColor 0 0 0
set pv(vtkTemp89) [$pv(vtkTemp1) GetPVSource GlyphSources Arrow0]
set pv(vtkTemp93) [$pv(vtkTemp1) GetPVSource GlyphSources Cone0]
set pv(vtkTemp97) [$pv(vtkTemp1) GetPVSource GlyphSources Sphere0]

# Excercise all of the different types of PV widgets.

$pv(vtkTemp1) OpenCustom "P3DReader" "$DataDir/Data/combxyz.bin"
set pv(vtkTemp292) [$pv(vtkTemp1) GetCurrentPVSource]
set pv(vtkTemp305) [$pv(vtkTemp292) GetPVWidget {QFileName}]
$pv(vtkTemp305) SetValue "$DataDir/Data/combq.bin"
$pv(vtkTemp292) AcceptCallback

# A mistake, but I will leave it here
set pv(vtkTemp154) [$pv(vtkTemp1) CreatePVSource DataSetSurfaceFilter]
$pv(vtkTemp154) DeleteCallback
$pv(vtkTemp1) SetCurrentPVSource $pv(vtkTemp292)
$pv(vtkTemp1) ShowCurrentSourceProperties

set pv(vtkTemp167) [$pv(vtkTemp1) CreatePVSource SphereSource]
$pv(vtkTemp167) AcceptCallback
$pv(vtkTemp1) ResetCameraCallback
set pv(vtkTemp184) [$pv(vtkTemp167) GetPVWidget {Radius}]
$pv(vtkTemp184) SetValue 3
$pv(vtkTemp167) AcceptCallback
$pv(vtkTemp184) SetValue 5
$pv(vtkTemp167) AcceptCallback

set pv(vtkTemp230) [$pv(vtkTemp1) CreatePVSource Glyph]
set pv(vtkTemp238) [$pv(vtkTemp230) GetPVWidget {Input}]
$pv(vtkTemp238) SetCurrentValue $pv(vtkTemp167)
set pv(vtkTemp239) [$pv(vtkTemp230) GetPVWidget {Glyph}]
$pv(vtkTemp239) SetCurrentValue $pv(vtkTemp89)
$pv(vtkTemp230) AcceptCallback
$pv(vtkTemp239) SetCurrentValue $pv(vtkTemp93)
set pv(vtkTemp251) [$pv(vtkTemp230) GetPVWidget {OrientScale}]
$pv(vtkTemp251) SetScaleFactor 2
$pv(vtkTemp230) AcceptCallback
$pv(vtkTemp251) SetOrientMode "Off"
$pv(vtkTemp230) AcceptCallback
set pv(vtkTemp265) [$pv(vtkTemp1) CreatePVSource DataSetSurfaceFilter]
set pv(vtkTemp274) [$pv(vtkTemp265) GetPVWidget {Input}]
$pv(vtkTemp274) SetCurrentValue $pv(vtkTemp230)
$pv(vtkTemp265) AcceptCallback
[$pv(vtkTemp274) GetCurrentValue] SetVisibility 1
$pv(vtkTemp274) SetCurrentValue $pv(vtkTemp292)
$pv(vtkTemp265) AcceptCallback
$pv(vtkTemp1) ResetCameraCallback

set pv(vtkTemp286) [$pv(vtkTemp1) CreatePVSource Calculator]
set pv(vtkTemp668) [$pv(vtkTemp286) GetPVWidget {Equation}]
$pv(vtkTemp668) AddScalarVariable Momentum_0 Momentum 0
$pv(vtkTemp668) AddScalarVariable Momentum_1 Momentum 1
$pv(vtkTemp668) SetFunctionLabel {Momentum_0+Momentum_1}
set pv(vtkTemp298) [$pv(vtkTemp286) GetPVWidget {ResultArray}]
$pv(vtkTemp298) SetValue {sum}
$pv(vtkTemp286) AcceptCallback

# Test the Plane widget tracing.

set pv(vtkTemp285) [$pv(vtkTemp1) CreatePVSource SphereSource]
set pv(vtkTemp295) [$pv(vtkTemp285) GetPVWidget {Center}]
set pv(vtkTemp300) [$pv(vtkTemp285) GetPVWidget {Radius}]
$pv(vtkTemp300) SetValue 5
$pv(vtkTemp295) SetValue 0 15 0
$pv(vtkTemp285) AcceptCallback

$pv(vtkTemp1) ResetCameraCallback

set pv(vtkTemp327) [$pv(vtkTemp1) CreatePVSource Clip]
set pv(vtkTemp328) [$pv(vtkTemp327) GetPVWidget {Clip Function}]
set pv(vtkTemp334) [$pv(vtkTemp328) GetPVWidget {Plane}]
$pv(vtkTemp334) SetCenter 0 16 0
$pv(vtkTemp334) SetNormal 0.57546 0.76627 -0.28578
$pv(vtkTemp327) AcceptCallback
[$pv(vtkTemp327) GetPVOutput] DrawSurface


# OK, turn off the trace so that the file we source is not open.

$Application StopRecordingScript

# Delete all the sources

$pv(vtkTemp1) SetCurrentPVSource $pv(vtkTemp327)
$pv(vtkTemp327) DeleteCallback
$pv(vtkTemp1) SetCurrentPVSource $pv(vtkTemp285)
$pv(vtkTemp285) DeleteCallback

$pv(vtkTemp1) SetCurrentPVSource $pv(vtkTemp286)
$pv(vtkTemp286) DeleteCallback
$pv(vtkTemp1) SetCurrentPVSource $pv(vtkTemp265)
$pv(vtkTemp265) DeleteCallback
$pv(vtkTemp1) SetCurrentPVSource $pv(vtkTemp292)
$pv(vtkTemp292) DeleteCallback
$pv(vtkTemp1) SetCurrentPVSource $pv(vtkTemp230)
$pv(vtkTemp230) DeleteCallback
$pv(vtkTemp1) SetCurrentPVSource $pv(vtkTemp167)
$pv(vtkTemp167) DeleteCallback


# 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]]
    }
}
   
$Application Exit


