!******************************************************************************!
! Tests that LayerT5 and LayerPoly LEGENDs render correctly when they have a COLORMAP of 1 color
! For backwards compatibility, this behavior is not automatic, but needs to be enabled 
!
! @bug      NXM-3574  One color layer has incorrect Legend color
! @since    3.9.4
! @author:  Jeanette McCall
!******************************************************************************!
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 "LEGEND entries should have the following line colors\n\n&
                      1) Original:\n   &
                         WORLD  - purple\n   &
                         CITIES - yellow\n\n&
                      2) Select 'Change to new 1 color COLORMAP'\n   &
                         WORLD  - aqua\n   &
                         CITIES - pink\n\n&
                      3) Select 'Use predefined full COLORMAP'\n   &
                         WORLD  - WHEEL colormap, bottom color yellow\n   &
                         CITIES - TERRAIN colormap, bottom color white\n\n&
                      4) Note the current color of the world and cities\n   &
                         Select 'OFF' for 'Toggle AutoAdjustLineColor'\n   &
                         and cycle through the COLORMAP selections\n   &
                         WORLD  - actual colors change, but 1 line\n           &
                                  colormap keeps previous color\n   &
                         CITIES - both actual color and single line\n           &
                                  legend color do not change\n\n&
                      "

    invoke origT5Setting   nxm.sys.libg.LayerT5.getAutoAdjustLineColor()
    invoke origPolySetting nxm.sys.libg.LayerPoly.getAutoAdjustLineColor()
    invoke ,, nxm.sys.libg.LayerT5.setAutoAdjustLineColor(true)
    invoke ,, nxm.sys.libg.LayerPoly.setAutoAdjustLineColor(true)
    res Z:autoadjust true
    invoke SPECTRUM  nxm.sys.inc.MidasColor.SPECTRUM
    invoke TERRAIN   nxm.sys.inc.MidasColor.TERRAIN
    invoke WHEEL nxm.sys.inc.MidasColor.WHEEL

    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 24 /title

      plot/id=colormap ^{datDir}.world.prm{Layer={COLORMAP=purple}}|^{datDir}.cities.prm{LAYER={COLORMAP=yellow}} /LEGEND=TL

      gcontrol/nc=1 button UPDATECOLOR "" "Change to new 1 color COLORMAP" ""
      gcontrol/nc=1 button USEFULLCOLORMAPS "" "Use predefined full COLORMAP" ""
      gcontrol/nc=1 button ORIGINALCOLOR "" "Change back to original 1 color COLORMAP" ""
      invoke cbgName   nxm.sys.libg.MColor.toString(reg.panel.theme.cbg)
      gcontrol line line1 "SomeWorthlessText" "^cbgName" 14 ,, "CENTER"    ! Transparent spacer
      gcontrol/nc=1 button AUTOADJUST "Toggle AutoAdjustLineColor" "ON,OFF" "ON"


    pipe off

    invoke ,, nxm.sys.libg.LayerT5.setAutoAdjustLineColor(^origT5Setting)
    invoke ,, nxm.sys.libg.LayerPoly.setAutoAdjustLineColor(^origPolySetting)

  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 "UPDATECOLOR" then
    invoke ,, reg.colormap.layers.cities.setColorMap(PINK)
    invoke ,, reg.colormap.layers.world.setColorMap(AQUA)
  elseif msg.name eqs "ORIGINALCOLOR" then
    invoke ,, reg.colormap.layers.cities.setColorMap(YELLOW)
    invoke ,, reg.colormap.layers.world.setColorMap(PURPLE)
  elseif msg.name eqs "USEFULLCOLORMAPS" then
    invoke ,, reg.colormap.layers.cities.setColorMap(TERRAIN)
    invoke ,, reg.colormap.layers.world.setColorMap(WHEEL)
  elseif msg.name eqs "AUTOADJUST" then
    if msg.data EQS OFF then
      res Z:autoadjust false
    else 
      res Z:autoadjust true
    endif
    invoke ,, nxm.sys.libg.LayerT5.setAutoAdjustLineColor(^autoadjust)
    invoke ,, nxm.sys.libg.LayerPoly.setAutoAdjustLineColor(^autoadjust)
  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
res msg.name
  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
