! Test changes to plot's UNZOOM message
!
! @Bug:     2235, 2238, 2357 (Unzoom Msg T values)
! @Author:  J Bauer
!
startmacro

  !! This macro updated to use a pipe section in Feb 2012 for Bug 2537  !! 

  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE

  call setDatDir

  set testfile ^{datDir}.apenny.prm
  set firstmsg "TRUE"   ! The first unzoom message
  set ignoreUnzoomMsg "FALSE"  ! used for bug 2743 test
  set counter 1
                    
  set instructions "This test should run to completion automatically."                  
                    
  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 8 /title                   
    plot/id=plot1/msgid=MAIN ^testfile 
    
    set this.timer(0) 1.1   ! automate the test
   
  pipe off
endmacro

!******************************************************************************!
procedure processMessage m:msg

  !say "^msg, data ^msg.data"

  if msg.name eqs "MAIN" then
    assert/text="test_plot_unzoom: " msg.data eqss "PASS"
    pipe stop
  
  elseif msg.name eqs "TIMER" then
    if counter eq 1 then
      invoke reg.plot1.preprocess("BUTTON",3,"nada")                     ! simulate right mouse click when zoomed all the way out  
      set counter 2
    elseif counter eq 2 then
       message sendw ID=plot1 NAME="ZOOM" DATA={X1=50,X2=100,Y1=0,Y2=50}  ! simulate zoom
       set counter 3
    elseif counter eq 3 then
       message sendw ID=plot1 NAME="ZOOM" DATA={X1=20,X2=50,Y1=0,Y2=50}   ! simulate zoom again
       set counter 4
    elseif counter eq 4 then
      invoke reg.plot1.preprocess("BUTTON",3,"nada")                     ! simulate right mouse click when zoomed in a bit
      set counter 5
    elseif counter eq 5
      set ignoreUnzoomMsg "TRUE"
      call testBug2743   
      set counter 6 
    elseif counter eq 6
      pipe stop     ! end of test
    endif
    
  elseif msg.name eqs "UNZOOM" AND ignoreUnzoomMsg eqs "FALSE"
  
    if firstmsg eqs "TRUE" then      ! not zoomed in. info should be -1
      set firstmsg "FALSE"
      assert/text="TEST_PLOT_UNZOOM: Unzoom at top level. Msg.info= ^msg.info" msg.info eq -1 
    else
      invoke reg.plot1.refresh()
      assert/text="TEST_PLOT_UNZOOM: Unzoom when zoomed in. Msg.info= ^msg.info &
         AND TMax= ^msg.data.tmax" msg.info eq reg.plot1.zoomLevel AND msg.data.tmax eq 50 
         
    endif 
  else
    ! do nothing
    !say "Unhandled message name: ^msg.name from fid: ^msg.fid dats: ^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

!******************************************************************************!
!
! Test Bug 2743
! Bug Description: "PLOT: zoom all the way out with "ZOOMOUT" data=-1 message does not reset zoom level/history"
! 
! This test simulates a user zooming in twice, followed by a zoom all the way out.  
! When zooming all the way out, history should be reset.  Final simulation of a 
! user right mouse click should not recall prior zoom in.
!
procedure testBug2743

  message sendw ID=plot1 NAME="ZOOM" DATA={X1=.25,X2=.75,Y1=.25,Y2=.75} ! simulate zoom
  message sendw ID=plot1 NAME="ZOOM" DATA={X1=.3,X2=.6,Y1=.3,Y2=.6}  	! simulate another zoom  
  message sendw ID=plot1 NAME="ZOOMOUT" DATA=-1   						! simulate zoom all the way out
  invoke reg.plot1.preprocess("BUTTON",3,"nada")                     	! simulate right mouse

  ! The following assertion verifies that the last simulated right mouse click
  ! does not change plot to most recent coordinates stored in history.
  assert/text="TEST_PLOT_UNZOOM: Zoomout clear history test" &
        reg.plot1.orx1 eq/t reg.plot1.rx1 &
    AND reg.plot1.orx1 eq/t reg.plot1.rx1 &
    AND reg.plot1.ory1 eq/t reg.plot1.ry1 &
    AND reg.plot1.ory2 eq/t reg.plot1.ry2 
    
return
