!******************************************************************************!
! Test Plot Scale dialog.
!
! Arguments: None
!
! Issue    NXM-1438 PLOT menu does not reflect reality
! Since    NeXtMidas 2.7.3
! Author:  J. Bauer
!******************************************************************************!
startmacro
switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE
switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE

set defaultInstructions &
    "Should see a plot of a sinewave.\n\n&
     Press the SET BOUNDS button to 'ZOOM' &
     in on the sinewave."

call setDatDir

if interAct then
  pipe init

  ! Change the keyMap to custom settings
  env set KEYMAP {PLOT={LEFT="L",RIGHT="R",in=i,down=d,up=u,out=o}}

  panel/setup/controls=gc
  plot/msgid=MAIN/id=idplot/READOUT="+OnAxis|-DateString" ^{datDir}.sinewave.prm

  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 20 /title

  gcontrol button setbounds "" "SET BOUNDS" /tleft
  gcontrol button scale     "" "SHOW SCALE DIALOG" /tleft

  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 rescale tests" msg.data eqss "PASS" 
  pipe stop
elseif msg.name eqs "SETBOUNDS" then
  invoke ,, reg.idplot.setXBounds(0,1)
  invoke ,, reg.idPlot.setYBounds(0,1)
  set gc.idtext.value "The plot should have:\n&
                       X and Y range of 0 to 1\n\n&
                       Press the 'SHOW SCALE DIALOG' button to bring up the scale dialog."
elseif msg.name eqs "SCALE" then
  invoke ,, reg.idplot.configure("SCALE")
  set gc.idtext.value "The scale dialog should be showing with:\n&
                       View X|Y Min / Max of 0 and 1, respectively.\n\n&
                       1) Use the dialog to change the value of View X or Y\n\n&
                       2) Hit the 'APPLY' button.\n&
                       => The view should change.\n\n&
                       3) Change the FORCE RESCALE value to TRUE\n\n&
                       4) Click apply.\n&
                       => The plot should revert to the default values\n   &
                          (i.e. look like the original)."
  invoke ,, gc.idtext.refresh()   ! needed since dialog stealing focus means text box does not refresh
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
