; $Id: davegr2d__set.pro,v 1.9 2006/08/31 17:57:38 azuah Exp $
;###############################################################################
;
; CLASS NAME:
;   DaveGr2D
;
; PURPOSE:
;   The DaveGr2D class extends the DaveGr class to better handle
;   plotting of 2D data ie area and surface plots.
;
; CATEGORY:
;   Data Browser
;
; SUPERCLASSES:
;   DaveGr
;
; PUBLIC METHODS:
;   Display
;   Get
;   ReserMiscGrAttribs
;   Set
;
; AUTHOR:
;   Richard Tumanjong Azuah
;   NIST Center for Neutron Research
;   100 Bureau Drive, Gaithersburg, MD 20899
;   United States
;   azuah@nist.gov; (301) 9755604
;   Dec, 2002
;
; LICENSE:
;  The software in this file is written by an employee of 
;  National Institute of Standards and Technology 
;  as part of the DAVE software project.
;
;  The DAVE software package is not subject to copyright protection
;  and is in the public domain. It should be considered as an
;  experimental neutron scattering data reduction, visualization, and
;  analysis system. As such, the authors assume no responsibility
;  whatsoever for its use, and make no guarantees, expressed or
;  implied, about its quality, reliability, or any other
;  characteristic. The use of certain trade names or commercial
;  products does not imply any endorsement of a particular product,
;  nor does it imply that the named product is necessarily the best
;  product for the stated purpose. We would appreciate acknowledgment
;  if the DAVE software is used or if the code in this file is
;  included in another product.
;
;###############################################################################



;===============================================================================
; DaveGr2D::Set
;
; PURPOSE:
;   Get method for class
;
; PARAMETERS:
;
; KEYWORDS:
;   plotType [in] - plot type ('contour'|'image'|'surface').
;
;   yColor [in] - y-axis color (RGB).
;
;   yFontVal [in] - y-axis font family name.
;
;   yFontSize [in] - y-axis fontsize
;
;   yLabel [in] - the y-axis label.
;
;   yLineSize [in] - y-axis line thickness.
;
;   yMiscAttribs [in] - a structure containing various y-axis graphics
;                       attributes.
;
;   _EXTRA [out] - enables keywords to be passed on
;
; RETURN VALUES:
;   0 => failure
;   1 => success
;
function DaveGr2D::set, plotType=plotType $
  ,yFontVal=yFont,yColor=yColor,yFontSize=yFontSize,yLabel=yLabel,yLineSize=yLineSize,fgColor=fgColor $
  ,fillflag=fillflag, nlevels=nlevels,shadeflag=shadeflag,interpFlag=interpFlag,style=style $
  ,skirtFlag=skirtFlag,skirtValue=skirtValue,colorIndex=colorIndex,hiddenLineFlag=hlFlag $
  ,vertShadeFlag=vertShadeFlag,bottomFlag=bottomFlag,bottomColor=bottomColor $
  ,ambLightInt=alInt,posLightInt=plInt,posLightLoc=plLoc,posLightFlag=plFlag,ambLightFlag=alFlag $
  ,posLightDir=plDir,yMiscAttribs=yMiscAttribs,transpose=transpose $
  ,cLabelFlag=cLabelFlag,cLabelInt=cLabelInt,cLabelDist=cLabelDist,downhillFlag=downhillFlag $
  ,cLinestyle=cLinestyle,cThick=cThick $
  ,_EXTRA=etc


; reset !error_state structure, ie clear all errors
message,/reset

;use this to return a fail condition if at least one error is encountered
retVal = 1

; plotType keyword
if (n_elements(plotType) gt 0) then begin
    ;; make sure value is a string
    if(vartype(plotType) eq 'STRING') then begin
        ;; make sure plotType is valid
        valid = ['CONTOUR','IMAGE','SURFACE']
        res = where(valid eq strupcase(plotType), count)
        if ((count gt 0) and (self.plotType ne strupcase(plotType))) then begin
            self.plotType = strupcase(plotType)
            ;; have to also change the plotAttrib's to match the new
            ;; plotType!
            heap_free,self.plotAttribPtr 
            heap_free,self.dPlotAttribPtr
            case self.plotType of 
                'CONTOUR': self->initContour 
                'IMAGE': self->initImage
                'SURFACE': self->initSurface 
            endcase
        endif else begin
            !error_state.msg = 'DaveGr2D::set: plotType keyword value should be CONTOUR, IMAGE or SURFACE'
            !error_state.code = -1
            return, 0
        endelse
    endif else begin
        !error_state.msg = 'DaveGr2D::set: plotType keyword value should be a string'
        !error_state.code = -1
        return, 0
    endelse
endif

; set miscellaneous graph attributes for y-axis
if (n_elements(yMiscAttribs)) then begin
    ;; make sure value is a valid structure
    if(vartype(yMiscAttribs) eq 'MISCGRATTRIBS') then self.yMiscAttribs = yMiscAttribs
endif

if (n_elements(transpose) gt 0) then begin
    self.transposeFlag = transpose
endif

if (n_elements(yFont) gt 0) then begin
    if (vartype(yFont) eq 'STRING') then self.yFont = yFont
endif

if (n_elements(yFontSize) gt 0) then begin
    self.yFontSize = yFontSize
endif

if (n_elements(yLabel) gt 0) then begin
    if (vartype(yLabel) eq 'STRING') then self.yLabel = yLabel
endif

if (n_elements(yColor) gt 0) then begin
    dim = size(yColor)
    if ( (dim[0] eq 1) and (dim[1] eq 3)) then self.yColor = yColor
endif

if (n_elements(yLineSize) gt 0) then $
  self.yLineSize = yLineSize

; Change colour index
if (n_elements(colorIndex) gt 0) then begin
    self.colorIndex = 0 > colorIndex < 40
    (self.palette)->loadCt, self.colorIndex
endif

; fillFlag
if (n_elements(fillFlag) gt 0) then begin
    if (self.plotType eq 'CONTOUR') then $
      (*self.plotAttribPtr).fillflag = fillFlag
endif

; nlevels
if (n_elements(nlevels) gt 0) then begin
    if (self.plotType eq 'CONTOUR') then $
      (*self.plotAttribPtr).nlevels = nlevels
endif

; cLabelFlag
if (n_elements(cLabelFlag) gt 0) then begin
    if (self.plotType eq 'CONTOUR') then $
      (*self.plotAttribPtr).cLabelFlag = cLabelFlag
endif

; cLabelInt
if (n_elements(cLabelInt) gt 0) then begin
    if (self.plotType eq 'CONTOUR') then $
      (*self.plotAttribPtr).cLabelInt = cLabelInt
endif

; cLabelDist
if (n_elements(cLabelDist) gt 0) then begin
    if (self.plotType eq 'CONTOUR') then $
      (*self.plotAttribPtr).cLabelDist = cLabelDist
endif

; downhillFlag
if (n_elements(downhillFlag) gt 0) then begin
    if (self.plotType eq 'CONTOUR') then $
      (*self.plotAttribPtr).downhillFlag = downhillFlag
endif

; cLinestyle
if (n_elements(cLinestyle) gt 0) then begin
    if (self.plotType eq 'CONTOUR') then $
      (*self.plotAttribPtr).cLinestyle = cLinestyle
endif

; cThick
if (n_elements(cThick) gt 0) then begin
    if (self.plotType eq 'CONTOUR') then $
      (*self.plotAttribPtr).cThick = cThick
endif

; bottomFlag
if (n_elements(bottomFlag) gt 0) then begin
    if (self.plotType eq 'SURFACE') then $
      (*self.plotAttribPtr).bottomFlag = bottomFlag
endif

; bottomColor
if (n_elements(bottomColor) gt 0) then begin
    if (self.plotType eq 'SURFACE') then $
      (*self.plotAttribPtr).bottomColor = bottomColor
endif

; shadeFlag
if (n_elements(shadeFlag) gt 0) then begin
    if (self.plotType ne 'IMAGE') then $
      (*self.plotAttribPtr).shadeFlag = shadeFlag
endif

; vertShadeFlag
if (n_elements(vertShadeFlag) gt 0) then begin
    if (self.plotType eq 'SURFACE') then $
      (*self.plotAttribPtr).vertShadeFlag = vertShadeFlag
endif

; interpFlag
if (n_elements(interpFlag) gt 0) then begin
    if (self.plotType eq 'IMAGE') then $
      (*self.plotAttribPtr).interpFlag = interpFlag
endif

; skirtFlag
if (n_elements(skirtFlag) gt 0) then begin
    if (self.plotType eq 'SURFACE') then $
      (*self.plotAttribPtr).skirtFlag = skirtFlag
endif

; skirtValue
if (n_elements(skirtValue) gt 0) then begin
    if (self.plotType eq 'SURFACE') then $
      (*self.plotAttribPtr).skirtValue = skirtValue
endif

; hiddenLineFlag
if (n_elements(hlFlag) gt 0) then begin
    if (self.plotType eq 'SURFACE') then $
      (*self.plotAttribPtr).hiddenLineFlag = hlFlag
endif

; style
if (n_elements(style) gt 0) then begin
    if (self.plotType eq 'SURFACE') then $
      (*self.plotAttribPtr).style = style
endif

; Ambient Light intensity
if (n_elements(alInt) gt 0) then begin
    if (self.plotType eq 'SURFACE') then $
      (*self.plotAttribPtr).ambLightInt = alInt
endif

; Positional Light intensity
if (n_elements(plInt) gt 0) then begin
    if (self.plotType eq 'SURFACE') then $
      (*self.plotAttribPtr).posLightInt = plInt
endif

; Positional Light Flag
if (n_elements(plFlag) gt 0) then begin
    if (self.plotType eq 'SURFACE') then $
      (*self.plotAttribPtr).posLightFlag = plFlag
endif

; Ambient Light Flag
if (n_elements(alFlag) gt 0) then begin
    if (self.plotType eq 'SURFACE') then $
      (*self.plotAttribPtr).ambLightFlag = alFlag
endif

; Positional Light Location
if (n_elements(plLoc) gt 0) then begin
    if (self.plotType eq 'SURFACE') then $
      (*self.plotAttribPtr).posLightLoc = plLoc
endif

; Positional Light Direction
if (n_elements(plDir) gt 0) then begin
    if (self.plotType eq 'SURFACE') then $
      (*self.plotAttribPtr).posLightDir = plDir
endif

; Anything else is handled by the base class
; However, if dataRef and addDataRef keywords were passed make sure that their values
; are valid DaveDat2D objects before passing resposibility to the base class
if (n_elements(etc) gt 0) then begin
    res = where(tag_names(etc) eq 'DATAREF', dataRef_isSet)
    if (dataRef_isSet gt 0) then begin
        if (vartype((etc.dataRef)[0]) ne 'DAVEDAT2D') then begin
            !error_state.msg = 'DaveGr2D::set: invalid object reference (dataRef) passed'
            !error_state.code = -1
            return, 0
        endif
    endif 
    res = where(tag_names(etc) eq 'ADDDATAREF', addDataRef_isSet)
    if (addDataRef_isSet gt 0) then begin
        if (vartype((etc.addDataRef)[0]) ne 'DAVEDAT2D') then begin
            !error_state.msg = 'DaveGr2D::set: invalid object reference (dataRef) passed'
            !error_state.code = -1
            return, 0
        endif
    endif 
    retVal = self->DaveGr::set(_EXTRA=etc)
endif

return, retVal
end
