!******************************************************************************!
! Test the changing of FEATUREs types string
!
!   notApplicableList - The list of feature types that are not applicable in
!                       this test or are not implemented.
!
!   Author : J. Hallam
!******************************************************************************!
startmacro s:notApplicableList["Data,Peak,IPlot,VRide"]
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE  ! for normal interactive test(s)

  call setDatDir

  if interAct then
    set featureTab {NAME="FEAT",TYPE="|BOX|TEXT|BTAG|TTAG|LTAG|RTAG",X=89,Y=66,DX=20,DY=30,SEMIMAJOR=1E6,SEMIMINOR=1E6,TILT=30,COLOR="YELLOW"}
    set featureColorList "RED,GREEN,BLUE,YELLOW,SILVER,#80909090"
    set fillColorList "null,#80909090,GRAY,SILVER,NAVY,TEAL,^featureColorList"
    res main_instructions "Change any of the ATTRIBUTES including type, size, color or text &
                    of the feature. Toggle the text on/off using the 'Text' option. &
                    Toggle the file OFF and the background file should go blank.\n&
                    ---------------------------------\n"

    ! The various types/flags of Features
    invoke typeListOrig nxm.sys.libg.Feature.typeList

    ! Remove things from the list that are not applicable in this test
    set typeList ""
    foreach val inlist typeListOrig
      SEDIT notApplicableList idx SELECT "^{val}"
      if idx lt 0 then
        if typeList.length eq 0 then
          set typeList "^{val}"
        else
          set typeList "^{typeList},^{val}"
        endif
      endif
    endfor

    pipe init
      panel/msgid=MAIN/setup/controls=gc
      plot/id=idplot ^{datDir}.apenny.prm options=+bstore
      feature label=ffeat table=^{featureTab} plot=idplot !since 3.5.4 add feature without changing instructions
      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" "initializing..." 24 14 /title

        gcontrol menu   featureType     "Type/Flags" "^typeList" "^featureTab.type" /toggle /chkbox
        gcontrol dval   featurePosX     "Position-X" featureTab.X  0 128 1
        gcontrol dval   featureSizeDX   "Size-DX"    featureTab.DX 0 100 1
        gcontrol dval   featurePosY     "Position-Y" featureTab.Y  0 128 1
        gcontrol dval   featureSizeDY   "Size-DY"    featureTab.DY 0 100 1
        gcontrol choice featureColor    "Color"      featureColorList featureTab.color
        gcontrol choice featureFillColor "FillColor" fillColorList   null
        gcontrol prompt featureText     "Text"       "^{featureTab.name}" 64 /INPUTBORDER=PERM
        gcontrol button toggleFile      "TOGGLE FILE:"    "ON,OFF" 1 /nc=2 /tleft

    pipe off
  endif
endmacro

!******************************************************************************!
procedure processMessage m:msg
  !say "msg.name ^msg.name, data ^msg.data"

  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: user indicated tests" msg.data eqss "PASS"
    pipe stop

  elseif msg.name eqss "FEATURE" then
    !info "msg.data '^msg.data', flags value ^gc.featureType.value"

    if ffeat NREXISTS then
      call addFeature
    endif
    if msg.name eqss "FEATURESIZE" then
      if "DY" SUBS msg.name then
        set ffeat.dy ^msg.data
      else
        set ffeat.dx ^msg.data
      endif
      call setInstructions "^{main_instructions}Depending on the symbol type, the size may or may not change to ^msg.data"

    elseif msg.name eqss "FEATUREPOS" then
      if msg.name EQS "FEATUREPOSY"
        set ffeat.y ^msg.data
        call setInstructions "^{main_instructions}Y position should now be ^msg.data"
      else
        set ffeat.x ^msg.data
        call setInstructions "^{main_instructions}X position should now be ^msg.data"
      endif

    elseif msg.name eqs "FEATURECOLOR" then
      set ffeat.color ^msg.data
      call setInstructions "^{main_instructions}Color should now be ^msg.data"

    elseif msg.name eqs "FEATUREFILLCOLOR" then
      set ffeat.fillcolor ^msg.data
      call setInstructions "^{main_instructions}Fill color should now be ^msg.data (null to use feature's color). &
           Must have VBAR, HBAR or FILLED enabled and at least one of (BOX, Circ, or Oval) to see the effect."

    elseif msg.name eqs "FEATURETYPE" then
      set ffeat.type "^gc.featureType.value"
      if msg.data eqs "DTAG" then
        call setInstructions "^{main_instructions}DTAG currently not implemented, so there should be no effect in toggling it."
      else
        call setInstructions "^{main_instructions}Toggled ^msg.data attribute. Feature type/flags should be ^gc.featureType.value"
      endif

    elseif msg.name eqs "FEATURETEXT" then
      set ffeat.type "+TEXT"
      set ffeat.text "^msg.data"
      call setInstructions "^{main_instructions}Text should be visible and = '^msg.data'"

    else
      warning "^reg.main.name: Do not know ^msg.data feature"
    endif

  elseif msg.name eqs "TOGGLEFILE" then
    if msg.data eqs "OFF" then
      invoke ,, reg.idplot.closeFile("*")
    else
      invoke ,, reg.idplot.openFile("^{datDir}.apenny.prm")
    endif

  else
    ! do nothing
    warn "Unhandled message name: ^msg.name from fid: ^msg.fid, data: ^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 open
  res starter_instructions "You should see a yellow rectangle around Lincoln's nose with the text &
                            FEAT on each side of the rectangle\n"
  call setInstructions "^{starter_instructions}\n^{main_instructions}"
return

!******************************************************************************!
procedure setInstructions s:msgString
  set reg.panel.controls.idtext.value msgString
return
