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.

144 lines
4.7 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 (C) 2009-2020 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. * Print the shape is the polygon defined in m_Corners (array of VECTOR2Is).
  68. */
  69. void PrintMarker( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset );
  70. /**
  71. * @return the position of this marker in internal units.
  72. */
  73. const VECTOR2I& GetPos() const { return m_Pos; }
  74. virtual const KIID GetUUID() const = 0;
  75. /**
  76. * Accessors to set/get marker type (DRC, ERC, or other)
  77. */
  78. void SetMarkerType( enum MARKER_T aMarkerType ) { m_markerType = aMarkerType; }
  79. enum MARKER_T GetMarkerType() const { return m_markerType; }
  80. bool IsExcluded() const { return m_excluded; }
  81. void SetExcluded( bool aExcluded ) { m_excluded = aExcluded; }
  82. virtual SEVERITY GetSeverity() const { return RPT_SEVERITY_UNDEFINED; }
  83. /**
  84. * @return the #RC_ITEM held within this marker so that its interface may be used.
  85. */
  86. std::shared_ptr<RC_ITEM> GetRCItem() const { return m_rcItem; }
  87. /**
  88. * Test if the given VECTOR2I is within the bounds of this object.
  89. *
  90. * @param aHitPosition is the VECTOR2I to test (in internal units).
  91. * @return true if a hit, else false.
  92. */
  93. bool HitTestMarker( const VECTOR2I& aHitPosition, int aAccuracy ) const;
  94. /**
  95. * Return the orthogonal, bounding box of this object for display purposes.
  96. *
  97. * This box should be an enclosing perimeter for visible components of this
  98. * object, and the units should be in the pcb or schematic coordinate system.
  99. * It is OK to overestimate the size by a few counts.
  100. */
  101. BOX2I GetBoundingBoxMarker() const;
  102. protected:
  103. virtual KIGFX::COLOR4D getColor() const = 0;
  104. public:
  105. VECTOR2I m_Pos; ///< position of the marker
  106. protected:
  107. MARKER_T m_markerType; // The type of marker (useful to filter markers)
  108. bool m_excluded; // User has excluded this specific error
  109. std::shared_ptr<RC_ITEM> m_rcItem;
  110. int m_scalingFactor; // Scaling factor to convert corners coordinates
  111. // to internal units coordinates
  112. BOX2I m_shapeBoundingBox; // Bounding box of the graphic symbol, relative
  113. // to the position of the shape, in marker shape
  114. // units
  115. };
  116. #endif // MARKER_BASE_H