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.

195 lines
4.4 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: BorderLGS.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of BorderLGS.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "BorderLGS.h"
  16. #include "..\..\LgLib\Version.h"
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char THIS_FILE[]=__FILE__;
  20. #define new DEBUG_NEW
  21. #endif
  22. CBorderLGS::CBorderLGS()
  23. {
  24. m_pBorder = NULL;
  25. m_nBorder = 0;
  26. // log info
  27. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CBorderLGS::CBorderLGS" );
  28. }
  29. CBorderLGS::~CBorderLGS()
  30. {
  31. Destroy();
  32. // log info
  33. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CBorderLGS::~CBorderLGS" );
  34. }
  35. BOOL CBorderLGS::Copy( CBorderLGS *pBorderLGS )
  36. {
  37. Destroy();
  38. if( !pBorderLGS )
  39. return FALSE;
  40. m_nBorder = pBorderLGS->m_nBorder;
  41. if( m_nBorder )
  42. {
  43. m_pBorder = new BORDER[ m_nBorder ];
  44. if( !m_pBorder )
  45. m_nBorder = 0;
  46. ::CopyMemory( m_pBorder, pBorderLGS->m_pBorder, sizeof(BORDER) * m_nBorder );
  47. }
  48. return TRUE;
  49. }
  50. void CBorderLGS::LoadAsSingleIPI( LPCTSTR pFileName )
  51. {
  52. HANDLE hFile = ::CreateFile( "DrawMap.dat", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
  53. if( hFile )
  54. {
  55. Destroy();
  56. DWORD dwRead;
  57. ::ReadFile( hFile, &m_nBorder, sizeof( m_nBorder ), &dwRead, NULL );
  58. if( m_nBorder )
  59. {
  60. m_pBorder = new BORDER[ m_nBorder ];
  61. if( !m_pBorder )
  62. m_nBorder = 0;
  63. ::ReadFile( hFile, m_pBorder, sizeof( BORDER ) * m_nBorder, &dwRead, NULL );
  64. }
  65. ::CloseHandle( hFile );
  66. }
  67. }
  68. void CBorderLGS::SaveAsSingleIPI( LPCTSTR pFileName )
  69. {
  70. HANDLE hFile = ::CreateFile( "DrawMap.dat", GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL );
  71. if( hFile )
  72. {
  73. DWORD dwWritten;
  74. ::WriteFile( hFile, &m_nBorder, sizeof( m_nBorder ), &dwWritten, NULL );
  75. ::WriteFile( hFile, m_pBorder, sizeof( BORDER ) * m_nBorder, &dwWritten, NULL );
  76. ::CloseHandle( hFile );
  77. }
  78. }
  79. void CBorderLGS::Serialize(CArchive &ar)
  80. {
  81. if( ar.IsStoring() )
  82. {
  83. ar << m_nBorder;
  84. for( int i = 0; i < m_nBorder; i++ )
  85. {
  86. for( int j = 0; j < 2; j++ )
  87. {
  88. ar << m_pBorder[i].bExist[j];
  89. ar << m_pBorder[i].dAngle[j];
  90. ar << m_pBorder[i].dRange[j];
  91. }
  92. }
  93. }
  94. else
  95. {
  96. Destroy();
  97. ar >> m_nBorder;
  98. m_pBorder = new BORDER[ m_nBorder ];
  99. if( !m_pBorder )
  100. m_nBorder = 0;
  101. for( int i = 0; i < m_nBorder; i++ )
  102. {
  103. for( int j = 0; j < 2; j++ )
  104. {
  105. ar >> m_pBorder[i].bExist[j];
  106. ar >> m_pBorder[i].dAngle[j];
  107. ar >> m_pBorder[i].dRange[j];
  108. }
  109. }
  110. }
  111. }
  112. void CBorderLGS::Destroy()
  113. {
  114. if( m_pBorder )
  115. {
  116. if( m_pBorder )
  117. delete [] m_pBorder;
  118. m_pBorder = NULL;
  119. }
  120. m_nBorder = 0;
  121. }
  122. BOOL CBorderLGS::Draw( CDC *pDC, CPoint *pCenter, double dScaleToPixel, double dRotateAngle )
  123. {
  124. // log info
  125. LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, "CBorderLGS::Draw", "Start..." );
  126. // COLORREF LsgColor[] = { RGB( 0xEF, 0xEF, 0 ), RGB( 0xEF, 0xEF, 0xEF ) };
  127. COLORREF LsgColor[] = { RGB( 0xAF, 0xAF, 0 ), RGB( 0xAF, 0xAF, 0 ) };
  128. if( m_pBorder && m_nBorder )
  129. {
  130. for( INT n = 0; n < 2; n++ )
  131. {
  132. LPPOINT pPolygon = new POINT[m_nBorder + 1];
  133. if( pPolygon )
  134. {
  135. for( INT i = 0; i <= m_nBorder; i ++ )
  136. {
  137. BORDER *pBorder = &m_pBorder[ i % m_nBorder ];
  138. double dz = 3.14 / 180.0 * ( pBorder->dAngle[n] + dRotateAngle );
  139. double xp = cos( dz ) * pBorder->dRange[n] * dScaleToPixel;
  140. double yp = sin( dz ) * pBorder->dRange[n] * dScaleToPixel;
  141. pPolygon[i].x = (INT)(xp + pCenter->x + 0.5);
  142. pPolygon[i].y = (INT)(pCenter->y - yp + 0.5);
  143. }
  144. CPen pen( PS_SOLID, 1, LsgColor[n] );
  145. CPen *pPen = pDC->SelectObject( &pen );
  146. CBrush brush( HS_DIAGCROSS, LsgColor[n] );
  147. CBrush *pBrush = pDC->SelectObject( &brush );
  148. INT nBkMode = pDC->SetBkMode( TRANSPARENT );
  149. pDC->Polygon( pPolygon, m_nBorder );
  150. // pDC->Polyline( pPolygon, m_nBorder + 1 );
  151. pDC->SetBkMode( nBkMode );
  152. pDC->SelectObject( pPen );
  153. pDC->SelectObject( pBrush );
  154. delete [] pPolygon;
  155. }
  156. }
  157. }
  158. // log info
  159. LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, "CBorderLGS::Draw", "Done" );
  160. return TRUE;
  161. }