clPlot.h
上传用户:fzchengxin
上传日期:2013-10-17
资源大小:2070k
文件大小:7k
源码类别:

Windows编程

开发平台:

Visual C++

  1. //*******************************************************************************************************/
  2. //* FileName        : clPlot.h
  3. //* Description     : Real Time Plot for MFC
  4. //* Contents: : axis y (x) axis info.
  5. //*   timeaxis time axis info
  6. //*   legend legend info.
  7. //*   serie data serie info & array
  8. //*   clPlot The plot itself.
  9. //* Author          : Jan Vidar Berger, Modified by Bill Chen
  10. //* Time : 2004.7.20 xianch@126.com
  11. //*******************************************************************************************************/
  12. #if !defined(AFX_DQPLOT_H__0D536D37_5CF1_11D1_AED1_0060973A08A4__INCLUDED_)
  13. #define AFX_DQPLOT_H__0D536D37_5CF1_11D1_AED1_0060973A08A4__INCLUDED_
  14. #if _MSC_VER >= 1000
  15. #pragma once
  16. #endif // _MSC_VER >= 1000
  17. // clPlot.h : header file
  18. //
  19. #define SERIENUMBER 5
  20. #define MAXSIRIEDATA 140 // 60 * 2, 每格最多两个数据
  21. #define COORWIDTH 35 // 坐标数值的宽度
  22. //*******************************************************************************************************/
  23. //* simple data value struct. used in dynamic array
  24. //*******************************************************************************************************/
  25. typedef struct _value{
  26. double dValue;
  27. CTime ValueTime;
  28. }value;
  29. //*******************************************************************************************************/
  30. //* non-time axis. used for left and right y axis. might be used for x as well.
  31. //*******************************************************************************************************/
  32. class  AFX_EXT_CLASS axis
  33. {
  34. public:
  35. double minrange;
  36. double maxrange;
  37. double m_dValuePrPixel;
  38. axis()
  39. {
  40. minrange = 0.0;
  41. maxrange = 200.0;
  42. m_dValuePrPixel = 1;
  43. };
  44. };
  45. //*******************************************************************************************************/
  46. //* time axis
  47. //*******************************************************************************************************/
  48. class  AFX_EXT_CLASS timeaxis
  49. {
  50. public:
  51. CString m_szTitle; // time axis title;
  52. CTime m_mintime; // min time
  53. CTime m_maxtime; // max time
  54. int m_iTimeMode; // axis grid and legend interval index
  55. double m_dSecondsPrPixel; //时间间隔(秒)/画图区宽度
  56. timeaxis()
  57. {
  58. m_szTitle = "Time";
  59. m_mintime = 0;
  60. m_maxtime = 600;
  61. m_iTimeMode = 0;
  62. m_dSecondsPrPixel = 1;
  63. }
  64. };
  65. //*******************************************************************************************************/
  66. //* legend
  67. //*******************************************************************************************************/
  68. /*
  69. class  AFX_EXT_CLASS legend
  70. {
  71. public:
  72. COLORREF m_color; // legend color code
  73. int m_istyle;
  74. CString m_szTitle; // legend title
  75. legend(){
  76. m_color = 0;
  77. m_istyle = PS_SOLID;
  78. m_szTitle = "";
  79. }
  80. };
  81. */
  82. /*******************************************************************************************************
  83. //* data serie
  84. 改进的循环队列, 元素个数为 #define MAXSIRIEDATA 120 + 1 个,
  85. 开始时, m_lbegin == m_lend
  86. 访问数据时, 若 m_lbegin != m_lend, go on!
  87. *******************************************************************************************************/
  88. class  AFX_EXT_CLASS serie
  89. {
  90. public:
  91. COLORREF m_color; // serie line color
  92. int m_iLineStyle; // line style
  93. value m_pvalues[MAXSIRIEDATA]; // value array
  94. int m_lbegin; // list begin
  95. int m_lend; // list end
  96. // Added later
  97. int m_nMinValue;
  98. int m_nMaxValue;
  99. CString m_strTitle;
  100. serie();
  101. ~serie();
  102. void AddPoint(CTime &valuetime, double y);
  103. void Reset();
  104. //private:
  105. int m_lNoValues; // number values (used for array size)
  106. };
  107. //*******************************************************************************************************/
  108. //* Class           : clPlot
  109. //*
  110. //* Base Class      : public CWnd
  111. //*
  112. //* Description     : Plot Component.
  113. //*
  114. //*   This is a standard plot and can be used for any application.
  115. //*
  116. //* 1. A special 'autoscroll'mode exist for real time plots.
  117. //* 2. Only a minimum of features are implemented.
  118. //* 3. Series and legends are separated and must be set up individually.
  119. //* 4. A set of defines (see top of file) are used to set the max array sizes.
  120. //* 5. Only time are supported as x-axis.
  121. //* 6. A large range of pre-calculated values are used for maximum speed.
  122. //*
  123. //* Author          : Jan Vidar Berger
  124. //*******************************************************************************************************/
  125. class AFX_EXT_CLASS clPlot : public CWnd
  126. {
  127. // Construction
  128. public:
  129. clPlot( int timespan = 1 ); // timespan in minutes
  130. // clPlot(clPlot &plot);
  131. virtual ~clPlot();
  132. // Attributes
  133. public:
  134. int m_nSpanTime;
  135. // bool m_bReDraw;
  136. CRect m_clientRect; // actual controlled rect
  137. CRect m_plotRect; // clientRect - margins
  138. int m_iMleft; // left margin
  139. int m_iMright; // right margin
  140. int m_iMtop; // top margin
  141. int m_iMbottom; // bottom margin
  142. COLORREF m_ctlBkColor; // control background color
  143. COLORREF m_gridColor; // grid line color
  144. BOOL m_bAutoScrollX; // automatic x range scrolling, import
  145. // legend m_pLegends[SERIENUMBER];
  146. serie m_series[SERIENUMBER]; // 存放点位置
  147. timeaxis m_timeaxis; // bottom axis
  148. CFont m_font;
  149. // 定义两种字体格式
  150. LOGFONT m_logFont;
  151. LOGFONT m_zoomFont; // 默认字体, used in ComputeRects
  152. double m_dzoom;
  153. int m_TextHeight; // 一个字符的高度
  154. // Operations
  155. public:
  156. BOOL Create(DWORD dwstyle, CRect &rect, CWnd *pParent, UINT id);
  157. void MoveWindow(CRect &Rect);
  158. void ClearData();
  159. virtual void Draw(CDC * dc); // Draw the entire plot
  160. virtual void DrawBasic(CDC * dc); // Draw plot basics
  161. virtual void DrawPlot(CDC * dc); // Draw the plot series
  162. virtual void DrawSerie(CDC *dc, int serie);
  163. virtual void DrawGrid(CDC * dc); // Draw grids
  164. virtual void DrawYAxisGrid(CDC * dc);
  165. virtual void DrawXAxisGrid(CDC * dc);
  166. virtual void ComputeRects(BOOL bInitialize);
  167. virtual BOOL AddPoint(int serie, CTime &valuetime, double y);
  168. virtual void SetBXRange(CTime &fromtime, CTime &totime,BOOL bMove=TRUE);
  169. virtual void SetSerie(int s, int style, COLORREF color, 
  170. int minrange, int maxrange, const char *szTitle);
  171. // Overrides
  172. // ClassWizard generated virtual function overrides
  173. //{{AFX_VIRTUAL(clPlot)
  174. //}}AFX_VIRTUAL
  175. // Implementation
  176. public:
  177. // void SetRedraw( bool b );
  178. // clPlot& operator = ( clPlot &plot );
  179. // Generated message map functions
  180. protected:
  181. //{{AFX_MSG(clPlot)
  182. afx_msg void OnPaint();
  183. //}}AFX_MSG
  184. BOOL clPlot::OnEraseBkgnd(CDC* pDC) ;
  185. DECLARE_MESSAGE_MAP()
  186. private:
  187. void WriteLegend(CDC *dc, int s);
  188. };
  189. /////////////////////////////////////////////////////////////////////////////
  190. //{{AFX_INSERT_LOCATION}}
  191. // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
  192. #endif // !defined(AFX_DQPLOT_H__0D536D37_5CF1_11D1_AED1_0060973A08A4__INCLUDED_)