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.
195 lines
4.4 KiB
195 lines
4.4 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 08/10/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: BorderLGS.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of BorderLGS.cpp
|
|
//----------------------------------------------------------------------------
|
|
#include "stdafx.h"
|
|
#include "BorderLGS.h"
|
|
#include "..\..\LgLib\Version.h"
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
CBorderLGS::CBorderLGS()
|
|
{
|
|
m_pBorder = NULL;
|
|
m_nBorder = 0;
|
|
|
|
// log info
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CBorderLGS::CBorderLGS" );
|
|
}
|
|
|
|
CBorderLGS::~CBorderLGS()
|
|
{
|
|
Destroy();
|
|
|
|
// log info
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CBorderLGS::~CBorderLGS" );
|
|
}
|
|
|
|
BOOL CBorderLGS::Copy( CBorderLGS *pBorderLGS )
|
|
{
|
|
Destroy();
|
|
|
|
if( !pBorderLGS )
|
|
return FALSE;
|
|
|
|
m_nBorder = pBorderLGS->m_nBorder;
|
|
if( m_nBorder )
|
|
{
|
|
m_pBorder = new BORDER[ m_nBorder ];
|
|
if( !m_pBorder )
|
|
m_nBorder = 0;
|
|
|
|
::CopyMemory( m_pBorder, pBorderLGS->m_pBorder, sizeof(BORDER) * m_nBorder );
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CBorderLGS::LoadAsSingleIPI( LPCTSTR pFileName )
|
|
{
|
|
HANDLE hFile = ::CreateFile( "DrawMap.dat", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
|
|
if( hFile )
|
|
{
|
|
Destroy();
|
|
|
|
DWORD dwRead;
|
|
|
|
::ReadFile( hFile, &m_nBorder, sizeof( m_nBorder ), &dwRead, NULL );
|
|
|
|
if( m_nBorder )
|
|
{
|
|
m_pBorder = new BORDER[ m_nBorder ];
|
|
if( !m_pBorder )
|
|
m_nBorder = 0;
|
|
|
|
::ReadFile( hFile, m_pBorder, sizeof( BORDER ) * m_nBorder, &dwRead, NULL );
|
|
}
|
|
|
|
::CloseHandle( hFile );
|
|
}
|
|
}
|
|
|
|
void CBorderLGS::SaveAsSingleIPI( LPCTSTR pFileName )
|
|
{
|
|
HANDLE hFile = ::CreateFile( "DrawMap.dat", GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL );
|
|
if( hFile )
|
|
{
|
|
DWORD dwWritten;
|
|
::WriteFile( hFile, &m_nBorder, sizeof( m_nBorder ), &dwWritten, NULL );
|
|
::WriteFile( hFile, m_pBorder, sizeof( BORDER ) * m_nBorder, &dwWritten, NULL );
|
|
::CloseHandle( hFile );
|
|
}
|
|
}
|
|
|
|
void CBorderLGS::Serialize(CArchive &ar)
|
|
{
|
|
if( ar.IsStoring() )
|
|
{
|
|
ar << m_nBorder;
|
|
for( int i = 0; i < m_nBorder; i++ )
|
|
{
|
|
for( int j = 0; j < 2; j++ )
|
|
{
|
|
ar << m_pBorder[i].bExist[j];
|
|
ar << m_pBorder[i].dAngle[j];
|
|
ar << m_pBorder[i].dRange[j];
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Destroy();
|
|
|
|
ar >> m_nBorder;
|
|
|
|
m_pBorder = new BORDER[ m_nBorder ];
|
|
if( !m_pBorder )
|
|
m_nBorder = 0;
|
|
|
|
for( int i = 0; i < m_nBorder; i++ )
|
|
{
|
|
for( int j = 0; j < 2; j++ )
|
|
{
|
|
ar >> m_pBorder[i].bExist[j];
|
|
ar >> m_pBorder[i].dAngle[j];
|
|
ar >> m_pBorder[i].dRange[j];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void CBorderLGS::Destroy()
|
|
{
|
|
if( m_pBorder )
|
|
{
|
|
if( m_pBorder )
|
|
delete [] m_pBorder;
|
|
m_pBorder = NULL;
|
|
}
|
|
m_nBorder = 0;
|
|
}
|
|
|
|
BOOL CBorderLGS::Draw( CDC *pDC, CPoint *pCenter, double dScaleToPixel, double dRotateAngle )
|
|
{
|
|
// log info
|
|
LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, "CBorderLGS::Draw", "Start..." );
|
|
|
|
// COLORREF LsgColor[] = { RGB( 0xEF, 0xEF, 0 ), RGB( 0xEF, 0xEF, 0xEF ) };
|
|
COLORREF LsgColor[] = { RGB( 0xAF, 0xAF, 0 ), RGB( 0xAF, 0xAF, 0 ) };
|
|
|
|
if( m_pBorder && m_nBorder )
|
|
{
|
|
for( INT n = 0; n < 2; n++ )
|
|
{
|
|
LPPOINT pPolygon = new POINT[m_nBorder + 1];
|
|
if( pPolygon )
|
|
{
|
|
for( INT i = 0; i <= m_nBorder; i ++ )
|
|
{
|
|
BORDER *pBorder = &m_pBorder[ i % m_nBorder ];
|
|
|
|
double dz = 3.14 / 180.0 * ( pBorder->dAngle[n] + dRotateAngle );
|
|
|
|
double xp = cos( dz ) * pBorder->dRange[n] * dScaleToPixel;
|
|
double yp = sin( dz ) * pBorder->dRange[n] * dScaleToPixel;
|
|
|
|
pPolygon[i].x = (INT)(xp + pCenter->x + 0.5);
|
|
pPolygon[i].y = (INT)(pCenter->y - yp + 0.5);
|
|
}
|
|
|
|
CPen pen( PS_SOLID, 1, LsgColor[n] );
|
|
CPen *pPen = pDC->SelectObject( &pen );
|
|
CBrush brush( HS_DIAGCROSS, LsgColor[n] );
|
|
CBrush *pBrush = pDC->SelectObject( &brush );
|
|
INT nBkMode = pDC->SetBkMode( TRANSPARENT );
|
|
|
|
pDC->Polygon( pPolygon, m_nBorder );
|
|
// pDC->Polyline( pPolygon, m_nBorder + 1 );
|
|
|
|
pDC->SetBkMode( nBkMode );
|
|
pDC->SelectObject( pPen );
|
|
pDC->SelectObject( pBrush );
|
|
|
|
delete [] pPolygon;
|
|
}
|
|
}
|
|
}
|
|
|
|
// log info
|
|
LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, "CBorderLGS::Draw", "Done" );
|
|
|
|
return TRUE;
|
|
}
|