! Tests LayerT5 points length expansion with cap
!
! @bug      NXM-3946 LayerT5 be able to set max grow to size on points
!
! @since    4.1.2
! @author:  Jeanette McCall
!******************************************************************************!
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
  invoke doubleMax java.lang.Double.MAX_VALUE
  res ptLon -175
  res lonInc 0.5
  res ptLat -88
  res latInc 0.5
  res starterSize 256
  res maxSize 1024
  res numPtsAdd 200
  res numPointsAdded 0
  

  set t:point5000_data {}
  set t:point5000_data.0 {POS=(0.0,0,0),NAME="TEMP"}
  header/create ram:point_starter.tmp TYPE=5000 RF=ECR COMPONENTS=(POS/VD/GEODETIC/DISTANCE_M,NAME/1A/UNDEFINED/NONE)
  file open/d/a out ram:point_starter.tmp
    invoke ,, out.setData(0,point5000_data.0)
  file close out


  if interAct then
    set instructions "Click 'Manually Add First Points'\n&
                      Expected: Starter points length is in effect...PASS\n&
                      then\n&
                      Click 'Add More Points' multiple times\n\n&
                      Expected: 4 Expanding points length...PASS\n&
                      then\n&
                      Expected: Capped at max points length...PASS\n&
                      "


    set layerPtGrow    "LT=T5,NAME=GROWPTSDATA,SIZE=^starterSize,MAXPOINTSSIZE=^maxSize,AutoselectEnable=CLICK,AutoSelectMode=PIXEL,SELECTCOLOR=BLUE,SELECTMESSAGES=TRUE"

    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 20 /title

      plot/id=t5plot/msgid=main world|point_starter.tmp{Layer={^layerPtGrow}} readoutExt=+SHOW|+POINTS readout=+OnAxis

      gcontrol label macro "Global Controls"
      gcontrol/nc=1 button SETPOINTS "" "Manually Add First Points"
      gcontrol/nc=1 button ADDPOINTS "" "Add More Points"
      shellgui/id=idshellgui/attach/rows=15

    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 eqss "MARK"
  elseif msg.name eqss "SETPOINTS"
    call addSymbolPoints
  elseif msg.name eqss "ADDPOINTS"
    call addNextAeroPoints
  elseif msg.name EQS "SELECT" OR msg.name EQS "DESELECT" then
   info "^msg.name MESSAGE"
   say "^msg.name ^msg.data"
  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

!*****************************************************************************
! add Point3D symbols to symbols layer
!*****************************************************************************
procedure addSymbolPoints
  res t5Lay reg.t5plot.layers.growptsdata
  ! delete "starter" point
  invoke ,, t5Lay.clear()


  ! add symbol points
  res t:symTable {POS={LAT=^{ptLat},LON=^{ptLon},ALT=0},NAME="Arrow",SYMBOL="Arrow.png"}
  invoke ,, t5Lay.setPoint(-1,symTable)
  res numPointsAdded 1

  call addNextAeroPoints

return
!*****************************************************************************
! add next Aero point
!*****************************************************************************
procedure addNextAeroPoints

  DO count 1 numPtsAdd 1
    calc ptLat ptLat latInc +
    calc ptLon ptLon lonInc +

    res t:symTable {POS={LAT=^{ptLat},LON=^{ptLon},ALT=0},COLOR=AQUA,NAME="Aero",SYMBOL="AERO"}
    invoke ,, t5Lay.setPoint(-1,symTable)
  ENDDO

  calc numPointsAdded numPointsAdded numPtsAdd +
  res numPointsAdded
  invoke ptslength t5Lay.getPointsLength()
  res ptslength
  if numPointsAdded LE starterSize then
    assert/text="^reg.main.name: Starter points length is in effect" ptslength LE starterSize
  elseif numPointsAdded LT maxSize then
    calc expLength ptslength starterSize / CEIL starterSize *
    assert/text="^reg.main.name: Expanding points length" ptslength EQ expLength
  else 
    assert/text="^reg.main.name: Capped at max points length" ptslength EQ maxSize
  endif

return