!******************************************************************************!
! Test that the plot renders correctly when zooming in on the map bounds when
! the range view is greater than 360 degrees.
!
! @bug      NXM-3981 Map zoom gives shifted partial map
! @since    4.1.3
! @author:  Zachary Matthews
!******************************************************************************!
startmacro
  switch INTERACTIVE  interAct     GET DEF=TRUE  SDEF=TRUE  ! for normal interactive test(s)
  switch COREGRAPHICS coreGraphics GET DEF=FALSE SDEF=TRUE  ! for a quick check of graphics - more extreme tests

  if interAct or coreGraphics then
    call setDatDir

    set instructions "Click through the button cycle on Right then Left.\n\n&
                      Expected: Plot X margins do not change.\n&
                      _________________________________________________________\n&
                      Failure Scenarios: \n&
                      Right Zoom:\n&
                      => If the world plot is slammed to the left, please FAIL this test.\n\n&
                      Pan after Right Zoom:\n&
                      => If the world plot is slammed to the right, please FAIL this test.\n\n&
                      Left Zoom:\n&
                      => If the world plot is slammed to the right, please FAIL this test."

    pipe on
      panel/msgid=MAIN/setup/controls=gc
      plot/id=worldPlot ^{datDir}.world.shp view=latloncontinuous
      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 14 /title

      gcontrol label rightZoomLabel "Right Side Zoom Testing"
      gcontrol Button rightZoomTestBtn  "" "START"  ""
      gcontrol label leftZoomLabel "Left Side Zoom Testing"
      gcontrol Button leftZoomTestBtn  "" "START"  ""
    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 "RIGHTZOOMTESTBTN" then
    if msg.data eqs "START" then
      invoke ,, gc.leftZoomTestBtn.setItem(1,"START")
      message FUNC=send ID=worldPlot NAME=openfile INFO=-1 DATA="^{datDir}.world.shp" QUALS={outerlimits={xmin=150,xmax=510,ymin=-90,ymax=90}}
      invoke ,, gc.rightZoomTestBtn.setItem(1,"ZOOM")
    elseif msg.data eqs "ZOOM" then
      invoke ,, gc.leftZoomTestBtn.setItem(1,"START")
      message FUNC=send ID=worldPlot NAME=zoom DATA={X1=480,X2=540,Y1=-75,Y2=75}
      invoke ,, gc.rightZoomTestBtn.setItem(1,"PAN")
    elseif msg.data eqs "PAN" then
      invoke ,, gc.leftZoomTestBtn.setItem(1,"START")
      invoke dblarray nxm.sys.test.TestUtil.createDoubleArray("350,400,-75,75")
      message FUNC=send ID=worldPlot NAME=panxy DATA=dblarray
      invoke ,, gc.rightZoomTestBtn.setItem(1,"START")
    endif
  elseif msg.name eqs "LEFTZOOMTESTBTN" then
    if msg.data eqs "START" then
      invoke ,, gc.RightZoomTestBtn.setItem(1,"START")
      message FUNC=send ID=worldPlot NAME=openfile INFO=-1 DATA="^{datDir}.world.shp" QUALS={outerlimits={xmin=-150,xmax=210,ymin=-90,ymax=90}}
      invoke ,, gc.leftZoomTestBtn.setItem(1,"ZOOM")
    elseif msg.data eqs "ZOOM" then
      invoke ,, gc.RightZoomTestBtn.setItem(1,"START")
      message FUNC=send ID=worldPlot NAME=zoom DATA={X1=-180,X2=-120,Y1=-75,Y2=75}
      invoke ,, gc.leftZoomTestBtn.setItem(1,"PAN")
    elseif msg.data eqs "PAN" then
      invoke ,, gc.RightZoomTestBtn.setItem(1,"START")
      invoke dblarray nxm.sys.test.TestUtil.createDoubleArray("-50,0,-75,75")
      message FUNC=send ID=worldPlot NAME=panxy DATA=dblarray
      invoke ,, gc.leftZoomTestBtn.setItem(1,"START")
    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
