1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
|
#ifndef PCB_NETLIST_H
#define PCB_NETLIST_H
/**
* @file pcb_netlist.h
*/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 Jean-Pierre Charras.
* Copyright (C) 2013 Wayne Stambaugh <stambaughw@verizon.net>.
* Copyright (C) 2012-2015 KiCad Developers, see CHANGELOG.TXT for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <boost/ptr_container/ptr_vector.hpp>
#include <wx/arrstr.h>
#include <fpid.h>
#include <class_module.h>
class REPORTER;
/**
* Class COMPONENT_NET
* is used to store the component pin name to net name associations stored in a netlist.
*/
class COMPONENT_NET
{
wxString m_pinName;
wxString m_netName;
public:
COMPONENT_NET() {}
COMPONENT_NET( const wxString& aPinName, const wxString& aNetName ) :
m_pinName( aPinName ), m_netName( aNetName )
{
}
const wxString& GetPinName() const { return m_pinName; }
const wxString& GetNetName() const { return m_netName; }
bool IsValid() const { return !m_pinName.IsEmpty(); }
bool operator <( const COMPONENT_NET& aNet ) const
{
return m_pinName < aNet.m_pinName;
}
int Format( OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl );
};
typedef std::vector< COMPONENT_NET > COMPONENT_NETS;
/**
* Class COMPONENT
* is used to store components and all of their related information found in a netlist.
*/
class COMPONENT
{
COMPONENT_NETS m_nets;
wxArrayString m_footprintFilters; ///< Footprint filters found in netlist.
wxString m_reference; ///< The component reference designator found in netlist.
wxString m_value; ///< The component value found in netlist.
// ZZZ This timestamp is string, not time_t
wxString m_timeStamp; ///< The component full time stamp found in netlist.
/// The name of the component in #m_library used when it was placed on the schematic..
wxString m_name;
/// The name of the component library where #m_name was found.
wxString m_library;
/// The #FPID of the footprint assigned to the component.
FPID m_fpid;
/// The alt FPID of the footprint, when there are 2 different assigned footprints,
/// One from the netlist, the other from the .cmp file.
/// this one is a copy of the netlist footprint assignment
FPID m_altFpid;
/// The #MODULE loaded for #m_fpid.
std::auto_ptr< MODULE > m_footprint;
/// Set to true if #m_fpid was changed when the footprint link file was read.
bool m_footprintChanged;
static COMPONENT_NET m_emptyNet;
public:
COMPONENT( const FPID& aFPID,
const wxString& aReference,
const wxString& aValue,
const wxString& aTimeStamp )
{
m_fpid = aFPID;
m_reference = aReference;
m_value = aValue;
m_timeStamp = aTimeStamp;
m_footprintChanged = false;
}
virtual ~COMPONENT() { };
void AddNet( const wxString& aPinName, const wxString& aNetName )
{
m_nets.push_back( COMPONENT_NET( aPinName, aNetName ) );
}
unsigned GetNetCount() const { return m_nets.size(); }
const COMPONENT_NET& GetNet( unsigned aIndex ) const { return m_nets[aIndex]; }
const COMPONENT_NET& GetNet( const wxString& aPinName );
void SortPins() { sort( m_nets.begin(), m_nets.end() ); }
void SetName( const wxString& aName ) { m_name = aName;}
const wxString& GetName() const { return m_name; }
void SetLibrary( const wxString& aLibrary ) { m_library = aLibrary; }
const wxString& GetLibrary() const { return m_library; }
const wxString& GetReference() const { return m_reference; }
const wxString& GetValue() const { return m_value; }
void SetFPID( const FPID& aFPID )
{
m_footprintChanged = !m_fpid.empty() && (m_fpid != aFPID);
m_fpid = aFPID;
}
void SetAltFPID( const FPID& aFPID )
{
m_altFpid = aFPID;
}
const FPID& GetFPID() const { return m_fpid; }
const FPID& GetAltFPID() const { return m_altFpid; }
const wxString& GetTimeStamp() const { return m_timeStamp; }
void SetFootprintFilters( const wxArrayString& aFilterList )
{
m_footprintFilters = aFilterList;
}
const wxArrayString& GetFootprintFilters() const { return m_footprintFilters; }
/**
* Function MatchesFootprintFilters
*
* @return true if \a aFootprintName matches any of the footprint filters or no footprint
* filters are defined.
*/
bool MatchesFootprintFilters( const wxString& aFootprintName ) const;
MODULE* GetModule( bool aRelease = false )
{
return ( aRelease ) ? m_footprint.release() : m_footprint.get();
}
void SetModule( MODULE* aModule );
bool IsLibSource( const wxString& aLibrary, const wxString& aName ) const
{
return aLibrary == m_library && aName == m_name;
}
bool FootprintChanged() const { return m_footprintChanged; }
void Format( OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl );
};
typedef boost::ptr_vector< COMPONENT > COMPONENTS;
typedef COMPONENTS::iterator COMPONENTS_ITER;
typedef COMPONENTS::const_iterator COMPONENTS_CITER;
/**
* Class NETLIST
* stores all of information read from a netlist along with the flags used to update
* the NETLIST in the #BOARD.
*/
class NETLIST
{
COMPONENTS m_components; ///< Components found in the netlist.
/// Remove footprints from #BOARD not found in netlist when true.
bool m_deleteExtraFootprints;
/// Do not actually make any changes. Only report changes to #BOARD from netlist
/// when true.
bool m_isDryRun;
/// Find component by time stamp if true or reference designator if false.
bool m_findByTimeStamp;
/// Replace component footprints when they differ from the netlist if true.
bool m_replaceFootprints;
public:
NETLIST() :
m_deleteExtraFootprints( false ),
m_isDryRun( false ),
m_findByTimeStamp( false ),
m_replaceFootprints( false )
{
}
/**
* Function IsEmpty()
* @return true if there are no components in the netlist.
*/
bool IsEmpty() const { return m_components.empty(); }
/**
* Function Clear
* removes all components from the netlist.
*/
void Clear() { m_components.clear(); }
/**
* Function GetCount
* @return the number of components in the netlist.
*/
unsigned GetCount() const { return m_components.size(); }
/**
* Function GetComponent
* returns the #COMPONENT at \a aIndex.
*
* @param aIndex the index in #m_components to fetch.
* @return a pointer to the #COMPONENT at \a Index.
*/
COMPONENT* GetComponent( unsigned aIndex ) { return &m_components[ aIndex ]; }
/**
* Function AddComponent
* adds \a aComponent to the NETLIST.
*
* @note If \a aComponent already exists in the NETLIST, \a aComponent is deleted
* to prevent memory leaks. An assertion is raised in debug builds.
*
* @param aComponent is the COMPONENT to save to the NETLIST.
*/
void AddComponent( COMPONENT* aComponent );
/**
* Function GetComponentByReference
* returns a #COMPONENT by \a aReference.
*
* @param aReference is the reference designator the #COMPONENT.
* @return a pointer to the #COMPONENT that matches \a aReference if found. Otherwise NULL.
*/
COMPONENT* GetComponentByReference( const wxString& aReference );
/**
* Function GetComponentByTimeStamp
* returns a #COMPONENT by \a aTimeStamp.
*
* @param aTimeStamp is the time stamp the #COMPONENT.
* @return a pointer to the #COMPONENT that matches \a aTimeStamp if found. Otherwise NULL.
*/
COMPONENT* GetComponentByTimeStamp( const wxString& aTimeStamp );
void SortByFPID();
void SortByReference();
void SetDeleteExtraFootprints( bool aDeleteExtraFootprints )
{
m_deleteExtraFootprints = aDeleteExtraFootprints;
}
bool GetDeleteExtraFootprints() const { return m_deleteExtraFootprints; }
void SetIsDryRun( bool aIsDryRun ) { m_isDryRun = aIsDryRun; }
bool IsDryRun() const { return m_isDryRun; }
void SetFindByTimeStamp( bool aFindByTimeStamp ) { m_findByTimeStamp = aFindByTimeStamp; }
bool IsFindByTimeStamp() const { return m_findByTimeStamp; }
void SetReplaceFootprints( bool aReplaceFootprints )
{
m_replaceFootprints = aReplaceFootprints;
}
bool GetReplaceFootprints() const { return m_replaceFootprints; }
/**
* Function AnyFootprintsLinked
* @return true if any component with a footprint link is found.
*/
bool AnyFootprintsLinked() const;
/**
* Function AllFootprintsLinked
* @return true if all components have a footprint link.
*/
bool AllFootprintsLinked() const;
/**
* Function NoFootprintsLinked
* @return true if none of the components have a footprint link.
*/
bool NoFootprintsLinked() const { return !AnyFootprintsLinked(); }
/**
* Function AnyFootprintsChanged
* @return true if any components footprints were changed when the footprint link file
* (*.cmp) was loaded.
*/
bool AnyFootprintsChanged() const;
void Format( const char* aDocName, OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl = 0 );
#define CTL_OMIT_EXTRA (1<<0)
#define CTL_OMIT_NETS (1<<1)
#define CTL_OMIT_FILTERS (1<<2)
#define CTL_FOR_BACKANNO (CTL_OMIT_NETS | CTL_OMIT_FILTERS | CTL_OMIT_EXTRA)
void FormatBackAnnotation( OUTPUTFORMATTER* aOut )
{
Format( "back_annotation", aOut, 0, CTL_FOR_BACKANNO );
}
};
#endif // PCB_NETLIST_H
|