KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_netlist.h
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) 2012 Jean-Pierre Charras.
5 * Copyright (C) 2013-2016 Wayne Stambaugh <[email protected]>.
6 * Copyright (C) 2012-2022 KiCad Developers, see AUTHORS.txt for contributors.
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
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#ifndef PCB_NETLIST_H
27#define PCB_NETLIST_H
28
29#include <boost/ptr_container/ptr_vector.hpp>
30#include <wx/arrstr.h>
31#include <nlohmann/json.hpp>
32
33#include <lib_id.h>
34#include <footprint.h>
35#include <ctl_flags.h>
36
37
38class REPORTER;
39
40
46{
47public:
49
50 COMPONENT_NET( const wxString& aPinName, const wxString& aNetName,
51 const wxString& aPinFunction, const wxString& aPinType ) :
52 m_pinName( aPinName ),
53 m_netName( aNetName ),
54 m_pinFunction( aPinFunction ),
55 m_pinType( aPinType )
56 {
57 }
58
59 const wxString& GetPinName() const { return m_pinName; }
60 const wxString& GetNetName() const { return m_netName; }
61 const wxString& GetPinFunction() const { return m_pinFunction; }
62 const wxString& GetPinType() const { return m_pinType; }
63
64 bool IsValid() const { return !m_pinName.IsEmpty(); }
65
66 bool operator <( const COMPONENT_NET& aNet ) const
67 {
68 return m_pinName < aNet.m_pinName;
69 }
70
71 int Format( OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl );
72
73private:
74 wxString m_pinName;
75 wxString m_netName;
76 wxString m_pinFunction;
77 wxString m_pinType;
78};
79
80
81typedef std::vector< COMPONENT_NET > COMPONENT_NETS;
82
87{
88public:
89 COMPONENT( const LIB_ID& aFPID,
90 const wxString& aReference,
91 const wxString& aValue,
92 const KIID_PATH& aPath,
93 const std::vector<KIID>& aKiids )
94 {
95 m_fpid = aFPID;
96 m_reference = aReference;
97 m_value = aValue;
98 m_pinCount = 0;
99 m_path = aPath;
100 m_kiids = aKiids;
101 }
102
103 virtual ~COMPONENT() { };
104
105 void AddNet( const wxString& aPinName, const wxString& aNetName, const wxString& aPinFunction,
106 const wxString& aPinType )
107 {
108 m_nets.emplace_back( aPinName, aNetName, aPinFunction, aPinType );
109 }
110
111 unsigned GetNetCount() const { return m_nets.size(); }
112
113 const COMPONENT_NET& GetNet( unsigned aIndex ) const { return m_nets[aIndex]; }
114
115 const COMPONENT_NET& GetNet( const wxString& aPinName ) const;
116
117 void ClearNets() { m_nets.clear(); }
118
119 void SortPins() { sort( m_nets.begin(), m_nets.end() ); }
120
121 void SetName( const wxString& aName ) { m_name = aName;}
122 const wxString& GetName() const { return m_name; }
123
124 void SetLibrary( const wxString& aLibrary ) { m_library = aLibrary; }
125 const wxString& GetLibrary() const { return m_library; }
126
127 void SetReference( const wxString& aReference ) { m_reference = aReference; }
128 const wxString& GetReference() const { return m_reference; }
129
130 void SetValue( const wxString& aValue ) { m_value = aValue; }
131 const wxString& GetValue() const { return m_value; }
132
133 void SetFields( nlohmann::ordered_map<wxString, wxString>& aFields )
134 {
135 m_fields = std::move( aFields );
136 }
137 const nlohmann::ordered_map<wxString, wxString>& GetFields() const { return m_fields; }
138
139 void SetProperties( std::map<wxString, wxString>& aProps )
140 {
141 m_properties = std::move( aProps );
142 }
143 const std::map<wxString, wxString>& GetProperties() const { return m_properties; }
144
145 void SetFPID( const LIB_ID& aFPID ) { m_fpid = aFPID; }
146 const LIB_ID& GetFPID() const { return m_fpid; }
147
148 void SetAltFPID( const LIB_ID& aFPID ) { m_altFpid = aFPID; }
149 const LIB_ID& GetAltFPID() const { return m_altFpid; }
150
151 const KIID_PATH& GetPath() const { return m_path; }
152
153 const std::vector<KIID>& GetKIIDs() const { return m_kiids; }
154
155 void SetFootprintFilters( const wxArrayString& aFilters ) { m_footprintFilters = aFilters; }
156 const wxArrayString& GetFootprintFilters() const { return m_footprintFilters; }
157
158 void SetPinCount( int aPinCount ) { m_pinCount = aPinCount; }
159 int GetPinCount() const { return m_pinCount; }
160
161 FOOTPRINT* GetFootprint( bool aRelease = false )
162 {
163 return ( aRelease ) ? m_footprint.release() : m_footprint.get();
164 }
165
166 void SetFootprint( FOOTPRINT* aFootprint );
167
168 bool IsLibSource( const wxString& aLibrary, const wxString& aName ) const
169 {
170 return aLibrary == m_library && aName == m_name;
171 }
172
173 void Format( OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl );
174
175private:
176 std::vector<COMPONENT_NET> m_nets;
177
178 wxArrayString m_footprintFilters;
180 wxString m_reference;
181 wxString m_value;
182
185
187 std::vector<KIID> m_kiids;
188
190 wxString m_name;
191
193 wxString m_library;
194
197
202
204 std::unique_ptr<FOOTPRINT> m_footprint;
205
207 std::map<wxString, wxString> m_properties;
208
210 nlohmann::ordered_map<wxString, wxString> m_fields;
211
213};
214
215
216typedef boost::ptr_vector< COMPONENT > COMPONENTS;
217
218
224{
225public:
227 m_findByTimeStamp( false ),
228 m_replaceFootprints( false )
229 {
230 }
231
235 bool IsEmpty() const { return m_components.empty(); }
236
240 void Clear() { m_components.clear(); }
241
245 unsigned GetCount() const { return m_components.size(); }
246
253 COMPONENT* GetComponent( unsigned aIndex ) { return &m_components[ aIndex ]; }
254
263 void AddComponent( COMPONENT* aComponent );
264
271 COMPONENT* GetComponentByReference( const wxString& aReference );
272
279 COMPONENT* GetComponentByPath( const KIID_PATH& aPath );
280
281 void SortByFPID();
282 void SortByReference();
283
284 void SetFindByTimeStamp( bool aFindByTimeStamp ) { m_findByTimeStamp = aFindByTimeStamp; }
285 bool IsFindByTimeStamp() const { return m_findByTimeStamp; }
286
287 void SetReplaceFootprints( bool aReplace ) { m_replaceFootprints = aReplace; }
289
293 bool AnyFootprintsLinked() const;
294
295 void Format( const char* aDocName, OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl = 0 );
296
297#define CTL_FOR_CVPCB (CTL_OMIT_NETS | CTL_OMIT_FILTERS | CTL_OMIT_EXTRA)
298
300 {
301 Format( "cvpcb_netlist", aOut, 0, CTL_FOR_CVPCB );
302 }
303
304private:
305 COMPONENTS m_components; // Components found in the netlist.
306
307 bool m_findByTimeStamp; // Associate components by KIID (or refdes if false)
308 bool m_replaceFootprints; // Update footprints to match footprints defined in netlist
309};
310
311
312#endif // PCB_NETLIST_H
Used to store the component pin name to net name (and pin function) associations stored in a netlist.
Definition: pcb_netlist.h:46
const wxString & GetNetName() const
Definition: pcb_netlist.h:60
wxString m_pinName
Definition: pcb_netlist.h:74
wxString m_pinType
Definition: pcb_netlist.h:77
COMPONENT_NET(const wxString &aPinName, const wxString &aNetName, const wxString &aPinFunction, const wxString &aPinType)
Definition: pcb_netlist.h:50
wxString m_pinFunction
Definition: pcb_netlist.h:76
int Format(OUTPUTFORMATTER *aOut, int aNestLevel, int aCtl)
Definition: pcb_netlist.cpp:32
wxString m_netName
Definition: pcb_netlist.h:75
bool operator<(const COMPONENT_NET &aNet) const
Definition: pcb_netlist.h:66
bool IsValid() const
Definition: pcb_netlist.h:64
const wxString & GetPinFunction() const
Definition: pcb_netlist.h:61
const wxString & GetPinName() const
Definition: pcb_netlist.h:59
const wxString & GetPinType() const
Definition: pcb_netlist.h:62
Store all of the related footprint information found in a netlist.
Definition: pcb_netlist.h:87
const COMPONENT_NET & GetNet(unsigned aIndex) const
Definition: pcb_netlist.h:113
const KIID_PATH & GetPath() const
Definition: pcb_netlist.h:151
void SetValue(const wxString &aValue)
Definition: pcb_netlist.h:130
void SetFields(nlohmann::ordered_map< wxString, wxString > &aFields)
Definition: pcb_netlist.h:133
nlohmann::ordered_map< wxString, wxString > m_fields
Component-specific user fields found in the netlist.
Definition: pcb_netlist.h:210
void SetLibrary(const wxString &aLibrary)
Definition: pcb_netlist.h:124
void SetProperties(std::map< wxString, wxString > &aProps)
Definition: pcb_netlist.h:139
wxArrayString m_footprintFilters
Definition: pcb_netlist.h:178
const wxString & GetReference() const
Definition: pcb_netlist.h:128
virtual ~COMPONENT()
Definition: pcb_netlist.h:103
void SetAltFPID(const LIB_ID &aFPID)
Definition: pcb_netlist.h:148
void Format(OUTPUTFORMATTER *aOut, int aNestLevel, int aCtl)
Definition: pcb_netlist.cpp:73
int m_pinCount
Definition: pcb_netlist.h:179
const wxString & GetValue() const
Definition: pcb_netlist.h:131
KIID_PATH m_path
A fully specified path to the component (but not the component: [ sheetUUID, sheetUUID,...
Definition: pcb_netlist.h:184
const nlohmann::ordered_map< wxString, wxString > & GetFields() const
Definition: pcb_netlist.h:137
wxString m_value
Definition: pcb_netlist.h:181
std::vector< KIID > m_kiids
A vector of possible KIIDs corresponding to all units in a symbol.
Definition: pcb_netlist.h:187
const std::map< wxString, wxString > & GetProperties() const
Definition: pcb_netlist.h:143
int GetPinCount() const
Definition: pcb_netlist.h:159
void SetFPID(const LIB_ID &aFPID)
Definition: pcb_netlist.h:145
void SortPins()
Definition: pcb_netlist.h:119
void SetPinCount(int aPinCount)
Definition: pcb_netlist.h:158
wxString m_reference
Definition: pcb_netlist.h:180
void ClearNets()
Definition: pcb_netlist.h:117
wxString m_name
The name of the component in m_library used when it was placed on the schematic.
Definition: pcb_netlist.h:190
LIB_ID m_altFpid
The alt LIB_ID of the footprint, when there are 2 different assigned footprints, One from the netlist...
Definition: pcb_netlist.h:201
const LIB_ID & GetAltFPID() const
Definition: pcb_netlist.h:149
void SetFootprint(FOOTPRINT *aFootprint)
Definition: pcb_netlist.cpp:40
bool IsLibSource(const wxString &aLibrary, const wxString &aName) const
Definition: pcb_netlist.h:168
FOOTPRINT * GetFootprint(bool aRelease=false)
Definition: pcb_netlist.h:161
void SetFootprintFilters(const wxArrayString &aFilters)
Definition: pcb_netlist.h:155
void AddNet(const wxString &aPinName, const wxString &aNetName, const wxString &aPinFunction, const wxString &aPinType)
Definition: pcb_netlist.h:105
wxString m_library
The name of the component library where m_name was found.
Definition: pcb_netlist.h:193
LIB_ID m_fpid
The LIB_ID of the footprint assigned to the component.
Definition: pcb_netlist.h:196
const wxArrayString & GetFootprintFilters() const
Definition: pcb_netlist.h:156
std::vector< COMPONENT_NET > m_nets
list of nets shared by the component pins
Definition: pcb_netlist.h:176
const std::vector< KIID > & GetKIIDs() const
Definition: pcb_netlist.h:153
COMPONENT(const LIB_ID &aFPID, const wxString &aReference, const wxString &aValue, const KIID_PATH &aPath, const std::vector< KIID > &aKiids)
Definition: pcb_netlist.h:89
static COMPONENT_NET m_emptyNet
Definition: pcb_netlist.h:212
std::unique_ptr< FOOTPRINT > m_footprint
The FOOTPRINT loaded for #m_FPID.
Definition: pcb_netlist.h:204
std::map< wxString, wxString > m_properties
Component-specific properties found in the netlist.
Definition: pcb_netlist.h:207
const LIB_ID & GetFPID() const
Definition: pcb_netlist.h:146
unsigned GetNetCount() const
Definition: pcb_netlist.h:111
const wxString & GetLibrary() const
Definition: pcb_netlist.h:125
const wxString & GetName() const
Definition: pcb_netlist.h:122
void SetName(const wxString &aName)
Definition: pcb_netlist.h:121
void SetReference(const wxString &aReference)
Definition: pcb_netlist.h:127
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
Store information read from a netlist along with the flags used to update the NETLIST in the BOARD.
Definition: pcb_netlist.h:224
void Format(const char *aDocName, OUTPUTFORMATTER *aOut, int aNestLevel, int aCtl=0)
bool GetReplaceFootprints() const
Definition: pcb_netlist.h:288
void SetReplaceFootprints(bool aReplace)
Definition: pcb_netlist.h:287
void SortByFPID()
bool m_findByTimeStamp
Definition: pcb_netlist.h:307
unsigned GetCount() const
Definition: pcb_netlist.h:245
void AddComponent(COMPONENT *aComponent)
Add aComponent to the NETLIST.
bool IsEmpty() const
Definition: pcb_netlist.h:235
COMPONENT * GetComponentByPath(const KIID_PATH &aPath)
Return a COMPONENT by aPath.
COMPONENT * GetComponentByReference(const wxString &aReference)
Return a COMPONENT by aReference.
void Clear()
Remove all components from the netlist.
Definition: pcb_netlist.h:240
void SetFindByTimeStamp(bool aFindByTimeStamp)
Definition: pcb_netlist.h:284
COMPONENT * GetComponent(unsigned aIndex)
Return the COMPONENT at aIndex.
Definition: pcb_netlist.h:253
bool m_replaceFootprints
Definition: pcb_netlist.h:308
COMPONENTS m_components
Definition: pcb_netlist.h:305
bool IsFindByTimeStamp() const
Definition: pcb_netlist.h:285
void SortByReference()
void FormatCvpcbNetlist(OUTPUTFORMATTER *aOut)
Definition: pcb_netlist.h:299
bool AnyFootprintsLinked() const
An interface used to output 8 bit text in a convenient way.
Definition: richio.h:322
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:71
std::vector< COMPONENT_NET > COMPONENT_NETS
Definition: pcb_netlist.h:81
boost::ptr_vector< COMPONENT > COMPONENTS
Definition: pcb_netlist.h:216
#define CTL_FOR_CVPCB
Definition: pcb_netlist.h:297