/*
 procoverlay

*!  VERSION 2.0.0  30oct2006

*/

VERSION 10.0

INCLUDE _std_mlarge
DEFINE _dlght 300
INCLUDE header

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

SCRIPT main_PREINIT
BEGIN
	create STRING marker1Results
	create STRING marker2Results
	create STRING marker_label1Results
	create STRING marker_label2Results
END

SCRIPT main_POSTINIT
BEGIN
	program main_checkMarker1Results
	program main_checkMarker2Results
	program main_checkMarkerLabel1Results
	program main_checkMarkerLabel2Results
END

PROGRAM POSTINIT_PROGRAM
BEGIN
	call create DOUBLE ny
	call ny.setvalue e(ny)
	if ny.isge(3) {
		call script gr_yaxis_setByoptsContext_on
		call script gr_xaxis_setByoptsContext_on
		call script gr_titles_setByoptsContext_on
		call script gr_legend_setByoptsContext_on
		call script gr_overall_setByoptsContext_on
	}
END

DIALOG main, tabtitle("Main") label("procoverlay - Procrustes overlay plot")
BEGIN
  CHECKBOX ck_autoaspect	_lft	_top	_iwd	.,		///
	option(autoaspect)						///
	label("Automatically adjust the aspect ratio based on the data")

  GROUPBOX gb_tgtopts		_lft	_ls	_iwd	_ht8h,		///
	label("Target")
  BUTTON bu_markers1		_ilft	_ms	120	.,		///
	label("Marker properties  ")					///
	onpush(script main_show_markers1_dialog)			///
	tooltip("Target marker properties")  
  BUTTON bu_marker_label1	@	_ls	120	.,		///
	label("Label properties  ")					///
	onpush(script main_show_marker_label1_dialog)			///
	tooltip("Target label properties")  
  CHECKBOX ck_noLabelTgt	_ilft	_ls	_ibwd	.,		///
	option(nolabel)							///
	clickon(gaction main.bu_marker_label1.disable)			///
	clickoff(gaction main.bu_marker_label1.enable)			///
	label("Do not show default observation labels")	 

  GROUPBOX gb_srcopts		_lft	+40	_iwd	_ht8h,		///
	label("Source")
  BUTTON bu_markers2		_ilft	_ms	120	.,		///
	label("Marker properties  ")					///
	onpush(script main_show_markers2_dialog)			///
	tooltip("Source marker properties")
  BUTTON bu_marker_label2	@	_ls	120	.,		///
	label("Label properties  ")					///
	onpush(script main_show_marker_label2_dialog)			///
	tooltip("Target label properties")  
  CHECKBOX ck_noLabelSrc	_ilft	_ls	_ibwd	.,		///
	label("Do not show default observation labels")			///
	clickon(gaction main.bu_marker_label2.disable)			///
	clickoff(gaction main.bu_marker_label2.enable)			///
	option(nolabel)
END

SCRIPT main_show_markers1_dialog
BEGIN
	create CHILD gr_marker_nolabel_options AS markers1, allowsubmit
	markers1.setExitString marker1Results
	markers1.settitle "Marker properties"
	markers1.setExitAction "program main_checkMarker1Results"
	markers1.setSubmitAction "program main_marker1Submit"
END
PROGRAM main_checkMarker1Results
BEGIN
	if marker1Results {
		call main.bu_markers1.setlabel "Marker properties *"
	}
	else {
		call main.bu_markers1.setlabel "Marker properties  "
	}
END
PROGRAM main_marker1Submit
BEGIN
	call program main_checkMarker1Results
	call Submit
END

SCRIPT main_show_markers2_dialog
BEGIN
	create CHILD gr_marker_nolabel_options AS markers2, allowsubmit
	markers2.setExitString marker2Results
	markers2.settitle "Marker properties"
	markers2.setExitAction "program main_checkMarker2Results"
	markers2.setSubmitAction "program main_marker2Submit"
END
PROGRAM main_checkMarker2Results
BEGIN
	if marker2Results {
		call main.bu_markers2.setlabel "Marker properties *"
	}
	else {
		call main.bu_markers2.setlabel "Marker properties  "
	}
END
PROGRAM main_marker2Submit
BEGIN
	call program main_checkMarker2Results
	call Submit
END

SCRIPT main_show_marker_label1_dialog
BEGIN
	create CHILD gr_markerlabel_options AS marker_label1, allowsubmit
	marker_label1.setExitString marker_label1Results
	marker_label1.settitle "Label properties"
	marker_label1.setExitAction "program main_checkMarkerLabel1Results"
	marker_label1.setSubmitAction "program main_marker_label1Submit"
END
PROGRAM main_checkMarkerLabel1Results
BEGIN
	if marker_label1Results {
		call main.bu_marker_label1.setlabel "Label properties *"
	}
	else {
		call main.bu_marker_label1.setlabel "Label properties  "
	}
END
PROGRAM main_marker_label1Submit
BEGIN
	call program main_checkMarkerLabel1Results
	call Submit
END

SCRIPT main_show_marker_label2_dialog
BEGIN
	create CHILD gr_markerlabel_options AS marker_label2, allowsubmit
	marker_label2.setExitString marker_label2Results
	marker_label2.settitle "Label properties"
	marker_label2.setExitAction "program main_checkMarkerLabel2Results"
	marker_label2.setSubmitAction "program main_marker_label2Submit"
END
PROGRAM main_checkMarkerLabel2Results
BEGIN
	if marker_label2Results {
		call main.bu_marker_label2.setlabel "Label properties *"
	}
	else {
		call main.bu_marker_label2.setlabel "Label properties  "
	}
END
PROGRAM main_marker_label2Submit
BEGIN
	call program main_checkMarkerLabel2Results
	call Submit
END

INCLUDE ifin
INCLUDE gr_yaxis
INCLUDE gr_xaxis
INCLUDE gr_titles
INCLUDE gr_legend
INCLUDE gr_overall

PROGRAM main_targetopts_output
BEGIN
	option main.ck_noLabelTgt
	if marker1Results & ! H(main.bu_markers1) {
		put " " marker1Results " "
	}
	if marker_label1Results & ! H(main.bu_marker_label1) {
		put " " marker_label1Results " "
	}
END

PROGRAM main_sourceopts_output
BEGIN
	option main.ck_noLabelSrc
	if marker2Results & ! H(main.bu_markers2) {
		put " " marker2Results " "
	}
	if marker_label2Results & ! H(main.bu_marker_label2) {
		put " " marker_label2Results " "
	}
END

PROGRAM command
BEGIN
	put "procoverlay "
	put " " /program ifin_output
	beginoptions
		option main.ck_autoaspect
		if marker1Results & ! H(main.bu_markers1) | 		///
		  marker_label1Results & ! H(main.bu_marker_label1) |	///
		  main.ck_noLabelTgt 					///
		 {
			put " targetopts(" 
			put /program main_targetopts_output
			put ") "
		}
		if marker2Results & ! H(main.bu_markers2) | 		///
		  marker_label2Results & ! H(main.bu_marker_label2) |	///
		  main.ck_noLabelSrc					///
		 {
			put " sourceopts(" 
			put /program main_sourceopts_output
			put ") "
		}
		put " " /program gr_yaxis_output
		put " " /program gr_xaxis_output
		put " " /program gr_titles_output
		put " " /program gr_legend_output
		put " " /program gr_overall_output
	endoptions
END

