;+
; PROJECT
;           SOLARB EIS
;
; NAME
;           EIS_MK_PLAN_GUI__DEFINE
;
; PURPOSE
;           eis_mk_plan gui class definition
;
; NOTES
;           The
;
; CATEGORY
;           EIS timeline planning
;
; WRITTEN
;           John A Rainne RAL
;
; VERSION
;           v0.1 JAR 7-Jan-2007
;               Fixed problem of disappearing studies when using image_tool.
;               Added a parameter "replot" that is set to 1 when image_tool
;               sends back pointing info to the PT. If this is found here,
;               then I redraw the timeline plot (and reset "replot=0")
;           v0.2 JAR 9-Jan-2007
;               (i)   Created a data rate gui object - this calculates and
;                     displays the plans data rates - allowing it to be
;                     exported to a file.
;               (ii)  Updated CPT v1.8 - where "Test CPT" now produces
;                     ORL and DR files
;               (iii) Removed cleanup tests
;               (iv)  Added running pointing offset to Pointing GUI
;           v0.3 JAR 24-Feb-2007
;               Fixed problem of timeline plot display period
;           v0.4 JAR 16-Mar-2007
;               Fixed problem of zero raster height and width (as seen
;               in image tool)
;           v0.5 JAR 23-Mar-2007
;               Added "Rasters Details..." button to allow user to view
;               the raster details.
;           v0.6 JAR 7-Apr-2007
;               Modified format of x and y_point
;           v0.7 JAR 13-Apr-2007
;               Introduced ra_width tag in sra structure - calculate the
;               raster width when initially reading the raster, and use
;               this tag - rather than calculate it on the fly.
;           v0.8 JAR 25-Apr-2007
;               Use sra.windHeight instead of reading raster db.
;           v0.9 JAR 30-Apr-2007
;               fov_width now depends on slitIndex. This is passed to
;               image_tool
;           v1.0 JAR 29-May-2007
;               Modified the remove_study method to include setting
;               the eis_timeline_container tag study_selected to zero.
;           v1.1 JAR 13-Jun-2007
;               Included bug fix to allow correct initialisation and saving
;               of studies that are moved.
;               Refresh summary after saving timeline db
;               Moved "delete all entries" button from Study to Plan menu
;           v1.2 JAR 15-Jun-2007
;               Refresh timeline plot after clicking "Send to image_tool"
;               because this caused the studies to (appear to) disappear
;               from the timeline.
;          v1.3 JAR 18-Jun-2007
;              If invoking image_tool while the currently seletected
;              study is an engineering entry, then call image_tool with
;              a zeroed point_stc structure, and bail out.
;          v1.4 JAR 18-Jun-2007
;              Introduced a Latest Changes dialog - to keep users
;              informed of recent bug fixes/enhancements.
;          v1.5 JAR 3-Jul-2007
;              Introduced "Copy timeline entry". Achieved by "getting"
;              the currently selected entry, setting its seq_id = zero
;              and setting its start_time to the current cursor time,
;              making it an eis_structure_container and finally adding
;              this object to the tlc.
;              Also included checking that there is sufficient time for
;              the copied entry.
;          v1.6 JAR 4-Jul-2007
;              Introduced a text-box for MIP value input.
;          v1.7 JAR 7-Aug-2007
;              Added facility to allow planner to select entries using
;              the summary tool.
;          v1.8 JAR 22-Aug-2007
;              Flag CPT'ed studies to be saved after updating planner,
;              observer and tohban tags in CPT gui. After dismissing
;              CPT gui, save entries to database.
;          v1.9 JAR 30-Aug-2007
;              Check study being appended to is NOT recursive
;          v2.0 JAR 5-Se-2007
;              Added ASRC functionality
;          v2.1 JAR 11-Sep-2007
;              Check entry to be MOVED or COPIED is SCI or ENG -
;              respond accordingly
;          v2.2 JAR 25-Oct_2007
;              Replaced logo jpeg - check it exists
;          v2.3 JAR 23-11-2007
;               Now reading J-Side files after reading database (see
;               eis_mk_plan_gui::readPlanFromDatabase) - instead of doing
;               it in eis_timeline_plot_gui on the fly every time.
;          v2.4 JAR 30-11-2007
;               Tidied up Cleanup method - added "Shutting down" messages.
;               Also, completed DR GUI.
;          v2.5 JAR 7-Dec-2007
;               Modified SCI_OBJ GUI. Now pass study SCI_OBJ
;               Removed OBSID/JOP_ID from mk_plan
;          v2.6 JAR 17-Dec-2007
;               Refresh DR GUI if it's up
;          v2.7 JAR 7-Mar-2008
;               1. Check that yip + raster height < 1024 when modifying
;                  either yip or y coordinate.
;               2. Pass image_tool the EIS fov = 1024
;          v2.8 JAR 18-Mar-2008
;               Check that YIP is > 0. Means also checking for y pointing
;          v2.9 JAR 27-Mar-2008
;               Added functionality to allow studies to be triggered by
;               a Bright Point (EIS Event). Toggle (radio) buttin activated.
;          v3.0 JAR 9-Apr-2008
;               Added functionality to view $CMNPLN/tomorrow/ files
;          v3.1 JAR 19-May-2008
;               Added functionality to MOVE multiple tl entries
;          v3.2 JAR 23-May-2008
;               Added "View Internal info" button to help menu
;          v3.3 JAR 12-Jun-2008
;               Added logo_fileName to definition. User can supply their
;               own JPEG image file to display.
;          v3.4 JAR 25-Jun-2008
;               1. Added "Modify metadata" button to "Study" menu
;               2. Created "meta_str" structure to remember metadata tags
;               3. Created "cpt_str"  structure to remember CPT      tags
;          v3.5 JAR 7-Jul-2008
;               Check there are timeline entries before invoking any
;               multiple action guis.
;          v3.6 JAR 4-Aug-2008
;               Added warning dialog if MIP is equal/less than 160.
;          v3.7 JAR 7-Aug-2008
;               Check if multiple GUIS are present when reading the timeline
;               database. If so, then complain and bail! Otherwise there
;               will be tlc conflicts.
;          v3.8 JAR 21-Aug-2008
;               Moved "View Environment Variables" button to the Help menu
;          v3.9 JAR 27-Aug-2008
;               Added "View Startup Log" in "RP" menu
;          v4.0 JAR 18-Sep-2008
;               Modified eis_cpt_environment_wrapper for eis_cpt v2.2
;          v4.1 JAR 10-Oct-2008
;                Modified call to eis_cpt_environment_wrapper routine
;          v4.2 JAR 21-Oct-2008
;               Added "View EISCO archive Log" in "RP" menu
;          v4.3 JAR 4-Nov-2008
;               Don't allow ORL engineering studies to be appended to
;               an existing study. They must be time-tagged.
;          v4.4 JAR 6-Jan-2009
;               Fixed bug when entering raster repeats > 4095
;          v4.5 JAR 6-May-2009
;               In the interests of MS users, make directory checking
;               case-insensitive!
;          v4.6 JAR 18-May-2009
;               When moving a (single study) - make sure it is a TT'ed
;               entry. If not, then bail out. If so, then move appended
;               studies with it.
;          v4.7 JAR 17-Jun-2009
;               1. Started work on a new OP Period Tool
;               2. Changed view from NGT to XTW eclipse periods
;          v4.8 JAR 13-Jul-2009
;               Reset time_tagged = 1, when copying study. This applies
;               both to single and multiple study copying.
;          v4.9 JAR
;               1. Added raster search tool to menu
;               2. When multiple move or copy tool is invoked, the new time
;                  is changed by clicking on the timeline plot.
;          v5.0 JAR 11-Aug-2009
;               Allowed use of (new) eis_op_gui tool
;          v5.1 JAR 28-Jan-2010
;               Updated ::update_yip method to accept values up to 1024
;               (previously 1023).
;          v5.2 JAR 5-Mar-2010
;               Check when toggling an trigger event that the selected study
;               has been saved. Can't handle cases where seq_id = 0
;          v5.3 JAR 18-Jun-2010
;               Redraw graphics after quitting eis_event_gui, since the plot
;               now draws the total time of both hunter and response studies.
;          v5.4 JAR 25-Oct-2010
;               Prepared to handle new version of eis_flare_gui
;          v5.5 JAR 31-Aug-2011
;               When copying a hunter/response study combo, save the hunter
;               study first - becuse the newly copied hunter study will
;               have seq_id EQ 0. We need to create a valid (incremented
;               and non-zero)
;          v5.6 JAR 19-Jan-2012
;               If XRTFlare, EISFlare or EISEvent toggled, then don't allow the
;               others to be enabled
;          v5.7 JAR 23-Jan-2011
;               If copied study is a trigger study, force the timeline DB to
;               automatically save
;          v5.8 JAR 16-Jul-2013
;               Added functionality to view EIS-AIA offset file (compiled by
;               John M).
;          v5.9 JAR 1-Apr-2014.
;               Now include "obs_id" and "aia_time" inputs to routine
;               "eis_pointing_offset"
;          v6.0 JAR 26-Aug-2014.
;               Set Hinode/SOT offsets in main program.
;          v6.1 JAR 03-Dec-2014.
;               Handle EISF exclusively with the response DB (like the
;               XRTF case)
;
;-
;______________________________________________________________________________
FUNCTION eis_mk_plan_gui::Init , rp = rp , response = response

IF (KEYWORD_SET(rp) EQ 1) THEN Self.rp = 1

; JAR 18-Sep-2008
eis_cpt_output_path = EXPAND_PATH(EXPAND_PATH(GETENV('cpt_output_dir')))
eis_cpt_input_path  = EXPAND_PATH(EXPAND_PATH(GETENV('cpt_input_dir' )))
cmdpln_eisco        = EXPAND_PATH(GETENV('CMDPLN_EISCO' ))

; Define eis_cpt environment constants
eis_cpt_environment_wrapper                                          ,     $
            concat_dir(eis_cpt_output_path , 'obstbl')               ,     $
            concat_dir(eis_cpt_output_path , 'obstbl_map')           ,     $
            concat_dir(eis_cpt_input_path  , 'engineering_tables')   ,     $
            concat_dir(eis_cpt_input_path  , 'sibcmd-table-20070731'),     $
   LATEST = concat_dir(cmdpln_eisco        , 'latest')               ,     $
   MSSL   = concat_dir(eis_cpt_output_path , 'mssl_tables')          ,     $
   INTEL  = concat_dir(eis_cpt_output_path , 'intel_tables')         ,     $
   ORL    = concat_dir(eis_cpt_output_path , 'orl')                  ,     $
   OBSTBL = concat_dir(eis_cpt_output_path , 'obstbl')               ,     $
   MAP    = concat_dir(eis_cpt_output_path , 'obstbl_map')





; ; Define eis_cpt environment constants
; eis_cpt_environment_wrapper , EXPAND_PATH(EXPAND_PATH(GETENV('cpt_input_dir')))   , $
;                               EXPAND_PATH(EXPAND_PATH(GETENV('cpt_output_dir')))

; Create the default colour tables
Self.o_def_ct = OBJ_NEW("def_ct")

; JAR 26-Aug-2014
; Define Hinode/SOT offsets here.
Self.sot_offset = [10.,20.]

; Create the tlc object
Self.eis_timeline_container = OBJ_NEW("eis_timeline_container",Self)

Event_Pro_update = 'eis_mk_plan_gui_update_EV'
Event_Pro        = 'eis_mk_plan_gui_EV'
;
;-------------------create the main base---------------------------------------;
pt_version = eis_get_pt_version_number()
widTitle = 'EIS Make Plan Tool' + pt_version
IF (Self.rp EQ 1) THEN widTitle = widTitle + "  REMOTE PLANNING MODE"

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

child = WIDGET_BASE(Self.tlbID)

;-------------------create the GUI------------------------------;
;--------plan menu list--------------------------------------------------------;
plan_menu                     = WIDGET_BUTTON(bar, VALUE='Plan', /MENU)

TL_SAVE_EVENT               = {eis_mk_plan_gui_Event}
TL_SAVE_EVENT.eis_mk_plan_gui   = Self
TL_SAVE_EVENT.Type          = "SAVE_PLAN"
TL_SAVEButton               = WIDGET_BUTTON(plan_menu,                      $
                                    value       = 'Save Plan'        ,      $
                                    Event_Pro   = 'eis_mk_plan_gui_EV',     $
                                    uValue      = TL_SAVE_EVENT)

READ_EVENT                  = {eis_mk_plan_gui_Event}
READ_EVENT.eis_mk_plan_gui  = Self
READ_EVENT.Type             = "READ_DATABASE"
READbutton                  = WIDGET_BUTTON(plan_menu                ,     $
                                    value       = 'Refresh Plan'     ,     $
                                    Event_Pro   = Event_Pro          ,     $
                                    uValue      = READ_EVENT )


OP_EVENT                   = {eis_mk_plan_gui_Event}
OP_EVENT.eis_mk_plan_gui   = Self
OP_EVENT.Type              = "OP_GUI"
value = 'View OP Period Info...'
OPButton                   = WIDGET_BUTTON(plan_menu                 ,     $
                                   value       = value               ,     $
                                   Event_Pro   = 'eis_mk_plan_gui_EV',     $
                                   uValue      = OP_EVENT            ,     $
                                   SENSITIVE   = 1                   ,     $
                                   /SEPARATOR)

EXPORT_EVENT                = {eis_mk_plan_gui_Event}
EXPORT_EVENT.eis_mk_plan_gui  = Self
EXPORT_EVENT.Type           = "EXPORT_PLAN"
EXPORTButton                = WIDGET_BUTTON(plan_menu ,                     $
                                    value       = 'Export plan...'  ,       $
                                    Event_Pro   = 'eis_mk_plan_gui_EV',     $
                                    uValue      = EXPORT_EVENT        ,     $
                                    SENSITIVE   = 0                   ,     $
                                    /SEPARATOR)


IMPORT_EVENT                = {eis_mk_plan_gui_Event}
IMPORT_EVENT.eis_mk_plan_gui  = Self
IMPORT_EVENT.Type           = "IMPORT_PLAN"
IMPORTButton                = WIDGET_BUTTON(plan_menu ,                     $
                                    value       = 'Import plan...'  ,       $
                                    Event_Pro   = 'eis_mk_plan_gui_EV',     $
                                    uValue      = IMPORT_EVENT        ,     $
                                    SENSITIVE   = 0)

ST_REMALL_EVENT             = {eis_mk_plan_gui_Event}
ST_REMALL_EVENT.eis_mk_plan_gui = Self
ST_REMALL_EVENT.Type        = "STUDY_REMOVE_ALL"
value = 'Delete all entries from timeline'
ST_REMALLButton             = WIDGET_BUTTON(plan_menu     ,                 $
                                    value       = value  ,                  $
                                    Event_Pro   = Event_Pro_update    ,     $
                                    uValue      = ST_REMALL_EVENT,/separator)

QUIT_EVENT                  = {eis_mk_plan_gui_Event}
QUIT_EVENT.eis_mk_plan_gui    = Self
QUIT_EVENT.Type             = "QUIT"
quitbutton                  = WIDGET_BUTTON(plan_menu,                      $
                                    value       = 'Exit',                   $
                                    Event_Pro   = 'eis_mk_plan_gui_EV',     $
                                    uValue      = QUIT_EVENT,/separator)

;------------------------------------------------------------------------------;
;--------study menu list--------------------------------------------------------;
study_menu                   = WIDGET_BUTTON(bar ,                           $
                                    VALUE       = 'Study' ,                 $
                                    /MENU)

ST_SEARCH_EVENT             = {eis_mk_plan_gui_Event}
ST_SEARCH_EVENT.eis_mk_plan_gui   = Self
ST_SEARCH_EVENT.Type        = "STSEARCHDB"
value = "Load and Insert/Append study from database..."
ST_SEARCHButton             = WIDGET_BUTTON(study_menu       ,              $
                                    value       = value  ,    $
                                    Event_Pro   = 'eis_mk_plan_gui_EV',     $
                                    uValue      = ST_SEARCH_EVENT)

value = "Multiple entries"
meMenu                     = WIDGET_BUTTON(study_menu                ,     $
                                   value       = value               ,     $
                                    /MENU)
value = "Selected (single) entry"
seMenu                     = WIDGET_BUTTON(study_menu                ,     $
                                   value       = value               ,     $
                                    /MENU)


ST_MMOVE_CP_EVENT           = {eis_mk_plan_gui_Event}
ST_MMOVE_CP_EVENT.eis_mk_plan_gui   = Self
ST_MMOVE_CP_EVENT.Type      = "ST_MMOVE_CP"
value = 'Move...'
ST_MMOVE_CPButton           = WIDGET_BUTTON(meMenu  ,                   $
                                    value       = value ,                   $
                                    Event_Pro   = Event_Pro           ,     $
                                    uValue      = ST_MMOVE_CP_EVENT  ,      $
                                    /SEPARATOR)

ST_MCOPY_CP_EVENT          = {eis_mk_plan_gui_Event}
ST_MCOPY_CP_EVENT.eis_mk_plan_gui   = Self
ST_MCOPY_CP_EVENT.Type     = "ST_MCOPY_CP"
value = 'Copy...'
ST_MCOPY_CPButton            = WIDGET_BUTTON(meMenu    ,                   $
                                    value       = value ,                   $
                                    Event_Pro   = Event_Pro    ,     $
                                    uValue      = ST_MCOPY_CP_EVENT)

ST_MDELETE_EVENT          = {eis_mk_plan_gui_Event}
ST_MDELETE_EVENT.eis_mk_plan_gui   = Self
ST_MDELETE_EVENT.Type     = "ST_MDELETE_CP"
value = 'Delete...'
ST_MDELETE_EVENTButton            = WIDGET_BUTTON(meMenu  ,                   $
                                    value       = value ,                   $
                                    Event_Pro   = Event_Pro    ,     $
                                    uValue      = ST_MDELETE_EVENT)

ST_MMETA_EVENT             = {eis_mk_plan_gui_Event}
ST_MMETA_EVENT.eis_mk_plan_gui   = Self
ST_MMETA_EVENT.Type        = "ST_MMETA_CP"
value = 'Modify metadata...'
ST_MMETA_EVENTButton       = WIDGET_BUTTON(meMenu  ,                   $
                                    value       = value ,                   $
                                    Event_Pro   = Event_Pro    ,     $
                                    uValue      = ST_MMETA_EVENT)

ST_MDVOL_EVENT             = {eis_mk_plan_gui_Event}
ST_MDVOL_EVENT.eis_mk_plan_gui   = Self
ST_MDVOL_EVENT.Type        = "ST_MDVOL_CP"
value = 'Calculate Data Volume Total...'
ST_MDVOL_EVENTButton       = WIDGET_BUTTON(meMenu  ,                   $
                                    value       = value ,                   $
                                    Event_Pro   = Event_Pro    ,     $
                                    uValue      = ST_MDVOL_EVENT)

ST_MOVE_CP_EVENT            = {eis_mk_plan_gui_Event}
ST_MOVE_CP_EVENT.eis_mk_plan_gui   = Self
ST_MOVE_CP_EVENT.Type       = "ST_MOVE_CP"
value = 'Move to Cursor Time'
ST_MOVE_CPButton            = WIDGET_BUTTON(seMenu  ,                   $
                                    value       = value ,                   $
                                    Event_Pro   = Event_Pro_update    ,     $
                                    uValue      = ST_MOVE_CP_EVENT    ,     $
                                    /SEPARATOR)

ST_COPY_CP_EVENT            = {eis_mk_plan_gui_Event}
ST_COPY_CP_EVENT.eis_mk_plan_gui   = Self
ST_COPY_CP_EVENT.Type       = "ST_COPY_CP"
value = 'Copy to Cursor Time'
ST_COPY_CPButton            = WIDGET_BUTTON(seMenu  ,                   $
                                    value       = value ,                   $
                                    Event_Pro   = Event_Pro_update    ,     $
                                    uValue      = ST_COPY_CP_EVENT)


ST_REM_EVENT                = {eis_mk_plan_gui_Event}
ST_REM_EVENT.eis_mk_plan_gui = Self
ST_REM_EVENT.Type           = "STUDY_REMOVE"
value = 'Delete'
ST_REMButton                = WIDGET_BUTTON(seMenu    ,                 $
                                    value       = value  ,                  $
                                    Event_Pro   = Event_Pro_update    ,     $
                                    uValue      = ST_REM_EVENT)





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

; UNDO_EVENT                  = {eis_mk_plan_gui_Event}
; UNDO_EVENT.eis_mk_plan_gui = Self
; UNDO_EVENT.Type             = "UNDO"
; UNDObutton                  = WIDGET_BUTTON(edit_menu,                      $
;                                     value       = 'Undo'   ,                $
;                                     Event_Pro   = 'eis_mk_plan_gui_EV',   $
;                                     uValue      = UNDO_EVENT)

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

THMS_EVENT                  = {eis_mk_plan_gui_Event}
THMS_EVENT.eis_mk_plan_gui = Self
THMS_EVENT.Type             = "DURATIONUNITS"
THMS_EVENT.extra            = 0
THMSbutton                  = WIDGET_BUTTON(timeButtonId,                   $
                                    value       = 'h:m:s',                  $
                                    Event_Pro   = 'eis_mk_plan_gui_EV',   $
                                    uValue      = THMS_EVENT)

HOUR_EVENT                  = {eis_mk_plan_gui_Event}
HOUR_EVENT.eis_mk_plan_gui = Self
HOUR_EVENT.Type             = "DURATIONUNITS"
HOUR_EVENT.extra            = 1
HOURbutton                  = WIDGET_BUTTON(timeButtonId,                   $
                                    value       = 'hours',                  $
                                    Event_Pro   = 'eis_mk_plan_gui_EV',     $
                                    uValue      = HOUR_EVENT)

MINS_EVENT                  = {eis_mk_plan_gui_Event}
MINS_EVENT.eis_mk_plan_gui = Self
MINS_EVENT.Type             = "DURATIONUNITS"
MINS_EVENT.extra            = 2
MINSbutton                  = WIDGET_BUTTON(timeButtonId,                   $
                                    value       = 'minutes',                $
                                    Event_Pro   = 'eis_mk_plan_gui_EV',     $
                                    uValue      = MINS_EVENT)

SECS_EVENT                  = {eis_mk_plan_gui_Event}
SECS_EVENT.eis_mk_plan_gui = Self
SECS_EVENT.Type             = "DURATIONUNITS"
SECS_EVENT.extra            = 3
SECSbutton                  = WIDGET_BUTTON(timeButtonId,                   $
                                    value       = 'seconds',                $
                                    Event_Pro   = 'eis_mk_plan_gui_EV',     $
                                    uValue      = SECS_EVENT)

; STOP_EVENT                  = {eis_mk_plan_gui_Event}
; STOP_EVENT.eis_mk_plan_gui = Self
; STOP_EVENT.Type             = "STOP"
; STOPbutton                  = WIDGET_BUTTON(edit_menu,                      $
;                                     value       = 'STOP'   ,                $
;                                     Event_Pro   = 'eis_mk_plan_gui_EV',   $
;                                     uValue      = STOP_EVENT)

;------------------------------------------------------------------------------;
;--------tools menu list-------------------------------------------------------;
tools_menu                   = WIDGET_BUTTON(bar, VALUE='Tools', /MENU)

IM_TOOL_EVENT               = {eis_mk_plan_gui_Event}
IM_TOOL_EVENT.eis_mk_plan_gui   = Self
IM_TOOL_EVENT.Type          = "PLAN_PLOT"
value = 'Planning Timeline Plot...'
IM_TOOLButton               = WIDGET_BUTTON(tools_menu ,                    $
                                    value       = value               ,     $
                                    Event_Pro   = 'eis_mk_plan_gui_EV',     $
                                    uValue      = IM_TOOL_EVENT)

IM_TOOL_EVENT               = {eis_mk_plan_gui_Event}
IM_TOOL_EVENT.eis_mk_plan_gui   = Self
IM_TOOL_EVENT.Type          = "IMAGE_TOOL"
IM_TOOLButton               = WIDGET_BUTTON(tools_menu ,                    $
                                    value       = 'Image Tool...'  ,        $
                                    Event_Pro   = 'eis_mk_plan_gui_EV',     $
                                    uValue      = IM_TOOL_EVENT)

RA_SEARCH_EVENT            = {eis_mk_plan_gui_Event}
RA_SEARCH_EVENT.eis_mk_plan_gui   = Self
RA_SEARCH_EVENT.Type       = "RA_SEARCH"
RA_SEARCHButton            = WIDGET_BUTTON(tools_menu                ,     $
                                   value       = 'Search rasters...' ,     $
                                   Event_Pro   = 'eis_mk_plan_gui_EV',     $
                                   uValue      = RA_SEARCH_EVENT)


CPT_GUI_EVENT               = {eis_mk_plan_gui_Event}
CPT_GUI_EVENT.eis_mk_plan_gui   = Self
CPT_GUI_EVENT.Type          = "CPT_GUI"
CPT_GUIButton               = WIDGET_BUTTON(tools_menu ,                    $
                                    value       = 'CPT...'  ,               $
                                    Event_Pro   = 'eis_mk_plan_gui_EV',     $
                                    uValue      = CPT_GUI_EVENT)

DR_EVENT                    = {eis_mk_plan_gui_Event}
DR_EVENT.eis_mk_plan_gui    = Self
DR_EVENT.Type               = "DR"
DRbutton                    = WIDGET_BUTTON(tools_menu,                     $
                                    value       = 'Data Rate Tool...',      $
                                    Event_Pro   = 'eis_mk_plan_gui_EV',     $
                                    uValue      = DR_EVENT)

CT_GUI_EVENT                = {eis_mk_plan_gui_Event}
CT_GUI_EVENT.eis_mk_plan_gui = Self
CT_GUI_EVENT.Type           = "CT_GUI"
CT_GUIButton                = WIDGET_BUTTON(tools_menu ,                    $
                                    value       = 'Plan Summary...'  ,      $
                                    Event_Pro   = 'eis_mk_plan_gui_EV',     $
                                    uValue      = CT_GUI_EVENT)

PREF_EVENT                  = {eis_mk_plan_gui_Event}
PREF_EVENT.eis_mk_plan_gui  = Self
PREF_EVENT.Type             = "PREF"
value = 'Preferences...'
PREFButton                  = WIDGET_BUTTON(tools_menu ,                    $
                                    value       = value      ,              $
                                    Event_Pro   = 'eis_mk_plan_gui_EV',     $
                                    uValue      = PREF_EVENT)

STRESS_EVENT               = {eis_mk_plan_gui_Event}
STRESS_EVENT.eis_mk_plan_gui  = Self
STRESS_EVENT.Type          = "STRESS"
value = 'Stress Management Tool...'
STRESSButton               = WIDGET_BUTTON(tools_menu ,                     $
                                    value       = value      ,              $
                                    Event_Pro   = 'eis_mk_plan_gui_EV',     $
                                    uValue      = STRESS_EVENT)

XDOC_EVENT                  = {eis_mk_plan_gui_Event}
XDOC_EVENT.eis_mk_plan_gui  = Self
XDOC_EVENT.Type             = "XDOC"
value = 'XDoc - Browse software tree...'
XDOCButton                  = WIDGET_BUTTON(tools_menu ,                    $
                                    value       = value      ,              $
                                    Event_Pro   = 'eis_mk_plan_gui_EV',     $
                                    uValue      = XDOC_EVENT)

;--------View menu list-------------------------------------------------------;
view_menu                  = WIDGET_BUTTON(bar, VALUE='View', /MENU)


OBEV_WIND_EVENT             = {eis_mk_plan_gui_Event}
OBEV_WIND_EVENT.eis_mk_plan_gui  = Self
OBEV_WIND_EVENT.Type        = "OBEV_WINDOWS"
value = 'View OBEV windows...'
OBEV_WINDButton             = WIDGET_BUTTON(view_menu                ,     $
                                    value       = value              ,     $
                                    Event_Pro   = Event_Pro          ,     $
                                    uValue      = OBEV_WIND_EVENT)

EISAIA_EVENT               = {eis_mk_plan_gui_Event}
EISAIA_EVENT.eis_mk_plan_gui  = Self
EISAIA_EVENT.Type          = "EISAIA_VIEW"
value = 'View IES-AIA Offsets...'
EISAIAButton             = WIDGET_BUTTON(view_menu                ,     $
                                    value       = value              ,     $
                                    Event_Pro   = Event_Pro          ,     $
                                    uValue      = EISAIA_EVENT)


value = "CP files"
cpMenu                     = WIDGET_BUTTON(view_menu                 ,     $
                                   value       = value               ,     $
                                    /MENU)

value = "Today"
todayMenu                  = WIDGET_BUTTON(cpMenu                    ,     $
                                   value       = value               ,     $
                                    /MENU)

OP_TODAY_EVENT             = {eis_mk_plan_gui_Event}
OP_TODAY_EVENT.eis_mk_plan_gui  = Self
OP_TODAY_EVENT.Type        = "OP_TODAY"
value = 'View OP file...'
OP_TODAYButton             = WIDGET_BUTTON(todayMenu                 ,     $
                                    value       = value              ,     $
                                    Event_Pro   = Event_Pro          ,     $
                                    uValue      = OP_TODAY_EVENT)


REPOINT_TODAY_EVENT     = {eis_mk_plan_gui_Event}
REPOINT_TODAY_EVENT.eis_mk_plan_gui  = Self
REPOINT_TODAY_EVENT.Type = "REPOINT_TODAY"
value = 'View Re-point file...'
REPOINT_TODAYButton     = WIDGET_BUTTON(todayMenu                    ,     $
                                    value       = value              ,     $
                                    Event_Pro   = Event_Pro          ,     $
                                    uValue      = REPOINT_TODAY_EVENT)

SAA_TODAY_EVENT         = {eis_mk_plan_gui_Event}
SAA_TODAY_EVENT.eis_mk_plan_gui  = Self
SAA_TODAY_EVENT.Type    = "SAA_TODAY"
value = 'View SAA events...'
SAA_TODAYButton         = WIDGET_BUTTON(todayMenu                    ,     $
                                    value       = value              ,     $
                                    Event_Pro   = Event_Pro          ,     $
                                    uValue      = SAA_TODAY_EVENT)

NGT_TODAY_EVENT         = {eis_mk_plan_gui_Event}
NGT_TODAY_EVENT.eis_mk_plan_gui  = Self
NGT_TODAY_EVENT.Type    = "NGT_TODAY"
value = 'View Eclipse (XTW) events...'
NGT_TODAYButton         = WIDGET_BUTTON(todayMenu                    ,     $
                                    value       = value              ,     $
                                    Event_Pro   = Event_Pro          ,     $
                                    uValue      = NGT_TODAY_EVENT)

ALL_TODAY_EVENT         = {eis_mk_plan_gui_Event}
ALL_TODAY_EVENT.eis_mk_plan_gui  = Self
ALL_TODAY_EVENT.Type    = "ALL_TODAY"
value = 'View ALL these files...'
ALL_TODAYButton         = WIDGET_BUTTON(todayMenu                    ,     $
                                   value       = value               ,     $
                                   Event_Pro   = Event_Pro           ,     $
                                   uValue      = ALL_TODAY_EVENT     ,     $
                                   /SEPARATOR)

;
; Tomorrow
;
value = "Tomorrow"
tomorrowMenu               = WIDGET_BUTTON(cpMenu                    ,     $
                                   value       = value               ,     $
                                    /MENU)

OP_TOMORROW_EVENT          = {eis_mk_plan_gui_Event}
OP_TOMORROW_EVENT.eis_mk_plan_gui  = Self
OP_TOMORROW_EVENT.Type     = "OP_TOMORROW"
value = 'View OP file...'
OP_TOMORROWButton          = WIDGET_BUTTON(tomorrowMenu              ,     $
                                    value       = value              ,     $
                                    Event_Pro   = Event_Pro          ,     $
                                    uValue      = OP_TOMORROW_EVENT)


REPOINT_TOMORROW_EVENT     = {eis_mk_plan_gui_Event}
REPOINT_TOMORROW_EVENT.eis_mk_plan_gui  = Self
REPOINT_TOMORROW_EVENT.Type = "REPOINT_TOMORROW"
value = 'View Re-point file...'
REPOINT_TOMORROWButton     = WIDGET_BUTTON(tomorrowMenu              ,     $
                                    value       = value              ,     $
                                    Event_Pro   = Event_Pro          ,     $
                                    uValue      = REPOINT_TOMORROW_EVENT)

SAA_TOMORROW_EVENT         = {eis_mk_plan_gui_Event}
SAA_TOMORROW_EVENT.eis_mk_plan_gui  = Self
SAA_TOMORROW_EVENT.Type    = "SAA_TOMORROW"
value = 'View SAA events...'
SAA_TOMORROWButton         = WIDGET_BUTTON(tomorrowMenu              ,     $
                                    value       = value              ,     $
                                    Event_Pro   = Event_Pro          ,     $
                                    uValue      = SAA_TOMORROW_EVENT)

NGT_TOMORROW_EVENT         = {eis_mk_plan_gui_Event}
NGT_TOMORROW_EVENT.eis_mk_plan_gui  = Self
NGT_TOMORROW_EVENT.Type    = "NGT_TOMORROW"
value = 'View Eclipse (XTW) events...'
NGT_TOMORROWButton         = WIDGET_BUTTON(tomorrowMenu              ,     $
                                    value       = value              ,     $
                                    Event_Pro   = Event_Pro          ,     $
                                    uValue      = NGT_TOMORROW_EVENT)

ALL_TOMORROW_EVENT         = {eis_mk_plan_gui_Event}
ALL_TOMORROW_EVENT.eis_mk_plan_gui  = Self
ALL_TOMORROW_EVENT.Type    = "ALL_TOMORROW"
value = 'View ALL these files...'
ALL_TOMORROWButton         = WIDGET_BUTTON(tomorrowMenu              ,     $
                                   value       = value               ,     $
                                   Event_Pro   = Event_Pro           ,     $
                                   uValue      = ALL_TOMORROW_EVENT  ,     $
                                   /SEPARATOR)

; ;------------------------------------------------------------------------------;
; ;--------prefs menu list-------------------------------------------------------;
; prefs_menu                     = WIDGET_BUTTON(bar, VALUE='Preferences', /MENU)
;
;;
;; Re-point Dialog
;;
;repointpopupMenu              = WIDGET_BUTTON(prefs_menu             ,        $
;                                    value       = 'Re-point dialog',        $
;                                    /MENU)
;
;POPON_EVENT                 = {eis_mk_plan_gui_Event}
;POPON_EVENT.eis_mk_plan_gui = Self
;POPON_EVENT.Type            = "REPOINTPOPUPON"
;POPON_EVENT.extra           = 0
;Self.repointpopup_onID      = WIDGET_BUTTON(repointpopupMenu ,               $
;                                    value       = 'On'      ,                $
;                                    Event_Pro   = 'eis_mk_plan_gui_EV',      $
;                                    uValue      = POPON_EVENT         ,      $
;                                    /CHECKED_MENU)
;
;POPOFF_EVENT                = {eis_mk_plan_gui_Event}
;POPOFF_EVENT.eis_mk_plan_gui = Self
;POPOFF_EVENT.Type           = "REPOINTPOPUPOFF"
;POPOFF_EVENT.extra          = 1
;Self.repointpopup_offID     = WIDGET_BUTTON(repointpopupMenu ,               $
;                                    value       = 'Off'      ,               $
;                                    Event_Pro   = 'eis_mk_plan_gui_EV',      $
;                                    uValue      = POPOFF_EVENT        ,      $
;                                    /CHECKED_MENU)
;WIDGET_CONTROL , Self.repointpopup_offID , set_button = 1

;------------------------------------------------------------------------------;
;--------View menu list-------------------------------------------------------;
IF (Self.rp EQ 1) THEN BEGIN
   value = "RP"
   rp_menu                 = WIDGET_BUTTON(bar, VALUE=value, /MENU)

   LOG_EVENT               = {eis_mk_plan_gui_Event}
   LOG_EVENT.eis_mk_plan_gui    = Self
   LOG_EVENT.Type          = "VIEW_RP_LOG"
   value = 'View Startup Log...'
   LOGButton               = WIDGET_BUTTON(rp_menu                   ,     $
                                   value       = value               ,     $
                                   Event_Pro   = Event_Pro           ,     $
                                   uValue      = LOG_EVENT)

   EISCO_LOG_EVENT         = {eis_mk_plan_gui_Event}
   EISCO_LOG_EVENT.eis_mk_plan_gui    = Self
   EISCO_LOG_EVENT.Type    = "VIEW_EISCO_LOG"
   value = 'View EISCO archive Log...'
   EISCO_LOGButton         = WIDGET_BUTTON(rp_menu                   ,     $
                                   value       = value               ,     $
                                   Event_Pro   = Event_Pro           ,     $
                                   uValue      = EISCO_LOG_EVENT)

ENDIF
;--------help menu list--------------------------------------------------------;
help_menu               = WIDGET_BUTTON(bar,VALUE='Help',/MENU,/help)

HELP_EVENT                  = {eis_mk_plan_gui_Event}
HELP_EVENT.eis_mk_plan_gui    = Self
HELP_EVENT.Type             = "HELP"
HELPButton                  = WIDGET_BUTTON(help_menu,                      $
                                    value       = 'Help...',                $
                                    Event_Pro   = 'eis_mk_plan_gui_EV',     $
                                    uValue      = HELP_EVENT)

VERS_EVENT                  = {eis_mk_plan_gui_Event}
VERS_EVENT.eis_mk_plan_gui    = Self
VERS_EVENT.Type             = "VERS"
VERSButton                  = WIDGET_BUTTON(help_menu,                      $
                                    value       = 'Version...',             $
                                    Event_Pro   = 'eis_mk_plan_gui_EV',     $
                                    uValue      = VERS_EVENT)

ENVVAR_EVENT               = {eis_mk_plan_gui_Event}
ENVVAR_EVENT.eis_mk_plan_gui    = Self
ENVVAR_EVENT.Type          = "ENVVAR"
value = 'View Environment Variables...'
ENVVARButton               = WIDGET_BUTTON(help_menu                 ,     $
                                   value       = value               ,     $
                                   Event_Pro   = Event_Pro           ,     $
                                   uValue      = ENVVAR_EVENT        ,     $
                                   /SEPARATOR)

INTERNAL_GUI_EVENT            = {eis_mk_plan_gui_Event}
INTERNAL_GUI_EVENT.eis_mk_plan_gui  = Self
INTERNAL_GUI_EVENT.Type       = "INTERNAL_GUI"
value = 'View Internal info...'
INTERNAL_GUIButton            = WIDGET_BUTTON(help_menu              ,     $
                                    value       = value              ,     $
                                    Event_Pro   = Event_Pro          ,     $
                                    uValue      = INTERNAL_GUI_EVENT)

TL_GUI_EVENT               = {eis_mk_plan_gui_Event}
TL_GUI_EVENT.eis_mk_plan_gui  = Self
TL_GUI_EVENT.Type          = "TL_GUI"
value = 'View TL Entry info...'
TL_GUIButton               = WIDGET_BUTTON(help_menu              ,     $
                                    value       = value              ,     $
                                    Event_Pro   = Event_Pro          ,     $
                                    uValue      = TL_GUI_EVENT)

RESP_GUI_EVENT             = {eis_mk_plan_gui_Event}
RESP_GUI_EVENT.eis_mk_plan_gui  = Self
RESP_GUI_EVENT.Type        = "RESP_GUI"
value = 'View Response DB info...'
RESP_GUIButton             = WIDGET_BUTTON(help_menu                 ,     $
                                   value       = value               ,     $
                                   Event_Pro   = Event_Pro           ,     $
                                   uValue      = RESP_GUI_EVENT)

LATEST_EVENT                = {eis_mk_plan_gui_Event}
LATEST_EVENT.eis_mk_plan_gui= Self
LATEST_EVENT.Type           = "LATEST"
LATESTButton                = WIDGET_BUTTON(help_menu,                      $
                                    value       = 'View Latest Changes...', $
                                    Event_Pro   = 'eis_mk_plan_gui_EV',     $
                                    uValue      = LATEST_EVENT)



; Call widget creation procedure
eis_mk_plan_widgets , Self , response = response
;
; Get default "eis_timeline_graphics_axes" srtucture
;
Self.tl_graphics.axes = eis_timeline_graphics_axes_default()
;
; Create Editable Cursor Position GUI
; Initialize it as current time
;
get_utc , utc
Self.cursor_time_gui = OBJ_NEW("eis_datetime_gui"                     ,     $
                             Self                                     ,     $
                             Self.eis_mk_plan_widgets.tl_cursorBase   ,     $
                             anytim2tai(utc)                          ,     $
                             xSize = 26)


; Set eis_timeline_container working_position = -1
Self.eis_timeline_container->setProperty , working_position = -1
Self.eis_timeline_container->setProperty , study_selected   =  0
;
; Invoke timeline graphics
;
o_eis_timeline_plot_gui = OBJ_NEW("eis_timeline_plot_gui" , Self)
o_eis_timeline_plot_gui->Realize
o_eis_timeline_plot_gui->XMANAGER
;o_eis_timeline_plot_gui->initialize_plot
Self.o_eis_timeline_plot_gui = o_eis_timeline_plot_gui

; Invoke Plan Summary GUI
Self.o_ct_summary = OBJ_NEW("eis_ct_summary_gui" , Self)
Self.o_ct_summary->Realize
Self.o_ct_summary->XMANAGER

Self.saa_check = 1
Self.num_days  = 4
Self.repoint_buffer  = 120.  ; 2 mins
Self.repoint_warning = 0B
Self.logo_fileName = concat_dir(GETENV('ancillary') , 'hinode_small.jpg')

; Set default values for cpt_str
Self.cpt_str.observer      = 'Unkown'
Self.cpt_str.planner       = 'Unkown'
Self.cpt_str.tohban        = 'Unkown'
Self.cpt_str.opogPassNum   = '0001'
Self.cpt_str.obstblPassNum = '0001'

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



RETURN, 1

END
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_mk_plan_gui_Cleanup , wid

WIDGET_CONTROL , wid , get_uvalue = eis_mk_plan_gui_Event
OBJ_DESTROY    , eis_mk_plan_gui_Event.eis_mk_plan_gui

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


END
;______________________________________________________________________________
; Cleanup
;______________________________________________________________________________
PRO eis_mk_plan_gui::CleanUp

OBJ_DESTROY , Self.eis_timeline_container

print,'+++++++++++++++++++++++++++++++'


; Re-pointing Pointer may contain an array of pointers - if so,
; kill them first. However, be careful, the first pointer in that
; array may be zero - and not the usual structure.
;
; JAR 6-Feb-2008
IF (PTR_VALID(Self.rpev) EQ 1) THEN BEGIN

   FOR i = 0, N_ELEMENTS(*Self.rpev) -1 DO BEGIN

       IF (PTR_VALID((*Self.rpev)[i]) EQ 1) THEN PTR_FREE , (*Self.rpev)[i]

   ENDFOR
ENDIF
PTR_FREE    , Self.rpev
PTR_FREE    , Self.opev
PTR_FREE    , Self.stev
PTR_FREE    , Self.obev
PTR_FREE    , Self.saa_ptr
PTR_FREE    , Self.ngt_ptr

OBJ_DESTROY , Self.eis_event_gui
OBJ_DESTROY , Self.eis_flare_gui
OBJ_DESTROY , Self.xrt_flare_gui

OBJ_DESTROY , Self.o_def_ct
OBJ_DESTROY , Self.cursor_time_gui

; Summary Tool
OBJ_DESTROY , Self.o_ct_summary
wait , 0.1
; DR GUI
OBJ_DESTROY , Self.dr_gui
wait , 0.1
; CPT GUI
OBJ_DESTROY , Self.cpt_gui
wait , 0.1
; Timeline Plot
OBJ_DESTROY , Self.o_eis_timeline_plot_gui
wait , 0.1

OBJ_DESTROY , Self.eis_mk_plan_ini

print,'EIS Planning Tools shut down!'
print,'+++++++++++++++++++++++++++++++'

;numItems = Self.rasterUndo->count()
;undoArray = Self.rasterUndo->get(/ALL)
;FOR i = 0 , numItems - 1 DO OBJ_DESTROY , undoArray[i]
;Self.rasterUndo->remove , /ALL
;OBJ_DESTROY , Self.rasterUndo

END
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_mk_plan_gui::setProperty                                    ,      $
                     eis_xrt_flare_control = eis_xrt_flare_control  ,      $
                     eis_event_control     = eis_event_control      ,      $
                     eis_flare_control     = eis_flare_control      ,      $
;                     cursor_time           = cursor_time           ,      $
                     eis_mk_plan_widgets   = eis_mk_plan_widgets    ,      $
                     tl_graphics           = tl_graphics            ,      $
                     sci_obj               = sci_obj                ,      $
                     text_input            = text_input             ,      $
                     opev                  = opev                   ,      $
                     replot                = replot                 ,      $
                     num_days              = num_days               ,      $
                     saa_check             = saa_check              ,      $
                     logo_fileName         = logo_fileName          ,      $
                     meta_str              = meta_str               ,      $
                     cpt_str               = cpt_str                ,      $
                     sot_offset            = sot_offset

widIDs = Self.eis_mk_plan_widgets

IF (N_ELEMENTS(sot_offset)    GT 0) THEN BEGIN
   Self.sot_offset = sot_offset
   ; Now update the timeline gui with the new SOT offset values
   Self.o_eis_timeline_plot_gui->update_sot_offset

ENDIF

IF (N_ELEMENTS(logo_fileName) GT 0) THEN Self.logo_fileName = logo_fileName
IF (N_ELEMENTS(saa_check)     GT 0) THEN Self.saa_check  = saa_check
IF (N_ELEMENTS(num_days)      GT 0) THEN Self.num_days   = num_days
IF (N_ELEMENTS(replot)        GT 0) THEN Self.replot     = replot
IF (N_ELEMENTS(meta_str)      GT 0) THEN Self.meta_str   = meta_str
IF (N_ELEMENTS(cpt_str)       GT 0) THEN Self.cpt_str    = cpt_str

IF (N_ELEMENTS(opev) GT 0) THEN BEGIN

    PTR_FREE , Self.opev
    Self.opev = PTR_NEW(opev)

ENDIF

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

; IF (N_ELEMENTS(cursor_time) GT 0) THEN BEGIN
;     stop
;     Self.cursor_time = cursor_time
; ENDIF


IF (N_ELEMENTS(text_input) GT 0) THEN BEGIN

    Self.eis_timeline_container->getProperty, working_position = wp
    count = Self.eis_timeline_container->count()

    IF (wp EQ -1)    THEN RETURN
    IF (wp GE count) THEN stop

    temp = Self.eis_timeline_container->get(position = wp)
    s    = temp->get()

    CASE text_input.title OF
        'obstitle' : temp->update_obstitle , text_input.str
        'obs_dec'  : temp->update_obs_dec  , text_input.str
        ELSE       : stop
    ENDCASE

ENDIF
IF (N_ELEMENTS(sci_obj) GT 0) THEN BEGIN

    Self.eis_timeline_container->getProperty, working_position = wp
    count = Self.eis_timeline_container->count()

    IF (wp EQ -1)    THEN RETURN
    IF (wp GE count) THEN stop

    temp = Self.eis_timeline_container->get(position = wp)
    s    = temp->get()

    ;Reset OBJ here!!!!!
    temp->update_sci_obj , sci_obj

    ; Update widget value
    WIDGET_CONTROL , widIDs.st_sci_objLabelID , set_value = STRTRIM(sci_obj,2)


ENDIF

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

IF (N_ELEMENTS(eis_flare_control) GT 0) THEN BEGIN

    ; Save new control structure
    Self.eis_flare_control = eis_flare_control

    ; Need to know which raster was selected. This is the currently
    ; selected raster in the raster list
    widIDs   = Self.eis_mk_plan_widgets
    index = WIDGET_INFO(widIDs.pl_raListID , /LIST_SELECT)

    Self.eis_timeline_container->getProperty, working_position = wp
    temp = Self.eis_timeline_container->get(position = wp)
    tl   = temp->get()
    sc   = tl.science_component
    sra  = tl.science_component.studyRasters[index]

    ; Study Tags
    sc.eis_flare_response.response_study_id    = eis_flare_control.response_identifier
    sc.eis_flare_response.repoint_raster_index = eis_flare_control.raster_identifier
    sc.eis_flare_response.x_repoint            = eis_flare_control.adjust_x
    sc.eis_flare_response.y_repoint            = eis_flare_control.adjust_y

    ; StudyRasters Tags
    sra.eis_flare_props.x_pixel_threshold      = eis_flare_control.x_threshold
    sra.eis_flare_props.y_pixel_threshold      = eis_flare_control.y_threshold
    sra.eis_flare_props.x_min_limit            = eis_flare_control.x_min_limit
    sra.eis_flare_props.y_min_limit            = eis_flare_control.y_min_limit
    sra.eis_flare_props.x_centre               = eis_flare_control.locate_x
    sra.eis_flare_props.y_centre               = eis_flare_control.locate_y

    ; Update "line_index" as sra.eis_flare_props.flare_flag
    sra.eis_flare_props.flare_flag = BYTARR(25)
    sra.eis_flare_props.flare_flag[eis_flare_control.line_index] = 1

    ; Reset OBJ here!!!!! Update value - and re-calculate study duration
    tl.science_component                     = sc
    tl.science_component.studyRasters[index] = sra
    temp->set , tl

    ; Redraw timeline graphics
    Self->initialize_plot

END


IF (N_ELEMENTS(eis_event_control) GT 0) THEN BEGIN

    ; Save new control structure
    Self.eis_event_control = eis_event_control

    ; Need to know which raster was selected. This is the currently
    ; selected raster in the raster list
    widIDs   = Self.eis_mk_plan_widgets
    index = WIDGET_INFO(widIDs.pl_raListID , /LIST_SELECT)

    Self.eis_timeline_container->getProperty, working_position = wp
    temp = Self.eis_timeline_container->get(position = wp)
    tl   = temp->get()
    sc   = tl.science_component
    sra  = tl.science_component.studyRasters[index]

    ; Study Tags
    sc.eis_event_response.response_study_id    = eis_event_control.response_identifier
    sc.eis_event_response.repoint_raster_index = eis_event_control.raster_identifier
    sc.eis_event_response.x_repoint            = eis_event_control.adjust_x
    sc.eis_event_response.y_repoint            = eis_event_control.adjust_y

    ; StudyRasters Tags
    sra.eis_event_props.x_pixel_threshold      = eis_event_control.x_threshold
    sra.eis_event_props.y_pixel_threshold      = eis_event_control.y_threshold
    sra.eis_event_props.x_min_limit            = eis_event_control.x_min_limit
    sra.eis_event_props.y_min_limit            = eis_event_control.y_min_limit

    ; Update "line_index" as sra.eis_event_props.event_flag
    sra.eis_event_props.event_flag = BYTARR(25)
    sra.eis_event_props.event_flag[eis_event_control.line_index] = 1

    ; Reset OBJ here!!!!! Update value - and re-calculate study duration
    tl.science_component                     = sc
    tl.science_component.studyRasters[index] = sra
    temp->set , tl

    ; Redraw timeline graphics
    Self->initialize_plot

END

IF (N_ELEMENTS(eis_xrt_flare_control) GT 0) THEN BEGIN

    ; Save new control structure
    Self.eis_xrt_flare_control = eis_xrt_flare_control

    ; Need to know which raster was selected. This is the currently
    ; selected raster in the raster list
    widIDs   = Self.eis_mk_plan_widgets
    index = WIDGET_INFO(widIDs.pl_raListID , /LIST_SELECT)

    Self.eis_timeline_container->getProperty, working_position = wp
    temp = Self.eis_timeline_container->get(position = wp)
    tl   = temp->get()
    sc   = tl.science_component
    sra  = tl.science_component.studyRasters[index]

    ; Study Tags
    sc.xrt_flare_response.response_study_id    = eis_xrt_flare_control.response_identifier
    sc.xrt_flare_response.repoint_raster_index = eis_xrt_flare_control.raster_identifier
    sc.xrt_flare_response.x_repoint            = eis_xrt_flare_control.adjust_x
    sc.xrt_flare_response.y_repoint            = eis_xrt_flare_control.adjust_y
    sc.xrt_flare_response.xrt_flare_in_fov     = eis_xrt_flare_control.verify_fov
    sc.xrt_flare_response.follow_on_study_id   = eis_xrt_flare_control.filler_identifier

    ; Reset OBJ here!!!!! Update value - and re-calculate study duration
    tl.science_component = sc
    temp->set , tl

    ; Redraw timeline graphics
    Self->initialize_plot

ENDIF

End
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_mk_plan_gui::getProperty                                        ,   $
                       eis_xrt_flare_control   = eis_xrt_flare_control  ,   $
                       eis_event_control       = eis_event_control      ,   $
                       eis_flare_control       = eis_flare_control      ,   $
                       tlbID                   = tlbID                  ,   $
                       o_def_ct                = o_def_ct               ,   $
                       tl_graphics             = tl_graphics            ,   $
                       eis_timeline_container  = eis_timeline_container ,   $
                       cursor_time_gui         = cursor_time_gui        ,   $
                       eis_study               = eis_study              ,   $
                       o_eis_timeline_plot_gui = o_eis_timeline_plot_gui,   $
                       o_ct_summary            = o_ct_summary           ,   $
                       opev                    = opev                   ,   $
                       stev                    = stev                   ,   $
                       obev                    = obev                   ,   $
                       rpev                    = rpev                   ,   $
                       cpt_gui                 = cpt_gui                ,   $
                       move_gui                = move_gui               ,   $
                       copy_gui                = copy_gui               ,   $
                       meta_gui                = meta_gui               ,   $
                       dvol_gui                = dvol_gui               ,   $
                       delete_gui              = delete_gui             ,   $
                       replot                  = replot                 ,   $
                       repointpopup_on         = repointpopup_on        ,   $
                       num_days                = num_days               ,   $
                       saa_check               = saa_check              ,   $
                       logo_fileName           = logo_fileName          ,   $
                       meta_str                = meta_str               ,   $
                       cpt_str                 = cpt_str                ,   $
                       eis_mk_plan_ini         = eis_mk_plan_ini        ,   $
                       rpmode                  = rpmode                 ,   $
                       sot_offset              = sot_offset

eis_xrt_flare_control   = Self.eis_xrt_flare_control
eis_event_control       = Self.eis_event_control
eis_flare_control       = Self.eis_flare_control
tlbID                   = Self.tlbID
o_def_ct                = Self.o_def_ct
tl_graphics             = Self.tl_graphics
eis_timeline_container  = Self.eis_timeline_container
cursor_time_gui         = Self.cursor_time_gui
eis_study               = Self.eis_study
o_eis_timeline_plot_gui = Self.o_eis_timeline_plot_gui
o_ct_summary            = Self.o_ct_summary
opev                    = Self.opev
stev                    = Self.stev
obev                    = Self.obev
rpev                    = Self.rpev
cpt_gui                 = Self.cpt_gui
move_gui                = Self.move_gui
copy_gui                = Self.copy_gui
meta_gui                = Self.meta_gui
dvol_gui                = Self.dvol_gui
delete_gui              = Self.delete_gui
replot                  = Self.replot
repointpopup_on         = Self.repointpopup_on
num_days                = Self.num_days
saa_check               = Self.saa_check
logo_fileName           = Self.logo_fileName
meta_str                = Self.meta_str
cpt_str                 = Self.cpt_str
eis_mk_plan_ini         = Self.eis_mk_plan_ini
rpmode                  = Self.rp
sot_offset              = Self.sot_offset


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

    Return, Self.tlbID
End

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

Widget_Control, Self.tlbID, _Extra=Widget_Control_Keywords

End

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

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

End

;______________________________________________________________________________
; Realize wrapper
;______________________________________________________________________________
PRO eis_mk_plan_gui::Realize

Widget_Control, Self.tlbID, /Realize

End

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

    XManager,"eis_mk_plan_gui" ,   Self.tlbID ,                         $
                     Event_Handler  = "eis_mk_plan_gui_EV",  $
        cleanup        = "eis_mk_plan_gui_Cleanup",                           $
        GROUP_LEADER   = group ,                                            $
        /NO_BLOCK

end

;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_mk_plan_gui_Event__Define

    struct = {  eis_mk_plan_gui_Event,                                    $
                Type                : "",                                   $
                eis_mk_plan_gui   : OBJ_NEW(),                            $
                extra               : 0                                     $
             }
END
;______________________________________________________________________________
; Event Handler wrapper
;______________________________________________________________________________
PRO eis_mk_plan_gui_EV , Event

;Get event handler structure containing eis_mk_plan_gui type object
Widget_CONTROL,Event.ID,get_uvalue = eis_mk_plan_gui_Event
IF (TAG_NAMES(event, /STRUCTURE_NAME) EQ 'WIDGET_TIMER') THEN BEGIN

    WIDGET_CONTROL , event.id , get_uValue = point_stc
    MESSAGE , 'Pointing structure received from pointing tool',/cont

    Widget_CONTROL,Event.top,get_uvalue = eis_mk_plan_gui_Event
    ;eis_mk_plan_gui_Event.Type = 'UPDATE_STC'
    ;eis_mk_plan_gui_Event.eis_mk_plan_gui->setTimer
    ;RETURN
ENDIF
;If a WIDGET_TAB event , just quit
IF (TAG_NAMES(event, /STRUCTURE_NAME) EQ 'WIDGET_TAB') THEN RETURN

;Call eis_mk_plan_gui's class member procedure "Handler"
eis_mk_plan_gui_Event.eis_mk_plan_gui->Handler,Event

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

;Get event handler structure containing eis_mk_plan_gui type object
Widget_CONTROL,Event.ID,get_uvalue = eis_mk_plan_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_plan_gui's class member procedure "Handler"
eis_mk_plan_gui_Event.eis_mk_plan_gui->HandlerUpdate,Event

END
;______________________________________________________________________________
PRO eis_mk_plan_gui::HandlerUpdate, Event

WIDGET_CONTROL, Event.ID, Get_UValue = eis_mk_plan_gui_Event
CASE eis_mk_plan_gui_Event.Type OF
    "STUDY_REMOVE"      : valid = Self->remove_study()
    "STUDY_REMOVE_ALL"  : valid = Self->remove_all_entries()
    "TT_ENABLE"         : valid = Self->enableTimeTagging()
    "TT_DISABLE"        : valid = Self->disableTimeTagging()
    "FIVEPC_ENABLE"     : valid = Self->five_pc_enable()
    "FIVEPC_DISABLE"    : valid = Self->five_pc_disable()
    "X_POINT"           : valid = Self->update_x_point()
    "Y_POINT"           : valid = Self->update_y_point()
    "MIPTEXT"           : valid = Self->update_mip()
    "YIPTEXT"           : valid = Self->update_yip()
    "REPEATS"           : valid = Self->update_ra_repeats()
    "COMP"              : valid = Self->update_ra_compression(event)
    "RESET_COMP"        : valid = Self->reset_ra_compression()
    "XRTFLARE"          : valid = Self->toggleXRTFlare()
    "AECEVENT"          : valid = Self->toggleAECEvent()
    "EISFLARE"          : valid = Self->toggleEISFlare()
    "EISEVENT"          : valid = Self->toggleEISEvent()
    "ST_MOVE_CP"        : valid = Self->move_study_to_cp()
    "ST_COPY_CP"        : valid = Self->copy_study_to_cp()
    "OBS_ID"            : valid = Self->update_obs_id()
    "JOP_ID"            : valid = Self->update_jop_id()
    "NOAA_NUM"          : valid = Self->update_noaa_num()
    "OBSTITLE"          : valid = Self->update_obstitle()
    "OBS_DEC"           : valid = Self->update_obs_dec()
    "POINTMODE"         : valid = Self->update_point_mode()
    ELSE                : print,eis_mk_plan_gui_Event.Type
ENDCASE

IF (valid EQ 1) THEN Self->eis_raster_update

END
;______________________________________________________________________________
PRO eis_mk_plan_gui::eis_raster_update

;; Get Duration and Volume
;Self->updateDurationAndVolume
;; Update line list
;Self->updateLineListWidget
;; Generate and update title
;Self->updateRasterTitle
;;WIDGET_CONTROL , Self.eis_mk_plan_widgets.ra_titleID ,                $
;;                    set_value = eis_generate_raster_title(Self.eis_raster)
;; Finally, save a copy of the current eis_raster
;oRasterItem = OBJ_NEW("eis_plan_undo" , Self.eis_raster)
;Self.rasterUndo->ADD , oRasterItem

END
;______________________________________________________________________________
;
; * THIS is the routine for putting in event handling NOT eis_mk_plan_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_plan_gui::Handler, Event

; Looking at tlbID for an eventID with the value of child
child = WIDGET_INFO(Self.tlbID,/CHILD)
IF (WIDGET_INFO(child , /VALID) EQ 1) THEN BEGIN

    IF (event.id EQ child) THEN BEGIN

        WIDGET_CONTROL , child , get_uValue = point_stc
        ; Call method to process updated stc
        Self->update_pointing , point_stc

        RETURN

    ENDIF
ENDIF

IF (KEYWORD_SET(event) EQ 1) THEN BEGIN
    ; Trap CONTEXT events here
    widgetType = TAG_NAMES(event, /STRUCTURE_NAME)
    IF (widgetType EQ 'WIDGET_CONTEXT') THEN BEGIN
        Self->rasterContextSensitiveMenu , event
        RETURN
    END
ENDIF


WIDGET_CONTROL, Event.ID, Get_UValue = eis_mk_plan_gui_Event
CASE eis_mk_plan_gui_Event.Type OF
    "QUIT"             : Self->quit
    "PLAN_PLOT"        : Self->invoke_timeline_plot
    "CT_GUI"           : Self->planSummary
    "TLB"              :
    "CPT_GUI"          : Self->cpt_gui
    "STSEARCHDB"       : Self->searchStudyDBGUI
    "ASCII"            : Self->asciiSave
    "DESC"             : Self->studyDescription
    "DURATIONUNITS"    : Self->setDurationUnits,eis_mk_plan_gui_Event.extra
    "VOLUMEUNIT"       : Self->updateDurationAndVolume
    "STOP"             : stop
    "EXPORT_PLAN"      : eis_export_timeline , Self.eis_timeline_container
    "IMPORT_PLAN"      : print,'not yet!'
    "READ_DATABASE"    : Self->readPlanFromDatabase
    "HELP"             : Self->displayHelp
    "XDOC"             : xdoc , group = Self.tlbID
    "PREF"             : Self->invoke_pref_gui
    "STRESS"           : Self->invoke_stress_gui
    "LATEST"           : Self->latest_changes
    "VERS"             : Self->version
    "SAVE_PLAN"        : Self->savePlanToDatabase
    "OP_GUI"           : Self->op_gui
    "RA_LIST"          : Self->selectStudyRaster , event;.index
    "SCI_OBJ"          : Self->sci_obj
    "TARGET"           : Self->target
    "JOIN_SB"          : Self->join_sb
    "POINTING"         : Self->pointing_gui
    "DR"               : Self->create_dr_file
    "IMAGE_TOOL"       : Self->image_tool_event
    "IM_TOOL_EVENT"    : Self->image_tool_event
    "RA_DETAILS"       : Self->ra_details
    "REPOINTPOPUPON"   : Self->repoint_popup_on
    "REPOINTPOPUPOFF"  : Self->repoint_popup_off
    "ASRC_ENABLE"      : Self->asrc_enable
    "ASRC_DIR"         : Self->asrc_direction , event
    "ASRC_SKIP"        : Self->asrc_skip      , event
    "ASRC_NSTEPS"      : Self->asrc_nsteps    , event
    "REPOINT_TOMORROW" : Self->repoint_tomorrow
    "OP_TOMORROW"      : Self->op_tomorrow
    "SAA_TOMORROW"     : Self->saa_tomorrow
    "NGT_TOMORROW"     : Self->ngt_tomorrow
    "ALL_TOMORROW"     : Self->all_tomorrow
    "REPOINT_TODAY"    : Self->repoint_today
    "OP_TODAY"         : Self->op_today
    "SAA_TODAY"        : Self->saa_today
    "NGT_TODAY"        : Self->ngt_today
    "ALL_TODAY"        : Self->all_today
    "ST_MMOVE_CP"      : Self->invoke_move_multiple_tl_gui
    "ST_MCOPY_CP"      : Self->invoke_copy_multiple_tl_gui
    "ST_MDELETE_CP"    : Self->invoke_delete_multiple_tl_gui
    "ST_MMETA_CP"      : Self->invoke_meta_multiple_tl_gui
    "ST_MDVOL_CP"      : Self->invoke_dvol_multiple_tl_gui
    "INTERNAL_GUI"     : Self->invoke_internal_gui
    "TL_GUI"           : Self->invoke_tl_gui
    "RESP_GUI"         : Self->invoke_response_gui
    "OBEV_WINDOWS"     : Self->view_obev_windows
    "EISAIA_VIEW"      : Self->view_eis_aia_offsets_gui
    "ENVVAR"           : Self->view_env_variables
    "VIEW_RP_LOG"      : Self->view_rp_log
    "VIEW_EISCO_LOG"   : Self->view_eisco_log
    "RA_SEARCH"        : Self->ra_search
    "EISE_PROPS"       : Self->invoke_eis_event_gui
    "EISF_PROPS"       : Self->invoke_eis_flare_gui
    "XRTF_PROPS"       : Self->invoke_xrt_flare_gui
    "CHECK_RESPONSE"   : Self->check_event_properties
    ELSE               : print,eis_mk_plan_gui_Event.Type
ENDCASE
END
;______________________________________________________________________________
; Check Trigger/Response Properties are valid
;______________________________________________________________________________
PRO eis_mk_plan_gui::check_event_properties

triggers = Self.eis_timeline_container->detect_trigger_studies(/QUIET)
IF (N_TAGS(triggers[0]) EQ 0) THEN BEGIN
   print,'No Trigger/Response Studies'
   RETURN
ENDIF

; JAR 7-Sep-2011
; Need to restrict tlc to start and stop time of timeline plot
; Use cpt method of creating a new and temporary cpt_tlc.
; Don't forget to destroy this object. It's only being created and
; used here to test the validity of the response tables.
tlc     = Self.eis_timeline_container
all_tlc_entries = tlc->get(/ALL)
; Need to get datetime_start and datetime_stop from timeline axes
datetime_start = Self.tl_graphics.axes.x_axis_day_tai
datetime_stop  = Self->get_disp_stop()
; Time to do it
cpt_tlc = OBJ_NEW('EIS_TIMELINE_CONTAINER' , Self)
FOR i = 0 , tlc->count() -1 DO BEGIN

    s = all_tlc_entries[i]->get()

    IF (s.time_component.start_time LE datetime_stop  ) AND                 $
       (s.time_component.start_time GE datetime_start ) THEN BEGIN
        IF (s.time_component.entry_type EQ 'S') OR                          $
           (s.time_component.entry_type EQ 'E') THEN BEGIN

            all_tlc_entries[i]->set , s
            ; If within CPT time range, then save to cpt_tlc
            cpt_tlc->add , all_tlc_entries[i]

        ENDIF
    ENDIF
ENDFOR

count = cpt_tlc->count()
; OK, make sure we have read all of the science components
FOR i = 0 , count -1 DO BEGIN

    temp = cpt_tlc->get(POSITION = i)
    temp->getProperty , seq_id = seq_id
    print,'CPTing seq_id = ' + STRCOMPRESS(seq_id,/REMOVE_ALL)
    tl   = temp->get()
    tc   = tl.time_component
    IF (tc.read_all NE 1) THEN temp->get_all_info

ENDFOR

; OK, got cpt_tlc. Now get triggers for only these entries.
triggers = cpt_tlc->detect_trigger_studies(/QUIET)

; 1. Instantiate "eis_response_obj" object
eis_response_obj = OBJ_NEW("eis_response_obj" , cpt_tlc , triggers)
; 2. Test the response parameters are valid
valid = eis_response_obj->check_is_valid()
IF (valid EQ 1) THEN BEGIN
   print,''
   print,'Trigger/Response Events are Valid. Continuing...'
   print,'********************************************************'
ENDIF ELSE BEGIN
   print,''
   print,'Trigger/Response Events are NOT Valid.'
   print,'CPT will NOT be successful.'
   print,'********************************************************'
   ; Cleanup and destroy "cpt_tlc" and "eis_response_obj" objects
   ; and bail out
   cpt_tlc->REMOVE , /ALL
   OBJ_DESTROY , cpt_tlc
   OBJ_DESTROY , eis_response_obj
   RETURN

ENDELSE

; 3. If valid, then get "eis_control" structure {eis_control_details}
; This is only temporary for testing purposes!!!!!!!!
; Call eis_response_obj method to create the eis_control structure
eis_control = eis_response_obj->get_eis_control()

; 4. Finally, destroy "eis_response_obj" object
OBJ_DESTROY , eis_response_obj

; Destroy cpt_tlc object
cpt_tlc->REMOVE , /ALL
OBJ_DESTROY , cpt_tlc


END
;______________________________________________________________________________
; Raster Search
;______________________________________________________________________________
PRO eis_mk_plan_gui::ra_search

eis_filter_studies = OBJ_NEW("eis_filter_studies" , parentClass = Self)
eis_filter_studies->Realize
eis_filter_studies->XMANAGER
eis_filter_studies->read_ra_db
eis_filter_studies->apply
eis_filter_studies->get_study_info

END
;______________________________________________________________________________
; View EISCO archive Log
;______________________________________________________________________________
PRO eis_mk_plan_gui::view_eisco_log

;fileName   = EXPAND_PATH("$HOME/eis_rp_archive/eis_rp_archive_log.txt")
; JAR 6-May-2009 - create log file name
pathName = STRJOIN([GETENV('HOME'),'eis_rp_archive'] ,/SINGLE ,PATH_SEP())
fileName = CONCAT_DIR(pathName , 'eis_rp_archive_log.txt')

IF (FILE_TEST(fileName) NE 1) THEN BEGIN
    BEEP
    mText = DIALOG_MESSAGE( "Can't find file. Aborting!"             ,     $
                     DIALOG_PARENT = Self.tlbID                      ,     $
                     /ERROR )
    RETURN
ENDIF

pt_version = eis_get_pt_version_number()
title      = "EISCO Archiving Log" + pt_version

XDISPLAYFILE , fileName , group = Self.tlbID , title = title

END
;______________________________________________________________________________
; View RP Startup Log
;______________________________________________________________________________
PRO eis_mk_plan_gui::view_rp_log

;fileName = EXPAND_PATH("$HOME/eis_mk_plan_rp.log")
; JAR 6-May-2009 - create log file name
fileName  = CONCAT_DIR(GETENV('HOME') , 'eis_mk_plan_rp.log')

IF (FILE_TEST(fileName) NE 1) THEN BEGIN
    BEEP
    mText = DIALOG_MESSAGE( "Can't find file. Aborting!"             ,     $
                     DIALOG_PARENT = Self.tlbID                      ,     $
                     /ERROR )
    RETURN
ENDIF

pt_version = eis_get_pt_version_number()
title      = "Remote Planning Startup Log" + pt_version

XDISPLAYFILE , fileName , group = Self.tlbID , title = title

END
;______________________________________________________________________________
; View OP Period Info
;______________________________________________________________________________
PRO eis_mk_plan_gui::op_gui

op_gui = OBJ_NEW("eis_op_gui" , Self)
op_gui->Realize
op_gui->XMANAGER
op_gui->apply

END
;______________________________________________________________________________
; View Environment Variables
;______________________________________________________________________________
PRO eis_mk_plan_gui::view_env_variables

env_var = OBJ_NEW("eis_env_var_gui" , Self , rp = Self.rp)
env_var->Realize
env_var->XMANAGER

END
;______________________________________________________________________________
; Setup Remote Planning
;______________________________________________________________________________
PRO eis_mk_plan_gui::rp_setup

; Change IDL prompt to remind planners.
!PROMPT = "EIS_RP_IDL>"


END
;______________________________________________________________________________
; Invoke EIS-AIA Offsets GUI
;______________________________________________________________________________
PRO eis_mk_plan_gui::view_eis_aia_offsets_gui

; OK, let's find the file. It has a fixed name and location.
basename = 'eis_aia_avgoffsets.txt'
pathname = STRJOIN([GETENV("SSW")                      ,           $
                    'hinode','eis','data','eis_aia_offset'], $
                 PATH_SEP(),/SINGLE)
filename = CONCAT_DIR(pathname,basename)

IF (FILE_TEST(fileName) EQ 1) THEN BEGIN
   XDISPLAYFILE , fileName                                             ,   $
                   group  = Self.tlbID                                 ,   $
                   title  = filename                                   ,   $
                   height = 40                                         ,   $
                   width  = 70
ENDIF ELSE BEGIN
    BEEP
    mText = "Can't read file 'eie_aia_avgoffsets.txt'"
    complain = DIALOG_MESSAGE( mText                                   ,   $
                     DIALOG_PARENT = Self.tlbID                        ,   $
                     /ERROR )
    RETURN

ENDELSE

END
;______________________________________________________________________________
; Invoke Preferences GUI
;______________________________________________________________________________
PRO eis_mk_plan_gui::view_obev_windows

obev = OBJ_NEW("eis_obev_gui" , Self)
obev->Realize
obev->XMANAGER
obev->refresh

END
;______________________________________________________________________________
; Invoke Preferences GUI
;______________________________________________________________________________
PRO eis_mk_plan_gui::invoke_pref_gui , set_tab_index = set_tab_index

; Invoke Preferences GUI
tl_gui = OBJ_NEW("eis_prefs_gui" , Self , set_tab_index = set_tab_index)
tl_gui->Realize
tl_gui->XMANAGER
tl_gui->logo_draw

END
;______________________________________________________________________________
; Invoke Stress Management GUI
;______________________________________________________________________________
PRO eis_mk_plan_gui::invoke_stress_gui

; Invoke Stress Management GUI
stress_gui = OBJ_NEW("eis_stress_gui" , Self)
stress_gui->Realize
stress_gui->XMANAGER
stress_gui->draw

END
;______________________________________________________________________________
; View TL Entry GUI
;______________________________________________________________________________
PRO eis_mk_plan_gui::invoke_response_gui

eis_response_db_gui = OBJ_NEW("eis_response_db_obj" , parentClass = Self)
eis_response_db_gui->Realize
eis_response_db_gui->XMANAGER
eis_response_db_gui->refresh

END
;______________________________________________________________________________
; View TL Entry GUI
;______________________________________________________________________________
PRO eis_mk_plan_gui::invoke_tl_gui

; Get working_position (index of selected study) and hence seq_id
Self.eis_timeline_container->getProperty, working_position = wp
temp   = Self.eis_timeline_container->get( position = wp)
tl     = temp->get()
seq_id = tl.time_component.sequence_id
IF (seq_id LT 5) THEN BEGIN
   status = eis_open_db(/TIME)
   n      = db_info('entries')
   seq_id = n[0]
ENDIF

; Invoke EIS Event GUI
tl_gui = OBJ_NEW("eis_tl_entry_gui" , parentClass = Self , seq_id = seq_id)
tl_gui->Realize
tl_gui->XMANAGER
tl_gui->refresh

END
;______________________________________________________________________________
; View Internal stuff
;______________________________________________________________________________
PRO eis_mk_plan_gui::invoke_internal_gui

; Invoke EIS Event GUI
internal_gui = OBJ_NEW("eis_internal_gui" , Self)
internal_gui->Realize
internal_gui->XMANAGER
internal_gui->refresh

END
;______________________________________________________________________________
; Invoke Metadata multiple TL entries GUI
;______________________________________________________________________________
PRO eis_mk_plan_gui::invoke_meta_multiple_tl_gui

; Ensure we only have 1 GUI
IF (OBJ_VALID(Self.meta_gui) EQ 1) THEN RETURN
count = Self.eis_timeline_container->count()
IF (count EQ 0) THEN BEGIN
    BEEP
    complain = DIALOG_MESSAGE( 'There are NO timeline entries. Aborting!' ,$
                     DIALOG_PARENT = Self.tlbID,                            $
                     /ERROR )
    RETURN
ENDIF


valid_cpt_gui = XREGISTERED("eis_cpt_gui")
IF (valid_cpt_gui EQ 1) THEN BEGIN
    BEEP
    mText = "The CPT GUI must be dismissed. Aborting!"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF
IF (OBJ_VALID(Self.move_gui) EQ 1) THEN BEGIN
    BEEP
    mText = "The Move GUI must be dismissed. Aborting!"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF
IF (OBJ_VALID(Self.copy_gui) EQ 1) THEN BEGIN
    BEEP
    mText = "The Copy GUI must be dismissed. Aborting!"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF
IF (OBJ_VALID(Self.delete_gui) EQ 1) THEN BEGIN
    BEEP
    mText = "The Delete GUI must be dismissed. Aborting!"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF

; Invoke EIS Event GUI
Self.meta_gui = OBJ_NEW("eis_meta_tl_gui" , Self)
Self.meta_gui->Realize
Self.meta_gui->XMANAGER

; Redraw timeline graphics
Self->initialize_plot

END
;______________________________________________________________________________
; Invoke Data Volume multiple TL entries GUI
;______________________________________________________________________________
PRO eis_mk_plan_gui::invoke_dvol_multiple_tl_gui

; Ensure we only have 1 GUI
IF (OBJ_VALID(Self.dvol_gui) EQ 1) THEN RETURN
count = Self.eis_timeline_container->count()
IF (count EQ 0) THEN BEGIN
    BEEP
    complain = DIALOG_MESSAGE( 'There are NO timeline entries. Aborting!' ,$
                     DIALOG_PARENT = Self.tlbID,                            $
                     /ERROR )
    RETURN
ENDIF

; Invoke EIS Event GUI
Self.dvol_gui = OBJ_NEW("eis_dvol_tl_gui" , Self)
Self.dvol_gui->Realize
Self.dvol_gui->XMANAGER

; Redraw timeline graphics
Self->initialize_plot

END
;______________________________________________________________________________
; Invoke Delete multiple TL entries GUI
;______________________________________________________________________________
PRO eis_mk_plan_gui::invoke_delete_multiple_tl_gui

; Ensure we only have 1 GUI
IF (OBJ_VALID(Self.delete_gui) EQ 1) THEN RETURN
count = Self.eis_timeline_container->count()
IF (count EQ 0) THEN BEGIN
    BEEP
    complain = DIALOG_MESSAGE( 'There are NO timeline entries. Aborting!' ,$
                     DIALOG_PARENT = Self.tlbID,                            $
                     /ERROR )
    RETURN
ENDIF


valid_cpt_gui = XREGISTERED("eis_cpt_gui")
IF (valid_cpt_gui EQ 1) THEN BEGIN
    BEEP
    mText = "The CPT GUI must be dismissed. Aborting!"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF
IF (OBJ_VALID(Self.move_gui) EQ 1) THEN BEGIN
    BEEP
    mText = "The Move GUI must be dismissed. Aborting!"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF
IF (OBJ_VALID(Self.copy_gui) EQ 1) THEN BEGIN
    BEEP
    mText = "The Move GUI must be dismissed. Aborting!"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF
IF (OBJ_VALID(Self.meta_gui) EQ 1) THEN BEGIN
    BEEP
    mText = "The Metadata GUI must be dismissed. Aborting!"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF

; Invoke EIS Event GUI
Self.delete_gui = OBJ_NEW("eis_delete_tl_gui" , Self)
Self.delete_gui->Realize
Self.delete_gui->XMANAGER

; Redraw timeline graphics
Self->initialize_plot

END
;______________________________________________________________________________
; Invoke Copy multiple TL entries GUI
;______________________________________________________________________________
PRO eis_mk_plan_gui::invoke_copy_multiple_tl_gui

; Ensure we only have 1 GUI
IF (OBJ_VALID(Self.copy_gui) EQ 1) THEN RETURN
count = Self.eis_timeline_container->count()
IF (count EQ 0) THEN BEGIN
    BEEP
    complain = DIALOG_MESSAGE( 'There are NO timeline entries. Aborting!' ,$
                     DIALOG_PARENT = Self.tlbID,                            $
                     /ERROR )
    RETURN
ENDIF


valid_cpt_gui = XREGISTERED("eis_cpt_gui")
IF (valid_cpt_gui EQ 1) THEN BEGIN
    BEEP
    mText = "The CPT GUI must be dismissed. Aborting!"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF
IF (OBJ_VALID(Self.move_gui) EQ 1) THEN BEGIN
    BEEP
    mText = "The Move GUI must be dismissed. Aborting!"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF
IF (OBJ_VALID(Self.delete_gui) EQ 1) THEN BEGIN
    BEEP
    mText = "The Delete GUI must be dismissed. Aborting!"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF
IF (OBJ_VALID(Self.meta_gui) EQ 1) THEN BEGIN
    BEEP
    mText = "The Metadata GUI must be dismissed. Aborting!"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF

; Invoke EIS Event GUI
Self.copy_gui = OBJ_NEW("eis_copy_tl_gui" , Self)
Self.copy_gui->Realize
Self.copy_gui->XMANAGER

; Redraw timeline graphics
Self->initialize_plot

END
;______________________________________________________________________________
; Invoke Move multiple TL entries GUI
;______________________________________________________________________________
PRO eis_mk_plan_gui::invoke_move_multiple_tl_gui

; Ensure we only have 1 GUI
IF (OBJ_VALID(Self.move_gui) EQ 1) THEN RETURN
count = Self.eis_timeline_container->count()
IF (count EQ 0) THEN BEGIN
    BEEP
    complain = DIALOG_MESSAGE( 'There are NO timeline entries. Aborting!' ,$
                     DIALOG_PARENT = Self.tlbID,                            $
                     /ERROR )
    RETURN
ENDIF


valid_cpt_gui = XREGISTERED("eis_cpt_gui")
IF (valid_cpt_gui EQ 1) THEN BEGIN
    BEEP
    mText = "The CPT GUI must be dismissed. Aborting!"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF
IF (OBJ_VALID(Self.copy_gui) EQ 1) THEN BEGIN
    BEEP
    mText = "The Copy GUI must be dismissed. Aborting!"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF
IF (OBJ_VALID(Self.delete_gui) EQ 1) THEN BEGIN
    BEEP
    mText = "The Delete GUI must be dismissed. Aborting!"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF
IF (OBJ_VALID(Self.meta_gui) EQ 1) THEN BEGIN
    BEEP
    mText = "The Metadata GUI must be dismissed. Aborting!"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF

; Invoke EIS Event GUI
Self.move_gui = OBJ_NEW("eis_move_tl_gui" , Self)
Self.move_gui->Realize
Self.move_gui->XMANAGER

; Redraw timeline graphics
Self->initialize_plot

END


;______________________________________________________________________________
; Start ini file object
;______________________________________________________________________________
PRO eis_mk_plan_gui::start_ini_obj

;
; Read ini file: $HOME/.eis_mk_plan
;
Self.eis_mk_plan_ini = OBJ_NEW("eis_mk_plan_ini" , Self)

END
;______________________________________________________________________________
; DELETE multiple TL entries
;______________________________________________________________________________
PRO eis_mk_plan_gui::apply_delete_tl_entries , tStart , tStop

;
; Get tl entries in this time range: tStart -> tStop
;
tlc = Self.eis_timeline_container
counter = tlc->count_tl_entries_in_time_range(anytim2tai(tStart) ,    $
                                              anytim2tai(tStop))
; If zero, then complain and bail!
IF (counter.counter LT 1) OR (PTR_VALID(counter.tl_list) NE 1) THEN BEGIN
    BEEP
    mText = "There are NO entries in this range. Aborting!"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF

delete_list = *counter.tl_list
time_array  = DBLARR(N_ELEMENTS(delete_list))
tlc         = Self.eis_timeline_container
FOR i = 0 , N_ELEMENTS(delete_list) - 1 DO BEGIN
    temp          = tlc->get( position = delete_list[i])
    tl            = temp->get()
    duration      = (tl.time_component.end_time - tl.time_component.start_time)
    time_array[i] = tl.time_component.start_time + (duration/2.)
ENDFOR

FOR i = 0 , N_ELEMENTS(delete_list) - 1 DO BEGIN
   ; Call eis_timeline_container method "remove_entry"
   ; Get working_position
   wp = Self.eis_timeline_container->returnSelectedStudyIndex(time_array[i])
   Self.eis_timeline_container->remove_entry, position = wp

ENDFOR

Self.eis_timeline_container->setProperty , working_position = -1   ,   $
                                           study_selected   = 0
;
; Redraw timeline graphics
Self.o_eis_timeline_plot_gui->initialize_plot
;
; Update Plan Summary Tool
;
Self->refreshSummary
Self->refresh_dr_gui
;
;
; Update widgets with values
;
Self->zeroWidgets

END
;______________________________________________________________________________
; COPY multiple TL entries
;______________________________________________________________________________
PRO eis_mk_plan_gui::apply_copy_tl_entries , tStart , tStop , tNew

;
; Get tl entries in this time range: tStart -> tStop
;
tlc = Self.eis_timeline_container
counter = tlc->count_tl_entries_in_time_range(anytim2tai(tStart) ,    $
                                              anytim2tai(tStop))
; If zero, then complain and bail!
IF (counter.counter LT 1) THEN BEGIN
    BEEP
    mText = "There are NO entries in this range. Aborting!"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF

;
; OK, got how many entries and start time of first and stop time
; of last.
;
; Now we need to make sure there are No studies in the time range
; counter.tStart_tai + tNew  -->  counter.tStop_tai + tNew
;
delT = anytim2tai(tNew) - counter.tStart_tai
new_counter = tlc->count_tl_entries_in_time_range(                          $
                           anytim2tai(counter.tStart_tai + delT)      ,     $
                           anytim2tai(counter.tStop_tai  + delT))
; If NOT zero, then existing entries must already occupy this time
; range. Complain and bail!
IF (new_counter.counter GT 0) THEN BEGIN
    BEEP
    mText = "There are existing entries in this range. Aborting!"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF

;
; OK, now it's time to COPY these entries. The entry index is included
; in the counter structure
;
; Loop over each tl entry - create an array of new tl entries - but don't
; add them here. This will screw up the tlc indexing if copying entries
; before the currently selected block!!!
;
FOR i = 0 , counter.counter - 1 DO BEGIN

    temp  = Self.eis_timeline_container->get( position = (*counter.tl_list)[i])
    tl    = temp->get()
    IF (tl.time_component.read_all NE 1) THEN BEGIN
        temp->get_all_info
        tl = temp->get()
    ENDIF

    new_time = tl.time_component.start_time + delT
;print,'Old time is: ' + anytim2utc(tl.time_component.start_time,/stime)
;print,'New time is: ' + anytim2utc(new_time,/stime)
    ;
    ; Create a new "eis_structure_container" object
    ;
    tl_new_obj = OBJ_NEW('eis_structure_container' , tl )
    tl_new_obj->set_seq_id    , seq_id = 0
    ; JAR 13-Jul-2009 - Reset time_tagged = 1, when copying study
    IF (i EQ 0) THEN tl_new_obj->set_as_time_tagged

    tl_new_obj->flag_save

    ;
    ;
    ; Update time_component tags
    ;
    CASE tl.time_component.entry_type OF
       "E" :  tl_new_obj->move_tl_eng_entry , new_time
       "S" :  tl_new_obj->move_tl_entry     , new_time
    ENDCASE

    CASE i OF
       0    : tl_new_obj_array = tl_new_obj
       ELSE : tl_new_obj_array = [ tl_new_obj_array , tl_new_obj]
    ENDCASE

ENDFOR
;
; Must add each new study here!
;
FOR i = 0 , counter.counter - 1 DO BEGIN

    ;
    ; Add entry to the tlc
    ;
    Self.eis_timeline_container->add_entry, tl_new_obj_array[i]
    Self.eis_timeline_container->setProperty, working_position = $
                                     (*counter.tl_list)[i]  ,    $
                                     study_selected = 1

ENDFOR

; Redraw timeline graphics
Self.o_eis_timeline_plot_gui->initialize_plot

; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = wp

; Update Cursor Position - set to new tl end_time. Need to refresh s
temp  = Self.eis_timeline_container->get( position = wp)
tl    = temp->get()
Self.cursor_time_gui->setProperty , datetime = tl.time_component.end_time
; Plot cursor time on timeline plot
Self.o_eis_timeline_plot_gui->plot_cursor_time
;
; Update Plan Summary Tool
;
Self->refreshSummary
Self->refresh_dr_gui

END
;______________________________________________________________________________
; Move multiple TL entries
;______________________________________________________________________________
PRO eis_mk_plan_gui::apply_move_tl_entries , tStart , tStop , tNew

;
; Get tl entries in this time range: tStart -> tStop
;
tlc = Self.eis_timeline_container
counter = tlc->count_tl_entries_in_time_range(anytim2tai(tStart) ,    $
                                              anytim2tai(tStop))
; If zero, then complain and bail!
IF (counter.counter LT 1) THEN BEGIN
    BEEP
    mText = "There are NO entries in this range. Aborting!"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF

;
; OK, got how many entries and start time of first and stop time
; of last.
;
; Now we need to make sure there are No studies in the time range
; counter.tStart_tai + tNew  -->  counter.tStop_tai + tNew
;
delT = anytim2tai(tNew) - counter.tStart_tai
new_counter = tlc->count_tl_entries_in_time_range(                          $
                           anytim2tai(counter.tStart_tai + delT)      ,     $
                           anytim2tai(counter.tStop_tai  + delT))
; If NOT zero, then existing entries must already occupy this time
; range. Complain and bail!

;stop
; 6-Jan-2009
; What if you want to
;IF (counter.counter EQ new_counter.counter) AND        $
;FOR i = 0 ,






IF (new_counter.counter GT 0) THEN BEGIN
    BEEP
    mText = "There are existing entries in this range. Aborting!"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF

;
; OK, now it's time to MOVE these entries. The entry index is included
; in the counter structure
;
; Loop over each tl entry
;
FOR i = 0 , counter.counter - 1 DO BEGIN

    temp  = Self.eis_timeline_container->get( position = (*counter.tl_list)[i])
    tl    = temp->get()
    IF (tl.time_component.read_all NE 1) THEN temp->get_all_info

    new_time = tl.time_component.start_time + delT

    CASE tl.time_component.entry_type OF
        "E" :   BEGIN
                    ; Need to update tl.start_time and tl.end_time
                    ; new_time = existing_start_time + delT
                    temp->move_tl_eng_entry , new_time
                END
        "S" :   BEGIN
                    ; Need to update tl.start_time and tl.end_time
                    ; new_time = existing_start_time + delT
                    temp->move_tl_entry , new_time
                    ; Update raster widgets
                    Self->updateStudyRasterListWidget
                END
    ENDCASE

ENDFOR

; Redraw timeline graphics
Self.o_eis_timeline_plot_gui->initialize_plot

; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = wp

; Update Cursor Position - set to new tl end_time. Need to refresh s
temp  = Self.eis_timeline_container->get( position = wp)
tl    = temp->get()
Self.cursor_time_gui->setProperty , datetime = tl.time_component.end_time
; Plot cursor time on timeline plot
Self.o_eis_timeline_plot_gui->plot_cursor_time
;
; Update Plan Summary Tool
;
Self->refreshSummary
Self->refresh_dr_gui

END
;______________________________________________________________________________
; Update Line Selection for EIS EVENT triggered studies
;______________________________________________________________________________
PRO eis_mk_plan_gui::rasterContextSensitiveMenu , event

; Get widget IDs
widIDs    = Self.eis_mk_plan_widgets
contextbase                = WIDGET_BASE(widIDs.pl_raListID ,              $
                                    /CONTEXT_MENU)


VIEW_EVENT                  = {eis_mk_plan_gui_Event}
VIEW_EVENT.eis_mk_plan_gui = Self
VIEW_EVENT.Type             = "RA_DETAILS"
value = 'View Details... '
st_rasterVIEWButton         = WIDGET_BUTTON(contextbase                ,   $
                                    value       = value                ,   $
                                    Event_Pro   = 'eis_mk_plan_gui_EV' ,   $
                                    uValue      = VIEW_EVENT)

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

END
;______________________________________________________________________________
; Update Line Selection for EIS EVENT triggered studies
;______________________________________________________________________________
PRO eis_mk_plan_gui::eise_line_select , line_index

; Set selected raster eis_flag = 0/1
widIDs   = Self.eis_mk_plan_widgets
index = WIDGET_INFO(widIDs.pl_raListID , /LIST_SELECT)

; Reset studyRasters[index].eis_event_props.event_flag
; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = wp
temp = Self.eis_timeline_container->get( position = wp)
tl   = temp->get()
sra  = tl.science_component.studyRasters[index]
sra.eis_event_props.event_flag             = BYTARR(25)
sra.eis_event_props.event_flag[line_index] = 1

tl.science_component.studyRasters[index]   = sra
temp->set , tl

END
;______________________________________________________________________________
; Invoke GUI to edit EIS Event Trigger Properties
;______________________________________________________________________________
PRO eis_mk_plan_gui::invoke_eis_event_gui

; Ensure we only have 1 GUI
IF (OBJ_VALID(Self.eis_event_gui) EQ 1) THEN RETURN

; Check EIS EVENT Flag is ON
widIDs   = Self.eis_mk_plan_widgets
button_set = WIDGET_INFO(widIDs.ra_eisEventID , /BUTTON_SET)
IF (button_set NE 1) THEN BEGIN
    BEEP
    mText = "EIS Event flag is disabled. Aborting!"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF

; Which raster are we dealing with
index = WIDGET_INFO(widIDs.pl_raListID , /LIST_SELECT)

; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = wp
; Get working_position entry
temp = Self.eis_timeline_container->get( position = wp)
tl   = temp->get()
; Already checked that this TL entry is saved, but for insurance!
IF (tl.time_component.sequence_id EQ 0) THEN BEGIN
    BEEP
    mText = "This operation is not possible because the study is not saved"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF

; Check if there is an existing RESPONSE DB entry
solarb_science = tl.science_component.solarb_science
resp_id = eis_solarb_science_id(solarb_science , 'eebp')

sra  = tl.science_component.studyRasters[index]
; Invoke EIS Event GUI - pass in the Hunter studyRaster line list ID
;Self.eis_event_gui = OBJ_NEW("eis_event_gui" , Self , sra.ll_id)
Self.eis_event_gui = OBJ_NEW("eis_event_gui" , Self , sra , index , resp_id)
Self.eis_event_gui->Realize
Self.eis_event_gui->XMANAGER

END
;______________________________________________________________________________
; Invoke GUI to edit EIS Event Trigger Properties
;______________________________________________________________________________
PRO eis_mk_plan_gui::invoke_eis_flare_gui

; Ensure we only have 1 GUI
IF (OBJ_VALID(Self.eis_flare_gui) EQ 1) THEN RETURN

; Check EIS FLARE Flag is ON
widIDs   = Self.eis_mk_plan_widgets
button_set = WIDGET_INFO(widIDs.ra_eisFlareID , /BUTTON_SET)
IF (button_set NE 1) THEN BEGIN
    BEEP
    mText = "EIS Flare flag is disabled. Aborting!"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF

; Which raster are we dealing with
ra_index = WIDGET_INFO(widIDs.pl_raListID , /LIST_SELECT)

; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = wp
; Get working_position entry
temp    = Self.eis_timeline_container->get( position = wp)
tl      = temp->get()
resp_id = tl.science_component.eis_flare_response.response_study_id
; Already checked that this TL entry is saved, but for insurance!
IF (tl.time_component.sequence_id EQ 0) THEN BEGIN
    BEEP
    mText = "This operation is not possible because the study is not saved"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF

;; Check if there is an existing RESPONSE DB entry
;solarb_science = tl.science_component.solarb_science
;resp_id = eis_solarb_science_id(solarb_science , 'eisf')

;sra  = tl.science_component.studyRasters[index]
;; Invoke EIS Flare GUI
;;Self.eis_flare_gui = OBJ_NEW("eis_flare_gui" , Self , sra.ll_id)
;Self.eis_flare_gui = OBJ_NEW("eis_flare_gui" , Self , sra , index , resp_id)
Self.eis_flare_gui = OBJ_NEW("eis_flare_gui" , Self , resp_id , ra_index)
Self.eis_flare_gui->Realize
Self.eis_flare_gui->XMANAGER
Self.eis_flare_gui->populate_widgets

END
;______________________________________________________________________________
; Invoke XRT Properties Tool
;______________________________________________________________________________
PRO eis_mk_plan_gui::invoke_xrt_flare_gui

; Ensure we only have 1 GUI
IF (OBJ_VALID(Self.xrt_flare_gui) EQ 1) THEN RETURN

; Check XRT FLARE Flag is ON
widIDs   = Self.eis_mk_plan_widgets
button_set = WIDGET_INFO(widIDs.ra_xrtFlareID , /BUTTON_SET)
IF (button_set NE 1) THEN BEGIN
    BEEP
    mText = "XRT Flare flag is disabled. Aborting!"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF

; Which raster are we dealing with
ra_index = WIDGET_INFO(widIDs.pl_raListID , /LIST_SELECT)

; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = wp
; Get working_position entry
temp    = Self.eis_timeline_container->get( position = wp)
tl      = temp->get()
resp_id = tl.science_component.xrt_flare_response.response_study_id
; Already checked that this TL entry is saved, but for insurance!
IF (tl.time_component.sequence_id EQ 0) THEN BEGIN
    BEEP
    mText = "This operation is not possible because the study is not saved"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF

Self.xrt_flare_gui = OBJ_NEW("eis_xrt_flare_gui" , Self , resp_id , ra_index)
Self.xrt_flare_gui->Realize
Self.xrt_flare_gui->XMANAGER

END
;______________________________________________________________________________
; If invoked, update the DR gui
;______________________________________________________________________________
PRO eis_mk_plan_gui::refresh_dr_gui , update = update

IF OBJ_VALID(Self.dr_gui) THEN BEGIN
    CASE KEYWORD_SET(update) OF
       0    : Self.dr_gui->plot_dr
       ELSE : Self.dr_gui->refresh
    ENDCASE
    Self.o_eis_timeline_plot_gui->tracker
ENDIF

END
;______________________________________________________________________________
; Set ASRC nSteps (allowed range: 1->127)
;______________________________________________________________________________
PRO eis_mk_plan_gui::asrc_nsteps , event

widIDs   = Self.eis_mk_plan_widgets
ra_index = WIDGET_INFO(widIDs.pl_raListID , /LIST_SELECT)

; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = wp
; Get working_position entry
temp = Self.eis_timeline_container->get( position = wp)
tl   = temp->get()

; Set value accordinly
temp->setProperty , asrc_nSteps = event.value

END
;______________________________________________________________________________
; Set ASRC skip - 1(default)/2 = 0/1
;______________________________________________________________________________
PRO eis_mk_plan_gui::asrc_skip , event

widIDs   = Self.eis_mk_plan_widgets
ra_index = WIDGET_INFO(widIDs.pl_raListID , /LIST_SELECT)

; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = wp
; Get working_position entry
temp = Self.eis_timeline_container->get( position = wp)
tl   = temp->get()

; Set value accordinly
temp->setProperty , asrc_skip = event.value

END
;______________________________________________________________________________
; Set ASRC direction - forward(default)/backward = 0/1
;______________________________________________________________________________
PRO eis_mk_plan_gui::asrc_direction , event

widIDs   = Self.eis_mk_plan_widgets
ra_index = WIDGET_INFO(widIDs.pl_raListID , /LIST_SELECT)

; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = wp
; Get working_position entry
temp = Self.eis_timeline_container->get( position = wp)
tl   = temp->get()

; Set value accordinly
temp->setProperty , asrc_direction = event.index

END
;______________________________________________________________________________
; Enable ASRC
;______________________________________________________________________________
PRO eis_mk_plan_gui::asrc_enable

; Get index of selected studyRaster
widIDs   = Self.eis_mk_plan_widgets
ra_index = WIDGET_INFO(widIDs.pl_raListID , /LIST_SELECT)
IF (ra_index EQ -1) THEN BEGIN
    BEEP
    complain = DIALOG_MESSAGE( 'No entry selected!' ,                       $
                     DIALOG_PARENT = Self.tlbID,                            $
                     /ERROR )
    RETURN
ENDIF

; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = wp
; Get working_position entry
temp = Self.eis_timeline_container->get( position = wp)
tl   = temp->get()

;
; OK, get state of enabled button
;
buttonSet = WIDGET_INFO(widIDs.pl_ra_asrcEnabledID , /BUTTON_SET)
; Set value accordinly
temp->setProperty , asrc_enabled = buttonSet

; If ASRC is ENABLED then

IF (buttonSet EQ 1) THEN BEGIN

   WIDGET_CONTROL , widIDs.ra_asrcBaseID , sensitive  = 1
   temp->setProperty , asrc_direction = 0
   temp->setProperty , asrc_skip      = 1
   temp->setProperty , asrc_nSteps    = 1

ENDIF ELSE BEGIN

   WIDGET_CONTROL , widIDs.ra_asrcBaseID , sensitive  = 0
   temp->setProperty , asrc_direction = 0
   temp->setProperty , asrc_skip      = 1
   temp->setProperty , asrc_nSteps    = 1

ENDELSE

;
; Just in case the values have changed above, check them out again
;
tl   = temp->get()

;
; ASRC Direction
;
asrc_direction = tl.science_component.studyRasters[ra_index].asrc_direction
WIDGET_CONTROL , widIDs.ra_asrcDirectionID , set_droplist_select = asrc_direction
;
; ASRC Skip
;
asrc_skip = tl.science_component.studyRasters[ra_index].asrc_skip
WIDGET_CONTROL , widIDs.ra_asrcSkipID , set_value = asrc_skip
;
;ASRC Number of Compensation Steps
;
asrc_nSteps = tl.science_component.studyRasters[ra_index].asrc_nSteps
WIDGET_CONTROL , widIDs.ra_asrcNStepsID , set_value = asrc_nSteps

; Update Raster List
 Self->updateStudyRasterListWidget

END
;______________________________________________________________________________
; Toggle Re-point dialog OFF
;______________________________________________________________________________
PRO eis_mk_plan_gui::repoint_popup_off

WIDGET_CONTROL , Self.repointpopup_onID  , set_button = 0
WIDGET_CONTROL , Self.repointpopup_offID , set_button = 1
Self.repointpopup_on = 0

END
;______________________________________________________________________________
; Toggle Re-point dialog ON
;______________________________________________________________________________
PRO eis_mk_plan_gui::repoint_popup_on

WIDGET_CONTROL , Self.repointpopup_onID  , set_button = 1
WIDGET_CONTROL , Self.repointpopup_offID , set_button = 0
Self.repointpopup_on = 1

END
;______________________________________________________________________________
; View Latest Changes file
;______________________________________________________________________________
PRO eis_mk_plan_gui::latest_changes

pt_version = eis_get_pt_version_number()
pathName   = GETENV('ancillary')
baseName   = 'eis_latest_changes.txt'
fileName   = CONCAT_DIR(pathName , baseName)

IF (FILE_TEST(fileName) EQ 1) THEN                                         $
               XDISPLAYFILE , fileName , group = Self.tlbID    ,           $
               title  = 'Latest Changes' + pt_version          ,           $
               height = 50                                     ,           $
               width  = 80

END
;______________________________________________________________________________
; Create a data_rate file
;______________________________________________________________________________
PRO eis_mk_plan_gui::ra_details

; Get index of selected studyRaster
widIDs   = Self.eis_mk_plan_widgets
ra_index = WIDGET_INFO(widIDs.pl_raListID , /LIST_SELECT)
IF (ra_index EQ -1) THEN BEGIN
    BEEP
    complain = DIALOG_MESSAGE( 'No entry selected!' ,                       $
                     DIALOG_PARENT = Self.tlbID,                            $
                     /ERROR )
    RETURN
ENDIF


; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = wp
; Get working_position entry
temp = Self.eis_timeline_container->get( position = wp)
tl   = temp->get()
sc   = tl.science_component
sra  = sc.studyRasters[ra_index]
ra   = db_read_raster_entry(sra.ra_id)
ll   = db_read_linelist_entry(sra.ll_id)

; Invoke Raster Details GUI
o_rasterDetails = OBJ_NEW("eis_raster_details_gui" , ra , ll         ,      $
                                    group_leader = Self.tlbID)
o_rasterDetails->Realize
o_rasterDetails->XMANAGER


END
;______________________________________________________________________________
; Create a data_rate file
;______________________________________________________________________________
PRO eis_mk_plan_gui::version

fileName = concat_dir(GETENV('ancillary') , 'eis_mk_plan_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)
pt_version = eis_get_pt_version_number()
; Display file contents in popup window
xpopup , mText , group = Self.tlbID , ySize = 16 , xSize = 60 ,$
                        title = "EIS_MK_PLAN Version" + pt_version

END
;______________________________________________________________________________
; Create a data_rate file
;______________________________________________________________________________
PRO eis_mk_plan_gui::create_dr_file

; Nothing to do if DR gui already exists. Only allow 1 instance!
IF OBJ_VALID(Self.dr_gui) THEN RETURN

; Invoke timeline graphics
Self.dr_gui = OBJ_NEW("eis_dr_gui" , Self)
Self.dr_gui->Realize
Self.dr_gui->XMANAGER
Self.dr_gui->refresh

END
;______________________________________________________________________________
; Quit
;______________________________________________________________________________
PRO eis_mk_plan_gui::quit

;
; Save database automatically
;
mText = '  Writing to Database...  '
XMESSAGE , mText , wbase = wbase , group = Self.tlbID; , font = 'helvetica'
Self.eis_timeline_container->write_database
WIDGET_CONTROL , wbase , /DESTROY

; Kill eis_mk_plan_gui
Self->Control, /Destroy

END
;______________________________________________________________________________
; Invoke Timeline Plot
;______________________________________________________________________________
PRO eis_mk_plan_gui::invoke_timeline_plot

IF (OBJ_VALID(Self.o_eis_timeline_plot_gui) EQ 0) THEN BEGIN

    ; Invoke timeline graphics
    o_eis_timeline_plot_gui = OBJ_NEW("eis_timeline_plot_gui" , Self)
    o_eis_timeline_plot_gui->Realize
    o_eis_timeline_plot_gui->XMANAGER
    o_eis_timeline_plot_gui->initialize_plot
    Self.o_eis_timeline_plot_gui = o_eis_timeline_plot_gui

ENDIF ELSE RETURN

END
;______________________________________________________________________________
; Invoke SCI_OBJ Tool
;______________________________________________________________________________
PRO eis_mk_plan_gui::sci_obj

; Firstly, check there ARE studies and that one is selected
count = Self.eis_timeline_container->count()
Self.eis_timeline_container->getProperty, working_position = wp
IF (count EQ 0) OR (wp EQ -1) THEN BEGIN
    BEEP
    complain = DIALOG_MESSAGE( 'No entry selected!' ,                       $
                     DIALOG_PARENT = Self.tlbID,                            $
                     /ERROR )
    RETURN
ENDIF

; Get SCI_OBJ from tl entry
temp           = Self.eis_timeline_container->get( position = wp)
tl             = temp->get()
sci_obj_string = tl.science_component.sci_obj

; Invoke SCI_OBJ Tool
s = OBJ_NEW("eis_sci_obj_gui" , Self , sci_obj_string = sci_obj_string)
s->Realize
s->XMANAGER

END
;______________________________________________________________________________
; Set TARGET
;______________________________________________________________________________
PRO eis_mk_plan_gui::target

; Firstly, check there ARE studies and that one is selected
count = Self.eis_timeline_container->count()
Self.eis_timeline_container->getProperty, working_position = wp
IF (count EQ 0) OR (wp EQ -1) THEN BEGIN
    BEEP
    complain = DIALOG_MESSAGE( 'No entry selected!' ,                       $
                     DIALOG_PARENT = Self.tlbID,                            $
                     /ERROR )
    RETURN
ENDIF

widIDs = Self.eis_mk_plan_widgets
; Get SCI_OBJ from tl entry
temp           = Self.eis_timeline_container->get( position = wp)
tl             = temp->get()

index = WIDGET_INFO(widIDs.st_targetID , /DROPLIST_SELECT)
WIDGET_CONTROL , widIDs.st_targetID , get_value = target_list
tl.science_component.target = target_list[index]

; Update value - and re-calculate study duration
temp->set , tl
temp->update_study_properties
; Update duration and volume
Self->updateDurationAndVolume

END
;______________________________________________________________________________
; Set JOIN_SB
;______________________________________________________________________________
PRO eis_mk_plan_gui::join_sb

widIDs = Self.eis_mk_plan_widgets
; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = working_position
temp  = Self.eis_timeline_container->get( position = working_position)
tl    = temp->get()

index = WIDGET_INFO(widIDs.st_join_sbID , /DROPLIST_SELECT)
CASE index OF
    0:  join_sb = 'E'
    1:  join_sb = 'E,S'
    2:  join_sb = 'E,X'
    3:  join_sb = 'E,S,X'
ENDCASE
tl.science_component.join_sb = join_sb

; Update value - and re-calculate study duration
temp->set , tl

END
;______________________________________________________________________________
; Invoke Pointing GUI
;______________________________________________________________________________
PRO eis_mk_plan_gui::pointing_gui

; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = wp
; Get working_position entry
temp     = Self.eis_timeline_container->get( position = wp)
s        = temp->get()
nRasters = s.science_component.nRasters

s = OBJ_NEW("eis_pointing_gui" , Self , nRasters)
s->Realize
s->XMANAGER

END
;______________________________________________________________________________
; Re-read spacecraft pointing
;______________________________________________________________________________
PRO eis_mk_plan_gui::offset_pointing_mechan , x_offset , y_offset

; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = wp
; Get working_position entry
temp     = Self.eis_timeline_container->get( position = wp)
temp->offset_pointing_mechan , x_offset , y_offset

Self->updateStudyRasterListWidget
;
; Update Plan Summary Tool
;
Self->refreshSummary

END
;______________________________________________________________________________
; Re-read spacecraft pointing
;______________________________________________________________________________
PRO eis_mk_plan_gui::offset_pointing_coords , x_offset , y_offset

; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = wp
; Get working_position entry
temp     = Self.eis_timeline_container->get( position = wp)
temp->offset_pointing_coords , x_offset , y_offset

Self->updateStudyRasterListWidget
;
; Update Plan Summary Tool
;
Self->refreshSummary

END
;______________________________________________________________________________
; Re-read spacecraft pointing
;______________________________________________________________________________
PRO eis_mk_plan_gui::pointing_refresh , no_change = no_change

; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = wp
; Get working_position entry {eis_structure_container}
temp     = Self.eis_timeline_container->get( position = wp)

CASE KEYWORD_SET(no_change) OF
   1    : temp->refresh_raster_pointing
   ELSE : temp->initialise_raster_pointing , num_days = Self.num_days
ENDCASE

Self->updateStudyRasterListWidget
;
; Update Plan Summary Tool
;
Self->refreshSummary

widIDs  = Self.eis_mk_plan_widgets
; DE-Sensitize raster widgets
WIDGET_CONTROL , widIDs.ra_propsBaseID   , sensitive       = 0
WIDGET_CONTROL , widIDs.pl_ra_asrcBaseID , sensitive       = 0
WIDGET_CONTROL , widIDs.ra_eventsBaseID  , sensitive       = 0
WIDGET_CONTROL , widIDs.ra_pointBaseID   , sensitive       = 0
WIDGET_CONTROL , widIDs.pl_raListID      , set_list_select = -1
; Set working_raster = -1
s = temp->get()
temp->set_index , -1

END
;______________________________________________________________________________
; Re-read spacecraft pointing
;______________________________________________________________________________
PRO eis_mk_plan_gui::pointing_relative

; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = wp
; Get working_position entry
temp     = Self.eis_timeline_container->get( position = wp)
temp->relative_raster_pointing , num_days = Self.num_days

Self->updateStudyRasterListWidget
;
; Update Plan Summary Tool
;
Self->refreshSummary

widIDs  = Self.eis_mk_plan_widgets
; DE-Sensitize raster widgets
WIDGET_CONTROL , widIDs.ra_propsBaseID   , sensitive       = 0
WIDGET_CONTROL , widIDs.pl_ra_asrcBaseID , sensitive       = 0
WIDGET_CONTROL , widIDs.ra_eventsBaseID  , sensitive       = 0
WIDGET_CONTROL , widIDs.ra_pointBaseID   , sensitive       = 0
WIDGET_CONTROL , widIDs.pl_raListID      , set_list_select = -1
; Set working_raster = -1
s = temp->get()
temp->set_index , -1

END
;______________________________________________________________________________
; Make all study rasters point to the same pointing
;______________________________________________________________________________
PRO eis_mk_plan_gui::pointing_inherit_all

; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = wp
; Get working_position entry
temp     = Self.eis_timeline_container->get( position = wp)
tl       = temp->get()
nRasters = tl.science_component.nRasters

; Get index of selected studyRaster
widIDs  = Self.eis_mk_plan_widgets
index   = WIDGET_INFO(widIDs.pl_raListID , /LIST_SELECT)

;
; Calculate delx and dely of first raster
;
ref_ra_id = tl.science_component.studyRasters[0].ra_id
ref_x     = tl.science_component.studyRasters[0].x_point
ref_y     = tl.science_component.studyRasters[0].y_point
ref_sc_x  = tl.science_component.studyRasters[0].sc_x
ref_sc_y  = tl.science_component.studyRasters[0].sc_y
delx      = ref_sc_x - ref_x
dely      = ref_sc_y - ref_y

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; JAR 27-Aug-2014. Get sot_offsets from tl.sc.disturbance
sot_offset = tl.science_component.disturbance
sot_offset = FLOAT(STRSPLIT(sot_offset,',',/EXTRACT))
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

FOR i = 0, nRasters - 1 DO BEGIN

   sra        = tl.science_component.studyRasters[i]
   ; Get MIP and YIP using delx/dely from first raster
   ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   ; JAR 1-Apr-2014. Add "obs_id" and "aia_time" inputs to routine
   ; "eis_get_mirror_position"
   obs_id   = tl.science_component.obs_id
   aia_time = sra.ra_start_time
   ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   mirr_pos   = eis_get_mirror_position(delx , dely , sra.ra_id ,   $
                              obs_id , aia_time , sot_offset)
   ; Get x/y coords from YIP/MIP
   xy         = eis_get_xy_point(sra.sc_x , sra.sc_y           ,         $
                                    mirr_pos.mip        , $
                                    mirr_pos.yStart     , $
                                    sra.ra_id           , $
                                    obs_id              , $
                                    aia_time            , $
                                    sot_offset)

   ; Update values
   tl.science_component.studyRasters[i].x_point = xy.x_point
   tl.science_component.studyRasters[i].y_point = xy.y_point
   tl.science_component.studyRasters[i].mip     = mirr_pos.mip
   tl.science_component.studyRasters[i].yip     = mirr_pos.yStart

ENDFOR

; Updates the timeline entry object
temp->set , tl

Self->updateStudyRasterListWidget
;
; Update Plan Summary Tool
;
Self->refreshSummary

widIDs  = Self.eis_mk_plan_widgets
; DE-Sensitize raster widgets
WIDGET_CONTROL , widIDs.ra_propsBaseID   , sensitive       = 0
WIDGET_CONTROL , widIDs.pl_ra_asrcBaseID , sensitive       = 0
WIDGET_CONTROL , widIDs.ra_eventsBaseID  , sensitive       = 0
WIDGET_CONTROL , widIDs.ra_pointBaseID   , sensitive       = 0
WIDGET_CONTROL , widIDs.pl_raListID      , set_list_select = -1
; Set working_raster = -1
tl = temp->get()
temp->set_index , -1

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

; Get widget IDs
widIDs = Self.eis_mk_plan_widgets
WIDGET_CONTROL , widIDs.pl_logoID , get_value = drawID
WSET , drawID

; Ensure file is really there
IF (FILE_TEST(Self.logo_fileName) NE 1) THEN RETURN

READ_JPEG , Self.logo_filename , icon
;icon_resized = CONGRID(icon,3,160,80)
icon_resized = CONGRID(icon,3,140,70)
TVSCL,icon_resized , true = 1

END
;______________________________________________________________________________
; Invoke image_tool
;______________________________________________________________________________
PRO eis_mk_plan_gui::image_tool_event

stc = Self->populate_point_stc()
eis_image_tool , point_stc = stc , /AUTO_PLOT

; Redraw timeline graphics
;Self.o_eis_timeline_plot_gui->initialize_plot
Self.o_eis_timeline_plot_gui->tracker

END
;______________________________________________________________________________
; Disable the 5 percent rule
;______________________________________________________________________________
FUNCTION eis_mk_plan_gui::five_pc_disable

print,'working on it'

RETURN , 1

END
;______________________________________________________________________________
; Enable the 5 percent rule
;______________________________________________________________________________
FUNCTION eis_mk_plan_gui::five_pc_enable

print,'working on it'

RETURN , 1

END
;______________________________________________________________________________
; Copy the selected study to the cursor position
;______________________________________________________________________________
FUNCTION eis_mk_plan_gui::copy_study_to_cp

; The method used here is to create a copy of the TL entry object, and
; then move that to the required time (the original is left alone)

; Firstly, check there ARE studies
count = Self.eis_timeline_container->count()
IF (count EQ 0) THEN BEGIN
    BEEP
    complain = DIALOG_MESSAGE( 'No entry selected!' ,                       $
                     DIALOG_PARENT = Self.tlbID,                            $
                     /ERROR )
    RETURN , 0
ENDIF

; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = wp
IF (wp EQ -1) THEN BEGIN
    BEEP
    complain = DIALOG_MESSAGE( 'No entry selected!' ,                       $
                     DIALOG_PARENT = Self.tlbID,                            $
                     /ERROR )
    RETURN , 0
ENDIF

; Get current cursor time
Self.cursor_time_gui->getProperty , datetime = cp_tai

; Check the cursor-time doesn't sit on an existing study
Self.eis_timeline_container->getProperty, study_selected = study_selected
IF (study_selected EQ 1) THEN BEGIN
    mText = "Can't place a new study on an existing entry! Aborting."
    BEEP
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN , 0
ENDIF

; Get working_position of original entry (index of selected study)
temp_orig = Self.eis_timeline_container->get(position = wp)
tl_orig   = temp_orig->get()

;
; Check sufficient time - if NOT, then bail out!
;
Self.eis_timeline_container->getProperty, all_blocks = all_blocks
start_time_orig = tl_orig.time_component.start_time
end_time_orig   = tl_orig.time_component.end_time
st_dur          = end_time_orig - start_time_orig
valid           = eis_check_sufficient_time(all_blocks , cp_tai        ,   $
                                            Self.tlbID , st_dur)
IF (valid NE 1) THEN RETURN , 0

; What is original study seq_id? If zero then unsaved, otherwise it is
;saved. Trigger studies are saved when created.
seq_id_old = tl_orig.time_component.sequence_id
IF (seq_id_old EQ 0) THEN BEGIN

   ; OK, the original study is unsaved. Save it now. Also, it can't be
   ; a trigger study - so no need to worry about response entry.
   Self->save_copied_hunter_study , temp_orig
   ; Now need to refresh this timeline object
   temp_orig  = Self.eis_timeline_container->get(position = wp)
   tl_orig    = temp_orig->get()
   seq_id_old = tl_orig.time_component.sequence_id

   ; Redraw timeline graphics
   Self.o_eis_timeline_plot_gui->initialize_plot
   ; Update Plan Summary Tool
   Self.eis_timeline_container->reorganise_container
   Self->refreshSummary

ENDIF

; OK, so the original study is saved (seq_id NE 0)
; Time to create a new TL object using the original instance. Then save it
; and update it. Additionally deal with the corresponding response entry
; if this is a trigger study

temp_new = OBJ_NEW('eis_structure_container' , tl_orig )

; OK, now save new tl entry to the tl DB and add it to the timeline
; container.
Self->save_copied_hunter_study , temp_new
Self.eis_timeline_container->add_entry, temp_new

; So what's left is;
; 1. Corresponding response study (if original was a hunter study)
; 2. Move tl entry start and stop times
; 3. Save the updates for 1. and 2.

; Creating/saving the response study (if the original study was a trigger
; study) must be the first step because the "move_tl_entry" method includes
; code to read it and update its pointing info.

tl_new   = temp_new->get()

save_here = 0
; If copied study was a trigger/hunter then create response entry
IF (tl_new.time_component.respond_to_xrt_flare EQ 1) THEN BEGIN
   ; Copied TL entry is an XRTF trigger study. However, the response entry
   ; id associated with this new hunter study is the original one. We need
   ; to create a new (unique) version.

   ; We need;
   ; 1. seq_id of new study
   new_seq_id = tl_new.time_component.sequence_id

   ; 2. resp_id of new response entry.
   new_resp_id = eis_db_get_num_response_entries() + 1

   ; 3. resp_id of original response entry.
   sc_orig = tl_orig.science_component
   orig_resp_id = sc_orig.xrt_flare_response.response_study_id

   ; 4. Retrieve response entry. Update "trig_st_seqid" and
   ;    "id". Then save response entry.
   r_struct = db_read_response_entry(id = orig_resp_id)
   r_struct.trig_st_seqid = new_seq_id
   r_struct.id            = new_resp_id
   db_save_response_entry_create , r_struct

   ; 5. Save response DB entry id to TL DB; specifically to the tag
   ;    sc.xrt_flare_response.response_study_id. Created a method in
   ;    "eis_structure_container::set_resp_id" to do so.
   temp_new->set_resp_id , xrtf_resp_id = new_resp_id

ENDIF
IF (tl_new.time_component.respond_to_eis_flare EQ 1) THEN BEGIN
   ; Copied TL entry is an EISF trigger study. However, the response entry
   ; id associated with this new hunter study is the original one. We need
   ; to create a new (unique) version.

   ; We need;
   ; 1. seq_id of new study
   new_seq_id = tl_new.time_component.sequence_id

   ; 2. resp_id of new response entry.
   new_resp_id = eis_db_get_num_response_entries() + 1

   ; 3. resp_id of original response entry.
   sc_orig = tl_orig.science_component
   orig_resp_id = sc_orig.eis_flare_response.response_study_id

   ; 4. Retrieve response entry. Update "trig_st_seqid" and
   ;    "id". Then save response entry.
   r_struct = db_read_response_entry(id = orig_resp_id)
   r_struct.trig_st_seqid = new_seq_id
   r_struct.id            = new_resp_id
   db_save_response_entry_create , r_struct

   ; 5. Save response DB entry id to TL DB; specifically to the tag
   ;    sc.xrt_flare_response.response_study_id. Created a method in
   ;    "eis_structure_container::set_resp_id" to do so.
   temp_new->set_resp_id , eisf_resp_id = new_resp_id

ENDIF

; Let's refresh the object contents
tl_new = temp_new->get()
tc     = tl_new.time_component
sc     = tl_new.science_component
; Check these 4 values are correct.
; 1. tc.respond_to_xrt_flare							= 1		YES
; 2. sc.xrt_flare_response.respond_to_xrt_flare			= 1		YES
; 3. sc.studyRasters[index].xrt_flare_props.xrt_flag	= 1		YES
; 4. sc.xrt_flare_response.response_study_id			= 366	YES


; 2. Start and stop times - do moving here
CASE tl_new.time_component.entry_type OF
    "E" :  temp_new->move_tl_eng_entry , cp_tai
    "S" :  temp_new->move_tl_entry     , cp_tai
ENDCASE
; Refresh tl_new
temp_new->set_as_time_tagged
temp_new->flag_save
tl_new   = temp_new->get()

;
; Update cursor_position to end of new study
;
Self->getProperty , cursor_time_gui = cursor_time_gui
cursor_time_gui->setProperty , datetime = tl_new.time_component.end_time
; Get current cursor time
Self.cursor_time_gui->getProperty , datetime = cp_tai

; Refresh the currently selected entry
blah = Self.eis_timeline_container->returnSelectedStudyIndex(cp_tai)
; Get working_position (index of selected study - this is the same
; value as blah)
Self.eis_timeline_container->getProperty, working_position = wp
temp_new = Self.eis_timeline_container->get( position = wp)
tl_new   = temp_new->get()


;IF (tl_new.time_component.respond_to_eis_flare EQ 1) THEN save_here = 1
IF (tl_new.time_component.respond_to_eis_event EQ 1) THEN save_here = 1
IF (save_here EQ 1) THEN BEGIN
   ;stop
   Self->savePlanToDatabase
ENDIF


; Update raster widgets
Self->updateStudyRasterListWidget

; Redraw timeline graphics
Self.o_eis_timeline_plot_gui->initialize_plot

Self.eis_timeline_container->reorganise_container

; Update Plan Summary Tool
Self->refreshSummary
Self->refresh_dr_gui

RETURN , 1

END
;______________________________________________________________________________
; Move the selected study to the cursor position
;______________________________________________________________________________
FUNCTION eis_mk_plan_gui::move_study_to_cp

; Firstly, check there ARE studies
count = Self.eis_timeline_container->count()
IF (count EQ 0) THEN BEGIN
    BEEP
    complain = DIALOG_MESSAGE( 'No entry selected!' ,                       $
                     DIALOG_PARENT = Self.tlbID,                            $
                     /ERROR )
    RETURN , 0
ENDIF

; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = working_position
IF (working_position EQ -1) THEN BEGIN
    BEEP
    complain = DIALOG_MESSAGE( 'No entry selected!' ,                       $
                     DIALOG_PARENT = Self.tlbID,                            $
                     /ERROR )
    RETURN , 0
ENDIF


; Get cursor time in TAI
Self.cursor_time_gui->getProperty , datetime = cp_tai

; Get working_position (index of selected study)
temp  = Self.eis_timeline_container->get( position = working_position)
s     = temp->get()

;
; Get the current block info
;
block_info = Self.eis_timeline_container->get_curr_block_info()

; Is this a time-tagged study? If not then bail out!
IF (block_info[0] NE working_position) THEN BEGIN
    BEEP
    mText    = STRARR(4)
    mText[0] = 'This is an APPENDED study - and is part of a group.'
    mText[1] = 'Appended studies may NOT be moved individually.'
    mText[2] = 'You may move the time-tagged study to which this study is appended to.'
    mText[3] = 'Aborting!'
    complain = DIALOG_MESSAGE( mText                                 ,     $
                     DIALOG_PARENT = Self.tlbID,                           $
                     /ERROR )
    RETURN , 0
ENDIF


t_off = 0.0
; Does this study have any studies appended to it?
FOR i = 0 , N_ELEMENTS(block_info) - 1 DO BEGIN
   ; Get index of selected study
   temp  = Self.eis_timeline_container->get( position = block_info[i])
   s     = temp->get()

   CASE s.time_component.entry_type OF
       "E" :   BEGIN
                   ; Need to update tl.start_time and tl.end_time
                   temp->move_tl_eng_entry , cp_tai + t_off
               END
       "S" :   BEGIN
                   ; Need to update tl.start_time and tl.end_time
                   temp->move_tl_entry , cp_tai + t_off
                   ; Update raster widgets
                   Self->updateStudyRasterListWidget
               END
   ENDCASE

   st_dur = s.time_component.end_time - s.time_component.start_time
   t_off  = t_off + st_dur + 0.1

ENDFOR



; Redraw timeline graphics
Self.o_eis_timeline_plot_gui->initialize_plot

; Update Cursor Position - set to new tl end_time. Need to refresh s
s     = temp->get()
Self.cursor_time_gui->setProperty , datetime = s.time_component.end_time
; Plot cursor time on timeline plot
Self.o_eis_timeline_plot_gui->plot_cursor_time

;
; Update Plan Summary Tool
;
; JAR 09-Oct-2013: Added call to reorganise the timeline container
; to sort entries according to time.
Self.eis_timeline_container->reorganise_container

Self->refreshSummary
Self->refresh_dr_gui

RETURN , 1

END
;______________________________________________________________________________
; New pointing received from eis_image_tool
;______________________________________________________________________________
PRO eis_mk_plan_gui::refreshSummary

IF (OBJ_VALID(Self.o_ct_summary) EQ 1) THEN Self.o_ct_summary->refreshSummary

END
;______________________________________________________________________________
; New pointing received from eis_image_tool
;______________________________________________________________________________
PRO eis_mk_plan_gui::update_pointing , point_stc

; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = wp
; Get working_position entry
temp     = Self.eis_timeline_container->get( position = wp)
s        = temp->get()
nRasters = s.science_component.nRasters

; Update raster pointings
temp->update_raster_pointing , s , point_stc


; Get index of selected studyRaster
widIDs = Self.eis_mk_plan_widgets
index = WIDGET_INFO(widIDs.pl_raListID , /LIST_SELECT)
Self->updateStudyRasterListWidget

;
; Update Plan Summary Tool
;
Self->refreshSummary
;
; JAR 7-Jan-2007
;
; Added a "replot" parameter to Self. It is set to unity after receiving
; updated pointings from image_tool. This is picked up when the user
; clicks on the timeline and the timeline graphics are redrawn. This
; was done to counter the fact that studies seemed to disappear off
; the timeline after using image_tool. JAR
Self.replot = 1

;
; OK, we want to update the mk_plan widgets of the selected raster.
; If a raster isn't selected, then bail out!
;
IF (index[0] EQ -1) THEN RETURN

; Update widget value
x_point_string = STRTRIM(STRING(format='(F-10.2)',point_stc[index].xCen),2)
y_point_string = STRTRIM(STRING(format='(F-10.2)',point_stc[index].yCen),2)
WIDGET_CONTROL , widIDs.pl_ra_xpointID , set_value = x_point_string
WIDGET_CONTROL , widIDs.pl_ra_ypointID , set_value = y_point_string


; Update MIP & YIP - for selected raster
sra   = s.science_component.studyRasters[index]
delx  = sra.sc_x - point_stc[index].xcen
dely  = sra.sc_y - point_stc[index].ycen
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; JAR 1-Apr-2014. Add "obs_id" and "aia_time" inputs to routine
; "eis_pointing_offset"
obs_id   = s.science_component.obs_id
aia_time = sra.ra_start_time
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; JAR 27-Aug-2014. Get sot_offsets from tl.sc.disturbance
sot_offset = s.science_component.disturbance
sot_offset = FLOAT(STRSPLIT(sot_offset,',',/EXTRACT))
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

mirror_pos = eis_get_mirror_position(delx , dely , sra.ra_id  ,  $
                            obs_id , aia_time , sot_offset)

; Issue warning if MIP = or < 160
mip_warning = "The PZT is non-linear between 0 and 160 steps."
IF (mirror_pos.mip LE 160) THEN BEGIN
   warning = DIALOG_MESSAGE( mip_warning                             ,     $
                             DIALOG_PARENT = Self.tlbID)
ENDIF

temp->setProperty , mip = mirror_pos.mip
; JAR 18-Mar-2008. Just for insurance
temp->setProperty , yip = mirror_pos.yStart > 1
; Update YIP widget
;mip = STRING(format='(A-8,I-6)'  , '  MIP = ' , ROUND(mirror_pos.mip))
;WIDGET_CONTROL , widIDs.pl_ra_mipID     , set_value = mip
;yip = STRING(format='(A-8,I-6)'  , '  YIP = ' , ROUND(mirror_pos.yStart))
;WIDGET_CONTROL , widIDs.pl_ra_yipID     , set_value = yip

; MIP Text Box
mip_text = STRTRIM(STRING(format='(I4)',mirror_pos.mip),2)
WIDGET_CONTROL , widIDs.pl_ra_mipInID , set_value = mip_text
; YIP Text Box
yip_text = STRTRIM(STRING(format='(I4)',mirror_pos.yStart),2)
WIDGET_CONTROL , widIDs.pl_ra_yipInID , set_value = yip_text


END
;______________________________________________________________________________
; Update x_point
;______________________________________________________________________________
FUNCTION eis_mk_plan_gui::populate_point_stc

IF (Self.eis_timeline_container->count() EQ 0) THEN RETURN , {eis_point_stc}

; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = wp
temp  = Self.eis_timeline_container->get( position = wp)
s     = temp->get()

; JAR 18-Jun-2007
; If study is of engineering type, then bail out!
IF (STRUPCASE(s.time_component.entry_type) EQ 'E') THEN RETURN , {eis_point_stc}


nRasters = s.science_component.nRasters

stc   = REPLICATE( {eis_point_stc} , nRasters )
child = WIDGET_INFO(Self.tlbID , /child)

FOR i = 0, nRasters - 1 DO BEGIN

    ;
    ; JAR & PRY 07-Mar-2008
    ; Subtracted EIS/SOT offsets - so sc_x and sc_y are the central
    ; coordinates of the EIS fov

    ; Get EIS pointing offset
    ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    ; JAR 1-Apr-2014. Add "obs_id" and "aia_time" inputs to routine
    ; "eis_pointing_offset"
    obs_id   = s.science_component.obs_id
    aia_time = s.science_component.studyRasters[i].ra_start_time
    ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    ; JAR 27-Aug-2014. Get sot_offsets from tl.sc.disturbance
    sot_offset = FLOAT(STRSPLIT(s.science_component.disturbance,',',/EXTRACT))
    ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


    offsets = eis_pointing_offset(obs_id , aia_time , sot_offset)


   ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   ; JAR 30-Apr-2014. Changed returned structure from "eis_pointing_offset"
   offset     = offsets.def_offset
   aia_offset = offsets.aia_offset
   sot_offset = offsets.sot_offset

   CASE obs_id OF
      0    : ; Nothing to do here
      1    :  BEGIN
                  offset[0] = offset[0] + aia_offset[0]
                  offset[1] = offset[1] + aia_offset[1]
              END
      2    :  BEGIN
                  offset[0] = offset[0] + aia_offset[0] - sot_offset[0]
                  offset[1] = offset[1] + aia_offset[1] - sot_offset[1]
             END
      ELSE :  ; Nothing to do here
   ENDCASE

   ; 16-May-2014
   ; Error reported by Ignacio that the "s" structure was incorrectly
   ; changed to "tl". Also, the "i" was incorrectly "index".
   ; These are fixed here.
   ; This was due to some sloppy copying and pasting!
   sc_x     = s.science_component.studyRasters[i].sc_x - offset[0]
   sc_y     = s.science_component.studyRasters[i].sc_y - offset[1]
   ;sc_x = s.science_component.studyRasters[i].sc_x - offsets.x_offset
   ;sc_y = s.science_component.studyRasters[i].sc_y - offsets.y_offset
   ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++





    start_time        = s.time_component.start_time
    date_obs          = anytim2utc(start_time,/stime,/truncate)

    stc[i].id         = child
    stc[i].date_obs   = date_obs
    stc[i].sci_obj    = s.science_component.studyRasters[i].ra_acronym
    stc[i].xcen       = s.science_component.studyRasters[i].x_point
    stc[i].ycen       = s.science_component.studyRasters[i].y_point
;     stc[i].sc_x       = s.science_component.studyRasters[i].sc_x
;     stc[i].sc_y       = s.science_component.studyRasters[i].sc_y
    stc[i].sc_x       = sc_x
    stc[i].sc_y       = sc_y


    ;
    ; JAR 30-Apr-2007
    ; Raster FOV depends on slitIndex
    ;
    CASE s.science_component.studyRasters[i].slitIndex OF
        0 : stc[i].fov_width  = 590
        1 : stc[i].fov_width  = 856
        2 : stc[i].fov_width  = 592
        3 : stc[i].fov_width  = 630
    ENDCASE
    ;stc[i].fov_height = 512
    stc[i].fov_height = 1024

    ; JAR 13-Apr-2007
    ; Use sra tag ra_width instead of calculating it
    ; stc[i].ras_width  = eis_get_total_raster_ width(ra)
;    ; Calculate the Raster Total Spatial Width
;    ra_id             = s.science_component.studyRasters[i].ra_id
;    ra                = db_read_raster_entry(ra_id)
    stc[i].ras_width  = s.science_component.studyRasters[i].ra_width
    stc[i].ras_height = s.science_component.studyRasters[i].windHeight

ENDFOR

RETURN , stc

END
;______________________________________________________________________________
; Toggle AEC Event
;______________________________________________________________________________
FUNCTION eis_mk_plan_gui::toggleAECEvent

print,'AEC Event coming soon...'
RETURN , 1

END
;______________________________________________________________________________
; Toggle EIS Event
;______________________________________________________________________________
FUNCTION eis_mk_plan_gui::toggleEISEvent


widIDs = Self.eis_mk_plan_widgets
; Is XRT Flare button selected?
xrtFlareOn = WIDGET_INFO( widIDs.ra_xrtFlareID , /BUTTON_SET)
IF (xrtFlareOn EQ 1) THEN BEGIN
   WIDGET_CONTROL , widIDs.ra_eisEventID , set_button = 0
   BEEP
   mText = "Operation not allowed. XRT Flare trigger is enabled."
   complain = DIALOG_MESSAGE(mText ,                        $
                                 DIALOG_PARENT = Self.tlbID,          $
                                 /ERROR )
   RETURN , 0
ENDIF
; Is EIS Flare button selected?
eisFlareOn = WIDGET_INFO( widIDs.ra_eisFlareID , /BUTTON_SET)
IF (eisFlareOn EQ 1) THEN BEGIN
   WIDGET_CONTROL , widIDs.ra_eisEventID , set_button = 0
   BEEP
   mText = "Operation not allowed. EIS Flare trigger is enabled."
   complain = DIALOG_MESSAGE(mText ,                        $
                                 DIALOG_PARENT = Self.tlbID,          $
                                 /ERROR )
   RETURN , 0
ENDIF

; Get index of selected studyRaster
index  = WIDGET_INFO(widIDs.pl_raListID , /LIST_SELECT)

; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = working_position
temp  = Self.eis_timeline_container->get( position = working_position)
tl    = temp->get()
sc    = tl.science_component
tc    = tl.time_component

; Is button selected?
eisEventOn = WIDGET_INFO( widIDs.ra_eisEventID , /BUTTON_SET)

; Can't handle seq_ids of zero. So make sure this can't happen
; JAR 5-Mar-2009
IF (tc.sequence_id LE 0) THEN BEGIN
   BEEP
   mText    = STRARR(2)
   mText[0] = 'This timeline entry must be saved first.'
   mText[1] = 'Do you want to save the plan now?'
   question = DIALOG_MESSAGE( mText                                  ,     $
                              DIALOG_PARENT = Self.tlbID             ,     $
                              /QUESTION )
   IF (question EQ 'Yes') THEN Self->savePlanToDatabase
   CASE eisEventOn OF
      0    : WIDGET_CONTROL , widIDs.ra_eisEventID , set_button = 1
      ELSE : WIDGET_CONTROL , widIDs.ra_eisEventID , set_button = 0
   ENDCASE
   RETURN , 0
ENDIF

; Flag/Unflag this studyRaster as EIS Event hunter
sc.eis_event_response.respond_to_eis_event = eisEventOn
; Reset all flags
sc.studyRasters[index].eis_event_props.event_flag = BYTARR(25)

CASE eisEventOn OF
    0    : BEGIN
               print,"Disabling EIS Event Trigger"
               sc.eis_event_response.respond_to_eis_event = 0
               tc.respond_to_eis_event                    = 0
           END
    ELSE : BEGIN
               print,"Enabling EIS Event Trigger"
               sc.studyRasters[index].eis_event_props.event_flag[0]=1
               sc.eis_event_response.respond_to_eis_event = 1
               tc.respond_to_eis_event                    = 1
               ; By default, use Self.eis_event_control values
               new = eis_eise_control_to_props(sc.eis_event_response, $
                             sc.studyRasters[index].eis_event_props , $
                             Self.eis_event_control)
               sc.eis_event_response                  = new.sty_props
               sc.studyRasters[index].eis_event_props = new.sra_props
           END
ENDCASE

; Update value - and re-calculate study duration
tl.time_component    = tc
tl.science_component = sc
temp->set , tl
; Update raster widgets
Self->updateStudyRasterListWidget
; Redraw timeline graphics
Self.o_eis_timeline_plot_gui->initialize_plot , /no_refresh

; Re-select selected raster
WIDGET_CONTROL , widIDs.pl_raListID , set_list_select = index
WIDGET_CONTROL , widIDs.ra_eventsBaseID , sensitive = 1

; Code to automatically invoke the EIS EVENT GUI when toggled ON
; IF (eisEventOn EQ 1) THEN BEGIN
;    IF (OBJ_VALID(Self.eis_event_gui) EQ 1) THEN RETURN , 1
;    tl    = temp->get()
;    sra   = tl.science_component.studyRasters[index]
;    ; Invoke EIS Event GUI
;    Self.eis_event_gui = OBJ_NEW("eis_event_gui"                      ,     $
;                               Self                                   ,     $
;                               ll_id     = sra.ll_id                  ,     $
;                               eise_flag = sra.eis_event_props.event_flag )
;    Self.eis_event_gui->Realize
;    Self.eis_event_gui->XMANAGER
; ENDIF

RETURN , 1

END
;______________________________________________________________________________
; Toggle EIS Flare
;______________________________________________________________________________
FUNCTION eis_mk_plan_gui::toggleEISFlare

widIDs = Self.eis_mk_plan_widgets
; Is XRT Flare button selected?
xrtFlareOn = WIDGET_INFO( widIDs.ra_xrtFlareID , /BUTTON_SET)
IF (xrtFlareOn EQ 1) THEN BEGIN
   WIDGET_CONTROL , widIDs.ra_eisFlareID , set_button = 0
   BEEP
   mText = "Operation not allowed. XRT Flare trigger is enabled."
   complain = DIALOG_MESSAGE(mText ,                        $
                                 DIALOG_PARENT = Self.tlbID,          $
                                 /ERROR )
   RETURN , 0
ENDIF
; Is EIS Event button selected?
eisEventOn = WIDGET_INFO( widIDs.ra_eisEventID , /BUTTON_SET)
IF (eisEventOn EQ 1) THEN BEGIN
   WIDGET_CONTROL , widIDs.ra_eisFlareID , set_button = 0
   BEEP
   mText = "Operation not allowed. EIS Event trigger is enabled."
   complain = DIALOG_MESSAGE(mText ,                        $
                                 DIALOG_PARENT = Self.tlbID,          $
                                 /ERROR )
   RETURN , 0
ENDIF

; Get index of selected studyRaster
index  = WIDGET_INFO(widIDs.pl_raListID , /LIST_SELECT)

; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = working_position
temp   = Self.eis_timeline_container->get( position = working_position)
tl     = temp->get()
sc     = tl.science_component
tc     = tl.time_component
seq_id = tc.sequence_id

; Is button selected?
eisFlareOn = WIDGET_INFO( widIDs.ra_eisFlareID , /BUTTON_SET)

; Can't handle seq_ids of zero. So make sure this can't happen
; JAR 5-Mar-2009
IF (tc.sequence_id LE 0) THEN BEGIN
   BEEP
   mText    = STRARR(2)
   mText[0] = 'This timeline entry must be saved first.'
   mText[1] = 'Do you want to save the plan now?'
   question = DIALOG_MESSAGE( mText                                  ,     $
                              DIALOG_PARENT = Self.tlbID             ,     $
                              /QUESTION )
   IF (question EQ 'Yes') THEN Self->savePlanToDatabase
   CASE eisFlareOn OF
      0    : WIDGET_CONTROL , widIDs.ra_eisFlareID , set_button = 1
      ELSE : WIDGET_CONTROL , widIDs.ra_eisFlareID , set_button = 0
   ENDCASE
   RETURN , 0
ENDIF

; 01-Dec-2014
; Toggle eisf flags on/off depending on the state of the button
tc.respond_to_eis_flare                              = eisFlareOn < 1
sc.eis_flare_response.respond_to_eis_flare           = eisFlareOn < 1
sc.studyRasters[index].eis_flare_props.flare_flag    = BYTARR(25)
sc.studyRasters[index].eis_flare_props.flare_flag[0] = eisFlareOn < 1
mText = ['Disabling','Enabling']
print,STRJOIN([mText[eisFlareOn < 1],' EIS Flare Trigger'],/SINGLE)

;
; OK, at this point, save eis_flare properties to TL DB. Will be saved
; again at the end of this method - but do it here for insurance!
status = eis_update_timeline_science_entry(seq_id , sc)
status = eis_update_timeline_entry(        seq_id , tc)

; IF toggling OFF, then bail out here
IF (eisFlareOn EQ 0) THEN BEGIN

   ; Update value - and re-calculate study duration
   tl.time_component    = tc
   tl.science_component = sc
   temp->set , tl
   ; Update raster widgets
   Self->updateStudyRasterListWidget

   ; Redraw timeline graphics
   Self.o_eis_timeline_plot_gui->initialize_plot

   ; Re-select selected raster
   WIDGET_CONTROL , widIDs.pl_raListID , set_list_select = index
   WIDGET_CONTROL , widIDs.ra_eventsBaseID , sensitive = 1

   RETURN , 1

ENDIF

; OK, so the button has been toggled on.

; The corresponding response DB entry id is stored in;
; sc.eis_flare_response.response_study_id. If this value is zero
; then we need to create a new response DB entry, and store its
; id here. If it is non-zero, then the response DB entry already
; exists - and we just need to update it.


old_resp_id = sc.eis_flare_response.response_study_id
; Is it zero or non-zero
IF (old_resp_id EQ 0) THEN BEGIN

   ; 1. Create new response DB entry
   nEntries    = eis_db_get_num_response_entries()
   new_resp_id = nEntries + 1
   r_struct    = Self->get_new_response_structure(new_resp_id,tc,sc, $
                                   index, /eis_flare)
   db_save_response_entry_create , r_struct
   ; 2. Save response DB entry id to TL DB; specifically to the tag
   ;   sc.xrt_flare_response.response_study_id.
   sc.eis_flare_response.response_study_id = new_resp_id

ENDIF ELSE BEGIN

   ; Now re-initialise response structure and update response DB entry
   ; (whose id exists already)
   r_struct = Self->get_new_response_structure(old_resp_id,  $
                                tc,sc,index, /eis_flare)
   db_save_response_entry_update , r_struct

ENDELSE

; Actually update the TL DB for this entry
status = eis_update_timeline_science_entry(seq_id , sc)
status = eis_update_timeline_entry(        seq_id , tc)

; Update value - and re-calculate study duration
tl.time_component    = tc
tl.science_component = sc
temp->set , tl
; Update raster widgets
Self->updateStudyRasterListWidget

; Redraw timeline graphics
Self.o_eis_timeline_plot_gui->initialize_plot

; Re-select selected raster
WIDGET_CONTROL , widIDs.pl_raListID , set_list_select = index
WIDGET_CONTROL , widIDs.ra_eventsBaseID , sensitive = 1

RETURN , 1

END
;______________________________________________________________________________
; Toggle XRT Flare
;______________________________________________________________________________
FUNCTION eis_mk_plan_gui::toggleXRTFlare

widIDs = Self.eis_mk_plan_widgets
; Is EIS Event button selected?
eisEventOn = WIDGET_INFO( widIDs.ra_eisEventID , /BUTTON_SET)
IF (eisEventOn EQ 1) THEN BEGIN
   WIDGET_CONTROL , widIDs.ra_xrtFlareID , set_button = 0
   BEEP
   mText = "Operation not allowed. EIS Event trigger is enabled."
   complain = DIALOG_MESSAGE(mText ,                        $
                                 DIALOG_PARENT = Self.tlbID,          $
                                 /ERROR )
   RETURN , 0
ENDIF
; Is EIS Flare button selected?
eisFlareOn = WIDGET_INFO( widIDs.ra_eisFlareID , /BUTTON_SET)
IF (eisFlareOn EQ 1) THEN BEGIN
   WIDGET_CONTROL , widIDs.ra_xrtFlareID , set_button = 0
   BEEP
   mText = "Operation not allowed. EIS Flare trigger is enabled."
   complain = DIALOG_MESSAGE(mText ,                        $
                                 DIALOG_PARENT = Self.tlbID,          $
                                 /ERROR )
   RETURN , 0
ENDIF

; Get index of selected studyRaster
index  = WIDGET_INFO(widIDs.pl_raListID , /LIST_SELECT)

; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = working_position
temp   = Self.eis_timeline_container->get( position = working_position)
tl     = temp->get()
tc     = tl.time_component
sc     = tl.science_component
seq_id = tc.sequence_id

; Is button selected?
xrtFlareOn = WIDGET_INFO( widIDs.ra_xrtFlareID , /BUTTON_SET)

; Can't handle seq_ids of zero. So make sure this can't happen
; JAR 5-Mar-2009
IF (tc.sequence_id LE 0) THEN BEGIN
   BEEP
   mText    = STRARR(2)
   mText[0] = 'This timeline entry must be saved first.'
   mText[1] = 'Do you want to save the plan now?'
   question = DIALOG_MESSAGE( mText                                  ,     $
                              DIALOG_PARENT = Self.tlbID             ,     $
                              /QUESTION )
   IF (question EQ 'Yes') THEN Self->savePlanToDatabase
   CASE xrtFlareOn OF
      0    : WIDGET_CONTROL , widIDs.ra_xrtFlareID , set_button = 1
      ELSE : WIDGET_CONTROL , widIDs.ra_xrtFlareID , set_button = 0
   ENDCASE
   RETURN , 0
ENDIF

; 28-Jun-2013
; Toggle xrtf flags on/off depending on the state of the button
; This code replaces that below.
tc.respond_to_xrt_flare                         = xrtFlareOn < 1
sc.xrt_flare_response.respond_to_xrt_flare      = xrtFlareOn < 1
sc.studyRasters[index].xrt_flare_props.xrt_flag = xrtFlareOn < 1
mText = ['Disabling','Enabling']
print,STRJOIN([mText[xrtFlareOn < 1],' XRT Flare Trigger'],/SINGLE)

;
; OK, at this point, save xrt_flare properties to TL DB. Will be saved
; again at the end of this method - but do it here for insurance!
status = eis_update_timeline_science_entry(seq_id , sc)
status = eis_update_timeline_entry(        seq_id , tc)

; IF toggling OFF, then bail out here
IF (xrtFlareOn EQ 0) THEN BEGIN

   ; Update value - and re-calculate study duration
   tl.time_component    = tc
   tl.science_component = sc
   temp->set , tl
   ; Update raster widgets
   Self->updateStudyRasterListWidget

   ; Redraw timeline graphics
   Self.o_eis_timeline_plot_gui->initialize_plot

   ; Re-select selected raster
   WIDGET_CONTROL , widIDs.pl_raListID , set_list_select = index
   WIDGET_CONTROL , widIDs.ra_eventsBaseID , sensitive = 1

   RETURN , 1

ENDIF

; OK, so the button has been toggled on.

; The corresponding response DB entry id is stored in;
; sc.xrt_flare_response.response_study_id. If this value is zero
; then we need to create a new response DB entry, and store its
; id here. If it is non-zero, then the response DB entry already
; exists - and we just need to update it.


old_resp_id = sc.xrt_flare_response.response_study_id
; Is it zero or non-zero
IF (old_resp_id EQ 0) THEN BEGIN

   ; 1. Create new response DB entry
   nEntries    = eis_db_get_num_response_entries()
   new_resp_id = nEntries + 1
   r_struct    = Self->get_new_response_structure(new_resp_id,tc,sc ,   $
                              index, /xrt_flare)
   db_save_response_entry_create , r_struct
   ; 2. Save response DB entry id to TL DB; specifically to the tag
   ;   sc.xrt_flare_response.response_study_id.
   sc.xrt_flare_response.response_study_id = new_resp_id

ENDIF ELSE BEGIN

   ; Now re-initialise response structure and update response DB entry
   ; (whose id exists already)
   r_struct = Self->get_new_response_structure(old_resp_id,  $
                                tc,sc,index, /xrt_flare)
   db_save_response_entry_update , r_struct

ENDELSE

; Actually update the TL DB for this entry
status = eis_update_timeline_science_entry(seq_id , sc)
status = eis_update_timeline_entry(        seq_id , tc)

; Update value - and re-calculate study duration
tl.time_component    = tc
tl.science_component = sc
temp->set , tl
; Update raster widgets
Self->updateStudyRasterListWidget

; Redraw timeline graphics
Self.o_eis_timeline_plot_gui->initialize_plot

; Re-select selected raster
WIDGET_CONTROL , widIDs.pl_raListID , set_list_select = index
WIDGET_CONTROL , widIDs.ra_eventsBaseID , sensitive = 1

RETURN , 1

END
;______________________________________________________________________________
; Create a new (default) response DB entry structure
;______________________________________________________________________________
PRO eis_mk_plan_gui::refresh_plot

; Redraw timeline graphics
Self.o_eis_timeline_plot_gui->initialize_plot

END
;______________________________________________________________________________
; Create a new (default) response DB entry structure
;______________________________________________________________________________
FUNCTION eis_mk_plan_gui::get_new_response_structure , new_resp_id , $
                        tc,sc,index , xrt_flare = xrt_flare ,        $
                        eis_flare = eis_flare

r_struct               = {eis_response_props}
r_struct.id            = new_resp_id
r_struct.trig_st_seqid = tc.sequence_id ; LONG 33202
IF (KEYWORD_SET(xrt_flare) EQ 1) THEN BEGIN
   r_struct.xrtf_respond  = 1B
   r_struct.type          = 'xrtf'
   ; Verify FOV - use "line_index" tag
   r_struct.line_index    = 1
   r_struct.adjust_x      = 1
   r_struct.adjust_y      = 1
   ; Get default x0 and y0 values
   x0y0                   = eis_get_default_x0y0()
   r_struct.locate_x      = x0y0[0]    ; Really x0
   r_struct.locate_y      = x0y0[1]    ; Really y0
ENDIF
IF (KEYWORD_SET(eis_flare) EQ 1) THEN BEGIN
   r_struct.eisf_respond  = 1B
   r_struct.type          = 'eisf'
   r_struct.x_min_limit   = 1
   r_struct.y_min_limit   = 1
   r_struct.x_threshold   = 1
   r_struct.y_threshold   = 1
   r_struct.adjust_x      = 1
   r_struct.adjust_y      = 1
   r_struct.locate_x      = 1 ; Flare peak
   r_struct.locate_y      = 1 ; Flare peak
ENDIF
; Inherit pointing from hunter study. Retain MIP and YIP, and recalculate
; solar pointing coordinates

ra_id = sc.studyRasters[index].ra_id
mip   = sc.studyRasters[index].mip
yip   = sc.studyRasters[index].yip
sc_x  = sc.studyRasters[index].sc_x
sc_y  = sc.studyRasters[index].sc_y

; If this is an XRTF response, then set the YIP = 306
IF (KEYWORD_SET(xrt_flare) EQ 1) THEN yip   = 306


; OK, calculate xcen and ycen
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; JAR 1-Apr-2014. Add "obs_id" and "aia_time" inputs to routine
; "eis_pointing_offset"
obs_id   = sc.obs_id
aia_time = sc.studyRasters[index].ra_start_time
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; JAR 27-Aug-2014. Add "sot_offset" input to routine
; "eis_get_xy_point"
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; JAR 27-Aug-2014. Get sot_offsets from tl.sc.disturbance
sot_offset = FLOAT(STRSPLIT(sc.disturbance,',',/EXTRACT))

xycen = eis_get_xy_point(sc_x , sc_y , mip , yip , ra_id   ,   $
                         obs_id , aia_time , sot_offset)

; Hunter st_id   = 478, MIP/YIP = 1232,306
; Response st_id = 479, MIP/YIP = 1232,306

; Now let's update these values
r_struct.ra1_xcen      = xycen.x_point
r_struct.ra1_ycen      = xycen.y_point
r_struct.ra1_mip       = mip
r_struct.ra1_yip       = yip
r_struct.ra1_sc_x      = sc_x
r_struct.ra1_sc_y      = sc_y

RETURN , r_struct

END
; ;______________________________________________________________________________
; ; Update OBS_ID
; ;______________________________________________________________________________
; FUNCTION eis_mk_plan_gui::update_obs_id
;
; widIDs = Self.eis_mk_plan_widgets
; ; Get OBS_ID
; WIDGET_CONTROL , widIDs.st_obs_idID , get_value = newValue
;
; IF (is_number(newValue[0]) NE 1) THEN newValue = 0L
;
; ; Get working_position (index of selected study)
; Self.eis_timeline_container->getProperty, working_position = working_position
; temp  = Self.eis_timeline_container->get( position = working_position)
; s     = temp->get()
;
; ; Update value
; temp->update_study_tag , obs_id = newValue
;
; RETURN , 1
;
; END
;______________________________________________________________________________
; Update Pointing Mode
;______________________________________________________________________________
FUNCTION eis_mk_plan_gui::update_point_mode

widIDs = Self.eis_mk_plan_widgets
; Get droplist selection index
new_obs_id = WIDGET_INFO(widIDs.pointmodeID,/DROPLIST_SELECT)

; Now what is the current obs_id? If it is the same then don't do anything.
; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = wp
temp       = Self.eis_timeline_container->get( position = wp)
tl         = temp->get()
old_obs_id = tl.science_component.obs_id

IF (new_obs_id EQ old_obs_id) THEN RETURN , 0

; OK, update the "obs_id" value
temp->update_study_tag , obs_id = new_obs_id

; Need some logic here to decide what to do with SOT offset.
; 1. If new selection is item 2 (AIA + SOT) then add SOT offset
; 2. If changing from 2 to 0 or 1, then subtract SOT offset
; 3. If toggling between 0 and 1, then no SOT offset is involved.
;
; This could be reduced to 2 conditions;
; 1. The new selected item is  2. Add      the SOT offset
; 2. The old selected item was 2. Subtract the SOT offset

; I've edited the routine "eis_pointing_offset" to set the sot_offset
; values as [0.,0.].


; So, if neither of these conditions is true, just refresh the pointing
; (as usual), and bail out
IF ((new_obs_id NE 2) AND (old_obs_id NE 2)) THEN BEGIN
   ; OK, so the Pointing Mode is to be changed.
   Self->pointing_refresh , /no_change
   RETURN , 1
ENDIF

mText = STRING(format='(D0.1,A-1,D0.1)'                                ,   $
               Self.sot_offset[0],',',Self.sot_offset[1])
print,STRJOIN([' + Updating the SOT offset = ',mText],/SINGLE)

; Loop over each studyraster, and update the pointing accordingly
FOR i = 0 , tl.science_component.nrasters -1 DO BEGIN

   ; Get studyRaster
   sra      = tl.science_component.studyRasters[i]

   IF (new_obs_id EQ 2) THEN BEGIN
       print,' Apply SOT offset'
       new_xcen = sra.x_point + Self.sot_offset[0]
       new_ycen = sra.y_point + Self.sot_offset[1]
   ENDIF

   ; This condition (1)
   IF (old_obs_id EQ 2) THEN BEGIN
       print,' Remove SOT offset'
       new_xcen = sra.x_point - Self.sot_offset[0]
       new_ycen = sra.y_point - Self.sot_offset[1]
   ENDIF

   ; Now calculate the corresponding MIP and YIP
   delx  = sra.sc_x - new_xcen
   dely  = sra.sc_y - new_ycen
   ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   ; JAR 1-Apr-2014. Add "obs_id" and "aia_time" inputs to routine
   ; "eis_get_mirror_position"
   obs_id   = new_obs_id
   aia_time = sra.ra_start_time
   ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   ; JAR 27-Aug-2014. Add "sot_offset" input to routine
   ; "eis_get_mirror_position"
   ;sot_offset = FLOAT(STRSPLIT(s.science_component.disturbance,',',/EXTRACT))
   sot_offset = [0.,0.]
   ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   mirror_pos = eis_get_mirror_position(delx , dely , sra.ra_id ,  $
                                obs_id , aia_time , sot_offset)


   ; Set temp.working_raster
   temp->set_index   , i
   ; And then update each sra's new xcen, ycen, mip and yip pointing
   temp->setProperty , x_point = new_xcen
   temp->setProperty , y_point = new_ycen
   temp->setProperty , mip     = mirror_pos.mip
   temp->setProperty , yip     = mirror_pos.ystart


ENDFOR

; Get index of selected studyRaster
index = WIDGET_INFO(widIDs.pl_raListID , /LIST_SELECT)

; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = wp
temp       = Self.eis_timeline_container->get( position = wp)
tl         = temp->get()
sra        = tl.science_component.studyRasters[index]

; Update widget values
x_point  = STRTRIM(STRING(format='(F-10.2)',sra.x_point),2)
y_point  = STRTRIM(STRING(format='(F-10.2)',sra.y_point),2)
mip_text = STRTRIM(STRING(format='(I-4)' , ROUND(sra.mip)),2)
yip_text = STRTRIM(STRING(format='(I-4)' , ROUND(sra.yip)),2)
WIDGET_CONTROL , widIDs.pl_ra_xpointID , set_value = x_point
WIDGET_CONTROL , widIDs.pl_ra_ypointID , set_value = y_point
WIDGET_CONTROL , widIDs.pl_ra_mipInID  , set_value = mip_text
WIDGET_CONTROL , widIDs.pl_ra_yipInID  , set_value = yip_text

Self->updateStudyRasterListWidget

; Issue warning if MIP = or < 160
mip_warning = "The PZT is non-linear between 0 and 160 steps."
IF (sra.mip LE 160) THEN BEGIN
   warning = DIALOG_MESSAGE( mip_warning                             ,     $
                             DIALOG_PARENT = Self.tlbID)
ENDIF

;
; Update Plan Summary Tool
;
Self->refreshSummary
Self->plot_pointing

; OK, so the Pointing Mode is to be changed.
Self->pointing_refresh , /no_change

RETURN , 1

END
;______________________________________________________________________________
; Update JOP_ID
;______________________________________________________________________________
FUNCTION eis_mk_plan_gui::update_jop_id

widIDs = Self.eis_mk_plan_widgets
; Get JOP_ID
WIDGET_CONTROL , widIDs.st_jop_idID , get_value = newValue

IF (is_number(newValue[0]) NE 1) THEN newValue = 0L

; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = working_position
temp  = Self.eis_timeline_container->get( position = working_position)
s     = temp->get()

; Update value
temp->update_study_tag , jop_id = newValue

RETURN , 1

END
;______________________________________________________________________________
; Update OBS_ID
;______________________________________________________________________________
FUNCTION eis_mk_plan_gui::update_noaa_num

widIDs = Self.eis_mk_plan_widgets
; Get NOAA_NUM
WIDGET_CONTROL , widIDs.st_noaa_numID , get_value = newValue

IF (is_number(newValue[0]) NE 1) THEN newValue = 0L

; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = working_position
temp  = Self.eis_timeline_container->get( position = working_position)
s     = temp->get()

; Update value
temp->update_study_tag , noaa_num = newValue

RETURN , 1

END
;______________________________________________________________________________
; Update OBSTITLE
;______________________________________________________________________________
FUNCTION eis_mk_plan_gui::update_obstitle

widIDs = Self.eis_mk_plan_widgets
; Get NOAA_NUM
WIDGET_CONTROL , widIDs.st_obstitleTextID , get_value = newValue

; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = working_position
temp  = Self.eis_timeline_container->get( position = working_position)
s     = temp->get()

; Update value
temp->update_study_tag , obstitle = newValue

RETURN , 1

END
;______________________________________________________________________________
; Update OBS_DEC
;______________________________________________________________________________
FUNCTION eis_mk_plan_gui::update_obs_dec

widIDs = Self.eis_mk_plan_widgets
; Get NOAA_NUM
WIDGET_CONTROL , widIDs.st_obsdecTextID , get_value = newValue

; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = working_position
temp  = Self.eis_timeline_container->get( position = working_position)
s     = temp->get()

; Update value
temp->update_study_tag , obs_dec = newValue

RETURN , 1

END
;______________________________________________________________________________
; Reset Raster Compression
;______________________________________________________________________________
FUNCTION eis_mk_plan_gui::reset_ra_compression

widIDs   = Self.eis_mk_plan_widgets
; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = wp
temp = Self.eis_timeline_container->get( position = wp)
tl   = temp->get()
; Get index of selected studyRaster
ra_index = WIDGET_INFO(widIDs.pl_raListID , /LIST_SELECT)
sra      = tl.science_component.studyRasters[ra_index]
tl_comp  = sra.ra_compression
;
; Get Original Compression
;
status = eis_open_db(/RASTER)
ra_comp  = dbval(sra.ra_id , 'COMPRESSION')
dbclose

; Only change if different!
IF (tl_comp EQ ra_comp) THEN RETURN , 0

; Set value accordinly
temp->setProperty , compression = ra_comp

; Update value - and re-calculate study duration
temp->setProperty , ra_repeats = newValue
temp->update_study_properties
; Update Study Duration and Volume values
Self->updateDurationAndVolume
; Update raster widgets
Self->updateStudyRasterListWidget
; Update Compression droplist widget
WIDGET_CONTROL , widIDs.pl_ra_compDropListID , set_droplist_select = ra_comp

RETURN , 1

END
;______________________________________________________________________________
; Update Raster Compression
;______________________________________________________________________________
FUNCTION eis_mk_plan_gui::update_ra_compression , event

widIDs   = Self.eis_mk_plan_widgets
; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = wp
temp = Self.eis_timeline_container->get( position = wp)
tl   = temp->get()
; Get index of selected studyRaster
ra_index = WIDGET_INFO(widIDs.pl_ra_compDropListID , /LIST_SELECT)

; Set value accordinly
temp->setProperty , compression = event.index

; Update value - and re-calculate study duration
temp->setProperty , ra_repeats = newValue
temp->update_study_properties
; Update Study Duration and Volume values
Self->updateDurationAndVolume
; Update raster widgets
Self->updateStudyRasterListWidget

RETURN , 1

END
;______________________________________________________________________________
; Update Raster Repeats
;______________________________________________________________________________
FUNCTION eis_mk_plan_gui::update_ra_repeats

widIDs = Self.eis_mk_plan_widgets
; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = wp      ,     $
                                          all_blocks       = all_blocks
temp  = Self.eis_timeline_container->get( position = wp)
tl    = temp->get()
; Get index of selected studyRaster
index = WIDGET_INFO(widIDs.pl_raListID , /LIST_SELECT)

; Get widget value
WIDGET_CONTROL , widIDs.pl_ra_repeatsID , get_value = newValue
ra_repeats = tl.science_component.studyRasters[index].ra_repeats
; arguments-> name , newValue , oldValue , minValue , maxValue , multiple
valid  = eis_validate_input('Raster Repeats' , newValue[0] ,                $
                              ra_repeats , 1 , 4095 , /ALLOW_SAME)

valid_2 = {valid:0B , mText:'' , curr_tl_list:-1}
IF (valid.valid EQ 1) THEN BEGIN
   ;
   ; Do checking here!
   ;
   valid_2 = eis_check_raster_repeats(Self , index , newValue[0])
ENDIF

IF (valid.valid EQ 1) AND (valid_2.valid NE 1) THEN BEGIN
   valid.valid = 0B
   valid.mText = valid_2.mText
ENDIF

CASE valid.valid OF
    0:  BEGIN
            BEEP
            complain = DIALOG_MESSAGE( valid.mText ,                        $
                                 DIALOG_PARENT = Self.tlbID,                $
                                 /ERROR )
            WIDGET_CONTROL , widIDs.pl_ra_repeatsID , set_value =          $
                                    STRCOMPRESS(ra_repeats,/REMOVE_ALL)
            print,''
            print,'    Raster Repeats Operation : Unsuccessful'
            print,'++++++++++++++++++++++++++++++++++++++++++++++++++' +   $
                  '++++++++++++++++++++++++++++++++'

            RETURN , 0
        END
    1:  newValue = FIX(newValue[0])
ENDCASE

; Update widget value
ra_repeats = STRCOMPRESS(newValue,/REMOVE_ALL)
WIDGET_CONTROL , widIDs.pl_ra_repeatsID , set_value = ra_repeats

FOR i = 0, N_ELEMENTS(valid_2.curr_tl_list) - 1 DO BEGIN

   temp  = Self.eis_timeline_container->get( position = valid_2.curr_tl_list[i])
   tl    = temp->get()
   IF (tl.time_component.read_all NE 1) THEN BEGIN
       temp->get_all_info
       tl = temp->get()
   ENDIF
   IF (valid_2.curr_tl_list[i] EQ wp) THEN BEGIN
       temp->setProperty , ra_repeats = newValue
       temp->update_study_properties
       temp  = Self.eis_timeline_container->get( position = wp)
       tl = temp->get()
   ENDIF

   ; Where are we in the block? Only need to move next entries. Not
   ; the selected one or any previous entries in the block
   IF (valid_2.curr_tl_list[i] GT wp) THEN BEGIN

       ; Get stop_time of previous entry
       prev_index = valid_2.curr_tl_list[i-1]
       prev_temp  = Self.eis_timeline_container->get( position = prev_index)
       prev_temp->getProperty , end_time = new_start_time
       ; Get Science or Engineering
       CASE tl.time_component.entry_type OF
           'S'  : temp->move_tl_entry     , new_start_time + 0.1
           'E'  : temp->move_tl_eng_entry , new_start_time + 0.1
           ELSE :
       ENDCASE

    ENDIF

ENDFOR

Self.eis_timeline_container->reorganise_container

; Update Study Duration and Volume values
Self->updateDurationAndVolume
; Update raster widgets
Self->updateStudyRasterListWidget

;
; Update Plan Summary Tool
;
Self->refreshSummary
Self->refresh_dr_gui

;
; Finally, want to set current time to end of last study
;
Self.eis_timeline_container->getProperty, working_position = wp
temp  = Self.eis_timeline_container->get( position = wp)
temp->getProperty , end_time = end_time
Self.cursor_time_gui->setProperty , datetime = end_time
; Redraw timeline graphics
Self.o_eis_timeline_plot_gui->initialize_plot

RETURN , valid.valid

END
;______________________________________________________________________________
; Update MIP text box
;______________________________________________________________________________
FUNCTION eis_mk_plan_gui::update_mip

widIDs = Self.eis_mk_plan_widgets
; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = working_position
temp  = Self.eis_timeline_container->get( position = working_position)
s     = temp->get()
; Get index of selected studyRaster
index = WIDGET_INFO(widIDs.pl_raListID , /LIST_SELECT)
; Get studyRaster
sra   = s.science_component.studyRasters[index]

; Get new x_point value
WIDGET_CONTROL , widIDs.pl_ra_mipInID , get_value = newValue
; arguments-> name , newValue , oldValue , minValue , maxValue , multiple
valid  = eis_validate_input('MIP' , newValue[0] ,                     $
                              sra.mip , 0 , 2400.)

CASE valid.valid OF
    0:  BEGIN
            newValue = sra.mip
            BEEP
            complain = DIALOG_MESSAGE( valid.mText ,                        $
                                 DIALOG_PARENT = Self.tlbID,                $
                                 /ERROR )
        END
    1:  newValue = ROUND(DOUBLE(newValue[0]))
ENDCASE

mip_warning = "The PZT is non-linear between 0 and 160 steps."
IF (newValue LE 160) THEN BEGIN
   warning = DIALOG_MESSAGE( mip_warning                             ,     $
                             DIALOG_PARENT = Self.tlbID)
ENDIF

; Update value
temp->setProperty , mip = newValue

; Update widget values
;; MIP Label
;mip_label = STRING(format='(A-8,I-6)'  , '  MIP = ' , newValue)
;WIDGET_CONTROL , widIDs.pl_ra_mipID     , set_value = mip_label
; MIP Text Box
mip_text = STRTRIM(STRING(format='(I4)',newValue),2)
WIDGET_CONTROL , widIDs.pl_ra_mipInID , set_value = mip_text

; Get x_point
; Changed MIP from 1038 to 1034 -> x_point 0. to 1.
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; JAR 1-Apr-2014. Add "obs_id" and "aia_time" inputs to routine
; "eis_get_xy_point"
obs_id   = s.science_component.obs_id
aia_time = sra.ra_start_time
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; JAR 27-Aug-2014. Add "sot_offset" input to routine
; "eis_get_xy_point"
sot_offset = FLOAT(STRSPLIT(s.science_component.disturbance,',',/EXTRACT))
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
xy_point = eis_get_xy_point(sra.sc_x                        ,              $
                            sra.sc_y                        ,              $
                            newValue                        ,              $
                            sra.yip                         ,              $
                            sra.ra_id                       ,              $
                            obs_id                          ,              $
                            aia_time                        ,              $
                            sot_offset)

temp->setProperty , x_point = xy_point.x_point

;
; Update x_point widget
;
x_point_text = STRTRIM(STRING(format='(F-10.2)',xy_point.x_point),2)
WIDGET_CONTROL , widIDs.pl_ra_xpointID , set_value = x_point_text

Self->updateStudyRasterListWidget
Self->plot_pointing

;
; Update Plan Summary Tool
;
Self->refreshSummary

RETURN , valid.valid

END
;______________________________________________________________________________
; Update MIP text box
;______________________________________________________________________________
FUNCTION eis_mk_plan_gui::update_yip

widIDs = Self.eis_mk_plan_widgets
; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = working_position
temp  = Self.eis_timeline_container->get( position = working_position)
s     = temp->get()
; Get index of selected studyRaster
index = WIDGET_INFO(widIDs.pl_raListID , /LIST_SELECT)
; Get studyRaster
sra   = s.science_component.studyRasters[index]

; Get new x_point value
WIDGET_CONTROL , widIDs.pl_ra_yipInID , get_value = newValue
; arguments-> name , newValue , oldValue , minValue , maxValue , multiple

valid  = eis_validate_input('YIP' , newValue[0] ,                     $
                              sra.yip , 1 , 1024.)

;
; JAR & PRY 7-Mar-2008
; Check yip + raster height =< 1024
;
IF (newValue[0] + sra.windHeight GT 1024) THEN BEGIN
    valid.valid = 0
    valid.mText = "Raster extends off CCD. Aborting!"
ENDIF

CASE valid.valid OF
    0:  BEGIN
            newValue = sra.yip
            BEEP
            complain = DIALOG_MESSAGE( valid.mText ,                        $
                                 DIALOG_PARENT = Self.tlbID,                $
                                 /ERROR )
        END
    1:  newValue = ROUND(DOUBLE(newValue[0]))
ENDCASE

; Update value
temp->setProperty , yip = newValue

; Update widget values
;; MIP Label
;mip_label = STRING(format='(A-8,I-6)'  , '  MIP = ' , newValue)
;WIDGET_CONTROL , widIDs.pl_ra_mipID     , set_value = mip_label
; MIP Text Box
yip_text = STRTRIM(STRING(format='(I4)',newValue),2)
WIDGET_CONTROL , widIDs.pl_ra_yipInID , set_value = yip_text

; Get y_point
; Get x_point
; Changed MIP from 1038 to 1034 -> x_point 0. to 1.
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; JAR 1-Apr-2014. Add "obs_id" and "aia_time" inputs to routine
; "eis_get_xy_point"
obs_id   = s.science_component.obs_id
aia_time = sra.ra_start_time
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; JAR 27-Aug-2014. Add "sot_offset" input to routine
; "eis_get_xy_point"
sot_offset = FLOAT(STRSPLIT(s.science_component.disturbance,',',/EXTRACT))
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
xy_point = eis_get_xy_point(sra.sc_x                        ,              $
                            sra.sc_y                        ,              $
                            sra.mip                         ,              $
                            newValue                        ,              $
                            sra.ra_id                       ,              $
                            obs_id                          ,              $
                            aia_time                        ,              $
                            sot_offset)

temp->setProperty , y_point = xy_point.y_point
;print,xy_point.y_point

;
; Update x_point widget
;
y_point_text = STRTRIM(STRING(format='(F-10.2)',xy_point.y_point),2)
WIDGET_CONTROL , widIDs.pl_ra_ypointID , set_value = y_point_text
Self->updateStudyRasterListWidget
Self->plot_pointing

;
; Update Plan Summary Tool
;
Self->refreshSummary

RETURN , valid.valid

END
;______________________________________________________________________________
; Update x_point
;______________________________________________________________________________
FUNCTION eis_mk_plan_gui::update_x_point

widIDs = Self.eis_mk_plan_widgets
; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = working_position
temp  = Self.eis_timeline_container->get( position = working_position)
s     = temp->get()
; Get index of selected studyRaster
index = WIDGET_INFO(widIDs.pl_raListID , /LIST_SELECT)
; Get studyRaster
sra   = s.science_component.studyRasters[index]

; Get new x_point value
WIDGET_CONTROL , widIDs.pl_ra_xpointID , get_value = newValue
; arguments-> name , newValue , oldValue , minValue , maxValue , multiple
valid  = eis_validate_input('X_POINT' , newValue[0] ,                     $
                              sra.x_point , -2000. , 2000.)

CASE valid.valid OF
    0:  BEGIN
            newValue = sra.x_point
            BEEP
            complain = DIALOG_MESSAGE( valid.mText ,                        $
                                 DIALOG_PARENT = Self.tlbID,                $
                                 /ERROR )
        END
    1:  newValue = DOUBLE(newValue[0])
ENDCASE

; Update value
temp->setProperty , x_point = newValue

; Update widget value
x_point = STRTRIM(STRING(format='(F-10.2)',newValue),2)
WIDGET_CONTROL , widIDs.pl_ra_xpointID , set_value = x_point
Self->updateStudyRasterListWidget

; Get MIP
;delx  = sra.sc_x - x_point
delx  = sra.sc_x - newValue
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; JAR 1-Apr-2014. Add "obs_id" and "aia_time" inputs to routine
; "eis_get_mirror_position"
obs_id   = s.science_component.obs_id
aia_time = sra.ra_start_time
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; JAR 27-Aug-2014. Add "sot_offset" input to routine
; "eis_get_mirror_position"
sot_offset = FLOAT(STRSPLIT(s.science_component.disturbance,',',/EXTRACT))
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
mirror_pos = eis_get_mirror_position(delx , 0 , sra.ra_id ,  $
                                obs_id , aia_time , sot_offset)
temp->setProperty , mip = mirror_pos.mip

;
; Update MIP widgets
;
;; Label
;mip_label = STRING(format='(A-8,I-6)'  , '  MIP = ' , ROUND(mirror_pos.mip))
;WIDGET_CONTROL , widIDs.pl_ra_mipID     , set_value = mip_label
; Text Box
mip_text  = STRTRIM(STRING(format='(I-4)' , ROUND(mirror_pos.mip)),2)
WIDGET_CONTROL , widIDs.pl_ra_mipInID     , set_value = mip_text

; Issue warning if MIP = or < 160
mip_warning = "The PZT is non-linear between 0 and 160 steps."
IF (mirror_pos.mip LE 160) THEN BEGIN
   warning = DIALOG_MESSAGE( mip_warning                             ,     $
                             DIALOG_PARENT = Self.tlbID)
ENDIF

;
; Update Plan Summary Tool
;
Self->refreshSummary
Self->plot_pointing

RETURN , valid.valid

END
;______________________________________________________________________________
; Update y_point
;______________________________________________________________________________
FUNCTION eis_mk_plan_gui::update_y_point

widIDs = Self.eis_mk_plan_widgets
; Get new y_point value
Self.eis_timeline_container->getProperty, working_position = working_position
temp  = Self.eis_timeline_container->get( position = working_position)
s     = temp->get()
; Get index of selected studyRaster
index = WIDGET_INFO(widIDs.pl_raListID , /LIST_SELECT)
; Get studyRaster
sra   = s.science_component.studyRasters[index]


; Get Y_POINT
WIDGET_CONTROL , widIDs.pl_ra_ypointID , get_value = newValue
; arguments-> name , newValue , oldValue , minValue , maxValue , multiple
valid  = eis_validate_input('Y_POINT' , newValue[0] ,                     $
                              sra.y_point , -2000. , 2000.)

;
; JAR & PRY 7-Mar-2008
; Check that yip + raster height < 1024
;
; Get YIP
dely  = sra.sc_y - newValue[0]
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; JAR 1-Apr-2014. Add "obs_id" and "aia_time" inputs to routine
; "eis_pointing_offset"
obs_id   = s.science_component.obs_id
aia_time = sra.ra_start_time
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; JAR 27-Aug-2014. Add "sot_offset" input to routine
; "eis_get_mirror_position"
sot_offset = FLOAT(STRSPLIT(s.science_component.disturbance,',',/EXTRACT))
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
mirror_pos = eis_get_mirror_position(0 , dely , sra.ra_id   ,  $
                                obs_id , aia_time , sot_offset)

;
; JAR 18-Mar-2008. Add check that YIP is > 1.
;
IF (mirror_pos.yStart LT 1) THEN BEGIN
    valid.valid = 0
    valid.mText = "No can do. Otherwise YIP will fall outside its " + $
                  "min value (YIP > 1). Aborting!"
ENDIF

IF (mirror_pos.yStart + sra.windHeight GT 1023) THEN BEGIN
    valid.valid = 0
    valid.mText = "Raster extends off CCD. Aborting!"
ENDIF


CASE valid.valid OF
    0:  BEGIN
            newValue = sra.y_point
            BEEP
            complain = DIALOG_MESSAGE( valid.mText ,                        $
                                 DIALOG_PARENT = Self.tlbID,                $
                                 /ERROR )
        END
    1:  newValue = DOUBLE(newValue[0])
ENDCASE

; Update value
temp->setProperty , y_point = newValue

; Update widget value
y_point = STRTRIM(STRING(format='(F-10.2)',newValue),2)
WIDGET_CONTROL , widIDs.pl_ra_ypointID , set_value = y_point

Self->updateStudyRasterListWidget

; Get YIP
dely  = sra.sc_y - y_point
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; JAR 1-Apr-2014. Include "obs_id" and "aia_time" inputs to routine
; "eis_get_mirror_position"
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
mirror_pos = eis_get_mirror_position(0 , dely , sra.ra_id ,     $
                                     obs_id , aia_time , sot_offset)
; JAR 18-Mar-2008. Just for insurance
temp->setProperty , yip = mirror_pos.yStart > 1

;; Update YIP widget
;yip = STRING(format='(A-8,I-6)'  , '  YIP = ' , ROUND(mirror_pos.yStart))
;WIDGET_CONTROL , widIDs.pl_ra_yipID     , set_value = yip
; Text Box
yip_text  = STRTRIM(STRING(format='(I-4)' , ROUND(mirror_pos.yStart)),2)
WIDGET_CONTROL , widIDs.pl_ra_yipInID     , set_value = yip_text

;
; Update Plan Summary Tool
;
Self->refreshSummary
Self->plot_pointing

RETURN , valid.valid

END
;______________________________________________________________________________
; Get disp_stop
;______________________________________________________________________________
FUNCTION eis_mk_plan_gui::get_disp_stop

disp_stop =  Self.tl_graphics.axes.x_axis_day_tai        +                  $
            (Self.tl_graphics.axes.x_axis_length  * 3600.)
RETURN , disp_stop

END
;______________________________________________________________________________
; Update graphical pointing info
;______________________________________________________________________________
PRO eis_mk_plan_gui::plot_pointing , no_point = no_point

; Get widget IDs
widIDs = Self.eis_mk_plan_widgets
WIDGET_CONTROL , widIDs.pointingDrawID , get_value = drawPointID
WSET , drawPointID

; Retrieve default colour table properties
Self.o_def_ct->getProperty , plotsCT = plotsCT , imageCT = imageCT
TVLCT , plotsCT[*,0] , plotsCT[*,1] , plotsCT[*,2] ;IMAGE ct

PLOT , FINDGEN(3) , /NODATA , BACKGROUND = 0 , color = 0
geo = WIDGET_INFO(widIDs.pointingDrawID , /GEOMETRY)
sun_radius = 1000.
win_radius = geo.xSize/2.-1
ratio      = sun_radius/win_radius

; 25-Jun-2013 JAR
; Added DEVICE keyword to tvcircle routine. Now works again
tvcircle , win_radius , win_radius , win_radius , color = 5 , /FILL,/DEVICE
; Draw cross-hair
IF (KEYWORD_SET(no_point) NE 1) THEN Self->oplot_pointing , geo , sun_radius

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

END
;______________________________________________________________________________
; OPLot pointing cross-hair
;______________________________________________________________________________
PRO eis_mk_plan_gui::oplot_pointing , geo , sun_radius

widIDs = Self.eis_mk_plan_widgets
WIDGET_CONTROL , widIDs.pointingDrawID , get_value = drawPointID
WSET , drawPointID
; Get new y_point value
Self.eis_timeline_container->getProperty, working_position = wp
; Get index of selected studyRaster
index      = WIDGET_INFO(widIDs.pl_raListID , /LIST_SELECT)
IF (wp LT 0) OR (index EQ -1) THEN RETURN

temp  = Self.eis_timeline_container->get( position = wp)
tl    = temp->get()
win_radius = geo.xSize/2.-1
ratio      = sun_radius/win_radius
x          = tl.science_component.studyRasters[index].x_point
y          = tl.science_component.studyRasters[index].y_point
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; Get EIS pointing offset
; JAR 1-Apr-2014. Add "obs_id" and "aia_time" inputs to routine
; "eis_pointing_offset"
obs_id   = tl.science_component.obs_id
aia_time = tl.time_component.start_time
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; JAR 27-Aug-2014. Add "sot_offset" input to routine
; "eis_pointing_offset"
sc         = tl.science_component
sot_offset = FLOAT(STRSPLIT(sc.disturbance,',',/EXTRACT))
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
offsets  = eis_pointing_offset(obs_id,aia_time,sot_offset)
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; JAR 30-Apr-2014. Changed returned structure from "eis_pointing_offset"
offset     = offsets.def_offset
aia_offset = offsets.aia_offset
sot_offset = offsets.sot_offset

CASE obs_id OF
   0    : ; Nothing to do here
   1    :  BEGIN
               offset[0] = offset[0] + aia_offset[0]
               offset[1] = offset[1] + aia_offset[1]
           END
   2    :  BEGIN
               offset[0] = offset[0] + aia_offset[0] - sot_offset[0]
               offset[1] = offset[1] + aia_offset[1] - sot_offset[1]
           END
   ELSE :  ; Nothing to do here
ENDCASE

sc_x     = tl.science_component.studyRasters[index].sc_x - offset[0]
sc_y     = tl.science_component.studyRasters[index].sc_y - offset[1]
;sc_x     = tl.science_component.studyRasters[index].sc_x - offsets.x_offset
;sc_y     = tl.science_component.studyRasters[index].sc_y - offsets.y_offset
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++





x_point  = x/ratio
y_point  = y/ratio
; PLOTS     , x_point + win_radius                                     ,     $
;             y_point + win_radius                                     ,     $
;             psym = 7 , color = 1 , symsize=1 , /DEVICE

;
; Draw FOV box
;
CASE tl.science_component.studyRasters[index].slitIndex OF
    0 : fov_half_width  = 590/2.
    1 : fov_half_width  = 856/2.
    2 : fov_half_width  = 592/2.
    3 : fov_half_width  = 630/2.
ENDCASE
fov_half_height = 1024./2

sc_x_box = [ (sc_x - fov_half_width )/ratio                          ,     $
             (sc_x - fov_half_width )/ratio                          ,     $
             (sc_x + fov_half_width )/ratio                          ,     $
             (sc_x + fov_half_width )/ratio                          ,     $
             (sc_x - fov_half_width )/ratio    ]
sc_y_box = [ (sc_y - fov_half_height)/ratio                          ,     $
             (sc_y + fov_half_height)/ratio                          ,     $
             (sc_y + fov_half_height)/ratio                          ,     $
             (sc_y - fov_half_height)/ratio                          ,     $
             (sc_y - fov_half_height)/ratio    ]
PLOTS     , sc_x_box + win_radius                                    ,     $
            sc_y_box + win_radius                                    ,     $
            color = 1, /DEVICE , lines = 0 , thick = 2

ra_half_width  = tl.science_component.studyRasters[index].ra_width/2.
ra_half_height = tl.science_component.studyRasters[index].windHeight/2.
ra_x_box = [ (x - ra_half_width )/ratio                              ,     $
             (x - ra_half_width )/ratio                              ,     $
             (x + ra_half_width )/ratio                              ,     $
             (x + ra_half_width )/ratio                              ,     $
             (x - ra_half_width )/ratio    ]
ra_y_box = [ (y - ra_half_height)/ratio                              ,     $
             (y + ra_half_height)/ratio                              ,     $
             (y + ra_half_height)/ratio                              ,     $
             (y - ra_half_height)/ratio                              ,     $
             (y - ra_half_height)/ratio    ]
PLOTS     , ra_x_box + win_radius                                    ,     $
            ra_y_box + win_radius                                    ,     $
            color = 1, /DEVICE , lines = 0

END
;______________________________________________________________________________
; A studyRaster has been selected
;______________________________________________________________________________
PRO eis_mk_plan_gui::selectStudyRaster , event

Self.eis_timeline_container->getProperty ,                                 $
                               working_position = working_position   ,     $
                               study_selected   = study_selected


IF (working_position EQ -1) AND (study_selected EQ 0) THEN BEGIN
    BEEP
    mText = ['No Timeline entry is selected!','Nothing to see here.']
    error = DIALOG_MESSAGE( mText                                    ,      $
                     DIALOG_PARENT = Self.tlbID,                            $
                     /ERROR )
    RETURN
ENDIF


WIDGET_CONTROL , /HOURGLASS

count = Self.eis_timeline_container->count()
IF (count EQ 0) THEN BEGIN
    BEEP
    complain = DIALOG_MESSAGE( 'No entry selected!' ,                       $
                     DIALOG_PARENT = Self.tlbID,                            $
                     /ERROR )
    RETURN
ENDIF

; Trap CONTEXT events here
widgetType = TAG_NAMES(event, /STRUCTURE_NAME)
IF (widgetType EQ 'WIDGET_CONTEXT') THEN BEGIN
    ;Self->rasterContextSensitiveMenu , event
    RETURN
END


widIDs = Self.eis_mk_plan_widgets
; Sensitize raster widgets
WIDGET_CONTROL , widIDs.ra_propsBaseID   , sensitive = 1
WIDGET_CONTROL , widIDs.pl_ra_asrcBaseID , sensitive = 1
WIDGET_CONTROL , widIDs.ra_eventsBaseID  , sensitive = 1
WIDGET_CONTROL , widIDs.ra_pointBaseID   , sensitive = 1

; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = wp

temp = Self.eis_timeline_container->get( position = wp)
s    = temp->get()
sc   = s.science_component
sra  = sc.studyRasters[event.index]

; Update working_raster index
sc.working_raster = event.index
temp->set_index , event.index

; Get studyRaster parameters
repeats = STRCOMPRESS(sra.ra_repeats   , /REMOVE_ALL)


x_point = STRTRIM(STRING(format='(F-10.2)',sra.x_point),2)
y_point = STRTRIM(STRING(format='(F-10.2)',sra.y_point),2)

;
mip_label = STRING(format='(A-8,I-6)'  , '  MIP = ' , ROUND(sra.mip))
yip_label = STRING(format='(A-8,I-6)'  , '  YIP = ' , ROUND(sra.yip))
mip_text  = STRTRIM(STRING(format='(I-4)'      , ROUND(sra.mip)),2)
yip_text  = STRTRIM(STRING(format='(I-4)'      , ROUND(sra.yip)),2)


; Update widget values with studyRaster parameters
;WIDGET_CONTROL , widIDs.pl_ra_yipID     , set_value = yip_label
;WIDGET_CONTROL , widIDs.pl_ra_mipID     , set_value = mip_label
WIDGET_CONTROL , widIDs.pl_ra_mipInID   , set_value = mip_text
WIDGET_CONTROL , widIDs.pl_ra_yipInID   , set_value = yip_text
WIDGET_CONTROL , widIDs.pl_ra_repeatsID , set_value = repeats
WIDGET_CONTROL , widIDs.pl_ra_xpointID  , set_value = x_point
WIDGET_CONTROL , widIDs.pl_ra_ypointID  , set_value = y_point
Self->plot_pointing
;
; Original Compression
;
status = eis_open_db(/RASTER)
ocomp  = dbval(sra.ra_id , 'COMPRESSION')
dbclose
CASE ocomp OF
    0    : ocomp_string = 'None'
    1    : ocomp_string = 'DPCM'
    2    : ocomp_string = 'JPEG98'
    3    : ocomp_string = 'JPEG90'
    4    : ocomp_string = 'JPEG75'
    5    : ocomp_string = 'JPEG50'
    6    : ocomp_string = 'JPEG95'
    7    : ocomp_string = 'JPEG92'
    8    : ocomp_string = 'JPEG85'
    9    : ocomp_string = 'JPEG65'
    ELSE : ocomp_string = 'None'
ENDCASE
WIDGET_CONTROL , widIDs.pl_ra_ocompID , set_value = STRTRIM(ocomp_string,2)
WIDGET_CONTROL , widIDs.pl_ra_compDropListID , set_droplist_select =       $
                                                sra.ra_compression

;
; ASRC - set Enabled button if set
;
WIDGET_CONTROL , widIDs.pl_ra_asrcEnabledID , set_button = sra.asrc_enabled
CASE sra.asrc_enabled OF
   1    : WIDGET_CONTROL , widIDs.ra_asrcBaseID , sensitive  = 1
   ELSE : WIDGET_CONTROL , widIDs.ra_asrcBaseID , sensitive  = 0
ENDCASE
;
; ASRC Direction
;
asrc_direction = sra.asrc_direction
WIDGET_CONTROL , widIDs.ra_asrcDirectionID , set_droplist_select = asrc_direction
;
; ASRC Skip
;
asrc_skip = sra.asrc_skip
WIDGET_CONTROL , widIDs.ra_asrcSkipID , set_value = asrc_skip
;
;ASRC Number of Compensation Steps
;
asrc_nSteps = sra.asrc_nSteps
WIDGET_CONTROL , widIDs.ra_asrcNStepsID , set_value = asrc_nSteps

;
; Raster Size
;
ra_w = STRCOMPRESS(sra.ra_width   , /REMOVE_ALL)
ra_h = STRCOMPRESS(sra.windHeight , /REMOVE_ALL)
ra_s = STRJOIN([ra_w,'"x',ra_h,'"'],/SINGLE)
WIDGET_CONTROL , widIDs.pl_ra_raID , set_value = ra_s

; JAR 11-Apr-2014
; Pointing Mode
obs_id = STRCOMPRESS(sc.obs_id,/REMOVE_ALL)
WIDGET_CONTROL , widIDs.pointmodeID , set_droplist_select = obs_id


;
; EIS FOV
;
CASE sra.slitIndex OF
    0 : fov_w  = '590"'
    1 : fov_w  = '856"'
    2 : fov_w  = '592"'
    3 : fov_w  = '630"'
ENDCASE
fov_h = '1024"'
eis_fov = STRJOIN([fov_w,'x',fov_h],/SINGLE)
WIDGET_CONTROL , widIDs.pl_ra_rafovID , set_value = eis_fov
;
; Spacecraft Pointing values
;
sc_x = STRTRIM(STRING(format='(F-7.2)',sra.sc_x),2)
sc_y = STRTRIM(STRING(format='(F-7.2)',sra.sc_y),2)
sc_point = STRJOIN([sc_x,'",',sc_y,'"'],/SINGLE)
WIDGET_CONTROL , widIDs.pl_ra_scID  , set_value = sc_point
;
; Tracking Curve
;
track = STRCOMPRESS(sra.cmp , /REMOVE_ALL)
WIDGET_CONTROL , widIDs.pl_ra_trackingID  , set_value = track
;
; Coarse Mirror Postion
;
;cmp     = STRJOIN([STRCOMPRESS(sra.cmp,/REMOVE_ALL),'"'],/SINGLE)
WIDGET_CONTROL , widIDs.pl_ra_cmpID     , set_value = '-/-'


;
; EIS EVENT
;
eisEventOn = sc.eis_event_response.respond_to_eis_event
; Get rasters that are flagged
eis_event_on = 0B
IF (eisEventOn EQ 1)                            THEN eis_event_on = 1B
IF (TOTAL(sra.eis_event_props.event_flag) EQ 0) THEN eis_event_on = 0B
WIDGET_CONTROL , widIDs.ra_eisEventID , set_button = eis_event_on



; EIS FLARE
eisFlareOn = s.science_component.eis_flare_response.respond_to_eis_flare
WIDGET_CONTROL , widIDs.ra_eisFlareID , set_button = eisFlareOn

; AEC EVENT
aecEventOn = s.science_component.aec_response.respond_to_aec
WIDGET_CONTROL , widIDs.ra_aecEventID , set_button = aecEventOn

;
; XRT Flare - is this raster an XRT Flare hunter
;
; These 2 tags should both be set to 1
xrtFlareOn_1 = sc.xrt_flare_response.respond_to_xrt_flare
xrtFlareOn_2 = s.science_component.studyRasters[event.index].xrt_flare_props.xrt_flag
;IF (xrtFlareOn_1 EQ xrtFlareOn_2) THEN xrtFlareOn = 1 ELSE xrtFlareOn = 0
;help,xrtFlareOn_1,xrtFlareOn_2
WIDGET_CONTROL , widIDs.ra_xrtFlareID , set_button = xrtFlareOn_1

END
;______________________________________________________________________________
; Kill eis_xRaster
;______________________________________________________________________________
PRO eis_mk_plan_gui::kill_xstudy , xstudy_obj

xstudy_obj->Control, /Destroy

END
;______________________________________________________________________________
; Invoke Plan Summary Tool
;______________________________________________________________________________
PRO eis_mk_plan_gui::planSummary

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

Self.o_ct_summary = OBJ_NEW("eis_ct_summary_gui" , Self)
Self.o_ct_summary->Realize
Self.o_ct_summary->XMANAGER
WIDGET_CONTROL , /HOURGLASS
Self.o_ct_summary->refreshSummary

END
;______________________________________________________________________________
; Initialize plot (if gui exists)
;______________________________________________________________________________
PRO eis_mk_plan_gui::initialize_plot

IF OBJ_VALID(Self.o_eis_timeline_plot_gui) THEN BEGIN
    ; Redraw timeline graphics
    Self.o_eis_timeline_plot_gui->initialize_plot
ENDIF

END
;______________________________________________________________________________
; Kill Metadata GUI
;______________________________________________________________________________
PRO eis_mk_plan_gui::kill_meta_gui

; Destroy CPT GUI
Self.meta_gui->Control, /Destroy
; And then the GUI object
OBJ_DESTROY , Self.meta_gui
; Redraw plot
Self->initialize_plot

END
;______________________________________________________________________________
; Kill Delete GUI
;______________________________________________________________________________
PRO eis_mk_plan_gui::kill_delete_gui

; Destroy CPT GUI
Self.delete_gui->Control, /Destroy
; And then the GUI object
OBJ_DESTROY , Self.delete_gui
; Redraw plot
Self->initialize_plot

END
;______________________________________________________________________________
; Kill Copy GUI
;______________________________________________________________________________
PRO eis_mk_plan_gui::kill_copy_gui

; Destroy CPT GUI
Self.copy_gui->Control, /Destroy
; And then the GUI object
OBJ_DESTROY , Self.copy_gui
; Redraw plot
Self->initialize_plot

END
;______________________________________________________________________________
; Kill Move GUI
;______________________________________________________________________________
PRO eis_mk_plan_gui::kill_move_gui

; Destroy CPT GUI
Self.move_gui->Control, /Destroy
; And then the GUI object
OBJ_DESTROY , Self.move_gui
; Redraw plot
Self->initialize_plot

END
;______________________________________________________________________________
; Kill CPT GUI
;______________________________________________________________________________
PRO eis_mk_plan_gui::kill_cpt_gui

; Destroy CPT GUI
Self.cpt_gui->Control, /Destroy
; And then the CPT GUI object
OBJ_DESTROY , Self.cpt_gui
; Save database - observer, planner and tohban details may have been added
Self->savePlanToDatabase

END
;______________________________________________________________________________
; Invoke CPT GUI
;______________________________________________________________________________
PRO eis_mk_plan_gui::cpt_gui

IF (OBJ_VALID(Self.copy_gui) EQ 1) THEN BEGIN
    BEEP
    mText = "The Copy GUI must be dismissed. Aborting!"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF
IF (OBJ_VALID(Self.move_gui) EQ 1) THEN BEGIN
    BEEP
    mText = "The Move GUI must be dismissed. Aborting!"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF

; How many entries are there?
count = Self.eis_timeline_container->count()
; If there are NO entries, then bail out!
IF (count EQ 0) THEN BEGIN
    mText = 'There are NO entries on the timeline. Aborting.'
    BEEP
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF

;
; If CPT gui is already invoked, then bail out
;
IF OBJ_VALID(Self.cpt_gui) THEN RETURN
;
; Save database automatically
;
mText = '  Writing to Database...  '
XMESSAGE , mText , wbase = wbase , group = Self.tlbID , font = 'helvetica'
Self.eis_timeline_container->write_database
WIDGET_CONTROL , wbase , /DESTROY


Self.cpt_gui = OBJ_NEW("eis_cpt_gui" , Self)
Self.cpt_gui->Realize
Self.cpt_gui->XMANAGER

; Redraw timeline graphics
Self->initialize_plot

END
;______________________________________________________________________________
; Disable Time-tagged
;______________________________________________________________________________
FUNCTION eis_mk_plan_gui::disableTimeTagging

; How many entries are there?
count = Self.eis_timeline_container->count()
IF (count EQ 0) THEN BEGIN
    mText = 'There are NO entries on the timeline. Aborting.'
    BEEP
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN , 0
ENDIF

WIDGET_CONTROL , /HOURGLASS

;stop
;; Get working_position (index of selected study)
;Self.eis_timeline_container->getProperty, working_position = working_position
;; Call eis_timeline_container method "remove_entry"
;Self.eis_timeline_container->remove_entry, position = working_position
;
;Self.eis_timeline_container->setproperty, working_position = -1
;;
;; Redraw timeline graphics
;Self.o_eis_timeline_plot_gui->initialize_plot
;;
;; Update Plan Summary Tool
;;
;Self.o_ct_summary->refreshSummary
;;
;;
;; Update widgets with values
;;
;Self->zeroWidgets

RETURN , 1

END
;______________________________________________________________________________
; Enable Time-tagged
;______________________________________________________________________________
FUNCTION eis_mk_plan_gui::enableTimeTagging

; How many entries are there?
count = Self.eis_timeline_container->count()
IF (count EQ 0) THEN BEGIN
    mText = 'There are NO entries. Aborting.'
    BEEP
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN , 0
ENDIF

WIDGET_CONTROL , /HOURGLASS

;stop
;; Get working_position (index of selected study)
;Self.eis_timeline_container->getProperty, working_position = working_position
;; Call eis_timeline_container method "remove_entry"
;Self.eis_timeline_container->remove_entry, position = working_position
;
;Self.eis_timeline_container->setproperty, working_position = -1
;;
;; Redraw timeline graphics
;Self.o_eis_timeline_plot_gui->initialize_plot
;;
;; Update Plan Summary Tool
;;
;Self.o_ct_summary->refreshSummary
;;
;;
;; Update widgets with values
;;
;Self->zeroWidgets

RETURN , 1

END
;______________________________________________________________________________
; Remove Study
;______________________________________________________________________________
PRO eis_mk_plan_gui::update_summary_selection

; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = wp
IF (wp NE -1) THEN BEGIN

    visible_list  = Self.eis_timeline_container->get_visible_list()
    visible_1     = where(visible_list eq 1)
    selected      = where(visible_1 EQ wp)
    ;
    ; Update Plan Summary Tool
    ;
    IF (OBJ_VALID(Self.o_ct_summary) EQ 1) THEN BEGIN
        Self.o_ct_summary->set_list_select , selected
    ENDIF

ENDIF

END
;______________________________________________________________________________
; Remove Study
;______________________________________________________________________________
FUNCTION eis_mk_plan_gui::remove_study

; How many entries are there?
count = Self.eis_timeline_container->count()
IF (count EQ 0) THEN BEGIN
    mText = 'There are NO entries. Aborting.'
    BEEP
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN , 0
ENDIF

WIDGET_CONTROL , /HOURGLASS
; Get working_position (index of selected study)
Self.eis_timeline_container->getProperty, working_position = wp
;
;
; Only going to delete this entry if;
;  (a) it IS the last study on the timeline
;  (b) it DOES NOT have an entry appended to it
;
; Is this a time-tagged study?
;
wp_temp    = Self.eis_timeline_container->get(POSITION = wp)
wp_tl      = wp_temp->get()
wp_ttagged = wp_tl.time_component.time_tagged
;
; Is it the last study on the timeline?
;
IF (count EQ wp + 1) THEN BEGIN

   ; Call eis_timeline_container method "remove_entry"
   Self.eis_timeline_container->remove_entry, position = wp

ENDIF ELSE BEGIN

   ; NOT last study on timeline.
   ;
   ; Is the next study time-tagged? If so, go ahead and delete!
   ;
   next_temp    = Self.eis_timeline_container->get(POSITION = wp + 1)
   next_tl      = next_temp->get()
   next_ttagged = next_tl.time_component.time_tagged

   IF (next_ttagged EQ 1) THEN BEGIN

       ; YES - next study is time-tagged
       ; Call eis_timeline_container method "remove_entry"
       print,"Next study is TTed. Deleting!"
       Self.eis_timeline_container->remove_entry, position = wp

   ENDIF ELSE BEGIN

       ; NO - next study is APPENDED (not time-tagged)
       ; Complain and bail out!
       mText = "This entry has a study appended to it. Aborting."
       BEEP
       d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
       RETURN , 0

   ENDELSE

ENDELSE


; Reset working_position as not set
Self.eis_timeline_container->setproperty, working_position = -1  ,          $
                                          study_selected   = 0

;
; Redraw timeline graphics
Self.o_eis_timeline_plot_gui->initialize_plot
;
; Update Plan Summary Tool
;
Self->refreshSummary
Self->refresh_dr_gui
;
;
; Update widgets with values
;
Self->zeroWidgets

RETURN , 1

END
;______________________________________________________________________________
; Remove Study
;______________________________________________________________________________
FUNCTION eis_mk_plan_gui::remove_all_entries

; How many entries are there?
count = Self.eis_timeline_container->count()
IF (count EQ 0) THEN BEGIN
    mText = 'There are NO entries. Aborting.'
    BEEP
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN , 0
ENDIF

question = 'Are you sure you want to remove all current entries?'
answer   = DIALOG_MESSAGE( question , /QUESTION , DIALOG_PARENT = Self.tlbID)
IF (answer NE 'Yes') THEN RETURN , 0

WIDGET_CONTROL , /HOURGLASS


; If there are entries
;
; Mark all entries as DELETED - update DB values
;
FOR i = 0, count - 1 DO BEGIN

    temp = Self.eis_timeline_container->get(POSITION = i)
    s    = temp->get()
    ; Get timeline entry - seq_id
    seq_id = s.time_component.sequence_id
    ; Update database entry so that entry_type = 'D'"
    IF (seq_id NE 0) THEN status = eis_delete_timeline_entry(seq_id)

ENDFOR

; OK, remove the entries from the tlc
Self.eis_timeline_container->clear_all

;
; Redraw timeline graphics
Self.o_eis_timeline_plot_gui->initialize_plot
;
; Update Plan Summary Tool
;
Self->refreshSummary
Self->refresh_dr_gui
;
;
; Update widgets with values
;
Self->zeroWidgets


RETURN , 1

END
;______________________________________________________________________________
; Add study - append to selected study
;______________________________________________________________________________
FUNCTION eis_mk_plan_gui::append_study

; Added check to ensure that ORL type engineering studies cannot
; be appended to existing studies. They must be time-tagged!
orl_list  = [191]
orl_check = WHERE(Self.eis_study.id EQ orl_list , count_orl)
IF (count_orl GT 0) THEN BEGIN
    mText = ['This is an ORL eng study and may NOT be appended. '    ,     $
            'It must be a time-tagged study.' , 'Aborting.']
    BEEP
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN , 0
ENDIF

; Check the cursor-time does sit on an existing study
Self.eis_timeline_container->getProperty, study_selected = study_selected
IF (study_selected EQ 0) THEN BEGIN
    mText = "Place the cursor position on to the entry you want to append to! Aborting."
    BEEP
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN , 0
ENDIF

; How many entries are there?
count = Self.eis_timeline_container->count()
; Check there is a study to append to
IF (count EQ 0) THEN BEGIN
    mText = 'There are NO entries to append to. Aborting.'
    BEEP
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN , 0
ENDIF

; Check a study is selected
Self.eis_timeline_container->getProperty, working_position = working_position
IF (working_position EQ -1) THEN BEGIN
    mText = "An entry isn't currently selected. Aborting."
    BEEP
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN , 0
ENDIF

;
; Get start_time ( = time_end of currently selected entry)
;
; Get object reference
previous   = Self.eis_timeline_container->get( position = working_position)
prev_str   = previous->get()

;
; JAR 30-Aug-2007
; Check study being appended to is NOT recursive
;
IF (prev_str.time_component.recursive EQ 1) THEN BEGIN
    mText = "Study being appended to is recursive. Aborting."
    BEEP
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN , 0
ENDIF

WIDGET_CONTROL , /HOURGLASS

start_time = prev_str.time_component.end_time + 0.1

;
; Check new study doesn't run into a following entry
;
; Get new study duration
st     = Self.eis_study
st_dur = st.duration
; ; IF study is something else, then stop
; IF (st.type NE 0) AND (st.type NE 1) THEN stop

; Check sufficient time
Self.cursor_time_gui->getProperty , datetime = cp_tai
;;
;; 1. Get next TT study block start time - and sufficient time
;;
;
;next_start_time = Self.eis_timeline_container->get_next_block_start_time(cp_tai)
;; If there is an entry following the cursor time, then check
;IF (next_start_time NE 0) THEN BEGIN
;
;    ; OK, we have a following block/entry
;    valid  = eis_check_sufficient_time( next_start_time                 ,   $
;                                        cp_tai                          ,   $
;                                        Self.tlbID                      ,   $
;                                        st_dur/1000.                    ,   $
;                                        /APPEND                         ,   $
;                                        start_time = start_time)
;    stop
;    IF (valid NE 1) THEN RETURN , 0
;
;ENDIF
;stop

Self.eis_timeline_container->getProperty, all_blocks = all_blocks

valid  = eis_check_sufficient_time(all_blocks       ,                       $
                                   cp_tai           ,                       $
                                   Self.tlbID       ,                       $
                                   st_dur/1000.     , /APPEND)
IF (valid NE 1) THEN RETURN , 0


; Call "eis_add_study"
eis_add_study , Self , start_time

; Get cursor time
;Self.cursor_time_gui->getProperty  , datetime = datetime
; Get working_position
wp = Self.eis_timeline_container->returnSelectedStudyIndex(start_time)
Self.eis_timeline_container->setProperty, working_position = wp      , $
                                          study_selected   = 1

Self.o_eis_timeline_plot_gui->initialize_plot

RETURN , 1

END
;______________________________________________________________________________
; Add study - insert at cursor position
;______________________________________________________________________________
FUNCTION eis_mk_plan_gui::insert_study

; Get current cursor time
Self.cursor_time_gui->getProperty , datetime = cp_tai

; Check the cursor-time doesn't sit on an existing study
Self.eis_timeline_container->getProperty, study_selected = study_selected
IF (study_selected EQ 1) THEN BEGIN
    mText = "Can't place a new study on an existing entry! Aborting."
    BEEP
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN , 0
ENDIF

;
; Warn if study is inserted within 2 mins of a s/c repointing
;
; JAR 11-Mar-2011
IF VALID_POINTER(Self.rpev) AND (Self.repoint_warning EQ 1) THEN BEGIN
;IF VALID_POINTER(Self.rpev)  THEN BEGIN


   new_cp_tai = Self->get_last_repoint_time()
   ; OK, if operation was cancelled, then bail out!
   IF (new_cp_tai EQ -1) THEN BEGIN
       print,'Operation cancelled!'
       RETURN , 0
   ENDIF
   ;If NOT, then reset cursor time accordingly
   cp_tai     = new_cp_tai

ENDIF


;
; Check for SAA events?
;
IF (Self.saa_check EQ 1) THEN BEGIN
   ; OK, what time period are we observing?
   axis_start = Self.tl_graphics.axes.x_axis_day_tai
   duration   = Self.tl_graphics.axes.x_axis_length
   obev       = *Self.obev
   IF (N_TAGS(obev[0]) NE 0) THEN BEGIN

       saa_valid = eis_check_saa_event(Self.tlbID,obev,cp_tai)
       IF (saa_valid NE 0) THEN BEGIN

           print,'+++++++++++++++++++++++++'
           print,' SAA event detected'
           print,'+++++++++++++++++++++++++'

           CASE saa_valid OF
               -1   : RETURN , 0
               ELSE : cp_tai = saa_valid
           ENDCASE
       ENDIF
   ENDIF
ENDIF


WIDGET_CONTROL , /HOURGLASS

count  = Self.eis_timeline_container->count()
; Get new study duration
st         = Self.eis_study
st_dur     = st.duration
start_time = cp_tai

IF (count GT 0) THEN BEGIN
;    ; Check for 5% Rule
    Self.eis_timeline_container->getProperty, all_blocks = all_blocks
;    start_time = eis_check_fivepc_rule(all_blocks , cp_tai , Self.tlbID)
;    IF (start_time EQ 0.) THEN RETURN , 0
;    ; Get new study duration
    valid  = eis_check_sufficient_time(all_blocks , cp_tai      ,       $
                                           Self.tlbID , st_dur/1000.)
    IF (valid NE 1) THEN RETURN , 0
ENDIF


; Call "eis_add_study"
eis_add_study , Self , start_time , /TIME_TAGGED

; OK, set cursor to end of newly inserted study
Self.eis_timeline_container->getProperty, working_position = wp
temp   = Self.eis_timeline_container->get(POSITION = wp)
tl     = temp->get()
; Update Cursor Time Widget
Self.cursor_time_gui->setproperty , datetime = tl.time_component.end_time
Self.o_eis_timeline_plot_gui->initialize_plot

RETURN , 1

END
;______________________________________________________________________________
; Set widget timer going
;______________________________________________________________________________
FUNCTION eis_mk_plan_gui::get_last_repoint_time

; Get current cursor time
Self.cursor_time_gui->getProperty , datetime = cp_tai


; Get an array of structures for each re-point
rp_array = eis_get_rp_array(Self.rpev)
stop
; If there is only 1 element then there is NO re-point info
;IF (N_ELEMENTS((*Self.rpev)[0]) EQ 1) THEN RETURN , cp_tai

before_cp_tai_list = WHERE(rp_array[*].date_time LE cp_tai,count)
; If there are none before the cursor time, then bail out
IF (count LT 1) THEN RETURN , cp_tai
; Get maximum value
last_repoint    = max(rp_array[before_cp_tai_list].date_time)


IF (last_repoint LE Self.repoint_buffer) THEN RETURN , 0

; Warn if cp_tai - last_repoint < 2 mins (default buffer)
time_diff = (cp_tai - last_repoint)
line01 = 'Time difference between cursor position and last repoint is: '
line02 = STRTRIM(string(format="(f8.2)",time_diff),2)
line03 = ' seconds ('
line04 = STRTRIM(SEC2DHMS(time_diff),2)
line05 = ').'
mText  = [line01,line02,line03,line04,line05]
print,mText
IF (time_diff GE Self.repoint_buffer) THEN RETURN , cp_tai

suggested_time = last_repoint + Self.repoint_buffer

line1 = 'Current cursor Time  : ' + anytim2utc(cp_tai,/stime)
line2 = 'Time of last repoint : ' + anytim2utc(last_repoint,/stime)
;
;
;
line31 = STRTRIM(sec2dhms(cp_tai - last_repoint),2)
line32 = STRJOIN(['Difference is        : ',line31],/SINGLE)
line33 = ' (Buffer is set to 2 mins)'
line3  = STRJOIN([line32,line33],/SINGLE)
;
;
;
line41 = 'Suggested start time :'
line42 = anytim2utc(suggested_time,/stime,/TRUNCATE)
line4  = STRJOIN([line41,line42],' ',/SINGLE)
line5  = ""
line6  = "Use this time?"
mText	 = [line1,line2,line3,line4,line5,line6]
question = DIALOG_MESSAGE(mText, /QUESTION                           ,     $
               DIALOG_PARENT = Self.tlbID , /CANCEL)

CASE question OF
   'Yes' : RETURN , suggested_time
   'No'  : RETURN , cp_tai
   ELSE  : RETURN , -1
ENDCASE

RETURN , last_repoint

END
;______________________________________________________________________________
; Set widget timer going
;______________________________________________________________________________
PRO eis_mk_plan_gui::setTimer

WIDGET_CONTROL , Self.eis_mk_plan_widgets.st_timerID , TIMER = 1.
get_utc , utc , /STIME , /TRUNCATE

widTitle = 'EIS Make Plan Tool - Current UT: ' + utc
WIDGET_CONTROL , Self.tlbID , TLB_Set_Title = widTitle

END
;______________________________________________________________________________
; Display help
;______________________________________________________________________________
PRO eis_mk_plan_gui::displayHelp

; Get eis_fonts
fonts = eis_fonts()

help_path  = GETENV('EIS_PLAN_HELP')
help_file  = CONCAT_DIR(help_path , 'eis_mk_plan_help.hlp')
pt_version = eis_get_pt_version_number()

widg_help , help_file , group_leader = Self.tlbID , font = fonts.mono ,    $
                        title = "EIS Make Plan Tool" + pt_version

END
;______________________________________________________________________________
; Update Duration Units (h:m:s/hours/minutes/seconds)
;______________________________________________________________________________
PRO eis_mk_plan_gui::setDurationUnits , index

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

END
;______________________________________________________________________________
; Edit Cursor Time
;______________________________________________________________________________
PRO eis_mk_plan_gui::editCursorTime

; Plot cursor time on timeline plot
IF OBJ_VALID(Self.o_eis_timeline_plot_gui) THEN                             $
    Self.o_eis_timeline_plot_gui->plot_cursor_time

END
;______________________________________________________________________________
; Update Cursor Time
;______________________________________________________________________________
PRO eis_mk_plan_gui::updateCursorTime , datetime

; offset   = xPos - Self.tl_graphics.axes.x_axis_start ;(seconds)
; datetime = Self.tl_graphics.axes.x_axis_day_tai + (offset*3600.)

; Update Cursor Time Widget
Self.cursor_time_gui->setproperty , datetime = datetime

; Is move_gui up? If so, then reset its New Start Time
valid_move_gui = XREGISTERED("eis_move_tl_gui")
IF (valid_move_gui EQ 1) THEN Self.move_gui->setProperty , tNewID = datetime

; Is copy_gui up? If so, then reset its New Start Time
valid_copy_gui = XREGISTERED("eis_copy_tl_gui")
IF (valid_copy_gui EQ 1) THEN Self.copy_gui->setProperty , tNewID = datetime

END
;______________________________________________________________________________
; Study Description
;______________________________________________________________________________
PRO eis_mk_plan_gui::studyDescription

; Check a study is selected
Self.eis_timeline_container->getProperty, working_position = working_position
IF (working_position EQ -1) THEN BEGIN
    mText = "An entry isn't selected. Aborting."
    BEEP
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF

; OK, get ID of selected study
temp   = Self.eis_timeline_container->get(POSITION = working_position)
s      = temp->get()
t      = s.time_component
st_id  = s.science_component.study_id

; Finally, call XDisplayfile wrapper
eis_view_study_descriptions , st_id , tlbID = Self.tlbID

END
;______________________________________________________________________________
; Fire up Study Database GUI
;______________________________________________________________________________
PRO eis_mk_plan_gui::searchStudyDBGUI

eis_xstudy , parentClass = Self

END
;______________________________________________________________________________
; Load a Study from Database
;______________________________________________________________________________
PRO eis_mk_plan_gui::loadStudy , st_id , filler = filler

; Load study
Self.eis_study = db_read_study_entry( st_id )
st_dur   = eis_study_duration(Self.eis_study)
st_vol   = eis_study_volume(Self.eis_study)

datarate = (st_vol/1024.) / (st_dur/1000.)
IF (datarate GT 50.) THEN BEGIN

    mText = "This study has a data rate which is > 50kBits/s!"
    BEEP
    d = DIALOG_MESSAGE(mText , /INFORMATION , DIALOG_PARENT = Self.tlbID)

ENDIF

END
;______________________________________________________________________________
; Select an entry - called from eis_ct_summary_gui tool
;______________________________________________________________________________
PRO eis_mk_plan_gui::select_entry , index , summary = summary

; If there are NO timeline entries then bail out
count = Self.eis_timeline_container->count()
IF (count EQ 0) THEN RETURN

; Check if index = working_position. If so, bail out
; Get working_position
Self.eis_timeline_container->getProperty , working_position = wp

IF (wp EQ index) THEN BEGIN

   ; Check keyword SUMMARY - if it's NOT set then bail out, since
   ; the selected entry is already the working_position.
   IF (KEYWORD_SET(summary) NE 1) THEN RETURN

ENDIF

Self.eis_timeline_container->setProperty , working_position = index
Self.eis_timeline_container->setProperty , study_selected   = 1
Self.eis_timeline_container->reorganise_container

; OK, get ID of selected study
temp   = Self.eis_timeline_container->get(POSITION = index)
s      = temp->get()
t      = s.time_component

; Update Cursor Time  - set to end time of selected study
new_time   = t.end_time
Self.cursor_time_gui->setproperty , datetime = new_time

; Redraw timeline graphics
;
Self.o_eis_timeline_plot_gui->initialize_plot
; Plot cursor time on timeline plot
Self.o_eis_timeline_plot_gui->plot_cursor_time
; Refresh DR GUI
Self->refresh_dr_gui

; ;
; ; By default, select first raster
; ;
; event = {event, index:0}
; Self->selectStudyRaster , event
; widIDs = Self.eis_mk_plan_widgets
; WIDGET_CONTROL , widIDs.pl_raListID , set_list_select = 0
; Self->updateStudyWidgets , /NO_REFRESH

END
;______________________________________________________________________________
; Zero all study widgets
;______________________________________________________________________________
PRO eis_mk_plan_gui::zeroWidgets

Self.eis_timeline_container->setProperty , working_position = -1

; Update Study ID, ACRONYM & TITLE labels
widIDs = Self.eis_mk_plan_widgets
WIDGET_CONTROL , widIDs.st_idID       , set_value = 'n/a'
WIDGET_CONTROL , widIDs.st_acronymID  , set_value = 'n/a'
WIDGET_CONTROL , widIDs.st_titleID    , set_value = 'n/a'


; Update TARGET, CATEGORY and AUTHOR labels
WIDGET_CONTROL , widIDs.st_otargetID  , set_value = 'n/a'
WIDGET_CONTROL , widIDs.st_targetID   , set_value = eis_get_target_list()
WIDGET_CONTROL , widIDs.st_categoryID , set_value = 'n/a'
WIDGET_CONTROL , widIDs.st_authorID   , set_value = 'n/a'

; Update Time START & STOP labels
WIDGET_CONTROL , widIDs.st_startLabelID , set_value = 'n/a'
WIDGET_CONTROL , widIDs.st_stopLabelID  , set_value = 'n/a'

; Update DURATION, VOLUME & DATARATE labels
WIDGET_CONTROL , widIDs.st_durationID , set_value = 'n/a'
WIDGET_CONTROL , widIDs.st_volumeID   , set_value = 'n/a'
WIDGET_CONTROL , widIDs.st_datarateID , set_value = 'n/a'

; OBSTITLE & OBS_DEC
WIDGET_CONTROL , widIDs.st_obstitleTextID , set_value = 'n/a'
WIDGET_CONTROL , widIDs.st_obsdecTextID   , set_value = 'n/a'

; JOIN_SB, OBS_ID, JOP_ID, SCI_OBJ
WIDGET_CONTROL , widIDs.st_join_sbID      , set_droplist_select = 0
;WIDGET_CONTROL , widIDs.st_obs_idID       , set_value           = 'n/a'
WIDGET_CONTROL , widIDs.st_jop_idID       , set_value           = 'n/a'
WIDGET_CONTROL , widIDs.st_sci_objLabelID , set_value           = 'n/a'
WIDGET_CONTROL , widIDs.st_noaa_numID     , set_value           = 'n/a'

; DE-Sensitize raster widgets
WIDGET_CONTROL , widIDs.ra_propsBaseID   , sensitive       = 0
WIDGET_CONTROL , widIDs.pl_ra_asrcBaseID , sensitive       = 0
WIDGET_CONTROL , widIDs.ra_eventsBaseID  , sensitive       = 0
WIDGET_CONTROL , widIDs.ra_pointBaseID   , sensitive       = 0
WIDGET_CONTROL , widIDs.pl_raListID      , set_value       = ''      ,     $
                                           set_list_select = -1
; ; Set working_raster = -1
; s = temp->get()
; temp->set_index , -1
;

END
;______________________________________________________________________________
; Update study widgets with values of selected study
;______________________________________________________________________________
PRO eis_mk_plan_gui::updateStudyWidgets , no_refresh = no_refresh

count = Self.eis_timeline_container->count()
; IF there are NO entries, then set w_p = -1, and bail out
IF (count EQ 0) THEN BEGIN
    ;eis_timeline_container->setProperty , working_position = -1
    RETURN
ENDIF
;
Self.eis_timeline_container->getProperty , working_position = wp

temp   = Self.eis_timeline_container->get(POSITION = wp)
tl     = temp->get()
tc     = tl.time_component
sc     = tl.science_component

; Get widget IDs
widIDs = Self.eis_mk_plan_widgets

; ID needs to be in 000001 format
idValue = STRING(format='(I06)',tc.st_id)
WIDGET_CONTROL , widIDs.st_idID       , set_value = idValue
WIDGET_CONTROL , widIDs.st_acronymID  , set_value = STRTRIM(tc.acronym,2)
WIDGET_CONTROL , widIDs.st_titleID    , set_value = STRTRIM(tc.title,2)
WIDGET_CONTROL , widIDs.st_categoryID , set_value = STRTRIM(tc.category,2)
WIDGET_CONTROL , widIDs.st_authorID   , set_value = STRTRIM(tc.author,2)
;
; Target
;
target = STRLOWCASE(STRTRIM(sc.target,2))
CASE target OF
    'quiet sun'     : set_droplist_select = 0
    'active region' : set_droplist_select = 1
    'flare'         : set_droplist_select = 2
    ELSE            : set_droplist_select = 0
ENDCASE
WIDGET_CONTROL , widIDs.st_targetID , set_droplist_select = set_droplist_select
WIDGET_CONTROL , widIDs.st_otargetID, set_value = STRTRIM(sc.target,2)

; Update Time START & STOP labels
start_time   = tc.start_time
stop_time    = tc.end_time
start_string = utc2str(anytim2utc(start_time),/stime)
stop_string  = utc2str(anytim2utc(stop_time) ,/stime)
WIDGET_CONTROL , widIDs.st_startLabelID , set_value = start_string
WIDGET_CONTROL , widIDs.st_stopLabelID  , set_value = stop_string

; ;
; ; Set Time-tagged (exclusive) buttons
; ;
; IF (tc.time_tagged EQ 1) THEN BEGIN
;     WIDGET_CONTROL , widIDs.st_tt_enableID   , set_button = 1
;     WIDGET_CONTROL , widIDs.st_tt_disableID  , set_button = 0
;     WIDGET_CONTROL , widIDs.st_5pc_enableID  , set_button = 1
;     WIDGET_CONTROL , widIDs.st_5pc_disableID , set_button = 0
; ENDIF ELSE BEGIN
;     WIDGET_CONTROL , widIDs.st_tt_enableID   , set_button = 0
;     WIDGET_CONTROL , widIDs.st_tt_disableID  , set_button = 1
;     WIDGET_CONTROL , widIDs.st_5pc_enableID  , set_button = 0
;     WIDGET_CONTROL , widIDs.st_5pc_disableID , set_button = 1
; ENDELSE
;
; JOIN_SB
;
join_sb = STRTRIM(STRUPCASE(sc.join_sb),2)
CASE join_sb OF
    'E'      : join_sb_index = 0
    'E,S'    : join_sb_index = 1
    'E,X'    : join_sb_index = 2
    'E,S,X'  : join_sb_index = 3
    ELSE     : join_sb_index = 0
ENDCASE
WIDGET_CONTROL , widIDs.st_join_sbID , set_droplist_select = join_sb_index

;
; SCI_OBJ
;
sci_obj = STRTRIM(sc.sci_obj,2)
WIDGET_CONTROL , widIDs.st_sci_objLabelID , set_value = sci_obj

;
; OBSTITLE
;
obstitle = STRTRIM( sc.obstitle , 2)
WIDGET_CONTROL , widIDs.st_obstitleTextID , set_value = obstitle
;
; OBS_DEC
;
obs_dec  = STRTRIM( sc.obs_dec , 2)
WIDGET_CONTROL , widIDs.st_obsdecTextID   , set_value = obs_dec
; ;
; ; OBS_ID
; ;
; obs_id = STRCOMPRESS(sc.obs_id,/REMOVE_ALL)
; WIDGET_CONTROL , widIDs.st_obs_idID , set_value = obs_id
;
; JOP_ID
;
jop_id = STRCOMPRESS(sc.jop_id,/REMOVE_ALL)
WIDGET_CONTROL , widIDs.st_jop_idID , set_value = jop_id
;
; NOAA_NUM
;
noaa_num = STRCOMPRESS(sc.noaa_num,/REMOVE_ALL)
WIDGET_CONTROL , widIDs.st_noaa_numID , set_value = noaa_num

Self->updateDurationAndVolume

IF KEYWORD_SET(no_refresh) THEN RETURN

WIDGET_CONTROL , widIDs.pl_raListID , set_list_select = -1
; DE-sensitize Base widgets
WIDGET_CONTROL , widIDs.ra_propsBaseID   , sensitive = 0
WIDGET_CONTROL , widIDs.pl_ra_asrcBaseID , sensitive = 0
WIDGET_CONTROL , widIDs.ra_eventsBaseID  , sensitive = 0
WIDGET_CONTROL , widIDs.ra_pointBaseID   , sensitive = 0

END
;______________________________________________________________________________
; Load study rasters into the list
;______________________________________________________________________________
PRO eis_mk_plan_gui::updateStudyRasterListWidget

; Get widget IDs
widIDs = Self.eis_mk_plan_widgets

count = Self.eis_timeline_container->count()
; IF there are NO entries, then set wp = -1, and bail out
IF (count EQ 0) THEN BEGIN
    ;eis_timeline_container->setProperty , working_position = -1
    WIDGET_CONTROL , widIDs.pl_raListID , set_value = ''
    RETURN
ENDIF
;
; Get index of selected studyRaster
index = WIDGET_INFO(widIDs.pl_raListID , /LIST_SELECT)


Self.eis_timeline_container->getProperty , working_position = wp
temp       = Self.eis_timeline_container->get(POSITION = wp)
tl         = temp->get()

tl.science_component.working_raster = index

temp->set_index , index
entry_type = tl.time_component.entry_type
IF (entry_type NE 'S') THEN BEGIN

    rasterList = ''
    WIDGET_CONTROL , widIDs.pl_rasterBaseID , sensitive = 0

ENDIF ELSE BEGIN

    ; Create rasterList
    rasterList = eis_mk_plan_create_rasterlist(tl)
    WIDGET_CONTROL , widIDs.pl_rasterBaseID , sensitive = 1

ENDELSE

; Update studyRaster widgets
WIDGET_CONTROL , widIDs.pl_raListID , set_value       = rasterList ,        $
                                      set_list_select = index

; IF (index GT -1) AND (entry_type EQ 'S') THEN BEGIN
;    event = {event, index:0}
;    Self->selectStudyRaster , event
;    Self->updateStudyWidgets; , /NO_REFRESH
;    ;Self->initialize_plot
; ENDIF

END
;______________________________________________________________________________
; Save Plan to Database
;______________________________________________________________________________
PRO eis_mk_plan_gui::savePlanToDatabase , no_date_dialog = no_date_dialog , $
                                          no_plot_update = no_plot_update

; How many entries are there?
count = Self.eis_timeline_container->count()
IF (count EQ 0) AND ~KEYWORD_SET(no_date_dialog) THEN BEGIN
    mText = 'There are NO entries to save. Aborting.'
    BEEP
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF

xmessage , '  Writing to Database...  ' , wbase = wbase , $
                       group = Self.tlbID , font = 'helvetica'


;
; Do we have any Event Trigger Studies? If so, save them here.
;
triggers = Self.eis_timeline_container->detect_trigger_studies()
IF (N_TAGS(triggers[0]) NE 0) THEN BEGIN

   ; Check each trigger study. Are all the required properties
   ; defined and valid?
   FOR i = 0 , N_ELEMENTS(triggers) - 1 DO BEGIN

       trig_type = STRLOWCASE(triggers[i].type)
       IF (trig_type EQ 'eebp') THEN Self->save_response_study , triggers[i]
       ;IF (trig_type EQ 'eisf') THEN Self->save_response_study , triggers[i]

   ENDFOR

ENDIF

; OK, do save!!!!!!!!
Self.eis_timeline_container->write_database
WIDGET_CONTROL , wbase , /DESTROY

; Unless told otherwise, redraw timeline graphics
IF KEYWORD_SET(no_plot_update) THEN RETURN
Self.o_eis_timeline_plot_gui->initialize_plot
; Refresh summary list
Self->refreshSummary

END
;______________________________________________________________________________
; Update trigger/response study structures
;______________________________________________________________________________
PRO eis_mk_plan_gui::save_response_study , trigger

;help , trigger , /STR
; Get tlc entry position
tlc_position = tlc_position
temp   = Self.eis_timeline_container->get(POSITION = tlc_position)
; Now check it has a non-zero sequence_id
tl     = temp->get()
seq_id = tl.time_component.sequence_id

; JAR 31-Aug-2011
; When copying a hunter study with a response study already
; defined, then we need to save the hunter study here and
; now - since it's seq_id = 0
IF (seq_id EQ 0) THEN BEGIN
    ; Save (copied) hunter study. Seq_id = 0
    Self->save_copied_hunter_study , temp
    ; Hunter study saved. Seq_id NE 0
    ; Refresh the timeline object
    tlc_position = trigger.tlc_position
    temp   = Self.eis_timeline_container->get(POSITION = tlc_position)
    ; Now check it has a non-zero sequence_id
    tl     = temp->get()
    seq_id = tl.time_component.sequence_id
ENDIF

CASE STRLOWCASE(trigger.type) OF
    'eebp' : struct = Self.eis_event_control
    'eisf' : struct = Self.eis_flare_control
    ELSE   :
ENDCASE

; Now save/update it. Get number of existing response DB entries?
status   = eis_open_db(/RESPONSE)
nEntries = db_info('entries')
; Is it a NEW entry? Or does it already exist?
; Search response_DB for seq_id AND type

filter_1 = STRJOIN(['TRIG_ST_SEQID=',STRCOMPRESS(seq_id,/REMOVE)],/SINGLE)
filter_2 = STRJOIN(['TYPE=',trigger.type],/SINGLE)
filter   = STRJOIN([filter_1 , filter_2],',',/SINGLE)
r      = dbfind(filter , count = found_response_studies)

; If Tag NOT found in DB. Create a new entry
IF (found_response_studies EQ 0) THEN new_id = nEntries[0] + 1

; Create response study structure and initialize it
CASE STRLOWCASE(trigger.type) OF
    'eebp' : r_struct = eis_eebp_initialize(struct , seq_id , new_id = new_id)
    'eisf' : r_struct = eis_eisf_initialize(struct , seq_id , new_id = new_id)
    ELSE   : stop
ENDCASE

IF (found_response_studies EQ 0) THEN BEGIN
    ; Tag NOT found in DB. Create a new entry
    ;response_struct.id = nEntries[0] + 1
    ;help,r_struct
    db_save_response_entry_create , r_struct
ENDIF ELSE BEGIN
    ; OK, this response entry already exists. Update it!
    ;help,r_struct
    db_save_response_entry_update , r_struct
ENDELSE

; OK, now add the response study ID to the regular timeline entry DB
response_id_string = STRCOMPRESS(r_struct.id,/REMOVE_ALL)
; Set science_component.solarb_science accordingly
new_solarb_science = STRJOIN([trigger.type                ,     $
                              response_id_string],':',/SINGLE)

old_solarb_science = temp->get_solarb_science()
solarb_science = eis_solarb_science_update(new_solarb_science ,     $
                                           old_solarb_science)
temp->update_study_tag , solarb_science = solarb_science

END
;______________________________________________________________________________
; Update trigger/response study structures
;______________________________________________________________________________
PRO eis_mk_plan_gui::save_copied_hunter_study , temp

; Copied hunter study seq_id = 0. Need to save this first.
tl     = temp->get()
seq_id = tl.time_component.sequence_id

; How many entries are there? New entry is this value + 1
status = eis_open_db(/TIME)
n      = db_info('entries')
seq_id = n[0] + 1
dbclose

tl.time_component.sequence_id    = seq_id
tl.science_component.sequence_id = seq_id

; Print message
print,STRJOIN(['Saving new TL entry as seq_id = ',                     $
                          STRCOMPRESS(seq_id,/REMOVE)],/SINGLE)

status = eis_write_science_component_database_table(tl.science_component)
status = eis_write_time_component_database_table(tl.time_component)
; Finally, update
temp->set_seq_id , seq_id = seq_id

END
;______________________________________________________________________________
; Update trigger/response study structures
;______________________________________________________________________________
PRO eis_mk_plan_gui::update_response_structures

;
; Do we have any Event Trigger Studies?
;
triggers = Self.eis_timeline_container->detect_trigger_studies()
; Bail out if none found
IF (N_TAGS(triggers[0]) EQ 0) THEN RETURN

; Break out the TLC
tlc = Self.eis_timeline_container

; Get a list indicies of each type
eebp_l = WHERE(STRMATCH(triggers[*].type,'eebp',/FOLD_CASE) EQ 1,num_eebp)
xrtf_l = WHERE(STRMATCH(triggers[*].type,'xrtf',/FOLD_CASE) EQ 1,num_xrtf)
eisf_l = WHERE(STRMATCH(triggers[*].type,'eisf',/FOLD_CASE) EQ 1,num_eisf)

IF (N_TAGS(triggers) NE 0) THEN BEGIN

   ; Check each trigger study. Are all the required properties
   ; defined and valid?
   FOR i = 0 , N_ELEMENTS(triggers) - 1 DO BEGIN
       trigger = triggers[i]
       ;help , trigger , /STR

       ; OK, what type of response study are we dealing with here?
       eebp_event = STRMATCH(trigger.type,'eebp',/FOLD_CASE)
       eisf_event = STRMATCH(trigger.type,'eisf',/FOLD_CASE)
       xrtf_event = STRMATCH(trigger.type,'xrtf',/FOLD_CASE)

       ; Create response study structure and initialize it
       IF (eebp_event EQ 1) THEN BEGIN
           struct = eis_event_control_initialize(trigger,tlc)
           CASE N_TAGS(struct) OF
               0    : Self.eis_event_control = {eis_event_control}
               ELSE : Self.eis_event_control = struct
           ENDCASE
       ENDIF
;       IF (xrtf_event EQ 1) THEN BEGIN
;           struct = eis_xrt_flare_control_initialize(trigger,tlc)
;           CASE N_TAGS(struct) OF
;               0    : Self.eis_xrt_flare_control = {eis_xrt_flare_control}
;               ELSE : Self.eis_xrt_flare_control = struct
;           ENDCASE
;       ENDIF
;       IF (eisf_event EQ 1) THEN BEGIN
;           struct = eis_flare_control_initialize(trigger,tlc)
;           CASE N_TAGS(struct) OF
;               0    : Self.eis_flare_control = {eis_flare_control}
;               ELSE : Self.eis_flare_control = struct
;           ENDCASE
;       ENDIF

   ENDFOR

ENDIF

END
;______________________________________________________________________________
; No timeline entries found
;______________________________________________________________________________
PRO eis_mk_plan_gui::no_tl_found

Self.eis_timeline_container->clear_all
Self->zeroWidgets
Self.eis_timeline_container->setproperty, working_position = -1
; Set cursor_position to start of display start

; Get display start time
disp_start = Self.tl_graphics.axes.x_axis_day_tai
disp_start_utc = anytim2utc(disp_start)

; Set cursor_position to NOW
get_utc , utc
disp_start_utc.time = utc.time

datetime = Self.tl_graphics.axes.x_axis_day_tai
Self.cursor_time_gui->setProperty , datetime = utc2tai(disp_start_utc)

END
;______________________________________________________________________________
; Read Plan from Database
;______________________________________________________________________________
PRO eis_mk_plan_gui::readPlanFromDatabase

; If any of the Multiple dialogs are up; then complain and bail out!
valid_cpt_gui = XREGISTERED("eis_cpt_gui")
IF (valid_cpt_gui EQ 1) THEN BEGIN
    BEEP
    mText = "The CPT GUI must be dismissed. Aborting!"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF
IF (OBJ_VALID(Self.move_gui) EQ 1) THEN BEGIN
    BEEP
    mText = "The Move GUI must be dismissed. Aborting!"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF
IF (OBJ_VALID(Self.copy_gui) EQ 1) THEN BEGIN
    BEEP
    mText = "The Copy GUI must be dismissed. Aborting!"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF
IF (OBJ_VALID(Self.delete_gui) EQ 1) THEN BEGIN
    BEEP
    mText = "The Delete GUI must be dismissed. Aborting!"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF
IF (OBJ_VALID(Self.meta_gui) EQ 1) THEN BEGIN
    BEEP
    mText = "The Metadata GUI must be dismissed. Aborting!"
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF



t0 = SYSTIME(1)

splash = OBJ_NEW("eis_splash" , Self)
splash->Realize
splash->XMANAGER
splash->plot_logo , fileName = Self.logo_fileName

WIDGET_CONTROL , /HOURGLASS

; Offset start and stop times by -1 day and +1 day, respectively!
times = eis_get_read_db_times(Self.tl_graphics.axes)

; Read database
timeline = eis_get_timeline_entries(times.start_time, times.stop_time, /ALL)
;
; Remove entries that don't have an entry_type = 'S' or 'E'
;
IF (N_TAGS(timeline[0]) NE 0) THEN BEGIN

    entry_type = timeline[*].entry_type
    valid_tl   = WHERE(entry_type EQ 'S' OR entry_type EQ 'E' , valid_count)
    IF (valid_count NE 0) THEN timeline   = timeline[valid_tl]

ENDIF
;
; IF no entries are found then tlc->clear_all, zero widgets and bail out
;
IF (N_TAGS(timeline[0]) EQ 0) THEN BEGIN

    Self->no_tl_found
    splash->wait,0.5
ENDIF ELSE BEGIN

    Self.eis_timeline_container->read_database, timeline , splash = splash
    Self.eis_timeline_container->getproperty, working_position = wp
    ; Take account of wp = -1 (ie - no visible entries)
    CASE wp OF
        -1   : Self->no_tl_found
        ELSE : Self->read_science_entry , /UPDATE_CP
    ENDCASE
    ; Check for trigger studies and update Martin's control structures
    Self->update_response_structures

ENDELSE

; Self.eis_timeline_container->getproperty, working_position = wp
; IF (wp NE -1) THEN

; OK, what time period are we observing?
start_time = Self.tl_graphics.axes.x_axis_day_tai
duration   = Self.tl_graphics.axes.x_axis_length

;
; Read Orbit Events
;
obev       = eis_read_orbit_events(                                        $
                    Self.tl_graphics.axes.x_axis_day_tai ,                 $
                    Self.tl_graphics.axes.x_axis_length  ,                 $
                    num_days = Self.num_days)

; Refresh pointer
PTR_FREE , Self.obev
Self.obev = PTR_NEW(obev)
;
; Read Station Events
;
stev       = eis_read_station_events(                                      $
                    Self.tl_graphics.axes.x_axis_day_tai ,                 $
                    Self.tl_graphics.axes.x_axis_length  ,                 $
                    num_days = Self.num_days)
; Refresh pointer
PTR_FREE , Self.stev
Self.stev = PTR_NEW(stev)

;
; Read Re-point files
;
rpev       = eis_read_repoint_events(                                      $
                    Self.tl_graphics.axes.x_axis_day_tai ,                 $
                    Self.tl_graphics.axes.x_axis_length  ,                 $
                    num_days = Self.num_days)


IF (PTR_VALID(Self.rpev) EQ 1) THEN BEGIN

   FOR i = 0, N_ELEMENTS(*Self.rpev) -1 DO BEGIN

       IF (PTR_VALID((*Self.rpev)[i]) NE 0) THEN PTR_FREE , (*Self.rpev)[i]

   ENDFOR
ENDIF
PTR_FREE    , Self.rpev

;PTR_FREE , Self.rpev
Self.rpev = PTR_NEW(rpev)



;
; Redraw timeline graphics
;
t1 = SYSTIME(1)
Self.o_eis_timeline_plot_gui->initialize_plot
t1_2 =SYSTIME(1) - t1
;
; Update Plan Summary Tool
;
t2 = SYSTIME(1)
Self->refreshSummary
Self->update_summary_selection
t2_2 =SYSTIME(1) - t2

;WIDGET_CONTROL , wbase , /DESTROY
splash->kill

db_time   = STRTRIM(STRING(format='(F9.2)',SYSTIME(1) - t0),2)
plot_time = STRTRIM(STRING(format='(F9.2)',t1_2),2)
summ_time = STRTRIM(STRING(format='(F9.2)',t2_2),2)
PRINT, STRJOIN([db_time,'s to read database, including ',            $
                 plot_time ,'s to re-display and ',                  $
                 summ_time,'s to update summary'],/SINGLE)

;
; Update the DR GUI if it exists
;
IF (OBJ_VALID(Self.dr_gui) EQ 1) THEN BEGIN

    ; Update DR date-times to new display date-times
    axes = Self.tl_graphics.axes
    new_start_time = axes.x_axis_day_tai
    new_stop_time  = axes.x_axis_day_tai + (3600. * axes.x_axis_length)

    Self.dr_gui->setProperty , start_time = new_start_time
    Self.dr_gui->setProperty , stop_time  = new_stop_time
    Self.dr_gui->update_reset_button
    Self.dr_gui->refresh

ENDIF


END
;______________________________________________________________________________
; Update XRT Flare Properties
;______________________________________________________________________________
PRO eis_mk_plan_gui::read_science_entry , update_cp = update_cp

Self.eis_timeline_container->getproperty, working_position = wp
temp       = Self.eis_timeline_container->get(POSITION = wp)
; OK, get stuff
temp->getProperty , read_all   = read_all           ,                       $
                    start_time = start_time         ,                       $
                    end_time   = end_time
;
; If read_all = 1 then we don't need to do anything!
;
IF (read_all NE 1) THEN BEGIN

    WIDGET_CONTROL , /HOURGLASS
    ; OK, read ALL of entry info
    temp->get_all_info

    IF KEYWORD_SET(update_cp) THEN BEGIN
        ;
        ; Plot cursor time
        ; Check tl entry time is less than display end
        start_disp =  Self.tl_graphics.axes.x_axis_day_tai +                $
                     (Self.tl_graphics.axes.x_axis_length  * 3600.)

        IF (end_time GT start_disp) THEN dt = start_time ELSE dt = end_time
        Self.cursor_time_gui->setProperty , datetime = dt

    ENDIF

ENDIF

END
;______________________________________________________________________________
; Tools: View Re-point Times
;______________________________________________________________________________
PRO eis_mk_plan_gui::xdisplay_cmdpln_file , baseName , directory , dims

pathName = STRJOIN([GETENV('CMDPLN') , directory],PATH_SEP(),/SINGLE)
fileName = CONCAT_DIR(EXPAND_PATH(pathName) , baseName)
;
; Test if file exists
;
valid_file = FILE_SEARCH(fileName , /FOLD_CASE , count = count)
IF (count LT 1) THEN BEGIN
    ; Try the auxiliary directory
    pathName   = STRJOIN([GETENV('CMDPLN') , directory,'auxiliary']  ,     $
                                        PATH_SEP(),/SINGLE)
    fileName   = CONCAT_DIR(EXPAND_PATH(pathName) , baseName)
    valid_file = FILE_SEARCH(fileName , /FOLD_CASE , count = count)
    IF (count LT 1) THEN BEGIN
       print,fileName + ' File not found!'
       RETURN
    ENDIF
ENDIF


pt_version = eis_get_pt_version_number()
title      = STRJOIN([valid_file[0] , pt_version] , " " , /SINGLE)

XDISPLAYFILE , valid_file[0]                                         ,     $
               group  = Self.tlbID                                   ,     $
               title  = title                                        ,     $
               width  = dims[0]                                      ,     $
               height = dims[1]

END
;______________________________________________________________________________
; Tools: View Today's SAA events
;______________________________________________________________________________
PRO eis_mk_plan_gui::saa_today

Self->read_saa_today
IF (PTR_VALID(Self.saa_ptr) NE 1) THEN BEGIN
    mText = "Can't find the obev file! Aborting."
    BEEP
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF

pt_version = eis_get_pt_version_number()
n_lines    = N_ELEMENTS(*Self.saa_ptr)
; Display file contents in popup window
xpopup ,  (*Self.saa_ptr)                                            ,     $
          group = Self.tlbID                                         ,     $
          ySize = n_lines < 30                                       ,     $
          xSize = 50                                                 ,     $
          title = "Todays's SAA events" + pt_version

END
;______________________________________________________________________________
; Tools: View Tomorrow's SAA events
;______________________________________________________________________________
PRO eis_mk_plan_gui::saa_tomorrow

Self->read_saa_tomorrow
IF (PTR_VALID(Self.saa_ptr) NE 1) THEN BEGIN
    mText = "Can't find the obev file! Aborting."
    BEEP
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF

pt_version = eis_get_pt_version_number()
n_lines    = N_ELEMENTS(*Self.saa_ptr)
; Display file contents in popup window
xpopup ,  (*Self.saa_ptr)                                            ,     $
          group = Self.tlbID                                         ,     $
          ySize = n_lines < 30                                       ,     $
          xSize = 50                                                 ,     $
          title = "Tomorrow's SAA events" + pt_version

END
;______________________________________________________________________________
; Tools: View All of Tomorrow's J-Side files
;______________________________________________________________________________
PRO eis_mk_plan_gui::all_today

Self->ngt_today
Self->saa_today
Self->op_today
Self->repoint_today

END
;______________________________________________________________________________
; Tools: View All of Tomorrow's J-Side files
;______________________________________________________________________________
PRO eis_mk_plan_gui::all_tomorrow

Self->ngt_tomorrow
Self->saa_tomorrow
Self->op_tomorrow
Self->repoint_tomorrow

END
;______________________________________________________________________________
; Tools: View Today's NGT events
;______________________________________________________________________________
PRO eis_mk_plan_gui::ngt_today

Self->read_saa_today
IF (PTR_VALID(Self.ngt_ptr) NE 1) THEN BEGIN
    mText = "Can't find the obev file! Aborting."
    BEEP
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF

pt_version = eis_get_pt_version_number()
n_lines    = N_ELEMENTS(*Self.ngt_ptr)
; Display file contents in popup window
xpopup ,  (*Self.ngt_ptr)                                            ,     $
          group = Self.tlbID                                         ,     $
          ySize = n_lines < 30                                       ,     $
          xSize = 50                                                 ,     $
          title = "Today's Eclipse events" + pt_version

END
;______________________________________________________________________________
; Tools: View Tomorrow's NGT events
;______________________________________________________________________________
PRO eis_mk_plan_gui::ngt_tomorrow

Self->read_saa_tomorrow
IF (PTR_VALID(Self.ngt_ptr) NE 1) THEN BEGIN
    mText = "Can't find the obev file! Aborting."
    BEEP
    d = DIALOG_MESSAGE(mText , /ERROR , DIALOG_PARENT = Self.tlbID)
    RETURN
ENDIF

pt_version = eis_get_pt_version_number()
n_lines    = N_ELEMENTS(*Self.ngt_ptr)
; Display file contents in popup window
xpopup ,  (*Self.ngt_ptr)                                            ,     $
          group = Self.tlbID                                         ,     $
          ySize = n_lines < 30                                       ,     $
          xSize = 50                                                 ,     $
          title = "Tomorrow's Eclipse events" + pt_version

END
;______________________________________________________________________________
; Tools: Read Today's SAA events
;______________________________________________________________________________
PRO eis_mk_plan_gui::read_saa_today

PTR_FREE , Self.saa_ptr
IF (STRLEN(GETENV('CMDPLN')) EQ 0) THEN RETURN
baseName = "obev_*.*"
pathName = STRJOIN([GETENV('CMDPLN') , 'today'],PATH_SEP(),/SINGLE)
fileName = CONCAT_DIR(EXPAND_PATH(pathName) , baseName)
;
; Test if file exists
;
valid_file = FILE_SEARCH(fileName , /FOLD_CASE , count = count)
IF (count LT 1) THEN BEGIN
    ; Try the auxiliary directory
    pathName   = STRJOIN([GETENV('CMDPLN') , 'today','auxiliary']    ,     $
                                        PATH_SEP(),/SINGLE)
    fileName   = CONCAT_DIR(EXPAND_PATH(pathName) , baseName)
    valid_file = FILE_SEARCH(fileName , /FOLD_CASE , count = count)
    IF (count LT 1) THEN BEGIN
       print,fileName + ' File not found!'
       RETURN
    ENDIF
ENDIF
;
; Read contents of file
;
lines = rd_ascii(valid_file[0])
;
; Get SAA and NGT events
;
saa_list = STREGEX(lines,'^SAA_' , /BOOLEAN)
saa_true = WHERE(saa_list EQ 1 , saa_count)
IF (saa_count GT 0) THEN Self.saa_ptr = PTR_NEW(lines[saa_true])

ngt_list = STREGEX(lines,'^XTW_' , /BOOLEAN)
ngt_true = WHERE(ngt_list EQ 1 , ngt_count)
IF (ngt_count GT 0) THEN Self.ngt_ptr = PTR_NEW(lines[ngt_true])

END
;______________________________________________________________________________
; Tools: Read Tomorrow's SAA events
;______________________________________________________________________________
PRO eis_mk_plan_gui::read_saa_tomorrow

PTR_FREE , Self.saa_ptr
IF (STRLEN(GETENV('CMDPLN')) EQ 0) THEN RETURN
baseName = "obev_*.*"
pathName = STRJOIN([GETENV('CMDPLN') , 'tomorrow'],PATH_SEP(),/SINGLE)
fileName = CONCAT_DIR(EXPAND_PATH(pathName) , baseName)
;
; Test if file exists
;
valid_file = FILE_SEARCH(fileName , /FOLD_CASE , count = count)
IF (count LT 1) THEN BEGIN
    ; Try the auxiliary directory
    pathName   = STRJOIN([GETENV('CMDPLN') , 'tomorrow','auxiliary']    ,     $
                                        PATH_SEP(),/SINGLE)
    fileName   = CONCAT_DIR(EXPAND_PATH(pathName) , baseName)
    valid_file = FILE_SEARCH(fileName , /FOLD_CASE , count = count)
    IF (count LT 1) THEN BEGIN
       print,fileName + ' File not found!'
       RETURN
    ENDIF
ENDIF
;
; Read contents of file
;
lines = rd_ascii(valid_file[0])
;
; Get SAA and NGT events
;
saa_list = STREGEX(lines,'^SAA_' , /BOOLEAN)
saa_true = WHERE(saa_list EQ 1 , saa_count)
IF (saa_count GT 0) THEN Self.saa_ptr = PTR_NEW(lines[saa_true])

ngt_list = STREGEX(lines,'^XTW_' , /BOOLEAN)
ngt_true = WHERE(ngt_list EQ 1 , ngt_count)
IF (ngt_count GT 0) THEN Self.ngt_ptr = PTR_NEW(lines[ngt_true])

END
;______________________________________________________________________________
; Tools: View Today's OP File
;______________________________________________________________________________
PRO eis_mk_plan_gui::op_today

IF (STRLEN(GETENV('CMDPLN')) EQ 0) THEN RETURN
Self->xdisplay_cmdpln_file , "op_period_*" , 'today' , [50,10]

END
;______________________________________________________________________________
; Tools: View Tomorrow's OP File
;______________________________________________________________________________
PRO eis_mk_plan_gui::op_tomorrow

IF (STRLEN(GETENV('CMDPLN')) EQ 0) THEN RETURN
Self->xdisplay_cmdpln_file , "op_period_*" , 'tomorrow' , [50,10]

END
;______________________________________________________________________________
; Tools: View Today's Re-point File
;______________________________________________________________________________
PRO eis_mk_plan_gui::repoint_today

IF (STRLEN(GETENV('CMDPLN')) EQ 0) THEN RETURN
Self->xdisplay_cmdpln_file , "re-point_*" , 'today' , [160,50]

END
;______________________________________________________________________________
; Tools: View Tomorrow's Re-point File
;______________________________________________________________________________
PRO eis_mk_plan_gui::repoint_tomorrow

IF (STRLEN(GETENV('CMDPLN')) EQ 0) THEN RETURN
Self->xdisplay_cmdpln_file , "re-point_*" , 'tomorrow' , [160,50]

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

; OK, get ID of selected study
Self.eis_timeline_container->getProperty , working_position = wp
IF (wp EQ -1) THEN RETURN
temp   = Self.eis_timeline_container->get(POSITION = wp)
s      = temp->get()
;t      = s.time_component
;st_id  = s.science_component.study_id

;nRasters     = s.science_component.nRasters
;studyRasters = s.science_component.studyRasters


widIDs = Self.eis_mk_plan_widgets
;
; Calculate Volume (bits)
;
volume = s.science_component.volume
; Convert volume to a string
volumeString = STRCOMPRESS(volume/1024,/REMOVE_ALL) + ' kBits'
WIDGET_CONTROL , widIDs.st_volumeID , set_value = volumeString
;
; Calculate duration
;
duration = s.science_component.duration
; Get duration in milliseconds
; Convert duration to a string
durationString = eis_format_duration(duration , units = Self.durationUnits)
Self.eis_study.duration = duration
WIDGET_CONTROL , widIDs.st_durationID , set_value = durationString

;
; Calculate datarate (ms)
;
; Convert datarate to a string
tl_dr  = (DOUBLE(volume)/1024.)  /  (DOUBLE(duration)/1000.)
dr     = STRJOIN([STRING(format='(D10.4)',tl_dr),' kBits'],/SINGLE)
WIDGET_CONTROL , widIDs.st_datarateID , set_value = STRTRIM(dr,2)
;print,duration/1000.

END
;______________________________________________________________________________
; Define Data members
;______________________________________________________________________________
PRO eis_mk_plan_gui__define

eis_mk_plan_widgets = {eis_mk_plan_widgets}

meta_str = {eis_meta_str                                             ,    $
            obstitle                 : ''                            ,    $
            obs_dec                  : ''                            ,    $
            join_sb                  : ''                            ,    $
            hop_id                   : ''                            ,    $
            noaa_num                 : ''                            ,    $
            sci_obj                  : ''                                 $
           }

cpt_str =  {eis_cpt_str                                              ,    $
            observer                 : ''                            ,    $
            planner                  : ''                            ,    $
            tohban                   : ''                            ,    $
            opogPassNum              : 0L                            ,    $
            obstblPassNum            : 0L                                 $
           }

struct = { eis_mk_plan_gui                                           ,     $
           tlbID                     : 0L                            ,     $
           eis_mk_plan_widgets       : eis_mk_plan_widgets           ,     $
           o_eis_timeline_plot_gui   : OBJ_NEW()                     ,     $
           o_ct_summary              : OBJ_NEW()                     ,     $
           o_def_ct                  : OBJ_NEW()                     ,     $
           dr_gui                    : OBJ_NEW()                     ,     $
           cpt_gui                   : OBJ_NEW()                     ,     $
           move_gui                  : OBJ_NEW()                     ,     $
           copy_gui                  : OBJ_NEW()                     ,     $
           meta_gui                  : OBJ_NEW()                     ,     $
           dvol_gui                  : OBJ_NEW()                     ,     $
           delete_gui                : OBJ_NEW()                     ,     $
           eis_mk_plan_ini           : OBJ_NEW()                     ,     $
           opev                      : PTR_NEW()                     ,     $
           stev                      : PTR_NEW()                     ,     $
           obev                      : PTR_NEW()                     ,     $
           rpev                      : PTR_NEW()                     ,     $
           saa_ptr                   : PTR_NEW()                     ,     $
           ngt_ptr                   : PTR_NEW()                     ,     $
           meta_str                  : meta_str                      ,     $
           cpt_str                   : cpt_str                       ,     $
           logo_fileName             : ''                            ,     $
           saa_check                 : 0                             ,     $
           durationUnits             : 0                             ,     $
           volumeUnits               : 0                             ,     $
           replot                    : 0B                            ,     $
           sot_offset                : FLTARR(2)                     ,     $
           eis_timeline_container    : OBJ_NEW()                     ,     $
           eis_study                 : {eis_study}                   ,     $
           tl_graphics               : {eis_timeline_graphics}       ,     $
           eis_xrt_flare_control     : {eis_xrt_flare_control}       ,     $
           eis_event_control         : {eis_event_control}           ,     $
           eis_flare_control         : {eis_flare_control}           ,     $
;          Trigger/Response Study GUI Objects
           eis_event_gui             : OBJ_NEW()                     ,     $
           eis_flare_gui             : OBJ_NEW()                     ,     $
           xrt_flare_gui             : OBJ_NEW()                     ,     $
;
           cursor_time_gui           : OBJ_NEW()                     ,     $
           repointpopup_offID        : 0L                            ,     $
           repointpopup_onID         : 0L                            ,     $
           num_days                  : 0                             ,     $
           repoint_buffer            : 0                             ,     $
           repoint_warning           : 0B                            ,     $
           rp                        : 0                             ,     $
           repointpopup_on           : 0B                                  $
         }

END
