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 
104 
106  std::unique_ptr< MODULE > m_footprint;
107 
109  std::map<wxString, wxString> m_properties;
110 
112 
113 public:
114  COMPONENT( const LIB_ID& aFPID,
115  const wxString& aReference,
116  const wxString& aValue,
117  const KIID_PATH& aPath )
118  {
119  m_fpid = aFPID;
120  m_reference = aReference;
121  m_value = aValue;
122  m_pinCount = 0;
123  m_path = aPath;
124  }
125 
126  virtual ~COMPONENT() { };
127 
128  void AddNet( const wxString& aPinName, const wxString& aNetName, const wxString& aPinFunction )
129  {
130  m_nets.push_back( COMPONENT_NET( aPinName, aNetName, aPinFunction ) );
131  }
132 
133  unsigned GetNetCount() const { return m_nets.size(); }
134 
135  const COMPONENT_NET& GetNet( unsigned aIndex ) const { return m_nets[aIndex]; }
136 
137  const COMPONENT_NET& GetNet( const wxString& aPinName ) const;
138 
139  void SortPins() { sort( m_nets.begin(), m_nets.end() ); }
140 
141  void SetName( const wxString& aName ) { m_name = aName;}
142  const wxString& GetName() const { return m_name; }
143 
144  void SetLibrary( const wxString& aLibrary ) { m_library = aLibrary; }
145  const wxString& GetLibrary() const { return m_library; }
146 
147  const wxString& GetReference() const { return m_reference; }
148  const wxString& GetValue() const { return m_value; }
149 
150  void SetProperties( std::map<wxString, wxString>& aProps )
151  {
152  m_properties = std::move( aProps );
153  }
154  const std::map<wxString, wxString>& GetProperties() const { return m_properties; }
155 
156  void SetFPID( const LIB_ID& aFPID ) { m_fpid = aFPID; }
157  const LIB_ID& GetFPID() const { return m_fpid; }
158 
159  void SetAltFPID( const LIB_ID& aFPID ) { m_altFpid = aFPID; }
160  const LIB_ID& GetAltFPID() const { return m_altFpid; }
161 
162  const KIID_PATH& GetPath() const { return m_path; }
163 
164  void SetFootprintFilters( const wxArrayString& aFilters ) { m_footprintFilters = aFilters; }
165  const wxArrayString& GetFootprintFilters() const { return m_footprintFilters; }
166 
167  void SetPinCount( int aPinCount ) { m_pinCount = aPinCount; }
168  int GetPinCount() const { return m_pinCount; }
169 
170  MODULE* GetModule( bool aRelease = false )
171  {
172  return ( aRelease ) ? m_footprint.release() : m_footprint.get();
173  }
174 
175  void SetModule( MODULE* aModule );
176 
177  bool IsLibSource( const wxString& aLibrary, const wxString& aName ) const
178  {
179  return aLibrary == m_library && aName == m_name;
180  }
181 
182  void Format( OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl );
183 };
184 
185 
186 typedef boost::ptr_vector< COMPONENT > COMPONENTS;
187 
188 
194 class NETLIST
195 {
196  COMPONENTS m_components; // Components found in the netlist.
197 
198  bool m_findByTimeStamp; // Associate components by KIID (or refdes if false)
199  bool m_replaceFootprints; // Update footprints to match footprints defined in netlist
200 
201 public:
203  m_findByTimeStamp( false ),
204  m_replaceFootprints( false )
205  {
206  }
207 
212  bool IsEmpty() const { return m_components.empty(); }
213 
218  void Clear() { m_components.clear(); }
219 
224  unsigned GetCount() const { return m_components.size(); }
225 
233  COMPONENT* GetComponent( unsigned aIndex ) { return &m_components[ aIndex ]; }
234 
244  void AddComponent( COMPONENT* aComponent );
245 
253  COMPONENT* GetComponentByReference( const wxString& aReference );
254 
262  COMPONENT* GetComponentByPath( const KIID_PATH& aPath );
263 
264  void SortByFPID();
265  void SortByReference();
266 
267  void SetFindByTimeStamp( bool aFindByTimeStamp ) { m_findByTimeStamp = aFindByTimeStamp; }
268  bool IsFindByTimeStamp() const { return m_findByTimeStamp; }
269 
270  void SetReplaceFootprints( bool aReplace ) { m_replaceFootprints = aReplace; }
271  bool GetReplaceFootprints() const { return m_replaceFootprints; }
272 
277  bool AnyFootprintsLinked() const;
278 
279  void Format( const char* aDocName, OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl = 0 );
280 
281 #define CTL_OMIT_EXTRA (1<<0)
282 #define CTL_OMIT_NETS (1<<1)
283 #define CTL_OMIT_FILTERS (1<<2)
284 
285 #define CTL_FOR_BACKANNO (CTL_OMIT_NETS | CTL_OMIT_FILTERS | CTL_OMIT_EXTRA)
286 
288  {
289  Format( "back_annotation", aOut, 0, CTL_FOR_BACKANNO );
290  }
291 };
292 
293 
294 #endif // PCB_NETLIST_H
bool IsLibSource(const wxString &aLibrary, const wxString &aName) const
Definition: pcb_netlist.h:177
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:126
void Format(OUTPUTFORMATTER *aOut, int aNestLevel, int aCtl)
Definition: pcb_netlist.cpp:70
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:103
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:156
bool AnyFootprintsLinked() const
Function AnyFootprintsLinked.
MODULE * GetModule(bool aRelease=false)
Definition: pcb_netlist.h:170
bool IsFindByTimeStamp() const
Definition: pcb_netlist.h:268
COMPONENTS m_components
Definition: pcb_netlist.h:196
void SetLibrary(const wxString &aLibrary)
Definition: pcb_netlist.h:144
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:224
void SetFindByTimeStamp(bool aFindByTimeStamp)
Definition: pcb_netlist.h:267
void SetProperties(std::map< wxString, wxString > &aProps)
Definition: pcb_netlist.h:150
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
static COMPONENT_NET m_emptyNet
Definition: pcb_netlist.h:111
const wxString & GetName() const
Definition: pcb_netlist.h:142
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:199
const LIB_ID & GetFPID() const
Definition: pcb_netlist.h:157
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
void SetReplaceFootprints(bool aReplace)
Definition: pcb_netlist.h:270
const wxString & GetNetName() const
Definition: pcb_netlist.h:60
NETLIST stores all of information read from a netlist along with the flags used to update the NETLIST...
Definition: pcb_netlist.h:194
const LIB_ID & GetAltFPID() const
Definition: pcb_netlist.h:160
unsigned GetNetCount() const
Definition: pcb_netlist.h:133
bool m_findByTimeStamp
Definition: pcb_netlist.h:198
bool operator<(const COMPONENT_NET &aNet) const
Definition: pcb_netlist.h:65
void SetPinCount(int aPinCount)
Definition: pcb_netlist.h:167
const wxString & GetReference() const
Definition: pcb_netlist.h:147
wxString m_netName
Definition: pcb_netlist.h:47
const COMPONENT_NET & GetNet(unsigned aIndex) const
Definition: pcb_netlist.h:135
void FormatBackAnnotation(OUTPUTFORMATTER *aOut)
Definition: pcb_netlist.h:287
const wxString & GetLibrary() const
Definition: pcb_netlist.h:145
std::map< wxString, wxString > m_properties
Component-specific properties found in the netlist.
Definition: pcb_netlist.h:109
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:233
void SetFootprintFilters(const wxArrayString &aFilters)
Definition: pcb_netlist.h:164
wxString m_pinFunction
Definition: pcb_netlist.h:48
void Clear()
Function Clear removes all components from the netlist.
Definition: pcb_netlist.h:218
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:139
void Format(const char *aDocName, OUTPUTFORMATTER *aOut, int aNestLevel, int aCtl=0)
bool GetReplaceFootprints() const
Definition: pcb_netlist.h:271
wxString m_value
The component value found in netlist.
Definition: pcb_netlist.h:86
void SetName(const wxString &aName)
Definition: pcb_netlist.h:141
#define CTL_FOR_BACKANNO
Definition: pcb_netlist.h:285
int GetPinCount() const
Definition: pcb_netlist.h:168
const wxString & GetPinName() const
Definition: pcb_netlist.h:59
bool IsEmpty() const
Function IsEmpty()
Definition: pcb_netlist.h:212
COMPONENT(const LIB_ID &aFPID, const wxString &aReference, const wxString &aValue, const KIID_PATH &aPath)
Definition: pcb_netlist.h:114
const std::map< wxString, wxString > & GetProperties() const
Definition: pcb_netlist.h:154
const wxString & GetValue() const
Definition: pcb_netlist.h:148
const wxArrayString & GetFootprintFilters() const
Definition: pcb_netlist.h:165
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:40
boost::ptr_vector< COMPONENT > COMPONENTS
Definition: pcb_netlist.h:186
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:106
void AddNet(const wxString &aPinName, const wxString &aNetName, const wxString &aPinFunction)
Definition: pcb_netlist.h:128
const KIID_PATH & GetPath() const
Definition: pcb_netlist.h:162
wxString m_pinName
Definition: pcb_netlist.h:46