$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 scalar range label of contour gets updated 
# properly when the input menu or the array 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
}

$kw(vtkTemp44) SetBackgroundColor 0 0 0
set kw(vtkTemp90) [$kw(vtkTemp1) GetPVSource GlyphSources Arrow0]
set kw(vtkTemp94) [$kw(vtkTemp1) GetPVSource GlyphSources Cone0]
set kw(vtkTemp98) [$kw(vtkTemp1) GetPVSource GlyphSources Sphere0]
set kw(vtkTemp99) [$kw(vtkTemp1) CreatePVSource ImageMandelbrotSource]
$kw(vtkTemp1) ShowCurrentSourceProperties
$kw(vtkTemp99) AcceptCallback
set kw(vtkTemp152) [$kw(vtkTemp1) CreatePVSource Calculator]
$kw(vtkTemp1) ShowCurrentSourceProperties
set kw(vtkTemp668) [$kw(vtkTemp152) GetPVWidget {Equation}]
$kw(vtkTemp668) AddScalarVariable Iterations Iterations 0
$kw(vtkTemp668) SetFunctionLabel {Iterations*2}
$kw(vtkTemp152) AcceptCallback
[$kw(vtkTemp152) GetPVOutput] DrawSurface
set kw(vtkTemp179) [$kw(vtkTemp1) CreatePVSource SphereSource]
$kw(vtkTemp1) ShowCurrentSourceProperties
set kw(vtkTemp194) [$kw(vtkTemp179) GetPVWidget {Radius}]
$kw(vtkTemp194) SetValue 1
set kw(vtkTemp197) [$kw(vtkTemp179) GetPVWidget {Theta Resolution}]
$kw(vtkTemp197) SetValue 32
set kw(vtkTemp206) [$kw(vtkTemp179) GetPVWidget {Phi Resolution}]
$kw(vtkTemp206) SetValue 32
$kw(vtkTemp179) AcceptCallback
set kw(vtkTemp236) [$kw(vtkTemp1) CreatePVSource ElevationFilter]
set kw(vtkTemp999) [$kw(vtkTemp236) GetPVWidget {Line}]
$kw(vtkTemp999) SetPoint1 0 0 0
$kw(vtkTemp999) SetPoint2 0 0 1
$kw(vtkTemp1) ShowCurrentSourceProperties
set kw(vtkTemp257) [$kw(vtkTemp236) GetPVWidget {ScalarRange}]
$kw(vtkTemp257) SetValue 0 10
$kw(vtkTemp236) AcceptCallback




set kw(vtkTemp267) [$kw(vtkTemp1) CreatePVSource Contour]
$kw(vtkTemp1) ShowCurrentSourceProperties
set ScalarRangeLabel [$kw(vtkTemp267) GetPVWidget {ScalarRangeLabel}]

puts $fp [$ScalarRangeLabel GetRange]

set kw(vtkTemp274) [$kw(vtkTemp267) GetPVWidget {Scalars}]
$kw(vtkTemp274) SetValue Elevation
set kw(vtkTemp277) [$kw(vtkTemp267) GetPVWidget {Contour Values}]
$kw(vtkTemp277) RemoveAllValues
$kw(vtkTemp277) AddValue 5.000000
$kw(vtkTemp267) AcceptCallback

set kw(vtkTemp1254) [$kw(vtkTemp267) GetPVOutput]
$kw(vtkTemp1254) ColorByProperty


puts $fp [$ScalarRangeLabel GetRange]

set kw(vtkTemp273) [$kw(vtkTemp267) GetPVWidget {Input}]
$kw(vtkTemp273) SetCurrentValue $kw(vtkTemp152)

puts $fp [$ScalarRangeLabel GetRange]

$kw(vtkTemp274) SetValue resultArray
$kw(vtkTemp267) AcceptCallback

puts $fp [$ScalarRangeLabel GetRange]

$kw(vtkTemp273) SetCurrentValue $kw(vtkTemp152)

puts $fp [$ScalarRangeLabel GetRange]

$kw(vtkTemp274) SetValue Iterations

puts $fp [$ScalarRangeLabel GetRange]

$kw(vtkTemp267) AcceptCallback

puts $fp [$ScalarRangeLabel GetRange]

close $fp

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

# might as well do the image comparison.

# 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]"
#  }

$kw(vtkTemp44) SetCameraState -1.425 1.244 7.301  -0.500 0.000 0.000  0.018 0.986 -0.166

# 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



