!******************************************************************************!
! Tests the counting of points in LayerT5
!
! @bug      NXM-3512 Count points in an area on map
! @since    3.9.3
! @author:  Kevin Esterheld
!******************************************************************************!

startmacro

switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE
switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE
switch KEEP        keep     GET DEF=FALSE SDEF=TRUE

set expPointCount  8
set expEllipsePointCount 9
call setDatDir

if interAct then
  mergefile ^{datDir}.cities.prm temp_testplot_cities /replay=40
  nxm.sys.test.plotellipsetester OUT="temp_testplot_hugefile" ELEM=10K
  !set startPoint 0
  set instructions "1. Left plot: point count 615\n\n&
                    2. Right plot: point count changing, Feature (red circle) added &
                    when points clear (every 5 seconds).\n\n  &
                    3. Click 'Start Auto Test' to run automatic tests. &
                    Check for any failures and choose PASS/FAIL accordingly."
  pipe on
    nxm.sys.test.plotellipsetester/RT/RATE=100/TL=25 OUT=_t5pipe{SIZE=150000} ELEM=Inf
    nxm.sys.test.plotellipsetester/RT/RATE=100/TL=25 OUT=_t5pipe2{SIZE=150000} ELEM=Inf
    panel/msgid=MAIN/setup/controls=gc
    plot/mousewheelzoom/usemouseposition/id=pipe ^{datDir}.world.prm|{LT="Drawable",name=t5GroupPipe,listlayers=true}|&
                                                _t5pipe{Layer={NAME=_t5pipe,group=t5GroupPipe,formRegions=true}}|&
                                                _t5pipe2{Layer={NAME=_t5pipe2,group=t5GroupPipe,formRegions=true}} &
                                                 x1=-180 x2=180 y1=-90 y2=90 options="-BStore" &
                                                 readoutExt=+SHOW|+FEATURE|+POINTS readout=+OnAxis
    plot/mousewheelzoom/usemouseposition/id=cities ^{datDir}.world.prm|{LT="Drawable",name=t5Group,listlayers=true}|&
                                                  ^{datDir}.cities.prm{Layer={NAME=cities,group=t5Group,formRegions=true}}|&
                                                  ^{datDir}.ellipse5000.prm{Layer={NAME=ellipse5000,group=t5Group}} &
                                                  readoutExt=+SHOW|+FEATURE|+POINTS readout=+OnAxis

    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" ^instructions 24 22 /title
    invoke nxm.sys.test.plotellipsetester.resetPlot(reg.pipe, 5)
    invoke pipedLayer reg.pipe.layers.T5GROUPPIPE.getDrawable(_t5pipe)
    invoke citiesLayer reg.cities.layers.T5GROUP.getDrawable(cities)

    gcontrol/nc=1 button autotest "" "Start Auto Test"

  pipe off
endif
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 "ZOOMRIGHT" then
    message sendw id=pipe name=ZOOM data={xmin=-79,xmax=-72,ymin=36,ymax=44}
  elseif msg.name eqs "AUTOTEST" then
    call testCitiesPlot
  else
    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 testCitiesPlot
  message sendw id=cities name=ZOOM data={xmin=-79,xmax=-72,ymin=36,ymax=44}
  invoke pointCount reg.cities.layers.T5GROUP.getNumVisiblePoints()
  assert/text="^reg.main.name: point count should equal ^{expPointCount}" expPointCount eq pointCount
  invoke reg.cities.zoomOut(-1)
  invoke citiesLayer.setEnable(-Global)
  pause .25 !need to let the layer draw again. give a pause for the test
  invoke pointCount reg.cities.layers.T5GROUP.getNumVisiblePoints()
  assert/text="^reg.main.name: point count should equal ^{expEllipsePointCount}" expEllipsePointCount eq pointCount
  invoke citiesLayer.setEnable(+Global)
return

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