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.
 
 
 
 
 

317 lines
9.6 KiB

//----------------------------------------------------------------------------
// Laser Guard Ltd.
// Copyright © 2000-2002. All Rights Reserved.
// Version 1.0 01/01/2000
// Last modification: 15/07/2001
// PROJECT:
// SUBSYSTEM:
// FILE: CameraDlg.cpp
// AUTHOR: Sergey Chizhevskiy
// OVERVIEW
// ~~~~~~~~
// Source file of CameraDlg.cpp
//----------------------------------------------------------------------------
// CameraDlg.cpp : implementation file
//
#include "stdafx.h"
#include "chicago.h"
#include "CameraDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCameraDlg dialog
CCameraDlg::CCameraDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCameraDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCameraDlg)
//}}AFX_DATA_INIT
m_CurrentCamera = 0;
::ZeroMemory( &m_Video, sizeof( m_Video ) );
m_bVideoConnected = FALSE;
}
CCameraDlg::~CCameraDlg()
{
}
void CCameraDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCameraDlg)
DDX_Control(pDX, IDC_CHECK_CAMERA_LOCK, m_Lock);
DDX_Control(pDX, IDC_STATIC_CAMERA_IMAGE, m_CameraImage);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCameraDlg, CDialog)
//{{AFX_MSG_MAP(CCameraDlg)
ON_BN_CLICKED(IDC_BUTTON_NEXT, OnButtonNext)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_BUTTON_CAMERA_PREV, OnButtonCameraPrev)
ON_BN_CLICKED(IDC_BUTTON_SNAPSHOT, OnButtonSnapshot)
ON_WM_TIMER()
ON_WM_MOVE()
ON_BN_CLICKED(IDC_CHECK_CAMERA_LOCK, OnCheckCameraLock)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CCameraDlg::SetSensorArray( CSensorArray *pSensorArray, CVideoWnd *pVideoWnd )
{
m_pSensorArray = pSensorArray;
m_Video.pVideoWnd = pVideoWnd;
m_CurrentCamera = 0;
}
BOOL CCameraDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CheckCamera();
// store video window's state
m_Video.pParent = m_Video.pVideoWnd->GetParent();
m_Video.pVideoWnd->GetWindowRect( &m_Video.rect );
m_Video.pParent->ScreenToClient( &m_Video.rect );
// move video window's to new position
CRect rect;
m_CameraImage.GetClientRect( &rect );
m_Video.pVideoWnd->SetParent( &m_CameraImage );
// m_Video.pVideoWnd->ShowWindow( SW_SHOW );
m_Video.pVideoWnd->MoveWindow( &rect );
::SetWindowLong( GetDlgItem( IDC_BUTTON_RIGHT )->GetSafeHwnd(), GWL_USERDATA, (LONG)this );
::SetWindowLong( GetDlgItem( IDC_BUTTON_LEFT )->GetSafeHwnd(), GWL_USERDATA, (LONG)this );
::SetWindowLong( GetDlgItem( IDC_BUTTON_UP )->GetSafeHwnd(), GWL_USERDATA, (LONG)this );
::SetWindowLong( GetDlgItem( IDC_BUTTON_DOWN )->GetSafeHwnd(), GWL_USERDATA, (LONG)this );
::SetWindowLong( GetDlgItem( IDC_BUTTON_FAR )->GetSafeHwnd(), GWL_USERDATA, (LONG)this );
::SetWindowLong( GetDlgItem( IDC_BUTTON_NEAR )->GetSafeHwnd(), GWL_USERDATA, (LONG)this );
m_pWndProc = (WNDPROC)::SetWindowLong( GetDlgItem( IDC_BUTTON_RIGHT )->GetSafeHwnd(), GWL_WNDPROC, (LONG)WindowProcButton );
m_pWndProc = (WNDPROC)::SetWindowLong( GetDlgItem( IDC_BUTTON_LEFT )->GetSafeHwnd(), GWL_WNDPROC, (LONG)WindowProcButton );
m_pWndProc = (WNDPROC)::SetWindowLong( GetDlgItem( IDC_BUTTON_UP )->GetSafeHwnd(), GWL_WNDPROC, (LONG)WindowProcButton );
m_pWndProc = (WNDPROC)::SetWindowLong( GetDlgItem( IDC_BUTTON_DOWN )->GetSafeHwnd(), GWL_WNDPROC, (LONG)WindowProcButton );
m_pWndProc = (WNDPROC)::SetWindowLong( GetDlgItem( IDC_BUTTON_FAR )->GetSafeHwnd(), GWL_WNDPROC, (LONG)WindowProcButton );
m_pWndProc = (WNDPROC)::SetWindowLong( GetDlgItem( IDC_BUTTON_NEAR )->GetSafeHwnd(), GWL_WNDPROC, (LONG)WindowProcButton );
SetTimer( 0, 500, NULL );
ChangeCamera();
return TRUE;
}
void CCameraDlg::OnDestroy()
{
m_Video.pVideoWnd->MoveWindow( &m_Video.rect );
m_Video.pVideoWnd->SetParent( m_Video.pParent );
CDialog::OnDestroy();
}
void CCameraDlg::ChangeCamera()
{
/*
CheckCamera();
CVideoCamera *pCamera = (CVideoCamera*)m_pSensorArray->GetVideoCamera( m_CurrentCamera );
if( pCamera )
{
CVideoDevice *pVD = m_pSensorArray->GetVideoDevice();
if( pVD )
pCamera->Connect( pVD->GetInput(0), TRUE, TRUE );
}
*/
}
void CCameraDlg::CheckCamera()
{
CVideoCamera *pCamera = (CVideoCamera*)m_pSensorArray->GetVideoCamera( m_CurrentCamera );
CString str;
if( pCamera )
{
CVideoCameraPTZ *pCameraPTZ;
BOOL bPTZ = FALSE;
switch( pCamera->GetType() )
{
case VC_FIX:
str.Format( "Camera <%s> fixed", (LPCTSTR)*pCamera->GetName() );
break;
case VC_PTZ:
pCameraPTZ = (CVideoCameraPTZ*)pCamera;
if( pCameraPTZ->IsReady() )
{
str.Format( "Camera <%s> ready", (LPCTSTR)*pCameraPTZ->GetName() );
bPTZ = TRUE;
}
else
str.Format( "Camera <%s> not ready", (LPCTSTR)*pCameraPTZ->GetName() );
break;
}
GetDlgItem( IDC_BUTTON_RIGHT )->EnableWindow( bPTZ );
GetDlgItem( IDC_BUTTON_LEFT )->EnableWindow( bPTZ );
GetDlgItem( IDC_BUTTON_UP )->EnableWindow( bPTZ );
GetDlgItem( IDC_BUTTON_DOWN )->EnableWindow( bPTZ );
GetDlgItem( IDC_BUTTON_FAR )->EnableWindow( bPTZ );
GetDlgItem( IDC_BUTTON_NEAR )->EnableWindow( bPTZ );
}
else
str.Format( "Camera #%d null", m_CurrentCamera );
SetWindowText( str );
}
void CCameraDlg::OnButtonCameraPrev()
{
m_Lock.SetCheck( BST_UNCHECKED );
OnCheckCameraLock();
m_CurrentCamera = (m_CurrentCamera - 1 + m_pSensorArray->GetVideoCameraCount() ) % m_pSensorArray->GetVideoCameraCount();
ChangeCamera();
}
void CCameraDlg::OnButtonNext()
{
m_Lock.SetCheck( BST_UNCHECKED );
OnCheckCameraLock();
m_CurrentCamera = (m_CurrentCamera+1) % m_pSensorArray->GetVideoCameraCount();
ChangeCamera();
}
void CCameraDlg::OnButtonSnapshot()
{
CVideoCamera *pCamera = (CVideoCamera*)m_pSensorArray->GetVideoCamera( m_CurrentCamera );
if( pCamera )
{
EVENT event;
event.id = LGS_EVENT_MANUAL_CAPTURE;
event.color = RGB( 0,0,0xFF );
_tcscpy( event.pText, _T("manual capture") );
SYSTEMTIME st;
::GetLocalTime( &st );
::SystemTimeToFileTime( &st, (LPFILETIME)&event.time );
event.pCamera = pCamera;
m_pSensorArray->GetEventQueue()->PostEvent( event );
}
}
LRESULT CCameraDlg::WindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
BOOL bRun = FALSE;
BOOL bPerform = FALSE;
switch( uMsg )
{
case BM_SETSTATE:
bRun = wParam;
bPerform = TRUE;
break;
}
if( bPerform )
{
CVideoCameraPTZ *pCamera = (CVideoCameraPTZ*)m_pSensorArray->GetVideoCamera( m_CurrentCamera );
if( pCamera )
{
UINT uID = ::GetWindowLong( hWnd, GWL_ID );
switch( uID )
{
case IDC_BUTTON_RIGHT: if( bRun ) pCamera->CmdPan( 50.0, PAN_RIGHT ); else pCamera->CmdPan( 0.0, PAN_STOP ); break;
case IDC_BUTTON_LEFT: if( bRun ) pCamera->CmdPan( 50.0, PAN_LEFT ); else pCamera->CmdPan( 0.0, PAN_STOP ); break;
case IDC_BUTTON_UP: if( bRun ) pCamera->CmdTilt( 50.0, TILT_UP ); else pCamera->CmdTilt( 0.0, TILT_STOP ); break;
case IDC_BUTTON_DOWN: if( bRun ) pCamera->CmdTilt( 50.0, TILT_DOWN ); else pCamera->CmdTilt( 0.0, TILT_STOP ); break;
case IDC_BUTTON_FAR: if( bRun ) pCamera->CmdZoom( 50.0, ZOOM_FAR ); else pCamera->CmdZoom( 0.0, ZOOM_STOP ); break;
case IDC_BUTTON_NEAR: if( bRun ) pCamera->CmdZoom( 50.0, ZOOM_NEAR ); else pCamera->CmdZoom( 0.0, ZOOM_STOP ); break;
}
}
}
return ::CallWindowProc( m_pWndProc, hWnd, uMsg, wParam, lParam );
}
BOOL CCameraDlg::PreTranslateMessage(MSG* pMsg)
{
switch( pMsg->message )
{
case WM_KEYDOWN:
switch( pMsg->wParam )
{
case VK_UP: SendDlgItemMessage( IDC_BUTTON_UP, BM_SETSTATE, TRUE ); return TRUE;
case VK_DOWN: SendDlgItemMessage( IDC_BUTTON_DOWN, BM_SETSTATE, TRUE ); return TRUE;
case VK_LEFT: SendDlgItemMessage( IDC_BUTTON_LEFT, BM_SETSTATE, TRUE ); return TRUE;
case VK_RIGHT: SendDlgItemMessage( IDC_BUTTON_RIGHT, BM_SETSTATE, TRUE ); return TRUE;
case VK_ADD: SendDlgItemMessage( IDC_BUTTON_FAR, BM_SETSTATE, TRUE ); return TRUE;
case VK_SUBTRACT: SendDlgItemMessage( IDC_BUTTON_NEAR, BM_SETSTATE, TRUE ); return TRUE;
}
break;
case WM_KEYUP:
switch( pMsg->wParam )
{
case VK_UP: SendDlgItemMessage( IDC_BUTTON_UP, BM_SETSTATE, FALSE ); return TRUE;
case VK_DOWN: SendDlgItemMessage( IDC_BUTTON_DOWN, BM_SETSTATE, FALSE ); return TRUE;
case VK_LEFT: SendDlgItemMessage( IDC_BUTTON_LEFT, BM_SETSTATE, FALSE ); return TRUE;
case VK_RIGHT: SendDlgItemMessage( IDC_BUTTON_RIGHT, BM_SETSTATE, FALSE ); return TRUE;
case VK_ADD: SendDlgItemMessage( IDC_BUTTON_FAR, BM_SETSTATE, FALSE ); return TRUE;
case VK_SUBTRACT: SendDlgItemMessage( IDC_BUTTON_NEAR, BM_SETSTATE, FALSE ); return TRUE;
}
break;
}
return CDialog::PreTranslateMessage(pMsg);
}
void CCameraDlg::OnTimer(UINT nIDEvent)
{
CheckCamera();
CDialog::OnTimer(nIDEvent);
}
void CCameraDlg::OnMove( int x, int y )
{
CDialog::OnMove(x, y);
if( m_Video.pVideoWnd->GetSafeHwnd() )
m_Video.pVideoWnd->Invalidate();
}
void CCameraDlg::OnCheckCameraLock()
{
CVideoCameraPTZ *pCamera = (CVideoCameraPTZ*)m_pSensorArray->GetVideoCamera( m_CurrentCamera );
if( pCamera )
{
BOOL bCheck = (m_Lock.GetCheck()==BST_CHECKED);
if( bCheck )
{
if( !pCamera->IsLock() )
{
pCamera->Lock();
CVideoDevice *pVD = NULL;//m_pSensorArray->GetVideoDevice();
if( pVD )
pCamera->Connect( pVD->GetInput(0), TRUE, FALSE );
}
else
m_Lock.SetCheck( BST_UNCHECKED );
}
else
{
if( pCamera->IsLock() )
{
pCamera->Unlock();
CVideoDevice *pVD = NULL;//m_pSensorArray->GetVideoDevice();
if( pVD )
pCamera->Disconnect();
}
}
}
}