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-2021 KiCad Developers
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_model.h>
31#include <sim/sim_library.h>
32
33
35{
36public:
38 {
48 };
49
50 struct ITEM
51 {
52 std::string refName;
53 std::string libraryPath;
54 std::vector<std::string> pinNumbers;
55 std::vector<std::string> pinNetNames;
56 std::unique_ptr<const SIM_MODEL> model;
57 std::string modelName;
58 };
59
61
65 bool WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions ) override;
66
70 bool DoWriteNetlist( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions );
71
75 virtual void WriteHead( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions );
76
80 virtual void WriteTail( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions );
81
88 virtual bool ReadSchematicAndLibraries( unsigned aNetlistOptions );
89
93 static void ReplaceForbiddenChars( std::string& aNetName );
94
98 std::set<std::string> GetNets() const { return m_nets; }
99
100
110 std::string GetItemName( const std::string& aRefName ) const;
111
115 const std::list<ITEM>& GetItems() const { return m_items; }
116
117 const std::vector<std::string>& GetDirectives() { return m_directives; }
118
119protected:
120 void ReadDirectives( unsigned aNetlistOptions = 0 );
121 virtual void WriteDirectives( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions ) const;
122
123 virtual std::string GenerateItemPinNetName( const std::string& aNetName, int& aNcCounter ) const;
124
128 SCH_SHEET_LIST GetSheets( unsigned aNetlistOptions = 0 ) const;
129
130private:
131 void readLibraryField( SCH_SYMBOL& aSymbol, ITEM& aItem );
132 void readNameField( SCH_SYMBOL& aSymbol, ITEM& aItem );
133 void readEnabledField( SCH_SYMBOL& aSymbol, ITEM& aItem );
134 bool readRefName( SCH_SHEET_PATH& aSheet, SCH_SYMBOL& aSymbol, ITEM& aItem,
135 std::set<std::string>& aRefNames );
136 bool readModel( SCH_SYMBOL& aSymbol, ITEM& aItem );
137 void readPinNumbers( SCH_SYMBOL& aSymbol, ITEM& aItem );
138 void readPinNetNames( SCH_SYMBOL& aSymbol, ITEM& aItem, int& aNcCounter );
139
140 void writeInclude( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions,
141 const std::string& aPath );
142
143 void writeIncludes( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions );
144 void writeModels( OUTPUTFORMATTER& aFormatter );
145 void writeItems( OUTPUTFORMATTER& aFormatter );
146
147 std::string m_title;
148 std::vector<std::string> m_directives;
149 std::map<std::string, std::unique_ptr<SIM_LIBRARY>> m_libraries;
150 std::set<std::string> m_rawIncludes;
151 std::set<std::string> m_nets;
152 std::list<ITEM> m_items;
153};
154
155
156#endif // NETLIST_EXPORTER_SPICE_H
An abstract class used for the netlist exporters that Eeschema supports.
void writeModels(OUTPUTFORMATTER &aFormatter)
void writeIncludes(OUTPUTFORMATTER &aFormatter, unsigned aNetlistOptions)
void readPinNumbers(SCH_SYMBOL &aSymbol, ITEM &aItem)
bool DoWriteNetlist(OUTPUTFORMATTER &aFormatter, unsigned aNetlistOptions)
Write the netlist in aFormatter.
static void ReplaceForbiddenChars(std::string &aNetName)
Replace illegal spice net name characters with underscores.
virtual void WriteDirectives(OUTPUTFORMATTER &aFormatter, unsigned aNetlistOptions) const
std::map< std::string, std::unique_ptr< SIM_LIBRARY > > m_libraries
Spice libraries.
std::string GetItemName(const std::string &aRefName) const
Return name of Spice device corresponding to a schematic symbol.
void readPinNetNames(SCH_SYMBOL &aSymbol, ITEM &aItem, int &aNcCounter)
std::string m_title
Spice simulation title found in the schematic sheet.
void writeInclude(OUTPUTFORMATTER &aFormatter, unsigned aNetlistOptions, const std::string &aPath)
SCH_SHEET_LIST GetSheets(unsigned aNetlistOptions=0) const
Return the paths of exported sheets (either all or the current one).
std::vector< std::string > m_directives
Spice directives found in the schematic sheet.
bool WriteNetlist(const wxString &aOutFileName, unsigned aNetlistOptions) override
Write to specified output file.
void writeItems(OUTPUTFORMATTER &aFormatter)
virtual void WriteHead(OUTPUTFORMATTER &aFormatter, unsigned aNetlistOptions)
Write the netlist head (title and so on).
bool readModel(SCH_SYMBOL &aSymbol, ITEM &aItem)
virtual std::string GenerateItemPinNetName(const std::string &aNetName, int &aNcCounter) const
const std::vector< std::string > & GetDirectives()
void readLibraryField(SCH_SYMBOL &aSymbol, ITEM &aItem)
std::set< std::string > m_rawIncludes
include directives found in symbols
std::set< std::string > GetNets() const
Return the list of nets.
std::list< ITEM > m_items
Items representing schematic symbols in Spice world.
std::set< std::string > m_nets
bool readRefName(SCH_SHEET_PATH &aSheet, SCH_SYMBOL &aSymbol, ITEM &aItem, std::set< std::string > &aRefNames)
void readEnabledField(SCH_SYMBOL &aSymbol, ITEM &aItem)
const std::list< ITEM > & GetItems() const
Return the list of items representing schematic components in the Spice world.
void ReadDirectives(unsigned aNetlistOptions=0)
virtual void WriteTail(OUTPUTFORMATTER &aFormatter, unsigned aNetlistOptions)
Write the tail (.end).
NETLIST_EXPORTER_SPICE(SCHEMATIC_IFACE *aSchematic)
virtual bool ReadSchematicAndLibraries(unsigned aNetlistOptions)
Process the schematic and Spice libraries to create net mapping and a list of SPICE_ITEMs.
void readNameField(SCH_SYMBOL &aSymbol, ITEM &aItem)
An interface used to output 8 bit text in a convenient way.
Definition: richio.h:310
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:80
std::vector< std::string > pinNetNames
std::unique_ptr< const SIM_MODEL > model
std::vector< std::string > pinNumbers