;------------------------------------------------------------------------------;
;+
; NAME:
;		         eis_ll_obj__DEFINE
; PURPOSE:
;		         This procedure defines the data memebers of the
;                   Object "eis_ll_obj".
; INPUTS:
;		         ll - an eis_line_list structure
; AUTHOR:
;		         John A. Rainnie - RAL (j.a.rainnie@rl.ac.uk)
;
; HISTORY:               V1, John Rainnie
;                        V2, 5-Feb-2007
;                          added slitindex call to eis_line_values
;-
;------------------------------------------------------------------------------;
FUNCTION eis_ll_obj::Init , parentClass, ll

Self.ll          = ll
Self.parentClass = parentClass

RETURN,1
END
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_ll_obj::setProperty , ll            = ll            ,            $
                              dataWindows   = dataWindows   ,            $
                              slitindex     = slitindex

IF (N_ELEMENTS(ll)          GT 0) THEN Self.ll           = ll
IF (N_ELEMENTS(dataWindows) GT 0) THEN Self.dataWindows  = dataWindows
IF (N_ELEMENTS(slitindex)   GT 0) THEN Self.ll.slitindex = slitindex


Self->refreshLineList

END
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_ll_obj::getProperty , ll = ll , dataWindows = dataWindows

ll          = Self.ll
dataWindows = Self.dataWindows

END
;______________________________________________________________________________
; Cleanup
;______________________________________________________________________________
PRO eis_ll_obj::Cleanup


END
;______________________________________________________________________________
; Sort Line List
;______________________________________________________________________________
PRO eis_ll_obj::sortLL

stop

END
;______________________________________________________________________________
; Refresh Line List
;______________________________________________________________________________
PRO eis_ll_obj::removeAllLines

; OK, update ll.nLines, ll and dataWindows
; ll.nLines
Self.ll.nLines   = 0
; dataWindows
Self.dataWindows = INTARR(25)
; ll
Self.ll.lines = REPLICATE({eis_line} , 25 )

Self->refreshLineList

END
;______________________________________________________________________________
; Refresh Line List
;______________________________________________________________________________
PRO eis_ll_obj::deleteLine , index

oldLines    = Self.ll.lines[0:Self.ll.nLines-1]

oldLineIndicies = INDGEN(Self.ll.nLines)             ; [0,1,2]
; OK, get indicies that are not the selected item
newLineIndicies = WHERE(oldLineIndicies NE index)    ; [1,2]

IF (newLineIndicies[0] NE -1) THEN BEGIN
    ; Ok, we want to create an array of eis_study_rasters...one less than
    ; we've already got!
    newLines = REPLICATE({eis_line} , Self.ll.nLines - 1 )
    newDataW = INTARR(Self.ll.nLines - 1)
    ; Update these with real values
    FOR i = 0, Self.ll.nLines - 1 - 1  DO BEGIN

        ; We want all the rasters EXCEPT the selected one
        newLines[i] = Self.ll.lines[   newLineIndicies[i] ]
        newDataW[i] = Self.dataWindows[newLineIndicies[i] ]

    ENDFOR
ENDIF ELSE BEGIN
    Self->removeAllLines
    RETURN
ENDELSE

; OK, update ll.nLines, ll and dataWindows
; ll.nLines
Self.ll.nLines   = Self.ll.nLines - 1
; dataWindows
Self.dataWindows = INTARR(25)
Self.dataWindows[0:Self.ll.nLines - 1] = newDataW
; ll
Self.ll.lines = REPLICATE({eis_line} , 25 )
Self.ll.lines[0:Self.ll.nLines - 1] = newLines

Self->refreshLineList

END
;______________________________________________________________________________
; Refresh Line List
;______________________________________________________________________________
PRO eis_ll_obj::addLine , line , defWidth

FOR i = 0, N_ELEMENTS(line) - 1 DO BEGIN

    Self.dataWindows[Self.ll.nLines] = defWidth
    ; OK, time to update the lineList values, wavelength, type and name
    lineSplit = STRSPLIT( line[i] , /EXTRACT)

    nLines = Self.ll.nLines
    Self.ll.lines[nLines].wavelength = LONG(   lineSplit[0] * 100.)

    IF (lineSplit[1] EQ 'c') THEN type = 0 ELSE type = 1
    Self.ll.lines[nLines].type         = type
    ; Get name
    name = STRTRIM(lineSplit[2] , 2) + ' ' +STRTRIM(lineSplit[3] , 2)
    Self.ll.lines[nLines].name       = name
    Self.ll.nLines = nLines + 1

ENDFOR

;Self->refreshLineList

END
;______________________________________________________________________________
; Refresh Line List
;______________________________________________________________________________
PRO eis_ll_obj::refreshLineList

; Handle case where there are zero lines!
IF (Self.ll.nLines EQ 0) THEN BEGIN
    Self.parentClass->setProperty , dataWindows = Self.dataWindows
    Self.parentClass->updateRasterLineList
    RETURN
ENDIF


; Sort new line list - "sorted" tags are {ll:ll , indicies:indicies}
sorted  = eis_linelist_sort(Self.ll)
Self.ll = sorted.ll

; Store current dataWindows and refresh stored values
dataWindows      = Self.dataWindows
Self.dataWindows = INTARR(25)

FOR i = 0, Self.ll.nLines - 1 DO BEGIN

    ; Eg; for core lines, sorted.indicies = [0, 1, 2]
    Self.dataWindows[i] = dataWindows[sorted.indicies[i]]

ENDFOR

; Calculate line properties
Self->calculateLineProperties_all
; Check for overlapping windows
Self->checkForOverlappingWindows

; Update Line List TITLE
Self->updateTitle
; Set mk_raster dataWindows
Self.parentClass->setProperty , dataWindows = Self.dataWindows
Self.parentClass->updateRasterLineList

END
;______________________________________________________________________________
; Update line list title
;______________________________________________________________________________
PRO eis_ll_obj::updateTitle

IF (Self.ll.nLines EQ 0) THEN BEGIN
    Self.ll.title = ''
    RETURN
ENDIF

Self.ll.title = eis_generate_linelist_title(Self.ll)

END
;______________________________________________________________________________
; Refresh Line List
;______________________________________________________________________________
PRO eis_ll_obj::calculateLineProperties_all

;
; Populate LL aux values , including, p0, p1, p2, CCD, quad, etc
;
FOR i = 0 , Self.ll.nLines -1 DO BEGIN

    ; Get eis_line values - starting with wavelength & width
    line  = Self.ll.lines[i]
    width = Self.datawindows[i]
   ;
   ; PRY, 5-Feb-2007
   ;   added slitindex input to eis_line_values
   ;
    slitindex = Self.ll.slitindex
    Self.ll.lines[i] = eis_line_values(line , width, slitindex)

ENDFOR

END
;______________________________________________________________________________
; Refresh Line List
;______________________________________________________________________________
PRO eis_ll_obj::checkForOverlappingWindows

Self.ll = eis_overlapping_windows( Self.ll  )
Self.ll = eis_split_window(Self.ll)

END
;______________________________________________________________________________
Pro eis_ll_obj__Define
;______________________________________________________________________________

junk =  {   eis_ll_obj,                                                $
                        ll             : {eis_line_list}         ,     $
                        dataWindows    : INTARR(25)              ,     $
                        parentClass    : OBJ_NEW()                     $
    	   }

End
