!------------------------------------------------------------------------------!
! BUG 1326 / 1901:  Test plotting a Layer2d file with changes to ZMin / ZMax
!
! Author:  J. Bauer
!------------------------------------------------------------------------------!
startmacro

  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE

  call setDatDir

  set instructions &
      "Should see 2 (altered) plots of a penny in the top plot. The one on the &
       right should look the same as the one on the left, even though they are &
       using  different ZMIN/ZMAX values. The bottom frame should show two plots &
       of a penny that look the same, even though they have different Z Scales. &
       KNOWN DR: You may need to press the RE-READ FILES button a few times to get the &
       plots to draw correctly (and sometimes it never does)."
       
   set plot_instr "The penny on the right in the top plot should looked 'washed out'."
   
   set lay_instr "The penny on the right in the bottom plot should looked 'washed out'."

  if interAct then
    pipe init
    pipe on

    panel/msgid=MAIN/setup/controls=gc
    
    fcalc temp99{aux=ram} ^{datDir}.apenny.prm 10 *
    plot/id=plot1/scalez=layer temp99|^{datDir}.apenny.prm{layer={xs=129,zmin=-50,zmax=100}} z1=-500 z2=1000
    
    plot/id=plot2/scalez=layer temp99|^{datDir}.apenny.prm{tag="xpen",layer={xs=129}}

    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" 24 18 /title

    gcontrol button reread "" "RE-READ FILES"
    gcontrol button zvals "CHANGE ZVALS" "PLOT,LAYER"

    pipe off

  endif

endmacro

!******************************************************************************!
procedure processMessage m:msg
  if msg.name eqs "MAIN" then
    assert/text="Plot border tests" msg.data eqss "PASS" 
    pipe stop
  elseif msg.name eqs "REREAD" then
    message func=sendw id=plot1 name=FILE data=reread
    message func=sendw id=plot2 name=FILE data=reread
  elseif msg.name eqs "ZVALS" then
    if msg.data eqs "PLOT" then
      set reg.plot1.z1 -500
      set reg.plot1.z2 1000
      set gc.idtext.value "^plot_instr"
    elseif msg.data eqs "LAYER" then
      set reg.plot2.layers.xpen.z1 -500
      set reg.plot2.layers.xpen.z2 1000
      set gc.idtext.value "^lay_instr"
    endif  
  else
    ! do nothing
    say "^reg.main.name: 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
