! Test the MPlot.clearData() function added as per Bug 429 (DR 542355-1)
!
! Author:  J. Czechowski
!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE

  call setDatDir

  set inst "Click on 'Export' to export a copy of the top plot into the bottom plot.\n\n&
            Then zoom and press 'Export' again to update the image."

  if interAct then
    pipe on
      panel/msgid=MAIN/setup/controls=gc
      plot/id=plot ^{datDir}.apenny.prm
      plot/id=img
      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" "^inst" 24 10 /title
      gcontrol button export "Options" "Export"

    pipe off
  endif

  erase/quiet "temp_test_export.png{AUX=^AUX.WRITE}"  ! remove the file
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 "EXPORT" then

    !invoke ei reg.plot.exportImage()
    !invoke ,, ei.writeToFile("^{fname}","^{ftype}")

    ! Changed from above to below for Bug 2475
    message send plot name="EXPORTIMAGE" info=0 data="temp_test_export.png{AUX=^AUX.WRITE}"
    pause 0.5  ! make sure the file is there
    message send img NAME="OPENFILE" INFO=-1 DATA="temp_test_export.png{AUX=^AUX.WRITE}"

  else
    ! do nothing
    say "^reg.main.name: 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
