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

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: CalibratePTZDlg.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of CalibratePTZDlg.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "CalibratePTZDlg.h"
  16. #include "Application.h"
  17. #include "..\LgLib\Version.h"
  18. CCalibratePTZDlg::CCalibratePTZDlg()
  19. {
  20. m_pApplication = NULL;
  21. m_bNeedSendGetPosition = FALSE;
  22. m_bNeedCheckPosition = FALSE;
  23. m_bNeedSetPosition = FALSE;
  24. m_dPositionPan = m_dPositionTilt = m_dPositionZoom = m_dPositionFocus = 0;
  25. m_dAngle = 0;
  26. m_dPanShift = 0;
  27. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CCalibratePTZDlg::CCalibratePTZDlg") );
  28. }
  29. CCalibratePTZDlg::~CCalibratePTZDlg()
  30. {
  31. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CCalibratePTZDlg::~CCalibratePTZDlg") );
  32. }
  33. UINT CCalibratePTZDlg::DoModal( CApplication* pApplication, HWND hParent )
  34. {
  35. HINSTANCE hInstance = (HINSTANCE)::GetWindowLong( hParent, GWL_HINSTANCE );
  36. m_pApplication = pApplication;
  37. return CGenericWnd::DoModal( hInstance, (LPCTSTR)IDD_CALIBRATE_PTZ_DLG, hParent );
  38. }
  39. LRESULT CCalibratePTZDlg::OnDestroy( WPARAM wParam, LPARAM lParam )
  40. {
  41. return CGenericWnd::OnDestroy( wParam, lParam );
  42. }
  43. BOOL CCalibratePTZDlg::CActiveButton::AttachButton( HWND hWnd, UINT uIconID )
  44. {
  45. if( !SubClassWindow( hWnd ) )
  46. {
  47. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CCalibratePTZDlg::CActiveButton::AttachButton"), _T("SubClassWindow failed") );
  48. return FALSE;
  49. }
  50. m_dSpeed = 0.0;
  51. m_bPressed = FALSE;
  52. m_hIcon = ::LoadIcon( (HINSTANCE)GetWindowLong( GWL_HINSTANCE ), (LPCTSTR)uIconID );
  53. return SendMessage( BM_SETIMAGE, IMAGE_ICON, (LPARAM)m_hIcon );
  54. }
  55. LRESULT CCalibratePTZDlg::CActiveButton::WindowProc( UINT uMsg, WPARAM wParam, LPARAM lParam )
  56. {
  57. switch( uMsg )
  58. {
  59. case WM_CREATE:
  60. m_hIcon = NULL;
  61. break;
  62. case BM_SETSTATE:
  63. // send appropriate WM_COMMAND to the parent wnd
  64. ::SendMessage( GetParent(), WM_COMMAND, MAKEWPARAM( GetWindowLong(GWL_ID), wParam ? BN_PUSHED : BN_UNPUSHED ), (LPARAM)GetSafeHwnd() );
  65. break;
  66. case WM_DESTROY:
  67. if( m_hIcon )
  68. {
  69. ::DeleteObject( m_hIcon );
  70. m_hIcon = NULL;
  71. }
  72. break;
  73. }
  74. return CGenericWnd::WindowProc( uMsg, wParam, lParam );
  75. };
  76. LRESULT CCalibratePTZDlg::OnCommand( WPARAM wParam, LPARAM lParam )
  77. {
  78. if( HIWORD(wParam) == BN_CLICKED )
  79. {
  80. switch( LOWORD(wParam) )
  81. {
  82. case IDOK:
  83. OnButtonOk();
  84. break;
  85. case IDCANCEL:
  86. OnButtonCancel();
  87. break;
  88. case IDC_BUTTON_GET_PTZF:
  89. OnButtonGetPTZF();
  90. break;
  91. case IDC_BUTTON_UPDATE_SHIFT:
  92. OnButtonUpdatePanShift();
  93. break;
  94. case IDC_CHECK_TABLE:
  95. OnCheckTablePanShift();
  96. break;
  97. case IDC_RADIO_RANGE0:
  98. case IDC_RADIO_RANGE1:
  99. case IDC_RADIO_RANGE2:
  100. case IDC_RADIO_RANGE3:
  101. case IDC_RADIO_RANGE4:
  102. case IDC_RADIO_RANGE5:
  103. case IDC_RADIO_RANGE6:
  104. case IDC_RADIO_RANGE7:
  105. case IDC_RADIO_RANGE8:
  106. case IDC_RADIO_RANGE9:
  107. OnRadioRange();
  108. break;
  109. case IDC_CHECK_SYNCHRONIZE:
  110. OnCheckSynchronize();
  111. break;
  112. }
  113. }
  114. switch( HIWORD(wParam) )
  115. {
  116. case BN_PUSHED:
  117. case BN_UNPUSHED:
  118. switch( LOWORD(wParam) )
  119. {
  120. case IDC_BUTTON_LEFT: OnPressButtonPTZ( BUTTON_LEFT, HIWORD(wParam) == BN_PUSHED ); break;
  121. case IDC_BUTTON_RIGHT: OnPressButtonPTZ( BUTTON_RIGHT, HIWORD(wParam) == BN_PUSHED ); break;
  122. case IDC_BUTTON_UP: OnPressButtonPTZ( BUTTON_UP, HIWORD(wParam) == BN_PUSHED ); break;
  123. case IDC_BUTTON_DOWN: OnPressButtonPTZ( BUTTON_DOWN, HIWORD(wParam) == BN_PUSHED ); break;
  124. case IDC_BUTTON_TELE: OnPressButtonPTZ( BUTTON_TELE, HIWORD(wParam) == BN_PUSHED ); break;
  125. case IDC_BUTTON_WIDE: OnPressButtonPTZ( BUTTON_WIDE, HIWORD(wParam) == BN_PUSHED ); break;
  126. case IDC_BUTTON_FAR: OnPressButtonPTZ( BUTTON_FAR, HIWORD(wParam) == BN_PUSHED ); break;
  127. case IDC_BUTTON_NEAR: OnPressButtonPTZ( BUTTON_NEAR, HIWORD(wParam) == BN_PUSHED ); break;
  128. }
  129. break;
  130. }
  131. return CGenericWnd::OnCommand( wParam, lParam );
  132. }
  133. LRESULT CCalibratePTZDlg::OnInitDialog( WPARAM wParam, LPARAM lParam )
  134. {
  135. HINSTANCE hInstance = (HINSTANCE)GetWindowLong( GWL_HINSTANCE );
  136. // attach buttons
  137. m_pButton[BUTTON_LEFT].AttachButton( GetDlgItem( IDC_BUTTON_LEFT ), IDI_CAMERA_LEFT );
  138. m_pButton[BUTTON_RIGHT].AttachButton( GetDlgItem( IDC_BUTTON_RIGHT ), IDI_CAMERA_RIGHT );
  139. m_pButton[BUTTON_UP].AttachButton( GetDlgItem( IDC_BUTTON_UP ), IDI_CAMERA_UP );
  140. m_pButton[BUTTON_DOWN].AttachButton( GetDlgItem( IDC_BUTTON_DOWN ), IDI_CAMERA_DOWN );
  141. m_pButton[BUTTON_WIDE].AttachButton( GetDlgItem( IDC_BUTTON_WIDE ), IDI_CAMERA_WIDE );
  142. m_pButton[BUTTON_TELE].AttachButton( GetDlgItem( IDC_BUTTON_TELE ), IDI_CAMERA_TELE );
  143. m_pButton[BUTTON_FAR].AttachButton( GetDlgItem( IDC_BUTTON_FAR ), IDI_CAMERA_FAR );
  144. m_pButton[BUTTON_NEAR].AttachButton( GetDlgItem( IDC_BUTTON_NEAR ), IDI_CAMERA_NEAR );
  145. // init radio buttons
  146. SendDlgItemMessage( IDC_RADIO_RANGE0, BM_SETCHECK, TRUE, 0 );
  147. // initialize values
  148. CProfile *pProfile = m_pApplication->GetProfile();
  149. for( INT i = 0; i < 10; i++ )
  150. {
  151. SendDlgItemMessage( IDC_PTZ_SPIN_ZOOM0 + i, UDM_SETPOS, 0, MAKELONG( pProfile->PtzRangeZoom(i), 0 ) );
  152. SendDlgItemMessage( IDC_PTZ_SPIN_TILT0 + i, UDM_SETPOS, 0, MAKELONG( pProfile->PtzRangeTilt(i), 0 ) );
  153. SendDlgItemMessage( IDC_SPIN_FOCUS0 + i, UDM_SETPOS, 0, MAKELONG( pProfile->PtzRangeFocus(i), 0 ) );
  154. }
  155. m_pButton[BUTTON_UP].EnableWindow( m_pApplication->GetCameraPTZ()->HasTilt() );
  156. m_pButton[BUTTON_DOWN].EnableWindow( m_pApplication->GetCameraPTZ()->HasTilt() );
  157. m_pButton[BUTTON_FAR].EnableWindow( m_pApplication->GetCameraPTZ()->HasFocus() );
  158. m_pButton[BUTTON_NEAR].EnableWindow( m_pApplication->GetCameraPTZ()->HasFocus() );
  159. // init variables
  160. m_bNeedSendGetPosition = FALSE;
  161. m_bNeedCheckPosition = FALSE;
  162. m_bNeedSetPosition = FALSE;
  163. m_dPositionPan = m_dPositionTilt = m_dPositionZoom = m_dPositionFocus = 0;
  164. m_dPanShift = pProfile->PtzPanShift();
  165. // install timer
  166. SetTimer( 1, 100, NULL );
  167. // update dinamic controls
  168. OnRadioRange();
  169. OnCheckSynchronize();
  170. return CGenericWnd::OnInitDialog( wParam, lParam );
  171. }
  172. void CCalibratePTZDlg::OnButtonOk()
  173. {
  174. // store data
  175. CProfile *pProfile = m_pApplication->GetProfile();
  176. for( INT i = 0; i < 10; i++ )
  177. {
  178. pProfile->PtzRangeTilt(i) = SendDlgItemMessage( IDC_PTZ_SPIN_TILT0 + i, UDM_GETPOS, 0, 0 );
  179. pProfile->PtzRangeZoom(i) = SendDlgItemMessage( IDC_PTZ_SPIN_ZOOM0 + i, UDM_GETPOS, 0, 0 );
  180. pProfile->PtzRangeFocus(i) = SendDlgItemMessage( IDC_SPIN_FOCUS0 + i, UDM_GETPOS, 0, 0 );
  181. }
  182. pProfile->PtzPanShiftSet( m_dPanShift );
  183. CGenericWnd::EndDialog( IDOK );
  184. }
  185. void CCalibratePTZDlg::OnButtonCancel()
  186. {
  187. CGenericWnd::EndDialog( IDCANCEL );
  188. }
  189. void CCalibratePTZDlg::EnableControls(BOOL bEnable)
  190. {
  191. // disable averything
  192. m_pButton[BUTTON_LEFT].EnableWindow( bEnable );
  193. m_pButton[BUTTON_RIGHT].EnableWindow( bEnable );
  194. m_pButton[BUTTON_UP].EnableWindow( bEnable && m_pApplication->GetCameraPTZ()->HasTilt() );
  195. m_pButton[BUTTON_DOWN].EnableWindow( bEnable && m_pApplication->GetCameraPTZ()->HasTilt() );
  196. m_pButton[BUTTON_TELE].EnableWindow( bEnable );
  197. m_pButton[BUTTON_WIDE].EnableWindow( bEnable );
  198. m_pButton[BUTTON_FAR].EnableWindow( bEnable && m_pApplication->GetCameraPTZ()->HasFocus() );
  199. m_pButton[BUTTON_NEAR].EnableWindow( bEnable && m_pApplication->GetCameraPTZ()->HasFocus() );
  200. ::EnableWindow( GetDlgItem( IDC_BUTTON_GET_PTZF ), bEnable );
  201. // disable radio and edit controls
  202. for( UINT i = 0; i < 10; i++ )
  203. {
  204. ::EnableWindow( GetDlgItem( IDC_PTZ_EDIT_ZOOM0 + i ), bEnable );
  205. ::EnableWindow( GetDlgItem( IDC_PTZ_EDIT_TILT0 + i ), bEnable && m_pApplication->GetCameraPTZ()->HasTilt() );
  206. ::EnableWindow( GetDlgItem( IDC_EDIT_FOCUS0 + i ), bEnable && m_pApplication->GetCameraPTZ()->HasFocus() );
  207. ::EnableWindow( GetDlgItem( IDC_RADIO_RANGE0 + i ), bEnable );
  208. }
  209. // disable check controls
  210. ::EnableWindow( GetDlgItem( IDC_CHECK_SYNCHRONIZE ), bEnable );
  211. // disable pan shift control
  212. ::EnableWindow( GetDlgItem( IDC_BUTTON_UPDATE_SHIFT ), bEnable );
  213. // disable check table control
  214. ::EnableWindow( GetDlgItem( IDC_CHECK_TABLE ), bEnable );
  215. }
  216. void CCalibratePTZDlg::OnRadioRange()
  217. {
  218. BOOL bEnabled = ::IsWindowEnabled( GetDlgItem( IDC_CHECK_SYNCHRONIZE ) );
  219. for( UINT i = 0; i < 10; i++ )
  220. {
  221. BOOL bChecked = IsDlgButtonChecked( IDC_RADIO_RANGE0 + i ) && bEnabled;
  222. // enable appropriate controls
  223. ::EnableWindow( GetDlgItem( IDC_PTZ_EDIT_ZOOM0 + i ), bChecked );
  224. ::EnableWindow( GetDlgItem( IDC_PTZ_EDIT_TILT0 + i ), bChecked && m_pApplication->GetCameraPTZ()->HasTilt() );
  225. ::EnableWindow( GetDlgItem( IDC_EDIT_FOCUS0 + i ), bChecked && m_pApplication->GetCameraPTZ()->HasFocus() );
  226. }
  227. }
  228. void CCalibratePTZDlg::OnCheckSynchronize()
  229. {
  230. BOOL bEnable = !IsDlgButtonChecked( IDC_CHECK_SYNCHRONIZE ) && ::IsWindowEnabled( GetDlgItem( IDC_CHECK_SYNCHRONIZE ) );
  231. for( UINT i = 0; i < 10; i++ )
  232. ::EnableWindow( GetDlgItem( IDC_RADIO_RANGE0 + i ), bEnable );
  233. }
  234. void CCalibratePTZDlg::OnPressButtonPTZ( INT nButton, BOOL bPressed )
  235. {
  236. // make shortcut to button
  237. CActiveButton *pButton = m_pButton + nButton;
  238. // update press state
  239. pButton->SetPressState( bPressed );
  240. // if button released we should send stop
  241. if( bPressed )
  242. {
  243. switch( nButton )
  244. {
  245. case BUTTON_LEFT: m_pApplication->GetCameraPTZ()->CameraPanLeft( pButton->GetPressSpeed() ); break;
  246. case BUTTON_RIGHT: m_pApplication->GetCameraPTZ()->CameraPanRight( pButton->GetPressSpeed() ); break;
  247. case BUTTON_UP: m_pApplication->GetCameraPTZ()->CameraTiltUp( pButton->GetPressSpeed() ); break;
  248. case BUTTON_DOWN: m_pApplication->GetCameraPTZ()->CameraTiltDown( pButton->GetPressSpeed() ); break;
  249. case BUTTON_TELE: m_pApplication->GetCameraPTZ()->CameraZoomTele( pButton->GetPressSpeed() ); break;
  250. case BUTTON_WIDE: m_pApplication->GetCameraPTZ()->CameraZoomWide( pButton->GetPressSpeed() ); break;
  251. case BUTTON_FAR: m_pApplication->GetCameraPTZ()->CameraFocusFar( pButton->GetPressSpeed() ); break;
  252. case BUTTON_NEAR: m_pApplication->GetCameraPTZ()->CameraFocusNear( pButton->GetPressSpeed() ); break;
  253. }
  254. LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CCalibratePTZDlg::OnTimer"), _T("Started button %d action"), nButton );
  255. }
  256. else
  257. {
  258. switch( nButton )
  259. {
  260. case BUTTON_LEFT:
  261. case BUTTON_RIGHT: pButton->SetStop( m_pApplication->GetCameraPTZ()->CameraPanStop() ); break;
  262. case BUTTON_UP:
  263. case BUTTON_DOWN: pButton->SetStop( m_pApplication->GetCameraPTZ()->CameraTiltStop() ); break;
  264. case BUTTON_TELE:
  265. case BUTTON_WIDE: pButton->SetStop( m_pApplication->GetCameraPTZ()->CameraZoomStop() ); break;
  266. case BUTTON_FAR:
  267. case BUTTON_NEAR: pButton->SetStop( m_pApplication->GetCameraPTZ()->CameraFocusStop() ); break;
  268. }
  269. if( pButton->IsStopped() )
  270. LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CCalibratePTZDlg::OnTimer"), _T("Stop button %d action"), nButton );
  271. }
  272. }
  273. LRESULT CCalibratePTZDlg::OnTimer( WPARAM wParam, LPARAM lParam )
  274. {
  275. // apply camera control buttons
  276. for( INT i = 0; i < BUTTON_COUNT; i++ )
  277. {
  278. CActiveButton *pButton = m_pButton + i;
  279. if( pButton->IsPressed() )
  280. {
  281. if( pButton->UpdatePressSpeed() )
  282. {
  283. switch( i )
  284. {
  285. case BUTTON_LEFT: m_pApplication->GetCameraPTZ()->CameraPanLeft( pButton->GetPressSpeed() ); break;
  286. case BUTTON_RIGHT: m_pApplication->GetCameraPTZ()->CameraPanRight( pButton->GetPressSpeed() ); break;
  287. case BUTTON_UP: m_pApplication->GetCameraPTZ()->CameraTiltUp( pButton->GetPressSpeed() ); break;
  288. case BUTTON_DOWN: m_pApplication->GetCameraPTZ()->CameraTiltDown( pButton->GetPressSpeed() ); break;
  289. case BUTTON_TELE: m_pApplication->GetCameraPTZ()->CameraZoomTele( pButton->GetPressSpeed() ); break;
  290. case BUTTON_WIDE: m_pApplication->GetCameraPTZ()->CameraZoomWide( pButton->GetPressSpeed() ); break;
  291. // case BUTTON_FAR: m_pApplication->GetCameraPTZ()->CameraFocusFar( pButton->GetPressSpeed() ); break;
  292. // case BUTTON_NEAR: m_pApplication->GetCameraPTZ()->CameraFocusNear( pButton->GetPressSpeed() ); break;
  293. case BUTTON_FAR: m_pApplication->GetCameraPTZ()->CameraFocusFar( 30 ); break;
  294. case BUTTON_NEAR: m_pApplication->GetCameraPTZ()->CameraFocusNear( 30 ); break;
  295. }
  296. LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CCalibratePTZDlg::OnTimer"), _T("Changed speed %d for button %d"), (INT)pButton->GetPressSpeed(), i );
  297. }
  298. }
  299. else
  300. {
  301. if( !pButton->IsStopped() )
  302. {
  303. switch( i )
  304. {
  305. case BUTTON_LEFT:
  306. case BUTTON_RIGHT: pButton->SetStop( m_pApplication->GetCameraPTZ()->CameraPanStop() ); break;
  307. case BUTTON_UP:
  308. case BUTTON_DOWN: pButton->SetStop( m_pApplication->GetCameraPTZ()->CameraTiltStop() ); break;
  309. case BUTTON_TELE:
  310. case BUTTON_WIDE: pButton->SetStop( m_pApplication->GetCameraPTZ()->CameraZoomStop() ); break;
  311. case BUTTON_FAR:
  312. case BUTTON_NEAR: pButton->SetStop( m_pApplication->GetCameraPTZ()->CameraFocusStop() ); break;
  313. }
  314. if( pButton->IsStopped() )
  315. LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CCalibratePTZDlg::OnTimer"), _T("Stop button %d action"), i );
  316. }
  317. }
  318. }
  319. // ask about camera position (if nessessary)
  320. GetCameraPosition();
  321. // perform table test
  322. SetCameraPosition();
  323. return CGenericWnd::OnTimer( wParam, lParam );
  324. }
  325. void CCalibratePTZDlg::OnButtonGetPTZF()
  326. {
  327. // disable controls
  328. EnableControls( FALSE );
  329. // ask camera about position
  330. m_bNeedSendGetPosition = TRUE;
  331. m_bNeedCheckPosition = TRUE;
  332. m_bUpdatePanShift = FALSE;
  333. GetCameraPosition();
  334. }
  335. void CCalibratePTZDlg::OnButtonUpdatePanShift()
  336. {
  337. // disable controls
  338. EnableControls( FALSE );
  339. // ask camera about position
  340. m_bNeedSendGetPosition = TRUE;
  341. m_bNeedCheckPosition = TRUE;
  342. m_bUpdatePanShift = TRUE;
  343. GetCameraPosition();
  344. }
  345. void CCalibratePTZDlg::OnCheckTablePanShift()
  346. {
  347. // disable controls
  348. EnableControls( !IsDlgButtonChecked( IDC_CHECK_TABLE ) );
  349. // enable only itself
  350. ::EnableWindow( GetDlgItem( IDC_CHECK_TABLE ), TRUE );
  351. // update according to state
  352. OnRadioRange();
  353. OnCheckSynchronize();
  354. }
  355. void CCalibratePTZDlg::GetCameraPosition()
  356. {
  357. // apply camera position ackwusition
  358. if( m_bNeedSendGetPosition )
  359. {
  360. m_bNeedSendGetPosition = !m_pApplication->GetCameraPTZ()->CameraInquarePosition();
  361. }
  362. else
  363. {
  364. if( m_bNeedCheckPosition )
  365. {
  366. double pan, tilt, zoom, focus;
  367. if( m_pApplication->GetCameraPTZ()->GetReplyData( &pan, &tilt, &zoom, &focus, NULL ) )
  368. {
  369. if( m_bUpdatePanShift )
  370. {
  371. // store pan shift
  372. m_dPanShift = m_dAngle - pan;
  373. while( m_dPanShift < 0 )
  374. m_dPanShift += 360.0;
  375. }
  376. else
  377. {
  378. // get current line
  379. BOOL bFound = FALSE;
  380. for( UINT i = 0; i < 10; i++ )
  381. {
  382. if( IsDlgButtonChecked( IDC_RADIO_RANGE0 + i ) )
  383. {
  384. bFound = TRUE;
  385. break;
  386. }
  387. }
  388. if( bFound )
  389. {
  390. SendDlgItemMessage( IDC_PTZ_SPIN_TILT0 + i, UDM_SETPOS, 0, MAKELPARAM( tilt, 0 ) );
  391. SendDlgItemMessage( IDC_PTZ_SPIN_ZOOM0 + i, UDM_SETPOS, 0, MAKELPARAM( zoom, 0 ) );
  392. SendDlgItemMessage( IDC_SPIN_FOCUS0 + i, UDM_SETPOS, 0, MAKELPARAM( focus, 0 ) );
  393. }
  394. }
  395. // enable PTZ control buttons
  396. EnableControls( TRUE );
  397. // update according to state
  398. OnRadioRange();
  399. OnCheckSynchronize();
  400. m_bNeedCheckPosition = FALSE;
  401. }
  402. }
  403. }
  404. }
  405. void CCalibratePTZDlg::SetCameraPosition()
  406. {
  407. if( m_bNeedSetPosition )
  408. {
  409. m_bNeedSetPosition = !m_pApplication->GetCameraPTZ()->CameraGotoPosition( m_dPositionPan, m_dPositionTilt, m_dPositionZoom, m_dPositionFocus );
  410. }
  411. }
  412. void CCalibratePTZDlg::OnTarget( double dAngle, double dRange )
  413. {
  414. // store angle for future use
  415. m_dAngle = dAngle;
  416. // if dlg was not created
  417. if( !GetSafeHwnd() )
  418. return;
  419. // determine to which range it belongs
  420. CProfile *pProfile = m_pApplication->GetProfile();
  421. INT nRange = dRange * 10 / pProfile->LgsRange();
  422. // if need to synchronize with targets
  423. if( IsDlgButtonChecked( IDC_CHECK_SYNCHRONIZE ) )
  424. {
  425. // check uppropriate button
  426. CheckRadioButton( IDC_RADIO_RANGE0, IDC_RADIO_RANGE9, IDC_RADIO_RANGE0 + nRange );
  427. // update control
  428. OnRadioRange();
  429. }
  430. // if need to test table and pan shift
  431. if( IsDlgButtonChecked( IDC_CHECK_TABLE ) )
  432. {
  433. m_bNeedSetPosition = TRUE;
  434. m_dPositionPan = m_dAngle - m_dPanShift;
  435. while( m_dPositionPan < 0.0 )
  436. m_dPositionPan += 360.0;
  437. m_dPositionTilt = SendDlgItemMessage( IDC_PTZ_SPIN_TILT0 + nRange, UDM_GETPOS, 0, 0 );
  438. m_dPositionZoom = SendDlgItemMessage( IDC_PTZ_SPIN_ZOOM0 + nRange, UDM_GETPOS, 0, 0 );
  439. m_dPositionFocus = SendDlgItemMessage( IDC_SPIN_FOCUS0 + nRange, UDM_GETPOS, 0, 0 );
  440. SetCameraPosition();
  441. }
  442. }