!******************************************************************************!
! EXPERIMENTAL ONLY - Clusters -  LayerT5s inside a LayerDrawable
!
! @author:  Kevin Esterheld
!******************************************************************************!

startmacro

switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE  ! for normal interactive test(s)
switch KEEP        keep     GET DEF=FALSE SDEF=TRUE

set expPointCount  8
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 "Both plots show clustering of points.\n\n&
                    Left Plot:\n&
                    Feature count of zero on right side of axis readout.\n&
                    Click 'Toggle HugeFile' to turn huge file on and off.\n\n&
                    Right Plot:\n&
                    1) Feature count should increment by one each time points are cleared (every 5 seconds).\n\n\n&
                    NOTE: left feature is showClusters at layerDrawable level, right&
                    is showClusters at LayerT5 level"

  pipe on
    nxm.sys.test.plotellipsetester/RT/RATE=100/TL=25 OUT=_t5pipe{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=piped,group=t5GroupPipe,showClusters=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,showClusters=true}|&
                                                  temp_testplot_hugefile{Layer={NAME=hugefile,group=t5Group}}|&
                                                  ^{datDir}.cities.prm{Layer={NAME=cities,group=t5Group,MinimumClusterSize=4}} &
                                                  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 20 /title
    invoke nxm.sys.test.plotellipsetester.resetPlot(reg.pipe, 5)         ! changed to 5-second intervals - since 4.0.0
    invoke pipedLayer reg.pipe.layers.T5GROUPPIPE.getDrawable(PIPED)
    invoke hugeFileLayer reg.cities.layers.T5GROUP.getDrawable(HUGEFILE)
    invoke citiesLayer reg.cities.layers.T5GROUP.getDrawable(CITIES)

    gcontrol/nc=1 button toggle "" "Toggle HugeFile"

  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 "TOGGLE" then
    invoke hugeFileLayer.toggle()
  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 setInstructions s:msgString
  set reg.panel.controls.idtext.value msgString
return
