//---------------------------------------------------------------------------- // Laser Guard Ltd. // Copyright © 2000-2002. All Rights Reserved. // Version 1.0 01/01/2000 // Last modification: 08/10/2003 // PROJECT: // SUBSYSTEM: // FILE: Sensor.cpp // AUTHOR: Sergey Chizhevskiy // OVERVIEW // ~~~~~~~~ // Source file of Sensor.cpp //---------------------------------------------------------------------------- // Sensor.cpp: implementation of the CSensor class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" //#include "Chicago.h" //#include "MapData.h" #include "Sensor.h" #include "AuxLib.h" #include "..\..\LgLib\Version.h" #include "..\..\LgLib\LgPerformanceCounter.h" #include "Zone.h" #include "SocketCCC.h" #include "CameraPTZ.h" #include "..\Chicago\PropertySensorWnd.h" #include "..\Chicago\PropertySensorWnd.h" #include "SensorArray.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CSensor::CSensor() { m_Position.x = m_Position.y = 0.5; m_iAddress = 0; m_nSocket = -1; m_nIndex = -1; m_nZone = -1; m_dwTime = 0UL; m_pZone = NULL; m_pSensorArray = NULL; m_pVideoCamera = NULL; m_pTransform[0] = NULL; m_pTransform[1] = NULL; m_nTemplateType = -1; m_nTemplateIndex = -1; m_nAddressCCC = -1; m_pPropertySensorWnd = NULL; m_bRemoteCamera = FALSE; m_dPanShift = 0; for( int i = 0; i < 10; i++ ) m_pTiltTable[i] = 0; m_nImageCount = 5; LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CSensor::CSensor") ); } CSensor::~CSensor() { if( m_pTransform[0] ) delete m_pTransform[0]; if( m_pTransform[1] ) delete m_pTransform[1]; LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CSensor::~CSensor") ); } BOOL CSensor::Paint( CDC *pDC, CRect& viewRect, CSize& mapSize, SDPOINT& mapShift, double mapScale, BOOL bInverse, BOOL bBigSize, CRect *pUpdateRect ) { SDPOINT shift( m_Position.x - mapShift.x, m_Position.y - mapShift.y ); CPoint p = CalcDrawPoint( viewRect, mapSize, shift, mapScale ); if( !viewRect.PtInRect(p) ) return FALSE; CRect rect; COLORREF color = GetStateColor( bInverse ); if( bBigSize ) { rect.SetRect( p.x - 24, p.y - 10, p.x + 24, p.y + 10 ); pDC->FillSolidRect( &rect, color ); // CBrush brush( color ); // pDC->FillRect( &rect, &brush ); INT nOldBkMode = pDC->SetBkMode( TRANSPARENT ); INT nOldTextColor = pDC->SetTextColor( 0 ); pDC->DrawText( m_strName, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER ); pDC->SetTextColor( nOldTextColor ); pDC->SetBkMode( nOldBkMode ); } else { rect.SetRect( p.x - 2, p.y - 2, p.x + 2, p.y + 2 ); pDC->FillSolidRect( &rect, color ); // CBrush brush( color ); // pDC->FillRect( &rect, &brush ); } if( bBigSize ) { /* LOGFONT lf; lf.lfHeight = -10; lf.lfWidth = 0; lf.lfEscapement = 0; lf.lfOrientation = 0; lf.lfWeight = 1000; lf.lfItalic = FALSE; lf.lfUnderline = FALSE; lf.lfStrikeOut = FALSE; lf.lfCharSet = OEM_CHARSET; lf.lfOutPrecision = OUT_DEFAULT_PRECIS; lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; lf.lfQuality = DEFAULT_QUALITY; lf.lfPitchAndFamily = FIXED_PITCH|FF_MODERN; strcpy( lf.lfFaceName, "Arial" ); CFont font; font.CreateFontIndirect( &lf ); CFont *pOldFont = (CFont*)pDC->SelectObject( &font ); pDC->SelectObject( pOldFont ); */ } if( pUpdateRect ) *pUpdateRect = rect; return TRUE; } void CSensor::SetState( int nState ) { CVisual::SetState( nState ); if( m_pZone ) m_pZone->UpdateState(); } void CSensor::Enable( BOOL bEnable ) { CVisual::Enable( bEnable ); if( m_pZone ) m_pZone->UpdateState(); } void CSensor::Reset() { CVisual::Reset(); if( m_pZone ) m_pZone->UpdateState(); } void CSensor::SetSensorArray(CSensorArray *pSensorArray) { m_pSensorArray = pSensorArray; } BOOL CSensor::GetWaveSound( LPCTSTR *pFile, int& nCount ) { ASSERT( pFile ); switch( GetState() ) { case ALARM: if( nCount >= 3 ) { pFile[0] = _T("ALARM.WAV"); pFile[1] = _T("SENSOR.WAV"); return TRUE; } break; case TIMEOUT: if( nCount >= 3 ) { pFile[0] = _T("ATTENTION.WAV"); pFile[1] = _T("TIMEOUT.WAV"); pFile[2] = _T("SENSOR.WAV"); nCount = 3; return TRUE; } break; } return FALSE; } double CSensor::GetRangeTilt( double dRange ) { int nTilt = (int)(dRange / 20); if( nTilt > 9 ) nTilt = 9; if( nTilt < 0 ) nTilt = 0; return m_pTiltTable[ nTilt ]; } bool CSensor::CameraTransform( BOOL nDevice, double angle, double range, double *pPan, double *pTilt, double *pZoom ) { if( !m_pVideoCamera || m_pVideoCamera->GetType() != VC_PTZ ) return false; CVideoCameraPTZ *pCameraPTZ = static_cast(m_pVideoCamera); if( m_bRemoteCamera ) { CTransform *pTransform = GetTransform( nDevice ); if( !pTransform ) return false; if( !pTransform->Evaluate( angle, range, *pPan, *pTilt, *pZoom ) ) return false; // scale zoom according to the range to the camera *pZoom = pCameraPTZ->GetRangeZoom( *pZoom ) / 100.0; } else { *pPan = angle - m_dPanShift; while( *pPan < 0.0 ) *pPan += 360.0; while( *pPan > 360.0 ) *pPan -= 360.0; *pTilt = GetRangeTilt( range ); *pZoom = pCameraPTZ->GetRangeZoom( range ) / 100.0; } return true; } void CSensor::SetSensorPropertyWnd( CPropertySensorWnd *pWnd ) { m_pPropertySensorWnd = pWnd; } void CSensor::CheckCommand() { for( INT i = 0; i < m_CommandInputSet.GetInputCount(); i++ ) { BOOL bOn = FALSE; if( !m_CommandInputSet.GetInput(i)->CheckCommand( &bOn ) ) continue; OnCommand( m_CommandInputSet.GetInput(i)->GetSubIndex(), bOn ); } } void CSensor::OnCommand( INT nCommand, BOOL bOn ) { LGLOG( LOG_LEVEL_LOW, LOG_TYPE_WARNING, this, _T("CSensor::OnCommand"), _T("Unimplemented command %d(%s)"), nCommand, bOn ? _T("ON") : _T("OFF") ); } void CSensor::OnEvent( INT nCommand, BOOL bOn ) { for( INT i = 0; i < m_EventOutputSet.GetOutputCount(); i++ ) { if( m_EventOutputSet.GetOutput(i)->GetSubIndex() != nCommand ) continue; LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CSensor::OnEvent"), _T("Event %d(%s)"), nCommand, bOn ? _T("ON") : _T("OFF") ); m_EventOutputSet.GetOutput(i)->CmdOn( bOn ); break; } } void CSensor::UpdateSensorProperty() { CLgPerformanceCounter pc; pc.Begin(); if( m_pPropertySensorWnd ) m_pPropertySensorWnd->OnUpdateSensorProperty(); LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CSensor::UpdateSensorProperty"), _T("Consumed time is %0.9f"), pc.End() ); } void CSensor::RedrawSensor() { CLgPerformanceCounter pc; pc.Begin(); RedrawUIMapObject(); m_pSensorArray->SetBackgroundDirty( TRUE ); LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CSensor::RedrawSensor"), _T("Consumed time is %0.9f"), pc.End() ); }