!******************************************************************************!
! This tests the ability to add separators in panel's fixed regions
!
!
! Arguments: None
!
! @bug      NXM-4071 panel needs to allow separators in fixed zones
! @since    4.1.4
! @author:  Jeanette McCall
!******************************************************************************!
startmacro S:throttle["REAL"]
  switch INTERACTIVE interAct     GET DEF=TRUE  SDEF=TRUE
  switch BASELINE    baseline     GET DEF=FALSE SDEF=TRUE
  switch COREGAPHICS coreGraphics GET DEF=FALSE SDEF=TRUE
  res oldLookAndFeel env.theme
  lookandfeel gear4

  call setDatDir

  if interAct OR coregraphics then
    set instructions "Expected in fixed regions:\n&
                      1) TOP   : plot and LIST of FFT.\n&
                      2) RIGHT : plot apenny and message log\n&
                      3) BOTTOM: LIST2 and plot of FFT chirp\n\n&
                      Expected in main section:\n&
                      plot of copies of FFT chirp and FFT.\n\n&
                      MENUBAR should behave as normal"

    set format sf
    set sr 1e4
    set over 0
    set sfreq sr/10
    set chirpamt sfreq/4
    set amp 1e4
    set noiseamp 1e2
    set fsize 512
    set numelem 10e10
    set firstClick true

    invoke tcur nxm.sys.lib.Time.current()

    pipe init
      panel/msgid=MAIN/menubar/setup/controls=gc

      ! Create waveforms with adjustable frequency (2nd one has frequency chirped each TL)
      waveform/id=wave/throttle=^throttle _wave format elem=numelem cos freq=sfreq amp=amp delta=1/sr start=^tcur
      waveform/id=wavec/throttle=^throttle/tl=4k _wavechirp format elem=numelem cos freq=sfreq amp=amp delta=1/sr chirp=^chirpamt start=^tcur
      ! Create ffts of the 2 waveforms (frame size can be adjusted using gcontrol)
      fft/dbf/id=fft _wave _fft{form=sf} fsize over=over
      fft/dbf/id=fftchirp _wavechirp _fftchirp fsize over=over
      ! plot the ffts
      plot/id=plotfft/msgid=MAIN/READOUT=Show|OnTitle|T|dT _fft view=iXY 
      plot/id=plotfftchirp/msgid=MAIN/READOUT=Show|OnTitle|T|dT _fftchirp view=iXY
      plot/id=plotfftcopy/msgid=MAIN/READOUT=Show|OnTitle|T|dT _fft view=iXY 
      plot/id=plotfftchirpcopy/msgid=MAIN/READOUT=Show|OnTitle|T|dT _fftchirp view=iXY
      list/id=listfft nxm.sys.test.test_fftout_timeline.prm
      list2/id=list2chirp nxm.sys.test.fft_wavechirp_tc.prm
      plot/id=penny ^{datDir}.apenny.prm

      ! add box feature to plot for creating a user selectable dragbox on the raster plot
      FEATURE/id=box1 label=box1 table={NAME=BOX1,TYPE=BOX,COLOR=WHITE,ENABLE=1} plot=idplotfft
      FEATURE/id=box2 label=box2 table={NAME=BOX2,TYPE=BOX,COLOR=WHITE,ENABLE=1} plot=idplotfft2

      ! add a logger to match Jeff's test
      msglog/id=logger/msgid=main/wrap/file=logFile
      res INFO 0
      message send logger ,, LOG ,INFO, "Open INSTRUCTIONS tab to see what to do"

      gcontrol label  macro   "INSTRUCTIONS"
      gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
      set gc.main.itemColors {PASS=GREEN,FAIL=RED}
      gcontrol text idtext "Instructions" "^instructions" 30 14 /title

      gcontrol label  plot  "PLOT/TIMELINE"
      gcontrol choice sfreq "Set SFREQ (multiplier):" ".25,.5,1,2,3,4" "1" /tleft
      gcontrol choice framesz "Set FFT FRAME Size:" "256,512,1k" "512" /tleft
      gcontrol tval   timeAtPos1 "Time at 1st click" 0 0 -1 /flags="NoMsg|NoEdit"
      gcontrol tval   timeAtPos2 "Time at 2nd click" 0 0 -1 /flags="NoMsg|NoEdit"
      gcontrol tval   tcurr "startTimeAt" tcur 0 -1 /msg=no /edit=no

      gcontrol label  tab3   "TAB3"
      gcontrol menu clickThree "Click Here" "TAB,THREE" /tleft
      gcontrol text idtextt3 "Instructions" "TAB3:This is tab3 text" 24 4 /title

      gcontrol label  tab4   "TAB4"
      gcontrol menu clickFour "Click Here" "TAB,FOUR" /tleft
      gcontrol text idtextt4 "Instructions" "TAB4:This is tab4 text" 24 4 /title

      gcontrol label  tab5   "TAB5"
      gcontrol menu clickFive "Click Here" "TAB,FIVE" /tleft
      gcontrol text idtextt5 "Instructions" "TAB5:This is tab5 text" 24 4 /title
    pipe off

  endif

  lookandfeel oldLookAndFeel
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 "DRAGBOX"  then
  elseif msg.name eqs "SFREQ" then
    ! set frequwency of both waveforms
    calc newfreq sfreq ^msg.data *
    set reg.wave.freq  ^newfreq
    set reg.wavec.freq  ^newfreq
    set reg.wave.state "RESTART"
    set reg.wavec.state "RESTART"
  elseif msg.name eqs "FRAMESZ" then ! since 3.7.2 for NXM-3040
    ! set framse size of both ffts
    res fsize msg.data
    set reg.fft.nfft fsize
  elseif msg.name eqs "MARK"
    ! set the "Time At # Click" gcontrols
    if firstClick then
      res gc.timeAtPos1.value msg.data.time
      res firstClick false
    else
      res gc.timeAtPos2.value msg.data.time
      res firstClick true
    endif
  elseif msg.name eqs "UNZOOM"
    if msg.fid eqs "IDPLOTFFT" then
      invoke reg.idplotfft.refresh()
    elseif msg.fid eqs "IDPLOTNOOP" then
      invoke reg.idplotnoop.refresh()
    endif
  elseif msg.name eqs "ZOOM"
  elseif msg.name eqss "CLICK"
    res display msg.data
    if display eqs ""
      res display msg.name
    endif
    popup/blocking=none popup OK "You clicked ^display" "INFO"
  else
    say "Unhandled message name=^msg.name info=^msg.info 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
