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 
27 
28 SCH_PIN::SCH_PIN( LIB_PIN* aLibPin, SCH_COMPONENT* aParentComponent ) :
29  SCH_ITEM( aParentComponent, SCH_PIN_T ),
30  m_libPin( aLibPin )
31 {
32  SetPosition( aLibPin->GetPosition() );
33  m_isDangling = true;
34 }
35 
36 
37 SCH_PIN::SCH_PIN( const SCH_PIN& aPin ) :
38  SCH_ITEM( aPin )
39 {
40  m_libPin = aPin.m_libPin;
41  m_position = aPin.m_position;
43 }
44 
45 
47 {
48  SCH_ITEM::operator=( aPin );
49 
50  m_libPin = aPin.m_libPin;
51  m_position = aPin.m_position;
53 
54  return *this;
55 }
56 
57 
58 bool SCH_PIN::Matches( wxFindReplaceData& aSearchData, void* aAuxData )
59 {
60  return m_libPin->Matches( aSearchData, aAuxData );
61 }
62 
63 
65 {
66  return static_cast<SCH_COMPONENT*>( GetParent() );
67 }
68 
69 
70 wxString SCH_PIN::GetSelectMenuText( EDA_UNITS aUnits ) const
71 {
72  return wxString::Format( "%s %s",
74  m_libPin->GetSelectMenuText( aUnits ) );
75 }
76 
77 
79 {
80  m_libPin->GetMsgPanelInfo( aUnits, aList, GetParentComponent() );
81 }
82 
83 
84 wxString SCH_PIN::GetDescription( const SCH_SHEET_PATH* aSheet )
85 {
86  if( GetName().IsEmpty() || GetNumber().IsEmpty() )
87  {
88  return wxString::Format( _( "Pin %s of component %s." ),
89  GetName().IsEmpty() ? GetNumber() : GetName(),
90  GetParentComponent()->GetRef( aSheet ) );
91  }
92  else
93  {
94  return wxString::Format( _( "Pin %s (%s) of component %s." ),
95  GetName(),
96  GetNumber(),
97  GetParentComponent()->GetRef( aSheet ) );
98  }
99 }
100 
101 
103 {
104  if( m_libPin->IsPowerConnection() )
105  return m_libPin->GetName();
106 
107  std::lock_guard<std::mutex> lock( m_netmap_mutex );
108 
109  if( m_net_name_map.count( aPath ) > 0 )
110  return m_net_name_map.at( aPath );
111 
112  wxString name = "Net-(";
113 
114  name << GetParentComponent()->GetRef( &aPath );
115 
116  bool annotated = true;
117 
118  // Add timestamp for uninitialized components
119  if( name.Last() == '?' )
120  {
122  annotated = false;
123  }
124 
125  name << "-Pad" << m_libPin->GetNumber() << ")";
126 
127  if( annotated )
128  m_net_name_map[ aPath ] = name;
129 
130  return name;
131 }
132 
133 
135 {
138 }
139 
140 
142 {
145 
146  r.RevertYAxis();
147 
148  r = t.TransformCoordinate( r );
150 
151  return r;
152 }
153 
154 
155 bool SCH_PIN::HitTest( const wxPoint& aPosition, int aAccuracy ) const
156 {
157  EDA_RECT rect = GetBoundingBox();
158  return rect.Inflate( aAccuracy ).Contains( aPosition );
159 }
160 
161 
162 
EDA_UNITS
Definition: common.h:184
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:1629
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:70
const wxString & GetName() const
Definition: sch_pin.h:102
bool Matches(wxFindReplaceData &aSearchData, void *aAuxData) override
Function Matches compares the item against the search criteria in aSearchData.
Definition: lib_pin.cpp:1638
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:155
std::mutex m_netmap_mutex
The name that this pin connection will drive onto a net.
Definition: sch_pin.h:43
wxString GetDescription(const SCH_SHEET_PATH *aSheet)
Definition: sch_pin.cpp:84
wxString AsString() const
Definition: common.cpp:170
std::map< const SCH_SHEET_PATH, wxString > m_net_name_map
Definition: sch_pin.h:44
const EDA_RECT GetBoundingBox() const override
Definition: lib_pin.h:131
wxString GetDefaultNetName(const SCH_SHEET_PATH aPath)
Definition: sch_pin.cpp:102
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
Function GetPosition.
Definition: sch_pin.h:82
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:352
const wxString & GetNumber() const
Definition: sch_pin.h:104
bool m_isDangling
Definition: sch_pin.h:40
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
const wxString & GetName() const
Definition: lib_pin.h:152
TRANSFORM & GetTransform() const
SCH_PIN(LIB_PIN *aLibPin, SCH_COMPONENT *aParentComponent)
Definition: sch_pin.cpp:28
EDA_ITEM * GetParent() const
Definition: base_struct.h:217
SCH_SHEET_PATH.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false)
Return the reference for the given sheet path.
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Operator assignment is used to assign the members of aItem to another object.
SCH_PIN & operator=(const SCH_PIN &aPin)
Definition: sch_pin.cpp:46
void SetPosition(const wxPoint &aPosition) override
Function SetPosition set the schematic item position to aPosition.
Definition: sch_pin.h:83
void GetMsgPanelInfo(EDA_UNITS aUnits, std::vector< MSG_PANEL_ITEM > &aList) override
Display basic info (type, part and convert) about the current item in message panel.
const KIID m_Uuid
Definition: base_struct.h:169
wxPoint GetPosition() const override
Definition: lib_pin.h:432
const wxString & GetNumber() const
Definition: lib_pin.h:180
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:205
#define _(s)
Definition: 3d_actions.cpp:33
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:99
wxPoint GetPosition() const override
Function GetPosition.
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
bool Matches(wxFindReplaceData &aSearchData, void *aAuxData) override
Function Matches compares the item against the search criteria in aSearchData.
Definition: sch_pin.cpp:58
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_pin.cpp:141
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
SCH_COMPONENT * GetParentComponent() const
Definition: sch_pin.cpp:64
LIB_PIN * m_libPin
Definition: sch_pin.h:37
SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
void GetMsgPanelInfo(EDA_UNITS aUnits, MSG_PANEL_ITEMS &aList) override
Definition: sch_pin.cpp:78
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
wxPoint GetTransformedPosition() const
Returns the pin's position in global coordinates.
Definition: sch_pin.cpp:134
wxPoint m_position
Definition: sch_pin.h:39