KiCad PCB EDA Suite
netlist_exporter_spice.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 (C) 1992-2023 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 NETLIST_EXPORTER_SPICE_H
27#define NETLIST_EXPORTER_SPICE_H
28
30#include <sim/sim_lib_mgr.h>
31#include <sim/sim_library.h>
32#include <sim/sim_model.h>
33#include <sim/spice_generator.h>
34
35
36class wxWindow;
37
38
40{
41public:
42 std::string Generate( const std::string& aProposedName );
43
44private:
45 std::unordered_set<std::string> m_names;
46};
47
48
50{
51public:
53 {
64 };
65
66 NETLIST_EXPORTER_SPICE( SCHEMATIC_IFACE* aSchematic, wxWindow* aDialogParent = nullptr );
67
71 bool WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions,
72 REPORTER& aReporter ) override;
73
77 bool DoWriteNetlist( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions,
78 REPORTER& aReporter );
79
83 virtual void WriteHead( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions );
84
88 virtual void WriteTail( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions );
89
96 virtual bool ReadSchematicAndLibraries( unsigned aNetlistOptions, REPORTER& aReporter );
97
101 static void ConvertToSpiceMarkup( std::string& aNetName );
102
106 std::set<std::string> GetNets() const { return m_nets; }
107
117 std::string GetItemName( const std::string& aRefName ) const;
118
122 const std::list<SPICE_ITEM>& GetItems() const { return m_items; }
123
127 const SPICE_ITEM* FindItem( const std::string& aRefName ) const;
128
129 const std::vector<wxString>& GetDirectives() { return m_directives; }
130
131protected:
132 void ReadDirectives( unsigned aNetlistOptions );
133 virtual void WriteDirectives( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions ) const;
134
135 virtual std::string GenerateItemPinNetName( const std::string& aNetName,
136 int& aNcCounter ) const;
137
141 SCH_SHEET_LIST GetSheets( unsigned aNetlistOptions = 0 ) const;
142
143private:
144 void readRefName( SCH_SHEET_PATH& aSheet, SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem,
145 std::set<std::string>& aRefNames );
146 void readModel( SCH_SHEET_PATH& aSheet, SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem );
147 void readPinNumbers( SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem );
148 void readPinNetNames( SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem, int& aNcCounter );
149
150 void writeInclude( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions,
151 const wxString& aPath );
152
153 void writeIncludes( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions );
154 void writeModels( OUTPUTFORMATTER& aFormatter );
155 void writeItems( OUTPUTFORMATTER& aFormatter );
156
159
162 std::vector<wxString> m_directives;
163 std::set<wxString> m_rawIncludes;
164 std::set<std::string> m_nets;
165
167 std::list<SPICE_ITEM> m_items;
168
169 wxWindow* m_dialogParent;
170};
171
172
173#endif // NETLIST_EXPORTER_SPICE_H
std::unordered_set< std::string > m_names
std::string Generate(const std::string &aProposedName)
An abstract class used for the netlist exporters that Eeschema supports.
bool DoWriteNetlist(OUTPUTFORMATTER &aFormatter, unsigned aNetlistOptions, REPORTER &aReporter)
Write the netlist in aFormatter.
void writeModels(OUTPUTFORMATTER &aFormatter)
void writeIncludes(OUTPUTFORMATTER &aFormatter, unsigned aNetlistOptions)
NETLIST_EXPORTER_SPICE(SCHEMATIC_IFACE *aSchematic, wxWindow *aDialogParent=nullptr)
std::list< SPICE_ITEM > m_items
void ReadDirectives(unsigned aNetlistOptions)
virtual void WriteDirectives(OUTPUTFORMATTER &aFormatter, unsigned aNetlistOptions) const
std::string GetItemName(const std::string &aRefName) const
Return name of Spice device corresponding to a schematic symbol.
SCH_SHEET_LIST GetSheets(unsigned aNetlistOptions=0) const
Return the paths of exported sheets (either all or the current one).
void readRefName(SCH_SHEET_PATH &aSheet, SCH_SYMBOL &aSymbol, SPICE_ITEM &aItem, std::set< std::string > &aRefNames)
static void ConvertToSpiceMarkup(std::string &aNetName)
Remove formatting wrappers and replace illegal spice net name characters with underscores.
void writeItems(OUTPUTFORMATTER &aFormatter)
std::vector< wxString > m_directives
Spice directives found in the schematic sheet.
virtual void WriteHead(OUTPUTFORMATTER &aFormatter, unsigned aNetlistOptions)
Write the netlist head (title and so on).
virtual std::string GenerateItemPinNetName(const std::string &aNetName, int &aNcCounter) const
const std::vector< wxString > & GetDirectives()
const SPICE_ITEM * FindItem(const std::string &aRefName) const
Find and return the item corresponding to aRefName.
void writeInclude(OUTPUTFORMATTER &aFormatter, unsigned aNetlistOptions, const wxString &aPath)
SIM_LIB_MGR m_libMgr
Holds libraries and models.
std::set< std::string > GetNets() const
Return the list of nets.
void readPinNumbers(SCH_SYMBOL &aSymbol, SPICE_ITEM &aItem)
virtual bool ReadSchematicAndLibraries(unsigned aNetlistOptions, REPORTER &aReporter)
Process the schematic and Spice libraries to create net mapping and a list of SPICE_ITEMs.
void readPinNetNames(SCH_SYMBOL &aSymbol, SPICE_ITEM &aItem, int &aNcCounter)
std::set< std::string > m_nets
Items representing schematic symbols in Spice world.
const std::list< SPICE_ITEM > & GetItems() const
Return the list of items representing schematic symbols in the Spice world.
std::set< wxString > m_rawIncludes
include directives found in symbols
virtual void WriteTail(OUTPUTFORMATTER &aFormatter, unsigned aNetlistOptions)
Write the tail (.end).
NAME_GENERATOR m_modelNameGenerator
Generates unique model names.
bool WriteNetlist(const wxString &aOutFileName, unsigned aNetlistOptions, REPORTER &aReporter) override
Write to specified output file.
void readModel(SCH_SHEET_PATH &aSheet, SCH_SYMBOL &aSymbol, SPICE_ITEM &aItem)
An interface used to output 8 bit text in a convenient way.
Definition: richio.h:310
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:71
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:81