KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_pin.h
Go to the documentation of this file.
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-2024 KiCad Developers, see AUTHOR.txt for contributors.
6 * @author Jon Evans <[email protected]>
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
22#ifndef _SCH_PIN_CONNECTION_H
23#define _SCH_PIN_CONNECTION_H
24
25#include <lib_pin.h>
26#include <sch_item.h>
27#include <sch_sheet_path.h>
28
29#include <mutex>
30#include <map>
31
32class SCH_SYMBOL;
33class MSG_PANEL_ITEM;
34
35
36class SCH_PIN : public SCH_ITEM
37{
38public:
39 SCH_PIN( LIB_PIN* aLibPin, SCH_SYMBOL* aParentSymbol );
40
41 SCH_PIN( SCH_SYMBOL* aParentSymbol, const wxString& aNumber, const wxString& aAlt );
42
43 SCH_PIN( const SCH_PIN& aPin );
44
45 SCH_PIN& operator=( const SCH_PIN& aPin );
46
47 static inline bool ClassOf( const EDA_ITEM* aItem )
48 {
49 return aItem && SCH_PIN_T == aItem->Type();
50 }
51
52 wxString GetClass() const override
53 {
54 return wxT( "SCH_PIN" );
55 }
56
58
59 LIB_PIN* GetLibPin() const { return m_libPin; }
60
61 void ClearDefaultNetName( const SCH_SHEET_PATH* aPath );
62 wxString GetDefaultNetName( const SCH_SHEET_PATH& aPath, bool aForceNoConnect = false );
63
64 wxString GetAlt() const { return m_alt; }
65 void SetAlt( const wxString& aAlt ) { m_alt = aAlt; }
66
67 const BOX2I ViewBBox() const override;
68
69 void ViewGetLayers( int aLayers[], int& aCount ) const override;
70
71 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override;
72 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
73
74 void Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset ) override {}
75
76 void Move( const VECTOR2I& aMoveVector ) override {}
77
78 void MirrorHorizontally( int aCenter ) override {}
79 void MirrorVertically( int aCenter ) override {}
80 void Rotate( const VECTOR2I& aCenter ) override {}
81
82 VECTOR2I GetPosition() const override { return GetTransformedPosition(); }
83 const VECTOR2I GetLocalPosition() const { return m_position; }
84 void SetPosition( const VECTOR2I& aPosition ) override { m_position = aPosition; }
85
86 /* Cannot use a default parameter here as it will not be compatible with the virtual. */
87 const BOX2I GetBoundingBox() const override { return GetBoundingBox( false, true, false ); }
88
93 const BOX2I GetBoundingBox( bool aIncludeInvisiblePins, bool aIncludeNameAndNumber,
94 bool aIncludeElectricalType ) const;
95
96 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
97 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
98
99 EDA_ITEM* Clone() const override;
100
101 bool IsConnectable() const override { return true; }
102
103 bool HasConnectivityChanges( const SCH_ITEM* aItem,
104 const SCH_SHEET_PATH* aInstance = nullptr ) const override;
105
106 bool IsDangling() const override
107 {
108 if( GetType() == ELECTRICAL_PINTYPE::PT_NC || GetType() == ELECTRICAL_PINTYPE::PT_NIC )
109 return false;
110
111 return m_isDangling;
112 }
113
114 void SetIsDangling( bool isDangling ) { m_isDangling = isDangling; }
115
116 void SetLibPin( LIB_PIN* aLibPin ) { m_libPin = aLibPin; }
117
122 bool IsStacked( const SCH_PIN* aPin ) const;
123
124 bool IsPointClickableAnchor( const VECTOR2I& aPos ) const override
125 {
126 return m_isDangling && GetPosition() == aPos;
127 }
128
131
132 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override;
133
134 bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) override;
135
136 /*
137 * While many of these are currently simply covers for the equivalent LIB_PIN methods,
138 * the new Eeschema file format will soon allow us to override them at the schematic level.
139 */
140 bool IsVisible() const;
141
142 wxString GetName() const;
143 wxString GetShownName() const;
144
145 wxString GetNumber() const { return m_number; }
146 wxString GetShownNumber() const;
147
148 void SetNumber( const wxString& aNumber ) { m_number = aNumber; }
149
151
153 {
155 }
156
158
160
161 int GetLength() const;
162
163 bool IsGlobalPower() const;
164
165 bool ConnectionPropagatesTo( const EDA_ITEM* aItem ) const override;
166
167 const wxString& GetOperatingPoint() const { return m_operatingPoint; }
168 void SetOperatingPoint( const wxString& aText ) { m_operatingPoint = aText; }
169
170 double Similarity( const SCH_ITEM& aItem ) const override;
171
172 bool operator==( const SCH_ITEM& aItem ) const override;
173
174 bool operator!=( const SCH_PIN& aRhs ) const { return !( *this == aRhs ); }
175
176#if defined(DEBUG)
177 void Show( int nestLevel, std::ostream& os ) const override {}
178#endif
179
180private:
182
183 wxString m_number;
184 wxString m_alt;
187
189 std::recursive_mutex m_netmap_mutex;
190 std::map<const SCH_SHEET_PATH, std::pair<wxString, bool>> m_net_name_map;
191
193};
194
195#endif
The base class for create windows for drawing purpose.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
wxString const GetCanonicalElectricalTypeName() const
Definition: lib_pin.h:87
EDA_MSG_PANEL items for displaying messages.
Definition: msgpanel.h:54
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:165
void SetAlt(const wxString &aAlt)
Definition: sch_pin.h:65
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const override
Return a user-visible description string of this item.
Definition: sch_pin.cpp:213
int GetLength() const
Definition: sch_pin.cpp:157
void Print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset) override
Print a schematic item.
Definition: sch_pin.h:74
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: sch_pin.cpp:181
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
Definition: sch_pin.cpp:232
wxString GetAlt() const
Definition: sch_pin.h:64
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition: sch_pin.cpp:165
void SetPosition(const VECTOR2I &aPosition) override
Definition: sch_pin.h:84
void SetNumber(const wxString &aNumber)
Definition: sch_pin.h:148
void Rotate(const VECTOR2I &aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_pin.h:80
bool HasConnectivityChanges(const SCH_ITEM *aItem, const SCH_SHEET_PATH *aInstance=nullptr) const override
Check if aItem has connectivity changes against this object.
Definition: sch_pin.cpp:468
SCH_PIN & operator=(const SCH_PIN &aPin)
Definition: sch_pin.cpp:73
wxString GetShownNumber() const
Definition: sch_pin.cpp:118
std::map< const SCH_SHEET_PATH, std::pair< wxString, bool > > m_net_name_map
Definition: sch_pin.h:190
const wxString & GetOperatingPoint() const
Definition: sch_pin.h:167
bool IsGlobalPower() const
Definition: sch_pin.cpp:297
bool IsVisible() const
Definition: sch_pin.cpp:87
bool ConnectionPropagatesTo(const EDA_ITEM *aItem) const override
Return true if this item should propagate connection info to aItem.
Definition: sch_pin.cpp:490
wxString GetName() const
Definition: sch_pin.cpp:95
bool operator==(const SCH_ITEM &aItem) const override
Definition: sch_pin.cpp:499
void SetLibPin(LIB_PIN *aLibPin)
Definition: sch_pin.h:116
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_pin.h:79
LIB_PIN * GetLibPin() const
Definition: sch_pin.h:59
bool m_isDangling
Definition: sch_pin.h:186
bool IsConnectable() const override
Definition: sch_pin.h:101
void ViewGetLayers(int aLayers[], int &aCount) const override
Return the layers the item is drawn on (which may be more than its "home" layer)
Definition: sch_pin.cpp:171
wxString GetNumber() const
Definition: sch_pin.h:145
bool IsDangling() const override
Definition: sch_pin.h:106
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_pin.h:78
std::recursive_mutex m_netmap_mutex
The name that this pin connection will drive onto a net.
Definition: sch_pin.h:189
PIN_ORIENTATION GetOrientation() const
Definition: sch_pin.cpp:149
wxString GetClass() const override
Return the class name.
Definition: sch_pin.h:52
VECTOR2I GetPosition() const override
Definition: sch_pin.h:82
LIB_PIN * m_libPin
Definition: sch_pin.h:181
wxString GetCanonicalElectricalTypeName() const
Definition: sch_pin.h:152
bool Replace(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) override
Perform a text replace using the find and replace criteria in aSearchData on items that support text ...
Definition: sch_pin.cpp:194
VECTOR2I m_position
Definition: sch_pin.h:185
const VECTOR2I GetLocalPosition() const
Definition: sch_pin.h:83
wxString m_operatingPoint
Definition: sch_pin.h:192
double Similarity(const SCH_ITEM &aItem) const override
Return a measure of how likely the other object is to represent the same object.
Definition: sch_pin.cpp:516
wxString GetShownName() const
Definition: sch_pin.cpp:104
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_pin.h:76
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_pin.h:47
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition: sch_pin.cpp:436
wxString m_alt
Definition: sch_pin.h:184
void SetOperatingPoint(const wxString &aText)
Definition: sch_pin.h:168
VECTOR2I GetTransformedPosition() const
Definition: sch_pin.cpp:407
void ClearDefaultNetName(const SCH_SHEET_PATH *aPath)
Definition: sch_pin.cpp:304
void SetIsDangling(bool isDangling)
Definition: sch_pin.h:114
bool IsPointClickableAnchor(const VECTOR2I &aPos) const override
Definition: sch_pin.h:124
bool IsStacked(const SCH_PIN *aPin) const
Definition: sch_pin.cpp:287
wxString m_number
Definition: sch_pin.h:183
SCH_SYMBOL * GetParentSymbol() const
Definition: sch_pin.cpp:207
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_pin.cpp:462
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_pin.h:87
wxString GetDefaultNetName(const SCH_SHEET_PATH &aPath, bool aForceNoConnect=false)
Definition: sch_pin.cpp:315
bool operator!=(const SCH_PIN &aRhs) const
Definition: sch_pin.h:174
GRAPHIC_PINSHAPE GetShape() const
Definition: sch_pin.cpp:138
ELECTRICAL_PINTYPE GetType() const
Definition: sch_pin.cpp:127
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Schematic symbol object.
Definition: sch_symbol.h:109
ELECTRICAL_PINTYPE
The symbol library pin object electrical types used in ERC tests.
Definition: pin_type.h:36
PIN_ORIENTATION
The symbol library pin object orientations.
Definition: pin_type.h:75
GRAPHIC_PINSHAPE
Definition: pin_type.h:56
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
@ SCH_PIN_T
Definition: typeinfo.h:163