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-2017 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.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 component 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 
67 
71 struct SPICE_ITEM
72 {
75 
77  wxChar m_primitive;
78 
81  wxString m_model;
82 
84  wxString m_refName;
85 
87  bool m_enabled;
88 
90  std::vector<wxString> m_pins;
91 
93  std::vector<int> m_pinSequence;
94 };
95 
96 
102 {
103 public:
105  NETLIST_EXPORTER( 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& aComponent ) const;
136 
141  bool WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions ) override;
142 
144  bool Format( OUTPUTFORMATTER* aFormatter, unsigned aCtl );
145 
152  bool ProcessNetlist( unsigned aCtl );
153 
154 
161  static void ReplaceForbiddenChars( wxString& aNetName );
162 
167  {
168  return m_netMap;
169  }
170 
174  static const std::vector<wxString>& GetSpiceFields()
175  {
176  return m_spiceFields;
177  }
178 
182  static const wxString& GetSpiceFieldName( SPICE_FIELD aField )
183  {
184  return m_spiceFields[(int) aField];
185  }
186 
190  static wxString GetSpiceField( SPICE_FIELD aField, SCH_COMPONENT* aComponent, unsigned aCtl );
191 
195  static wxString GetSpiceFieldDefVal( SPICE_FIELD aField, SCH_COMPONENT* aComponent, unsigned aCtl );
196 
200  void UpdateDirectives( unsigned aCtl );
201 
205  const std::vector<wxString> GetDirectives() const
206  {
207  return m_directives;
208  }
209 
213  static bool StringToBool( const wxString& aStr )
214  {
215  if( aStr.IsEmpty() )
216  return false;
217 
218  char c = tolower( aStr[0] );
219 
220  // Different ways of saying false (no/false/0)
221  return !( c == 'n' || c == 'f' || c == '0' );
222  }
223 
224 protected:
228  virtual void writeDirectives( OUTPUTFORMATTER* aFormatter, unsigned aCtl ) const;
229 
230 private:
232  wxString m_title;
233 
235  std::vector<wxString> m_directives;
236 
238  std::set<wxString> m_libraries;
239 
242 
245 
246  // Component fields that are processed during netlist export & simulation
247  static const std::vector<wxString> m_spiceFields;
248 };
249 
250 #endif
NETLIST_EXPORTER_PSPICE(SCHEMATIC *aSchematic)
bool Format(OUTPUTFORMATTER *aFormatter, unsigned aCtl)
const SPICE_ITEM_LIST & GetSpiceItems() const
Returns list of items representing schematic components in the Spice world.
PROJECT holds project specific data.
Definition: project.h:61
Holds all the data relating to one schematic A schematic may consist of one or more sheets (and one r...
Definition: schematic.h:42
std::set< wxString > m_libraries
Libraries used by the simulated circuit
SCH_COMPONENT * m_parent
Schematic component represented by this SPICE_ITEM.
Structure to represent a schematic component in the Spice simulation.
std::vector< wxString > m_pins
Array containing Standard Pin Name
static const wxString & GetSpiceFieldName(SPICE_FIELD aField)
Returns a string used for a particular component field related to Spice simulation.
const std::vector< wxString > GetDirectives() const
Returnss a vector of Spice directives found in the schematics.
OUTPUTFORMATTER is an important interface (abstract class) used to output 8 bit text in a convenient ...
Definition: richio.h:327
bool m_enabled
Flag to indicate whether the component should be used in simulation.
std::vector< wxString > m_directives
Spice directives found in the processed schematic sheet
static bool StringToBool(const wxString &aStr)
Convertes typical boolean string values (no/yes, true/false, 1/0) to a boolean value.
wxString m_model
Library model (for semiconductors and subcircuits), component value (for passive components) or volta...
SPICE_ITEM_LIST m_spiceItems
List of items representing schematic components in the Spice world
static wxString GetSpiceFieldDefVal(SPICE_FIELD aField, SCH_COMPONENT *aComponent, unsigned aCtl)
Retrieves the default value for a given field.
wxString m_title
Spice simulation title found in the processed schematic sheet
NET_INDEX_MAP m_netMap
Maps circuit nodes to net names
NETLIST_EXPORTER is a abstract class used for the netlist exporters that eeschema supports.
virtual void writeDirectives(OUTPUTFORMATTER *aFormatter, unsigned aCtl) const
Saves the Spice directives.
void UpdateDirectives(unsigned aCtl)
Updates the vector of Spice directives placed in the schematics.
const NET_INDEX_MAP & GetNetIndexMap() const
Returns a map of circuit nodes to net names.
bool ProcessNetlist(unsigned aCtl)
Processes the netlist to create net mapping and a list of SPICE_ITEMs.
std::list< SPICE_ITEM > SPICE_ITEM_LIST
static void ReplaceForbiddenChars(wxString &aNetName)
some chars are not accepted in netnames in spice netlists.
std::map< wxString, int > NET_INDEX_MAP
Net name to circuit node number mapping
bool WriteNetlist(const wxString &aOutFileName, unsigned aNetlistOptions) override
Function WriteNetlist writes to specified output file.
SPICE_PRIMITIVE
Basic Spice component primitives
static wxString GetSpiceField(SPICE_FIELD aField, SCH_COMPONENT *aComponent, unsigned aCtl)
Retrieves either the requested field value or the default value.
Schematic symbol object.
Definition: sch_component.h:88
NETLIST_EXPORTER_PSPICE generates a PSPICE compatible netlist.
static const std::vector< wxString > m_spiceFields
wxChar m_primitive
Spice primitive type (
wxString GetSpiceDevice(const wxString &aComponent) const
Returns name of Spice device corresponding to a schematic component.
SPICE_NETLIST_OPTIONS
Flags for Spice netlist generation (can be combined)
static const std::vector< wxString > & GetSpiceFields()
Returns a vector of component field names related to Spice simulation.
std::vector< int > m_pinSequence
Numeric indices into m_SortedComponentPinList