! Tests LayerT5 Ellipsoids for Type 5000 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

    ! creation of starter T5000 file
    set t:ellipsoid5000_data {}
    set t:ellipsoid5000_data.0 {POS=(0.0,0,0),NAME="JEREMY",ELLIPSOID=(100000,1000000,50000,0,0,0)}
    set t:ellipsoid5000_data.1 {POS=(3.0E6,20,20),NAME="JENNIFER",ELLIPSOID=(100000,1000000,50000,20,45,90)}
    table ellipsoid5000_data getsize tblSize
    header/create ram:t5_starter.tmp TYPE=5000 RF=ECR COMPONENTS=(POS/VD/GEODETIC/DISTANCE_M,NAME/1A/UNDEFINED/NONE,ELLIPSOID/6D/UNDEFINED/NONE)
    foreach l:keyIdx intable ellipsoid5000_data
      file open/d/a out ram:t5_starter.tmp
        invoke ,, out.setData(keyIdx,ellipsoid5000_data.^{keyIdx})
      file close out
    endfor

    ! set attributes for each of the snake plots
    res snakecolor "YELLOW"
    res snakerate 0.4
    invoke ,, nxm.sys.test.t5pathgenerator.setVaryNote(true)

    ! define each layers' settings (including data type, autoselect, and select messages being enabled)
    set layerXYZ "LT=T5,NAME=XYZDATA,DATATYPE="XYZ",AutoselectEnable=CLICK,AutoSelectMode=PIXEL,SELECTCOLOR=BLUE,SELECTMESSAGES=TRUE"
    set layerGEO "LT=T5,NAME=GEODATA,AutoselectEnable=CLICK,AutoSelectMode=PIXEL,SELECTCOLOR=BLUE,SELECTMESSAGES=TRUE"
    set layerXYZPipe "LT=T5,NAME=XYZDATAPIPE,DATATYPE="XYZ",AutoselectEnable=CLICK,AutoSelectMode=PIXEL,SELECTCOLOR=BLUE,SELECTMESSAGES=TRUE"
    set layerGEOPipe "LT=T5,NAME=GEODATAPIPE,AutoselectEnable=CLICK,AutoSelectMode=PIXEL,SELECTCOLOR=BLUE,SELECTMESSAGES=TRUE"

    set instructions "Should see plots of ellipsoids via Type 5000 files.\n\n&
                      The TOP plots show fixed data.\n  &
                      - In the TOP plots, the bottom point's ellipse should have no rotation in any direction.\n  &
                      - In the TOP 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&
                      The BOTTOM plots show piped data.\n  &
                      - In the BOTTOM plots, for every group of four points, each ellipse should have rotation as described:\n    &
                        - First point's ellipse: Only about the X-axis (EAST in ENU) 45 degrees\n    &
                        - Second point's ellipse: Only about the Y-axis (NORTH in ENU) 25 degrees\n    &
                        - Third point's ellipse: Only about the Z-axis (UP in ENU) 60 degrees\n    &
                        - Fourth point's ellipse: No rotation in any direction\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 20 /title
      nxm.sys.test.t5pathgenerator/TRAJECTORY/NAME="XYZELLIPSOID"/XYZ/INCR=10/ALT_START=0/LAT_START=0/LON_START=0&
                                  /ALT_DEST=2000000000/LAT_DEST=40000000/LON_DEST=50000000/ALT_SHIFT=0/LON_SHIFT=5000000/LAT_SHIFT=0&
                                  /NOELLIPSE/ELLIPSOID/ROTATE/DIRECTCOLOR=^snakecolor/NOFLAGS/RT/NOTEMODETYPE=QA/RATE=^snakeRate OUT=_xyzEpsoid{SIZE=10000} ELEM=Inf /bg
      nxm.sys.test.t5pathgenerator/TRAJECTORY/NAME="GEOELLIPSOID"/INCR=30/ALT_START=0/LAT_START=0/LON_START=0&
                                  /ALT_DEST=10000000/LAT_DEST=80/LON_DEST=180/ALT_SHIFT=20000/LON_SHIFT=20/LAT_SHIFT=0&
                                  /NOELLIPSE/ELLIPSOID/ROTATE/DIRECTCOLOR=^snakecolor/NOFLAGS/RT/NOTEMODETYPE=QA/RATE=^snakeRate OUT=_geoEpsoid{SIZE=10000} ELEM=Inf /bg

      ! 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=xyzplot/msgid=main t5_starter.tmp{Layer={^layerXYZ}} 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=geoplot/msgid=main ^{datDir}.world.prm|t5_starter.tmp{Layer={^layerGEO}} view=GEODETIC readout=+OnAxis

      ! Piped 3DGRAPH/XYZ plot with custom axis labels
      plot/id=xyzplotpipe/msgid=main _xyzEpsoid{Layer={^layerXYZPipe}} view=3DGRAPH &
             AXIS=-RNUMBERS|-BNUMBERS xlabel=EAST ylabel=NORTH zlabel=UP

      ! Piped GEODETIC plot
      plot/id=geoplotpipe/msgid=main ^{datDir}.world.prm|_geoEpsoid{Layer={^layerGEOPipe}} view=GEODETIC x1=-180 x2=180 y1=-90 y2=90 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 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
