!******************************************************************************!
! Plot tests for LayerMulti.
!
! @bug    954  LayerMulti: does not correctly handle pipe data ...
! @bug    1210 LayerMulti: Missing refresh() at the end of setColumns(..)
!
! Author:  J. Hallam / Neon Ngo
!******************************************************************************!
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)

  if interAct then
    res  testfile "temp_testplot_layermult.tmp"
    res L:numElements 50
    call createFile testfile numElements
    res bpe 24                ! bytes per element in testfile
    res ps  numElements*bpe*3 ! pipe size for _zerosize pipe

    pipe on

      panel/msgid=MAIN/setup/controls=gc
      gcontrol label macro "MACRO"
      gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
      set gc.main.itemColors {PASS=GREEN,FAIL=RED}

      set myInstructions "Plots 1, 2, 3, and 4 should look the same after the pipe finishes &
                          drawing one screens worth of data. Plot 5 should plot the data 3 times. &
                          Plot 6 is 1.5 times the number of data elements, so it should shift the &
                          data on the plot as the piped data cycles. The 4 dynamic (Piped Data) plots &
                          should have a veritical draw line on where it last drew the plot data. &
                          Change the columns and all the plot should reflect the change. &
                          Finally, PAUSE the pipe, then try to ZOOM and PAN in the plots; for &
                          Plot 4. only the last line-segments in the buffer are plotted."

      gcontrol text idtext "Instructions" "^myInstructions" 24 20 /title
      gcontrol menu changeColumns "Columns" "ORD1,ORD2,ORD3" "ORD1|ORD2|ORD3" /tleft /toggle /togglelist /chkbox /nc=3
      gcontrol button state "Pipe" "Run,Pause" 1 /tleft

      noop/wrap/tl=1/rt       testfile _mygoodpipe{size=numElements}
      noop/wrap/tl=1/rt/ps=ps testfile _zerosize{size=0}  ! <-- Matches Bug 954 (where SIZE=0 for data over RMIF)

      ! Plot 1. Static data
      plot/id=staticplot testfile{TAG=MULT}
      ! Plot 4. Static data with paging mode
      plot/id=staticpagingplot/lpb=(numElements/3) testfile{TAG=MULT}

      ! Plot 2. Piped data, SIZE=number elements
      plot/id=goodpipeplot _mygoodpipe{TAG=MULT}
      ! Plot 3. Piped Data, SIZE=0, /LPS=number elements
      plot/id=lpsplot/lps=numElements _zerosize{TAG=MULT,LAYER={LT="Multi",COLUMNS=gc.changeColumns.value}}
      ! Plot 5. Pipd data, SIZE=0
      plot/id=ZeroSizePipePlot _zerosize{TAG=MULT,LAYER={LT="Multi",COLUMNS=gc.changeColumns.value}}
      ! Plot 6. Pipe data, SIZE=0, /LPS= 1.5 * number of elements
      plot/id=oddlpsplot/lps=(numElements*1.5)/tl=(numElements*1.5) _zerosize{TAG=MULT,LAYER={LT="Multi",COLUMNS=gc.changeColumns.value}}

    pipe off

    erase testfile
  endif

  ! Additional interactive tests, only run with /BASELINE
  if interAct and baseline then
    %test_plot_layermulti_bug1229  ! Bug 1229 Bug 1344
    !%test_plot_layermulti_bug1649 ! Bug 1649 Skipping since this test fails
    %test_plot_layermulti_modes    ! Bug 2542
  endif
endmacro

!**************************************************************************************************!
procedure processMessage
  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: User indicated tests" msg.data eqss "PASS"
    pipe stop

  elseif msg.name eqs "CHANGECOLUMNS" then
    set reg.lpsplot.layers.MULT.columns          "^msg.data"
    set reg.staticplot.layers.MULT.columns       "^msg.data"
    set reg.staticpagingplot.layers.MULT.columns "^msg.data"
    set reg.goodpipeplot.layers.MULT.columns     "^msg.data"
    set reg.ZeroSizePipePlot.layers.MULT.columns "^msg.data"
    set reg.lpsplot.layers.MULT.columns          "^msg.data"
    set reg.oddLPSPlot.layers.MULT.columns       "^msg.data"

  elseif msg.name eqs "STATE"
    pipe ^msg.data

  else
    warning "^reg.main.name: unrecognized message ^msg.name from ^msg.fid"
  endif
return

!**************************************************************************************************!
procedure createFile fn:fname L:nels[100] D:xdelta[0.05]
  file open/d/n tag fname{SR=(ORD1/SD,ORD2/SD,ORD3/SD)}
  do i 0 nels-1
    result tag.setdata(i,ORD1) 10+i
    result tag.setdata(i,ORD2) 20+i
    result tag.setdata(i,ORD3) nels+30-i
  enddo
  file close tag
  headermod fname format=sd xs=0 xd=xdelta
return
