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.
483 lines
12 KiB
483 lines
12 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 08/10/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: LocatorWnd.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of LocatorWnd.cpp
|
|
//----------------------------------------------------------------------------
|
|
#include "stdafx.h"
|
|
#include "LocatorWnd.h"
|
|
#include <math.h>
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
CLocatorWnd::CLocatorWnd()
|
|
{
|
|
memset( &m_PTZ, 0, sizeof(m_PTZ) );
|
|
memset( &m_dPTZ, 0, sizeof(m_dPTZ) );
|
|
m_nTimer = 0;
|
|
m_dwDirection = 0;
|
|
m_bSynchronizedPan = FALSE;
|
|
m_bSynchronizedTilt = FALSE;
|
|
m_bChange = FALSE;
|
|
m_nChangeTime = 0;
|
|
m_bBackground = FALSE;
|
|
}
|
|
|
|
CLocatorWnd::~CLocatorWnd()
|
|
{
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(CLocatorWnd, CWnd)
|
|
//{{AFX_MSG_MAP(CLocatorWnd)
|
|
ON_WM_PAINT()
|
|
ON_WM_SIZE()
|
|
ON_WM_TIMER()
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
BOOL CLocatorWnd::Create( CWnd *pParentWnd, INT x, INT y, INT cx, INT cy )
|
|
{
|
|
CRect rect( x, y, x + cx, y + cy );
|
|
return Create( pParentWnd, rect );
|
|
}
|
|
|
|
BOOL CLocatorWnd::Create( CWnd* pParentWnd, CRect &rect )
|
|
{
|
|
CString strClassName = ::AfxRegisterWndClass( CS_HREDRAW | CS_VREDRAW, LoadCursor( NULL, IDC_ARROW ), NULL, NULL );
|
|
|
|
if( !CWnd::Create( strClassName, NULL, WS_CHILD | WS_VISIBLE, rect, pParentWnd, 0 ) )
|
|
return FALSE;
|
|
|
|
m_nTimer = CWnd::SetTimer( 0, 50, NULL );
|
|
if( !m_nTimer )
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CLocatorWnd::OnPaint()
|
|
{
|
|
CPaintDC dc(this);
|
|
|
|
Draw( &dc );
|
|
}
|
|
|
|
void CLocatorWnd::DrawCamera( CDC *pDC )
|
|
{
|
|
// paint video frame
|
|
CRect rect;
|
|
GetClientRect( &rect );
|
|
|
|
// calculate positions
|
|
double d = 3.0 + (1.0 - m_PTZ.dZoom) * 21.0;
|
|
INT w = rect.Width() / 2;
|
|
INT h = rect.Height() / 2;
|
|
double r = h * ( 0.2 + m_PTZ.dZoom * 0.8 );
|
|
|
|
COLORREF color = m_bSynchronizedPan ? RGB(0,255,0) : RGB(255,0,0);
|
|
CBrush brush( color );
|
|
CPen pen( PS_SOLID, 2, color );
|
|
|
|
CBrush *pBrush = pDC->SelectObject( &brush );
|
|
CPen *pPen = pDC->SelectObject( &pen );
|
|
INT nOldROP = pDC->SetROP2( R2_XORPEN );
|
|
|
|
INT x1 = (INT)( ( cos( ( m_PTZ.dPan + d ) / 360.0 * 6.2831 ) ) * r + w );
|
|
INT y1 = (INT)( ( sin( ( m_PTZ.dPan + d ) / 360.0 * 6.2831 ) ) * r + h );
|
|
INT x2 = (INT)( ( cos( ( m_PTZ.dPan - d ) / 360.0 * 6.2831 ) ) * r + w );
|
|
INT y2 = (INT)( ( sin( ( m_PTZ.dPan - d ) / 360.0 * 6.2831 ) ) * r + h );
|
|
POINT p[] = { { x1, y1 }, { x2, y2 }, { w, h } };
|
|
rect.SetRect( (INT)(w-r), (INT)(h-r), (INT)(w+r), (INT)(h+r) );
|
|
pDC->Pie( &rect, p[0], p[1] );
|
|
|
|
/*
|
|
pDC->MoveTo( w, h );
|
|
pDC->AngleArc( w, h, r, 360 - (m_PTZ.dPan + d), d * 2 );
|
|
pDC->LineTo( w, h );
|
|
*/
|
|
pDC->SetROP2( nOldROP );
|
|
pDC->SelectObject( pPen );
|
|
pDC->SelectObject( pBrush );
|
|
}
|
|
|
|
void CLocatorWnd::Draw(CDC *pDC)
|
|
{
|
|
CRect rect;
|
|
GetClientRect( &rect );
|
|
|
|
m_MemoryDC.BitBlt( 0, 0, rect.Width(), rect.Height(), &m_FieldDC, 0, 0, SRCCOPY );
|
|
|
|
// DrawCamera( &m_MemoryDC );
|
|
|
|
BLENDFUNCTION bf;
|
|
bf.AlphaFormat = 0;
|
|
bf.BlendFlags = 0;
|
|
bf.BlendOp = 0;
|
|
bf.SourceConstantAlpha = 100;
|
|
|
|
::AlphaBlend( m_MemoryDC.GetSafeHdc(), 0, 0, rect.Width(), rect.Height(),
|
|
m_CameraDC.GetSafeHdc(), 0, 0, rect.Width(), rect.Height(), bf );
|
|
|
|
pDC->BitBlt( 0, 0, rect.Width(), rect.Height(), &m_MemoryDC, 0, 0, SRCCOPY );
|
|
}
|
|
|
|
BOOL CLocatorWnd::Clear()
|
|
{
|
|
CRect rect;
|
|
GetClientRect( &rect );
|
|
|
|
// prepare dimentions
|
|
INT cx = rect.Width();
|
|
INT cy = rect.Height();
|
|
|
|
if( !m_bBackground )
|
|
{
|
|
CPen pen( PS_SOLID, 1, RGB(127 ,0,0) );
|
|
CPen *pPen = m_FieldDC.SelectObject( &pen );
|
|
CBrush brush( RGB(0,127,0) );
|
|
CBrush *pBrush = m_FieldDC.SelectObject( &brush );
|
|
|
|
// draw locator field
|
|
INT W = cx / 2;
|
|
INT H = cy / 2;
|
|
for( INT i = 4; i >= 0; i-- )
|
|
{
|
|
INT w = W / 5 * (i + 1);
|
|
INT h = H / 5 * (i + 1);
|
|
m_FieldDC.Ellipse( W-w, H-h, W+w, H+h );
|
|
}
|
|
|
|
// draw lines
|
|
m_FieldDC.MoveTo( 0, H );
|
|
m_FieldDC.LineTo( cx, H );
|
|
m_FieldDC.MoveTo( W, 0 );
|
|
m_FieldDC.LineTo( W, cy );
|
|
|
|
m_FieldDC.SelectObject( pBrush );
|
|
m_FieldDC.SelectObject( pPen );
|
|
}
|
|
else
|
|
m_FieldDC.BitBlt( 0, 0, cx, cy, &m_BackgroundDC, 0, 0, SRCCOPY );
|
|
|
|
InvalidateRect( NULL, FALSE );
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CLocatorWnd::OnSize(UINT nType, int cx, int cy)
|
|
{
|
|
CWnd::OnSize(nType, cx, cy);
|
|
|
|
m_MemoryDC.Create( cx, cy, RGB(0,0,0) );
|
|
|
|
m_FieldDC.Create( cx, cy, RGB(0,0,0) );
|
|
|
|
// draw locator field
|
|
Clear();
|
|
|
|
// create camera
|
|
m_CameraDC.Create( cx, cy, RGB(0,0,0) );
|
|
|
|
RedrawCamera();
|
|
}
|
|
|
|
void CLocatorWnd::RedrawCamera()
|
|
{
|
|
// return;
|
|
|
|
// paint video frame
|
|
CRect rect;
|
|
GetClientRect( &rect );
|
|
|
|
// calculate positions
|
|
double d = 3.0 + (1.0 - m_PTZ.dZoom) * 21.0;
|
|
INT w = rect.Width() / 2;
|
|
INT h = rect.Height() / 2;
|
|
double r = h * ( 0.2 + m_PTZ.dZoom * 0.8 );
|
|
INT x1 = (INT)( ( cos( ( m_PTZ.dPan + d ) / 360.0 * 6.2831 ) ) * r + w );
|
|
INT y1 = (INT)( ( sin( ( m_PTZ.dPan + d ) / 360.0 * 6.2831 ) ) * r + h );
|
|
INT x2 = (INT)( ( cos( ( m_PTZ.dPan - d ) / 360.0 * 6.2831 ) ) * r + w );
|
|
INT y2 = (INT)( ( sin( ( m_PTZ.dPan - d ) / 360.0 * 6.2831 ) ) * r + h );
|
|
|
|
// redraw
|
|
m_CameraDC.FillSolidRect( rect, RGB(0,0,0) );
|
|
|
|
// draw
|
|
POINT p[] = { { x1, y1 }, { x2, y2 }, { w, h } };
|
|
// m_CameraDC.Polygon( p, 3 );
|
|
// m_CameraDC.MoveTo( x1, y1 );
|
|
// m_CameraDC.LineTo( w, h );
|
|
// m_CameraDC.LineTo( x2, y2 );
|
|
// POINT p[] = { { x1, y1 }, { x2, y2 } };
|
|
|
|
COLORREF color = m_bSynchronizedPan ? RGB(0,255,0) : RGB(255,0,0);
|
|
CBrush brush( color );
|
|
CPen pen( PS_SOLID, 1, color );
|
|
|
|
CBrush *pBrush = m_CameraDC.SelectObject( &brush );
|
|
CPen *pPen = m_CameraDC.SelectObject( &pen );
|
|
|
|
rect.SetRect( (INT)(w-r), (INT)(h-r), (INT)(w+r), (INT)(h+r) );
|
|
m_CameraDC.Pie( &rect, p[0], p[1] );
|
|
|
|
// select old pen
|
|
// m_CameraDC.SelectObject( pPen );
|
|
// CPen pen1( PS_SOLID, 10, RGB(0xFF,0xFF,0xFF) );
|
|
// pPen = m_CameraDC.SelectObject( &pen1 );
|
|
/*
|
|
GetClientRect( &rect );
|
|
double l = ( sqrt( pow( rect.Width(), 2 ) + pow( rect.Height(), 2 ) ) - rect.Width() ) / 4;
|
|
|
|
w = l;
|
|
h = l;
|
|
r = h * ( 0.2 + m_PTZ.dZoom * 0.8 ) * 2;
|
|
x1 = (INT)( ( cos( ( m_PTZ.dTilt + d ) / 360.0 * 6.2831 ) ) * r + w );
|
|
y1 = (INT)( ( sin( ( m_PTZ.dTilt + d ) / 360.0 * 6.2831 ) ) * r + h );
|
|
x2 = (INT)( ( cos( ( m_PTZ.dTilt - d ) / 360.0 * 6.2831 ) ) * r + w );
|
|
y2 = (INT)( ( sin( ( m_PTZ.dTilt - d ) / 360.0 * 6.2831 ) ) * r + h );
|
|
|
|
POINT p1[] = { { x1, y1 }, { x2, y2 }, { w, h } };
|
|
rect.SetRect( (INT)(-r), (INT)(rect.Height()-r*2), (INT)(r), (INT)(rect.Height()) );
|
|
m_CameraDC.Pie( &rect, p1[0], p1[1] );
|
|
*/
|
|
/*
|
|
m_CameraDC.MoveTo( 0, rect.bottom - (INT)l );
|
|
x1 = (INT)( ( cos( m_PTZ.dTilt / 360.0 * 6.2831 ) ) * l );
|
|
y1 = (INT)( ( sin( m_PTZ.dTilt / 360.0 * 6.2831 ) ) * l ) + rect.bottom - (INT)l;
|
|
m_CameraDC.LineTo( x1, y1 );
|
|
*/
|
|
m_CameraDC.SelectObject( pPen );
|
|
m_CameraDC.SelectObject( pBrush );
|
|
}
|
|
|
|
BOOL CLocatorWnd::DestroyWindow()
|
|
{
|
|
CWnd::KillTimer( m_nTimer );
|
|
|
|
return CWnd::DestroyWindow();
|
|
}
|
|
|
|
void CLocatorWnd::OnTimer( UINT nIDEvent )
|
|
{
|
|
BOOL bChange = FALSE;
|
|
|
|
switch( m_dwDirection & PAN_MASK )
|
|
{
|
|
case PAN_LEFT:
|
|
// perform acceleration
|
|
if( m_dPTZ.dPan < 10 )
|
|
m_dPTZ.dPan += 1;
|
|
|
|
// calculate new position
|
|
m_PTZ.dPan -= m_dPTZ.dPan;
|
|
if( m_PTZ.dPan < 0.0 )
|
|
m_PTZ.dPan += 360.0;
|
|
|
|
// remember changes
|
|
bChange = TRUE;
|
|
break;
|
|
case PAN_RIGTH:
|
|
// perform acceleration
|
|
if( m_dPTZ.dPan < 10 )
|
|
m_dPTZ.dPan += 1;
|
|
|
|
// calculate new position
|
|
m_PTZ.dPan += m_dPTZ.dPan;
|
|
if( m_PTZ.dPan >= 360.0 )
|
|
m_PTZ.dPan -= 360.0;
|
|
bChange = TRUE;
|
|
break;
|
|
case PAN_STOP:
|
|
default:
|
|
break;
|
|
}
|
|
switch( m_dwDirection & TILT_MASK )
|
|
{
|
|
case TILT_UP:
|
|
// perform acceleration
|
|
if( m_dPTZ.dTilt < 10 )
|
|
m_dPTZ.dTilt += 1;
|
|
|
|
// calculate new position
|
|
m_PTZ.dTilt -= m_dPTZ.dTilt;
|
|
if( m_PTZ.dTilt < -30.0 )
|
|
m_PTZ.dTilt = -30.0;
|
|
bChange = TRUE;
|
|
break;
|
|
case TILT_DOWN:
|
|
// perform acceleration
|
|
if( m_dPTZ.dTilt < 10 )
|
|
m_dPTZ.dTilt += 1;
|
|
|
|
// calculate new position
|
|
m_PTZ.dTilt += m_dPTZ.dTilt;
|
|
if( m_PTZ.dTilt > 90.0 )
|
|
m_PTZ.dTilt = 90.0;
|
|
bChange = TRUE;
|
|
break;
|
|
case TILT_STOP:
|
|
default:
|
|
break;
|
|
}
|
|
switch( m_dwDirection & ZOOM_MASK )
|
|
{
|
|
case ZOOM_TELE:
|
|
// perform acceleration
|
|
if( m_dPTZ.dZoom < 0.10 )
|
|
m_dPTZ.dZoom += 0.01;
|
|
|
|
// calculate new position
|
|
m_PTZ.dZoom += m_dPTZ.dZoom;
|
|
if( m_PTZ.dZoom > 1.0 )
|
|
m_PTZ.dZoom = 1.0;
|
|
bChange = TRUE;
|
|
break;
|
|
case ZOOM_WIDE:
|
|
// perform acceleration
|
|
if( m_dPTZ.dZoom < 0.10 )
|
|
m_dPTZ.dZoom += 0.01;
|
|
|
|
// calculate new position
|
|
m_PTZ.dZoom -= m_dPTZ.dZoom;
|
|
if( m_PTZ.dZoom < 0.0 )
|
|
m_PTZ.dZoom = 0.0;
|
|
bChange = TRUE;
|
|
break;
|
|
case ZOOM_STOP:
|
|
default:
|
|
break;
|
|
}
|
|
|
|
// apply changes
|
|
if( bChange )
|
|
{
|
|
RedrawCamera();
|
|
InvalidateRect( NULL, FALSE );
|
|
m_bChange = TRUE;
|
|
m_nChangeTime = 10;
|
|
m_pCameraPositionWnd->SetPosition( m_PTZ.dPan, m_PTZ.dTilt, m_PTZ.dZoom, m_bSynchronizedTilt );
|
|
}
|
|
|
|
if( m_bChange )
|
|
{
|
|
if( m_nChangeTime-- <= 0 )
|
|
{
|
|
GetParent()->SendMessage( LG_CAMERA_POSITION_CHANGED );
|
|
m_bChange = FALSE;
|
|
}
|
|
}
|
|
|
|
/*
|
|
if( rand()%2 )
|
|
{
|
|
AddTarget( rand() % 360, (rand() % 100) / 100.0, RGB(0xE0,0xE0,0) );
|
|
}
|
|
*/
|
|
CWnd::OnTimer(nIDEvent);
|
|
}
|
|
|
|
void CLocatorWnd::MovePTZ( DWORD dwDir )
|
|
{
|
|
if( dwDir & PAN_MASK )
|
|
{
|
|
if( ( m_dwDirection & PAN_MASK ) != ( dwDir & PAN_MASK ) )
|
|
{
|
|
m_dPTZ.dPan = 0;
|
|
m_dwDirection = ( m_dwDirection & ~PAN_MASK ) | ( dwDir & PAN_MASK );
|
|
}
|
|
m_bSynchronizedPan = FALSE;
|
|
}
|
|
|
|
if( dwDir & TILT_MASK )
|
|
{
|
|
if( ( m_dwDirection & TILT_MASK ) != ( dwDir & TILT_MASK ) )
|
|
{
|
|
m_dPTZ.dTilt = 0;
|
|
m_dwDirection = ( m_dwDirection & ~TILT_MASK ) | ( dwDir & TILT_MASK );
|
|
}
|
|
m_bSynchronizedTilt = FALSE;
|
|
}
|
|
|
|
if( dwDir & ZOOM_MASK )
|
|
{
|
|
if( ( m_dwDirection & ZOOM_MASK ) != ( dwDir & ZOOM_MASK ) )
|
|
{
|
|
m_dPTZ.dZoom = 0;
|
|
m_dwDirection = ( m_dwDirection & ~ZOOM_MASK ) | ( dwDir & ZOOM_MASK );
|
|
}
|
|
m_bSynchronizedPan = FALSE;
|
|
m_bSynchronizedTilt = FALSE;
|
|
}
|
|
}
|
|
|
|
BOOL CLocatorWnd::AddTarget( double dAngle, double dRange, COLORREF color )
|
|
{
|
|
// paint video frame
|
|
CRect rect;
|
|
GetClientRect( &rect );
|
|
|
|
// calculate positions
|
|
INT w = rect.Width() / 2;
|
|
INT h = rect.Height() / 2;
|
|
INT x = (INT)( ( cos( dAngle / 360.0 * 6.2831 ) ) * dRange * w + w );
|
|
INT y = (INT)( ( -sin( dAngle / 360.0 * 6.2831 ) ) * dRange * h + h );
|
|
|
|
// draw
|
|
CBrush brush( color );
|
|
CPen pen( PS_SOLID, 1, color );
|
|
CBrush *pBrush = m_FieldDC.SelectObject( &brush );
|
|
CPen *pPen = m_FieldDC.SelectObject( &pen );
|
|
m_FieldDC.Ellipse( x-2, y-2, x+2, y+2 );
|
|
m_FieldDC.SelectObject( pPen );
|
|
m_FieldDC.SelectObject( pBrush );
|
|
|
|
CWnd::InvalidateRect( NULL, FALSE );
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CLocatorWnd::ValidatePTZ( double dPan, double dTilt, double dZoom )
|
|
{
|
|
double dP = fabs(m_PTZ.dPan - dPan);
|
|
double dT = fabs(m_PTZ.dTilt - dTilt);
|
|
double dZ = fabs(m_PTZ.dZoom - dZoom);
|
|
|
|
BOOL bSynchronizedZoom = dZ < 0.1 || dZ > 0.8;
|
|
|
|
m_bSynchronizedPan = ( dP < 10 || dP > 350 ) && bSynchronizedZoom;
|
|
m_bSynchronizedTilt = ( dT < 10 || dT > 80 ) && bSynchronizedZoom;
|
|
|
|
m_pCameraPositionWnd->SetPosition( m_PTZ.dPan, m_PTZ.dTilt, m_PTZ.dZoom, m_bSynchronizedTilt );
|
|
|
|
RedrawCamera();
|
|
|
|
CWnd::InvalidateRect( NULL, FALSE );
|
|
}
|
|
|
|
BOOL CLocatorWnd::SetBackgroundDIB( CLgImageDIB *pDIB )
|
|
{
|
|
CRect rect;
|
|
GetClientRect( &rect );
|
|
BITMAPINFOHEADER *pBmih = *pDIB;
|
|
if( !pBmih || !m_BackgroundDC.Create( pBmih->biWidth, pBmih->biHeight ) )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLocatorWnd::SetBackgroundDIB"), _T("m_BackgroundDC.Create failed") );
|
|
}
|
|
else
|
|
if( pDIB->Draw( m_BackgroundDC, &rect ) && pDIB->Draw( m_FieldDC, &rect ) )
|
|
{
|
|
InvalidateRect( NULL, FALSE );
|
|
}
|
|
return m_bBackground = TRUE;
|
|
}
|