! Test Layer2D's paging mode (i.e. when lines per screen (LPS) is less than the
! number of elements in the file) on a scalar byte (SB) data file (e.g. apenny)
!
! Bug:     1293
! Issue: NXM-3453 PLOT: delta readouts should not require second click
! Author:  Neon Ngo
!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE

  call setDatDir

  if interAct then
    set testfile ^{datDir}.apenny.prm
    status testfile size=numElements
    set L:lps numElements/2
    set instructions "Should see plot of a penny. It is drawn using paging mode &
                        on a SB data file with /LPS=^lps.\n\n&
                        1) Click on the plot then move the mouse.\n\n&
                        2) Observe the readout and ensure the given &
                        dZ value is the same as the current Z value minus the last &
                        mouse click pos Z value given in the prompt below.\n\n&
                        3) Each click should turn the on axis delta readings on and off.\n\n&
                        4) Click the 'True' button and delta readings should always be active."

    pipe init
      panel/msgid=MAIN/setup/controls=gc
      ! NTN: to test Bug 1293, set the lines per screen (LPS) to be half the number
      !      of elements in the test file to force paging mode
      plot/msgid=main ^testfile readout="+onAxis|+dz" /lps=^lps
      assert/text="Layer2D using paging mode" reg.plot.layers.apenny.ispaged

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


      gcontrol text idtext "Instructions" "^instructions" 24 18 /title

      gcontrol prompt zmark "Z val at last mouse click:" /noedit

      gcontrol button AlwaysDeltas "delta on axis readouts always active" "True,False" "False"
    pipe off
  endif

endmacro

!******************************************************************************!
procedure processMessage m:msg

  !say "msg.name ^msg.name, data ^msg.data"

  if msg.name eqs "MAIN" then
    assert/text="Plot Layer2D paging mode" msg.data eqss "PASS"
    pipe stop
  elseif msg.name eqs "MARK" then
    !say "Got MARK msg: data= ^msg.data"
    set gc.zmark.value msg.data.z
  elseif msg.name eqs "ALWAYSDELTAS" then
    ! This section added for NXM-3453 +ALAYSDELTAS
    if msg.data eqs TRUE then
      invoke ,, reg.plot.setReadout("+ALWAYSDELTAS")
    else
      invoke ,, reg.plot.setReadout("-ALWAYSDELTAS")
    endif
  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
