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.

182 lines
4.8 KiB

  1. /**
  2. * @file class_marker_base.cpp
  3. * @brief Implementation of MARKER_BASE class.
  4. * Markers are used to show something (usually a drc/erc problem).
  5. * Markers in Pcbnew and Eeschema are derived from this base class.
  6. */
  7. /* file class_marker_base.cpp
  8. */
  9. #include "fctsys.h"
  10. #include "gr_basic.h"
  11. #include "class_base_screen.h"
  12. #include "common.h"
  13. #include "macros.h"
  14. #include "class_drawpanel.h"
  15. #include "class_marker_base.h"
  16. #include "dialog_display_info_HTML_base.h"
  17. // Default marquer shape:
  18. #define M_SHAPE_SCALE 6 // default scaling factor for MarkerShapeCorners coordinates
  19. #define CORNERS_COUNT 8
  20. /* corners of the default shape
  21. * actual coordinates are these values * .m_ScalingFactor
  22. */
  23. static const wxPoint MarkerShapeCorners[CORNERS_COUNT] =
  24. {
  25. wxPoint( 0, 0 ),
  26. wxPoint( 8, 1 ),
  27. wxPoint( 4, 3 ),
  28. wxPoint( 13, 8 ),
  29. wxPoint( 9, 9 ),
  30. wxPoint( 8, 13 ),
  31. wxPoint( 3, 4 ),
  32. wxPoint( 1, 8 )
  33. };
  34. /*******************/
  35. /* Classe MARKER_BASE */
  36. /*******************/
  37. void MARKER_BASE::init()
  38. {
  39. m_MarkerType = 0;
  40. m_Color = RED;
  41. wxPoint start = MarkerShapeCorners[0];
  42. wxPoint end = MarkerShapeCorners[0];
  43. for( unsigned ii = 0; ii < CORNERS_COUNT; ii++ )
  44. {
  45. wxPoint corner = MarkerShapeCorners[ii];
  46. m_Corners.push_back( corner );
  47. start.x = std::min( start.x, corner.x);
  48. start.y = std::min( start.y, corner.y);
  49. end.x = std::max( end.x, corner.x);
  50. end.y = std::max( end.y, corner.y);
  51. }
  52. m_ShapeBoundingBox.SetOrigin(start);
  53. m_ShapeBoundingBox.SetEnd(end);
  54. }
  55. MARKER_BASE::MARKER_BASE( const MARKER_BASE& aMarker )
  56. {
  57. m_Pos = aMarker.m_Pos;
  58. m_Corners = aMarker.m_Corners;
  59. m_MarkerType = aMarker.m_MarkerType;
  60. m_Color = aMarker.m_Color;
  61. m_ShapeBoundingBox = aMarker.m_ShapeBoundingBox;
  62. m_ScalingFactor = aMarker.m_ScalingFactor;
  63. }
  64. MARKER_BASE::MARKER_BASE()
  65. {
  66. m_ScalingFactor = M_SHAPE_SCALE;
  67. init();
  68. }
  69. MARKER_BASE::MARKER_BASE( int aErrorCode, const wxPoint& aMarkerPos,
  70. const wxString& aText, const wxPoint& aPos,
  71. const wxString& bText, const wxPoint& bPos )
  72. {
  73. m_ScalingFactor = M_SHAPE_SCALE;
  74. init();
  75. SetData( aErrorCode, aMarkerPos,
  76. aText, aPos,
  77. bText, bPos );
  78. }
  79. MARKER_BASE::MARKER_BASE( int aErrorCode, const wxPoint& aMarkerPos,
  80. const wxString& aText, const wxPoint& aPos )
  81. {
  82. m_ScalingFactor = M_SHAPE_SCALE;
  83. init();
  84. SetData( aErrorCode, aMarkerPos, aText, aPos );
  85. }
  86. MARKER_BASE::~MARKER_BASE()
  87. {
  88. }
  89. void MARKER_BASE::SetData( int aErrorCode, const wxPoint& aMarkerPos,
  90. const wxString& aText, const wxPoint& aPos,
  91. const wxString& bText, const wxPoint& bPos )
  92. {
  93. m_Pos = aMarkerPos;
  94. m_drc.SetData( aErrorCode,
  95. aText, bText, aPos, bPos );
  96. }
  97. void MARKER_BASE::SetData( int aErrorCode, const wxPoint& aMarkerPos,
  98. const wxString& aText, const wxPoint& aPos )
  99. {
  100. m_Pos = aMarkerPos;
  101. m_drc.SetData( aErrorCode,
  102. aText, aPos );
  103. }
  104. bool MARKER_BASE::HitTestMarker( const wxPoint& refPos ) const
  105. {
  106. wxPoint rel_pos = refPos - m_Pos;
  107. rel_pos.x /= m_ScalingFactor;
  108. rel_pos.y /= m_ScalingFactor;
  109. return m_ShapeBoundingBox.Contains( rel_pos );
  110. }
  111. EDA_RECT MARKER_BASE::GetBoundingBoxMarker() const
  112. {
  113. wxSize realsize = m_ShapeBoundingBox.GetSize();
  114. wxPoint realposition = m_ShapeBoundingBox.GetPosition();
  115. realsize.x *= m_ScalingFactor;
  116. realsize.y *= m_ScalingFactor;
  117. realposition.x *= m_ScalingFactor;
  118. realposition.y *= m_ScalingFactor;
  119. realposition += m_Pos;
  120. return EDA_RECT( m_Pos, realsize );
  121. }
  122. void MARKER_BASE::DrawMarker( EDA_DRAW_PANEL* aPanel, wxDC* aDC, GR_DRAWMODE aDrawMode,
  123. const wxPoint& aOffset )
  124. {
  125. wxPoint corners[CORNERS_COUNT];
  126. GRSetDrawMode( aDC, aDrawMode );
  127. for( unsigned ii = 0; ii < m_Corners.size(); ii++ )
  128. {
  129. corners[ii] = m_Corners[ii];
  130. corners[ii].x *= m_ScalingFactor;
  131. corners[ii].y *= m_ScalingFactor;
  132. corners[ii] += m_Pos + aOffset;
  133. }
  134. GRClosedPoly( aPanel->GetClipBox(), aDC, CORNERS_COUNT, corners,
  135. true, // = Filled
  136. 0, // outline width
  137. m_Color, // outline color
  138. m_Color // fill collor
  139. );
  140. }
  141. void MARKER_BASE::DisplayMarkerInfo( EDA_DRAW_FRAME* aFrame )
  142. {
  143. wxString msg = m_drc.ShowHtml();
  144. DIALOG_DISPLAY_HTML_TEXT_BASE infodisplay( (wxWindow*)aFrame, wxID_ANY, _( "Marker Info" ),
  145. wxGetMousePosition(), wxSize( 550, 140 ) );
  146. infodisplay.m_htmlWindow->SetPage( msg );
  147. infodisplay.ShowModal();
  148. }