;+
; Project     : SOHO - CDS     
;                   
; Name        : TP_RASDUR
;               
; Purpose     : Defines the window to display raster duration info.
;               
; Explanation : Creates the widgets which form the window within which
;               the raster duration information is displayed.
;               
; Use         : tp_rasdur
;    
; Inputs      : None
;               
; Opt. Inputs : None
;               
; Outputs     : None
;               
; Opt. Outputs: None
;               
; Keywords    : None
;
; Calls       : None
;               
; Restrictions: For use with MK_RASTER
;               
; Side effects: None
;               
; Category    : Planning, technical
;               
; Prev. Hist. : None
;
; Written     : C D Pike, RAL, 10-Mar-97
;               
; Modified    : Include new LOW++ telemetry rate.  CDP, 28-nov-97
;
; Version     : Version 2, 28-Nov-97
;-            

pro tp_rasdur_event, ev

;
;  common for data and widgets ids
;
@tplan_com

;
;  common holding LUT
;
common tp_colors, r,g,b

                         
widget_control, ev.id, get_uval=uval, get_val=val

case strmid(uval,0,4) of

;
;  Restore LUT, read last used tm rate and finish
;
   'DONE': begin
             tvlct,r,g,b
             widget_control, tlmrate_id, get_val=tlmrate
             tlmrate = round(float(tlmrate(0)))
             case tlmrate of
                22: begin
                       tp_obs.raster_v.tel_rate = 'H'
                       widget_control, tmr_info_2, set_val='HIGH'
                    end
                11: begin
                       tp_obs.raster_v.tel_rate = 'M'
                       widget_control, tmr_info_2, set_val='MEDIUM'
                    end
                 3: begin
                       tp_obs.raster_v.tel_rate = 'P'
                       widget_control, tmr_info_2, set_val='LOW++'
                    end
                 2: begin
                       tp_obs.raster_v.tel_rate = 'L'
                       widget_control, tmr_info_2, set_val='LOW'
                    end
              else: begin
                       tp_obs.raster_v.tel_rate = 'M'
                       widget_control, tmr_info_2, set_val='MEDIUM'
                    end
             endcase
             widget_control, plot_rasdur_base, /destroy
          end

;
;  Hardcopy menu
;
   'HARD': tp_draw_rasdur, /hard

;
;  Recalculate
;
   'RECA': tp_draw_rasdur


;
;  set the telemetry rate
;
   'TLM2': widget_control, tlmrate_id, set_val='3.2'
   'TLM3': widget_control, tlmrate_id, set_val='22.0'
   'TLM4': widget_control, tlmrate_id, set_val='1.9'
   'TLM5': widget_control, tlmrate_id, set_val='11.0'

;
;  set the engineering rate
;
   'ENG1': widget_control, engrate_id, set_val='2'
   'ENG2': widget_control, engrate_id, set_val='4'
   'ENG3': widget_control, engrate_id, set_val='8'
   'ENG4': widget_control, engrate_id, set_val='16'
   'ENG5': widget_control, engrate_id, set_val='32'
   'ENG6': widget_control, engrate_id, set_val='64'

;
;  else - no action here
;
   else:

endcase

end


;
;   MAIN program 
;   ------------
;


PRO tp_rasdur

;
;  common for data and widgets ids
;
@tplan_com

;
;  common holding LUT
;
common tp_colors, r,g,b

;
;  guard against trigger happy users
;
if xregistered('tp_rasdur') then begin
  widget_control,info_line,set_val='Duration info already on display',/append
  widget_control,plot_rasdur_base,map=1
  return
endif


;
;  create main base
;
plot_rasdur_base = WIDGET_BASE(title='VDS Raster Duration',  /FRAME, /COLUMN,$
                       group_leader = base, xoffset=850, yoffset=800)
rasdur_butt = widget_base(plot_rasdur_base, /row, group_leader=base)
rasdur_info1 = widget_base(plot_rasdur_base, /row, group_leader=base)
rasdur_info2 = widget_base(plot_rasdur_base, /row, group_leader=base)


;
;  'Done' button to exit
;
doneid = widget_button(rasdur_butt, value='Done', uvalue='DONE')
;
;  Hardcopy option
;
hardid = widget_button(rasdur_butt, value='Hardcopy', uvalue='HARD')

;
;  Recalculate option
;
calcid = widget_button(rasdur_butt, value='Recalculate', uvalue='RECA')


 
;
;  Engineering rate
;
dummy = widget_base(rasdur_info1,/row)
xpdmenu,find_with_def('eng_rate.pdm',!PATH),dummy
engrate_id = widget_text(rasdur_info1,xsize=3,ysize=1,uvalue='ERAT',$
                         value='8')
 
;
;  Telemetry mode
;
dummy = widget_base(rasdur_info1,/row)
xpdmenu,find_with_def('tlm_rate.pdm',!PATH),dummy
if tp_obs.raster_v.tel_rate eq 'L' then tr = '1.9'
if tp_obs.raster_v.tel_rate eq 'P' then tr = '3.2'
if tp_obs.raster_v.tel_rate eq 'M' then tr = '11'
if tp_obs.raster_v.tel_rate eq 'H' then tr = '22'
tlmrate_id = widget_text(rasdur_info1,xsize=5,ysize=1,uvalue='TRAT',$
                         value=tr)
 

;
;  Telemetry info
;
dummy    = widget_label(rasdur_info2,value='Spare telemetry (secs)')
ras_info2 = widget_label(rasdur_info2,value=strpad('0',20),frame=5,xsize=50)
widget_control,ras_info2,set_val='  0.0 '
 

;
;  Raser duration information
;
dummy    = widget_label(rasdur_info2,value='Raster duration (secs)')
ras_info1 = widget_label(rasdur_info2,value=strpad('0',20),frame=5,xsize=60)
widget_control,ras_info1,set_val='  0.0 '
 


 
;
;  Widget for display of windows
;

a1  = WIDGET_BASE(plot_rasdur_base, /ROW)
rasdurp_image = widget_draw(a1,xsize=600,ysize=700)

;
;  make it all appear
;
WIDGET_CONTROL, plot_rasdur_base, /realize

;
;  load top value of colour table to be white
;
tvlct,rr,gg,bb,/get
n = n_elements(rr)-1
r = rr & g = gg & b = bb
rr(n) = 255 & gg(n) = 255 & bb(n) = 255
tvlct,rr,gg,bb
 
end
