!******************************************************************************!
! Both the ellipse being tiny and the ELLIPSE LOCATION are very important in this]
! test case. The high zoom code need to use Jeff's sin/cos table approach so
! lines are drawn in the correct location.
!
! @issue    NXM-3415 Feature in wrong location in Geodetic view
! @since    4.1.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

  res test_blue_file ellipseflagsmeta5000_tiny.tmp
  res csvFile        nxm.sys.test.ellipseflagsmeta5000_tiny.csv
  res grpTable       nxm.sys.test.ellipseflagsmeta5000grp.tbl
  call createBlue

  res L:diagRate 100
  calc L:diagPtsBuffer diagRate 5 *
  calc popupTime diagRate 20.0 /

  if interAct then
    set instructions "Toggle back and forth between views:\n\n&
                      The blue Feature ellipse should lie on top &
                      the yellow T5 ellipse.\n\n&
                      The yellow diamond and red circle features &
                      should be in the middle of the ellipse.\n\n&
                      The green cone should be near (GEO) or around (LATLON) &
                      the blue ellipse.&
                      "


    set ellipseColumnNames "D:ALT,D:LAT,D:LON,D:ETILT,D:EMIN,D:EMAJ,NAME,D:TIME,B:F1,B:F2,B:F3,B:F4,B:F5,B:F6,B:F7,B:F8,Z:NOTE"
    set ellipseLayerCSV "LT=T5,TimeOrder=TRUE,Group=t5Group,NAME=CSV,SIZE=6,AutoselectEnable=CLICK,AutoSelectMode=PIXEL,SELECTCOLOR=PINK,X=LON,Y=LAT,Z=ALT,LABEL=NAME,TIMELF=TIME,METAPOS=METADATA"
    set qualsEllipseCSV {HEADERROWS=L:1,COLUMNNAMES="^ellipseColumnNames",LAYER={^ellipseLayerCSV},TAG=CSVFILE}
    set ellipselayerPRM "LT=T5,TimeOrder=True,Group=t5Group,NAME=PRM,AutoselectEnable=CLICK,AutoSelectMode=PIXEL,SELECTCOLOR=AQUA"
    set qualsCone {HEADERROWS=L:1,COLUMNNAMES="D:X,D:Y,D:Z,D:POSPX,D:POSPY,D:POSPZ,D:CONEA,D:CONEB,D:CONEANGLE,NAME", LAYER={LT="T5"}}

    set has1stLayer false
    set has2ndLayer false

    invoke booleanfalse java.lang.Boolean.valueOf("false")
    invoke booleantrue java.lang.Boolean.valueOf("true")

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

      plot/id=timepts ^{datDir}.world.prm|{LT="Drawable",name=t5Group,listlayers=true}|&
                             ^test_blue_file{LAYER={^ellipselayerPRM},TAG=PRMFILE}|&
                             nxm.sys.test.cone5000_tiny.csv^{qualsCone} &
                                   readoutExt=+SHOW|-FEATURES|+POINTS &
                             readout=+OnAxis|+AlwaysDeltas view=geo

      gcontrol button changeview "" "ViewGeo,LatLon" 

      FEATURE label=pipebox table={NAME=PIPEBOX,TYPE=BOX,COLOR=AQUA,ENABLE=1} plot=timepipe

!11.34670487106017,113.98280802292263
    invoke dblarray nxm.sys.test.TestUtil.createDoubleArray("11.34670487106017,113.98280802292263,6.0")
      ! Send PANOBS matching plot.processMessage PANOBS message
    message send timepts name=PANOBS info=-7  QUALS={ORIG_MSG_DATA={X=L:517,Y=L:257,W=L:-72,H=L:57}} DATA=dblarray
    message send timepts NAME=ZOOM INFO=0 DATA={XMIN=11.905e-3,XMAX=11.93e-3,YMIN=21.155e-3,YMAX=21.175e-3}

      call addFeatures
    pipe off

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

  endif

    erase test_blue_file
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 "CHANGEVIEW" then
    if msg.data eqs "VIEWGEO" then
      set plotview "GEO"
      invoke ,, reg.timepts.setView("GEO")
      invoke dblarray nxm.sys.test.TestUtil.createDoubleArray("11.34670487106017,113.98280802292263,6.0")
      ! Send PANOBS matching plot.processMessage PANOBS message
      message send timepts name=PANOBS info=-7  QUALS={ORIG_MSG_DATA={X=L:517,Y=L:257,W=L:-72,H=L:57}} DATA=dblarray
      message send timepts NAME=ZOOM INFO=0 DATA={XMIN=11.9212e-3,XMAX=11.922e-3,YMIN=21.1636e-3,YMAX=21.164300e-3}
    elseif msg.data starts "LATLON" then
      set plotview "LATLON"
      invoke ,, reg.timepts.setView("LATLON")
      message send timepts NAME=ZOOM INFO=0 DATA={XMIN=-170.00001,XMAX=-169.9999,YMIN=64.999960,YMAX=65.00002}
    endif
  elseif msg.name eqss "GEODETIC" then
    invoke dblarray nxm.sys.test.TestUtil.createDoubleArray("11.34670487106017,113.98280802292263,6.0")
    ! Send PANOBS matching plot.processMessage PANOBS message
    message send timepts name=PANOBS info=-7  QUALS={ORIG_MSG_DATA={X=L:517,Y=L:257,W=L:-72,H=L:57}} DATA=dblarray
    message send timepts NAME=ZOOM INFO=0 DATA={XMIN=11.905e-3,XMAX=11.93e-3,YMIN=21.155e-3,YMAX=21.175e-3}
  elseif msg.name EQS "LATLON" then
    message send timepts NAME=ZOOM INFO=0 DATA={XMIN=-170.0019,XMAX=-169.9999,YMIN=64.99994,YMAX=65.00001}
  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

!******************************************************************************!
procedure addFeatures

  feature label=ydiamond table={NAME="Y_DIAMOND",SYMBOL=DIAMOND,&
                          COLOR=YELLOW,X=-170,Y=65,Z=1500,SYMBOLSIZE=12} plot=timepts

  feature label=ycircle table={NAME="R_CIRCLE",SYMBOL=CIRCLE,&
                          COLOR=RED,X=-170,Y=65,Z=1500,SYMBOLSIZE=8} plot=timepts

  feature label=bellipse table={NAME="P_ELLIPSE",TYPE="ELPS",X=-170,Y=65,Z=1500,&
                                SEMIMAJOR=4,SEMIMINOR=0.15,TILT=-70,&
                                COLOR="BLUE"} plot=timepts
return
