!
! Test the plotting of files for LayerVehicle.
!
! Author:  J. Czechowski IV
!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE

  call setDatDir

  if interAct then
    ! These are just good test cases. The first one is for DirecTV, the second
    ! is for Sirius. These are just approximate numbers that I found on the web,
    ! not anything useful beyond this test. The SPACEWAY-1 is a good test case
    ! where the horizon line crosses 180/-180 lat. The Radiosat 1 is a good test
    ! case that is not on the equator.
    set areLayersClear true
    set myveh1 {POINTS={}}
    set myveh1.attributes     {COLOR=Yellow,Symbol=Cross}
    set myveh1.location       {LABEL="SPACEWAY-1",POS={ALT=3.49E7,LAT=0,LON=-102.8}}
    set myveh1.location.ATTRIBUTES {SYMBOL=DIAMOND}
    set myveh1.site           {LABEL="El Segundo, CA",POS={ALT=0,LAT=33'55'17,LON=-118'24'22}}
    set myveh1.points.UPLINK  {POS={ALT=0,LAT=33'55'17,LON=-118'24'22},CANGLE=0.4,LABEL=""}
    set myveh1.points.UPLINK.ATTRIBUTES {SYMBOL=Plus,Color=Purple}

    set myveh2 {POINTS={}}
    set myveh2.attributes     {COLOR=Cyan,Symbol=Cross}
    set myveh2.location       {LABEL="Radiosat 1",POS={ALT=1.79E7,LAT=63.8,LON=-100}}
    set myveh2.location.ATTRIBUTES {SYMBOL=DIAMOND}
    set myveh2.site           {LABEL="Vernon, NJ",POS={ALT=0,LAT=41.2,LON=-74.5}}
    set myveh2.points.UPLINK  {POS={ALT=0,LAT=41.2,LON=-74.5},CANGLE=0.4,LABEL=""}
    set myveh2.points.UPLINK.ATTRIBUTES {SYMBOL=Plus,Color=Blue}

    ! This one tests Bug 1280 with respect to a clipping problem near the poles
    set myveh3 {POINTS={}}
    set myveh3.attributes     {COLOR=Magenta,Symbol=Cross}
    set myveh3.location       {LABEL="BUG1280",POS={ALT=3.49E7,LAT=10,LON=0}}
    set myveh3.site           {ATTRIBUTES={VISIBLE=FALSE}}

    ! This one tests Bug 1404 with respect to symbol angle
    set myveh4 {POINTS={}}
    set myveh4.attributes     {COLOR=Orange,Symbol=Aero,SymbolSize=12,SymbolFill=TRUE}
    set myveh4.location       {LABEL="AIRPLANE",POS={ALT=0,LAT=0,LON=0}} ! StateVector set after layer is up
    set myveh4.site           {ATTRIBUTES={VISIBLE=FALSE}}

    ! This one tests NXM-3968 ability to control marking per vehicle
    set myveh5 {POINTS={}}
    set myveh5.attributes     {COLOR=WHITE,Symbol=Aero,SymbolSize=12,SymbolFill=TRUE,MARKER=FALSE}
    set myveh5.location       {LABEL="JAY",POS={ALT=4E7,LAT=20,LON=20}} ! StateVector set after layer is up
    set myveh5.site           {ATTRIBUTES={VISIBLE=FALSE}}

    set instructions "1) Verify SPACEWAY-1 (DirecTV) is over the Pacific near &
      the Equator with site located in El Segundo, CA.\n\n2) Verify &
      Radiosat 1 (Sirius) is over Canada with site in Vernon, NJ.\n\n3) Verify &
      an airplane exists south of London heading NorthWest.\n\n4) Verify the &
      footprint of BUG1280 includes the North Pole.\n\n5) Verify an additional &
      purple footprint exists at -45,-45 that is shaped like a triangle.&
      \n\n6) Zoom into the El Segundo site, change the Opaqueness and Alpha &
      sliders, and verify the change in the opacity.\n\n7) Select the GEO &
      View button, rotate earth 360 degress.  Verify no exceptions are & 
      displayed in the console.\n\n&
      8) Test clear/populate layers in both geo and latlon views"

    pipe init
      panel/setup/controls=gc
      plot/id=idplot ^{datDir}.world.prm|^{datDir}.capital_cities.prm|{LT=Vehicle,CONEFILL=TRUE}&
                                          |{LT="nxm.sys.test.test_plot_layervehicle$LayerVehicleFixedPosp",CONEFILL=TRUE} view=latlon

      call setup

      gcontrol label mainLab "Main" Open
      gcontrol menu  main    "Exit with Status = " "PASS,FAIL" /tleft
      gcontrol text  idtext  "Instructions"        "^instructions" 24 34 /title
      
      gcontrol lval opaqueNess   "Opaqueness " 50 0 100 1 /tleft /slider
      gcontrol lval alpha        "Alpha      " 127 0 255 1 /tleft /slider
      
      ! Instruction #7 and this button are related to Bug 2769
      gcontrol button changeView   "Change Views"          "Geo,LatLon"
      gcontrol button clearLayers  "Clear/Populate Layers" "Clear,Populate"

      set gc.main.itemColors {PASS=GREEN,FAIL=RED}
    pipe off
  endif
endmacro

!******************************************************************************!
! 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

!******************************************************************************!

procedure setup
  if areLayersClear isTrue
    set lay   reg.idplot.layers.vehicle
    set layfp reg.idplot.layers.VEHICLEFIXEDPOSP

    set lay.vehicle("MYVEH1") myveh1
    set lay.vehicle("MYVEH2") myveh2
    set lay.vehicle("MYVEH3") myveh3
    set lay.vehicle("MYVEH4") myveh4
    set lay.vehicle("MYVEH5") myveh5

    invoke ,, layfp.setFixedPosp(0,-45,-45)
    set layfp.vehicle("MYVEH1") myveh1
    invoke mv1 layfp.getVehicle("MYVEH1")
    invoke nxm.sys.test.test_plot_layervehicle.setSampleFootprint(mv1,"UPLINK")

    new nxm.sys.lib.StateVector sv4
    invoke ,, sv4.setGeo(0,51,0)
    invoke ,, sv4.setHeadingSpeed(315,500)
    set lay.vehicles.myveh4.location.sv sv4
    set areLayersClear false
  endIf
return

procedure processMessage m:msg
  if /verbose then say "^reg.main.name: Got message name=^msg.name, info=^msg.info, data=^msg.data"

  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: Interactive tests" msg.data eqss "PASS"
    pipe stop
  elseif msg.name EQS "OPAQUENESS" then
    set lay.opaqueness ^msg.data
    set  gc.alpha.value lay.alpha
  elseif msg.name EQS "ALPHA" then
    set lay.alpha ^msg.data 
    set gc.opaqueness.value ^lay.opaqueness
  elseif msg.name eqs "changeView" then
    if msg.data eqs "GEO" then
      invoke ,, reg.idplot.setView("GEO")
    else
     invoke ,, reg.idplot.setView("LATLON")
    endif
  elseif msg.name eqs "CLEARLAYERS" then
    if msg.data EQS "CLEAR" then
      invoke ,, reg.idplot.clearData
      set areLayersClear true
    else
      call setup
    message FUNC=send ID=IDPLOT NAME=OPENFILE DATA="^{datDir}.capital_cities.prm"
    endif
  else
    warn "^reg.main.name: Unhandled message name=^msg.name, info=^msg.info, data=^msg.data"
  endif
return
