!******************************************************************************!
! Tests drawing partially hidden features and images in GEODETIC.
!
! @bug      NXM-3995 Features and Images drawn in GEODETIC enlarged up
!                    against top left corner
! @since    NeXtMidas 4.1.3
! @author:  Zachary Matthews
!******************************************************************************!
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.8.1

  if interAct or coreGraphics then
    call setDatDir

    if ^{env.NMROOT} EQS "classpath:" then
      res world_shp_file  "world_copy.shp{AUX=RAM}"
      file copy ^{datDir}.world.shp world_shp_file
      file copy ^{datDir}.world.dbf world_copy.dbf{AUX=RAM}
      res world_prm_file  "world_copy.prm{AUX=RAM}"
      file copy ^{datDir}.world.prm world_prm_file
    else
      res world_shp_file "^{datDir}.world.shp"
      res world_prm_file "^{datDir}.world.prm"
    endif

    set instructions "Expected: Top plots should look like bottom plots\n          &
                      (except for sight rotation).\n&
                      _________________________________________________________\n&
                      Note: \n&
                      Background: ViewGeo.rwc2pix assigns pixel coordinate 0,0 to non-visible points. &
                      Feature.draw and MPlot.drawImage call this on bounding points. &
                      If one coordinate was visible and another not, objects showed up oversized at the TL corner of the plot."

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

      plot/id=mplotFeaturesActual   world_prm_file readout=+onAxis readoutext=+show view=geodetic
      plot/id=mplotFeaturesExpected world_prm_file readout=+onAxis readoutext=+show view=geodetic
       call addMPlotFeatures

      plot/id=layerKMLwithImageActual   world_shp_file|nxm.sys.test.kmlTest.kml readout=+onAxis readoutext=+show view=geodetic
      plot/id=layerKMLwithImageExpected world_shp_file|nxm.sys.test.kmlTest.kml readout=+onAxis readoutext=+show view=geodetic

      plot/id=layerDrawableFeaturesActual   world_prm_file|{LT="Drawable",name="FEATGROUPACTUAL"}   readout=+onAxis readoutext=+show view=geodetic
      plot/id=layerDrawableFeaturesExpected world_prm_file|{LT="Drawable",name="FEATGROUPEXPECTED"} readout=+onAxis readoutext=+show view=geodetic
       call addLayerDrawableFeatures

      plot/id=layerDrawableVennDiagramFeaturesActual   world_prm_file|{LT="Drawable",name="VENNACTUAL"}   readout=+onAxis readoutext=+show view=geodetic
      plot/id=layerDrawableVennDiagramFeaturesExpected world_prm_file|{LT="Drawable",name="VENNEXPECTED"} readout=+onAxis readoutext=+show view=geodetic
       call addLayerDrawableVennDiagramFeatures

      message FUNC=SEND ID=MAIN NAME=START
    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 eqs "START" then
    ! MPlot Features
    invoke dblarray nxm.sys.test.TestUtil.createDoubleArray("84.03976293018698,13.915332965507979,6.0")
    message send MPLOTFEATURESACTUAL name=PANOBS info=-7 QUALS={ORIG_MSG_DATA={X=L:220,Y=L:244,W=L:-6,H=L:3}}} DATA=dblarray
    invoke dblarray nxm.sys.test.TestUtil.createDoubleArray("74.63937608299162,13.915332965507979,6.0")
    message send MPLOTFEATURESEXPECTED name=PANOBS info=-7 QUALS={ORIG_MSG_DATA={X=L:194,Y=L:228,W=L:27,H=L:0}}} DATA=dblarray

    ! LayerKML Image
    invoke dblarray nxm.sys.test.TestUtil.createDoubleArray("-104.51989134508266,9.632967553155169,6.0")
    message send LAYERKMLWITHIMAGEACTUAL name=PANOBS info=-7  QUALS={ORIG_MSG_DATA={X=L:221,Y=L:267,W=L:6,H=L:0}} DATA=dblarray
    invoke dblarray nxm.sys.test.TestUtil.createDoubleArray("-104.8680538209047,9.632967553155169,6.0")
    message send LAYERKMLWITHIMAGEEXPECTED name=PANOBS info=-7  QUALS={ORIG_MSG_DATA={X=L:217,Y=L:265,W=L:-6,H=L:0}} DATA=dblarray

    ! LayerDrawable Features
    invoke dblarray nxm.sys.test.TestUtil.createDoubleArray("7.242180552045241,13.060503594511102,6.0")
    message send LAYERDRAWABLEFEATURESACTUAL name=PANOBS info=-7  QUALS={ORIG_MSG_DATA={X=L:188,Y=L:257,W=L:161,H=L:67}} DATA=dblarray
    invoke dblarray nxm.sys.test.TestUtil.createDoubleArray("4.456880745468839,8.534391408824447,6.0")
    message send LAYERDRAWABLEFEATURESEXPECTED name=PANOBS info=-7  QUALS={ORIG_MSG_DATA={X=L:189,Y=L:281,W=L:8,H=L:-13}} DATA=dblarray

    ! LayerDrawable Venn Diagram Features
    invoke dblarray nxm.sys.test.TestUtil.createDoubleArray("91.86903341250898,-24.357538658190926,6.0")
    message send LAYERDRAWABLEVENNDIAGRAMFEATURESACTUAL name=PANOBS info=-7 QUALS={ORIG_MSG_DATA={X=L:252,Y=L:167,W=L:6,H=L:0}} DATA=dblarray
    invoke dblarray nxm.sys.test.TestUtil.createDoubleArray("93.95397549745107,-24.357538658190926,6.0")
    message send LAYERDRAWABLEVENNDIAGRAMFEATURESEXPECTED name=PANOBS info=-7 QUALS={ORIG_MSG_DATA={X=L:269,Y=L:160,W=L:-10,H=L:12}} DATA=dblarray
  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

!******************************************************************************!
! Make MPlot Features and add them to both MPlotFeatures Plots
!******************************************************************************!
procedure addMPlotFeatures
  do featNum 1 50
    calc xval ^featNum 180 MOD/T
    calc yval ^featNum 90 MOD/T
    feature table={NAME="MP_FEATURE_ACTUAL_CIRCLE_^{featNum}",TYPE=CIRCLE,X=^xval,Y=^yval,DX=10,DY=10,COLOR="RED"}   plot=mplotFeaturesActual
    feature table={NAME="MP_FEATURE_EXPECTED_CIRCLE_^{featNum}",TYPE=CIRCLE,X=^xval,Y=^yval,DX=10,DY=10,COLOR="RED"} plot=mplotFeaturesExpected
  enddo
return

!******************************************************************************!
! Make LayerDrawable Features and add them to both LayerDrawableFeatures Plots
!******************************************************************************!
procedure addLayerDrawableFeatures

  ! Initial values for the features
  set featX -50
  set featY -50

  ! Create variables to easily access both FEATGROUP LayerDrawable Layers
  set layFeatsActual   reg.layerDrawableFeaturesActual.layers.featGroupActual
  set layFeatsExpected reg.layerDrawableFeaturesExpected.layers.featGroupExpected

  ! Add 100 features to both FEATGROUP LayerDrawable Layers
  do featNum 1 100
    feature label=ld_feature_actual_circle_^{featNum}   table={NAME="LD_FEATURE_ACTUAL_CIRCLE_^{featNum}",LAYER=layFeatsActual,TYPE="CIRC",X=featX,Y=featY,DX=5,DY=5,COLOR="RED"}     plot=layerDrawableFeaturesActual
    feature label=ld_feature_expected_circle_^{featNum} table={NAME="LD_FEATURE_EXPECTED_CIRCLE_^{featNum}",LAYER=layFeatsExpected,TYPE="CIRC",X=featX,Y=featY,DX=5,DY=5,COLOR="RED"} plot=layerDrawableFeaturesExpected
    calc featX featX 1 +
    calc featY featY 1 +
  enddo

  feature label=box1Actual   table={NAME=BOX1ACTUAL,TYPE=BOX,X=-45,Y=-45,DX=20,DY=20,COLOR=WHITE,ENABLE=1}   plot=layerDrawableFeaturesActual
  feature label=box1Expected table={NAME=BOX1EXPECTED,TYPE=BOX,X=-45,Y=-45,DX=20,DY=20,COLOR=WHITE,ENABLE=1} plot=layerDrawableFeaturesExpected
return

!******************************************************************************!
! Make LayerDrawable Venn Diagram Features and add them to both LayerDrawableVennDiagram Plots
!******************************************************************************!
procedure addLayerDrawableVennDiagramFeatures
  set layVennActual reg.layerDrawableVennDiagramFeaturesActual.layers.VENNACTUAL
  feature ,, vennRedActual    {NAME="RED",   LINE={COLOR="#66FF0000"},LAYER=layVennActual,TYPE=BOX|FILLED, X=-180,Y=60,DX=50,DY=50}  layerDrawableVennDiagramFeaturesActual
  feature ,, vennGreenActual  {NAME="GREEN", LINE={COLOR="#6600FF00"},LAYER=layVennActual,TYPE=BOX|FILLED, X=-100,Y=-20,DX=30,DY=30} layerDrawableVennDiagramFeaturesActual
  feature ,, vennBlueActual   {NAME="BLUE",  LINE={COLOR="#660000FF"},LAYER=layVennActual,TYPE=BOX|FILLED, X=0,Y=20,DX=25,DY=25}     layerDrawableVennDiagramFeaturesActual
  feature ,, vennYellowActual {NAME="YELLOW",LINE={COLOR="#99FFFF00"},LAYER=layVennActual,TYPE=VBAR|FILLED,X=180,Y=-40,DX=15,DY=15}  layerDrawableVennDiagramFeaturesActual
  feature ,, vennWhiteActual  {NAME="WHITE", LINE={COLOR="#66AAAAAA"},LAYER=layVennActual,TYPE=CIRC|FILLED,X=100,Y=10,DX=30,DY=30}   layerDrawableVennDiagramFeaturesActual

  set layVennExpected reg.layerDrawableVennDiagramFeaturesExpected.layers.VENNEXPECTED
  feature ,, vennRedExpected    {NAME="RED",   LINE={COLOR="#66FF0000"},LAYER=layVennExpected,TYPE=BOX|FILLED, X=-180,Y=60,DX=50,DY=50}  layerDrawableVennDiagramFeaturesExpected
  feature ,, vennGreenExpected  {NAME="GREEN", LINE={COLOR="#6600FF00"},LAYER=layVennExpected,TYPE=BOX|FILLED, X=-100,Y=-20,DX=30,DY=30} layerDrawableVennDiagramFeaturesExpected
  feature ,, vennBlueExpected   {NAME="BLUE",  LINE={COLOR="#660000FF"},LAYER=layVennExpected,TYPE=BOX|FILLED, X=0,Y=20,DX=25,DY=25}     layerDrawableVennDiagramFeaturesExpected
  feature ,, vennYellowExpected {NAME="YELLOW",LINE={COLOR="#99FFFF00"},LAYER=layVennExpected,TYPE=VBAR|FILLED,X=180,Y=-40,DX=15,DY=15}  layerDrawableVennDiagramFeaturesExpected
  feature ,, vennWhiteExpected  {NAME="WHITE", LINE={COLOR="#66AAAAAA"},LAYER=layVennExpected,TYPE=CIRC|FILLED,X=100,Y=10,DX=30,DY=30}   layerDrawableVennDiagramFeaturesExpected
return
