#include <origin.h>
#include <GetNBox.h>
#include <xfutils.h>
enum{
	pnotation_para,
	pnotation_abbr,
	pnotation_both,
};

//put additional include files here
#include <operation.h>

	/// ML 1/30/2008 QA70-10929 NLFIT_CONVERTING_INPUT_DATA_OPER_TREE_TO_LT_TREE


void getnlr(TreeNode& tr, const Worksheet& iw, const int& showall, const int& pnotation)
{
	if( !iw )
		XF_THROW(XFERR_NO_ACTIVE_WKSPG);
	
	/// ML 1/30/2008 QA70-10929 NLFIT_CONVERTING_INPUT_DATA_OPER_TREE_TO_LT_TREE
	/*
	vector<uint> vUIDs;
	if( !iw.FindIncomingOperations(vUIDs) )
		XF_THROW(CER_GET_OPERATION_OBJECT);
	
	//if ( index <= 0 || index > vUIDs.GetSize() )
		//XF_THROW(CER_GET_OPERATION_OBJECT);
	
	Operation &op = (Operation &) Project.GetOperationObject(vUIDs[0]);
	if( !op )
		XF_THROW(CER_GET_OPERATION_OBJECT);
		
	Tree trReport;
	op.GetTree(trReport);
	
	//if( !nlsf_report_sheet_to_LT_tree(trReport, tr) )
	vector<double> vdValue;
	TreeNode trNode = trReport.FitWorkArea.Parameters.Values;
	vdValue = trNode.dVals;
	if( !okutil_operation_tree_to_labtalk_tree(&trReport, &tr, showall ? 0 : NLFIT_PARAMS_CHECK_SHOW) )
		XF_THROW(CER_NLF_CONV_REPORT_TREE_TO_LT_TREE);
	*/
	//////////
	//TreeNode	trSource;
	DWORD		dwOption = 0; ///---Sim 02-01-2007 FIX_CANNOT_ACCESS_WHEN_ONLY_REPORT_TREE
	Tree		treeSource;
	DWORD		dwOperUID = 0;
	vector<uint> vUIDs;
	if( iw.FindIncomingOperations(vUIDs) && 0 < vUIDs.GetSize() )
	{
		Operation &op = (Operation &) Project.GetOperationObject(vUIDs[0]);
		if ( !op )
		{
			//;	// will do below
			XF_THROW(CER_GET_OPERATION_OBJECT);
		}
		else
		{
			op.GetTree(treeSource);
			dwOperUID = op.GetUID(TRUE);
		}
	}
	
	if( 0 == dwOperUID )	// if no operation could be found
	{
		// Try to get just the report tree:
		Tree	trCalc;
		if(!iw.GetReportTree(trCalc, NULL, 0, GRT_TYPE_RESULTS))
			XF_THROW(CER_NLF_CONV_REPORT_TREE_TO_LT_TREE);
		
		treeSource.AddNode(trCalc);		
	}
	
	///---Sim 02-01-2007 FIX_CANNOT_ACCESS_WHEN_ONLY_REPORT_TREE
	dwOption |= NLFIT_ACCESS_CALC_ONLY;
	dwOption |= NLFIT_ACCESS_NO_GUIDATA; ///---Sim 03-15-2008 MORE_ACCESS_NLFIT_REPORT_TREE
	if ( !showall )
		dwOption |= NLFIT_PARAMS_CHECK_SHOW;
	//------ Folger 02/19/08 QA80-10929 OPTIONAL_DWORD_TO_DISPLAY_KEY_AND_NAME
	switch ( pnotation )
	{
	case pnotation_para:
		dwOption |= NLFIT_DISPLAY_NODE_NAME;
		break;
	case pnotation_abbr:
		dwOption |= NLFIT_DISPLAY_NODE_KEY;
		break;
	case pnotation_both:
		dwOption |= NLFIT_DISPLAY_NODE_KEY;
		dwOption |= NLFIT_DISPLAY_NODE_NAME;
		break;
	default:
		break;
	}
	//------
	//if( !okutil_operation_tree_to_labtalk_tree(&treeSource, &tr, showall ? 0 : NLFIT_PARAMS_CHECK_SHOW, dwOperUID) )
	if( !okutil_operation_tree_to_labtalk_tree(&treeSource, &tr, dwOption, dwOperUID) )
	///---END FIX_CANNOT_ACCESS_WHEN_ONLY_REPORT_TREE
		XF_THROW(CER_NLF_CONV_REPORT_TREE_TO_LT_TREE);
	/// end NLFIT_CONVERTING_INPUT_DATA_OPER_TREE_TO_LT_TREE
	
	
}

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

}

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