!******************************************************************************!
! Tests raster options on pipes, with hope of adding xcut and ycut
!
! Bug:    NXM-3567 X-Cut does not work on piped data
! Since:  NeXtMidas 4.1.1
! Author: Jeanette McCall
!******************************************************************************!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE ! for normal interactive test(s)
  switch TYPE        ftype    GET DEF="FFT PIPE"      ! file type to swap (PIPES or STATIC FILES)

  call setDatDir

  call setSwapFileType ftype
  set lastFileType ftype

  set sr 1e5
  set fsize 1k
  set instructions "This test case tests XCuts and YCuts on a piped Layer2D plot.\n\n&
                    1. Click on the fft plot.\n2. Press 'x' to perform an XCut, and press 'y' &
                    to perform a YCut.\n3. Change the frame size and repeat steps 1 and 2.\n&
                    4. Switch to the basic pipe plot and repeat steps 1 and 2.\n&
                    5. Switch to the static plot and repeat steps 1 and 2.\n&
                    6. Switch back to the fft plot and repeat steps 1 and 2."

  if interAct then
    if ^{env.NMROOT} EQS "classpath:" then
      res apennyFilename "apenny_tmp{AUX=RAM}"
      res fmCaptureFilename "fm_capture_t1000_tmp{AUX=RAM}"
      file copy ^{datDir}.fm_capture_t1000.prm fmCaptureFilename
      file unprotect fmCaptureFilename
    else
      res apennyFilename "apenny_tmp"
      res fmCaptureFilename "^{datDir}.fm_capture_t1000.prm"
    endif

    file copy ^{datDir}.apenny.prm apennyFilename
    file unprotect apennyFilename
    headermod apennyFilename yd=.01 yu=time_s

    pipe init
      panel/setup/controls=gc/msgid=main
      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 9 /title
      noop/rt/wrap/id=apennypipe/tl=1 apennyFilename _apennypipe
      noop/rt/wrap/id=fm fmCaptureFilename _fmwave{ps=32k}
      fft/psd/log/id=fft _fmwave _fmpsd nfft=fsize
      plot/msgid=MAIN/id=idplot/cuts testFile type=raster /READOUT=Show|OnAxis|X|dX|Y|dY|AlwaysDeltas view=iYX
      gcontrol button fileType  "Swap File Type" "Static File,Basic Pipe,FFT Pipe" ftype /FLAGS=-OneRow|+ChkBox|
      gcontrol tval timeAtClick "Time at click" 0 0 -1 /flags="NoMsg|NoEdit"
      gcontrol choice framesz "Set FFT FRAME Size:" "128,256,512,1k,2k" 1k /tleft
    pipe off

    if ^{env.NMROOT} NEQS "classpath:" then
      erase apennyFilename
    endif
  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 "FILETYPE" then
    call setSwapFileType msg.data
    message send id=idplot name="CLOSEFILE" info=-1 data="*"
    message send id=idplot name="OPENFILE" info=-1 data=testFile
    set lastFileType msg.data
  elseif msg.name eqs "MARK" then
    res gc.timeAtClick.value msg.data.time
  elseif msg.name eqs "FRAMESZ" then
    res fsize msg.data
    set reg.fft.nfft fsize
  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 setSwapFileType S:ftype["FFT PIPE"]
  if ftype eqs "FFT PIPE" then
    set testFile _fmpsd
    if GC REXISTS then invoke ,, gc.framesz.panel.setVisible(true)
  elseif ftype eqs "BASIC PIPE" then
    set testFile _apennypipe
    if GC REXISTS then invoke ,, gc.framesz.panel.setVisible(false)
  else
    set testFile apennyFilename
    if GC REXISTS then invoke ,, gc.framesz.panel.setVisible(false)
  endif
return