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 <footprint.h>
34 
35 
36 class REPORTER;
37 
38 
45 {
46  wxString m_pinName;
47  wxString m_netName;
48  wxString m_pinFunction;
49  wxString m_pinType;
50 
51 public:
53 
54  COMPONENT_NET( const wxString& aPinName, const wxString& aNetName,
55  const wxString& aPinFunction, const wxString& aPinType ) :
56  m_pinName( aPinName ),
57  m_netName( aNetName ),
58  m_pinFunction( aPinFunction ),
59  m_pinType( aPinType )
60  {
61  }
62 
63  const wxString& GetPinName() const { return m_pinName; }
64  const wxString& GetNetName() const { return m_netName; }
65  const wxString& GetPinFunction() const { return m_pinFunction; }
66  const wxString& GetPinType() const { return m_pinType; }
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 
95 
97  std::vector<KIID> m_kiids;
98 
100  wxString m_name;
101 
103  wxString m_library;
104 
107 
112 
114  std::unique_ptr< FOOTPRINT > m_footprint;
115 
117  std::map<wxString, wxString> m_properties;
118 
120 
121 public:
122  COMPONENT( const LIB_ID& aFPID,
123  const wxString& aReference,
124  const wxString& aValue,
125  const KIID_PATH& aPath,
126  const std::vector<KIID>& aKiids )
127  {
128  m_fpid = aFPID;
129  m_reference = aReference;
130  m_value = aValue;
131  m_pinCount = 0;
132  m_path = aPath;
133  m_kiids = aKiids;
134  }
135 
136  virtual ~COMPONENT() { };
137 
138  void AddNet( const wxString& aPinName, const wxString& aNetName, const wxString& aPinFunction,
139  const wxString& aPinType )
140  {
141  m_nets.push_back( COMPONENT_NET( aPinName, aNetName, aPinFunction, aPinType ) );
142  }
143 
144  unsigned GetNetCount() const { return m_nets.size(); }
145 
146  const COMPONENT_NET& GetNet( unsigned aIndex ) const { return m_nets[aIndex]; }
147 
148  const COMPONENT_NET& GetNet( const wxString& aPinName ) const;
149 
150  void SortPins() { sort( m_nets.begin(), m_nets.end() ); }
151 
152  void SetName( const wxString& aName ) { m_name = aName;}
153  const wxString& GetName() const { return m_name; }
154 
155  void SetLibrary( const wxString& aLibrary ) { m_library = aLibrary; }
156  const wxString& GetLibrary() const { return m_library; }
157 
158  const wxString& GetReference() const { return m_reference; }
159  const wxString& GetValue() const { return m_value; }
160 
161  void SetProperties( std::map<wxString, wxString>& aProps )
162  {
163  m_properties = std::move( aProps );
164  }
165  const std::map<wxString, wxString>& GetProperties() const { return m_properties; }
166 
167  void SetFPID( const LIB_ID& aFPID ) { m_fpid = aFPID; }
168  const LIB_ID& GetFPID() const { return m_fpid; }
169 
170  void SetAltFPID( const LIB_ID& aFPID ) { m_altFpid = aFPID; }
171  const LIB_ID& GetAltFPID() const { return m_altFpid; }
172 
173  const KIID_PATH& GetPath() const { return m_path; }
174 
175  const std::vector<KIID>& GetKIIDs() const { return m_kiids; }
176 
177  void SetFootprintFilters( const wxArrayString& aFilters ) { m_footprintFilters = aFilters; }
178  const wxArrayString& GetFootprintFilters() const { return m_footprintFilters; }
179 
180  void SetPinCount( int aPinCount ) { m_pinCount = aPinCount; }
181  int GetPinCount() const { return m_pinCount; }
182 
183  FOOTPRINT* GetFootprint( bool aRelease = false )
184  {
185  return ( aRelease ) ? m_footprint.release() : m_footprint.get();
186  }
187 
188  void SetFootprint( FOOTPRINT* aFootprint );
189 
190  bool IsLibSource( const wxString& aLibrary, const wxString& aName ) const
191  {
192  return aLibrary == m_library && aName == m_name;
193  }
194 
195  void Format( OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl );
196 };
197 
198 
199 typedef boost::ptr_vector< COMPONENT > COMPONENTS;
200 
201 
207 class NETLIST
208 {
209  COMPONENTS m_components; // Components found in the netlist.
210 
211  bool m_findByTimeStamp; // Associate components by KIID (or refdes if false)
212  bool m_replaceFootprints; // Update footprints to match footprints defined in netlist
213 
214 public:
216  m_findByTimeStamp( false ),
217  m_replaceFootprints( false )
218  {
219  }
220 
225  bool IsEmpty() const { return m_components.empty(); }
226 
231  void Clear() { m_components.clear(); }
232 
237  unsigned GetCount() const { return m_components.size(); }
238 
246  COMPONENT* GetComponent( unsigned aIndex ) { return &m_components[ aIndex ]; }
247 
257  void AddComponent( COMPONENT* aComponent );
258 
266  COMPONENT* GetComponentByReference( const wxString& aReference );
267 
275  COMPONENT* GetComponentByPath( const KIID_PATH& aPath );
276 
277  void SortByFPID();
278  void SortByReference();
279 
280  void SetFindByTimeStamp( bool aFindByTimeStamp ) { m_findByTimeStamp = aFindByTimeStamp; }
281  bool IsFindByTimeStamp() const { return m_findByTimeStamp; }
282 
283  void SetReplaceFootprints( bool aReplace ) { m_replaceFootprints = aReplace; }
284  bool GetReplaceFootprints() const { return m_replaceFootprints; }
285 
290  bool AnyFootprintsLinked() const;
291 
292  void Format( const char* aDocName, OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl = 0 );
293 
294 #define CTL_OMIT_EXTRA (1<<0)
295 #define CTL_OMIT_NETS (1<<1)
296 #define CTL_OMIT_FILTERS (1<<2)
297 
298 #define CTL_FOR_CVPCB (CTL_OMIT_NETS | CTL_OMIT_FILTERS | CTL_OMIT_EXTRA)
299 
301  {
302  Format( "cvpcb_netlist", aOut, 0, CTL_FOR_CVPCB );
303  }
304 };
305 
306 
307 #endif // PCB_NETLIST_H
bool IsLibSource(const wxString &aLibrary, const wxString &aName) const
Definition: pcb_netlist.h:190
void SetAltFPID(const LIB_ID &aFPID)
Definition: pcb_netlist.h:170
KIID_PATH m_path
A fully specified path to the component (but not the component: [ sheetUUID, sheetUUID,...
Definition: pcb_netlist.h:94
std::unique_ptr< FOOTPRINT > m_footprint
The FOOTPRINT loaded for #m_FPID.
Definition: pcb_netlist.h:114
void SortByFPID()
virtual ~COMPONENT()
Definition: pcb_netlist.h:136
void Format(OUTPUTFORMATTER *aOut, int aNestLevel, int aCtl)
Definition: pcb_netlist.cpp:73
wxString m_name
The name of the component in m_library used when it was placed on the schematic..
Definition: pcb_netlist.h:100
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:111
void FormatCvpcbNetlist(OUTPUTFORMATTER *aOut)
Definition: pcb_netlist.h:300
wxString m_library
The name of the component library where m_name was found.
Definition: pcb_netlist.h:103
void SetFPID(const LIB_ID &aFPID)
Definition: pcb_netlist.h:167
bool AnyFootprintsLinked() const
Function AnyFootprintsLinked.
const wxString & GetPinType() const
Definition: pcb_netlist.h:66
bool IsFindByTimeStamp() const
Definition: pcb_netlist.h:281
COMPONENTS m_components
Definition: pcb_netlist.h:209
void SetLibrary(const wxString &aLibrary)
Definition: pcb_netlist.h:155
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:88
unsigned GetCount() const
Function GetCount.
Definition: pcb_netlist.h:237
void SetFindByTimeStamp(bool aFindByTimeStamp)
Definition: pcb_netlist.h:280
void SetProperties(std::map< wxString, wxString > &aProps)
Definition: pcb_netlist.h:161
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:97
static COMPONENT_NET m_emptyNet
Definition: pcb_netlist.h:119
void SetFootprint(FOOTPRINT *aFootprint)
Definition: pcb_netlist.cpp:40
const wxString & GetName() const
Definition: pcb_netlist.h:153
void AddComponent(COMPONENT *aComponent)
Function AddComponent adds 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:212
const LIB_ID & GetFPID() const
Definition: pcb_netlist.h:168
COMPONENT_NETS m_nets
list of nets shared by the component pins
Definition: pcb_netlist.h:87
COMPONENT_NET is used to store the component pin name to net name (and pin function) associations sto...
Definition: pcb_netlist.h:44
void SetReplaceFootprints(bool aReplace)
Definition: pcb_netlist.h:283
const wxString & GetNetName() const
Definition: pcb_netlist.h:64
NETLIST stores all of information read from a netlist along with the flags used to update the NETLIST...
Definition: pcb_netlist.h:207
const LIB_ID & GetAltFPID() const
Definition: pcb_netlist.h:171
unsigned GetNetCount() const
Definition: pcb_netlist.h:144
bool m_findByTimeStamp
Definition: pcb_netlist.h:211
bool operator<(const COMPONENT_NET &aNet) const
Definition: pcb_netlist.h:70
void SetPinCount(int aPinCount)
Definition: pcb_netlist.h:180
const wxString & GetReference() const
Definition: pcb_netlist.h:158
wxString m_netName
Definition: pcb_netlist.h:47
#define CTL_FOR_CVPCB
Definition: pcb_netlist.h:298
const COMPONENT_NET & GetNet(unsigned aIndex) const
Definition: pcb_netlist.h:146
COMPONENT_NET(const wxString &aPinName, const wxString &aNetName, const wxString &aPinFunction, const wxString &aPinType)
Definition: pcb_netlist.h:54
const wxString & GetLibrary() const
Definition: pcb_netlist.h:156
std::map< wxString, wxString > m_properties
Component-specific properties found in the netlist.
Definition: pcb_netlist.h:117
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:65
bool IsValid() const
Definition: pcb_netlist.h:68
COMPONENT * GetComponent(unsigned aIndex)
Function GetComponent returns the COMPONENT at aIndex.
Definition: pcb_netlist.h:246
void SetFootprintFilters(const wxArrayString &aFilters)
Definition: pcb_netlist.h:177
wxString m_pinFunction
Definition: pcb_netlist.h:48
void Clear()
Function Clear removes all components from the netlist.
Definition: pcb_netlist.h:231
LIB_ID m_fpid
The LIB_ID of the footprint assigned to the component.
Definition: pcb_netlist.h:106
void SortPins()
Definition: pcb_netlist.h:150
COMPONENT(const LIB_ID &aFPID, const wxString &aReference, const wxString &aValue, const KIID_PATH &aPath, const std::vector< KIID > &aKiids)
Definition: pcb_netlist.h:122
void Format(const char *aDocName, OUTPUTFORMATTER *aOut, int aNestLevel, int aCtl=0)
bool GetReplaceFootprints() const
Definition: pcb_netlist.h:284
wxString m_value
The component value found in netlist.
Definition: pcb_netlist.h:91
void SetName(const wxString &aName)
Definition: pcb_netlist.h:152
int GetPinCount() const
Definition: pcb_netlist.h:181
void AddNet(const wxString &aPinName, const wxString &aNetName, const wxString &aPinFunction, const wxString &aPinType)
Definition: pcb_netlist.h:138
const wxString & GetPinName() const
Definition: pcb_netlist.h:63
wxString m_pinType
Definition: pcb_netlist.h:49
bool IsEmpty() const
Function IsEmpty()
Definition: pcb_netlist.h:225
const std::map< wxString, wxString > & GetProperties() const
Definition: pcb_netlist.h:165
const wxString & GetValue() const
Definition: pcb_netlist.h:159
const wxArrayString & GetFootprintFilters() const
Definition: pcb_netlist.h:178
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
boost::ptr_vector< COMPONENT > COMPONENTS
Definition: pcb_netlist.h:199
int m_pinCount
Number of pins found in netlist.
Definition: pcb_netlist.h:89
const KIID_PATH & GetPath() const
Definition: pcb_netlist.h:173
FOOTPRINT * GetFootprint(bool aRelease=false)
Definition: pcb_netlist.h:183
wxString m_pinName
Definition: pcb_netlist.h:46
const std::vector< KIID > & GetKIIDs() const
Definition: pcb_netlist.h:175