/*
    gr_ed_contour.idlg
    
*!  VERSION 1.0.1  05jun2011

*/


SCRIPT contour_PREINIT
BEGIN
	create DOUBLE index

	create STRING crule

	create STRING b_color
	create STRING b_rgb
	create STRING userbcolor
	
	create STRING e_color
	create STRING e_rgb
	create STRING userecolor
	
	create DOUBLE drawview
END

SCRIPT contour_POSTINIT
BEGIN
	contour.ck_hide.show
	
	program contour_get_defaults
	program contour_initialize_controls
END

LIST contour_cl_bclr_sel
BEGIN
	contour.cl_bclr.show
	contour.cl_bclr.hide
END

LIST contour_cl_eclr_sel
BEGIN
	contour.cl_eclr.show
	contour.cl_eclr.hide
END

PROGRAM contour_check_rule
BEGIN
	if contour.cb_crule.iseq("intensity") {
		call contour.tx_bclr.disable
		call contour.cb_bclr.disable
		call contour.cl_bclr.disable
	}
	else {
		call contour.tx_bclr.enable
		call contour.cb_bclr.enable
		call contour.cl_bclr.enable
	}
END

DIALOG contour
BEGIN
  GROUPBOX gb_colors	_lft	_top	_iwd	_ht8h,		///
	label("Color properties")

  TEXT     tx_crule	_ilft	_ss	_wd	.,		///
	label("Color rule:") right
  COMBOBOX cb_crule	_sep	@	_cbwd	.,		///
	dropdownlist 						///
	contents(_zyx2rule)					///
	onselchange(program contour_check_rule)

  TEXT     tx_bclr	_ilft	_mls	_wd	.,		///
	label("Start color:") right
  COMBOBOX cb_bclr	_sep	@	_cbwd	.,		///
	dropdownlist contents(_colors) 				///
	onselchangelist(contour_cl_bclr_sel)
  COLOR    cl_bclr	_cbsep	@	_clwd	.,

  TEXT     tx_eclr	_ilft	_mls	_wd	.,		///
	label("End color:") right
  COMBOBOX cb_eclr	_sep	@	_cbwd	.,		///
	dropdownlist contents(_colors) 				///
	onselchangelist(contour_cl_eclr_sel)
  COLOR    cl_eclr	_cbsep	@	_clwd	.,


  CHECKBOX ck_hide	_lft	_xxls	_rj80	.,		///
	label("Hide plot")
END

PROGRAM contour_get_defaults
BEGIN
	call G.withvalue index.setvalue class @.style.rule.styledex
	call index.withvalue crule.setvalue class .__STYLES.zyx2rule[@]
	call contour.cb_crule.setdefault class crule.value

	call G.withvalue index.setvalue class @.style.bshade.color.styledex
	
	if (index) {
		call index.withvalue b_color.setvalue class .__STYLES.color[@]
		call contour.cb_bclr.setdefault class b_color.value
	}

	call G.withvalue b_rgb.setvalue class @.style.bshade.color.rgb
	call contour.cl_bclr.setdefault class b_rgb.value

	call G.withvalue userbcolor.setvalue class @.style.userbcolor	
	if(userbcolor) {
		call G.withvalue b_color.setvalue class @.style.bcolor[@]
		call G.withvalue b_rgb.setvalue class @.style.bcolor.rgb
		call contour.cl_bclr.setdefault class b_rgb.value	
	}

	call G.withvalue index.setvalue class @.style.eshade.color.styledex
	if (index) {
		call index.withvalue e_color.setvalue class .__STYLES.color[@]
		call contour.cb_eclr.setdefault class e_color.value
	}

	call G.withvalue e_rgb.setvalue class @.style.eshade.color.rgb
	call contour.cl_eclr.setdefault class e_rgb.value

	call G.withvalue userecolor.setvalue class @.style.userecolor	
	if(userecolor) {
		call G.withvalue e_color.setvalue class @.style.ecolor[@]
		call G.withvalue e_rgb.setvalue class @.style.ecolor.rgb
		call contour.cl_eclr.setdefault class e_rgb.value	
	}

	call G.withvalue drawview.setvalue class @.draw_view.istrue
	if drawview {
		call contour.ck_hide.setdefault 0
	}
	else {
		call contour.ck_hide.setdefault 1
	}
END

PROGRAM contour_initialize_controls
BEGIN
	call contour.cb_crule.setvalue class crule.value

	if b_color {
		call contour.cb_bclr.setvalue class b_color.value
	}
	if ! b_color {
		call contour.cb_bclr.setvalue "custom"
	}
	call contour.cl_bclr.setvalue class b_rgb.value

	if e_color {
		call contour.cb_eclr.setvalue class e_color.value
	}
	if ! e_color {
		call contour.cb_eclr.setvalue "custom"
	}
	call contour.cl_eclr.setvalue class e_rgb.value

	if drawview {
		call contour.ck_hide.setoff
	}
	else {
		call contour.ck_hide.seton
	}
END

PROGRAM contour_output
BEGIN 
	call program contour_get_defaults

	if ! contour.cl_bclr.isvisible() & ! contour.cb_bclr.isdefault() {
		put "set(bcolor " 
		put contour.cb_bclr 
		put ") "
		put "set(userbcolor " `"""'
		put "yes"
		put `"""'
		put ") "
	}
	if contour.cl_bclr.isvisible() & ! contour.cl_bclr.isdefault() {
		put "set(bcolor "  `"""'
		put contour.cl_bclr
		put `"""'
		put ") "
		put "set(userbcolor " `"""'
		put "yes"
		put `"""'
		put ") "
	}

	if ! contour.cl_eclr.isvisible() & ! contour.cb_eclr.isdefault() {
		put "set(ecolor " 
		put contour.cb_eclr 
		put ") "
		put "set(userecolor " `"""'
		put "yes"
		put `"""'
		put ") "
	}
	if contour.cl_eclr.isvisible() & ! contour.cl_eclr.isdefault() {
		put "set(ecolor "  `"""'
		put contour.cl_eclr
		put `"""'
		put ") "
		put "set(userecolor " `"""'
		put "yes"
		put `"""'
		put ") "
	}

	if ! contour.cb_crule.isdefault() {
		put "set(rule " 
		put contour.cb_crule
		put ") "
	}
END

PROGRAM contour_hide_output
BEGIN
	if ! contour.ck_hide.isdefault() & contour.ck_hide.isvisible() {
		if contour.ck_hide {
			put "set(draw_view no) "
		}
		else {
			put "set(draw_view yes) "
		}
	}
END
