#include <origin.h>
#include <GetNBox.h>
#include <xfutils.h>
enum{
	pnotation_para,
	pnotation_abbr,
	pnotation_both,
};
enum{
	init_auto,
	init_enable,
	init_disable,
};
enum{
	option_init_all,
	option_change_data,
};


//put additional include files here
#include <operation.h>
/// Hong 01/22/08 QA80-10929 LTNL_ACCESS_FITSESSION_PONTER
#ifdef _FOR_SMART_LOADING_ONLY
#include <..\originlab\nlsf_utils.h>
#include <xfgraph_utils.h>
///---Sim 09-13-2008 LT_operation.c compile err in nlbegin after ///---Sim 09-10-2008 NLFIT_LABTALK_TREE_ACCESS
#include <..\originlab\wksOperation.h>
#include <stats_utils.h>
#include <..\originlab\stats_guis.h>
#include <event_utils.h>
#include <report_utils.h>
#include <..\originlab\graph_utils.h>
#include <..\originlab\stats_operations.h>
#include <..\originlab\StatsOpBase.h>
#include <FitterOperation.h>
#include <..\originlab\FitNL.h>
///---END
#endif
/// end LTNL_ACCESS_FITSESSION_PONTER
#include <..\originlab\op_utils.h>

///////////////////////////////////////////////////////////////////////
//////// modification log
/// Iris 03/25/08 QA80-11299 FIX_LTNL_USING_DEFAULT_THEME_IF_NOT_SPECIFIED
/// Hong 06/16/08 QA80-11699 FIX_2D_FITTING_FAIL_GENERATE_REPORT
/// Kyle 09/11/08 USE_NEW_STYLE
/// Iris 10/10/2008 ADD_XFVAR_TO_CONTROL_IF_AUTO_INIT_PARAM	
/// Hong 03/10/09 FOLGER_FOUND_RUNTIME_ERR_IF_RUN_NLFIT_WITH_INVALID_FUNCTION_NAME
/// Sophy 8/5/2009 QA80-14072 SUPPORT_CHANGE_INPUTDATA_IN_NLFIT_FROM_LABTALK
///////////////////////////////////////////////////////////////////////



void nlbeginm(const MatrixObject& im, const string& func, TreeNode& nltree, const int& replica, const string& theme, const int& pnotation, const int& init, const int& option)
{
	
	
	/// Iris 03/25/08 QA80-11299 FIX_LTNL_USING_DEFAULT_THEME_IF_NOT_SPECIFIED
	//string strTheme;
	//if(theme)
	//	strTheme = theme;
	//lt_cf_nlbegin(iy, func, nltree, mode, replica, strTheme, pnotation);
	if ( !im )
		XF_THROW(CER_NO_MATRIX);
	
	/// Max 5/29/08 v8.0873 NOT_SUPPORT_REPLICA_FIT_FOR_SR2
	if (replica > 0)
		XF_THROW(_L("Matrix fitting with replica is not supported in current version"));
	///---
	
	LPCSTR lpcstr = NULL;
	if ( theme && !theme.IsEmpty() )
		lpcstr = theme;
	
	MatrixLayer ml;
	im.GetParent(ml);
	
	DataRange	drInput;
	string 		strRng;
	strRng.Format("%s!%d", ml.m_strBookSheet, im.GetIndex()+1);
	drInput.Add("Z", strRng);  
	
	int mode = 0; // matrix fit only supports 1 dataset
	/// Hong 06/16/08 QA80-11699 FIX_2D_FITTING_FAIL_GENERATE_REPORT
	//lt_cf_nlbegin(drInput, func, nltree, mode, replica, lpcstr, pnotation);
	///Kyle 09/11/08 USE_NEW_STYLE
	//lt_cf_nlbegin(drInput, func, nltree, mode, replica, lpcstr, pnotation, NLFIT_MATRIX_FITTING);
	//---- Iris 10/10/2008 ADD_XFVAR_TO_CONTROL_IF_AUTO_INIT_PARAM	
	//lt_nlf_nlbegin(drInput, func, nltree, mode, replica, lpcstr, pnotation, NLFIT_MATRIX_FITTING);
	bool bAutoInit;
	bool* pbAutoInit = NULL;	
	if( init_auto != init )
	{
		bAutoInit = init_enable == init? true : false;
		pbAutoInit = &bAutoInit;
	}
	/// Hong 03/10/09 FOLGER_FOUND_RUNTIME_ERR_IF_RUN_NLFIT_WITH_INVALID_FUNCTION_NAME
	//lt_nlf_nlbegin(drInput, func, nltree, mode, replica, lpcstr, pnotation, NLFIT_MATRIX_FITTING, pbAutoInit);
	///Sophy 8/5/2009 QA80-14072 SUPPORT_CHANGE_INPUTDATA_IN_NLFIT_FROM_LABTALK
	//int		nErr = lt_nlf_nlbegin(drInput, func, nltree, mode, replica, lpcstr, pnotation, NLFIT_MATRIX_FITTING, pbAutoInit);
	int		nErr = OP_NOERROR;
	if ( option == NLFIT_CHANGE_DATA )
		nErr = lt_nlf_change_inputdata(drInput);
	else
		nErr = lt_nlf_nlbegin(drInput, func, nltree, mode, replica, lpcstr, pnotation, NLFIT_MATRIX_FITTING, pbAutoInit);
	///end SUPPORT_CHANGE_INPUTDATA_IN_NLFIT_FROM_LABTALK
	if ( OP_NOERROR != nErr )
		XF_THROW(cvt_op_err_to_nlf_xf_err(nErr));
	/// end FOLGER_FOUND_RUNTIME_ERR_IF_RUN_NLFIT_WITH_INVALID_FUNCTION_NAME
	//----
	
	///End USE_NEW_STYLE
	/// end FIX_2D_FITTING_FAIL_GENERATE_REPORT
	///end FIX_LTNL_USING_DEFAULT_THEME_IF_NOT_SPECIFIED
	
}

//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 nlbeginm_before_execute(TreeNode& trGetN, int nGetNDialog, int& nRet, int dwCntrl)
{

}
