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.

165 lines
5.6 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_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_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 IsType( const std::vector<KICAD_T>& aScanTypes ) const override;
  49. void SetPosition( const VECTOR2I& aPos ) override { setPosition( aPos ); }
  50. VECTOR2I GetPosition() const override { return getPosition(); }
  51. VECTOR2I GetCenter() const override { return getCenter(); }
  52. bool HasLineStroke() const override { return true; }
  53. STROKE_PARAMS GetStroke() const override { return m_stroke; }
  54. void SetStroke( const STROKE_PARAMS& aStroke ) override { m_stroke = aStroke; }
  55. /**
  56. * Return 4 corners for a rectangle or rotated rectangle (stored as a poly). Unimplemented
  57. * for other shapes.
  58. */
  59. std::vector<VECTOR2I> GetCorners() const;
  60. /**
  61. * Allows items to return their visual center rather than their anchor. For some shapes this
  62. * is similar to GetCenter(), but for unfilled shapes a point on the outline is better.
  63. */
  64. const VECTOR2I GetFocusPosition() const override;
  65. /**
  66. * Return the parent footprint or NULL if PCB_SHAPE does not belong to a footprint.
  67. *
  68. * @return the parent footprint or NULL.
  69. */
  70. FOOTPRINT* GetParentFootprint() const;
  71. /**
  72. * Make a set of SHAPE objects representing the PCB_SHAPE. Caller owns the objects.
  73. */
  74. std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
  75. FLASHING aFlash = FLASHING::DEFAULT ) const override;
  76. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  77. const BOX2I GetBoundingBox() const override { return getBoundingBox(); }
  78. bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override
  79. {
  80. return hitTest( aPosition, aAccuracy );
  81. }
  82. bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override
  83. {
  84. return hitTest( aRect, aContained, aAccuracy );
  85. }
  86. void NormalizeRect();
  87. virtual void Move( const VECTOR2I& aMoveVector ) override;
  88. virtual void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override;
  89. virtual void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) override;
  90. void Scale( double aScale );
  91. /**
  92. * Convert the shape to a closed polygon.
  93. *
  94. * Used in filling zones calculations. Circles and arcs are approximated by segments.
  95. *
  96. * @param aCornerBuffer is a buffer to store the polygon.
  97. * @param aClearanceValue is the clearance around the pad.
  98. * @param aError is the maximum deviation from a true arc.
  99. * @param aErrorLoc whether any approximation error should be placed inside or outside
  100. * @param ignoreLineWidth is used for edge cut items where the line width is only
  101. * for visualization
  102. */
  103. void TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
  104. PCB_LAYER_ID aLayer, int aClearanceValue,
  105. int aError, ERROR_LOC aErrorLoc,
  106. bool ignoreLineWidth = false ) const override;
  107. virtual wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
  108. virtual BITMAPS GetMenuImage() const override;
  109. virtual EDA_ITEM* Clone() const override;
  110. virtual const BOX2I ViewBBox() const override;
  111. ///< @copydoc VIEW_ITEM::ViewGetLOD
  112. double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
  113. virtual void SwapData( BOARD_ITEM* aImage ) override;
  114. struct cmp_drawings
  115. {
  116. bool operator()( const BOARD_ITEM* aFirst, const BOARD_ITEM* aSecond ) const;
  117. };
  118. #if defined(DEBUG)
  119. void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
  120. #endif
  121. protected:
  122. EDA_ANGLE getParentOrientation() const override;
  123. VECTOR2I getParentPosition() const override;
  124. };
  125. #endif // PCB_SHAPE_H