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-2017 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 
34 #include <boost/ptr_container/ptr_vector.hpp>
35 #include <wx/arrstr.h>
36 
37 #include <lib_id.h>
38 #include <class_module.h>
39 
40 
41 class REPORTER;
42 
43 
50 {
51  wxString m_pinName;
52  wxString m_netName;
53  wxString m_pinFunction;
54 
55 public:
57 
58  COMPONENT_NET( const wxString& aPinName, const wxString& aNetName,
59  const wxString& aPinFunction ) :
60  m_pinName( aPinName ), m_netName( aNetName ), m_pinFunction( aPinFunction )
61  {
62  }
63 
64  const wxString& GetPinName() const { return m_pinName; }
65  const wxString& GetNetName() const { return m_netName; }
66  const wxString& GetPinFunction() const { return m_pinFunction; }
67 
68  bool IsValid() const { return !m_pinName.IsEmpty(); }
69 
70  bool operator <( const COMPONENT_NET& aNet ) const
71  {
72  return m_pinName < aNet.m_pinName;
73  }
74 
75  int Format( OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl );
76 };
77 
78 
79 typedef std::vector< COMPONENT_NET > COMPONENT_NETS;
80 
85 class COMPONENT
86 {
88  wxArrayString m_footprintFilters;
89  int m_pinCount;
90  wxString m_reference;
91  wxString m_value;
92 
93  // ZZZ This timestamp is string, not time_t
94  wxString m_timeStamp;
95 
97  wxString m_name;
98 
100  wxString m_library;
101 
104 
105 
110 
112  std::unique_ptr< MODULE > m_footprint;
113 
116 
118 
119 public:
120  COMPONENT( const LIB_ID& aFPID,
121  const wxString& aReference,
122  const wxString& aValue,
123  const wxString& aTimeStamp )
124  {
125  m_fpid = aFPID;
126  m_reference = aReference;
127  m_value = aValue;
128  m_pinCount = 0;
129  m_timeStamp = aTimeStamp;
130  m_footprintChanged = false;
131  }
132 
133  virtual ~COMPONENT() { };
134 
135  void AddNet( const wxString& aPinName, const wxString& aNetName, const wxString& aPinFunction )
136  {
137  m_nets.push_back( COMPONENT_NET( aPinName, aNetName, aPinFunction ) );
138  }
139 
140  unsigned GetNetCount() const { return m_nets.size(); }
141 
142  const COMPONENT_NET& GetNet( unsigned aIndex ) const { return m_nets[aIndex]; }
143 
144  const COMPONENT_NET& GetNet( const wxString& aPinName );
145 
146  void SortPins() { sort( m_nets.begin(), m_nets.end() ); }
147 
148  void SetName( const wxString& aName ) { m_name = aName;}
149  const wxString& GetName() const { return m_name; }
150 
151  void SetLibrary( const wxString& aLibrary ) { m_library = aLibrary; }
152  const wxString& GetLibrary() const { return m_library; }
153 
154  const wxString& GetReference() const { return m_reference; }
155 
156  const wxString& GetValue() const { return m_value; }
157 
158  void SetFPID( const LIB_ID& aFPID )
159  {
160  m_footprintChanged = !m_fpid.empty() && (m_fpid != aFPID);
161  m_fpid = aFPID;
162  }
163 
164  void SetAltFPID( const LIB_ID& aFPID )
165  {
166  m_altFpid = aFPID;
167  }
168 
169  const LIB_ID& GetFPID() const { return m_fpid; }
170 
171  const LIB_ID& GetAltFPID() const { return m_altFpid; }
172 
173  const wxString& GetTimeStamp() const { return m_timeStamp; }
174 
175  void SetFootprintFilters( const wxArrayString& aFilterList )
176  {
177  m_footprintFilters = aFilterList;
178  }
179 
180  const wxArrayString& GetFootprintFilters() const { return m_footprintFilters; }
181 
182  void SetPinCount( int aPinCount )
183  {
184  m_pinCount = aPinCount;
185  }
186 
187  int GetPinCount() const { return m_pinCount; }
188 
189  MODULE* GetModule( bool aRelease = false )
190  {
191  return ( aRelease ) ? m_footprint.release() : m_footprint.get();
192  }
193 
194  void SetModule( MODULE* aModule );
195 
196  bool IsLibSource( const wxString& aLibrary, const wxString& aName ) const
197  {
198  return aLibrary == m_library && aName == m_name;
199  }
200 
201  bool FootprintChanged() const { return m_footprintChanged; }
202 
203  void Format( OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl );
204 };
205 
206 
207 typedef boost::ptr_vector< COMPONENT > COMPONENTS;
208 typedef COMPONENTS::iterator COMPONENTS_ITER;
209 typedef COMPONENTS::const_iterator COMPONENTS_CITER;
210 
211 
217 class NETLIST
218 {
220 
223 
227 
230 
233 
234 public:
236  m_deleteExtraFootprints( false ),
237  m_isDryRun( false ),
238  m_findByTimeStamp( false ),
239  m_replaceFootprints( false )
240  {
241  }
242 
247  bool IsEmpty() const { return m_components.empty(); }
248 
253  void Clear() { m_components.clear(); }
254 
259  unsigned GetCount() const { return m_components.size(); }
260 
268  COMPONENT* GetComponent( unsigned aIndex ) { return &m_components[ aIndex ]; }
269 
279  void AddComponent( COMPONENT* aComponent );
280 
288  COMPONENT* GetComponentByReference( const wxString& aReference );
289 
297  COMPONENT* GetComponentByTimeStamp( const wxString& aTimeStamp );
298 
299  void SortByFPID();
300 
301  void SortByReference();
302 
303  void SetDeleteExtraFootprints( bool aDeleteExtraFootprints )
304  {
305  m_deleteExtraFootprints = aDeleteExtraFootprints;
306  }
307 
309 
310  void SetIsDryRun( bool aIsDryRun ) { m_isDryRun = aIsDryRun; }
311 
312  bool IsDryRun() const { return m_isDryRun; }
313 
314  void SetFindByTimeStamp( bool aFindByTimeStamp ) { m_findByTimeStamp = aFindByTimeStamp; }
315 
316  bool IsFindByTimeStamp() const { return m_findByTimeStamp; }
317 
318  void SetReplaceFootprints( bool aReplaceFootprints )
319  {
320  m_replaceFootprints = aReplaceFootprints;
321  }
322 
323  bool GetReplaceFootprints() const { return m_replaceFootprints; }
324 
329  bool AnyFootprintsLinked() const;
330 
335  bool AllFootprintsLinked() const;
336 
341  bool NoFootprintsLinked() const { return !AnyFootprintsLinked(); }
342 
348  bool AnyFootprintsChanged() const;
349 
350  void Format( const char* aDocName, OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl = 0 );
351 
352 #define CTL_OMIT_EXTRA (1<<0)
353 #define CTL_OMIT_NETS (1<<1)
354 #define CTL_OMIT_FILTERS (1<<2)
355 
356 #define CTL_FOR_BACKANNO (CTL_OMIT_NETS | CTL_OMIT_FILTERS | CTL_OMIT_EXTRA)
357 
359  {
360  Format( "back_annotation", aOut, 0, CTL_FOR_BACKANNO );
361  }
362 };
363 
364 
365 #endif // PCB_NETLIST_H
bool IsLibSource(const wxString &aLibrary, const wxString &aName) const
Definition: pcb_netlist.h:196
void SetAltFPID(const LIB_ID &aFPID)
Definition: pcb_netlist.h:164
void SortByFPID()
virtual ~COMPONENT()
Definition: pcb_netlist.h:133
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:97
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:109
wxString m_library
The name of the component library where m_name was found.
Definition: pcb_netlist.h:100
void SetFPID(const LIB_ID &aFPID)
Definition: pcb_netlist.h:158
bool AnyFootprintsLinked() const
Function AnyFootprintsLinked.
MODULE * GetModule(bool aRelease=false)
Definition: pcb_netlist.h:189
bool IsFindByTimeStamp() const
Definition: pcb_netlist.h:316
COMPONENTS m_components
Components found in the netlist.
Definition: pcb_netlist.h:219
void SetLibrary(const wxString &aLibrary)
Definition: pcb_netlist.h:151
bool NoFootprintsLinked() const
Function NoFootprintsLinked.
Definition: pcb_netlist.h:341
Class OUTPUTFORMATTER is an important interface (abstract class) used to output 8 bit text in a conve...
Definition: richio.h:327
wxArrayString m_footprintFilters
Footprint filters found in netlist.
Definition: pcb_netlist.h:88
unsigned GetCount() const
Function GetCount.
Definition: pcb_netlist.h:259
void SetFindByTimeStamp(bool aFindByTimeStamp)
Definition: pcb_netlist.h:314
bool FootprintChanged() const
Definition: pcb_netlist.h:201
Class REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:61
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:117
const wxString & GetName() const
Definition: pcb_netlist.h:149
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:232
const LIB_ID & GetFPID() const
Definition: pcb_netlist.h:169
COMPONENT_NETS m_nets
list of nets shared by the component pins
Definition: pcb_netlist.h:87
Class COMPONENT_NET is used to store the component pin name to net name (and pin function) associatio...
Definition: pcb_netlist.h:49
bool GetDeleteExtraFootprints() const
Definition: pcb_netlist.h:308
void SetFootprintFilters(const wxArrayString &aFilterList)
Definition: pcb_netlist.h:175
const wxString & GetNetName() const
Definition: pcb_netlist.h:65
bool IsDryRun() const
Definition: pcb_netlist.h:312
wxString m_timeStamp
The component full time stamp found in netlist.
Definition: pcb_netlist.h:94
void SetReplaceFootprints(bool aReplaceFootprints)
Definition: pcb_netlist.h:318
Class NETLIST stores all of information read from a netlist along with the flags used to update the N...
Definition: pcb_netlist.h:217
const LIB_ID & GetAltFPID() const
Definition: pcb_netlist.h:171
unsigned GetNetCount() const
Definition: pcb_netlist.h:140
bool m_findByTimeStamp
Find component by time stamp if true or reference designator if false.
Definition: pcb_netlist.h:229
bool m_isDryRun
Do not actually make any changes.
Definition: pcb_netlist.h:226
bool operator<(const COMPONENT_NET &aNet) const
Definition: pcb_netlist.h:70
void SetPinCount(int aPinCount)
Definition: pcb_netlist.h:182
bool AllFootprintsLinked() const
Function AllFootprintsLinked.
const wxString & GetReference() const
Definition: pcb_netlist.h:154
void SetIsDryRun(bool aIsDryRun)
Definition: pcb_netlist.h:310
bool m_deleteExtraFootprints
Remove footprints from BOARD not found in netlist when true.
Definition: pcb_netlist.h:222
wxString m_netName
Definition: pcb_netlist.h:52
const COMPONENT_NET & GetNet(unsigned aIndex) const
Definition: pcb_netlist.h:142
void FormatBackAnnotation(OUTPUTFORMATTER *aOut)
Definition: pcb_netlist.h:358
const wxString & GetLibrary() const
Definition: pcb_netlist.h:152
Class COMPONENT is used to store components and all of their related information found in a netlist.
Definition: pcb_netlist.h:85
const wxString & GetPinFunction() const
Definition: pcb_netlist.h:66
bool IsValid() const
Definition: pcb_netlist.h:68
COMPONENT * GetComponent(unsigned aIndex)
Function GetComponent returns the COMPONENT at aIndex.
Definition: pcb_netlist.h:268
bool m_footprintChanged
Set to true if m_fpid was changed when the footprint link file was read.
Definition: pcb_netlist.h:115
wxString m_pinFunction
Definition: pcb_netlist.h:53
void Clear()
Function Clear removes all components from the netlist.
Definition: pcb_netlist.h:253
LIB_ID m_fpid
The LIB_ID of the footprint assigned to the component.
Definition: pcb_netlist.h:103
void SortPins()
Definition: pcb_netlist.h:146
void Format(const char *aDocName, OUTPUTFORMATTER *aOut, int aNestLevel, int aCtl=0)
bool GetReplaceFootprints() const
Definition: pcb_netlist.h:323
wxString m_value
The component value found in netlist.
Definition: pcb_netlist.h:91
void SetName(const wxString &aName)
Definition: pcb_netlist.h:148
#define CTL_FOR_BACKANNO
Definition: pcb_netlist.h:356
int GetPinCount() const
Definition: pcb_netlist.h:187
const wxString & GetPinName() const
Definition: pcb_netlist.h:64
bool IsEmpty() const
Function IsEmpty()
Definition: pcb_netlist.h:247
const wxString & GetValue() const
Definition: pcb_netlist.h:156
const wxArrayString & GetFootprintFilters() const
Definition: pcb_netlist.h:180
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:90
std::vector< COMPONENT_NET > COMPONENT_NETS
Definition: pcb_netlist.h:79
void SetModule(MODULE *aModule)
Definition: pcb_netlist.cpp:47
Module description (excepted pads)
void SetDeleteExtraFootprints(bool aDeleteExtraFootprints)
Definition: pcb_netlist.h:303
boost::ptr_vector< COMPONENT > COMPONENTS
Definition: pcb_netlist.h:207
COMPONENT_NET(const wxString &aPinName, const wxString &aNetName, const wxString &aPinFunction)
Definition: pcb_netlist.h:58
int m_pinCount
Number of pins found in netlist.
Definition: pcb_netlist.h:89
std::unique_ptr< MODULE > m_footprint
The MODULE loaded for m_fpid.
Definition: pcb_netlist.h:112
bool AnyFootprintsChanged() const
Function AnyFootprintsChanged.
COMPONENTS::const_iterator COMPONENTS_CITER
Definition: pcb_netlist.h:209
void AddNet(const wxString &aPinName, const wxString &aNetName, const wxString &aPinFunction)
Definition: pcb_netlist.h:135
COMPONENTS::iterator COMPONENTS_ITER
Definition: pcb_netlist.h:208
const wxString & GetTimeStamp() const
Definition: pcb_netlist.h:173
COMPONENT(const LIB_ID &aFPID, const wxString &aReference, const wxString &aValue, const wxString &aTimeStamp)
Definition: pcb_netlist.h:120
wxString m_pinName
Definition: pcb_netlist.h:51
COMPONENT * GetComponentByTimeStamp(const wxString &aTimeStamp)
Function GetComponentByTimeStamp returns a COMPONENT by aTimeStamp.