KiCad PCB EDA Suite
netlist_exporter_pspice.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 <dick@softplc.com>
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_PSPICE_H
27 #define NETLIST_EXPORTER_PSPICE_H
28 
29 #include "netlist_exporter_base.h"
30 #include <list>
31 #include <map>
32 
33 class PROJECT;
34 
37  NET_ADJUST_INCLUDE_PATHS = 8, // use full paths for included files (if they are in search path)
38  NET_ADJUST_PASSIVE_VALS = 16, // reformat passive symbol values (e.g. 1M -> 1Meg)
39  NET_ALL_FLAGS = 0xffff
40 };
41 
48  SF_END // sentinel
49 };
50 
53  SP_UNKNOWN = ' ',
54  SP_RESISTOR = 'R',
55  SP_CAPACITOR = 'C',
56  SP_INDUCTOR = 'L',
57  SP_DIODE = 'D',
58  SP_BJT = 'Q',
59  SP_MOSFET = 'M',
60  SP_JFET = 'J',
61  SP_SUBCKT = 'X',
62  SP_VSOURCE = 'V',
63  SP_ISOURCE = 'I'
64 };
65 
68 
72 struct SPICE_ITEM
73 {
76 
78  wxChar m_primitive;
79 
82  wxString m_model;
83 
85  wxString m_refName;
86 
88  bool m_enabled;
89 
91  std::vector<wxString> m_pins;
92 
94  std::vector<int> m_pinSequence;
95 };
96 
97 
102 {
103 public:
105  NETLIST_EXPORTER_BASE( aSchematic )
106  {
107  }
108 
110  {
111  }
112 
113  typedef std::list<SPICE_ITEM> SPICE_ITEM_LIST;
114 
116  typedef std::map<wxString, int> NET_INDEX_MAP;
117 
122  {
123  return m_spiceItems;
124  }
125 
135  wxString GetSpiceDevice( const wxString& aSymbol ) const;
136 
140  bool WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions ) override;
141 
143  bool Format( OUTPUTFORMATTER* aFormatter, unsigned aCtl );
144 
151  bool ProcessNetlist( unsigned aCtl );
152 
153 
159  static void ReplaceForbiddenChars( wxString& aNetName );
160 
165  {
166  return m_netMap;
167  }
168 
172  static const std::vector<wxString>& GetSpiceFields()
173  {
174  return m_spiceFields;
175  }
176 
180  static const wxString& GetSpiceFieldName( SPICE_FIELD aField )
181  {
182  return m_spiceFields[(int) aField];
183  }
184 
188  static wxString GetSpiceField( SPICE_FIELD aField, SCH_SYMBOL* aSymbol, unsigned aCtl );
189 
193  static wxString GetSpiceFieldDefVal( SPICE_FIELD aField, SCH_SYMBOL* aSymbol, unsigned aCtl );
194 
198  void UpdateDirectives( unsigned aCtl );
199 
203  const std::vector<wxString> GetDirectives() const
204  {
205  return m_directives;
206  }
207 
211  static bool StringToBool( const wxString& aStr )
212  {
213  if( aStr.IsEmpty() )
214  return false;
215 
216  char c = tolower( aStr[0] );
217 
218  // Different ways of saying false (no/false/0)
219  return !( c == 'n' || c == 'f' || c == '0' );
220  }
221 
222 protected:
226  virtual void writeDirectives( OUTPUTFORMATTER* aFormatter, unsigned aCtl ) const;
227 
228 private:
230  wxString m_title;
231 
233  std::vector<wxString> m_directives;
234 
236  std::set<wxString> m_libraries;
237 
240 
243 
244  // Component fields that are processed during netlist export & simulation
245  static const std::vector<wxString> m_spiceFields;
246 };
247 
248 #endif
bool Format(OUTPUTFORMATTER *aFormatter, unsigned aCtl)
const SPICE_ITEM_LIST & GetSpiceItems() const
Return list of items representing schematic components in the Spice world.
Container for project specific data.
Definition: project.h:62
std::set< wxString > m_libraries
Map circuit nodes to net names.
Structure to represent a schematic symbol in the Spice simulation.
std::vector< wxString > m_pins
Numeric indices into m_SortedSymbolPinList.
static const wxString & GetSpiceFieldName(SPICE_FIELD aField)
Return a string used for a particular component field related to Spice simulation.
const std::vector< wxString > GetDirectives() const
Return a vector of Spice directives found in the schematics.
An interface used to output 8 bit text in a convenient way.
Definition: richio.h:306
bool m_enabled
Array containing Standard Pin Name.
std::vector< wxString > m_directives
Libraries used by the simulated circuit.
static bool StringToBool(const wxString &aStr)
Convert typical boolean string values (no/yes, true/false, 1/0) to a boolean value.
SCH_SYMBOL * m_parent
< Schematic symbol represented by this SPICE_ITEM.
wxString m_refName
Flag to indicate whether the symbol should be used in simulation.
wxString m_title
< Spice simulation title found in the processed schematic sheet
NET_INDEX_MAP m_netMap
List of items representing schematic components in the Spice world.
static wxString GetSpiceFieldDefVal(SPICE_FIELD aField, SCH_SYMBOL *aSymbol, unsigned aCtl)
Retrieve the default value for a given field.
virtual void writeDirectives(OUTPUTFORMATTER *aFormatter, unsigned aCtl) const
Save the Spice directives.
void UpdateDirectives(unsigned aCtl)
Update the vector of Spice directives placed in the schematics.
wxString GetSpiceDevice(const wxString &aSymbol) const
Return name of Spice device corresponding to a schematic symbol.
const NET_INDEX_MAP & GetNetIndexMap() const
Return a map of circuit nodes to net names.
bool ProcessNetlist(unsigned aCtl)
Process the netlist to create net mapping and a list of SPICE_ITEMs.
std::list< SPICE_ITEM > SPICE_ITEM_LIST
Net name to circuit node number mapping.
static void ReplaceForbiddenChars(wxString &aNetName)
Replace illegal spice net name characters with an underscore.
NETLIST_EXPORTER_PSPICE(SCHEMATIC_IFACE *aSchematic)
An abstract class used for the netlist exporters that Eeschema supports.
std::map< wxString, int > NET_INDEX_MAP
static wxString GetSpiceField(SPICE_FIELD aField, SCH_SYMBOL *aSymbol, unsigned aCtl)
Retrieve either the requested field value or the default value.
bool WriteNetlist(const wxString &aOutFileName, unsigned aNetlistOptions) override
Write to specified output file.
Schematic symbol object.
Definition: sch_symbol.h:78
Generate a PSPICE compatible netlist.
static const std::vector< wxString > m_spiceFields
wxChar m_primitive
Library model (for semiconductors and subcircuits), component value (for passive components) or volta...
SPICE_NETLIST_OPTIONS
Flags for Spice netlist generation (can be combined)
static const std::vector< wxString > & GetSpiceFields()
Return a vector of component field names related to Spice simulation.
std::vector< int > m_pinSequence