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.

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