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.

176 lines
6.1 KiB

11 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2018 Jean-Pierre Charras jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2022 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 PCB_SHAPE_H
  25. #define PCB_SHAPE_H
  26. #include <board_connected_item.h>
  27. #include <eda_shape.h>
  28. class LINE_READER;
  29. class EDA_DRAW_FRAME;
  30. class FOOTPRINT;
  31. class MSG_PANEL_ITEM;
  32. class PCB_SHAPE : public BOARD_CONNECTED_ITEM, public EDA_SHAPE
  33. {
  34. public:
  35. PCB_SHAPE( BOARD_ITEM* aParent, KICAD_T aItemType, SHAPE_T aShapeType );
  36. PCB_SHAPE( BOARD_ITEM* aParent = NULL, SHAPE_T aShapeType = SHAPE_T::SEGMENT );
  37. // Do not create a copy constructor & operator=.
  38. // The ones generated by the compiler are adequate.
  39. ~PCB_SHAPE();
  40. static inline bool ClassOf( const EDA_ITEM* aItem )
  41. {
  42. return aItem && PCB_SHAPE_T == aItem->Type();
  43. }
  44. wxString GetClass() const override
  45. {
  46. return wxT( "PCB_SHAPE" );
  47. }
  48. bool IsConnected() const override;
  49. wxString GetFriendlyName() const override { return EDA_SHAPE::GetFriendlyName(); }
  50. bool IsType( const std::vector<KICAD_T>& aScanTypes ) const override;
  51. void SetLayer( PCB_LAYER_ID aLayer ) override;
  52. PCB_LAYER_ID GetLayer() const override { return m_layer; }
  53. void SetPosition( const VECTOR2I& aPos ) override { setPosition( aPos ); }
  54. VECTOR2I GetPosition() const override { return getPosition(); }
  55. VECTOR2I GetCenter() const override { return getCenter(); }
  56. /**
  57. * @return a list of connection points (may be empty): points where this shape can form
  58. * electrical connections to other shapes that are natural "start/end" points.
  59. */
  60. std::vector<VECTOR2I> GetConnectionPoints() const;
  61. bool HasLineStroke() const override { return true; }
  62. STROKE_PARAMS GetStroke() const override { return m_stroke; }
  63. void SetStroke( const STROKE_PARAMS& aStroke ) override { m_stroke = aStroke; }
  64. int GetWidth() const override;
  65. void StyleFromSettings( const BOARD_DESIGN_SETTINGS& settings ) override;
  66. /**
  67. * Return 4 corners for a rectangle or rotated rectangle (stored as a poly). Unimplemented
  68. * for other shapes.
  69. */
  70. virtual std::vector<VECTOR2I> GetCorners() const;
  71. /**
  72. * Allows items to return their visual center rather than their anchor. For some shapes this
  73. * is similar to GetCenter(), but for unfilled shapes a point on the outline is better.
  74. */
  75. const VECTOR2I GetFocusPosition() const override;
  76. /**
  77. * Make a set of SHAPE objects representing the PCB_SHAPE. Caller owns the objects.
  78. */
  79. std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
  80. FLASHING aFlash = FLASHING::DEFAULT ) const override;
  81. bool IsProxyItem() const override { return m_proxyItem; }
  82. void SetIsProxyItem( bool aIsProxy = true ) override;
  83. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  84. const BOX2I GetBoundingBox() const override { return getBoundingBox(); }
  85. bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override
  86. {
  87. return hitTest( aPosition, aAccuracy );
  88. }
  89. bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override
  90. {
  91. return hitTest( aRect, aContained, aAccuracy );
  92. }
  93. void NormalizeRect();
  94. virtual void Move( const VECTOR2I& aMoveVector ) override;
  95. virtual void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override;
  96. virtual void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) override;
  97. virtual void Mirror( const VECTOR2I& aCentre, bool aMirrorAroundXAxis );
  98. void Scale( double aScale );
  99. /**
  100. * Convert the shape to a closed polygon. Circles and arcs are approximated by segments.
  101. *
  102. * @param aBuffer is a buffer to store the polygon.
  103. * @param aClearance is the clearance around the pad.
  104. * @param aError is the maximum deviation from a true arc.
  105. * @param aErrorLoc whether any approximation error should be placed inside or outside
  106. * @param ignoreLineWidth is used for edge cut items where the line width is only for
  107. * visualization
  108. */
  109. void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance,
  110. int aError, ERROR_LOC aErrorLoc,
  111. bool ignoreLineWidth = false ) const override;
  112. virtual wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override;
  113. virtual BITMAPS GetMenuImage() const override;
  114. virtual EDA_ITEM* Clone() const override;
  115. virtual const BOX2I ViewBBox() const override;
  116. virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
  117. ///< @copydoc VIEW_ITEM::ViewGetLOD
  118. double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
  119. #if defined(DEBUG)
  120. void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
  121. #endif
  122. protected:
  123. virtual void swapData( BOARD_ITEM* aImage ) override;
  124. struct cmp_drawings
  125. {
  126. bool operator()( const BOARD_ITEM* aFirst, const BOARD_ITEM* aSecond ) const;
  127. };
  128. };
  129. #endif // PCB_SHAPE_H