#include <origin.h>
#include <GetNBox.h>
#include <xfutils.h>
enum{
	mode_auto,
	mode_concat,
	mode_global,
	mode_cons,
};
enum{
	pnotation_para,
	pnotation_abbr,
	pnotation_both,
};
enum{
	init_auto,
	init_enable,
	init_disable,
};
enum{
	weight_none,
	weight_ins,
	weight_stat,
};
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> //CPY 5/1/08 op_utils.c compile err in nlbegin after Hong 01/29/08 QA80-10929 LT_NL_ALLOW_UPDATE_PARAMS_BY_DIALOG
///---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>
///===================end of include headers=============================

/*------------------------------------------------------------------------------*
 * Modification Log:															*
 * 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
 *	Folger 03/11/09 QA80-13253 NLFIT_LT_COMMAND_SUPPORT_SPECIFY_WEIGHT_METHOD	*
 *	Sophy 8/5/2009 QA80-14072 SUPPORT_CHANGE_INPUTDATA_IN_NLFIT_FROM_LABTALK	*
 *------------------------------------------------------------------------------*/


void nlbegin(const XYRange& iy, const string& func, TreeNode& nltree, const int& mode, const int& replica, const string& theme, const int& pnotation, const int& init, const int& weight, const int& option)
{
	
	LPCSTR lpcstr = NULL;
	if ( theme && !theme.IsEmpty() )
		lpcstr = theme;		
	
	//---- Iris 10/10/2008 ADD_XFVAR_TO_CONTROL_IF_AUTO_INIT_PARAM	
	//lt_nlf_nlbegin(iy, func, nltree, mode, replica, lpcstr, pnotation);
	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
	// Hong, this fix will NOT fix the runtime error above, instead give info of error, so user will know he it's NOT able to call NLFit before correct this error
	//lt_nlf_nlbegin(iy, func, nltree, mode, replica, lpcstr, pnotation, NLFIT_GENERAL_XY_FITTING, pbAutoInit);
	///------ Folger 03/11/09 QA80-13253 NLFIT_LT_COMMAND_SUPPORT_SPECIFY_WEIGHT_METHOD
	//int		nErr = lt_nlf_nlbegin(iy, func, nltree, mode, replica, lpcstr, pnotation, NLFIT_GENERAL_XY_FITTING, pbAutoInit);
	///Sophy 8/5/2009 QA80-14072 SUPPORT_CHANGE_INPUTDATA_IN_NLFIT_FROM_LABTALK
	//int		nErr = lt_nlf_nlbegin(iy, func, nltree, mode, replica, lpcstr, pnotation, NLFIT_GENERAL_XY_FITTING, pbAutoInit, weight <= 0 ? 0 : weight);
	int		nErr = OP_NOERROR;
	if ( option == NLFIT_CHANGE_DATA )
		nErr = lt_nlf_change_inputdata(iy);
	else
		nErr = lt_nlf_nlbegin(iy, func, nltree, mode, replica, lpcstr, pnotation, NLFIT_GENERAL_XY_FITTING, pbAutoInit, weight <= 0 ? 0 : weight);
	///end SUPPORT_CHANGE_INPUTDATA_IN_NLFIT_FROM_LABTALK
	///------ End NLFIT_LT_COMMAND_SUPPORT_SPECIFY_WEIGHT_METHOD
	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
	//----
	
	//lt_cf_nlbegin(iy, func, nltree, mode, replica, lpcstr, pnotation);	
	/// end FIX_LTNL_USING_DEFAULT_THEME_IF_NOT_SPECIFIED
	///end SUPPORT_XYZ_INPUT
	
}

//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 nlbegin_event1(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	if( xf_is_extended_event(nEventID) )
		return nlbegin_event1_ex(trGetN, nRow, nEventID, dwEnables, lpcszNodeName, DynaCntrlContainer, strAux, strErrMsg);
	DECLARE_BUTTON_ENABLES
	return false;

}

int nlbegin_make_tree(TreeNode& tr, LPCSTR lpcszVarName)
{
	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 nlbegin_before_execute(TreeNode& trGetN, int nGetNDialog, int& nRet, int dwCntrl)
{

}
//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 nlbegin_event1_ex(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	return false;
}
