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 
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  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
68  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
69 
70  void Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) override {}
71 
72  void Move( const wxPoint& aMoveVector ) override {}
73 
74  void MirrorHorizontally( int aCenter ) override {}
75  void MirrorVertically( int aCenter ) override {}
76  void Rotate( const wxPoint& aCenter ) override {}
77 
78  wxPoint GetPosition() const override { return GetTransformedPosition(); }
79  const wxPoint GetLocalPosition() const { return m_position; }
80  void SetPosition( const wxPoint& aPosition ) override { m_position = aPosition; }
81 
82  const EDA_RECT GetBoundingBox() const override;
83  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
84 
85  bool IsDangling() const override { return m_isDangling; }
86  void SetIsDangling( bool isDangling ) { m_isDangling = isDangling; }
87 
88  bool IsPointClickableAnchor( const wxPoint& aPos ) const override
89  {
90  return m_isDangling && GetPosition() == aPos;
91  }
92 
94  wxPoint GetTransformedPosition() const;
95 
96  bool Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const override;
97 
98  bool Replace( const wxFindReplaceData& aSearchData, void* aAuxData ) override;
99 
100  /*
101  * While many of these are currently simply covers for the equivalent LIB_PIN methods,
102  * the new Eeschema file format will soon allow us to override them at the schematic level.
103  */
104  bool IsVisible() const { return m_libPin->IsVisible(); }
105 
106  wxString GetName() const;
107  wxString GetShownName() const;
108 
109  wxString GetNumber() const { return m_number; }
110  wxString GetShownNumber() const;
111 
112  void SetNumber( const wxString& aNumber ) { m_number = aNumber; }
113 
114  ELECTRICAL_PINTYPE GetType() const;
115 
117  {
119  }
120 
121  GRAPHIC_PINSHAPE GetShape() const;
122 
123  int GetOrientation() const;
124 
125  int GetLength() const;
126 
127  bool IsPowerConnection() const { return m_libPin->IsPowerConnection(); }
128 
129  bool ConnectionPropagatesTo( const EDA_ITEM* aItem ) const override;
130 
131 
132 #if defined(DEBUG)
133  void Show( int nestLevel, std::ostream& os ) const override {}
134 #endif
135 
136 private:
138 
139  wxString m_number;
140  wxString m_alt;
141  wxPoint m_position;
143 
145  std::recursive_mutex m_netmap_mutex;
146  std::map<const SCH_SHEET_PATH, std::pair<wxString, bool>> m_net_name_map;
147 };
148 
149 #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:172
void Move(const wxPoint &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_pin.h:72
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:153
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:305
SCH_SYMBOL * GetParentSymbol() const
Definition: sch_pin.cpp:166
const wxPoint GetLocalPosition() const
Definition: sch_pin.h:79
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:70
bool IsVisible() const
Definition: sch_pin.h:104
void SetIsDangling(bool isDangling)
Definition: sch_pin.h:86
void ClearDefaultNetName(const SCH_SHEET_PATH *aPath)
Definition: sch_pin.cpp:233
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:76
wxString GetDefaultNetName(const SCH_SHEET_PATH &aPath, bool aForceNoConnect=false)
Definition: sch_pin.cpp:244
wxString GetNumber() const
Definition: sch_pin.h:109
GRAPHIC_PINSHAPE
Definition: pin_type.h:55
The base class for create windows for drawing purpose.
bool IsDangling() const override
Definition: sch_pin.h:85
wxPoint GetPosition() const override
Definition: sch_pin.h:78
bool IsPointClickableAnchor(const wxPoint &aPos) const override
Definition: sch_pin.h:88
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:186
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_pin.h:74
bool m_isDangling
Definition: sch_pin.h:142
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:180
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:143
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:145
SCH_PIN & operator=(const SCH_PIN &aPin)
Definition: sch_pin.cpp:67
void SetPosition(const wxPoint &aPosition) override
Definition: sch_pin.h:80
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_pin.h:75
wxString m_number
Definition: sch_pin.h:139
void SetNumber(const wxString &aNumber)
Definition: sch_pin.h:112
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:116
Schematic symbol object.
Definition: sch_symbol.h:78
wxString m_alt
Definition: sch_pin.h:140
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:146
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:317
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
bool IsPowerConnection() const
Definition: sch_pin.h:127
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:291
wxString const GetCanonicalElectricalTypeName() const
Definition: lib_pin.h:87
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
LIB_PIN * m_libPin
Definition: sch_pin.h:137
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:113
wxPoint GetTransformedPosition() const
Definition: sch_pin.cpp:284
wxPoint m_position
Definition: sch_pin.h:141