!******************************************************************************!
! Test case PLOT MIMIC
!
! @bug      2910 - PLOT: MIMIC capability should be available to users
! @since:   NeXtMidas 3.5.4
! @author:  Jeanette McCall
! @version: $Id: test_plot_mimic.mm,v 1.1 2015/06/22 18:33:27 jtm Exp $
!******************************************************************************!
startmacro/msgid=MAIN
  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)
  
  if interAct then
    set instructions "The top and bottom plots should be line plots and the middle plot should be a raster plot.\n&
      1) ZOOM in and out on the different plots and the other plots should MIMIC.\n&
      2) While ZOOMed in try PANing on the different plots (using MMB Drag), all the plot should follow."

    res sr      1e5
    res over    0
    res sfreq   sr/10
    res amp     1e4
    res navg    1
    res nfft    1k
    res format  sf
    res samples inf

    pipe on
      panel/msgid=MAIN/setup/controls=gc
      gcontrol label macro "Test MACRO" AlwaysOpen
      gcontrol menu  main "Exit with Status =" "PASS,FAIL" TABLE={ItemColors={PASS="GREEN",FAIL="RED"}} /tleft
      gcontrol text  idtext "Instructions" instructions 24 12 /title


      waveform _wave format=sf elem=inf shape=sin freq=sfreq amp=amp delta=1/sr
      fft _wave _fft nfft=nfft navg=navg over=over /dbf
      noop _fft _fftcopy

      gc dvalue sfreq "Sine Freq" sfreq -sr sr sr/20

      plot/id=plot1/nice _fft{cl=8} cnt=motion|click|drag type=line y1=-100 y2=80 MIMIC=plot2|plot3
      feature ,, mark1 {TYPE=SYM|VRIDE,SYMBOL=CIRCLE,NAME=MARK,COLOR=YELLOW,ENABLE=1,X=SR/10} plot1
      plot/id=plot2/nice _fft   cnt=click|drag    z1=-100 z2=80   /lpb=16      MIMIC=plot1|plot3 /lpb=16
      plot/id=plot3/nice _fftcopy{cl=8} cnt=click|drag type=line  scale=AutoMin|AutoMax AUTOL=32 MIMIC=plot1|plot2

    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 "SFREQ"
    set reg.waveform.freq msg.data
  elseif msg.name eqs "CFREQ"
  elseif msg.fid eqss "PLOT" then
    res fid msg.fid
    if msg.name eqs "POINTER"
      pause 0.1
      message prune ,, msg
      if fid eqs "PLOT1" then set msg.name "MARK"
    endif
    if msg.name eqs "MARK" then
      set mark1.x ^msg.data.x	 ! Update plot marker
      set gc.SFREQ.action msg.data.x
    endif
  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
