|
|
//----------------------------------------------------------------------------
// Laser Guard Ltd.
// Copyright � 2000-2002. All Rights Reserved.
// Version 1.0 01/01/2000
// Last modification: 08/10/2003
// PROJECT:
// SUBSYSTEM:
// FILE: Zone.cpp
// AUTHOR: Sergey Chizhevskiy
// OVERVIEW
// ~~~~~~~~
// Source file of Zone.cpp
//----------------------------------------------------------------------------
// Zone.cpp: implementation of the CZone class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
//#include "chicago.h"
#include "Visual.h"
#include "Sensor.h"
#include "SensorArray.h"
#include "Zone.h"
#include "..\..\LgLib\Version.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CZone::CZone(){ m_strName = "ZONE"; m_nNumber = -1; m_pSensorArray = NULL; m_nCount = 0; m_ppSensors = NULL; m_bSoundAlarm = TRUE;
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CZone::CZone") );}
CZone::~CZone(){ if( m_ppSensors ) delete [] m_ppSensors;
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CZone::~CZone") );}
BOOL CZone::Create( CSensorArray *pSensorArray, int nNumber ){ m_pSensorArray = pSensorArray; m_nNumber = nNumber;
m_nState = CSensor::UNKNOWN;
m_nCount = 0; for( int i = 0; i < m_pSensorArray->GetSensorCount(); i++ ) if( m_pSensorArray->GetSensor(i)->GetZoneIndex() == m_nNumber ) m_nCount++;
m_ppSensors = new CSensor*[ m_nCount ]; m_nCount = 0; m_Position.x = m_Position.y = 0.0; m_Rect.left = m_Rect.top = 1.0; m_Rect.bottom = m_Rect.right = 0.0; for( i = 0; i < m_pSensorArray->GetSensorCount(); i++ ) { if( m_pSensorArray->GetSensor(i)->GetZoneIndex() == m_nNumber ) { CSensor *pSensor = m_pSensorArray->GetSensor(i); pSensor->SetZone( this ); m_ppSensors[ m_nCount++ ] = pSensor; m_Position.x += pSensor->GetPosition().x; m_Position.y += pSensor->GetPosition().y; if( m_Rect.left > pSensor->GetPosition().x ) m_Rect.left = pSensor->GetPosition().x; if( m_Rect.right < pSensor->GetPosition().x ) m_Rect.right = pSensor->GetPosition().x; if( m_Rect.top > pSensor->GetPosition().y ) m_Rect.top = pSensor->GetPosition().y; if( m_Rect.bottom < pSensor->GetPosition().y ) m_Rect.bottom = pSensor->GetPosition().y;
} } if( m_nCount > 0 ) { m_Position.x /= m_nCount; m_Position.y /= m_nCount; }
return TRUE;}
void CZone::UpdateState(){ int nState = UNKNOWN;
for( int i = 0; i < m_nCount; i++ ) { if( m_ppSensors[i]->GetState() > nState ) { nState = m_ppSensors[i]->GetState(); } }
CVisual::SetState( nState );}
void CZone::Reset(){ for( int i = 0; i < m_nCount; i++ ) m_ppSensors[i]->Reset();
// PARANOID: Zone state updated in CSensor::Reset;
UpdateState();}
void CZone::Enable( BOOL bEnable ){ for( int i = 0; i < m_nCount; i++ ) m_ppSensors[i]->Enable( bEnable );
// PARANOID: Zone state updated in CSensor::Enable;
UpdateState();}
BOOL CZone::Paint(CDC *pDC, CRect &viewRect, CSize &mapSize, SDPOINT &mapShift, double mapScale, BOOL bInverse, BOOL bBigSize, CRect *pUpdateRect){ return TRUE; // WARNING: TEST ONLY!!!
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 - 18, p.x + 24, p.y + 18 );// rect.SetRect( p.x - 4, p.y - 4, p.x + 4, p.y + 4 );
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_WORDBREAK | DT_CENTER ); pDC->SetTextColor( nOldTextColor ); pDC->SetBkMode( nOldBkMode ); } else {// rect.SetRect( p.x - 8, p.y - 8, p.x + 8, p.y + 8 );
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;}
|