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 <lib_id.h>
35#include <footprint.h>
36#include <ctl_flags.h>
37
38
39class REPORTER;
40
41
47{
48public:
50
51 COMPONENT_NET( const wxString& aPinName, const wxString& aNetName,
52 const wxString& aPinFunction, const wxString& aPinType ) :
53 m_pinName( aPinName ),
54 m_netName( aNetName ),
55 m_pinFunction( aPinFunction ),
56 m_pinType( aPinType )
57 {
58 }
59
60 const wxString& GetPinName() const { return m_pinName; }
61 const wxString& GetNetName() const { return m_netName; }
62 const wxString& GetPinFunction() const { return m_pinFunction; }
63 const wxString& GetPinType() const { return m_pinType; }
64
65 bool IsValid() const { return !m_pinName.IsEmpty(); }
66
67 bool operator <( const COMPONENT_NET& aNet ) const
68 {
69 return m_pinName < aNet.m_pinName;
70 }
71
72 int Format( OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl );
73
74private:
75 wxString m_pinName;
76 wxString m_netName;
77 wxString m_pinFunction;
78 wxString m_pinType;
79};
80
81
82typedef std::vector< COMPONENT_NET > COMPONENT_NETS;
83
84
86{
87 wxString name;
90 std::vector<KIID> members;
91};
92
93typedef boost::ptr_vector< NETLIST_GROUP > NETLIST_GROUPS;
94
95
100{
101public:
102 COMPONENT( const LIB_ID& aFPID,
103 const wxString& aReference,
104 const wxString& aValue,
105 const KIID_PATH& aPath,
106 const std::vector<KIID>& aKiids )
107 {
108 m_fpid = aFPID;
109 m_reference = aReference;
110 m_value = aValue;
111 m_pinCount = 0;
112 m_path = aPath;
113 m_kiids = aKiids;
115 m_group = nullptr;
116 }
117
118 virtual ~COMPONENT() { };
119
120 void AddNet( const wxString& aPinName, const wxString& aNetName, const wxString& aPinFunction,
121 const wxString& aPinType )
122 {
123 m_nets.emplace_back( aPinName, aNetName, aPinFunction, aPinType );
124 }
125
126 unsigned GetNetCount() const { return m_nets.size(); }
127
128 const COMPONENT_NET& GetNet( unsigned aIndex ) const { return m_nets[aIndex]; }
129
130 const COMPONENT_NET& GetNet( const wxString& aPinName ) const;
131
132 void ClearNets() { m_nets.clear(); }
133
134 void SortPins() { sort( m_nets.begin(), m_nets.end() ); }
135
136 void SetName( const wxString& aName ) { m_name = aName;}
137 const wxString& GetName() const { return m_name; }
138
139 void SetLibrary( const wxString& aLibrary ) { m_library = aLibrary; }
140 const wxString& GetLibrary() const { return m_library; }
141
142 void SetReference( const wxString& aReference ) { m_reference = aReference; }
143 const wxString& GetReference() const { return m_reference; }
144
145 void SetValue( const wxString& aValue ) { m_value = aValue; }
146 const wxString& GetValue() const { return m_value; }
147
148 void SetFields( nlohmann::ordered_map<wxString, wxString> aFields )
149 {
150 m_fields = std::move( aFields );
151 }
152 const nlohmann::ordered_map<wxString, wxString>& GetFields() const { return m_fields; }
153
154 void SetProperties( std::map<wxString, wxString> aProps )
155 {
156 m_properties = std::move( aProps );
157 }
158 const std::map<wxString, wxString>& GetProperties() const { return m_properties; }
159
160 void SetFPID( const LIB_ID& aFPID ) { m_fpid = aFPID; }
161 const LIB_ID& GetFPID() const { return m_fpid; }
162
163 void SetAltFPID( const LIB_ID& aFPID ) { m_altFpid = aFPID; }
164 const LIB_ID& GetAltFPID() const { return m_altFpid; }
165
166 const KIID_PATH& GetPath() const { return m_path; }
167
168 const std::vector<KIID>& GetKIIDs() const { return m_kiids; }
169
170 void SetFootprintFilters( const wxArrayString& aFilters ) { m_footprintFilters = aFilters; }
171 const wxArrayString& GetFootprintFilters() const { return m_footprintFilters; }
172
173 void SetPinCount( int aPinCount ) { m_pinCount = aPinCount; }
174 int GetPinCount() const { return m_pinCount; }
175
176 FOOTPRINT* GetFootprint( bool aRelease = false )
177 {
178 return ( aRelease ) ? m_footprint.release() : m_footprint.get();
179 }
180
181 void SetFootprint( FOOTPRINT* aFootprint );
182
183 bool IsLibSource( const wxString& aLibrary, const wxString& aName ) const
184 {
185 return aLibrary == m_library && aName == m_name;
186 }
187
188 void Format( OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl );
189
190 void SetHumanReadablePath( const wxString& aPath ) { m_humanReadablePath = aPath; }
191 const wxString& GetHumanReadablePath() const { return m_humanReadablePath; }
192
193 void SetComponentClassNames( const std::unordered_set<wxString>& aClassNames )
194 {
195 m_componentClassNames = aClassNames;
196 }
197
198 std::unordered_set<wxString>& GetComponentClassNames() { return m_componentClassNames; }
199
202
203 std::vector<std::set<wxString>>& JumperPadGroups() { return m_jumperPadGroups; }
204 const std::vector<std::set<wxString>>& JumperPadGroups() const { return m_jumperPadGroups; }
205
206 NETLIST_GROUP* GetGroup() const { return m_group; }
207 void SetGroup( NETLIST_GROUP* aGroup ) { m_group = aGroup; }
208
209private:
210 std::vector<COMPONENT_NET> m_nets;
211
212 wxArrayString m_footprintFilters;
214 wxString m_reference;
215 wxString m_value;
216
217 // human-readable hierarchical sheet path (e.g. /root/block0/sheet1)
219
222
224 std::vector<KIID> m_kiids;
225
227 wxString m_name;
228
230 wxString m_library;
231
234
239
241 std::unique_ptr<FOOTPRINT> m_footprint;
242
244 std::map<wxString, wxString> m_properties;
245
247 nlohmann::ordered_map<wxString, wxString> m_fields;
248
250 std::unordered_set<wxString> m_componentClassNames;
251
253 std::vector<std::set<wxString>> m_jumperPadGroups;
254
258
261
263};
264
265
266typedef boost::ptr_vector< COMPONENT > COMPONENTS;
267
268
274{
275public:
277 m_findByTimeStamp( false ),
278 m_replaceFootprints( false )
279 {
280 }
281
285 bool IsEmpty() const { return m_components.empty(); }
286
290 void Clear() { m_components.clear(); }
291
295 unsigned GetCount() const { return m_components.size(); }
296
303 COMPONENT* GetComponent( unsigned aIndex ) { return &m_components[ aIndex ]; }
304
313 void AddComponent( COMPONENT* aComponent );
314
321 void AddGroup( NETLIST_GROUP* aGroup );
322
330 NETLIST_GROUP* GetGroupByUuid( const KIID& aUuid );
331
337
344 COMPONENT* GetComponentByReference( const wxString& aReference );
345
352 COMPONENT* GetComponentByPath( const KIID_PATH& aPath );
353
360 COMPONENT* GetComponentByUuid( const KIID& aUuid );
361
362 void SortByFPID();
363 void SortByReference();
364
365 void SetFindByTimeStamp( bool aFindByTimeStamp ) { m_findByTimeStamp = aFindByTimeStamp; }
366 bool IsFindByTimeStamp() const { return m_findByTimeStamp; }
367
368 void SetReplaceFootprints( bool aReplace ) { m_replaceFootprints = aReplace; }
370
374 bool AnyFootprintsLinked() const;
375
376 void Format( const char* aDocName, OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl = 0 );
377
378#define CTL_FOR_CVPCB (CTL_OMIT_NETS | CTL_OMIT_FILTERS | CTL_OMIT_EXTRA)
379
381 {
382 Format( "cvpcb_netlist", aOut, 0, CTL_FOR_CVPCB );
383 }
384
385private:
386 COMPONENTS m_components; // Components found in the netlist.
387 NETLIST_GROUPS m_groups; // Groups found in the netlist.
388
389
390 bool m_findByTimeStamp; // Associate components by KIID (or refdes if false)
391 bool m_replaceFootprints; // Update footprints to match footprints defined in netlist
392};
393
394
395#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:47
const wxString & GetNetName() const
Definition: pcb_netlist.h:61
wxString m_pinName
Definition: pcb_netlist.h:75
wxString m_pinType
Definition: pcb_netlist.h:78
COMPONENT_NET(const wxString &aPinName, const wxString &aNetName, const wxString &aPinFunction, const wxString &aPinType)
Definition: pcb_netlist.h:51
wxString m_pinFunction
Definition: pcb_netlist.h:77
int Format(OUTPUTFORMATTER *aOut, int aNestLevel, int aCtl)
Definition: pcb_netlist.cpp:34
wxString m_netName
Definition: pcb_netlist.h:76
bool operator<(const COMPONENT_NET &aNet) const
Definition: pcb_netlist.h:67
bool IsValid() const
Definition: pcb_netlist.h:65
const wxString & GetPinFunction() const
Definition: pcb_netlist.h:62
const wxString & GetPinName() const
Definition: pcb_netlist.h:60
const wxString & GetPinType() const
Definition: pcb_netlist.h:63
Store all of the related footprint information found in a netlist.
Definition: pcb_netlist.h:100
const std::vector< std::set< wxString > > & JumperPadGroups() const
Definition: pcb_netlist.h:204
const wxString & GetHumanReadablePath() const
Definition: pcb_netlist.h:191
const COMPONENT_NET & GetNet(unsigned aIndex) const
Definition: pcb_netlist.h:128
const KIID_PATH & GetPath() const
Definition: pcb_netlist.h:166
void SetValue(const wxString &aValue)
Definition: pcb_netlist.h:145
nlohmann::ordered_map< wxString, wxString > m_fields
Component-specific user fields found in the netlist.
Definition: pcb_netlist.h:247
void SetLibrary(const wxString &aLibrary)
Definition: pcb_netlist.h:139
std::unordered_set< wxString > m_componentClassNames
Component classes for this footprint.
Definition: pcb_netlist.h:250
wxArrayString m_footprintFilters
Definition: pcb_netlist.h:212
const wxString & GetReference() const
Definition: pcb_netlist.h:143
virtual ~COMPONENT()
Definition: pcb_netlist.h:118
void SetAltFPID(const LIB_ID &aFPID)
Definition: pcb_netlist.h:163
void Format(OUTPUTFORMATTER *aOut, int aNestLevel, int aCtl)
Definition: pcb_netlist.cpp:75
int m_pinCount
Definition: pcb_netlist.h:213
const wxString & GetValue() const
Definition: pcb_netlist.h:146
void SetProperties(std::map< wxString, wxString > aProps)
Definition: pcb_netlist.h:154
KIID_PATH m_path
A fully specified path to the component (but not the component: [ sheetUUID, sheetUUID,...
Definition: pcb_netlist.h:221
const nlohmann::ordered_map< wxString, wxString > & GetFields() const
Definition: pcb_netlist.h:152
wxString m_value
Definition: pcb_netlist.h:215
std::vector< KIID > m_kiids
A vector of possible KIIDs corresponding to all units in a symbol.
Definition: pcb_netlist.h:224
bool m_duplicatePadNumbersAreJumpers
Flag that this footprint should automatically treat sets of two or more pads with the same number as ...
Definition: pcb_netlist.h:257
const std::map< wxString, wxString > & GetProperties() const
Definition: pcb_netlist.h:158
int GetPinCount() const
Definition: pcb_netlist.h:174
void SetFPID(const LIB_ID &aFPID)
Definition: pcb_netlist.h:160
void SortPins()
Definition: pcb_netlist.h:134
void SetPinCount(int aPinCount)
Definition: pcb_netlist.h:173
wxString m_reference
Definition: pcb_netlist.h:214
void ClearNets()
Definition: pcb_netlist.h:132
wxString m_name
The name of the component in m_library used when it was placed on the schematic.
Definition: pcb_netlist.h:227
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:238
const LIB_ID & GetAltFPID() const
Definition: pcb_netlist.h:164
wxString m_humanReadablePath
Definition: pcb_netlist.h:218
std::vector< std::set< wxString > > m_jumperPadGroups
Jumper pad groups for this footprint.
Definition: pcb_netlist.h:253
void SetFootprint(FOOTPRINT *aFootprint)
Definition: pcb_netlist.cpp:42
bool IsLibSource(const wxString &aLibrary, const wxString &aName) const
Definition: pcb_netlist.h:183
FOOTPRINT * GetFootprint(bool aRelease=false)
Definition: pcb_netlist.h:176
NETLIST_GROUP * GetGroup() const
Definition: pcb_netlist.h:206
void SetFootprintFilters(const wxArrayString &aFilters)
Definition: pcb_netlist.h:170
void AddNet(const wxString &aPinName, const wxString &aNetName, const wxString &aPinFunction, const wxString &aPinType)
Definition: pcb_netlist.h:120
wxString m_library
The name of the component library where m_name was found.
Definition: pcb_netlist.h:230
LIB_ID m_fpid
The LIB_ID of the footprint assigned to the component.
Definition: pcb_netlist.h:233
const wxArrayString & GetFootprintFilters() const
Definition: pcb_netlist.h:171
std::vector< COMPONENT_NET > m_nets
list of nets shared by the component pins
Definition: pcb_netlist.h:210
void SetFields(nlohmann::ordered_map< wxString, wxString > aFields)
Definition: pcb_netlist.h:148
const std::vector< KIID > & GetKIIDs() const
Definition: pcb_netlist.h:168
COMPONENT(const LIB_ID &aFPID, const wxString &aReference, const wxString &aValue, const KIID_PATH &aPath, const std::vector< KIID > &aKiids)
Definition: pcb_netlist.h:102
void SetHumanReadablePath(const wxString &aPath)
Definition: pcb_netlist.h:190
static COMPONENT_NET m_emptyNet
Definition: pcb_netlist.h:262
std::unique_ptr< FOOTPRINT > m_footprint
The FOOTPRINT loaded for #m_FPID.
Definition: pcb_netlist.h:241
NETLIST_GROUP * m_group
Group membership for this footprint. Nullptr if none.
Definition: pcb_netlist.h:260
void SetDuplicatePadNumbersAreJumpers(bool aEnabled)
Definition: pcb_netlist.h:201
bool GetDuplicatePadNumbersAreJumpers() const
Definition: pcb_netlist.h:200
std::map< wxString, wxString > m_properties
Component-specific properties found in the netlist.
Definition: pcb_netlist.h:244
const LIB_ID & GetFPID() const
Definition: pcb_netlist.h:161
void SetGroup(NETLIST_GROUP *aGroup)
Definition: pcb_netlist.h:207
unsigned GetNetCount() const
Definition: pcb_netlist.h:126
std::unordered_set< wxString > & GetComponentClassNames()
Definition: pcb_netlist.h:198
const wxString & GetLibrary() const
Definition: pcb_netlist.h:140
void SetComponentClassNames(const std::unordered_set< wxString > &aClassNames)
Definition: pcb_netlist.h:193
const wxString & GetName() const
Definition: pcb_netlist.h:137
std::vector< std::set< wxString > > & JumperPadGroups()
Definition: pcb_netlist.h:203
void SetName(const wxString &aName)
Definition: pcb_netlist.h:136
void SetReference(const wxString &aReference)
Definition: pcb_netlist.h:142
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.
Definition: pcb_netlist.h:274
void Format(const char *aDocName, OUTPUTFORMATTER *aOut, int aNestLevel, int aCtl=0)
bool GetReplaceFootprints() const
Definition: pcb_netlist.h:369
void SetReplaceFootprints(bool aReplace)
Definition: pcb_netlist.h:368
void SortByFPID()
bool m_findByTimeStamp
Definition: pcb_netlist.h:390
unsigned GetCount() const
Definition: pcb_netlist.h:295
void AddGroup(NETLIST_GROUP *aGroup)
void AddComponent(COMPONENT *aComponent)
Add aComponent to the NETLIST.
bool IsEmpty() const
Definition: pcb_netlist.h:285
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:290
COMPONENT * GetComponentByUuid(const KIID &aUuid)
Return a COMPONENT by aUuid.
void SetFindByTimeStamp(bool aFindByTimeStamp)
Definition: pcb_netlist.h:365
NETLIST_GROUP * GetGroupByUuid(const KIID &aUuid)
Return a NETLIST_GROUP by aUuid.
COMPONENT * GetComponent(unsigned aIndex)
Return the COMPONENT at aIndex.
Definition: pcb_netlist.h:303
void ApplyGroupMembership()
After groups and components are parsed, apply the group memberships to the internal components based ...
bool m_replaceFootprints
Definition: pcb_netlist.h:391
COMPONENTS m_components
Definition: pcb_netlist.h:386
NETLIST_GROUPS m_groups
Definition: pcb_netlist.h:387
bool IsFindByTimeStamp() const
Definition: pcb_netlist.h:366
void SortByReference()
void FormatCvpcbNetlist(OUTPUTFORMATTER *aOut)
Definition: pcb_netlist.h:380
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:73
std::vector< COMPONENT_NET > COMPONENT_NETS
Definition: pcb_netlist.h:82
boost::ptr_vector< COMPONENT > COMPONENTS
Definition: pcb_netlist.h:266
#define CTL_FOR_CVPCB
Definition: pcb_netlist.h:378
boost::ptr_vector< NETLIST_GROUP > NETLIST_GROUPS
Definition: pcb_netlist.h:93
std::vector< KIID > members
Definition: pcb_netlist.h:90
LIB_ID libId
Definition: pcb_netlist.h:89
wxString name
Definition: pcb_netlist.h:87