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.

156 lines
5.1 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2009-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright The KiCad Developers, see AUTHORS.TXT for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #ifndef MARKER_BASE_H
  25. #define MARKER_BASE_H
  26. #include <memory>
  27. #include <rc_item.h>
  28. #include <gr_basic.h>
  29. class SHAPE_LINE_CHAIN;
  30. namespace KIGFX
  31. {
  32. class RENDER_SETTINGS;
  33. }
  34. using KIGFX::RENDER_SETTINGS;
  35. /**
  36. * Marker are mainly used to show a DRC or ERC error or warning.
  37. */
  38. class MARKER_BASE
  39. {
  40. public:
  41. enum MARKER_T
  42. {
  43. MARKER_UNSPEC,
  44. MARKER_ERC,
  45. MARKER_DRC,
  46. MARKER_DRAWING_SHEET,
  47. MARKER_RATSNEST,
  48. MARKER_PARITY,
  49. MARKER_SIMUL
  50. };
  51. MARKER_BASE( int aScalingFactor, std::shared_ptr<RC_ITEM> aItem,
  52. MARKER_T aType = MARKER_UNSPEC );
  53. virtual ~MARKER_BASE() {};
  54. /**
  55. * The scaling factor to convert polygonal shape coordinates to internal units.
  56. */
  57. int MarkerScale() const { return m_scalingFactor; }
  58. void SetMarkerScale( int aScale ) { m_scalingFactor = aScale; }
  59. /**
  60. * Return the shape polygon in internal units in a #SHAPE_LINE_CHAIN the coordinates
  61. * are relatives to the marker position (are not absolute).
  62. *
  63. * @param aPolygon is the #SHAPE_LINE_CHAIN to fill with the shape.
  64. */
  65. void ShapeToPolygon( SHAPE_LINE_CHAIN& aPolygon, int aScale = -1 ) const;
  66. /**
  67. * @return the position of this marker in internal units.
  68. */
  69. const VECTOR2I& GetPos() const { return m_Pos; }
  70. virtual const KIID GetUUID() const = 0;
  71. /**
  72. * Accessors to set/get marker type (DRC, ERC, or other)
  73. */
  74. void SetMarkerType( enum MARKER_T aMarkerType ) { m_markerType = aMarkerType; }
  75. enum MARKER_T GetMarkerType() const { return m_markerType; }
  76. bool IsExcluded() const { return m_excluded; }
  77. void SetExcluded( bool aExcluded, const wxString& aComment = wxEmptyString )
  78. {
  79. m_excluded = aExcluded;
  80. m_comment = aComment;
  81. }
  82. wxString GetComment() const { return m_comment; }
  83. virtual SEVERITY GetSeverity() const { return RPT_SEVERITY_UNDEFINED; }
  84. /**
  85. * @return the #RC_ITEM held within this marker so that its interface may be used.
  86. */
  87. std::shared_ptr<RC_ITEM> GetRCItem() const { return m_rcItem; }
  88. /**
  89. * Test if the given #VECTOR2I is within the bounds of this object.
  90. *
  91. * @param aHitPosition is the #VECTOR2I to test (in internal units).
  92. * @return true if a hit, else false.
  93. */
  94. bool HitTestMarker( const VECTOR2I& aHitPosition, int aAccuracy ) const;
  95. /**
  96. * Test if the given #BOX2I intersects or contains the bounds of this object.
  97. */
  98. bool HitTestMarker( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const;
  99. /**
  100. * Test if the given #SHAPE_LINE_CHAIN intersects or contains the bounds of this object.
  101. */
  102. bool HitTestMarker( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const;
  103. /**
  104. * Return the orthogonal, bounding box of this object for display purposes.
  105. *
  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. BOX2I GetBoundingBoxMarker() const;
  111. protected:
  112. virtual KIGFX::COLOR4D getColor() const = 0;
  113. public:
  114. VECTOR2I m_Pos; ///< Position of the marker.
  115. protected:
  116. MARKER_T m_markerType; ///< The type of marker.
  117. bool m_excluded; ///< User has excluded this specific error.
  118. wxString m_comment; ///< User supplied comment.
  119. std::shared_ptr<RC_ITEM> m_rcItem;
  120. int m_scalingFactor; ///< Scaling factor to convert corners coordinates
  121. ///< to internal units coordinates.
  122. BOX2I m_shapeBoundingBox; ///< Bounding box of the graphic symbol relative
  123. ///< to the position of the shape in marker shape
  124. ///< units.
  125. };
  126. #endif // MARKER_BASE_H