PRO gui_updateOptPane, topBase

;;-----------------------------------------------------------------------------
;; PURPOSE:
;;	Updates the option pane in the GUI based on the options chosen and
;;	which module is selcted in the module list. 
;;
;; CALLING SEQUENCE:
;;	gui_updateOptPane, topBase
;;
;; REQUIRED INPUTS:
;;	topBase - The widget ID of the top base, which contains the options in
;;		its uvalue
;;
;; OUTPUTS:
;;
;; OPTIONAL INPUT KEYWORDS:
;;
;; EXAMPLE:
;;      IDL> gui_updateOptPane, topBase
;;
;; PROCEDURES USED (i.e. called directly!):
;;
;; MODIFICATION HISTORY:
;;   2004-07-28  M. Desnoyer    Created
;;
;;-----------------------------------------------------------------------------

;; Get a copy of the options
widget_control, topBase, get_uvalue=opts

;; Find the option pane
optPane = widget_info(topBase, find_by_uname='optionpane')

;; Find the module list
modList = widget_info(topBase, find_by_uname='modlist')

;; Find the enable button
ena = widget_info(optPane, find_by_uname='ena')

;; If there's something in the option pane already, destroy it
widget_control, optPane, update=0
inOptPane = widget_info(widget_info(optPane, /CHILD), /SIBLING)
IF inOptPane NE 0 THEN widget_control, inOptPane, /DESTROY

;; Determine which module should be showing
CASE widget_info(modList, /list_select) OF
0: BEGIN ;; Calibrate temperatures/voltages
	widget_control, ena, set_value=[opts.mods.tempVolt], /sensitive, /map
END
1: BEGIN ;; Decompress
	;; Automatically enabled and can't change
	widget_control, ena, /set_button, sensitive=0, /map
	
	;; Add the filename box
	base = widget_base(optPane, /column)
	radio = cw_bgroup(base, ['Average Value', 'Normal Distribution', $
		'Uniform Distribution'], /exclusive, label_top= $
		'Bin Distribution to Use', $
		set_value=opts.compressMeth-1, uname='radio', /return_index)
	docompress = cw_bgroup(base, ['Specify Decompression LUT'], $
		/nonexclusive, uname='docompress', $
		set_value=[opts.compressEna])
	compressPick = dicw_fnfinder(base, uname='compresspick', $
		value=opts.compressfn, filter='*.fit', xsize=20, $
		title='Please Select a Decompression LUT', $
		sensitive=opts.compressEna)
END
2: BEGIN ;; Flag Sat
	widget_control, ena, set_value=[opts.mods.flagSat], /sensitive, /map
END
3: BEGIN ;; Uneven Bit Weighting
	widget_control, ena, set_value=[opts.mods.bitWeight], /sensitive, /map
	
	;; Add the filename box
	base = widget_base(optPane, /column, sensitive=opts.mods.bitWeight)
	doadc = cw_bgroup(base, ['Specify Bit Weight Correction LUT'], $
		/nonexclusive, uname='doadc', $
		set_value=[opts.adcEna])
	adcpick = dicw_fnfinder(base, uname='adcpick', value=opts.adcfn, $
		filter='*.fit', sensitive=opts.adcEna, xsize=20, $
		title='Please Select a Bit Weighting LUT')
END
4: BEGIN ;; Linearize DN
	widget_control, ena, set_value=[opts.mods.linDN], /map, $
		sensitive=opts.det NE 0

	;; Add the filename box
	base = widget_base(optPane, /column, sensitive=opts.mods.linDN AND $
		opts.det NE 0)
	dolindn = cw_bgroup(base, ['Specify Linearization Polynomial'], $
		/nonexclusive, uname='dolindn', $
		set_value=[opts.lindnEna])
	lindnpick = dicw_fnfinder(base, uname='lindnpick', xsize=20, $
		value=opts.lindnfn, filter='*.fit', sensitive=opts.lindnEna,$
		title='Please Select a Linearization Polynomial')
END
5: BEGIN ;; Dark Frame
	widget_control, ena, set_value=[opts.mods.dark], /sensitive, /map
	base = widget_base(optPane, row=2, sensitive=opts.mods.dark)
	radio = cw_bgroup(base, ['Pre Calculated Model', $
		"Team's Best Dark", 'File'], /exclusive, $
		label_top='Where to Get Dark Frame', set_value=opts.darkalg, $
		uname='radio', /return_index)
	drkPick = dicw_fnfinder(base, uname='drkpick', value=opts.darkfn, $
		sensitive=opts.darkalg EQ 2, filter='*.fit', xsize=20, $
		title='Please Select a Dark Frame')
END
6: BEGIN ;; XTalk
	widget_control, ena, set_value=[opts.mods.xTalk], /sensitive, /map
END
7: BEGIN ;; Gain
	widget_control, ena, set_value=[opts.mods.gain], /map, /sensitive
	
	;; Add the filename box
	base = widget_base(optPane, /column,sensitive=opts.mods.gain )
	dogain = cw_bgroup(base, ['Specify Gain Map'], $
		/nonexclusive, uname='dogain', $
		set_value=[opts.gainEna])
	gainPick = dicw_fnfinder(base, uname='gainpick', value=opts.gainfn, $
		sensitive=opts.gainEna, filter='*.fit', xsize=20, $
		title='Please Select a Gain Map')
END
8: BEGIN ;; Flat Field
	widget_control, ena, set_value=[opts.mods.flat], /map, /sensitive
	
	;; Add the filename box
	base = widget_base(optPane, /column, sensitive=opts.mods.flat )
	doflat = cw_bgroup(base, ['Specify Flat Field'], $
		/nonexclusive, uname='doflat', $
		set_value=[opts.flatEna])
	flatPick = dicw_fnfinder(base, uname='flatpick', value=opts.flatfn, $
		sensitive=opts.flatEna, filter='*.fit', xsize=20, $
		title='Please Select a Flat Field')
END
9: BEGIN ;; Desmear
	widget_control, ena, set_value=[opts.mods.desmear], /map, $
		sensitive=opts.det NE 1
	radio = cw_bgroup(optPane, ['No Desmearing', 'POC Rows', $
		'Column Averaging'], /exclusive, label_top= $
		'Desmearing Algorithm to Use', set_value=opts.desmearalg, $
		uname='radio', /return_index)
	widget_control, radio, sensitive=opts.mods.desmear AND opts.det NE 1
END
10: BEGIN ;; BadPixs
	widget_control, ena, set_value=[opts.mods.badPixs], /sensitive, /map

	;; Add the filename box
	base = widget_base(optPane, /column, sensitive=opts.mods.badPixs)
	dobadpixs = cw_bgroup(base, ['Specify Bad Pixel Map'], /nonexclusive, $
		uname='dobadpixs', set_value=[opts.badpixsEna])
	badpixsPick = dicw_fnfinder(base, uname='badpixspick', xsize=20, $
		value=opts.badpixsfn, sensitive=opts.badpixsEna, $
		filter='*.fit', title='Please Select a Bad Pixel Map')
END
11: BEGIN ;; Unit conversion
	widget_control, ena, set_value=1, sensitive=0, /map
	base = widget_base(optPane, column=1)

	;; Insert the file choosers for calibration constants/spectral maps
	IF opts.det NE 1 THEN BEGIN
		dovisconst = cw_bgroup(base, $
			['Specify VIS Calibration Constant'],$
			/nonexclusive, uname='dovisconst', $
			set_value=[opts.visconstEna])
		visconstPick = dicw_fnfinder(base, uname='visconstpick', $
			value=opts.visconstfn, sensitive=opts.visconstEna, $
			filter='*.fit', xsize=20, $
			title='Please Select a Calibration Constant' )
	ENDIF 
	IF opts.det NE 0 THEN BEGIN
		dospec = cw_bgroup(base, ['Specify IR Spectral Map'],$
			/nonexclusive, uname='dospec', $
			set_value=[opts.specEna])
		specPick = dicw_fnfinder(base, uname='specpick', $
			value=opts.specfn, sensitive=opts.specEna, $
			filter='*.fit', xsize=20, $
			title='Please Select a Spectral Map' )
		doconstmap = cw_bgroup(base, $
			['Specify IR Absolute Calibration'],$
			/nonexclusive, uname='doconstmap', $
			set_value=[opts.constmapEna])
		constmapPick = dicw_fnfinder(base, uname='constmappick', $
			value=opts.constmapfn, sensitive=opts.constmapEna, $
			filter='*.fit', xsize=20, $
			title='Please Select an Absolute Calibration' )
		doHLamb = cw_bgroup(base, $
			['Specify IR Solar Spectrum Lookup Table'],$
			/nonexclusive, uname='dohlamb', $
			set_value=[opts.hlambEna])
		hlambPick = dicw_fnfinder(base, uname='hlambpick', $
			value=opts.hlambfn, sensitive=opts.hlambEna, $
			filter='*.fit', xsize=20, $
			title='Please Select a Solar Spectrum Lookup Table' )
	ENDIF
END
12: BEGIN ;; Interpolate
	widget_control, ena, set_value=[opts.mods.fillGaps], /sensitive, /map
	
	base = widget_base(optPane, /column, sensitive=opts.mods.fillGaps)
	whatInterp = cw_bgroup(base, ['Interpolate Over Bad Pixels', $
		'Interpolate Over Missing'], /nonexclusive, uname='whatinterp', $
		set_value=[opts.badPixsInterp, opts.missingInterp])
	gapSlide = dicw_slider_w_val(base, maximum=200, minimum=1, $
		title='Maximum Size of Gap (in pixels) to Fill', value=$
		1>opts.maxgapsize<200, uname='gapslide')
END
13: BEGIN ;; Despike
	widget_control, ena, set_value=[opts.mods.despike], /sensitive, /map
	
	;; Sliders to set the options
	base = widget_base(optPane, /column, sensitive=opts.mods.despike)
	radio = cw_bgroup(base, ['Mean', 'Median'], /exclusive, $
		label_top= 'Despiking Statistic to Use', set_value=opts.spikemed, $
		uname='radio', /return_index, /row)
	spikethresh = dicw_slider_w_val(base, minimum=2, maximum=20, $
		title='Threshold (in sigmas from the median/mean)', $
		value=2.0>opts.spikethresh<20.0, uname='spikethresh',xsize=260)
	spikebox = dicw_slider_w_val(base, maximum=49, minimum=1, $
		title='Size of Box When Calculating Statistics', $
		value=1>opts.spikeBox<49,uname='spikebox',xsize=260)
	spikeiter = dicw_slider_w_val(base, maximum=50, minimum=1, $
		title='Maximum Number of Iterations', value=$
		1>opts.spikeIter<50, uname='spikeiter',xsize=260)
END
14: BEGIN ;; Denoise
	widget_control, ena, set_value=[opts.mods.denoise], /sensitive, /map
END
15: BEGIN ;; MTF
	widget_control, ena, set_value=[opts.mods.mtf], /sensitive, /map

	;; Add the filename box
	base = widget_base(optPane, /column, sensitive=opts.mods.mtf)
	radio = cw_bgroup(base, ['Constrained Least Squares', 'R-Lucy w/ Denoising'],$
		/exclusive, label_top= 'Deconvolution Algorithm', $
		set_value=opts.mtfAlg-1, uname='radio', /return_index)
	CASE opts.mtfAlg OF
	1: mtfParam = dicw_slider_w_val(base,maximum=0.1,minimum=0,$
		title='Gamma T', value=0>opts.mtfParam<0.1, uname='mtfparam', $
		format='(F6.3)')
	2: mtfParam = dicw_slider_w_val(base,maximum=500,minimum=1,$
		title='Number of Iterations', value=0>opts.mtfParam<500,uname='mtfparam',$
		format='(I3.0)')
	DEFAULT: message, 'Should not have gotten here'
	ENDCASE
	domtf = cw_bgroup(base, ['Specify PSF'], $
		/nonexclusive, uname='domtf', $
		set_value=[opts.mtfEna])
	mtfPick = dicw_fnfinder(base, uname='mtfpick', $
		value=opts.mtffn, sensitive=opts.mtfEna, xsize=20, $
		filter='*.fit', title='Please Select a PSF' )
END
16: BEGIN ;; Geometric
	widget_control, ena, set_value=[opts.mods.geom], /map, $
		sensitive=opts.det NE 1

	;; Add the filename box
	base = widget_base(optPane, /column, sensitive=opts.mods.geom AND $
		opts.det NE 1)
	dogeom = cw_bgroup(base, ['Specify Rubber Sheet Tie Points'], $
		/nonexclusive, uname='dogeom', $
		set_value=[opts.geomEna])
	geomPick = dicw_fnfinder(base, uname='geompick', $
		value=opts.geomfn, sensitive=opts.geomEna, xsize=20, $
		filter='*.fit', title='Please Select a Tie Point Definition')
END
ELSE: widget_control, ena, map=0
ENDCASE

widget_control, optPane, update=1
RETURN

END