;------------------------------------------------------------------------------;
;+
; NAME
;           eis_mk_raster_gui__define
;
; PURPOSE
;           This object
;
; INPUTS
;
;
; WRITTEN
;           John A Rainnie, RAL, Dec-2005
;
; HISTORY
;           V0.1 JAR, 24-Feb-2007
;               Included checks to ensure a raster cannot be saved if its
;               total spatial width exceeds the EIS FOV width. Warnings will
;               invoked when this happens.
;           V0.2 JAR, 7-Mar-2007
;               Check that the current linelist is saved before allowing
;               the raster to be saved
;           v0.3 JAR, 16-Mar-2007
;               (a) Don't realise Raster and LineList Import and
;                   Export buttons
;               (b) Keep number of pointings value as integer
;           v0.4 JAR, 21-March-2007
;               Corrected bug encountered when loading a 25-line
;               line list.
;           v0.5 JAR/PRY 26-Apr-2007
;               Updated raster fov checking - depends on slitIndex
;           v0.6 JAR 25-Oct_2007
;              Replaced logo jpeg - check it exists
;
;-
;------------------------------------------------------------------------------;
FUNCTION eis_mk_raster_gui::Init

;replace call to astrolib
DEFSYSV , '!DEBUG', 0
DEFSYSV , '!TEXTUNIT', 0
DEFSYSV , '!PRIV', 2
DEFSYSV , '!TEXTOUT', EXIST = EXIST

; Create the default colour tables
Self.o_def_ct     = OBJ_NEW("def_ct")
Self.colour_table = 3
Self.eis_ll_obj   = OBJ_NEW("eis_ll_obj" , Self , {eis_line_list})
Self.xySize       = [1024L,200]

;-------------------create the main base---------------------------------------;
pt_version = eis_get_pt_version_number()
widTitle = 'EIS Make Raster Tool' + pt_version

TLB_EVENT                   = {eis_mk_raster_gui_Event}
TLB_EVENT.eis_mk_raster_gui = Self
TLB_EVENT.Type              = "TLB"
Self.tlbID                  = WIDGET_BASE(                                  $
                                    TITLE       = widTitle,                 $
                                    COLUMN      = 1,                        $
                                    mbar        = bar,                      $
                                    UValue      = TLB_EVENT)

;;-------------------create the GUI------------------------------;
;;--------file menu list--------------------------------------------------------;
;file_menu	                  = WIDGET_BUTTON(bar, VALUE='Exit', /MENU)

;------------------------------------------------------------------------------;
event_pro        = 'eis_mk_raster_gui_EV'
event_pro_update = 'eis_mk_raster_gui_update_EV'

;--------raster menu list------------------------------------------------------;
raster_menu	                = WIDGET_BUTTON(bar, VALUE='Raster', /MENU)

RA_SEARCH_EVENT             = {eis_mk_raster_gui_Event}
RA_SEARCH_EVENT.eis_mk_raster_gui   = Self
RA_SEARCH_EVENT.Type        = "RASEARCHDB"
value = 'Load raster from database...'
RA_SEARCHButton             = WIDGET_BUTTON(raster_menu ,                   $
                                    value       = value ,                   $
                                    Event_Pro   = 'eis_mk_raster_gui_EV',   $
                                    uValue      = RA_SEARCH_EVENT )

RA_SAVE_EVENT               = {eis_mk_raster_gui_Event}
RA_SAVE_EVENT.eis_mk_raster_gui   = Self
RA_SAVE_EVENT.Type          = "RASAVEDB"
RA_SAVEButton               = WIDGET_BUTTON(raster_menu,                    $
                                    value       = 'Save in database...' ,   $
                                    Event_Pro   = 'eis_mk_raster_gui_EV',   $
                                    uValue      = RA_SAVE_EVENT)

;RA_ASCII_EVENT              = {eis_mk_raster_gui_Event}
;RA_ASCII_EVENT.eis_mk_raster_gui   = Self
;RA_ASCII_EVENT.Type         = "RA_EXPORT"
;RA_ASCIIButton              = WIDGET_BUTTON(raster_menu,                    $
;                                    value       = 'Export...',              $
;                                    Event_Pro   = 'eis_mk_raster_gui_EV',   $
;                                    uValue      = RA_ASCII_EVENT ,          $
;                                    /SEPARATOR)
;
;IMPORT_EVENT                = {eis_mk_raster_gui_Event}
;IMPORT_EVENT.eis_mk_raster_gui = Self
;IMPORT_EVENT.Type           = "RA_IMPORT"
;event_pro_update = 'eis_mk_raster_gui_update_EV'
;IMPORTbutton                = WIDGET_BUTTON(raster_menu,                    $
;                                    value       = 'Import...'   ,           $
;                                    Event_Pro   = event_pro_update  ,       $
;                                    uValue      = IMPORT_EVENT,sensitive=0)

VIEW_EVENT                  = {eis_mk_raster_gui_Event}
VIEW_EVENT.eis_mk_raster_gui = Self
VIEW_EVENT.Type             = "VIEWRASTER"
VIEWbutton                  = WIDGET_BUTTON(raster_menu,                    $
                                    value       = 'View Details...' ,       $
                                    Event_Pro   = 'eis_mk_raster_gui_EV',   $
                                    uValue      = VIEW_EVENT ,              $
                                    /SEPARATOR)

QUIT_EVENT                  = {eis_mk_raster_gui_Event}
QUIT_EVENT.eis_mk_raster_gui    = Self
QUIT_EVENT.Type             = "QUIT"
quitbutton                  = WIDGET_BUTTON(raster_menu  ,                  $
                                    value       = 'Exit',                   $
                                    Event_Pro   = 'eis_mk_raster_gui_EV',   $
                                    uValue      = QUIT_EVENT,/separator)

;------------------------------------------------------------------------------;
;--------line list menu list---------------------------------------------------;
ll_menu	                    = WIDGET_BUTTON(bar, VALUE='Linelist', /MENU)

LL_ADD_EVENT                = {eis_mk_raster_gui_Event}
LL_ADD_EVENT.eis_mk_raster_gui  = Self
LL_ADD_EVENT.Type           = "LL_ADDNEWLINE"
value   = "Add a line from the EIS project list..."
ll_addButton                = WIDGET_BUTTON(ll_menu,                        $
                                    value       = value   ,                 $
                                    Event_Pro   = 'eis_mk_raster_gui_EV', $
                                    uValue      = LL_ADD_EVENT)

;
; Delete Line
;
LL_DEL_EVENT                = {eis_mk_raster_gui_Event}
LL_DEL_EVENT.eis_mk_raster_gui  = Self
LL_DEL_EVENT.Type           = "LL_DELETE"
value = "Remove selected line from list"
ll_DELButton                = WIDGET_BUTTON(ll_menu   ,                     $
                                    value       = value      ,              $
                                    Event_Pro   = event_pro_update, $
                                    uValue      = LL_DEL_EVENT )

;
; Custom Name
;
LL_NAME_EVENT               = {eis_mk_raster_gui_Event}
LL_NAME_EVENT.eis_mk_raster_gui  = Self
LL_NAME_EVENT.Type          = "LL_CUSTOM_NAME"
value = "Assign a custom name..."
ll_DELButton                = WIDGET_BUTTON(ll_menu   ,                     $
                                    value       = value      ,              $
                                    Event_Pro   = event_pro               , $
                                    uValue      = LL_NAME_EVENT )

;
; Core Lines
;
LL_CORE_EVENT               = {eis_mk_raster_gui_Event}
LL_CORE_EVENT.eis_mk_raster_gui = Self
LL_CORE_EVENT.Type          = "LL_CORELINES"
LL_COREButton               = WIDGET_BUTTON(ll_menu   ,                     $
                                    value       = 'Insert Core lines only', $
                                    Event_Pro   = event_pro_update        , $
                                    uValue      = LL_CORE_EVENT)

;
; Load a Line List from the Database
;
RA_ASCII_EVENT              = {eis_mk_raster_gui_Event}
RA_ASCII_EVENT.eis_mk_raster_gui = Self
RA_ASCII_EVENT.Type         = "LL_DB"
value = 'Load line list from database...'
RA_ASCIIButton              = WIDGET_BUTTON(ll_menu    ,                    $
                                    value       = value,                    $
                                    Event_Pro   = 'eis_mk_raster_gui_EV',       $
                                    uValue      = RA_ASCII_EVENT ,          $
                                    /SEPARATOR)

;
; Save Line List in Database
;
DB_SAVE_EVENT               = {eis_mk_raster_gui_Event}
DB_SAVE_EVENT.eis_mk_raster_gui = Self
DB_SAVE_EVENT.Type          = "LL_DBSAVE"
value   = 'Save in database...'
DB_SAVEButton               = WIDGET_BUTTON(ll_menu  ,                      $
                                    value       = value                  ,  $
                                    Event_Pro   = event_pro              ,  $
                                    uValue      = DB_SAVE_EVENT )

;;
;; Export
;;
;LL_EXPORT_EVENT             = {eis_mk_raster_gui_Event}
;LL_EXPORT_EVENT.eis_mk_raster_gui   = Self
;LL_EXPORT_EVENT.Type        = "LL_EXPORT"
;LL_EXPORTButton             = WIDGET_BUTTON(ll_menu    ,                    $
;                                    value       = 'Export...' ,             $
;                                    Event_Pro   = event_pro   ,             $
;                                    uValue      = LL_EXPORT_EVENT ,         $
;                                    /SEPARATOR)
;
;;
;; Import
;;
;LL_IMPORT_EVENT             = {eis_mk_raster_gui_Event}
;LL_IMPORT_EVENT.eis_mk_raster_gui = Self
;LL_IMPORT_EVENT.Type        = "LL_IMPORT"
;tooltip = "Export the line list as an ASCII file"
;LL_IMPORTButton             = WIDGET_BUTTON(ll_menu    ,                    $
;                                    value       = 'Import...' ,             $
;                                    Event_Pro   = event_pro_update   ,      $
;                                    uValue      = LL_IMPORT_EVENT ,sensitive=0)

;------------------------------------------------------------------------------;
;--------plot menu list--------------------------------------------------------;
plot_menu	                  = WIDGET_BUTTON(bar, VALUE='Plot', /MENU)

PLOT_EVENT                  = {eis_mk_raster_gui_Event}
PLOT_EVENT.eis_mk_raster_gui = Self
PLOT_EVENT.Type             = "PLOTSPECTRUM"
PLOTbutton                  = WIDGET_BUTTON(plot_menu,                      $
                                    value       = 'Spectrum...',            $
                                    Event_Pro   = 'eis_mk_raster_gui_EV',   $
                                    uValue      = PLOT_EVENT)

image_menu	                 = WIDGET_BUTTON(plot_menu, VALUE='Image', /MENU)

IMAGE_EVENT                 = {eis_mk_raster_gui_Event}
IMAGE_EVENT.eis_mk_raster_gui = Self
IMAGE_EVENT.Type            = "IMAGE"
IMAGE_EVENT.extra           = 0
IMAGETextID                 = WIDGET_BUTTON(image_menu     ,                $
                                    value       = 'Quiet'   ,               $
                                    Event_Pro   = Event_Pro       ,         $
                                    uValue      = IMAGE_EVENT)

IMAGE_EVENT                 = {eis_mk_raster_gui_Event}
IMAGE_EVENT.eis_mk_raster_gui = Self
IMAGE_EVENT.Type            = "IMAGE"
IMAGE_EVENT.extra           = 1
IMAGETextID                 = WIDGET_BUTTON(image_menu     ,                $
                                    value       = 'Active'   ,              $
                                    Event_Pro   = Event_Pro       ,         $
                                    uValue      = IMAGE_EVENT)

IMAGE_EVENT                 = {eis_mk_raster_gui_Event}
IMAGE_EVENT.eis_mk_raster_gui = Self
IMAGE_EVENT.Type            = "IMAGE"
IMAGE_EVENT.extra           = 2
IMAGETextID                 = WIDGET_BUTTON(image_menu     ,                $
                                    value       = 'Flare'   ,               $
                                    Event_Pro   = Event_Pro       ,         $
                                    uValue      = IMAGE_EVENT)

;------------------------------------------------------------------------------;
;--------edit menu list--------------------------------------------------------;
edit_menu	                  = WIDGET_BUTTON(bar, VALUE='Edit', /MENU)

UNDO_EVENT                  = {eis_mk_raster_gui_Event}
UNDO_EVENT.eis_mk_raster_gui = Self
UNDO_EVENT.Type             = "UNDO"
UNDObutton                  = WIDGET_BUTTON(edit_menu,                      $
                                    value       = 'Undo'   ,                $
                                    Event_Pro   = 'eis_mk_raster_gui_EV',   $
                                    uValue      = UNDO_EVENT)

;UNDOCOUNT_EVENT             = {eis_mk_raster_gui_Event}
;UNDOCOUNT_EVENT.eis_mk_raster_gui = Self
;UNDOCOUNT_EVENT.Type        = "UNDOCOUNT"
;UNDOCOUNTbutton             = WIDGET_BUTTON(edit_menu,                      $
;                                    value       = 'UNDOCOUNT'   ,           $
;                                    Event_Pro   = 'eis_mk_raster_gui_EV',   $
;                                    uValue      = UNDOCOUNT_EVENT)

timeButtonId                = WIDGET_BUTTON(edit_menu ,                     $
                                    value       = 'Time format' ,           $
                                    /MENU)

THMS_EVENT                  = {eis_mk_raster_gui_Event}
THMS_EVENT.eis_mk_raster_gui = Self
THMS_EVENT.Type             = "SETTIMEUNIT"
THMS_EVENT.extra            = 0
THMSbutton                  = WIDGET_BUTTON(timeButtonId,                   $
                                    value       = 'h:m:s',                  $
                                    Event_Pro   = 'eis_mk_raster_gui_EV',   $
                                    uValue      = THMS_EVENT)

HOUR_EVENT                  = {eis_mk_raster_gui_Event}
HOUR_EVENT.eis_mk_raster_gui = Self
HOUR_EVENT.Type             = "SETTIMEUNIT"
HOUR_EVENT.extra            = 1
HOURbutton                  = WIDGET_BUTTON(timeButtonId,                   $
                                    value       = 'hours',                  $
                                    Event_Pro   = 'eis_mk_raster_gui_EV',   $
                                    uValue      = HOUR_EVENT)

MINS_EVENT                  = {eis_mk_raster_gui_Event}
MINS_EVENT.eis_mk_raster_gui = Self
MINS_EVENT.Type             = "SETTIMEUNIT"
MINS_EVENT.extra            = 2
MINSbutton                  = WIDGET_BUTTON(timeButtonId,                   $
                                    value       = 'minutes',                $
                                    Event_Pro   = 'eis_mk_raster_gui_EV',   $
                                    uValue      = MINS_EVENT)

SECS_EVENT                  = {eis_mk_raster_gui_Event}
SECS_EVENT.eis_mk_raster_gui = Self
SECS_EVENT.Type             = "SETTIMEUNIT"
SECS_EVENT.extra            = 3
SECSbutton                  = WIDGET_BUTTON(timeButtonId,                   $
                                    value       = 'seconds',                $
                                    Event_Pro   = 'eis_mk_raster_gui_EV',   $
                                    uValue      = SECS_EVENT)

;HELPRA_EVENT                = {eis_mk_raster_gui_Event}
;HELPRA_EVENT.eis_mk_raster_gui = Self
;HELPRA_EVENT.Type           = "HELPRASTER"
;HELPRAbutton                = WIDGET_BUTTON(edit_menu,                      $
;                                    value       = 'help,raster',            $
;                                    Event_Pro   = 'eis_mk_raster_gui_EV',   $
;                                    uValue      = HELPRA_EVENT)
;
;STOP_EVENT                  = {eis_mk_raster_gui_Event}
;STOP_EVENT.eis_mk_raster_gui = Self
;STOP_EVENT.Type             = "STOP"
;STOPbutton                  = WIDGET_BUTTON(edit_menu,                      $
;                                    value       = 'Stop'     ,              $
;                                    Event_Pro   = 'eis_mk_raster_gui_EV',   $
;                                    uValue      = STOP_EVENT)
;------------------------------------------------------------------------------;
;--------help menu list--------------------------------------------------------;
help_menu	            = WIDGET_BUTTON(bar,VALUE='Help',/MENU,/help)

HELP_EVENT                  = {eis_mk_raster_gui_Event}
HELP_EVENT.eis_mk_raster_gui    = Self
HELP_EVENT.Type             = "HELP"
HELPButton                  = WIDGET_BUTTON(help_menu,                      $
                                    value       = 'Help...',                $
                                    Event_Pro   = 'eis_mk_raster_gui_EV',   $
                                    uValue      = HELP_EVENT)

;ABOUT_EVENT                 = {eis_mk_raster_gui_Event}
;ABOUT_EVENT.eis_mk_raster_gui   = Self
;ABOUT_EVENT.Type            = "ABOUT"
;ABOUTButton                 = WIDGET_BUTTON(help_menu,                      $
;                                    value       = 'About...',               $
;                                    Event_Pro   = 'eis_mk_raster_gui_EV',   $
;                                    uValue      = ABOUT_EVENT)

VERS_EVENT                  = {eis_mk_raster_gui_Event}
VERS_EVENT.eis_mk_raster_gui    = Self
VERS_EVENT.Type             = "VERS"
VERSButton                  = WIDGET_BUTTON(help_menu,                      $
                                    value       = 'Version...',             $
                                    Event_Pro   = 'eis_mk_raster_gui_EV',   $
                                    uValue      = VERS_EVENT)

; Call widget creation procedure
eis_mk_raster_widgets , Self

; OK, create IDL_CONTAINER - rasterUndo will contain all the undo actions
Self.rasterUndo = OBJ_NEW("IDL_Container")

RETURN, 1

END
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_mk_raster_gui_Cleanup , wid

WIDGET_CONTROL , wid , get_uvalue = eis_mk_raster_gui_Event
OBJ_DESTROY    , eis_mk_raster_gui_Event.eis_mk_raster_gui

;print,"cleaning up...here's what's left over..."
;print,"****************************************"
;print,"****************************************"
;help,/heap
;print,"****************************************"
;print,"****************************************"

END
;______________________________________________________________________________
; Cleanup
;______________________________________________________________________________
PRO eis_mk_raster_gui::CleanUp

; Free up plot object
IF (OBJ_VALID(Self.o_eis_plot) EQ 1) THEN BEGIN
    OBJ_DESTROY , Self.o_eis_plot
ENDIF

OBJ_DESTROY , Self.o_def_ct
OBJ_DESTROY , Self.eis_ll_obj
; Free up raster UNDO objects
undoArray = Self.rasterUndo->get(/ALL)
OBJ_DESTROY , undoArray
; And finally the IDL_Container object
OBJ_DESTROY , Self.rasterUndo

END
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_mk_raster_gui::setProperty, $
            eis_mk_raster_widgets = eis_mk_raster_widgets ,                 $
            dataWindows = dataWindows ,                                     $
            eis_raster = eis_raster

IF (N_ELEMENTS(eis_raster) GT 0) THEN BEGIN
    Self.eis_raster    = eis_raster
    ; Save a copy of the current eis_raster & line list
    ; Retrieve current Line List
    Self.eis_ll_obj->getProperty , ll = ll
    oRasterItem = OBJ_NEW("eis_raster_undo" , Self.eis_raster , ll)
    Self.rasterUndo->ADD , oRasterItem
ENDIF

IF (N_ELEMENTS(eis_mk_raster_widgets) GT 0) THEN BEGIN
    Self.eis_mk_raster_widgets    = eis_mk_raster_widgets
ENDIF

IF (N_ELEMENTS(dataWindows) GT 0) THEN BEGIN
    Self.eis_raster.dataWindows = dataWindows
ENDIF

End
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_mk_raster_gui::GetProperty, tlbID        = tlbID             ,	 $
                                    eis_raster   = eis_raster            ,  $
                                    eis_ll_obj   = eis_ll_obj           ,  $
                           eis_mk_raster_widgets = eis_mk_raster_widgets ,  $
                                    o_def_ct     = o_def_ct

tlbID                     = Self.tlbID
eis_raster                = Self.eis_raster
eis_ll_obj                = Self.eis_ll_obj
eis_mk_raster_widgets     = Self.eis_mk_raster_widgets
o_def_ct                  = Self.o_def_ct

End
;______________________________________________________________________________
; Return widget id
;______________________________________________________________________________
Function eis_mk_raster_gui::tlbID

    Return, Self.tlbID
End

;______________________________________________________________________________
; Widget_Control wrapper
;______________________________________________________________________________
PRO eis_mk_raster_gui::Control, _Ref_Extra=Widget_Control_Keywords

Widget_Control, Self.tlbID, _Extra=Widget_Control_Keywords

End

;______________________________________________________________________________
; Widget_Info wrapper
;______________________________________________________________________________
Function eis_mk_raster_gui::Info, _Ref_Extra=Widget_Info_Keywords

Return, Widget_Info(Self.tlbID, _Extra=Widget_Info_Keywords)

End

;______________________________________________________________________________
; Realize wrapper
;______________________________________________________________________________
PRO eis_mk_raster_gui::Realize

Widget_Control, Self.tlbID, /Realize

End

;______________________________________________________________________________
; XManager wrapper
;______________________________________________________________________________
PRO eis_mk_raster_gui::XManager,group=group

    XManager,"eis_mk_raster_gui" ,   Self.tlbID ,                         $
                     Event_Handler  = "eis_mk_raster_gui_EV",  $
        cleanup        = "eis_mk_raster_gui_Cleanup",                           $
        GROUP_LEADER   = group ,                                            $
        /NO_BLOCK

end

;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_mk_raster_gui_Event__Define

    struct = {  eis_mk_raster_gui_Event,                                    $
                Type                : "",                                   $
                eis_mk_raster_gui   : OBJ_NEW(),                            $
                extra               : 0                                     $
             }
END
;______________________________________________________________________________
; Event Handler wrapper
;______________________________________________________________________________
PRO eis_mk_raster_gui_EV , Event

;Get event handler structure containing eis_mk_raster_gui type object
Widget_CONTROL,Event.ID,get_uvalue = eis_mk_raster_gui_Event
;If a WIDGET_TAB event , just quit
IF (TAG_NAMES(event, /STRUCTURE_NAME) EQ 'WIDGET_TAB') THEN BEGIN
    ;print,'tab event'
    RETURN
ENDIF

;Call eis_mk_raster_gui's class member procedure "Handler"
eis_mk_raster_gui_Event.eis_mk_raster_gui->Handler,Event

END
;______________________________________________________________________________
; Event Handler wrapper
;______________________________________________________________________________
PRO eis_mk_raster_gui_update_EV , Event

;Get event handler structure containing eis_mk_raster_gui type object
Widget_CONTROL,Event.ID,get_uvalue = eis_mk_raster_gui_Event
;If a WIDGET_TAB event , just quit
IF (TAG_NAMES(event, /STRUCTURE_NAME) EQ 'WIDGET_TAB') THEN BEGIN
    ;print,'tab event'
    RETURN
ENDIF

;Call eis_mk_raster_gui's class member procedure "Handler"
eis_mk_raster_gui_Event.eis_mk_raster_gui->HandlerUpdate,Event

END
;______________________________________________________________________________
PRO eis_mk_raster_gui::HandlerUpdate, Event

valid = 0

;IF (TAG_NAMES(event, /STRUCTURE_NAME) EQ 'WIDGET_SLIDER') THEN BEGIN
;
;    stop
;    IF (event.drag EQ 1) THEN RETURN
;ENDIF

WIDGET_CONTROL, Event.ID, Get_UValue = eis_mk_raster_gui_Event
type = eis_mk_raster_gui_Event.Type
CASE type OF
    "SLITSLOT"          : valid = Self->rasterSlitSlot(event)
    "LL_CORELINES"      : valid = Self->defaultCoreLines()
    "LL_DELETE"         : valid = Self->deleteLine()
    "HEIGHT"            : valid = Self->rasterHeight(event.drag)
    "WIDTH"             : valid = Self->rasterDefaultWidth(event.drag)
    "DEFAULTWIDTH"      : valid = Self->setAllLinesToDefaultWidth()
    "RATYPESCAN"        : valid = Self->rasterTypeScanning()
    "RATYPESTARE"       : valid = Self->rasterTypeSitAndStare()
    "NUM_FM_STEPS"      : valid = Self->rasterNumMirrorSteps()
    "FM_STEP_SIZE"      : valid = Self->rasterFineMirrorStepSize()
    "NEXP"              : valid = Self->rasterNumExposuresPerStep(event.index)
    "SNS_NEXPS"         : valid = Self->rasterSNSNumExposures()
    "SNS_DURATION"      : valid = Self->rasterSNSDuration()
    "RA_IMPORT"         : valid = Self->importRaster()
    "LL_IMPORT"         : valid = Self->importLineList()
    "LINEWIDTH"         : valid = Self->selectedLineWidth(event)
    "p0"                : valid = Self->p0()
    "w0"                : valid = Self->w0()
    "FULLQUADRANT"      : valid = Self->fullQuadrant()
    "COMP"              : valid = Self->compression()
    ELSE                : print,'update - '+eis_mk_raster_gui_Event.Type
ENDCASE

IF (valid EQ 1) THEN Self->eis_raster_update

END
;______________________________________________________________________________
PRO eis_mk_raster_gui::eis_raster_update

; Update SNS Duration
Self->updateSNSDuration
; Get Duration and Volume
Self->updateDurationAndVolume
; Update line list
Self->updateLineListWidget
; Generate and update title
Self->updateRasterTitle
; Finally, save a copy of the current eis_raster & line list
; Retrieve current Line LIst
Self.eis_ll_obj->getProperty , ll = ll
oRasterItem = OBJ_NEW("eis_raster_undo" , Self.eis_raster , ll)
Self.rasterUndo->ADD , oRasterItem

END
;______________________________________________________________________________
;
; * THIS is the routine for putting in event handling NOT eis_mk_raster_gui_Ev above.
;
; Event Handler - handle events.  Derived classes must
; contain their own implementation in order to handle events or else pass in an
; procedure name/function name using the Event_Pro/Event_Func keywords to
; CWidget::Init()
;______________________________________________________________________________
PRO eis_mk_raster_gui::Handler, Event

; Get widget IDs
widIDs = Self.eis_mk_raster_widgets

WIDGET_CONTROL, Event.ID, Get_UValue = eis_mk_raster_gui_Event
CASE eis_mk_raster_gui_Event.Type OF
    "QUIT"          : Self->Control, /Destroy
    "TLB"           :
    "SETTIMEUNIT"   : Self->setTimeUnits,eis_mk_raster_gui_Event.extra
    "VIEWRASTER"    : Self->viewRasterDetails
    "UNDO"          : Self->rasterUndo
    "PLOTSPECTRUM"  : Self->plotSpectrumGUI
    "RASAVEDB"      : Self->saveRasterToDatabase
    "RASTERLIST"    : Self->rasterLineListEvent , event
    "SETEXPOSURES"  : Self->rasterExposureTimes
    "LL_ADDNEWLINE" : Self->create_eis_lines_gui
    "LL_DBSAVE"     : Self->saveLineListToDatabase
    "RA_EXPORT"     : Self->exportRasterGUI
    "LL_EXPORT"     : Self->exportLineListGUI
    "DURATIONUNIT"  : Self->updateDurationAndVolume
    "VOLUMEUNIT"    : Self->updateDurationAndVolume
    "IMAGE"         : Self->initializePlot , eis_mk_raster_gui_Event.extra
    "DRAW"          : Self->drawEvents, event
    "IMAGE_CT"      : Self->update_colour_table , event.index
    "RASEARCHDB"    : eis_xraster    , parentClass = Self
    "LL_DB"         : eis_xlinelist  , parentClass = Self
    "LINE_NAME"     : Self->invoke_line_name_gui
    "LL_CUSTOM_NAME": Self->invoke_line_name_custom_gui
    ;
    ; Some useful (but temporary things)
    ;
;    "HELPRASTER"    : help,Self.eis_raster,/str
;    "UNDOCOUNT"     : help,Self.rasterUndo->count()
;    "STOP"          : stop
    "HELP"          : Self->displayHelp
;    "ABOUT"         : print,'about'
    "VERS"          : Self->version
    ELSE            : print,eis_mk_raster_gui_Event.Type
ENDCASE

END
;______________________________________________________________________________
; Update Line Name
;______________________________________________________________________________
PRO eis_mk_raster_gui::version

fileName = concat_dir(GETENV('ancillary') , 'eis_mk_raster_version.txt')
; Make sure the file is actually there
valid    = FILE_TEST(fileName)
IF (valid NE 1) THEN BEGIN
    print,"No version file found!"
    RETURN
ENDIF

; OK, read file
mText = rd_ascii(fileName)
; Display file contents in popup window
xpopup , mText , group = Self.tlbID , ySize = 10 ,  xSize = 40 ,            $
                                 title = "EIS_MK_RASTER Verion"

END
;______________________________________________________________________________
; Update Line Name
;______________________________________________________________________________
PRO eis_mk_raster_gui::invoke_line_name_custom_gui

; Get widget IDs
widIDs = Self.eis_mk_raster_widgets

; Ensure a line is selected
index = WIDGET_INFO(widIDs.ra_listID , /LIST_SELECT)
IF (index EQ -1) THEN BEGIN
    mText    = 'No line selected. Aborting.'
    complain = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF
; Retrive Line List
Self.eis_ll_obj->getProperty , ll = ll

; If a core line is selected, then bail out
core_lines_list  = [19282 , 19512 , 25632]
core_lines_index = WHERE(ll.lines[index].wavelength EQ core_lines_list)
IF (core_lines_index[0] NE -1) THEN BEGIN

    mText    = "Cannot modify a core line's name. Aborting."
    complain = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN

ENDIF

line_name = ll.lines[index].name

o_eis_line_name = OBJ_NEW("eis_line_name_custom_gui" , Self , line_name)
o_eis_line_name->Realize
o_eis_line_name->XMANAGER

END
;______________________________________________________________________________
; Kill eis_xRaster
;______________________________________________________________________________
PRO eis_mk_raster_gui::kill_xraster , xraster_obj

xraster_obj->Control, /Destroy

END
;______________________________________________________________________________
; Kill eis_xLinelist
;______________________________________________________________________________
PRO eis_mk_raster_gui::kill_xlinelist , xlinelist_obj

xlinelist_obj->Control, /Destroy

END
;______________________________________________________________________________
; Update Line Name
;______________________________________________________________________________
PRO eis_mk_raster_gui::invoke_line_name_gui

; Get widget IDs
widIDs = Self.eis_mk_raster_widgets

; Ensure a line is selected
index = WIDGET_INFO(widIDs.ra_listID , /LIST_SELECT)
IF (index EQ -1) THEN BEGIN
    mText    = 'No line selected. Aborting.'
    complain = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF
; Retrive Line List
Self.eis_ll_obj->getProperty , ll = ll

line_name = ll.lines[index].name

o_eis_line_name = OBJ_NEW("eis_line_name_gui" , Self , line_name)
o_eis_line_name->Realize
o_eis_line_name->XMANAGER

END
;______________________________________________________________________________
; Update Line Name - this procedure is called by "eis_line_name_gui"
;______________________________________________________________________________
PRO eis_mk_raster_gui::update_line_name , line_name

; Get widget IDs
widIDs = Self.eis_mk_raster_widgets
; Retrive Line List
Self.eis_ll_obj->getProperty , ll = ll

; Ensure a line is selected
index = WIDGET_INFO(widIDs.ra_listID , /LIST_SELECT)
IF (index EQ -1) THEN BEGIN
    mText    = 'No line selected. Aborting.'
    complain = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF

; Update value
ll.lines[index].name = line_name
; Update new values
Self.eis_ll_obj->setProperty , ll = ll , dataWindows = Self.eis_raster.dataWindows

END
;______________________________________________________________________________
; Modify Line Name
;______________________________________________________________________________
PRO eis_mk_raster_gui::modifyLineName

; Get widget IDs
widIDs = Self.eis_mk_raster_widgets
; Retrive Line List
Self.eis_ll_obj->getProperty , ll = ll

; Ensure a line is selected
index = WIDGET_INFO(widIDs.ra_listID , /LIST_SELECT)
IF (index EQ -1) THEN BEGIN
    mText    = 'No line selected. Aborting.'
    complain = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF

; Get line properties
; Ensure we're NOT dealing with a core line here! - check type
type = ll.lines[index].type
IF (type EQ 0) THEN BEGIN
    mText    = "This is a core line. Are you sure you want to modify it?"
    question = DIALOG_MESSAGE(mText , /QUESTION , DIALOG_PARENT = Self.tlbID)
    IF (question NE 'Yes') THEN RETURN
ENDIF

stop
;; Get name from text widget - replace spaces with underscores
;WIDGET_CONTROL , widIDs.ra_customTextID , get_value = widValue
;split = STRSPLIT(widValue , /EXTRACT)
;new_name = STRJOIN(split , '_' , /SINGLE)
;
;; Maximum of 6 characters
;IF (STRLEN(new_name) GT 8) THEN new_name = STRMID(new_name , 0 , 8)

; Update value
ll.lines[index].name = new_name + ' 0'
; Update new values
Self.eis_ll_obj->setProperty , ll = ll , dataWindows = Self.eis_raster.dataWindows

END
;______________________________________________________________________________
; Draw Area Events
;______________________________________________________________________________
PRO eis_mk_raster_gui::update_colour_table , index

Self.colour_table = index
Self->initializePlot , Self.spectrum_index

END
;______________________________________________________________________________
; Draw Area Events
;______________________________________________________________________________
PRO eis_mk_raster_gui::drawEvents, event

; Convert wavelengths to pixels
xScale = Self.xySize[0] / 2048.
yScale = Self.xySize[1] / 1024.

; Make label - something like "CCD2: 264.37 �(pixel 828)"
; Or                          "CCD1: 189.12 �(pixel 1022)"

; Get pixel value
x_pixel = STRCOMPRESS(ROUND(event.x/xScale),/REMOVE_ALL)
; Get ccd value (1 or 2)
IF (event.y LT Self.xySize[1]/2.) THEN ccd = 2 ELSE ccd = 1
; Get wavelngth value - format it and add Angstrom sign
;
; PRY, 31/1/2007
; I've added the slit index as an additional input to
; eis_pixel_to_wavelength.
;
;x_wave        = eis_pixel_to_wavelength(x_pixel,ccd)
x_wave        = eis_pixel_to_wavelength(x_pixel,ccd,Self.eis_raster.slitindex)
x_wave_string = STRING(format='(F-7.2)',x_wave)+ STRING("305B)
; Join them all up
info = STRJOIN(['CCD' , STRCOMPRESS(ccd,/REMOVE_ALL), ', ' ,                $
                x_wave_string , ' (pixel ' ,x_pixel, ')'],/SINGLE)
; Finally, update the widget
WIDGET_CONTROL , Self.eis_mk_raster_widgets.ra_cursor_posID , set_value = info

END
;______________________________________________________________________________
; Full quadrant
;______________________________________________________________________________
FUNCTION eis_mk_raster_gui::fullQuadrant

; Get widget IDs
widIDs = Self.eis_mk_raster_widgets
index = WIDGET_INFO(widIDs.ra_listID , /LIST_SELECT)
; Retrieve ll
Self.eis_ll_obj->getProperty , ll = ll

;; Check there aren't any other lines/windows in this quadrant
quad = ll.lines[index].quad
;indicies = WHERE(ll.lines[*].quad EQ quad)
;IF (N_ELEMENTS(indicies) NE 1) THEN BEGIN
;    BEEP
;    mText = 'Remove other lines from this quadrant first. Aborting!'
;    doh   = DIALOG_MESSAGE( mText ,                                         $
;                     DIALOG_PARENT = Self.tlbID,                            $
;                     /ERROR )
;    RETURN
;ENDIF

; Change p0 to quadrant central pixel (ie; 512 or 1536)
; Calculate wavelength
; Change dataWindow to 1024
Self.eis_raster.dataWindows[index]    = 1024
ccd  = ll.lines[index].ccd

IF (ccd EQ 1) AND (quad EQ 0) THEN p0 = 512
IF (ccd EQ 1) AND (quad EQ 1) THEN p0 = 512 + 1024
IF (ccd EQ 2) AND (quad EQ 2) THEN p0 = 512
IF (ccd EQ 2) AND (quad EQ 3) THEN p0 = 512 + 1024

ll.lines[index].p0 = p0
ll.lines[index].type = 2

; Convert new p0 to wavelength
; PRY, 1/2/2007, added slitindex input
;
newWave = eis_pixel_to_wavelength(p0,ll.lines[index].ccd, $
                                  Self.eis_raster.slitindex)
ll.lines[index].wavelength = ROUND(newWave*100)

; OK, de-sensitize "Selected Line" pane
Self->updateSelectedLineWidgets , -1 ;index
WIDGET_CONTROL , widIDs.ra_listID , set_list_select = -1

; Update new values
Self.eis_ll_obj->setProperty , ll = ll , dataWindows = Self.eis_raster.dataWindows

RETURN , 1

END
;______________________________________________________________________________
; W0
;______________________________________________________________________________
FUNCTION eis_mk_raster_gui::w0

; Get widget IDs
widIDs = Self.eis_mk_raster_widgets
WIDGET_CONTROL , widIDs.ra_w0ID , get_value = widValue
index = WIDGET_INFO(widIDs.ra_listID , /LIST_SELECT)
; Retrieve ll
Self.eis_ll_obj->getProperty , ll = ll

; Get new value from widget
CASE ll.lines[index].ccd OF
    1   :   minVals = [eis_pixel_to_wavelength(0   ,1)   ,                  $
                       eis_pixel_to_wavelength(2047,1)]
    2   :   minVals = [eis_pixel_to_wavelength(0   ,0)   ,                  $
                       eis_pixel_to_wavelength(2047,0)]
    ELSE:   stop
ENDCASE

; arguments-> name , newValue , oldValue , minValue , maxValue , multiple
valid  = eis_validate_input('Cental Wavelength' , widValue[0] ,             $
                              ll.lines[index].p0 , minVals[0] , minVals[1])

CASE valid.valid OF
    0:  BEGIN
            newValue = ll.lines[index].wavelength
            BEEP
            ccdString   = STRCOMPRESS(FIX(ll.lines[index].ccd),/REMOVE_ALL)
            valid.mText = 'Wavelngth value must be in the range: '    +     $
                          STRING(format='(F6.2)',minVals[0]) + ' to ' +     $
                          STRING(format='(F6.2)',minVals[1])          +     $
                          STRING("305B) + ' for CCD ' + ccdString + '. Aborting!'

            complain = DIALOG_MESSAGE( valid.mText ,                        $
                                 DIALOG_PARENT = Self.tlbID,                $
                                 /ERROR )
        END
    1:  newValue = ROUND(FLOAT(widValue[0])*100.)
ENDCASE

; Update new central wavelength value
ll.lines[index].wavelength = newValue

; Update new values
Self.eis_ll_obj->setProperty , ll = ll

; OK, de-sensitize "Selected Line" pane
Self->updateSelectedLineWidgets , index

RETURN , valid.valid

END
;______________________________________________________________________________
; P0
;______________________________________________________________________________
FUNCTION eis_mk_raster_gui::p0

; Get widget IDs
widIDs = Self.eis_mk_raster_widgets
index = WIDGET_INFO(widIDs.ra_listID , /LIST_SELECT)
; Retrieve ll
Self.eis_ll_obj->getProperty , ll = ll

; Get new value from widget
WIDGET_CONTROL , widIDs.ra_p0ID , get_value = widValue
; arguments-> name , newValue , oldValue , minValue , maxValue , multiple
valid  = eis_validate_input('Central Pixel' , widValue[0] ,                 $
                              ll.lines[index].p0 , 0 , 2047)

width = Self.eis_raster.dataWindows[index]

IF (widValue[0] - width/2. LT 0) THEN BEGIN
    valid.valid = 0
    valid.mText = "This is out of range for CCD2"
ENDIF

CASE valid.valid OF
    0:  BEGIN
            newValue = ll.lines[index].p0
            BEEP
            complain = DIALOG_MESSAGE( valid.mText ,                        $
                                 DIALOG_PARENT = Self.tlbID,                $
                                 /ERROR )
        END
    1:  newValue = LONG(widValue[0])
ENDCASE

; Convert p0 to wavelength
; PRY, 1/2/2007, added slitindex input
;
newWave = eis_pixel_to_wavelength(newValue,ll.lines[index].ccd, $
                                  Self.eis_raster.slitindex)
;
;; Is this a project line?
;project_line = eis_is_a_project_line(ROUND(newWave*100))
;IF (project_line EQ 1) THEN BEGIN
;
;    stop
;
;ENDIF ELSE BEGIN
    ; Update value
    ll.lines[index].p0 = newValue
    ll.lines[index].wavelength = ROUND(newWave*100)
;ENDELSE

; OK, de-sensitize "Selected Line" pane
WIDGET_CONTROL , widIDs.ra_listID , set_list_select = -1
Self->updateSelectedLineWidgets , -1 ;index

; Update new values
Self.eis_ll_obj->setProperty , ll = ll

RETURN , valid.valid

END
;______________________________________________________________________________
; Modify line name
;______________________________________________________________________________
FUNCTION eis_mk_raster_gui::selectedLineWidth , event

index = WIDGET_INFO(Self.eis_mk_raster_widgets.ra_listID , /LIST_SELECT)
IF (index EQ -1) THEN BEGIN
    mText    = 'No line selected. Aborting.'
    complain = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN , 0
ENDIF

; Retrive Line List
Self.eis_ll_obj->getProperty , ll = ll

; CCD1: Check p0 minimum GE 0
p0 = ll.lines[index].p0

IF (p0 - (event.value * 8)/2. LT 0) THEN BEGIN

    newValue = p0
    mText    = 'Width too big!'
    BEEP
    complain = DIALOG_MESSAGE( mText ,                                      $
                                 DIALOG_PARENT = Self.tlbID,                $
                                 /ERROR )
ENDIF ELSE BEGIN
    newValue = event.value * 8
ENDELSE

Self.eis_raster.dataWindows[index] = newValue

; Update dataWindows and refesh
Self.eis_ll_obj->setProperty , ll = ll , dataWindows = Self.eis_raster.dataWindows

Self->updateSelectedLineWidgets , index

; Return 0 if dragging, and 1 if not
RETURN , 1 - event.drag

END
;______________________________________________________________________________
; Save Line List to an ASCII file
;______________________________________________________________________________
PRO eis_mk_raster_gui::exportLineListGUI

o_eis_export_gui = OBJ_NEW("eis_export_gui" , Self , /LL)
o_eis_export_gui->Realize
o_eis_export_gui->XMANAGER

END
;______________________________________________________________________________
; Export LineList
;______________________________________________________________________________
PRO eis_mk_raster_gui::export_ll , acronym , author , st_info = st_info

; Retrieve Line List
Self.eis_ll_obj->getProperty , ll = ll
ll.acronym = acronym
ll.author  = author

; Get fileName
fileName = eis_export_filename_generate(acronym , Self.tlbID)
IF (fileName[0] EQ '') THEN RETURN
; Get
ll_array = eis_get_string_linelist(ll)
; OK, open file and write to it
OPENW  , lun , fileName , /GET_LUN
PRINTF , lun , ll_array
CLOSE  , lun

END
;______________________________________________________________________________
; Export Raster
;______________________________________________________________________________
PRO eis_mk_raster_gui::export_ra , acronym , author , st_info = st_info

ra         = Self.eis_raster
ra.acronym = acronym
ra.author  = author

; Get fileName
fileName = eis_export_filename_generate(acronym , Self.tlbID)
IF (fileName[0] EQ '') THEN RETURN

; Retrieve Line List - and calculate Raster duration
Self.eis_ll_obj->getProperty , ll = ll
ra.duration = LONG(eis_raster_duration(ra , ll))

; Get raster strings
ra_array = eis_get_string_raster(ra)
; Get linelist strings
ll_array = eis_get_string_linelist(ll)
; OK, open file and write to it
OPENW  , lun , fileName , /GET_LUN
PRINTF , lun , ra_array
PRINTF , lun , ll_array
CLOSE  , lun

END
;______________________________________________________________________________
; Save the line list to the database
;______________________________________________________________________________
PRO eis_mk_raster_gui::saveLineListToDatabase

; Retrieve Line List
Self.eis_ll_obj->getProperty , ll = ll

IF (ll.nLines EQ 0) THEN BEGIN
    mText    = "One or more lines must be selected - Dummy. Aborting !"
    complain = DIALOG_MESSAGE( mText , DIALOG_PARENT = Self.tlbID, /ERROR)
    RETURN
ENDIF

o_eis_ll_db_update = OBJ_NEW("eis_db_save_gui" , Self , /LL)
o_eis_ll_db_update->Realize
o_eis_ll_db_update->XMANAGER

END
;______________________________________________________________________________
; Delete line from Line List
;______________________________________________________________________________
FUNCTION eis_mk_raster_gui::deleteLine

index = WIDGET_INFO(Self.eis_mk_raster_widgets.ra_listID , /LIST_SELECT)
; Retrieve Line List
Self.eis_ll_obj->getProperty , ll = ll

IF (index EQ -1) THEN BEGIN
    mText    = 'No line selected - dummy! Aborting.'
    complain = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN , 0
ENDIF

IF (ll.nlines EQ 0) THEN BEGIN
    mText    = 'No lines to remove - dummy! Aborting.'
    complain = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN , 0
ENDIF

; Ensure we're NOT dealing with a core line here! - check type
IF (ll.lines[index].type EQ 0) THEN BEGIN
    mText    = "Are you sure you want to remove this core line?"
    question = DIALOG_MESSAGE(mText , /QUESTION , DIALOG_PARENT = Self.tlbID)
    IF (question NE 'Yes') THEN RETURN , 0
ENDIF

; Call eis_ll_obj method to remove the selected line
Self.eis_ll_obj->deleteLine , index

; Update spectrum plot - if it's up
IF (OBJ_VALID(Self.o_eis_plot) EQ 1) THEN Self.o_eis_plot->plotSpectrum

RETURN , 1

END
;______________________________________________________________________________
; Create default line list - 3 core lines
;______________________________________________________________________________
FUNCTION eis_mk_raster_gui::defaultCoreLines

; Read line list entry from database
Self->loadLineList , 1
; Update title widget
Self->updateLineListWidget

RETURN , 0

END
;______________________________________________________________________________
; Create create/modify line GUI
;______________________________________________________________________________
PRO eis_mk_raster_gui::addLine , line

; Call addLine method in eis_ll_obj
Self.eis_ll_obj->addLine , line , Self.eis_raster.windWidth
; OK, update stuff
Self.eis_ll_obj->getProperty , ll = ll , dataWindows = dataWindows
Self.eis_raster.nWindows    = ll.nLines
; Now that we've updated nWindows, refresh line list
Self.eis_ll_obj->refreshLineList
; Finally, add eis_raster to UNDO container
oRasterItem     = OBJ_NEW("eis_raster_undo" , Self.eis_raster , ll)
Self.rasterUndo->ADD , oRasterItem

END
;______________________________________________________________________________
; Create create/modify line GUI
;______________________________________________________________________________
PRO eis_mk_raster_gui::create_eis_lines_gui

o_eis_lines = OBJ_NEW("eis_lines_gui" , Self )
o_eis_lines->Realize
o_eis_lines->XMANAGER

END
;______________________________________________________________________________
; Display Help
;______________________________________________________________________________
PRO eis_mk_raster_gui::displayHelp

; Get eis_fonts
fonts = eis_fonts()

help_path = GETENV('EIS_PLAN_HELP')
help_file = CONCAT_DIR(help_path , 'eis_mk_raster_help.hlp')

widg_help , help_file , group_leader = Self.tlbID , font = fonts.mono

END
;______________________________________________________________________________
; View Raster Details
;______________________________________________________________________________
PRO eis_mk_raster_gui::updateSelectedLineWidgets , index

; Get widget IDs
widIDs = Self.eis_mk_raster_widgets

IF (index EQ -1) THEN BEGIN
    WIDGET_CONTROL , widIDs.ra_listID , set_list_select = -1
    WIDGET_CONTROL , widIDs.ra_ll_lineBaseID , sensitive = 0
    RETURN
ENDIF

; Retrieve Line List
Self.eis_ll_obj->getProperty , ll = ll

; Update selected line properties widgets
p0 = ll.lines[index].p0
p1 = ll.lines[index].p1
p2 = ll.lines[index].p2
WIDGET_CONTROL , widIDs.ra_p0ID , set_value = STRCOMPRESS(p0,/REMOVE_ALL)
WIDGET_CONTROL , widIDs.ra_p1ID , set_value = STRCOMPRESS(p1,/REMOVE_ALL)
WIDGET_CONTROL , widIDs.ra_p2ID , set_value = STRCOMPRESS(p2,/REMOVE_ALL)
; And wavelength
w0 = STRING(format='(F6.2)', ll.lines[index].wavelength / 100.)
w1 = STRING(format='(F6.2)', ll.lines[index].w1         / 100.)
w2 = STRING(format='(F6.2)', ll.lines[index].w2         / 100.)
WIDGET_CONTROL , widIDs.ra_w0ID , set_value = w0
WIDGET_CONTROL , widIDs.ra_w1ID , set_value = w1
WIDGET_CONTROL , widIDs.ra_w2ID , set_value = w2

; Now get window width
width       = Self.eis_raster.dataWindows[index]
widthString = STRCOMPRESS( width , /REMOVE_ALL)
WIDGET_CONTROL , widIDs.ra_sliderID , set_value = width / 8
; Update slider value
WIDGET_CONTROL , widIDs.ra_lineWidthID , set_value = widthString

; Update Line Name
line_name = ll.lines[index].name
WIDGET_CONTROL , widIDs.ra_lineNameLabelID , set_value = line_name

END
;______________________________________________________________________________
; View Raster Details
;______________________________________________________________________________
PRO eis_mk_raster_gui::rasterLineListEvent , event

; Retrieve Line List
Self.eis_ll_obj->getProperty , ll = ll

; Bail out if there are no lines
IF (ll.nLines EQ 0) THEN RETURN

; Get widget IDs
widIDs = Self.eis_mk_raster_widgets
index  = WIDGET_INFO(widIDs.ra_listID , /LIST_SELECT)

; If a core line is selected, then de-sensitize name text widget
core_lines_list  = [19282 , 19512 , 25632]
core_lines_index = WHERE(ll.lines[index].wavelength EQ core_lines_list)
IF (core_lines_index[0] EQ -1) THEN BEGIN

    ; Pixel and Wavelength text boxes
    WIDGET_CONTROL , widIDs.ra_p0ID , sensitive = 1
    WIDGET_CONTROL , widIDs.ra_w0ID , sensitive = 1
    WIDGET_CONTROL , widIDs.ra_lineNameButtID , sensitive = 1

ENDIF ELSE BEGIN

    ; Pixel and Wavelength text boxes
    WIDGET_CONTROL , widIDs.ra_p0ID , sensitive = 0
    WIDGET_CONTROL , widIDs.ra_w0ID , sensitive = 0
    WIDGET_CONTROL , widIDs.ra_lineNameButtID , sensitive = 0

ENDELSE

IF (index EQ -1) THEN RETURN

; Trap CONTEXT events here
widgetType = TAG_NAMES(event, /STRUCTURE_NAME)
IF (widgetType NE 'WIDGET_CONTEXT') THEN BEGIN
    ; Update lines/windows plot
    Self->updatePlot
    Self->updateSelectedLineWidgets , index
    WIDGET_CONTROL , widIDs.ra_ll_lineBaseID , sensitive = 1
    RETURN
END

; OK, we have a context-sensitive click event!
contextbase                 = WIDGET_BASE(widIDs.ra_ListID ,                $
                                    /CONTEXT_MENU)
;
; Modify Line Width
;
LL_DEL_EVENT                = {eis_mk_raster_gui_Event}
LL_DEL_EVENT.eis_mk_raster_gui  = Self
LL_DEL_EVENT.Type           = "LL_DELETE"
value = "Remove line"
Event_Pro_update = 'eis_mk_raster_gui_update_EV'
LL_DELButton                = WIDGET_BUTTON(contextbase   ,                 $
                                    value       = value      ,              $
                                    Event_Pro   = Event_Pro_update  ,       $
                                    uValue      = LL_DEL_EVENT )

widget_displaycontextmenu, event.id, event.x, event.y, contextbase

END
;______________________________________________________________________________
; View Raster Details
;______________________________________________________________________________
PRO eis_mk_raster_gui::viewRasterDetails

; Retrieve Line List
Self.eis_ll_obj->getProperty , ll = ll
o_rasterDetails = OBJ_NEW("eis_raster_details_gui" , Self.eis_raster ,      $
                                                     ll              ,      $
                                              group_leader = Self.tlbID)
o_rasterDetails->Realize
o_rasterDetails->XMANAGER

END
;______________________________________________________________________________
; Update Raster Title
;______________________________________________________________________________
PRO eis_mk_raster_gui::setTimeUnits , index

Self.timeUnits = index
; Get Duration and Volume
Self->updateDurationAndVolume

END
;______________________________________________________________________________
; Update Raster Title
;______________________________________________________________________________
PRO eis_mk_raster_gui::updateRasterTitle

Self.eis_raster.title = eis_generate_raster_title(Self.eis_raster)
; Generate and update title
widIDs = Self.eis_mk_raster_widgets
WIDGET_CONTROL , widIDs.ra_titleID , set_value = Self.eis_raster.title

END
;______________________________________________________________________________
; Undo previous change
;______________________________________________________________________________
PRO eis_mk_raster_gui::rasterUndo

numUndo = Self.rasterUndo->count()

IF (numUndo LT 2) THEN BEGIN
    BEEP
    complain = DIALOG_MESSAGE( 'Nothing to UNDO - stoopid!' ,               $
                                 DIALOG_PARENT = Self.tlbID,                $
                                 /ERROR )
    RETURN
ENDIF

; We want penultimate eis_raster
oRasterItem = Self.rasterUndo->get(POSITION = (numUndo - 2))
oRasterItem->getProperty , ra = ra , ll = ll
Self.eis_raster  = ra
; Finally, load the undid raster
Self.eis_ll_obj->setProperty , ll = ll , dataWindows = ra.dataWindows
Self->updateRasterWidgets

; Get widget IDs
widIDs = Self.eis_mk_raster_widgets
index  = WIDGET_INFO(widIDs.ra_listID , /LIST_SELECT)
; OK, de-sensitize "Selected Line" pane
Self->updateSelectedLineWidgets , -1

; OK, and kill the last UNDO raster
oRasterItemRemove = Self.rasterUndo->get(POSITION = (numUndo - 1))
Self.rasterUndo->remove , POSITION = numUndo - 1
OBJ_DESTROY , oRasterItemRemove

END
;______________________________________________________________________________
; Export a raster definition
;______________________________________________________________________________
PRO eis_mk_raster_gui::exportRasterGUI

o_eis_export_gui = OBJ_NEW("eis_export_gui" , Self , /RA)
o_eis_export_gui->Realize
o_eis_export_gui->XMANAGER

END
;______________________________________________________________________________
; Import a lineList definition
;______________________________________________________________________________
FUNCTION eis_mk_raster_gui::importLinelist

CASE !VERSION.OS_FAMILY of
    'Windows'   : path = GETENV('SystemDrive')
    'unix'      : path = GETENV('HOME')
    ELSE        : stop
ENDCASE

; Get fileName
fileName = DIALOG_PICKFILE(path              = path  ,                      $
                           dialog_parent     = Self.tlbID       ,           $
                           filter            = '*.def'          ,           $
                           /READ )

IF (fileName[0] EQ '') THEN BEGIN
    screwUp = DIALOG_MESSAGE("No valid filename selected. Aborting !" ,     $
                             dialog_parent  = Self.tlbID ,                  $
                             /ERROR)
    RETURN , 0
ENDIF

; Call function to read file
ll = eis_import_linelist(fileName)

; OK, ll = 0 is returned if failed
IF (N_TAGS(ll) EQ 0) THEN BEGIN
    BEEP
    mText = 'Invalid Line List definition file. Aborting!'
    d = DIALOG_MESSAGE(mText, /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN , 0
ENDIF

;
; Load Line List
;
Self.eis_raster.ll_id    = ll.id

; How many windows are defined in the raster
nWindows = Self.eis_raster.nWindows

; Get default width - set all widths to this value
dataWindows                           = INTARR(25) + Self.eis_raster.windWidth
dataWindows[ll.nLines : *           ] = 0
dataWindows[0         : nWindows - 1] = Self.eis_raster.dataWindows[0:nWindows - 1]

; Update nWindows to the new value (from lineList)
Self.eis_raster.nWindows = ll.nLines

; Update ll object
Self.eis_ll_obj->setProperty , ll = ll , dataWindows = dataWindows

; OK, de-sensitize "Selected Line" pane
WIDGET_CONTROL , Self.eis_mk_raster_widgets.ra_listID , set_list_select = -1
Self->updateSelectedLineWidgets , -1

RETURN , 1

END
;______________________________________________________________________________
; Import a raster definition
;______________________________________________________________________________
FUNCTION eis_mk_raster_gui::importRaster

CASE !VERSION.OS_FAMILY of
    'Windows'   : path = GETENV('SystemDrive')
    'unix'      : path = GETENV('HOME')
    ELSE        : stop
ENDCASE

; Get fileName
fileName = DIALOG_PICKFILE(path              = path  ,                      $
                           dialog_parent     = Self.tlbID       ,           $
                           filter            = '*.def'          ,           $
                           /READ )

IF (fileName[0] EQ '') THEN BEGIN
    screwUp = DIALOG_MESSAGE("No valid filename selected. Aborting !" ,     $
                             dialog_parent  = Self.tlbID ,                  $
                             /ERROR)
    RETURN , 0
ENDIF

; Call function to read file
ra_and_ll = eis_import_raster(fileName)
; OK, ll = 0 is returned if failed
IF (N_TAGS(ra_and_ll) EQ 0) THEN BEGIN
    BEEP
    mText = 'Invalid Raster definition file. Aborting!'
    d = DIALOG_MESSAGE(mText, /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN , 0
ENDIF

ll = ra_and_ll.ll

Self.eis_raster = ra_and_ll.ra

;
; Load Line List
;
; Update ll object
; Get default width - set all widths to this value
nWindows = Self.eis_raster.nWindows
dataWindows                           = INTARR(25) + Self.eis_raster.windWidth
dataWindows[ll.nLines : *           ] = 0
dataWindows[0         : nWindows - 1] = Self.eis_raster.dataWindows[0:nWindows - 1]
Self.eis_ll_obj->setProperty , ll          = ll     ,             $
                               dataWindows = Self.eis_raster.dataWindows

; How many windows are defined in the raster
nWindows = Self.eis_raster.nWindows

Self->updateRasterWidgets

; OK, de-sensitize "Selected Line" pane
WIDGET_CONTROL , Self.eis_mk_raster_widgets.ra_listID , set_list_select = -1
Self->updateSelectedLineWidgets , -1

RETURN , 1

END
;______________________________________________________________________________
; Select Sit'N'Stare Type Raster
;______________________________________________________________________________
FUNCTION eis_mk_raster_gui::rasterTypeSitAndStare

widIDs = Self.eis_mk_raster_widgets
WIDGET_CONTROL , widIDs.ra_typeScanBaseID , map = 0
WIDGET_CONTROL , widIDs.ra_typeSNSBaseID  , map = 1
Self.eis_raster.rasterType = 1

; Get Duration and Volume
Self->updateDurationAndVolume

; Update nExposures Label
nExpLabel = 'Number of exposures/set'
WIDGET_CONTROL , widIDs.ra_nExpLabelID    , set_value = nExpLabel

;; Update info Label
;scanInfoLabel = ''
;WIDGET_CONTROL , widIDs.ra_scanInfoLabelID , set_value = scanInfoLabel

; Update info Label
raster_width_label = eis_get_total_raster_width_string(Self.eis_raster ,    $
                                                       Self.tlbID)
WIDGET_CONTROL , widIDs.ra_scanInfoLabelID , set_value = raster_width_label

RETURN , 1

END
;______________________________________________________________________________
; Select Scanning Type Raster
;______________________________________________________________________________
FUNCTION eis_mk_raster_gui::rasterTypeScanning

widIDs = Self.eis_mk_raster_widgets
WIDGET_CONTROL , widIDs.ra_typeScanBaseID , map = 1
WIDGET_CONTROL , widIDs.ra_typeSNSBaseID  , map = 0
Self.eis_raster.rasterType = 0

; Get Duration and Volume
Self->updateDurationAndVolume

; Update nExposures Label
nExpLabel = 'Number of exposures/step'
WIDGET_CONTROL , widIDs.ra_nExpLabelID    , set_value = nExpLabel

;; Update info Label
;nExpString    = STRCOMPRESS(Self.eis_raster.scan_FM_nSteps+1,/REMOVE_ALL)
;scanInfoLabel = '(Number of exposures = ' + nExpString + ')'
;WIDGET_CONTROL , widIDs.ra_scanInfoLabelID , set_value = scanInfoLabel

; Update info Label
raster_width_label = eis_get_total_raster_width_string(Self.eis_raster ,    $
                                                       Self.tlbID)
WIDGET_CONTROL , widIDs.ra_scanInfoLabelID , set_value = raster_width_label

RETURN , 1

END
;______________________________________________________________________________
; Save Raster to Database
;______________________________________________________________________________
PRO eis_mk_raster_gui::saveRasterToDatabase

;
; Just a few checks first
;
; Retrieve Line List
Self.eis_ll_obj->getProperty , ll = ll

;
; JAR  7-March-2007
; Check whether the current linelist is already saved.
; If not, alert the user to save it before allowing them to save the raster
;
ll_title     = STRTRIM(ll.title,2)
unique_title = eis_title_unique(ll_title , ll.acronym , /LINELIST)
IF (unique_title.unique_title EQ 1) THEN BEGIN
    BEEP
    mText = ['This is a new linelist, and must be saved before saving ' +   $
            'the raster definition.', '','Select Linelist -> Save in '   +   $
             'database...','','Aborting!']
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF

;
; Check there are NO windows either overlapping or crossing central pixel
;
overlap = TOTAL(ll.lines[*].over)
IF (overlap NE 0) THEN BEGIN
    BEEP
    mText = 'There are overlapping windows. Aborting!'
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF
split = TOTAL(ll.lines[*].split)
IF (split NE 0) THEN BEGIN
    BEEP
    mText = 'One or more windows are split over the central pixel. Aborting!'
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF

; Check all p1's are >= 0
negative_p1 = WHERE(ll.lines[*].p1 LT 0. , p1_count)
IF (p1_count NE 0) THEN BEGIN
    BEEP
    mText = 'The LHS of a window falls off the CCD. Aborting!'
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF
; Check all p2's are =< 2047
negative_p2 = WHERE(ll.lines[*].p2 GT 2047. , p2_count)
IF (p2_count NE 0) THEN BEGIN
    BEEP
    mText = 'The RHS of a window falls off the CCD. Aborting!'
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF
;
; JAR 24-Feb-2007
; Check total spatial width of raster - if it exceeds EIS FOV, then bail out!
;
ra_width = eis_get_total_raster_width(Self.eis_raster)
CASE Self.eis_raster.slitIndex OF
    0: fov_width = 590.
    1: fov_width = 856.
    2: fov_width = 592.
    3: fov_width = 630.
ENDCASE
IF (ra_width GT fov_width) THEN BEGIN
    BEEP
    mText   = ['The total spatial width of this raster exceeds the EIS' +   $
               ' FOV width. Aborting!']
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF

;
; If linelist has ID = 0, then bail out
;
IF (ll.id EQ 0) THEN BEGIN
    BEEP
    mText = 'Line list is not saved. Aborting!'
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF

; Warn if any exposure Times are zero
nExp         = Self.eis_raster.nExp
expTime      = Self.eis_raster.exposures[0:nExp - 1]
zeroExpTimes = WHERE(expTime EQ 0.)
IF (zeroExpTimes[0] NE -1) THEN BEGIN
    BEEP
    mText = 'One or more exposure times are zero. Continue?'
    d = DIALOG_MESSAGE(mText,/QUESTION , DIALOG_PARENT = Self.tlbID)
    IF (d EQ 'No') THEN RETURN
ENDIF

; Check the Line List exists already.
;
; OK, Let's assume the LL is already saved
;
o_eis_ra_db_update = OBJ_NEW("eis_db_save_gui" , Self , /RA)
o_eis_ra_db_update->Realize
o_eis_ra_db_update->XMANAGER

END
;______________________________________________________________________________
; Set exposure times
;______________________________________________________________________________
PRO eis_mk_raster_gui::updateExposureTimes

widIDs = Self.eis_mk_raster_widgets
; Update exposure times label
expTimeValue = STRARR(Self.eis_raster.nExp)
FOR i = 0,Self.eis_raster.nExp -1 DO BEGIN

    expTime = Self.eis_raster.exposures[i]/1000.
    delTime = Self.eis_raster.delays[i]

    blah1 = STRCOMPRESS( STRING(format='(F-6.2)',expTime),/REMOVE_ALL)
    blah2 = STRCOMPRESS( STRING(format='(I-6)',delTime),/REMOVE_ALL)

    expTimeValue[i] = blah1 + '(' + blah2 + ')'

ENDFOR
WIDGET_CONTROL , widIDs.ra_expTimesID , set_value = STRJOIN(expTimeValue,',')

; Update SNS Duration
Self->updateSNSDuration
; Generate and update title
Self->updateRasterTitle
; Get Duration and Volume
Self->updateDurationAndVolume

END
;______________________________________________________________________________
; Set exposure times
;______________________________________________________________________________
PRO eis_mk_raster_gui::rasterExposureTimes

o_eis_exposure_times = OBJ_NEW("eis_exposure_times_gui" , Self)
o_eis_exposure_times->Realize
o_eis_exposure_times->XMANAGER

END
;______________________________________________________________________________
; Set slit/slot
;______________________________________________________________________________
FUNCTION eis_mk_raster_gui::rasterSlitSlot , event

IF (Self.eis_raster.slitIndex EQ event.index) THEN RETURN , 0
Self.eis_raster.slitIndex = FIX(event.index)

;
; PRY, 2-Feb-2007
;   enter slitindex into the EIS line list object
;
Self.eis_ll_obj->getProperty , ll = ll
ll.slitindex=FIX(event.index)
Self.eis_ll_obj->setProperty , ll = ll

CASE event.index OF
    0:  BEGIN
            Self.eis_raster.windwidth        = 32
            Self.eis_raster.scan_FM_stepSize = 1
        END
    1:  BEGIN
            Self.eis_raster.windwidth        = 272
            Self.eis_raster.scan_FM_stepSize = 264
        END
    2:  BEGIN
            Self.eis_raster.windwidth        = 32
            Self.eis_raster.scan_FM_stepSize = 2
        END
    3:  BEGIN
            Self.eis_raster.windwidth        = 48
            Self.eis_raster.scan_FM_stepSize = 40
        END
ENDCASE

widIDs   = Self.eis_mk_raster_widgets
newWidth = STRCOMPRESS(Self.eis_raster.windwidth,/REMOVE)
WIDGET_CONTROL , widIDs.ra_widthID , set_value = newWidth

; Update Step Size
newSSize = STRCOMPRESS(Self.eis_raster.scan_FM_stepSize , /REMOVE)
WIDGET_CONTROL , widIDs.ra_fmStepsID , set_value = newSSize

; Redraw graphics
Self->initializePlot , Self.spectrum_index

; Change all widths to selection
valid = Self->setAllLinesToDefaultWidth()

; Update info Label
raster_width_label = eis_get_total_raster_width_string(Self.eis_raster ,    $
                                                       Self.tlbID)
WIDGET_CONTROL , widIDs.ra_scanInfoLabelID , set_value = raster_width_label

RETURN , 1

END
;______________________________________________________________________________
; Set all window widths to default value
;______________________________________________________________________________
FUNCTION eis_mk_raster_gui::setAllLinesToDefaultWidth

; Get widget IDs
widIDs = Self.eis_mk_raster_widgets
index = WIDGET_INFO(widIDs.ra_listID , /LIST_SELECT)

; Retrieve Line List
Self.eis_ll_obj->getProperty , ll = ll

; Zero all widths
Self.eis_raster.dataWindows = INTARR(25)
width = Self.eis_raster.windWidth
; Update widths
FOR i = 0, Self.eis_raster.nWindows -  1 DO BEGIN

    ; Set all widths to default value
    Self.eis_raster.dataWindows[i] = width
    ; Get eis_line values - starting with wavelength & width
    line  = ll.lines[i]
    ;
    ; PRY, 1/2/2007, added slitindex input
    ;
    ll.lines[i] = eis_line_values(line , width, Self.eis_raster.slitindex )

ENDFOR

; Retrieve Line List
Self.eis_ll_obj->setProperty , ll = ll , dataWindows = Self.eis_raster.dataWindows
; Update Selected Line Properties
Self->updateSelectedLineWidgets , index
; Update "Default Width" slider to new value
WIDGET_CONTROL , widIDs.ra_widthSliderID  , set_value = width/8

RETURN , 1

END
;______________________________________________________________________________
; Edit raster: SNS Duration
;______________________________________________________________________________
FUNCTION eis_mk_raster_gui::rasterSNSDuration

widIDs = Self.eis_mk_raster_widgets
; Get
WIDGET_CONTROL , widIDs.ra_snsDurationID , get_value = orig
; arguments-> name , newValue , oldValue , minValue , maxValue , multiple
; Calculating raster duration

expT      = (TOTAL(Self.eis_raster.exposures[0:Self.eis_raster.nExp-1])) ; = 75
delT      = (TOTAL(Self.eis_raster.delays[   0:Self.eis_raster.nExp-1])) ; = 75
duration  = (Self.eis_raster.sns_nExps * expT  / 1000.)  ; = 75

seconds   = FLOOR(FIX(orig[0]))    ; = 150
sns_nExps = FLOOR(seconds / expT)  ; = 2
valid     = eis_validate_input('Duration' , sns_nExps ,                     $
                              Self.eis_raster.sns_nExps , 1 , 65535)

CASE valid.valid OF
    0:  BEGIN
            newValue = Self.eis_raster.sns_nExps
            beep
        				complain = DIALOG_MESSAGE( valid.mText ,                        $
                             				DIALOG_PARENT = Self.tlbID,                $
                             				/ERROR )
        END
    1:  newValue = sns_nExps
ENDCASE

; Update value
Self.eis_raster.sns_nExps = newValue
; Update widget value
WIDGET_CONTROL , Self.eis_mk_raster_widgets.ra_snsNExpID ,              $
        set_value = STRCOMPRESS(Self.eis_raster.sns_nExps  , /REMOVE_ALL)

; Update SNS Duration
Self->updateSNSDuration

RETURN , valid.valid

END
;______________________________________________________________________________
; Update S'N'S duration
;______________________________________________________________________________
PRO eis_mk_raster_gui::updateSNSDuration

; Calculating raster duration
expT      = (TOTAL(Self.eis_raster.exposures[0:Self.eis_raster.nExp-1]))
delT      = (TOTAL(Self.eis_raster.delays[   0:Self.eis_raster.nExp-1]))
duration  = (Self.eis_raster.sns_nExps * (expT + delT) / 1000.)

durString = STRTRIM(STRING(format='(F12.3)',duration) , 2)
widIDs = Self.eis_mk_raster_widgets
WIDGET_CONTROL , widIDs.ra_snsDurationID , set_value = durString

END
;______________________________________________________________________________
; Edit raster: SNS Number of Exposures
;______________________________________________________________________________
FUNCTION eis_mk_raster_gui::compression

widIDs = Self.eis_mk_raster_widgets
index = WIDGET_INFO(widIDs.ra_compID , /DROPLIST_SELECT)
Self.eis_raster.compression = index

RETURN , 1

END
;______________________________________________________________________________
; Edit raster: SNS Number of Exposures
;______________________________________________________________________________
FUNCTION eis_mk_raster_gui::rasterSNSNumExposures

widIDs = Self.eis_mk_raster_widgets
; Get SNS raster number exposures
WIDGET_CONTROL , widIDs.ra_snsNExpID , get_value = orig
; arguments-> name , newValue , oldValue , minValue , maxValue , multiple
valid  = eis_validate_input('Number Exposures' , orig[0] ,                  $
                              Self.eis_raster.sns_nExps , 1 , 65535)

CASE valid.valid OF
    0:  BEGIN
            newValue = Self.eis_raster.sns_nExps
            beep
        				complain = DIALOG_MESSAGE( valid.mText ,                        $
                             				DIALOG_PARENT = Self.tlbID,                $
                             				/ERROR )
        END
    1:  newValue = LONG(orig[0])
ENDCASE

; Update value
Self.eis_raster.sns_nExps = newValue
; Update widget value
WIDGET_CONTROL , Self.eis_mk_raster_widgets.ra_snsNExpID ,              $
        set_value = STRCOMPRESS(Self.eis_raster.sns_nExps  , /REMOVE_ALL)

RETURN , valid.valid

END
;______________________________________________________________________________
; Edit raster: Default Width
;______________________________________________________________________________
FUNCTION eis_mk_raster_gui::rasterDefaultWidth , drag

widIDs = Self.eis_mk_raster_widgets
; Get Default Window Width
WIDGET_CONTROL , widIDs.ra_widthSliderID , get_value = widValue
; Update label
widthString = STRCOMPRESS(widValue * 8 , /REMOVE_ALL)
WIDGET_CONTROL , widIDs.ra_widthID , set_value = widthString
; Update value
Self.eis_raster.windWidth = widValue * 8

RETURN , 1 - drag

END
;______________________________________________________________________________
; Edit raster: Window Height
;______________________________________________________________________________
FUNCTION eis_mk_raster_gui::rasterHeight , drag

widIDs = Self.eis_mk_raster_widgets
; Get Window Height
WIDGET_CONTROL , widIDs.ra_heightSliderID , get_value = widValue
; Update label
heightString = STRCOMPRESS(widValue * 8 , /REMOVE_ALL)
WIDGET_CONTROL , widIDs.ra_heightID , set_value = heightString
; Update value
Self.eis_raster.windHeight = widValue * 8

; Update lines/windows plot
Self->updatePlot

RETURN , 1 - drag

END
;______________________________________________________________________________
; Set Number of exposures / pointing
;______________________________________________________________________________
FUNCTION eis_mk_raster_gui::rasterNumExposuresPerStep , index

widIDs = Self.eis_mk_raster_widgets
; Update value
Self.eis_raster.nExp = index + 1
; Update exposure times
Self->updateExposureTimes

RETURN , 1

END
;______________________________________________________________________________
; Edit raster: fine mirror steps
;______________________________________________________________________________
FUNCTION eis_mk_raster_gui::rasterFineMirrorStepSize

CASE Self.eis_raster.slitIndex OF
    0: fov_w = 590.
    1: fov_w = 856.
    2: fov_w = 592.
    3: fov_w = 630.
ENDCASE

; Get Fine Mirror Step Size
widIDs = Self.eis_mk_raster_widgets
WIDGET_CONTROL , widIDs.ra_fMStepsID , get_value = orig
; arguments-> name , newValue , oldValue , minValue , maxValue , multiple
valid  = eis_validate_input('FMR Step Size' , orig[0] ,                     $
                              Self.eis_raster.scan_FM_stepSize , 1 , fov_w)

; Also, ensure  num_pointings * step_size LE 590
num_pointings = Self.eis_raster.scan_fm_nSteps + 1
IF ((FIX(orig[0]) * num_pointings) GE fov_w) THEN BEGIN

    valid.valid = 0
    valid.mText = 'Product of Number of Pointings and Step Size'  +         $
                  ' must be LE ' + STRCOMPRESS(FIX(fov_w),/REMOVE_ALL) +    $
                  '". Aborting!'

ENDIF

CASE valid.valid OF
    0:  BEGIN
            newValue = Self.eis_raster.scan_FM_stepSize
            beep
            complain = DIALOG_MESSAGE( valid.mText ,                        $
                                 DIALOG_PARENT = Self.tlbID,                $
                                 /ERROR )
        END
    1:  newValue = FIX(orig[0])
ENDCASE

; Update value
Self.eis_raster.scan_FM_stepSize = newValue
; Update widget value
scan_FM_stepSize = STRCOMPRESS(newValue , /REMOVE_ALL)
WIDGET_CONTROL , widIDs.ra_fMStepsID , set_value = scan_FM_stepSize

; Update info Label
raster_width_label = eis_get_total_raster_width_string(Self.eis_raster,     $
                                                       Self.tlbID)
WIDGET_CONTROL , widIDs.ra_scanInfoLabelID , set_value = raster_width_label

RETURN , valid.valid

END
;______________________________________________________________________________
; Edit raster: number of pointings
;______________________________________________________________________________
FUNCTION eis_mk_raster_gui::rasterNumMirrorSteps

CASE Self.eis_raster.slitIndex OF
    0: fov_w = 590.
    1: fov_w = 856.
    2: fov_w = 592.
    3: fov_w = 630.
ENDCASE

; Get Fine Mirror Step Size
widIDs = Self.eis_mk_raster_widgets
WIDGET_CONTROL , widIDs.ra_nMirrStepsID , get_value = orig

; arguments-> name , newValue , oldValue , minValue , maxValue , multiple
valid  = eis_validate_input('FMR Step Size' , orig[0] ,                     $
                              Self.eis_raster.scan_FM_nSteps , 1 , fov_w)
; Also, ensure  num_pointings * step_size LE 590
step_size = Self.eis_raster.scan_fm_stepsize
num_pointings = FIX(orig[0]) + 1
IF ((num_pointings * step_size) GT fov_w) THEN BEGIN

    valid.valid = 0
    valid.mText = 'Product of Number of Pointings and Step Size'  +         $
                  ' must be LE ' + STRCOMPRESS(FIX(fov_w),/REMOVE_ALL) +    $
                  '". Aborting!'

ENDIF

CASE valid.valid OF
    0:  BEGIN
            newValue = Self.eis_raster.scan_FM_nSteps
            beep
            complain = DIALOG_MESSAGE( valid.mText ,                        $
                                 DIALOG_PARENT = Self.tlbID,                $
                                 /ERROR )
        END
    1:  newValue = orig[0]
ENDCASE

; Update value
Self.eis_raster.scan_FM_nSteps = newValue
; Update widget value
WIDGET_CONTROL , widIDs.ra_nMirrStepsID ,                $
        set_value = STRCOMPRESS(FIX(Self.eis_raster.scan_FM_nSteps), /REMOVE_ALL)

; Update info Label
nExpString    = STRCOMPRESS(newValue + 1,/REMOVE_ALL)
scanInfoLabel = '(Number of exposures = ' + nExpString + ')'
WIDGET_CONTROL , widIDs.ra_scanInfoLabelID , set_value = scanInfoLabel

; Update info Label
raster_width_label = eis_get_total_raster_width_string(Self.eis_raster ,    $
                                                       Self.tlbID)
WIDGET_CONTROL , widIDs.ra_scanInfoLabelID , set_value = raster_width_label

RETURN , valid.valid

END
;______________________________________________________________________________
; Fire up spectrum plotting GUI
;______________________________________________________________________________
PRO eis_mk_raster_gui::updatePlot

widIDs = Self.eis_mk_raster_widgets
; Retrieve default colour table properties
Self.o_def_ct->getProperty , plotsCT = plotsCT , imageCT = imageCT
;++++++++++++++++++++++++++++++++++++++++++++++++
;
; Cache Pixmap
;
;++++++++++++++++++++++++++++++++++++++++++++++++
; Set cache pixmap as current window
WSET , widIDs.ra_cacID
; Copy contents of reference pixmap to cache pixmap
TVLCT,plotsCT[*,0] , plotsCT[*,1] , plotsCT[*,2] ;PLOT ct
DEVICE , Copy = [ 0 , 0 , Self.xySize[0] , Self.xySize[1] , 0 , 0 , widIDs.ra_refID ]
; Plot windows to cache pixmap
Self->plotWindows
;++++++++++++++++++++++++++++++++++++++++++++++++
;
; Draw Widget Area
;
;++++++++++++++++++++++++++++++++++++++++++++++++
; Set draw widget as current window
WIDGET_CONTROL , widIDs.ra_drawID , get_value = drawID
WSET , drawID

DEVICE , Copy = [ 0 , 0 , Self.xySize[0] , Self.xySize[1] , 0 , 0 , widIDs.ra_cacID ]

TVLCT , imageCT[*,0] , imageCT[*,1] , imageCT[*,2] ;IMAGE ct

END
;______________________________________________________________________________
; Plot LOGO
;______________________________________________________________________________
PRO eis_mk_raster_gui::plot_logo

; Get widget IDs
widIDs = Self.eis_mk_raster_widgets
WIDGET_CONTROL , widIDs.ra_iconID , get_value = drawID
WSET , drawID

;fileName = concat_dir(GETENV('ancillary') , 'eis_logo_ sarah_3.jpg')
fileName = concat_dir(GETENV('ancillary') , 'hinode_small.jpg')
; Ensure file is really there
IF (FILE_TEST(fileName) NE 1) THEN RETURN

READ_JPEG , filename , icon
icon_resized = CONGRID(icon,3,160,80)
TVSCL,icon_resized , true = 1

END
;______________________________________________________________________________
; Fire up spectrum plotting GUI
;______________________________________________________________________________
PRO eis_mk_raster_gui::initializePlot , index

widIDs = Self.eis_mk_raster_widgets

Self.spectrum_index = index

;
; PRY, 5-Feb-2007
;   introduced slitindex so that images from different slits can be plotted.
;
slitindex = Self.eis_raster.slitindex

CASE slitindex OF
  3: BEGIN
    CASE index OF
      0:      fileName = 'eis_quiet_3.jpg'
      1:      fileName = 'eis_active_3.jpg'
      2:      fileName = 'eis_flare.jpg'
      ELSE:   stop
    ENDCASE
  END
 ;
  2: BEGIN
    CASE index OF
      0:      fileName = 'eis_quiet_2.jpg'
      1:      fileName = 'eis_active_2.jpg'
      2:      fileName = 'eis_flare.jpg'
      ELSE:   stop
    ENDCASE
  END
 ;
  1: BEGIN
    CASE index OF
      0:      fileName = 'eis_quiet_1.jpg'
      1:      fileName = 'eis_active_1.jpg'
      2:      fileName = 'eis_flare.jpg'
      ELSE:   stop
    ENDCASE
  END
 ;
  ELSE: BEGIN
    CASE index OF
      0:      fileName = 'eis_quiet.jpg'
      1:      fileName = 'eis_active.jpg'
      2:      fileName = 'eis_flare.jpg'
      ELSE:   stop
    ENDCASE
  END

ENDCASE

READ_JPEG , CONCAT_DIR( GETENV('ancillary'),fileName ) , ccd

; Retrieve default colour table properties
Self.o_def_ct->getProperty , plotsCT = plotsCT , imageCT = imageCT
;++++++++++++++++++++++++++++++++++++++++++++++++
;
; Reference Pixmap
;
;++++++++++++++++++++++++++++++++++++++++++++++++
; Set reference pixmap as current window
WSET , widIDs.ra_refID

;
; Plot the image & axes - to reference pixmap
LOADCT , Self.colour_table , /SILENT
TVSCL , CONGRID(ccd , Self.xySize[0] , Self.xySize[1])
TVLCT,plotsCT[*,0] , plotsCT[*,1] , plotsCT[*,2] ;PLOT ct
Self->plotCCDAxes
;++++++++++++++++++++++++++++++++++++++++++++++++
;
; Cache Pixmap
;
;++++++++++++++++++++++++++++++++++++++++++++++++
; Set cache pixmap as current window
WSET , widIDs.ra_cacID
; Copy contents of reference pixmap to cache pixmap
DEVICE , Copy = [ 0 , 0 , Self.xySize[0] , Self.xySize[1] , 0 , 0 , widIDs.ra_refID ]
; Plot windows to cache pixmap
Self->plotWindows
;++++++++++++++++++++++++++++++++++++++++++++++++
;
; Draw Widget Area
;
;++++++++++++++++++++++++++++++++++++++++++++++++
; Set draw widget as current window
WIDGET_CONTROL , widIDs.ra_drawID , get_value = drawID
WSET , drawID

DEVICE , Copy = [ 0 , 0 , Self.xySize[0] , Self.xySize[1] , 0 , 0 , widIDs.ra_cacID ]
TVLCT , imageCT[*,0] , imageCT[*,1] , imageCT[*,2] ;IMAGE ct

END
;______________________________________________________________________________
; Plot Line Windows
;______________________________________________________________________________
PRO eis_mk_raster_gui::plotWindows

index = WIDGET_INFO(Self.eis_mk_raster_widgets.ra_listID , /LIST_SELECT)
height   = Self.eis_raster.windHeight

; Retrieve Line List
Self.eis_ll_obj->getProperty , ll = ll

; Now plot line widths
FOR i = 0, ll.nLines - 1 DO BEGIN

    width     = Self.eis_raster.dataWindows[i]
    ; Default colour is cyan - but yellow when selected
    color     = (index EQ i) ? 5 : 4
    ; Default thickness is 1 - but 2 when selected
    thick     = (index EQ i) ? 2 : 1
    ; If windows overlap, draw as dashed lines
    lineStyle = (ll.lines[i].over EQ 1) ? 2 : 0

;    IF (ll.lines[i].ccd EQ 1) THEN offset = 512 ELSE offset = 0
    IF (ll.lines[i].ccd EQ 1) THEN offset = 767 ELSE offset = 255
    ; OK, make window boxes
    p1 = ll.lines[i].p1 ;+ 2
    p2 = ll.lines[i].p2 ;+ 2
    ; Get y-coordinates
    top_y = offset + height / 2 - 1
    bot_y = offset - height / 2 - 1
    xw = [p1    , p1    , p2    , p2    , p1   ]
    yw = [bot_y , top_y , top_y , bot_y , bot_y]
    ; Now scale xw & yw to window dimensions
    xScale = Self.xySize[0] / 2048.
    yScale = Self.xySize[1] / 1024.

    xPoints = ROUND(xw * xScale) < Self.xySize[0] - 1
    yPoints = ROUND(yw * yScale) < Self.xySize[1] - 1

    PLOTS  , xPoints , yPoints , /DEVICE , color = color     ,              $
                                           lines = lineStyle ,              $
                                           thick = thick

ENDFOR

END
;______________________________________________________________________________
; Fire up spectrum plotting GUI
;______________________________________________________________________________
PRO eis_mk_raster_gui::plotCCDAxes

yS = Self.xySize[1]
xs = Self.xySize[0] / 2048.

;
; Central Line
;
PLOTS  ,[FLOOR(1023 * xS) , FLOOR(1023 * xS)] , [0   , yS-1]  , lines = 3 , /DEVICE

;
; Pixels Scale
;
FOR i = 100, 2000 , 100 DO BEGIN
    ; Lower axis
    XYOUTS , (i * xS) - 10 , 10 , STRCOMPRESS(i,/REMOVE_ALL)  , /DEVICE
    PLOTS  , [FLOOR(i * xS)  , FLOOR(i * xS)] , [0 , 5]                 , /DEVICE
    ; Upper axis
    XYOUTS , (i * xS) - 10 , yS-18 , STRCOMPRESS(i,/REMOVE_ALL) , /DEVICE
    PLOTS  , [FLOOR(i * xS)  , FLOOR(i * xS)] , [yS-6 , yS-1]             , /DEVICE
ENDFOR

;
; Wavelength scale
;
; PRY, 5-Feb-2007
;  The wavelengths for CCD-A were not being calculated correctly, so I've
;  now defined WAVE1 and WAVE2 (instead of the previous WAVE).
;
wave1 = (INDGEN(21)*200) + 17000    ; 17000 -> 21000
wave2 = (INDGEN(21)*200) + 25000    ; 25000 -> 29000
FOR i=0,N_ELEMENTS(wave1)-1 DO BEGIN

 ;
 ; PRY 1/2/2007, added slitindex input
 ;
    pixel = eis_wavelength_to_pixels(wave1[i], Self.eis_raster.slitindex )
    ;print,FLOOR(pixel * xS)
    XYOUTS , (pixel * xS) - 10 , yS-38 , STRCOMPRESS(FIX(wave1[i]/100.),/REMOVE_ALL) , /DEVICE
    PLOTS  ,[FLOOR(pixel * xS) , FLOOR(pixel * xS)] , [yS-26   , yS-1]  , /DEVICE

    pixel = eis_wavelength_to_pixels(wave2[i], Self.eis_raster.slitindex )
    XYOUTS , (pixel * xS) - 10 , 28 , STRCOMPRESS(FIX((wave2[i])/100.),/REMOVE_ALL) , /DEVICE
    PLOTS  ,[FLOOR(pixel * xS) , FLOOR(pixel * xS)] , [0   , 24]  , /DEVICE

ENDFOR

END
;______________________________________________________________________________
; Fire up spectrum plotting GUI
;______________________________________________________________________________
PRO eis_mk_raster_gui::plotSpectrumGUI

IF (OBJ_VALID(Self.o_eis_plot) EQ 1) THEN RETURN

WIDGET_CONTROL ,/HOURGLASS

o_eis_plot = OBJ_NEW("eis_plot_spectrum" , Self)
o_eis_plot->Realize
; Plot spectrum
o_eis_plot->plotShortwaveSpectrum
o_eis_plot->XMANAGER
Self.o_eis_plot = o_eis_plot

END
;______________________________________________________________________________
; Create create/modify line GUI
;______________________________________________________________________________
PRO eis_mk_raster_gui::loadLineList , ll_id

; Read line list entry from database
ll = db_read_linelist_entry(ll_id)

Self.eis_raster.ll_id    = ll.id

; How many windows are defined in the raster
nWindows = Self.eis_raster.nWindows

; Get default width - set all widths to this value
dataWindows = INTARR(25) + Self.eis_raster.windWidth
IF (ll.nLines LT 25) THEN BEGIN

    dataWindows[ll.nLines:*]     = 0
    dataWindows[0: nWindows - 1] = Self.eis_raster.dataWindows[0:nWindows - 1]

ENDIF

; Update nWindows to the new value (from lineList)
Self.eis_raster.nWindows = ll.nLines

; Update ll object
slitindex = Self.eis_raster.slitindex
Self.eis_ll_obj->setProperty , ll = ll , dataWindows = dataWindows , slitindex = slitindex

; OK, de-sensitize "Selected Line" pane
WIDGET_CONTROL , Self.eis_mk_raster_widgets.ra_listID , set_list_select = -1
Self->updateSelectedLineWidgets , -1

; Add eis_raster to UNDO container
oRasterItem = OBJ_NEW("eis_raster_undo" , Self.eis_raster , ll)
Self.rasterUndo->ADD , oRasterItem

END
;______________________________________________________________________________
; Load Raster from Database
;______________________________________________________________________________
PRO eis_mk_raster_gui::loadRaster , ra_id

Self.eis_raster = db_read_raster_entry(ra_id)

ll = db_read_linelist_entry(Self.eis_raster.ll_id)
d  = eis_raster_duration(Self.eis_raster,ll)
;print,'loadRaster: ',sec2dhms(d/1000)
;print,ll.nLines-1
;print,Self.eis_raster.dataWindows[0:ll.nLines-1]

; OK, update eis_raster
;
; Load Line List if required
;
Self->loadLineList , Self.eis_raster.ll_id

; Update ll object
Self.eis_ll_obj->getProperty , ll = ll
d = eis_raster_duration(Self.eis_raster,ll)
;print,'loadRaster: ',sec2dhms(d/1000)
;print,ll.nLines-1
;print,Self.eis_raster.dataWindows[0:ll.nLines-1]

Self->updateRasterWidgets

; JAR 22-Feb-2006
; If slitIndex changes then change spectrum plot
; Redraw graphics
Self->initializePlot , Self.spectrum_index

END
;______________________________________________________________________________
; Update Raster Widget Values
;______________________________________________________________________________
PRO eis_mk_raster_gui::updateRasterWidgets

; Ensure SNS num Exps is not zero
Self.eis_raster.sns_nExps = Self.eis_raster.sns_nExps > 1
Self->updateSNSDuration

; Get widget IDs
widIDs = Self.eis_mk_raster_widgets

widgets = [ widIDs.ra_fMStepsID           ,                                 $
            widIDs.ra_snsNExpID           ,                                 $
            widIDs.ra_snsDurationID ]

values  = [ Self.eis_raster.scan_FM_stepSize   ,                            $
            Self.eis_raster.sns_nExps          ,                            $
            Self.eis_raster.sns_duration]

;
; Update "Number of Pointing Positions"
;
nMirrSteps = STRCOMPRESS(FIX(Self.eis_raster.scan_FM_nSteps),/REMOVE_ALL)
WIDGET_CONTROL , widIDs.ra_nMirrStepsID , set_value = nMirrSteps

;
; Update raster height slider widget
;
windHeight       = Self.eis_raster.windHeight
WIDGET_CONTROL , widIDs.ra_heightSliderID , set_value = windHeight/8
windHeightString = STRCOMPRESS(windHeight , /REMOVE_ALL)
WIDGET_CONTROL , widIDs.ra_heightID       , set_value = windHeightString
;
; Update number of wind width
;
windWidth        = Self.eis_raster.windWidth
WIDGET_CONTROL , widIDs.ra_widthSliderID  , set_value = windWidth/8
windWidthString  = STRCOMPRESS(windWidth  , /REMOVE_ALL)
WIDGET_CONTROL , widIDs.ra_widthID        , set_value = windWidthString
;
; Update number of exposures
;
nExps            = Self.eis_raster.nExp
WIDGET_CONTROL , widIDs.ra_nExpsID , set_droplist_select = nExps - 1

; Update widget text boxes
FOR i = 0 , N_ELEMENTS(widgets) -1 DO BEGIN
    WIDGET_CONTROL , widgets[i] , set_value =                               $
                        STRCOMPRESS(values[i] ,/REMOVE_ALL)
ENDFOR

; Raster Type = scanning / sit'n'stare
IF (Self.eis_raster.rasterType EQ 0) THEN BEGIN
    ; Scanning Mode
    WIDGET_CONTROL , widIDs.ra_typeScanID     , set_button = 1
    WIDGET_CONTROL , widIDs.ra_typeScanBaseID , map = 1
    WIDGET_CONTROL , widIDs.ra_typeSNSBaseID  , map = 0
    nExpLabel     = 'Number of exposures/step'
;    nExpString    = STRCOMPRESS(Self.eis_raster.scan_FM_nSteps+1,/REMOVE_ALL)
;    scanInfoLabel = '(Number of exposures = ' + nExpString + ')'
;
;    raster_width  = (values[0] * values[1]) + slitSlotWidth

ENDIF ELSE BEGIN
    ; Sit'N'Stare Mode
    WIDGET_CONTROL , widIDs.ra_typeSNSID      , set_button = 1
    WIDGET_CONTROL , widIDs.ra_typeSNSBaseID  , map = 1
    WIDGET_CONTROL , widIDs.ra_typeScanBaseID , map = 0
    ;Self->updateSNSDuration
    nExpLabel     = 'Number of exposures/set'
;    scanInfoLabel = ''
;
;    raster_width  = slitSlotWidth

ENDELSE

; Update Compression Droplist
WIDGET_CONTROL , widIDs.ra_compID , set_droplist_select =                   $
                                                Self.eis_raster.compression

; Update info Label
raster_width_label = eis_get_total_raster_width_string(Self.eis_raster ,    $
                                                       Self.tlbID)
WIDGET_CONTROL , widIDs.ra_scanInfoLabelID , set_value = raster_width_label

; Update nExposures Label
WIDGET_CONTROL , widIDs.ra_nExpLabelID    , set_value = nExpLabel

; Update exposure times
Self->updateExposureTimes

; Update slit/slot combobox
WIDGET_CONTROL , widIDs.ra_slitSlotID , set_droplist_select =               $
                                                Self.eis_raster.slitIndex
; Update Author and Date fields
WIDGET_CONTROL , widIDs.ra_authorID , set_value = Self.eis_raster.author
WIDGET_CONTROL , widIDs.ra_dateID   , set_value = Self.eis_raster.date

; Get Duration and Volume
Self->updateDurationAndVolume

; ID needs to be in 000001 format
idValue = STRING(format='(I06)',Self.eis_raster.id)
WIDGET_CONTROL , widIDs.ra_idID      , set_value    = idValue
WIDGET_CONTROL , widIDs.ra_acronymID , set_value    = Self.eis_raster.acronym
; Generate and update title
Self->updateRasterTitle

END
;______________________________________________________________________________
; Get duration - convert to time, and display in widget label
;______________________________________________________________________________
PRO eis_mk_raster_gui::updateDurationAndVolume

widIDs = Self.eis_mk_raster_widgets
;
; Calculate Volume
;
volume_bits   = eis_raster_volume(Self.eis_raster)
volume_string = eis_raster_volume_string(Self.eis_raster  ,                 $
                                                units = Self.volumeUnits)
Self.eis_raster.volume = volume_bits
WIDGET_CONTROL , widIDs.ra_volumeID , set_value = volume_string

;
; Calculate duration
;
; Retrieve Line List
Self.eis_ll_obj->getProperty , ll = ll

duration = eis_raster_duration(Self.eis_raster , ll)
Self.eis_raster.duration = duration
; Convert duration to a string
durationString = eis_format_duration(duration , units = Self.timeUnits)
WIDGET_CONTROL , widIDs.ra_durationID , set_value = durationString
;
; dataRate
;
datarate = eis_raster_datarate(Self.eis_raster)
WIDGET_CONTROL , widIDs.ra_dataRateID , set_value = dataRate

;
; Original data volume
;
orig_vol = STRJOIN(['(none = '                                      ,       $
                    STRCOMPRESS(Self.eis_raster.volume,/REMOVE_ALL) ,       $
                    ' bits)'],/SINGLE)
WIDGET_CONTROL , widIDs.ra_comp_origID , set_value = orig_vol

END
;______________________________________________________________________________
; Update line list widget
;______________________________________________________________________________
PRO eis_mk_raster_gui::updateRasterLineList

; Get widget IDs
widIDs = Self.eis_mk_raster_widgets
; Retrieve Line List
Self.eis_ll_obj->getProperty , ll = ll

; Bail out if there are no lines
IF (ll.nLines EQ 0) THEN BEGIN
    stop
    WIDGET_CONTROL , widIDs.ra_listID , set_list_select = -1
    WIDGET_CONTROL , widIDs.ra_ll_lineBaseID , sensitive = 0
    RETURN
ENDIF
; Update Line List Info widgets
; ID needs to be in 000001 format
id = STRING(format='(I06)',ll.id)
WIDGET_CONTROL , widIDs.ra_ll_idID      , set_value = id
WIDGET_CONTROL , widIDs.ra_ll_acronymID , set_value = ll.acronym
WIDGET_CONTROL , widIDs.ra_ll_dateID    , set_value = ll.date
WIDGET_CONTROL , widIDs.ra_ll_authorID  , set_value = ll.author

; Generate and update title
Self->updateRasterTitle
; Get Duration and Volume
Self->updateDurationAndVolume
; Update Line List widget_list
Self->updateLineListWidget

; Update spectrum plot - if it's up
IF (OBJ_VALID(Self.o_eis_plot) EQ 1) THEN Self.o_eis_plot->plotSpectrum
; Update lines/windows plot
Self->updatePlot

END
;______________________________________________________________________________
; Update line list widget
;______________________________________________________________________________
PRO eis_mk_raster_gui::updateLineListWidget

index = WIDGET_INFO(Self.eis_mk_raster_widgets.ra_listID , /LIST_SELECT)
; Get ll
Self.eis_ll_obj->getProperty , ll = ll

IF (ll.nLines EQ 0) THEN BEGIN
    ; Update line list widget
    WIDGET_CONTROL , Self.eis_mk_raster_widgets.ra_listID  ,            $
                            set_value = ''
    RETURN
ENDIF

lineArray = STRARR(ll.nLines)

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

    line  = ll.lines[i]
    ; Get line number
    wave  = STRING(format='(F6.2)',line.wavelength/100.)

    CASE line.type OF
        0    :  type = 'c'
        1    :  type = 'p'
        ELSE :  type = 'u'
    ENDCASE
    w     = STRJOIN([wave,'  (',type,')'],/SINGLE)

    name  = STRTRIM(line.name , 2)
    width = Self.eis_raster.dataWindows[i]

    IF (line.over  EQ 1) THEN overlap = '!' ELSE overlap = ''
    IF (line.split EQ 1) THEN BEGIN

        split   = '*'

    ENDIF ELSE BEGIN

        split   = ''

    ENDELSE

    lineArray[i] = STRING(format='(I-4,A-15,A-12,I-7,I-4,A-1,A-2,I-5)',     $
                        i+1,w,name,line.p0,line.ccd,split,overlap,width)

ENDFOR

; Update line list widget
WIDGET_CONTROL , Self.eis_mk_raster_widgets.ra_listID  ,                $
                            set_value = lineArray

WIDGET_CONTROL , Self.eis_mk_raster_widgets.ra_listID  ,                $
                            set_list_select = index
END
;______________________________________________________________________________
; Define Data members
;______________________________________________________________________________
PRO eis_mk_raster_gui__define

eis_mk_raster_widgets = {eis_mk_raster_widgets}

struct = { eis_mk_raster_gui                                          ,     $
           tlbID                     : 0L                             ,     $
           eis_mk_raster_widgets     : eis_mk_raster_widgets          ,     $
           o_eis_plot                : OBJ_NEW()                      ,     $
           o_def_ct                  : OBJ_NEW()                      ,     $
           rasterUndo                : OBJ_NEW()                      ,     $
           ra_refID                  : 0L                             ,     $
           timeUnits                 : 0                              ,     $
           volumeUnits               : 0                              ,     $
           xySize                    : LONARR(2)                      ,     $
           eis_raster                : {eis_raster}                   ,     $
           eis_ll_obj                : OBJ_NEW()                      ,     $
           colour_table              : 0                              ,     $
           spectrum_index            : 0                                    $
         }

END