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  wxString m_reference;
88  wxString m_value;
89 
90  // ZZZ This timestamp is string, not time_t
91  wxString m_timeStamp;
92 
94  wxString m_name;
95 
97  wxString m_library;
98 
101 
106 
108  std::unique_ptr< MODULE > m_footprint;
109 
112 
114 
115 public:
116  COMPONENT( const LIB_ID& aFPID,
117  const wxString& aReference,
118  const wxString& aValue,
119  const wxString& aTimeStamp )
120  {
121  m_fpid = aFPID;
122  m_reference = aReference;
123  m_value = aValue;
124  m_timeStamp = aTimeStamp;
125  m_footprintChanged = false;
126  }
127 
128  virtual ~COMPONENT() { };
129 
130  void AddNet( const wxString& aPinName, const wxString& aNetName )
131  {
132  m_nets.push_back( COMPONENT_NET( aPinName, aNetName ) );
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 );
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 wxString& GetTimeStamp() const { return m_timeStamp; }
169 
170  void SetFootprintFilters( const wxArrayString& aFilterList )
171  {
172  m_footprintFilters = aFilterList;
173  }
174 
175  const wxArrayString& GetFootprintFilters() const { return m_footprintFilters; }
176 
177  MODULE* GetModule( bool aRelease = false )
178  {
179  return ( aRelease ) ? m_footprint.release() : m_footprint.get();
180  }
181 
182  void SetModule( MODULE* aModule );
183 
184  bool IsLibSource( const wxString& aLibrary, const wxString& aName ) const
185  {
186  return aLibrary == m_library && aName == m_name;
187  }
188 
189  bool FootprintChanged() const { return m_footprintChanged; }
190 
191  void Format( OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl );
192 };
193 
194 
195 typedef boost::ptr_vector< COMPONENT > COMPONENTS;
196 typedef COMPONENTS::iterator COMPONENTS_ITER;
197 typedef COMPONENTS::const_iterator COMPONENTS_CITER;
198 
199 
205 class NETLIST
206 {
208 
211 
215 
218 
221 
222 public:
224  m_deleteExtraFootprints( false ),
225  m_isDryRun( false ),
226  m_findByTimeStamp( false ),
227  m_replaceFootprints( false )
228  {
229  }
230 
235  bool IsEmpty() const { return m_components.empty(); }
236 
241  void Clear() { m_components.clear(); }
242 
247  unsigned GetCount() const { return m_components.size(); }
248 
256  COMPONENT* GetComponent( unsigned aIndex ) { return &m_components[ aIndex ]; }
257 
267  void AddComponent( COMPONENT* aComponent );
268 
276  COMPONENT* GetComponentByReference( const wxString& aReference );
277 
285  COMPONENT* GetComponentByTimeStamp( const wxString& aTimeStamp );
286 
287  void SortByFPID();
288 
289  void SortByReference();
290 
291  void SetDeleteExtraFootprints( bool aDeleteExtraFootprints )
292  {
293  m_deleteExtraFootprints = aDeleteExtraFootprints;
294  }
295 
297 
298  void SetIsDryRun( bool aIsDryRun ) { m_isDryRun = aIsDryRun; }
299 
300  bool IsDryRun() const { return m_isDryRun; }
301 
302  void SetFindByTimeStamp( bool aFindByTimeStamp ) { m_findByTimeStamp = aFindByTimeStamp; }
303 
304  bool IsFindByTimeStamp() const { return m_findByTimeStamp; }
305 
306  void SetReplaceFootprints( bool aReplaceFootprints )
307  {
308  m_replaceFootprints = aReplaceFootprints;
309  }
310 
311  bool GetReplaceFootprints() const { return m_replaceFootprints; }
312 
317  bool AnyFootprintsLinked() const;
318 
323  bool AllFootprintsLinked() const;
324 
329  bool NoFootprintsLinked() const { return !AnyFootprintsLinked(); }
330 
336  bool AnyFootprintsChanged() const;
337 
338  void Format( const char* aDocName, OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl = 0 );
339 
340 #define CTL_OMIT_EXTRA (1<<0)
341 #define CTL_OMIT_NETS (1<<1)
342 #define CTL_OMIT_FILTERS (1<<2)
343 
344 #define CTL_FOR_BACKANNO (CTL_OMIT_NETS | CTL_OMIT_FILTERS | CTL_OMIT_EXTRA)
345 
347  {
348  Format( "back_annotation", aOut, 0, CTL_FOR_BACKANNO );
349  }
350 };
351 
352 
353 #endif // PCB_NETLIST_H
void SetAltFPID(const LIB_ID &aFPID)
Definition: pcb_netlist.h:159
const wxString & GetPinName() const
Definition: pcb_netlist.h:61
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:94
bool empty() const
Function empty.
Definition: lib_id.h:198
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:105
const LIB_ID & GetFPID() const
Definition: pcb_netlist.h:164
bool IsLibSource(const wxString &aLibrary, const wxString &aName) const
Definition: pcb_netlist.h:184
bool AnyFootprintsLinked() const
Function AnyFootprintsLinked.
wxString m_library
The name of the component library where m_name was found.
Definition: pcb_netlist.h:97
void SetFPID(const LIB_ID &aFPID)
Definition: pcb_netlist.h:153
const wxArrayString & GetFootprintFilters() const
Definition: pcb_netlist.h:175
MODULE * GetModule(bool aRelease=false)
Definition: pcb_netlist.h:177
bool AnyFootprintsChanged() const
Function AnyFootprintsChanged.
COMPONENTS m_components
Components found in the netlist.
Definition: pcb_netlist.h:207
void SetLibrary(const wxString &aLibrary)
Definition: pcb_netlist.h:146
const wxString & GetLibrary() const
Definition: pcb_netlist.h:147
bool FootprintChanged() const
Definition: pcb_netlist.h:189
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:302
bool IsValid() const
Definition: pcb_netlist.h:65
bool IsEmpty() const
Function IsEmpty()
Definition: pcb_netlist.h:235
Class REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:61
Class LIB_ID.
Definition: lib_id.h:56
static COMPONENT_NET m_emptyNet
Definition: pcb_netlist.h:113
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:220
const wxString & GetReference() const
Definition: pcb_netlist.h:149
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:151
bool GetDeleteExtraFootprints() const
Definition: pcb_netlist.h:296
void SetFootprintFilters(const wxArrayString &aFilterList)
Definition: pcb_netlist.h:170
wxString m_timeStamp
The component full time stamp found in netlist.
Definition: pcb_netlist.h:91
bool GetReplaceFootprints() const
Definition: pcb_netlist.h:311
void SetReplaceFootprints(bool aReplaceFootprints)
Definition: pcb_netlist.h:306
Class NETLIST stores all of information read from a netlist along with the flags used to update the N...
Definition: pcb_netlist.h:205
COMPONENT_NET(const wxString &aPinName, const wxString &aNetName)
Definition: pcb_netlist.h:56
bool NoFootprintsLinked() const
Function NoFootprintsLinked.
Definition: pcb_netlist.h:329
bool m_findByTimeStamp
Find component by time stamp if true or reference designator if false.
Definition: pcb_netlist.h:217
bool m_isDryRun
Do not actually make any changes.
Definition: pcb_netlist.h:214
const wxString & GetNetName() const
Definition: pcb_netlist.h:63
bool IsFindByTimeStamp() const
Definition: pcb_netlist.h:304
void SetIsDryRun(bool aIsDryRun)
Definition: pcb_netlist.h:298
bool m_deleteExtraFootprints
Remove footprints from BOARD not found in netlist when true.
Definition: pcb_netlist.h:210
const wxString & GetTimeStamp() const
Definition: pcb_netlist.h:168
wxString m_netName
Definition: pcb_netlist.h:51
void FormatBackAnnotation(OUTPUTFORMATTER *aOut)
Definition: pcb_netlist.h:346
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:256
bool m_footprintChanged
Set to true if m_fpid was changed when the footprint link file was read.
Definition: pcb_netlist.h:111
const LIB_ID & GetAltFPID() const
Definition: pcb_netlist.h:166
void Clear()
Function Clear removes all components from the netlist.
Definition: pcb_netlist.h:241
const wxString & GetName() const
Definition: pcb_netlist.h:144
LIB_ID m_fpid
The LIB_ID of the footprint assigned to the component.
Definition: pcb_netlist.h:100
void SortPins()
Definition: pcb_netlist.h:141
void Format(const char *aDocName, OUTPUTFORMATTER *aOut, int aNestLevel, int aCtl=0)
wxString m_value
The component value found in netlist.
Definition: pcb_netlist.h:88
void SetName(const wxString &aName)
Definition: pcb_netlist.h:143
#define CTL_FOR_BACKANNO
Definition: pcb_netlist.h:344
void AddNet(const wxString &aPinName, const wxString &aNetName)
Definition: pcb_netlist.h:130
bool AllFootprintsLinked() const
Function AllFootprintsLinked.
COMPONENT * GetComponentByReference(const wxString &aReference)
Function GetComponentByReference returns a COMPONENT by aReference.
const COMPONENT_NET & GetNet(unsigned aIndex) const
Definition: pcb_netlist.h:137
wxString m_reference
The component reference designator found in netlist.
Definition: pcb_netlist.h:87
std::vector< COMPONENT_NET > COMPONENT_NETS
Definition: pcb_netlist.h:76
void SetModule(MODULE *aModule)
Definition: pcb_netlist.cpp:47
bool IsDryRun() const
Definition: pcb_netlist.h:300
Module description (excepted pads)
void SetDeleteExtraFootprints(bool aDeleteExtraFootprints)
Definition: pcb_netlist.h:291
boost::ptr_vector< COMPONENT > COMPONENTS
Definition: pcb_netlist.h:195
std::unique_ptr< MODULE > m_footprint
The MODULE loaded for m_fpid.
Definition: pcb_netlist.h:108
unsigned GetCount() const
Function GetCount.
Definition: pcb_netlist.h:247
COMPONENTS::const_iterator COMPONENTS_CITER
Definition: pcb_netlist.h:197
unsigned GetNetCount() const
Definition: pcb_netlist.h:135
COMPONENTS::iterator COMPONENTS_ITER
Definition: pcb_netlist.h:196
COMPONENT(const LIB_ID &aFPID, const wxString &aReference, const wxString &aValue, const wxString &aTimeStamp)
Definition: pcb_netlist.h:116
wxString m_pinName
Definition: pcb_netlist.h:50
COMPONENT * GetComponentByTimeStamp(const wxString &aTimeStamp)
Function GetComponentByTimeStamp returns a COMPONENT by aTimeStamp.