Old fashion design for PC-104
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
3.7 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: GraphWnd.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of GraphWnd.cpp
  13. //----------------------------------------------------------------------------
  14. // GraphWnd.cpp : implementation file
  15. //
  16. #include "stdafx.h"
  17. #include "Calibration.h"
  18. #include "GraphWnd.h"
  19. #include ".\graphwnd.h"
  20. IMPLEMENT_DYNAMIC(CGraphWnd, CWnd)
  21. CGraphWnd::CGraphWnd()
  22. {
  23. m_Min.x = m_Min.y = 0.0;
  24. m_Max.x = m_Max.y = 1.0;
  25. m_Axis.x = 0;
  26. m_Axis.y = 0;
  27. m_Step.cx = m_Step.cy = 0.1;
  28. CGraphData GraphData;
  29. GraphData.bVisible = TRUE;
  30. GraphData.rgbColor = RGB(0xFF,0xFF,0xFF);
  31. /*
  32. GraphData.Add( CLgDPoint(0.0,0.0) );
  33. GraphData.Add( CLgDPoint(0.2,0.1) );
  34. GraphData.Add( CLgDPoint(0.3,0.4) );
  35. GraphData.Add( CLgDPoint(0.6,0.5) );
  36. GraphData.Add( CLgDPoint(0.7,0.8) );
  37. GraphData.Add( CLgDPoint(1.0,0.9) );
  38. */
  39. m_GraphDataArray.Add( GraphData );
  40. // GraphData.RemoveAll();
  41. GraphData.bVisible = TRUE;
  42. GraphData.rgbColor = RGB(0xFF,0xFF,0);
  43. /*
  44. GraphData.Add( CLgDPoint(0.0,0.0) );
  45. GraphData.Add( CLgDPoint(0.1,0.2) );
  46. GraphData.Add( CLgDPoint(0.4,0.3) );
  47. GraphData.Add( CLgDPoint(0.5,0.6) );
  48. GraphData.Add( CLgDPoint(0.8,0.7) );
  49. GraphData.Add( CLgDPoint(0.9,1.0) );
  50. */
  51. m_GraphDataArray.Add( GraphData );
  52. }
  53. CGraphWnd::~CGraphWnd()
  54. {
  55. }
  56. BEGIN_MESSAGE_MAP(CGraphWnd, CWnd)
  57. ON_WM_PAINT()
  58. END_MESSAGE_MAP()
  59. void CGraphWnd::SetField( CLgDPoint min, CLgDPoint max, CLgDPoint axis, CLgDSize step )
  60. {
  61. // store parameters
  62. m_Min = min;
  63. m_Max = max;
  64. m_Axis = axis;
  65. m_Step = step;
  66. // draw
  67. CClientDC dc( this );
  68. OnDraw( &dc );
  69. }
  70. void CGraphWnd::OnPaint()
  71. {
  72. CPaintDC dc(this);
  73. OnDraw( &dc );
  74. }
  75. void CGraphWnd::OnDraw( CDC *pDC )
  76. {
  77. CRect rect;
  78. GetClientRect( &rect );
  79. #define OFFSET 5
  80. double dX = m_Max.x - m_Min.x;
  81. double dY = m_Max.y - m_Min.y;
  82. double x2d = ( rect.Width() - ( OFFSET * 2 ) ) / dX;
  83. double y2d = ( rect.Height() - ( OFFSET * 2 ) ) / dY;
  84. #define X2D(x) ((INT)( x*x2d+OFFSET ))
  85. #define Y2D(y) ((INT)( rect.Height()-OFFSET-y*y2d ))
  86. // draw background
  87. pDC->FillRect( &rect, &CBrush( RGB(0,0x7F,0) ) );
  88. // draw axises
  89. pDC->MoveTo( X2D(m_Axis.x), Y2D(m_Min.y) );
  90. pDC->LineTo( X2D(m_Axis.x), Y2D(m_Max.y) );
  91. pDC->MoveTo( X2D(m_Min.x), Y2D(m_Axis.y) );
  92. pDC->LineTo( X2D(m_Max.x), Y2D(m_Axis.y) );
  93. // draw steps
  94. int sX = dX / m_Step.cx;
  95. for( INT i = 0; i < sX; i++ )
  96. {
  97. pDC->MoveTo( X2D(dX * i / sX), Y2D(m_Axis.y) - 2 );
  98. pDC->LineTo( X2D(dX * i / sX), Y2D(m_Axis.y) + 2 );
  99. }
  100. int sY = dY / m_Step.cy;
  101. for( i = 0; i < sY; i++ )
  102. {
  103. pDC->MoveTo( X2D(m_Axis.x) - 2, Y2D(dY * i / sY) );
  104. pDC->LineTo( X2D(m_Axis.x) + 2, Y2D(dY * i / sY) );
  105. }
  106. // draw data
  107. for( i = 0; i < m_GraphDataArray.GetCount(); i++ )
  108. {
  109. if( !m_GraphDataArray[i].bVisible )
  110. continue;
  111. CPen pen( PS_SOLID, 1, m_GraphDataArray[i].rgbColor );
  112. CPen *pPen = pDC->SelectObject( &pen );
  113. for( INT j = 0; j < m_GraphDataArray[i].GetCount(); j++ )
  114. {
  115. if( j == 0 ) pDC->MoveTo( X2D(m_GraphDataArray[i][j].x), Y2D(m_GraphDataArray[i][j].y) );
  116. else pDC->LineTo( X2D(m_GraphDataArray[i][j].x), Y2D(m_GraphDataArray[i][j].y) );
  117. }
  118. pDC->SelectObject( pPen );
  119. }
  120. }
  121. BOOL CGraphWnd::Create( CWnd *pParentWnd, LPRECT pRect )
  122. {
  123. CString strClassName = ::AfxRegisterWndClass( CS_HREDRAW | CS_VREDRAW, NULL, NULL, NULL );
  124. if( !CWnd::Create( strClassName, NULL, WS_CHILD | WS_VISIBLE, *pRect, pParentWnd, 0 ) )
  125. return FALSE;
  126. return FALSE;
  127. }