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@verizon.net>.
6  * Copyright (C) 2012-2020 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 <class_module.h>
34 
35 
36 class REPORTER;
37 
38 
45 {
46  wxString m_pinName;
47  wxString m_netName;
48  wxString m_pinFunction;
49 
50 public:
52 
53  COMPONENT_NET( const wxString& aPinName, const wxString& aNetName,
54  const wxString& aPinFunction ) :
55  m_pinName( aPinName ), m_netName( aNetName ), m_pinFunction( aPinFunction )
56  {
57  }
58 
59  const wxString& GetPinName() const { return m_pinName; }
60  const wxString& GetNetName() const { return m_netName; }
61  const wxString& GetPinFunction() const { return m_pinFunction; }
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 };
72 
73 
74 typedef std::vector< COMPONENT_NET > COMPONENT_NETS;
75 
80 class COMPONENT
81 {
83  wxArrayString m_footprintFilters;
84  int m_pinCount;
85  wxString m_reference;
86  wxString m_value;
87 
90 
92  wxString m_name;
93 
95  wxString m_library;
96 
99 
100 
105 
107  std::unique_ptr< MODULE > m_footprint;
108 
111 
113 
114 public:
115  COMPONENT( const LIB_ID& aFPID,
116  const wxString& aReference,
117  const wxString& aValue,
118  const KIID_PATH& aPath )
119  {
120  m_fpid = aFPID;
121  m_reference = aReference;
122  m_value = aValue;
123  m_pinCount = 0;
124  m_path = aPath;
125  m_footprintChanged = false;
126  }
127 
128  virtual ~COMPONENT() { };
129 
130  void AddNet( const wxString& aPinName, const wxString& aNetName, const wxString& aPinFunction )
131  {
132  m_nets.push_back( COMPONENT_NET( aPinName, aNetName, aPinFunction ) );
133  }
134 
135  unsigned GetNetCount() const { return m_nets.size(); }
136 
137  const COMPONENT_NET& GetNet( unsigned aIndex ) const { return m_nets[aIndex]; }
138 
139  const COMPONENT_NET& GetNet( const wxString& aPinName ) const;
140 
141  void SortPins() { sort( m_nets.begin(), m_nets.end() ); }
142 
143  void SetName( const wxString& aName ) { m_name = aName;}
144  const wxString& GetName() const { return m_name; }
145 
146  void SetLibrary( const wxString& aLibrary ) { m_library = aLibrary; }
147  const wxString& GetLibrary() const { return m_library; }
148 
149  const wxString& GetReference() const { return m_reference; }
150 
151  const wxString& GetValue() const { return m_value; }
152 
153  void SetFPID( const LIB_ID& aFPID )
154  {
155  m_footprintChanged = !m_fpid.empty() && (m_fpid != aFPID);
156  m_fpid = aFPID;
157  }
158 
159  void SetAltFPID( const LIB_ID& aFPID )
160  {
161  m_altFpid = aFPID;
162  }
163 
164  const LIB_ID& GetFPID() const { return m_fpid; }
165 
166  const LIB_ID& GetAltFPID() const { return m_altFpid; }
167 
168  const KIID_PATH& GetPath() const { return m_path; }
169 
170  void SetFootprintFilters( const wxArrayString& aFilterList )
171  {
172  m_footprintFilters = aFilterList;
173  }
174 
175  const wxArrayString& GetFootprintFilters() const { return m_footprintFilters; }
176 
177  void SetPinCount( int aPinCount )
178  {
179  m_pinCount = aPinCount;
180  }
181 
182  int GetPinCount() const { return m_pinCount; }
183 
184  MODULE* GetModule( bool aRelease = false )
185  {
186  return ( aRelease ) ? m_footprint.release() : m_footprint.get();
187  }
188 
189  void SetModule( MODULE* aModule );
190 
191  bool IsLibSource( const wxString& aLibrary, const wxString& aName ) const
192  {
193  return aLibrary == m_library && aName == m_name;
194  }
195 
196  bool FootprintChanged() const { return m_footprintChanged; }
197 
198  void Format( OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl );
199 };
200 
201 
202 typedef boost::ptr_vector< COMPONENT > COMPONENTS;
203 typedef COMPONENTS::iterator COMPONENTS_ITER;
204 typedef COMPONENTS::const_iterator COMPONENTS_CITER;
205 
206 
212 class NETLIST
213 {
215 
218 
222 
225 
228 
229 public:
231  m_deleteExtraFootprints( false ),
232  m_isDryRun( false ),
233  m_findByTimeStamp( false ),
234  m_replaceFootprints( false )
235  {
236  }
237 
242  bool IsEmpty() const { return m_components.empty(); }
243 
248  void Clear() { m_components.clear(); }
249 
254  unsigned GetCount() const { return m_components.size(); }
255 
263  COMPONENT* GetComponent( unsigned aIndex ) { return &m_components[ aIndex ]; }
264 
274  void AddComponent( COMPONENT* aComponent );
275 
283  COMPONENT* GetComponentByReference( const wxString& aReference );
284 
292  COMPONENT* GetComponentByPath( const KIID_PATH& aPath );
293 
294  void SortByFPID();
295 
296  void SortByReference();
297 
298  void SetDeleteExtraFootprints( bool aDeleteExtraFootprints )
299  {
300  m_deleteExtraFootprints = aDeleteExtraFootprints;
301  }
302 
304 
305  void SetIsDryRun( bool aIsDryRun ) { m_isDryRun = aIsDryRun; }
306 
307  bool IsDryRun() const { return m_isDryRun; }
308 
309  void SetFindByTimeStamp( bool aFindByTimeStamp ) { m_findByTimeStamp = aFindByTimeStamp; }
310 
311  bool IsFindByTimeStamp() const { return m_findByTimeStamp; }
312 
313  void SetReplaceFootprints( bool aReplaceFootprints )
314  {
315  m_replaceFootprints = aReplaceFootprints;
316  }
317 
318  bool GetReplaceFootprints() const { return m_replaceFootprints; }
319 
324  bool AnyFootprintsLinked() const;
325 
330  bool AllFootprintsLinked() const;
331 
336  bool NoFootprintsLinked() const { return !AnyFootprintsLinked(); }
337 
343  bool AnyFootprintsChanged() const;
344 
345  void Format( const char* aDocName, OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl = 0 );
346 
347 #define CTL_OMIT_EXTRA (1<<0)
348 #define CTL_OMIT_NETS (1<<1)
349 #define CTL_OMIT_FILTERS (1<<2)
350 
351 #define CTL_FOR_BACKANNO (CTL_OMIT_NETS | CTL_OMIT_FILTERS | CTL_OMIT_EXTRA)
352 
354  {
355  Format( "back_annotation", aOut, 0, CTL_FOR_BACKANNO );
356  }
357 };
358 
359 
360 #endif // PCB_NETLIST_H
bool IsLibSource(const wxString &aLibrary, const wxString &aName) const
Definition: pcb_netlist.h:191
void SetAltFPID(const LIB_ID &aFPID)
Definition: pcb_netlist.h:159
KIID_PATH m_path
A fully specified path to the component: [ sheetUUID, sheetUUID, .., componentUUID ].
Definition: pcb_netlist.h:89
void SortByFPID()
virtual ~COMPONENT()
Definition: pcb_netlist.h:128
void Format(OUTPUTFORMATTER *aOut, int aNestLevel, int aCtl)
Definition: pcb_netlist.cpp:76
wxString m_name
The name of the component in m_library used when it was placed on the schematic..
Definition: pcb_netlist.h:92
COMPONENT * GetComponentByPath(const KIID_PATH &aPath)
Function GetComponentByPath returns 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:104
wxString m_library
The name of the component library where m_name was found.
Definition: pcb_netlist.h:95
void SetFPID(const LIB_ID &aFPID)
Definition: pcb_netlist.h:153
bool AnyFootprintsLinked() const
Function AnyFootprintsLinked.
MODULE * GetModule(bool aRelease=false)
Definition: pcb_netlist.h:184
bool IsFindByTimeStamp() const
Definition: pcb_netlist.h:311
COMPONENTS m_components
Components found in the netlist.
Definition: pcb_netlist.h:214
void SetLibrary(const wxString &aLibrary)
Definition: pcb_netlist.h:146
bool NoFootprintsLinked() const
Function NoFootprintsLinked.
Definition: pcb_netlist.h:336
OUTPUTFORMATTER is an important interface (abstract class) used to output 8 bit text in a convenient ...
Definition: richio.h:327
wxArrayString m_footprintFilters
Footprint filters found in netlist.
Definition: pcb_netlist.h:83
unsigned GetCount() const
Function GetCount.
Definition: pcb_netlist.h:254
void SetFindByTimeStamp(bool aFindByTimeStamp)
Definition: pcb_netlist.h:309
bool FootprintChanged() const
Definition: pcb_netlist.h:196
REPORTER is 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
bool empty() const
Definition: lib_id.h:186
static COMPONENT_NET m_emptyNet
Definition: pcb_netlist.h:112
const wxString & GetName() const
Definition: pcb_netlist.h:144
void AddComponent(COMPONENT *aComponent)
Function AddComponent adds aComponent to the NETLIST.
int Format(OUTPUTFORMATTER *aOut, int aNestLevel, int aCtl)
Definition: pcb_netlist.cpp:39
void SortByReference()
bool m_replaceFootprints
Replace component footprints when they differ from the netlist if true.
Definition: pcb_netlist.h:227
const LIB_ID & GetFPID() const
Definition: pcb_netlist.h:164
COMPONENT_NETS m_nets
list of nets shared by the component pins
Definition: pcb_netlist.h:82
COMPONENT_NET is used to store the component pin name to net name (and pin function) associations sto...
Definition: pcb_netlist.h:44
bool GetDeleteExtraFootprints() const
Definition: pcb_netlist.h:303
void SetFootprintFilters(const wxArrayString &aFilterList)
Definition: pcb_netlist.h:170
const wxString & GetNetName() const
Definition: pcb_netlist.h:60
bool IsDryRun() const
Definition: pcb_netlist.h:307
void SetReplaceFootprints(bool aReplaceFootprints)
Definition: pcb_netlist.h:313
NETLIST stores all of information read from a netlist along with the flags used to update the NETLIST...
Definition: pcb_netlist.h:212
const LIB_ID & GetAltFPID() const
Definition: pcb_netlist.h:166
unsigned GetNetCount() const
Definition: pcb_netlist.h:135
bool m_findByTimeStamp
Find component by time stamp if true or reference designator if false.
Definition: pcb_netlist.h:224
bool m_isDryRun
Do not actually make any changes.
Definition: pcb_netlist.h:221
bool operator<(const COMPONENT_NET &aNet) const
Definition: pcb_netlist.h:65
void SetPinCount(int aPinCount)
Definition: pcb_netlist.h:177
bool AllFootprintsLinked() const
Function AllFootprintsLinked.
const wxString & GetReference() const
Definition: pcb_netlist.h:149
void SetIsDryRun(bool aIsDryRun)
Definition: pcb_netlist.h:305
bool m_deleteExtraFootprints
Remove footprints from BOARD not found in netlist when true.
Definition: pcb_netlist.h:217
wxString m_netName
Definition: pcb_netlist.h:47
const COMPONENT_NET & GetNet(unsigned aIndex) const
Definition: pcb_netlist.h:137
void FormatBackAnnotation(OUTPUTFORMATTER *aOut)
Definition: pcb_netlist.h:353
const wxString & GetLibrary() const
Definition: pcb_netlist.h:147
COMPONENT is used to store components and all of their related information found in a netlist.
Definition: pcb_netlist.h:80
const wxString & GetPinFunction() const
Definition: pcb_netlist.h:61
bool IsValid() const
Definition: pcb_netlist.h:63
COMPONENT * GetComponent(unsigned aIndex)
Function GetComponent returns the COMPONENT at aIndex.
Definition: pcb_netlist.h:263
bool m_footprintChanged
Set to true if m_fpid was changed when the footprint link file was read.
Definition: pcb_netlist.h:110
wxString m_pinFunction
Definition: pcb_netlist.h:48
void Clear()
Function Clear removes all components from the netlist.
Definition: pcb_netlist.h:248
LIB_ID m_fpid
The LIB_ID of the footprint assigned to the component.
Definition: pcb_netlist.h:98
void SortPins()
Definition: pcb_netlist.h:141
void Format(const char *aDocName, OUTPUTFORMATTER *aOut, int aNestLevel, int aCtl=0)
bool GetReplaceFootprints() const
Definition: pcb_netlist.h:318
wxString m_value
The component value found in netlist.
Definition: pcb_netlist.h:86
void SetName(const wxString &aName)
Definition: pcb_netlist.h:143
#define CTL_FOR_BACKANNO
Definition: pcb_netlist.h:351
int GetPinCount() const
Definition: pcb_netlist.h:182
const wxString & GetPinName() const
Definition: pcb_netlist.h:59
bool IsEmpty() const
Function IsEmpty()
Definition: pcb_netlist.h:242
COMPONENT(const LIB_ID &aFPID, const wxString &aReference, const wxString &aValue, const KIID_PATH &aPath)
Definition: pcb_netlist.h:115
const wxString & GetValue() const
Definition: pcb_netlist.h:151
const wxArrayString & GetFootprintFilters() const
Definition: pcb_netlist.h:175
COMPONENT * GetComponentByReference(const wxString &aReference)
Function GetComponentByReference returns a COMPONENT by aReference.
wxString m_reference
The component reference designator found in netlist.
Definition: pcb_netlist.h:85
std::vector< COMPONENT_NET > COMPONENT_NETS
Definition: pcb_netlist.h:74
void SetModule(MODULE *aModule)
Definition: pcb_netlist.cpp:47
void SetDeleteExtraFootprints(bool aDeleteExtraFootprints)
Definition: pcb_netlist.h:298
boost::ptr_vector< COMPONENT > COMPONENTS
Definition: pcb_netlist.h:202
COMPONENT_NET(const wxString &aPinName, const wxString &aNetName, const wxString &aPinFunction)
Definition: pcb_netlist.h:53
int m_pinCount
Number of pins found in netlist.
Definition: pcb_netlist.h:84
std::unique_ptr< MODULE > m_footprint
The MODULE loaded for m_fpid.
Definition: pcb_netlist.h:107
bool AnyFootprintsChanged() const
Function AnyFootprintsChanged.
COMPONENTS::const_iterator COMPONENTS_CITER
Definition: pcb_netlist.h:204
void AddNet(const wxString &aPinName, const wxString &aNetName, const wxString &aPinFunction)
Definition: pcb_netlist.h:130
const KIID_PATH & GetPath() const
Definition: pcb_netlist.h:168
COMPONENTS::iterator COMPONENTS_ITER
Definition: pcb_netlist.h:203
wxString m_pinName
Definition: pcb_netlist.h:46