KiCad PCB EDA Suite
sch_pin.cpp
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 change_log.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 #include <lib_pin.h>
23 #include <sch_symbol.h>
24 #include <sch_pin.h>
25 #include <sch_sheet_path.h>
26 #include <sch_edit_frame.h>
27 
28 
29 SCH_PIN::SCH_PIN( LIB_PIN* aLibPin, SCH_COMPONENT* aParentSymbol ) :
30  SCH_ITEM( aParentSymbol, SCH_PIN_T )
31 {
32  m_alt = wxEmptyString;
33  m_number = aLibPin->GetNumber();
34  m_libPin = aLibPin;
35  SetPosition( aLibPin->GetPosition() );
36  m_isDangling = true;
37 }
38 
39 
44 SCH_PIN::SCH_PIN( SCH_COMPONENT* aParentSymbol, const wxString& aNumber, const wxString& aAlt ) :
45  SCH_ITEM( aParentSymbol, SCH_PIN_T )
46 {
47  m_alt = aAlt;
48  m_number = aNumber;
49  m_libPin = nullptr;
50  m_isDangling = true;
51 }
52 
53 
54 SCH_PIN::SCH_PIN( const SCH_PIN& aPin ) :
55  SCH_ITEM( aPin )
56 {
57  m_alt = aPin.m_alt;
58  m_number = aPin.m_number;
59  m_libPin = aPin.m_libPin;
60  m_position = aPin.m_position;
62 }
63 
64 
66 {
67  SCH_ITEM::operator=( aPin );
68 
69  m_alt = aPin.m_alt;
70  m_number = aPin.m_number;
71  m_libPin = aPin.m_libPin;
72  m_position = aPin.m_position;
74 
75  return *this;
76 }
77 
78 
79 wxString SCH_PIN::GetName() const
80 {
81  if( !m_alt.IsEmpty() )
82  return m_alt;
83 
84  return m_libPin->GetName();
85 }
86 
87 
89 {
90  if( !m_alt.IsEmpty() )
91  return m_libPin->GetAlt( m_alt ).m_Type;
92 
93  return m_libPin->GetType();
94 }
95 
96 
98 {
99  if( !m_alt.IsEmpty() )
100  return m_libPin->GetAlt( m_alt ).m_Shape;
101 
102  return m_libPin->GetShape();
103 }
104 
105 
107 {
108  return m_libPin->GetOrientation();
109 }
110 
111 
113 {
114  return m_libPin->GetLength();
115 }
116 
117 
118 bool SCH_PIN::Matches( const wxFindReplaceData& aSearchData, void* aAuxDat ) const
119 {
120  if( !( aSearchData.GetFlags() & FR_SEARCH_ALL_PINS ) )
121  return false;
122 
123  return EDA_ITEM::Matches( GetName(), aSearchData )
124  || EDA_ITEM::Matches( GetNumber(), aSearchData );
125 }
126 
127 
128 bool SCH_PIN::Replace( const wxFindReplaceData& aSearchData, void* aAuxData )
129 {
130  bool isReplaced = false;
131 
132  /* TODO: waiting on a way to override pins in the schematic...
133  isReplaced |= EDA_ITEM::Replace( aSearchData, m_name );
134  isReplaced |= EDA_ITEM::Replace( aSearchData, m_number );
135  */
136 
137  return isReplaced;
138 }
139 
140 
142 {
143  return static_cast<SCH_COMPONENT*>( GetParent() );
144 }
145 
146 
147 wxString SCH_PIN::GetSelectMenuText( EDA_UNITS aUnits ) const
148 {
149  return wxString::Format( "%s %s",
150  GetParentSymbol()->GetSelectMenuText( aUnits ),
151  m_libPin->GetSelectMenuText( aUnits ) );
152 }
153 
154 
156 {
157  wxString msg;
158 
159  aList.push_back( MSG_PANEL_ITEM( _( "Type" ), _( "Pin" ) ) );
160 
161  if( m_libPin->GetUnit() == 0 )
162  msg = _( "All" );
163  else
164  msg.Printf( wxT( "%d" ), m_libPin->GetUnit() );
165 
166  aList.push_back( MSG_PANEL_ITEM( _( "Unit" ), msg ) );
167 
168  if( m_libPin->GetConvert() == LIB_ITEM::LIB_CONVERT::BASE )
169  msg = _( "no" );
170  else if( m_libPin->GetConvert() == LIB_ITEM::LIB_CONVERT::DEMORGAN )
171  msg = _( "yes" );
172  else
173  msg = wxT( "?" );
174 
175  aList.push_back( MSG_PANEL_ITEM( _( "Converted" ), msg ) );
176 
177  aList.push_back( MSG_PANEL_ITEM( _( "Name" ), GetName() ) );
178  msg = GetNumber().IsEmpty() ? wxT( "?" ) : GetNumber();
179  aList.push_back( MSG_PANEL_ITEM( _( "Number" ), msg ) );
180  aList.push_back( MSG_PANEL_ITEM( _( "Type" ), ElectricalPinTypeGetText( GetType() ) ) );
181 
182  msg = PinShapeGetText( GetShape() );
183  aList.push_back( MSG_PANEL_ITEM( _( "Style" ), msg ) );
184 
185  msg = IsVisible() ? _( "Yes" ) : _( "No" );
186  aList.push_back( MSG_PANEL_ITEM( _( "Visible" ), msg ) );
187 
188  // Display pin length
189  msg = StringFromValue( aFrame->GetUserUnits(), GetLength() );
190  aList.push_back( MSG_PANEL_ITEM( _( "Length" ), msg ) );
191 
192  msg = PinOrientationName( (unsigned) PinOrientationIndex( GetOrientation() ) );
193  aList.push_back( MSG_PANEL_ITEM( _( "Orientation" ), msg ) );
194 
195  msg = MessageTextFromValue( aFrame->GetUserUnits(), m_position.x );
196  aList.emplace_back( _( "Pos X" ), msg );
197 
198  msg = MessageTextFromValue( aFrame->GetUserUnits(), m_position.y );
199  aList.emplace_back( _( "Pos Y" ), msg );
200 
201  SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( aFrame );
202  SCH_SHEET_PATH* currentSheet = schframe ? &schframe->GetCurrentSheet() : nullptr;
203  SCH_COMPONENT* symbol = GetParentSymbol();
204 
205  aList.emplace_back( symbol->GetRef( currentSheet ), symbol->GetValue( currentSheet, true ) );
206 
207 #if defined(DEBUG)
208 
209  SCH_EDIT_FRAME* frame = dynamic_cast<SCH_EDIT_FRAME*>( aFrame );
210 
211  if( !frame )
212  return;
213 
214  SCH_CONNECTION* conn = Connection();
215 
216  if( conn )
217  conn->AppendInfoToMsgPanel( aList );
218 
219 #endif
220 
221 }
222 
223 
225 {
226  std::lock_guard<std::recursive_mutex> lock( m_netmap_mutex );
227 
228  if( aPath )
229  m_net_name_map.erase( *aPath );
230  else
231  m_net_name_map.clear();
232 }
233 
234 
235 wxString SCH_PIN::GetDefaultNetName( const SCH_SHEET_PATH& aPath, bool aForceNoConnect )
236 {
237  if( m_libPin->IsPowerConnection() )
238  return m_libPin->GetName();
239 
240  std::lock_guard<std::recursive_mutex> lock( m_netmap_mutex );
241 
242  auto it = m_net_name_map.find( aPath );
243 
244  if( it != m_net_name_map.end() )
245  {
246  if( it->second.second == aForceNoConnect )
247  return it->second.first;
248  }
249 
250  wxString name = "Net-(";
251 
252  if( aForceNoConnect || GetType() == ELECTRICAL_PINTYPE::PT_NC )
253  name = ( "unconnected-(" );
254 
255  name << GetParentSymbol()->GetRef( &aPath );
256 
257  bool annotated = true;
258 
259  // Add timestamp for uninitialized symbols
260  if( name.Last() == '?' )
261  {
263  annotated = false;
264  }
265 
266  name << "-Pad" << m_libPin->GetNumber() << ")";
267 
268  if( annotated )
269  m_net_name_map[ aPath ] = std::make_pair( name, aForceNoConnect );
270 
271  return name;
272 }
273 
274 
276 {
279 }
280 
281 
283 {
286 
287  r.RevertYAxis();
288 
289  r = t.TransformCoordinate( r );
291 
292  return r;
293 }
294 
295 
296 bool SCH_PIN::HitTest( const wxPoint& aPosition, int aAccuracy ) const
297 {
298  EDA_RECT rect = GetBoundingBox();
299  return rect.Inflate( aAccuracy ).Contains( aPosition );
300 }
301 
302 
303 bool SCH_PIN::ConnectionPropagatesTo( const EDA_ITEM* aItem ) const
304 {
305  // Reciprocal checking is done in CONNECTION_GRAPH anyway
306  return !( m_libPin->GetType() == ELECTRICAL_PINTYPE::PT_NC );
307 }
void Offset(int dx, int dy)
Definition: eda_rect.h:152
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: lib_pin.cpp:1155
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:147
wxString MessageTextFromValue(EDA_UNITS aUnits, int aValue, bool aAddUnitLabel, EDA_DATA_TYPE aType)
Convert a value to a string using double notation.
Definition: base_units.cpp:125
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:128
virtual bool Matches(const wxFindReplaceData &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:414
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:296
const wxPoint GetLocalPosition() const
Definition: sch_pin.h:90
int GetLength() const
Definition: sch_pin.cpp:112
int GetOrientation() const
Definition: lib_pin.h:125
bool IsVisible() const
Definition: sch_pin.h:112
SCH_COMPONENT * GetParentSymbol() const
Definition: sch_pin.cpp:141
void ClearDefaultNetName(const SCH_SHEET_PATH *aPath)
Definition: sch_pin.cpp:224
wxString ElectricalPinTypeGetText(ELECTRICAL_PINTYPE aType)
Definition: pin_type.cpp:235
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:128
wxString GetDefaultNetName(const SCH_SHEET_PATH &aPath, bool aForceNoConnect=false)
Definition: sch_pin.cpp:235
int PinOrientationIndex(int code)
Definition: pin_type.cpp:145
wxString AsString() const
Definition: kiid.cpp:213
Schematic editor (Eeschema) main window.
wxString GetNumber() const
Definition: sch_pin.h:116
wxString PinShapeGetText(GRAPHIC_PINSHAPE aShape)
Definition: pin_type.cpp:255
ALT GetAlt(const wxString &aAlt)
Definition: lib_pin.h:182
const EDA_RECT GetBoundingBox() const override
Definition: lib_pin.h:222
GRAPHIC_PINSHAPE
Definition: pin_type.h:54
The base class for create windows for drawing purpose.
void RevertYAxis()
Mirror the rectangle from the X axis (negate Y pos and size).
Definition: eda_rect.h:203
wxPoint GetPosition() const override
Definition: sch_pin.h:89
ELECTRICAL_PINTYPE m_Type
Definition: lib_pin.h:62
bool Contains(const wxPoint &aPoint) const
Definition: eda_rect.cpp:57
wxPoint TransformCoordinate(const wxPoint &aPoint) const
Calculate a new coordinate according to the mirror/rotation transform.
Definition: transform.cpp:42
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:234
SCH_PIN(LIB_PIN *aLibPin, SCH_COMPONENT *aParentSymbol)
Definition: sch_pin.cpp:29
SCH_CONNECTION * Connection(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve the connection associated with this object in the given sheet.
Definition: sch_item.cpp:131
wxString PinOrientationName(unsigned aPinOrientationCode)
Definition: pin_type.cpp:114
int GetUnit() const
Definition: lib_item.h:262
bool m_isDangling
Definition: sch_pin.h:42
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
const wxString GetValue(const SCH_SHEET_PATH *sheet, bool aResolve) const
Definition: sch_symbol.cpp:587
const wxString & GetName() const
Definition: lib_pin.h:156
EDA_ITEM * GetParent() const
Definition: eda_item.h:164
int GetOrientation() const
Definition: sch_pin.cpp:106
bool Matches(const wxFindReplaceData &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: sch_pin.cpp:118
GRAPHIC_PINSHAPE GetShape() const
Definition: sch_pin.cpp:97
TRANSFORM & GetTransform()
Definition: sch_symbol.h:273
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
int GetConvert() const
Definition: lib_item.h:265
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Assign the members of aItem to another object.
Definition: eda_item.cpp:193
std::recursive_mutex m_netmap_mutex
The name that this pin connection will drive onto a net.
Definition: sch_pin.h:45
SCH_PIN & operator=(const SCH_PIN &aPin)
Definition: sch_pin.cpp:65
void SetPosition(const wxPoint &aPosition) override
Definition: sch_pin.h:91
const KIID m_Uuid
Definition: eda_item.h:524
wxPoint GetPosition() const override
Definition: lib_pin.h:258
wxString m_number
Definition: sch_pin.h:39
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
EDA_UNITS
Definition: eda_units.h:38
const wxString & GetNumber() const
Definition: lib_pin.h:165
ELECTRICAL_PINTYPE GetType() const
Definition: lib_pin.h:134
void AppendInfoToMsgPanel(MSG_PANEL_ITEMS &aList) const
Adds information about the connection object to aList.
const char * name
Definition: DXF_plotter.cpp:59
wxString m_alt
Definition: sch_pin.h:40
ELECTRICAL_PINTYPE
The component library pin object electrical types used in ERC tests.
Definition: pin_type.h:34
std::map< const SCH_SHEET_PATH, std::pair< wxString, bool > > m_net_name_map
Definition: sch_pin.h:46
int GetLength() const
Definition: lib_pin.h:131
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
#define _(s)
Definition: 3d_actions.cpp:33
ELECTRICAL_PINTYPE GetType() const
Definition: sch_pin.cpp:88
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:155
Schematic symbol object.
Definition: sch_symbol.h:79
bool ConnectionPropagatesTo(const EDA_ITEM *aItem) const override
Returns true if this item should propagate connection info to aItem.
Definition: sch_pin.cpp:303
wxPoint GetPosition() const override
Definition: sch_symbol.h:666
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:149
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:97
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, EDA_DATA_TYPE aType)
Convert a value to a string using double notation.
Definition: base_units.cpp:225
SCH_SHEET_PATH & GetCurrentSheet() const
EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:54
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_pin.cpp:282
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:37
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:196
GRAPHIC_PINSHAPE m_Shape
Definition: lib_pin.h:61
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
wxString GetName() const
Definition: sch_pin.cpp:79
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Inflate the rectangle horizontally by dx and vertically by dy.
Definition: eda_rect.cpp:363
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.
Definition: sch_symbol.cpp:426
wxPoint GetTransformedPosition() const
Returns the pin's position in global coordinates.
Definition: sch_pin.cpp:275
wxPoint m_position
Definition: sch_pin.h:41