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 The 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 <json_common.h>
32#include <unordered_set>
33
34#include <kiid.h>
35#include <lib_id.h>
36#include <ctl_flags.h>
38
39
40class REPORTER;
41class FOOTPRINT;
42class OUTPUTFORMATTER;
43
44
49class COMPONENT_NET
50{
51public:
53
54 COMPONENT_NET( const wxString& aPinName, const wxString& aNetName,
55 const wxString& aPinFunction, const wxString& aPinType ) :
56 m_pinName( aPinName ),
57 m_netName( aNetName ),
58 m_pinFunction( aPinFunction ),
59 m_pinType( aPinType )
60 {
61 }
62
63 const wxString& GetPinName() const { return m_pinName; }
64 const wxString& GetNetName() const { return m_netName; }
65 const wxString& GetPinFunction() const { return m_pinFunction; }
66 const wxString& GetPinType() const { return m_pinType; }
67
68 bool IsValid() const { return !m_pinName.IsEmpty(); }
69
70 bool operator <( const COMPONENT_NET& aNet ) const
71 {
72 return m_pinName < aNet.m_pinName;
73 }
74
75 int Format( OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl );
76
77private:
78 wxString m_pinName;
79 wxString m_netName;
80 wxString m_pinFunction;
81 wxString m_pinType;
82};
83
84
85typedef std::vector< COMPONENT_NET > COMPONENT_NETS;
86
87
88struct NETLIST_GROUP
89{
90 wxString name;
91 KIID uuid;
93 std::vector<KIID> members;
94};
95
96typedef boost::ptr_vector< NETLIST_GROUP > NETLIST_GROUPS;
97
98
100{
101 COMPONENT_VARIANT( const wxString& aName = wxEmptyString ) : m_name( aName ) {}
102
103 wxString m_name;
104 bool m_dnp = false;
105 bool m_excludedFromBOM = false;
106 bool m_excludedFromSim = false;
108
109 bool m_hasDnp = false;
113
114 nlohmann::ordered_map<wxString, wxString> m_fields;
115};
116
117
121class COMPONENT
122{
123public:
124 COMPONENT( const LIB_ID& aFPID,
125 const wxString& aReference,
126 const wxString& aValue,
127 const KIID_PATH& aPath,
128 const std::vector<KIID>& aKiids );
129
130 virtual ~COMPONENT();
131
132 void AddNet( const wxString& aPinName, const wxString& aNetName, const wxString& aPinFunction,
133 const wxString& aPinType )
134 {
135 m_nets.emplace_back( aPinName, aNetName, aPinFunction, aPinType );
136 }
137
138 unsigned GetNetCount() const { return m_nets.size(); }
139
140 const COMPONENT_NET& GetNet( unsigned aIndex ) const { return m_nets[aIndex]; }
141
142 const COMPONENT_NET& GetNet( const wxString& aPinName ) const;
143
144 void ClearNets() { m_nets.clear(); }
145
146 void SortPins() { sort( m_nets.begin(), m_nets.end() ); }
147
148 void SetName( const wxString& aName ) { m_name = aName;}
149 const wxString& GetName() const { return m_name; }
150
151 void SetLibrary( const wxString& aLibrary ) { m_library = aLibrary; }
152 const wxString& GetLibrary() const { return m_library; }
153
154 void SetReference( const wxString& aReference ) { m_reference = aReference; }
155 const wxString& GetReference() const { return m_reference; }
156
157 void SetValue( const wxString& aValue ) { m_value = aValue; }
158 const wxString& GetValue() const { return m_value; }
159
160 void SetFields( nlohmann::ordered_map<wxString, wxString> aFields )
161 {
162 m_fields = std::move( aFields );
163 }
164 const nlohmann::ordered_map<wxString, wxString>& GetFields() const { return m_fields; }
165
166 void SetProperties( std::map<wxString, wxString> aProps )
167 {
168 m_properties = std::move( aProps );
169 }
170 const std::map<wxString, wxString>& GetProperties() const { return m_properties; }
171
172 void SetFPID( const LIB_ID& aFPID ) { m_fpid = aFPID; }
173 const LIB_ID& GetFPID() const { return m_fpid; }
174
175 void SetAltFPID( const LIB_ID& aFPID ) { m_altFpid = aFPID; }
176 const LIB_ID& GetAltFPID() const { return m_altFpid; }
177
178 const KIID_PATH& GetPath() const { return m_path; }
179
180 const std::vector<KIID>& GetKIIDs() const { return m_kiids; }
181
182 void SetFootprintFilters( const wxArrayString& aFilters ) { m_footprintFilters = aFilters; }
183 const wxArrayString& GetFootprintFilters() const { return m_footprintFilters; }
184
185 void SetPinCount( int aPinCount ) { m_pinCount = aPinCount; }
186 int GetPinCount() const { return m_pinCount; }
187
188 FOOTPRINT* GetFootprint( bool aRelease = false );
189
190 void SetFootprint( FOOTPRINT* aFootprint );
191
192 bool IsLibSource( const wxString& aLibrary, const wxString& aName ) const
193 {
194 return aLibrary == m_library && aName == m_name;
195 }
196
197 void Format( OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl );
198
199 void SetHumanReadablePath( const wxString& aPath ) { m_humanReadablePath = aPath; }
200 const wxString& GetHumanReadablePath() const { return m_humanReadablePath; }
201
202 void SetComponentClassNames( const std::unordered_set<wxString>& aClassNames )
203 {
204 m_componentClassNames = aClassNames;
205 }
206
207 std::unordered_set<wxString>& GetComponentClassNames() { return m_componentClassNames; }
208
211
212 std::vector<std::set<wxString>>& JumperPadGroups() { return m_jumperPadGroups; }
213 const std::vector<std::set<wxString>>& JumperPadGroups() const { return m_jumperPadGroups; }
214
215 NETLIST_GROUP* GetGroup() const { return m_group; }
216 void SetGroup( NETLIST_GROUP* aGroup ) { m_group = aGroup; }
217
218 // Unit info for multi-unit symbols
219 struct UNIT_INFO
220 {
221 wxString m_unitName; // e.g. A
222 std::vector<wxString> m_pins; // pin numbers in this unit
223 };
224
225 void SetUnitInfo( const std::vector<UNIT_INFO>& aUnits ) { m_units = aUnits; }
226 const std::vector<UNIT_INFO>& GetUnitInfo() const { return m_units; }
227
229 const COMPONENT_VARIANT* GetVariant( const wxString& aVariantName ) const;
230 COMPONENT_VARIANT* GetVariant( const wxString& aVariantName );
231 void AddVariant( const COMPONENT_VARIANT& aVariant );
232
233private:
234 std::vector<COMPONENT_NET> m_nets;
235
236 wxArrayString m_footprintFilters;
237 int m_pinCount;
238 wxString m_reference;
239 wxString m_value;
240
241 // human-readable hierarchical sheet path (e.g. /root/block0/sheet1)
242 wxString m_humanReadablePath;
243
246
248 std::vector<KIID> m_kiids;
249
251 wxString m_name;
252
254 wxString m_library;
255
258
263
265 std::unique_ptr<FOOTPRINT> m_footprint;
266
268 std::map<wxString, wxString> m_properties;
269
271 nlohmann::ordered_map<wxString, wxString> m_fields;
272
274 std::unordered_set<wxString> m_componentClassNames;
275
277 std::vector<std::set<wxString>> m_jumperPadGroups;
278
282
285
287
288 // Unit information parsed from the netlist (optional)
289 std::vector<UNIT_INFO> m_units;
290
292};
293
294
295typedef boost::ptr_vector< COMPONENT > COMPONENTS;
296
297
302class NETLIST
303{
304public:
306 m_findByTimeStamp( false ),
307 m_replaceFootprints( false )
308 {
309 }
310
314 bool IsEmpty() const { return m_components.empty(); }
315
319 void Clear() { m_components.clear(); }
320
324 unsigned GetCount() const { return m_components.size(); }
325
332 COMPONENT* GetComponent( unsigned aIndex ) { return &m_components[ aIndex ]; }
333
342 void AddComponent( COMPONENT* aComponent );
343
350 void AddGroup( NETLIST_GROUP* aGroup );
351
360
366
373 COMPONENT* GetComponentByReference( const wxString& aReference );
374
382
390
393
394 void SetFindByTimeStamp( bool aFindByTimeStamp ) { m_findByTimeStamp = aFindByTimeStamp; }
395 bool IsFindByTimeStamp() const { return m_findByTimeStamp; }
396
397 void SetReplaceFootprints( bool aReplace ) { m_replaceFootprints = aReplace; }
399
404
405 void Format( const char* aDocName, OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl = 0 );
406
407#define CTL_FOR_CVPCB (CTL_OMIT_NETS | CTL_OMIT_FILTERS | CTL_OMIT_EXTRA)
408
410 {
411 Format( "cvpcb_netlist", aOut, 0, CTL_FOR_CVPCB );
412 }
413
417 const std::vector<wxString>& GetVariantNames() const { return m_variantNames; }
418
422 void AddVariant( const wxString& aName, const wxString& aDescription = wxEmptyString )
423 {
424 if( aName.IsEmpty() )
425 return;
426
427 for( const wxString& existingName : m_variantNames )
428 {
429 if( existingName.CmpNoCase( aName ) == 0 )
430 {
431 if( aDescription.IsEmpty() )
432 m_variantDescriptions.erase( existingName );
433 else
434 m_variantDescriptions[existingName] = aDescription;
435
436 return;
437 }
438 }
439
440 m_variantNames.push_back( aName );
441
442 if( aDescription.IsEmpty() )
443 return;
444
445 m_variantDescriptions[aName] = aDescription;
446 }
447
451 wxString GetVariantDescription( const wxString& aVariantName ) const
452 {
453 wxString actualName;
454
455 for( const wxString& existingName : m_variantNames )
456 {
457 if( existingName.CmpNoCase( aVariantName ) == 0 )
458 {
459 actualName = existingName;
460 break;
461 }
462 }
463
464 if( !actualName.IsEmpty() )
465 {
466 auto it = m_variantDescriptions.find( actualName );
467
468 if( it != m_variantDescriptions.end() )
469 return it->second;
470 }
471
472 return wxEmptyString;
473 }
474
478 const std::map<wxString, wxString>& GetVariantDescriptions() const
479 {
481 }
482
483private:
484 COMPONENTS m_components; // Components found in the netlist.
485 NETLIST_GROUPS m_groups; // Groups found in the netlist.
486
487 std::vector<wxString> m_variantNames; // Variant names in order.
488 std::map<wxString, wxString> m_variantDescriptions; // Variant descriptions.
489
490 bool m_findByTimeStamp; // Associate components by KIID (or refdes if false)
491 bool m_replaceFootprints; // Update footprints to match footprints defined in netlist
492};
493
494
495#endif // PCB_NETLIST_H
const char * name
std::map< wxString, ValueType, DETAIL::CASE_INSENSITIVE_COMPARER > CASE_INSENSITIVE_MAP
Used to store the component pin name to net name (and pin function) associations stored in a netlist.
const wxString & GetNetName() const
Definition pcb_netlist.h:64
COMPONENT_NET(const wxString &aPinName, const wxString &aNetName, const wxString &aPinFunction, const wxString &aPinType)
Definition pcb_netlist.h:54
int Format(OUTPUTFORMATTER *aOut, int aNestLevel, int aCtl)
bool operator<(const COMPONENT_NET &aNet) const
bool IsValid() const
Definition pcb_netlist.h:68
const wxString & GetPinFunction() const
Definition pcb_netlist.h:65
const wxString & GetPinName() const
Definition pcb_netlist.h:63
const wxString & GetPinType() const
Definition pcb_netlist.h:66
Store all of the related component information found in a netlist.
const std::vector< std::set< wxString > > & JumperPadGroups() const
const std::vector< UNIT_INFO > & GetUnitInfo() const
const wxString & GetHumanReadablePath() const
const COMPONENT_NET & GetNet(unsigned aIndex) const
const KIID_PATH & GetPath() const
void SetValue(const wxString &aValue)
std::vector< COMPONENT_NET > m_nets
list of nets shared by the component pins
void SetLibrary(const wxString &aLibrary)
std::map< wxString, wxString > m_properties
Component-specific properties found in the netlist.
wxArrayString m_footprintFilters
const wxString & GetReference() const
virtual ~COMPONENT()
void AddVariant(const COMPONENT_VARIANT &aVariant)
CASE_INSENSITIVE_MAP< COMPONENT_VARIANT > m_variants
void SetAltFPID(const LIB_ID &aFPID)
void Format(OUTPUTFORMATTER *aOut, int aNestLevel, int aCtl)
const COMPONENT_VARIANT * GetVariant(const wxString &aVariantName) const
const wxString & GetValue() const
void SetProperties(std::map< wxString, wxString > aProps)
KIID_PATH m_path
A fully specified path to the component (but not the component: [ sheetUUID, sheetUUID,...
const nlohmann::ordered_map< wxString, wxString > & GetFields() const
NETLIST_GROUP * m_group
Group membership for this footprint. Nullptr if none.
bool m_duplicatePadNumbersAreJumpers
Flag that this footprint should automatically treat sets of two or more pads with the same number as ...
const std::map< wxString, wxString > & GetProperties() const
nlohmann::ordered_map< wxString, wxString > m_fields
Component-specific user fields found in the netlist.
int GetPinCount() const
void SetFPID(const LIB_ID &aFPID)
void SortPins()
void SetPinCount(int aPinCount)
void SetUnitInfo(const std::vector< UNIT_INFO > &aUnits)
const COMPONENT_NET & GetNet(const wxString &aPinName) const
std::unordered_set< wxString > m_componentClassNames
Component classes for this footprint.
void ClearNets()
wxString m_name
The name of the component in m_library used when it was placed on the schematic.
LIB_ID m_altFpid
The alt LIB_ID of the footprint, when there are 2 different assigned footprints, One from the netlist...
const LIB_ID & GetAltFPID() const
void SetFootprint(FOOTPRINT *aFootprint)
bool IsLibSource(const wxString &aLibrary, const wxString &aName) const
const CASE_INSENSITIVE_MAP< COMPONENT_VARIANT > & GetVariants() const
std::vector< KIID > m_kiids
A vector of possible KIIDs corresponding to all units in a symbol.
FOOTPRINT * GetFootprint(bool aRelease=false)
NETLIST_GROUP * GetGroup() const
void SetFootprintFilters(const wxArrayString &aFilters)
void AddNet(const wxString &aPinName, const wxString &aNetName, const wxString &aPinFunction, const wxString &aPinType)
wxString m_library
The name of the component library where m_name was found.
LIB_ID m_fpid
The LIB_ID of the footprint assigned to the component.
const wxArrayString & GetFootprintFilters() const
static COMPONENT_NET m_emptyNet
void SetFields(nlohmann::ordered_map< wxString, wxString > aFields)
const std::vector< KIID > & GetKIIDs() const
COMPONENT(const LIB_ID &aFPID, const wxString &aReference, const wxString &aValue, const KIID_PATH &aPath, const std::vector< KIID > &aKiids)
void SetHumanReadablePath(const wxString &aPath)
std::unique_ptr< FOOTPRINT > m_footprint
The FOOTPRINT loaded for #m_FPID.
void SetDuplicatePadNumbersAreJumpers(bool aEnabled)
bool GetDuplicatePadNumbersAreJumpers() const
const LIB_ID & GetFPID() const
void SetGroup(NETLIST_GROUP *aGroup)
std::vector< UNIT_INFO > m_units
std::vector< std::set< wxString > > m_jumperPadGroups
Jumper pad groups for this footprint.
unsigned GetNetCount() const
std::unordered_set< wxString > & GetComponentClassNames()
const wxString & GetLibrary() const
void SetComponentClassNames(const std::unordered_set< wxString > &aClassNames)
const wxString & GetName() const
std::vector< std::set< wxString > > & JumperPadGroups()
void SetName(const wxString &aName)
void SetReference(const wxString &aReference)
Definition kiid.h:49
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.
void Format(const char *aDocName, OUTPUTFORMATTER *aOut, int aNestLevel, int aCtl=0)
bool GetReplaceFootprints() const
void AddVariant(const wxString &aName, const wxString &aDescription=wxEmptyString)
Add a variant name to the netlist.
void SetReplaceFootprints(bool aReplace)
void SortByFPID()
std::vector< wxString > m_variantNames
const std::vector< wxString > & GetVariantNames() const
unsigned GetCount() const
void AddGroup(NETLIST_GROUP *aGroup)
void AddComponent(COMPONENT *aComponent)
Add aComponent to the NETLIST.
bool IsEmpty() const
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.
COMPONENT * GetComponentByUuid(const KIID &aUuid)
Return a COMPONENT by aUuid.
void SetFindByTimeStamp(bool aFindByTimeStamp)
std::map< wxString, wxString > m_variantDescriptions
NETLIST_GROUP * GetGroupByUuid(const KIID &aUuid)
Return a NETLIST_GROUP by aUuid.
COMPONENT * GetComponent(unsigned aIndex)
Return the COMPONENT at aIndex.
void ApplyGroupMembership()
After groups and components are parsed, apply the group memberships to the internal components based ...
const std::map< wxString, wxString > & GetVariantDescriptions() const
wxString GetVariantDescription(const wxString &aVariantName) const
bool IsFindByTimeStamp() const
void SortByReference()
void FormatCvpcbNetlist(OUTPUTFORMATTER *aOut)
bool AnyFootprintsLinked() const
An interface used to output 8 bit text in a convenient way.
Definition richio.h:295
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
std::vector< COMPONENT_NET > COMPONENT_NETS
boost::ptr_vector< COMPONENT > COMPONENTS
boost::ptr_vector< NETLIST_GROUP > NETLIST_GROUPS
#define CTL_FOR_CVPCB
COMPONENT_VARIANT(const wxString &aName=wxEmptyString)
bool m_hasExcludedFromPosFiles
nlohmann::ordered_map< wxString, wxString > m_fields
std::vector< KIID > members