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 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_component.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( wxFindReplaceData& aSearchData, void* aAuxDat )
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( 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  aList.push_back( MSG_PANEL_ITEM( _( "Number" ), msg ) );
179  aList.push_back( MSG_PANEL_ITEM( _( "Type" ), ElectricalPinTypeGetText( GetType() ) ) );
180 
181  msg = PinShapeGetText( GetShape() );
182  aList.push_back( MSG_PANEL_ITEM( _( "Style" ), msg ) );
183 
184  msg = IsVisible() ? _( "Yes" ) : _( "No" );
185  aList.push_back( MSG_PANEL_ITEM( _( "Visible" ), msg ) );
186 
187  // Display pin length
188  msg = StringFromValue( aFrame->GetUserUnits(), GetLength() );
189  aList.push_back( MSG_PANEL_ITEM( _( "Length" ), msg ) );
190 
191  msg = PinOrientationName( (unsigned) PinOrientationIndex( GetOrientation() ) );
192  aList.push_back( MSG_PANEL_ITEM( _( "Orientation" ), msg ) );
193 
194  msg = MessageTextFromValue( aFrame->GetUserUnits(), m_position.x );
195  aList.emplace_back( _( "Pos X" ), msg );
196 
197  msg = MessageTextFromValue( aFrame->GetUserUnits(), m_position.y );
198  aList.emplace_back( _( "Pos Y" ), msg );
199 
200  SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( aFrame );
201  SCH_SHEET_PATH* currentSheet = schframe ? &schframe->GetCurrentSheet() : nullptr;
202  SCH_COMPONENT* symbol = GetParentSymbol();
203 
204  aList.emplace_back( symbol->GetRef( currentSheet ), symbol->GetValue( currentSheet, true ) );
205 
206 #if defined(DEBUG)
207 
208  SCH_EDIT_FRAME* frame = dynamic_cast<SCH_EDIT_FRAME*>( aFrame );
209 
210  if( !frame )
211  return;
212 
213  SCH_CONNECTION* conn = Connection();
214 
215  if( conn )
216  conn->AppendInfoToMsgPanel( aList );
217 
218 #endif
219 
220 }
221 
222 
224 {
225  std::lock_guard<std::recursive_mutex> lock( m_netmap_mutex );
226 
227  if( aPath )
228  m_net_name_map.erase( *aPath );
229  else
230  m_net_name_map.clear();
231 }
232 
233 
235 {
236  if( m_libPin->IsPowerConnection() )
237  return m_libPin->GetName();
238 
239  std::lock_guard<std::recursive_mutex> lock( m_netmap_mutex );
240 
241  if( m_net_name_map.count( aPath ) > 0 )
242  return m_net_name_map.at( aPath );
243 
244  wxString name = "Net-(";
245 
246  name << GetParentSymbol()->GetRef( &aPath );
247 
248  bool annotated = true;
249 
250  // Add timestamp for uninitialized symbols
251  if( name.Last() == '?' )
252  {
254  annotated = false;
255  }
256 
257  name << "-Pad" << m_libPin->GetNumber() << ")";
258 
259  if( annotated )
260  m_net_name_map[ aPath ] = name;
261 
262  return name;
263 }
264 
265 
267 {
270 }
271 
272 
274 {
277 
278  r.RevertYAxis();
279 
280  r = t.TransformCoordinate( r );
282 
283  return r;
284 }
285 
286 
287 bool SCH_PIN::HitTest( const wxPoint& aPosition, int aAccuracy ) const
288 {
289  EDA_RECT rect = GetBoundingBox();
290  return rect.Inflate( aAccuracy ).Contains( aPosition );
291 }
292 
293 
294 bool SCH_PIN::ConnectionPropagatesTo( const EDA_ITEM* aItem ) const
295 {
296  // Reciprocal checking is done in CONNECTION_GRAPH anyway
297  return !( m_libPin->GetType() == ELECTRICAL_PINTYPE::PT_NC );
298 }
void Offset(int dx, int dy)
Definition: eda_rect.h:157
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: lib_pin.cpp:1135
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: sch_pin.cpp:147
wxString MessageTextFromValue(EDA_UNITS aUnits, int aValue, bool aAddUnitLabel, EDA_DATA_TYPE aType)
Definition: base_units.cpp:123
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
Definition: sch_pin.cpp:287
wxString GetDefaultNetName(const SCH_SHEET_PATH &aPath)
Definition: sch_pin.cpp:234
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:223
wxString ElectricalPinTypeGetText(ELECTRICAL_PINTYPE aType)
Definition: pin_type.cpp:240
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:128
int PinOrientationIndex(int code)
Definition: pin_type.cpp:150
wxString AsString() const
Definition: kiid.cpp:174
std::map< const SCH_SHEET_PATH, wxString > m_net_name_map
Definition: sch_pin.h:46
Schematic editor (Eeschema) main window.
wxString GetNumber() const
Definition: sch_pin.h:116
wxString PinShapeGetText(GRAPHIC_PINSHAPE aShape)
Definition: pin_type.cpp:260
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:53
The base class for create windows for drawing purpose.
void RevertYAxis()
Function RevertYAxis Mirror the rectangle from the X axis (negate Y pos and size)
Definition: eda_rect.h:209
wxPoint GetPosition() const override
Definition: sch_pin.h:89
ELECTRICAL_PINTYPE m_Type
Definition: lib_pin.h:62
bool Contains(const wxPoint &aPoint) const
Function Contains.
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:119
int GetUnit() const
Definition: lib_item.h:296
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
const wxString & GetName() const
Definition: lib_pin.h:156
TRANSFORM & GetTransform() const
EDA_ITEM * GetParent() const
Definition: eda_item.h:183
int GetOrientation() const
Definition: sch_pin.cpp:106
GRAPHIC_PINSHAPE GetShape() const
Definition: sch_pin.cpp:97
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
bool Replace(wxFindReplaceData &aSearchData, void *aAuxData) override
Function Replace performs a text replace using the find and replace criteria in aSearchData on items ...
Definition: sch_pin.cpp:128
int GetConvert() const
Definition: lib_item.h:299
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Operator assignment is used to 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:151
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)
Function Format outputs 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
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
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, MSG_PANEL_ITEMS &aList) override
Definition: sch_pin.cpp:155
Schematic symbol object.
Definition: sch_component.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:294
wxPoint GetPosition() const override
EDA_ITEM is a base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:148
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)
Function StringFromValue returns the string from aValue according to units (inch, mm ....
Definition: base_units.cpp:220
SCH_SHEET_PATH & GetCurrentSheet() const
bool Matches(wxFindReplaceData &aSearchData, void *aAuxData) override
Function Matches compares the item against the search criteria in aSearchData.
Definition: sch_pin.cpp:118
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
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_pin.cpp:273
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
virtual bool Matches(wxFindReplaceData &aSearchData, void *aAuxData)
Function Matches compares the item against the search criteria in aSearchData.
Definition: eda_item.h:446
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:194
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)
Function Inflate inflates 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.
wxPoint GetTransformedPosition() const
Returns the pin's position in global coordinates.
Definition: sch_pin.cpp:266
wxPoint m_position
Definition: sch_pin.h:41