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.
 
 
 
 
 

512 lines
17 KiB

//----------------------------------------------------------------------------
// Laser Guard Ltd.
// Copyright © 2000-2002. All Rights Reserved.
// Version 1.0 01/01/2000
// Last modification: 08/10/2003
// PROJECT:
// SUBSYSTEM:
// FILE: CalibratePTZDlg.cpp
// AUTHOR: Sergey Chizhevskiy
// OVERVIEW
// ~~~~~~~~
// Source file of CalibratePTZDlg.cpp
//----------------------------------------------------------------------------
#include "stdafx.h"
#include "CalibratePTZDlg.h"
#include "Application.h"
#include "..\LgLib\Version.h"
CCalibratePTZDlg::CCalibratePTZDlg()
{
m_pApplication = NULL;
m_bNeedSendGetPosition = FALSE;
m_bNeedCheckPosition = FALSE;
m_bNeedSetPosition = FALSE;
m_dPositionPan = m_dPositionTilt = m_dPositionZoom = m_dPositionFocus = 0;
m_dAngle = 0;
m_dPanShift = 0;
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CCalibratePTZDlg::CCalibratePTZDlg") );
}
CCalibratePTZDlg::~CCalibratePTZDlg()
{
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CCalibratePTZDlg::~CCalibratePTZDlg") );
}
UINT CCalibratePTZDlg::DoModal( CApplication* pApplication, HWND hParent )
{
HINSTANCE hInstance = (HINSTANCE)::GetWindowLong( hParent, GWL_HINSTANCE );
m_pApplication = pApplication;
return CGenericWnd::DoModal( hInstance, (LPCTSTR)IDD_CALIBRATE_PTZ_DLG, hParent );
}
LRESULT CCalibratePTZDlg::OnDestroy( WPARAM wParam, LPARAM lParam )
{
return CGenericWnd::OnDestroy( wParam, lParam );
}
BOOL CCalibratePTZDlg::CActiveButton::AttachButton( HWND hWnd, UINT uIconID )
{
if( !SubClassWindow( hWnd ) )
{
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CCalibratePTZDlg::CActiveButton::AttachButton"), _T("SubClassWindow failed") );
return FALSE;
}
m_dSpeed = 0.0;
m_bPressed = FALSE;
m_hIcon = ::LoadIcon( (HINSTANCE)GetWindowLong( GWL_HINSTANCE ), (LPCTSTR)uIconID );
return SendMessage( BM_SETIMAGE, IMAGE_ICON, (LPARAM)m_hIcon );
}
LRESULT CCalibratePTZDlg::CActiveButton::WindowProc( UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch( uMsg )
{
case WM_CREATE:
m_hIcon = NULL;
break;
case BM_SETSTATE:
// send appropriate WM_COMMAND to the parent wnd
::SendMessage( GetParent(), WM_COMMAND, MAKEWPARAM( GetWindowLong(GWL_ID), wParam ? BN_PUSHED : BN_UNPUSHED ), (LPARAM)GetSafeHwnd() );
break;
case WM_DESTROY:
if( m_hIcon )
{
::DeleteObject( m_hIcon );
m_hIcon = NULL;
}
break;
}
return CGenericWnd::WindowProc( uMsg, wParam, lParam );
};
LRESULT CCalibratePTZDlg::OnCommand( WPARAM wParam, LPARAM lParam )
{
if( HIWORD(wParam) == BN_CLICKED )
{
switch( LOWORD(wParam) )
{
case IDOK:
OnButtonOk();
break;
case IDCANCEL:
OnButtonCancel();
break;
case IDC_BUTTON_GET_PTZF:
OnButtonGetPTZF();
break;
case IDC_BUTTON_UPDATE_SHIFT:
OnButtonUpdatePanShift();
break;
case IDC_CHECK_TABLE:
OnCheckTablePanShift();
break;
case IDC_RADIO_RANGE0:
case IDC_RADIO_RANGE1:
case IDC_RADIO_RANGE2:
case IDC_RADIO_RANGE3:
case IDC_RADIO_RANGE4:
case IDC_RADIO_RANGE5:
case IDC_RADIO_RANGE6:
case IDC_RADIO_RANGE7:
case IDC_RADIO_RANGE8:
case IDC_RADIO_RANGE9:
OnRadioRange();
break;
case IDC_CHECK_SYNCHRONIZE:
OnCheckSynchronize();
break;
}
}
switch( HIWORD(wParam) )
{
case BN_PUSHED:
case BN_UNPUSHED:
switch( LOWORD(wParam) )
{
case IDC_BUTTON_LEFT: OnPressButtonPTZ( BUTTON_LEFT, HIWORD(wParam) == BN_PUSHED ); break;
case IDC_BUTTON_RIGHT: OnPressButtonPTZ( BUTTON_RIGHT, HIWORD(wParam) == BN_PUSHED ); break;
case IDC_BUTTON_UP: OnPressButtonPTZ( BUTTON_UP, HIWORD(wParam) == BN_PUSHED ); break;
case IDC_BUTTON_DOWN: OnPressButtonPTZ( BUTTON_DOWN, HIWORD(wParam) == BN_PUSHED ); break;
case IDC_BUTTON_TELE: OnPressButtonPTZ( BUTTON_TELE, HIWORD(wParam) == BN_PUSHED ); break;
case IDC_BUTTON_WIDE: OnPressButtonPTZ( BUTTON_WIDE, HIWORD(wParam) == BN_PUSHED ); break;
case IDC_BUTTON_FAR: OnPressButtonPTZ( BUTTON_FAR, HIWORD(wParam) == BN_PUSHED ); break;
case IDC_BUTTON_NEAR: OnPressButtonPTZ( BUTTON_NEAR, HIWORD(wParam) == BN_PUSHED ); break;
}
break;
}
return CGenericWnd::OnCommand( wParam, lParam );
}
LRESULT CCalibratePTZDlg::OnInitDialog( WPARAM wParam, LPARAM lParam )
{
HINSTANCE hInstance = (HINSTANCE)GetWindowLong( GWL_HINSTANCE );
// attach buttons
m_pButton[BUTTON_LEFT].AttachButton( GetDlgItem( IDC_BUTTON_LEFT ), IDI_CAMERA_LEFT );
m_pButton[BUTTON_RIGHT].AttachButton( GetDlgItem( IDC_BUTTON_RIGHT ), IDI_CAMERA_RIGHT );
m_pButton[BUTTON_UP].AttachButton( GetDlgItem( IDC_BUTTON_UP ), IDI_CAMERA_UP );
m_pButton[BUTTON_DOWN].AttachButton( GetDlgItem( IDC_BUTTON_DOWN ), IDI_CAMERA_DOWN );
m_pButton[BUTTON_WIDE].AttachButton( GetDlgItem( IDC_BUTTON_WIDE ), IDI_CAMERA_WIDE );
m_pButton[BUTTON_TELE].AttachButton( GetDlgItem( IDC_BUTTON_TELE ), IDI_CAMERA_TELE );
m_pButton[BUTTON_FAR].AttachButton( GetDlgItem( IDC_BUTTON_FAR ), IDI_CAMERA_FAR );
m_pButton[BUTTON_NEAR].AttachButton( GetDlgItem( IDC_BUTTON_NEAR ), IDI_CAMERA_NEAR );
// init radio buttons
SendDlgItemMessage( IDC_RADIO_RANGE0, BM_SETCHECK, TRUE, 0 );
// initialize values
CProfile *pProfile = m_pApplication->GetProfile();
for( INT i = 0; i < 10; i++ )
{
SendDlgItemMessage( IDC_PTZ_SPIN_ZOOM0 + i, UDM_SETPOS, 0, MAKELONG( pProfile->PtzRangeZoom(i), 0 ) );
SendDlgItemMessage( IDC_PTZ_SPIN_TILT0 + i, UDM_SETPOS, 0, MAKELONG( pProfile->PtzRangeTilt(i), 0 ) );
SendDlgItemMessage( IDC_SPIN_FOCUS0 + i, UDM_SETPOS, 0, MAKELONG( pProfile->PtzRangeFocus(i), 0 ) );
}
m_pButton[BUTTON_UP].EnableWindow( m_pApplication->GetCameraPTZ()->HasTilt() );
m_pButton[BUTTON_DOWN].EnableWindow( m_pApplication->GetCameraPTZ()->HasTilt() );
m_pButton[BUTTON_FAR].EnableWindow( m_pApplication->GetCameraPTZ()->HasFocus() );
m_pButton[BUTTON_NEAR].EnableWindow( m_pApplication->GetCameraPTZ()->HasFocus() );
// init variables
m_bNeedSendGetPosition = FALSE;
m_bNeedCheckPosition = FALSE;
m_bNeedSetPosition = FALSE;
m_dPositionPan = m_dPositionTilt = m_dPositionZoom = m_dPositionFocus = 0;
m_dPanShift = pProfile->PtzPanShift();
// install timer
SetTimer( 1, 100, NULL );
// update dinamic controls
OnRadioRange();
OnCheckSynchronize();
return CGenericWnd::OnInitDialog( wParam, lParam );
}
void CCalibratePTZDlg::OnButtonOk()
{
// store data
CProfile *pProfile = m_pApplication->GetProfile();
for( INT i = 0; i < 10; i++ )
{
pProfile->PtzRangeTilt(i) = SendDlgItemMessage( IDC_PTZ_SPIN_TILT0 + i, UDM_GETPOS, 0, 0 );
pProfile->PtzRangeZoom(i) = SendDlgItemMessage( IDC_PTZ_SPIN_ZOOM0 + i, UDM_GETPOS, 0, 0 );
pProfile->PtzRangeFocus(i) = SendDlgItemMessage( IDC_SPIN_FOCUS0 + i, UDM_GETPOS, 0, 0 );
}
pProfile->PtzPanShiftSet( m_dPanShift );
CGenericWnd::EndDialog( IDOK );
}
void CCalibratePTZDlg::OnButtonCancel()
{
CGenericWnd::EndDialog( IDCANCEL );
}
void CCalibratePTZDlg::EnableControls(BOOL bEnable)
{
// disable averything
m_pButton[BUTTON_LEFT].EnableWindow( bEnable );
m_pButton[BUTTON_RIGHT].EnableWindow( bEnable );
m_pButton[BUTTON_UP].EnableWindow( bEnable && m_pApplication->GetCameraPTZ()->HasTilt() );
m_pButton[BUTTON_DOWN].EnableWindow( bEnable && m_pApplication->GetCameraPTZ()->HasTilt() );
m_pButton[BUTTON_TELE].EnableWindow( bEnable );
m_pButton[BUTTON_WIDE].EnableWindow( bEnable );
m_pButton[BUTTON_FAR].EnableWindow( bEnable && m_pApplication->GetCameraPTZ()->HasFocus() );
m_pButton[BUTTON_NEAR].EnableWindow( bEnable && m_pApplication->GetCameraPTZ()->HasFocus() );
::EnableWindow( GetDlgItem( IDC_BUTTON_GET_PTZF ), bEnable );
// disable radio and edit controls
for( UINT i = 0; i < 10; i++ )
{
::EnableWindow( GetDlgItem( IDC_PTZ_EDIT_ZOOM0 + i ), bEnable );
::EnableWindow( GetDlgItem( IDC_PTZ_EDIT_TILT0 + i ), bEnable && m_pApplication->GetCameraPTZ()->HasTilt() );
::EnableWindow( GetDlgItem( IDC_EDIT_FOCUS0 + i ), bEnable && m_pApplication->GetCameraPTZ()->HasFocus() );
::EnableWindow( GetDlgItem( IDC_RADIO_RANGE0 + i ), bEnable );
}
// disable check controls
::EnableWindow( GetDlgItem( IDC_CHECK_SYNCHRONIZE ), bEnable );
// disable pan shift control
::EnableWindow( GetDlgItem( IDC_BUTTON_UPDATE_SHIFT ), bEnable );
// disable check table control
::EnableWindow( GetDlgItem( IDC_CHECK_TABLE ), bEnable );
}
void CCalibratePTZDlg::OnRadioRange()
{
BOOL bEnabled = ::IsWindowEnabled( GetDlgItem( IDC_CHECK_SYNCHRONIZE ) );
for( UINT i = 0; i < 10; i++ )
{
BOOL bChecked = IsDlgButtonChecked( IDC_RADIO_RANGE0 + i ) && bEnabled;
// enable appropriate controls
::EnableWindow( GetDlgItem( IDC_PTZ_EDIT_ZOOM0 + i ), bChecked );
::EnableWindow( GetDlgItem( IDC_PTZ_EDIT_TILT0 + i ), bChecked && m_pApplication->GetCameraPTZ()->HasTilt() );
::EnableWindow( GetDlgItem( IDC_EDIT_FOCUS0 + i ), bChecked && m_pApplication->GetCameraPTZ()->HasFocus() );
}
}
void CCalibratePTZDlg::OnCheckSynchronize()
{
BOOL bEnable = !IsDlgButtonChecked( IDC_CHECK_SYNCHRONIZE ) && ::IsWindowEnabled( GetDlgItem( IDC_CHECK_SYNCHRONIZE ) );
for( UINT i = 0; i < 10; i++ )
::EnableWindow( GetDlgItem( IDC_RADIO_RANGE0 + i ), bEnable );
}
void CCalibratePTZDlg::OnPressButtonPTZ( INT nButton, BOOL bPressed )
{
// make shortcut to button
CActiveButton *pButton = m_pButton + nButton;
// update press state
pButton->SetPressState( bPressed );
// if button released we should send stop
if( bPressed )
{
switch( nButton )
{
case BUTTON_LEFT: m_pApplication->GetCameraPTZ()->CameraPanLeft( pButton->GetPressSpeed() ); break;
case BUTTON_RIGHT: m_pApplication->GetCameraPTZ()->CameraPanRight( pButton->GetPressSpeed() ); break;
case BUTTON_UP: m_pApplication->GetCameraPTZ()->CameraTiltUp( pButton->GetPressSpeed() ); break;
case BUTTON_DOWN: m_pApplication->GetCameraPTZ()->CameraTiltDown( pButton->GetPressSpeed() ); break;
case BUTTON_TELE: m_pApplication->GetCameraPTZ()->CameraZoomTele( pButton->GetPressSpeed() ); break;
case BUTTON_WIDE: m_pApplication->GetCameraPTZ()->CameraZoomWide( pButton->GetPressSpeed() ); break;
case BUTTON_FAR: m_pApplication->GetCameraPTZ()->CameraFocusFar( pButton->GetPressSpeed() ); break;
case BUTTON_NEAR: m_pApplication->GetCameraPTZ()->CameraFocusNear( pButton->GetPressSpeed() ); break;
}
LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CCalibratePTZDlg::OnTimer"), _T("Started button %d action"), nButton );
}
else
{
switch( nButton )
{
case BUTTON_LEFT:
case BUTTON_RIGHT: pButton->SetStop( m_pApplication->GetCameraPTZ()->CameraPanStop() ); break;
case BUTTON_UP:
case BUTTON_DOWN: pButton->SetStop( m_pApplication->GetCameraPTZ()->CameraTiltStop() ); break;
case BUTTON_TELE:
case BUTTON_WIDE: pButton->SetStop( m_pApplication->GetCameraPTZ()->CameraZoomStop() ); break;
case BUTTON_FAR:
case BUTTON_NEAR: pButton->SetStop( m_pApplication->GetCameraPTZ()->CameraFocusStop() ); break;
}
if( pButton->IsStopped() )
LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CCalibratePTZDlg::OnTimer"), _T("Stop button %d action"), nButton );
}
}
LRESULT CCalibratePTZDlg::OnTimer( WPARAM wParam, LPARAM lParam )
{
// apply camera control buttons
for( INT i = 0; i < BUTTON_COUNT; i++ )
{
CActiveButton *pButton = m_pButton + i;
if( pButton->IsPressed() )
{
if( pButton->UpdatePressSpeed() )
{
switch( i )
{
case BUTTON_LEFT: m_pApplication->GetCameraPTZ()->CameraPanLeft( pButton->GetPressSpeed() ); break;
case BUTTON_RIGHT: m_pApplication->GetCameraPTZ()->CameraPanRight( pButton->GetPressSpeed() ); break;
case BUTTON_UP: m_pApplication->GetCameraPTZ()->CameraTiltUp( pButton->GetPressSpeed() ); break;
case BUTTON_DOWN: m_pApplication->GetCameraPTZ()->CameraTiltDown( pButton->GetPressSpeed() ); break;
case BUTTON_TELE: m_pApplication->GetCameraPTZ()->CameraZoomTele( pButton->GetPressSpeed() ); break;
case BUTTON_WIDE: m_pApplication->GetCameraPTZ()->CameraZoomWide( pButton->GetPressSpeed() ); break;
// case BUTTON_FAR: m_pApplication->GetCameraPTZ()->CameraFocusFar( pButton->GetPressSpeed() ); break;
// case BUTTON_NEAR: m_pApplication->GetCameraPTZ()->CameraFocusNear( pButton->GetPressSpeed() ); break;
case BUTTON_FAR: m_pApplication->GetCameraPTZ()->CameraFocusFar( 30 ); break;
case BUTTON_NEAR: m_pApplication->GetCameraPTZ()->CameraFocusNear( 30 ); break;
}
LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CCalibratePTZDlg::OnTimer"), _T("Changed speed %d for button %d"), (INT)pButton->GetPressSpeed(), i );
}
}
else
{
if( !pButton->IsStopped() )
{
switch( i )
{
case BUTTON_LEFT:
case BUTTON_RIGHT: pButton->SetStop( m_pApplication->GetCameraPTZ()->CameraPanStop() ); break;
case BUTTON_UP:
case BUTTON_DOWN: pButton->SetStop( m_pApplication->GetCameraPTZ()->CameraTiltStop() ); break;
case BUTTON_TELE:
case BUTTON_WIDE: pButton->SetStop( m_pApplication->GetCameraPTZ()->CameraZoomStop() ); break;
case BUTTON_FAR:
case BUTTON_NEAR: pButton->SetStop( m_pApplication->GetCameraPTZ()->CameraFocusStop() ); break;
}
if( pButton->IsStopped() )
LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CCalibratePTZDlg::OnTimer"), _T("Stop button %d action"), i );
}
}
}
// ask about camera position (if nessessary)
GetCameraPosition();
// perform table test
SetCameraPosition();
return CGenericWnd::OnTimer( wParam, lParam );
}
void CCalibratePTZDlg::OnButtonGetPTZF()
{
// disable controls
EnableControls( FALSE );
// ask camera about position
m_bNeedSendGetPosition = TRUE;
m_bNeedCheckPosition = TRUE;
m_bUpdatePanShift = FALSE;
GetCameraPosition();
}
void CCalibratePTZDlg::OnButtonUpdatePanShift()
{
// disable controls
EnableControls( FALSE );
// ask camera about position
m_bNeedSendGetPosition = TRUE;
m_bNeedCheckPosition = TRUE;
m_bUpdatePanShift = TRUE;
GetCameraPosition();
}
void CCalibratePTZDlg::OnCheckTablePanShift()
{
// disable controls
EnableControls( !IsDlgButtonChecked( IDC_CHECK_TABLE ) );
// enable only itself
::EnableWindow( GetDlgItem( IDC_CHECK_TABLE ), TRUE );
// update according to state
OnRadioRange();
OnCheckSynchronize();
}
void CCalibratePTZDlg::GetCameraPosition()
{
// apply camera position ackwusition
if( m_bNeedSendGetPosition )
{
m_bNeedSendGetPosition = !m_pApplication->GetCameraPTZ()->CameraInquarePosition();
}
else
{
if( m_bNeedCheckPosition )
{
double pan, tilt, zoom, focus;
if( m_pApplication->GetCameraPTZ()->GetReplyData( &pan, &tilt, &zoom, &focus, NULL ) )
{
if( m_bUpdatePanShift )
{
// store pan shift
m_dPanShift = m_dAngle - pan;
while( m_dPanShift < 0 )
m_dPanShift += 360.0;
}
else
{
// get current line
BOOL bFound = FALSE;
for( UINT i = 0; i < 10; i++ )
{
if( IsDlgButtonChecked( IDC_RADIO_RANGE0 + i ) )
{
bFound = TRUE;
break;
}
}
if( bFound )
{
SendDlgItemMessage( IDC_PTZ_SPIN_TILT0 + i, UDM_SETPOS, 0, MAKELPARAM( tilt, 0 ) );
SendDlgItemMessage( IDC_PTZ_SPIN_ZOOM0 + i, UDM_SETPOS, 0, MAKELPARAM( zoom, 0 ) );
SendDlgItemMessage( IDC_SPIN_FOCUS0 + i, UDM_SETPOS, 0, MAKELPARAM( focus, 0 ) );
}
}
// enable PTZ control buttons
EnableControls( TRUE );
// update according to state
OnRadioRange();
OnCheckSynchronize();
m_bNeedCheckPosition = FALSE;
}
}
}
}
void CCalibratePTZDlg::SetCameraPosition()
{
if( m_bNeedSetPosition )
{
m_bNeedSetPosition = !m_pApplication->GetCameraPTZ()->CameraGotoPosition( m_dPositionPan, m_dPositionTilt, m_dPositionZoom, m_dPositionFocus );
}
}
void CCalibratePTZDlg::OnTarget( double dAngle, double dRange )
{
// store angle for future use
m_dAngle = dAngle;
// if dlg was not created
if( !GetSafeHwnd() )
return;
// determine to which range it belongs
CProfile *pProfile = m_pApplication->GetProfile();
INT nRange = dRange * 10 / pProfile->LgsRange();
// if need to synchronize with targets
if( IsDlgButtonChecked( IDC_CHECK_SYNCHRONIZE ) )
{
// check uppropriate button
CheckRadioButton( IDC_RADIO_RANGE0, IDC_RADIO_RANGE9, IDC_RADIO_RANGE0 + nRange );
// update control
OnRadioRange();
}
// if need to test table and pan shift
if( IsDlgButtonChecked( IDC_CHECK_TABLE ) )
{
m_bNeedSetPosition = TRUE;
m_dPositionPan = m_dAngle - m_dPanShift;
while( m_dPositionPan < 0.0 )
m_dPositionPan += 360.0;
m_dPositionTilt = SendDlgItemMessage( IDC_PTZ_SPIN_TILT0 + nRange, UDM_GETPOS, 0, 0 );
m_dPositionZoom = SendDlgItemMessage( IDC_PTZ_SPIN_ZOOM0 + nRange, UDM_GETPOS, 0, 0 );
m_dPositionFocus = SendDlgItemMessage( IDC_SPIN_FOCUS0 + nRange, UDM_GETPOS, 0, 0 );
SetCameraPosition();
}
}