KiCad PCB EDA Suite
Loading...
Searching...
No Matches
netlist_exporter_base.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) 1992-2013 jp.charras at wanadoo.fr
5 * Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright The 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, see <https://www.gnu.org/licenses/>.
20 */
21
22#ifndef NETLIST_EXPORTER_H
23#define NETLIST_EXPORTER_H
24
25#include <schematic.h>
26
27#include <functional>
28#include <map>
29#include <set>
30#include <optional>
31#include <unordered_map>
32
33class SCH_SYMBOL;
34class SCH_PIN;
35class LIB_SYMBOL;
36class REPORTER;
37class KIWAY;
38
43{
44public:
48 void Clear() { m_set.clear(); }
49
54 bool Lookup( const wxString& aString )
55 {
56 std::pair<us_iterator, bool> pair = m_set.insert( aString );
57
58 return !pair.second;
59 }
60
61 std::set<wxString> m_set;
62
63 typedef std::set<wxString>::iterator us_iterator;
64};
65
70{
71 // a "less than" test on two LIB_SYMBOLs (.m_name wxStrings)
72 bool operator()( LIB_SYMBOL* const& libsymbol1, LIB_SYMBOL* const& libsymbol2 ) const;
73};
74
75
77{
78 PIN_INFO( const wxString& aPinNumber, const wxString& aNetName, const wxString& aPinName,
79 const wxString& aSourcePin = wxEmptyString ) :
80 num( aPinNumber ),
81 netName( aNetName ),
82 pinName( aPinName ),
83 srcPin( aSourcePin )
84 {}
85
86 wxString num;
87 wxString netName;
88 wxString pinName;
89 wxString srcPin;
90};
91
92
96using EXPORT_EXCLUSION = std::function<bool( const SCH_SYMBOL*, const SCH_SHEET_PATH& )>;
97
98
100{
101public:
102 NETLIST_EXPORTER_BASE( SCHEMATIC* aSchematic, KIWAY* aKiway ) :
103 m_schematic( aSchematic ),
104 m_kiway( aKiway )
105 {
106 wxASSERT( aSchematic );
107
108 m_exportVariant = aSchematic->GetCurrentVariant();
109 }
110
111 virtual ~NETLIST_EXPORTER_BASE() = default;
112
116 bool WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions, REPORTER& aReporter );
117
147 static wxString MakeCommandLine( const wxString& aFormatString, const wxString& aNetlistFile,
148 const wxString& aFinalFile,
149 const wxString& aProjectDirectory );
150
151protected:
153 {
154 public:
155 explicit CONNECTIVITY_SCOPE( NETLIST_EXPORTER_BASE& aExporter );
159
160 private:
162 };
163
164 virtual bool writeNetlist( const wxString& aOutFileName, unsigned aNetlistOptions, REPORTER& aReporter )
165 {
166 return false;
167 }
168
170 {
171 wxString name;
172 bool hasNoConnect = false;
173 std::vector<std::pair<SCH_PIN*, SCH_SHEET_PATH>> pins;
174 };
175
176 void rebuildConnectivity();
177 std::optional<wxString> itemNetName( const SCH_ITEM& aItem, const SCH_SHEET_PATH& aPath ) const;
179 std::vector<EXPORT_NET> m_exportNets;
180 std::map<SCH_SHEET_PATH, std::unordered_map<KIID, wxString>> m_exportItemNets;
182
190 std::vector<PIN_INFO> CreatePinList( SCH_SYMBOL* aSymbol, const SCH_SHEET_PATH& aSheetPath );
191
202 SCH_SYMBOL* findNextSymbol( EDA_ITEM* aItem, const SCH_SHEET_PATH& aSheetPath,
203 const EXPORT_EXCLUSION& aExcluded = nullptr );
204
208 bool packageOwnedElsewhere( const SCH_SYMBOL* aSymbol, const SCH_SHEET_PATH& aSheetPath,
209 const EXPORT_EXCLUSION& aExcluded ) const;
210
215
226 void eraseDuplicatePins( std::vector<PIN_INFO>& pins );
227
229 void appendResolvedPins( std::vector<PIN_INFO>& aPins, const SCH_PIN* aPin, const SCH_SHEET_PATH& aSheetPath,
230 const wxString& aNetName );
231
233 std::vector<wxString> resolvePadNumbers( const SCH_PIN* aPin, const SCH_SHEET_PATH& aSheetPath ) const;
234
235 const std::set<wxString>& footprintPads( const wxString& aFootprintId ) const;
236
243 void findAllUnitsOfSymbol( SCH_SYMBOL* aSchSymbol, const SCH_SHEET_PATH& aSheetPath,
244 std::vector<PIN_INFO>& aPins );
245
246protected:
249
251 std::set<LIB_SYMBOL*, LIB_SYMBOL_LESS_THAN> m_libParts;
252
253
256
257 KIWAY* m_kiway = nullptr;
258
259 mutable std::map<wxString, std::set<wxString>> m_footprintPadCache;
260};
261
262#endif
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:348
Define a library symbol object.
Definition lib_symbol.h:114
CONNECTIVITY_SCOPE(NETLIST_EXPORTER_BASE &aExporter)
CONNECTIVITY_SCOPE(const CONNECTIVITY_SCOPE &)=delete
CONNECTIVITY_SCOPE & operator=(const CONNECTIVITY_SCOPE &)=delete
NETLIST_EXPORTER_BASE(SCHEMATIC *aSchematic, KIWAY *aKiway)
virtual bool writeNetlist(const wxString &aOutFileName, unsigned aNetlistOptions, REPORTER &aReporter)
virtual ~NETLIST_EXPORTER_BASE()=default
std::optional< wxString > itemNetName(const SCH_ITEM &aItem, const SCH_SHEET_PATH &aPath) const
const std::set< wxString > & footprintPads(const wxString &aFootprintId) const
void findAllUnitsOfSymbol(SCH_SYMBOL *aSchSymbol, const SCH_SHEET_PATH &aSheetPath, std::vector< PIN_INFO > &aPins)
Find all units for symbols with multiple symbols per package.
std::map< wxString, std::set< wxString > > m_footprintPadCache
std::set< LIB_SYMBOL *, LIB_SYMBOL_LESS_THAN > m_libParts
unique library symbols used. LIB_SYMBOL items are sorted by names
void eraseDuplicatePins(std::vector< PIN_INFO > &pins)
Erase duplicate pins.
std::vector< wxString > resolvePadNumbers(const SCH_PIN *aPin, const SCH_SHEET_PATH &aSheetPath) const
Resolve aPin to its effective pad number(s) for every netlist path (issue #2282).
std::map< SCH_SHEET_PATH, std::unordered_map< KIID, wxString > > m_exportItemNets
UNIQUE_STRINGS m_referencesAlreadyFound
Used for "multiple symbols per package" symbols to avoid processing a lib symbol more than once.
std::vector< EXPORT_NET > m_exportNets
EXPORT_EXCLUSION boardExclusion() const
bool WriteNetlist(const wxString &aOutFileName, unsigned aNetlistOptions, REPORTER &aReporter)
Write to specified output file.
wxString m_exportVariant
The schematic we're generating a netlist for.
SCH_SYMBOL * findNextSymbol(EDA_ITEM *aItem, const SCH_SHEET_PATH &aSheetPath, const EXPORT_EXCLUSION &aExcluded=nullptr)
Check if the given symbol should be processed for netlisting.
KIWAY * m_kiway
The variant of the schematic to export.
static wxString MakeCommandLine(const wxString &aFormatString, const wxString &aNetlistFile, const wxString &aFinalFile, const wxString &aProjectDirectory)
Build up a string that describes a command line for executing a child process.
void appendResolvedPins(std::vector< PIN_INFO > &aPins, const SCH_PIN *aPin, const SCH_SHEET_PATH &aSheetPath, const wxString &aNetName)
Resolve aPin to its pad number(s) and append a PIN_INFO for each (issue #2282).
bool packageOwnedElsewhere(const SCH_SYMBOL *aSymbol, const SCH_SHEET_PATH &aSheetPath, const EXPORT_EXCLUSION &aExcluded) const
std::vector< PIN_INFO > CreatePinList(SCH_SYMBOL *aSymbol, const SCH_SHEET_PATH &aSheetPath)
Find a symbol from the DrawList and builds its pin list.
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
Holds all the data relating to one schematic.
Definition schematic.h:155
wxString GetCurrentVariant() const
Return the current variant being edited.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Schematic symbol object.
Definition sch_symbol.h:76
Track unique wxStrings and is useful in telling if a string has been seen before.
std::set< wxString > m_set
set of wxStrings already found
void Clear()
Erase the record.
bool Lookup(const wxString &aString)
std::set< wxString >::iterator us_iterator
std::function< bool(const SCH_SYMBOL *, const SCH_SHEET_PATH &)> EXPORT_EXCLUSION
An abstract class used for the netlist exporters that Eeschema supports.
Used by std:set<LIB_SYMBOL*> instantiation which uses LIB_SYMBOL name as its key.
bool operator()(LIB_SYMBOL *const &libsymbol1, LIB_SYMBOL *const &libsymbol2) const
std::vector< std::pair< SCH_PIN *, SCH_SHEET_PATH > > pins
PIN_INFO(const wxString &aPinNumber, const wxString &aNetName, const wxString &aPinName, const wxString &aSourcePin=wxEmptyString)
wxString num
Resolved footprint pad number.
wxString srcPin
Original symbol pin number that mapped to this pad (issue #2282).