!******************************************************************************!
! Test case to test LayerDrawable refresh issue and LayerT5 setting points size on file
!
! @issue    NXM-3552 LayerT5 setSize does not set the number of points kept, when reading directly from a file
!           NXM-3571 LayerDrawable sometimes stops refreshing
! @since    3.9.4
! @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

  if interAct then
    set instructions "********         TOP PLOT              ********\n&
                      Only 20 cities should be plotted\n\n&
                      ********     BOTTOM PLOT               ********\n&
                      1) Click 'Add a piped Layer' twice\n&
                      => the red scattered points should be added at a fast rate\n&
                      => the yellow diagonal points should be added at a slow rate\n&
                      FAIL this if instead the red points are added in clumps each time &
                      an additional yellow point appears.&
                      "

    set ellipselayerPIPE "LT=T5,Group=t5Group2,NAME=DIAG,AutoselectEnable=CLICK,AutoSelectMode=PIXEL,SELECTCOLOR=AQUA"
    set ellipselayerPIPE2 "LT=T5,Group=t5Group2,NAME=QUAD,AutoselectEnable=CLICK,AutoSelectMode=PIXEL,SELECTCOLOR=WHITE"

    set has1stLayer false
    set has2ndLayer false

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

      nxm.sys.test.plotellipsetester/DIAGONAL/COLOR=4/NOTEMODETYPE=VA/RT/RATE=1/STARTTIME="2007:01:02::00:00:00" OUT=_t5pipe{SIZE=10000} ELEM=Inf
      nxm.sys.test.plotellipsetester/BQ/COLOR=3/RT/NOTEMODETYPE=4VA/RATE=700/STARTTIME="2007:01:02::00:00:00" OUT=_t5pipe2{SIZE=10000} ELEM=Inf

      plot/id=cities  ^{datDir}.world.prm|^{datDir}.cities.prm{LAYER={SIZE=20}} readout=+OnAxis

      plot/id=timepipe/msgid=1 ^{datDir}.world.prm|{LT="Drawable",name=t5Group2}  &
               readout=+OnAxis|+AlwaysDeltas view=latlon Y1=-90 Y2=90 X1=-180 X2=180

      gcontrol/nc=1 button clearLayers "" "Clear all layers" ""
      gcontrol/nc=1 button ADDLAYER "" "Add a piped Layer" ""
      gcontrol button showDiagonal   "Diagonal Points" "HIDE,SHOW" "SHOW" /tleft

    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 "CLEARLAYERS" then
    invoke ,, reg.timepipe.clearData()
  elseif msg.name eqs "ADDLAYER" then
    if has1stLayer isFalse then
      invoke ,, reg.timepipe.openFile(_t5pipe{LAYER={^ellipselayerPIPE},TAG=DIAGPIPE})
      ! bstore set by openfile and needs to be removed for this test
      set has1stLayer true
    elseif has2ndLayer isFalse then
      invoke ,, reg.timepipe.openFile(_t5pipe2{LAYER={^ellipselayerPIPE2},TAG=QUADPIPE})
      ! bstore set by openfile and needs to be removed for this test
      set has2ndLayer true
    else
      say "no more layers to add"
    endif
  elseif msg.name eqs "SHOWDIAGONAL" then
    if msg.data EQS "HIDE" then
      res reg.timepipe.layers.t5group2.getLayer(DIAG).setEnable(-GLOBAL)
    else
      res reg.timepipe.layers.t5group2.getLayer(DIAG).setEnable(+GLOBAL)
    endif
  elseif msg.name eqs "PANXY" then
  elseif msg.name eqs "ZOOM" then
  elseif msg.name eqs "DRAGBOX" then
  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
res msg.name
  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
