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 
49 {
50  wxString m_pinName;
51  wxString m_netName;
52 
53 public:
55 
56  COMPONENT_NET( const wxString& aPinName, const wxString& aNetName ) :
57  m_pinName( aPinName ), m_netName( aNetName )
58  {
59  }
60 
61  const wxString& GetPinName() const { return m_pinName; }
62 
63  const wxString& GetNetName() const { return m_netName; }
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 };
74 
75 
76 typedef std::vector< COMPONENT_NET > COMPONENT_NETS;
77 
78 
83 class COMPONENT
84 {
86  wxArrayString m_footprintFilters;
87  int m_pinCount;
88  wxString m_reference;
89  wxString m_value;
90 
91  // ZZZ This timestamp is string, not time_t
92  wxString m_timeStamp;
93 
95  wxString m_name;
96 
98  wxString m_library;
99 
102 
107 
109  std::unique_ptr< MODULE > m_footprint;
110 
113 
115 
116 public:
117  COMPONENT( const LIB_ID& aFPID,
118  const wxString& aReference,
119  const wxString& aValue,
120  const wxString& aTimeStamp )
121  {
122  m_fpid = aFPID;
123  m_reference = aReference;
124  m_value = aValue;
125  m_pinCount = 0;
126  m_timeStamp = aTimeStamp;
127  m_footprintChanged = false;
128  }
129 
130  virtual ~COMPONENT() { };
131 
132  void AddNet( const wxString& aPinName, const wxString& aNetName )
133  {
134  m_nets.push_back( COMPONENT_NET( aPinName, aNetName ) );
135  }
136 
137  unsigned GetNetCount() const { return m_nets.size(); }
138 
139  const COMPONENT_NET& GetNet( unsigned aIndex ) const { return m_nets[aIndex]; }
140 
141  const COMPONENT_NET& GetNet( const wxString& aPinName );
142 
143  void SortPins() { sort( m_nets.begin(), m_nets.end() ); }
144 
145  void SetName( const wxString& aName ) { m_name = aName;}
146  const wxString& GetName() const { return m_name; }
147 
148  void SetLibrary( const wxString& aLibrary ) { m_library = aLibrary; }
149  const wxString& GetLibrary() const { return m_library; }
150 
151  const wxString& GetReference() const { return m_reference; }
152 
153  const wxString& GetValue() const { return m_value; }
154 
155  void SetFPID( const LIB_ID& aFPID )
156  {
157  m_footprintChanged = !m_fpid.empty() && (m_fpid != aFPID);
158  m_fpid = aFPID;
159  }
160 
161  void SetAltFPID( const LIB_ID& aFPID )
162  {
163  m_altFpid = aFPID;
164  }
165 
166  const LIB_ID& GetFPID() const { return m_fpid; }
167 
168  const LIB_ID& GetAltFPID() const { return m_altFpid; }
169 
170  const wxString& GetTimeStamp() const { return m_timeStamp; }
171 
172  void SetFootprintFilters( const wxArrayString& aFilterList )
173  {
174  m_footprintFilters = aFilterList;
175  }
176 
177  const wxArrayString& GetFootprintFilters() const { return m_footprintFilters; }
178 
179  void SetPinCount( int aPinCount )
180  {
181  m_pinCount = aPinCount;
182  }
183 
184  int GetPinCount() const { return m_pinCount; }
185 
186  MODULE* GetModule( bool aRelease = false )
187  {
188  return ( aRelease ) ? m_footprint.release() : m_footprint.get();
189  }
190 
191  void SetModule( MODULE* aModule );
192 
193  bool IsLibSource( const wxString& aLibrary, const wxString& aName ) const
194  {
195  return aLibrary == m_library && aName == m_name;
196  }
197 
198  bool FootprintChanged() const { return m_footprintChanged; }
199 
200  void Format( OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl );
201 };
202 
203 
204 typedef boost::ptr_vector< COMPONENT > COMPONENTS;
205 typedef COMPONENTS::iterator COMPONENTS_ITER;
206 typedef COMPONENTS::const_iterator COMPONENTS_CITER;
207 
208 
214 class NETLIST
215 {
217 
220 
224 
227 
230 
231 public:
233  m_deleteExtraFootprints( false ),
234  m_isDryRun( false ),
235  m_findByTimeStamp( false ),
236  m_replaceFootprints( false )
237  {
238  }
239 
244  bool IsEmpty() const { return m_components.empty(); }
245 
250  void Clear() { m_components.clear(); }
251 
256  unsigned GetCount() const { return m_components.size(); }
257 
265  COMPONENT* GetComponent( unsigned aIndex ) { return &m_components[ aIndex ]; }
266 
276  void AddComponent( COMPONENT* aComponent );
277 
285  COMPONENT* GetComponentByReference( const wxString& aReference );
286 
294  COMPONENT* GetComponentByTimeStamp( const wxString& aTimeStamp );
295 
296  void SortByFPID();
297 
298  void SortByReference();
299 
300  void SetDeleteExtraFootprints( bool aDeleteExtraFootprints )
301  {
302  m_deleteExtraFootprints = aDeleteExtraFootprints;
303  }
304 
305  bool GetDeleteExtraFootprints() const { return m_deleteExtraFootprints; }
306 
307  void SetIsDryRun( bool aIsDryRun ) { m_isDryRun = aIsDryRun; }
308 
309  bool IsDryRun() const { return m_isDryRun; }
310 
311  void SetFindByTimeStamp( bool aFindByTimeStamp ) { m_findByTimeStamp = aFindByTimeStamp; }
312 
313  bool IsFindByTimeStamp() const { return m_findByTimeStamp; }
314 
315  void SetReplaceFootprints( bool aReplaceFootprints )
316  {
317  m_replaceFootprints = aReplaceFootprints;
318  }
319 
320  bool GetReplaceFootprints() const { return m_replaceFootprints; }
321 
326  bool AnyFootprintsLinked() const;
327 
332  bool AllFootprintsLinked() const;
333 
338  bool NoFootprintsLinked() const { return !AnyFootprintsLinked(); }
339 
345  bool AnyFootprintsChanged() const;
346 
347  void Format( const char* aDocName, OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl = 0 );
348 
349 #define CTL_OMIT_EXTRA (1<<0)
350 #define CTL_OMIT_NETS (1<<1)
351 #define CTL_OMIT_FILTERS (1<<2)
352 
353 #define CTL_FOR_BACKANNO (CTL_OMIT_NETS | CTL_OMIT_FILTERS | CTL_OMIT_EXTRA)
354 
356  {
357  Format( "back_annotation", aOut, 0, CTL_FOR_BACKANNO );
358  }
359 };
360 
361 
362 #endif // PCB_NETLIST_H
void SetAltFPID(const LIB_ID &aFPID)
Definition: pcb_netlist.h:161
const wxString & GetPinName() const
Definition: pcb_netlist.h:61
virtual ~COMPONENT()
Definition: pcb_netlist.h:130
wxString m_name
The name of the component in m_library used when it was placed on the schematic.. ...
Definition: pcb_netlist.h:95
bool empty() const
Definition: lib_id.h:173
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:106
const LIB_ID & GetFPID() const
Definition: pcb_netlist.h:166
bool IsLibSource(const wxString &aLibrary, const wxString &aName) const
Definition: pcb_netlist.h:193
wxString m_library
The name of the component library where m_name was found.
Definition: pcb_netlist.h:98
int GetPinCount() const
Definition: pcb_netlist.h:184
void SetFPID(const LIB_ID &aFPID)
Definition: pcb_netlist.h:155
const wxArrayString & GetFootprintFilters() const
Definition: pcb_netlist.h:177
MODULE * GetModule(bool aRelease=false)
Definition: pcb_netlist.h:186
COMPONENTS m_components
Components found in the netlist.
Definition: pcb_netlist.h:216
void SetLibrary(const wxString &aLibrary)
Definition: pcb_netlist.h:148
const wxString & GetLibrary() const
Definition: pcb_netlist.h:149
bool FootprintChanged() const
Definition: pcb_netlist.h:198
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:86
void SetFindByTimeStamp(bool aFindByTimeStamp)
Definition: pcb_netlist.h:311
bool IsValid() const
Definition: pcb_netlist.h:65
bool IsEmpty() const
Function IsEmpty()
Definition: pcb_netlist.h:244
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
static COMPONENT_NET m_emptyNet
Definition: pcb_netlist.h:114
int Format(OUTPUTFORMATTER *aOut, int aNestLevel, int aCtl)
Definition: pcb_netlist.cpp:39
bool m_replaceFootprints
Replace component footprints when they differ from the netlist if true.
Definition: pcb_netlist.h:229
const wxString & GetReference() const
Definition: pcb_netlist.h:151
COMPONENT_NETS m_nets
Definition: pcb_netlist.h:85
Class COMPONENT_NET is used to store the component pin name to net name associations stored in a netl...
Definition: pcb_netlist.h:48
const wxString & GetValue() const
Definition: pcb_netlist.h:153
bool GetDeleteExtraFootprints() const
Definition: pcb_netlist.h:305
void SetFootprintFilters(const wxArrayString &aFilterList)
Definition: pcb_netlist.h:172
wxString m_timeStamp
The component full time stamp found in netlist.
Definition: pcb_netlist.h:92
bool GetReplaceFootprints() const
Definition: pcb_netlist.h:320
void SetReplaceFootprints(bool aReplaceFootprints)
Definition: pcb_netlist.h:315
Class NETLIST stores all of information read from a netlist along with the flags used to update the N...
Definition: pcb_netlist.h:214
COMPONENT_NET(const wxString &aPinName, const wxString &aNetName)
Definition: pcb_netlist.h:56
bool NoFootprintsLinked() const
Function NoFootprintsLinked.
Definition: pcb_netlist.h:338
bool m_findByTimeStamp
Find component by time stamp if true or reference designator if false.
Definition: pcb_netlist.h:226
bool m_isDryRun
Do not actually make any changes.
Definition: pcb_netlist.h:223
void SetPinCount(int aPinCount)
Definition: pcb_netlist.h:179
const wxString & GetNetName() const
Definition: pcb_netlist.h:63
bool IsFindByTimeStamp() const
Definition: pcb_netlist.h:313
void SetIsDryRun(bool aIsDryRun)
Definition: pcb_netlist.h:307
bool m_deleteExtraFootprints
Remove footprints from BOARD not found in netlist when true.
Definition: pcb_netlist.h:219
const wxString & GetTimeStamp() const
Definition: pcb_netlist.h:170
wxString m_netName
Definition: pcb_netlist.h:51
void FormatBackAnnotation(OUTPUTFORMATTER *aOut)
Definition: pcb_netlist.h:355
Class COMPONENT is used to store components and all of their related information found in a netlist...
Definition: pcb_netlist.h:83
bool operator<(const COMPONENT_NET &aNet) const
Definition: pcb_netlist.h:67
COMPONENT * GetComponent(unsigned aIndex)
Function GetComponent returns the COMPONENT at aIndex.
Definition: pcb_netlist.h:265
bool m_footprintChanged
Set to true if m_fpid was changed when the footprint link file was read.
Definition: pcb_netlist.h:112
const LIB_ID & GetAltFPID() const
Definition: pcb_netlist.h:168
void Clear()
Function Clear removes all components from the netlist.
Definition: pcb_netlist.h:250
const wxString & GetName() const
Definition: pcb_netlist.h:146
LIB_ID m_fpid
The LIB_ID of the footprint assigned to the component.
Definition: pcb_netlist.h:101
void SortPins()
Definition: pcb_netlist.h:143
wxString m_value
The component value found in netlist.
Definition: pcb_netlist.h:89
void SetName(const wxString &aName)
Definition: pcb_netlist.h:145
#define CTL_FOR_BACKANNO
Definition: pcb_netlist.h:353
void AddNet(const wxString &aPinName, const wxString &aNetName)
Definition: pcb_netlist.h:132
const COMPONENT_NET & GetNet(unsigned aIndex) const
Definition: pcb_netlist.h:139
wxString m_reference
The component reference designator found in netlist.
Definition: pcb_netlist.h:88
std::vector< COMPONENT_NET > COMPONENT_NETS
Definition: pcb_netlist.h:76
bool IsDryRun() const
Definition: pcb_netlist.h:309
Module description (excepted pads)
void SetDeleteExtraFootprints(bool aDeleteExtraFootprints)
Definition: pcb_netlist.h:300
boost::ptr_vector< COMPONENT > COMPONENTS
Definition: pcb_netlist.h:204
int m_pinCount
Number of pins found in netlist.
Definition: pcb_netlist.h:87
std::unique_ptr< MODULE > m_footprint
The MODULE loaded for m_fpid.
Definition: pcb_netlist.h:109
unsigned GetCount() const
Function GetCount.
Definition: pcb_netlist.h:256
COMPONENTS::const_iterator COMPONENTS_CITER
Definition: pcb_netlist.h:206
unsigned GetNetCount() const
Definition: pcb_netlist.h:137
COMPONENTS::iterator COMPONENTS_ITER
Definition: pcb_netlist.h:205
COMPONENT(const LIB_ID &aFPID, const wxString &aReference, const wxString &aValue, const wxString &aTimeStamp)
Definition: pcb_netlist.h:117
wxString m_pinName
Definition: pcb_netlist.h:50