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<NETLIST_OBJECT*> m_pins;
91 
93  std::vector<int> m_pinSequence;
94 };
95 
96 
102 {
103 public:
104  NETLIST_EXPORTER_PSPICE( NETLIST_OBJECT_LIST* aMasterList, PROJECT* aProject = NULL ) :
105  NETLIST_EXPORTER( aMasterList ),
106  m_project( aProject )
107  {
108  }
109 
111  {
112  }
113 
114  typedef std::list<SPICE_ITEM> SPICE_ITEM_LIST;
115 
117  typedef std::map<wxString, int> NET_INDEX_MAP;
118 
122  const SPICE_ITEM_LIST& GetSpiceItems() const
123  {
124  return m_spiceItems;
125  }
126 
136  wxString GetSpiceDevice( const wxString& aComponent ) const;
137 
142  bool WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions ) override;
143 
145  bool Format( OUTPUTFORMATTER* aFormatter, unsigned aCtl );
146 
153  bool ProcessNetlist( unsigned aCtl );
154 
155 
162  static void ReplaceForbiddenChars( wxString& aNetName );
163 
167  const NET_INDEX_MAP& GetNetIndexMap() const
168  {
169  return m_netMap;
170  }
171 
175  static const std::vector<wxString>& GetSpiceFields()
176  {
177  return m_spiceFields;
178  }
179 
183  static const wxString& GetSpiceFieldName( SPICE_FIELD aField )
184  {
185  return m_spiceFields[(int) aField];
186  }
187 
191  static wxString GetSpiceField( SPICE_FIELD aField, SCH_COMPONENT* aComponent, unsigned aCtl );
192 
196  static wxString GetSpiceFieldDefVal( SPICE_FIELD aField, SCH_COMPONENT* aComponent, unsigned aCtl );
197 
201  void UpdateDirectives( unsigned aCtl );
202 
206  const std::vector<wxString> GetDirectives() const
207  {
208  return m_directives;
209  }
210 
214  static bool StringToBool( const wxString& aStr )
215  {
216  if( aStr.IsEmpty() )
217  return false;
218 
219  char c = tolower( aStr[0] );
220 
221  // Different ways of saying false (no/false/0)
222  return !( c == 'n' || c == 'f' || c == '0' );
223  }
224 
225 protected:
229  virtual void writeDirectives( OUTPUTFORMATTER* aFormatter, unsigned aCtl ) const;
230 
231 private:
233  wxString m_title;
234 
236  std::vector<wxString> m_directives;
237 
239  std::set<wxString> m_libraries;
240 
242  NET_INDEX_MAP m_netMap;
243 
245  SPICE_ITEM_LIST m_spiceItems;
246 
249 
250  // Component fields that are processed during netlist export & simulation
251  static const std::vector<wxString> m_spiceFields;
252 };
253 
254 #endif
const std::vector< wxString > GetDirectives() const
Returnss a vector of Spice directives found in the schematics.
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
Class PROJECT holds project specific data.
Definition: project.h:57
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.
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...
wxString m_title
Spice simulation title found in the processed schematic sheet
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...
const SPICE_ITEM_LIST & GetSpiceItems() const
Returns list of items representing schematic components in the Spice world.
std::list< SPICE_ITEM > SPICE_ITEM_LIST
PROJECT * m_project
Project object to fetch its settings (e.g. paths)
std::map< wxString, int > NET_INDEX_MAP
Net name to circuit node number mapping
NETLIST_EXPORTER_PSPICE(NETLIST_OBJECT_LIST *aMasterList, PROJECT *aProject=NULL)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
SPICE_PRIMITIVE
Basic Spice component primitives
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
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