!******************************************************************************!
! Tests that drawing a DRAGBOX over a layer with partially tranparent objects
! does not cause the objects to become brighter, because MPlot.drawDataArea
! did not clear the area before redrawing
!
! @issue   NXM-3961 plot world.shp opaqueness changes on dragbox
! @author  Jeanette McCall
! Since:   NeXtMidas 4.1.3
!******************************************************************************!
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

  call setDatDir

  set defaultAlpha         64
  set testfile_1           test_raster1.tmp{AUX=RAM}
  set testfile_2           test_raster2.tmp{AUX=RAM}
  set testfile_3           test_raster3.tmp{AUX=RAM}

  if interAct or coreGraphics then
    call createLayer2D
    call createLayerT5

    set instructions "Draw dragboxes in each plot\n\n&
                      The plot components should not change alpha except for the TL plot."
    pipe init
      panel/msgid=MAIN/setup/controls=gc
      gcontrol label mainLabel "Main"
        gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
        set gc.main.itemColors {PASS=GREEN,FAIL=RED}
        gcontrol text idtext "Instructions" "^{instructions}" 30 20 /title

      plot/id=3rasterplots ^testfile_1{LAYER={DC=true}}|^testfile_2{LAYER={DC=true}}|^testfile_3{LAYER={DC=true}} view=iYX

      plot/id=vehiclelay ^{datDir}.world.prm|{LT=Vehicle,CONEFILL=TRUE} X1=-125 X2=-110 Y1=25 Y2=45
      call createLayerVehicle

      plot/id=shapelay world.shp{LAYER={LABEL=NAME,OPAQ=30}}
      pause 0.1
      feature label=fcircdep table={NAME="CIRCDEP",TYPE="CIRC||FILLED",X=80,Y=-50,DX=20,COLOR="#66FF0000"} plot=shapelay

      plot/id=kmllay/READOUT="+OnAxis" ^{datDir}.world.prm|nxm.sys.test.kmlPolyFillTest.kml X1=-180 X2=-120 Y1=-20 Y2=40

      plot/id=layerT5/READOUT="+OnAxis|+DateString" ^{datDir}.world.prm|ram:temp_cone5000{LAYER={LT="T5",CONIC=1,FLAGS=+fillcones|+ConeFlagHoriz}}

      plot/id=layerdrawable ^{datDir}.world.prm|{LT="Drawable",name="VENNDRAWABLE"}  /MSGID=MAIN  view=latloncontinuous
      call addToLayerDrawable

    pipe off

  endif
endmacro

!******************************************************************************!
procedure processMessage m:msg
  !say "msg.name ^msg.name, data ^msg.data"

  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: User indicated tests for Layer2D using Direct Colors" msg.data eqss "PASS"
    pipe stop
  elseif msg.name eqs "ZOOM" then
  elseif msg.name eqs "UNZOOM" then
  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

!******************************************************************************!
! Create Layer2D with partial transparency
!******************************************************************************!
procedure createLayer2D

  call createRaster testfile_1 2 red    ! raster plot with bin 2 red
  call createRaster testfile_2 4 green
  call createRaster testfile_3 6 blue

return

!******************************************************************************!
! Create an color bar of specified color image with increasing alpha
! values from completely translucent (alpha=0) to completely opaque (alpha=255).
! Put image in the middle of Canada.
procedure createRaster FN:outfilename S:stripe s:clr
  set l:fs 7
  file open/d/n outfile ^outfilename{TYPE=2000,FORM=SL,FS=^fs}

  ! generate RGB colors from translucent to opaque
  do l:i 0 255 1
    table tab create
    new java.awt.Color(i,0,0,i) red
    new java.awt.Color(0,i,0,i) green
    new java.awt.Color(0,0,i,i) blue
    new java.awt.Color(0,0,0,0) blk
    set tab.F1 blk.rgb
    set tab.F2 blk.rgb
    set tab.F3 blk.rgb
    set tab.F4 blk.rgb
    set tab.F5 blk.rgb
    set tab.F6 blk.rgb
    set tab.F7 blk.rgb
    set tab.F^stripe ^{clr}.rgb

    file write outfile tab
  enddo
  file close outfile

return

!******************************************************************************!
! Create LayerVehicle with partial transparency
!******************************************************************************!
procedure createLayerVehicle

    set myveh1 {POINTS={}}
    set myveh1.attributes     {COLOR=Yellow,Symbol=Cross}
    set myveh1.location       {LABEL="SPACEWAY-1",POS={ALT=3.49E7,LAT=0,LON=-102.8}}
    set myveh1.location.ATTRIBUTES {SYMBOL=DIAMOND}
    set myveh1.site           {LABEL="El Segundo, CA",POS={ALT=0,LAT=33'55'17,LON=-118'24'22}}
    set myveh1.points.UPLINK  {POS={ALT=0,LAT=33'55'17,LON=-118'24'22},CANGLE=0.4,LABEL=""}
    set myveh1.points.UPLINK.ATTRIBUTES {SYMBOL=Plus,Color=Purple}
    set lay   reg.vehiclelay.layers.vehicle
    set lay.vehicle("MYVEH1") myveh1

return

!******************************************************************************!
! Create LayerT5 with partial transparency
!******************************************************************************!
procedure createLayerT5

  set t:cone5000_data_a   {}
  set t:cone5000_data_a.0 {POS=(0,50,20),POSP=(3.7E7,15,20),CONE=(-1,14.75,14.75),NAME="BEYONDHORIZON",LABEL="BEYONDHORIZON",FLAG=(13,0,2,2,-9,1,4,4)}
  set t:cone5000_data_a.1 {POS=(0.006568699999999999,-25,140),POSP=(3.481502E7,-45,123),CONE=(-1,0.6332,0.6332),NAME="ONSURFACE",LABEL="ONSURFACE",FLAG=(9,0,4,2,-9,1,4,4)}
  set t:cone5000_data_a.2 {POS=(0.1997,34.3982,67.0013),POSP=(34815020,-3.9757,16.7008),CONE=(-1,0.6332,0.6332),NAME="SOMEHORIZON",LABEL="SOMEHORIZON",FLAG=(11,0,3,2,0,1,2,4)}

  invoke tblSize cone5000_data_a.getSize()
  set lastTableEntry tblSize-1

  file open/n out ram:temp_cone5000{COMPONENTS=(POS/VD,POSP/VD,CONE/VD,NAME/9A,LABEL/9A,FLAG/8B),SIZE=tblSize}

  do i 0 lastTableEntry 1
    invoke ,, out.setData(^i,cone5000_data_a.^i)
  enddo
  file close out
return

!******************************************************************************!
! Add features with partial transparency to LayerDrawable
!******************************************************************************!
procedure addToLayerDrawable

  set layVenn reg.layerdrawable.layers.VENNDRAWABLE

  feature ,, vennRed    {NAME="RED",   LINE={COLOR="#66FF0000"},LAYER=layVenn,TYPE=BOX|FILLED, X=-180,Y=60,DX=50,DY=50} LayerDrawable
  feature ,, vennGreen  {NAME="GREEN", LINE={COLOR="#6600FF00"},LAYER=layVenn,TYPE=BOX|FILLED, X=-100,Y=-20,DX=30,DY=30} LayerDrawable
  feature ,, vennBlue   {NAME="BLUE",  LINE={COLOR="#660000FF"},LAYER=layVenn,TYPE=BOX|FILLED, X=0,Y=20,DX=25,DY=25} LayerDrawable
  feature ,, vennYellow {NAME="YELLOW",LINE={COLOR="#99FFFF00"},LAYER=layVenn,TYPE=VBAR|FILLED,X=180,Y=-40,DX=15,DY=15} LayerDrawable
  feature ,, vennWhite  {NAME="WHITE", LINE={COLOR="#66AAAAAA"},LAYER=layVenn,TYPE=CIRC|FILLED,X=100,Y=10,DX=30,DY=30} LayerDrawable

return

