#include <origin.h>
#include <GetNBox.h>
#include <xfutils.h>

/*------------------------------------------------------------------------------*
 * Modification Log:															*
 *	Kenny 08/25/2009 QA81-14203 RESET_PAGE_NAME_IF_CREATED_FROM_OC				*
 *------------------------------------------------------------------------------*/



void plotellipse(const double& a, const double& b, const int& points, XYRange& oy)
{
	// --------------------------------------------------------------------------
	// This example shows how to compute x, y values for an ellipse and
	// then create a plot
	//
	// Declare vectors for t, x, y
	vector t(points), x(points), y(points);
	///Echo 9/30/07 v8.0711 ELLIPSE_NOT_SMOOTH_FOR_FEW_POINTS
	/*
	// Fill t with requested points from -2*PI to 2*PI
	double dStep = 4 * PI / (points - 1);
	t.Data(-2 * PI, 2 * PI, dStep);
	// Compute x, y and place them in newly created worksheet
	x=a*sin(t);
	y=b*cos(t);
	*/
	double theta; //vary from 0 to 2*pi to plot the ellipse
	double r;
	for(int i=0; i<points; i++)
	{
		theta=i*2*4*atan(1.0)/points;
		r=1/sqrt(pow(cos(theta),2)/pow(a,2)+pow(sin(theta),2)/pow(b,2));
		
		x[i]=r*cos(theta);
		y[i]=r*sin(theta);		
	}
	x[points-1] = x[0];
	y[points-1] = y[0];
	///end ELLIPSE_NOT_SMOOTH_FOR_FEW_POINTS
	oy.SetData(&x, &y);
	// Create a graph page and add x,y as a line plot
	GraphPage gpg;
	/// Kenny 08/25/2009 QA81-14203 RESET_PAGE_NAME_IF_CREATED_FROM_OC
	//gpg.Create("Origin");
	gpg.Create("Origin", CREATE_DEFAULT_OPTIONS | CREATE_ENUM_EXIST_PAGE);
	/// End QA81-14203 RESET_PAGE_NAME_IF_CREATED_FROM_OC
	GraphLayer gly = gpg.Layers(0);
	gly.AddPlot(oy, IDM_PLOT_LINE);
	gly.Rescale();
	// --------------------------------------------------------------------------
}

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

}

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