!******************************************************************************!
! Test the plotting of FEATUREs
!
!   Author : J. Hallam / Neon Ngo
!******************************************************************************!
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)
  switch COREGRAPHICS  coregraphics GET DEF=FALSE SDEF=TRUE  ! for a quick check of graphics - more extreme tests - since 3.9.2

  call setDatDir
  res  z:mytrue true

  if interAct then
    call test_line_settings_lost ! Bug 1405 (Symbol settings lost if symbol is null)

    invoke pi nxm.sys.inc.Constants.PI
    invoke radiusEarth nxm.sys.inc.Constants.EARTH_EQUATORIAL_RADIUS

    res normalTests "None,Circ,Aero,Arrow,ASCII,Circle,Triangle,Lines,Filled,&
                     Many,Thickness,Tri,OSymbol,ZoomIn,Data,Image,Scroll"

    invoke isWarning nxm.sys.libg.Feature.isWarningFeatureNotDrawn()

    pipe init
      panel/msgid=MAIN/setup/controls=gc/options=-RotateTabs
      plot/id=idmap  ^{datDir}.world.prm
      ! NTN: added options=+BSTORE|+DBUFFER on PLOT to reduce flickering
      plot/id=idplot ^{datDir}.apenny.prm options=+BSTORE|+DBUFFER

      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" "Select each of the 'Add Penny Feature' and 'Add World Feature' options below." 24 13 /title
      gcontrol/nc=3 button nextpenny "Add Penny Feature" ^normalTests none
      gcontrol/nc=3 button nextmap   "Add World Feature" "None,Image,Ellipse" none
    pipe off
  endif

  ! Additional tests, only run with /BASELINE
  if baseline then
    %test_feature_no_name

    if interAct then
      %test_feature_attributes
      %test_feature_ellipse
      %test_feature_hilite
      %test_feature_groups
      %test_feature_remove
      %test_feature_save_load
      %test_feature_tags_visible ! added to automated testing in 3.7.2
      %test_feature_time
      %test_feature_top
      %test_feature_select_popup
    endif

  ! If COREGRAPHICS run a short list of extreme tests that tend to be the ones to show graphical issues
  elseif coregraphics then
    !%test_feature_tags_visible /coregraphics ! nxm413 removing from coregraphics
  endif
endmacro

!******************************************************************************!
procedure processMessage m:msg
  !say "msg.name ^msg.name, data ^msg.data"
  invoke ,,        nxm.sys.libg.Feature.setWarningFeatureNotDrawn(^isWarning)

  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: user indicated tests" msg.data eqss "PASS"
    pipe stop

  elseif msg.name eqss "NEXTMAP" then
    invoke xxx reg.win.idmap.makeVisibleTab()

    if msg.data EQS "NONE" then
      set reg.idmap.removeFeature "*"
      call setInstructions "All features should be removed from the world plot"

    elseif msg.data EQS "ELLIPSE" then
      call test_feature_ELLIPSE

    elseif msg.data EQS "IMAGE" then
      call test_feature_MAPIMAGE

    else
      warning "Do not know ^msg.data feature"

    endif

  elseif msg.name eqss "NEXTPENNY" then
    invoke xxx reg.win.idplot.makeVisibleTab()

    if msg.data EQS "NONE" then
      set reg.idplot.removeFeature "*"
      call setInstructions "All features should be removed from the Penny plot"

    elseif msg.data EQS "CIRC" then
      call test_feature_circ

    elseif msg.data EQS "FILLFEA" then
      call test_feature_circ_deprecated

    elseif msg.data EQS "TRI" then
      call test_feature_TRI RED

    elseif msg.data EQS "OSYMBOL" then
      call test_feature_OSYMBOL AQUA

    elseif msg.data EQS "ASCII" then
      call test_feature_ASCII GREEN

    elseif msg.data EQS "CIRCLE" then
      call test_feature_CIRCLE_symbol blue

    elseif msg.data EQS "CROSS" then
      call test_feature_CROSS blue

    elseif msg.data EQS "TRIANGLE" then
      call test_feature_TRIANGLE_symbol blue

    elseif msg.data EQS "LINES" then
     call test_feature_lines blue

    elseif msg.data EQS "FILLED" then
      call test_feature_FILLED GREEN

    elseif msg.data EQS "AERO" then
      call test_feature_AERO BLUE

    elseif msg.data EQS "ARROW" then
      call test_feature_ARROW BLUE

    elseif msg.data EQS "MANY" then
      call test_feature_MANY red

    elseif msg.data EQS "SCROLL" then
      call test_feature_TOOMANY red

    elseif msg.data EQS "THICKNESS" then
      call test_feature_THICKNESS green

    elseif msg.data EQS "ZOOMIN" then
      call test_dr836

    elseif msg.data EQS "DATA" then
      invoke ,,        nxm.sys.libg.Feature.setWarningFeatureNotDrawn(myTrue)
      call test_data_dr1392

    elseif msg.data EQS "IMAGE" then
      call test_image

    else
      warning "Do not know ^msg.data feature"
    endif
  else
    ! do nothing
    say "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 test_line_settings_lost
  ! Basic line tests for Bug 1405 (Symbol settings lost if symbol is null)
  new nxm.sys.libg.Line line

  set l:size 2
  set z:fill false
  do l:hdg 0 360 45
    set line.symbolSize    size
    set line.symbolFill    fill
    set line.symbolHeading hdg

    assert/text="^reg.main.name line.symbolSize    = ^size" line.symbolSize    eq  size
    assert/text="^reg.main.name line.symbolFill    = ^fill" line.symbolFill    eqs fill
    assert/text="^reg.main.name line.symbolHeading = ^hdg"  line.symbolHeading eqt CALC(hdg,360,MOD)

    if fill isTrue then
      set z:fill false
    else
      set z:fill true
    endif
    calc l:size size 2 +
  enddo


  set line.symbolSize    12
  set line.symbolFill    true
  set line.symbolHeading 45
  set line.symbol        "DIAMOND"
  assert/text="^reg.main.name line.symbolSize    = 12"   line.symbolSize    eq  12
  assert/text="^reg.main.name line.symbolFill    = true" line.symbolFill    eqs true
  assert/text="^reg.main.name line.symbolHeading = 45"   line.symbolHeading eqt 45

  set l:size 2
  set z:fill false
  do l:hdg 0 360 45
    set line.symbolSize    size
    set line.symbolFill    fill
    set line.symbolHeading hdg
    assert/text="^reg.main.name line.symbolSize    = ^size"            line.symbolSize     eq  size
    assert/text="^reg.main.name line.symbolFill    = ^fill"            line.symbolFill     eqs fill
    assert/text="^reg.main.name line.symbolHeading = ^hdg"             line.symbolHeading  eqt CALC(hdg,360,MOD)
    assert/text="^reg.main.name line.symbol.size   = line.symbolSize"  line.symbol.size    eq  line.symbolSize
    assert/text="^reg.main.name line.symbol.fill   = line.symbolFill"  line.symbol.fill    eqs line.symbolFill
    assert/text="^reg.main.name line.symbol.angle  = line.symbolAngle" line.symbol.angle   eq  line.symbolAngle

    if fill isTrue then
      set z:fill false
    else
      set z:fill true
    endif
    calc l:size size 2 +
  enddo
return

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

!******************************************************************************!
procedure test_image
  feature label=fnetwork table={NAME="network",TYPE=SYMBOL,X=12,Y=92,LINE={SYMBOL="^{datDir}.network.png"}} plot=idplot
  call setInstructions "Expected: an icon depicting two computers on top of the IN in 'IN GOD WE TRUST'."
return

!******************************************************************************!
procedure test_feature_circ
  !!! DX controls size of CIRCLE !!!
  feature label=fcirc1 table={NAME="CIRC1",TYPE="CIRC",X=89,Y=66,DX=3,COLOR="yellow"} plot=idplot
  feature label=fcirc2 table={NAME="CIRC2",TYPE="CIRC|FILLED",X=50,Y=75,DX=3,COLOR="yellow"} plot=idplot
  call setInstructions "Expected:\n&
                        - a YELLOW outline CIRCLE on Lincoln's nose\n&
                        - a filled YELLOW circle by his ear."
return

!******************************************************************************!
procedure test_feature_circ_deprecated
  !!! DX controls size of CIRCLE !!!
  feature label=fcircdep table={NAME="CIRCDEP",TYPE="CIRC|FILLFEA",X=80,Y=60,DX=3,COLOR="yellow"} plot=idplot
  call setInstructions "Expected a filled YELLOW circle by Lincoln's mouth."
return

!******************************************************************************!
procedure  test_feature_TRI S:color["RED"]
  feature label=ftri table={NAME="TRI",TYPE=TRI,X=55,Y=76,DX=10,COLOR=^color} plot=idplot
  call setInstructions "Expected: a ^color TRIANGLE on Lincoln's ear."
return

!******************************************************************************!
procedure  test_feature_OSYMBOL S:color["RED"]
  feature label=fosymbol table={NAME="OSYMBOL",TYPE=OSYMBOL,X=106,Y=19,DX=10,COLOR=^color} plot=idplot
  call setInstructions "Expected: a ^color CIRCLE on the '8' of 1984."
return

!******************************************************************************!
procedure test_feature_ASCII S:color["GREEN"]
  feature label=fascii1 table={NAME="ASCII1",TYPE=SYMBOL,X=7,Y=41,COLOR=^color,&
                               LINE={SYMBOL="ASCII-liberty"}} plot=idplot
  feature label=fascii2 table={NAME="ASCII2",TYPE=SYMBOL,X=7,Y=50,COLOR=^color,&
                               LINE={SYMBOL="ASCII-BigText",FONTSIZE=20,FONTSTYLE=BOLD|ITALIC}} plot=idplot
  call setInstructions "Expected:\n&
                       - a ^color ASCII symbol over the word LIBERTY\n  &
                         with the text 'liberty'\n&
                       - above it is another ^color symbol\n  &
                         with the text 'BigText'."
return

!******************************************************************************!
procedure test_feature_CIRCLE_symbol S:color["GREEN"]
  set centerX 5
  set centerY 120
  ! since 3.3.1: "middle" fcircle1 has SymbolFill=on to test Bug 2704
  feature label=fcircle1 table={NAME="CIRCLE_SYMBOL1",TYPE=SYMBOL,X=centerX,Y=centerY,COLOR=^color,&
                                LINE={SYMBOL="Circle",SYMBOLSIZE=10,SymbolFill=on}} plot=idplot
  feature label=fcircle2 table={NAME="CIRCLE_SYMBOL2",TYPE=SYMBOL,X=centerX,Y=centerY,COLOR=^color,&
                                LINE={SYMBOL="Circle",SYMBOLSIZE=20,SymbolFill=off}} plot=idplot
  feature label=fcircle3 table={NAME="CIRCLE_SYMBOL3",TYPE=SYMBOL,X=centerX,Y=centerY,COLOR=^color,&
                                LINE={SYMBOL="Circle",SYMBOLSIZE=30}} plot=idplot
  call setInstructions "Expected: 3 ^color CIRCLE symbols\n&
                        - with the same center point in the upper left corner\n&
                        - middle CIRCLE should be filled."
return

!******************************************************************************!
procedure test_feature_TRIANGLE_symbol S:color["GREEN"]
  feature label=ftriangle1 table={NAME="TRIANGLE1",TYPE=SYMBOL,X=120,Y=125,&
                                  COLOR=^color,LINE={SYMBOL="UTRI"},METADATA="This is TRIANGLE1"} plot=idplot
  feature label=ftriangle2 table={NAME="TRIANGLE2",TYPE=SYMBOL,X=120,Y=120,&
                                  COLOR=^color,LINE={SYMBOL="LTRI"},METADATA="This is TRIANGLE2"} plot=idplot
  feature label=ftriangle3 table={NAME="TRIANGLE3",TYPE=SYMBOL,X=120,Y=115,&
                                  COLOR=^color,LINE={SYMBOL="DTRI"},METADATA="This is TRIANGLE3"} plot=idplot
  feature label=ftriangle4 table={NAME="TRIANGLE4",TYPE=SYMBOL,X=120,Y=110,&
                                  COLOR=^color,LINE={SYMBOL="RTRI"},METADATA="This is TRIANGLE4"} plot=idplot
  feature label=ftriangle5 table={NAME="TRIANGLE5",TYPE=SYMBOL,X=120,Y=105,&
                                  COLOR=^color,LINE={SYMBOL="TRI",SymbolFill=on},METADATA="This is TRIANGLE5"} plot=idplot

  call setInstructions "Expected:\n&
                       - 5 five ^color triangle features along the right\n  &
                         that (from top to bottom) point:\n  &
                         UP, LEFT, DOWN, RIGHT, UP\n&
                       - Last one is filled.\n\n&
                        1) MMB click on one of the triangles.\n&
                        2) Select: Features -> Selected -> <NAME> -> Metadata \n&
                        3) Should say 'This is <name of feature>'"
return
!******************************************************************************!
procedure test_feature_lines S:color["BLUE"]
  feature label=flines table={NAME="LINES",TYPE=HLINE|VLINE,X=85,Y=45,&
                              COLOR=BLUE} plot=idplot

  call setInstructions "Expected: &
                        a HORIZONTAL and a VERTICAL line INTERSECTING &
                        on Lincoln's chin."
return
!******************************************************************************!
procedure test_feature_FILLED S:color["BLUE"]
  feature label=ffilled1 table={NAME="FILLED1",TYPE=SYMBOL,X=52,Y=80,COLOR=^color,&
                                LINE={SYMBOL="DTri",SYMBOLSIZE=12,&
                                      SYMBOLFILL=OFF}} plot=idplot
  feature label=ffilled2 table={NAME="FILLED2",TYPE=SYMBOL,X=58,Y=80,COLOR=^color,&
                                LINE={SYMBOL="DTri",SYMBOLSIZE=12,&
                                      SYMBOLFILL=ON}} plot=idplot

  call setInstructions "Expected: 2 ^color TRIANGLE features at the top of &
                        Lincoln's ear.\n\n&
                        Right one: ^color and filled\n&
                        Left one:  ^color and NOT filled"
return
!******************************************************************************!
procedure test_feature_AERO S:color["BLUE"]
  feature label=faero1 table={NAME="AERO1",TYPE=SYMBOL,X=10,Y=10,COLOR=^color,&
                                LINE={SYMBOL="Aero",SYMBOLSIZE=24,&
                                      SYMBOLFILL=ON}} plot=idplot
  feature label=faero2 table={NAME="AERO2",TYPE=SYMBOL,X=10,Y=20,COLOR=^color,&
                                LINE={SYMBOL="Aero",SYMBOLSIZE=24,&
                                      SYMBOLFILL=ON}} plot=idplot
  calc faero1.line.symbolangle -3.14 2 /
  calc faero2.line.symbolangle +3.14 2 /

  call setInstructions "Expected: 2 ^color AERO features in the lower left corner.\n\n&
                        Top: should be pointing left\n&
                        Bottom: should be pointing right."
return

!******************************************************************************!
procedure test_feature_ARROW S:color["BLUE"]
  feature label=farrow1 table={NAME="ARROW1",TYPE=SYMBOL,X=40,Y=10,COLOR=^color,&
                                LINE={SYMBOL="Arrow",SYMBOLSIZE=24,&
                                      SYMBOLFILL=ON}} plot=idplot
  feature label=farrow2 table={NAME="ARROW2",TYPE=SYMBOL,X=50,Y=10,COLOR=^color,&
                                LINE={SYMBOL="Arrow",SYMBOLSIZE=24,&
                                      SYMBOLFILL=ON}} plot=idplot
  set farrow1.line.symbolangledeg -90
  set farrow2.line.symbolangledeg +90

  call setInstructions "Expected:\n&
                        2 ^color ARROW features along the bottom.\n&
                        The 2 arrows should be pointing at each other."
return

!******************************************************************************!
procedure test_feature_ELLIPSE
  calc semiMaj 2 pi * radiusEarth * 360 / 15 * ! 15 degrees
  calc semiMin semiMaj 2 /                     ! 7.5 degrees
  set tilt 0
  feature label=fellipse table={NAME="ELLIPSE",TYPE="ELPS",X=15,Y=7.5,&
                                SEMIMAJOR=semiMaj,SEMIMINOR=semiMin,TILT=90,&
                                COLOR="GREEN"} plot=idmap

  call setInstructions "Expected:\n&
                        - a GREEN ellipse centered at (15,7.5)\n  &
                         spanning 30 degrees (two grid lines) in X\n  &
                         spanning 15 degrees (1 grid line) in Y"
return

!******************************************************************************!
procedure test_feature_MAPIMAGE
  feature label=farrowne table={NAME="ARROW_NE",TYPE=SYMBOL,X=-90,Y=45,SYMBOLHEADING=45,&
                                LINE={SYMBOL="^{datDir}.Arrow.png"}} plot=idmap
  feature label=farrownw table={NAME="ARROW_SW",TYPE=SYMBOL,X=90,Y=45,SYMBOLHEADING=225,&
                                LINE={SYMBOL="^{datDir}.Arrow.png"}} plot=idmap

  call setInstructions "Expected:\n&
                        - 2 green arrows\n&
                        - One over the North America: points North East\n&
                        - One over Asia: points South West."
return

!******************************************************************************!

procedure test_feature_TOOMANY S:color["BLUE"]
  res index 0

  set reg.idplot.removeFeature "*"
  set manyfeatures {}
  set L:xpos 0
  set L:ypos 0
  while index lt 1000
    res  lbl scroll^{index}

    feature label=manyfeatures.^lbl table={NAME="^lbl",TYPE=SYMBOL,X=^xpos,Y=^ypos,COLOR=^color} plot=idplot
    calc L:index index 1 +
    res  lbl scroll^{index}
    feature label=manyfeatures.^lbl table={NAME="^lbl",TYPE=SYMBOL,X=^xpos,Y=^ypos,COLOR=^color} plot=idplot
  endwhile

  call setInstructions "1) Click the middle mouse button and go to the Features menu. &
                        Ensure that a scrollbar exists for the list and that all 1000 features are shown.\n&
                        2) Try scrolling both by paging (clicking above/below scrollbar) and by dragging knob.\n&
                        3) Try selecting features and renaming or deleting them."
return





procedure test_feature_MANY S:color["BLUE"]
  res index 0

  set reg.idplot.removeFeature "*"
  set manyfeatures {}

  while index lt 100
    calc L:xpos index 10 +
    calc L:ypos xpos
    calc L:index index 1 +
    res  lbl manysym^{index}

    feature label=manyfeatures.^lbl table={NAME="^lbl",TYPE=SYMBOL,X=^xpos,Y=^ypos,COLOR=^color} plot=idplot

    calc L:ypos 120 xpos -
    calc L:index index 1 +
    res  lbl manysym^{index}
    feature label=manyfeatures.^lbl table={NAME="^lbl",TYPE=SYMBOL,X=^xpos,Y=^ypos,COLOR=^color} plot=idplot
  endwhile

  call setInstructions "Expected:\n&
                       - 100 features in the shape of a saltire\n&
                       - ('X') with the center two overlapping.\n&
                       - All other features should have been removed first.\n\n&
                       THEN:\n&
                       1) MMB on PLOT -> Features -> DeleteAll\n&
                       2) select Yes\n&
                       3) confirm  that all features are removed."
return

!******************************************************************************!
procedure test_feature_THICKNESS S:color["GREEN"]
  res index 0

  set reg.idplot.removeFeature "*"
  set manyfeatures {}

  while index lt 5
    calc L:xpos  20
    calc L:ypos  50 index 10 * -
    calc L:thick index 2 *
    calc L:index index 1 +
    res  lbl manysym^{index}

    feature label=manyfeatures.^lbl table={NAME="^lbl",TYPE=HLINE,&
                         X=^xpos,Y=^ypos,COLOR=^color,LINE={THICKNESS="^thick"}} plot=idplot
  endwhile

  call setInstructions "Expected: ^index horizontal lines that increase in thickness &
                        going from top to bottom."
return


!******************************************************************************!
! test zooming into circle feature to make sure it still displays
procedure test_dr836 S:color["YELLOW"]
  set x 60.0  ! x-coordinate center point
  set y 75.0  ! y-coordinate center point
  set d 5.0   ! diameter
  set r (d/2) ! radius
  set x1 (x - r)
  set x2 (x + r)
  set y1 (y - r)
  set y2 (y + r)

  !!! DX controls size of CIRCLE !!!
  feature label=fcirc3 table={NAME="CIRC3",TYPE="CIRC|FILLED",X=^x,Y=^y,DX=^d,COLOR=^color} plot=idplot
  message send ID=idplot NAME="GOTOLOCATION" DATA={XVAL=^x,YVAL=^y,RADIUS=^r,FLAGS="Zoom"}
  !message send ID=idplot NAME="ZOOM" DATA={X1=^{x1},X2=^{x2},Y1=^{y1},Y2=^{y2}}
  call setInstructions "1) Should see a filled ^color circle\n   &
                           It is zoomed in to show the circle.\n\n&
                        2) Zoom inside the circle several times\n   &
                           It should still be filled.\n\n&
                        Unzoom before moving to next test."
return

!******************************************************************************!
! Bug 1392 test case - test adding TYPE=|DATA| onto a non-Layer1D (it should
! not crash the PLOT) and the other types specified in the type mask should be drawn.
!
! Modified for Bug 1735 to include setting type manually to provoke warning message
procedure test_data_dr1392 S:color["WHITE"]
  feature label=fdata table={NAME="DATA1",TYPE=DATA|SYMBOL,LINE={SYMBOL="STAR"},X=55,Y=60,DX=10,COLOR=^color} plot=idplot
  res reg.idplot.features.data1.type +data
  call setInstructions "Expected:\n&
                        - The PLOT should not crash\n&
                        - WARNing about the use of type=|Data| in terminal\n&
                        - a ^color STAR SYMBOL (*) below Lincoln's ear."
return
