!******************************************************************************!
! Tests new continuous lat/lon mode for LayerPoly and LayerDrawable
!
! Arguments: none
!
! @bug      NXM-3284 Need Continuous Lat/Lon Plot
! @since    3.9.0
! @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 numRedCircles 40

  if interAct then
    set instructions "In the Map... \n&
                      You should see a map of the world with Alaska, SV1, and SV2 plotted, as &
                      well as ^{numRedCircles} red circle Features. \n\n&
                      1. Pan through continuous Longitude in both of the maps &
                      (mouse panning should be smooth and not jump around) \n\n&
                      2. Zoom in and pan again.\n\n&
                      3. Press the 'Pan to Edge' button to check that the state vector is split &
                      on the edges and not streched across the screen \n\n&
                      In the Bottom Plot... \n\n&
                      1. Select in various places within the plot using LMB, &
                      the colors of the Venn diagram (RED/GREEN/BLUE) or the vertical YELLOW bar &
                      will be reported in the Shell."

    set hasSV2 true
    set hasSV3 false

    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 26 /title
      gcontrol button pan "" "Pan To Edge" 

      ! Change the keyMap to custom settings
      env set KEYMAP {PLOT={LEFT="L",RIGHT="R",in=i,down=d,up=u,out=o}}

      plot/id=plot1 ^{datDir}.world.prm|^{datDir}.alaska.prm|&
                   {LT="Drawable",name="SPACE"}|&
                   {LT="Drawable",name="FEATGROUP"}|&
                   ^{datDir}.sv1.prm{LAYER={NAME="SV1",group="SPACE"}}|&
                   ^{datDir}.sv2.prm{LAYER={NAME="SV2",group="SPACE"}} view=latloncontinuous

      ! now add a bazillion features to the plot
      call addFeatures

      plot/id=plot2 ^{datDir}.world.prm|{LT="Drawable",name="VENN"}  /MSGID=MAIN  view=latloncontinuous

      set layVenn reg.plot2.layers.VENN
      feature ,, vennRed    {NAME="RED",   LINE={COLOR="#66FF0000"},LAYER=layVenn,TYPE=BOX|FILLED, X=-180,Y=60,DX=50,DY=50} PLOT2
      feature ,, vennGreen  {NAME="GREEN", LINE={COLOR="#6600FF00"},LAYER=layVenn,TYPE=BOX|FILLED, X=-100,Y=-20,DX=30,DY=30} PLOT2
      feature ,, vennBlue   {NAME="BLUE",  LINE={COLOR="#660000FF"},LAYER=layVenn,TYPE=BOX|FILLED, X=0,Y=20,DX=25,DY=25} PLOT2
      feature ,, vennYellow {NAME="YELLOW",LINE={COLOR="#99FFFF00"},LAYER=layVenn,TYPE=VBAR|FILLED,X=180,Y=-40,DX=15,DY=15} PLOT2
      feature ,, vennWhite  {NAME="WHITE", LINE={COLOR="#66AAAAAA"},LAYER=layVenn,TYPE=CIRC|FILLED,X=100,Y=10,DX=30,DY=30} PLOT2
!      !feature ,, vennPink {NAME="PINK",LINE={COLOR=PINK},LAYER=layVenn,TYPE=ELPS|FILLED,X=140,Y=0,DX=25,DY=40,SEMIMAJOR=10,SEMIMINOR=10,TILT=30} PLOT2 !Add if BUG 2940 is worked

      shellgui/id=idshellgui/attach

!      gcontrol button listButt  "List Features               " "FEAT" "" /TLeft

    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 "LISTBUTT" then
    if msg.data eqs "FEAT"
      invoke t:featObjs layFeats.getDrawables("FEATURES",true)
      res t:featObjs
    endif
  elseif msg.name eqs "PAN" then
    invoke nxm.sys.test.TestLayerDrawable.panTest(reg.plot1)
  elseif msg.fid EQS "PLOT2" then
    if msg.name EQS "MARK" then
      invoke matches REG.PLOT2.LAYERS.VENN.getDrawablesAt(msg.data)

      if (matches.size == 0) then
        say "Selected colors: <NONE>"
      else
        say/L=0 "Selected colors:"
        for f in matches
          say/L=0 " ^f.name"
        endfor
        say/L=1 ""
      endif
    endif

  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

!******************************************************************************!
! Make a bazillion features and add them to the plot
!******************************************************************************!
procedure addFeatures

  ! initial values for the feature
  set featX -100
  set featY -80

  ! create variables to easily access LayerDrawables Layers
  set layFeats reg.plot1.layers.featGroup
  set laySpace reg.plot1.layers.space

  ! Add some features to the feature group layerDrawable
  do featNum 1 ^numRedCircles
    feature label=f_^{featNum} table={NAME="FEAT_^{FEATNUM}",LAYER=layFeats,TYPE="CIRC",X=featX,Y=featY,DX=5,COLOR="RED"} plot=plot1
    calc featX featX 3 +
    calc featY featY 1 +
  enddo

return

!******************************************************************************!
! Make a few (10) more features and add them to the plot
!******************************************************************************!
procedure addMoreFeats

  do addSome 1 10 1
    calc L:featNum featNum 1 +
    feature label=f_^{featNum} table={NAME="FEAT_^{FEATNUM}",LAYER=layFeats,TYPE="CIRC",X=featX,Y=featY,DX=5,COLOR="RED"} plot=plot1
    calc featX featX 3 +
    calc featY featY 1 +
  enddo

return

!******************************************************************************!
! remove some (10) of the features
!******************************************************************************!
procedure remFeats
  do remSome 1 10 1
    if featNum gt -1 then
      !invoke ,, layFeats.removeDrawable("FEAT_^{featNum}")   ! alternate way of doing it
      invoke ,, reg.plot1.removeFeature("FEAT_^{featNum}")
      calc L:featNum featNum 1 -

      ! the lines below  prevent the features position from creeping off the screen
      calc featX featX 3 -
      calc featY featY 1 -
    endif
  enddo
return

