#include <origin.h>
#include <GetNBox.h>
#include <xfutils.h>
#include <..\originlab\grobj_utils.h>
#include <..\originlab\GraphObjTools.h>
#include <..\Originlab\XFunctionEx.h>

#include <stats_utils.h>
#include <..\originlab\nlsf_utils.h> 
#include <..\originlab\graph_utils.h>
#include <..\originlab\QuickFit.h>
#include <oUtils.h>
#include <o8dlg.h>

/*------------------------------------------------------------------------------*
 * Modification Log:															*
 *	Folger 01/21/10 QA81-14903 QUICKFIT_SAVE_THEME_WITHOUT_ROI					*
 *	Kyle 01/27/2010 CHANGE_PARAMETER_TABLE_DESIGN_IN_TABLE_AND_REPORT_TAB		*
 *	Hong 01/28/10 QA80-14995-P2 FIX_OUTPUT_TO_WKS_FAIL_ALL_PUT_TO_ONE_SHEET_IF_NOT_VALID_SHORT_NAME
 *	Folger 02/02/10 QUICKFIT_SUPPORT_WITHOUT_ROI_BOX_WITH_CNTRL_KEY_DOWN		*
 *	Kenny 2/4/2010 QA81-14832-P3 QUICK_FIT_IMPROVE_ROI_TOP_RELATED_GUI			*
 *	Folger 02/04/10 SUPPORT_LOAD_THEME_IN_ROI_TOOLS_CONTEXT_MENU				*
 *	Sim 02-20-2010 QA81-14832-P3 SUPPORT_MULTI_SEL_CHECKBOX_FOR_SHOW_TOP_ROI_BOX*
 *  Iris 2/25/2010 TO_PREVENT_MOVE_ROI_WHEN_LOAD_THEME							*
 *	Sophy 3/1/2010 GET_FITCURVE_COLOR_FROM_THEME_FILE_WHNE_NO_ROI				*
 *  Iris 3/01/2010 TO_PREVENT_LOCALIZE_NLFIT_FUNCTION_LIST						*
 *	Kenny 3/4/2010 QA81-14832 QUICK_FIT_WRONG_AUTO_PREVIEW_FITTED_CURVE_COLOR	*
 *	Folger 04/09/10 QA81-15992 QUICK_FIT_OUTPUT_REPORT_INCLUDE_NUMBER_ITERATION_AND_FIT_STATUS
 *------------------------------------------------------------------------------*/
 
static bool _check_if_active_plot_valid() 
{
	GraphLayer gl = Project.ActiveLayer();
	if(!gl)
		return false;
	
	DataPlot dp = gl.DataPlots();
	if(!dp)
		return false;
	
	return okutil_is_good_plot_type_for_analysis(dp.GetPlotType(), true, false);
}

static void _update_function_list(TreeNode& trGetN, bool bFromBtn = false)
{
	quickfit_update_function_list(trGetN);
}


///------ Folger 01/21/10 QA81-14903 QUICKFIT_SAVE_THEME_WITHOUT_ROI
static	BOOL	_quick_fit_without_roi(LPCSTR lpcszFile, string* pstrTheme)
{
	static	BOOL	l_bNoROI = FALSE;
	static	string	l_strTheme;
	
	if ( lpcszFile )
	{
		if ( '\0' == *lpcszFile )
		{
			l_bNoROI = FALSE;
			l_strTheme.Empty();
		}
		else
		{
			l_strTheme = okutil_theme_get_theme_name(lpcszFile);
			///------ Folger 02/02/10 QUICKFIT_SUPPORT_WITHOUT_ROI_BOX_WITH_CNTRL_KEY_DOWN
			//int		nIndex = -1;
			//l_bNoROI = (nIndex = l_strTheme.Find(STR_NO_ROI_SPECIFIER)) > 0 && nIndex + lstrlen(STR_NO_ROI_SPECIFIER) == l_strTheme.GetLength();
			l_bNoROI = CNTRL_DOWN;
			///------ End QUICKFIT_SUPPORT_WITHOUT_ROI_BOX_WITH_CNTRL_KEY_DOWN
		}
	}
	
	if ( pstrTheme )
		*pstrTheme = l_strTheme;
	return l_bNoROI;
}
///------ End QUICKFIT_SAVE_THEME_WITHOUT_ROI




void addtool_quickfit(const int& mode, const string& func, const int& btn_edit, const TreeNode& trtable, const TreeNode& trreport, const TreeNode& trcurve, const TreeNode& trroi)
{
	if( !_check_if_active_plot_valid() )
		XF_THROW(CER_INVALID_RANGE);	
	
	Tree tr;
	quick_fit_get_preference_settings(tr); 
	
	int nBranchDataID = XF_TREENODE_VAR_ID_TABLE; 
	quick_fit_check_convert_data_id_based_on_xf_treenode_var_id(trtable, nBranchDataID);
	
	nBranchDataID = XF_TREENODE_VAR_ID_REPORT;
	quick_fit_check_convert_data_id_based_on_xf_treenode_var_id(trreport, nBranchDataID);		
	
	nBranchDataID = XF_TREENODE_VAR_ID_FITCURVE;
	quick_fit_check_convert_data_id_based_on_xf_treenode_var_id(trcurve, nBranchDataID);		
	
	nBranchDataID = XF_TREENODE_VAR_ID_ROI;
	quick_fit_check_convert_data_id_based_on_xf_treenode_var_id(trroi, nBranchDataID);		
	
	tree_copy_values_by_id(trtable, tr.Table);
	tree_copy_values_by_id(trreport, tr.Report);		
	tree_copy_values_by_id(trcurve, tr.FitCurve);				
	tree_copy_values_by_id(trroi, tr.ROI);
	
	/// Kenny 2/5/2010 QA81-14832-P3 QUICK_FIT_IMPROVE_ROI_TOP_RELATED_GUI
	TreeNode trDestROI = tr.ROI;
	octree_copy_atts_by_id(&trroi, &trDestROI, STR_COMBO_ATTRIB);
	/// End QUICK_FIT_IMPROVE_ROI_TOP_RELATED_GUI
	
	/// Iris 2/25/2010 TO_PREVENT_MOVE_ROI_WHEN_LOAD_THEME
	TreeNode trSourceXScale = trroi.XScale;
	TreeNode trDestXScale = tr.ROI.XScale;
	octree_copy_atts(&trSourceXScale, &trDestXScale, STR_FORCE_APPLY_ROI_X_POS_ATTRIB);
	///End TO_PREVENT_MOVE_ROI_WHEN_LOAD_THEME
	
	///Sophy 1/28/2010 SMART_DIFF_STATS_BETWEEN_POLYFIT_AND_NLFIT
	#define	TSHOW(_Node)	tr.Table._Node.Show = trtable._Node.Show
	TSHOW(AdjR);
	TSHOW(RSqr);
	TSHOW(Correlation);
	#define	RSHOW(_Node)	tr.Report._Node.Show = trreport._Node.Show
	RSHOW(AdjR);
	RSHOW(RSqr);
	RSHOW(Correlation);
	///end SMART_DIFF_STATS_BETWEEN_POLYFIT_AND_NLFIT
	
	///------ Folger 04/09/10 QA81-15992 QUICK_FIT_OUTPUT_REPORT_INCLUDE_NUMBER_ITERATION_AND_FIT_STATUS
	//RSHOW(NumIter);
	//RSHOW(FitStatus);
	///------ End QUICK_FIT_OUTPUT_REPORT_INCLUDE_NUMBER_ITERATION_AND_FIT_STATUS
	
	///---Sim 02-20-2010 QA81-14832-P3 SUPPORT_MULTI_SEL_CHECKBOX_FOR_SHOW_TOP_ROI_BOX
	#define	ROISHOW(_Node)	tr.ROI.ShowTop._Node.Show = trroi.ShowTop._Node.Show
	ROISHOW(AdjR);
	ROISHOW(RSqr);
	ROISHOW(Correlation);
	///---END QA81-14832-P3 SUPPORT_MULTI_SEL_CHECKBOX_FOR_SHOW_TOP_ROI_BOX
	
	tr.func.strVal = func;	
	tr.mode.nVal = mode;
	
	///------ Folger 01/21/10 QA81-14903 QUICKFIT_SAVE_THEME_WITHOUT_ROI
	string		strTheme;
	if ( _quick_fit_without_roi(NULL, &strTheme) )
	{
		string	strLT;
		int		nOrder = quick_fit_get_order(mode, func);
		///Sophy 3/1/2010 UPDATE_SETTINGS_FROM_THEME_FILE_WHNE_NO_ROI
		int nColor = trroi.FitLineColor.nVal;
		if ( INDEX_COLOR_AUTOMATIC == nColor )
		{
			if ( !trroi.FitLineColor.GetAttribute(STR_ATTRIB_AUTO_COLOR, nColor) )
				nColor = SYSCOLOR_BLUE;
			/// Kenny 03/04/2010 QA81-14832 QUICK_FIT_WRONG_AUTO_PREVIEW_FITTED_CURVE_COLOR
			//GraphLayer gl = Project.ActiveLayer();
			//DataPlot dpSrc;
			//if ( gl && (dpSrc = gl.DataPlots()) )
			//{
				//if ( get_plot_color(dpSrc) == nColor )
					//nColor++;
			//}
			nColor = quickfit_get_fit_line_auto_color(nColor);
			/// End QA81-14832 QUICK_FIT_WRONG_AUTO_PREVIEW_FITTED_CURVE_COLOR
		}
		string strOutputRange = get_output_range_str(trcurve.OutputFitCurveTo.nVal);
		///end UPDATE_SETTINGS_FROM_THEME_FILE_WHNE_NO_ROI
		strLT.Format("quickfit func:=\"%s\" order:=%d color:=%d replace:=0 oy:=%s;", 0 == nOrder ? func : "", nOrder, nColor, strOutputRange);
		QuickFitNoROIThemeSwtichHelper		clHelper(strTheme);
		LT_execute(strLT);
	}
	else
	///------ End QUICKFIT_SAVE_THEME_WITHOUT_ROI
	{
		///Sophy 2/10/2010 QA81-15097 ROI_TOOLS_DONT_WORK_WHEN_XY_AXIS_EXCHANGED
		//!!! when #15102 fixed, should remove this code to allow quick fit on X-Y Axes exchanged graph
		if ( is_active_graphlayer_xyexchanged() )
		{
			LT_execute("type -a");
			out_str(_L("Quick Fit Gadget doesn't work on graph with X-Y Axes exchanged!"));
			return;
		}
		///end ROI_TOOLS_DONT_WORK_WHEN_XY_AXIS_EXCHANGED
		AddToolQuickFit(tr);
	}
	
}

//nEventID < 0 on event, like GETNE_ON_INIT, GETNE_ON_OK etc, >0 on change from control
//return 0 to do nothing, return PEVENT_GETN_RET_TO_CLOSE to close dialog
//dwEnables = bOKEnable, bBTN1Enable, bBTN2Enable, bBTN3Enable, , can set to false to disable OK/Apply buttons
//lpcszNodeName = the trGetN TreeNode tag name that generates the event, or is  if GETNE_ON_OK etc
//strAux = optional string for XF Wizard Bar, like DLG_NEED_CHANGE_GRID etc, it will be invalid if from internal node value change event
//strErrMsg = allowing messages to be shown
int addtool_quickfit_event1(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	if( xf_is_extended_event(nEventID) )
		return addtool_quickfit_event1_ex(trGetN, nRow, nEventID, dwEnables, lpcszNodeName, DynaCntrlContainer, strAux, strErrMsg);
	DECLARE_BUTTON_ENABLES
	 
	trGetN.trreport.WksName.Show = OUTPUT_TO_WORKSHEET == trGetN.trreport.OutputTo.nVal;
		
	/// Iris 1/15/2010 NEW_QUICKFIT_ROI_XF_DLG
	if( GETNE_ON_INIT == nEventID || GETNE_ON_THEME == nEventID || 0 == lstrcmpi(lpcszNodeName, "mode"))
	{	
		_update_function_list(trGetN);
		
		/// Kenny 2/8/2010 QA81-14832-P3 QUICK_FIT_IMPROVE_ROI_TOP_RELATED_GUI
		quickfit_update_on_mode_function_change(trGetN, QFROI_UPDATESHOWTOP_SEL_IGNORE);
		/// End QUICK_FIT_IMPROVE_ROI_TOP_RELATED_GUI
	} 
	///Kyle 01/22/2010 SHOW_ALL_PARAMETERS_AS_CHECK_LIST
	/// Hong 01/28/10 QA80-14995-P2 FIX_OUTPUT_TO_WKS_FAIL_ALL_PUT_TO_ONE_SHEET_IF_NOT_VALID_SHORT_NAME
	if ( GETNE_ON_INIT == nEventID || GETNE_ON_THEME == nEventID || 0 == lstrcmpi(lpcszNodeName, "WksName") )
	{
		///Sophy 1/29/2010 QA80-14995-P2 CHECK_UPDATE_REPORT_WORKSHEET_NAME_FOR_ROI_TOOLS
		//if ( !check_report_wks_name(trGetN.trreport) )
			//strErrMsg = CER_SHEET_NAME_ILLEGAL_CHAR;
		string strBookSheetName = trGetN.trreport.WksName.strVal;
		if ( !check_update_worksheet_name(strBookSheetName) )
		{
			trGetN.trreport.WksName.strVal = strBookSheetName; //update report book sheet name
			strErrMsg = CER_SHEET_NAME_ILLEGAL_CHAR;
		}		
		///end CHECK_UPDATE_REPORT_WORKSHEET_NAME_FOR_ROI_TOOLS
	}
	/// end FIX_OUTPUT_TO_WKS_FAIL_ALL_PUT_TO_ONE_SHEET_IF_NOT_VALID_SHORT_NAME
	
	/// Kenny 2/5/2010 QA81-14832-P3 QUICK_FIT_IMPROVE_ROI_TOP_RELATED_GUI
	bool bNeedToUpdateRoiParamList = false;
	/// End QUICK_FIT_IMPROVE_ROI_TOP_RELATED_GUI
	
	if( GETNE_ON_INIT == nEventID || GETNE_ON_THEME == nEventID 
		|| 0 == lstrcmpi(lpcszNodeName, "func") 
		|| 0 == lstrcmpi(lpcszNodeName, "mode") )
	{
		///------ Folger 02/04/10 SUPPORT_LOAD_THEME_IN_ROI_TOOLS_CONTEXT_MENU
		//_quick_fit_update_param_list(trGetN);
		/////Sophy 1/28/2010 SMART_DIFF_STATS_BETWEEN_POLYFIT_AND_NLFIT
		//quick_fit_update_output_choice_on_mode_change(trGetN, trGetN.trtable);
		//quick_fit_update_output_choice_on_mode_change(trGetN, trGetN.trreport);
		/////end SMART_DIFF_STATS_BETWEEN_POLYFIT_AND_NLFIT
		if ( 0 == lstrcmpi(lpcszNodeName, "func") )
		{
			quickfit_on_func_change(trGetN, DynaCntrlContainer);
		}
		quickfit_update_on_mode_function_change(trGetN);
		///------ End SUPPORT_LOAD_THEME_IN_ROI_TOOLS_CONTEXT_MENU
		
		/// Kenny 2/5/2010 QA81-14832-P3 QUICK_FIT_IMPROVE_ROI_TOP_RELATED_GUI
		// In case the above invoke cause the show top selection change.
		bNeedToUpdateRoiParamList = true;
		/// End QUICK_FIT_IMPROVE_ROI_TOP_RELATED_GUI
	}
	
	/// Kenny 2/5/2010 QA81-14832-P3 QUICK_FIT_IMPROVE_ROI_TOP_RELATED_GUI
	//if( 0 == lstrcmpi(lpcszNodeName, "ShowTop") )
	//{
		//trGetN.trroi.Params.Show = ROI_TOP_SHOW_PARAM == trGetN.trroi.ShowTop.nVal;
	//}
	if( bNeedToUpdateRoiParamList || 0 == lstrcmpi(lpcszNodeName, "ShowTop") )
	{
		///---Sim 02-20-2010 QA81-14832-P3 SUPPORT_MULTI_SEL_CHECKBOX_FOR_SHOW_TOP_ROI_BOX
		//int nShowTop = quick_fit_get_roi_show_top_enum(trGetN.trroi.ShowTop);
		//trGetN.trroi.Params.Show = ROI_TOP_SHOW_PARAM == nShowTop;
		trGetN.trroi.Params.Show = true;
		///---END QA81-14832-P3 SUPPORT_MULTI_SEL_CHECKBOX_FOR_SHOW_TOP_ROI_BOX
	}
	/// End QUICK_FIT_IMPROVE_ROI_TOP_RELATED_GUI
	
	///End SHOW_ALL_PARAMETERS_AS_CHECK_LIST
	///Kyle 01/27/2010 CHANGE_PARAMETER_TABLE_DESIGN_IN_TABLE_AND_REPORT_TAB
	else if( 0 == lstrcmpi(lpcszNodeName, "Params") )
	{
		trGetN.trreport.ShowError.Show = PARAMETER_TABLE_NONE != trGetN.trreport.Params.nVal;
		trGetN.trtable.ShowError.Show = PARAMETER_TABLE_NONE != trGetN.trtable.Params.nVal;
	}
	///End CHANGE_PARAMETER_TABLE_DESIGN_IN_TABLE_AND_REPORT_TAB	
	
	
	/// Iris 2/01/2010 NEED_DISPLAY_SOURCE_DATA_POINTS_WHEN_CHOOSE_SAVE_AS_INPUT_DATA_IN_XF_DLG
	if(GETNE_ON_INIT == nEventID || GETNE_ON_THEME == nEventID || 0 == lstrcmpi(lpcszNodeName, "FitCurve"))
	{
		bool bSameAsInput = FIT_CURVE_TYPE_SAME_AS_INPUT == trGetN.trcurve.FitCurve.nVal;
		///Sophy 3/1/2010 UPDATE_FITCURVE_SETTINGS_IN_QUICKFIT_PREFERENCE_DLG as to Max's suggestion, we should just hide it
		//trGetN.trcurve.NumPoints.Enable = !bSameAsInput;
		trGetN.trcurve.NumPoints.Show = !bSameAsInput;
		///end UPDATE_FITCURVE_SETTINGS_IN_QUICKFIT_PREFERENCE_DLG
		if( bSameAsInput )
		{
			int nNumPoints;
			quick_fit_get_source_from_to(NULL, NULL, &nNumPoints);
			trGetN.trcurve.NumPoints.nVal = nNumPoints;
		}
	}
	///End NEED_DISPLAY_SOURCE_DATA_POINTS_WHEN_CHOOSE_SAVE_AS_INPUT_DATA_IN_XF_DLG
	
	/// Iris 2/25/2010 TO_PREVENT_MOVE_ROI_WHEN_LOAD_THEME
	if( 0 == lstrcmpi(lpcszNodeName, "leftx") || 0 == lstrcmpi(lpcszNodeName, "rightx") )
	{
		trGetN.trroi.XScale.SetAttribute(STR_FORCE_APPLY_ROI_X_POS_ATTRIB, 1);
	}
	
	if( GETNE_ON_THEME == nEventID )
	{
		trGetN.trroi.XScale.RemoveAttribute(STR_FORCE_APPLY_ROI_X_POS_ATTRIB); 
		quick_fit_check_update_roi_x_position(trGetN.trroi);
	}
	///End TO_PREVENT_MOVE_ROI_WHEN_LOAD_THEME
	return true;

}

int addtool_quickfit_make_tree(TreeNode& tr, LPCSTR lpcszVarName)
{
	
	if( 0 == strcmp(lpcszVarName, "trreport") )
	{
		construct_quick_fit_report_refer_gui(tr); 
	}
	if( 0 == strcmp(lpcszVarName, "trtable") )
	{
		construct_quick_fit_table_prefer_gui(tr); 
	}
	if( 0 == strcmp(lpcszVarName, "trcurve") )
	{
		construct_quick_fit_curve_refer_gui(tr); 
	}	
	if( 0 == strcmp(lpcszVarName, "trroi") )
	{
		construct_quick_fit_roi_refer_gui(tr); 
	}
	
	return false;
}
//nGetNDialog = 0,1,2, corresponding to the XF GetN dropdown, 0 = dialog is not used
//you can change nRet to be one of XFEVT_PROCEED (defualt), XFEVT_ABORT, XFEVT_PROCEED_NO_DLG or XFEVT_PROCEED_WITH_DLG(when nGetNDialog = 0)
//nGetNDialog = -1 when Ok on GetN dialog to allow handler to preocess <auto> etc variables
//dwCntrl is combination of bits
//LTXF_FROM_GUI_MENU, LTXF_FROM_GUI_PROMPT, LTXF_FROM_AUTO_UPDATE, LTXF_FROM_FUNCTION, LTXF_THEME_USED, LTXF_CHANGE_PARAM
void addtool_quickfit_before_execute(TreeNode& trGetN, int nGetNDialog, int& nRet, int dwCntrl)
{
	///------ Folger 01/21/10 QA81-14903 QUICKFIT_SAVE_THEME_WITHOUT_ROI
	if ( 0 == nGetNDialog || -1 == nGetNDialog )
	{
		string	strThemeFile;
		if ( !O_QUERY_BOOL(dwCntrl, LTXF_SHOW_DIALOG) )
		{
			/// Hong 01/28/10 QA80-14995-P2 FIX_OUTPUT_TO_WKS_FAIL_ALL_PUT_TO_ONE_SHEET_IF_NOT_VALID_SHORT_NAME
			///Sophy 1/29/2010 QA80-14995-P2 CHECK_UPDATE_REPORT_WORKSHEET_NAME_FOR_ROI_TOOLS
			//if ( !check_report_wks_name(trGetN.trreport) )
				//dwCntrl |= LTXF_SHOW_DIALOG;
			string strBookSheetName = trGetN.trreport.WksName.strVal;
			if ( !check_update_worksheet_name(strBookSheetName) )
			{
				trGetN.trreport.WksName.strVal = strBookSheetName; //update report book sheet name
				dwCntrl |= LTXF_SHOW_DIALOG;
			}		
			///end CHECK_UPDATE_REPORT_WORKSHEET_NAME_FOR_ROI_TOOLS
			/// end FIX_OUTPUT_TO_WKS_FAIL_ALL_PUT_TO_ONE_SHEET_IF_NOT_VALID_SHORT_NAME
			
			//trGetN.GetAttribute(STR_THEME_FILE_ATTRIB, strThemeFile);
			//
			///// Kenny 2/4/2010 QA81-14832-P3 QUICK_FIT_IMPROVE_ROI_TOP_RELATED_GUI
			//quick_fit_update_roi_show_top(trGetN, ROI_TOP_SHOW_PARAM);
			///// End QA81-14832-P3 QUICK_FIT_IMPROVE_ROI_TOP_RELATED_GUI
			trGetN.GetAttribute(STR_THEME_FILE_ATTRIB, strThemeFile);
			
			quickfit_update_on_mode_function_change(trGetN, QFROI_UPDATESHOWTOP_SEL_IGNORE);
			///------ End SUPPORT_LOAD_THEME_IN_ROI_TOOLS_CONTEXT_MENU
		}
		_quick_fit_without_roi(strThemeFile, NULL);
	}
	///------ End QUICKFIT_SAVE_THEME_WITHOUT_ROI
	
	/// Iris 1/15/2010 NEW_QUICKFIT_ROI_XF_DLG
	// setup edit function list button
	if( nGetNDialog > 0 )// use dialog
	{
		/// Iris 3/01/2010 TO_PREVENT_LOCALIZE_NLFIT_FUNCTION_LIST
		trGetN.func.SetAttribute(STR_OCNTRL_OPTNS, OCNTRLPARAM1_NOT_LOCALIZED);
		///End TO_PREVENT_LOCALIZE_NLFIT_FUNCTION_LIST
		
		TreeNode trBtnEditFunc = trGetN.btn_edit;
		trBtnEditFunc.SetAttribute(STR_LABEL_ATTRIB, "");
		trBtnEditFunc.SetAttribute(STR_ID_ATTRIB, ONODETYPE_PUSHBUTTON_GROUP);
		DWORD dwDisplyBits = DISPLAY_EDITOR_HORZ | DISPLAY_EDITOR_RIGHT;
		trBtnEditFunc.SetAttribute(STR_ATTRIB_DISPFMT, (string)dwDisplyBits);
		trBtnEditFunc.SetAttribute(STR_COMBO_ATTRIB, STR_UPDATE_FUNCTION_LIST);	
		
		///------ Folger 01/21/10 QA81-14903 QUICKFIT_SAVE_THEME_WITHOUT_ROI
		quick_fit_set_attributes(trGetN);
		///------ End QUICKFIT_SAVE_THEME_WITHOUT_ROI
	}
	///End NEW_QUICKFIT_ROI_XF_DLG
	
	/// Kenny 3/4/2010 QA81-14832 QUICK_FIT_WRONG_AUTO_PREVIEW_FITTED_CURVE_COLOR
	int nAutoLineColor = quickfit_get_fit_line_auto_color();
	trGetN.trroi.FitLineColor.SetAttribute(STR_ATTRIB_AUTO_COLOR, nAutoLineColor);
	/// QA81-14832 QUICK_FIT_WRONG_AUTO_PREVIEW_FITTED_CURVE_COLOR
	
	if( is_xf_startup(nGetNDialog, dwCntrl) )
	{
		if(is_use_origin_chm())
			trGetN.SetAttribute(STR_HELPID_ATTRIB, IDD_XF_addtool_quickfit);
		
		/// Iris 2/25/2010 TO_PREVENT_MOVE_ROI_WHEN_LOAD_THEME
		//if( 0 == trGetN.trroi.XScale.fixscale.nVal )
		//	quickfit_get_auto_x_range(trGetN.trroi.XScale.leftx, trGetN.trroi.XScale.rightx);
		quick_fit_check_update_roi_x_position(trGetN.trroi);
		///End TO_PREVENT_MOVE_ROI_WHEN_LOAD_THEME
	}
	
}
//nEventID < 0 on event, like GETNE_ON_INIT, GETNE_ON_OK etc, >0 on change from control
//return 0 to do nothing, return PEVENT_GETN_RET_TO_CLOSE to close dialog
//dwEnables = bOKEnable, bBTN1Enable, bBTN2Enable, bBTN3Enable, , can set to false to disable OK/Apply buttons
//lpcszNodeName = the trGetN TreeNode tag name that generates the event, or is  if GETNE_ON_OK etc
//strAux = optional string for XF Wizard Bar, like DLG_NEED_CHANGE_GRID etc, it will be invalid if from internal node value change event
//strErrMsg = allowing messages to be shown
int addtool_quickfit_event1_ex(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	return false;
}
