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 
59 {
60  return static_cast<SCH_COMPONENT*>( GetParent() );
61 }
62 
63 
64 wxString SCH_PIN::GetSelectMenuText( EDA_UNITS_T aUnits ) const
65 {
66  return wxString::Format( "%s %s",
68  m_libPin->GetSelectMenuText( aUnits ) );
69 }
70 
71 
73 {
74  m_libPin->GetMsgPanelInfo( aUnits, aList, GetParentComponent() );
75 }
76 
77 
79 {
81  return m_libPin->GetName();
82 
83  std::lock_guard<std::mutex> lock( m_netmap_mutex );
84 
85  if( m_net_name_map.count( aPath ) > 0 )
86  return m_net_name_map.at( aPath );
87 
88  wxString name = "Net-(";
89 
90  name << GetParentComponent()->GetRef( &aPath );
91 
92  // TODO(JE) do we need adoptTimestamp?
93  if( /* adoptTimestamp && */ name.Last() == '?' )
95 
96  name << "-Pad" << m_libPin->GetNumber() << ")";
97 
98  m_net_name_map[ aPath ] = name;
99 
100  return name;
101 }
102 
103 
105 {
108 }
109 
110 
112 {
115 
116  t.y2 = -t.y2;
117  r = t.TransformCoordinate( r );
119 
120  return r;
121 }
122 
123 
124 bool SCH_PIN::HitTest( const wxPoint& aPosition, int aAccuracy ) const
125 {
126  EDA_RECT rect = GetBoundingBox();
127  return rect.Inflate( aAccuracy ).Contains( aPosition );
128 }
129 
130 
131 
void Offset(int dx, int dy)
Definition: eda_rect.h:128
wxString GetSelectMenuText(EDA_UNITS_T aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: sch_pin.cpp:64
int y2
Definition: transform.h:51
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:124
std::mutex m_netmap_mutex
The name that this pin connection will drive onto a net.
Definition: sch_pin.h:42
std::map< const SCH_SHEET_PATH, wxString > m_net_name_map
Definition: sch_pin.h:43
const EDA_RECT GetBoundingBox() const override
Definition: lib_pin.h:129
wxString GetDefaultNetName(const SCH_SHEET_PATH aPath)
Definition: sch_pin.cpp:78
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_pin.h:75
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:41
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
bool m_isDangling
Definition: sch_pin.h:39
Class for tranforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
const wxString & GetName() const
Definition: lib_pin.h:150
TRANSFORM & GetTransform() const
timestamp_t GetTimeStamp() const
Definition: base_struct.h:210
SCH_PIN(LIB_PIN *aLibPin, SCH_COMPONENT *aParentComponent)
Definition: sch_pin.cpp:28
EDA_ITEM * GetParent() const
Definition: base_struct.h:214
void GetMsgPanelInfo(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList) override
Display basic info (type, part and convert) about the current item in message panel.
Class SCH_SHEET_PATH.
const wxString GetRef(const SCH_SHEET_PATH *aSheet)
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:76
wxString GetSelectMenuText(EDA_UNITS_T aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: lib_pin.cpp:1667
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_pin.h:432
const wxString & GetNumber() const
Definition: lib_pin.h:178
const char * name
Definition: DXF_plotter.cpp:61
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
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:73
wxPoint GetPosition() const override
Function GetPosition.
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_pin.cpp:111
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
void GetMsgPanelInfo(EDA_UNITS_T aUnits, MSG_PANEL_ITEMS &aList) override
Definition: sch_pin.cpp:72
SCH_COMPONENT * GetParentComponent() const
Definition: sch_pin.cpp:58
LIB_PIN * m_libPin
Definition: sch_pin.h:36
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Definition: sch_item.h:114
EDA_UNITS_T
Definition: common.h:157
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:104
wxPoint m_position
Definition: sch_pin.h:38