/*
    gr_locpolyci_options.dlg
    
*!  VERSION 1.0.2  04jan2010

*/

VERSION 10.0

INCLUDE _std_mlarge
DEFINE _dlght 250
INCLUDE header_gr_child

DEFINE _clwd 15

HELP hlp1, view("help twoway_lpolyci")
RESET res1

SCRIPT PREINIT
BEGIN
	create STRING lineResults
END

SCRIPT POSTINIT
BEGIN
	program checkLineResults
END

INCLUDE _kernel_function_list

DIALOG main, label("Local polynomial plot options") tabtitle("Main")
BEGIN
  TEXT     tx_function		_lft	_top	200	.,	///
	label("Kernel function:")
  COMBOBOX cb_function		@	_ss	_vnwd	.,	///
	dropdownlist						///
	contents(kernel_function)				///
	values(kernel_function_val)
	
  SPINNER  sp_degree		@	+35	_spwd	.,	///
	default(0) min(0) max(10000000)				///
	option(degree)
  TEXT     tx_degree		_spsep	@	380	.,	///
	label("Degree of the polynomial to be used for smoothing (default = 0)")
	
  CHECKBOX ck_points		_lft	+35	_iwd	.,	///
	onclickon(script points_on)				///
	onclickoff(script points_off)	  			///
	label("Override the number of points at which the smooth is to be evaluated")
  SPINNER  sp_points		+20	_ss	_en7wd	.,	///
	default(50) min(1) max(10000000) option(n)
  TEXT     tx_points		_en7sep	@	200	.,	///
	label("Number of points")
END

SCRIPT points_on
BEGIN
	main.sp_points.enable
	main.tx_points.enable
END

SCRIPT points_off
BEGIN
	main.sp_points.disable
	main.tx_points.disable
END

DIALOG se_ci, tabtitle("SE/CI")
BEGIN
  DEFINE _x _lft
  DEFINE _y _top
  DEFINE _cx 200
  INCLUDE _sp_level

  CHECKBOX ck_bwidth		_lft	_ls	_iwd	.,	///
	onclickon(script bwidth_on)				///
	onclickoff(script bwidth_off)				///
	label("Override the width of the smoothing window around each point")
  EDIT     ed_bwidth		+20	_ss	_en7wd	.,	///
  	option(bwidth) label("Halfwidth of the kernel")
  TEXT     tx_bwidth		_en7sep	@	200	.,	///
	label("Halfwidth of the kernel")

  CHECKBOX ck_pwidth		_lft	_ls	_iwd	.,	///
	onclickon(script pwidth_on)				///
	onclickoff(script pwidth_off)				///
	label("Override the pilot bandwidth")
  EDIT     ed_pwidth		+20	_ss	_en7wd	.,	///
  	option(pwidth) label("Pilot bandwidth")
  TEXT     tx_pwidth		_en7sep	@	200	.,	///
	label("Pilot bandwidth")

  CHECKBOX ck_var		_lft	_ls	_iwd	.,	///
	onclickon(script var_on)				///
	onclickoff(script var_off)				///
	label("Override the estimate of the residual variance")
  EDIT     ed_var		+20	_ss	_en7wd	.,	///
  	option(var) label("Estimate") numonly
  TEXT     tx_var		_en7sep	@	200	.,	///
	label("Estimate")
END

SCRIPT bwidth_on
BEGIN
	se_ci.ed_bwidth.enable
	se_ci.tx_bwidth.enable
END

SCRIPT bwidth_off
BEGIN
	se_ci.ed_bwidth.disable
	se_ci.tx_bwidth.disable
END

SCRIPT pwidth_on
BEGIN
	se_ci.ed_pwidth.enable
	se_ci.tx_pwidth.enable
END

SCRIPT pwidth_off
BEGIN
	se_ci.ed_pwidth.disable
	se_ci.tx_pwidth.disable
END

SCRIPT var_on
BEGIN
	se_ci.ed_var.enable
	se_ci.tx_var.enable
END

SCRIPT var_off
BEGIN
	se_ci.ed_var.disable
	se_ci.tx_var.disable
END

SCRIPT plot_PREINIT
BEGIN
	create STRING lineResults
	create STRING markerResults
	create STRING rareaResults
	create STRING rbarResults
	create STRING rspikeResults
	create STRING rlineResults
END

SCRIPT plot_POSTINIT
BEGIN
	program checkLineResults
	program checkMarkerResults
	program checkRangeAreaResults
	program checkRangeBarResults
	program checkRangeSpikeResults
	program checkRangeLineResults
END

DIALOG plot, tabtitle("Plot")
BEGIN
  TEXT     tx_plot		_lft	_top	120	.,	///
	label("Plot type of fit:")
DEFINE y @y
  COMBOBOX cb_plot		@	_ss	@	.,	///
	dropdownlist						///
	contents(fit_plot_list)					///
	values(fit_plot_list_values)				///
	onselchangelist(fit_plot_actions)			///
	option(fitplot) default(line)
  BUTTON   bu_line_opts		@	+35	@	.,	///
	label("Line properties  ")				///
	onpush(script line_options_show)			///
	tooltip("Line properties for local polynomial plot")
  BUTTON   bu_marker_opts	@	_ls	@	.,	///
	label("Marker properties  ")				///
	onpush(script marker_options_show)			///
	tooltip("Marker symbol and label properties for local polynomial plot")

  TEXT     tx_ciplot		+160	y	155	.,	///
	label("Plot type of CI:")
  COMBOBOX cb_ciplot		@	_ss	@	.,	///
	dropdownlist						///
	contents(fit_ciplot_list)				///
	values(fit_ciplot_list_values)				///
	onselchangelist(fit_ciplot_actions)			///
	option(ciplot) default(rarea)
	
  BUTTON   bu_rarea_opts	@	+35	@	.,	///
	label("Area properties  ")				///
	onpush(script rarea_options_show)			///
	tooltip("Area properties for confidence interval plot")
  BUTTON   bu_rbar_opts		@	@	@	.,	///
	label("Bar properties  ")				///
	onpush(script rbar_options_show)			///
	tooltip("Bar properties for confidence interval plot")
  BUTTON   bu_rspike_opts	@	@	@	.,	///
	label("Spike properties  ")				///
	onpush(script rspike_options_show)			///
	tooltip("Spike properties for confidence interval plot")
  BUTTON   bu_rline_opts	@	@	@	.,	///
	label("Line properties  ")				///
	onpush(script rline_options_show)			///
	tooltip("Line properties for confidence interval plot")
  
  TEXT     tx_cap_size		+175	-20	120	.,	///
	label("Cap size:") 
  COMBOBOX cb_cap_size		@	+20	100	.,	///
	dropdown 						///
	contents(symbolsizes) option(msize)
END

LIST fit_plot_list
BEGIN
	Line
	Connected
	Scatter
END
LIST fit_plot_list_values
BEGIN
	line
	connected
	scatter
END
LIST fit_plot_actions
BEGIN
	script line_on
	script connected_on
	script scatter_on
END

SCRIPT line_on
BEGIN
	plot.bu_line_opts.enable
	plot.bu_marker_opts.disable
END
SCRIPT connected_on
BEGIN
	plot.bu_line_opts.enable
	plot.bu_marker_opts.enable
END
SCRIPT scatter_on
BEGIN
	plot.bu_line_opts.disable
	plot.bu_marker_opts.enable
END

LIST fit_ciplot_list
BEGIN
	Range area
	Range bar
	Range spike
	Range spike w/cap
	Range line
END
LIST fit_ciplot_list_values
BEGIN
	rarea
	rbar
	rspike
	rcap
	rline
END
LIST fit_ciplot_actions
BEGIN
	script rarea_on
	script rbar_on
	script rspike_on
	script rcap_on
	script rline_on
END

SCRIPT rarea_on
BEGIN
	plot.bu_rarea_opts.show
	plot.bu_rbar_opts.hide
	plot.bu_rspike_opts.hide
	plot.bu_rline_opts.hide
	plot.cb_cap_size.hide
	plot.tx_cap_size.hide
END
SCRIPT rbar_on
BEGIN
	plot.bu_rarea_opts.hide
	plot.bu_rbar_opts.show
	plot.bu_rspike_opts.hide
	plot.bu_rline_opts.hide
	plot.cb_cap_size.hide
	plot.tx_cap_size.hide
END
SCRIPT rspike_on
BEGIN
	plot.bu_rarea_opts.hide
	plot.bu_rbar_opts.hide
	plot.bu_rspike_opts.show
	plot.bu_rline_opts.hide
	plot.cb_cap_size.hide
	plot.tx_cap_size.hide
END
SCRIPT rcap_on
BEGIN
	plot.bu_rarea_opts.hide
	plot.bu_rbar_opts.hide
	plot.bu_rspike_opts.show
	plot.bu_rline_opts.hide
	plot.cb_cap_size.show
	plot.tx_cap_size.show
END
SCRIPT rline_on
BEGIN
	plot.bu_rarea_opts.hide
	plot.bu_rbar_opts.hide
	plot.bu_rspike_opts.hide
	plot.bu_rline_opts.show
	plot.cb_cap_size.hide
	plot.tx_cap_size.hide
END

SCRIPT line_options_show
BEGIN
	create CHILD gr_line_options AS lineOptions, allowsubmit
	lineOptions.setExitString lineResults
	lineOptions.settitle "Line properties for local polynomial"
	lineOptions.setExitAction "program checkLineResults"
	lineOptions.setSubmitAction "script lineSubmit"
	lineOptions.callthru "script gr_line_setOptionsTo_cl"
END
PROGRAM checkLineResults
BEGIN
	if lineResults.iseq("") {
		call plot.bu_line_opts.setlabel "Line properties  "
	}
	if lineResults.isneq("") {
		call plot.bu_line_opts.setlabel "Line properties *"
	}
END
SCRIPT lineSubmit
BEGIN
	program checkLineResults
	Submit
END

SCRIPT marker_options_show
BEGIN
	create CHILD gr_marker_options AS markerOptions, allowsubmit
	markerOptions.setExitString markerResults
	markerOptions.settitle "Marker properties for local polynomial"
	markerOptions.setExitAction "program checkMarkerResults"
	markerOptions.setSubmitAction "script markerSubmit"
END
PROGRAM checkMarkerResults
BEGIN
	if markerResults.iseq("") {
		call plot.bu_marker_opts.setlabel "Marker properties  "
	}
	if markerResults.isneq("") {
		call plot.bu_marker_opts.setlabel "Marker properties *"
	}
END
SCRIPT markerSubmit
BEGIN
	program checkMarkerResults
	Submit
END

SCRIPT rarea_options_show
BEGIN
	create CHILD gr_rarea_options AS rareaOptions, allowsubmit
	rareaOptions.setExitString rareaResults
	rareaOptions.settitle "Area properties for local polynomial CI's"
	rareaOptions.setExitAction "program checkRangeAreaResults"
	rareaOptions.setSubmitAction "script rareaSubmit"
	rareaOptions.callthru "script gr_rarea_setOptionsTo_bl"
	rareaOptions.callthru "script gr_rarea_setOrientationOff"
END
PROGRAM checkRangeAreaResults
BEGIN
	if rareaResults.iseq("") {
		call plot.bu_rarea_opts.setlabel "Area properties  "
	}
	if rareaResults.isneq("") {
		call plot.bu_rarea_opts.setlabel "Area properties *"
	}
END
SCRIPT rareaSubmit
BEGIN
	program checkRangeAreaResults
	Submit
END

SCRIPT rbar_options_show
BEGIN
	create CHILD gr_rbar_options AS rbarOptions, allowsubmit
	rbarOptions.setExitString rbarResults
	rbarOptions.settitle "Bar properties for local polynomial CI's"
	rbarOptions.setExitAction "program checkRangeBarResults"
	rbarOptions.setSubmitAction "script rbarSubmit"
	rbarOptions.callthru "script gr_rbar_setOptionsTo_bl"
	rbarOptions.callthru "script gr_rbar_setOrientationOff"
	rbarOptions.callthru "script gr_rbar_setBarWidthOff"
END
PROGRAM checkRangeBarResults
BEGIN
	if rbarResults.iseq("") {
		call plot.bu_rbar_opts.setlabel "Bar properties  "
	}
	if rbarResults.isneq("") {
		call plot.bu_rbar_opts.setlabel "Bar properties *"
	}
END
SCRIPT rbarSubmit
BEGIN
	program checkRangeBarResults
	Submit
END

SCRIPT rspike_options_show
BEGIN
	create CHILD gr_rspike_options AS rspikeOptions, allowsubmit
	rspikeOptions.setExitString rspikeResults
	rspikeOptions.settitle "Spike properties for local polynomial CI's"
	rspikeOptions.setExitAction "program checkRangeSpikeResults"
	rspikeOptions.setSubmitAction "script rspikeSubmit"
	rspikeOptions.callthru "script gr_rspike_setOptionsTo_bl"
	rspikeOptions.callthru "script gr_rspike_setOrientationOff"
END
PROGRAM checkRangeSpikeResults
BEGIN
	if rspikeResults.iseq("") {
		call plot.bu_rspike_opts.setlabel "Spike properties  "
	}
	if rspikeResults.isneq("") {
		call plot.bu_rspike_opts.setlabel "Spike properties *"
	}
END
SCRIPT rspikeSubmit
BEGIN
	program checkRangeSpikeResults
	Submit
END

SCRIPT rline_options_show
BEGIN
	create CHILD gr_line_options AS rlineOptions, allowsubmit
	rlineOptions.setExitString rlineResults
	rlineOptions.settitle "Range line options for local polynomial CI's"
	rlineOptions.setExitAction "program checkRangeLineResults"
	rlineOptions.setSubmitAction "script rlineSubmit"
	rlineOptions.callthru "script gr_line_setOptionsTo_bl"
END
PROGRAM checkRangeLineResults
BEGIN
	if rlineResults.iseq("") {
		call plot.bu_rline_opts.setlabel "Line properties  "
	}
	if rlineResults.isneq("") {
		call plot.bu_rline_opts.setlabel "Line properties *"
	}
END
SCRIPT rlineSubmit
BEGIN
	program checkRangeLineResults
	Submit
END

PROGRAM command
BEGIN
	put main.cb_function " "
	optionarg /hidedefault main.sp_degree
	optionarg main.sp_points

	optionarg /hidedefault se_ci.sp_level
	if se_ci.ck_bwidth {
		require se_ci.ed_bwidth
		optionarg se_ci.ed_bwidth
	}
	if se_ci.ck_pwidth {
		require se_ci.ed_pwidth
		optionarg se_ci.ed_pwidth
	}
	if se_ci.ck_var {
		require se_ci.ed_var
		optionarg se_ci.ed_var
	}
	
	optionarg /hidedefault plot.cb_plot
	if ! D(plot.bu_line_opts) {
		put " " lineResults " "
	}
	if ! D(plot.bu_marker_opts) {
		put " " markerResults " "
	}
	optionarg /hidedefault plot.cb_ciplot
	if ! H(plot.bu_rarea_opts) {
		put " " rareaResults " "
	}
	if ! H(plot.bu_rbar_opts) {
		put " " rbarResults " "
	}
	if ! H(plot.bu_rspike_opts) {
		put " " rspikeResults " "
	}
	if ! H(plot.bu_rline_opts) {
		put " " rlineResults " "
	}
	optionarg /hidedefault plot.cb_cap_size
END
