!******************************************************************************!
! Test using large time values with no TimeCode in LayerT5 files
!
! @bug      2632 LayerT5 Stack Overflow
! @author:  J Bauer
!******************************************************************************!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE  ! for normal interactive test(s)
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE  ! for defects or more obscure test case(s)

  call setDatDir

  if interAct then
    set instructions "Click the 'Times' buttons below to set the time State Vector files to &
                      various values.\n\n&
                      Drag the slider to move the Aero StateVector manually."


    timex now d:startTime sod=mySod      ! get time in double format and also the seconds of the day
    calc midnite startTime mySod -       ! get time at midnite as a double

    noop ^{datDir}.sv1.prm ram:mysv1                ! create file
    noop ^{datDir}.sv3.prm ram:mysv2{TC=^midnite}   ! create file to animate

    calc initsteps 289 300 * 50 /

    pipe on
      panel/msgid=MAIN/setup/controls=gc
      gcontrol label macro "Test MACRO"
      gcontrol menu  main "Exit with Status =" "PASS,FAIL" TABLE={ItemColors={PASS="GREEN",FAIL="RED"}} /tleft

      gcontrol text  idtext "Instructions" instructions 24 8 /title

      gcontrol lVal secJump "Move it!" def=1 min=1 max=300 inc=1 /slider
      gcontrol line
      gcontrol button myButt "Times" "Animate,Small,Large"

      plot/id=plot1 ^{datDir}.world.prm|mysv1|mysv2

      res layT5A reg.plot1.layers.mysv1
      res layT5B reg.plot1.layers.mysv2

      set layT5B.line.symbol "Aero"
      set layT5B.line.symbolSize 16

    pipe off

  endif
endmacro

!******************************************************************************!
! Main process message for this macro. Should be right after the ENDMACRO.
!******************************************************************************!
procedure processMessage m:msg
  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: User indicated tests" msg.data eqss "PASS"
    pipe stop

  elseif msg.name eqs "SECJUMP"
    calc newTime gc.secJump.val 289 *
    set layT5B.time newTime
    invoke ,, layT5B.refresh()

  elseif msg.name eqs "MYBUTT" then
    if msg.data eqs "ANIMATE" then
      set step 0
      set gc.idtext.value "You should see the plane move 50 times along it's orbit"
      do count 1 50 1
        calc newTime midnite step +
        set layT5B.time newTime
        calc step step initsteps +
        pause .1
        invoke ,, layT5B.refresh()
      enddo


    elseif msg.data eqs "SMALL" then
      set step 4000
      calc newTime midnite step +
      set layT5B.time newTime
      set gc.idtext.value "You should see the plane move to a single spot"
      invoke ,, layT5B.refresh()

    elseif msg.data eqs "LARGE"
      set layT5A.line.symbol nxm.sys.test.icon56.png
      set layT5A.line.symbolSize 16
      set layT5A.line.symbolHeading 270
      set layT5A.time ^startTime
      invoke ,, layT5A.refresh()
      set gc.idtext.value "The small track should be replaced by an image of a plane, facing west"
    endif

  else
    ! say "Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif
return

!******************************************************************************!
! If an unexpected exception is caught, mark test as failed, unless it is expected
!******************************************************************************!
procedure processException m:emsg
  if expectedException REXISTS then
    assert/text="^reg.main.name: Expected ERROR starts with: ^{expectedException}" expectedException EQSS emsg.data.message
    remove expectedException
  else
    assert/text="^reg.main.name: Caught unexpected exception ^{emsg.data}" "FALSE" isTrue
    if "Trace" SUBS ENV.DEBUG then invoke ,, emsg.data.printStackTrace()
  endif
return

!******************************************************************************!
! Set the dat directory
!******************************************************************************!
procedure setDatDir
  invoke nxmMajor env.nmversion.subString(0,1)
  invoke major java.lang.Integer.valueOf(nxmMajor)
  if major GE 4 then
    invoke s:datDir           nxm.sys.test.DatLocator.getDatDirLocation()
    invoke s:datDirSlash      nxm.sys.test.DatLocator.getDatDirSlashLocation()
    invoke z:sysDatFull       nxm.sys.test.DatLocator.sysDatFull()
    invoke z:sysTestDatExists nxm.sys.test.DatLocator.sysTestDatExists()
  else
    set s:datDir           "nxm.sys.dat"
    set s:datDirSlash      "nxm/sys/dat"
    set z:sysDatFull       true
    set z:sysTestDatExists false
  endif
return
