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.

287 lines
7.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: Sensor.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of Sensor.cpp
  13. //----------------------------------------------------------------------------
  14. // Sensor.cpp: implementation of the CSensor class.
  15. //
  16. //////////////////////////////////////////////////////////////////////
  17. #include "stdafx.h"
  18. //#include "Chicago.h"
  19. //#include "MapData.h"
  20. #include "Sensor.h"
  21. #include "AuxLib.h"
  22. #include "..\..\LgLib\Version.h"
  23. #include "..\..\LgLib\LgPerformanceCounter.h"
  24. #include "Zone.h"
  25. #include "SocketCCC.h"
  26. #include "CameraPTZ.h"
  27. #include "..\Chicago\PropertySensorWnd.h"
  28. #include "..\Chicago\PropertySensorWnd.h"
  29. #include "SensorArray.h"
  30. #ifdef _DEBUG
  31. #undef THIS_FILE
  32. static char THIS_FILE[]=__FILE__;
  33. #define new DEBUG_NEW
  34. #endif
  35. //////////////////////////////////////////////////////////////////////
  36. // Construction/Destruction
  37. //////////////////////////////////////////////////////////////////////
  38. CSensor::CSensor()
  39. {
  40. m_Position.x = m_Position.y = 0.5;
  41. m_iAddress = 0;
  42. m_nSocket = -1;
  43. m_nIndex = -1;
  44. m_nZone = -1;
  45. m_dwTime = 0UL;
  46. m_pZone = NULL;
  47. m_pSensorArray = NULL;
  48. m_pVideoCamera = NULL;
  49. m_pTransform[0] = NULL;
  50. m_pTransform[1] = NULL;
  51. m_nTemplateType = -1;
  52. m_nTemplateIndex = -1;
  53. m_nAddressCCC = -1;
  54. m_pPropertySensorWnd = NULL;
  55. m_bRemoteCamera = FALSE;
  56. m_dPanShift = 0;
  57. for( int i = 0; i < 10; i++ )
  58. m_pTiltTable[i] = 0;
  59. m_nImageCount = 5;
  60. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CSensor::CSensor") );
  61. }
  62. CSensor::~CSensor()
  63. {
  64. if( m_pTransform[0] )
  65. delete m_pTransform[0];
  66. if( m_pTransform[1] )
  67. delete m_pTransform[1];
  68. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CSensor::~CSensor") );
  69. }
  70. BOOL CSensor::Paint( CDC *pDC, CRect& viewRect, CSize& mapSize, SDPOINT& mapShift, double mapScale, BOOL bInverse, BOOL bBigSize, CRect *pUpdateRect )
  71. {
  72. SDPOINT shift( m_Position.x - mapShift.x, m_Position.y - mapShift.y );
  73. CPoint p = CalcDrawPoint( viewRect, mapSize, shift, mapScale );
  74. if( !viewRect.PtInRect(p) ) return FALSE;
  75. CRect rect;
  76. COLORREF color = GetStateColor( bInverse );
  77. if( bBigSize )
  78. {
  79. rect.SetRect( p.x - 24, p.y - 10, p.x + 24, p.y + 10 );
  80. pDC->FillSolidRect( &rect, color );
  81. // CBrush brush( color );
  82. // pDC->FillRect( &rect, &brush );
  83. INT nOldBkMode = pDC->SetBkMode( TRANSPARENT );
  84. INT nOldTextColor = pDC->SetTextColor( 0 );
  85. pDC->DrawText( m_strName, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER );
  86. pDC->SetTextColor( nOldTextColor );
  87. pDC->SetBkMode( nOldBkMode );
  88. }
  89. else
  90. {
  91. rect.SetRect( p.x - 2, p.y - 2, p.x + 2, p.y + 2 );
  92. pDC->FillSolidRect( &rect, color );
  93. // CBrush brush( color );
  94. // pDC->FillRect( &rect, &brush );
  95. }
  96. if( bBigSize )
  97. {
  98. /* LOGFONT lf;
  99. lf.lfHeight = -10;
  100. lf.lfWidth = 0;
  101. lf.lfEscapement = 0;
  102. lf.lfOrientation = 0;
  103. lf.lfWeight = 1000;
  104. lf.lfItalic = FALSE;
  105. lf.lfUnderline = FALSE;
  106. lf.lfStrikeOut = FALSE;
  107. lf.lfCharSet = OEM_CHARSET;
  108. lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
  109. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  110. lf.lfQuality = DEFAULT_QUALITY;
  111. lf.lfPitchAndFamily = FIXED_PITCH|FF_MODERN;
  112. strcpy( lf.lfFaceName, "Arial" );
  113. CFont font;
  114. font.CreateFontIndirect( &lf );
  115. CFont *pOldFont = (CFont*)pDC->SelectObject( &font );
  116. pDC->SelectObject( pOldFont );
  117. */
  118. }
  119. if( pUpdateRect ) *pUpdateRect = rect;
  120. return TRUE;
  121. }
  122. void CSensor::SetState( int nState )
  123. {
  124. CVisual::SetState( nState );
  125. if( m_pZone )
  126. m_pZone->UpdateState();
  127. }
  128. void CSensor::Enable( BOOL bEnable )
  129. {
  130. CVisual::Enable( bEnable );
  131. if( m_pZone )
  132. m_pZone->UpdateState();
  133. }
  134. void CSensor::Reset()
  135. {
  136. CVisual::Reset();
  137. if( m_pZone )
  138. m_pZone->UpdateState();
  139. }
  140. void CSensor::SetSensorArray(CSensorArray *pSensorArray)
  141. {
  142. m_pSensorArray = pSensorArray;
  143. }
  144. BOOL CSensor::GetWaveSound( LPCTSTR *pFile, int& nCount )
  145. {
  146. ASSERT( pFile );
  147. switch( GetState() )
  148. {
  149. case ALARM:
  150. if( nCount >= 3 )
  151. {
  152. pFile[0] = _T("ALARM.WAV");
  153. pFile[1] = _T("SENSOR.WAV");
  154. return TRUE;
  155. }
  156. break;
  157. case TIMEOUT:
  158. if( nCount >= 3 )
  159. {
  160. pFile[0] = _T("ATTENTION.WAV");
  161. pFile[1] = _T("TIMEOUT.WAV");
  162. pFile[2] = _T("SENSOR.WAV");
  163. nCount = 3;
  164. return TRUE;
  165. }
  166. break;
  167. }
  168. return FALSE;
  169. }
  170. double CSensor::GetRangeTilt( double dRange )
  171. {
  172. int nTilt = (int)(dRange / 20);
  173. if( nTilt > 9 ) nTilt = 9;
  174. if( nTilt < 0 ) nTilt = 0;
  175. return m_pTiltTable[ nTilt ];
  176. }
  177. bool CSensor::CameraTransform( BOOL nDevice, double angle, double range, double *pPan, double *pTilt, double *pZoom )
  178. {
  179. if( !m_pVideoCamera || m_pVideoCamera->GetType() != VC_PTZ )
  180. return false;
  181. CVideoCameraPTZ *pCameraPTZ = static_cast<CVideoCameraPTZ*>(m_pVideoCamera);
  182. if( m_bRemoteCamera )
  183. {
  184. CTransform *pTransform = GetTransform( nDevice );
  185. if( !pTransform )
  186. return false;
  187. if( !pTransform->Evaluate( angle, range, *pPan, *pTilt, *pZoom ) )
  188. return false;
  189. // scale zoom according to the range to the camera
  190. *pZoom = pCameraPTZ->GetRangeZoom( *pZoom ) / 100.0;
  191. }
  192. else
  193. {
  194. *pPan = angle - m_dPanShift;
  195. while( *pPan < 0.0 ) *pPan += 360.0;
  196. while( *pPan > 360.0 ) *pPan -= 360.0;
  197. *pTilt = GetRangeTilt( range );
  198. *pZoom = pCameraPTZ->GetRangeZoom( range ) / 100.0;
  199. }
  200. return true;
  201. }
  202. void CSensor::SetSensorPropertyWnd( CPropertySensorWnd *pWnd )
  203. {
  204. m_pPropertySensorWnd = pWnd;
  205. }
  206. void CSensor::CheckCommand()
  207. {
  208. for( INT i = 0; i < m_CommandInputSet.GetInputCount(); i++ )
  209. {
  210. BOOL bOn = FALSE;
  211. if( !m_CommandInputSet.GetInput(i)->CheckCommand( &bOn ) )
  212. continue;
  213. OnCommand( m_CommandInputSet.GetInput(i)->GetSubIndex(), bOn );
  214. }
  215. }
  216. void CSensor::OnCommand( INT nCommand, BOOL bOn )
  217. {
  218. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_WARNING, this, _T("CSensor::OnCommand"), _T("Unimplemented command %d(%s)"), nCommand, bOn ? _T("ON") : _T("OFF") );
  219. }
  220. void CSensor::OnEvent( INT nCommand, BOOL bOn )
  221. {
  222. for( INT i = 0; i < m_EventOutputSet.GetOutputCount(); i++ )
  223. {
  224. if( m_EventOutputSet.GetOutput(i)->GetSubIndex() != nCommand )
  225. continue;
  226. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CSensor::OnEvent"), _T("Event %d(%s)"), nCommand, bOn ? _T("ON") : _T("OFF") );
  227. m_EventOutputSet.GetOutput(i)->CmdOn( bOn );
  228. break;
  229. }
  230. }
  231. void CSensor::UpdateSensorProperty()
  232. {
  233. CLgPerformanceCounter pc;
  234. pc.Begin();
  235. if( m_pPropertySensorWnd )
  236. m_pPropertySensorWnd->OnUpdateSensorProperty();
  237. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CSensor::UpdateSensorProperty"), _T("Consumed time is %0.9f"), pc.End() );
  238. }
  239. void CSensor::RedrawSensor()
  240. {
  241. CLgPerformanceCounter pc;
  242. pc.Begin();
  243. RedrawUIMapObject();
  244. m_pSensorArray->SetBackgroundDirty( TRUE );
  245. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CSensor::RedrawSensor"), _T("Consumed time is %0.9f"), pc.End() );
  246. }