// ChildFrm.h : interface of the CChildFrame class
//
/////////////////////////////////////////////////////////////////////////////
#if !defined (CHILDFRM_H)
#	define CHILDFRM_H


class CChildFrame;

#define MAX_WIDTH 1280
#define MAX_HEIGHT 1280

#	if !defined (STYLE_HPP)
#		include "style.hpp"
#	endif


#include "LabRat.h"
#include "LabRatview.h"
#include "comboview.h"
#include "logicview.h"
#include "timeview.h"
#include "nameview.h"
#include "valueview.h"
#include "LabRatdoc.h"
#include "lranlyzr.hpp"             
#include "traceline.hpp"





#define MINUTE			60.0f
#define SECOND			1.0f
#define MILLISECOND  1.e-3f
#define MICROSECOND  1.e-6f

#if defined (SUPPORT_NANOSECOND)
#	define NANOSECOND	   1.e-9f
#endif



#define DIVISIONS            20
#define PIXELS_PER_DIVISION  50

#if defined (SUPPORT_NANOSECOND)
#	define SCALES_COUNT         5
#else
#	define SCALES_COUNT			 4
#endif 

#if defined (SUPPORT_NANOSECOND)
	static float SCALES[SCALES_COUNT] =
	{NANOSECOND, MICROSECOND, MILLISECOND, SECOND, MINUTE};	
	static char *SCALES_TEXT[SCALSE_COUNT] =
	{"ns", "us", "ms", "s", "m"}
#else
	static float SCALES[SCALES_COUNT] =
	{MICROSECOND, MILLISECOND, SECOND, MINUTE};
	static char *SCALES_TEXT[SCALES_COUNT] =
	{"us", "ms", "s", "m"};
#endif

#define SCALE_STEP_COUNT 9

static int SCALE_STEP[SCALE_STEP_COUNT] = 
		{1,2,5,10,20,50,100,200,500};

#if defined (SUPPORT_NANOSECOND)
	enum {
		Nanosecond = 0,
		Microsecond = 1,
		Millisecond = 2,
		Second = 3,
		Minute = 4
	};
#else
	enum {
		Nanosecond = -1,
		Microsecond = 0,
		Millisecond = 1,
		Second = 2,
		Minute = 3
	};
#endif


class ViewedTime
{
public:
	Time 
		startTime,
		endTime,
		
		timeToPixel,
		pixelToTime,

		pixelsPerDivision,

		startTimeSel,
		endTimeSel;
	
	int
		secondEnum,
		step;

	ViewedTime()
	{startTime = 0.0f; endTime = 0.0f; 
	 timeToPixel = 0.0f; pixelToTime = 0.0f;
	 pixelsPerDivision = 0; secondEnum = 0; step = 0;
	 startTimeSel = 0.0f;endTimeSel = 0.0f;}
};


class CChildFrame : public CMDIChildWnd
{
	DECLARE_DYNCREATE(CChildFrame)
public:
	CChildFrame();

// Attributes
public:


	enum {
		MoveMode,
		ZoomMode,
		SelectMode,
	};

	int currentMode;

	CBitmap *screenBitmap;
	CSize bitmapSize;

	CSplitterWnd m_wndSplitter;
	CSplitterWnd m_wndSplitter2;

	CComboView *comboView;
	CTimeView *timeView;
	CNameView *nameView;
	CValueView *valueView;
	CLogicView *logicView;

	CRect 
		timeSize,
		nameSize,
		valueSize,
		logicSize;

	ViewedTime
		viewedTime;
	
	CObArray	*traceListArray;
   int traceCount;

	CLabRatDoc 
		*document;

	TraceAnalyzerRegistry	
		analyzerRegistry;

	// User prefs
	int borderSize;
	int boxMinimum;


// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CChildFrame)
	public:
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
	protected:
	virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext);
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CChildFrame();

	void SaveSize(void); 

	void FrameTimeSpan(
			Time time_span, 
			int screen_size	
		);

	void SetTime(void);

	void
		OnInitialUpdate(void);

	void 
		SetComboBox(int step_enum, int second_enum);

	void Draw(CWnd *window_pointer = NULL);
	void DrawCRect(CRect rectangle, MY_RGB color);

	void DrawLine(
		CPoint from_point,
		CPoint to_point,
		MY_RGB  color,
		int  thickness
	);

	void DrawLine(
		Time from_time,
		Time to_time,
		int  from_value,
		int  to_value,
		int  offset,
		MY_RGB  color,
		int  thickness
	);

	void DrawBox(
		Time from_time,
		Time to_time,
		int  to_value,
		int  from_value,
		int  offset,
		MY_RGB  color
	);

	void DrawText(
		CString text,
		Time time,
		int  height,
		MY_RGB  color
	);

	void DrawTextLeft(
		CString text,
		Time time,
		int  height,
		MY_RGB  color
	);

	void DrawText(
		CString text,
		int  x,
		int  height,
		MY_RGB  color
	);

#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

// Generated message map functions
protected:
	//{{AFX_MSG(CChildFrame)
	afx_msg void OnUpdateViewZoom(CCmdUI* pCmdUI);
	afx_msg void OnViewZoom();
	afx_msg void OnUpdateViewMove(CCmdUI* pCmdUI);
	afx_msg void OnViewMove();
	afx_msg void OnViewSelect();
	afx_msg void OnUpdateViewSelect(CCmdUI* pCmdUI);
	afx_msg void OnEnableBug();
	afx_msg void OnUpdateEnableBug(CCmdUI* pCmdUI);
	//}}AFX_MSG
	

	DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////
#endif
