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
36
37class REPORTER;
38
39
45{
46public:
48
49 COMPONENT_NET( const wxString& aPinName, const wxString& aNetName,
50 const wxString& aPinFunction, const wxString& aPinType ) :
51 m_pinName( aPinName ),
52 m_netName( aNetName ),
53 m_pinFunction( aPinFunction ),
54 m_pinType( aPinType )
55 {
56 }
57
58 const wxString& GetPinName() const { return m_pinName; }
59 const wxString& GetNetName() const { return m_netName; }
60 const wxString& GetPinFunction() const { return m_pinFunction; }
61 const wxString& GetPinType() const { return m_pinType; }
62
63 bool IsValid() const { return !m_pinName.IsEmpty(); }
64
65 bool operator <( const COMPONENT_NET& aNet ) const
66 {
67 return m_pinName < aNet.m_pinName;
68 }
69
70 int Format( OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl );
71
72private:
73 wxString m_pinName;
74 wxString m_netName;
75 wxString m_pinFunction;
76 wxString m_pinType;
77};
78
79
80typedef std::vector< COMPONENT_NET > COMPONENT_NETS;
81
86{
87public:
88 COMPONENT( const LIB_ID& aFPID,
89 const wxString& aReference,
90 const wxString& aValue,
91 const KIID_PATH& aPath,
92 const std::vector<KIID>& aKiids )
93 {
94 m_fpid = aFPID;
95 m_reference = aReference;
96 m_value = aValue;
97 m_pinCount = 0;
98 m_path = aPath;
99 m_kiids = aKiids;
100 }
101
102 virtual ~COMPONENT() { };
103
104 void AddNet( const wxString& aPinName, const wxString& aNetName, const wxString& aPinFunction,
105 const wxString& aPinType )
106 {
107 m_nets.emplace_back( aPinName, aNetName, aPinFunction, aPinType );
108 }
109
110 unsigned GetNetCount() const { return m_nets.size(); }
111
112 const COMPONENT_NET& GetNet( unsigned aIndex ) const { return m_nets[aIndex]; }
113
114 const COMPONENT_NET& GetNet( const wxString& aPinName ) const;
115
116 void ClearNets() { m_nets.clear(); }
117
118 void SortPins() { sort( m_nets.begin(), m_nets.end() ); }
119
120 void SetName( const wxString& aName ) { m_name = aName;}
121 const wxString& GetName() const { return m_name; }
122
123 void SetLibrary( const wxString& aLibrary ) { m_library = aLibrary; }
124 const wxString& GetLibrary() const { return m_library; }
125
126 void SetReference( const wxString& aReference ) { m_reference = aReference; }
127 const wxString& GetReference() const { return m_reference; }
128
129 void SetValue( const wxString& aValue ) { m_value = aValue; }
130 const wxString& GetValue() const { return m_value; }
131
132 void SetFields( nlohmann::ordered_map<wxString, wxString>& aFields )
133 {
134 m_fields = std::move( aFields );
135 }
136 const nlohmann::ordered_map<wxString, wxString>& GetFields() const { return m_fields; }
137
138 void SetProperties( std::map<wxString, wxString>& aProps )
139 {
140 m_properties = std::move( aProps );
141 }
142 const std::map<wxString, wxString>& GetProperties() const { return m_properties; }
143
144 void SetFPID( const LIB_ID& aFPID ) { m_fpid = aFPID; }
145 const LIB_ID& GetFPID() const { return m_fpid; }
146
147 void SetAltFPID( const LIB_ID& aFPID ) { m_altFpid = aFPID; }
148 const LIB_ID& GetAltFPID() const { return m_altFpid; }
149
150 const KIID_PATH& GetPath() const { return m_path; }
151
152 const std::vector<KIID>& GetKIIDs() const { return m_kiids; }
153
154 void SetFootprintFilters( const wxArrayString& aFilters ) { m_footprintFilters = aFilters; }
155 const wxArrayString& GetFootprintFilters() const { return m_footprintFilters; }
156
157 void SetPinCount( int aPinCount ) { m_pinCount = aPinCount; }
158 int GetPinCount() const { return m_pinCount; }
159
160 FOOTPRINT* GetFootprint( bool aRelease = false )
161 {
162 return ( aRelease ) ? m_footprint.release() : m_footprint.get();
163 }
164
165 void SetFootprint( FOOTPRINT* aFootprint );
166
167 bool IsLibSource( const wxString& aLibrary, const wxString& aName ) const
168 {
169 return aLibrary == m_library && aName == m_name;
170 }
171
172 void Format( OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl );
173
174private:
175 std::vector<COMPONENT_NET> m_nets;
176
177 wxArrayString m_footprintFilters;
179 wxString m_reference;
180 wxString m_value;
181
184
186 std::vector<KIID> m_kiids;
187
189 wxString m_name;
190
192 wxString m_library;
193
196
201
203 std::unique_ptr<FOOTPRINT> m_footprint;
204
206 std::map<wxString, wxString> m_properties;
207
209 nlohmann::ordered_map<wxString, wxString> m_fields;
210
212};
213
214
215typedef boost::ptr_vector< COMPONENT > COMPONENTS;
216
217
223{
224public:
226 m_findByTimeStamp( false ),
227 m_replaceFootprints( false )
228 {
229 }
230
234 bool IsEmpty() const { return m_components.empty(); }
235
239 void Clear() { m_components.clear(); }
240
244 unsigned GetCount() const { return m_components.size(); }
245
252 COMPONENT* GetComponent( unsigned aIndex ) { return &m_components[ aIndex ]; }
253
262 void AddComponent( COMPONENT* aComponent );
263
270 COMPONENT* GetComponentByReference( const wxString& aReference );
271
278 COMPONENT* GetComponentByPath( const KIID_PATH& aPath );
279
280 void SortByFPID();
281 void SortByReference();
282
283 void SetFindByTimeStamp( bool aFindByTimeStamp ) { m_findByTimeStamp = aFindByTimeStamp; }
284 bool IsFindByTimeStamp() const { return m_findByTimeStamp; }
285
286 void SetReplaceFootprints( bool aReplace ) { m_replaceFootprints = aReplace; }
288
292 bool AnyFootprintsLinked() const;
293
294 void Format( const char* aDocName, OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl = 0 );
295
296#define CTL_OMIT_EXTRA (1<<0)
297#define CTL_OMIT_NETS (1<<1)
298#define CTL_OMIT_FILTERS (1<<2)
299#define CTL_OMIT_FP_UUID (1<<3)
300
301#define CTL_FOR_CVPCB (CTL_OMIT_NETS | CTL_OMIT_FILTERS | CTL_OMIT_EXTRA)
302
304 {
305 Format( "cvpcb_netlist", aOut, 0, CTL_FOR_CVPCB );
306 }
307
308private:
309 COMPONENTS m_components; // Components found in the netlist.
310
311 bool m_findByTimeStamp; // Associate components by KIID (or refdes if false)
312 bool m_replaceFootprints; // Update footprints to match footprints defined in netlist
313};
314
315
316#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:45
const wxString & GetNetName() const
Definition: pcb_netlist.h:59
wxString m_pinName
Definition: pcb_netlist.h:73
wxString m_pinType
Definition: pcb_netlist.h:76
COMPONENT_NET(const wxString &aPinName, const wxString &aNetName, const wxString &aPinFunction, const wxString &aPinType)
Definition: pcb_netlist.h:49
wxString m_pinFunction
Definition: pcb_netlist.h:75
int Format(OUTPUTFORMATTER *aOut, int aNestLevel, int aCtl)
Definition: pcb_netlist.cpp:32
wxString m_netName
Definition: pcb_netlist.h:74
bool operator<(const COMPONENT_NET &aNet) const
Definition: pcb_netlist.h:65
bool IsValid() const
Definition: pcb_netlist.h:63
const wxString & GetPinFunction() const
Definition: pcb_netlist.h:60
const wxString & GetPinName() const
Definition: pcb_netlist.h:58
const wxString & GetPinType() const
Definition: pcb_netlist.h:61
Store all of the related footprint information found in a netlist.
Definition: pcb_netlist.h:86
const COMPONENT_NET & GetNet(unsigned aIndex) const
Definition: pcb_netlist.h:112
const KIID_PATH & GetPath() const
Definition: pcb_netlist.h:150
void SetValue(const wxString &aValue)
Definition: pcb_netlist.h:129
void SetFields(nlohmann::ordered_map< wxString, wxString > &aFields)
Definition: pcb_netlist.h:132
nlohmann::ordered_map< wxString, wxString > m_fields
Component-specific user fields found in the netlist.
Definition: pcb_netlist.h:209
void SetLibrary(const wxString &aLibrary)
Definition: pcb_netlist.h:123
void SetProperties(std::map< wxString, wxString > &aProps)
Definition: pcb_netlist.h:138
wxArrayString m_footprintFilters
Definition: pcb_netlist.h:177
const wxString & GetReference() const
Definition: pcb_netlist.h:127
virtual ~COMPONENT()
Definition: pcb_netlist.h:102
void SetAltFPID(const LIB_ID &aFPID)
Definition: pcb_netlist.h:147
void Format(OUTPUTFORMATTER *aOut, int aNestLevel, int aCtl)
Definition: pcb_netlist.cpp:73
int m_pinCount
Definition: pcb_netlist.h:178
const wxString & GetValue() const
Definition: pcb_netlist.h:130
KIID_PATH m_path
A fully specified path to the component (but not the component: [ sheetUUID, sheetUUID,...
Definition: pcb_netlist.h:183
const nlohmann::ordered_map< wxString, wxString > & GetFields() const
Definition: pcb_netlist.h:136
wxString m_value
Definition: pcb_netlist.h:180
std::vector< KIID > m_kiids
A vector of possible KIIDs corresponding to all units in a symbol.
Definition: pcb_netlist.h:186
const std::map< wxString, wxString > & GetProperties() const
Definition: pcb_netlist.h:142
int GetPinCount() const
Definition: pcb_netlist.h:158
void SetFPID(const LIB_ID &aFPID)
Definition: pcb_netlist.h:144
void SortPins()
Definition: pcb_netlist.h:118
void SetPinCount(int aPinCount)
Definition: pcb_netlist.h:157
wxString m_reference
Definition: pcb_netlist.h:179
void ClearNets()
Definition: pcb_netlist.h:116
wxString m_name
The name of the component in m_library used when it was placed on the schematic.
Definition: pcb_netlist.h:189
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:200
const LIB_ID & GetAltFPID() const
Definition: pcb_netlist.h:148
void SetFootprint(FOOTPRINT *aFootprint)
Definition: pcb_netlist.cpp:40
bool IsLibSource(const wxString &aLibrary, const wxString &aName) const
Definition: pcb_netlist.h:167
FOOTPRINT * GetFootprint(bool aRelease=false)
Definition: pcb_netlist.h:160
void SetFootprintFilters(const wxArrayString &aFilters)
Definition: pcb_netlist.h:154
void AddNet(const wxString &aPinName, const wxString &aNetName, const wxString &aPinFunction, const wxString &aPinType)
Definition: pcb_netlist.h:104
wxString m_library
The name of the component library where m_name was found.
Definition: pcb_netlist.h:192
LIB_ID m_fpid
The LIB_ID of the footprint assigned to the component.
Definition: pcb_netlist.h:195
const wxArrayString & GetFootprintFilters() const
Definition: pcb_netlist.h:155
std::vector< COMPONENT_NET > m_nets
list of nets shared by the component pins
Definition: pcb_netlist.h:175
const std::vector< KIID > & GetKIIDs() const
Definition: pcb_netlist.h:152
COMPONENT(const LIB_ID &aFPID, const wxString &aReference, const wxString &aValue, const KIID_PATH &aPath, const std::vector< KIID > &aKiids)
Definition: pcb_netlist.h:88
static COMPONENT_NET m_emptyNet
Definition: pcb_netlist.h:211
std::unique_ptr< FOOTPRINT > m_footprint
The FOOTPRINT loaded for #m_FPID.
Definition: pcb_netlist.h:203
std::map< wxString, wxString > m_properties
Component-specific properties found in the netlist.
Definition: pcb_netlist.h:206
const LIB_ID & GetFPID() const
Definition: pcb_netlist.h:145
unsigned GetNetCount() const
Definition: pcb_netlist.h:110
const wxString & GetLibrary() const
Definition: pcb_netlist.h:124
const wxString & GetName() const
Definition: pcb_netlist.h:121
void SetName(const wxString &aName)
Definition: pcb_netlist.h:120
void SetReference(const wxString &aReference)
Definition: pcb_netlist.h:126
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:223
void Format(const char *aDocName, OUTPUTFORMATTER *aOut, int aNestLevel, int aCtl=0)
bool GetReplaceFootprints() const
Definition: pcb_netlist.h:287
void SetReplaceFootprints(bool aReplace)
Definition: pcb_netlist.h:286
void SortByFPID()
bool m_findByTimeStamp
Definition: pcb_netlist.h:311
unsigned GetCount() const
Definition: pcb_netlist.h:244
void AddComponent(COMPONENT *aComponent)
Add aComponent to the NETLIST.
bool IsEmpty() const
Definition: pcb_netlist.h:234
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:239
void SetFindByTimeStamp(bool aFindByTimeStamp)
Definition: pcb_netlist.h:283
COMPONENT * GetComponent(unsigned aIndex)
Return the COMPONENT at aIndex.
Definition: pcb_netlist.h:252
bool m_replaceFootprints
Definition: pcb_netlist.h:312
COMPONENTS m_components
Definition: pcb_netlist.h:309
bool IsFindByTimeStamp() const
Definition: pcb_netlist.h:284
void SortByReference()
void FormatCvpcbNetlist(OUTPUTFORMATTER *aOut)
Definition: pcb_netlist.h:303
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:80
boost::ptr_vector< COMPONENT > COMPONENTS
Definition: pcb_netlist.h:215
#define CTL_FOR_CVPCB
Definition: pcb_netlist.h:301