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 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, 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#include <list>
36
37
38class wxWindow;
39
40
42{
43public:
44 std::string Generate( const std::string& aProposedName );
45
46private:
47 std::unordered_set<std::string> m_names;
48};
49
50
52{
53public:
71
72 NETLIST_EXPORTER_SPICE( SCHEMATIC* aSchematic );
73
77 bool WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions,
78 REPORTER& aReporter ) override;
79
83 bool DoWriteNetlist( const wxString& aSimCommand, unsigned aSimOptions,
84 OUTPUTFORMATTER& aFormatter, REPORTER& aReporter );
85
89 virtual void WriteHead( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions );
90
94 virtual void WriteTail( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions );
95
102 virtual bool ReadSchematicAndLibraries( unsigned aNetlistOptions, REPORTER& aReporter );
103
107 static void ConvertToSpiceMarkup( wxString* aNetName );
108
112 std::set<wxString> GetNets() const { return m_nets; }
113
123 wxString GetItemName( const wxString& aRefName ) const;
124
128 const std::list<SPICE_ITEM>& GetItems() const { return m_items; }
129
133 const SPICE_ITEM* FindItem( const wxString& aRefName ) const;
134
135 const std::vector<wxString>& GetDirectives() { return m_directives; }
136
137protected:
138 void ReadDirectives( unsigned aNetlistOptions );
139 virtual void WriteDirectives( const wxString& aSimCommand, unsigned aSimOptions,
140 OUTPUTFORMATTER& candidate ) const;
141
142 virtual wxString GenerateItemPinNetName( const wxString& aNetName, int& aNcCounter ) const;
143
147 SCH_SHEET_LIST BuildSheetList( unsigned aNetlistOptions = 0 ) const;
148
149private:
150 void readRefName( SCH_SHEET_PATH& aSheet, SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem,
151 std::set<std::string>& aRefNames );
152
164 wxString collectMergedSimPins( SCH_SYMBOL& aSymbol, const SCH_SHEET_PATH& aSheet );
165
166 void readModel( SCH_SHEET_PATH& aSheet, SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem,
167 const wxString& aVariantName, REPORTER& aReporter );
168 void readPinNumbers( SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem,
169 const std::vector<PIN_INFO>& aPins );
170 void readPinNetNames( SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem,
171 const std::vector<PIN_INFO>& aPins, int& aNcCounter );
172 void getNodePattern( SPICE_ITEM& aItem, std::vector<std::string>& aModifiers );
173 void readNodePattern( SPICE_ITEM& aItem );
174
175 void writeInclude( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions,
176 const wxString& aPath );
177
178 void writeIncludes( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions );
179 void writeModels( OUTPUTFORMATTER& aFormatter );
180 void writeItems( OUTPUTFORMATTER& aFormatter );
181
182private:
185
186 std::vector<wxString> m_directives;
187 std::set<wxString> m_rawIncludes;
188 std::set<wxString> m_nets;
189
191 std::list<SPICE_ITEM> m_items;
192};
193
194
195#endif // NETLIST_EXPORTER_SPICE_H
std::unordered_set< std::string > m_names
std::string Generate(const std::string &aProposedName)
NETLIST_EXPORTER_BASE(SCHEMATIC *aSchematic)
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).
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 collectMergedSimPins(SCH_SYMBOL &aSymbol, const SCH_SHEET_PATH &aSheet)
Collect merged Sim.Pins from all units of a multi-unit symbol.
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
NETLIST_EXPORTER_SPICE(SCHEMATIC *aSchematic)
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
void readModel(SCH_SHEET_PATH &aSheet, SCH_SYMBOL &aSymbol, SPICE_ITEM &aItem, const wxString &aVariantName, REPORTER &aReporter)
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:295
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:88
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