KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 {
66 };
67
68 NETLIST_EXPORTER_SPICE( SCHEMATIC_IFACE* aSchematic, wxWindow* aDialogParent = nullptr );
69
73 bool WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions,
74 REPORTER& aReporter ) override;
75
79 bool DoWriteNetlist( const wxString& aSimCommand, unsigned aSimOptions,
80 OUTPUTFORMATTER& aFormatter, REPORTER& aReporter );
81
85 virtual void WriteHead( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions );
86
90 virtual void WriteTail( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions );
91
98 virtual bool ReadSchematicAndLibraries( unsigned aNetlistOptions, REPORTER& aReporter );
99
103 static void ConvertToSpiceMarkup( std::string& aNetName );
104
108 std::set<std::string> GetNets() const { return m_nets; }
109
119 std::string GetItemName( const std::string& aRefName ) const;
120
124 const std::list<SPICE_ITEM>& GetItems() const { return m_items; }
125
129 const SPICE_ITEM* FindItem( const std::string& aRefName ) const;
130
131 const std::vector<wxString>& GetDirectives() { return m_directives; }
132
133protected:
134 void ReadDirectives( unsigned aNetlistOptions );
135 virtual void WriteDirectives( const wxString& aSimCommand, unsigned aSimOptions,
136 OUTPUTFORMATTER& candidate ) const;
137
138 virtual std::string GenerateItemPinNetName( const std::string& aNetName,
139 int& aNcCounter ) const;
140
144 SCH_SHEET_LIST GetSheets( unsigned aNetlistOptions = 0 ) const;
145
146private:
147 void readRefName( SCH_SHEET_PATH& aSheet, SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem,
148 std::set<std::string>& aRefNames );
149 void readModel( SCH_SHEET_PATH& aSheet, SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem,
150 REPORTER& aReporter );
151 void readPinNumbers( SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem,
152 const std::vector<PIN_INFO>& aPins );
153 void readPinNetNames( SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem,
154 const std::vector<PIN_INFO>& aPins, int& aNcCounter );
155
156 void writeInclude( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions,
157 const wxString& aPath );
158
159 void writeIncludes( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions );
160 void writeModels( OUTPUTFORMATTER& aFormatter );
161 void writeItems( OUTPUTFORMATTER& aFormatter );
162
165
168 std::vector<wxString> m_directives;
169 std::set<wxString> m_rawIncludes;
170 std::set<std::string> m_nets;
171
173 std::list<SPICE_ITEM> m_items;
174
175 wxWindow* m_dialogParent;
176};
177
178
179#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.
void readPinNetNames(SCH_SYMBOL &aSymbol, SPICE_ITEM &aItem, const std::vector< PIN_INFO > &aPins, int &aNcCounter)
void writeModels(OUTPUTFORMATTER &aFormatter)
void writeIncludes(OUTPUTFORMATTER &aFormatter, unsigned aNetlistOptions)
std::list< SPICE_ITEM > m_items
void ReadDirectives(unsigned aNetlistOptions)
std::string GetItemName(const std::string &aRefName) const
Return name of Spice device corresponding to a schematic symbol.
void readModel(SCH_SHEET_PATH &aSheet, SCH_SYMBOL &aSymbol, SPICE_ITEM &aItem, REPORTER &aReporter)
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)
virtual void WriteDirectives(const wxString &aSimCommand, unsigned aSimOptions, OUTPUTFORMATTER &candidate) const
SIM_LIB_MGR m_libMgr
Holds libraries and models.
std::set< std::string > GetNets() const
Return the list of nets.
virtual bool ReadSchematicAndLibraries(unsigned aNetlistOptions, REPORTER &aReporter)
Process the schematic and Spice libraries to create net mapping and a list of SPICE_ITEMs.
bool DoWriteNetlist(const wxString &aSimCommand, unsigned aSimOptions, OUTPUTFORMATTER &aFormatter, REPORTER &aReporter)
Write the netlist in aFormatter.
std::set< std::string > m_nets
Items representing schematic symbols in Spice world.
void readPinNumbers(SCH_SYMBOL &aSymbol, SPICE_ITEM &aItem, const std::vector< PIN_INFO > &aPins)
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.
An interface used to output 8 bit text in a convenient way.
Definition: richio.h:322
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:109