!
! Test panning with PANOBS, PANY, and PANX messages
!
! LayerWMS is used along with the LayerT5 cities.prm to make it more sensitive
! to refresh related issues.  This is also use case that originally triggered
! the DR.
!
! Arguments:
!   layers      - layers to display
!   numFeatures - number of features on LatLon plot
!   useTiles    - use of tiles rather than a single image
!   numThreads  - number of download threads
!
! @bug      NXM-3034 PLOT: GEODETIC view panning, dragging broken
! @since    3.7.2
! @author:  Jeanette McCall
!******************************************************************************!
startmacro cs:url["http://nextmidas.com:8800/geoserver/ows"] &
           cs:layers["shapePolitical,Relief,cadrg,imint"] L:numFeatures[60] &
           S:useTiles["TRUE"] L:numThreads[2]  cs:crsOverride[""] &
           s:requestedVersion[""]
  switch INTERACTIVE interAct GET DEF=TRUE
  switch BASELINE    baseline GET DEF=FALSE
  switch IGNOREHREF  ignoreHREF GET DEF=FALSE SDEF=TRUE ! Ignore GetCapabilities HREF and use original URL

  invoke z:jvmHangFix nxm.sys.lib.Shell.getJVMHangWorkaround()
  res z:mytrue true
  invoke ,, nxm.sys.lib.Shell.setJVMHangWorkaround(^mytrue)

  call setDatDir

  call createOptEntriesTable

  if interAct then

    pipe on
      panel/msgid=MAIN/setup/controls=gc
      plot/id=llplot ^{datDir}.world.prm{ENABLE=+BS}|{LT=WMS,IGNOREHREF=^ignoreHREF,^{OPTENTRIES.WMS_VERSION}URL="^url",^{OPTENTRIES.CRS}&
        LAYERS="^layers",ENABLE=+BS,USETILES=useTiles,DOWNLOADTHREADS=numThreads} view=LatLon options=+dbuf &
        ZOOMTO={x1=-75,x2=-120,y1=10,y2=110}
      plot/id=geoplot {LT=WMS,IGNOREHREF=^ignoreHREF,^{OPTENTRIES.WMS_VERSION}^{OPTENTRIES.CRS}URL="^url",LAYERS="^layers",&
        ENABLE=+BS,USETILES=useTiles,DOWNLOADTHREADS=numThreads}|^{datDir}.cities.prm &
        view=Geodetic options=+dbuf



      gcontrol label macro "MACRO"
      gcontrol menu    main "Exit with Status = " "PASS,FAIL" /tleft
      set gc.main.itemColors {PASS=GREEN,FAIL=RED}

      set instructions "You should see two LayerWMS plots.  The top right plot should be a Geodetic view. &
                        The bottom right is a zoomed in LatLon View showing North America.\n\n&
                        Once the plots are fully downloaded:\n\n&
                        1) Use the RMB to PAN the Geodetic plot\n   &
                        The plot should render while panning.\n\n&
                        2) On the Zoomed in LatLon Plot:\n   &
                           a) click below the Vertical scroll bar to cause the plot\n      &
                              to page down (around 20).\n   &
                           b) click to the right of the Horizontal scroll bar to page\n      &
                              to the right (around -60).\n      &
                              Now part of South America should be visible.\n   &
                           c) try scrolling beyond the bounds of the plot.\n      &
                              You should not be able to scroll beyond the plot bounds.\n\n&
                        Click PASS if everything was as described.\n\n& 
                        _________________________________________________________\n&
                        Note:\n&
                        '1)' tests the PANOBS message\n&
                        '2)' tests the PANY and PANX messages&
                        "

       gcontrol text    idtext "Instructions" "^instructions" 24 30 /title


    pipe off

  endif  ! end if interAct

  invoke ,, nxm.sys.lib.Shell.setJVMHangWorkaround(^jvmHangFix)
endmacro

!******************************************************************************!
! Main process message for this macro.
!******************************************************************************!
procedure processMessage m:msg
  !say "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

  else
    say "Unhandled message name: ^msg.name from fid: ^msg.fid dats: ^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

!******************************************************************************!
! Create Table holding optional LayerWMS LAYER entries
!******************************************************************************!
procedure createOptEntriesTable

  TABLE OPTENTRIES CREATE {CRS="",WMS_VERSION=""}
  if CRSOVERRIDE STARTS "{" THEN
    table optentries SETKEY CRS "CoordRefSystems=^{crsOverride},"
  elseif CRSOVERRIDE NEQS "" THEN
    ! NXM-3743 support adding CRS entries by name
    table optentries SETKEY CRS "ByNameCRSs=^{crsOverride},"
  endif
  if REQUESTEDVERSION NEQS "" THEN
    table optentries SETKEY WMS_VERSION "RequestedVersion=^{requestedVersion},"
  endif

return
