!******************************************************************************!
! Test case for multiple independent piped LayerT5s 
!
! @bug      NXM-3576 Map does not paint with piped LayerT5s
! @since    3.9.3
! @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 "This tests multiple piped LayerT5s being plotted independently\n\n&
                      1) Click 'Add a piped Layer' twice\n\n&
                      The map will have:\n&
                      - yellow diagonal points and\n&
                      - red scatter points\n\n&
                      2) Pan the plot to the extended Longitude range\n\n&
                      The map should not be flickering or constantly resizing\n\n&
                      Note: Trying to select points along the diagonal may well &
                      result in both a red and yellow point being selected, &
                      since this is not using LayerDrawable"

    set ellipselayerPIPE "LT=T5,TimeOrder=False,NAME=DIAG,AutoselectEnable=CLICK,AutoSelectMode=PIXEL,SELECTCOLOR=AQUA,SELECTMESSAGES=TRUE"
    set ellipselayerPIPE2 "LT=T5,TimeOrder=False,NAME=QUAD,AutoselectEnable=CLICK,AutoSelectMode=PIXEL,SELECTCOLOR=WHITE,SELECTMESSAGES=TRUE"

    set has1stLayer false
    set has2ndLayer false

    invoke booleantrue java.lang.Boolean.valueOf("true")
    invoke origT5Setting   nxm.sys.libg.LayerT5.getAutoAdjustLineColor()
    invoke ,, nxm.sys.libg.LayerT5.setAutoAdjustLineColor(^booleantrue)

    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

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

      plot/id=timepipe ^{datDir}.world.prm readoutExt=+SHOW|-FEATURES|+POINTS readout=+OnAxis|+AlwaysDeltas &
                             view=latloncontinuous  Y1=-90 Y2=90

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


    pipe off

    invoke ,, nxm.sys.libg.LayerT5.setAutoAdjustLineColor(^origT5Setting)

  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})
      set has1stLayer true
    elseif has2ndLayer isFalse then
      invoke ,, reg.timepipe.openFile(_t5pipe2{LAYER={^ellipselayerPIPE2},TAG=QUADPIPE})
      set has2ndLayer true
    else
      say "no more layers to add"
    endif
  elseif msg.name eqs "SHOWDIAGONAL" then
    if msg.data EQS "HIDE" then
      invoke ,, reg.timepipe.layers.diag.setEnable(-GLOBAL)
    else
      invoke ,, reg.timepipe.layers.diag.setEnable(+GLOBAL)
  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
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

!*****************************************************************************
! create blue file for this test
!*****************************************************************************
procedure createBlue

  %CONVERT_CSV_TO_T5000 ^csvFile ^grpTable ^test_blue_file rf=ecr

return
