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.

143 lines
4.9 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
  5. * Copyright (C) 2004-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 LIB_SHAPE_H
  25. #define LIB_SHAPE_H
  26. #include <lib_item.h>
  27. #include <eda_shape.h>
  28. class LIB_SHAPE : public LIB_ITEM, public EDA_SHAPE
  29. {
  30. public:
  31. LIB_SHAPE( LIB_SYMBOL* aParent, SHAPE_T aShape, int aLineWidth = 0,
  32. FILL_T aFillType = FILL_T::NO_FILL, KICAD_T aType = LIB_SHAPE_T );
  33. // Do not create a copy constructor. The one generated by the compiler is adequate.
  34. ~LIB_SHAPE() { }
  35. wxString GetClass() const override
  36. {
  37. return wxT( "LIB_SHAPE" );
  38. }
  39. static inline bool ClassOf( const EDA_ITEM* aItem )
  40. {
  41. return aItem && aItem->Type() == LIB_SHAPE_T;
  42. }
  43. wxString GetTypeName() const override
  44. {
  45. return ShowShape();
  46. }
  47. STROKE_PARAMS GetStroke() const { return m_stroke; }
  48. void SetStroke( const STROKE_PARAMS& aStroke ) { m_stroke = aStroke; }
  49. bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
  50. bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
  51. int GetPenWidth() const override;
  52. LINE_STYLE GetEffectiveLineStyle() const
  53. {
  54. if( m_stroke.GetLineStyle() == LINE_STYLE::DEFAULT )
  55. return LINE_STYLE::SOLID;
  56. else
  57. return m_stroke.GetLineStyle();
  58. }
  59. const BOX2I GetBoundingBox() const override;
  60. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  61. void BeginEdit( const VECTOR2I& aStartPoint ) override { beginEdit( aStartPoint ); }
  62. bool ContinueEdit( const VECTOR2I& aPosition ) override { return continueEdit( aPosition ); }
  63. void CalcEdit( const VECTOR2I& aPosition ) override { calcEdit( aPosition ); }
  64. void EndEdit( bool aClosed = false ) override { endEdit( aClosed ); }
  65. void SetEditState( int aState ) { setEditState( aState ); }
  66. void AddPoint( const VECTOR2I& aPosition );
  67. void Offset( const VECTOR2I& aOffset ) override;
  68. void MoveTo( const VECTOR2I& aPosition ) override;
  69. VECTOR2I GetPosition() const override { return getPosition(); }
  70. void SetPosition( const VECTOR2I& aPosition ) override { setPosition( aPosition ); }
  71. VECTOR2I GetCenter() const { return getCenter(); }
  72. /**
  73. * Make a set of SHAPE objects representing the LIB_SHAPE. Caller owns the objects.
  74. *
  75. * @param aEdgeOnly indicates only edges should be generated (even if 0 width), and no fill
  76. * shapes.
  77. */
  78. virtual std::vector<SHAPE*> MakeEffectiveShapes( bool aEdgeOnly = false ) const override
  79. {
  80. return makeEffectiveShapes( aEdgeOnly, true );
  81. }
  82. void Normalize();
  83. void MirrorHorizontal( const VECTOR2I& aCenter ) override;
  84. void MirrorVertical( const VECTOR2I& aCenter ) override;
  85. void Rotate( const VECTOR2I& aCenter, bool aRotateCCW = true ) override;
  86. void Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOffset,
  87. const TRANSFORM& aTransform, bool aDimmed ) const override;
  88. wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override;
  89. BITMAPS GetMenuImage() const override;
  90. EDA_ITEM* Clone() const override;
  91. void ViewGetLayers( int aLayers[], int& aCount ) const override;
  92. double Similarity( const LIB_ITEM& aOther ) const override;
  93. bool operator==( const LIB_ITEM& aOther ) const override;
  94. private:
  95. /**
  96. * @copydoc LIB_ITEM::compare()
  97. *
  98. * The circle specific sort order is as follows:
  99. * - Circle horizontal (X) position.
  100. * - Circle vertical (Y) position.
  101. * - Circle radius.
  102. */
  103. int compare( const LIB_ITEM& aOther, int aCompareFlags = 0 ) const override;
  104. void print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, void* aData,
  105. const TRANSFORM& aTransform, bool aDimmed ) override;
  106. };
  107. #endif // LIB_SHAPE_H