KiCad PCB EDA Suite
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-2021 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 GetSelectMenuText( 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 IsDangling() const override
104 {
106 return false;
107
108 return m_isDangling;
109 }
110
111 void SetIsDangling( bool isDangling ) { m_isDangling = isDangling; }
112
117 bool IsStacked( const SCH_PIN* aPin ) const;
118
119 bool IsPointClickableAnchor( const VECTOR2I& aPos ) const override
120 {
121 return m_isDangling && GetPosition() == aPos;
122 }
123
126
127 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override;
128
129 bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) override;
130
131 /*
132 * While many of these are currently simply covers for the equivalent LIB_PIN methods,
133 * the new Eeschema file format will soon allow us to override them at the schematic level.
134 */
135 bool IsVisible() const { return m_libPin->IsVisible(); }
136
137 wxString GetName() const;
138 wxString GetShownName() const;
139
140 wxString GetNumber() const { return m_number; }
141 wxString GetShownNumber() const;
142
143 void SetNumber( const wxString& aNumber ) { m_number = aNumber; }
144
146
148 {
150 }
151
153
154 int GetOrientation() const;
155
156 int GetLength() const;
157
158 bool IsPowerConnection() const { return m_libPin->IsPowerConnection(); }
159
160 bool ConnectionPropagatesTo( const EDA_ITEM* aItem ) const override;
161
162
163#if defined(DEBUG)
164 void Show( int nestLevel, std::ostream& os ) const override {}
165#endif
166
167private:
169
170 wxString m_number;
171 wxString m_alt;
174
176 std::recursive_mutex m_netmap_mutex;
177 std::map<const SCH_SHEET_PATH, std::pair<wxString, bool>> m_net_name_map;
178};
179
180#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:93
bool IsVisible() const
Definition: lib_pin.h:103
bool IsPowerConnection() const
Return whether this pin forms an implicit power connection: i.e., is hidden and of type POWER_IN.
Definition: lib_pin.h:197
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:147
void SetAlt(const wxString &aAlt)
Definition: sch_pin.h:65
int GetLength() const
Definition: sch_pin.cpp:141
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:162
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:202
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:147
void SetPosition(const VECTOR2I &aPosition) override
Definition: sch_pin.h:84
void SetNumber(const wxString &aNumber)
Definition: sch_pin.h:143
void Rotate(const VECTOR2I &aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_pin.h:80
SCH_PIN & operator=(const SCH_PIN &aPin)
Definition: sch_pin.cpp:71
wxString GetShownNumber() const
Definition: sch_pin.cpp:108
std::map< const SCH_SHEET_PATH, std::pair< wxString, bool > > m_net_name_map
Definition: sch_pin.h:177
bool IsVisible() const
Definition: sch_pin.h:135
bool ConnectionPropagatesTo(const EDA_ITEM *aItem) const override
Return true if this item should propagate connection info to aItem.
Definition: sch_pin.cpp:373
wxString GetSelectMenuText(UNITS_PROVIDER *aUnitsProvider) const override
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: sch_pin.cpp:194
wxString GetName() const
Definition: sch_pin.cpp:85
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:173
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:153
wxString GetNumber() const
Definition: sch_pin.h:140
bool IsDangling() const override
Definition: sch_pin.h:103
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:176
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:168
wxString GetCanonicalElectricalTypeName() const
Definition: sch_pin.h:147
SCH_PIN(LIB_PIN *aLibPin, SCH_SYMBOL *aParentSymbol)
Definition: sch_pin.cpp:32
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:175
VECTOR2I m_position
Definition: sch_pin.h:172
const VECTOR2I GetLocalPosition() const
Definition: sch_pin.h:83
bool IsPowerConnection() const
Definition: sch_pin.h:158
wxString GetShownName() const
Definition: sch_pin.cpp:94
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:341
wxString m_alt
Definition: sch_pin.h:171
VECTOR2I GetTransformedPosition() const
Definition: sch_pin.cpp:318
void ClearDefaultNetName(const SCH_SHEET_PATH *aPath)
Definition: sch_pin.cpp:256
void SetIsDangling(bool isDangling)
Definition: sch_pin.h:111
bool IsPointClickableAnchor(const VECTOR2I &aPos) const override
Definition: sch_pin.h:119
bool IsStacked(const SCH_PIN *aPin) const
Definition: sch_pin.cpp:248
wxString m_number
Definition: sch_pin.h:170
SCH_SYMBOL * GetParentSymbol() const
Definition: sch_pin.cpp:188
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_pin.cpp:367
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_pin.h:87
int GetOrientation() const
Definition: sch_pin.cpp:135
wxString GetDefaultNetName(const SCH_SHEET_PATH &aPath, bool aForceNoConnect=false)
Definition: sch_pin.cpp:267
GRAPHIC_PINSHAPE GetShape() const
Definition: sch_pin.cpp:126
ELECTRICAL_PINTYPE GetType() const
Definition: sch_pin.cpp:117
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:80
ELECTRICAL_PINTYPE
The symbol library pin object electrical types used in ERC tests.
Definition: pin_type.h:36
@ PT_NC
not connected (must be left open)
@ PT_NIC
not internally connected (may be connected to anything)
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:159