startmacro
!
! Test the X and Y Cuts
!
! Author:  J. Hallam / J. Bauer
!
switch INTERACTIVE  interAct     GET DEF=TRUE  SDEF=TRUE
switch BASELINE     baseline     GET DEF=FALSE SDEF=TRUE
switch COREGRAPHICS coreGraphics GET DEF=FALSE SDEF=TRUE  ! for a quick check of graphics - more extreme tests

call setDatDir

set defaultInstructions &
    "Should see a (zoomed-in) plot of Alaska.\n\n&
     1) Push the 'XCut' button to bring up a XCut line plot\n&
     2) Push the 'YCut' button to bring up a YCut line plot.\n&
     => The Cuts should come up zoomed (X-Axis on the Cut\n   &
        plot corresponds to the zoomed Cut axis).\n\n&
     3) Next MMB click on the plot to bring up the plot menu, click on 'Options'.\n   &
        LMB click on 'Xcut' in the Plot Options Menu to update the Xcut plot.\n&
     4) Repeat Step 3 except LMB click on 'Ycut' in the Plot Options Menu\n   &
        to update the Ycut plot.\n\n&
     5) Next LMB click on the plot (to get focus).\n&
     6) Press 'X' on the keyboard to update the XCut plot\n   &
        or 'Y' to update the YCut plot.\n&
     => The Y values in the line plot correspond to\n   &
         altitude values on the map.\n\n&
     7) Hover over a mountain (brown patch on the map)\n&
     8) Do a cut.\n&
     => The mountain should show as a higher Y-Axis value\n   on the cut."


if interAct or coreGraphics then
  ! test for NXM-2898 XCut (test improved in 3.7.3 for NXM-3158)  
  ! plot apenny below
  plot/ID=ORIG ^{datDir}.apenny.prm CM=20log VIEW=POLAR READOUT=Show|onStatus|onTitle|X|dX|Y|dY|dRange|View|Scientific|ExtPrec| /bg
  ! message sendw XCUT_ORIG
  message sendw ORIG NAME=XCUT DATA={IX=60,IY=72}
  pause 1

  ! onAxis should be added to original Plot Mask
  invoke onAxisMask nxm.sys.libg.MPlot.R_ONAXIS
  calc L:expectedXcutReadout REG.ORIG.READOUT onAxisMask BOR

  assert/text="^reg.main.name XCUT complex mode equals Original Plot complex mode." REG.XCUT_ORIG.CM EQS REG.ORIG.CM
  assert/text="^reg.main.name XCUT readout equals Original Plot readout." REG.XCUT_ORIG.READOUT EQ expectedXcutReadout
  ! message send exit to close xycut and plot
  message send XCUT_ORIG NAME=EXIT
  message send ORIG NAME=EXIT

  pipe init

    panel/msgid=MAIN/setup/controls=gc
    plot/id=idplot/READOUT="+OnAxis" ^{datDir}.alaska.prm ZOOMTO={X1=-160,X2=-145,Y1=60,Y2=75}

    gcontrol label mainLabel "Main"
    gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
    set gc.main.itemColors {PASS=GREEN,FAIL=RED}
    gcontrol text idtext "Instructions" "^defaultInstructions" 40 22 /title

    gcontrol button cuts "SEND CUT MESSAGE" "XCUT,YCUT"

  pipe off

  %test_plot_xycut_layer2d_pipe ! NXM-3567 since 4.1.1

endif

endmacro

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

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

call setInstructions "^defaultInstructions"

if msg.name eqs "MAIN" then
  assert/text="^reg.main.name user selected " msg.data eqss "PASS"
  pipe stop
elseif msg.name eqs "CUTS" then
  set l:ix 300
  set l:iy 300
  set t:loc {IX=^ix,IY=^iy}
  message func=send id=idplot name=msg.data data=^loc
else
  ! do nothing
  say "^reg.main.name: Unhandled message name: ^msg.name from fid: ^msg.fid data: ^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

!******************************************************************************!
procedure open
  ! Automatically called
return

!******************************************************************************!
procedure setInstructions s:msgString
  set reg.panel.controls.idtext.value msgString
return
