! Tests Symbols and Icons on LayerT5
!
! @bug      NXM-3910 Point3D/LayerT5 support for Symbols / Icons
!           NXM-4204 Features/Symbols need more detailed text on selection
!
! @since    4.1.2
! @author:  Zachary Matthews
!******************************************************************************!
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

  set t:ellipse5000_data {}
  set t:ellipse5000_data.0 {POS=(0,0,0),POSP=(0,-1,-5),NAME="STAR",SYMBOL="SQUARE"}
  set t:ellipse5000_data.1 {POS=(0,5,5),POSP=(0,9,9),NAME="AERO",SYMBOL="AERO"}
  set t:ellipse5000_data.2 {POS=(0,10,10),POSP=(0,13,7),NAME="RTRIANGLE",SYMBOL="UTRIANGLE"}
  set t:ellipse5000_data.3 {POS=(0,15,15),POSP=(0,11,11),NAME="SQUARE",SYMBOL="AERO"}
  set t:ellipse5000_data.4 {POS=(4000000,20,20),POSP=(4000000,15,25),NAME="ARROWPNG",SYMBOL="Arrow.png"}
  header/create ram:t5_starter.tmp TYPE=5000 RF=ECR COMPONENTS=(POS/VD/GEODETIC/DISTANCE_M,POSP/VD/GEODETIC/DISTANCE_M,&
                                                                NAME/2A/UNDEFINED/NONE,SYMBOL/2A/UNDEFINED/NONE)
  foreach keyIdx INTABLE ellipse5000_data
    file open/d/a out ram:t5_starter.tmp
      invoke ,, out.setData(keyIdx,ellipse5000_data.^{keyIdx})
    file close out
  endfor

  set layerXYZ         "LT=T5,NAME=XYZDATA,DATATYPE="XYZ",AutoselectEnable=CLICK,AutoSelectMode=PIXEL,SELECTCOLOR=WHITE,SELECTMESSAGES=TRUE"
  set ellipselayerPIPE "LT=T5,TimeOrder=False,Group=t5Group2,NAME=DIAG,AutoselectEnable=CLICK,AutoSelectMode=PIXEL,SELECTCOLOR=AQUA,SELECTMESSAGES=TRUE"

  set csvColumnNames "D:ALT,D:LAT,D:LON,D:POSPX,D:POSPY,D:POSPZ,NAME,B:F1,B:F2,B:F3,B:F4,B:F5,B:F6,B:F7,B:F8,Z:NOTE,SYMBOL"
  set layerCSV "LT=T5,TimeOrder=TRUE,Group=t5Group,NAME=CSV,SIZE=20,AutoselectEnable=CLICK,AutoSelectMode=PIXEL,SELECTCOLOR=YELLOW,X=LON,Y=LAT,Z=ALT,LABEL=NAME,METAPOS=METADATA"
  set qualsCSV {HEADERROWS=L:1,COLUMNNAMES="^csvColumnNames",LAYER={^layerCSV},SELECTIONKEYS="NAME,POS",TAG=CSVFILE}

  set hasPipedLayer false

  if interAct then
    set instructions "This test case reads in Type 5000 data with SYMBOL components specified, and then plots it\n\n&
                      ********         TOP PLOT              ********\n&
                      1. The top plot should have five different symbols plotted diagonally.\n\n&
                      ********        MIDDLE PLOT            ********\n&
                      1. The middle plot should have five different symbols plotted from a csv.\n\n&
                      ********        BOTTOM PLOT            ********\n&
                      1. Click 'Add .. Layer' to get yellow diagonal points\n&
                      2. Zoom in so that the Symbol of each point is visible.\n&
                      3. The diagonal points should all be using AERO symbols.\n\n&
                      If all tests passed, please pass this test."
    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=csv ^{datDir}.world.prm|{LT="Drawable",name=t5Group,listlayers=true}|nxm.sys.test.symbol5000.csv^{qualsCSV} &
       readoutExt=+SHOW|-FEATURES|+POINTS readout=+OnAxis|+AlwaysDeltas view=latloncontinuous

      plot/id=xyzplot/msgid=main t5_starter.tmp{Layer={^{layerXYZ},SELECTIONKEYS="NAME,POS"}} view=YX  readoutExt=+SHOW|-FEATURES|+POINTS readout=+OnAxis|-Scientific|+DateString

      nxm.sys.test.plotellipsetester/DIAGONAL/DIRECTCOLOR=YELLOW/NOFLAGS/NOTEMODETYPE=4Z/SYMBOL=AERO/RT/RATE=500/STARTTIME="2007:01:02::00:00:00" OUT=_t5pipe{SIZE=10000} ELEM=Inf
      plot/id=timepipe/msgid=1 ^{datDir}.world.prm|{LT="Drawable",name=t5Group2,listlayers=true} readoutExt=+SHOW|+POINTS &
               readout=+OnAxis|+AlwaysDeltas view=latloncontinuous Y1=-90 Y2=90

      gcontrol/nc=1 button ADDLAYER "" "Add a piped Layer" ""

    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 "ADDLAYER" then
    if hasPipedLayer isFalse then
      invoke ,, reg.timepipe.openFile(_t5pipe{LAYER={^ellipselayerPIPE,FormRegions=true},TAG=DIAGPIPE})
      set hasPipedLayer true
    else
      say "No more piped layers to add"
    endif
  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
