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.
438 lines
13 KiB
438 lines
13 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 08/10/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: TroubleListWnd.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of TroubleListWnd.cpp
|
|
//----------------------------------------------------------------------------
|
|
#include "stdafx.h"
|
|
#include "chicago.h"
|
|
#include "TroubleListWnd.h"
|
|
#include "..\..\lglib\lgaux.h"
|
|
#include "..\DLIB\SensorLGS.h"
|
|
#include "..\DLIB\SensorDC.h"
|
|
#include "..\DLIB\SensorCLD.h"
|
|
#include "..\..\LgLib\Version.h"
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
BEGIN_MESSAGE_MAP(CTroubleListWnd, CLgListWnd)
|
|
//{{AFX_MSG_MAP(CTroubleListWnd)
|
|
ON_WM_LBUTTONDOWN()
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
CTroubleListWnd::CTroubleListWnd()
|
|
{
|
|
m_pSensorArray = NULL;
|
|
m_hIconPower = NULL;
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CTroubleListWnd::CTroubleListWnd") );
|
|
}
|
|
|
|
CTroubleListWnd::~CTroubleListWnd()
|
|
{
|
|
RemoveAll();
|
|
|
|
if( m_hIconPower )
|
|
DestroyIcon( m_hIconPower );
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CTroubleListWnd::~CTroubleListWnd") );
|
|
}
|
|
|
|
void CTroubleListWnd::OnItemDraw( CDC *pDC, CRect *pRect, void *pItem, BOOL bActive )
|
|
{
|
|
LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CTroubleListWnd::OnItemDraw"), _T("Started...") );
|
|
|
|
PTROUBLE pTrouble = (PTROUBLE)pItem;
|
|
|
|
CSensor *pSensor = pTrouble->pSensor;
|
|
|
|
// copy minimap background
|
|
pDC->BitBlt( pRect->left, pRect->top, pRect->Width(), pRect->Height(), &m_MemoryDC, 0, 0, SRCCOPY );
|
|
|
|
int cxImage = (int)((m_ItemSize.cy - 20)*4./3.);
|
|
int cyImage = m_ItemSize.cy - 20;
|
|
|
|
// copy minimap background
|
|
pDC->BitBlt( pRect->left, pRect->top, cxImage, cyImage, &pTrouble->dcDraw, 0, 0, SRCCOPY );
|
|
|
|
// fill line under bottom text
|
|
pDC->FillSolidRect( pRect->left, pRect->bottom - 20, pRect->Width(), 20, pSensor->GetStateColor( m_bOddUpdate ) );
|
|
|
|
// draw target lines
|
|
COLORREF color[2] = { RGB(0xFF,0xFF,0xFF), RGB(0,0,0) };
|
|
|
|
CPen pen( PS_DOT, 1, m_bOddUpdate ? color[0] : color[1] );
|
|
CPen *pPen = pDC->SelectObject( &pen );
|
|
int nBkColor = pDC->SetBkColor( m_bOddUpdate ? color[1] : color[0] );
|
|
|
|
CPoint pos( (int)(m_MinimapRect.Width() * pSensor->GetPosition().x),
|
|
(int)(m_MinimapRect.Height() * pSensor->GetPosition().y) );
|
|
pos += m_MinimapRect.TopLeft() + pRect->TopLeft();
|
|
pDC->MoveTo( pos.x, m_MinimapRect.top + pRect->top );
|
|
pDC->LineTo( pos.x, m_MinimapRect.bottom + pRect->top );
|
|
pDC->MoveTo( m_MinimapRect.left + pRect->left, pos.y );
|
|
pDC->LineTo( m_MinimapRect.right + pRect->left, pos.y );
|
|
|
|
pDC->SetBkColor( nBkColor );
|
|
pDC->SelectObject( pPen );
|
|
|
|
// draw bottom text
|
|
COLORREF nColor = pDC->SetTextColor( pSensor->GetStateColor( !m_bOddUpdate ) );
|
|
INT nBkMode = pDC->SetBkMode( TRANSPARENT );
|
|
|
|
CRect TextRect( pRect->left + 20, pRect->bottom - 20, pRect->right, pRect->bottom );
|
|
|
|
pDC->DrawText( pSensor->GetName(), &TextRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
|
|
|
|
pDC->SetTextColor( nColor );
|
|
pDC->SetBkMode( nBkMode );
|
|
|
|
// additional work
|
|
switch( pSensor->GetType() )
|
|
{
|
|
case CVisual::LGS:
|
|
switch( pSensor->GetState() )
|
|
{
|
|
case CSensor::NORMAL:
|
|
case CSensor::ALARM:
|
|
case CSensor::POSTALARM:
|
|
if( !static_cast<CSensorLGS*>(pSensor)->IsPowered() && !m_bOddUpdate )
|
|
pDC->DrawIcon( pRect->left, pRect->bottom - GetSystemMetrics( SM_CXICON ), m_hIconPower );
|
|
|
|
if( static_cast<CSensorLGS*>(pSensor)->IsSetHzInProgress() )
|
|
{
|
|
TCHAR pText[MAX_PATH];
|
|
_sntprintf( pText, MAX_PATH, _T("Upload %d%%"), static_cast<CSensorLGS*>(pSensor)->GetSetHzProgress() );
|
|
|
|
nColor = pDC->SetTextColor( pSensor->GetStateColor( !m_bOddUpdate ) );
|
|
nBkMode = pDC->SetBkMode( TRANSPARENT );
|
|
|
|
TextRect.SetRect( pRect->left + 20, pRect->bottom - 20, pRect->right, pRect->bottom );
|
|
pDC->DrawText( pText, &TextRect, /*DT_CENTER | */DT_VCENTER | DT_SINGLELINE );
|
|
|
|
pDC->SetTextColor( nColor );
|
|
pDC->SetBkMode( nBkMode );
|
|
}
|
|
else
|
|
if( static_cast<CSensorLGS*>(pSensor)->IsInStudyMode() )
|
|
{
|
|
TCHAR pText[MAX_PATH];
|
|
_sntprintf( pText, MAX_PATH, _T("Adaptation") );
|
|
|
|
nColor = pDC->SetTextColor( pSensor->GetStateColor( !m_bOddUpdate ) );
|
|
nBkMode = pDC->SetBkMode( TRANSPARENT );
|
|
|
|
TextRect.SetRect( pRect->left + 20, pRect->bottom - 20, pRect->right, pRect->bottom );
|
|
pDC->DrawText( pText, &TextRect, /*DT_CENTER | */DT_VCENTER | DT_SINGLELINE );
|
|
|
|
pDC->SetTextColor( nColor );
|
|
pDC->SetBkMode( nBkMode );
|
|
}
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
|
|
LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CTroubleListWnd::OnItemDraw"), _T("Done") );
|
|
}
|
|
|
|
void CTroubleListWnd::OnItemMove( void* pItem, CRect *pRect, BOOL bShow, BOOL bActive )
|
|
{
|
|
LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CTroubleListWnd::OnItemMove"), _T("Started...") );
|
|
|
|
if( bShow )
|
|
InvalidateRect( NULL );
|
|
|
|
LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CTroubleListWnd::OnItemMove"), _T("Done") );
|
|
}
|
|
|
|
BOOL CTroubleListWnd::Create( CWnd *pParentWnd, int x, int y, int nWidth, int nHeight, CLgUIMapBackground *pBackground )
|
|
{
|
|
// load icon
|
|
m_hIconPower = (HICON)::LoadImage( AfxGetInstanceHandle(), (LPCTSTR)IDI_ICON_POWER, IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR );
|
|
|
|
if( !CLgListWnd::Create( pParentWnd, x, y, nWidth, nHeight ) )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CTroubleListWnd::Create"), _T("CLgListWnd::Create failed") );
|
|
return FALSE;
|
|
}
|
|
|
|
CWnd::ModifyStyle( 0, WS_DLGFRAME | WS_CLIPSIBLINGS );
|
|
|
|
int ik = 35;
|
|
|
|
int iWidth = ik * 7;
|
|
int iHeight = ik * 3 + 20;
|
|
|
|
if( !SetItemSize( CSize( iWidth, iHeight ) ) )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CTroubleListWnd::Create"), _T("SetItemSize failed") );
|
|
return FALSE;
|
|
}
|
|
|
|
if( !m_MemoryDC.Create( m_ItemSize.cx, m_ItemSize.cy, RGB(0x7F,0x7F,0x7F) ) )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CTroubleListWnd::Create"), _T("m_MemoryDC.Create failed") );
|
|
return FALSE;
|
|
}
|
|
|
|
if( !pBackground )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CTroubleListWnd::Create"), _T("pBackground is NULL") );
|
|
return TRUE;
|
|
}
|
|
|
|
CRect WholeRect( m_ItemSize.cx - (m_ItemSize.cy - 20), 0, m_ItemSize.cx, m_ItemSize.cy - 20 );
|
|
|
|
double dAspect = ((double)pBackground->GetSize().cx) / ((double)pBackground->GetSize().cy);
|
|
|
|
FitRectWithAspect( &WholeRect, &m_MinimapRect, dAspect );
|
|
|
|
pBackground->Draw( &m_MemoryDC, &m_MinimapRect );
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CTroubleListWnd::Create"), _T("Succeeded") );
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
void CTroubleListWnd::UpdateInfo( BOOL bOdd )
|
|
{
|
|
if( !m_pSensorArray )
|
|
return;
|
|
|
|
BOOL bChanged = FALSE;
|
|
|
|
for( int i = 0; i < m_pSensorArray->GetSensorCount(); i++ )
|
|
{
|
|
CSensor *pSensor = m_pSensorArray->GetSensor( i );
|
|
|
|
ASSERT( pSensor );
|
|
|
|
BOOL bInTrouble = pSensor->GetState() != CSensor::NORMAL;
|
|
|
|
// pefrom additional checking
|
|
switch( pSensor->GetType() )
|
|
{
|
|
case CVisual::LGS:
|
|
if( !bInTrouble &&
|
|
( !static_cast<CSensorLGS*>(pSensor)->IsPowered() || static_cast<CSensorLGS*>(pSensor)->IsSetHzInProgress() || static_cast<CSensorLGS*>(pSensor)->IsInStudyMode() ) )
|
|
bInTrouble = TRUE;
|
|
break;
|
|
}
|
|
|
|
// if sensor has some problems
|
|
if( bInTrouble )
|
|
{
|
|
BOOL bFound = FALSE;
|
|
|
|
PTROUBLE pFoundTrouble;
|
|
|
|
for( int j = 0; j < m_ArrayItem.GetSize(); j++ )
|
|
{
|
|
PTROUBLE pTrouble = (PTROUBLE)m_ArrayItem[j];
|
|
|
|
ASSERT( pTrouble );
|
|
|
|
if( pTrouble->nType == TT_SENSOR &&
|
|
pTrouble->pSensor == pSensor )
|
|
{
|
|
bFound = TRUE;
|
|
pFoundTrouble = pTrouble;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if( bFound )
|
|
{
|
|
if( !m_pSensorArray->GetSetupSettings().bTroubleWindowShowFirstImage && pFoundTrouble->nBitmapCount )
|
|
{
|
|
DWORD dwTime = GetTickCount();
|
|
if( ( dwTime - pFoundTrouble->dwImageTime ) >= TROUBLE_IMAGE_TIMEOUT )
|
|
{
|
|
pFoundTrouble->dwImageTime = dwTime;
|
|
|
|
if( pFoundTrouble->nImageSkip )
|
|
pFoundTrouble->nImageSkip--;
|
|
else
|
|
{
|
|
HBITMAP hBitmap = pFoundTrouble->pBitmap[ pFoundTrouble->nBitmapIndexView ];
|
|
|
|
// increase view counter
|
|
pFoundTrouble->nBitmapIndexView = ( pFoundTrouble->nBitmapIndexView + 1 ) % pFoundTrouble->nBitmapCount;
|
|
|
|
CLgMemoryDC dc;
|
|
dc.Create( hBitmap );
|
|
|
|
int nStretchMode = pFoundTrouble->dcDraw.SetStretchBltMode( COLORONCOLOR );
|
|
pFoundTrouble->dcDraw.StretchBlt( 0, 0, pFoundTrouble->dcDraw.GetSize().cx, pFoundTrouble->dcDraw.GetSize().cy, &dc, 0,0,dc.GetSize().cx, dc.GetSize().cy, SRCCOPY );
|
|
pFoundTrouble->dcDraw.SetStretchBltMode( nStretchMode );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
PTROUBLE pTrouble = new TROUBLE;
|
|
|
|
int cxImage = (int)((m_ItemSize.cy - 20)*4./3.);
|
|
int cyImage = m_ItemSize.cy - 20;
|
|
|
|
ASSERT( pTrouble );
|
|
|
|
pTrouble->nType = TT_SENSOR;
|
|
pTrouble->pSensor = pSensor;
|
|
pTrouble->dcDraw.Create( cxImage, cyImage, RGB(0x7f,0x7f,0x7f) );
|
|
|
|
CRect SensorRect( 0, 0, cxImage, cyImage );
|
|
CRect DrawRect;
|
|
FitRectWithAspect( &SensorRect, &DrawRect, 1.0 );
|
|
|
|
CLgMemoryDC *pSrcDC;
|
|
switch( pSensor->GetType() )
|
|
{
|
|
case CSensor::LGS:
|
|
pSrcDC = ((CSensorLGS*)pSensor)->GetSurface();
|
|
pTrouble->dcDraw.StretchBlt( DrawRect.left, DrawRect.top, DrawRect.Width(), DrawRect.Height(), pSrcDC, 0, 0, pSrcDC->GetSize().cx, pSrcDC->GetSize().cy, SRCCOPY );
|
|
break;
|
|
case CSensor::DC:
|
|
pSrcDC = ((CSensorDC*)pSensor)->GetBG();
|
|
pTrouble->dcDraw.StretchBlt( DrawRect.left, DrawRect.top, DrawRect.Width(), DrawRect.Height(), pSrcDC, 0, 0, pSrcDC->GetSize().cx, pSrcDC->GetSize().cy, SRCCOPY );
|
|
break;
|
|
case CSensor::CLD:
|
|
pSrcDC = ((CSensorCLD*)pSensor)->GetSurface();
|
|
pTrouble->dcDraw.StretchBlt( DrawRect.left, DrawRect.top, DrawRect.Width(), DrawRect.Height(), pSrcDC, 0, 0, pSrcDC->GetSize().cx, pSrcDC->GetSize().cy, SRCCOPY );
|
|
break;
|
|
}
|
|
|
|
if( Add( pTrouble ) )
|
|
bChanged = TRUE;
|
|
else
|
|
{
|
|
// delete pTrouble;
|
|
OnItemRemove( pTrouble );
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
BOOL bFound = FALSE;
|
|
|
|
for( int j = 0; j < m_ArrayItem.GetSize(); j++ )
|
|
{
|
|
PTROUBLE pTrouble = (PTROUBLE)m_ArrayItem[j];
|
|
|
|
ASSERT( pTrouble );
|
|
|
|
if( pTrouble->nType == TT_SENSOR &&
|
|
pTrouble->pSensor == pSensor )
|
|
{
|
|
if( Remove( pTrouble ) )
|
|
bChanged = TRUE;
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
m_bOddUpdate = bOdd;
|
|
|
|
InvalidateRect( NULL );
|
|
}
|
|
|
|
void CTroubleListWnd::OnLButtonDown(UINT nFlags, CPoint point)
|
|
{
|
|
PTROUBLE pTrouble = (PTROUBLE)GetItemFromPoint( &point );
|
|
|
|
if( pTrouble && pTrouble->nType == TT_SENSOR )
|
|
{
|
|
CSensor *pSensor = pTrouble->pSensor;
|
|
if( pSensor )
|
|
{
|
|
GetParent()->SendMessage( WM_SENSOR_SHOW, (WPARAM)pSensor, (LPARAM)pSensor );
|
|
}
|
|
}
|
|
|
|
CLgListWnd::OnLButtonDown(nFlags, point);
|
|
}
|
|
|
|
void CTroubleListWnd::OnItemRemove( void *pItem )
|
|
{
|
|
PTROUBLE pTrouble = (PTROUBLE)pItem;
|
|
|
|
for( INT i = 0; i < pTrouble->nBitmapCount; i++ )
|
|
::DeleteObject( pTrouble->pBitmap[i] );
|
|
|
|
delete pTrouble;
|
|
// delete (PTROUBLE)pItem;
|
|
}
|
|
|
|
void CTroubleListWnd::SetItemImage( CSensor *pSensor, HBITMAP hBitmap )
|
|
{
|
|
if( !pSensor || !hBitmap )
|
|
return;
|
|
|
|
BOOL bDelete = TRUE;
|
|
|
|
for( int j = 0; j < m_ArrayItem.GetSize(); j++ )
|
|
{
|
|
PTROUBLE pTrouble = (PTROUBLE)m_ArrayItem[j];
|
|
|
|
ASSERT( pTrouble );
|
|
|
|
if( pTrouble->nType == TT_SENSOR && pTrouble->pSensor == pSensor )
|
|
{
|
|
CLgMemoryDC dc;
|
|
dc.Create( hBitmap );
|
|
|
|
if( !m_pSensorArray->GetSetupSettings().bTroubleWindowShowFirstImage ||
|
|
!pTrouble->bImage )
|
|
{
|
|
pTrouble->bImage = TRUE;
|
|
|
|
int nStretchMode = pTrouble->dcDraw.SetStretchBltMode( COLORONCOLOR );
|
|
pTrouble->dcDraw.StretchBlt( 0, 0, pTrouble->dcDraw.GetSize().cx, pTrouble->dcDraw.GetSize().cy, &dc, 0,0,dc.GetSize().cx, dc.GetSize().cy, SRCCOPY );
|
|
pTrouble->dcDraw.SetStretchBltMode( nStretchMode );
|
|
}
|
|
|
|
// delete previous image (if any)
|
|
if( pTrouble->pBitmap[ pTrouble->nBitmapIndexAdd ] )
|
|
::DeleteObject( pTrouble->pBitmap[ pTrouble->nBitmapIndexAdd ] );
|
|
|
|
// store image in list
|
|
pTrouble->pBitmap[ pTrouble->nBitmapIndexAdd ] = hBitmap;
|
|
|
|
// store last image index
|
|
pTrouble->nBitmapIndexView = pTrouble->nBitmapIndexAdd;
|
|
|
|
// increase image counter
|
|
if( pTrouble->nBitmapCount < pSensor->GetImageCount() )
|
|
pTrouble->nBitmapCount++;
|
|
|
|
// increase image position
|
|
pTrouble->nBitmapIndexAdd = ( pTrouble->nBitmapIndexAdd + 1 ) % pSensor->GetImageCount();
|
|
|
|
pTrouble->dwImageTime = GetTickCount();
|
|
pTrouble->nImageSkip = TROUBLE_IMAGE_SKIP;
|
|
|
|
// don't delete!
|
|
bDelete = FALSE;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if( bDelete )
|
|
::DeleteObject( hBitmap );
|
|
}
|