/*
  sg__connections_prop_result.dlg

*!  VERSION 1.0.0  13jul2011

*/

VERSION 12.0
MODAL

INCLUDE _std_medium
DEFINE _dlght 360
INCLUDE header_sem_ed

DEFINE _clwd	15
DEFINE _wd	155
DEFINE _sep	+160
DEFINE _wd2	110
DEFINE _sep2	+115
DEFINE _cbwd	125
DEFINE _cbsep	+130

INCLUDE sg__common_output		/* routines necessary for output */

SCRIPT PREINIT
BEGIN
	script sg__common_output_init 	/* initialize output globals */

	create STRING OBJ
	program setupOBJECT

	create STRING sTemp
	create STRING sSrcType
	create STRING sSrcTypeOrig

	program global_get_defaults
END

PROGRAM setupOBJECT
BEGIN
	if ! __MESSAGE {
		stopbox stop 	///
			"An unexpected error has occurred." "Object not found."
		exit 198
	}
	call OBJ.setvalue class __MESSAGE.value
END

PROGRAM global_get_defaults
BEGIN
	call sSrcType.setvalue class .__SEMG.dbsettings.source
	call sSrcTypeOrig.setvalue class .__SEMG.dbsettings.source
	
	if (sSrcType.iseq("selected")) {
		call sSrcType.setvalue "edgestyle"
	}
END

SCRIPT main_PREINIT
BEGIN
	create STRING sTangent
	create STRING sDistance
	create STRING sPosRel
	create STRING sGap
	create STRING sOffsetX
	create STRING sOffsetY
	create STRING sFormat
	create STRING sFontSz
	create STRING sFontClr
	create STRING sFontFace
	create BOOLEAN bBold
	create BOOLEAN bItalic
	
	create STRING sResult		/* set by parent */
	create STRING sSrcResInit
	create STRING sSrcResOut
END

SCRIPT main_POSTINIT
BEGIN

END

PROGRAM loadDefaults /* to be called by parent dialog */
BEGIN
	/* sResult setup by parent dialog */
	/* sSrcResInit formed by sSrcType and sResult (example: lexog_result1) */
	call sSrcType.withvalue sSrcResInit.setvalue "@_"
	call sSrcResInit.append class sResult.value

	/* sSrcResOut formed by sSrcType and sResult (example: lexog.result1) */
	call sSrcType.withvalue sSrcResOut.setvalue "@."
	call sSrcResOut.append class sResult.value
	
	call program main_get_defaults
	call program main_initialize_controls
END

PROGRAM main_get_defaults
BEGIN
	call sSrcResInit.withvalue sTangent.setvalue class .__SEMG.dbsettings.@_tangent
	if (sTangent.iseq("no")) {
		call main.ck_tangent.setdefault 0
	}
	if (sTangent.iseq("yes")) {
		call main.ck_tangent.setdefault 1
	}

	call sSrcResInit.withvalue sDistance.setvalue class .__SEMG.dbsettings.@_loc
	call sDistance.withvalue main.cb_distance.setdefault "@"

	call sSrcResInit.withvalue sPosRel.setvalue class .__SEMG.dbsettings.@_relpos
	call sPosRel.withvalue main.cb_position.setdefault "@"

	call sSrcResInit.withvalue sGap.setvalue class .__SEMG.dbsettings.@_gap
	call sGap.withvalue main.cb_gap.setdefault "@"

	call sSrcResInit.withvalue sOffsetX.setvalue class .__SEMG.dbsettings.@_xoffset
	call sOffsetX.withvalue main.cb_offset_x.setdefault "@"

	call sSrcResInit.withvalue sOffsetY.setvalue class .__SEMG.dbsettings.@_yoffset
	call sOffsetY.withvalue main.cb_offset_y.setdefault "@"

	call sSrcResInit.withvalue sFontSz.setvalue class .__SEMG.dbsettings.@_size
	call sFontSz.withvalue main.cb_fsize.setdefault "@"

	call sSrcResInit.withvalue sFormat.setvalue class .__SEMG.dbsettings.@_fmt
	call sFormat.withvalue main.ed_fmt.setdefault "@"

	call sSrcResInit.withvalue sFontClr.setvalue class .__SEMG.dbsettings.@_color
	call sFontClr.withvalue main.cb_fcolor.setdefault "@"

	call sSrcResInit.withvalue sFontFace.setvalue class .__SEMG.dbsettings.@_face
	call sFontFace.withvalue main.cb_fface.setdefault "@"

	call sSrcResInit.withvalue sTemp.setvalue class .__SEMG.dbsettings.@_bold
	if (sTemp.iseq("2")) {
		call bBold.settrue
		call main.ck_bold.setdefault 1
	}
	else {
		call bBold.setfalse
		call main.ck_bold.setdefault 0
	}

	call sSrcResInit.withvalue sTemp.setvalue class .__SEMG.dbsettings.@_italic
	if (sTemp.iseq("2")) {
		call bItalic.settrue
		call main.ck_italic.setdefault 1
	}
	else {
		call bItalic.setfalse
		call main.ck_italic.setdefault 0
	}
END

PROGRAM main_initialize_controls
BEGIN
	if (sTangent.iseq("no")) {
		call main.ck_tangent.setoff
	}
	if (sTangent.iseq("yes")) {
		call main.ck_tangent.seton
	}

	call main.cb_distance.setvalue class sDistance.value
	call main.cb_position.setvalue class sPosRel.value
	call main.cb_gap.setvalue class sGap.value
	call main.cb_offset_x.setvalue class sOffsetX.value
	call main.cb_offset_y.setvalue class sOffsetY.value
	call main.ed_fmt.setvalue class sFormat.value
	call main.cb_fsize.setvalue class sFontSz.value
	call main.cb_fcolor.setvalue class sFontClr.value
	call main.cb_fface.setvalue class sFontFace.value

	if (bBold) {
		call main.ck_bold.seton
	}
	else {
		call main.ck_bold.setoff
	}
	if (bItalic) {
		call main.ck_italic.seton
	}
	else {
		call main.ck_italic.setoff
	}
END

DIALOG main, label("Appearance of results") tabtitle("Main")
BEGIN
  GROUPBOX gb_text	_lft	_top	_iwd	_ht16,		///
	label("Text")
  TEXT     tx_null1	_ilft	_ss	_wd	.,		///
	label("") right
  CHECKBOX ck_tangent	_sep	@	140	.,		///
	label("Text tangent to line")

  TEXT     tx_distance	_ilft	_ms	_wd	.,		///
	label("Distance between nodes:") right
  COMBOBOX cb_distance	_sep	@	80	., nomemory	///
	dropdown contents(.__SEM_STYLES_LABEL.pct)		///
	values(.__SEM_STYLES.pct)
  TEXT     tx_distance_m +85	@	50	.,		///
	label("( % )")

  TEXT     tx_position	_ilft	_ms	_wd	.,		///
	label("Orientation relative to line:") right
  COMBOBOX cb_position	_sep	@	80	., nomemory	///
	dropdown						///
	contents(.__SEM_STYLES_LABEL.relative_posn)		///
	values(.__SEM_STYLES.relative_posn)

  TEXT     tx_gap	_ilft	_mls	_wd	.,		///
	label("Gap from line:") right
  COMBOBOX cb_gap	_sep	@	80	., nomemory	///
	dropdown contents(.__SEM_STYLES_LABEL.gap)		///
	values(.__SEM_STYLES.gap)
  TEXT     tx_gap_m	+85	@	50	.,		///
	label("( pt. )")

  TEXT     tx_offset	_ilft	_mls	_wd	.,		///
	label("Offset:") right 
  COMBOBOX cb_offset_x	_sep	@	80	., nomemory	///
	tooltip("X offset") dropdown				///
	contents(.__SEM_STYLES_LABEL.pointsize)			///
	values(.__SEM_STYLES.pointsize)
  COMBOBOX cb_offset_y	+85	@	80	., nomemory	///
	tooltip("Y offset") dropdown				///
	contents(.__SEM_STYLES_LABEL.pointsize)			///
	values(.__SEM_STYLES.pointsize)
  TEXT     tx_offset_m	+85	@	50	.,		///
	label("( pt. )")

  TEXT     tx_fmt	_ilft	_mls	_wd	.,		///
  	label("Format:") right
  EDIT     ed_fmt	_sep	@	165	., nomemory	///
	option(format)
  BUTTON   bu_fmt	+170	@	20	.,		///
	label("...") onpush(script main_GetFormat)		///
	tooltip("Create display format")

  GROUPBOX gb_font	_lft	+45	_iwd	_ht10h,		///
	label("Font")
  TEXT     tx_fsize	_ilft	_ss	_wd	.,		///
	label("Size:") right
  COMBOBOX cb_fsize	_sep	@	80	., nomemory	///
	dropdown contents(.__SEM_STYLES_LABEL.pointsize)	///
	values(.__SEM_STYLES.pointsize)
  TEXT     tx_fsize_m	+85	@	50	.,		///
	label("( pt. )")

  TEXT     tx_fcolor	_ilft	_mls	_wd	.,		///
	label("Font color:") right
  COMBOBOX cb_fcolor	_sep	@	_cbwd	., nomemory	///
	dropdown contents(.__SEM_STYLES_LABEL.color)		///
	values(.__SEM_STYLES.color)

  TEXT     tx_fface	_ilft	_mls	_wd	.,		///
	label("Font face:") right
  COMBOBOX cb_fface	_sep	@	_cbwd	., nomemory	///
	dropdown contents(.__SEM_STYLES_LABEL.face)		///
	values(.__SEM_STYLES.face)

  CHECKBOX ck_bold	@	_mls	60	., nomemory	///
	label("Bold") 
  CHECKBOX ck_italic	+65	@	_wd	., nomemory	///
	label("Italic") 
END

SCRIPT main_GetFormat
BEGIN
	create STRING mainFormat
	create CHILD format_chooser
	format_chooser.setExitString mainFormat
	format_chooser.setExitAction "main.ed_fmt.setvalue class mainFormat.value"
END

PROGRAM main_output
BEGIN
	call program main_get_defaults

	call create STRING sMainTmp
	if (sSrcType.iseq("edgestyle")) {
		call sMainTmp.setvalue "SetStyleSelected"
	}
	else { 
		call sMainTmp.setvalue "SetStyle"
	}

	if (!main.ck_tangent.isdefault()) {
		call sg__PARAM2.setvalue class sMainTmp.value
		call sg__ARG_00.setvalue class sSrcResOut.value
		call sg__ARG_00.append ".tangent"
		if main.ck_tangent {
			call sg__ARG_01.setvalue "yes"
		}
		else {
			call sg__ARG_01.setvalue "no"
		}
		put /program sg__do_output_sub
	}

	if (! main.cb_distance.isdefault()) {
		call sg__PARAM2.setvalue class sMainTmp.value
		call sg__ARG_00.setvalue class sSrcResOut.value
		call sg__ARG_00.append ".loc"
		call sg__ARG_01.setvalue class main.cb_distance.value
		put /program sg__do_output_sub
	}

	if (! main.cb_position.isdefault()) {
		call sg__PARAM2.setvalue class sMainTmp.value
		call sg__ARG_00.setvalue class sSrcResOut.value
		call sg__ARG_00.append ".relpos"
		call sg__ARG_01.setvalue class main.cb_position.value
		put /program sg__do_output_sub
	}

	if (! main.cb_gap.isdefault()) {
		call sg__PARAM2.setvalue class sMainTmp.value
		call sg__ARG_00.setvalue class sSrcResOut.value
		call sg__ARG_00.append ".gap"
		call sg__ARG_01.setvalue class main.cb_gap.value
		put /program sg__do_output_sub
	}

	if (!main.cb_offset_x.isdefault()) {
		call sg__PARAM2.setvalue class sMainTmp.value
		call sg__ARG_00.setvalue class sSrcResOut.value
		call sg__ARG_00.append ".xoffset"
		call sg__ARG_01.setvalue class main.cb_offset_x.value
		put /program sg__do_output_sub
	}
	if (!main.cb_offset_y.isdefault()) {
		call sg__PARAM2.setvalue class sMainTmp.value
		call sg__ARG_00.setvalue class sSrcResOut.value
		call sg__ARG_00.append ".yoffset"
		call sg__ARG_01.setvalue class main.cb_offset_y.value
		put /program sg__do_output_sub
	}

	if (!main.ed_fmt.isdefault()) {
		call sg__PARAM2.setvalue class sMainTmp.value
		call sg__ARG_00.setvalue class sSrcResOut.value
		call sg__ARG_00.append ".fmt"
		call sg__ARG_01.setvalue class main.ed_fmt.value
		put /program sg__do_output_sub
	}

	if (!main.cb_fsize.isdefault()) {
		call sg__PARAM2.setvalue class sMainTmp.value
		call sg__ARG_00.setvalue class sSrcResOut.value
		call sg__ARG_00.append ".size"
		call sg__ARG_01.setvalue class main.cb_fsize.value
		put /program sg__do_output_sub
	}

	if (!main.cb_fcolor.isdefault()) {
		call sg__PARAM2.setvalue class sMainTmp.value
		call sg__ARG_00.setvalue class sSrcResOut.value
		call sg__ARG_00.append ".color"
		call sg__ARG_01.setvalue class main.cb_fcolor.value
		put /program sg__do_output_sub
	}

	if (!main.cb_fface.isdefault()) {
		call sg__PARAM2.setvalue class sMainTmp.value
		call sg__ARG_00.setvalue class sSrcResOut.value
		call sg__ARG_00.append ".face"
		call sg__ARG_01.setvalue class main.cb_fface.value
		put /program sg__do_output_sub
	}

	if (!main.ck_bold.isdefault()) {
		call sg__PARAM2.setvalue class sMainTmp.value
		call sg__ARG_00.setvalue class sSrcResOut.value
		call sg__ARG_00.append ".bold"
		if main.ck_bold {
			call sg__ARG_01.setvalue "yes"
		}
		else {
			call sg__ARG_01.setvalue "no"
		}
		put /program sg__do_output_sub
	}

	if (!main.ck_italic.isdefault()) {
		call sg__PARAM2.setvalue class sMainTmp.value
		call sg__ARG_00.setvalue class sSrcResOut.value
		call sg__ARG_00.append ".italic"
		if main.ck_italic {
			call sg__ARG_01.setvalue "yes"
		}
		else {
			call sg__ARG_01.setvalue "no"
		}
		put /program sg__do_output_sub
	}
END

/*****************************************************************************/

PROGRAM command
BEGIN
	call sg__PARAM1.setvalue class OBJ.value
	
	call sg__PARAM2.setvalue "BeginSet"
	call sg__DESCPT.setvalue "change connection results' appearance"
	put /program sg__do_output_sub
	
	put /program main_output

	call sg__PARAM2.setvalue "EndSet"
	call sg__DESCPT.setvalue "change connection results' appearance"
	put /program sg__do_output_sub
END
