; $Id: davegr1d__set.pro,v 1.9 2005/02/17 23:29:23 azuah Exp $
;###############################################################################
;
; CLASS NAME:
;   DaveGr1D
;
; PURPOSE:
;   The DaveGr1D class extends the DaveGr class to better handle
;   plotting of 1D data ie line plots.
;
; CATEGORY:
;   Data Browser
;
; SUPERCLASSES:
;   DaveGr
;
; PUBLIC METHODS:
;   Display
;   Get
;   ResetLegend
;   ReserMiscGrAttribs
;   Set
;
; AUTHOR:
;   Richard Tumanjong Azuah
;   NIST Center for Neutron Research
;   100 Bureau Drive, Gaithersburg, MD 20899
;   United States
;   azuah@nist.gov; (301) 9755604
;   Nov, 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.
;
;###############################################################################



;===============================================================================
; DaveGr1D::Set
;
; PURPOSE:
;   Set method for class
;
; PARAMETERS:
;
; KEYWORDS:
;   lineType [in] - assign the linetype index (integer)
;
;   lineSize [in] - assign the line size (float)
;
;   symType [in] - assign the symbol index (integer)
;
;   symSize [in] - assign the symbol size (float)
;
;   lineSymFlag [in] - assign the lineSymFlag which specifies whether
;                      lines, symbols or symbols+lines are to be plotted.
;
;   myPlotType [in] - assign the plot type (string): 'POINT' or
;                     'HISTOGRAM'. Normally, the plot type is
;                     determined by the independent axis
;                     type. However, it is possible to overide the
;                     default type using this keyword in combination
;                     with the myPlotTypeFlag keyword.
;
;   myPlotTypeFlag [in] - assign (integer) setting for myPlotTypeFlag
;                         variable. If set to 1, then the myPlotType
;                         setting will be used to overide the
;                         independent variable type.
;
;   color [in] - assign the line/symbol display color as an RGB tripplet.
;
;   maskIndex [in] - assign a list of independent axis (integer)
;                    indices to be masked.
;
;   legend [in] - an IDL structure containing plot legend attributes.
;
;   _EXTRA [in] - enables keywords to passed on
;
; RETURN VALUES:
;   0 => failure
;   1 => success
;
function DaveGr1D::set, lineType=lineType, lineSize=lineSize, symType=symType, symSize=symSize, $
                        lineSymFlag=lsFlag, color=color, maskIndex=maskIndex, position=pos, $
                        legend=legend,_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

; Set index 'pos' (from which changes should be made in the data
; array) to zero if not set
pos_IsSet = 0b
if (n_elements(pos) gt 0) then pos_IsSet = 1b else pos = 0

; nos of data elements
maxLen = self->count()

numericType=['FLOAT','INT','DOUBLE','LONG','BYTE']
integralType=['INT','LONG','BYTE']
floatType=['FLOAT','DOUBLE']
stringType=['STRING']

; lineType
len = n_elements(lineType)
if (len gt 0) then begin
    res = where((vartype(lineType) eq numericType), count) ; input must be a number 
    if (count ge 0) then begin
        len = len < maxLen
        self.lineType[pos:(pos+len)-1] = byte(lineType[0:len-1]); cast to byte
    endif else begin
        !error_state.msg = 'DaveGr1D::set: lineType keyword value should be an integer'
        !error_state.code = -1
        return, 0
    endelse
endif

; lineSize
len = n_elements(lineSize)
if (len gt 0) then begin
    res = where((vartype(lineSize) eq numericType), count) ; input must be a number 
    if (count ge 0) then begin
        len = len < maxLen
        self.lineSize[pos:(pos+len)-1] = float(lineSize[0:len-1]); cast to float
    endif else begin
        !error_state.msg = 'DaveGr1D::set: lineSize keyword value should be a float'
        !error_state.code = -1
        return, 0
    endelse
endif

; symType
len = n_elements(symtype)
if (len gt 0) then begin
    res = where((vartype(symType) eq numericType), count) ; input must be a number 
    if (count ge 0) then begin
        len = len < maxLen
        self.symType[pos:(pos+len)-1] = byte(symType[0:len-1]) ; cast to byte
    endif else begin
        !error_state.msg = 'DaveGr1D::set: symType keyword value should be an integer'
        !error_state.code = -1
        return, 0
    endelse
endif

; symSize
len = n_elements(symSize)
if (len gt 0) then begin
    res = where((vartype(symSize) eq numericType), count) ; input must be a number 
    if (count ge 0) then begin
        len = len < maxLen
        self.symSize[pos:(pos+len)-1] = byte(symSize[0:len-1]) ; cast to byte
    endif else begin
        !error_state.msg = 'DaveGr1D::set: symSize keyword value should be an integer'
        !error_state.code = -1
        return, 0
    endelse
endif

; lineSymFlag
len = n_elements(lsFlag)
if (len gt 0) then begin
    res = where((vartype(lsFlag) eq numericType), count) ; input must be a number 
    if (count ge 0) then begin
        len = len < maxLen
        self.lineSymFlag[pos:(pos+len)-1] = byte(lsFlag[0:len-1]) ; cast to byte
    endif else begin
        !error_state.msg = 'DaveGr1D::set: lineSymFlag keyword value should be an integer'
        !error_state.code = -1
        return, 0
    endelse
endif

; line/symbol Color; color should be 3-element byte array
len = n_elements(color)
if (len gt 0) then begin
    res = where((vartype(color) eq integralType), count) ; input must be a string 
    dim = size(color)
    len = (dim[0] eq 1)? 1 : dim[1]
    if ((count ge 0) and ((dim[0] eq 1) or (dim[0] eq 2)) and ((dim[1] eq 3) or (dim[2] eq 3))) then begin
        iend = (pos+len) < maxLen
        self.color[pos:iend-1,*] = (dim[0] eq 1)? color : color[0:len-1,*] 
    endif else begin
        !error_state.msg = 'DaveGr1D::set: color keyword value should be a byte array of [R,G,B] values'
        !error_state.code = -1
        return, 0
    endelse
endif

; maskIndex
if (n_elements(maskIndex) gt 0) then begin
    res = where((vartype(maskIndex) eq integralType), count) ; input must be an integer
    if (count ge 0) then begin
        if (ptr_valid(self.maskPtr)) then begin
            (*self.maskPtr) = fix(maskIndex) ; cast to integer
        endif else begin
            self.maskPtr = ptr_new(fix(maskIndex))
        endelse
    endif else begin
        !error_state.msg = 'DaveGr1D::set: maskIndex keyword value should be an integer vector'
        !error_state.code = -1
        return, 0
    endelse
endif

; set legend
if (n_elements(legend)) then begin
    ;; make sure value is a valid structure
    if(vartype(legend) eq 'LEGENDSTR') then self.legend = legend
endif

; Anything else is handled by the base class
retVal = self->DaveGr::set(_EXTRA=etc)

return, retVal
end
