#include <origin.h>
#include <GetNBox.h>
#include <xfutils.h>
enum{
	type_math,
	type_abs,
};
//put additional include files here
#include <event_utils.h>
#include <o8dlg.h>



//put your own support static functions here
#define	MIN_INPUT_DATA_NUMBER 2


static int _check_err_condition(TreeNode& trGetN)
{
	int nErr = CER_NO_ERROR;

	if(get_input_xyrange_num(trGetN.iy) != 1)
		nErr = CER_NOT_ONE_XYRANGE;
	
	if(nErr == CER_NO_ERROR && 0>= get_input_xyrange_data_size(trGetN.iy))
		nErr = CER_NO_DATA;

	if(nErr == CER_NO_ERROR && MIN_INPUT_DATA_NUMBER > get_input_xyrange_data_size(trGetN.iy))
		nErr = CER_DATA_TOO_FEW;

	return nErr;
}






void polyarea(const XYRange& iy, const int& type, double& area)
{
	
	vector vX, vY;
	double dArea;
	
	
	iy.GetData(vY, vX);
	if(vX.GetSize() != vY.GetSize())
	{
		out_str("Input data error!");
	}
	
	dArea = -ocmath_d_polygon_area(vX, vY, vX.GetSize());
	if(type == type_abs)
	{
		dArea = fabs(dArea);
	}
	
	area = dArea;
	
	
	
}

//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 polyarea_event1(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	if( xf_is_extended_event(nEventID) )
		return polyarea_event1_ex(trGetN, nRow, nEventID, dwEnables, lpcszNodeName, DynaCntrlContainer, strAux, strErrMsg);
	DECLARE_BUTTON_ENABLES
	bool bIsChangingPlot = lstrcmpi(lpcszNodeName, "plot") == 0? true:false;
	
	int init = GETNE_ON_INIT;
	int the = GETNE_ON_THEME;
	int nErr = CER_NO_ERROR;
	
	nErr = _check_err_condition(trGetN);
	
	if(nErr != CER_NO_ERROR)
	{
		bOKEnable = false;
		strErrMsg = nErr;
		///Arvin 07/30/07 WRONG_ERR_MASSAGE
		if(nErr == CER_DATA_TOO_FEW)
		{
			strErrMsg += ":";
			strErrMsg += MIN_INPUT_DATA_NUMBER;
		}
		///end WRONG_ERR_MASSAGE
	}
	
	return true;
	
	

}

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