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.

1076 lines
33 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: CalibrationDlg.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of CalibrationDlg.cpp
  13. //----------------------------------------------------------------------------
  14. // CalibrationDlg.cpp : implementation file
  15. //
  16. #include "stdafx.h"
  17. #include "Calibration.h"
  18. #include "CalibrationDlg.h"
  19. #include "OptionsDlg.h"
  20. #include "..\DLIB\SocketPTZ.h"
  21. #include "..\DLIB\SocketLGS.h"
  22. #include "..\Chicago\VideoBase.h"
  23. #include "ParametersDlg.h"
  24. #include "LoadDlg.h"
  25. #include "RelationDlg.h"
  26. #include "ReportDlg.h"
  27. #include "SetupDlg.h"
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33. enum
  34. {
  35. TAB_CAMERA = 0,
  36. TAB_LINEARIZATION = 1
  37. };
  38. CCalibrationDlg::CCalibrationDlg(CWnd* pParent /*=NULL*/)
  39. : CDialog(CCalibrationDlg::IDD, pParent)
  40. {
  41. //{{AFX_DATA_INIT(CCalibrationDlg)
  42. // NOTE: the ClassWizard will add member initialization here
  43. //}}AFX_DATA_INIT
  44. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  45. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  46. ::ZeroMemory( &m_bPtzRun, sizeof(m_bPtzRun) );
  47. m_pTarget[0].bValid = FALSE;
  48. m_pTarget[1].bValid = FALSE;
  49. m_bPtzReady = FALSE;
  50. m_bTestMode = FALSE;
  51. m_pVideoWnd = NULL;
  52. m_pVideoBase = NULL;
  53. ::ZeroMemory( &m_Relation, sizeof( m_Relation ) );
  54. m_bCtGetInProgress[0] = m_bCtGetInProgress[1] = FALSE;
  55. m_bCtSetInProgress[0] = m_bCtSetInProgress[1] = FALSE;
  56. }
  57. void CCalibrationDlg::DoDataExchange(CDataExchange* pDX)
  58. {
  59. CDialog::DoDataExchange(pDX);
  60. //{{AFX_DATA_MAP(CCalibrationDlg)
  61. // DDX_Control(pDX, IDC_BUTTON_TEST, m_Test);
  62. DDX_Control(pDX, IDC_CHECK_FILTER, m_Filter);
  63. //}}AFX_DATA_MAP
  64. DDX_Control(pDX, IDC_TAB_MODE, m_TabMode);
  65. }
  66. BEGIN_MESSAGE_MAP(CCalibrationDlg, CDialog)
  67. //{{AFX_MSG_MAP(CCalibrationDlg)
  68. ON_WM_PAINT()
  69. ON_WM_QUERYDRAGICON()
  70. ON_WM_TIMER()
  71. ON_WM_MOVE()
  72. ON_BN_CLICKED(IDC_BUTTON_CLEAR, OnButtonClear)
  73. ON_BN_CLICKED(IDC_CHECK_FILTER, OnCheckFilter)
  74. ON_BN_CLICKED(IDC_BUTTON_RESET, OnButtonReset)
  75. ON_NOTIFY(TCN_SELCHANGE, IDC_TAB_MODE, OnSelchangeTabMode)
  76. ON_MESSAGE(WM_OPTIONS_CHANGED, OnOptionsChanged)
  77. ON_MESSAGE(WM_CALIBRATION, OnWMCalibration)
  78. ON_BN_CLICKED(IDC_BUTTON_OPTIONS, OnButtonOptions)
  79. //}}AFX_MSG_MAP
  80. END_MESSAGE_MAP()
  81. /////////////////////////////////////////////////////////////////////////////
  82. // CCalibrationDlg message handlers
  83. BOOL CCalibrationDlg::OnInitDialog()
  84. {
  85. CDialog::OnInitDialog();
  86. // Set the icon for this dialog. The framework does this automatically
  87. // when the application's main window is not a dialog
  88. SetIcon(m_hIcon, TRUE); // Set big icon
  89. SetIcon(m_hIcon, FALSE); // Set small icon
  90. // ShowWindow( SW_MAXIMIZE );
  91. CSetupDlg SetupDlg;
  92. if( SetupDlg.DoModal() != IDOK )
  93. {
  94. EndDialog( IDCANCEL );
  95. return TRUE;
  96. }
  97. CRect rect;
  98. m_TabMode.InsertItem( TAB_CAMERA, _T("Camera") );
  99. m_TabMode.InsertItem( TAB_LINEARIZATION, _T("LRF") );
  100. m_TabMode.GetClientRect( &rect );
  101. m_TabMode.AdjustRect( FALSE, rect );
  102. m_TabCameraDlg.SetCalibrationDlg( this );
  103. m_TabCameraDlg.Create( CTabCameraDlg::IDD, &m_TabMode );
  104. m_TabCameraDlg.MoveWindow( rect );
  105. m_TabCameraDlg.ShowWindow( SW_SHOW );
  106. m_TabLinearizationDlg.SetCalibrationDlg( this );
  107. m_TabLinearizationDlg.Create( CTabLinearizationDlg::IDD, &m_TabMode );
  108. m_TabLinearizationDlg.MoveWindow( rect );
  109. m_TabLinearizationDlg.ShowWindow( SW_HIDE );
  110. ::SetWindowLong( GetDlgItem( IDC_BUTTON_RIGHT )->GetSafeHwnd(), GWL_USERDATA, (LONG)this );
  111. ::SetWindowLong( GetDlgItem( IDC_BUTTON_LEFT )->GetSafeHwnd(), GWL_USERDATA, (LONG)this );
  112. ::SetWindowLong( GetDlgItem( IDC_BUTTON_UP )->GetSafeHwnd(), GWL_USERDATA, (LONG)this );
  113. ::SetWindowLong( GetDlgItem( IDC_BUTTON_DOWN )->GetSafeHwnd(), GWL_USERDATA, (LONG)this );
  114. ::SetWindowLong( GetDlgItem( IDC_BUTTON_FAR )->GetSafeHwnd(), GWL_USERDATA, (LONG)this );
  115. ::SetWindowLong( GetDlgItem( IDC_BUTTON_NEAR )->GetSafeHwnd(), GWL_USERDATA, (LONG)this );
  116. m_pWndProc = (WNDPROC)::SetWindowLong( GetDlgItem( IDC_BUTTON_RIGHT )->GetSafeHwnd(), GWL_WNDPROC, (LONG)WindowProcButton_ );
  117. m_pWndProc = (WNDPROC)::SetWindowLong( GetDlgItem( IDC_BUTTON_LEFT )->GetSafeHwnd(), GWL_WNDPROC, (LONG)WindowProcButton_ );
  118. m_pWndProc = (WNDPROC)::SetWindowLong( GetDlgItem( IDC_BUTTON_UP )->GetSafeHwnd(), GWL_WNDPROC, (LONG)WindowProcButton_ );
  119. m_pWndProc = (WNDPROC)::SetWindowLong( GetDlgItem( IDC_BUTTON_DOWN )->GetSafeHwnd(), GWL_WNDPROC, (LONG)WindowProcButton_ );
  120. m_pWndProc = (WNDPROC)::SetWindowLong( GetDlgItem( IDC_BUTTON_FAR )->GetSafeHwnd(), GWL_WNDPROC, (LONG)WindowProcButton_ );
  121. m_pWndProc = (WNDPROC)::SetWindowLong( GetDlgItem( IDC_BUTTON_NEAR )->GetSafeHwnd(), GWL_WNDPROC, (LONG)WindowProcButton_ );
  122. // m_Options.strLgsPortName = "com4";
  123. // m_Options.strCameraPortName = "com3";
  124. m_Settings.Create( _T("LaserGuard\\ISSC") );
  125. m_Storage.SetEventQueue( &m_EventQueue );
  126. m_Storage.Load( SetupDlg.GetSetupName(), 0, &m_Settings, FALSE );
  127. // CRect rect;
  128. GetDlgItem( IDC_STATIC_VIDEO )->GetWindowRect( &rect );
  129. ScreenToClient( rect );
  130. m_pVideoBase = new CVideoBase;
  131. m_pVideoBase->SetSensorArray( &m_Storage );
  132. m_pVideoBase->Create( this, &m_Settings );
  133. /*
  134. m_pVideoWnd = (CDDVideoWnd*)m_pVideoBase->AllocVideoWnd( 2, 0 );
  135. if( m_pVideoWnd )
  136. {
  137. CWnd *pWnd = GetDlgItem(IDC_STATIC_VIDEO);
  138. CRect rect;
  139. pWnd->GetClientRect( &rect );
  140. m_pVideoWnd->SetParent( pWnd );
  141. m_pVideoWnd->ShowWindow( SW_SHOW );
  142. m_pVideoWnd->MoveWindow( &rect );
  143. }
  144. */
  145. //#ifndef _DEBUG
  146. // m_VideoWnd.Create( this, rect.left, rect.top, rect.Width(), rect.Height() );
  147. // m_VideoWnd.ShowWindow( SW_SHOW );
  148. MakeCrossTarget();
  149. //#endif
  150. GetDlgItem( IDC_STATIC_LOCATOR )->GetWindowRect( &rect );
  151. ScreenToClient( rect );
  152. m_PropertyLGSWnd.Create( this, rect.left, rect.top, rect.Width(), rect.Height() );
  153. m_PropertyLGSWnd.SetSensor( (CSensorLGS*)m_Relation.pSensor/*m_Storage.GetSensor( 0 )*/ );
  154. m_PropertyLGSWnd.ShowWindow( SW_SHOW );
  155. CListCtrl *pListCtrl = &m_TabCameraDlg.m_ListTarget;
  156. pListCtrl->SendMessage( LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT );
  157. CRect lRect;
  158. pListCtrl->GetClientRect(&lRect);
  159. int nWidth = lRect.Width() / 7;
  160. pListCtrl->InsertColumn( 0, _T("MA"), LVCFMT_LEFT, nWidth, 0 );
  161. pListCtrl->InsertColumn( 1, _T("MR"), LVCFMT_LEFT, nWidth, 1 );
  162. pListCtrl->InsertColumn( 2, _T("SA"), LVCFMT_LEFT, nWidth, 2 );
  163. pListCtrl->InsertColumn( 3, _T("SR"), LVCFMT_LEFT, nWidth, 3 );
  164. pListCtrl->InsertColumn( 4, _T("CP"), LVCFMT_LEFT, nWidth, 4 );
  165. pListCtrl->InsertColumn( 5, _T("CT"), LVCFMT_LEFT, nWidth, 5 );
  166. pListCtrl->InsertColumn( 6, _T("CR"), LVCFMT_LEFT, nWidth, 6 );
  167. LPCTSTR pText = _T("n/a");
  168. GetDlgItem( IDC_EDIT_CAMERA_PAN )->SetWindowText( pText );
  169. GetDlgItem( IDC_EDIT_CAMERA_TILT )->SetWindowText( pText );
  170. GetDlgItem( IDC_EDIT_CAMERA_ZOOM )->SetWindowText( pText );
  171. SetTimer( 0, 250, NULL );
  172. Communication();
  173. return TRUE; // return TRUE unless you set the focus to a control
  174. }
  175. // If you add a minimize button to your dialog, you will need the code below
  176. // to draw the icon. For MFC applications using the document/view model,
  177. // this is automatically done for you by the framework.
  178. void CCalibrationDlg::OnPaint()
  179. {
  180. if (IsIconic())
  181. {
  182. CPaintDC dc(this); // device context for painting
  183. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  184. // Center icon in client rectangle
  185. int cxIcon = GetSystemMetrics(SM_CXICON);
  186. int cyIcon = GetSystemMetrics(SM_CYICON);
  187. CRect rect;
  188. GetClientRect(&rect);
  189. int x = (rect.Width() - cxIcon + 1) / 2;
  190. int y = (rect.Height() - cyIcon + 1) / 2;
  191. // Draw the icon
  192. dc.DrawIcon(x, y, m_hIcon);
  193. }
  194. else
  195. {
  196. CDialog::OnPaint();
  197. }
  198. }
  199. // The system calls this to obtain the cursor to display while the user drags
  200. // the minimized window.
  201. HCURSOR CCalibrationDlg::OnQueryDragIcon()
  202. {
  203. return (HCURSOR) m_hIcon;
  204. }
  205. BOOL CCalibrationDlg::DestroyWindow()
  206. {
  207. if( GetSafeHwnd() )
  208. KillTimer( 0 );
  209. if( m_pVideoBase )
  210. {
  211. m_pVideoBase->Destroy();
  212. delete m_pVideoBase;
  213. m_pVideoBase = NULL;
  214. }
  215. if( m_pVideoWnd )
  216. {
  217. // m_pVideoWnd->DestroyWindow();
  218. // delete m_pVideoWnd;
  219. m_pVideoWnd = NULL;
  220. }
  221. return CDialog::DestroyWindow();
  222. }
  223. static double cD2R = asin(1.0) * 2.0 / 180.0;
  224. #define Degree2Radian(a) (a * cD2R)
  225. BOOL CCalibrationDlg::InVisibleZone( double angle, double range )
  226. {
  227. double x, y, r;
  228. if( m_PropertyLGSWnd.GetFilter( x, y, r ) && m_Relation.pSensor )
  229. {
  230. double max_range = 100.0;
  231. double zero_shift = 0.0;
  232. switch( m_Relation.pSensor->GetType() )
  233. {
  234. case CVisual::LGS:
  235. max_range = static_cast<CSensorLGS*>(m_Relation.pSensor)->GetMaxRange();
  236. zero_shift = static_cast<CSensorLGS*>(m_Relation.pSensor)->GetZeroShift();
  237. break;
  238. }
  239. angle = angle + zero_shift;
  240. while( angle >= 360.0 ) angle -= 360.0;
  241. while( angle < 0.0 ) angle += 360.0;
  242. x *= max_range;
  243. y *= max_range;
  244. r *= max_range;
  245. double tx = cos( Degree2Radian( angle ) ) * range;
  246. double ty = -sin( Degree2Radian( angle ) ) * range;
  247. double tr = sqrt( pow( tx-x, 2.0 ) + pow( ty-y, 2.0 ) );
  248. // LGLOG( LOG_LEVEL_LOW, LOG_TYPE_INFO, this, _T("CCalibrationDlg::InVisibleZone"), _T("%0.0f,%0.0f(%0.0f,%0.0f) %s %0.0f,%0.0f,%0.0f"), angle, range, tx, ty, ( tr < r )? "inside" : "outside", x, y, r );
  249. if( tr > r )
  250. return FALSE;
  251. }
  252. return TRUE; // filter disabled, so everythink in visible zone
  253. }
  254. BOOL CCalibrationDlg::GetTarget( INT nDevice, double *pAngle, double *pRange, double *pMaxRange )
  255. {
  256. if( !m_Relation.pSensor )
  257. return FALSE;
  258. *pAngle = m_pTarget[nDevice].angle;
  259. *pRange = m_pTarget[nDevice].range;
  260. *pMaxRange = static_cast<CSensorLGS*>(m_Relation.pSensor)->GetMaxRange();
  261. return m_pTarget[nDevice].bValid;
  262. }
  263. void CCalibrationDlg::OnTimer(UINT nIDEvent)
  264. {
  265. m_Storage.CheckSensors();
  266. m_Storage.CheckCameras();
  267. CheckPtz();
  268. CheckReady();
  269. CheckCalibrationTable();
  270. EVENT event;
  271. while( m_EventQueue.GetEvent( event ) )
  272. {
  273. switch( event.id )
  274. {
  275. case LGS_EVENT_ALARM_SHOW:
  276. if( event.pSensor == m_Relation.pSensor )
  277. {
  278. switch( event.target.bDevice )
  279. {
  280. case 0:
  281. if( InVisibleZone( event.target.dAngle, event.target.dRange ) ) // either filter disabled or target in visible zone
  282. {
  283. m_pTarget[0].angle = event.target.dAngle;
  284. m_pTarget[0].range = event.target.dRange;
  285. m_pTarget[0].bValid = TRUE;
  286. }
  287. if( m_bTestMode && m_pTarget[0].bValid )
  288. {
  289. double pan, tilt, zoom;
  290. event.pSensor->CameraTransform( 0, m_pTarget[0].angle, m_pTarget[0].range, &pan, &tilt, &zoom );
  291. CVideoCameraPTZ *pCamera = (CVideoCameraPTZ*)m_Relation.pCamera;//m_Storage.GetVideoCamera(0);
  292. if( pCamera && pCamera->IsReady() )
  293. {
  294. pCamera->CmdSetPTZ( pan, tilt, zoom );
  295. }
  296. }
  297. break;
  298. case 1:
  299. if( InVisibleZone( event.target.dAngle, event.target.dRange ) ) // either filter disabled or target in visible zone
  300. {
  301. m_pTarget[1].angle = event.target.dAngle;
  302. m_pTarget[1].range = event.target.dRange;
  303. m_pTarget[1].bValid = TRUE;
  304. }
  305. if( m_bTestMode && m_pTarget[1].bValid )
  306. {
  307. double pan, tilt, zoom;
  308. event.pSensor->CameraTransform( 1, m_pTarget[1].angle, m_pTarget[1].range, &pan, &tilt, &zoom );
  309. CVideoCameraPTZ *pCamera = (CVideoCameraPTZ*)m_Relation.pCamera;//m_Storage.GetVideoCamera(0);
  310. if( pCamera && pCamera->IsReady() )
  311. {
  312. pCamera->CmdSetPTZ( pan, tilt, zoom );
  313. }
  314. }
  315. break;
  316. }
  317. }
  318. break;
  319. }
  320. }
  321. CheckLocator();
  322. m_PropertyLGSWnd.SendMessage( WM_TIMER );
  323. CDialog::OnTimer(nIDEvent);
  324. }
  325. LRESULT CALLBACK CCalibrationDlg::WindowProcButton_( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  326. {
  327. CCalibrationDlg *pThis = (CCalibrationDlg*)::GetWindowLong( hWnd, GWL_USERDATA );
  328. if( pThis )
  329. return pThis->WindowProcButton( hWnd, uMsg, wParam, lParam );
  330. return ::DefWindowProc( hWnd, uMsg, wParam, lParam );
  331. }
  332. LRESULT CCalibrationDlg::WindowProcButton( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  333. {
  334. BOOL bRun = FALSE;
  335. BOOL bPerform = FALSE;
  336. switch( uMsg )
  337. {
  338. case BM_SETSTATE:
  339. bRun = wParam;
  340. bPerform = TRUE;
  341. break;
  342. }
  343. if( bPerform )
  344. {
  345. CVideoCameraPTZ *pCamera = (CVideoCameraPTZ*)m_Relation.pCamera;//m_Storage.GetVideoCamera(0);
  346. if( pCamera )
  347. {
  348. const double speed = 0.15;
  349. const double acceleration = 0.05;
  350. UINT uID = ::GetWindowLong( hWnd, GWL_ID );
  351. switch( uID )
  352. {
  353. case IDC_BUTTON_RIGHT: if( m_bPtzRun[0] != bRun ) { if( bRun ) pCamera->CmdPan( speed, PAN_RIGHT, acceleration ); else pCamera->CmdPan( 0.0, PAN_STOP ); m_bPtzRun[0] = bRun; } break;
  354. case IDC_BUTTON_LEFT: if( m_bPtzRun[0] != bRun ) { if( bRun ) pCamera->CmdPan( speed, PAN_LEFT, acceleration ); else pCamera->CmdPan( 0.0, PAN_STOP ); m_bPtzRun[0] = bRun; } break;
  355. case IDC_BUTTON_UP: if( m_bPtzRun[1] != bRun ) { if( bRun ) pCamera->CmdTilt( speed, TILT_UP, acceleration ); else pCamera->CmdTilt( 0.0, TILT_STOP ); m_bPtzRun[1] = bRun; } break;
  356. case IDC_BUTTON_DOWN: if( m_bPtzRun[1] != bRun ) { if( bRun ) pCamera->CmdTilt( speed, TILT_DOWN, acceleration ); else pCamera->CmdTilt( 0.0, TILT_STOP ); m_bPtzRun[1] = bRun; } break;
  357. case IDC_BUTTON_FAR: if( m_bPtzRun[2] != bRun ) { if( bRun ) pCamera->CmdZoom( speed, ZOOM_TELE, acceleration ); else pCamera->CmdZoom( 0.0, ZOOM_STOP ); m_bPtzRun[2] = bRun; } break;
  358. case IDC_BUTTON_NEAR: if( m_bPtzRun[2] != bRun ) { if( bRun ) pCamera->CmdZoom( speed, ZOOM_WIDE, acceleration ); else pCamera->CmdZoom( 0.0, ZOOM_STOP ); m_bPtzRun[2] = bRun; } break;
  359. }
  360. }
  361. }
  362. return ::CallWindowProc( m_pWndProc, hWnd, uMsg, wParam, lParam );
  363. }
  364. BOOL CCalibrationDlg::PreTranslateMessage(MSG* pMsg)
  365. {
  366. switch( pMsg->message )
  367. {
  368. case WM_KEYDOWN:
  369. switch( pMsg->wParam )
  370. {
  371. case VK_UP: SendDlgItemMessage( IDC_BUTTON_UP, BM_SETSTATE, TRUE ); return TRUE;
  372. case VK_DOWN: SendDlgItemMessage( IDC_BUTTON_DOWN, BM_SETSTATE, TRUE ); return TRUE;
  373. case VK_LEFT: SendDlgItemMessage( IDC_BUTTON_LEFT, BM_SETSTATE, TRUE ); return TRUE;
  374. case VK_RIGHT: SendDlgItemMessage( IDC_BUTTON_RIGHT, BM_SETSTATE, TRUE ); return TRUE;
  375. case VK_ADD: SendDlgItemMessage( IDC_BUTTON_FAR, BM_SETSTATE, TRUE ); return TRUE;
  376. case VK_SUBTRACT: SendDlgItemMessage( IDC_BUTTON_NEAR, BM_SETSTATE, TRUE ); return TRUE;
  377. }
  378. break;
  379. case WM_KEYUP:
  380. switch( pMsg->wParam )
  381. {
  382. case VK_UP: SendDlgItemMessage( IDC_BUTTON_UP, BM_SETSTATE, FALSE ); return TRUE;
  383. case VK_DOWN: SendDlgItemMessage( IDC_BUTTON_DOWN, BM_SETSTATE, FALSE ); return TRUE;
  384. case VK_LEFT: SendDlgItemMessage( IDC_BUTTON_LEFT, BM_SETSTATE, FALSE ); return TRUE;
  385. case VK_RIGHT: SendDlgItemMessage( IDC_BUTTON_RIGHT, BM_SETSTATE, FALSE ); return TRUE;
  386. case VK_ADD: SendDlgItemMessage( IDC_BUTTON_FAR, BM_SETSTATE, FALSE ); return TRUE;
  387. case VK_SUBTRACT: SendDlgItemMessage( IDC_BUTTON_NEAR, BM_SETSTATE, FALSE ); return TRUE;
  388. }
  389. break;
  390. }
  391. return CDialog::PreTranslateMessage(pMsg);
  392. }
  393. void CCalibrationDlg::CheckPtz()
  394. {
  395. CVideoCameraPTZ *pCamera = (CVideoCameraPTZ*)m_Relation.pCamera;//m_Storage.GetVideoCamera(0);
  396. if( pCamera )
  397. {
  398. CString str;
  399. if( pCamera->IsReady() )
  400. str.Format( "Video camera <%s>", (LPCTSTR)*pCamera->GetName() );
  401. else
  402. str.Format( "Video camera <%s> busy", (LPCTSTR)*pCamera->GetName() );
  403. GetDlgItem( IDC_STATIC_VIDEO_FRAME )->SetWindowText( str );
  404. GetDlgItem( IDC_BUTTON_RIGHT )->EnableWindow( TRUE );
  405. GetDlgItem( IDC_BUTTON_LEFT )->EnableWindow( TRUE );
  406. GetDlgItem( IDC_BUTTON_UP )->EnableWindow( TRUE );
  407. GetDlgItem( IDC_BUTTON_DOWN )->EnableWindow( TRUE );
  408. GetDlgItem( IDC_BUTTON_FAR )->EnableWindow( TRUE );
  409. GetDlgItem( IDC_BUTTON_NEAR )->EnableWindow( TRUE );
  410. BOOL bRun = FALSE;
  411. for( int i = 0; i < 3; i++ )
  412. {
  413. if( m_bPtzRun[i] )
  414. {
  415. bRun = TRUE;
  416. break;
  417. }
  418. }
  419. if( !bRun )
  420. {
  421. pCamera->CmdGetPTZ();
  422. }
  423. double pan, tilt, zoom;
  424. if( pCamera->GetPTZ( pan, tilt, zoom ) )
  425. {
  426. zoom *= 100.0;
  427. TCHAR pText[20];
  428. _stprintf( pText, _T("%0.1f�"), pan );
  429. GetDlgItem( IDC_EDIT_CAMERA_PAN )->SetWindowText( pText );
  430. _stprintf( pText, _T("%0.1f�"), tilt );
  431. GetDlgItem( IDC_EDIT_CAMERA_TILT )->SetWindowText( pText );
  432. _stprintf( pText, _T("%0.1f%%"), zoom );
  433. // _stprintf( pText, _T("-1.0") );
  434. GetDlgItem( IDC_EDIT_CAMERA_ZOOM )->SetWindowText( pText );
  435. GetDlgItem( IDC_EDIT_CAMERA_PAN )->EnableWindow( TRUE );
  436. GetDlgItem( IDC_EDIT_CAMERA_TILT )->EnableWindow( TRUE );
  437. GetDlgItem( IDC_EDIT_CAMERA_ZOOM )->EnableWindow( TRUE );
  438. m_bPtzReady = TRUE;
  439. }
  440. else
  441. {
  442. GetDlgItem( IDC_EDIT_CAMERA_PAN )->EnableWindow( FALSE );
  443. GetDlgItem( IDC_EDIT_CAMERA_TILT )->EnableWindow( FALSE );
  444. GetDlgItem( IDC_EDIT_CAMERA_ZOOM )->EnableWindow( FALSE );
  445. m_bPtzReady = FALSE;
  446. }
  447. }
  448. else
  449. {
  450. GetDlgItem( IDC_STATIC_VIDEO_FRAME )->SetWindowText( "Video camera" );
  451. GetDlgItem( IDC_BUTTON_RIGHT )->EnableWindow( FALSE );
  452. GetDlgItem( IDC_BUTTON_LEFT )->EnableWindow( FALSE );
  453. GetDlgItem( IDC_BUTTON_UP )->EnableWindow( FALSE );
  454. GetDlgItem( IDC_BUTTON_DOWN )->EnableWindow( FALSE );
  455. GetDlgItem( IDC_BUTTON_FAR )->EnableWindow( FALSE );
  456. GetDlgItem( IDC_BUTTON_NEAR )->EnableWindow( FALSE );
  457. }
  458. }
  459. void CCalibrationDlg::CheckLocator()
  460. {
  461. if( m_Relation.pSensor )
  462. {
  463. CString str;
  464. str.Format( "Locator <%s>", (LPCTSTR)m_Relation.pSensor->GetName() );
  465. GetDlgItem( IDC_STATIC_LOCATOR_FRAME )->SetWindowText( str );
  466. }
  467. if( m_pTarget[0].bValid && m_pTarget[1].bValid )
  468. {
  469. double tx1 = cos( Degree2Radian( m_pTarget[0].angle ) ) * m_pTarget[0].range;
  470. double ty1 = -sin( Degree2Radian( m_pTarget[0].angle ) ) * m_pTarget[0].range;
  471. double tx2 = cos( Degree2Radian( m_pTarget[1].angle ) ) * m_pTarget[1].range;
  472. double ty2 = -sin( Degree2Radian( m_pTarget[1].angle ) ) * m_pTarget[1].range;
  473. double tr = sqrt( pow( tx1-tx2, 2.0 ) + pow( ty1-ty2, 2.0 ) );
  474. if( tr > 10.0 )
  475. m_pTarget[0].bValid = m_pTarget[1].bValid = FALSE; // too big distance between targets
  476. }
  477. if( m_pTarget[0].bValid )
  478. {
  479. TCHAR pText[20];
  480. _stprintf( pText, _T("%0.1f�"), m_pTarget[0].angle );
  481. GetDlgItem( IDC_EDIT_MASTER_ANGLE )->SetWindowText( pText );
  482. _stprintf( pText, _T("%0.1fm."), m_pTarget[0].range );
  483. GetDlgItem( IDC_EDIT_MASTER_RANGE )->SetWindowText( pText );
  484. GetDlgItem( IDC_EDIT_MASTER_ANGLE )->EnableWindow( TRUE );
  485. GetDlgItem( IDC_EDIT_MASTER_RANGE )->EnableWindow( TRUE );
  486. }
  487. else
  488. {
  489. LPCTSTR pText = _T("n/a");
  490. GetDlgItem( IDC_EDIT_MASTER_ANGLE )->SetWindowText( pText );
  491. GetDlgItem( IDC_EDIT_MASTER_RANGE )->SetWindowText( pText );
  492. GetDlgItem( IDC_EDIT_MASTER_ANGLE )->EnableWindow( FALSE );
  493. GetDlgItem( IDC_EDIT_MASTER_RANGE )->EnableWindow( FALSE );
  494. }
  495. if( m_pTarget[1].bValid )
  496. {
  497. TCHAR pText[20];
  498. _stprintf( pText, _T("%0.1f�"), m_pTarget[1].angle );
  499. GetDlgItem( IDC_EDIT_SLAVE_ANGLE )->SetWindowText( pText );
  500. _stprintf( pText, _T("%0.1fm."), m_pTarget[1].range );
  501. GetDlgItem( IDC_EDIT_SLAVE_RANGE )->SetWindowText( pText );
  502. GetDlgItem( IDC_EDIT_SLAVE_ANGLE )->EnableWindow( TRUE );
  503. GetDlgItem( IDC_EDIT_SLAVE_RANGE )->EnableWindow( TRUE );
  504. }
  505. else
  506. {
  507. LPCTSTR pText = _T("n/a");
  508. GetDlgItem( IDC_EDIT_SLAVE_ANGLE )->SetWindowText( pText );
  509. GetDlgItem( IDC_EDIT_SLAVE_RANGE )->SetWindowText( pText );
  510. GetDlgItem( IDC_EDIT_SLAVE_ANGLE )->EnableWindow( FALSE );
  511. GetDlgItem( IDC_EDIT_SLAVE_RANGE )->EnableWindow( FALSE );
  512. }
  513. }
  514. void CCalibrationDlg::OnButtonOptions()
  515. {
  516. CRelationDlg dlg;
  517. dlg.SetSensorArray( &m_Storage );
  518. dlg.SetRelation( &m_Relation );
  519. if( dlg.DoModal() == IDOK )
  520. {
  521. RELATION relation;
  522. dlg.GetRelation( &relation );
  523. if( relation.pCamera != m_Relation.pCamera ||
  524. relation.pSensor != m_Relation.pSensor )
  525. {
  526. m_Relation = relation;
  527. m_PropertyLGSWnd.SetSensor( static_cast<CSensorLGS*>(m_Relation.pSensor) );
  528. DownloadCalibrationTables();
  529. OnButtonClear();
  530. if( m_Relation.pCamera )
  531. {
  532. CVideoCamera *pVideoCamera = m_Relation.pCamera;
  533. //find connected video input
  534. CVideoPin *pOutputPin = pVideoCamera->GetOutput(0);
  535. if( !pOutputPin )
  536. {
  537. // camera already exist in capturing jobs list
  538. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, "CVideoCapture::Capture", "camera %p has no output pin", pVideoCamera );
  539. return;
  540. }
  541. // search for video input device
  542. while( pOutputPin )
  543. {
  544. // get conneted pin
  545. CVideoPin *pInputPin = pOutputPin->GetCPin();
  546. if( !pInputPin )
  547. {
  548. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, "CVideoCapture::Capture", "camera %p has output pin that don't conneted to other pin", pVideoCamera );
  549. return;
  550. }
  551. CVideoDevice *pVideoDevice = NULL;
  552. INT nInputPin = 0;
  553. pInputPin->GetVideoDevice( &pVideoDevice, &nInputPin );
  554. if( !pVideoDevice )
  555. {
  556. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, "CVideoCapture::Capture", "input pin don't belong to any device" );
  557. return;
  558. }
  559. // if it is video capture device
  560. for( INT i = 0; i < m_Storage.GetVideoCaptureDeviceCount(); i++ )
  561. {
  562. CVideoCaptureDevice *pVideoCaptureDevice = m_Storage.GetVideoCaptureDevice(i);
  563. if( pVideoDevice == pVideoCaptureDevice )
  564. {
  565. CDDVideoWnd *pVideoWnd = static_cast<CDDVideoWnd*>(pVideoCaptureDevice->GetCaptureSource( nInputPin ));
  566. if( pVideoWnd )
  567. {
  568. if( m_pVideoWnd )
  569. m_pVideoWnd->ShowWindow( SW_HIDE );
  570. m_pVideoWnd = pVideoWnd;
  571. CRect rect;
  572. CWnd *pWnd = GetDlgItem(IDC_STATIC_VIDEO);
  573. pWnd->GetClientRect( &rect );
  574. m_pVideoWnd->SetParent( pWnd );
  575. m_pVideoWnd->ShowWindow( SW_SHOW );
  576. m_pVideoWnd->MoveWindow( &rect );
  577. MakeCrossTarget();
  578. }
  579. goto VIDEO_INPUT_FOUND;
  580. }
  581. }
  582. // get associated pin
  583. pOutputPin = pInputPin->GetAPin();
  584. }
  585. VIDEO_INPUT_FOUND:;
  586. }
  587. }
  588. }
  589. }
  590. BOOL CCalibrationDlg::Communication()
  591. {
  592. m_Storage.CommandLoop( MODE_HOST );
  593. /* for( int i = 0; i < m_Storage.GetSocketCount(); i++ )
  594. {
  595. CSocket *pSocket = m_Storage.GetSocket( i );
  596. switch( pSocket->GetType() )
  597. {
  598. case SOCKET_LGS:
  599. ((CSocketLGS*)pSocket)->Create( &m_Storage, (LPCTSTR)m_Options.strLgsPortName );
  600. pSocket->CommandLoopStart();
  601. break;
  602. case SOCKET_PTZ:
  603. ((CSocketPTZ*)pSocket)->Create( &m_Storage, (LPCTSTR)m_Options.strCameraPortName );
  604. m_Storage.GetVideoCamera(0 )->CmdInit();
  605. break;
  606. }
  607. }
  608. */
  609. // NEED TO BE CHANGED!!!
  610. return TRUE;
  611. }
  612. LRESULT CCalibrationDlg::OnOptionsChanged( WPARAM wParam, LPARAM lParam )
  613. {
  614. return Communication();
  615. }
  616. void CCalibrationDlg::OnButtonDelete()
  617. {
  618. CListCtrl *pListCtrl = &m_TabCameraDlg.m_ListTarget;
  619. while( TRUE )
  620. {
  621. POSITION pos = pListCtrl->GetFirstSelectedItemPosition();
  622. if( pos )
  623. pListCtrl->DeleteItem( pListCtrl->GetNextSelectedItem(pos) );
  624. else
  625. break;
  626. }
  627. }
  628. void CCalibrationDlg::OnButtonAdd()
  629. {
  630. TCHAR pBuffer[MAX_PATH];
  631. CListCtrl *pListCtrl = &m_TabCameraDlg.m_ListTarget;
  632. pListCtrl->InsertItem( 0, "" );
  633. if( m_pTarget[0].bValid )
  634. {
  635. _stprintf( pBuffer, _T("%5.1f"), m_pTarget[0].angle );
  636. pListCtrl->SetItemText( 0, 0, pBuffer );
  637. _stprintf( pBuffer, _T("%5.1f"), m_pTarget[0].range );
  638. pListCtrl->SetItemText( 0, 1, pBuffer );
  639. }
  640. else
  641. {
  642. pListCtrl->SetItemText( 0, 0, _T("-1.0") );
  643. pListCtrl->SetItemText( 0, 1, _T("-1.0") );
  644. }
  645. if( m_pTarget[1].bValid )
  646. {
  647. _stprintf( pBuffer, _T("%5.1f"), m_pTarget[1].angle );
  648. pListCtrl->SetItemText( 0, 2, pBuffer );
  649. _stprintf( pBuffer, _T("%5.1f"), m_pTarget[1].range );
  650. pListCtrl->SetItemText( 0, 3, pBuffer );
  651. }
  652. else
  653. {
  654. pListCtrl->SetItemText( 0, 2, _T("-1.0") );
  655. pListCtrl->SetItemText( 0, 3, _T("-1.0") );
  656. }
  657. CVideoCameraPTZ *pCamera = (CVideoCameraPTZ*)m_Relation.pCamera;//m_Storage.GetVideoCamera(0);
  658. ASSERT( pCamera );
  659. double pan = -1.0, tilt = -1.0, zoom = -1.0;
  660. pCamera->GetPTZ( pan, tilt, zoom );
  661. _stprintf( pBuffer, _T("%5.1f"), pan );
  662. pListCtrl->SetItemText( 0, 4, pBuffer );
  663. _stprintf( pBuffer, _T("%5.1f"), tilt );
  664. pListCtrl->SetItemText( 0, 5, pBuffer );
  665. // _stprintf( pBuffer, _T("%5.1f"), zoom );
  666. _stprintf( pBuffer, _T("-1.0") );
  667. pListCtrl->SetItemText( 0, 6, pBuffer );
  668. }
  669. void CCalibrationDlg::CheckReady()
  670. {
  671. if( m_bPtzReady && ( m_pTarget[0].bValid || m_pTarget[1].bValid ))
  672. m_TabCameraDlg.m_ButtonAdd.EnableWindow( TRUE );
  673. else
  674. m_TabCameraDlg.m_ButtonAdd.EnableWindow( FALSE );
  675. }
  676. void CCalibrationDlg::OnButtonParameters()
  677. {
  678. CParametersDlg dlg;
  679. dlg.SetCalibrationData( &m_CalibrationData );
  680. dlg.DoModal();
  681. }
  682. void CCalibrationDlg::OnButtonCalculate()
  683. {
  684. TCHAR pBuffer[ MAX_PATH ];
  685. CListCtrl *pListCtrl = &m_TabCameraDlg.m_ListTarget;
  686. int nCount = pListCtrl->GetItemCount();
  687. if( !nCount )
  688. return;
  689. for( int i = 0; i < nCount; i++ )
  690. {
  691. pListCtrl->GetItemText( i, 0, pBuffer, MAX_PATH );
  692. double ma = atof( pBuffer );
  693. pListCtrl->GetItemText( i, 1, pBuffer, MAX_PATH );
  694. double mr = atof( pBuffer );
  695. pListCtrl->GetItemText( i, 2, pBuffer, MAX_PATH );
  696. double sa = atof( pBuffer );
  697. pListCtrl->GetItemText( i, 3, pBuffer, MAX_PATH );
  698. double sr = atof( pBuffer );
  699. pListCtrl->GetItemText( i, 4, pBuffer, MAX_PATH );
  700. double cp = atof( pBuffer );
  701. pListCtrl->GetItemText( i, 5, pBuffer, MAX_PATH );
  702. double ct = atof( pBuffer );
  703. pListCtrl->GetItemText( i, 6, pBuffer, MAX_PATH );
  704. double cz = atof( pBuffer );
  705. m_CalibrationData.AddData( ma, mr, sa, sr, cp, ct, cz );
  706. }
  707. pListCtrl->DeleteAllItems();
  708. CString name;
  709. m_CalibrationData.Execute( GetSafeHwnd(), name );
  710. if( m_Relation.pSensor )
  711. {
  712. m_Relation.pSensor->GetCalibrationNameArray().Add( name );
  713. m_Storage.SaveCalibrationName( m_Relation.pSensor );
  714. }
  715. m_TabCameraDlg.m_ButtonCalculate.EnableWindow( FALSE );
  716. }
  717. LRESULT CCalibrationDlg::OnWMCalibration(WPARAM wParam, LPARAM lParam)
  718. {
  719. m_TabCameraDlg.m_ButtonCalculate.EnableWindow( TRUE );
  720. OnButtonReport();
  721. return 0;
  722. }
  723. void CCalibrationDlg::OnButtonLoad()
  724. {
  725. CLoadDlg dlg;
  726. dlg.SetData( &m_Storage, &m_CalibrationData, &m_Relation );
  727. if( dlg.DoModal() == IDOK )
  728. {
  729. CDataList list;
  730. m_CalibrationData.GetDataList( dlg.GetFolderName(), list );
  731. POSITION pos = list.GetTailPosition();
  732. while( pos )
  733. {
  734. DATACALC dc = list.GetPrev( pos );
  735. TCHAR pBuffer[MAX_PATH];
  736. CListCtrl *pListCtrl = &m_TabCameraDlg.m_ListTarget;
  737. pListCtrl->InsertItem( 0, "" );
  738. _stprintf( pBuffer, _T("%5.1f"), dc.ma );
  739. pListCtrl->SetItemText( 0, 0, pBuffer );
  740. _stprintf( pBuffer, _T("%5.1f"), dc.mr );
  741. pListCtrl->SetItemText( 0, 1, pBuffer );
  742. _stprintf( pBuffer, _T("%5.1f"), dc.sa );
  743. pListCtrl->SetItemText( 0, 2, pBuffer );
  744. _stprintf( pBuffer, _T("%5.1f"), dc.sr );
  745. pListCtrl->SetItemText( 0, 3, pBuffer );
  746. _stprintf( pBuffer, _T("%5.1f"), dc.cp );
  747. pListCtrl->SetItemText( 0, 4, pBuffer );
  748. _stprintf( pBuffer, _T("%5.1f"), dc.ct );
  749. pListCtrl->SetItemText( 0, 5, pBuffer );
  750. _stprintf( pBuffer, _T("%5.1f"), dc.cz );
  751. pListCtrl->SetItemText( 0, 6, pBuffer );
  752. }
  753. }
  754. }
  755. void CCalibrationDlg::OnMove(int x, int y)
  756. {
  757. CDialog::OnMove(x, y);
  758. }
  759. void CCalibrationDlg::OnButtonReset()
  760. {
  761. if( m_Relation.pSensor && m_Relation.pSensor->GetType() != CVisual::LGS )
  762. return;
  763. if( MessageBox( _T("Are you sure that you want to reset LGS?"), NULL, MB_YESNO | MB_ICONEXCLAMATION ) != IDYES )
  764. return;
  765. static_cast<CSensorLGS*>(m_Relation.pSensor)->CmdReset( FALSE );
  766. OnButtonClear();
  767. }
  768. void CCalibrationDlg::OnButtonClear()
  769. {
  770. if( m_Relation.pSensor )
  771. m_Relation.pSensor->Reset();
  772. m_PropertyLGSWnd.InvalidateRect( NULL );
  773. m_PropertyLGSWnd.RedrawWindow();
  774. m_pTarget[0].bValid = FALSE;
  775. m_pTarget[1].bValid = FALSE;
  776. }
  777. void CCalibrationDlg::OnCheckFilter()
  778. {
  779. m_PropertyLGSWnd.UseVisibleZone( m_Filter.GetCheck() );
  780. }
  781. void CCalibrationDlg::OnButtonTest()
  782. {
  783. CVideoCameraPTZ* pCamera = (CVideoCameraPTZ*)m_Relation.pCamera;
  784. if( m_bTestMode )
  785. {
  786. m_Test.SetWindowText( _T("Test...") );
  787. m_bTestMode = FALSE;
  788. if( pCamera /*&& pCamera->IsReady()*/ )
  789. {
  790. if( MessageBox( _T("Assign parameters to relation?"), NULL, MB_YESNO | MB_ICONQUESTION ) == IDYES )
  791. {
  792. DATARES dr[2];
  793. if( m_CalibrationData.GetResult( m_TestFolderName, dr[0], dr[1] ) )
  794. {
  795. m_Storage.SaveTransform( m_Relation.pSensor );
  796. }
  797. }
  798. }
  799. }
  800. else
  801. {
  802. if( pCamera /*&& pCamera->IsReady()*/ )
  803. {
  804. CLoadDlg dlg;
  805. dlg.SetData( &m_Storage, &m_CalibrationData, &m_Relation );
  806. if( dlg.DoModal() == IDOK )
  807. {
  808. DATARES dr[2];
  809. if( m_CalibrationData.GetResult( m_TestFolderName = dlg.GetFolderName(), dr[0], dr[1] ) )
  810. {
  811. m_Relation.pSensor->GetTransform(0)->Prepare( dr[0].x, dr[0].y, dr[0].z, dr[0].psi, dr[0].theta, dr[0].phi );
  812. m_Relation.pSensor->GetTransform(1)->Prepare( dr[1].x, dr[1].y, dr[1].z, dr[1].psi, dr[1].theta, dr[1].phi );
  813. m_Test.SetWindowText( _T("Stop") );
  814. m_bTestMode = TRUE;
  815. }
  816. }
  817. }
  818. }
  819. }
  820. void CCalibrationDlg::OnButtonReport()
  821. {
  822. CReportDlg dlg;
  823. dlg.SetCalibrationData( &m_Storage, &m_CalibrationData, &m_Relation );
  824. dlg.DoModal();
  825. }
  826. void CCalibrationDlg::MakeCrossTarget()
  827. {
  828. if( m_pVideoWnd && m_pVideoWnd->GetSafeHwnd() )
  829. {
  830. CRect rect;
  831. m_pVideoWnd->GetClientRect( &rect );
  832. const double pX = 0.10; // 15%
  833. const double pY = 0.25; // 30%
  834. const int W1 = 2; // width
  835. const int W2 = 1; // width
  836. double x1 = ( rect.Width() * ( 1.0 - pX ) ) / 2.0;
  837. double y1 = ( rect.Height() * ( 1.0 - pY ) ) / 2.0;
  838. double x2 = x1 + rect.Width() * pX;
  839. double y2 = y1 + rect.Height() * pY;
  840. double x3 = rect.Width() / 2;
  841. double y3 = rect.Height() / 2;
  842. CRect frameS( (int)x1, (int)y1, (int)x2, (int)y2 );
  843. CRect frameB( (int)x1 - W1, (int)y1 - W1, (int)x2 + W1, (int)y2 + W1 );
  844. CRect frameU( (int)x3 - W2, frameB.top, (int)x3 + W2, frameB.top - W1 );
  845. CRect frameD( (int)x3 - W2, frameB.bottom, (int)x3 + W2, frameB.bottom + W1 );
  846. CRect frameL( frameB.left, (int)y3 - W2, frameB.left - W1, (int)y3 + W2 );
  847. CRect frameR( frameB.right, (int)y3 - W2, frameB.right + W1, (int)y3 + W2 );
  848. CRgn rgn;
  849. rgn.CreateRectRgnIndirect( &rect );
  850. CRgn rgnS;
  851. rgnS.CreateRectRgnIndirect( frameS );
  852. CRgn rgnB;
  853. rgnB.CreateRectRgnIndirect( frameB );
  854. CRgn rgnU;
  855. rgnU.CreateRectRgnIndirect( frameU );
  856. CRgn rgnD;
  857. rgnD.CreateRectRgnIndirect( frameD );
  858. CRgn rgnL;
  859. rgnL.CreateRectRgnIndirect( frameL );
  860. CRgn rgnR;
  861. rgnR.CreateRectRgnIndirect( frameR );
  862. rgn.CombineRgn( &rgn, &rgnB, RGN_DIFF );
  863. rgn.CombineRgn( &rgn, &rgnU, RGN_DIFF );
  864. rgn.CombineRgn( &rgn, &rgnD, RGN_DIFF );
  865. rgn.CombineRgn( &rgn, &rgnL, RGN_DIFF );
  866. rgn.CombineRgn( &rgn, &rgnR, RGN_DIFF );
  867. rgn.CombineRgn( &rgn, &rgnS, RGN_OR );
  868. m_pVideoWnd->SetWindowRgn( (HRGN)rgn.GetSafeHandle(), TRUE );
  869. }
  870. }
  871. void CCalibrationDlg::OnSelchangeTabMode( NMHDR* pNMHDR, LRESULT* pResult )
  872. {
  873. BOOL bShowCamera = FALSE;
  874. BOOL bShowLinearization = FALSE;
  875. switch( m_TabMode.GetCurSel() )
  876. {
  877. case TAB_CAMERA: bShowCamera = TRUE; break;
  878. case TAB_LINEARIZATION: bShowLinearization = TRUE; break;
  879. }
  880. m_TabCameraDlg.ShowWindow( bShowCamera ? SW_SHOW : SW_HIDE );
  881. m_TabLinearizationDlg.ShowWindow( bShowLinearization ? SW_SHOW : SW_HIDE );
  882. *pResult = 0;
  883. }
  884. BOOL CCalibrationDlg::DownloadCalibrationTables()
  885. {
  886. if( !m_Relation.pSensor )
  887. return FALSE;
  888. m_bCtGetInProgress[0] = static_cast<CSensorLGS*>(m_Relation.pSensor)->CmdGetCalibrationTable(0);
  889. m_bCtGetInProgress[1] = static_cast<CSensorLGS*>(m_Relation.pSensor)->CmdGetCalibrationTable(1);
  890. return m_bCtGetInProgress[0] && m_bCtGetInProgress[1];
  891. }
  892. BOOL CCalibrationDlg::UploadCalibrationTables(CLgDeviceLGS::LGS_CALIBRATION_TABLE& ct1, CLgDeviceLGS::LGS_CALIBRATION_TABLE& ct2)
  893. {
  894. if( !m_Relation.pSensor )
  895. return FALSE;
  896. m_bCtSetInProgress[1] = static_cast<CSensorLGS*>(m_Relation.pSensor)->CmdSetCalibrationTable( ct2 );
  897. m_bCtSetInProgress[0] = static_cast<CSensorLGS*>(m_Relation.pSensor)->CmdSetCalibrationTable( ct1 );
  898. return m_bCtSetInProgress[0] && m_bCtSetInProgress[1];
  899. }
  900. void CCalibrationDlg::CheckCalibrationTable()
  901. {
  902. if( !m_Relation.pSensor || m_Relation.pSensor->GetType() != CVisual::LGS )
  903. return;
  904. CLgDeviceLGS::LGS_CALIBRATION_TABLE ct;
  905. for( INT i = 0; i < 2; i++ )
  906. {
  907. if( m_bCtGetInProgress[i] && static_cast<CSensorLGS*>(m_Relation.pSensor)->GetGetCalibrationTable( i, ct ) )
  908. {
  909. m_bCtGetInProgress[i] = FALSE;
  910. m_TabLinearizationDlg.SetCalibrationTable( FALSE, ct );
  911. // LGLOG( LOG_LEVEL_LOW, LOG_TYPE_INFO, this, _T("CCalibrationDlg::OnTimer"), _T("Received calibration table for %s"), i ? _T("slave") : _T("master") );
  912. }
  913. if( m_bCtSetInProgress[i] && static_cast<CSensorLGS*>(m_Relation.pSensor)->GetSetCalibrationTable( i, ct ) )
  914. {
  915. m_bCtSetInProgress[i] = FALSE;
  916. m_TabLinearizationDlg.SetCalibrationTable( TRUE, ct );
  917. // LGLOG( LOG_LEVEL_LOW, LOG_TYPE_INFO, this, _T("CCalibrationDlg::OnTimer"), _T("Received calibration table for %s"), i ? _T("slave") : _T("master") );
  918. }
  919. }
  920. }