Blame view

GUI/SW2/SRC/src/netlist/SimnGnuCap.cpp 12 KB
886c558b   Steve Greedy   SACAMOS Public Re...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
//**************************************************************************************************
//                                         SimnGnuCap.cpp                                          *
//                                        ----------------                                         *
// Started     : 2008-05-07                                                                        *
// Last Update : 2015-04-09                                                                        *
// Copyright   : (C) 2008-2016 MSWaters                                                            *
//**************************************************************************************************

//**************************************************************************************************
//                                                                                                 *
//      This program is free software; you can redistribute it and/or modify it under the          *
//      terms of the GNU General Public License as published by the Free Software Foundation;      *
//      either version 3 of the License, or (at your option) any later version.                    *
//                                                                                                 *
//**************************************************************************************************

#include "SimnGnuCap.hpp"

//**************************************************************************************************
// Constructor.

SimnGnuCap::SimnGnuCap( void ) : SimnBase( )
{
  m_eSimEng = eSIMR_GNUCAP;

  // Initialize all object attributes
  bClear( );
}

//**************************************************************************************************
// Destructor.

SimnGnuCap::~SimnGnuCap( )
{
}

//**************************************************************************************************
// Extract the simulator engine and return true if it's GNU-Cap.
//
// Return Values :
//   true  - Success
//   false - Failure

bool  SimnGnuCap::bLoadSimEng( void )
{
  wxString  os1;
  size_t    sz1;

  // Scan the circuit description for simulator type
  for( sz1=0; sz1<NetList::m_osaNetLst.GetCount( ); sz1++ )
  {
    os1 = NetList::m_osaNetLst.Item( sz1 );
    if( os1.IsEmpty( ) ) continue;
    if( os1.Upper( ).Contains( wxT("GNU-CAP") ) ) return( true );
  }

  return( false );
}

//**************************************************************************************************
// Extract all the simulator command lines from the circuit description.
// The following commands are currently detected and extracted :
//
//   .OPTIONS
//   .IC
//   .OP
//   .DC
//   .AC
//   .TRANSIENT
//   .FOURIER
//   .PRINT
//   .GENERATOR
//
// Return Values :
//   true  - Success
//   false - Failure

bool  SimnGnuCap::bLoadSimCmds( void )
{
  bool      bRtn=false;
  wxString  os1;
  size_t    sz1;

  // Scan the circuit description for simulation commands
  for( sz1=0; sz1<NetList::m_osaNetLst.GetCount( ); sz1++ )
  {
    os1 = NetList::m_osaNetLst.Item( sz1 );

    if( os1.IsEmpty( ) )               continue;
    if( ! os1.StartsWith( wxT(".") ) ) continue;

    os1.MakeUpper( );

    if(      os1.StartsWith( wxT(".OPT") ) ) // OPTIONS command
      m_oCmdOPT.bSetString( NetList::m_osaNetLst.Item( sz1 ) );
    else if( os1.StartsWith( wxT(".GEN") ) ) // GENERATOR command
      m_oCmdGEN.bSetString( NetList::m_osaNetLst.Item( sz1 ) );
    else if( os1.StartsWith( wxT(".OP")  ) ) // OP command
      m_oCmdOP .bSetString( NetList::m_osaNetLst.Item( sz1 ) );
    else if( os1.StartsWith( wxT(".DC")  ) ) // DC command
      m_oCmdDC .bSetString( NetList::m_osaNetLst.Item( sz1 ) );
    else if( os1.StartsWith( wxT(".AC")  ) ) // AC command
      m_oCmdAC .bSetString( NetList::m_osaNetLst.Item( sz1 ) );
    else if( os1.StartsWith( wxT(".TR")  ) ) // TRANSIENT command
      m_oCmdTR .bSetString( NetList::m_osaNetLst.Item( sz1 ) );
    else if( os1.StartsWith( wxT(".FO")  ) ) // FOURIER command
      m_oCmdFO .bSetString( NetList::m_osaNetLst.Item( sz1 ) );
    else if( os1.StartsWith( wxT(".PR")  ) ) // PRINT command
      m_oCmdPR.bSetString( NetList::m_osaNetLst.Item( sz1 ) );
    else                               continue;

    bRtn = true;
  }

  return( bRtn );
}

//**************************************************************************************************
// Extract the source component.
//
// Return Values :
//   true  - Success
//   false - Failure

bool  SimnGnuCap::bLoadSigSrc( void )
{
  // Search for and extract a signal source component
  if( SimnBase::bLoadSigSrc( ) )
    return( true );

  // Special treatment for a DC Signal Source
  if( eGetAnaType( ) == eCMD_DC )
  {
    m_oCpntSwpSrc.bClear( );
    m_oCpntSwpSrc.bSetName( m_oCmdDC.m_osSource );
    return( true );
  }

  return( false );
}

//**************************************************************************************************
// Clear all object attributes.
//
// Return Values :
//   true  - Success
//   false - Failure

bool  SimnGnuCap::bClear( void )
{
  // Clear the command object attributes
  bClrCmds( );

  // Clear the base class
  return( SimnBase::bClear( ) );
}

//**************************************************************************************************
// Clear all simulator command objects.
//
// Return Values :
//   true  - Success
//   false - Failure

bool  SimnGnuCap::bClrCmds( void )
{
  m_oCmdOPT.bSetDefaults( );
  m_oCmdOP .bSetDefaults( );
  m_oCmdDC .bSetDefaults( );
  m_oCmdAC .bSetDefaults( );
  m_oCmdTR .bSetDefaults( );
  m_oCmdFO .bSetDefaults( );
  m_oCmdPR .bSetDefaults( );
  m_oCmdGEN.bSetDefaults( );

  return( true );
}

//**************************************************************************************************
// Clear all test points ie. nodes and components.
//
// Return Values :
//   true  - Success
//   false - Failure

bool  SimnGnuCap::bClrTstPts( void )
{
  m_oCmdPR.m_osaNodes.Empty( );
  m_oCmdPR.m_osaCpnts.Empty( );

  return( true );
}

//**************************************************************************************************
// Do the current simulation settings constitute a valid simulation?
//
// Return Values :
//   true  - Valid
//   false - Not valid

bool  SimnGnuCap::bValidate( void )
{
  // Validate the base class
  SimnBase::bValidate( );

  if( ! m_oCmdOPT.bIsValid( ) ) SetErrMsg( m_oCmdOPT.rosGetErrMsg( ) );
  if( ! m_oCmdPR .bIsValid( ) ) SetErrMsg( m_oCmdPR .rosGetErrMsg( ) );
  if( ! m_oCmdGEN.bIsValid( ) ) SetErrMsg( m_oCmdGEN.rosGetErrMsg( ) );

  switch( eGetAnaType( ) )
  {
    case eCMD_OP :
      if( ! m_oCmdOP.bIsValid( ) ) SetErrMsg( m_oCmdOP.rosGetErrMsg( ) );
      break;

    case eCMD_DC :
      if( ! m_oCmdDC.bIsValid( ) ) SetErrMsg( m_oCmdDC.rosGetErrMsg( ) );
      break;

    case eCMD_AC :
      if( ! m_oCmdAC.bIsValid( ) ) SetErrMsg( m_oCmdAC.rosGetErrMsg( ) );
      break;

    case eCMD_TR :
      if( ! m_oCmdTR.bIsValid( ) ) SetErrMsg( m_oCmdTR.rosGetErrMsg( ) );
      break;

    case eCMD_FO :
      if( ! m_oCmdFO.bIsValid( ) ) SetErrMsg( m_oCmdFO.rosGetErrMsg( ) );
      break;

    default :
      SetErrMsg( wxT("No valid analysis command exists.") );
  }

  return( bIsValid( ) );
}

//**************************************************************************************************
// Load the simulation information from the netlist string array into the object attributes.
//
// Return Values :
//   true  - Success
//   false - Failure

bool  SimnGnuCap::bLoad( void )
{
  // Envoke the base class load operations
  return( SimnBase::bLoad( ) );
}

//**************************************************************************************************
// Save the simulation information to the netlist string array from the object attributes.
//
// Return Values :
//   true  - Success
//   false - Failure

bool  SimnGnuCap::bSave( void )
{
  // Envoke the base class save operations
  if( ! SimnBase::bSave( ) ) return( false );

  // Append the simulation command lines to the end of the file
  NetList::m_osaNetLst.Last( ) = wxT("********** GNU-Cap Simulation Commands **********");
  NetList::m_osaNetLst.Add( wxT("") );
  NetList::m_osaNetLst.Add( m_oCmdOPT );
  NetList::m_osaNetLst.Add( m_oCmdPR );
  if( m_oCmdGEN.bIsValid( ) ) NetList::m_osaNetLst.Add( m_oCmdGEN );
  if( m_oCmdOP .bIsValid( ) ) NetList::m_osaNetLst.Add( m_oCmdOP  );
  if( m_oCmdDC .bIsValid( ) ) NetList::m_osaNetLst.Add( m_oCmdDC  );
  if( m_oCmdAC .bIsValid( ) ) NetList::m_osaNetLst.Add( m_oCmdAC  );
  if( m_oCmdTR .bIsValid( ) ) NetList::m_osaNetLst.Add( m_oCmdTR  );
  if( m_oCmdFO .bIsValid( ) ) NetList::m_osaNetLst.Add( m_oCmdFO  );
  NetList::m_osaNetLst.Add( wxT("") );

  // Add the circuit description terminator
  NetList::m_osaNetLst.Add( wxT(".END") );

  return( true );
}

//**************************************************************************************************
// Add a node to the list of test points.
//
// Argument List :
//   rosName - The name of the node to be added to the list of test points
//
// Return Values :
//   true  - Success
//   false - Failure

bool  SimnGnuCap::bAddTstNode( const wxString & rosName )
{
  // Is the node name valid?
  if( rosName.IsEmpty( ) )                                 return( false );
  // Is the node name already in the test node list?
  if( rosaGetTstNodes( ).Index( rosName ) != wxNOT_FOUND ) return( true );

  // Add the node name to the list of test points
  m_oCmdPR.m_osaNodes.Add( rosName );
  m_oCmdPR.m_osaNodes.Sort( &iStrCmpNode );

  return( true );
}

//**************************************************************************************************
// Add a component to the list of test points.
//
// Argument List :
//   rosName - The name of the component to be added to the list of test points
//
// Return Values :
//   true  - Success
//   false - Failure

bool  SimnGnuCap::bAddTstCpnt( const wxString & rosName )
{
  // Is the component name valid?
  if( rosName.IsEmpty( ) )                                 return( false );
  // Is the component name already in the test component list?
  if( rosaGetTstCpnts( ).Index( rosName ) != wxNOT_FOUND ) return( true );

  // Add the component name to the list of test points
  m_oCmdPR.m_osaCpnts.Add( rosName );
  m_oCmdPR.m_osaCpnts.Sort( &iStrCmpCpnt );

  return( true );
}

//**************************************************************************************************
// Copy the contents of a SimnNgSpice object.
//
// Argument List :
//   roSimn - A reference to a SimnNgSpice object
//
// Return Values :
//   A reference to this object

SimnGnuCap & SimnGnuCap::operator = ( const SimnNgSpice & roSimn )
{
  (SimnBase &) *this = (SimnBase &) roSimn;

  m_oCmdOPT = roSimn.m_oCmdOPT;
  m_oCmdPR  = roSimn.m_oCmdPR;
  m_oCmdGEN = roSimn.m_oCpntIndSrc;

  if( roSimn.eGetAnaType( ) == eCMD_DC )
    if( roSimn.m_oCmdDC.m_osSource == wxT("TEMP") )
      m_oCmdPR.bSetAnaType( eCMD_OP );

  switch( eGetAnaType( ) )
  {
    case eCMD_OP :
      m_oCmdOP = roSimn.m_oCmdDC;
      break;

    case eCMD_DC :
      m_oCmdDC = roSimn.m_oCmdDC;
      break;

    case eCMD_AC :
      m_oCmdAC = roSimn.m_oCmdAC;
      break;

    case eCMD_TR :
      m_oCmdTR = roSimn.m_oCmdTR;
      break;

    default :
      break;
  }

  return( *this );
}

//**************************************************************************************************
// Print the object attributes.
//
// Argument List :
//   rosPrefix - A prefix to every line displayed (usually just spaces)

void  SimnGnuCap::Print( const wxString & rosPrefix )
{
  SimnBase::Print( rosPrefix + wxT("SimnBase::") );

  m_oCmdOPT.Print( rosPrefix + wxT("m_oCmdOPT.") );
  m_oCmdOP .Print( rosPrefix + wxT("m_oCmdOP.")  );
  m_oCmdDC .Print( rosPrefix + wxT("m_oCmdDC.")  );
  m_oCmdAC .Print( rosPrefix + wxT("m_oCmdAC.")  );
  m_oCmdTR .Print( rosPrefix + wxT("m_oCmdTR.")  );
  m_oCmdFO .Print( rosPrefix + wxT("m_oCmdFO.")  );
  m_oCmdPR .Print( rosPrefix + wxT("m_oCmdPR.")  );
  m_oCmdGEN.Print( rosPrefix + wxT("m_oCmdGEN.") );
}

//**************************************************************************************************