!******************************************************************************!
! Test control of individual plot color without FLAG component
!
! @bug      2823 PLOT: LayerT5 does not allow control of individual plot color without FLAG component
! @bug      2875 MColor: Constants for Type 5000 colors
! @author:  J 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 "You should see a plot of the world (Africa) with an ellipse at (0,45) LAT/LON\n\n &
                      1) Select the 'Merge Pnt: change current \n &
                         Pnt to Red' button. The current Pnt (the \n &
                         ellipse) should change to RED\n\n &
                      2) Next select the 'Merge All Pnts Green: \n &
                         change current Pnt to Green' button. The \n &
                         current Pnt should change to GREEN\n\n &
                      3) Select each color in the 'Set Pnt:\n &
                         check ...' menu and make sure circles \n &
                         with a ellipse around them of that \n &
                         color appear at LAT=-7.5, LON=-7.5 \n &
                      If the colors change, select PASS."

    ! Since 3.5.3 - switch to using new MColor constants
    invoke gray=nxm.sys.libg.MColor.T5_INDEX_GRAY
    invoke darkgreen=nxm.sys.libg.MColor.T5_INDEX_DARK_GREEN
    invoke red=nxm.sys.libg.MColor.T5_INDEX_RED 
    invoke yellow=nxm.sys.libg.MColor.T5_INDEX_YELLOW
    invoke green=nxm.sys.libg.MColor.T5_INDEX_GREEN

    res fileOneEllipse "ram:temp_5000"
    thin ^{datDir}.ellipseflags5000.prm ^fileOneEllipse 0 1

    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 28 20 /title

      ! Tests new methods mergePoint and mergeAllPoints
      gcontrol button mergePoint "" "Merge Pnt: change current Pnt to Red"
      gcontrol button mergeAllPoints "" "Merge All Pnts: change current Pnt to Green"

      ! menu tests "else if" changes in LayterT5 draw & since 3.5.3 new MColor constants
      gcontrol menu setPntColor "\n Set Pnt: check each circle color" "gray,darkgreen,red,yellow,green" "" /ChkBox

      xgeoplot/bg/id=xgeo file=^{datDir}.world.shp{Layer={LABEL=NAME,OPAQ=0}}|^{fileOneEllipse}{TAG=PNTSLAYER,LAYER={debugMask=0}} &
          ZOOMTO={X1=-25,X2=75,Y1=-30,Y2=30}
      set layt5 reg.xgeo.layers.PNTSLAYER

    pipe off

    erase ^fileOneEllipse

  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 "MERGEPOINT" then
   message send xgeo ,, T5REC 2048 {LAYER=2,INDEX=1,COLOR=^red}

  elseif msg.name eqs "MERGEALLPOINTS" then
    !index == 0 means all points
    message send xgeo ,, T5REC 2048 {LAYER=2,INDEX=0,COLOR=5}

  elseif msg.name eqs "SETPNTCOLOR" then
    ! SYMBOLID 2=Circle (see XmUtil.xmSymbolNames) - Note: Points in a layer must contain the same elements (be homogeneous)
    invoke ,, layt5.setPoint(0,{NAME="SETPT",ELPS={SEMIMAJOR=3000000.0,SEMIMINOR=700000.0,TILT=0},&
                             POS={LAT=-7.5,LON=-7.5},FLAG={CONE=-9, COLOR=^{^{msg.data}},SYMBOLSIZE=20,SYMBOLID=2}}) !Note:CONE=-9 makes Ellipse visible

  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
