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.

317 lines
9.6 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: 15/07/2001
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: CameraDlg.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of CameraDlg.cpp
  13. //----------------------------------------------------------------------------
  14. // CameraDlg.cpp : implementation file
  15. //
  16. #include "stdafx.h"
  17. #include "chicago.h"
  18. #include "CameraDlg.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CCameraDlg dialog
  26. CCameraDlg::CCameraDlg(CWnd* pParent /*=NULL*/)
  27. : CDialog(CCameraDlg::IDD, pParent)
  28. {
  29. //{{AFX_DATA_INIT(CCameraDlg)
  30. //}}AFX_DATA_INIT
  31. m_CurrentCamera = 0;
  32. ::ZeroMemory( &m_Video, sizeof( m_Video ) );
  33. m_bVideoConnected = FALSE;
  34. }
  35. CCameraDlg::~CCameraDlg()
  36. {
  37. }
  38. void CCameraDlg::DoDataExchange(CDataExchange* pDX)
  39. {
  40. CDialog::DoDataExchange(pDX);
  41. //{{AFX_DATA_MAP(CCameraDlg)
  42. DDX_Control(pDX, IDC_CHECK_CAMERA_LOCK, m_Lock);
  43. DDX_Control(pDX, IDC_STATIC_CAMERA_IMAGE, m_CameraImage);
  44. //}}AFX_DATA_MAP
  45. }
  46. BEGIN_MESSAGE_MAP(CCameraDlg, CDialog)
  47. //{{AFX_MSG_MAP(CCameraDlg)
  48. ON_BN_CLICKED(IDC_BUTTON_NEXT, OnButtonNext)
  49. ON_WM_DESTROY()
  50. ON_BN_CLICKED(IDC_BUTTON_CAMERA_PREV, OnButtonCameraPrev)
  51. ON_BN_CLICKED(IDC_BUTTON_SNAPSHOT, OnButtonSnapshot)
  52. ON_WM_TIMER()
  53. ON_WM_MOVE()
  54. ON_BN_CLICKED(IDC_CHECK_CAMERA_LOCK, OnCheckCameraLock)
  55. //}}AFX_MSG_MAP
  56. END_MESSAGE_MAP()
  57. void CCameraDlg::SetSensorArray( CSensorArray *pSensorArray, CVideoWnd *pVideoWnd )
  58. {
  59. m_pSensorArray = pSensorArray;
  60. m_Video.pVideoWnd = pVideoWnd;
  61. m_CurrentCamera = 0;
  62. }
  63. BOOL CCameraDlg::OnInitDialog()
  64. {
  65. CDialog::OnInitDialog();
  66. CheckCamera();
  67. // store video window's state
  68. m_Video.pParent = m_Video.pVideoWnd->GetParent();
  69. m_Video.pVideoWnd->GetWindowRect( &m_Video.rect );
  70. m_Video.pParent->ScreenToClient( &m_Video.rect );
  71. // move video window's to new position
  72. CRect rect;
  73. m_CameraImage.GetClientRect( &rect );
  74. m_Video.pVideoWnd->SetParent( &m_CameraImage );
  75. // m_Video.pVideoWnd->ShowWindow( SW_SHOW );
  76. m_Video.pVideoWnd->MoveWindow( &rect );
  77. ::SetWindowLong( GetDlgItem( IDC_BUTTON_RIGHT )->GetSafeHwnd(), GWL_USERDATA, (LONG)this );
  78. ::SetWindowLong( GetDlgItem( IDC_BUTTON_LEFT )->GetSafeHwnd(), GWL_USERDATA, (LONG)this );
  79. ::SetWindowLong( GetDlgItem( IDC_BUTTON_UP )->GetSafeHwnd(), GWL_USERDATA, (LONG)this );
  80. ::SetWindowLong( GetDlgItem( IDC_BUTTON_DOWN )->GetSafeHwnd(), GWL_USERDATA, (LONG)this );
  81. ::SetWindowLong( GetDlgItem( IDC_BUTTON_FAR )->GetSafeHwnd(), GWL_USERDATA, (LONG)this );
  82. ::SetWindowLong( GetDlgItem( IDC_BUTTON_NEAR )->GetSafeHwnd(), GWL_USERDATA, (LONG)this );
  83. m_pWndProc = (WNDPROC)::SetWindowLong( GetDlgItem( IDC_BUTTON_RIGHT )->GetSafeHwnd(), GWL_WNDPROC, (LONG)WindowProcButton );
  84. m_pWndProc = (WNDPROC)::SetWindowLong( GetDlgItem( IDC_BUTTON_LEFT )->GetSafeHwnd(), GWL_WNDPROC, (LONG)WindowProcButton );
  85. m_pWndProc = (WNDPROC)::SetWindowLong( GetDlgItem( IDC_BUTTON_UP )->GetSafeHwnd(), GWL_WNDPROC, (LONG)WindowProcButton );
  86. m_pWndProc = (WNDPROC)::SetWindowLong( GetDlgItem( IDC_BUTTON_DOWN )->GetSafeHwnd(), GWL_WNDPROC, (LONG)WindowProcButton );
  87. m_pWndProc = (WNDPROC)::SetWindowLong( GetDlgItem( IDC_BUTTON_FAR )->GetSafeHwnd(), GWL_WNDPROC, (LONG)WindowProcButton );
  88. m_pWndProc = (WNDPROC)::SetWindowLong( GetDlgItem( IDC_BUTTON_NEAR )->GetSafeHwnd(), GWL_WNDPROC, (LONG)WindowProcButton );
  89. SetTimer( 0, 500, NULL );
  90. ChangeCamera();
  91. return TRUE;
  92. }
  93. void CCameraDlg::OnDestroy()
  94. {
  95. m_Video.pVideoWnd->MoveWindow( &m_Video.rect );
  96. m_Video.pVideoWnd->SetParent( m_Video.pParent );
  97. CDialog::OnDestroy();
  98. }
  99. void CCameraDlg::ChangeCamera()
  100. {
  101. /*
  102. CheckCamera();
  103. CVideoCamera *pCamera = (CVideoCamera*)m_pSensorArray->GetVideoCamera( m_CurrentCamera );
  104. if( pCamera )
  105. {
  106. CVideoDevice *pVD = m_pSensorArray->GetVideoDevice();
  107. if( pVD )
  108. pCamera->Connect( pVD->GetInput(0), TRUE, TRUE );
  109. }
  110. */
  111. }
  112. void CCameraDlg::CheckCamera()
  113. {
  114. CVideoCamera *pCamera = (CVideoCamera*)m_pSensorArray->GetVideoCamera( m_CurrentCamera );
  115. CString str;
  116. if( pCamera )
  117. {
  118. CVideoCameraPTZ *pCameraPTZ;
  119. BOOL bPTZ = FALSE;
  120. switch( pCamera->GetType() )
  121. {
  122. case VC_FIX:
  123. str.Format( "Camera <%s> fixed", (LPCTSTR)*pCamera->GetName() );
  124. break;
  125. case VC_PTZ:
  126. pCameraPTZ = (CVideoCameraPTZ*)pCamera;
  127. if( pCameraPTZ->IsReady() )
  128. {
  129. str.Format( "Camera <%s> ready", (LPCTSTR)*pCameraPTZ->GetName() );
  130. bPTZ = TRUE;
  131. }
  132. else
  133. str.Format( "Camera <%s> not ready", (LPCTSTR)*pCameraPTZ->GetName() );
  134. break;
  135. }
  136. GetDlgItem( IDC_BUTTON_RIGHT )->EnableWindow( bPTZ );
  137. GetDlgItem( IDC_BUTTON_LEFT )->EnableWindow( bPTZ );
  138. GetDlgItem( IDC_BUTTON_UP )->EnableWindow( bPTZ );
  139. GetDlgItem( IDC_BUTTON_DOWN )->EnableWindow( bPTZ );
  140. GetDlgItem( IDC_BUTTON_FAR )->EnableWindow( bPTZ );
  141. GetDlgItem( IDC_BUTTON_NEAR )->EnableWindow( bPTZ );
  142. }
  143. else
  144. str.Format( "Camera #%d null", m_CurrentCamera );
  145. SetWindowText( str );
  146. }
  147. void CCameraDlg::OnButtonCameraPrev()
  148. {
  149. m_Lock.SetCheck( BST_UNCHECKED );
  150. OnCheckCameraLock();
  151. m_CurrentCamera = (m_CurrentCamera - 1 + m_pSensorArray->GetVideoCameraCount() ) % m_pSensorArray->GetVideoCameraCount();
  152. ChangeCamera();
  153. }
  154. void CCameraDlg::OnButtonNext()
  155. {
  156. m_Lock.SetCheck( BST_UNCHECKED );
  157. OnCheckCameraLock();
  158. m_CurrentCamera = (m_CurrentCamera+1) % m_pSensorArray->GetVideoCameraCount();
  159. ChangeCamera();
  160. }
  161. void CCameraDlg::OnButtonSnapshot()
  162. {
  163. CVideoCamera *pCamera = (CVideoCamera*)m_pSensorArray->GetVideoCamera( m_CurrentCamera );
  164. if( pCamera )
  165. {
  166. EVENT event;
  167. event.id = LGS_EVENT_MANUAL_CAPTURE;
  168. event.color = RGB( 0,0,0xFF );
  169. _tcscpy( event.pText, _T("manual capture") );
  170. SYSTEMTIME st;
  171. ::GetLocalTime( &st );
  172. ::SystemTimeToFileTime( &st, (LPFILETIME)&event.time );
  173. event.pCamera = pCamera;
  174. m_pSensorArray->GetEventQueue()->PostEvent( event );
  175. }
  176. }
  177. LRESULT CCameraDlg::WindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  178. {
  179. BOOL bRun = FALSE;
  180. BOOL bPerform = FALSE;
  181. switch( uMsg )
  182. {
  183. case BM_SETSTATE:
  184. bRun = wParam;
  185. bPerform = TRUE;
  186. break;
  187. }
  188. if( bPerform )
  189. {
  190. CVideoCameraPTZ *pCamera = (CVideoCameraPTZ*)m_pSensorArray->GetVideoCamera( m_CurrentCamera );
  191. if( pCamera )
  192. {
  193. UINT uID = ::GetWindowLong( hWnd, GWL_ID );
  194. switch( uID )
  195. {
  196. case IDC_BUTTON_RIGHT: if( bRun ) pCamera->CmdPan( 50.0, PAN_RIGHT ); else pCamera->CmdPan( 0.0, PAN_STOP ); break;
  197. case IDC_BUTTON_LEFT: if( bRun ) pCamera->CmdPan( 50.0, PAN_LEFT ); else pCamera->CmdPan( 0.0, PAN_STOP ); break;
  198. case IDC_BUTTON_UP: if( bRun ) pCamera->CmdTilt( 50.0, TILT_UP ); else pCamera->CmdTilt( 0.0, TILT_STOP ); break;
  199. case IDC_BUTTON_DOWN: if( bRun ) pCamera->CmdTilt( 50.0, TILT_DOWN ); else pCamera->CmdTilt( 0.0, TILT_STOP ); break;
  200. case IDC_BUTTON_FAR: if( bRun ) pCamera->CmdZoom( 50.0, ZOOM_FAR ); else pCamera->CmdZoom( 0.0, ZOOM_STOP ); break;
  201. case IDC_BUTTON_NEAR: if( bRun ) pCamera->CmdZoom( 50.0, ZOOM_NEAR ); else pCamera->CmdZoom( 0.0, ZOOM_STOP ); break;
  202. }
  203. }
  204. }
  205. return ::CallWindowProc( m_pWndProc, hWnd, uMsg, wParam, lParam );
  206. }
  207. BOOL CCameraDlg::PreTranslateMessage(MSG* pMsg)
  208. {
  209. switch( pMsg->message )
  210. {
  211. case WM_KEYDOWN:
  212. switch( pMsg->wParam )
  213. {
  214. case VK_UP: SendDlgItemMessage( IDC_BUTTON_UP, BM_SETSTATE, TRUE ); return TRUE;
  215. case VK_DOWN: SendDlgItemMessage( IDC_BUTTON_DOWN, BM_SETSTATE, TRUE ); return TRUE;
  216. case VK_LEFT: SendDlgItemMessage( IDC_BUTTON_LEFT, BM_SETSTATE, TRUE ); return TRUE;
  217. case VK_RIGHT: SendDlgItemMessage( IDC_BUTTON_RIGHT, BM_SETSTATE, TRUE ); return TRUE;
  218. case VK_ADD: SendDlgItemMessage( IDC_BUTTON_FAR, BM_SETSTATE, TRUE ); return TRUE;
  219. case VK_SUBTRACT: SendDlgItemMessage( IDC_BUTTON_NEAR, BM_SETSTATE, TRUE ); return TRUE;
  220. }
  221. break;
  222. case WM_KEYUP:
  223. switch( pMsg->wParam )
  224. {
  225. case VK_UP: SendDlgItemMessage( IDC_BUTTON_UP, BM_SETSTATE, FALSE ); return TRUE;
  226. case VK_DOWN: SendDlgItemMessage( IDC_BUTTON_DOWN, BM_SETSTATE, FALSE ); return TRUE;
  227. case VK_LEFT: SendDlgItemMessage( IDC_BUTTON_LEFT, BM_SETSTATE, FALSE ); return TRUE;
  228. case VK_RIGHT: SendDlgItemMessage( IDC_BUTTON_RIGHT, BM_SETSTATE, FALSE ); return TRUE;
  229. case VK_ADD: SendDlgItemMessage( IDC_BUTTON_FAR, BM_SETSTATE, FALSE ); return TRUE;
  230. case VK_SUBTRACT: SendDlgItemMessage( IDC_BUTTON_NEAR, BM_SETSTATE, FALSE ); return TRUE;
  231. }
  232. break;
  233. }
  234. return CDialog::PreTranslateMessage(pMsg);
  235. }
  236. void CCameraDlg::OnTimer(UINT nIDEvent)
  237. {
  238. CheckCamera();
  239. CDialog::OnTimer(nIDEvent);
  240. }
  241. void CCameraDlg::OnMove( int x, int y )
  242. {
  243. CDialog::OnMove(x, y);
  244. if( m_Video.pVideoWnd->GetSafeHwnd() )
  245. m_Video.pVideoWnd->Invalidate();
  246. }
  247. void CCameraDlg::OnCheckCameraLock()
  248. {
  249. CVideoCameraPTZ *pCamera = (CVideoCameraPTZ*)m_pSensorArray->GetVideoCamera( m_CurrentCamera );
  250. if( pCamera )
  251. {
  252. BOOL bCheck = (m_Lock.GetCheck()==BST_CHECKED);
  253. if( bCheck )
  254. {
  255. if( !pCamera->IsLock() )
  256. {
  257. pCamera->Lock();
  258. CVideoDevice *pVD = NULL;//m_pSensorArray->GetVideoDevice();
  259. if( pVD )
  260. pCamera->Connect( pVD->GetInput(0), TRUE, FALSE );
  261. }
  262. else
  263. m_Lock.SetCheck( BST_UNCHECKED );
  264. }
  265. else
  266. {
  267. if( pCamera->IsLock() )
  268. {
  269. pCamera->Unlock();
  270. CVideoDevice *pVD = NULL;//m_pSensorArray->GetVideoDevice();
  271. if( pVD )
  272. pCamera->Disconnect();
  273. }
  274. }
  275. }
  276. }