! Tests LayerT5 Ellipsoids for CSV files
!
! @bug      NXM-3934 LayerT5 Ellipsoid Support
! @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)

  if interAct then
    call setDatDir

    ! define each layers' settings (including data type, autoselect, and select messages being enabled)
    set csvColumnNames "D:ALT,D:LAT,D:LON,NAME,D:ELLIPSOIDMAJ,D:ELLIPSOIDMIN,D:ELLIPSOIDMED,D:ELLIPSOIDROTX,D:ELLIPSOIDROTY,D:ELLIPSOIDROTZ,&
                        B:F1,B:F2,B:F3,B:F4,B:F5,B:F6,B:F7,B:F8,Z:NOTE"
    set layerXYZCSV "LT=T5,TimeOrder=TRUE,NAME=XYZCSV,DATATYPE="XYZ",SIZE=20,AutoselectEnable=CLICK,AutoSelectMode=PIXEL,SELECTCOLOR=BLUE,X=LON,Y=LAT,Z=ALT,LABEL=NAME,METAPOS=METADATA"
    set layerGEOCSV "LT=T5,TimeOrder=TRUE,NAME=GEOCSV,SIZE=20,AutoselectEnable=CLICK,AutoSelectMode=PIXEL,SELECTCOLOR=BLUE,X=LON,Y=LAT,Z=ALT,LABEL=NAME,METAPOS=METADATA"
    set qualsXYZCSV {HEADERROWS=L:1,COLUMNNAMES="^csvColumnNames",LAYER={^layerXYZCSV},TAG=CSVFILEXYZ}
    set qualsGEOCSV {HEADERROWS=L:1,COLUMNNAMES="^csvColumnNames",LAYER={^layerGEOCSV},TAG=CSVFILEGEO}

    set instructions "Should see plots of ellipsoids via a CSV file.\n\n&
                      In BOTH plots, the bottom point's ellipse should have no rotation in any direction.\n\n&
                      In BOTH plots, the top point's ellipse should have rotation about all three axes as described:\n  &
                      - About the X-axis (EAST in ENU) 20 degrees\n  &
                      - About the Y-axis (NORTH in ENU) 45 degrees\n  &
                      - About the Z-axis (UP in ENU) 90 degrees\n\n&
                      NOTE: Everything should be verified both visually and by looking at ctrl-click popups.\n\n&
                      If all tests passed, please click PASS to 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 13 /title

      ! 3DGRAPH/XYZ plot with custom axis labels
      !   1) regular readout and axis numbers are disabled, as they display the -1.2 to 1.2 values like XYZ view and are useless
      !   2) extended readout point counts could be enabled if this were part of a LayerDrawable
      plot/id=xyzcsvplot/msgid=main nxm.sys.test.ellipsoid5000.csv^qualsXYZCSV view=3DGRAPH &
             AXIS=-RNUMBERS|-BNUMBERS xlabel=EAST ylabel=NORTH zlabel=UP

      ! GEODETIC plot
      !   Note: Real usage would be best if all the layerT5 layers were part of a LayerDrawable
      !   That would allow point selection to be coordinated among layers and the point count to show on the extended readout
      !   Additional information: You have a layer or layers of symbols too (currently only available via setPoint(Table) API
      plot/id=geocsvplot/msgid=main ^{datDir}.world.prm|nxm.sys.test.ellipsoid5000.csv^qualsGEOCSV view=GEODETIC readout=+OnAxis

      ! SHELLGUI for message display
      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" or msg.name EQS "PANOBS"
  elseif msg.name eqss "ADDELLIPSOID"
    call addEllipsoid
  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
