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* aParentComponent ) :
30  SCH_ITEM( aParentComponent, 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 
40 SCH_PIN::SCH_PIN( const SCH_PIN& aPin ) :
41  SCH_ITEM( aPin )
42 {
43  m_alt = aPin.m_alt;
44  m_number = aPin.m_number;
45  m_libPin = aPin.m_libPin;
46  m_position = aPin.m_position;
48 }
49 
50 
52 {
53  SCH_ITEM::operator=( aPin );
54 
55  m_alt = aPin.m_alt;
56  m_number = aPin.m_number;
57  m_libPin = aPin.m_libPin;
58  m_position = aPin.m_position;
60 
61  return *this;
62 }
63 
64 
65 wxString SCH_PIN::GetName() const
66 {
67  if( !m_alt.IsEmpty() )
68  return m_alt;
69 
70  return m_libPin->GetName();
71 }
72 
73 
75 {
76  if( !m_alt.IsEmpty() )
77  return m_libPin->GetAlt( m_alt ).m_Type;
78 
79  return m_libPin->GetType();
80 }
81 
82 
84 {
85  if( !m_alt.IsEmpty() )
86  return m_libPin->GetAlt( m_alt ).m_Shape;
87 
88  return m_libPin->GetShape();
89 }
90 
91 
93 {
94  return m_libPin->GetOrientation();
95 }
96 
97 
98 int SCH_PIN::GetLength() const
99 {
100  return m_libPin->GetLength();
101 }
102 
103 
104 bool SCH_PIN::Matches( wxFindReplaceData& aSearchData, void* aAuxDat )
105 {
106  if( !( aSearchData.GetFlags() & FR_SEARCH_ALL_PINS ) )
107  return false;
108 
109  return EDA_ITEM::Matches( GetName(), aSearchData )
110  || EDA_ITEM::Matches( GetNumber(), aSearchData );
111 }
112 
113 
114 bool SCH_PIN::Replace( wxFindReplaceData& aSearchData, void* aAuxData )
115 {
116  bool isReplaced = false;
117 
118  /* TODO: waiting on a way to override pins in the schematic...
119  isReplaced |= EDA_ITEM::Replace( aSearchData, m_name );
120  isReplaced |= EDA_ITEM::Replace( aSearchData, m_number );
121  */
122 
123  return isReplaced;
124 }
125 
126 
128 {
129  return static_cast<SCH_COMPONENT*>( GetParent() );
130 }
131 
132 
133 wxString SCH_PIN::GetSelectMenuText( EDA_UNITS aUnits ) const
134 {
135  return wxString::Format( "%s %s",
137  m_libPin->GetSelectMenuText( aUnits ) );
138 }
139 
140 
142 {
143  wxString msg;
144 
145  aList.push_back( MSG_PANEL_ITEM( _( "Type" ), _( "Pin" ), CYAN ) );
146 
147  if( m_libPin->GetUnit() == 0 )
148  msg = _( "All" );
149  else
150  msg.Printf( wxT( "%d" ), m_libPin->GetUnit() );
151 
152  aList.push_back( MSG_PANEL_ITEM( _( "Unit" ), msg, BROWN ) );
153 
154  if( m_libPin->GetConvert() == LIB_ITEM::LIB_CONVERT::BASE )
155  msg = _( "no" );
156  else if( m_libPin->GetConvert() == LIB_ITEM::LIB_CONVERT::DEMORGAN )
157  msg = _( "yes" );
158  else
159  msg = wxT( "?" );
160 
161  aList.push_back( MSG_PANEL_ITEM( _( "Converted" ), msg, BROWN ) );
162 
163  aList.push_back( MSG_PANEL_ITEM( _( "Name" ), GetName(), DARKCYAN ) );
164  aList.push_back( MSG_PANEL_ITEM( _( "Number" ), msg, DARKCYAN ) );
165  aList.push_back( MSG_PANEL_ITEM( _( "Type" ), ElectricalPinTypeGetText( GetType() ), RED ) );
166 
167  msg = PinShapeGetText( GetShape() );
168  aList.push_back( MSG_PANEL_ITEM( _( "Style" ), msg, BLUE ) );
169 
170  msg = IsVisible() ? _( "Yes" ) : _( "No" );
171  aList.push_back( MSG_PANEL_ITEM( _( "Visible" ), msg, DARKGREEN ) );
172 
173  // Display pin length
174  msg = StringFromValue( aFrame->GetUserUnits(), GetLength(), true );
175  aList.push_back( MSG_PANEL_ITEM( _( "Length" ), msg, MAGENTA ) );
176 
177  msg = PinOrientationName( (unsigned) PinOrientationIndex( GetOrientation() ) );
178  aList.push_back( MSG_PANEL_ITEM( _( "Orientation" ), msg, DARKMAGENTA ) );
179 
180  msg = MessageTextFromValue( aFrame->GetUserUnits(), m_position.x, true );
181  aList.emplace_back( _( "Pos X" ), msg, DARKMAGENTA );
182 
183  msg = MessageTextFromValue( aFrame->GetUserUnits(), m_position.y, true );
184  aList.emplace_back( _( "Pos Y" ), msg, DARKMAGENTA );
185 
186  SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( aFrame );
187  SCH_SHEET_PATH* currentSheet = schframe ? &schframe->GetCurrentSheet() : nullptr;
189 
190  aList.emplace_back( comp->GetRef( currentSheet ), comp->GetValue( currentSheet ), DARKCYAN );
191 
192 #if defined(DEBUG)
193 
194  SCH_EDIT_FRAME* frame = dynamic_cast<SCH_EDIT_FRAME*>( aFrame );
195 
196  if( !frame )
197  return;
198 
199  SCH_CONNECTION* conn = Connection( frame->GetCurrentSheet() );
200 
201  if( conn )
202  conn->AppendInfoToMsgPanel( aList );
203 
204 #endif
205 
206 }
207 
208 
210 {
211  std::lock_guard<std::recursive_mutex> lock( m_netmap_mutex );
212 
213  if( aPath )
214  m_net_name_map.erase( *aPath );
215  else
216  m_net_name_map.clear();
217 }
218 
219 
221 {
222  if( m_libPin->IsPowerConnection() )
223  return m_libPin->GetName();
224 
225  std::lock_guard<std::recursive_mutex> lock( m_netmap_mutex );
226 
227  if( m_net_name_map.count( aPath ) > 0 )
228  return m_net_name_map.at( aPath );
229 
230  wxString name = "Net-(";
231 
232  name << GetParentComponent()->GetRef( &aPath );
233 
234  bool annotated = true;
235 
236  // Add timestamp for uninitialized components
237  if( name.Last() == '?' )
238  {
240  annotated = false;
241  }
242 
243  name << "-Pad" << m_libPin->GetNumber() << ")";
244 
245  if( annotated )
246  m_net_name_map[ aPath ] = name;
247 
248  return name;
249 }
250 
251 
253 {
256 }
257 
258 
260 {
263 
264  r.RevertYAxis();
265 
266  r = t.TransformCoordinate( r );
268 
269  return r;
270 }
271 
272 
273 bool SCH_PIN::HitTest( const wxPoint& aPosition, int aAccuracy ) const
274 {
275  EDA_RECT rect = GetBoundingBox();
276  return rect.Inflate( aAccuracy ).Contains( aPosition );
277 }
278 
279 
280 bool SCH_PIN::ConnectionPropagatesTo( const EDA_ITEM* aItem ) const
281 {
282  // Reciprocal checking is done in CONNECTION_GRAPH anyway
283  return !( m_libPin->GetType() == ELECTRICAL_PINTYPE::PT_NC );
284 }
EDA_UNITS
Definition: common.h:198
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:1138
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:133
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:273
wxString GetDefaultNetName(const SCH_SHEET_PATH &aPath)
Definition: sch_pin.cpp:220
const wxPoint GetLocalPosition() const
Definition: sch_pin.h:88
int GetLength() const
Definition: sch_pin.cpp:98
int GetOrientation() const
Definition: lib_pin.h:125
bool IsVisible() const
Definition: sch_pin.h:108
void ClearDefaultNetName(const SCH_SHEET_PATH *aPath)
Definition: sch_pin.cpp:209
wxString ElectricalPinTypeGetText(ELECTRICAL_PINTYPE aType)
Definition: pin_type.cpp:239
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:128
Definition: color4d.h:61
int PinOrientationIndex(int code)
Definition: pin_type.cpp:149
wxString AsString() const
Definition: common.cpp:165
std::map< const SCH_SHEET_PATH, wxString > m_net_name_map
Definition: sch_pin.h:46
const wxString GetValue(const SCH_SHEET_PATH *sheet) const
Schematic editor (Eeschema) main window.
wxString GetNumber() const
Definition: sch_pin.h:112
wxString PinShapeGetText(GRAPHIC_PINSHAPE aShape)
Definition: pin_type.cpp:259
ALT GetAlt(const wxString &aAlt)
Definition: lib_pin.h:182
const EDA_RECT GetBoundingBox() const override
Definition: lib_pin.h:218
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:87
ELECTRICAL_PINTYPE m_Type
Definition: lib_pin.h:62
bool Contains(const wxPoint &aPoint) const
Function Contains.
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:230
wxString PinOrientationName(unsigned aPinOrientationCode)
Definition: pin_type.cpp:118
int GetUnit() const
Definition: lib_item.h:295
bool m_isDangling
Definition: sch_pin.h:42
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
const wxString & GetName() const
Definition: lib_pin.h:156
TRANSFORM & GetTransform() const
SCH_PIN(LIB_PIN *aLibPin, SCH_COMPONENT *aParentComponent)
Definition: sch_pin.cpp:29
EDA_ITEM * GetParent() const
Definition: base_struct.h:195
int GetOrientation() const
Definition: sch_pin.cpp:92
Definition: color4d.h:58
GRAPHIC_PINSHAPE GetShape() const
Definition: sch_pin.cpp:83
SCH_SHEET_PATH.
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:114
int GetConvert() const
Definition: lib_item.h:298
Definition: color4d.h:59
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Operator assignment is used to assign the members of aItem to another object.
std::recursive_mutex m_netmap_mutex
The name that this pin connection will drive onto a net.
Definition: sch_pin.h:45
SCH_CONNECTION * Connection(const SCH_SHEET_PATH &aPath) const
Retrieve the connection associated with this object in the given sheet.
Definition: sch_item.cpp:150
SCH_PIN & operator=(const SCH_PIN &aPin)
Definition: sch_pin.cpp:51
void SetPosition(const wxPoint &aPosition) override
Definition: sch_pin.h:89
const KIID m_Uuid
Definition: base_struct.h:162
wxPoint GetPosition() const override
Definition: lib_pin.h:254
wxString m_number
Definition: sch_pin.h:39
wxString MessageTextFromValue(EDA_UNITS aUnits, int aValue, bool aUseMils, EDA_DATA_TYPE aType)
Definition: base_units.cpp:124
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.
Definition: color4d.h:56
const char * name
Definition: DXF_plotter.cpp:60
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:201
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:74
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:141
Schematic symbol object.
Definition: sch_component.h:80
bool ConnectionPropagatesTo(const EDA_ITEM *aItem) const override
Returns true if this item should propagate connection info to aItem.
Definition: sch_pin.cpp:280
wxPoint GetPosition() const override
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
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:104
EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_pin.cpp:259
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
not connected (must be left open)
SCH_COMPONENT * GetParentComponent() const
Definition: sch_pin.cpp:127
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: base_struct.h:458
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
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, bool aUseMils, EDA_DATA_TYPE aType)
Function StringFromValue returns the string from aValue according to units (inch, mm ....
Definition: base_units.cpp:233
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
wxString GetName() const
Definition: sch_pin.cpp:65
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
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:252
wxPoint m_position
Definition: sch_pin.h:41