!******************************************************************************!
! Test re-scaling of map PLOTs.  Plot should scale to smallest dimension, so entire map is shown.
!
! Issue: NXM-2919 Plot does not scale to smallest dimension
!
! @author:  Jeanette McCall
! @since    NeXtMidas 3.7.1
!******************************************************************************!
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)
  switch COREGRAPHICS coreGraphics     GET DEF=FALSE SDEF=TRUE ! for a quick check of graphics - more extreme tests - since 3.8.1

  if interAct or coreGraphics then
    ! NXM-3845 since NeXtMidas 4.1.1
    call setDatDir

    res world_file world_ram{AUX=RAM}
    file copy ^{datDir}.world.prm world_file
    file unprotect world_file

    res outer_limit_x1 -50

    set instructions "You should see 5 map plots. \n\n&
                      1) Try shrinking the Window vertically and make sure the entire maps show.\n\n&
                      2) Expand back to regular size and make sure the maps display properly.\n\n&
                      3) Try expanding and shrinking the Window in the horizontal direction. Making sure &
                      each of the maps continue display properly in their entirety (no portions cut off)\n\n&
                      4) Click the 'Outer Limit..' button and resize. When shrunk small enough horizontally, the &
                       minimum Longitude displayed will be ^{outer_limit_x1} for the LatLon, Mercator, and Polar views.\n\n&
                      5) Click the 'Zoom' button and resize.  All of the views except Polar should shrink down &
                      as far as Africa, continue to show all of Africa. Polar is zoomed to the North Pole.\n\n&
                      Note: Prior to the fix for NXM-2919 dramatic re-sizing would cause the extreme top/bottom &
                      or left/right of the world to be cut off. Care should be taken to see that the whole &
                      of the world is displayed."

    pipe on
      httpserv 9080 DIR="nxm/sys/test" NAME="test"

      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 32 /title

      result airportQuals {HEADERROWS=1,LAYER={LT="Scatter",X="LONGITUDE",Y="LATITUDE",LINE={COLOR="red",TYPE="symbol"}}}
      plot/id=plot_ll  world_file|^{datDir}.airports.csv^{airportQuals} view=latlon
      plot/id=plot_geo ^{datDir}.world.shp view=geodetic
      plot/id=plot_pol world_file view=polar
      plot/id=plot_mer ^{datDir}.world.shp|&               ! updated to KML for NXM-2938
                       nxm.sys.test.kmlTest.kml{LAYER={ICONSIZE=10,ICONZOOMSIZE=48,COLORBLENDRATIO=0.8,ALLOWPOPUPS=FALSE}} &
                       view=mercator
      plot/id=plot_xyz ^{datDir}.world.shp view=xyz

      gcontrol button setouterlimit "" "Outer Limit X1=^{outer_limit_x1} LatLon/Mercator/Polar"
      gcontrol button zoom          "" "Zoom to Africa (or North Pole for Polar)"

    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 "SETOUTERLIMIT" then
    message send plot_ll  name=openfile data="world_file" quals={outerlimits={x1=^outer_limit_x1}}
    message send plot_mer name=openfile data="^{datDir}.world.shp" quals={outerlimits={x1=^outer_limit_x1}}
    message send plot_pol name=openfile data="world_file" quals={outerlimits={x1=^outer_limit_x1}}
  elseif msg.name eqs "ZOOM" THEN
    message send PLOT_LL  name=zoom DATA={X1=-20,X2=70,Y1=-37,Y2=45}       ! zoom to Africa
    message send PLOT_GEO name=zoom DATA={X1=-0.5,X2=1,Y1=-0.8,Y2=0.75}    ! zoom to Africa
    message send PLOT_MER name=zoom DATA={X1=-20,X2=70,Y1=-37,Y2=45}       ! zoom to Africa
    message send PLOT_XYZ name=zoom DATA={X1=-0.15,X2=0.4,Y1=-0.4,Y2=0.5}  ! zoom to Africa
    message send PLOT_POL name=zoom DATA={X1=-50,X2=50,Y1=-50,Y2=50}       ! zoom to North Pole
  else
    say "Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  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
