!******************************************************************************!
! Test the plotting of LayerGeo in Geodetic View and checks for extra
! TDOA/FDOA contours.
!
! Bug:    NXM-4002 LayerGeo erroneous FDOA/StateVector line drawn
!                  around the North Pole in Geodetic view
! Since:  NeXtMidas 4.1.3
! 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

    set instructions "Broken behavior: The plot has extra TDOA (red) and FDOA (yellow) contour lines tightly around the North Pole.\n&
                      _________________________________________________________\n&
                      Note: \n&
                      TODO: Fix Contour and ContourHighPrecision drawContour to not think it needs to do drawLine in these conditions. This affects GEODETIC view only."

    invoke GEODETIC nxm.sys.lib.Position.GEODETIC
    invoke tdoamodeList nxm.sys.libg.LayerGeo.tdoamodeList
    invoke fdoamodeList nxm.sys.libg.LayerGeo.fdoamodeList

    pipe init
      panel/msgid=MAIN/setup/controls=gc
      plot/id=idplot/msgid=MAIN ^{datDir}.world.prm view=geo

      gcontrol label mainLab "MACRO" Open
      gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
      set gc.main.itemColors {PASS=GREEN,FAIL=RED}
      gcontrol text idtext "Instructions" "^{instructions}" 24 8 /title

      call initializeLayerGeo
      call panLayerGeoPlot
    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
  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

!******************************************************************************!
! Initialize the LayerGeo
!******************************************************************************!
procedure initializeLayerGeo
  new nxm.sys.lib.Position(GEODETIC) site
  set site.lat 10
  set site.lon 10
  set site.alt 0
  layer "Geo" geoLayer {NAME=GL,SVA=^{datDir}.sv1.prm,SVB=^{datDir}.sv2.prm,&
                        SVALABEL="SVA",SVBLABEL="SVB",&
                        SITE=site,SITELABEL="MYSITE",TARGETLABEL="Target",&
                        FLAGS="ALL",CONIC=1,TDOAMODE="Contour",FDOAMODE="Contour",&
                        TDOA=0,FDOA=0,DTDOA=-3,DFDOA=-3} idplot

  ! Set the target position
  new nxm.sys.lib.Position(GEODETIC) tPos
  set tPos.lat 5
  set tPos.lon -100
  set geolayer.pos tPos

  ! Set the pointing position A
  new nxm.sys.lib.Position(GEODETIC) pA
  set pA.lat -75
  set pA.lon -75
  set geolayer.pointposA pA

  ! Set the pointing position B
  new nxm.sys.lib.Position(GEODETIC) pB
  set pB.lat -45
  set pB.lon -45
  set geolayer.pointposB pB
return

!******************************************************************************!
! Pan the LayerGeo Plot to check for extra TDOA/FDOA contours drawn at the North Pole
!******************************************************************************!
procedure panLayerGeoPlot
  invoke dblarray nxm.sys.test.TestUtil.createDoubleArray("0.7258064516129032,53.95161290322581,6.0")
  message send IDPLOT name=PANOBS info=-7 QUALS={ORIG_MSG_DATA={X=L:413,Y=L:227,W=L:-3,H=L:63}} DATA=dblarray
return
