!******************************************************************************!
! Test setting results through mouse interaction on an xgeoplot using /XCNT and /MTAG
! 
! @since    NeXtMidas 3.9.1
! @bug      3094 Need X-Midas style /MTAG support for XGEOPLOT
! @author:  Kevin Esterheld
!******************************************************************************!
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)

  call setDatDir

  if interAct then
    set instructions "This uses xgeoplot\n\n&
                      You should see three plots. \n\n&
                      On the top plot, moving the mouse over the plot updates PROMPT 1 with the Z value under the mouse.\n\n&
                      Left-clicking the middle plot will update PROMPT 2 with the mouse's X coordinate and PROMPT 3 with the Y coordinate.\n\n&
                      PROMPT 4 will update with the bottom plot longitude from a mouse movement on that plot.\n\n&
                      Left-clicking on the bottom plot turns the updating on and off."

    pipe on
      panel/msgid=MAIN/setup/controls=gc
      gcontrol label macro "Test MACRO"
      gcontrol menu  main "Exit with Status =" "PASS,FAIL" TABLE={ItemColors={PASS="GREEN",FAIL="RED"}} /tleft
      gcontrol text  idtext "Instructions" instructions 24 22 /title

      gcontrol prompt prompt1 "PROMPT 1 (Top Z Value)" ""
      gcontrol prompt prompt2 "PROMPT 2 (Mid X Value)" ""
      gcontrol prompt prompt3 "PROMPT 3 (Mid Y Value)" ""
      gcontrol prompt prompt4 "PROMPT 4 (Bottom Lon)" ""
      xgeoplot/id=plot1/xcnt=motion/mtag=(z:gc.prompt1.value) ^{datDir}.apenny.prm
      xgeoplot/id=plot2/xcnt=click/mtag=(x:gc.prompt2.value,y:gc.prompt3.value) ^{datDir}.apenny.prm
      xgeoplot/id=plot3/msgid=main/mtag=(x:gc.prompt4.value) ^{datDir}.world.prm cnt=motion|click   ! uses CNT= instead of /XCNT
      
      gcontrol line
      
    pipe off

  endif
endmacro

!******************************************************************************!
! Main process message for this macro. Should be right after the ENDMACRO.
!******************************************************************************!
procedure processMessage m:msg
   !say "Got msg ^msg"
  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: User indicated tests" msg.data eqss "PASS"
    pipe stop
  elseif msg.fid eqs "PLOT3" and msg.info eq 1 then
    ! the code below will use the left-click as a start-stop of the mtag functions
    set mtagTable reg.plot3.mtag
    set t:newTab {}
    table mtagTable equals newTab nullTable
    if mtagTable isNull or nullTable isTrue
      set t:newTab {x=gc.prompt4.value}
    endif
      set reg.plot3.mtag newTab
  else
    !say "Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif
return

!******************************************************************************!
! If an unexpected exception is caught, mark test as failed, unless it is expected
!******************************************************************************!
procedure processException m:emsg
  if expectedException REXISTS then
    assert/text="^reg.main.name: Expected ERROR starts with: ^{expectedException}" expectedException EQSS emsg.data.message
    remove expectedException
  else
    assert/text="^reg.main.name: Caught unexpected exception ^{emsg.data}" "FALSE" isTrue
    if "Trace" SUBS ENV.DEBUG then invoke ,, emsg.data.printStackTrace()
  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
