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.

221 lines
6.9 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2024 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_SHEEET_PIN_H
  25. #define SCH_SHEEET_PIN_H
  26. #include <sch_label.h>
  27. class KIID;
  28. class LINE_READER;
  29. class SCH_SHEET;
  30. /**
  31. * Define the edge of the sheet that the sheet pin is positioned.
  32. *
  33. * SHEET_LEFT_SIDE = 0: pin on left side
  34. * SHEET_RIGHT_SIDE = 1: pin on right side
  35. * SHEET_TOP_SIDE = 2: pin on top side
  36. * SHEET_BOTTOM_SIDE =3: pin on bottom side
  37. *
  38. * For compatibility reasons, this does not follow same values as text orientation.
  39. */
  40. enum class SHEET_SIDE
  41. {
  42. LEFT = 0,
  43. RIGHT,
  44. TOP,
  45. BOTTOM,
  46. UNDEFINED
  47. };
  48. /**
  49. * Define a sheet pin (label) used in sheets to create hierarchical schematics.
  50. *
  51. * A SCH_SHEET_PIN is used to create a hierarchical sheet in the same way a
  52. * pin is used in a symbol. It connects the objects in the sheet object
  53. * to the objects in the schematic page to the objects in the page that is
  54. * represented by the sheet. In a sheet object, a SCH_SHEET_PIN must be
  55. * connected to a wire, bus, or label. In the schematic page represented by
  56. * the sheet, it corresponds to a hierarchical label.
  57. */
  58. class SCH_SHEET_PIN : public SCH_HIERLABEL
  59. {
  60. public:
  61. SCH_SHEET_PIN( SCH_SHEET* parent, const VECTOR2I& pos = VECTOR2I( 0, 0 ),
  62. const wxString& text = wxEmptyString );
  63. // Do not create a copy constructor. The one generated by the compiler is adequate.
  64. ~SCH_SHEET_PIN() { }
  65. static inline bool ClassOf( const EDA_ITEM* aItem )
  66. {
  67. return aItem && SCH_SHEET_PIN_T == aItem->Type();
  68. }
  69. wxString GetClass() const override
  70. {
  71. return wxT( "SCH_SHEET_PIN" );
  72. }
  73. bool operator ==( const SCH_SHEET_PIN* aPin ) const;
  74. bool operator!=( const SCH_SHEET_PIN* aRhs ) const { return !( this == aRhs ); }
  75. static SHEET_SIDE GetOppositeSide( SHEET_SIDE aSide )
  76. {
  77. switch( aSide )
  78. {
  79. case SHEET_SIDE::TOP: return SHEET_SIDE::BOTTOM;
  80. case SHEET_SIDE::BOTTOM: return SHEET_SIDE::TOP;
  81. case SHEET_SIDE::LEFT: return SHEET_SIDE::RIGHT;
  82. case SHEET_SIDE::RIGHT: return SHEET_SIDE::LEFT;
  83. default: return SHEET_SIDE::UNDEFINED;
  84. }
  85. }
  86. /**
  87. * Return true for items which are moved with the anchor point at mouse cursor
  88. * and false for items moved with no reference to anchor (usually large items).
  89. *
  90. * @return true for a hierarchical sheet pin.
  91. */
  92. bool IsMovableFromAnchorPoint() const override { return true; }
  93. void Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
  94. const VECTOR2I& aOffset, bool aForceNoFill, bool aDimmed ) override;
  95. /**
  96. * Calculate the graphic shape (a polygon) associated to the text.
  97. *
  98. * @param aPoints is a buffer to fill with polygon corners coordinates.
  99. * @param aPos is the position of the shape.
  100. */
  101. void CreateGraphicShape( const RENDER_SETTINGS* aSettings, std::vector<VECTOR2I>& aPoints,
  102. const VECTOR2I& aPos ) const override;
  103. void SwapData( SCH_ITEM* aItem ) override;
  104. int GetPenWidth() const override;
  105. /**
  106. * Get the sheet label number.
  107. *
  108. * @return Number of the sheet label.
  109. */
  110. int GetNumber() const { return m_number; }
  111. /**
  112. * Set the sheet label number.
  113. *
  114. * @param aNumber New sheet number label.
  115. */
  116. void SetNumber( int aNumber );
  117. void SetSide( SHEET_SIDE aEdge );
  118. SHEET_SIDE GetSide() const;
  119. /**
  120. * Adjust label position to edge based on proximity to vertical or horizontal edge
  121. * of the parent sheet.
  122. */
  123. void ConstrainOnEdge( VECTOR2I aPos, bool aAllowEdgeSwitch );
  124. /**
  125. * Get the parent sheet object of this sheet pin.
  126. *
  127. * @return The sheet that is the parent of this sheet pin or NULL if it does
  128. * not have a parent.
  129. */
  130. SCH_SHEET* GetParent() const { return (SCH_SHEET*) m_parent; }
  131. #if defined(DEBUG)
  132. void Show( int nestLevel, std::ostream& os ) const override;
  133. #endif
  134. // Geometric transforms (used in block operations):
  135. void Move( const VECTOR2I& aMoveVector ) override
  136. {
  137. Offset( aMoveVector );
  138. }
  139. void MirrorVertically( int aCenter ) override;
  140. void MirrorHorizontally( int aCenter ) override;
  141. void Rotate( const VECTOR2I& aCenter, bool aRotateCCW ) override;
  142. bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override
  143. {
  144. return SCH_ITEM::Matches( GetText(), aSearchData );
  145. }
  146. bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData = nullptr ) override
  147. {
  148. return EDA_TEXT::Replace( aSearchData );
  149. }
  150. bool IsReplaceable() const override { return true; }
  151. void GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList ) override;
  152. bool IsConnectable() const override { return true; }
  153. bool HasConnectivityChanges( const SCH_ITEM* aItem,
  154. const SCH_SHEET_PATH* aInstance = nullptr ) const override;
  155. wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override;
  156. BITMAPS GetMenuImage() const override;
  157. void SetPosition( const VECTOR2I& aPosition ) override
  158. {
  159. ConstrainOnEdge( aPosition, true );
  160. }
  161. bool IsPointClickableAnchor( const VECTOR2I& aPos ) const override
  162. {
  163. return m_isDangling && GetPosition() == aPos;
  164. }
  165. bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
  166. EDA_ITEM* Clone() const override;
  167. double Similarity( const SCH_ITEM& aOther ) const override;
  168. bool operator==( const SCH_ITEM& aOther ) const override;
  169. private:
  170. int m_number; ///< Label number use for saving sheet label to file.
  171. ///< Sheet label numbering begins at 2.
  172. ///< 0 is reserved for the sheet name.
  173. ///< 1 is reserve for the sheet file name.
  174. SHEET_SIDE m_edge;
  175. };
  176. #endif // SCH_SHEEET_PIN_H