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.

168 lines
5.7 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 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. #ifndef SCH_SHAPE_H
  25. #define SCH_SHAPE_H
  26. #include <sch_item.h>
  27. #include <eda_shape.h>
  28. #include <schematic.h>
  29. class SCH_SHAPE : public SCH_ITEM, public EDA_SHAPE
  30. {
  31. public:
  32. SCH_SHAPE( SHAPE_T aShape = SHAPE_T::UNDEFINED, SCH_LAYER_ID aLayer = LAYER_NOTES,
  33. int aLineWidth = 0, FILL_T aFillType = FILL_T::NO_FILL,
  34. KICAD_T aType = SCH_SHAPE_T );
  35. // Do not create a copy constructor. The one generated by the compiler is adequate.
  36. virtual ~SCH_SHAPE() override {}
  37. wxString GetClass() const override
  38. {
  39. return wxT( "SCH_SHAPE" );
  40. }
  41. bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
  42. bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
  43. bool HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const override;
  44. bool IsEndPoint( const VECTOR2I& aPoint ) const override;
  45. int GetPenWidth() const override { return GetStroke().GetWidth(); }
  46. bool HasLineStroke() const override { return true; }
  47. STROKE_PARAMS GetStroke() const override { return m_stroke; }
  48. void SetStroke( const STROKE_PARAMS& aStroke ) override;
  49. int GetEffectiveWidth() const override;
  50. LINE_STYLE GetEffectiveLineStyle() const
  51. {
  52. if( m_stroke.GetLineStyle() == LINE_STYLE::DEFAULT )
  53. return LINE_STYLE::SOLID;
  54. else
  55. return m_stroke.GetLineStyle();
  56. }
  57. int GetHatchLineWidth() const override
  58. {
  59. return GetEffectiveWidth() / 2;
  60. }
  61. int GetHatchLineSpacing() const override
  62. {
  63. return GetHatchLineWidth() * 40;
  64. }
  65. void SetFilled( bool aFilled ) override;
  66. const BOX2I GetBoundingBox() const override;
  67. VECTOR2I GetPosition() const override { return getPosition(); }
  68. void SetPosition( const VECTOR2I& aPos ) override { setPosition( aPos ); }
  69. VECTOR2I GetCenter() const { return getCenter(); }
  70. void BeginEdit( const VECTOR2I& aStartPoint ) override { beginEdit( aStartPoint ); }
  71. bool ContinueEdit( const VECTOR2I& aPosition ) override { return continueEdit( aPosition ); }
  72. void CalcEdit( const VECTOR2I& aPosition ) override { calcEdit( aPosition ); }
  73. void EndEdit( bool aClosed = false ) override { endEdit(); }
  74. void SetEditState( int aState ) { setEditState( aState ); }
  75. void Move( const VECTOR2I& aOffset ) override;
  76. void Normalize();
  77. void MirrorHorizontally( int aCenter ) override;
  78. void MirrorVertically( int aCenter ) override;
  79. void Rotate( const VECTOR2I& aCenter, bool aRotateCCW ) override;
  80. void AddPoint( const VECTOR2I& aPosition );
  81. /**
  82. * Make a set of SHAPE objects representing the SCH_SHAPE. Caller owns the objects.
  83. *
  84. * @param aEdgeOnly indicates only edges should be generated (even if 0 width), and no fill
  85. * shapes.
  86. */
  87. std::vector<SHAPE*> MakeEffectiveShapes( bool aEdgeOnly = false ) const override
  88. {
  89. return makeEffectiveShapes( aEdgeOnly, true );
  90. }
  91. void Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
  92. int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed ) override;
  93. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  94. wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
  95. BITMAPS GetMenuImage() const override;
  96. EDA_ITEM* Clone() const override;
  97. std::vector<int> ViewGetLayers() const override;
  98. double Similarity( const SCH_ITEM& aOther ) const override;
  99. bool operator==( const SCH_ITEM& aOther ) const override;
  100. #if defined(DEBUG)
  101. void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
  102. #endif
  103. protected:
  104. void swapData( SCH_ITEM* aItem ) override;
  105. void setFilled( bool aFlag ) override
  106. {
  107. m_fill = aFlag ? FILL_T::FILLED_WITH_COLOR : FILL_T::NO_FILL;
  108. }
  109. bool isMoving() const override { return IsMoving(); }
  110. int getMaxError() const override
  111. {
  112. if( SCHEMATIC* schematic = Schematic() )
  113. return schematic->Settings().m_MaxError;
  114. else
  115. return schIUScale.mmToIU( ARC_LOW_DEF_MM );
  116. }
  117. /**
  118. * @copydoc SCH_ITEM::compare()
  119. *
  120. * The circle specific sort order is as follows:
  121. * - Circle horizontal (X) position.
  122. * - Circle vertical (Y) position.
  123. * - Circle radius.
  124. */
  125. int compare( const SCH_ITEM& aOther, int aCompareFlags = 0 ) const override;
  126. };
  127. #endif // SCH_SHAPE_H