! Test Layer2D's plotting with changing size of colormaps (Bug 1698)
!    and inverting a colormap (BUG 2196)
!
! Bug:     1698 (CMAPs), 2196 (CMAP inversion)
! Author:  J. Bauer
!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE

  call setDatDir

  if interAct then
    set testfile ^{datDir}.apenny.prm
    
    set cmap16 "#000026,#000063,#00178A,#004F9E,#0387B3,#03ABAB,#03BD66,#00D11F,&
                #1CD600,#5ED100,#A3CF00,#CFBF00,#F0A600,#FF7500,#FF4000,#FF0000"
    
    set cmap31 "#000026,#000026,#000063,#000063,#00178A,#00178A,#004F9E,#004F9E,&
                #0387B3,#0387B3,#03ABAB,#03ABAB,#03BD66,#03BD66,#00D11F,#00D11F,&
                #1CD600,#1CD600,#5ED100,#5ED100,#A3CF00,#A3CF00,#CFBF00,#CFBF00,&
                #F0A600,#F0A600,#FF7500,#FF7500,#FF4000,#FF4000,#FF0000"
                
    set cmap32 "#000026,#000026,#000063,#000063,#00178A,#00178A,#004F9E,#004F9E,&
                #0387B3,#0387B3,#03ABAB,#03ABAB,#03BD66,#03BD66,#00D11F,#00D11F,&
                #1CD600,#1CD600,#5ED100,#5ED100,#A3CF00,#A3CF00,#CFBF00,#CFBF00,&
                #F0A600,#F0A600,#FF7500,#FF7500,#FF4000,#FF4000,#FF0000,#FF0000"       

    ! Zoom Settings
    set x1 0
    set x2 25
    set y1 75
    set y2 100

    pipe init
      panel/msgid=MAIN/setup/controls=gc
      
      plot/id=plot32 ^testfile{LAYER={COLORMAP="^cmap32"}}
      !plot/id=plot31 ^testfile{LAYER={COLORMAP="^cmap31"}}
      plot/id=plot16 ^testfile{LAYER={COLORMAP="^cmap16"}}

      gcontrol label  macro   "MACRO"
      gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
      set gc.main.itemColors {PASS=GREEN,FAIL=RED}

      set instructions "Should see 2 plots of a penny, each using a custom &
                        colormap. Click on each 'GRAYSCALE' button to convert &
                        the plot to the pre-defined grayscale colormap. Both &
                        plots should look identical. Click on each 'XRAMP' &
                        button to convert to the xramp colormap and zoom in on &
                        the plot. The plots should look identical. Prior to Bug &
                        1698 fix the bottom plot would show color irregularities. &
                        Click on the buttons under 'REVERSE COLORMAP' and &
                        'INVERT COLORMAP' to reverse and/or invert &
                        the colors used in the plots."
                        
      gcontrol text idtext "Instructions" "^instructions" 24 20 /title
      
      gcontrol button gray32 "" "GRAYSCALE TOP"
      gcontrol button gray16 "" "GRAYSCALE BOTTOM" 
      gcontrol button xramp32 "" "XRAMP TOP"
      gcontrol button xramp16 "" "XRAMP BOTTOM"
      
      gcontrol label  reverseLabel "REVERSE COLORMAP"
      gcontrol button reverse "" "TOP,BOTTOM" 
      
      gcontrol label invertLabel "INVERT COLORMAP"
      gcontrol button invert "" "TOP,BOTTOM"
       

    pipe off
  endif

endmacro

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

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

  if msg.name eqs "MAIN" then
    assert/text="Plot Layer2D colormap" msg.data eqss "PASS"
    pipe stop
  
  elseif msg.name eqs "GRAY32" then
    res reg.plot32.layers.apenny.colormap grayscale
  elseif msg.name eqs "GRAY16" then
    res reg.plot16.layers.apenny.colormap grayscale
  elseif msg.name eqs "XRAMP32" then
    message sendw id=plot32 name=zoom data={xmin=^{x1},xmax=^{x2},ymin=^{y1},ymax=^{y2}}
    res reg.plot32.layers.apenny.colormap xramp
  elseif msg.name eqs "XRAMP16" then
    message sendw id=plot16 name=ZOOM data={xmin=^{x1},xmax=^{x2},ymin=^{y1},ymax=^{y2}}
    res reg.plot16.layers.apenny.colormap xramp
  elseif msg.name eqs "REVERSE" then
    if msg.data eqs "TOP" then
      invoke ,, reg.plot32.layers.apenny.setEffects("~REVERSECOLORS")
    elseif msg.data eqs "BOTTOM" then
      invoke ,, reg.plot16.layers.apenny.reverseColorMap()
    endif
   elseif msg.name eqs "INVERT" then
     if msg.data eqs "TOP" then
       invoke ,, reg.plot32.layers.apenny.setEffects("~INVERTCOLORS")
     elseif msg.data eqs "BOTTOM" then
       invoke ,, reg.plot16.layers.apenny.invertColorMap()
     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
