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.

196 lines
5.0 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: Zone.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of Zone.cpp
  13. //----------------------------------------------------------------------------
  14. // Zone.cpp: implementation of the CZone class.
  15. //
  16. //////////////////////////////////////////////////////////////////////
  17. #include "stdafx.h"
  18. //#include "chicago.h"
  19. #include "Visual.h"
  20. #include "Sensor.h"
  21. #include "SensorArray.h"
  22. #include "Zone.h"
  23. #include "..\..\LgLib\Version.h"
  24. #ifdef _DEBUG
  25. #undef THIS_FILE
  26. static char THIS_FILE[]=__FILE__;
  27. #define new DEBUG_NEW
  28. #endif
  29. //////////////////////////////////////////////////////////////////////
  30. // Construction/Destruction
  31. //////////////////////////////////////////////////////////////////////
  32. CZone::CZone()
  33. {
  34. m_strName = "ZONE";
  35. m_nNumber = -1;
  36. m_pSensorArray = NULL;
  37. m_nCount = 0;
  38. m_ppSensors = NULL;
  39. m_bSoundAlarm = TRUE;
  40. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CZone::CZone") );
  41. }
  42. CZone::~CZone()
  43. {
  44. if( m_ppSensors )
  45. delete [] m_ppSensors;
  46. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CZone::~CZone") );
  47. }
  48. BOOL CZone::Create( CSensorArray *pSensorArray, int nNumber )
  49. {
  50. m_pSensorArray = pSensorArray;
  51. m_nNumber = nNumber;
  52. m_nState = CSensor::UNKNOWN;
  53. m_nCount = 0;
  54. for( int i = 0; i < m_pSensorArray->GetSensorCount(); i++ )
  55. if( m_pSensorArray->GetSensor(i)->GetZoneIndex() == m_nNumber )
  56. m_nCount++;
  57. m_ppSensors = new CSensor*[ m_nCount ];
  58. m_nCount = 0;
  59. m_Position.x = m_Position.y = 0.0;
  60. m_Rect.left = m_Rect.top = 1.0;
  61. m_Rect.bottom = m_Rect.right = 0.0;
  62. for( i = 0; i < m_pSensorArray->GetSensorCount(); i++ )
  63. {
  64. if( m_pSensorArray->GetSensor(i)->GetZoneIndex() == m_nNumber )
  65. {
  66. CSensor *pSensor = m_pSensorArray->GetSensor(i);
  67. pSensor->SetZone( this );
  68. m_ppSensors[ m_nCount++ ] = pSensor;
  69. m_Position.x += pSensor->GetPosition().x;
  70. m_Position.y += pSensor->GetPosition().y;
  71. if( m_Rect.left > pSensor->GetPosition().x )
  72. m_Rect.left = pSensor->GetPosition().x;
  73. if( m_Rect.right < pSensor->GetPosition().x )
  74. m_Rect.right = pSensor->GetPosition().x;
  75. if( m_Rect.top > pSensor->GetPosition().y )
  76. m_Rect.top = pSensor->GetPosition().y;
  77. if( m_Rect.bottom < pSensor->GetPosition().y )
  78. m_Rect.bottom = pSensor->GetPosition().y;
  79. }
  80. }
  81. if( m_nCount > 0 )
  82. {
  83. m_Position.x /= m_nCount;
  84. m_Position.y /= m_nCount;
  85. }
  86. return TRUE;
  87. }
  88. void CZone::UpdateState()
  89. {
  90. int nState = UNKNOWN;
  91. for( int i = 0; i < m_nCount; i++ )
  92. {
  93. if( m_ppSensors[i]->GetState() > nState )
  94. {
  95. nState = m_ppSensors[i]->GetState();
  96. }
  97. }
  98. CVisual::SetState( nState );
  99. }
  100. void CZone::Reset()
  101. {
  102. for( int i = 0; i < m_nCount; i++ )
  103. m_ppSensors[i]->Reset();
  104. // PARANOID: Zone state updated in CSensor::Reset;
  105. UpdateState();
  106. }
  107. void CZone::Enable( BOOL bEnable )
  108. {
  109. for( int i = 0; i < m_nCount; i++ )
  110. m_ppSensors[i]->Enable( bEnable );
  111. // PARANOID: Zone state updated in CSensor::Enable;
  112. UpdateState();
  113. }
  114. BOOL CZone::Paint(CDC *pDC, CRect &viewRect, CSize &mapSize, SDPOINT &mapShift, double mapScale, BOOL bInverse, BOOL bBigSize, CRect *pUpdateRect)
  115. {
  116. return TRUE; // WARNING: TEST ONLY!!!
  117. SDPOINT shift( m_Position.x - mapShift.x, m_Position.y - mapShift.y );
  118. CPoint p = CalcDrawPoint( viewRect, mapSize, shift, mapScale );
  119. if( !viewRect.PtInRect(p) ) return FALSE;
  120. CRect rect;
  121. COLORREF color = GetStateColor( bInverse );
  122. if( bBigSize )
  123. {
  124. rect.SetRect( p.x - 24, p.y - 18, p.x + 24, p.y + 18 );
  125. // rect.SetRect( p.x - 4, p.y - 4, p.x + 4, p.y + 4 );
  126. pDC->FillSolidRect( &rect, color );
  127. // CBrush brush( color );
  128. // pDC->FillRect( &rect, &brush );
  129. INT nOldBkMode = pDC->SetBkMode( TRANSPARENT );
  130. INT nOldTextColor = pDC->SetTextColor( 0 );
  131. pDC->DrawText( m_strName, &rect, DT_WORDBREAK | DT_CENTER );
  132. pDC->SetTextColor( nOldTextColor );
  133. pDC->SetBkMode( nOldBkMode );
  134. }
  135. else
  136. {
  137. // rect.SetRect( p.x - 8, p.y - 8, p.x + 8, p.y + 8 );
  138. rect.SetRect( p.x - 2, p.y - 2, p.x + 2, p.y + 2 );
  139. pDC->FillSolidRect( &rect, color );
  140. // CBrush brush( color );
  141. // pDC->FillRect( &rect, &brush );
  142. }
  143. if( bBigSize )
  144. {
  145. /* LOGFONT lf;
  146. lf.lfHeight = -10;
  147. lf.lfWidth = 0;
  148. lf.lfEscapement = 0;
  149. lf.lfOrientation = 0;
  150. lf.lfWeight = 1000;
  151. lf.lfItalic = FALSE;
  152. lf.lfUnderline = FALSE;
  153. lf.lfStrikeOut = FALSE;
  154. lf.lfCharSet = OEM_CHARSET;
  155. lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
  156. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  157. lf.lfQuality = DEFAULT_QUALITY;
  158. lf.lfPitchAndFamily = FIXED_PITCH|FF_MODERN;
  159. strcpy( lf.lfFaceName, "Arial" );
  160. CFont font;
  161. font.CreateFontIndirect( &lf );
  162. CFont *pOldFont = (CFont*)pDC->SelectObject( &font );
  163. pDC->SelectObject( pOldFont );
  164. */
  165. }
  166. if( pUpdateRect ) *pUpdateRect = rect;
  167. return TRUE;
  168. }