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-2016 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 SEARCH_STACK;
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_RESISTOR = 'R',
54  SP_CAPACITOR = 'C',
55  SP_INDUCTOR = 'L',
56  SP_DIODE = 'D',
57  SP_BJT = 'Q',
58  SP_MOSFET = 'M',
59  SP_SUBCKT = 'X',
60  SP_VSOURCE = 'V',
61  SP_ISOURCE = 'I'
62 };
63 
65 
69 struct SPICE_ITEM
70 {
73 
75  wxChar m_primitive;
76 
79  wxString m_model;
80 
82  wxString m_refName;
83 
85  bool m_enabled;
86 
88  std::vector<NETLIST_OBJECT*> m_pins;
89 
91  std::vector<int> m_pinSequence;
92 };
93 
94 
100 {
101 public:
103  SEARCH_STACK* aPaths = NULL ) :
104  NETLIST_EXPORTER( aMasterList, aLibs ), m_paths( aPaths )
105  {
106  }
107 
109  {
110  }
111 
112  typedef std::list<SPICE_ITEM> SPICE_ITEM_LIST;
113 
115  typedef std::map<wxString, int> NET_INDEX_MAP;
116 
120  const SPICE_ITEM_LIST& GetSpiceItems() const
121  {
122  return m_spiceItems;
123  }
124 
129  bool WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions ) override;
130 
132  bool Format( OUTPUTFORMATTER* aFormatter, unsigned aCtl );
133 
140  bool ProcessNetlist( unsigned aCtl );
141 
142 
149  static void ReplaceForbiddenChars( wxString& aNetName );
150 
154  const NET_INDEX_MAP& GetNetIndexMap() const
155  {
156  return m_netMap;
157  }
158 
162  static const std::vector<wxString>& GetSpiceFields()
163  {
164  return m_spiceFields;
165  }
166 
170  static const wxString& GetSpiceFieldName( SPICE_FIELD aField )
171  {
172  return m_spiceFields[(int) aField];
173  }
174 
178  static wxString GetSpiceField( SPICE_FIELD aField, SCH_COMPONENT* aComponent, unsigned aCtl );
179 
183  static wxString GetSpiceFieldDefVal( SPICE_FIELD aField, SCH_COMPONENT* aComponent, unsigned aCtl );
184 
188  void UpdateDirectives( unsigned aCtl );
189 
193  const std::vector<wxString> GetDirectives() const
194  {
195  return m_directives;
196  }
197 
201  static bool StringToBool( const wxString& aStr )
202  {
203  if( aStr.IsEmpty() )
204  return false;
205 
206  char c = tolower( aStr[0] );
207 
208  // Different ways of saying false (no/false/0)
209  return !( c == 'n' || c == 'f' || c == '0' );
210  }
211 
212 protected:
216  virtual void writeDirectives( OUTPUTFORMATTER* aFormatter, unsigned aCtl ) const;
217 
218 private:
220  std::vector<wxString> m_directives;
221 
223  std::set<wxString> m_libraries;
224 
226  NET_INDEX_MAP m_netMap;
227 
229  SPICE_ITEM_LIST m_spiceItems;
230 
233 
234  // Component fields that are processed during netlist export & simulation
235  static const std::vector<wxString> m_spiceFields;
236 };
237 
238 #endif
const std::vector< wxString > GetDirectives() const
Returnss a vector of Spice directives found in the schematics.
bool Format(OUTPUTFORMATTER *aFormatter, unsigned aCtl)
>
const NET_INDEX_MAP & GetNetIndexMap() const
Returns a map of circuit nodes to net names.
std::vector< NETLIST_OBJECT * > m_pins
Array containing Standard Pin Name
NETLIST_EXPORTER_PSPICE(NETLIST_OBJECT_LIST *aMasterList, PART_LIBS *aLibs, SEARCH_STACK *aPaths=NULL)
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.
static const wxString & GetSpiceFieldName(SPICE_FIELD aField)
Returns a string used for a particular component field related to Spice simulation.
Class OUTPUTFORMATTER is an important interface (abstract class) used to output 8 bit text in a conve...
Definition: richio.h:327
bool m_enabled
Flag to indicate whether the component should be used in simulation.
SEARCH_STACK * m_paths
Paths to be searched for included Spice libraries
Class SEARCH_STACK looks for files in a number of places.
Definition: search_stack.h:41
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
Class NETLIST_OBJECT_LIST is a container holding and owning NETLIST_OBJECTs, which are connected item...
static wxString GetSpiceFieldDefVal(SPICE_FIELD aField, SCH_COMPONENT *aComponent, unsigned aCtl)
Retrieves the default value for a given field.
NET_INDEX_MAP m_netMap
Maps circuit nodes to net names
Class NETLIST_EXPORTER is a abstract class used for the netlist exporters that eeschema supports...
void UpdateDirectives(unsigned aCtl)
Updates the vector of Spice directives placed in the schematics.
bool ProcessNetlist(unsigned aCtl)
Processes the netlist to create net mapping and a list of SPICE_ITEMs.
const SPICE_ITEM_LIST & GetSpiceItems() const
Returns list of items representing schematic components in the Spice world.
std::list< SPICE_ITEM > SPICE_ITEM_LIST
static void ReplaceForbiddenChars(wxString &aNetName)
some chars are not accepted in netnames in spice netlists.
virtual void writeDirectives(OUTPUTFORMATTER *aFormatter, unsigned aCtl) const
Saves the Spice directives.
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.
Class PART_LIBS is a collection of PART_LIBs.
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.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:68
Class NETLIST_EXPORTER_PSPICE generates a PSPICE compatible netlist.
static const std::vector< wxString > m_spiceFields
wxChar m_primitive
Spice primitive type (
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