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 <map>
28#include <set>
29#include <optional>
30#include <unordered_map>
31
32class SCH_SYMBOL;
33class SCH_PIN;
34class LIB_SYMBOL;
35class REPORTER;
36class KIWAY;
37
42{
43public:
47 void Clear() { m_set.clear(); }
48
53 bool Lookup( const wxString& aString )
54 {
55 std::pair<us_iterator, bool> pair = m_set.insert( aString );
56
57 return !pair.second;
58 }
59
60 std::set<wxString> m_set;
61
62 typedef std::set<wxString>::iterator us_iterator;
63};
64
69{
70 // a "less than" test on two LIB_SYMBOLs (.m_name wxStrings)
71 bool operator()( LIB_SYMBOL* const& libsymbol1, LIB_SYMBOL* const& libsymbol2 ) const;
72};
73
74
76{
77 PIN_INFO( const wxString& aPinNumber, const wxString& aNetName, const wxString& aPinName,
78 const wxString& aSourcePin = wxEmptyString ) :
79 num( aPinNumber ),
80 netName( aNetName ),
81 pinName( aPinName ),
82 srcPin( aSourcePin )
83 {}
84
85 wxString num;
86 wxString netName;
87 wxString pinName;
88 wxString srcPin;
89};
90
91
96{
97public:
99 m_schematic( aSchematic )
100 {
101 wxASSERT( aSchematic );
102 }
103
104 virtual ~NETLIST_EXPORTER_BASE() = default;
105
106 void SetKiway( KIWAY* aKiway ) { m_kiway = aKiway; }
107
111 bool WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions, REPORTER& aReporter );
112
142 static wxString MakeCommandLine( const wxString& aFormatString, const wxString& aNetlistFile,
143 const wxString& aFinalFile,
144 const wxString& aProjectDirectory );
145
146protected:
148 {
149 public:
150 explicit CONNECTIVITY_SCOPE( NETLIST_EXPORTER_BASE& aExporter );
154
155 private:
157 };
158
159 virtual bool writeNetlist( const wxString& aOutFileName, unsigned aNetlistOptions,
160 REPORTER& aReporter ) { return false; }
161
163 {
164 wxString name;
165 bool hasNoConnect = false;
166 std::vector<std::pair<SCH_PIN*, SCH_SHEET_PATH>> pins;
167 };
168
169 void rebuildConnectivity();
170 std::optional<wxString> itemNetName( const SCH_ITEM& aItem, const SCH_SHEET_PATH& aPath ) const;
172 std::vector<EXPORT_NET> m_exportNets;
173 std::map<SCH_SHEET_PATH, std::unordered_map<KIID, wxString>> m_exportItemNets;
175
183 std::vector<PIN_INFO> CreatePinList( SCH_SYMBOL* aSymbol, const SCH_SHEET_PATH& aSheetPath );
184
194 SCH_SYMBOL* findNextSymbol( EDA_ITEM* aItem, const SCH_SHEET_PATH& aSheetPath );
195
206 void eraseDuplicatePins( std::vector<PIN_INFO>& pins );
207
209 void appendResolvedPins( std::vector<PIN_INFO>& aPins, const SCH_PIN* aPin, const SCH_SHEET_PATH& aSheetPath,
210 const wxString& aNetName );
211
213 std::vector<wxString> resolvePadNumbers( const SCH_PIN* aPin, const SCH_SHEET_PATH& aSheetPath ) const;
214
215 const std::set<wxString>& footprintPads( const wxString& aFootprintId ) const;
216
223 void findAllUnitsOfSymbol( SCH_SYMBOL* aSchSymbol, const SCH_SHEET_PATH& aSheetPath,
224 std::vector<PIN_INFO>& aPins );
225
229
231 std::set<LIB_SYMBOL*, LIB_SYMBOL_LESS_THAN> m_libParts;
232
235
236 KIWAY* m_kiway = nullptr;
237
238 mutable std::map<wxString, std::set<wxString>> m_footprintPadCache;
239};
240
241#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:340
Define a library symbol object.
Definition lib_symbol.h:119
CONNECTIVITY_SCOPE(NETLIST_EXPORTER_BASE &aExporter)
CONNECTIVITY_SCOPE(const CONNECTIVITY_SCOPE &)=delete
CONNECTIVITY_SCOPE & operator=(const CONNECTIVITY_SCOPE &)=delete
SCHEMATIC * m_schematic
The schematic we're generating a netlist for.
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.
SCH_SYMBOL * findNextSymbol(EDA_ITEM *aItem, const SCH_SHEET_PATH &aSheetPath)
Check if the given symbol should be processed for netlisting.
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).
NETLIST_EXPORTER_BASE(SCHEMATIC *aSchematic)
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
bool WriteNetlist(const wxString &aOutFileName, unsigned aNetlistOptions, REPORTER &aReporter)
Write to specified output file.
void SetKiway(KIWAY *aKiway)
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).
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:148
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:165
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:75
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
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).