;------------------------------------------------------------------------------;
;+
; NAME:
;                    eis_pointing_gui
; PURPOSE:
;                    This object
; INPUTS:
;                    GROUP -
; VERSION
;       v0.1 JAR 7-June-2007
;           Removed multi-raster condition to include "retain relative
;           pointing" button
;       v0.2 JAR 6-Jul-2007
;           Re-designed GUI layout.
;           Included facility to supply pointing offsets in mechanical units
;           (MIP and YIP)
;
;-
;------------------------------------------------------------------------------;
FUNCTION eis_pointing_gui::Init , parentClass , nRasters

Self.parentClass  = parentClass
Self.group_leader = parentClass->tlbID()
;-------------------create the main base---------------------------------------;
pt_version = eis_get_pt_version_number()
widTitle = 'EIS Pointing Tool' + pt_version
TLB_EVENT                   = {eis_pointing_gui_Event}
TLB_EVENT.eis_pointing_gui = Self
TLB_EVENT.Type              = "TLB"
Self.tlbID                  = WIDGET_BASE(                                  $
                                    TITLE       = widTitle,                 $
                                    COLUMN      = 1,                        $
                                    /FLOATING      ,                        $
                                    GROUP_LEADER = Self.group_leader ,      $
                                    UValue      = TLB_EVENT,                $
                                    xOffset     = 800)

;-------------------create the GUI------------------------------;
Self->createGUI , nRasters
;Self->readLLDataBase

RETURN, 1

END
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_pointing_gui::createGUI , nRasters

; ______________________________________________________________________
;
; Refresh Base
;
; ______________________________________________________________________
refreshBase                 = WIDGET_BASE(Self.tlbID ,                      $
                                    COLUMN      = 1  ,                      $
                                    frame       = 4)

refreshTopLHSBase           = WIDGET_BASE(refreshBase ,                      $
                                    ROW         = 1)

refreshLHSBase              = WIDGET_BASE(refreshTopLHSBase ,                     $
                                    COLUMN      = 1    ,                    $
                                    xSize       = 400)
value = 'Refresh s/c pointing - centre the study on the EIS FOV'
aLabel                      = WIDGET_LABEL(refreshLHSBase    ,              $
                                    value       = value      ,              $
                                    /ALIGN_LEFT)

refreshRHSBase              = WIDGET_BASE(refreshTopLHSBase ,                     $
                                    COLUMN      = 1)

REFRESH_EVENT               = {eis_pointing_gui_Event}
REFRESH_EVENT.eis_pointing_gui = Self
REFRESH_EVENT.Type          = "REFRESH"
refresh_buttonID            = WIDGET_BUTTON(refreshRHSBase      ,           $
                                    value       = ' Go '        ,           $
                                    Event_Pro   = 'eis_pointing_gui_EV',    $
                                    uValue      = REFRESH_EVENT)


; ______________________________________________________________________
;
; Relative Pointing Base
;
; ______________________________________________________________________
Self->create_relative_widgets

; ______________________________________________________________________
;
; Same Pointing Base
;
; ______________________________________________________________________
IF (nRasters GT 1) THEN Self->create_all_same_widgets

; ______________________________________________________________________
;
; Offset Pointing Base
;
; ______________________________________________________________________
IF (nRasters GT 1) THEN Self->create_offset_widgets


; ______________________________________________________________________
;
; Bottom Base
;
; ______________________________________________________________________
bottomBase                  = WIDGET_BASE(Self.tlbID ,                      $
                                    ROW         = 1,/grid_layout,/frame)

; ______________________________________________________________________
;
; Quit Button
;
; ______________________________________________________________________

QUIT_EVENT                  = {eis_pointing_gui_Event}
QUIT_EVENT.eis_pointing_gui = Self
QUIT_EVENT.Type             = "QUIT"
quitbutton                  = WIDGET_BUTTON(bottomBase ,                    $
                                    value       = ' Dismiss ' ,             $
                                    Event_Pro   = 'eis_pointing_gui_EV',    $
                                    uValue      = QUIT_EVENT)

END

;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_pointing_gui_Cleanup , wid

WIDGET_CONTROL , wid , get_uvalue = eis_pointing_gui_Event
OBJ_DESTROY    , eis_pointing_gui_Event.eis_pointing_gui

END
;______________________________________________________________________________
; Cleanup
;______________________________________________________________________________
PRO eis_pointing_gui::CleanUp


END
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_pointing_gui::setProperty, autoScaleStr  = autoScaleStr

IF (N_ELEMENTS(autoScaleStr) GT 0) THEN BEGIN
    stop
ENDIF

End
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_pointing_gui::GetProperty, tlbID   = tlbID

tlbID = Self.tlbID

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

    Return, Self.tlbID
End

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

Widget_Control, Self.tlbID, _Extra=Widget_Control_Keywords

End

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

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

End

;______________________________________________________________________________
; Realize wrapper
;______________________________________________________________________________
PRO eis_pointing_gui::Realize

Widget_Control, Self.tlbID, /Realize

End

;______________________________________________________________________________
; XManager wrapper
;______________________________________________________________________________
PRO eis_pointing_gui::XManager

XMANAGER , "eis_pointing_gui" ,   Self.tlbID ,                                 $
    Event_Handler  = "eis_pointing_gui_EV",                                    $
    cleanup        = "eis_pointing_gui_Cleanup",                               $
    GROUP_LEADER   = Self.group_leader ,                                   $
    /NO_BLOCK

END

;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_pointing_gui_Event__Define

    struct = {  eis_pointing_gui_Event,                                         $
                Type                 : "",         $ ;Unique identifier for event
                eis_pointing_gui   : OBJ_NEW(),  $ ;Reference to object passed
                extra                : 0           $ ;to - often object associated
             }
END
;______________________________________________________________________________
; Event Handler wrapper
;______________________________________________________________________________
PRO eis_pointing_gui_EV , Event

;Get event handler structure containing eis_pointing_gui type object
Widget_CONTROL,Event.ID,get_uvalue = eis_pointing_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_pointing_gui's class member procedure "Handler"
eis_pointing_gui_Event.eis_pointing_gui->Handler,Event

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

WIDGET_CONTROL, Event.ID, Get_UValue = eis_pointing_gui_Event
CASE eis_pointing_gui_Event.Type OF
    "QUIT"      : Self->Control, /Destroy
    "REFRESH"   : Self->refresh
    "ALL_SAME"  : Self->all_same
    "OFFSET"    : Self->offset
    "XOFFSET"   : ;Self->x_offset
    "YOFFSET"   : ;Self->y_offset
    "RELATIVE"  : Self->relative
    ELSE        : print,eis_pointing_gui_Event.Type
ENDCASE

END
;______________________________________________________________________________
; All same pointing widgets
;______________________________________________________________________________
PRO eis_pointing_gui::create_all_same_widgets

sameBase                    = WIDGET_BASE(Self.tlbID ,                      $
                                    COLUMN      = 1  ,                      $
                                    frame       = 4)

sameTopBase                 = WIDGET_BASE(sameBase   ,                      $
                                    ROW         = 1)


sameLHSBase                 = WIDGET_BASE(sameTopBase    ,                  $
                                    COLUMN      = 1    ,                    $
                                    xSize       = 400)
value = 'Centre all study rasters on the same relative pointing'
aLabel                      = WIDGET_LABEL(sameLHSBase       ,              $
                                    value       = value      ,              $
                                    /ALIGN_LEFT)

sameRHSBase                 = WIDGET_BASE(sameTopBase    ,                  $
                                    COLUMN      = 1)

SAME_EVENT                  = {eis_pointing_gui_Event}
SAME_EVENT.eis_pointing_gui = Self
SAME_EVENT.Type             = "ALL_SAME"
all_same_buttonID           = WIDGET_BUTTON(sameRHSBase         ,           $
                                    value       = ' Go '        ,           $
                                    Event_Pro   = 'eis_pointing_gui_EV',    $
                                    uValue      = SAME_EVENT)

END
;______________________________________________________________________________
; All same pointing widgets
;______________________________________________________________________________
PRO eis_pointing_gui::create_relative_widgets

relativeBase                = WIDGET_BASE(Self.tlbID ,                      $
                                    ROW         = 1  ,                      $
                                    frame       = 4)

relativeTopBase             = WIDGET_BASE(relativeBase ,                    $
                                    ROW         = 1)

relativeLHSBase             = WIDGET_BASE(relativeTopBase    ,              $
                                    COLUMN      = 1    ,                    $
                                    xSize       = 400)
value = 'Refresh s/c pointing - but apply relative pointing (ie: retain'
aLabel                      = WIDGET_LABEL(relativeLHSBase       ,          $
                                    value       = value      ,              $
                                    /ALIGN_LEFT)

value = '                       existing MIP and YIP values)'
aLabel                      = WIDGET_LABEL(relativeLHSBase       ,          $
                                    value       = value      ,              $
                                    /ALIGN_LEFT)


relativeRHSBase             = WIDGET_BASE(relativeTopBase    ,              $
                                    COLUMN      = 1)

RELATIVE_EVENT              = {eis_pointing_gui_Event}
RELATIVE_EVENT.eis_pointing_gui = Self
RELATIVE_EVENT.Type         = "RELATIVE"
relative_buttonID           = WIDGET_BUTTON(relativeRHSBase         ,       $
                                    value       = ' Go '        ,           $
                                    Event_Pro   = 'eis_pointing_gui_EV',    $
                                    uValue      = RELATIVE_EVENT)

END
;______________________________________________________________________________
; Offset Widgets
;______________________________________________________________________________
PRO eis_pointing_gui::create_offset_widgets

offsetBase                  = WIDGET_BASE(Self.tlbID ,                      $
                                    COLUMN      = 1  ,                      $
                                    frame       = 4)

offset_rowBase              = WIDGET_BASE(offsetBase ,                      $
                                    ROW         = 1)


offsetLHSBase               = WIDGET_BASE(offset_rowBase    ,               $
                                    COLUMN      = 1    ,                    $
                                    xSize       = 400)
value = 'Apply running offsets to each raster:'
aLabel                      = WIDGET_LABEL(offsetLHSBase       ,            $
                                    value       = value      ,              $
                                    /ALIGN_LEFT)

offsetRHSBase               = WIDGET_BASE(offset_rowBase    ,               $
                                    COLUMN      = 1)

OFFSET_EVENT                = {eis_pointing_gui_Event}
OFFSET_EVENT.eis_pointing_gui = Self
OFFSET_EVENT.Type           = "OFFSET"
offset_buttonID             = WIDGET_BUTTON(offsetRHSBase         ,         $
                                    value       = ' Go '        ,           $
                                    Event_Pro   = 'eis_pointing_gui_EV',    $
                                    uValue      = OFFSET_EVENT)


;
; widget tab
;
Self.offset_tabBase         = WIDGET_TAB(offsetBase)



;
; OFFSETS - heliospheric
;
offset_coordsBase           = WIDGET_BASE(Self.offset_tabBase    ,          $
                                    TITLE       = ' Heliospheric Coords ' , $
                                    ROW         = 1)

aLabel                      = WIDGET_LABEL(offset_coordsBase ,              $
                                    value       = "  X:")

X_EVENT                    = {eis_pointing_gui_Event}
X_EVENT.eis_pointing_gui   = Self
X_EVENT.Type               = "XOFFSET"
Self.x_offsetID            = WIDGET_TEXT(offset_coordsBase   ,              $
                                    value       = '0.0',                    $
                                    Event_Pro   = 'eis_pointing_gui_EV' ,   $
                                    xSize       = 8                    ,    $
                                    /EDITABLE                           ,   $
                                    uValue      = X_EVENT)

aLabel                      = WIDGET_LABEL(offset_coordsBase ,              $
                                    value       = "    Y:")

Y_EVENT                    = {eis_pointing_gui_Event}
Y_EVENT.eis_pointing_gui   = Self
Y_EVENT.Type               = "YOFFSET"
Self.y_offsetID            = WIDGET_TEXT(offset_coordsBase   ,              $
                                    value       = '0.0',                    $
                                    Event_Pro   = 'eis_pointing_gui_EV' ,   $
                                    xSize       = 8                    ,    $
                                    /EDITABLE                           ,   $
                                    uValue      = Y_EVENT)


;
; OFFSETS - mechanical
;
offset_mechBase             = WIDGET_BASE(Self.offset_tabBase    ,          $
                                    TITLE       = ' Mechanical Units '  ,   $
                                    ROW         = 1)

aLabel                      = WIDGET_LABEL(offset_mechBase   ,              $
                                    value       = "MIP:")

MIP_EVENT                   = {eis_pointing_gui_Event}
MIP_EVENT.eis_pointing_gui  = Self
MIP_EVENT.Type              = "MIPOFFSET"
Self.mip_offsetID           = WIDGET_TEXT(offset_mechBase     ,             $
                                    value       = '0'  ,                    $
                                    Event_Pro   = 'eis_pointing_gui_EV' ,   $
                                    xSize       = 8                    ,    $
                                    /EDITABLE                           ,   $
                                    uValue      = MIP_EVENT)

aLabel                      = WIDGET_LABEL(offset_mechBase   ,              $
                                    value       = "  YIP:")

YIP_EVENT                   = {eis_pointing_gui_Event}
YIP_EVENT.eis_pointing_gui  = Self
YIP_EVENT.Type              = "YIPOFFSET"
Self.yip_offsetID           = WIDGET_TEXT(offset_mechBase    ,              $
                                    value       = '0'  ,                    $
                                    Event_Pro   = 'eis_pointing_gui_EV' ,   $
                                    xSize       = 8                    ,    $
                                    /EDITABLE                           ,   $
                                    uValue      = YIP_EVENT)

END
;______________________________________________________________________________
; Relative pointing
;______________________________________________________________________________
PRO eis_pointing_gui::relative

Self.parentClass->pointing_relative
Self->Control, /Destroy

END
;______________________________________________________________________________
; Offset pointing
;______________________________________________________________________________
PRO eis_pointing_gui::offset

; Which tab is selected - Helio Coords or Mech Units
tab_index = WIDGET_INFO(Self.offset_tabBase , /TAB_CURRENT)

IF (tab_index EQ 0) THEN BEGIN
    WIDGET_CONTROL , Self.x_offsetID   , get_value = x_value
    WIDGET_CONTROL , Self.y_offsetID   , get_value = y_value
ENDIF ELSE BEGIN
    WIDGET_CONTROL , Self.mip_offsetID , get_value = x_value
    WIDGET_CONTROL , Self.yip_offsetID , get_value = y_value
ENDELSE
;
; Check x and y offsets are valid
;
; arguments-> name , newValue , oldValue , minValue , maxValue , multiple
x_valid  = is_number(x_value[0])
y_valid  = is_number(y_value[0])

IF (x_valid NE 1) THEN BEGIN
    BEEP
    mText = "X Offset is invalid. Aborting!"
    complain = DIALOG_MESSAGE( mText ,                                      $
                     DIALOG_PARENT = Self.tlbID,                            $
                     /ERROR )
    RETURN
ENDIF
IF (y_valid NE 1) THEN BEGIN
    BEEP
    mText = "Y Offset is invalid. Aborting!"
    complain = DIALOG_MESSAGE( mText ,                                      $
                     DIALOG_PARENT = Self.tlbID,                            $
                     /ERROR )
    RETURN
ENDIF


; Call eis_mk_plan method "offset_pointing" with offset values
CASE tab_index OF
    0    : Self.parentClass->offset_pointing_coords ,                       $
                                 DOUBLE(x_value[0]) , DOUBLE(y_value[0])
    ELSE : Self.parentClass->offset_pointing_mechan ,                       $
                                 FIX(x_value[0])    , FIX(y_value[0])
ENDCASE

Self->Control, /Destroy

END
;______________________________________________________________________________
; All same pointing
;______________________________________________________________________________
PRO eis_pointing_gui::all_same

Self.parentClass->pointing_inherit_all
Self->Control, /Destroy

END
;______________________________________________________________________________
; Refresh
;______________________________________________________________________________
PRO eis_pointing_gui::refresh

Self.parentClass->pointing_refresh
Self->Control, /Destroy

END
;______________________________________________________________________________
; Define Data members
;______________________________________________________________________________
PRO eis_pointing_gui__define

    struct          =   { eis_pointing_gui                              ,     $
                                    tlbID           : 0L              ,     $
                                    group_leader    : 0L              ,     $
                                    x_offsetID      : 0L              ,     $
                                    y_offsetID      : 0L              ,     $
                                    mip_offsetID    : 0L              ,     $
                                    yip_offsetID    : 0L              ,     $
                                    offset_tabBase  : 0L              ,     $
                                    parentClass     : OBJ_NEW()             $
                      }

END
