KiCad PCB EDA Suite
Loading...
Searching...
No Matches
common/netlist_reader/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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#ifndef NETLIST_H
25#define NETLIST_H
26
27#include <boost/ptr_container/ptr_vector.hpp>
28#include <wx/arrstr.h>
29#include <wx/string.h>
30#include <json_common.h>
31#include <unordered_set>
32#include <set>
33
34#include <lib_id.h>
35#include <kiid.h>
36#include <ctl_flags.h>
37
38
39class OUTPUTFORMATTER;
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
104{
105public:
106 COMPONENT( const LIB_ID& aFPID,
107 const wxString& aReference,
108 const wxString& aValue,
109 const KIID_PATH& aPath,
110 const std::vector<KIID>& aKiids )
111 {
112 m_fpid = aFPID;
113 m_reference = aReference;
114 m_value = aValue;
115 m_pinCount = 0;
116 m_path = aPath;
117 m_kiids = aKiids;
119 m_group = nullptr;
120 }
121
122 virtual ~COMPONENT() { };
123
124 void AddNet( const wxString& aPinName, const wxString& aNetName, const wxString& aPinFunction,
125 const wxString& aPinType )
126 {
127 m_nets.emplace_back( aPinName, aNetName, aPinFunction, aPinType );
128 }
129
130 unsigned GetNetCount() const { return m_nets.size(); }
131
132 const COMPONENT_NET& GetNet( unsigned aIndex ) const { return m_nets[aIndex]; }
133
134 const COMPONENT_NET& GetNet( const wxString& aPinName ) const;
135
136 void ClearNets() { m_nets.clear(); }
137
138 void SortPins() { sort( m_nets.begin(), m_nets.end() ); }
139
140 void SetName( const wxString& aName ) { m_name = aName;}
141 const wxString& GetName() const { return m_name; }
142
143 void SetLibrary( const wxString& aLibrary ) { m_library = aLibrary; }
144 const wxString& GetLibrary() const { return m_library; }
145
146 void SetReference( const wxString& aReference ) { m_reference = aReference; }
147 const wxString& GetReference() const { return m_reference; }
148
149 void SetValue( const wxString& aValue ) { m_value = aValue; }
150 const wxString& GetValue() const { return m_value; }
151
152 void SetFields( nlohmann::ordered_map<wxString, wxString> aFields )
153 {
154 m_fields = std::move( aFields );
155 }
156 const nlohmann::ordered_map<wxString, wxString>& GetFields() const { return m_fields; }
157
158 void SetProperties( std::map<wxString, wxString> aProps )
159 {
160 m_properties = std::move( aProps );
161 }
162 const std::map<wxString, wxString>& GetProperties() const { return m_properties; }
163
164 void SetFPID( const LIB_ID& aFPID ) { m_fpid = aFPID; }
165 const LIB_ID& GetFPID() const { return m_fpid; }
166
167 void SetAltFPID( const LIB_ID& aFPID ) { m_altFpid = aFPID; }
168 const LIB_ID& GetAltFPID() const { return m_altFpid; }
169
170 const KIID_PATH& GetPath() const { return m_path; }
171
172 const std::vector<KIID>& GetKIIDs() const { return m_kiids; }
173
174 void SetFootprintFilters( const wxArrayString& aFilters ) { m_footprintFilters = aFilters; }
175 const wxArrayString& GetFootprintFilters() const { return m_footprintFilters; }
176
177 void SetPinCount( int aPinCount ) { m_pinCount = aPinCount; }
178 int GetPinCount() const { return m_pinCount; }
179
180 bool IsLibSource( const wxString& aLibrary, const wxString& aName ) const
181 {
182 return aLibrary == m_library && aName == m_name;
183 }
184
185 void Format( OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl );
186
187 void SetHumanReadablePath( const wxString& aPath ) { m_humanReadablePath = aPath; }
188 const wxString& GetHumanReadablePath() const { return m_humanReadablePath; }
189
190 void SetComponentClassNames( const std::unordered_set<wxString>& aClassNames )
191 {
192 m_componentClassNames = aClassNames;
193 }
194
195 std::unordered_set<wxString>& GetComponentClassNames() { return m_componentClassNames; }
196
199
200 std::vector<std::set<wxString>>& JumperPadGroups() { return m_jumperPadGroups; }
201 const std::vector<std::set<wxString>>& JumperPadGroups() const { return m_jumperPadGroups; }
202
203 NETLIST_GROUP* GetGroup() const { return m_group; }
204 void SetGroup( NETLIST_GROUP* aGroup ) { m_group = aGroup; }
205
206 // Unit info for multi-unit symbols
208 {
209 wxString m_unitName; // e.g. A
210 std::vector<wxString> m_pins; // pin numbers in this unit
211 };
212
213 void SetUnitInfo( const std::vector<UNIT_INFO>& aUnits ) { m_units = aUnits; }
214 const std::vector<UNIT_INFO>& GetUnitInfo() const { return m_units; }
215
216protected:
217 std::vector<COMPONENT_NET> m_nets;
218
219 wxArrayString m_footprintFilters;
221 wxString m_reference;
222 wxString m_value;
223
224 // human-readable hierarchical sheet path (e.g. /root/block0/sheet1)
226
229
231 std::vector<KIID> m_kiids;
232
234 wxString m_name;
235
237 wxString m_library;
238
241
246
248 std::map<wxString, wxString> m_properties;
249
251 nlohmann::ordered_map<wxString, wxString> m_fields;
252
254 std::unordered_set<wxString> m_componentClassNames;
255
257 std::vector<std::set<wxString>> m_jumperPadGroups;
258
262
265
267
268 // Unit information parsed from the netlist (optional)
269 std::vector<UNIT_INFO> m_units;
270};
271
272
273typedef boost::ptr_vector< COMPONENT > COMPONENTS;
274
275
281{
282public:
284 m_findByTimeStamp( false ),
285 m_replaceFootprints( false )
286 {
287 }
288
289 virtual ~NETLIST() = default;
290
294 bool IsEmpty() const { return m_components.empty(); }
295
299 void Clear() { m_components.clear(); }
300
304 unsigned GetCount() const { return m_components.size(); }
305
312 COMPONENT* GetComponent( unsigned aIndex ) { return &m_components[ aIndex ]; }
313
322 void AddComponent( COMPONENT* aComponent );
323
330 void AddGroup( NETLIST_GROUP* aGroup );
331
339 NETLIST_GROUP* GetGroupByUuid( const KIID& aUuid );
340
346
353 COMPONENT* GetComponentByReference( const wxString& aReference );
354
361 COMPONENT* GetComponentByPath( const KIID_PATH& aPath );
362
369 COMPONENT* GetComponentByUuid( const KIID& aUuid );
370
371 void SortByFPID();
372 void SortByReference();
373
374 void SetFindByTimeStamp( bool aFindByTimeStamp ) { m_findByTimeStamp = aFindByTimeStamp; }
375 bool IsFindByTimeStamp() const { return m_findByTimeStamp; }
376
377 void SetReplaceFootprints( bool aReplace ) { m_replaceFootprints = aReplace; }
379
383 bool AnyFootprintsLinked() const;
384
385 void Format( const char* aDocName, OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl = 0 );
386
387#define CTL_FOR_CVPCB (CTL_OMIT_NETS | CTL_OMIT_FILTERS | CTL_OMIT_EXTRA)
388
390 {
391 Format( "cvpcb_netlist", aOut, 0, CTL_FOR_CVPCB );
392 }
393
394protected:
395 COMPONENTS m_components; // Components found in the netlist.
396 NETLIST_GROUPS m_groups; // Groups found in the netlist.
397
398 bool m_findByTimeStamp; // Associate components by KIID (or refdes if false)
399 bool m_replaceFootprints; // Update footprints to match footprints defined in netlist
400};
401
402
403#endif // NETLIST_H
Used to store the component pin name to net name (and pin function) associations stored in a netlist.
const wxString & GetNetName() const
COMPONENT_NET(const wxString &aPinName, const wxString &aNetName, const wxString &aPinFunction, const wxString &aPinType)
int Format(OUTPUTFORMATTER *aOut, int aNestLevel, int aCtl)
bool operator<(const COMPONENT_NET &aNet) const
const wxString & GetPinFunction() const
const wxString & GetPinName() const
const wxString & GetPinType() const
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
void SetAltFPID(const LIB_ID &aFPID)
void Format(OUTPUTFORMATTER *aOut, int aNestLevel, int aCtl)
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.
void SetFPID(const LIB_ID &aFPID)
void SetPinCount(int aPinCount)
void SetUnitInfo(const std::vector< UNIT_INFO > &aUnits)
std::unordered_set< wxString > m_componentClassNames
Component classes for this footprint.
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
bool IsLibSource(const wxString &aLibrary, const wxString &aName) const
std::vector< KIID > m_kiids
A vector of possible KIIDs corresponding to all units in a symbol.
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)
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
void Format(const char *aDocName, OUTPUTFORMATTER *aOut, int aNestLevel, int aCtl=0)
bool GetReplaceFootprints() const
void SetReplaceFootprints(bool aReplace)
unsigned GetCount() const
void AddGroup(NETLIST_GROUP *aGroup)
virtual ~NETLIST()=default
void AddComponent(COMPONENT *aComponent)
Add aComponent to the NETLIST.
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)
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 ...
bool IsFindByTimeStamp() const
void FormatCvpcbNetlist(OUTPUTFORMATTER *aOut)
An interface used to output 8 bit text in a convenient way.
Definition richio.h:323
std::vector< COMPONENT_NET > COMPONENT_NETS
boost::ptr_vector< COMPONENT > COMPONENTS
boost::ptr_vector< NETLIST_GROUP > NETLIST_GROUPS
#define CTL_FOR_CVPCB
std::vector< KIID > members