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.

188 lines
5.3 KiB

  1. /**********************************************************************************
  2. * class MARKER_BASE; markers are used to show something (usually a drc/erc problem)
  3. * Markers in pcbnew and eeschema are derived from this basic class
  4. **********************************************************************************/
  5. /* file class_marker_base.cpp
  6. */
  7. #include "fctsys.h"
  8. #include "gr_basic.h"
  9. #include "class_base_screen.h"
  10. #include "common.h"
  11. #include "macros.h"
  12. #include "class_drawpanel.h"
  13. #include "class_marker_base.h"
  14. #include "dialog_display_info_HTML_base.h"
  15. // Default marquer shape:
  16. #define M_SHAPE_SCALE 6 // default scaling factor for MarkerShapeCorners coordinates
  17. #define CORNERS_COUNT 8
  18. /* corners of the default shape
  19. * real coordinates are these values * .m_ScalingFactor
  20. */
  21. static const wxPoint MarkerShapeCorners[CORNERS_COUNT] =
  22. {
  23. wxPoint( 0, 0 ),
  24. wxPoint( 8, 1 ),
  25. wxPoint( 4, 3 ),
  26. wxPoint( 13, 8 ),
  27. wxPoint( 9, 9 ),
  28. wxPoint( 8, 13 ),
  29. wxPoint( 3, 4 ),
  30. wxPoint( 1, 8 )
  31. };
  32. /*******************/
  33. /* Classe MARKER_BASE */
  34. /*******************/
  35. void MARKER_BASE::init()
  36. {
  37. m_MarkerType = 0;
  38. m_Color = RED;
  39. wxPoint start = MarkerShapeCorners[0];
  40. wxPoint end = MarkerShapeCorners[0];
  41. for( unsigned ii = 0; ii < CORNERS_COUNT; ii++ )
  42. {
  43. wxPoint corner = MarkerShapeCorners[ii];
  44. m_Corners.push_back( corner );
  45. start.x = MIN( start.x, corner.x);
  46. start.y = MIN( start.y, corner.y);
  47. end.x = MAX( end.x, corner.x);
  48. end.y = MAX( end.y, corner.y);
  49. }
  50. m_ShapeBoundingBox.SetOrigin(start);
  51. m_ShapeBoundingBox.SetEnd(end);
  52. }
  53. MARKER_BASE::MARKER_BASE()
  54. {
  55. m_ScalingFactor = M_SHAPE_SCALE;
  56. init();
  57. }
  58. MARKER_BASE::MARKER_BASE( int aErrorCode, const wxPoint& aMarkerPos,
  59. const wxString& aText, const wxPoint& aPos,
  60. const wxString& bText, const wxPoint& bPos )
  61. {
  62. m_ScalingFactor = M_SHAPE_SCALE;
  63. init();
  64. SetData( aErrorCode, aMarkerPos,
  65. aText, aPos,
  66. bText, bPos );
  67. }
  68. MARKER_BASE::MARKER_BASE( int aErrorCode, const wxPoint& aMarkerPos,
  69. const wxString& aText, const wxPoint& aPos )
  70. {
  71. m_ScalingFactor = M_SHAPE_SCALE;
  72. init();
  73. SetData( aErrorCode, aMarkerPos, aText, aPos );
  74. }
  75. /* Effacement memoire de la structure */
  76. MARKER_BASE::~MARKER_BASE()
  77. {
  78. }
  79. void MARKER_BASE::SetData( int aErrorCode, const wxPoint& aMarkerPos,
  80. const wxString& aText, const wxPoint& aPos,
  81. const wxString& bText, const wxPoint& bPos )
  82. {
  83. m_Pos = aMarkerPos;
  84. m_drc.SetData( aErrorCode,
  85. aText, bText, aPos, bPos );
  86. }
  87. void MARKER_BASE::SetData( int aErrorCode, const wxPoint& aMarkerPos,
  88. const wxString& aText, const wxPoint& aPos )
  89. {
  90. m_Pos = aMarkerPos;
  91. m_drc.SetData( aErrorCode,
  92. aText, aPos );
  93. }
  94. /******************************************************/
  95. bool MARKER_BASE::HitTestMarker( const wxPoint& refPos )
  96. /******************************************************/
  97. {
  98. wxPoint rel_pos = refPos - m_Pos;
  99. rel_pos.x /= m_ScalingFactor;
  100. rel_pos.y /= m_ScalingFactor;
  101. return m_ShapeBoundingBox.Inside(rel_pos);
  102. }
  103. /**
  104. * Function GetBoundingBoxMarker
  105. * returns the orthogonal, bounding box of this object for display purposes.
  106. * This box should be an enclosing perimeter for visible components of this
  107. * object, and the units should be in the pcb or schematic coordinate system.
  108. * It is OK to overestimate the size by a few counts.
  109. */
  110. EDA_Rect MARKER_BASE::GetBoundingBoxMarker()
  111. {
  112. wxSize realsize = m_ShapeBoundingBox.GetSize();
  113. wxPoint realposition = m_ShapeBoundingBox.GetPosition();
  114. realsize.x *= m_ScalingFactor;
  115. realsize.y *= m_ScalingFactor;
  116. realposition.x *= m_ScalingFactor;
  117. realposition.y *= m_ScalingFactor;
  118. realposition += m_Pos;
  119. return EDA_Rect( m_Pos,realsize );
  120. }
  121. /**********************************************************************/
  122. void MARKER_BASE::DrawMarker( WinEDA_DrawPanel* aPanel, wxDC* aDC, int aDrawMode,
  123. const wxPoint& aOffset )
  124. /**********************************************************************/
  125. /** Function DrawMarker
  126. * The shape is the polygon defined in m_Corners (array of wxPoints)
  127. */
  128. {
  129. wxPoint corners[CORNERS_COUNT];
  130. GRSetDrawMode( aDC, aDrawMode );
  131. for( unsigned ii = 0; ii < m_Corners.size(); ii++ )
  132. {
  133. corners[ii] = m_Corners[ii];
  134. corners[ii].x *= m_ScalingFactor;
  135. corners[ii].y *= m_ScalingFactor;
  136. corners[ii] += m_Pos + aOffset;
  137. }
  138. GRClosedPoly( &aPanel->m_ClipBox, aDC, CORNERS_COUNT, corners,
  139. true, // = Filled
  140. 0, // outline width
  141. m_Color, // outline color
  142. m_Color // fill collor
  143. );
  144. }
  145. /** Function DisplayMarkerInfo()
  146. * Displays the full info of this marker, within an HTML window
  147. */
  148. void MARKER_BASE::DisplayMarkerInfo( WinEDA_DrawFrame* aFrame )
  149. {
  150. wxString msg = m_drc.ShowHtml();
  151. DIALOG_DISPLAY_HTML_TEXT_BASE
  152. infodisplay( (wxWindow*)aFrame, wxID_ANY, _("Marker Info"),
  153. wxGetMousePosition(), wxSize( 550, 140 ) );
  154. infodisplay.m_htmlWindow->SetPage( msg );
  155. infodisplay.ShowModal();
  156. }