! Tests adding a DATA Feature on a Layer1D plot before piped data is active
! The DATA feature should remain, even when not visible
!
! Note: This test runs to completion on its own
!
! @issue:   NXM-2710 and NXM-4075
! @author:  Jeanette McCall
! @since:   NeXtMidas 4.1.4
!
startmacro

	switch INTERACTIVE interAct GET DEF=TRUE SDEF=TRUE

  ! set sampling rate
  set sr 1e5
  
  set instr "This test will run to completion on its own."

  invoke z:waswarning nxm.sys.libg.Feature.isWarningFeatureNotDrawn()
  invoke ,, nxm.sys.libg.Feature.setWarningFeatureNotDrawn(true)

  if interAct then

  pipe init

    panel/msgid=main/setup/controls=gc

    ! line plot of fft
    plot/id=idplot/READOUT="+OnAxis" _myfft TYPE=LINE
    ! add DATA feature to plot before _myfft started
    feature label=fdata table={NAME="PLOTFEAT", &
       TYPE=DATA,X=sr/40,DX=sr/10,COLOR=RED} plot=idplot
   
    ! Display instructions   
    gcontrol text info "Instructions" "^instr" 34 20 /title
  
 
    ! Start timer to imitate Jeff's hardware macros
    info "There should be one Warning about Feature PLOTFEAT of type |DATA| not being drawn until layer present."  
    set this.timer(0) 0.1 ! pauses for one tenth second then sends TIMER message back to macro

   endif

  invoke ,, nxm.sys.libg.Feature.setWarningFeatureNotDrawn(waswarning)
endmacro

!******************************************************************!
procedure processMessage m:msg
  if msg.name EQS "Timer" then
    pipe run
    ! Generate sine wave and get fft of the sine wave
    waveform/rt/bg _mywave{ps=32k} shape=sin form=cf elem=512k amp=32e3 freq=sr/40 delta=1/sr
    fft/bg _mywave _myfft

    set this.timer(0) 0 ! this turns timer off
    pause 2

    assert/text="^reg.main.name: Feature Not Lost When PIPE Activity Delayed" &
       reg.idplot.features.plotfeat.type eqss "|Data|"
    pipe stop
  else
    ! do nothing
    say "^reg.main.name: Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif
return