!******************************************************************************!
! Test the PLOT BaseLayer concept added in 3.5.0
!
! @bug      2792 PLOT: Need ability to group layers and see the groups in a tree list
! @bug      2894 PLOT: regression due to adding Base Layer concept causes Layers to not display properly
!                (3.6.0 updated test case and code so that this test case works)
! @author:  J Bauer
!******************************************************************************!
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)

  call setDatDir

  if interAct then
    set instructions "You should see two plots. \n\n&
                      The top PLOT should be view=LATLON, and the bottom plot should be view=YX.\n\n&
                      1) Click on the WORLD button and the view should change to LATLON.\n\n&
                      2) Click on the SV1 button and the view should change back to YX."

    pipe on
      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 16 /title

      plot/id=plot1  ^{datDir}.sv1.prm|^{datDir}.sv3.prm|^{datDir}.world.prm{LAYER={BASELAYER=TRUE}}

      plot/id=plot2  ^{datDir}.sv1.prm|^{datDir}.sv3.prm|^{datDir}.world.prm


      gcontrol prompt viewOne "PLOT 1 View:" reg.plot1.view
      gcontrol prompt viewTwo "PLOT 2 View:" reg.plot2.view
      gcontrol button baseButt "Set Base Layer" "SV1,WORLD" "SV1"

    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 "BASEBUTT" then
    if msg.data eqs "WORLD" then
      set reg.plot2.baseLayer reg.plot2.layers.world  ! set using layer
    else
      set reg.plot2.baseLayer sv1                     ! set using layer name
    endif

    set gc.viewTwo.value reg.plot2.view

  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
