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.

285 lines
7.5 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: LgUICameraEngine.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of LgUICameraEngine.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "LgUICameraEngine.h"
  16. #include "LgUICamera.h"
  17. #include "LgUICameraVideoWnd.h"
  18. #include "LgUICameraMainWnd.h"
  19. #include "LgUICameraListWnd.h"
  20. #include "LgUICameraControlWnd.h"
  21. #include "..\UISite\LgUISiteEngine.h"
  22. CLgUICameraEngine::CLgUICameraEngine()
  23. {
  24. m_pActiveCamera = NULL;
  25. }
  26. CLgUICameraEngine::~CLgUICameraEngine()
  27. {
  28. Destroy();
  29. }
  30. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  31. // create / destroy
  32. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  33. BOOL CLgUICameraEngine::Create()
  34. {
  35. // create background window (used as base for CLgUICameraVideoWnd)
  36. if( !m_HiddenWnd.GetSafeHwnd() )
  37. {
  38. CString strClassName = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW, NULL, NULL, NULL );
  39. CRect rect(0,0,10,10);
  40. if( !m_HiddenWnd.CreateEx( 0, strClassName, NULL, WS_OVERLAPPED, rect, NULL, 0 ) )
  41. return FALSE;
  42. }
  43. return TRUE;
  44. }
  45. void CLgUICameraEngine::Destroy()
  46. {
  47. // destroy all video windows
  48. while( CLgLink<CLgUICameraEngine,CLgUICameraVideoWnd>::GetCount() )
  49. delete *CLgLink<CLgUICameraEngine,CLgUICameraVideoWnd>::GetAt(0);
  50. // destroy background window
  51. if( m_HiddenWnd.GetSafeHwnd() )
  52. m_HiddenWnd.DestroyWindow();
  53. }
  54. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  55. // main control methods
  56. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  57. BOOL CLgUICameraEngine::SetActiveCamera( CLgUICamera* pVideoCamera )
  58. {
  59. // check pointer
  60. if( !pVideoCamera )
  61. return FALSE;
  62. // check camera link
  63. if( CLgLink<CLgUICameraEngine,CLgUICamera>::Find( (CLgLink<CLgUICamera,CLgUICameraEngine>*&)pVideoCamera ) == -1 )
  64. return FALSE;
  65. // get pointers to objects
  66. CLgUICameraListWnd *pListWnd = *this;
  67. CLgUICameraMainWnd *pMainWnd = *this;
  68. CLgUICameraControlWnd *pControlWnd = *this;
  69. // if active camera already exist then substitute it (if it differs from entered)
  70. if( m_pActiveCamera )
  71. {
  72. // don't need to do anything
  73. if( m_pActiveCamera == pVideoCamera )
  74. return TRUE;
  75. // if exist link to main video window
  76. if( pListWnd )
  77. {
  78. CLgUICameraVideoWnd *pVideoWnd = m_pActiveCamera->GetVideoWnd();
  79. if( !pVideoWnd )
  80. // error situation!!!
  81. return FALSE;
  82. // try to add to list current active camera
  83. if( !pListWnd->Link( pVideoWnd ) )
  84. return FALSE;
  85. }
  86. }
  87. // clear pointer (paranoia)
  88. m_pActiveCamera = NULL;
  89. // if exist link with video cameras list wnd
  90. if( pListWnd )
  91. {
  92. CLgUICameraVideoWnd *pVideoWnd = pVideoCamera->GetVideoWnd();
  93. if( !pVideoWnd )
  94. // error situation!!!
  95. return FALSE;
  96. // remove camera from list
  97. pListWnd->Unlink( pVideoWnd );
  98. }
  99. // if exist link to main video window
  100. if( pMainWnd )
  101. {
  102. CLgUICameraVideoWnd *pVideoWnd = pVideoCamera->GetVideoWnd();
  103. if( !pVideoWnd )
  104. // error situation!!!
  105. return FALSE;
  106. // unregister old wnd
  107. pMainWnd->CLgLink<CLgUICameraMainWnd,CLgUICameraVideoWnd>::Unlink();
  108. // set new camera as main camera
  109. if( !pMainWnd->Link( pVideoWnd ) )
  110. return FALSE;
  111. }
  112. // if exist link to control window
  113. if( pControlWnd )
  114. {
  115. // unregister old camera (if any)
  116. pControlWnd->CLgLink<CLgUICameraControlWnd,CLgUICamera>::Unlink();
  117. // set new camera as main camera
  118. if( !pControlWnd->Link( pVideoCamera ) )
  119. return FALSE;
  120. }
  121. // store pointer for new camera
  122. m_pActiveCamera = pVideoCamera;
  123. return FALSE;
  124. }
  125. BOOL CLgUICameraEngine::SetActiveVideo( CLgUICameraVideoWnd* pVideoWnd )
  126. {
  127. // check pointer
  128. if( !pVideoWnd )
  129. return FALSE;
  130. // check camera link
  131. if( CLgLink<CLgUICameraEngine,CLgUICameraVideoWnd>::Find( (CLgLink<CLgUICameraVideoWnd,CLgUICameraEngine>*&)pVideoWnd ) == -1 )
  132. return FALSE;
  133. CLgUICamera *pVideoCamera = pVideoWnd->GetVideoCamera();
  134. if( !pVideoCamera )
  135. // error situation
  136. return FALSE;
  137. return SetActiveCamera( pVideoCamera );
  138. }
  139. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  140. // notifications from CLgVideoCamera objects
  141. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  142. BOOL CLgUICameraEngine::OnVideoCameraStream( CLgUICamera* pVideoCamera, BOOL bRun )
  143. {
  144. // check pointer
  145. if( !pVideoCamera )
  146. return FALSE;
  147. CLgArray< CLgLink<CLgUICameraVideoWnd,CLgUICameraEngine>* >& arrVideoWnd = *this;
  148. // check camera link
  149. if( CLgLink<CLgUICameraEngine,CLgUICamera>::Find( (CLgLink<CLgUICamera,CLgUICameraEngine>*&)pVideoCamera ) == -1 )
  150. return FALSE;
  151. // get pointers to objects
  152. CLgUICameraListWnd *pListWnd = *this;
  153. CLgUICameraMainWnd *pMainWnd = *this;
  154. CLgUICameraControlWnd *pControlWnd = *this;
  155. if( bRun )
  156. {
  157. // try to find cmaera among connected cameras
  158. for( INT i = 0; i < arrVideoWnd.GetCount(); i++ )
  159. {
  160. CLgUICameraVideoWnd *pTempVideoWnd = *arrVideoWnd[i];
  161. // if no connected cameras
  162. if( pTempVideoWnd->GetVideoCamera() == pVideoCamera )
  163. {
  164. return TRUE;
  165. }
  166. }
  167. // try to find free CLgUICameraVideoWnd
  168. CLgUICameraVideoWnd *pVideoWnd = NULL;
  169. for( i = 0; i < arrVideoWnd.GetCount(); i++ )
  170. {
  171. CLgUICameraVideoWnd *pTempVideoWnd = *arrVideoWnd[i];
  172. // if no connected cameras
  173. if( !pTempVideoWnd->GetVideoCamera() )
  174. {
  175. pVideoWnd = pTempVideoWnd;
  176. break;
  177. }
  178. }
  179. // try to create new CLgUICameraVideoWnd
  180. if( !pVideoWnd )
  181. {
  182. pVideoWnd = new CLgUICameraVideoWnd();
  183. if( !pVideoWnd )
  184. return FALSE;
  185. // create window
  186. if( !pVideoWnd->Create( &m_HiddenWnd, 0, 0, 10, 10 ) )
  187. {
  188. delete pVideoWnd;
  189. return FALSE;
  190. }
  191. // add into internal list
  192. if( !CLgLink<CLgUICameraEngine,CLgUICameraVideoWnd>::Link( pVideoWnd ) )
  193. {
  194. delete pVideoWnd;
  195. return FALSE;
  196. }
  197. }
  198. // link video window to video camera
  199. if( !pVideoWnd->CLgLinkS<CLgUICameraVideoWnd,CLgUICamera>::Link( pVideoCamera ) )
  200. return FALSE;
  201. // if exist link with video cameras list wnd
  202. if( pListWnd )
  203. {
  204. // addd camera into list
  205. if( !pListWnd->Link( pVideoWnd ) )
  206. return FALSE;
  207. }
  208. // if active camera is not exist
  209. if( !m_pActiveCamera )
  210. return SetActiveCamera( pVideoCamera );
  211. }
  212. else
  213. {
  214. // remember pointer to video wnd
  215. CLgUICameraVideoWnd *pVideoWnd = pVideoCamera->GetVideoWnd();
  216. if( pVideoWnd )
  217. {
  218. // unlink camera from window
  219. pVideoCamera->CLgLinkS<CLgUICamera,CLgUICameraVideoWnd>::Unlink();
  220. }
  221. // if main control camera is this camera
  222. if( m_pActiveCamera == pVideoCamera )
  223. {
  224. if( pListWnd )
  225. {
  226. // if there is cameras
  227. if( pListWnd->GetVideoWndCount() )
  228. {
  229. // set first camera as active camera
  230. return SetActiveVideo( pListWnd->GetVideoWnd(0) );
  231. }
  232. }
  233. }
  234. else
  235. {
  236. // if exist link with video cameras list wnd
  237. if( pListWnd )
  238. {
  239. // addd camera into list
  240. pListWnd->Unlink( pVideoWnd );
  241. }
  242. }
  243. }
  244. return TRUE;
  245. }