;+
; Project     : SOHO - CDS     
;                   
; Name        : SEL_LINE_MENU
;               
; Purpose     : Defines the mk_raster line selection window.
;               
; Explanation : Creates the widgets which form the window within which
;               the spectral lines can be selected.
;               
; Use         : sel_line_menu
;    
; Inputs      : None
;               
; Opt. Inputs : None
;               
; Outputs     : None
;               
; Opt. Outputs: None
;               
; Keywords    : None
;
; Calls       : 
;               
; Restrictions: None
;               
; Side effects: None
;               
; Category    : Technical, planning
;               
; Prev. Hist. : None
;
; Written     : C D Pike, RAL, 3-Apr-95
;               
; Modified    : 
;
; Version     : Version 1, 3-Apr-95
;-            

PRO sel_line_menu

;
;  common for communication
;
common tp_sell, sel_line_base, line_list_id, base_1, lls, line, nlls
common tp_el, in_array, out_array, edid, butt, ll_desc
common obs_spec, tp_obs

;
;  guard against trigger happy users
;
if xregistered('sel_line') then return

;
;  create main base
;
sel_line_base = WIDGET_BASE(title='CDS spectral line selection',$
                           /FRAME, /COLUMN, xoffset=575)
;                           group_leader = base)

;
;  and subsidiary ones
;
pmenu_base  = WIDGET_BASE(sel_line_base, /COLUMN)
m1_widg    = WIDGET_BASE(pmenu_base, /ROW, space=50)


;
;  form the widgets
;
font="-adobe-helvetica-bold-r-normal--14-100-100-100-p-82-iso8859-1"
;
;  first the 'Done' button to exit
;
doneid = widget_button(m1_widg, value='OK',font=font)

;
;  then the clear and exit
;
clearid = widget_button(m1_widg, value='Reset',font=font)

;
;  then the cancel and exit
;
cancelid = widget_button(m1_widg, value='Cancel',font=font)


;
;  and the sort menu
;
xpdmenu, ['"Sort by" {', $
                        '"Wavelength"          SORT_W',$
                        '"Element"             SORT_E','}'], m1_widg, font=font
                                    

;
;  make up the line list
;
if tp_obs.raster_p.detector eq 'N' then begin
   w1 = pix2wave('N1',0) & w2 = pix2wave('N1',1023)
   ll1 = cds_sline(w1,w2,/cds)
   w1 = pix2wave('N2',0) & w2 = pix2wave('N2',1023)
   ll = concat2d(ll1,cds_sline(w1,w2,/cds))
endif else begin
   w1 = pix2wave('G1',0) & w2 = pix2wave('G1',2047)
   ll = cds_sline(w1,w2,/cds)
   w1 = pix2wave('G2',0) & w2 = pix2wave('G2',2047)
   ll = concat2d(ll,cds_sline(w1,w2,/cds))
   w1 = pix2wave('G3',0) & w2 = pix2wave('G3',2047)
   ll = concat2d(ll,cds_sline(w1,w2,/cds))
   w1 = pix2wave('G4',0) & w2 = pix2wave('G4',2047)
   ll = concat2d(ll,cds_sline(w1,w2,/cds))
endelse
nl = n_elements(ll)/3
lls = strarr(nl)
for i=0,nl-1 do begin
   temp = strpad(strtrim(ll(0,i),2)+' '+strtrim(ll(1,i),2),10,/after) 
   lls(i) = temp + ll(2,i)
endfor


;
;  and the list widget to display the list
;
line_list_id = widget_list(pmenu_base, value=lls, ysize=40)


;
;  read existing entries
;
widget_control, edid, get_val=out_array

;
;  how many used?
;
n = where(out_array(0,*) ne '')
if n(0) eq -1 then nlls = 0 else nlls = n_elements(n)
nlls_init = nlls


;
;  make it all appear
;
WIDGET_CONTROL, sel_line_base, /realize
xmanager, 'sel_line', sel_line_base, group=base_1
end
