!******************************************************************************!
! Test the plotting of Type 2000 files (Layer2D).
!
! Author:  J. Czechowski
!******************************************************************************!
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)
  switch COREGRAPHICS coreGraphics GET DEF=FALSE SDEF=TRUE  ! for a quick check of graphics - more extreme tests

  if interAct then
    call setDatDir

    set samples 1e9
    set format sf
    set sr 1e5
    set over 0
    set sfreq sr/10
    set cfreq 0
    set amp 1e4
    set nexp 1

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

      waveform/throttle=real _wave format 10e10 sin freq=sfreq amp=amp delta=1/sr
      fft/dbf _wave _waveb{form=sb} nfft=1k over=over
      !plot/id=idplot2/nice _waveb{cl=8} type=line y1=-100 y2=80
      plot/id=idplot/nice _waveb{tag="lay2d"} z1=-100 z2=80 /lpb=16 axis=~grid ! Axis added for Bug 73

      plot/id=apenny/mousewheelzoom/usemouseposition ^{datDir}.apenny.prm axis=~grid|gridfront          ! Axis added for Bug 73 !3.9.1 add mouse zoom
      plot/id=threed ^{datDir}.alaska.prm view=xyz axis=~grid ! Axis added for Bug 73

      gcontrol label  macro   "MACRO"
      gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
      set gc.main.itemColors {PASS=GREEN,FAIL=RED}
      set instructions "Each Plot should have a grid showing. The grid in the &
                        plot of Alaska should be partially hidden by the plot. &
                        Change Z-Axis Range to HALF and DOUBLE, then verify changes."
      gcontrol text idtext "Instructions" "^instructions" 24 8 /title
      gcontrol label  tests   "TESTS" AlwaysOpen
      gcontrol choice zvalues "Set Z-axis range:" "Half,Normal,Double" "NORMAL" /tleft
      !!! Deprecated in 2.5.0 -- use the reference in MPlot
      !!! gcontrol dval   setZ1   "Z1 Monitor" 0 -999 999 5 /msg=no /edit=no /mon=reg.idplot.layers.lay2d.z1
      !!! gcontrol dval   setZ2   "Z2 Monitor" 0 -999 999 5 /msg=no /edit=no /mon=reg.idplot.layers.lay2d.z2
      gcontrol dval   setZ1   "Z1 Monitor" 0 -999 999 5 /msg=no /edit=no /mon=reg.idplot.z1
      gcontrol dval   setZ2   "Z2 Monitor" 0 -999 999 5 /msg=no /edit=no /mon=reg.idplot.z2
    pipe off
  endif

  ! Additional interactive tests, only run with /BASELINE
  if interAct and baseline then
    %test_plot_layer2d_big                ! Bug 1849 - JTM fixed test in 4.1.4
    %test_plot_layer2d_colormap           ! Bug 1698 Bug 2196
    %test_plot_layer2d_compression        ! Bug 1031 Bug 1043
    %test_plot_layer2d_directcolor        ! <-- Includes test for Bug 724 (DR 553688)
    %test_plot_layer2d_dragbox            ! NXM-3088 for Layer2D DATAX refresh issue
    %test_plot_layer2d_feature 40k        ! Bug 1878
    %test_plot_layer2d_feature 400k       ! Bug 1878
    %test_plot_layer2d_feature 4000k      ! Bug 1878
    %test_plot_layer2d_fft_flow           ! NXM-3213 MMB plot on top of popped out plot +SwingPopups
    %test_plot_layer2d_flicker            ! Bug 2388
    %test_plot_layer2d_flow               ! Bug 1254 Bug 1544 Bug 2091
    %test_plot_layer2d_lps 4              ! Bug ??
    %test_plot_layer2d_lps 2              ! Bug ??
    %test_plot_layer2d_lps 1              ! Bug ??
    %test_plot_layer2d_ordered            ! Bug 1254 Bug 1544 Bug 2091
    %test_plot_layer2d_paging             ! Bug 1293
    !%test_plot_layer2d_pipes             ! Bug 2338 Bug 2340 Skipping - covered elsewhere
    !%test_plot_layer2d_time              ! Bug 2166 Skipping - covered elsewhere
    %test_plot_layer2d_transparent_raster ! NXM-3598
    %test_plot_layer2d_view_rendering     ! Bug 1043 Bug 1048
    %test_plot_layer2d_zooms              ! Bug 1871 Bug 2327
    %test_plot_layer2d_zvals              ! Bug 1326 Bug 1901

  ! If COREGRAPHICS run a short list of extreme tests that tend to be the ones to show graphical issues
  elseif coreGraphics then
    %test_plot_layer2d_dragbox ! NXM-3088 for Layer2D DATAX refresh issue
  endif
endmacro

!******************************************************************************!
procedure processMessage m:msg
  !say "msg.name ^msg.name, data ^msg.data"

  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name " msg.data eqss "PASS"
    pipe stop

  elseif msg.name eqs "ZVALUES" then
    if msg.data eqs "NORMAL" then
      set zMult 1.0
      set descr   "the same as the original range"
    elseif msg.data eqs "HALF" then
      set zMult 0.5
      set descr   "half of the original range (i.e. more blue)"
    elseif msg.data eqs "DOUBLE" then
      set zMult 2.0
      set descr   "twice the original range (i.e. more red)"
    else
      warn "Unknown setting for ZVALUES: ^{msg.data}"
    endif

    set plots {IDPLOT={LAYER="LAY2D",MIN=-100,MAX=80},&
               THREED={LAYER="ALASKA",MIN=-1.2,MAX=1.2},&
               APENNY={LAYER="APENNY",MIN=-127,MAX=127}}

    foreach key intable plots
      calc min ^{plots.^{key}.min} zMult *
      calc max ^{plots.^{key}.max} zMult *

!!! Deprecated in 2.5.0 -- use the reference in MPlot
!!!      set reg.^{key}.layers.^{plots.^{key}.layer}.z1 min
!!!      set reg.^{key}.layers.^{plots.^{key}.layer}.z2 max
      set reg.^{key}.z1 min
      set reg.^{key}.z2 max

      if key eqs "IDPLOT" then
        set gc.idtext.value "The new z-axis values for the pipe should be Z1=^{min} &
                             and Z2=^{max}. The dynamic range of the pipe and the &
                             penny should be ^{descr}; the 3D plot of Alaska should &
                             be unchanged."
      endif

!!! Deprecated in 2.5.0 -- use the reference in MPlot
!!!      assert/text="Checking reg.^{key}.layers.^{plots.^{key}.layer}.z1" &
!!!                            reg.^{key}.layers.^{plots.^{key}.layer}.z1 eq min
!!!      assert/text="Checking reg.^{key}.layers.^{plots.^{key}.layer}.z2" &
!!!                            reg.^{key}.layers.^{plots.^{key}.layer}.z2 eq max

      assert/text="Checking reg.^{key}.z1" reg.^{key}.z1 eq min
      assert/text="Checking reg.^{key}.z2" reg.^{key}.z2 eq max
    endfor
  else
    ! do nothing
    say "Unhandled message name: ^msg.name from fid: ^msg.fid dats: ^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
