!******************************************************************************!
! Test the plotting of Type 5000 files (LayerT5).
!
! Author:  J. Hallam, J. Czechowski
!******************************************************************************!
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 KEEP         keep         GET DEF=FALSE SDEF=TRUE
  switch COREGRAPHICS coreGraphics GET DEF=FALSE SDEF=TRUE  ! for a quick check of graphics - more extreme tests - since 3.8.1

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

  if interAct or coreGraphics then
    call setDatDir

    mergefile ^{datDir}.cities.prm temp_testplot_cities /replay=40
    nxm.sys.test.plotellipsetester OUT="temp_testplot_hugefile" ELEM=10K
    !set startPoint 0
    set labelEllipse "Test clearing point by point"
    set labelPipe "Test Point Timeouts"
    res pointTimeout 2

    pipe on
      nxm.sys.test.plotellipsetester/DIAGONAL/RT/RATE=10/TL=1 OUT=_t5pipe{SIZE=150000} ELEM=Inf
      nxm.sys.test.plotellipsetester/RT/RATE=1000/TL=25 OUT=_t5pipe2{SIZE=150000} ELEM=Inf

      panel/msgid=MAIN/setup/controls=gc
      plot/mousewheelzoom/usemouseposition/id=idplot x1=-180 x2=180 y1=-90 y2=90 view=latloncontinuous &
                      readout=+onAxis|+AlwaysDeltas

      gcontrol label macro "MACRO"
      gcontrol menu    main "Exit with Status = " "PASS,FAIL" /tleft
      set gc.main.itemColors {PASS=GREEN,FAIL=RED}
      gcontrol text    idtext "Instructions" "initializing..." 24 22 /title
      gcontrol/nc=3 button nextplot "File" &
        "Cone,ConeFlag,Ellipse,EllipseFlag,ZeroSize,Positions,LargeFile,HugeFile,Pipe,Pipe2" none
      gcontrol/nc=2 button setflag  "Set Flag" &
        "SymbolsOn,LabelsOn,EllipsesOn,ConesOn,SymbolsOff,LabelsOff,EllipsesOff,&
         ConesOff" none
      gcontrol pipemon idmon  _t5pipe
      gcontrol/nc=1 button clearLayers "" "Clear all layers" ""
      gcontrol/nc=1 button specialAction "" "Test"
      invoke gc.specialAction.panel.setVisible(false)

    pipe off

    if keep isFalse then
      erase/quiet/warn=n "temp_testplot_cities"
      erase/quiet/warn=n "temp_testplot_hugefile"
      erase/quiet/warn=n "ram:temp_testplot_layert5_zerosize"
    endif
  endif

  ! Additional interactive tests, only run with /BASELINE
  if interAct and baseline then
    %test_plot_layert5_clusters_drawable         ! NXM-2968
    %test_plot_layert5_clusters_fixed            ! NXM-2968 NXM-3512
    %test_plot_layert5_clusters_pipe             ! NXM-2968
    %test_plot_layert5_color_cntrl               ! Bug 2823 Bug 2875
    %test_plot_layert5_count_points_range_fixed  ! NXM-3542
    %test_plot_layert5_count_points_range_pipe   ! NXM-3542
    %test_plot_layert5_counts                    ! NXM-3512
    %test_plot_layert5_counts_lat_lon_cont       ! NXM-4014
    %test_plot_layert5_csv                       ! NXM-3500 NXM-3510 NXM-3515
    %test_plot_layert5_dateline                  ! Bug 2595
    %test_plot_layert5_drawable_map_limits       ! NXM-3581 NXM-3610
    %test_plot_layert5_drawable_openfile         ! NXM-3515 NXM-3569 NXM-3570 NXM-3577 NXM-3578 NXM-3580 NXM-3584
    !%test_plot_layert5_drawable_pipe_open_close ! NXM-3566 NXM-3568 NXM-3646 NXM-3689 Skipping since covered in test_plot_layerdrawable_gak
    %test_plot_layert5_drawable_point_select     ! NXM-3566 NXM-3568 NXM-3569
    %test_plot_layert5_drawable_refresh          ! NXM-3552 NXM-3571
    %test_plot_layert5_drawable_tiny_ellipse     ! NXM-3415
    %test_plot_layert5_ellipse                   ! Bug 2471
    %test_plot_layert5_ellipsoid                 ! NXM-3934
    !%test_plot_layert5_ellipsoid_csv            ! NXM-3934 Called in test_plot_layert5_ellipsoid
    !%test_plot_layert5_ellipsoid_t5000          ! NXM-3934 Called in test_plot_layert5_ellipsoid
    %test_plot_layert5_fill_northpole            ! NXM-3271
    %test_plot_layert5_filter_visibility         ! NXM-3862 NXM-3873 NXM-3901 NXM-3904 NXM-3910
    %test_plot_layert5_filter_highlight          ! NXM-3862 NXM-3914 NXM-3947
    %test_plot_layert5_line                      ! Bug 1223
    !%test_plot_layert5_line_zoom                ! Bug 1223 Skipping since never got completed, probably covered elsewhere
    %test_plot_layert5_metadata                  ! NXM-3955
    %test_plot_layert5_multi_openfile            ! NXM-3576
    %test_plot_layert5_points_size               ! NXM-3946
    %test_plot_layert5_polygon                   ! NXM-3558
    !%test_plot_layert5_polygon_edit             ! NXM-3558 Called in test_plot_layert5_polygon
    %test_plot_layert5_select                    ! NXM-3511
    %test_plot_layert5_select_modes              ! NXM-3511
    %test_plot_layert5_selectcolor               ! Bug 2888
    %test_plot_layert5_symbols                   ! NXM-3910
    %test_plot_layert5_time                      ! Bug 2632
    !%test_plot_layert5_time_window              ! NXM-3515 Skipping since broken and covered elsewhere
    %test_plot_layert5_xyz_2d                    ! NXM-3913 NXM-3921
    %test_plot_layert5_xyz_raster                ! NXM-3913 NXM-3921 NXM-4115
    %test_plot_layert5_zoom                      ! Bug 2488

  ! If COREGRAPHICS run a short list of extreme tests that tend to be the ones to show graphical issues
  elseif coreGraphics then
    %test_plot_layert5_clusters_fixed    ! NXM-2968 NXM-3512
    %test_plot_layert5_clusters_pipe     ! NXM-2968
    %test_plot_layert5_counts            ! NXM-3512
    %test_plot_layert5_drawable_openfile ! NXM-3515 NXM-3569 NXM-3570 NXM-3577 NXM-3578 NXM-3580 NXM-3584
    %test_plot_layert5_drawable_tiny_ellipse ! NXM-3415
    %test_plot_layert5_ellipsoid         ! NXM-3934
    %test_plot_layert5_fill_northpole    ! NXM-3271
    %test_plot_layert5_filter_visibility ! NXM-3862 NXM-3873 NXM-3901 NXM-3904 NXM-3910
    %test_plot_layert5_filter_highlight  ! NXM-3862 NXM-3914 NXM-3947
    %test_plot_layert5_symbols           ! NXM-3910
    %test_plot_layert5_xyz_2d            ! NXM-3913 NXM-3921
  endif

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

!******************************************************************************!
procedure processMessage m:msg

  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: Interactive tests" msg.data eqss "PASS"
    pipe stop

  elseif msg.name eqs "NEXTPLOT" then
    invoke gc.specialAction.panel.setVisible(false)
    if     msg.data EQS "NONE" then
      call test_plot_none
    elseif msg.data EQS "CONE" then
      call test_plot_layerT5_cone
    elseif msg.data EQS "CONEFLAG" then
      call test_plot_layerT5_coneflags
    elseif msg.data EQS "ELLIPSE" then
      invoke gc.specialaction.setItem(1,labelEllipse)
      invoke gc.specialAction.panel.setVisible(true)
      call test_plot_layert5_ellipse
    elseif msg.data EQS "ELLIPSEFLAG" then
      call test_plot_layert5_ellipseflags
    elseif msg.data EQS "ZEROSIZE" then
      call test_plot_layert5_zerosize
    elseif msg.data EQS "POSITIONS" then
      call test_plot_layert5_positions
    elseif msg.data EQS "LARGEFILE" then
      call test_plot_layert5_largefile
    elseif msg.data EQS "HUGEFILE" then
      call test_plot_layert5_hugefile
    elseif msg.data EQS "PIPE" then
      invoke gc.specialaction.setItem(1,labelPipe)
      invoke gc.specialAction.panel.setVisible(true)
      call test_plot_layert5_pipe
    elseif msg.data EQS "PIPE2" then
      call test_plot_layert5_pipe2
    else
      warning "Do not know ^msg.data layer"
    endif
  elseif msg.name eqs "SETFLAG" then
    res t5field "reg.idplot.layers.^{idlayer}.field"

    if     msg.data EQS "SYMBOLSON" then
      set ^t5field +SYMBOL
    elseif msg.data EQS "SYMBOLSOFF" then
      set ^t5field -SYMBOL
    elseif msg.data EQS "LABELSON" then
      set ^t5field +LABEL
    elseif msg.data EQS "LABELSOFF" then
      set ^t5field -LABEL
    elseif msg.data EQS "ELLIPSESON" then
      set ^t5field +ELPS
    elseif msg.data EQS "ELLIPSESOFF" then
      set ^t5field -ELPS
    elseif msg.data EQS "CONESON" then
      set ^t5field +CONE
    elseif msg.data EQS "CONESOFF" then
      set ^t5field -CONE
    else
      warning "Can not set '^msg.data'"
    endif
  elseif msg.name EQS "CLEARLAYERS" then
    invoke ,, reg.idplot.clearData()
  elseif msg.name EQS "SPECIALACTION" then
    if msg.data eqs labelEllipse then
      invoke ,, reg.idplot.layers.ellipse5000.deletePoints(5,6)
      invoke ,, reg.idplot.layers.ellipse5000.deletePoints(8,-1)
    elseif msg.data eqs labelPipe then
      invoke time_window_rel_pt nxm.sys.libg.LayerT5.WINDOW_RELATIVE_POINT
      invoke time_window_rel_cl nxm.sys.libg.LayerT5.WINDOW_RELATIVE_CLOCK
      invoke ,, reg.idplot.layers._T5PIPE.setTimeWindow(^pointTimeout,-1,time_window_rel_cl)
    endif
  else
    ! do nothing
    say "Unhandled message name: ^msg.name from fid: ^msg.fid dats: ^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

!******************************************************************************!
procedure open
  call setInstructions "Click 'Cone' button to display plot."
return

!******************************************************************************!
procedure newplot s:plotstring s:instructions
  message FUNC=send ID=IDPLOT NAME=CLOSEFILE DATA="*"
  foreach item intable testfiles
   if testfiles.^item nFEXISTS then
    warning "Could not generate/find ^testfiles.^item"
    return
   endif
  endfor
  call setInstructions instructions
  message FUNC=send ID=IDPLOT NAME=OPENFILE DATA=^{plotstring}
return

!******************************************************************************!
procedure test_plot_none
  result testfiles {}
  call newplot "" "Should see a blank screen"
return

!******************************************************************************!
procedure test_plot_layerT5_cone
  result testfiles {}
  result testfiles.world    "^{datDir}.world.prm"
  result testfiles.capitals "^{datDir}.capital_cities.prm"
  result testfiles.cone     "^{datDir}.cone5000.prm"
  result idlayer            "cone5000"

  call newplot &
    "^{testfiles.world}|^{testfiles.cone}{Layer={symbol=star,color=red}}" &
    "Should see a world plot with a RED * and a cone. You will need to zoom in.\n\n&
    Test clearing the layers by clicking 'Clear all layers'"
return

!******************************************************************************!
procedure test_plot_layerT5_coneflags
  result testfiles {}
  result testfiles.world     "^{datDir}.world.prm"
  result testfiles.coneflags "^{datDir}.coneflags5000.prm"
  result idlayer             "coneflags5000"

  call newplot "^{testfiles.world}|^{testfiles.coneflags}" &
    "Should see a world plot with:\n&
    1) a GREEN cross named LABEL1 inside a GREEN cone\n&
    2) a YELLOW cross named LABEL2 inside a YELLOW cone\n&
    3) a RED circle named LABEL3 w/o a cone\n\n&
    There should be no other cones, crosses labels &
    or stars.\n\n&
    Click 'Clear all layers'\n&
     - all cones/crosses/labels should be removed"

return

!******************************************************************************!
procedure test_plot_layert5_ellipseflags
  result testfiles {}
  result testfiles.world    "^{datDir}.world.prm"
  result testfiles.ellipse  "^{datDir}.ellipseflags5000.prm"
  result idlayer            "ellipseflags5000"

  call newplot "^{testfiles.world}|^{testfiles.ellipse}" &
    "Should see a world plot with 6 colored points.\n&
     - 5 named TONY5,..,TONY9 of alternating colors\n   with 1 ellipse around each\n&
     - 1 named TONY with 4 multi-colored ellipses\n   around it. (ZOOM IN)\n\n&
     Test clearing the layers by clicking 'Clear all layers'"

return

!******************************************************************************!
procedure test_plot_layert5_zerosize
  result testfiles {}
  result testfiles.world    "^{datDir}.world.prm"
  result testfiles.ellipse  "ram:temp_testplot_layert5_zerosize"
  result idlayer            "zerosize"

  thin ^{datDir}.ellipse5000.prm testfiles.ellipse 0 0

  call newplot "^{testfiles.world}|^{testfiles.ellipse}" &
    "Should see a WORLD plot with NO ellipse points.\n\n&
    Layer should not be constantly refreshing or flashing (DR 534702-1)."

return

!******************************************************************************!
procedure test_plot_layert5_ellipse
  result testfiles {}
  result testfiles.world    "^{datDir}.world.prm"
  result testfiles.ellipse  "^{datDir}.ellipse5000.prm"
  result idlayer            "ellipse5000"

  call newplot "^{testfiles.world}|^{testfiles.ellipse}" &
    "Should see a world plot with 6 green points.\n&
    - 5 with 1 ellipse around each\n&
    - 1 with 4 ellipses around it. (ZOOM IN).\n\n&
    Click 'Test clearing point by point'\n&
    1) should not see any warnings or errors in the\n   terminal.\n&
    2) 2 points will clear around India and\n   1 point north of the UK."

return

!******************************************************************************!
procedure test_plot_layert5_positions
  result testfiles {}
  result testfiles.world    "^{datDir}.world.prm"
  result testfiles.cities   "^{datDir}.cities.prm{LAYER={AutoselectEnable=CLICK,AutoSelectMode=PIXEL}}"
  result idlayer            "cities"

  call newplot "^{testfiles.world}|^{testfiles.cities}" &
    "Should see a world plot with many of the major cities indicated by a &
     green cross.\n\n&
     Zoom in on Ireland: the cities of 'Dublin' &
     and 'Belfast' should be indicated by name.\n\n&
     Click 'Clear all layers'\n&
     - all cities should be removed"

return

!******************************************************************************!
procedure test_plot_layert5_largefile
  result testfiles {}
  result testfiles.world    "^{datDir}.world.prm"
  result testfiles.cities   "temp_testplot_cities{TAG=CITIES}"
  result idlayer            "cities"

  call newplot "^{testfiles.world}|^{testfiles.cities}" &
    "Should see a world plot with many of the major cities indicated by a &
     green cross.\n\n&
     Click 'Clear all layers'\n&
     - all cities should be removed"

return

!******************************************************************************!
procedure test_plot_layert5_hugefile
  result testfiles {}
  result testfiles.world    "^{datDir}.world.prm"
  result testfiles.cities   "temp_testplot_hugefile{TAG=CITIES}"
  result idlayer            "cities"

  call newplot "^{testfiles.world}|^{testfiles.cities}" &
    "Should see a world plot with a huge number of green ellipses.\n\n&
    1) Zoom in to see ellipse curvature\n\n&
    2) Click 'Clear all layers'\n&
    - all ellipses should be removed"

return

!******************************************************************************!
procedure test_plot_layert5_pipe
  result testfiles {}
  result testfiles.world    "^{datDir}.world.prm"
  result testfiles.cities   "_t5pipe{LAYER={TimeOrder=TRUE,AutoselectEnable=CLICK,AutoSelectMode=PIXEL}}"
  result idlayer            "_t5pipe"

  call newplot "^{testfiles.world}|^{testfiles.cities}" &
    "Points are added in a diagonal line across the world.\n\n&
     1) Click 'Clear all layers'\n&
     -> all previous points are cleared\n\n&
     2) Wait until points build up again\n\n&
     3) Click '^{labelPipe}'\n& 
     only points less than ^pointTimeout seconds old are kept"



  ! bstore set by openfile and needs to be removed for this test
  pause .25
  set reg.idplot.options "-bstore"

return

!******************************************************************************!
procedure test_plot_layert5_pipe2
  result testfiles {}
  result testfiles.world    "^{datDir}.world.prm"
  result testfiles.cities   "_t5pipe2"
  result idlayer            "_t5pipe2"

  call newplot "^{testfiles.world}|^{testfiles.cities}" &
    "Should see thousands of ellipses plotted all over the world. Points are &
     being added at a rate of 100 points/sec with the latest 150000 points visible.\n\n&
     1) Run for at least six minutes to make sure OutOfMemoryError exception does &
     not happen (DR 1808).\n\n&
     2) Make sure at that time the PIPE is still flowing and MMB brings up the plot menu.\n\n&
     3) Test clearing the layers by clicking 'Clear all layers'"



  ! bstore set by openfile and needs to be removed for this test
  pause .25
  set reg.idplot.options "-bstore"

return

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

!******************************************************************************!
procedure setInstructions s:msgString
  set reg.panel.controls.idtext.value msgString
return
