$Application ExitOnReturnOn

set pvWindow [$Application GetMainWindow]
set pv(vtkTemp43) [$pvWindow 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}
        }
    }
} 



# Also test to see if the ExtentEntry gets initialized properly.
# 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
}




proc AdjustContourValue { cnt val } {
    set entry [$cnt GetPVWidget {Contour Values}]
    $entry RemoveAllValues
    $entry AddValue $val
    $entry AddValueCallback
    $cnt AcceptCallback
}




$pv(vtkTemp43) SetBackgroundColor 0 0 0

#change to rotate camera interactor style
$pvWindow ChangeInteractorStyle 1

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

# Create the contour filter
set cInt [$pvWindow CreatePVSource Contour]
$cInt AcceptCallback

$pvWindow SetCurrentPVSource $kw(vtkTemp292)

set pvExtract [$pvWindow CreatePVSource ExtractGrid]
set VOIEntry [$pvExtract GetPVWidget {VOI}]

#----------- Text comparison ------------
# Save the default extent in the test text file.
puts $fp "Default range of the ExtentEntry:"
puts $fp [$VOIEntry GetRange]
close $fp

# compare the text file with the regression version.
source $DataDir/Utility/rtText.tcl
pvFileTest $DataDir/Baseline/CombustorTest.txt
file delete -force out.txt

if {[$Application GetExitStatus]} {
  $Application Exit
}
#----------------------------------------


# continue with the reast of the test/


$VOIEntry SetValue 0 56 0 32 0 0 
$pvExtract AcceptCallback

set RenWin1 [[[$Application GetMainWindow] GetMainView] GetRenderWindow]
$RenWin1 SetSize 300 300

[$pvExtract GetPVOutput] SetVisibility 0

set pvGlyph [$pvWindow CreatePVSource Glyph]
$pvGlyph AcceptCallback

[$pvGlyph GetPVOutput] ColorByProperty
set GlyphOrientScale [$pvGlyph GetPVWidget {OrientScale}]
$GlyphOrientScale SetScaleMode Scalar
$GlyphOrientScale SetScaleFactor 3.0
$pvGlyph AcceptCallback
[$pvGlyph GetPVOutput] SetVisibility 0


set cntOutput [$cInt GetPVOutput]

set Ren1 [[[$Application GetMainWindow] GetMainView] GetRenderer]
set camera [$Ren1 GetActiveCamera]
$camera SetPosition -29.1076 -40.3242 38.8874
$camera SetFocalPoint 8.255 0 29.7631
$camera SetViewUp -0.00809309 0.227813 0.973671
$camera SetViewAngle 30
$camera SetClippingRange 34.7159 82.3051

# Vary isosuface
$cntOutput SetVisibility 1
[$kw(vtkTemp292) GetPVOutput] SetVisibility 1

set start 0.2
set end 0.7
set num 2
set incr [expr ($end - $start)/$num]
for {set i 0} {$i < $num} {incr i 1} {
    set val [expr $start + $i * $incr]
    AdjustContourValue $cInt $val 

}

# Rotate isosuface
AdjustContourValue $cInt 0.3

$cntOutput ColorByPointField Momentum 3
$cntOutput SetScalarBarVisibility 1
$cInt UpdateParameterWidgets

set RenWin1 [[[$Application GetMainWindow] GetMainView] GetRenderWindow]
$RenWin1 SetSize 300 300

for {set i 0} {$i < 1} {incr i 1} {
    $camera Azimuth 10
    $RenWin1 Render
    update
}

$cntOutput SetVisibility 0
$cntOutput SetScalarBarVisibility 0

# Here goes cut-plane (see end of this file)

$camera SetPosition -28.8139 1.07506 33.8794
$camera SetFocalPoint 26.5733 -0.117269 27.8723
$camera SetViewUp 0.10793 0.00506272 0.994146
$camera SetViewAngle 30
$camera SetClippingRange 18.5955 61.8423

$VOIEntry SetValue 0 56 0 32 0 0 
$pvExtract AcceptCallback

[$pvExtract GetPVOutput] SetVisibility 1

[$pvGlyph GetPVOutput] SetVisibility 1
[$pvGlyph GetPVOutput] ColorByProperty

$camera SetPosition 36.8437 -0.196199 53.7392
$camera SetFocalPoint -5.92921 -0.324064 18.022
$camera SetViewUp -0.639592 -0.0625532 0.766165
$camera SetViewAngle 30
$camera SetClippingRange 15.0904 64.6074

$VOIEntry SetValue 0 0 0 32 3 20
$pvExtract AcceptCallback
$RenWin1 Render

set extOutput [$pvExtract GetPVOutput]
$extOutput ColorByPointField {Density} 1
$extOutput SetScalarBarVisibility 1

for {set i 55} {$i < 56} {incr i 1} {
    $VOIEntry SetValue $i $i 0 32 3 20
    $pvExtract AcceptCallback
    $RenWin1 Render
    update
}

[$pvExtract GetPVOutput] DrawSurface
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]]
    }
}





