startmacro
!******************************************************************************!
! Test adding overlay files to current plot in xgeoplot (NXM-2907)
!  NeXtMidas interactive test macro template
!
! Arguments: None
!
! @author:  Elizabeth Ryan
! @since NeXtMidas 3.7.1
!******************************************************************************!
  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 xgeoOpt xgeoOpt DEF="SYS" SDEF="SYS"

  call setDatDir

  if interAct then

    res xgeoid 2

    call resetData

    res sizeCities   FILE(temp_xgeo_cities).size
    res sizeEllipses FILE(temp_xgeo_ellipse).size

    ! calculate layer number for each layer used in this test - since 3.7.0 for bugs 2917 and 2965
    res  worldLayer  1
    calc citiesLayer worldLayer  1 +
    calc ellpsLayer  citiesLayer 1 +

    set files  "^{datDir}.world.prm|temp_xgeo_ellipse"
    set colors {world=NULL,temp_xgeo_ellipse=RED,temp_xgeo_cities=CYAN}
 
    res initialInstructions &
       "Verify 'cities' are shown on the world map (green X's).  These are added by the OVERLAY message. &
        Verify no warnings or errors are displayed in the terminal. & 
        e.g. 'WARN: Unhandled message name=OVERLAY'"
       
    pipe on
      panel/msgid=MAIN/setup/controls=gc

      xgeoplot;^{xgeoOpt}/id=^XGEOID "^files"

      message func=send id=^XGEOID name=overlay info=3 data="temp_xgeo_cities"

      set reg.^{xgeoid}.layers.temp_xgeo_ellipse.color "^colors.temp_xgeo_ellipse"

      gcontrol label macro "Test MACRO"
      gcontrol menu  main "Exit with Status =" "PASS,FAIL" TABLE={ItemColors={PASS="GREEN",FAIL="RED"}} /tleft
      gcontrol text idtext "Tests X-Midas style messaging." "^initialInstructions" 24 20 /title

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

!******************************************************************************!
procedure resetData
  thin ^{datDir}.ellipse5000.prm temp_xgeo_ellipse{AUX=RAM}
  thin ^{datDir}.cities.prm      temp_xgeo_cities{AUX=RAM}
return
