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.

184 lines
4.9 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: Visual.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of Visual.cpp
  13. //----------------------------------------------------------------------------
  14. // Visual.cpp: implementation of the CVisual class.
  15. //
  16. //////////////////////////////////////////////////////////////////////
  17. #include "stdafx.h"
  18. //#include "chicago.h"
  19. #include "Visual.h"
  20. #include "..\..\LgLib\Version.h"
  21. #ifdef _DEBUG
  22. #undef THIS_FILE
  23. static char THIS_FILE[]=__FILE__;
  24. #define new DEBUG_NEW
  25. #endif
  26. //////////////////////////////////////////////////////////////////////
  27. // Construction/Destruction
  28. //////////////////////////////////////////////////////////////////////
  29. CVisual::CVisual()
  30. {
  31. m_strName = "noname";
  32. m_nState = UNKNOWN;
  33. m_nType = VISUAL;
  34. m_pBitmap = NULL;
  35. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CVisual::CVisual") );
  36. }
  37. CVisual::~CVisual()
  38. {
  39. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CVisual::~CVisual") );
  40. }
  41. COLORREF CVisual::GetStateColor( BOOL bInverse )
  42. {
  43. return GetStateColor( m_nState, bInverse );
  44. }
  45. void CVisual::GetStateString( CString& str )
  46. {
  47. str = GetName() + " " + GetStateString( m_nState );
  48. }
  49. COLORREF CVisual::GetStateColor( int nState, BOOL bInverse )
  50. {
  51. COLORREF color;
  52. switch( nState )
  53. {
  54. case UNKNOWN: color = RGB( 0x00, 0x00, 0xFF ); break;
  55. case NORMAL: color = (bInverse) ? RGB( 0x00, 0x7F, 0x00 ) : RGB( 0x00, 0xFF, 0x00 ); break;
  56. case TIMEOUT: color = (bInverse) ? RGB( 0x7F, 0x7F, 0x00 ) : RGB( 0xFF, 0xFF, 0x00 ); break;
  57. case ALARM: color = (bInverse) ? RGB( 0x7F, 0x00, 0x00 ) : RGB( 0xFF, 0x00, 0x00 ); break;
  58. case POSTALARM: color = (bInverse) ? RGB( 0xFF, 0x00, 0x00 ) : RGB( 0x00, 0xFF, 0x00 ); break;
  59. case DISABLE: color = (bInverse) ? RGB( 0x7F, 0x7F, 0x7F ) : RGB( 0xFF, 0xFF, 0xFF ); break;
  60. }
  61. return color;
  62. }
  63. LPCTSTR CVisual::GetStateString( int nState )
  64. {
  65. LPCTSTR pStr = NULL;
  66. switch( nState )
  67. {
  68. case UNKNOWN: pStr = _T( "state unknown" ); break;
  69. case NORMAL: pStr = _T( "normally work" ); break;
  70. case TIMEOUT: pStr = _T( "not response" ); break;
  71. case ALARM: pStr = _T( "send alarm" ); break;
  72. case DISABLE: pStr = _T( "disabled" ); break;
  73. case POSTALARM: pStr = _T( "alarm disapeared" ); break;
  74. }
  75. return pStr;
  76. }
  77. BOOL CVisual::GetBlinkState()
  78. {
  79. switch( m_nState )
  80. {
  81. case TIMEOUT:
  82. case ALARM:
  83. case POSTALARM:
  84. case DISABLE:
  85. return TRUE;
  86. case UNKNOWN:
  87. case NORMAL:
  88. default:
  89. return FALSE;
  90. }
  91. }
  92. BOOL CVisual::PaintBounds( CDC *pDC, CRect &viewRect, CSize &mapSize, SDPOINT &mapShift, double mapScale, BOOL bInverse, BOOL bBigSize, CRect *pUpdateRect )
  93. {
  94. SDPOINT shift( m_Position.x - mapShift.x, m_Position.y - mapShift.y );
  95. CPoint p = CalcDrawPoint( viewRect, mapSize, shift, mapScale );
  96. if( !viewRect.PtInRect(p) ) return FALSE;
  97. COLORREF color = RGB( 0xFF, 0x00, 0xFF );
  98. CRect rect;
  99. CPen pen( PS_SOLID, 2, color );
  100. // int nOldRop2 = pDC->SetROP2( R2_XORPEN );
  101. CPen *pOldPen = pDC->SelectObject( &pen );
  102. if( /*bBigSize*/1 )
  103. {
  104. int dx = 26;
  105. int dy = 12;
  106. pDC->MoveTo( p.x - dx, p.y - dy );
  107. pDC->LineTo( p.x + dx, p.y - dy );
  108. pDC->LineTo( p.x + dx, p.y + dy );
  109. pDC->LineTo( p.x - dx, p.y + dy );
  110. pDC->LineTo( p.x - dx, p.y - dy );
  111. rect.SetRect( p.x - dx - 1, p.y - dy - 1, p.x + dx + 1, p.y + dy + 1 );
  112. }
  113. else
  114. {
  115. /* pDC->MoveTo( p.x - 2, p.y - 2 );
  116. pDC->LineTo( p.x + 2, p.y - 2 );
  117. pDC->LineTo( p.x + 2, p.y + 2 );
  118. pDC->LineTo( p.x - 2, p.y + 2 );
  119. pDC->LineTo( p.x - 2, p.y - 2 );
  120. rect.SetRect( p.x - 2, p.y - 2, p.x + 2, p.y + 2 );
  121. */ }
  122. pDC->SelectObject( pOldPen );
  123. // pDC->SetROP2( nOldRop2 );
  124. if( pUpdateRect ) *pUpdateRect = rect;
  125. return TRUE;
  126. }
  127. void CVisual::Reset()
  128. {
  129. if( GetState() != DISABLE )
  130. SetState( UNKNOWN );
  131. }
  132. void CVisual::OnUIMapDraw( CLgUIMapObjectWnd *pMap, CDC *pDC, BOOL bActive, BOOL bOddUpdate )
  133. {
  134. CLgDPoint dp( m_Position.x, m_Position.y );
  135. CPoint p = pMap->AreaToWindow( &dp );
  136. CRect rect;
  137. if( bActive && !bOddUpdate )
  138. rect.SetRect( p.x - 4, p.y - 4, p.x + 4, p.y + 4 );
  139. else
  140. rect.SetRect( p.x - 2, p.y - 2, p.x + 2, p.y + 2 );
  141. pDC->FillSolidRect( &rect, GetStateColor( bOddUpdate ) );
  142. }
  143. BOOL CVisual::OnUIMapHitTest( CLgUIMapObjectWnd *pMap, CLgDRect *pRect )
  144. {
  145. CLgDPoint dp( m_Position.x, m_Position.y );
  146. return pRect->PtInRect( dp );
  147. }
  148. void CVisual::OnUIMapDrawBackground( CLgUIMapObjectWnd *pMap, CDC *pDC )
  149. {
  150. CLgDPoint dp( m_Position.x, m_Position.y );
  151. CPoint center = pMap->AreaToWindow( &dp );
  152. OnDrawBackground( pDC, center, pMap->GetMeterToPixelScale() );
  153. }
  154. void CVisual::OnDrawBackground( CDC *pDC, CPoint center, double dMeterToPixelScale )
  155. {
  156. }