PRO gui_optevent, ev

;;-----------------------------------------------------------------------------
;; PURPOSE:
;;	Event handler for the DI calibration GUI Option Pane
;;
;; CALLING SEQUENCE:
;;	gui_optevent, ev
;;
;; REQUIRED INPUTS:
;;	ev - Event structure
;;
;; OUTPUTS:
;;
;; OPTIONAL INPUT KEYWORDS:
;;
;; EXAMPLE:
;;      IDL> gui_optevent, ev
;;
;; PROCEDURES USED (i.e. called directly!):
;;
;; MODIFICATION HISTORY:
;;   2004-07-29  M. Desnoyer    Created
;;
;;-----------------------------------------------------------------------------

;; Get the options structure
widget_control, ev.TOP, get_uvalue=opts, /NO_COPY

;; The different widgets that could produce an event
CASE widget_info(ev.ID, /UNAME) OF

;; The enable button
'ena': BEGIN
	
	;; Figure out which module we're seeing
	CASE widget_info(widget_info(ev.TOP, find_by_uname='modlist'),$
		/list_select) OF
	0: opts.mods.tempVolt = ev.select
	2: opts.mods.flagSat = ev.select
	3: opts.mods.bitWeight = ev.select 
	4: opts.mods.linDN = ev.select
	5: opts.mods.dark = ev.select
	6: opts.mods.xtalk = ev.select
	7: opts.mods.gain = ev.select
	8: opts.mods.flat = ev.select
	9: opts.mods.desmear = ev.select
	10: opts.mods.badPixs = ev.select
	12: opts.mods.fillGaps = ev.select
	13: opts.mods.despike = ev.select
	14: opts.mods.denoise = ev.select
	15: opts.mods.mtf = ev.select
	16: opts.mods.geom = ev.select
	ELSE: message, 'Invalid module selected'
	ENDCASE
	
	;; Enable/Disable the module
	sib = widget_info(ev.id, /SIBLING)
	IF sib NE 0 THEN widget_control, sib, sensitive=ev.select

	;; Update the list
	widget_control, ev.TOP, set_uvalue=opts, /NO_COPY
	gui_updateModList, ev.TOP
	RETURN
END

;; The gap size slider
'gapslide': opts.maxgapsize = ev.value

;; Despiking threshold slider
'spikethresh': opts.spikeThresh = ev.value

;; Despiking iterate slider
'spikeiter': opts.spikeIter = ev.value

;; Despiking box size slider
'spikebox': opts.spikeBox = ev.value

;; Decompression slider
'mtfparam':opts.mtfParam = ev.value

;; Compression LUT selection
'compresspick': opts.compressfn = ev.value

;; Bit Weighting LUT selection
'adcpick': opts.adcfn = ev.value

;; Linearize DN polynomial selection
'lindnpick':opts.lindnfn = ev.value

;; The dark frame selection field
'drkpick': opts.darkfn = ev.value

;; Gain selection filed
'gainpick': opts.gainfn = ev.value

;; The flat field selection field
'flatpick': opts.flatfn = ev.value

;; Bad pixel field selection
'badpixspick': opts.badpixsfn = ev.value

;; Geometric tie point selection
'geompick': opts.geomfn = ev.value

;; MTF selection
'mtfpick': opts.mtffn = ev.value

;; VIS constant selection
'visconstpick': opts.visconstfn = ev.value

;; Spectral map selection
'specpick': opts.specfn = ev.value

;; Calibration constant map selection
'constmappick': opts.constmapfn = ev.value

;; H-lambda selection
'hlambpick': opts.hlambfn = ev.value

;; Some radio button was pressed
'radio': BEGIN
	;; Only care about set events
	IF ev.select EQ 0 THEN BREAK

	;; Find out which radio button based on the current module
	selected = widget_info(widget_info(ev.TOP, find_by_uname='modlist'),$
		/list_select)
	CASE selected OF
	1: opts.compressMeth = ev.value+1
	5: BEGIN
		opts.darkalg = ev.value
		widget_control, widget_info(ev.ID,/sibling), $
			sensitive= ev.value EQ 2
	END
	9: opts.desmearalg = ev.value
	13: opts.spikemed = ev.value
	15: BEGIN
		opts.mtfAlg = ev.value+1
		opts.mtfParam = ev.value EQ 0?0.01:100
		widget_control, ev.TOP, set_uvalue=opts
		gui_updateoptpane, ev.TOP
	END
	ELSE: message, 'Unknown Radio Button'
	ENDCASE
END

;; Decompression file input enable button
'docompress': BEGIN
	opts.compressEna = ev.select
	widget_control, widget_info(ev.ID,/SIBLING), sensitive=ev.select
END

;; Bit Weighting file input enable button
'doadc': BEGIN
	opts.adcEna = ev.select
	widget_control, widget_info(ev.ID,/SIBLING), sensitive=ev.select
END

;; Linearization file input enable button
'dolindn': BEGIN
	opts.lindnEna = ev.select
	widget_control, widget_info(ev.ID,/SIBLING), sensitive=ev.select
END

;; Gain file inputer enable button
'dogain': BEGIN
	opts.gainEna = ev.select
	widget_control, widget_info(ev.ID,/SIBLING), sensitive=ev.select
END

;; Flat field file input enable button
'doflat': BEGIN
	opts.flatEna = ev.select
	widget_control, widget_info(ev.ID,/SIBLING), sensitive=ev.select
END

;; Bad pixel map options
'dobadpixs': BEGIN
	opts.badpixsEna = ev.select
	widget_control, widget_info(ev.ID,/SIBLING), $
		sensitive=ev.select
END

;; Type of pixels to interpolate over
'whatinterp':BEGIN
	IF ev.value EQ 0 THEN $ ;; Bad pixel button
		opts.badPixsInterp = ev.select $
	ELSE $	;; Missing data button
		opts.missingInterp = ev.select
END

;; Geometric file input enable button
'dogeom': BEGIN
	opts.geomEna = ev.select
	widget_control, widget_info(ev.ID,/SIBLING), sensitive=ev.select
END

;; Convolution filter file input enable button
'domtf': BEGIN
	opts.mtfEna = ev.select
	widget_control, widget_info(ev.ID,/SIBLING), sensitive=ev.select
END

;; VIS constant file input enable button
'dovisconst': BEGIN
	opts.visconstEna = ev.select
	widget_control, widget_info(ev.ID,/SIBLING), sensitive=ev.select
END

;; Spectral map file input enable button
'dospec': BEGIN
	opts.specEna = ev.select
	widget_control, widget_info(ev.ID,/SIBLING), sensitive=ev.select
END

;; IR constant map file input enable button
'doconstmap': BEGIN
	opts.constmapEna = ev.select
	widget_control, widget_info(ev.ID,/SIBLING), sensitive=ev.select
END

;; H-Lamba lookup table specify
'dohlamb': BEGIN
	opts.hlambEna = ev.select
	widget_control, widget_info(ev.ID,/SIBLING), sensitive=ev.select
END

ENDCASE

;; Update the data structure
widget_control, ev.TOP, set_uvalue=opts, /NO_COPY

RETURN

END