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.
285 lines
7.5 KiB
285 lines
7.5 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 08/10/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: LgUICameraEngine.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of LgUICameraEngine.cpp
|
|
//----------------------------------------------------------------------------
|
|
#include "stdafx.h"
|
|
#include "LgUICameraEngine.h"
|
|
#include "LgUICamera.h"
|
|
#include "LgUICameraVideoWnd.h"
|
|
#include "LgUICameraMainWnd.h"
|
|
#include "LgUICameraListWnd.h"
|
|
#include "LgUICameraControlWnd.h"
|
|
|
|
#include "..\UISite\LgUISiteEngine.h"
|
|
|
|
CLgUICameraEngine::CLgUICameraEngine()
|
|
{
|
|
m_pActiveCamera = NULL;
|
|
}
|
|
|
|
CLgUICameraEngine::~CLgUICameraEngine()
|
|
{
|
|
Destroy();
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// create / destroy
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
BOOL CLgUICameraEngine::Create()
|
|
{
|
|
// create background window (used as base for CLgUICameraVideoWnd)
|
|
if( !m_HiddenWnd.GetSafeHwnd() )
|
|
{
|
|
CString strClassName = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW, NULL, NULL, NULL );
|
|
CRect rect(0,0,10,10);
|
|
if( !m_HiddenWnd.CreateEx( 0, strClassName, NULL, WS_OVERLAPPED, rect, NULL, 0 ) )
|
|
return FALSE;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CLgUICameraEngine::Destroy()
|
|
{
|
|
// destroy all video windows
|
|
while( CLgLink<CLgUICameraEngine,CLgUICameraVideoWnd>::GetCount() )
|
|
delete *CLgLink<CLgUICameraEngine,CLgUICameraVideoWnd>::GetAt(0);
|
|
|
|
// destroy background window
|
|
if( m_HiddenWnd.GetSafeHwnd() )
|
|
m_HiddenWnd.DestroyWindow();
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// main control methods
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
BOOL CLgUICameraEngine::SetActiveCamera( CLgUICamera* pVideoCamera )
|
|
{
|
|
// check pointer
|
|
if( !pVideoCamera )
|
|
return FALSE;
|
|
|
|
// check camera link
|
|
if( CLgLink<CLgUICameraEngine,CLgUICamera>::Find( (CLgLink<CLgUICamera,CLgUICameraEngine>*&)pVideoCamera ) == -1 )
|
|
return FALSE;
|
|
|
|
// get pointers to objects
|
|
CLgUICameraListWnd *pListWnd = *this;
|
|
CLgUICameraMainWnd *pMainWnd = *this;
|
|
CLgUICameraControlWnd *pControlWnd = *this;
|
|
|
|
// if active camera already exist then substitute it (if it differs from entered)
|
|
if( m_pActiveCamera )
|
|
{
|
|
// don't need to do anything
|
|
if( m_pActiveCamera == pVideoCamera )
|
|
return TRUE;
|
|
|
|
// if exist link to main video window
|
|
if( pListWnd )
|
|
{
|
|
CLgUICameraVideoWnd *pVideoWnd = m_pActiveCamera->GetVideoWnd();
|
|
if( !pVideoWnd )
|
|
// error situation!!!
|
|
return FALSE;
|
|
|
|
// try to add to list current active camera
|
|
if( !pListWnd->Link( pVideoWnd ) )
|
|
return FALSE;
|
|
}
|
|
}
|
|
|
|
// clear pointer (paranoia)
|
|
m_pActiveCamera = NULL;
|
|
|
|
// if exist link with video cameras list wnd
|
|
if( pListWnd )
|
|
{
|
|
CLgUICameraVideoWnd *pVideoWnd = pVideoCamera->GetVideoWnd();
|
|
if( !pVideoWnd )
|
|
// error situation!!!
|
|
return FALSE;
|
|
|
|
// remove camera from list
|
|
pListWnd->Unlink( pVideoWnd );
|
|
}
|
|
|
|
// if exist link to main video window
|
|
if( pMainWnd )
|
|
{
|
|
CLgUICameraVideoWnd *pVideoWnd = pVideoCamera->GetVideoWnd();
|
|
if( !pVideoWnd )
|
|
// error situation!!!
|
|
return FALSE;
|
|
|
|
// unregister old wnd
|
|
pMainWnd->CLgLink<CLgUICameraMainWnd,CLgUICameraVideoWnd>::Unlink();
|
|
|
|
// set new camera as main camera
|
|
if( !pMainWnd->Link( pVideoWnd ) )
|
|
return FALSE;
|
|
}
|
|
|
|
// if exist link to control window
|
|
if( pControlWnd )
|
|
{
|
|
// unregister old camera (if any)
|
|
pControlWnd->CLgLink<CLgUICameraControlWnd,CLgUICamera>::Unlink();
|
|
|
|
// set new camera as main camera
|
|
if( !pControlWnd->Link( pVideoCamera ) )
|
|
return FALSE;
|
|
}
|
|
|
|
// store pointer for new camera
|
|
m_pActiveCamera = pVideoCamera;
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
BOOL CLgUICameraEngine::SetActiveVideo( CLgUICameraVideoWnd* pVideoWnd )
|
|
{
|
|
// check pointer
|
|
if( !pVideoWnd )
|
|
return FALSE;
|
|
|
|
// check camera link
|
|
if( CLgLink<CLgUICameraEngine,CLgUICameraVideoWnd>::Find( (CLgLink<CLgUICameraVideoWnd,CLgUICameraEngine>*&)pVideoWnd ) == -1 )
|
|
return FALSE;
|
|
|
|
CLgUICamera *pVideoCamera = pVideoWnd->GetVideoCamera();
|
|
if( !pVideoCamera )
|
|
// error situation
|
|
return FALSE;
|
|
|
|
return SetActiveCamera( pVideoCamera );
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// notifications from CLgVideoCamera objects
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
BOOL CLgUICameraEngine::OnVideoCameraStream( CLgUICamera* pVideoCamera, BOOL bRun )
|
|
{
|
|
// check pointer
|
|
if( !pVideoCamera )
|
|
return FALSE;
|
|
|
|
CLgArray< CLgLink<CLgUICameraVideoWnd,CLgUICameraEngine>* >& arrVideoWnd = *this;
|
|
|
|
// check camera link
|
|
if( CLgLink<CLgUICameraEngine,CLgUICamera>::Find( (CLgLink<CLgUICamera,CLgUICameraEngine>*&)pVideoCamera ) == -1 )
|
|
return FALSE;
|
|
|
|
// get pointers to objects
|
|
CLgUICameraListWnd *pListWnd = *this;
|
|
CLgUICameraMainWnd *pMainWnd = *this;
|
|
CLgUICameraControlWnd *pControlWnd = *this;
|
|
|
|
if( bRun )
|
|
{
|
|
// try to find cmaera among connected cameras
|
|
for( INT i = 0; i < arrVideoWnd.GetCount(); i++ )
|
|
{
|
|
CLgUICameraVideoWnd *pTempVideoWnd = *arrVideoWnd[i];
|
|
// if no connected cameras
|
|
if( pTempVideoWnd->GetVideoCamera() == pVideoCamera )
|
|
{
|
|
return TRUE;
|
|
}
|
|
}
|
|
|
|
// try to find free CLgUICameraVideoWnd
|
|
CLgUICameraVideoWnd *pVideoWnd = NULL;
|
|
for( i = 0; i < arrVideoWnd.GetCount(); i++ )
|
|
{
|
|
CLgUICameraVideoWnd *pTempVideoWnd = *arrVideoWnd[i];
|
|
// if no connected cameras
|
|
if( !pTempVideoWnd->GetVideoCamera() )
|
|
{
|
|
pVideoWnd = pTempVideoWnd;
|
|
break;
|
|
}
|
|
}
|
|
|
|
// try to create new CLgUICameraVideoWnd
|
|
if( !pVideoWnd )
|
|
{
|
|
pVideoWnd = new CLgUICameraVideoWnd();
|
|
if( !pVideoWnd )
|
|
return FALSE;
|
|
|
|
// create window
|
|
if( !pVideoWnd->Create( &m_HiddenWnd, 0, 0, 10, 10 ) )
|
|
{
|
|
delete pVideoWnd;
|
|
return FALSE;
|
|
}
|
|
|
|
// add into internal list
|
|
if( !CLgLink<CLgUICameraEngine,CLgUICameraVideoWnd>::Link( pVideoWnd ) )
|
|
{
|
|
delete pVideoWnd;
|
|
return FALSE;
|
|
}
|
|
}
|
|
|
|
// link video window to video camera
|
|
if( !pVideoWnd->CLgLinkS<CLgUICameraVideoWnd,CLgUICamera>::Link( pVideoCamera ) )
|
|
return FALSE;
|
|
|
|
// if exist link with video cameras list wnd
|
|
if( pListWnd )
|
|
{
|
|
// addd camera into list
|
|
if( !pListWnd->Link( pVideoWnd ) )
|
|
return FALSE;
|
|
}
|
|
|
|
// if active camera is not exist
|
|
if( !m_pActiveCamera )
|
|
return SetActiveCamera( pVideoCamera );
|
|
}
|
|
else
|
|
{
|
|
// remember pointer to video wnd
|
|
CLgUICameraVideoWnd *pVideoWnd = pVideoCamera->GetVideoWnd();
|
|
if( pVideoWnd )
|
|
{
|
|
// unlink camera from window
|
|
pVideoCamera->CLgLinkS<CLgUICamera,CLgUICameraVideoWnd>::Unlink();
|
|
}
|
|
|
|
// if main control camera is this camera
|
|
if( m_pActiveCamera == pVideoCamera )
|
|
{
|
|
if( pListWnd )
|
|
{
|
|
// if there is cameras
|
|
if( pListWnd->GetVideoWndCount() )
|
|
{
|
|
// set first camera as active camera
|
|
return SetActiveVideo( pListWnd->GetVideoWnd(0) );
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// if exist link with video cameras list wnd
|
|
if( pListWnd )
|
|
{
|
|
// addd camera into list
|
|
pListWnd->Unlink( pVideoWnd );
|
|
}
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|