KiCad PCB EDA Suite
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 <stambaughw@gmail.com>.
6  * Copyright (C) 2012-2021 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 
32 #include <lib_id.h>
33 #include <footprint.h>
34 
35 
36 class REPORTER;
37 
38 
44 {
45 public:
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 
71 private:
72  wxString m_pinName;
73  wxString m_netName;
74  wxString m_pinFunction;
75  wxString m_pinType;
76 };
77 
78 
79 typedef std::vector< COMPONENT_NET > COMPONENT_NETS;
80 
84 class COMPONENT
85 {
86 public:
87  COMPONENT( const LIB_ID& aFPID,
88  const wxString& aReference,
89  const wxString& aValue,
90  const KIID_PATH& aPath,
91  const std::vector<KIID>& aKiids )
92  {
93  m_fpid = aFPID;
94  m_reference = aReference;
95  m_value = aValue;
96  m_pinCount = 0;
97  m_path = aPath;
98  m_kiids = aKiids;
99  }
100 
101  virtual ~COMPONENT() { };
102 
103  void AddNet( const wxString& aPinName, const wxString& aNetName, const wxString& aPinFunction,
104  const wxString& aPinType )
105  {
106  m_nets.push_back( COMPONENT_NET( aPinName, aNetName, aPinFunction, aPinType ) );
107  }
108 
109  unsigned GetNetCount() const { return m_nets.size(); }
110 
111  const COMPONENT_NET& GetNet( unsigned aIndex ) const { return m_nets[aIndex]; }
112 
113  const COMPONENT_NET& GetNet( const wxString& aPinName ) const;
114 
115  void SortPins() { sort( m_nets.begin(), m_nets.end() ); }
116 
117  void SetName( const wxString& aName ) { m_name = aName;}
118  const wxString& GetName() const { return m_name; }
119 
120  void SetLibrary( const wxString& aLibrary ) { m_library = aLibrary; }
121  const wxString& GetLibrary() const { return m_library; }
122 
123  const wxString& GetReference() const { return m_reference; }
124  const wxString& GetValue() const { return m_value; }
125 
126  void SetProperties( std::map<wxString, wxString>& aProps )
127  {
128  m_properties = std::move( aProps );
129  }
130  const std::map<wxString, wxString>& GetProperties() const { return m_properties; }
131 
132  void SetFPID( const LIB_ID& aFPID ) { m_fpid = aFPID; }
133  const LIB_ID& GetFPID() const { return m_fpid; }
134 
135  void SetAltFPID( const LIB_ID& aFPID ) { m_altFpid = aFPID; }
136  const LIB_ID& GetAltFPID() const { return m_altFpid; }
137 
138  const KIID_PATH& GetPath() const { return m_path; }
139 
140  const std::vector<KIID>& GetKIIDs() const { return m_kiids; }
141 
142  void SetFootprintFilters( const wxArrayString& aFilters ) { m_footprintFilters = aFilters; }
143  const wxArrayString& GetFootprintFilters() const { return m_footprintFilters; }
144 
145  void SetPinCount( int aPinCount ) { m_pinCount = aPinCount; }
146  int GetPinCount() const { return m_pinCount; }
147 
148  FOOTPRINT* GetFootprint( bool aRelease = false )
149  {
150  return ( aRelease ) ? m_footprint.release() : m_footprint.get();
151  }
152 
153  void SetFootprint( FOOTPRINT* aFootprint );
154 
155  bool IsLibSource( const wxString& aLibrary, const wxString& aName ) const
156  {
157  return aLibrary == m_library && aName == m_name;
158  }
159 
160  void Format( OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl );
161 
162 private:
164  wxArrayString m_footprintFilters;
166  wxString m_reference;
167  wxString m_value;
168 
171 
173  std::vector<KIID> m_kiids;
174 
176  wxString m_name;
177 
179  wxString m_library;
180 
183 
188 
190  std::unique_ptr< FOOTPRINT > m_footprint;
191 
193  std::map<wxString, wxString> m_properties;
194 
196 };
197 
198 
199 typedef boost::ptr_vector< COMPONENT > COMPONENTS;
200 
201 
206 class NETLIST
207 {
208 public:
210  m_findByTimeStamp( false ),
211  m_replaceFootprints( false )
212  {
213  }
214 
218  bool IsEmpty() const { return m_components.empty(); }
219 
223  void Clear() { m_components.clear(); }
224 
228  unsigned GetCount() const { return m_components.size(); }
229 
236  COMPONENT* GetComponent( unsigned aIndex ) { return &m_components[ aIndex ]; }
237 
246  void AddComponent( COMPONENT* aComponent );
247 
254  COMPONENT* GetComponentByReference( const wxString& aReference );
255 
262  COMPONENT* GetComponentByPath( const KIID_PATH& aPath );
263 
264  void SortByFPID();
265  void SortByReference();
266 
267  void SetFindByTimeStamp( bool aFindByTimeStamp ) { m_findByTimeStamp = aFindByTimeStamp; }
268  bool IsFindByTimeStamp() const { return m_findByTimeStamp; }
269 
270  void SetReplaceFootprints( bool aReplace ) { m_replaceFootprints = aReplace; }
271  bool GetReplaceFootprints() const { return m_replaceFootprints; }
272 
276  bool AnyFootprintsLinked() const;
277 
278  void Format( const char* aDocName, OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl = 0 );
279 
280 #define CTL_OMIT_EXTRA (1<<0)
281 #define CTL_OMIT_NETS (1<<1)
282 #define CTL_OMIT_FILTERS (1<<2)
283 #define CTL_OMIT_FP_UUID (1<<3)
284 
285 #define CTL_FOR_CVPCB (CTL_OMIT_NETS | CTL_OMIT_FILTERS | CTL_OMIT_EXTRA)
286 
288  {
289  Format( "cvpcb_netlist", aOut, 0, CTL_FOR_CVPCB );
290  }
291 
292 private:
293  COMPONENTS m_components; // Components found in the netlist.
294 
295  bool m_findByTimeStamp; // Associate components by KIID (or refdes if false)
296  bool m_replaceFootprints; // Update footprints to match footprints defined in netlist
297 };
298 
299 
300 #endif // PCB_NETLIST_H
bool IsLibSource(const wxString &aLibrary, const wxString &aName) const
Definition: pcb_netlist.h:155
void SetAltFPID(const LIB_ID &aFPID)
Definition: pcb_netlist.h:135
KIID_PATH m_path
A fully specified path to the component (but not the component: [ sheetUUID, sheetUUID,...
Definition: pcb_netlist.h:170
std::unique_ptr< FOOTPRINT > m_footprint
The FOOTPRINT loaded for #m_FPID.
Definition: pcb_netlist.h:190
void SortByFPID()
virtual ~COMPONENT()
Definition: pcb_netlist.h:101
void Format(OUTPUTFORMATTER *aOut, int aNestLevel, int aCtl)
Definition: pcb_netlist.cpp:74
wxString m_name
The name of the component in m_library used when it was placed on the schematic..
Definition: pcb_netlist.h:176
COMPONENT * GetComponentByPath(const KIID_PATH &aPath)
Return a COMPONENT by aPath.
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:187
void FormatCvpcbNetlist(OUTPUTFORMATTER *aOut)
Definition: pcb_netlist.h:287
wxString m_library
The name of the component library where m_name was found.
Definition: pcb_netlist.h:179
void SetFPID(const LIB_ID &aFPID)
Definition: pcb_netlist.h:132
bool AnyFootprintsLinked() const
const wxString & GetPinType() const
Definition: pcb_netlist.h:60
bool IsFindByTimeStamp() const
Definition: pcb_netlist.h:268
COMPONENTS m_components
Definition: pcb_netlist.h:293
void SetLibrary(const wxString &aLibrary)
Definition: pcb_netlist.h:120
An interface used to output 8 bit text in a convenient way.
Definition: richio.h:306
wxArrayString m_footprintFilters
Footprint filters found in netlist.
Definition: pcb_netlist.h:164
unsigned GetCount() const
Definition: pcb_netlist.h:228
void SetFindByTimeStamp(bool aFindByTimeStamp)
Definition: pcb_netlist.h:267
void SetProperties(std::map< wxString, wxString > &aProps)
Definition: pcb_netlist.h:126
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:64
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
std::vector< KIID > m_kiids
A vector of possible KIIDs corresponding to all units in a symbol.
Definition: pcb_netlist.h:173
static COMPONENT_NET m_emptyNet
Definition: pcb_netlist.h:195
void SetFootprint(FOOTPRINT *aFootprint)
Definition: pcb_netlist.cpp:40
const wxString & GetName() const
Definition: pcb_netlist.h:118
void AddComponent(COMPONENT *aComponent)
Add aComponent to the NETLIST.
int Format(OUTPUTFORMATTER *aOut, int aNestLevel, int aCtl)
Definition: pcb_netlist.cpp:32
void SortByReference()
bool m_replaceFootprints
Definition: pcb_netlist.h:296
const LIB_ID & GetFPID() const
Definition: pcb_netlist.h:133
COMPONENT_NETS m_nets
list of nets shared by the component pins
Definition: pcb_netlist.h:163
Used to store the component pin name to net name (and pin function) associations stored in a netlist.
Definition: pcb_netlist.h:43
void SetReplaceFootprints(bool aReplace)
Definition: pcb_netlist.h:270
const wxString & GetNetName() const
Definition: pcb_netlist.h:58
Store information read from a netlist along with the flags used to update the NETLIST in the BOARD.
Definition: pcb_netlist.h:206
const LIB_ID & GetAltFPID() const
Definition: pcb_netlist.h:136
unsigned GetNetCount() const
Definition: pcb_netlist.h:109
bool m_findByTimeStamp
Definition: pcb_netlist.h:295
bool operator<(const COMPONENT_NET &aNet) const
Definition: pcb_netlist.h:64
void SetPinCount(int aPinCount)
Definition: pcb_netlist.h:145
const wxString & GetReference() const
Definition: pcb_netlist.h:123
wxString m_netName
Definition: pcb_netlist.h:73
#define CTL_FOR_CVPCB
Definition: pcb_netlist.h:285
const COMPONENT_NET & GetNet(unsigned aIndex) const
Definition: pcb_netlist.h:111
COMPONENT_NET(const wxString &aPinName, const wxString &aNetName, const wxString &aPinFunction, const wxString &aPinType)
Definition: pcb_netlist.h:48
const wxString & GetLibrary() const
Definition: pcb_netlist.h:121
std::map< wxString, wxString > m_properties
Component-specific properties found in the netlist.
Definition: pcb_netlist.h:193
Store all of the related footprint information found in a netlist.
Definition: pcb_netlist.h:84
const wxString & GetPinFunction() const
Definition: pcb_netlist.h:59
bool IsValid() const
Definition: pcb_netlist.h:62
COMPONENT * GetComponent(unsigned aIndex)
Return the COMPONENT at aIndex.
Definition: pcb_netlist.h:236
void SetFootprintFilters(const wxArrayString &aFilters)
Definition: pcb_netlist.h:142
wxString m_pinFunction
Definition: pcb_netlist.h:74
void Clear()
Remove all components from the netlist.
Definition: pcb_netlist.h:223
LIB_ID m_fpid
The LIB_ID of the footprint assigned to the component.
Definition: pcb_netlist.h:182
void SortPins()
Definition: pcb_netlist.h:115
COMPONENT(const LIB_ID &aFPID, const wxString &aReference, const wxString &aValue, const KIID_PATH &aPath, const std::vector< KIID > &aKiids)
Definition: pcb_netlist.h:87
void Format(const char *aDocName, OUTPUTFORMATTER *aOut, int aNestLevel, int aCtl=0)
bool GetReplaceFootprints() const
Definition: pcb_netlist.h:271
wxString m_value
The component value found in netlist.
Definition: pcb_netlist.h:167
void SetName(const wxString &aName)
Definition: pcb_netlist.h:117
int GetPinCount() const
Definition: pcb_netlist.h:146
void AddNet(const wxString &aPinName, const wxString &aNetName, const wxString &aPinFunction, const wxString &aPinType)
Definition: pcb_netlist.h:103
const wxString & GetPinName() const
Definition: pcb_netlist.h:57
wxString m_pinType
Definition: pcb_netlist.h:75
bool IsEmpty() const
Definition: pcb_netlist.h:218
const std::map< wxString, wxString > & GetProperties() const
Definition: pcb_netlist.h:130
const wxString & GetValue() const
Definition: pcb_netlist.h:124
const wxArrayString & GetFootprintFilters() const
Definition: pcb_netlist.h:143
COMPONENT * GetComponentByReference(const wxString &aReference)
Return a COMPONENT by aReference.
wxString m_reference
The component reference designator found in netlist.
Definition: pcb_netlist.h:166
std::vector< COMPONENT_NET > COMPONENT_NETS
Definition: pcb_netlist.h:79
boost::ptr_vector< COMPONENT > COMPONENTS
Definition: pcb_netlist.h:199
int m_pinCount
Number of pins found in netlist.
Definition: pcb_netlist.h:165
const KIID_PATH & GetPath() const
Definition: pcb_netlist.h:138
FOOTPRINT * GetFootprint(bool aRelease=false)
Definition: pcb_netlist.h:148
wxString m_pinName
Definition: pcb_netlist.h:72
const std::vector< KIID > & GetKIIDs() const
Definition: pcb_netlist.h:140