// AttitudeCtrl.h: interface for the CAttitudeCtrl class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_ATTITUDECTRL_H__0D48673C_A644_4866_94A2_24889B8627D6__INCLUDED_)
#define AFX_ATTITUDECTRL_H__0D48673C_A644_4866_94A2_24889B8627D6__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <deque>
#include <math.h>
using namespace std;

#define BMP_HEIGHT 721 //360 pixels for display * 2 pixels per unit, plus 2 pixels for 'X' axis

///////////////////////////////////////////////////////////////////////////
//
// This class supports a time series plot using up to 4 seperate plots
//
///////////////////////////////////////////////////////////////////////////

typedef enum tagLINE1_IDS
{
	ROLL	= 1,
	PITCH	= 2,
	ROLLRT	= 3,
	PITCHRT	= 4

}LINE1_IDS;
	
typedef enum tagLINE2_IDS
{
	EASTRT	= 1,
	NORTHRT	= 2,
	DEPTHRT	= 3

}LINE2_IDS;
	

class CAttitudeCtrl  
{
public:
///////////////////////////
public: //CONSTRUCTION
///////////////////////////
						 CAttitudeCtrl		(	void );
	virtual				~CAttitudeCtrl		(	void );

///////////////////////////
public: //VARIABLES
///////////////////////////

	enum {ROLL = 0, PITCH, HEAVE} EAttitudeType;

///////////////////////////
public: //FUNCTIONS
///////////////////////////
	BOOL				InitCtrl			(	CWnd		*pWnd, 
												CWnd		*pRectWnd, 
												int			maxWidth );							//Initialize all

	void				Cleanup				(	void );											//Cleanup all

	void				AddAngle			(	float		angle, 
												UINT		lineID );							//Add new data
	
	void				Resize				(	CRect		rect );								//Call when window size changed
	
	void				Refresh				(	void );											//Call for refresh, non-size related, obeys update rate selected by user	

	void				ForceRefresh		(	void );											//Refreshes without considering update rate

	void				SetPlaneColor		(	COLORREF	color );							//Display color 
	
	void				SetAxisColor		(	COLORREF	color );							//Axis colors
	
	void				SetFontColor		(	COLORREF	color );							//Text color
	
	void				SetLineColor		(	COLORREF	color,
												UINT		lineID );							//Data color

	void				SetUpdateRate		(	UINT		rate );
	
	void				SetDisplayType		(	int			mode );								//Class keeps internal type
	void				SetScale			(	int			degress);							//scales degress to +/- input argument						


	BOOL				m_bLine1, m_bLine2, m_bLine3, m_bLine4;


///////////////////////////
private: //VARIABLES
///////////////////////////
	

	//Update
	UINT		updateRate;
	UINT		updateCount;

	//GDI
	CDC			m_DC1, m_DC2;
	CWnd		*m_pParentWnd;
	CWnd		*m_pwndBltArea;

	CBitmap		m_Bitmap, m_Bitmap2;								
	CPen		m_penAxisY, m_penAxisX; 
	CPen		m_penData1, m_penData2, m_penData3, m_penData4;
	
	CBrush		m_brPlane, m_brOther;
	
	CFont		m_ftAngles, m_ftCurrentAngle;

	CPen		*m_pOldPen;
	
	COLORREF	crPlane, crAxis; 
	COLORREF	m_crData1, m_crData2, m_crData3, m_crData4;

	//ATTRIBUTES
	CRect		m_Rect;
	int			m_nDegreeScale;
	int			m_OffsetInc;

	//HISTORY for each line
	deque<float> m_qHistory1;							//History que of depths
	deque<float> m_qHistory2;
	deque<float> m_qHistory3;
	deque<float> m_qHistory4;

	//float		*m_fpHistory1;
	//float		*m_fpHistory2;
	//float		*m_fpHistory3;
	//float		*m_fpHistory4;

	int			m_maxHistorySize;						//Max history size
	
	POINT		*m_pPolyLine1;							//Polyline = array of POINT structs
	POINT		*m_pPolyLine2;
	POINT		*m_pPolyLine3;
	POINT		*m_pPolyLine4;

	int			m_nPoints1;								//How many POINTS are stored
	int			m_nPoints2;
	int			m_nPoints3;
	int			m_nPoints4;


///////////////////////////
private: //FUNCTIONS
///////////////////////////

	int			TransformToScale			(	int			rawAngle);	//Takes the angle value and outputs a Y coordinate in BMP space 

	void		InitGDI						(	void );
	void		CreatePlane					(	void );
	void		FillPlane					(	void );
	void		DrawAxes					(	void );
	void		DrawLine					(	void );
	void		Render						(	void );
	CRect		GetBltRect					(	void );

};

#endif // !defined(AFX_ATTITUDECTRL_H__0D48673C_A644_4866_94A2_24889B8627D6__INCLUDED_)
