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.

438 lines
13 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: TroubleListWnd.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of TroubleListWnd.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "chicago.h"
  16. #include "TroubleListWnd.h"
  17. #include "..\..\lglib\lgaux.h"
  18. #include "..\DLIB\SensorLGS.h"
  19. #include "..\DLIB\SensorDC.h"
  20. #include "..\DLIB\SensorCLD.h"
  21. #include "..\..\LgLib\Version.h"
  22. #ifdef _DEBUG
  23. #undef THIS_FILE
  24. static char THIS_FILE[]=__FILE__;
  25. #define new DEBUG_NEW
  26. #endif
  27. BEGIN_MESSAGE_MAP(CTroubleListWnd, CLgListWnd)
  28. //{{AFX_MSG_MAP(CTroubleListWnd)
  29. ON_WM_LBUTTONDOWN()
  30. //}}AFX_MSG_MAP
  31. END_MESSAGE_MAP()
  32. CTroubleListWnd::CTroubleListWnd()
  33. {
  34. m_pSensorArray = NULL;
  35. m_hIconPower = NULL;
  36. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CTroubleListWnd::CTroubleListWnd") );
  37. }
  38. CTroubleListWnd::~CTroubleListWnd()
  39. {
  40. RemoveAll();
  41. if( m_hIconPower )
  42. DestroyIcon( m_hIconPower );
  43. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CTroubleListWnd::~CTroubleListWnd") );
  44. }
  45. void CTroubleListWnd::OnItemDraw( CDC *pDC, CRect *pRect, void *pItem, BOOL bActive )
  46. {
  47. LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CTroubleListWnd::OnItemDraw"), _T("Started...") );
  48. PTROUBLE pTrouble = (PTROUBLE)pItem;
  49. CSensor *pSensor = pTrouble->pSensor;
  50. // copy minimap background
  51. pDC->BitBlt( pRect->left, pRect->top, pRect->Width(), pRect->Height(), &m_MemoryDC, 0, 0, SRCCOPY );
  52. int cxImage = (int)((m_ItemSize.cy - 20)*4./3.);
  53. int cyImage = m_ItemSize.cy - 20;
  54. // copy minimap background
  55. pDC->BitBlt( pRect->left, pRect->top, cxImage, cyImage, &pTrouble->dcDraw, 0, 0, SRCCOPY );
  56. // fill line under bottom text
  57. pDC->FillSolidRect( pRect->left, pRect->bottom - 20, pRect->Width(), 20, pSensor->GetStateColor( m_bOddUpdate ) );
  58. // draw target lines
  59. COLORREF color[2] = { RGB(0xFF,0xFF,0xFF), RGB(0,0,0) };
  60. CPen pen( PS_DOT, 1, m_bOddUpdate ? color[0] : color[1] );
  61. CPen *pPen = pDC->SelectObject( &pen );
  62. int nBkColor = pDC->SetBkColor( m_bOddUpdate ? color[1] : color[0] );
  63. CPoint pos( (int)(m_MinimapRect.Width() * pSensor->GetPosition().x),
  64. (int)(m_MinimapRect.Height() * pSensor->GetPosition().y) );
  65. pos += m_MinimapRect.TopLeft() + pRect->TopLeft();
  66. pDC->MoveTo( pos.x, m_MinimapRect.top + pRect->top );
  67. pDC->LineTo( pos.x, m_MinimapRect.bottom + pRect->top );
  68. pDC->MoveTo( m_MinimapRect.left + pRect->left, pos.y );
  69. pDC->LineTo( m_MinimapRect.right + pRect->left, pos.y );
  70. pDC->SetBkColor( nBkColor );
  71. pDC->SelectObject( pPen );
  72. // draw bottom text
  73. COLORREF nColor = pDC->SetTextColor( pSensor->GetStateColor( !m_bOddUpdate ) );
  74. INT nBkMode = pDC->SetBkMode( TRANSPARENT );
  75. CRect TextRect( pRect->left + 20, pRect->bottom - 20, pRect->right, pRect->bottom );
  76. pDC->DrawText( pSensor->GetName(), &TextRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
  77. pDC->SetTextColor( nColor );
  78. pDC->SetBkMode( nBkMode );
  79. // additional work
  80. switch( pSensor->GetType() )
  81. {
  82. case CVisual::LGS:
  83. switch( pSensor->GetState() )
  84. {
  85. case CSensor::NORMAL:
  86. case CSensor::ALARM:
  87. case CSensor::POSTALARM:
  88. if( !static_cast<CSensorLGS*>(pSensor)->IsPowered() && !m_bOddUpdate )
  89. pDC->DrawIcon( pRect->left, pRect->bottom - GetSystemMetrics( SM_CXICON ), m_hIconPower );
  90. if( static_cast<CSensorLGS*>(pSensor)->IsSetHzInProgress() )
  91. {
  92. TCHAR pText[MAX_PATH];
  93. _sntprintf( pText, MAX_PATH, _T("Upload %d%%"), static_cast<CSensorLGS*>(pSensor)->GetSetHzProgress() );
  94. nColor = pDC->SetTextColor( pSensor->GetStateColor( !m_bOddUpdate ) );
  95. nBkMode = pDC->SetBkMode( TRANSPARENT );
  96. TextRect.SetRect( pRect->left + 20, pRect->bottom - 20, pRect->right, pRect->bottom );
  97. pDC->DrawText( pText, &TextRect, /*DT_CENTER | */DT_VCENTER | DT_SINGLELINE );
  98. pDC->SetTextColor( nColor );
  99. pDC->SetBkMode( nBkMode );
  100. }
  101. else
  102. if( static_cast<CSensorLGS*>(pSensor)->IsInStudyMode() )
  103. {
  104. TCHAR pText[MAX_PATH];
  105. _sntprintf( pText, MAX_PATH, _T("Adaptation") );
  106. nColor = pDC->SetTextColor( pSensor->GetStateColor( !m_bOddUpdate ) );
  107. nBkMode = pDC->SetBkMode( TRANSPARENT );
  108. TextRect.SetRect( pRect->left + 20, pRect->bottom - 20, pRect->right, pRect->bottom );
  109. pDC->DrawText( pText, &TextRect, /*DT_CENTER | */DT_VCENTER | DT_SINGLELINE );
  110. pDC->SetTextColor( nColor );
  111. pDC->SetBkMode( nBkMode );
  112. }
  113. break;
  114. }
  115. break;
  116. }
  117. LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CTroubleListWnd::OnItemDraw"), _T("Done") );
  118. }
  119. void CTroubleListWnd::OnItemMove( void* pItem, CRect *pRect, BOOL bShow, BOOL bActive )
  120. {
  121. LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CTroubleListWnd::OnItemMove"), _T("Started...") );
  122. if( bShow )
  123. InvalidateRect( NULL );
  124. LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CTroubleListWnd::OnItemMove"), _T("Done") );
  125. }
  126. BOOL CTroubleListWnd::Create( CWnd *pParentWnd, int x, int y, int nWidth, int nHeight, CLgUIMapBackground *pBackground )
  127. {
  128. // load icon
  129. m_hIconPower = (HICON)::LoadImage( AfxGetInstanceHandle(), (LPCTSTR)IDI_ICON_POWER, IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR );
  130. if( !CLgListWnd::Create( pParentWnd, x, y, nWidth, nHeight ) )
  131. {
  132. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CTroubleListWnd::Create"), _T("CLgListWnd::Create failed") );
  133. return FALSE;
  134. }
  135. CWnd::ModifyStyle( 0, WS_DLGFRAME | WS_CLIPSIBLINGS );
  136. int ik = 35;
  137. int iWidth = ik * 7;
  138. int iHeight = ik * 3 + 20;
  139. if( !SetItemSize( CSize( iWidth, iHeight ) ) )
  140. {
  141. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CTroubleListWnd::Create"), _T("SetItemSize failed") );
  142. return FALSE;
  143. }
  144. if( !m_MemoryDC.Create( m_ItemSize.cx, m_ItemSize.cy, RGB(0x7F,0x7F,0x7F) ) )
  145. {
  146. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CTroubleListWnd::Create"), _T("m_MemoryDC.Create failed") );
  147. return FALSE;
  148. }
  149. if( !pBackground )
  150. {
  151. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CTroubleListWnd::Create"), _T("pBackground is NULL") );
  152. return TRUE;
  153. }
  154. CRect WholeRect( m_ItemSize.cx - (m_ItemSize.cy - 20), 0, m_ItemSize.cx, m_ItemSize.cy - 20 );
  155. double dAspect = ((double)pBackground->GetSize().cx) / ((double)pBackground->GetSize().cy);
  156. FitRectWithAspect( &WholeRect, &m_MinimapRect, dAspect );
  157. pBackground->Draw( &m_MemoryDC, &m_MinimapRect );
  158. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CTroubleListWnd::Create"), _T("Succeeded") );
  159. return TRUE;
  160. }
  161. void CTroubleListWnd::UpdateInfo( BOOL bOdd )
  162. {
  163. if( !m_pSensorArray )
  164. return;
  165. BOOL bChanged = FALSE;
  166. for( int i = 0; i < m_pSensorArray->GetSensorCount(); i++ )
  167. {
  168. CSensor *pSensor = m_pSensorArray->GetSensor( i );
  169. ASSERT( pSensor );
  170. BOOL bInTrouble = pSensor->GetState() != CSensor::NORMAL;
  171. // pefrom additional checking
  172. switch( pSensor->GetType() )
  173. {
  174. case CVisual::LGS:
  175. if( !bInTrouble &&
  176. ( !static_cast<CSensorLGS*>(pSensor)->IsPowered() || static_cast<CSensorLGS*>(pSensor)->IsSetHzInProgress() || static_cast<CSensorLGS*>(pSensor)->IsInStudyMode() ) )
  177. bInTrouble = TRUE;
  178. break;
  179. }
  180. // if sensor has some problems
  181. if( bInTrouble )
  182. {
  183. BOOL bFound = FALSE;
  184. PTROUBLE pFoundTrouble;
  185. for( int j = 0; j < m_ArrayItem.GetSize(); j++ )
  186. {
  187. PTROUBLE pTrouble = (PTROUBLE)m_ArrayItem[j];
  188. ASSERT( pTrouble );
  189. if( pTrouble->nType == TT_SENSOR &&
  190. pTrouble->pSensor == pSensor )
  191. {
  192. bFound = TRUE;
  193. pFoundTrouble = pTrouble;
  194. break;
  195. }
  196. }
  197. if( bFound )
  198. {
  199. if( !m_pSensorArray->GetSetupSettings().bTroubleWindowShowFirstImage && pFoundTrouble->nBitmapCount )
  200. {
  201. DWORD dwTime = GetTickCount();
  202. if( ( dwTime - pFoundTrouble->dwImageTime ) >= TROUBLE_IMAGE_TIMEOUT )
  203. {
  204. pFoundTrouble->dwImageTime = dwTime;
  205. if( pFoundTrouble->nImageSkip )
  206. pFoundTrouble->nImageSkip--;
  207. else
  208. {
  209. HBITMAP hBitmap = pFoundTrouble->pBitmap[ pFoundTrouble->nBitmapIndexView ];
  210. // increase view counter
  211. pFoundTrouble->nBitmapIndexView = ( pFoundTrouble->nBitmapIndexView + 1 ) % pFoundTrouble->nBitmapCount;
  212. CLgMemoryDC dc;
  213. dc.Create( hBitmap );
  214. int nStretchMode = pFoundTrouble->dcDraw.SetStretchBltMode( COLORONCOLOR );
  215. pFoundTrouble->dcDraw.StretchBlt( 0, 0, pFoundTrouble->dcDraw.GetSize().cx, pFoundTrouble->dcDraw.GetSize().cy, &dc, 0,0,dc.GetSize().cx, dc.GetSize().cy, SRCCOPY );
  216. pFoundTrouble->dcDraw.SetStretchBltMode( nStretchMode );
  217. }
  218. }
  219. }
  220. }
  221. else
  222. {
  223. PTROUBLE pTrouble = new TROUBLE;
  224. int cxImage = (int)((m_ItemSize.cy - 20)*4./3.);
  225. int cyImage = m_ItemSize.cy - 20;
  226. ASSERT( pTrouble );
  227. pTrouble->nType = TT_SENSOR;
  228. pTrouble->pSensor = pSensor;
  229. pTrouble->dcDraw.Create( cxImage, cyImage, RGB(0x7f,0x7f,0x7f) );
  230. CRect SensorRect( 0, 0, cxImage, cyImage );
  231. CRect DrawRect;
  232. FitRectWithAspect( &SensorRect, &DrawRect, 1.0 );
  233. CLgMemoryDC *pSrcDC;
  234. switch( pSensor->GetType() )
  235. {
  236. case CSensor::LGS:
  237. pSrcDC = ((CSensorLGS*)pSensor)->GetSurface();
  238. pTrouble->dcDraw.StretchBlt( DrawRect.left, DrawRect.top, DrawRect.Width(), DrawRect.Height(), pSrcDC, 0, 0, pSrcDC->GetSize().cx, pSrcDC->GetSize().cy, SRCCOPY );
  239. break;
  240. case CSensor::DC:
  241. pSrcDC = ((CSensorDC*)pSensor)->GetBG();
  242. pTrouble->dcDraw.StretchBlt( DrawRect.left, DrawRect.top, DrawRect.Width(), DrawRect.Height(), pSrcDC, 0, 0, pSrcDC->GetSize().cx, pSrcDC->GetSize().cy, SRCCOPY );
  243. break;
  244. case CSensor::CLD:
  245. pSrcDC = ((CSensorCLD*)pSensor)->GetSurface();
  246. pTrouble->dcDraw.StretchBlt( DrawRect.left, DrawRect.top, DrawRect.Width(), DrawRect.Height(), pSrcDC, 0, 0, pSrcDC->GetSize().cx, pSrcDC->GetSize().cy, SRCCOPY );
  247. break;
  248. }
  249. if( Add( pTrouble ) )
  250. bChanged = TRUE;
  251. else
  252. {
  253. // delete pTrouble;
  254. OnItemRemove( pTrouble );
  255. }
  256. }
  257. }
  258. else
  259. {
  260. BOOL bFound = FALSE;
  261. for( int j = 0; j < m_ArrayItem.GetSize(); j++ )
  262. {
  263. PTROUBLE pTrouble = (PTROUBLE)m_ArrayItem[j];
  264. ASSERT( pTrouble );
  265. if( pTrouble->nType == TT_SENSOR &&
  266. pTrouble->pSensor == pSensor )
  267. {
  268. if( Remove( pTrouble ) )
  269. bChanged = TRUE;
  270. break;
  271. }
  272. }
  273. }
  274. }
  275. m_bOddUpdate = bOdd;
  276. InvalidateRect( NULL );
  277. }
  278. void CTroubleListWnd::OnLButtonDown(UINT nFlags, CPoint point)
  279. {
  280. PTROUBLE pTrouble = (PTROUBLE)GetItemFromPoint( &point );
  281. if( pTrouble && pTrouble->nType == TT_SENSOR )
  282. {
  283. CSensor *pSensor = pTrouble->pSensor;
  284. if( pSensor )
  285. {
  286. GetParent()->SendMessage( WM_SENSOR_SHOW, (WPARAM)pSensor, (LPARAM)pSensor );
  287. }
  288. }
  289. CLgListWnd::OnLButtonDown(nFlags, point);
  290. }
  291. void CTroubleListWnd::OnItemRemove( void *pItem )
  292. {
  293. PTROUBLE pTrouble = (PTROUBLE)pItem;
  294. for( INT i = 0; i < pTrouble->nBitmapCount; i++ )
  295. ::DeleteObject( pTrouble->pBitmap[i] );
  296. delete pTrouble;
  297. // delete (PTROUBLE)pItem;
  298. }
  299. void CTroubleListWnd::SetItemImage( CSensor *pSensor, HBITMAP hBitmap )
  300. {
  301. if( !pSensor || !hBitmap )
  302. return;
  303. BOOL bDelete = TRUE;
  304. for( int j = 0; j < m_ArrayItem.GetSize(); j++ )
  305. {
  306. PTROUBLE pTrouble = (PTROUBLE)m_ArrayItem[j];
  307. ASSERT( pTrouble );
  308. if( pTrouble->nType == TT_SENSOR && pTrouble->pSensor == pSensor )
  309. {
  310. CLgMemoryDC dc;
  311. dc.Create( hBitmap );
  312. if( !m_pSensorArray->GetSetupSettings().bTroubleWindowShowFirstImage ||
  313. !pTrouble->bImage )
  314. {
  315. pTrouble->bImage = TRUE;
  316. int nStretchMode = pTrouble->dcDraw.SetStretchBltMode( COLORONCOLOR );
  317. pTrouble->dcDraw.StretchBlt( 0, 0, pTrouble->dcDraw.GetSize().cx, pTrouble->dcDraw.GetSize().cy, &dc, 0,0,dc.GetSize().cx, dc.GetSize().cy, SRCCOPY );
  318. pTrouble->dcDraw.SetStretchBltMode( nStretchMode );
  319. }
  320. // delete previous image (if any)
  321. if( pTrouble->pBitmap[ pTrouble->nBitmapIndexAdd ] )
  322. ::DeleteObject( pTrouble->pBitmap[ pTrouble->nBitmapIndexAdd ] );
  323. // store image in list
  324. pTrouble->pBitmap[ pTrouble->nBitmapIndexAdd ] = hBitmap;
  325. // store last image index
  326. pTrouble->nBitmapIndexView = pTrouble->nBitmapIndexAdd;
  327. // increase image counter
  328. if( pTrouble->nBitmapCount < pSensor->GetImageCount() )
  329. pTrouble->nBitmapCount++;
  330. // increase image position
  331. pTrouble->nBitmapIndexAdd = ( pTrouble->nBitmapIndexAdd + 1 ) % pSensor->GetImageCount();
  332. pTrouble->dwImageTime = GetTickCount();
  333. pTrouble->nImageSkip = TROUBLE_IMAGE_SKIP;
  334. // don't delete!
  335. bDelete = FALSE;
  336. break;
  337. }
  338. }
  339. if( bDelete )
  340. ::DeleteObject( hBitmap );
  341. }