Blame view

GUI/SW2/SRC/src/base/SimnBase.cpp 8.46 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
//**************************************************************************************************
//                                          SimnBase.cpp                                           *
//                                         --------------                                          *
// Started     : 2008-05-01                                                                        *
// Last Update : 2016-10-01                                                                        *
// 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 "SimnBase.hpp"

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

SimnBase::SimnBase( void )
{
  m_eSimEng = eSIMR_NONE;

  // Initialize all object attributes
  bClear( );
}

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

SimnBase::~SimnBase( )
{
}

//**************************************************************************************************
// Extract the source component.
//
// Several tasks are performed here :
//  - Search for a component which is being used as a signal source.
//  - Extract the source component's original definition.
//  - Set the attribute m_oCpntSwpSrc to the source component definition.
//  - Set the component in m_oaCpnts to it's original definition.
//
// Return Values :
//   true  - Success
//   false - Failure

bool  SimnBase::bLoadSigSrc( void )
{
  Component  oCpnt;
  wxString   os1;
  size_t     sz1;

  // Scan the circuit description for a source component
  for( sz1=0; sz1<m_osaNetLst.GetCount( )-1; sz1++, os1.Empty( ) )
  {
    os1 = m_osaNetLst.Item( sz1 );

    // Is this a signal source?
    if(   os1.IsEmpty( ) )                             continue; // No
    if( ! os1.StartsWith( wxT("* Signal source (") ) ) continue; // No
    if(   os1.GetChar( os1.Len( )-1 ) != wxT(')') )    continue; // No
    break;                                                       // Yes, looks like a signal source
  }
  if( os1.IsEmpty( ) )      return( false );

  // Attempt to extract the original component definition
  os1 = os1.AfterFirst( wxT('(') );
  os1 = os1.BeforeLast( wxT(')') );
  oCpnt = os1;
  if( ! oCpnt.bIsValid( ) ) return( false );

  // Set the source component
  m_oCpntSwpSrc = m_osaNetLst.Item( sz1 + 1 );

  // Scan the component list for the source component
  for( sz1=0; sz1<m_oaCpnts.GetCount( ); sz1++ )
  {
    if( m_oaCpnts.Item( sz1 ).rosGetName( ) == oCpnt.rosGetName( ) )
    {
      // Set the signal source component back to it's original definition
      m_oaCpnts.Item( sz1 ) = oCpnt.rosGetString( );
      break;
    }
  }

  return( true );
}

//**************************************************************************************************
// If a signal source has been defined save it's current and original definitions in the netlist
// string array : NetList::m_osaNetLst
//
// Return Values :
//   true  - Success
//   false - Failure

bool  SimnBase::bSaveSigSrc( void )
{
  Component  oCpnt;
  wxString   os1;
  size_t     sz1;

  // If a signal source has been selected insert it in the simulation file
  if( ! m_oCpntSwpSrc.bIsValid( ) ) return( true );

  // Find the original definition of the signal source component
  for( sz1=0; sz1<m_oaCpnts.GetCount( ); sz1++ )
    if( m_oCpntSwpSrc.rosGetName( ) == m_oaCpnts[ sz1 ].rosGetName( ) )
      break;

  // Find the source component and insert a comment before it
  for( sz1=0; sz1<NetList::m_osaNetLst.GetCount( ); sz1++ )
  {
    // Is this a component definition?
    oCpnt = NetList::m_osaNetLst.Item( sz1 );
    if( ! oCpnt.bIsValid( ) ) continue;

    // Is this the signal source component?
    if( oCpnt.rosGetName( ) == m_oCpntSwpSrc.rosGetName( ) )
    {
      NetList::m_osaNetLst.Item( sz1 ) = m_oCpntSwpSrc.rosGetString( );
      os1 = wxT("* Signal source (") + oCpnt.rosGetString( ) + wxT(')');
      NetList::m_osaNetLst.Insert( os1, sz1 );
      break;
    }
  }

  return( true );
}

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

bool  SimnBase::bClear( void )
{
  // Clear the sweep source component
  m_oCpntSwpSrc.bClear( );
  m_oCpntSwpSrc.bSetName( wxT("None") );

  // Clear any error messages
  m_osErrMsg.Empty( );

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

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

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

  // Clear the error message
  m_osErrMsg.Clear( );

  // Check the simulation engine
  if( m_eSimEng == eSIMR_NONE )
  {
    SetErrMsg( wxT("No simulation engine has been specified.") );
    return( false );
  }

  // Check the analysis type
  if( eGetAnaType( ) == eCMD_NONE )
  {
    SetErrMsg( wxT("No analysis type has been specified.") );
    return( false );
  }

  // Have any test components or test nodes been specified?
  if( rosaGetTstNodes( ).GetCount( )<=0 || rosaGetTstCpnts( ).GetCount( )<=0 )
  {
    SetErrMsg( wxT("No nodes or components have been selected.") );
    return( false );
  }

  return( true );
}

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

bool  SimnBase::bLoad( void )
{
  // Envoke the base class load operations
  if( ! NetList::bLoad( ) ) return( false );

  // Check for a simulator signifier
  if( ! bLoadSimEng( ) )    return( false );

  // Extract the simulator instructions
  bLoadSimCmds( );
  bLoadSigSrc ( );

  return( true );
}

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

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

  // Save the signal source to the simulation file
  if( ! bSaveSigSrc( ) )    return( false );

  return( true );
}

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

SimnBase & SimnBase::operator = ( const SimnBase & roSimn )
{
  m_oCpntSwpSrc = roSimn.m_oCpntSwpSrc;

  return( *this );
}

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

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

  std::cout << rosPrefix.mb_str( )  << "m_eSimEng  : ";
  switch( m_eSimEng )
  {
    case eSIMR_GNUCAP  : std::cout << "eSIMR_GNUCAP";  break;
    case eSIMR_NGSPICE : std::cout << "eSIMR_NGSPICE"; break;
    case eSIMR_NONE    : std::cout << "eSIMR_NONE";    break;
  }
  std::cout << '\n';

  std::cout << rosPrefix .mb_str( ) << "m_osErrMsg : " << m_osErrMsg.mb_str( ) << '\n';

  m_oCpntSwpSrc.Print( rosPrefix + wxT("m_oCpntSwpSrc::") );
}

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