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.

209 lines
6.4 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-2021 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. static SHEET_SIDE GetOppositeSide( SHEET_SIDE aSide )
  75. {
  76. switch( aSide )
  77. {
  78. case SHEET_SIDE::TOP: return SHEET_SIDE::BOTTOM;
  79. case SHEET_SIDE::BOTTOM: return SHEET_SIDE::TOP;
  80. case SHEET_SIDE::LEFT: return SHEET_SIDE::RIGHT;
  81. case SHEET_SIDE::RIGHT: return SHEET_SIDE::LEFT;
  82. default: return SHEET_SIDE::UNDEFINED;
  83. }
  84. }
  85. /**
  86. * Return true for items which are moved with the anchor point at mouse cursor
  87. * and false for items moved with no reference to anchor (usually large items).
  88. *
  89. * @return true for a hierarchical sheet pin.
  90. */
  91. bool IsMovableFromAnchorPoint() const override { return true; }
  92. void Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset ) override;
  93. /**
  94. * Calculate the graphic shape (a polygon) associated to the text.
  95. *
  96. * @param aPoints is a buffer to fill with polygon corners coordinates.
  97. * @param aPos is the position of the shape.
  98. */
  99. void CreateGraphicShape( const RENDER_SETTINGS* aSettings, std::vector<VECTOR2I>& aPoints,
  100. const VECTOR2I& aPos ) const override;
  101. void SwapData( SCH_ITEM* aItem ) override;
  102. int GetPenWidth() const override;
  103. /**
  104. * Get the sheet label number.
  105. *
  106. * @return Number of the sheet label.
  107. */
  108. int GetNumber() const { return m_number; }
  109. /**
  110. * Set the sheet label number.
  111. *
  112. * @param aNumber New sheet number label.
  113. */
  114. void SetNumber( int aNumber );
  115. void SetSide( SHEET_SIDE aEdge );
  116. SHEET_SIDE GetSide() const;
  117. /**
  118. * Adjust label position to edge based on proximity to vertical or horizontal edge
  119. * of the parent sheet.
  120. */
  121. void ConstrainOnEdge( VECTOR2I Pos );
  122. /**
  123. * Get the parent sheet object of this sheet pin.
  124. *
  125. * @return The sheet that is the parent of this sheet pin or NULL if it does
  126. * not have a parent.
  127. */
  128. SCH_SHEET* GetParent() const { return (SCH_SHEET*) m_parent; }
  129. #if defined(DEBUG)
  130. void Show( int nestLevel, std::ostream& os ) const override;
  131. #endif
  132. // Geometric transforms (used in block operations):
  133. void Move( const VECTOR2I& aMoveVector ) override
  134. {
  135. Offset( aMoveVector );
  136. }
  137. void MirrorVertically( int aCenter ) override;
  138. void MirrorHorizontally( int aCenter ) override;
  139. void Rotate( const VECTOR2I& aCenter ) override;
  140. bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override
  141. {
  142. return SCH_ITEM::Matches( GetText(), aSearchData );
  143. }
  144. bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData = nullptr ) override
  145. {
  146. return EDA_TEXT::Replace( aSearchData );
  147. }
  148. bool IsReplaceable() const override { return true; }
  149. void GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList ) override;
  150. bool IsConnectable() const override { return true; }
  151. wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override;
  152. BITMAPS GetMenuImage() const override;
  153. void SetPosition( const VECTOR2I& aPosition ) override { ConstrainOnEdge( aPosition ); }
  154. bool IsPointClickableAnchor( const VECTOR2I& aPos ) const override
  155. {
  156. return m_isDangling && GetPosition() == aPos;
  157. }
  158. bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
  159. EDA_ITEM* Clone() const override;
  160. private:
  161. int m_number; ///< Label number use for saving sheet label to file.
  162. ///< Sheet label numbering begins at 2.
  163. ///< 0 is reserved for the sheet name.
  164. ///< 1 is reserve for the sheet file name.
  165. SHEET_SIDE m_edge;
  166. };
  167. #endif // SCH_SHEEET_PIN_H