!------------------------------------------------------------------------------!
! Demonstrate errors from setting invalid plot parameters.
!
! @Author:  J. Bauer
! @Bug: 1716, 1897
!------------------------------------------------------------------------------!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE

  call setDatDir

  set def_instructions &
      "Should see a PLOT of a penny and a shellgui.\n\n&
       1) Click on the 4 buttons to set invalid values on PLOT &
       and observe the SHELGUI for passed test cases.\n&
       'Compression' now gives a not found in list WARNing\n&
       in the terminal and NOT in the shell gui.\n\n& 
       2) Click on the buttons to change the Plot type and line type.\n\n&
       Note: If running confidence tests, you may need to open a separate terminal to run the test successfully."

  set daFile "^{datDir}.apenny.prm"
  set val   ""
  set eFlag ""
  set stat  "FAIL"
  invoke plotTypes nxm.sys.prim.plot.typeList
  invoke lineTypes nxm.sys.libg.Line.typeList

  if interAct then
    pipe init

    panel/msgid=MAIN/setup/controls=gc
      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" "^def_instructions" 24 14 /title


    shellgui/id=idshellgui/attach

    plot/id=idplot/READOUT="+OnAxis" daFile

    gcontrol/nc=2 button sets "Click to set with invalid data" "Type,Mode,View,Compression" none

    gcontrol/nc=2 button setPlotType "Set Plot Type" "^plotTypes"
    gcontrol prompt showPlotType "Plot Type: " "" /MON=reg.idplot.plottype /flags=+NOEDIT

    gcontrol/nc=2 button setLineType "Set Line Type" "^lineTypes"
    gcontrol prompt showLineType "Line Type: " ""  /MON=reg.idplot.layers.apenny.line.type /flags=+NOEDIT

    pipe off

  endif

  ! Lines below executed after the user hits PASS/FAIL
  assert/text="^reg.main.name:  User indicated" stat eqss "PASS"
  set eFlag "PLOTTYPE"
  plot/id=idplot/READOUT="+OnAxis" daFile type="BOGUS_PLOT_TYPE"

endmacro

!******************************************************************************!
procedure processMessage m:msg
  if msg.name eqs "MAIN" then
    set stat msg.data
    !assert/text="^reg.main.name:  User indicated" msg.data eqss "PASS"   ! handled in main macro section
    pipe stop

  elseif msg.name eqs "SETS" then
    set eFlag msg.data
    set reg.idplot.^{msg.data} "BOGUS_VALUE_FOR_^{msg.data}"

  elseif msg.name eqs "SETPLOTTYPE" then
    set reg.idplot.type ^msg.data

  elseif msg.name eqs "SETLINETYPE" then
    if reg.idplot.plottype neqs LINE then
      set reg.idplot.plottype LINE
    endif
    set reg.idplot.layers.apenny.line.type ^msg.data
  endif
return

!******************************************************************************!
! Prior to Bug 1897 fix this would procedure would cause a stack trace for
!    index out of bounds (neverending loop in macro.java)
procedure processException m:emsg
  !say "Got Exception: eFlag= ^eFlag"
  if eFlag eqs "MODE" or eFlag eqs "VIEW" or eFlag eqs "COMPRESSION" or eFlag eqs "TYPE" then
    assert/text="DR1716: Setting invalid value for plot ^eFlag." &
      "MidasException" SUBS ^emsg.data AND "not found in list" SUBS ^emsg.data

  elseif eFlag eqs "PLOTTYPE" then
    assert/text="DR1897: Handled exception for invalid TYPE." &
      "MidasException" SUBS ^emsg.data AND "not in list" SUBS ^emsg.data

  else
    assert/text="^reg.main.name: Caught unexpected exception ^{emsg.data}" "FALSE" isTrue
    if "Trace" SUBS ENV.DEBUG then invoke ,, emsg.data.printStackTrace()
  endif

  set eFlag ""

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
