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.
1066 lines
27 KiB
1066 lines
27 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 27/04/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: Device.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of Device.cpp
|
|
//----------------------------------------------------------------------------
|
|
#include "stdafx.h"
|
|
#include "ObjectFactory.h"
|
|
|
|
#ifdef SETUP_LGS_PROJECT
|
|
#include "Resource.h"
|
|
#endif
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
using namespace SETUP_LGS_NAMESPACE;
|
|
|
|
/***************************************************************************
|
|
|
|
***************************************************************************/
|
|
CPin::CPin()
|
|
{
|
|
m_Owner.nType = DT_NONE;
|
|
m_Owner.nIndex = -1;
|
|
m_Owner.nPin = -1;
|
|
|
|
m_pDevice = NULL;
|
|
m_nDeviceCount = 0;
|
|
m_nDeviceMax = 0;
|
|
|
|
m_nPinType = PT_NONE;
|
|
m_nTruePinType = PT_NONE;
|
|
|
|
m_Pos = CPoint( 0, 0 );
|
|
|
|
m_Name = _T( "ERROR" );
|
|
}
|
|
|
|
CPin::~CPin()
|
|
{
|
|
if( m_pDevice )
|
|
free( m_pDevice );
|
|
}
|
|
|
|
COLORREF CPin::GetColor()
|
|
{
|
|
switch( m_nPinType )
|
|
{
|
|
case PT_NONE:
|
|
break;
|
|
case PT_VIDEO_IN:
|
|
case PT_VIDEO_OUT:
|
|
return RGB( 0xFF,0xFF,0 );
|
|
case PT_RABBIT_IN:
|
|
case PT_RABBIT_OUT:
|
|
return RGB( 0x7F,0x7F,0x7F );
|
|
case PT_SOCKET_MD:
|
|
return RGB( 0,0xFF,0 );
|
|
case PT_SOCKET_PTZ:
|
|
return RGB( 0xFF,0,0xFF );
|
|
case PT_SOCKET_LGS:
|
|
return RGB( 0,0x7F,0 );
|
|
case PT_SOCKET_VM:
|
|
return RGB( 0x7F,0,0x7F );
|
|
}
|
|
|
|
ASSERT( NULL ); // color definition should be for each pin type
|
|
|
|
return 0;
|
|
}
|
|
|
|
void CPin::Initialize( int nOwnerType, int nOwnerPin, int nPinType, int nTruePinType, int nDeviceMax, CPoint pos, LPCTSTR pName )
|
|
{
|
|
ASSERT( m_nPinType == PT_NONE );
|
|
ASSERT( m_nTruePinType == PT_NONE );
|
|
|
|
m_Owner.nType = nOwnerType;
|
|
m_Owner.nPin = nOwnerPin;
|
|
m_nPinType = nPinType;
|
|
m_nTruePinType = nTruePinType;
|
|
m_nDeviceMax = nDeviceMax;
|
|
m_Pos = pos;
|
|
|
|
/*
|
|
switch( m_nPinType )
|
|
{
|
|
case PT_NONE: ASSERT(NULL);
|
|
break;
|
|
case PT_VIDEO_IN:
|
|
m_Name = _T("VIDEO IN");
|
|
break;
|
|
case PT_VIDEO_OUT:
|
|
m_Name = _T("VIDEO OUT");
|
|
break;
|
|
case PT_RABBIT_IN:
|
|
m_Name = _T("RABBIT IN");
|
|
break;
|
|
case PT_RABBIT_OUT:
|
|
m_Name = _T("RABBIT OUT");
|
|
break;
|
|
case PT_SOCKET:
|
|
m_Name = _T("SOCKET");
|
|
break;
|
|
}
|
|
*/
|
|
|
|
m_Name = pName;
|
|
}
|
|
|
|
BOOL CPin::Connect( CPin *pPin )
|
|
{
|
|
ASSERT( m_nPinType != PT_NONE );
|
|
ASSERT( m_nTruePinType != PT_NONE );
|
|
ASSERT( pPin );
|
|
ASSERT( pPin->m_nPinType != PT_NONE );
|
|
ASSERT( pPin->m_nTruePinType != PT_NONE );
|
|
ASSERT( m_Owner.nIndex != -1 );
|
|
ASSERT( pPin->m_Owner.nIndex != -1 );
|
|
|
|
if( pPin != this && // impossible to connect to itself
|
|
m_nTruePinType == pPin->m_nPinType &&
|
|
m_nPinType == pPin->m_nTruePinType && // possible to connect only compatible pins
|
|
m_nDeviceCount <= m_nDeviceMax &&
|
|
pPin->m_nDeviceCount <= pPin->m_nDeviceMax ) // possible to connect not more then "m_nDeviceMax" pins to pin
|
|
{
|
|
BOOL bFound = FALSE;
|
|
|
|
for( int i = 0; i < m_nDeviceCount; i++ )
|
|
{
|
|
if( ( m_pDevice[i].nType == pPin->m_Owner.nType ) &&
|
|
( m_pDevice[i].nIndex == pPin->m_Owner.nIndex ) &&
|
|
( m_pDevice[i].nPin == pPin->m_Owner.nPin ) )
|
|
bFound = TRUE;
|
|
}
|
|
|
|
if( !bFound )
|
|
{
|
|
m_pDevice = (DID*)realloc( m_pDevice, sizeof( DID ) * (m_nDeviceCount + 1) );
|
|
m_pDevice[ m_nDeviceCount ] = pPin->m_Owner;
|
|
m_nDeviceCount++;
|
|
|
|
pPin->m_pDevice = (DID*)realloc( pPin->m_pDevice, sizeof( DID ) * (pPin->m_nDeviceCount + 1) );
|
|
pPin->m_pDevice[ pPin->m_nDeviceCount ] = m_Owner;
|
|
pPin->m_nDeviceCount++;
|
|
return TRUE;
|
|
}
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
BOOL CPin::Disconnect( CPin *pPin )
|
|
{
|
|
ASSERT( m_nPinType != PT_NONE );
|
|
ASSERT( m_nTruePinType != PT_NONE );
|
|
ASSERT( m_Owner.nIndex != -1 );
|
|
|
|
if( pPin )
|
|
{
|
|
ASSERT( pPin->m_nPinType != PT_NONE );
|
|
ASSERT( pPin->m_nTruePinType != PT_NONE );
|
|
ASSERT( pPin->m_Owner.nIndex != -1 );
|
|
|
|
for( int i = 0; i < m_nDeviceCount; i++ )
|
|
{
|
|
if( ( m_pDevice[i].nType == pPin->m_Owner.nType ) &&
|
|
( m_pDevice[i].nIndex == pPin->m_Owner.nIndex ) &&
|
|
( m_pDevice[i].nPin == pPin->m_Owner.nPin ) )
|
|
{
|
|
m_nDeviceCount--;
|
|
m_pDevice[i] = m_pDevice[ m_nDeviceCount ]; // move last to deleting position
|
|
m_pDevice = (DID*)realloc( m_pDevice, sizeof( DID ) * m_nDeviceCount ); // deallocate unusable DID
|
|
return TRUE;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for( int i = 0; i < m_nDeviceCount; i++ )
|
|
{
|
|
CDevice *pDevice = GetOF()->DeviceGet( m_pDevice[i].nIndex, m_pDevice[i].nType );
|
|
CPin *pPin = pDevice->GetPin( m_pDevice[i].nPin );
|
|
pPin->Disconnect( this );
|
|
}
|
|
|
|
if( m_pDevice )
|
|
{
|
|
free( m_pDevice );
|
|
m_pDevice = NULL;
|
|
}
|
|
m_nDeviceCount = 0;
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
void CPin::Serialize(CArchive& ar)
|
|
{
|
|
if (ar.IsStoring())
|
|
{
|
|
ar << m_Pos.x;
|
|
ar << m_Pos.y;
|
|
ar << m_nPinType;
|
|
ar << m_nTruePinType;
|
|
ar << m_Owner.nType;
|
|
ar << m_Owner.nIndex;
|
|
ar << m_Owner.nPin;
|
|
ar << m_nDeviceCount;
|
|
for( int i = 0; i < m_nDeviceCount; i++ )
|
|
{
|
|
ar << m_pDevice[i].nType;
|
|
ar << m_pDevice[i].nIndex;
|
|
ar << m_pDevice[i].nPin;
|
|
}
|
|
ar << m_Name;
|
|
}
|
|
else
|
|
{
|
|
ar >> m_Pos.x;
|
|
ar >> m_Pos.y;
|
|
ar >> m_nPinType;
|
|
ar >> m_nTruePinType;
|
|
ar >> m_Owner.nType;
|
|
ar >> m_Owner.nIndex;
|
|
ar >> m_Owner.nPin;
|
|
ar >> m_nDeviceCount;
|
|
m_pDevice = (DID*)realloc( m_pDevice, sizeof( DID ) * m_nDeviceCount );
|
|
for( int i = 0; i < m_nDeviceCount; i++ )
|
|
{
|
|
ar >> m_pDevice[i].nType;
|
|
ar >> m_pDevice[i].nIndex;
|
|
ar >> m_pDevice[i].nPin;
|
|
}
|
|
ar >> m_Name;
|
|
}
|
|
}
|
|
|
|
/***************************************************************************
|
|
|
|
***************************************************************************/
|
|
CDevice::CDevice()
|
|
{
|
|
m_hIcon[0] = NULL;
|
|
m_hIcon[1] = NULL;
|
|
m_nIndex = -1;
|
|
m_pPin = NULL;
|
|
m_nPin = 0;
|
|
m_Name = _T("UNKNOWN");
|
|
m_pOF = NULL;
|
|
}
|
|
|
|
CDevice::~CDevice()
|
|
{
|
|
if( m_hIcon[0] )
|
|
DeleteObject( m_hIcon[0] );
|
|
if( m_hIcon[1] )
|
|
DeleteObject( m_hIcon[1] );
|
|
|
|
if( m_pPin )
|
|
delete [] m_pPin;
|
|
}
|
|
|
|
void CDevice::CreatePins( PIN_DESC* pPinDesc, int nCount )
|
|
{
|
|
m_nPin = nCount;
|
|
m_pPin = new CPin[nCount];
|
|
for( int i = 0; i < nCount; i++ )
|
|
m_pPin[i].Initialize( GetType(), i, pPinDesc[i].nPinType, pPinDesc[i].nTruePinType, pPinDesc[i].nDeviceMax, *pPinDesc[i].pPos, pPinDesc[i].pName );
|
|
}
|
|
|
|
CPin *CDevice::GetFreePin( int nType, int nIndex )
|
|
{
|
|
// ASSERT( nIndex < m_nPin );
|
|
|
|
for( int i = nIndex; i < m_nPin; i++ )
|
|
{
|
|
if( m_pPin[i].GetType() == nType && m_pPin[i].IsFree() )
|
|
{
|
|
return &m_pPin[i];
|
|
}
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
BOOL CDevice::IsPossibleToConnect( CDevice *pDevice )
|
|
{
|
|
if( pDevice )
|
|
{
|
|
for( int i = 0; i < m_nPin; i++ )
|
|
{
|
|
for( int j = 0; j < pDevice->m_nPin; j++ )
|
|
{
|
|
if( m_pPin[i].GetType() == pDevice->m_pPin[j].GetTrueType() &&
|
|
m_pPin[i].IsFree() && pDevice->m_pPin[j].IsFree())
|
|
return TRUE;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for( int i = 0; i < m_nPin; i++ )
|
|
{
|
|
if( m_pPin[i].IsFree() )
|
|
return TRUE;
|
|
}
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
void CDevice::SetIndex( int nIndex )
|
|
{
|
|
m_nIndex = nIndex;
|
|
|
|
for( int i = 0; i < GetPinCount(); i++ )
|
|
{
|
|
GetPin( i )->m_Owner.nIndex = nIndex;
|
|
GetPin( i )->m_pOF = GetOF();
|
|
}
|
|
}
|
|
|
|
void CDevice::Serialize(CArchive& ar)
|
|
{
|
|
if (ar.IsStoring())
|
|
{
|
|
ar << m_Pos.x;
|
|
ar << m_Pos.y;
|
|
ar << m_Name;
|
|
}
|
|
else
|
|
{
|
|
ar >> m_Pos.x;
|
|
ar >> m_Pos.y;
|
|
ar >> m_Name;
|
|
}
|
|
|
|
for( int i = 0; i < GetPinCount(); i++ )
|
|
{
|
|
GetPin(i)->Serialize( ar );
|
|
GetPin(i)->m_pOF = GetOF();
|
|
}
|
|
}
|
|
|
|
void CDevice::Draw( CDC *pDC, BOOL bActive, CPoint shift, double scale )
|
|
{
|
|
CPoint p( (int)(m_Pos.x * scale) - NORMAL_SIZE - shift.x,
|
|
(int)(m_Pos.y * scale) - NORMAL_SIZE - shift.y );
|
|
if( bActive )
|
|
{
|
|
pDC->DrawIcon( p, m_hIcon[1] );
|
|
}
|
|
else
|
|
{
|
|
pDC->DrawIcon( p, m_hIcon[0] );
|
|
}
|
|
}
|
|
|
|
/***************************************************************************
|
|
|
|
***************************************************************************/
|
|
CDeviceCamera::CDeviceCamera()
|
|
{
|
|
PIN_DESC pPD[] =
|
|
{
|
|
{ PT_VIDEO_OUT, PT_VIDEO_IN, 1, &CPoint( 4,15 ), 0, _T("VIDEO OUT") }
|
|
};
|
|
CreatePins( pPD, sizeof(pPD) / sizeof(pPD[0]) );
|
|
|
|
m_Name = _T("Fixed camera");
|
|
}
|
|
|
|
CDeviceCamera::~CDeviceCamera()
|
|
{
|
|
}
|
|
|
|
/***************************************************************************
|
|
|
|
***************************************************************************/
|
|
CDeviceLGS::CDeviceLGS()
|
|
{
|
|
PIN_DESC pPD[] =
|
|
{
|
|
{ PT_SOCKET_MD, PT_SOCKET_MD, INT_MAX, &CPoint( 15,31 ), 0, _T("SOCKET MD") }
|
|
};
|
|
CreatePins( pPD, sizeof(pPD) / sizeof(pPD[0]) );
|
|
|
|
m_Name = _T("Multi-drop LGS sensor");
|
|
|
|
m_nSubType = ST_MULTI;
|
|
m_nAddress = 0;
|
|
}
|
|
|
|
CDeviceLGS::~CDeviceLGS()
|
|
{
|
|
}
|
|
|
|
void CDeviceLGS::Serialize( CArchive& ar )
|
|
{
|
|
CDevice::Serialize( ar );
|
|
if (ar.IsStoring())
|
|
{
|
|
ar << m_nSubType;
|
|
ar << m_nAddress;
|
|
}
|
|
else
|
|
{
|
|
ar >> m_nSubType;
|
|
ar >> m_nAddress;
|
|
}
|
|
}
|
|
|
|
void CDeviceLGS::ChangeSubType( int nSubType )
|
|
{
|
|
GetOF()->DeviceDisconnect( this );
|
|
m_nSubType = nSubType;
|
|
CPin *pPin = GetPin( 0 );
|
|
switch( m_nSubType )
|
|
{
|
|
case ST_MULTI:
|
|
pPin->m_nPinType = PT_SOCKET_MD;
|
|
pPin->m_nTruePinType = PT_SOCKET_MD;
|
|
pPin->m_nDeviceMax = INT_MAX;
|
|
pPin->m_Name = _T("SOCKET MD");
|
|
break;
|
|
case ST_SINGLE:
|
|
pPin->m_nPinType = PT_SOCKET_LGS;
|
|
pPin->m_nTruePinType = PT_SOCKET_LGS;
|
|
pPin->m_nDeviceMax = 1;
|
|
pPin->m_Name = _T("SOCKET LGS");
|
|
break;
|
|
}
|
|
}
|
|
/***************************************************************************
|
|
|
|
***************************************************************************/
|
|
CDeviceMigvan::CDeviceMigvan()
|
|
{
|
|
m_bAuto = FALSE;
|
|
m_pHardwareID[0] = 0;
|
|
m_pHardwareID[1] = 0;
|
|
m_pHardwareID[2] = 0;
|
|
m_pHardwareID[3] = 0;
|
|
m_pHardwareID[4] = 0;
|
|
}
|
|
|
|
CDeviceMigvan::~CDeviceMigvan()
|
|
{
|
|
}
|
|
|
|
void CDeviceMigvan::Serialize( CArchive& ar )
|
|
{
|
|
CDevice::Serialize( ar );
|
|
if (ar.IsStoring())
|
|
{
|
|
ar << m_pHardwareID[0];
|
|
ar << m_pHardwareID[1];
|
|
ar << m_pHardwareID[2];
|
|
ar << m_pHardwareID[3];
|
|
ar << m_pHardwareID[4];
|
|
ar << m_bAuto;
|
|
}
|
|
else
|
|
{
|
|
ar >> m_pHardwareID[0];
|
|
ar >> m_pHardwareID[1];
|
|
ar >> m_pHardwareID[2];
|
|
ar >> m_pHardwareID[3];
|
|
ar >> m_pHardwareID[4];
|
|
ar >> m_bAuto;
|
|
}
|
|
}
|
|
/***************************************************************************
|
|
|
|
***************************************************************************/
|
|
CDeviceMigvanCameraPTZ::CDeviceMigvanCameraPTZ()
|
|
{
|
|
PIN_DESC pPD[] =
|
|
{
|
|
{ PT_VIDEO_OUT, PT_VIDEO_IN, 1, &CPoint( 4,15 ), 0, _T("VIDEO OUT") },
|
|
{ PT_SOCKET_PTZ, PT_SOCKET_PTZ, INT_MAX, &CPoint( 15,31 ), 0, _T("SOCKET PTZ") }
|
|
};
|
|
CreatePins( pPD, sizeof(pPD) / sizeof(pPD[0]) );
|
|
|
|
m_Name = _T("Migvan PTZ camera");
|
|
}
|
|
|
|
CDeviceMigvanCameraPTZ::~CDeviceMigvanCameraPTZ()
|
|
{
|
|
}
|
|
|
|
/***************************************************************************
|
|
|
|
***************************************************************************/
|
|
CDeviceMigvanVM8x4::CDeviceMigvanVM8x4()
|
|
{
|
|
PIN_DESC pPD[] =
|
|
{
|
|
{ PT_VIDEO_OUT, PT_VIDEO_IN, 1, &CPoint( 5,11 ), 0, _T("VIDEO OUT 1") },
|
|
{ PT_VIDEO_OUT, PT_VIDEO_IN, 1, &CPoint( 5,14 ), 1, _T("VIDEO OUT 2") },
|
|
{ PT_VIDEO_OUT, PT_VIDEO_IN, 1, &CPoint( 5,17 ), 2, _T("VIDEO OUT 3") },
|
|
{ PT_VIDEO_OUT, PT_VIDEO_IN, 1, &CPoint( 5,20 ), 3, _T("VIDEO OUT 4") },
|
|
{ PT_VIDEO_IN, PT_VIDEO_OUT, 1, &CPoint( 26, 5 ), 0, _T("VIDEO IN 1") },
|
|
{ PT_VIDEO_IN, PT_VIDEO_OUT, 1, &CPoint( 26, 8 ), 1, _T("VIDEO IN 2") },
|
|
{ PT_VIDEO_IN, PT_VIDEO_OUT, 1, &CPoint( 26,11 ), 2, _T("VIDEO IN 3") },
|
|
{ PT_VIDEO_IN, PT_VIDEO_OUT, 1, &CPoint( 26,14 ), 3, _T("VIDEO IN 4") },
|
|
{ PT_VIDEO_IN, PT_VIDEO_OUT, 1, &CPoint( 26,17 ), 4, _T("VIDEO IN 5") },
|
|
{ PT_VIDEO_IN, PT_VIDEO_OUT, 1, &CPoint( 26,20 ), 5, _T("VIDEO IN 6") },
|
|
{ PT_VIDEO_IN, PT_VIDEO_OUT, 1, &CPoint( 26,23 ), 6, _T("VIDEO IN 7") },
|
|
{ PT_VIDEO_IN, PT_VIDEO_OUT, 1, &CPoint( 26,26 ), 7, _T("VIDEO IN 8") },
|
|
{ PT_SOCKET_VM, PT_SOCKET_VM, INT_MAX, &CPoint( 16,31 ), 0, _T("SOCKET VM") }
|
|
};
|
|
CreatePins( pPD, sizeof(pPD) / sizeof(pPD[0]) );
|
|
|
|
m_Name = _T("Migvan video matrix");
|
|
}
|
|
|
|
CDeviceMigvanVM8x4::~CDeviceMigvanVM8x4()
|
|
{
|
|
}
|
|
|
|
/***************************************************************************
|
|
|
|
***************************************************************************/
|
|
CDeviceRabbit::CDeviceRabbit()
|
|
{
|
|
PIN_DESC pPD[] =
|
|
{
|
|
{ PT_VIDEO_OUT, PT_VIDEO_IN, 1, &CPoint( 5,11 ), 0, _T("VIDEO OUT 1") },
|
|
{ PT_VIDEO_OUT, PT_VIDEO_IN, 1, &CPoint( 5,19 ), 1, _T("VIDEO OUT 2") },
|
|
{ PT_VIDEO_IN, PT_VIDEO_OUT, 1, &CPoint( 26, 9 ), 0, _T("VIDEO IN 1-1") },
|
|
{ PT_VIDEO_IN, PT_VIDEO_OUT, 1, &CPoint( 26,13 ), 1, _T("VIDEO IN 1-2") },
|
|
{ PT_VIDEO_IN, PT_VIDEO_OUT, 1, &CPoint( 26,17 ), 2, _T("VIDEO IN 2-1") },
|
|
{ PT_VIDEO_IN, PT_VIDEO_OUT, 1, &CPoint( 26,21 ), 3, _T("VIDEO IN 2-2") },
|
|
{ PT_SOCKET_MD, PT_SOCKET_MD, INT_MAX, &CPoint( 16,31 ), 0, _T("SOCKET MD") },
|
|
{ PT_RABBIT_IN, PT_RABBIT_OUT, 1, &CPoint( 16,0 ), 0, _T("CONNECTION TO CAMERA") }
|
|
};
|
|
CreatePins( pPD, sizeof(pPD) / sizeof(pPD[0]) );
|
|
|
|
m_Name = _T("Rabbit controller");
|
|
|
|
m_nAddress = 0;
|
|
}
|
|
|
|
CDeviceRabbit::~CDeviceRabbit()
|
|
{
|
|
}
|
|
|
|
void CDeviceRabbit::Serialize( CArchive& ar )
|
|
{
|
|
CDevice::Serialize( ar );
|
|
if (ar.IsStoring())
|
|
{
|
|
ar << m_nAddress;
|
|
}
|
|
else
|
|
{
|
|
ar >> m_nAddress;
|
|
}
|
|
}
|
|
|
|
/***************************************************************************
|
|
|
|
***************************************************************************/
|
|
CDeviceRabbitCamera::CDeviceRabbitCamera()
|
|
{
|
|
PIN_DESC pPD[] =
|
|
{
|
|
{ PT_VIDEO_OUT, PT_VIDEO_IN, 1, &CPoint( 4,15 ), 0, _T("VIDEO OUT") },
|
|
{ PT_RABBIT_OUT, PT_RABBIT_IN, 1, &CPoint( 15,31 ), 0, _T("CONNECTION TO RABBIT") }
|
|
};
|
|
CreatePins( pPD, sizeof(pPD) / sizeof(pPD[0]) );
|
|
|
|
m_Name = _T("PTZ Migvan&Rabbit camera");
|
|
}
|
|
|
|
CDeviceRabbitCamera::~CDeviceRabbitCamera()
|
|
{
|
|
}
|
|
|
|
/***************************************************************************
|
|
|
|
***************************************************************************/
|
|
CDeviceSocket::CDeviceSocket()
|
|
{
|
|
PIN_DESC pPD[] =
|
|
{
|
|
{ PT_SOCKET_MD, PT_SOCKET_MD, INT_MAX, &CPoint( 31,16 ), 0, _T("SOCKET MD") }
|
|
};
|
|
CreatePins( pPD, sizeof(pPD) / sizeof(pPD[0]) );
|
|
|
|
m_Name = _T("Computer communication socket");
|
|
|
|
m_nSubType = ST_MD;
|
|
m_Port = _T("COM1");
|
|
m_BaudRate = _T("19200");
|
|
}
|
|
|
|
CDeviceSocket::~CDeviceSocket()
|
|
{
|
|
}
|
|
|
|
void CDeviceSocket::Serialize( CArchive& ar )
|
|
{
|
|
CDevice::Serialize( ar );
|
|
if (ar.IsStoring())
|
|
{
|
|
ar << m_nSubType;
|
|
ar << m_Port;
|
|
ar << m_BaudRate;
|
|
}
|
|
else
|
|
{
|
|
ar >> m_nSubType;
|
|
ar >> m_Port;
|
|
ar >> m_BaudRate;
|
|
}
|
|
}
|
|
|
|
void CDeviceSocket::ChangeSubType( int nSubType )
|
|
{
|
|
GetOF()->DeviceDisconnect( this );
|
|
m_nSubType = nSubType;
|
|
CPin *pPin = GetPin( 0 );
|
|
switch( m_nSubType )
|
|
{
|
|
case ST_MD:
|
|
pPin->m_nPinType = PT_SOCKET_MD;
|
|
pPin->m_nTruePinType = PT_SOCKET_MD;
|
|
pPin->m_nDeviceMax = INT_MAX;
|
|
pPin->m_Name = _T("SOCKET MD");
|
|
break;
|
|
case ST_PTZ:
|
|
pPin->m_nPinType = PT_SOCKET_PTZ;
|
|
pPin->m_nTruePinType = PT_SOCKET_PTZ;
|
|
pPin->m_nDeviceMax = INT_MAX;
|
|
pPin->m_Name = _T("SOCKET PTZ");
|
|
break;
|
|
case ST_LGS:
|
|
pPin->m_nPinType = PT_SOCKET_LGS;
|
|
pPin->m_nTruePinType = PT_SOCKET_LGS;
|
|
pPin->m_nDeviceMax = 1;
|
|
pPin->m_Name = _T("SOCKET LGS");
|
|
break;
|
|
case ST_VM:
|
|
pPin->m_nPinType = PT_SOCKET_VM;
|
|
pPin->m_nTruePinType = PT_SOCKET_VM;
|
|
pPin->m_nDeviceMax = INT_MAX;
|
|
pPin->m_Name = _T("SOCKET VM");
|
|
break;
|
|
}
|
|
}
|
|
|
|
/***************************************************************************
|
|
|
|
***************************************************************************/
|
|
CDeviceVideoIn::CDeviceVideoIn()
|
|
{
|
|
PIN_DESC pPD[] =
|
|
{
|
|
{ PT_VIDEO_IN, PT_VIDEO_OUT, 1, &CPoint( 31, 16 ), 0, _T("VIDEO IN") }
|
|
};
|
|
CreatePins( pPD, sizeof(pPD) / sizeof(pPD[0]) );
|
|
|
|
m_Name = _T("Computer video input");
|
|
}
|
|
|
|
CDeviceVideoIn::~CDeviceVideoIn()
|
|
{
|
|
}
|
|
|
|
/***************************************************************************
|
|
|
|
***************************************************************************/
|
|
CObjectFactory::CObjectFactory()
|
|
{
|
|
for( int i = 0; i < DT_COUNT; i++ )
|
|
{
|
|
m_pDevice[i].nCount = 0;
|
|
m_pDevice[i].ppDevice = NULL;
|
|
m_pDevice[i].nType = DT_FIRST + i;
|
|
}
|
|
|
|
m_Background = _T("");
|
|
|
|
m_MapSize.cx = 1000;
|
|
m_MapSize.cy = 1000;
|
|
}
|
|
|
|
CObjectFactory::~CObjectFactory()
|
|
{
|
|
for( int i = 0; i < DT_COUNT; i++ )
|
|
{
|
|
if( m_pDevice[i].ppDevice )
|
|
{
|
|
for( int j = 0; j < m_pDevice[i].nCount; j++ )
|
|
delete m_pDevice[i].ppDevice[j];
|
|
free( m_pDevice[i].ppDevice );
|
|
}
|
|
}
|
|
}
|
|
|
|
CDevice* CObjectFactory::ClassCreate(int nType)
|
|
{
|
|
CDevice *pDevice = NULL;
|
|
|
|
switch( nType )
|
|
{
|
|
case DT_CAMERA: pDevice = new CDeviceCamera; break;
|
|
case DT_CAMERA_PTZ: pDevice = new CDeviceMigvanCameraPTZ; break;
|
|
case DT_CAMERA_RABBIT: pDevice = new CDeviceRabbitCamera; break;
|
|
case DT_RABBIT: pDevice = new CDeviceRabbit; break;
|
|
case DT_VM8X4: pDevice = new CDeviceMigvanVM8x4; break;
|
|
case DT_SOCKET: pDevice = new CDeviceSocket; break;
|
|
case DT_VIDEO_IN: pDevice = new CDeviceVideoIn; break;
|
|
case DT_LGS: pDevice = new CDeviceLGS; break;
|
|
}
|
|
|
|
ASSERT( pDevice ); // check source code: requared class absent!!!
|
|
|
|
#ifdef SETUP_LGS_PROJECT
|
|
switch( nType )
|
|
{
|
|
case DT_CAMERA:
|
|
pDevice->m_hIcon[0] = LoadIcon( AfxGetInstanceHandle(), (LPCTSTR)IDI_CAMERA_1 );
|
|
pDevice->m_hIcon[1] = LoadIcon( AfxGetInstanceHandle(), (LPCTSTR)IDI_CAMERA_2 );
|
|
break;
|
|
case DT_CAMERA_PTZ:
|
|
pDevice->m_hIcon[0] = LoadIcon( AfxGetInstanceHandle(), (LPCTSTR)IDI_CAMERA_PTZ_1 );
|
|
pDevice->m_hIcon[1] = LoadIcon( AfxGetInstanceHandle(), (LPCTSTR)IDI_CAMERA_PTZ_2 );
|
|
break;
|
|
case DT_CAMERA_RABBIT:
|
|
pDevice->m_hIcon[0] = LoadIcon( AfxGetInstanceHandle(), (LPCTSTR)IDI_CAMERA_RABBIT_1 );
|
|
pDevice->m_hIcon[1] = LoadIcon( AfxGetInstanceHandle(), (LPCTSTR)IDI_CAMERA_RABBIT_2 );
|
|
break;
|
|
case DT_RABBIT:
|
|
pDevice->m_hIcon[0] = LoadIcon( AfxGetInstanceHandle(), (LPCTSTR)IDI_RABBIT_1 );
|
|
pDevice->m_hIcon[1] = LoadIcon( AfxGetInstanceHandle(), (LPCTSTR)IDI_RABBIT_2 );
|
|
break;
|
|
case DT_VM8X4:
|
|
pDevice->m_hIcon[0] = LoadIcon( AfxGetInstanceHandle(), (LPCTSTR)IDI_VM8X4_1 );
|
|
pDevice->m_hIcon[1] = LoadIcon( AfxGetInstanceHandle(), (LPCTSTR)IDI_VM8X4_2 );
|
|
break;
|
|
case DT_SOCKET:
|
|
pDevice->m_hIcon[0] = LoadIcon( AfxGetInstanceHandle(), (LPCTSTR)IDI_SOCKET_1 );
|
|
pDevice->m_hIcon[1] = LoadIcon( AfxGetInstanceHandle(), (LPCTSTR)IDI_SOCKET_2 );
|
|
break;
|
|
case DT_VIDEO_IN:
|
|
pDevice->m_hIcon[0] = LoadIcon( AfxGetInstanceHandle(), (LPCTSTR)IDI_VIDEO_IN_1 );
|
|
pDevice->m_hIcon[1] = LoadIcon( AfxGetInstanceHandle(), (LPCTSTR)IDI_VIDEO_IN_2 );
|
|
break;
|
|
case DT_LGS:
|
|
pDevice->m_hIcon[0] = LoadIcon( AfxGetInstanceHandle(), (LPCTSTR)IDI_LGS_MD_1 );
|
|
pDevice->m_hIcon[1] = LoadIcon( AfxGetInstanceHandle(), (LPCTSTR)IDI_LGS_MD_2 );
|
|
break;
|
|
case DT_CAMERA_LGS:
|
|
pDevice->m_hIcon[0] = LoadIcon( AfxGetInstanceHandle(), (LPCTSTR)IDI_CAMERA_LGS_1 );
|
|
pDevice->m_hIcon[1] = LoadIcon( AfxGetInstanceHandle(), (LPCTSTR)IDI_CAMERA_LGS_2 );
|
|
break;
|
|
}
|
|
#endif
|
|
|
|
pDevice->m_pOF = this;
|
|
|
|
return pDevice;
|
|
}
|
|
|
|
CDevice *CObjectFactory::DeviceGet( CRect &rect )
|
|
{
|
|
for( int i = 0; i < DT_COUNT; i++ )
|
|
{
|
|
for( int j = 0; j < m_pDevice[i].nCount; j++ )
|
|
{
|
|
if( rect.PtInRect( m_pDevice[i].ppDevice[j]->m_Pos ) )
|
|
return m_pDevice[i].ppDevice[j];
|
|
}
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
CDevice* CObjectFactory::DeviceAdd(double x, double y, int nType)
|
|
{
|
|
for( int i = 0; i < DT_COUNT; i++ )
|
|
{
|
|
if( m_pDevice[i].nType == nType )
|
|
{
|
|
m_pDevice[i].ppDevice = (CDevice**)realloc( m_pDevice[i].ppDevice, sizeof( CDevice* ) * ( m_pDevice[i].nCount + 1 ) );
|
|
m_pDevice[i].ppDevice[ m_pDevice[i].nCount ] = ClassCreate( nType );
|
|
m_pDevice[i].ppDevice[ m_pDevice[i].nCount ]->m_Pos.x = x;
|
|
m_pDevice[i].ppDevice[ m_pDevice[i].nCount ]->m_Pos.y = y;
|
|
m_pDevice[i].ppDevice[ m_pDevice[i].nCount ]->SetIndex( m_pDevice[i].nCount );
|
|
return m_pDevice[i].ppDevice[ m_pDevice[i].nCount++ ];
|
|
}
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
void CObjectFactory::DeviceDisconnect(CDevice *pDevice)
|
|
{
|
|
CDevice *pD1 = pDevice;
|
|
for( int i = 0; i < pD1->GetPinCount(); i++ )
|
|
{
|
|
CPin *pP1 = pD1->GetPin( i );
|
|
/* for( int j = 0; j < pP1->m_nDeviceCount; j++ )
|
|
{
|
|
CDevice *pD2 = DeviceGet( pP1->m_pDevice[j].nIndex, pP1->m_pDevice[j].nType );
|
|
CPin *pP2 = pD2->GetPin( pP1->m_pDevice[j].nPin );
|
|
|
|
pP2->Disconnect( pP1 ); // disconnect all pins from device
|
|
}
|
|
*/
|
|
pP1->Disconnect( NULL );
|
|
}
|
|
}
|
|
|
|
int CObjectFactory::DeviceMove( CDevice *pDevice, int nIndex )
|
|
{
|
|
CDevice *pD1 = pDevice;
|
|
for( int i = 0; i < pD1->GetPinCount(); i++ )
|
|
{
|
|
CPin *pP1 = pD1->GetPin( i );
|
|
for( int j = 0; j < pP1->m_nDeviceCount; j++ )
|
|
{
|
|
CDevice *pD2 = DeviceGet( pP1->m_pDevice[j].nIndex, pP1->m_pDevice[j].nType );
|
|
CPin *pP2 = pD2->GetPin( pP1->m_pDevice[j].nPin );
|
|
|
|
for( int k = 0; k < pP2->m_nDeviceCount; k++ )
|
|
{
|
|
if( pP2->m_pDevice[k].nIndex == pD1->GetIndex() &&
|
|
pP2->m_pDevice[k].nType == pD1->GetType() )
|
|
{
|
|
pP2->m_pDevice[k].nIndex = nIndex; // re-indexing
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
pD1->SetIndex( nIndex ); // re-indexing itself
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CObjectFactory::DeviceDelete( CDevice *pDevice )
|
|
{
|
|
int nIndex = pDevice->GetIndex();
|
|
int nType = pDevice->GetType();
|
|
|
|
DeviceDisconnect( pDevice ); // disconnect from all pins
|
|
delete pDevice; // delete device
|
|
|
|
m_pDevice[ nType ].nCount--;
|
|
if( m_pDevice[ nType ].nCount )
|
|
{
|
|
int nLast = m_pDevice[ nType ].nCount;
|
|
DeviceMove( m_pDevice[ nType ].ppDevice[ nLast ], nIndex ); // re-indexing last element
|
|
m_pDevice[ nType ].ppDevice[ nIndex ] = m_pDevice[ nType ].ppDevice[ nLast ]; // change element onto last element
|
|
}
|
|
m_pDevice[ nType ].ppDevice = (CDevice**)realloc( m_pDevice[ nType ].ppDevice, sizeof( CDevice* ) * m_pDevice[ nType ].nCount );
|
|
}
|
|
|
|
void CObjectFactory::DeviceDelete( int nIndex, int nType )
|
|
{
|
|
for( int i = 0; i < DT_COUNT; i++ )
|
|
{
|
|
if( m_pDevice[i].nType == nType )
|
|
{
|
|
DeviceDelete( m_pDevice[i].ppDevice[ nIndex ] );
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
CDevice *CObjectFactory::DeviceGet(int nIndex, int nType)
|
|
{
|
|
for( int i = 0; i < DT_COUNT; i++ )
|
|
{
|
|
if( m_pDevice[i].nType == nType )
|
|
{
|
|
return ( nIndex < m_pDevice[i].nCount ) ? m_pDevice[i].ppDevice[nIndex] : NULL;
|
|
}
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
void CObjectFactory::DrawDevice( CDC *pDC, CDevice *pDevice, CPoint shift, double scale )
|
|
{
|
|
CDevice *pD1 = pDevice;
|
|
for( int i = 0; i < pD1->GetPinCount(); i++ )
|
|
{
|
|
CPin *pP1 = pD1->GetPin( i );
|
|
for( int j = 0; j < pP1->m_nDeviceCount; j++ )
|
|
{
|
|
CDevice *pD2 = DeviceGet( pP1->m_pDevice[j].nIndex, pP1->m_pDevice[j].nType );
|
|
CPin *pP2 = pD2->GetPin( pP1->m_pDevice[j].nPin );
|
|
|
|
DrawLine( pDC, pP1, pP2, FALSE, shift, scale );
|
|
}
|
|
}
|
|
pD1->Draw( pDC, FALSE, shift, scale );
|
|
}
|
|
|
|
void CObjectFactory::Draw( CDC *pDC, CPoint shift, double scale )
|
|
{
|
|
CRect rect( -shift.x, -shift.y, -shift.x + (int)(m_MapSize.cx * scale), (int)(-shift.y + m_MapSize.cy * scale) );
|
|
pDC->FillSolidRect( &rect, RGB( 0,0,0 ) );
|
|
|
|
pDC->PlayMetaFile( m_MetaFile, rect );
|
|
|
|
for( int i = 0; i < DT_COUNT; i++ )
|
|
{
|
|
for( int j = 0; j < m_pDevice[i].nCount; j++ )
|
|
{
|
|
DrawDevice( pDC, m_pDevice[i].ppDevice[j], shift, scale );
|
|
}
|
|
}
|
|
}
|
|
|
|
void CObjectFactory::DrawLine( CDC *pDC, CPin *pP1, CPin *pP2, BOOL bActive, CPoint shift, double scale )
|
|
{
|
|
CDevice *pD1 = DeviceGet( pP1->m_Owner.nIndex, pP1->m_Owner.nType );
|
|
CDevice *pD2 = DeviceGet( pP2->m_Owner.nIndex, pP2->m_Owner.nType );
|
|
|
|
CPoint sp1( (int)(pD1->m_Pos.x * scale), (int)(pD1->m_Pos.y * scale) );
|
|
CPoint sp2( (int)(pD2->m_Pos.x * scale), (int)(pD2->m_Pos.y * scale) );
|
|
CPoint p1( sp1 + pP1->m_Pos - CPoint( NORMAL_SIZE, NORMAL_SIZE ) - shift );
|
|
CPoint p2( sp2 + pP2->m_Pos - CPoint( NORMAL_SIZE, NORMAL_SIZE ) - shift );
|
|
|
|
CPen pen( PS_SOLID, bActive ? 3 : 0, pP1->GetColor() );
|
|
CPen *pPen = (CPen*)pDC->SelectObject( &pen );
|
|
pDC->MoveTo( p1 );
|
|
pDC->LineTo( p2 );
|
|
pDC->SelectObject( pPen );
|
|
}
|
|
|
|
// D C-D
|
|
//p1 ----------------- p2
|
|
// \ | /
|
|
// \ | /
|
|
// B \ | / A
|
|
// \ /
|
|
// p3
|
|
|
|
static BOOL PtInLine( CPoint p1, CPoint p2, CPoint p3, int nQuality )
|
|
{
|
|
double C = sqrt( pow(p1.x-p2.x,2) + pow(p1.y-p2.y,2) );
|
|
double B = sqrt( pow(p1.x-p3.x,2) + pow(p1.y-p3.y,2) );
|
|
double A = sqrt( pow(p2.x-p3.x,2) + pow(p2.y-p3.y,2) );
|
|
|
|
double D = ( pow(B,2) - pow(A,2) + pow(C,2) ) / (2*C);
|
|
|
|
if( floor( fabs(D) - C ) > nQuality )
|
|
return FALSE;
|
|
|
|
double X = p1.x + (p2.x-p1.x) * D / C;
|
|
double Y = p1.y + (p2.y-p1.y) * D / C;
|
|
|
|
BOOL bInX = FALSE;
|
|
BOOL bInY = FALSE;
|
|
|
|
double X1, X2;
|
|
if( p1.x < p2.x ) { X1 = p1.x - nQuality; X2 = p2.x + nQuality; }
|
|
else { X1 = p2.x - nQuality; X2 = p1.x + nQuality; }
|
|
|
|
double Y1, Y2;
|
|
if( p1.y < p2.y ) { Y1 = p1.y - nQuality; Y2 = p2.y + nQuality; }
|
|
else { Y1 = p2.y - nQuality; Y2 = p1.y + nQuality; }
|
|
|
|
double R = sqrt( pow(p3.x-X,2) + pow(p3.y-Y,2) );
|
|
|
|
return ( floor(R) <= nQuality ) && ( X1 <= X ) && ( X <= X2 ) &&
|
|
( Y1 <= Y ) && ( Y <= Y2 );
|
|
}
|
|
|
|
BOOL CObjectFactory::ConnectionGet( CDevice *pD, CPoint p, CPin **pPin1, CPin **pPin2, double scale )
|
|
{
|
|
CDevice *pD1 = pD;
|
|
for( int i = 0; i < pD1->GetPinCount(); i++ )
|
|
{
|
|
CPin *pP1 = pD1->GetPin( i );
|
|
CPoint sp1( (int)(pD1->m_Pos.x * scale), (int)(pD1->m_Pos.y * scale) );
|
|
CPoint p1( sp1 + pP1->m_Pos - CPoint( NORMAL_SIZE, NORMAL_SIZE ) );
|
|
for( int j = 0; j < pP1->m_nDeviceCount; j++ )
|
|
{
|
|
CDevice *pD2 = DeviceGet( pP1->m_pDevice[j].nIndex, pP1->m_pDevice[j].nType );
|
|
CPin *pP2 = pD2->GetPin( pP1->m_pDevice[j].nPin );
|
|
CPoint sp2( (int)(pD2->m_Pos.x * scale), (int)(pD2->m_Pos.y * scale) );
|
|
CPoint p2( sp2 + pP2->m_Pos - CPoint( NORMAL_SIZE, NORMAL_SIZE ) );
|
|
|
|
if( PtInLine( p1, p2, p, 1 ) )
|
|
{
|
|
*pPin1 = pP1;
|
|
*pPin2 = pP2;
|
|
return TRUE;
|
|
}
|
|
}
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
BOOL CObjectFactory::ConnectionGet( CPoint p, CPin **pPin1, CPin **pPin2, double scale )
|
|
{
|
|
for( int i = 0; i < DT_COUNT; i++ )
|
|
{
|
|
for( int j = 0; j < m_pDevice[i].nCount; j++ )
|
|
{
|
|
if( ConnectionGet( m_pDevice[i].ppDevice[j], p, pPin1, pPin2, scale ) )
|
|
return TRUE;
|
|
}
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
void CObjectFactory::Serialize(CArchive& ar)
|
|
{
|
|
if (ar.IsStoring())
|
|
{
|
|
ar << m_MapSize.cx;
|
|
ar << m_MapSize.cy;
|
|
ar << m_Background;
|
|
for( int i = 0; i < DT_COUNT; i++ )
|
|
{
|
|
ar << m_pDevice[i].nCount;
|
|
for( int j = 0; j < m_pDevice[i].nCount; j++ )
|
|
m_pDevice[i].ppDevice[j]->Serialize( ar );
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ar >> m_MapSize.cx;
|
|
ar >> m_MapSize.cy;
|
|
ar >> m_Background;
|
|
SetBackground( m_Background );
|
|
for( int i = 0; i < DT_COUNT; i++ )
|
|
{
|
|
ar >> m_pDevice[i].nCount;
|
|
m_pDevice[i].ppDevice = (CDevice**) malloc( m_pDevice[i].nCount * sizeof(CDevice*) );
|
|
for( int j = 0; j < m_pDevice[i].nCount; j++ )
|
|
{
|
|
m_pDevice[i].ppDevice[j] = ClassCreate( m_pDevice[i].nType );
|
|
m_pDevice[i].ppDevice[j]->SetIndex(j);
|
|
m_pDevice[i].ppDevice[j]->Serialize( ar );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void CObjectFactory::SetBackground(LPCTSTR pFileName)
|
|
{
|
|
m_Background = pFileName;
|
|
m_MapSize.cx = 1000;
|
|
if( m_MetaFile.Load( m_Background ) )
|
|
m_MapSize.cy = m_MapSize.cx * m_MetaFile.GetSize().cy / m_MetaFile.GetSize().cx;
|
|
else
|
|
m_MapSize.cy = 1000;
|
|
}
|