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, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef NETLIST_H
21#define NETLIST_H
22
23#include <boost/ptr_container/ptr_vector.hpp>
24#include <wx/arrstr.h>
25#include <wx/string.h>
26#include <json_common.h>
27#include <unordered_set>
28#include <set>
29
30#include <lib_id.h>
31#include <kiid.h>
32#include <ctl_flags.h>
33#include <jumper_group.h>
34
35
36class OUTPUTFORMATTER;
37
38
44{
45public:
47
48 COMPONENT_NET( const wxString& aPinName, const wxString& aNetName,
49 const wxString& aPinFunction, const wxString& aPinType ) :
50 m_pinName( aPinName ),
51 m_netName( aNetName ),
52 m_pinFunction( aPinFunction ),
53 m_pinType( aPinType )
54 {
55 }
56
57 const wxString& GetPinName() const { return m_pinName; }
58 const wxString& GetNetName() const { return m_netName; }
59 const wxString& GetPinFunction() const { return m_pinFunction; }
60 const wxString& GetPinType() const { return m_pinType; }
61
62 bool IsValid() const { return !m_pinName.IsEmpty(); }
63
64 bool operator <( const COMPONENT_NET& aNet ) const
65 {
66 return m_pinName < aNet.m_pinName;
67 }
68
69 int Format( OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl );
70
71private:
72 wxString m_pinName;
73 wxString m_netName;
74 wxString m_pinFunction;
75 wxString m_pinType;
76};
77
78
79typedef std::vector< COMPONENT_NET > COMPONENT_NETS;
80
81
83{
84 wxString name;
87 std::vector<KIID> members;
88};
89
90
99{
100public:
101 COMPONENT( const LIB_ID& aFPID,
102 const wxString& aReference,
103 const wxString& aValue,
104 const KIID_PATH& aPath,
105 const std::vector<KIID>& aKiids )
106 {
107 m_fpid = aFPID;
108 m_reference = aReference;
109 m_value = aValue;
110 m_pinCount = 0;
111 m_path = aPath;
112 m_kiids = aKiids;
114 m_group = nullptr;
115 }
116
117 virtual ~COMPONENT() { };
118
119 void AddNet( const wxString& aPinName, const wxString& aNetName, const wxString& aPinFunction,
120 const wxString& aPinType )
121 {
122 m_nets.emplace_back( aPinName, aNetName, aPinFunction, aPinType );
123 }
124
125 unsigned GetNetCount() const { return m_nets.size(); }
126
127 const COMPONENT_NET& GetNet( unsigned aIndex ) const { return m_nets[aIndex]; }
128
129 const COMPONENT_NET& GetNet( const wxString& aPinName ) const;
130
131 void ClearNets() { m_nets.clear(); }
132
133 void SortPins() { sort( m_nets.begin(), m_nets.end() ); }
134
135 void SetName( const wxString& aName ) { m_name = aName;}
136 const wxString& GetName() const { return m_name; }
137
138 void SetLibrary( const wxString& aLibrary ) { m_library = aLibrary; }
139 const wxString& GetLibrary() const { return m_library; }
140
141 void SetReference( const wxString& aReference ) { m_reference = aReference; }
142 const wxString& GetReference() const { return m_reference; }
143
144 void SetValue( const wxString& aValue ) { m_value = aValue; }
145 const wxString& GetValue() const { return m_value; }
146
147 void SetFields( nlohmann::ordered_map<wxString, wxString> aFields )
148 {
149 m_fields = std::move( aFields );
150 }
151 const nlohmann::ordered_map<wxString, wxString>& GetFields() const { return m_fields; }
152
153 void SetProperties( std::map<wxString, wxString> aProps )
154 {
155 m_properties = std::move( aProps );
156 }
157 const std::map<wxString, wxString>& GetProperties() const { return m_properties; }
158
159 void SetFPID( const LIB_ID& aFPID ) { m_fpid = aFPID; }
160 const LIB_ID& GetFPID() const { return m_fpid; }
161
162 void SetAltFPID( const LIB_ID& aFPID ) { m_altFpid = aFPID; }
163 const LIB_ID& GetAltFPID() const { return m_altFpid; }
164
165 const KIID_PATH& GetPath() const { return m_path; }
166
167 const std::vector<KIID>& GetKIIDs() const { return m_kiids; }
168
169 void SetFootprintFilters( const wxArrayString& aFilters ) { m_footprintFilters = aFilters; }
170 const wxArrayString& GetFootprintFilters() const { return m_footprintFilters; }
171
172 void SetPinCount( int aPinCount ) { m_pinCount = aPinCount; }
173 int GetPinCount() const { return m_pinCount; }
174
175 bool IsLibSource( const wxString& aLibrary, const wxString& aName ) const
176 {
177 return aLibrary == m_library && aName == m_name;
178 }
179
180 void Format( OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl );
181
182 void SetHumanReadablePath( const wxString& aPath ) { m_humanReadablePath = aPath; }
183 const wxString& GetHumanReadablePath() const { return m_humanReadablePath; }
184
185 void SetComponentClassNames( const std::unordered_set<wxString>& aClassNames )
186 {
187 m_componentClassNames = aClassNames;
188 }
189
190 std::unordered_set<wxString>& GetComponentClassNames() { return m_componentClassNames; }
191
194
197
198 NETLIST_GROUP* GetGroup() const { return m_group; }
199 void SetGroup( NETLIST_GROUP* aGroup ) { m_group = aGroup; }
200
201 // Unit info for multi-unit symbols
203 {
204 wxString m_unitName; // e.g. A
205 std::vector<wxString> m_pins; // pin numbers in this unit
206 };
207
208 void SetUnitInfo( const std::vector<UNIT_INFO>& aUnits ) { m_units = aUnits; }
209 const std::vector<UNIT_INFO>& GetUnitInfo() const { return m_units; }
210
211protected:
212 std::vector<COMPONENT_NET> m_nets;
213
214 wxArrayString m_footprintFilters;
216 wxString m_reference;
217 wxString m_value;
218
219 // human-readable hierarchical sheet path (e.g. /root/block0/sheet1)
221
224
226 std::vector<KIID> m_kiids;
227
229 wxString m_name;
230
232 wxString m_library;
233
236
241
243 std::map<wxString, wxString> m_properties;
244
246 nlohmann::ordered_map<wxString, wxString> m_fields;
247
249 std::unordered_set<wxString> m_componentClassNames;
250
253
257
260
262
263 // Unit information parsed from the netlist (optional)
264 std::vector<UNIT_INFO> m_units;
265};
266
267
273{
274public:
276 m_findByTimeStamp( false ),
277 m_replaceFootprints( false )
278 {
279 }
280
281 virtual ~NETLIST() = default;
282
286 bool IsEmpty() const { return m_components.empty(); }
287
291 void Clear()
292 {
293 m_components.clear();
294 m_groups.clear();
295 }
296
300 unsigned GetCount() const { return m_components.size(); }
301
308 COMPONENT* GetComponent( unsigned aIndex ) { return &m_components[ aIndex ]; }
309
318 void AddComponent( COMPONENT* aComponent );
319
326 void AddGroup( NETLIST_GROUP* aGroup );
327
335 NETLIST_GROUP* GetGroupByUuid( const KIID& aUuid );
336
342
349 COMPONENT* GetComponentByReference( const wxString& aReference );
350
357 COMPONENT* GetComponentByPath( const KIID_PATH& aPath );
358
365 COMPONENT* GetComponentByUuid( const KIID& aUuid );
366
367 void SortByFPID();
368 void SortByReference();
369
370 void SetFindByTimeStamp( bool aFindByTimeStamp ) { m_findByTimeStamp = aFindByTimeStamp; }
371 bool IsFindByTimeStamp() const { return m_findByTimeStamp; }
372
373 void SetReplaceFootprints( bool aReplace ) { m_replaceFootprints = aReplace; }
375
379 bool AnyFootprintsLinked() const;
380
381 void Format( const char* aDocName, OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl = 0 );
382
383#define CTL_FOR_CVPCB (CTL_OMIT_NETS | CTL_OMIT_FILTERS | CTL_OMIT_EXTRA)
384
386 {
387 Format( "cvpcb_netlist", aOut, 0, CTL_FOR_CVPCB );
388 }
389
390protected:
391 boost::ptr_vector<COMPONENT> m_components; // Components found in the netlist.
392 boost::ptr_vector<NETLIST_GROUP> m_groups; // Groups found in the netlist.
393
394 bool m_findByTimeStamp; // Associate components by KIID (or refdes if false)
395 bool m_replaceFootprints; // Update footprints to match footprints defined in netlist
396};
397
398
399#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< 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)
JUMPER_GROUP_SET m_jumperPadGroups
Jumper pad groups for this footprint.
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
unsigned GetNetCount() const
std::unordered_set< wxString > & GetComponentClassNames()
JUMPER_GROUP_SET & JumperPadGroups()
const wxString & GetLibrary() const
void SetComponentClassNames(const std::unordered_set< wxString > &aClassNames)
const JUMPER_GROUP_SET & JumperPadGroups() const
const wxString & GetName() const
void SetName(const wxString &aName)
void SetReference(const wxString &aReference)
Represents an (ordered) list of JUMPER_GROUP objects.
Definition kiid.h:46
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
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.
boost::ptr_vector< COMPONENT > m_components
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)
boost::ptr_vector< NETLIST_GROUP > m_groups
An interface used to output 8 bit text in a convenient way.
Definition richio.h:294
std::vector< COMPONENT_NET > COMPONENT_NETS
#define CTL_FOR_CVPCB
std::vector< KIID > members