!******************************************************************************!
! Test manually adjusting Axis Units labels
!
! @bug      945  PLOT: provide own axis titles for Plot
! @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
    set instructions "1. Enter text in each of the top two Prompts. You should see the text for that axis label change &
                      in each plot after you hit enter.\n\n&
                      2. Enter text in each of the next two prompts. The axis units should not change until &
                      after you hit the button below them.\n\n&
                      3. Change one or both of the bottom two prompts to be blank and hit the button again. &
                      In the left plot, the default units label should be displayed for whichever axis &
                      was submitted blank. The right plot should show that axis title as blank."

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

      ! to change the default axis labels individually
      gcontrol prompt xLabel "Enter text to set custom X Axis Label" ""
      gcontrol prompt yLabel "Enter text to set custom Y Axis Label" ""

      gcontrol line spacer1

      ! to change both labels at once
      gcontrol prompt xLabel2 "Enter X Label text for 'both at once'" ""
      gcontrol prompt yLabel2 "Enter Y Label text for 'both at once'" ""
      gcontrol button changeBoth "" "Click to change both at once!" ""

      ! create a real time plot to ensure no race conditions with repaint call in MPlot
      wave _wave elem=inf shape=sin  amp=1e4
      fft _wave _waveb nfft=1k navg=1 over=0 /dbf

      plot/id=plot1 _waveb

      ! use apenny because it has no units set in the file
      plot/id=plot2 ^{datDir}.apenny.prm

    pipe off

  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 "XLABEL" then
    set reg.plot1.XAxisLabel msg.data
    set reg.plot2.XAxisLabel msg.data

  elseif msg.name eqs "YLABEL" then
    set reg.plot1.YAxisLabel msg.data
    set reg.plot2.YAxisLabel msg.data

  elseif msg.name eqs "CHANGEBOTH" then
    invoke ,, reg.plot1.setAxisLabels("^{gc.xlabel2.value}","^{gc.ylabel2.value}")
    invoke ,, reg.plot2.setAxisLabels("^{gc.xlabel2.value}","^{gc.ylabel2.value}")

  elseif msg.name eqs  "XLABEL2" OR msg.name eqs "YLABEL2" then
    ! do nothing

  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
