startmacro
!
! Test the holding of plot refreshes (BUG 1813)
!
! Version: $Id: test_plot_hold_refreshes.mm,v 1.5 2015/09/02 14:24:12 paq Exp $
!
switch INTERACTIVE interAct GET DEF=TRUE
if interAct then
  set s:initInstr "1) Click 'ADD FEATURE' to add or reset a Feature.\n&
                   2) Click 'MOVE FEATURE' to watch the feature move.\n&
                   3) Click the 'FEATURES' button\n&
                   4) Press 'MOVE FEATURE' again.\n&
                   5) You should not see the Feature move unless you resize &
                   the screen.\n\n&
                   *********************************\n&
                   Note: This macro tests plot's ability to hold (block) refreshes, in order to &
                   allow a user to make multiple changes and then 'commit' them &
                   all at once.\n&
                   ----------------------------------\n"
  invoke pi nxm.sys.inc.Constants.PI
  invoke radiusEarth nxm.sys.inc.Constants.EARTH_EQUATORIAL_RADIUS
  calc earthCircumference 2 pi * radiusEarth * 360 /
  calc semiMaj earthCircumference 15 *
  calc semiMin semiMaj 2 /
  set tilt 0
  set z:displayed FALSE

  pipe init

  panel/msgid=MAIN/setup/controls=gc
  plot/id=idplot world.shp
    
  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" "^initInstr" 24 22 /title
  gcontrol text holdText "HOLD REFRESH STATUS" "" 24 1 /title
  gcontrol/nc=1 button add "" "ADD FEATURE" none
  gcontrol button move "" "MOVE FEATURE"
  gcontrol button zoom "" "ZOOM TO FEATURE"
  gcontrol button refr "" "REFRESH LAYER"
  !gcontrol/nc=4 button  hold "HOLD REFRESHES" "NONE,FEATURES,LAYERS,ALL"
  gcontrol/nc=2 button toggle "TOGGLE REFRESHES" "FEATURES,LAYERS"

  
  call toggleInstructions

  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" msg.data eqss "PASS"
	  pipe stop
	elseif msg.name eqs "HOLD" then
	  set endX fellipse.x
	  set endY fellipse.y
	  if msg.data eqs "NONE" then
	    call setInstructions "No refresh is held/blocked, and the ellipse should be &
	        centered at ^{endX},^{endY}."
	  elseif msg.data eqss "FEATURE" then
	    call setInstructions "Feature refreshes are held."
	  elseif msg.data eqss "LAYER" then
	    call setInstructions "Layer refreshes are held."
	  else
	    call setInstructions "All refreshes are held. Resizing the screen should &
	        make a blank plot. Pressing 'NONE' should recover it."
	  endif
	  set reg.idplot.holdRefresh ^msg.data
	
	elseif msg.name eqs "TOGGLE" then
	  set reg.idplot.holdRefresh "~^msg.data"
	  call toggleInstructions
	
  elseif msg.name eqs "ADD" then
	  call add_ellipse
	
	elseif msg.name eqs "MOVE" then
	  	call moveFeature
	  	
	elseif msg.name eqs "ZOOM" then
	 		call zoomToFeature
	 		
	elseif msg.name eqs "REFR" then
	 	  call refreshLayer
	 	  	
		else
	  ! do nothing
	  ! say "Unhandled message name: ^msg.name from fid: ^msg.fid, data: ^msg.data"
	endif

return

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

!******************************************************************************!
procedure add_ellipse
  set s:instr "^{s:initInstr}A green ellipse should appear at -50,50. Click 'MOVE FEATURE' to &
     move the Feature NorthEast across the map."

  call setInstructions "^instr"
  ! add ellipse to plot
  feature label=fellipse table={NAME="ELLIPSE",TYPE="ELPS",X=-50,Y=-50,&
                                SEMIMAJOR=semiMaj,SEMIMINOR=semiMin,TILT=90,&
                                COLOR="GREEN"} plot=idplot

  set displayed TRUE

return

!*******************************************************************************
procedure moveFeature

  ! Make sure the feature is displayed
  if displayed isFalse then
    call add_ellipse
  endif

  set s:instr "^{s:initInstr}Unless the refresh is held (blocked), the green ellipse should change locations."
  set startX fellipse.x
  set startY fellipse.y

  call setInstructions "^instr"

  do count 1 20 1
    set fellipse.x startX+(count+5)
    set fellipse.y startY+(count+5)
    set fellipse.semiMajor semiMaj
    set fellipse.semiMinor semiMin
    set fellipse.tilt 90
    pause .1
  enddo

return
!************************************************************************
procedure zoomToFeature

  ! Make sure the feature is displayed
   if displayed isFalse then
     call add_ellipse
   endif

   calc xmin fellipse.x 10 -
   calc xmax fellipse.x 10 +
   calc ymin fellipse.y 20 -
   calc ymax fellipse.y 20 +

   message sendw id=idplot name=ZOOM data={xmin=^{xmin},xmax=^{xmax},ymin=^{ymin},ymax=^{ymax}}
   
   call setInstructions "^{s:initInstr}Plot should be zoomed and centered on the Feature. If &
       holding refresh on the Layer, the map behind the Feature should be blank."

return
!**************************************************************************
procedure refreshLayer

  invoke ,, reg.idplot.resize()
  
  call setInstructions "^{s:initInstr}If the plot background was blank (black), it should now &
    properly display the map."

return
!**************************************************************************
procedure toggleInstructions

  res holdStatus reg.idplot.holdrefresh
  
  set reg.panel.controls.holdText.value  "  HoldRefresh = ^holdStatus" 

return