startmacro
! Tests the XGEOPLOT java primitive.
!
! Author:  JPH
!
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE
  switch xgeoOpt xgeoOpt DEF="SYS" SDEF="SYS"
 
  call setDatDir

  if interAct then

    res xgeoid 2

    call resetData

    res sizeCities   FILE(temp_xgeo_cities).size
    res sizeEllipses FILE(temp_xgeo_ellipse).size

    ! calculate layer number for each layer used in this test - since 3.7.0 for bugs 2917 and 2965
    res  worldLayer  1
    calc citiesLayer worldLayer  1 +
    calc ellpsLayer  citiesLayer 1 +
    ! Calculate Layer numbers for Layers used in createT5Layer, mergePoint, and mergeAllPts procedures
    calc L:firstT5CreateLayNum ellpsLayer 1 +
    calc L:secondT5CreateLayNum firstT5CreateLayNum 1 +
    calc L:thirdT5CreateLayNum firstT5CreateLayNum 2 +

    set files  "^{datDir}.world.prm|temp_xgeo_cities|temp_xgeo_ellipse"
    set colors {world=NULL,temp_xgeo_cities=YELLOW,temp_xgeo_ellipse=RED}
    res commonInstructions &
        "Tests:\n&
        1) Select colors and Layer number followed\n   by each of the 'Reread...' buttons.\n&
        2) Select the 'T5LAYER..' and 'T5REC..' test\n   buttons in order."

    res initialInstructions &
       "Verify the XGEOPLOT displays: \n&
       1) ^sizeCities ^colors.temp_xgeo_cities cities. \n&
       2) ^sizeEllipses ^colors.temp_xgeo_ellipse ellipses.\n&
       \n&
        ^commonInstructions"

    pipe on
      panel/msgid=MAIN/setup/controls=gc

      ! As of 2.7.0 there is a HOST version of XGEOPLOT.  Want to test java here
      xgeoplot;^{xgeoOpt}/id=^XGEOID "^files"
      set reg.^{xgeoid}.layers.temp_xgeo_ellipse.color "^colors.temp_xgeo_ellipse"
      set reg.^{xgeoid}.layers.temp_xgeo_cities.color "^colors.temp_xgeo_cities"
 
      gcontrol label macro "MACRO"
        gcontrol TYPE=menu NAME=main TITLE="Exit with Status = " P1="PASS,FAIL" &
                TABLE={ITEMCOLORS={PASS=GREEN,FAIL=RED}} /tleft

      gcontrol text idtext "Tests X-Midas style messaging." "^initialInstructions" 24 20 /title
      gcontrol label messagesLab "Messages"
        gcontrol button reset          ""    "Reset Test"
        gcontrol choice colorCities    "Cities Color" "Red,Green,Blue,Cyan,Yellow" "^colors.temp_xgeo_cities"
        gcontrol choice colorEllipse   "Ellipse Color" "Red,Green,Blue,Cyan,Yellow" "^colors.temp_xgeo_ellipse"
        gcontrol choice layerNumber    "Layer Number (2=cities,3=ell)" "0,1,2,3" "3"
        gcontrol button rereadALL      "" "Reread - ALL layers"
        gcontrol button reread         "" "Reread - KEEP COLOR"
        gcontrol button rereadNewColorCities  "" "Reread Layer 2 (Cities)  - NEW COLOR "
        gcontrol button rereadNewColorEllps   "" "Reread Layer 3 (Ellipse) - NEW COLOR "

        ! Bug 2812 Commented out viewType choice as they were never fully implemented in xgeoplot setView
        ! gcontrol choice viewType      "ViewType" "LATLON,PERSPECTIVE,SVA,SVB" "LATLON"
        ! current implementation of SETVIEW now tested with CREATET5, but section is left for unimplemented portions
        ! gcontrol button setView   ""    "Test Set View"
        gcontrol button createT5    ""    "T5LAYER CREATE"       ! Since 3.7.0 for bug 2917
        gcontrol button mergePoint  ""    "T5REC mergePoint"     ! Improved in 3.7.0 for bug 2965
        gcontrol button mergeAllPt  ""    "T5REC mergeAllPoints" ! Since 3.7.0 for bug 2965
        gcontrol button deletePts   ""    "T5LAYER DELETE"       ! Since 3.7.0 for bug 2965
        gcontrol button copyPts     ""    "T5LAYER COPY"         ! Since 3.7.0 for bug 2965

    pipe off

    if baseline then
     %test_xgeoplot_cones
    endif
  endif

endmacro

!******************************************************************************!
procedure processMessage
  if     msg.name EQSS "MAIN" then
    assert/text="^reg.main.name: Tests for AUX" msg.data eqss "PASS"
    pipe stop

  elseif msg.name EQSS "RESET" then
    call resetData
    message FUNC=SEND ID=^XGEOID INFO=0 NAME=REREAD      ! Reread ALL layers
    set box {MINLON=-180,MAXLON=180,MINLAT=-90,MAXLAT=90}
    message FUNC=SEND ID=^XGEOID INFO=1 NAME="SETVIEW" &
              DATA={VAL1=^box.minLon,VAL2=^box.maxLon,VAL3=^box.minLat,VAL4=^box.maxLat}
    set gc.idText.value "^initialInstructions"
    pause 0.2
    set reg.^{xgeoid}.layers.temp_xgeo_cities.color  ^colors.temp_xgeo_cities
    set reg.^{xgeoid}.layers.temp_xgeo_ellipse.color ^colors.temp_xgeo_ellipse

  elseif msg.name EQSS "COLOR" then
    ! Nothing to do

  elseif msg.name EQS "REREAD" then
      set L:layNum ^gc.layerNumber.value 
      if ^layNum EQ ^citiesLayer then ! Cities
        say "thinning cities...."
        thin ^{datDir}.cities.prm temp_xgeo_cities{AUX=RAM} 0 8
      endif
      if ^layNum EQ ^ellpsLayer then ! Ellipses
        say "thinning ellipses...."
        thin ^{datDir}.ellipse5000 temp_xgeo_ellipse{AUX=RAM} 0 4
      endif

      res sizeCities   FILE(temp_xgeo_cities).size
      res sizeEllipses FILE(temp_xgeo_ellipse).size
      message FUNC=SEND ID=^XGEOID INFO=^layNum NAME=REREAD
      set gc.idText.value &
       "Verify the XGEOPLOT displays: \n&
          1) ^sizeCities cities. \n&
          2) ^sizeEllipses ellipses. \n&
          3) The colors have not changed.\n&
       \n&
        ^commonInstructions"

  elseif msg.name STARTS "REREADNEWCOLOR" then ! updated in 3.7.0 to use extra buttons to make testing easier

    if msg.name EQS "REREADNEWCOLORCITIES" then
      set L:layNum ^citiesLayer
      say "thinning cities...."
      thin ^{datDir}.cities.prm temp_xgeo_cities{AUX=RAM} 0 8
      message FUNC=SEND ID=^XGEOID INFO=^layNum NAME=REREAD &
              DATA=temp_xgeo_cities{LAYER={COLOR=^gc.colorCities.value}}

    elseif msg.name EQS "REREADNEWCOLORELLPS" then
      set L:layNum ^ellpsLayer
      say "thinning ellipses...."
      thin ^{datDir}.ellipse5000.prm temp_xgeo_ellipse{AUX=RAM} 0 4
      message FUNC=SEND ID=^XGEOID INFO=^layNum NAME=REREAD &
                DATA=temp_xgeo_ellipse{LAYER={COLOR=^gc.colorEllipse.value}}
    endif

    res sizeCities   FILE(temp_xgeo_cities).size
    res sizeEllipses FILE(temp_xgeo_ellipse).size
    set gc.idText.value &
      "Verify the XGEOPLOT displays: \n&
        1) ^sizeCities ^gc.colorCities.value cities. \n&
        2) ^sizeEllipses ^gc.colorEllipse.value ellipses. \n&
        3) The colors have changed.\n\n&
        ^commonInstructions"

  elseif msg.name EQS "REREADALL" then
    say "thinning cities...."
    thin ^{datDir}.cities.prm temp_xgeo_cities{AUX=RAM} 0 8
    say "thinning ellipses...."
    thin ^{datDir}.ellipse5000.prm temp_xgeo_ellipse{AUX=RAM} 0 4
    pause 0.2
    message FUNC=SEND ID=^XGEOID INFO=0 NAME=REREAD      ! Reread ALL layers

    res sizeCities   FILE(temp_xgeo_cities).size
    res sizeEllipses FILE(temp_xgeo_ellipse).size
    set gc.idText.value &
       "Verify the XGEOPLOT displays: \n&
          1) ^sizeCities cities. \n&
          2) ^sizeEllipses ellipses. \n&
          3) The colors have not changed.\n&
       \n&
        ^commonInstructions"

  elseif msg.name EQSS "SETVIEW" then
    ! From X-Midas explain file:
    !  SETVIEW [minlon maxlon minlat maxlat [eyelat eyelon eyedis]]
    !    info = 1-latlon 2-persp 3-svA 4-svB  (negative for split mode)
    !    min/maxlon = display longitude min/max (degrees or earth radii)
    !    min/maxlat = display latitude min/max (degrees or earth radii)
    !    eyelat/lon/dis = viewing lat/lon/distance for perspective mode
    set box {MINLON=-20,MAXLON=20,MINLAT=-10,MAXLAT=10}

    !if gc.viewType.value EQSS "LAT" then
      message FUNC=SEND ID=^XGEOID INFO=1 NAME="SETVIEW" &
              DATA={VAL1=^box.minLon,VAL2=^box.maxLon,VAL3=^box.minLat,VAL4=^box.maxLat}

    ! Bug 2812 - Cleanup -  These set view values have not been implemented in GEOplot
    ! So commenting out for now.
    !elseif gc.viewType.value EQSS "PERSP" then
    !  set box.eyeLat 10
    !  set box.eyeLon 20
    !  set box.eyeDist 100 !??
    !  message FUNC=SEND ID=^XGEOID INFO=2 NAME="SETVIEW" &
    !          DATA={VAL1=^box.minLon,VAL2=^box.maxLon,VAL3=^box.minLat,VAL4=^box.maxLat}
    !elseif gc.viewType.value EQSS "SVA" then
    !elseif gc.viewType.value EQSS "SVB" then
    !else
    !  warning "^reg.main.name: unrecognized view type ^gc.viewType.value"
    !endif

    set gc.idText.value &
      "Verify the XGEOPLOT displays: \n&
      1) Zoom to ^box.minlat, ^box.maxlat, ^box.minLon, ^box.maxLon \n&
       \n&
       ^commonInstructions"

  ! Added in 3.7.0 for bug 2917
  elseif msg.name EQSS "CREATET5" then
    call createT5Layer

  ! Added additional test for Bug 2807 - improved in 3.7.0
  elseif msg.name EQSS "MERGEPOINTT" then
    call mergePoint

  ! Added additional test for Bug 2807/ - improved in 3.7.0
  elseif msg.name EQSS "MERGEALLPTS" then
    call mergeAllPoints

  ! Added in 3.7.0 for bug 2917
  elseif msg.name EQSS "DELETEPTS" then
    call deletePoints

  ! Added in 3.7.0 for bug 2917
  elseif msg.name EQSS "COPYPTS" then
    call copyPoints

  else

  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 resetData
  thin ^{datDir}.ellipse5000.prm temp_xgeo_ellipse{AUX=RAM}
  thin ^{datDir}.cities.prm      temp_xgeo_cities{AUX=RAM}
return

!*******************************************************************************
! Test xgeoplot T5LAYER CREATE message - since 3.7.0 for bug 2917
!
procedure createT5Layer

  set box {MINLON=-1,MAXLON=8,MINLAT=-3,MAXLAT=5}
  invoke darkgreen nxm.sys.libg.MColor.T5_INDEX_DARK_GREEN
  invoke red       nxm.sys.libg.MColor.T5_INDEX_RED
  invoke yellow    nxm.sys.libg.MColor.T5_INDEX_YELLOW

  set gc.idText.value &
      "Verify the XGEOPLOT displays: \n&
      1) Zoom to LON ^box.minlon to ^box.maxlon, LAT ^box.minlat to ^box.maxlat \n&
      2) Green PNT1REC at (0.5,0,5) with an error\n   ellipse around it \n&
      3) Red PNT2REC at LON=5,LAT=1 and red PNT3REC\n   at LON=5,LAT=3 with a cone around each \n&
      4) Yellow PNT4TEXT,..,PNT7TEXT at LON=2 and\n   LAT=1,2,3,and 4 - displaying of TEXT/Note\n   currently unimplemented \n&
       \n&
       ^commonInstructions"

  ! Use SETVIEW message to zoom in to where points will be displayed
  message FUNC=SEND ID=^XGEOID INFO=1 NAME="SETVIEW" &
     DATA={VAL1=^box.minLon,VAL2=^box.maxLon,VAL3=^box.minLat,VAL4=^box.maxLat}

  ! Create 3 Layers - need homogeneous points on each
  invoke firstLayerNum reg.2.getNextNumForLayerName() ! figure out where we are on auto-generated layer names
  set L:firstT5CreateLayNum 4
  calc L:secondT5CreateLayNum firstT5CreateLayNum 1 +
  calc L:thirdT5CreateLayNum firstT5CreateLayNum 2 +
  set t:msg_data_create {ACTION="CREATE",P1=1}
  message FUNC=SEND ID=^XGEOID INFO=1 NAME="T5LAYER" &
              DATA=t:msg_data_create

  message FUNC=SEND ID=^XGEOID INFO=1 NAME="T5LAYER" &
              DATA=t:msg_data_create

  message FUNC=SEND ID=^XGEOID INFO=1 NAME="T5LAYER" &
              DATA=t:msg_data_create

  ! Use T5REC message to add Point with Error Ellipse component on first LayerT5
  message FUNC=SEND ID=^XGEOID INFO=-1 NAME="T5REC" &
             DATA={Layer=^firstT5CreateLayNum,INDEX=1, &
             ModMask="ALT|LAT|LON|R|AZIM|A|B|COLOR|CONE|NAME|SYMBOL|SIZE|INVERT", &
             ALT=45.0,LAT=0.5,LON=0.5,R=0,AZIM=15.0,A=300000.0,B=70000.0, &
             COLOR=^darkgreen,CONE=-9, SYMBOL=5,SIZE=3,INVERT=1,NAME=PNT1REC}

  ! Use T5REC message to add two Points with Cone component on second LayerT5
  message FUNC=SEND ID=^XGEOID INFO=-1 NAME="T5REC" &
             DATA={Layer=^secondT5CreateLayNum,INDEX=1, &
             ModMask="ALT|LAT|LON|R|AZIM|ELEV|ROLL|COLOR|CONE|NAME|SYMBOL|SIZE|INVERT",&
             ALT=0,LAT=1,LON=5,R=-1, AZIM=1000000.0,ELEV=1.2,ROLL=4.8,COLOR=^red,&
             CONE=-9, SYMBOL=5,SIZE=3,INVERT=1,NAME=PNT2REC}
  message FUNC=SEND ID=^XGEOID INFO=-1 NAME="T5REC" &
             DATA={Layer=^secondT5CreateLayNum,INDEX=2, &
             ModMask="ALT|LAT|LON|R|AZIM|ELEV|ROLL|COLOR|CONE|NAME|SYMBOL|SIZE|INVERT",&
             ALT=0.0,LAT=3,LON=5,R=-1, AZIM=1000000.0,ELEV=3.5,ROLL=5.5,COLOR=^red,&
             CONE=-9, SYMBOL=5,SIZE=3,INVERT=1,NAME=PNT3REC}

  ! Use T5TEXT message to add Point with TEXT/NOTE component on third LayerT5
  message FUNC=SEND ID=^XGEOID INFO=-1 NAME="T5TEXT" &
             DATA={Layer=^thirdT5CreateLayNum,INDEX=1,&
             ModMask="ALT|LAT|LON|NAME|COLOR|SYMBOL|TEXT|SIZE|INVERT",&
             ALT=55.0,LAT=1,LON=2,COLOR=^yellow,SYMBOL=2,SIZE=3,INVERT=1,&
             NAME=PNT4TEXT, TEXT=Hello}
  message FUNC=SEND ID=^XGEOID INFO=-1 NAME="T5TEXT" &
             DATA={Layer=^thirdT5CreateLayNum,INDEX=2,&
             ModMask="ALT|LAT|LON|NAME|COLOR|SYMBOL|TEXT|SIZE|INVERT",&
             ALT=55.0,LAT=2,LON=2,COLOR=^yellow,SYMBOL=2,SIZE=3,INVERT=1,&
             NAME=PNT5TEXT, TEXT=Hello}
  message FUNC=SEND ID=^XGEOID INFO=-1 NAME="T5TEXT" &
             DATA={Layer=^thirdT5CreateLayNum,INDEX=3,&
             ModMask="ALT|LAT|LON|NAME|COLOR|SYMBOL|TEXT|SIZE|INVERT",&
             ALT=55.0,LAT=3,LON=2,COLOR=^yellow,SYMBOL=2,SIZE=3,INVERT=1,&
             NAME=PNT6TEXT, TEXT=Hello}
  message FUNC=SEND ID=^XGEOID INFO=-1 NAME="T5TEXT" &
             DATA={Layer=^thirdT5CreateLayNum,INDEX=4,&
             ModMask="ALT|LAT|LON|NAME|COLOR|SYMBOL|TEXT|SIZE|INVERT",&
             ALT=55.0,LAT=4,LON=2,COLOR=^yellow,SYMBOL=2,SIZE=3,INVERT=1,&
             NAME=PNT7TEXT, TEXT=Hello}

  ! Set cone angle for T5 layer with PNT2REC and PNT3REC
  pause 0.5
  calc l:secondLayerNum firstLayerNum 1 +
  res layerName "T5_^{secondLayerNum}"
  invoke ,, reg.2.layers.^{layerName}.setConeAngle(5)
  invoke ,, reg.2.layers.^{layerName}.setConic(5)
return

!*******************************************************************************
! Test xgeoplot T5REC message and LayerT5.mergePoint() - updated in 3.7.0 for bug 2965
!
! Note: This procedure is dependent on createT5Layer being called first
!
procedure mergePoint

  set L:layNum ^secondT5CreateLayNum
  invoke green  nxm.sys.libg.MColor.T5_INDEX_GREEN

  message FUNC=SEND ID=^XGEOID INFO=24 NAME="T5REC" &
             DATA={Layer=^layNum,INDEX=2,ModMask="NAME|SYMBOL|SIZE|LAT|COLOR",&
             NAME=MERGED_PT,LAT=4,COLOR=^green,SYMBOL=3,SIZE=6} !Since 3.5.3 set lat/lon as mergePoint is now default Bug 2823

  set gc.idText.value &
      "Verify that the point formerly named PNT3REC: \n&
      1) Is now named MERGED_PT \n&
      2) Moved up to LON=5,LAT=4 \n&
      2) Now has its symbol being a square\n&
      3) Is a bright green \n&
      4) Is otherwise the same\n\n&
      Verify other points remained the same: \n&
      1) Green PNT1REC at (0.5,0.5) with ellipse \n&
      2) Red PNT2REC at LON=5,LAT=1 with cone\n&
      3) Yellow PNT4TEXT,..,PNT7TEXT at LON=2 and\n   LAT=1,2,3,and 4\n&
       \n&
       ^commonInstructions"

return

!*******************************************************************************
! Test xgeoplot T5REC message and LayerT5.mergeAllPoints() - since 3.7.0 for bug 2965
!
! Note: This procedure is dependent on createT5Layer & mergePoint being called first
!
procedure mergeAllPoints

  set L:layNum ^secondT5CreateLayNum
  invoke gray  nxm.sys.libg.MColor.T5_INDEX_GRAY

  message FUNC=SEND ID=^XGEOID INFO=24 NAME="T5REC" &
             DATA={Layer=^layNum,INDEX=0,ModMask="LON|COLOR",LON=6.0,COLOR=1} !Since 3.5.3 set lat/lon as mergePoint is now default Bug 2823

  set gc.idText.value &
      "Verify that the points PNT2REC and MERGED_PT: \n&
      1) Moved to the right to LON=6 \n&
      2) Are gray \n&
      3) Are otherwise the same\n\n&
      Verify  other points remained the same: \n&
      1) Green PNT1REC at (0.5,0.5) with ellipse\n&
      2) Yellow PNT4TEXT,..,PNT7TEXT at LON=2 and\n   LAT=1,2,3,and 4\n&
       \n&
       ^commonInstructions"

return

!*******************************************************************************
! Test xgeoplot T5LAYER DELETE message- since 3.7.0 for bug 2965
!
! Note: This procedure is dependent on createT5Layer being called first
!
procedure deletePoints

  set L:layNum ^thirdT5CreateLayNum
  invoke gray  nxm.sys.libg.MColor.T5_INDEX_GRAY

  message FUNC=SEND ID=^XGEOID INFO=^layNum NAME="T5LAYER" &
              DATA={ACTION="DELETE",P1=1,P2=2}

  message FUNC=SEND ID=^XGEOID INFO=^layNum NAME="T5LAYER" &
              DATA={ACTION="DELETE",P1=4,P2=-1}

  set gc.idText.value &
      "Verify that of the TEXT Points:\n&
      - only PNT6TEXT remains\n&
      (i.e. PNT4TXT, PNT5TXT, and PNT7TXT were deleted)\n&
       \n&
       ^commonInstructions"

return

!*******************************************************************************
! Test xgeoplot T5LAYER DELETE message- since 3.7.0 for bug 2965
!
! Note: This procedure is dependent on createT5Layer & deletePoints being called first
!
procedure copyPoints

  set L:layNum ^thirdT5CreateLayNum
  invoke gray  nxm.sys.libg.MColor.T5_INDEX_GRAY

  ! Create copy of PNT6TXT as points[0]
  message FUNC=SEND ID=^XGEOID INFO=^layNum NAME="T5LAYER" &
              DATA={ACTION="COPY",P1=3,P2=1}

  ! Append copy of PNT6TXT to points
  message FUNC=SEND ID=^XGEOID INFO=^layNum NAME="T5LAYER" &
              DATA={ACTION="COPY",P1=3,P2=0}

  ! Modify points[0] copy of PNT6TXT to be at Latitude 4.3
  message FUNC=SEND ID=^XGEOID INFO=24 NAME="T5REC" &
              DATA={Layer=^layNum,INDEX=1,ModMask="LAT",LAT=4.3}

  ! Modify appended copy of PNT6TXT to be at Latitude 4.7
   message FUNC=SEND ID=^XGEOID INFO=24 NAME="T5REC" &
               DATA={Layer=^layNum,INDEX=5,ModMask="LAT",LAT=4.7}

  set gc.idText.value &
      "Verify there are two copies of PNT6TEXT along with the original\n&
      Note: The copies were modified so their latitudes are 4.3 and 4.7\n&
       \n&
       ^commonInstructions"

return
