!******************************************************************************!
! This macro tests a "visible" FEATURE's text/tags are dynamically placed in visible 
! part of the PLOT. Before the fix was put in, the user could pan out of the view of the FEATURE's
! text labels because it was statically positioned.
!
! @bug      2970 - PLOT: Features text placement sticky
! @author:  Peter Quan
!******************************************************************************!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE  ! for normal interactive test(s)

  call setDatDir

  if interAct then
    set featureTab {NAME="FEAT",TEXT="Feat",TYPE="|BOX|TEXT|BTAG|TTAG|LTAG|RTAG|DTag",X=89,Y=66,DX=20,DY=30,COLOR="YELLOW"}
    res zoomTests "Left,Bottom,Right,Top,Top Left,&
                     Top Right,Bottom Left,Bottom Right,&
                     Top Half,Left Half,Bottom Half,Right Half"
    set instruct "Click on each button below and verify the "Feat" text is always centered with respect to the &
                  line it is on. If 2 or more lines of the square are visible, then you should see the same amount &
                  of "FEAT" text on the screen. \n\nFor instance, if you click on the Top Left button, you should &
                  see two "FEAT" text centered on the left and top lines of the square."

    pipe on
      panel/msgid=MAIN/setup/controls=gc
      plot/id=idplot ^{datDir}.apenny.prm options=+bstore
      feature label=ffeat table=^{featureTab} plot=idplot
      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" instruct 24 14 /title
      gcontrol/nc=3 button zoomAction "Feature Zoom Test" ^zoomTests
    pipe off
  endif
endmacro

!******************************************************************************!
! Main process message for this macro. Should be right after the ENDMACRO.
!******************************************************************************!
procedure processMessage m:msg
  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: User indicated tests" msg.data eqss "PASS"
    pipe stop

  elseif msg.name eqss "ZOOMACTION" then

     if msg.data EQS "Left" then
       message FUNC=sendw ID=IDPLOT NAME=ZOOM data={x1=77,x2=85,y1=60,y2=70}

     elseif msg.data EQS "Bottom" then
       message FUNC=sendw ID=IDPLOT NAME=ZOOM data={x1=84,x2=92,y1=49,y2=53}

     elseif msg.data EQS "Right" then
       message FUNC=sendw ID=IDPLOT NAME=ZOOM data={x1=95,x2=105,y1=60,y2=70}

     elseif msg.data EQS "Top" then
       message FUNC=sendw ID=IDPLOT NAME=ZOOM data={x1=84,x2=92,y1=79,y2=83}

     elseif msg.data EQS "Top Left" then
       message FUNC=sendw ID=IDPLOT NAME=ZOOM data={x1=77,x2=82,y1=78,y2=83}

     elseif msg.data EQS "Top Right" then
       message FUNC=sendw ID=IDPLOT NAME=ZOOM data={x1=94,x2=102,y1=78,y2=83}

     elseif msg.data EQS "Bottom Left" then
       message FUNC=sendw ID=IDPLOT NAME=ZOOM data={x1=77,x2=82,y1=49,y2=54}

     elseif msg.data EQS "Bottom Right" then
       message FUNC=sendw ID=IDPLOT NAME=ZOOM data={x1=95,x2=100,y1=49,y2=54}

     elseif msg.data EQS "Top Half" then
       message FUNC=sendw ID=IDPLOT NAME=ZOOM data={x1=70,x2=110,y1=76,y2=82}

     elseif msg.data EQS "Left Half" then
       message FUNC=sendw ID=IDPLOT NAME=ZOOM data={x1=75,x2=82,y1=45,y2=95}

     elseif msg.data EQS "Bottom Half" then
       message FUNC=sendw ID=IDPLOT NAME=ZOOM data={x1=70,x2=110,y1=48,y2=58}

     elseif msg.data EQS "Right Half" then
       message FUNC=sendw ID=IDPLOT NAME=ZOOM data={x1=90,x2=102,y1=45,y2=95}

     endif
  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
