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 
32 class SCH_SYMBOL;
33 class MSG_PANEL_ITEM;
34 
35 
36 class SCH_PIN : public SCH_ITEM
37 {
38 public:
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 
57  SCH_SYMBOL* GetParentSymbol() const;
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  void ViewGetLayers( int aLayers[], int& aCount ) const override;
68 
69  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
70  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
71 
72  void Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) override {}
73 
74  void Move( const wxPoint& aMoveVector ) override {}
75 
76  void MirrorHorizontally( int aCenter ) override {}
77  void MirrorVertically( int aCenter ) override {}
78  void Rotate( const wxPoint& aCenter ) override {}
79 
80  wxPoint GetPosition() const override { return GetTransformedPosition(); }
81  const wxPoint GetLocalPosition() const { return m_position; }
82  void SetPosition( const wxPoint& aPosition ) override { m_position = aPosition; }
83 
84  const EDA_RECT GetBoundingBox() const override;
85  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
86 
87  EDA_ITEM* Clone() const override;
88 
89  bool IsConnectable() const override { return true; }
90 
91  bool IsDangling() const override
92  {
94  return false;
95 
96  return m_isDangling;
97  }
98 
99  void SetIsDangling( bool isDangling ) { m_isDangling = isDangling; }
100 
101  bool IsPointClickableAnchor( const wxPoint& aPos ) const override
102  {
103  return m_isDangling && GetPosition() == aPos;
104  }
105 
107  wxPoint GetTransformedPosition() const;
108 
109  bool Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const override;
110 
111  bool Replace( const wxFindReplaceData& aSearchData, void* aAuxData ) override;
112 
113  /*
114  * While many of these are currently simply covers for the equivalent LIB_PIN methods,
115  * the new Eeschema file format will soon allow us to override them at the schematic level.
116  */
117  bool IsVisible() const { return m_libPin->IsVisible(); }
118 
119  wxString GetName() const;
120  wxString GetShownName() const;
121 
122  wxString GetNumber() const { return m_number; }
123  wxString GetShownNumber() const;
124 
125  void SetNumber( const wxString& aNumber ) { m_number = aNumber; }
126 
127  ELECTRICAL_PINTYPE GetType() const;
128 
130  {
132  }
133 
134  GRAPHIC_PINSHAPE GetShape() const;
135 
136  int GetOrientation() const;
137 
138  int GetLength() const;
139 
140  bool IsPowerConnection() const { return m_libPin->IsPowerConnection(); }
141 
142  bool ConnectionPropagatesTo( const EDA_ITEM* aItem ) const override;
143 
144 
145 #if defined(DEBUG)
146  void Show( int nestLevel, std::ostream& os ) const override {}
147 #endif
148 
149 private:
151 
152  wxString m_number;
153  wxString m_alt;
154  wxPoint m_position;
156 
158  std::recursive_mutex m_netmap_mutex;
159  std::map<const SCH_SHEET_PATH, std::pair<wxString, bool>> m_net_name_map;
160 };
161 
162 #endif
LIB_PIN * GetLibPin() const
Definition: sch_pin.h:59
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: sch_pin.cpp:181
void Move(const wxPoint &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_pin.h:74
bool Replace(const wxFindReplaceData &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:162
bool IsConnectable() const override
Definition: sch_pin.h:89
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition: sch_pin.cpp:315
SCH_SYMBOL * GetParentSymbol() const
Definition: sch_pin.cpp:175
const wxPoint GetLocalPosition() const
Definition: sch_pin.h:81
int GetLength() const
Definition: sch_pin.cpp:137
void Print(const RENDER_SETTINGS *aSettings, const wxPoint &aOffset) override
Print a schematic item.
Definition: sch_pin.h:72
bool IsVisible() const
Definition: sch_pin.h:117
void SetIsDangling(bool isDangling)
Definition: sch_pin.h:99
void ClearDefaultNetName(const SCH_SHEET_PATH *aPath)
Definition: sch_pin.cpp:243
wxString GetAlt() const
Definition: sch_pin.h:64
void Rotate(const wxPoint &aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_pin.h:78
wxString GetDefaultNetName(const SCH_SHEET_PATH &aPath, bool aForceNoConnect=false)
Definition: sch_pin.cpp:254
wxString GetNumber() const
Definition: sch_pin.h:122
GRAPHIC_PINSHAPE
Definition: pin_type.h:55
The base class for create windows for drawing purpose.
bool IsDangling() const override
Definition: sch_pin.h:91
wxPoint GetPosition() const override
Definition: sch_pin.h:80
bool IsPointClickableAnchor(const wxPoint &aPos) const override
Definition: sch_pin.h:101
wxString GetShownName() const
Definition: sch_pin.cpp:90
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:188
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_pin.h:76
not internally connected (may be connected to anything)
bool m_isDangling
Definition: sch_pin.h:155
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_pin.h:47
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:189
wxString GetShownNumber() const
Definition: sch_pin.cpp:104
int GetOrientation() const
Definition: sch_pin.cpp:131
bool Matches(const wxFindReplaceData &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: sch_pin.cpp:152
bool IsVisible() const
Definition: lib_pin.h:97
GRAPHIC_PINSHAPE GetShape() const
Definition: sch_pin.cpp:122
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
std::recursive_mutex m_netmap_mutex
The name that this pin connection will drive onto a net.
Definition: sch_pin.h:158
SCH_PIN & operator=(const SCH_PIN &aPin)
Definition: sch_pin.cpp:67
void SetPosition(const wxPoint &aPosition) override
Definition: sch_pin.h:82
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_pin.h:77
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_pin.cpp:327
wxString m_number
Definition: sch_pin.h:152
void SetNumber(const wxString &aNumber)
Definition: sch_pin.h:125
EDA_UNITS
Definition: eda_units.h:38
wxString GetClass() const override
Return the class name.
Definition: sch_pin.h:52
wxString GetCanonicalElectricalTypeName() const
Definition: sch_pin.h:129
Schematic symbol object.
Definition: sch_symbol.h:78
wxString m_alt
Definition: sch_pin.h:153
ELECTRICAL_PINTYPE
The symbol library pin object electrical types used in ERC tests.
Definition: pin_type.h:35
std::map< const SCH_SHEET_PATH, std::pair< wxString, bool > > m_net_name_map
Definition: sch_pin.h:159
ELECTRICAL_PINTYPE GetType() const
Definition: sch_pin.cpp:113
SCH_PIN(LIB_PIN *aLibPin, SCH_SYMBOL *aParentSymbol)
Definition: sch_pin.cpp:31
void SetAlt(const wxString &aAlt)
Definition: sch_pin.h:65
Handle the component boundary box.
Definition: eda_rect.h:42
bool ConnectionPropagatesTo(const EDA_ITEM *aItem) const override
Return true if this item should propagate connection info to aItem.
Definition: sch_pin.cpp:333
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
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:143
bool IsPowerConnection() const
Definition: sch_pin.h:140
EDA_MSG_PANEL items for displaying messages.
Definition: msgpanel.h:53
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_pin.cpp:301
wxString const GetCanonicalElectricalTypeName() const
Definition: lib_pin.h:87
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
not connected (must be left open)
LIB_PIN * m_libPin
Definition: sch_pin.h:150
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:182
wxString GetName() const
Definition: sch_pin.cpp:81
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112
wxPoint GetTransformedPosition() const
Definition: sch_pin.cpp:294
wxPoint m_position
Definition: sch_pin.h:154