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.

138 lines
4.5 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 CHANGELOG.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. #include <eda_rect.h>
  30. class SHAPE_LINE_CHAIN;
  31. namespace KIGFX
  32. {
  33. class RENDER_SETTINGS;
  34. }
  35. using KIGFX::RENDER_SETTINGS;
  36. /*
  37. * Marker are mainly used to show a DRC or ERC error or warning
  38. */
  39. class MARKER_BASE
  40. {
  41. public:
  42. enum TYPEMARKER {
  43. MARKER_UNSPEC,
  44. MARKER_ERC,
  45. MARKER_PCB,
  46. MARKER_SIMUL
  47. };
  48. MARKER_BASE( int aScalingFactor, std::shared_ptr<RC_ITEM> aItem,
  49. TYPEMARKER aType = MARKER_UNSPEC );
  50. virtual ~MARKER_BASE();
  51. /**
  52. * The scaling factor to convert polygonal shape coordinates to internal units.
  53. */
  54. int MarkerScale() const { return m_scalingFactor; }
  55. /**
  56. * Return the shape polygon in internal units in a #SHAPE_LINE_CHAIN the coordinates
  57. * are relatives to the marker position (are not absolute).
  58. *
  59. * @param aPolygon is the #SHAPE_LINE_CHAIN to fill with the shape.
  60. */
  61. void ShapeToPolygon( SHAPE_LINE_CHAIN& aPolygon, int aScale = -1 ) const;
  62. /**
  63. * Print the shape is the polygon defined in m_Corners (array of wxPoints).
  64. */
  65. void PrintMarker( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset );
  66. /**
  67. * @return the position of this marker in internal units.
  68. */
  69. const wxPoint& 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 TYPEMARKER aMarkerType ) { m_markerType = aMarkerType; }
  75. enum TYPEMARKER GetMarkerType() const { return m_markerType; }
  76. bool IsExcluded() const { return m_excluded; }
  77. void SetExcluded( bool aExcluded ) { m_excluded = aExcluded; }
  78. /**
  79. * @return the #RC_ITEM held within this marker so that its interface may be used.
  80. */
  81. std::shared_ptr<RC_ITEM> GetRCItem() const { return m_rcItem; }
  82. /**
  83. * Test if the given wxPoint is within the bounds of this object.
  84. *
  85. * @param aHitPosition is the wxPoint to test (in internal units).
  86. * @return true if a hit, else false.
  87. */
  88. bool HitTestMarker( const wxPoint& aHitPosition, int aAccuracy ) const;
  89. /**
  90. * Return the orthogonal, bounding box of this object for display purposes.
  91. *
  92. * This box should be an enclosing perimeter for visible components of this
  93. * object, and the units should be in the pcb or schematic coordinate system.
  94. * It is OK to overestimate the size by a few counts.
  95. */
  96. EDA_RECT GetBoundingBoxMarker() const;
  97. protected:
  98. virtual KIGFX::COLOR4D getColor() const = 0;
  99. public:
  100. wxPoint m_Pos; ///< position of the marker
  101. protected:
  102. TYPEMARKER m_markerType; // The type of marker (useful to filter markers)
  103. bool m_excluded; // User has excluded this specific error
  104. std::shared_ptr<RC_ITEM> m_rcItem;
  105. int m_scalingFactor; // Scaling factor to convert corners coordinates
  106. // to internal units coordinates
  107. EDA_RECT m_shapeBoundingBox; // Bounding box of the graphic symbol, relative
  108. // to the position of the shape, in marker shape
  109. // units
  110. };
  111. #endif // MARKER_BASE_H