!******************************************************************************!
! Test the saving and loading of features
!
!   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

    pipe init
      panel/msgid=MAIN/setup/controls=gc
      ! NTN: added options=+BSTORE|+DBUFFER on PLOT to reduce flickering
      plot/id=idplot ^{datDir}.apenny.prm options=+BSTORE|+DBUFFER

      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" "Click on the buttons below in order and follow their instructions. " 24 9 /title
      gcontrol button addFeat "" "Add Features"
      gcontrol button saveFeatures "" "Save Features" /tleft
      gcontrol button remFeat "" "Remove Features"
      gcontrol button loadFeatures "" "Load Features" /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 eqs "ADDFEAT" then
    call test_feature_TRIANGLE blue

  elseif msg.name eqs "REMFEAT" then
    set reg.idplot.removeFeature "*"
    call setInstructions "All features should be removed from the Penny plot"

  elseif msg.name eqs "SAVEFEATURES" then
    call setInstructions "Should see the Save dialog popup. Choose a name for the file &
       and click Submit."
    message FUNC=send ID=idplot MSG="FEATURE" NAME="FEATURE" INFO=0 DATA="SAVE"

  elseif msg.name eqs "LOADFEATUREs" then
   call setInstructions "Should see the Load dialog popup. Select the file you saved &
       and click Submit. The Features should appear on the plot as they were saved."
    message FUNC=send ID=idplot MSG="FEATURE" NAME="FEATURE" INFO=0 DATA="LOAD"

  else
    ! do nothing
    say "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 setInstructions s:msgString
  set reg.panel.controls.idtext.value msgString
return

!******************************************************************************!
procedure test_feature_TRIANGLE S:color["GREEN"]
  feature label=ftriangle1 table={NAME="TRIANGLE1",TYPE=SYMBOL,X=120,Y=125,&
                                  COLOR=^color,LINE={SYMBOL="UTRI"}} plot=idplot
  feature label=ftriangle2 table={NAME="TRIANGLE2",TYPE=SYMBOL,X=120,Y=120,&
                                  COLOR=^color,LINE={SYMBOL="LTRI"}} plot=idplot
  feature label=ftriangle3 table={NAME="TRIANGLE3",TYPE=SYMBOL,X=120,Y=115,&
                                  COLOR=^color,LINE={SYMBOL="DTRI"}} plot=idplot
  feature label=ftriangle4 table={NAME="TRIANGLE4",TYPE=SYMBOL,X=120,Y=110,&
                                  COLOR=^color,LINE={SYMBOL="RTRI"}} plot=idplot
  feature label=ftriangle5 table={NAME="TRIANGLE5",TYPE=SYMBOL,X=120,Y=105,&
                                  COLOR=^color,LINE={SYMBOL="TRI"}} plot=idplot

  call setInstructions "Should see five ^color triangle features along the right &
                        that (from top to bottom) point UP, LEFT, DOWN, RIGHT, UP."
return
