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.

204 lines
7.1 KiB

  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 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. #pragma once
  25. #include <board_connected_item.h>
  26. #include <eda_shape.h>
  27. class LINE_READER;
  28. class EDA_DRAW_FRAME;
  29. class FOOTPRINT;
  30. class MSG_PANEL_ITEM;
  31. class PCB_SHAPE : public BOARD_CONNECTED_ITEM, public EDA_SHAPE
  32. {
  33. public:
  34. PCB_SHAPE( BOARD_ITEM* aParent, KICAD_T aItemType, SHAPE_T aShapeType );
  35. PCB_SHAPE( BOARD_ITEM* aParent = nullptr, SHAPE_T aShapeType = SHAPE_T::SEGMENT );
  36. // Do not create a copy constructor & operator=.
  37. // The ones generated by the compiler are adequate.
  38. ~PCB_SHAPE() override;
  39. static bool ClassOf( const EDA_ITEM* aItem )
  40. {
  41. return aItem && PCB_SHAPE_T == aItem->Type();
  42. }
  43. wxString GetClass() const override
  44. {
  45. return wxT( "PCB_SHAPE" );
  46. }
  47. void Serialize( google::protobuf::Any &aContainer ) const override;
  48. bool Deserialize( const google::protobuf::Any &aContainer ) override;
  49. bool IsConnected() const override;
  50. wxString GetFriendlyName() const override { return getFriendlyName(); }
  51. bool IsType( const std::vector<KICAD_T>& aScanTypes ) const override;
  52. void SetLayer( PCB_LAYER_ID aLayer ) override;
  53. PCB_LAYER_ID GetLayer() const override { return m_layer; }
  54. bool IsOnLayer( PCB_LAYER_ID aLayer ) const override;
  55. virtual LSET GetLayerSet() const override;
  56. virtual void SetLayerSet( const LSET& aLayers ) override;
  57. void SetPosition( const VECTOR2I& aPos ) override { setPosition( aPos ); }
  58. VECTOR2I GetPosition() const override { return getPosition(); }
  59. VECTOR2I GetCenter() const override { return getCenter(); }
  60. /**
  61. * @return a list of connection points (may be empty): points where this shape can form
  62. * electrical connections to other shapes that are natural "start/end" points.
  63. */
  64. std::vector<VECTOR2I> GetConnectionPoints() const;
  65. bool HasLineStroke() const override { return true; }
  66. STROKE_PARAMS GetStroke() const override { return m_stroke; }
  67. void SetStroke( const STROKE_PARAMS& aStroke ) override { m_stroke = aStroke; }
  68. int GetWidth() const override;
  69. void StyleFromSettings( const BOARD_DESIGN_SETTINGS& settings ) override;
  70. /**
  71. * Return 4 corners for a rectangle or rotated rectangle (stored as a poly). Unimplemented
  72. * for other shapes.
  73. */
  74. virtual std::vector<VECTOR2I> GetCorners() const;
  75. /**
  76. * Allows items to return their visual center rather than their anchor. For some shapes this
  77. * is similar to GetCenter(), but for unfilled shapes a point on the outline is better.
  78. */
  79. const VECTOR2I GetFocusPosition() const override;
  80. /**
  81. * Make a set of SHAPE objects representing the PCB_SHAPE. Caller owns the objects.
  82. */
  83. std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
  84. FLASHING aFlash = FLASHING::DEFAULT ) const override;
  85. bool IsProxyItem() const override { return m_proxyItem; }
  86. void SetIsProxyItem( bool aIsProxy = true ) override;
  87. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  88. const BOX2I GetBoundingBox() const override { return getBoundingBox(); }
  89. bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override
  90. {
  91. return hitTest( aPosition, aAccuracy );
  92. }
  93. bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override
  94. {
  95. return hitTest( aRect, aContained, aAccuracy );
  96. }
  97. void Normalize() override;
  98. /**
  99. * Normalize coordinates to compare 2 similar PCB_SHAPES
  100. * similat to Normalize(), but also normalize SEGMENT end points
  101. * needed only for graphic comparisons
  102. */
  103. void NormalizeForCompare() override;
  104. void Move( const VECTOR2I& aMoveVector ) override;
  105. void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override;
  106. void Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override;
  107. virtual void Mirror( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override;
  108. void Scale( double aScale );
  109. /**
  110. * Convert the shape to a closed polygon. Circles and arcs are approximated by segments.
  111. *
  112. * @param aBuffer is a buffer to store the polygon.
  113. * @param aClearance is the clearance around the pad.
  114. * @param aError is the maximum deviation from a true arc.
  115. * @param aErrorLoc whether any approximation error should be placed inside or outside
  116. * @param ignoreLineWidth is used for edge cut items where the line width is only for
  117. * visualization
  118. */
  119. void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance,
  120. int aError, ERROR_LOC aErrorLoc,
  121. bool ignoreLineWidth = false ) const override;
  122. wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
  123. BITMAPS GetMenuImage() const override;
  124. EDA_ITEM* Clone() const override;
  125. const BOX2I ViewBBox() const override;
  126. std::vector<int> ViewGetLayers() const override;
  127. ///< @copydoc VIEW_ITEM::ViewGetLOD
  128. double ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const override;
  129. double Similarity( const BOARD_ITEM& aBoardItem ) const override;
  130. bool operator==( const PCB_SHAPE& aShape ) const;
  131. bool operator==( const BOARD_ITEM& aBoardItem ) const override;
  132. void SetHasSolderMask( bool aVal ) { m_hasSolderMask = aVal; }
  133. bool HasSolderMask() const { return m_hasSolderMask; }
  134. void SetLocalSolderMaskMargin( std::optional<int> aMargin ) { m_solderMaskMargin = aMargin; }
  135. std::optional<int> GetLocalSolderMaskMargin() const { return m_solderMaskMargin; }
  136. int GetSolderMaskExpansion() const;
  137. #if defined(DEBUG)
  138. void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
  139. #endif
  140. protected:
  141. void swapData( BOARD_ITEM* aImage ) override;
  142. struct cmp_drawings
  143. {
  144. bool operator()( const BOARD_ITEM* aFirst, const BOARD_ITEM* aSecond ) const;
  145. };
  146. bool m_hasSolderMask;
  147. std::optional<int> m_solderMaskMargin;
  148. };