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 <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 
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 #include <widgets/msgpanel.h>
29 
30 #include <mutex>
31 #include <map>
32 
33 class SCH_SYMBOL;
34 
35 class SCH_PIN : public SCH_ITEM
36 {
37 public:
38  SCH_PIN( LIB_PIN* aLibPin, SCH_SYMBOL* aParentSymbol );
39 
40  SCH_PIN( SCH_SYMBOL* aParentSymbol, const wxString& aNumber, const wxString& aAlt );
41 
42  SCH_PIN( const SCH_PIN& aPin );
43 
44  SCH_PIN& operator=( const SCH_PIN& aPin );
45 
46  static inline bool ClassOf( const EDA_ITEM* aItem )
47  {
48  return aItem && SCH_PIN_T == aItem->Type();
49  }
50 
51  wxString GetClass() const override
52  {
53  return wxT( "SCH_PIN" );
54  }
55 
56  SCH_SYMBOL* GetParentSymbol() const;
57 
58  LIB_PIN* GetLibPin() const { return m_libPin; }
59 
60  void ClearDefaultNetName( const SCH_SHEET_PATH* aPath );
61  wxString GetDefaultNetName( const SCH_SHEET_PATH& aPath, bool aForceNoConnect = false );
62 
63  wxString GetAlt() const { return m_alt; }
64  void SetAlt( const wxString& aAlt ) { m_alt = aAlt; }
65 
66  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
67  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, MSG_PANEL_ITEMS& aList ) override;
68 
69  void Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) override {}
70 
71  void Move( const wxPoint& aMoveVector ) override {}
72 
73  void MirrorHorizontally( int aCenter ) override {}
74  void MirrorVertically( int aCenter ) override {}
75  void Rotate( const wxPoint& aCenter ) override {}
76 
77  wxPoint GetPosition() const override { return GetTransformedPosition(); }
78  const wxPoint GetLocalPosition() const { return m_position; }
79  void SetPosition( const wxPoint& aPosition ) override { m_position = aPosition; }
80 
81  const EDA_RECT GetBoundingBox() const override;
82  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
83 
84  bool IsDangling() const override { return m_isDangling; }
85  void SetIsDangling( bool isDangling ) { m_isDangling = isDangling; }
86 
87  bool IsPointClickableAnchor( const wxPoint& aPos ) const override
88  {
89  return m_isDangling && GetPosition() == aPos;
90  }
91 
93  wxPoint GetTransformedPosition() const;
94 
95  bool Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const override;
96 
97  bool Replace( const wxFindReplaceData& aSearchData, void* aAuxData ) override;
98 
99  /*
100  * While many of these are currently simply covers for the equivalent LIB_PIN methods,
101  * the new Eeschema file format will soon allow us to override them at the schematic level.
102  */
103  bool IsVisible() const { return m_libPin->IsVisible(); }
104 
105  wxString GetName() const;
106  wxString GetShownName() const;
107 
108  wxString GetNumber() const { return m_number; }
109  wxString GetShownNumber() const;
110 
111  void SetNumber( const wxString& aNumber ) { m_number = aNumber; }
112 
113  ELECTRICAL_PINTYPE GetType() const;
114 
116  {
118  }
119 
120  GRAPHIC_PINSHAPE GetShape() const;
121 
122  int GetOrientation() const;
123 
124  int GetLength() const;
125 
126  bool IsPowerConnection() const { return m_libPin->IsPowerConnection(); }
127 
128  bool ConnectionPropagatesTo( const EDA_ITEM* aItem ) const override;
129 
130 
131 #if defined(DEBUG)
132  void Show( int nestLevel, std::ostream& os ) const override {}
133 #endif
134 
135 private:
137 
138  wxString m_number;
139  wxString m_alt;
140  wxPoint m_position;
142 
144  std::recursive_mutex m_netmap_mutex;
145  std::map<const SCH_SHEET_PATH, std::pair<wxString, bool>> m_net_name_map;
146 };
147 
148 #endif
LIB_PIN * GetLibPin() const
Definition: sch_pin.h:58
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:170
void Move(const wxPoint &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_pin.h:71
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:151
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 contained within or on the bounding box of an item.
Definition: sch_pin.cpp:318
SCH_SYMBOL * GetParentSymbol() const
Definition: sch_pin.cpp:164
const wxPoint GetLocalPosition() const
Definition: sch_pin.h:78
int GetLength() const
Definition: sch_pin.cpp:135
void Print(const RENDER_SETTINGS *aSettings, const wxPoint &aOffset) override
Print a schematic item.
Definition: sch_pin.h:69
bool IsVisible() const
Definition: sch_pin.h:103
void SetIsDangling(bool isDangling)
Definition: sch_pin.h:85
void ClearDefaultNetName(const SCH_SHEET_PATH *aPath)
Definition: sch_pin.cpp:246
wxString GetAlt() const
Definition: sch_pin.h:63
void Rotate(const wxPoint &aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_pin.h:75
wxString GetDefaultNetName(const SCH_SHEET_PATH &aPath, bool aForceNoConnect=false)
Definition: sch_pin.cpp:257
wxString GetNumber() const
Definition: sch_pin.h:108
GRAPHIC_PINSHAPE
Definition: pin_type.h:55
The base class for create windows for drawing purpose.
bool IsDangling() const override
Definition: sch_pin.h:84
wxPoint GetPosition() const override
Definition: sch_pin.h:77
bool IsPointClickableAnchor(const wxPoint &aPos) const override
Definition: sch_pin.h:87
wxString GetShownName() const
Definition: sch_pin.cpp:88
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:186
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_pin.h:73
bool m_isDangling
Definition: sch_pin.h:141
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_pin.h:46
wxString GetShownNumber() const
Definition: sch_pin.cpp:102
int GetOrientation() const
Definition: sch_pin.cpp:129
bool Matches(const wxFindReplaceData &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: sch_pin.cpp:141
bool IsVisible() const
Definition: lib_pin.h:97
GRAPHIC_PINSHAPE GetShape() const
Definition: sch_pin.cpp:120
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:144
SCH_PIN & operator=(const SCH_PIN &aPin)
Definition: sch_pin.cpp:65
void SetPosition(const wxPoint &aPosition) override
Definition: sch_pin.h:79
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_pin.h:74
wxString m_number
Definition: sch_pin.h:138
void SetNumber(const wxString &aNumber)
Definition: sch_pin.h:111
EDA_UNITS
Definition: eda_units.h:38
wxString GetClass() const override
Return the class name.
Definition: sch_pin.h:51
wxString GetCanonicalElectricalTypeName() const
Definition: sch_pin.h:115
Schematic symbol object.
Definition: sch_symbol.h:78
wxString m_alt
Definition: sch_pin.h:139
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:145
ELECTRICAL_PINTYPE GetType() const
Definition: sch_pin.cpp:111
SCH_PIN(LIB_PIN *aLibPin, SCH_SYMBOL *aParentSymbol)
Definition: sch_pin.cpp:29
void SetAlt(const wxString &aAlt)
Definition: sch_pin.h:64
Handle the component boundary box.
Definition: eda_rect.h:42
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, MSG_PANEL_ITEMS &aList) override
Definition: sch_pin.cpp:178
bool ConnectionPropagatesTo(const EDA_ITEM *aItem) const override
Return true if this item should propagate connection info to aItem.
Definition: sch_pin.cpp:329
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:97
bool IsPowerConnection() const
Definition: sch_pin.h:126
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_pin.cpp:304
wxString const GetCanonicalElectricalTypeName() const
Definition: lib_pin.h:87
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
Message panel definition file.
LIB_PIN * m_libPin
Definition: sch_pin.h:136
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:197
wxString GetName() const
Definition: sch_pin.cpp:79
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113
wxPoint GetTransformedPosition() const
Definition: sch_pin.cpp:297
wxPoint m_position
Definition: sch_pin.h:140