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 {
68 };
69
71
75 bool WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions,
76 REPORTER& aReporter ) override;
77
81 bool DoWriteNetlist( const wxString& aSimCommand, unsigned aSimOptions,
82 OUTPUTFORMATTER& aFormatter, REPORTER& aReporter );
83
87 virtual void WriteHead( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions );
88
92 virtual void WriteTail( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions );
93
100 virtual bool ReadSchematicAndLibraries( unsigned aNetlistOptions, REPORTER& aReporter );
101
105 static void ConvertToSpiceMarkup( wxString* aNetName );
106
110 std::set<wxString> GetNets() const { return m_nets; }
111
121 wxString GetItemName( const wxString& aRefName ) const;
122
126 const std::list<SPICE_ITEM>& GetItems() const { return m_items; }
127
131 const SPICE_ITEM* FindItem( const wxString& aRefName ) const;
132
133 const std::vector<wxString>& GetDirectives() { return m_directives; }
134
135protected:
136 void ReadDirectives( unsigned aNetlistOptions );
137 virtual void WriteDirectives( const wxString& aSimCommand, unsigned aSimOptions,
138 OUTPUTFORMATTER& candidate ) const;
139
140 virtual wxString GenerateItemPinNetName( const wxString& aNetName, int& aNcCounter ) const;
141
145 SCH_SHEET_LIST BuildSheetList( unsigned aNetlistOptions = 0 ) const;
146
147private:
148 void readRefName( SCH_SHEET_PATH& aSheet, SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem,
149 std::set<std::string>& aRefNames );
150 void readModel( SCH_SHEET_PATH& aSheet, SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem,
151 REPORTER& aReporter );
152 void readPinNumbers( SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem,
153 const std::vector<PIN_INFO>& aPins );
154 void readPinNetNames( SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem,
155 const std::vector<PIN_INFO>& aPins, int& aNcCounter );
156 void getNodePattern( SPICE_ITEM& aItem, std::vector<std::string>& aModifiers );
157 void readNodePattern( SPICE_ITEM& aItem );
158
159 void writeInclude( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions,
160 const wxString& aPath );
161
162 void writeIncludes( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions );
163 void writeModels( OUTPUTFORMATTER& aFormatter );
164 void writeItems( OUTPUTFORMATTER& aFormatter );
165
168
169 std::vector<wxString> m_directives;
170 std::set<wxString> m_rawIncludes;
171 std::set<wxString> m_nets;
172
174 std::list<SPICE_ITEM> m_items;
175};
176
177
178#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 getNodePattern(SPICE_ITEM &aItem, std::vector< std::string > &aModifiers)
static void ConvertToSpiceMarkup(wxString *aNetName)
Remove formatting wrappers and replace illegal spice net name characters with underscores.
void ReadDirectives(unsigned aNetlistOptions)
SCH_SHEET_LIST BuildSheetList(unsigned aNetlistOptions=0) const
Return the paths of exported sheets (either all or the current one).
void readModel(SCH_SHEET_PATH &aSheet, SCH_SYMBOL &aSymbol, SPICE_ITEM &aItem, REPORTER &aReporter)
virtual wxString GenerateItemPinNetName(const wxString &aNetName, int &aNcCounter) const
std::set< wxString > m_nets
Items representing schematic symbols in Spice world.
void readRefName(SCH_SHEET_PATH &aSheet, SCH_SYMBOL &aSymbol, SPICE_ITEM &aItem, std::set< std::string > &aRefNames)
wxString GetItemName(const wxString &aRefName) const
Return name of Spice device corresponding to a schematic symbol.
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).
const std::vector< wxString > & GetDirectives()
void writeInclude(OUTPUTFORMATTER &aFormatter, unsigned aNetlistOptions, const wxString &aPath)
std::set< wxString > GetNets() const
Return the list of nets.
virtual void WriteDirectives(const wxString &aSimCommand, unsigned aSimOptions, OUTPUTFORMATTER &candidate) const
SIM_LIB_MGR m_libMgr
Holds libraries and models.
const SPICE_ITEM * FindItem(const wxString &aRefName) const
Find and return the item corresponding to aRefName.
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.
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.
void readNodePattern(SPICE_ITEM &aItem)
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:105