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.

184 lines
5.8 KiB

7 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2018 CERN
  5. * Copyright (C) 2019-2023 KiCad Developers, see AUTHOR.txt for contributors.
  6. * @author Jon Evans <jon@craftyjon.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #ifndef _SCH_PIN_CONNECTION_H
  22. #define _SCH_PIN_CONNECTION_H
  23. #include <lib_pin.h>
  24. #include <sch_item.h>
  25. #include <sch_sheet_path.h>
  26. #include <mutex>
  27. #include <map>
  28. class SCH_SYMBOL;
  29. class MSG_PANEL_ITEM;
  30. class SCH_PIN : public SCH_ITEM
  31. {
  32. public:
  33. SCH_PIN( LIB_PIN* aLibPin, SCH_SYMBOL* aParentSymbol );
  34. SCH_PIN( SCH_SYMBOL* aParentSymbol, const wxString& aNumber, const wxString& aAlt );
  35. SCH_PIN( const SCH_PIN& aPin );
  36. SCH_PIN& operator=( const SCH_PIN& aPin );
  37. static inline bool ClassOf( const EDA_ITEM* aItem )
  38. {
  39. return aItem && SCH_PIN_T == aItem->Type();
  40. }
  41. wxString GetClass() const override
  42. {
  43. return wxT( "SCH_PIN" );
  44. }
  45. SCH_SYMBOL* GetParentSymbol() const;
  46. LIB_PIN* GetLibPin() const { return m_libPin; }
  47. void ClearDefaultNetName( const SCH_SHEET_PATH* aPath );
  48. wxString GetDefaultNetName( const SCH_SHEET_PATH& aPath, bool aForceNoConnect = false );
  49. wxString GetAlt() const { return m_alt; }
  50. void SetAlt( const wxString& aAlt ) { m_alt = aAlt; }
  51. const BOX2I ViewBBox() const override;
  52. void ViewGetLayers( int aLayers[], int& aCount ) const override;
  53. wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override;
  54. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  55. void Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset ) override {}
  56. void Move( const VECTOR2I& aMoveVector ) override {}
  57. void MirrorHorizontally( int aCenter ) override {}
  58. void MirrorVertically( int aCenter ) override {}
  59. void Rotate( const VECTOR2I& aCenter ) override {}
  60. VECTOR2I GetPosition() const override { return GetTransformedPosition(); }
  61. const VECTOR2I GetLocalPosition() const { return m_position; }
  62. void SetPosition( const VECTOR2I& aPosition ) override { m_position = aPosition; }
  63. /* Cannot use a default parameter here as it will not be compatible with the virtual. */
  64. const BOX2I GetBoundingBox() const override { return GetBoundingBox( false, true, false ); }
  65. /**
  66. * @param aIncludeInvisibles - if false, do not include labels for invisible pins
  67. * in the calculation.
  68. */
  69. const BOX2I GetBoundingBox( bool aIncludeInvisiblePins, bool aIncludeNameAndNumber,
  70. bool aIncludeElectricalType ) const;
  71. bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
  72. bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
  73. EDA_ITEM* Clone() const override;
  74. bool IsConnectable() const override { return true; }
  75. bool IsDangling() const override
  76. {
  77. if( GetType() == ELECTRICAL_PINTYPE::PT_NC || GetType() == ELECTRICAL_PINTYPE::PT_NIC )
  78. return false;
  79. return m_isDangling;
  80. }
  81. void SetIsDangling( bool isDangling ) { m_isDangling = isDangling; }
  82. /**
  83. * @param aPin Comparison Pin
  84. * @return True if aPin is stacked with this pin
  85. */
  86. bool IsStacked( const SCH_PIN* aPin ) const;
  87. bool IsPointClickableAnchor( const VECTOR2I& aPos ) const override
  88. {
  89. return m_isDangling && GetPosition() == aPos;
  90. }
  91. /// @return the pin's position in global coordinates.
  92. VECTOR2I GetTransformedPosition() const;
  93. bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override;
  94. bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) override;
  95. /*
  96. * While many of these are currently simply covers for the equivalent LIB_PIN methods,
  97. * the new Eeschema file format will soon allow us to override them at the schematic level.
  98. */
  99. bool IsVisible() const { return m_libPin->IsVisible(); }
  100. wxString GetName() const;
  101. wxString GetShownName() const;
  102. wxString GetNumber() const { return m_number; }
  103. wxString GetShownNumber() const;
  104. void SetNumber( const wxString& aNumber ) { m_number = aNumber; }
  105. ELECTRICAL_PINTYPE GetType() const;
  106. wxString GetCanonicalElectricalTypeName() const
  107. {
  108. return LIB_PIN::GetCanonicalElectricalTypeName( GetType() );
  109. }
  110. GRAPHIC_PINSHAPE GetShape() const;
  111. int GetOrientation() const;
  112. int GetLength() const;
  113. bool IsPowerConnection() const { return m_libPin->IsPowerConnection(); }
  114. bool ConnectionPropagatesTo( const EDA_ITEM* aItem ) const override;
  115. const wxString& GetOperatingPoint() const { return m_operatingPoint; }
  116. void SetOperatingPoint( const wxString& aText ) { m_operatingPoint = aText; }
  117. #if defined(DEBUG)
  118. void Show( int nestLevel, std::ostream& os ) const override {}
  119. #endif
  120. private:
  121. LIB_PIN* m_libPin;
  122. wxString m_number;
  123. wxString m_alt;
  124. VECTOR2I m_position;
  125. bool m_isDangling;
  126. /// The name that this pin connection will drive onto a net.
  127. std::recursive_mutex m_netmap_mutex;
  128. std::map<const SCH_SHEET_PATH, std::pair<wxString, bool>> m_net_name_map;
  129. wxString m_operatingPoint;
  130. };
  131. #endif