Blame view

GUI/SW2/SRC/src/netlist/CpntNgsIndSrc.cpp 12.7 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
//**************************************************************************************************
//                                        CpntNgsIndSrc.cpp                                        *
//                                       -------------------                                       *
// Started     : 2008-06-12                                                                        *
// Last Update : 2014-12-15                                                                        *
// 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 "CpntNgsIndSrc.hpp"

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

CpntNgsIndSrc::CpntNgsIndSrc( void ) : Component( )
{
  bClear( );
}

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

CpntNgsIndSrc::~CpntNgsIndSrc( )
{
}

//**************************************************************************************************
// Parse the value part of the component definition string.
//
// Eg. : Vin 3 0 SIN(0 1 100Meg 1ns 1E10)
//
// Return Values :
//   true  - Success
//   false - Failure

bool  CpntNgsIndSrc::bParseValue( void )
{
  wxStringTokenizer  ostk1;
  size_t             szSin, szPulse;
  size_t             sz1, sz2;

  ClrValues( );

  // Find the beginning of the SIN and/or PULSE sections
  szSin   = Component::m_osValue.Upper( ).Find( wxT("SIN(") );
  szPulse = Component::m_osValue.Upper( ).Find( wxT("PULSE(") );
  if( szSin==wxString::npos && szPulse==wxString::npos ) return( false );

  // Extract the sinusoid function parameter values
  if( szSin != wxString::npos )
  {
    sz1 = Component::m_osValue.find( wxT('('), szSin );
    sz2 = Component::m_osValue.find( wxT(')'), szSin );
    if( sz1==wxString::npos || sz2==wxString::npos )     return( false );

    ostk1.SetString( Component::m_osValue.substr( sz1+1, sz2-sz1-1 ) );
    if( ostk1.CountTokens( ) != 5 )                      return( false );

    m_osSinOffset = ostk1.GetNextToken( );
    m_osSinAmp    = ostk1.GetNextToken( );
    m_osSinFreq   = ostk1.GetNextToken( );
    m_osSinDelay  = ostk1.GetNextToken( );
    m_osSinDamp   = ostk1.GetNextToken( );
  }

  // Extract the pulse function parameter values
  if( szPulse != wxString::npos )
  {
    sz1 = Component::m_osValue.find( wxT('('), szPulse );
    sz2 = Component::m_osValue.find( wxT(')'), szPulse );
    if( sz1==wxString::npos || sz2==wxString::npos )     return( false );

    ostk1.SetString( Component::m_osValue.substr( sz1+1, sz2-sz1-1 ) );
    if( ostk1.CountTokens( ) != 7 )                      return( false );

    m_osPulInitial = ostk1.GetNextToken( );
    m_osPulMax     = ostk1.GetNextToken( );
    m_osPulDelay   = ostk1.GetNextToken( );
    m_osPulRise    = ostk1.GetNextToken( );
    m_osPulFall    = ostk1.GetNextToken( );
    m_osPulWidth   = ostk1.GetNextToken( );
    m_osPulPeriod  = ostk1.GetNextToken( );
  }

  return( true );
}

//**************************************************************************************************
// Format the value part of the command string.
//
// Eg. : Vin 3 0 SIN(0 1 100Meg 1ns 1E10)
//
// Return Values :
//   true  - Success
//   false - Failure

bool  CpntNgsIndSrc::bFormatValue( void )
{
  float  f1;
  bool   b1;

  m_osValue.Empty( );

  f1 = 0.0;
  b1 = CnvtType::bStrToFlt( m_osSinAmp, &f1 );
  if( b1==true && f1!=0.0 )
  { // Create the sinusoid function section
    m_osValue << wxT("SIN( ");
    m_osValue << m_osSinOffset << wxT(' ');
    m_osValue << m_osSinAmp    << wxT(' ');
    m_osValue << m_osSinFreq   << wxT(' ');
    m_osValue << m_osSinDelay  << wxT(' ');
    m_osValue << m_osSinDamp   << wxT(' ');
    m_osValue << wxT(')');
  }

  f1 = 0.0;
  b1 = CnvtType::bStrToFlt( m_osPulMax, &f1 );
  if( b1==true && f1!=0.0 )
  { // Create the pulse function section
    if( ! m_osValue.IsEmpty( ) ) m_osValue << wxT(' ');
    m_osValue << wxT("PULSE( ");
    m_osValue << m_osPulInitial << wxT(' ');
    m_osValue << m_osPulMax     << wxT(' ');
    m_osValue << m_osPulDelay   << wxT(' ');
    m_osValue << m_osPulRise    << wxT(' ');
    m_osValue << m_osPulFall    << wxT(' ');
    m_osValue << m_osPulWidth   << wxT(' ');
    m_osValue << m_osPulPeriod  << wxT(' ');
    m_osValue << wxT(')');
  }

  if( m_osValue.IsEmpty( ) ) m_osValue = wxT("0.0");

  return( true );
}

//**************************************************************************************************
// Check that the object attributes are valid.
//
// Return Values :
//   true  - Success
//   false - Failure

bool  CpntNgsIndSrc::bValidate( void )
{
  double  dfSinOffset, dfSinAmp, dfSinFreq, dfSinDelay, dfSinDamp;
  double  dfPulInitial, dfPulMax, dfPulDelay, dfPulRise, dfPulWidth, dfPulFall,
          dfPulPeriod;

  // Check the validity of the base component
  if( ! Component::bValidate( ) )                return( false );

  // Check that the component type is valid
  if( m_eType!=eCPNT_IVS && m_eType!=eCPNT_ICS ) return( false );

  // Check the sinusoidal source values
  dfSinAmp    = 0.0;
  dfSinOffset = 0.0;
  dfSinFreq   = 0.0;
  dfSinDelay  = 0.0;
  dfSinDamp   = 0.0;
  if( ! CnvtType::bStrToFlt( m_osSinOffset, &dfSinOffset ) )
    bSetErrMsg( wxT("sinusoid offset value is invalid") );
  if( ! CnvtType::bStrToFlt( m_osSinAmp,    &dfSinAmp    ) )
    bSetErrMsg( wxT("sinusoid amplitude value is invalid") );
  if( ! CnvtType::bStrToFlt( m_osSinFreq,   &dfSinFreq   ) )
    bSetErrMsg( wxT("sinusoid frequency value is invalid") );
  if( ! CnvtType::bStrToFlt( m_osSinDelay,  &dfSinDelay  ) )
    bSetErrMsg( wxT("sinusoid delay value is invalid") );
  if( ! CnvtType::bStrToFlt( m_osSinDamp,   &dfSinDamp   ) )
    bSetErrMsg( wxT("sinusoid damping factor is invalid") );

  // Check overall sinusoidal source logic
  if( dfSinFreq>0.0 && dfSinAmp <=0.0 )
    bSetErrMsg( wxT("sinusoid amplitude value must be greater than zero") );
  if( dfSinAmp >0.0 && dfSinFreq<=0.0 )
    bSetErrMsg( wxT("sinusoid frequency must be greater than zero") );

  // Check the pulse source values
  dfPulInitial = 0.0;
  dfPulMax     = 0.0;
  dfPulDelay   = 0.0;
  dfPulRise    = 0.0;
  dfPulWidth   = 0.0;
  dfPulFall    = 0.0;
  dfPulPeriod  = 0.0;
  if( ! CnvtType::bStrToFlt( m_osPulInitial, &dfPulInitial ) )
    bSetErrMsg( wxT("initial pulse value is invalid") );
  if( ! CnvtType::bStrToFlt( m_osPulMax,     &dfPulMax     ) )
    bSetErrMsg( wxT("maximum pulse value is invalid") );
  if( ! CnvtType::bStrToFlt( m_osPulDelay,   &dfPulDelay   ) )
    bSetErrMsg( wxT("pulse delay value is invalid") );
  if( ! CnvtType::bStrToFlt( m_osPulRise,    &dfPulRise    ) )
    bSetErrMsg( wxT("pulse rise time value is invalid") );
  if( ! CnvtType::bStrToFlt( m_osPulWidth,   &dfPulWidth   ) )
    bSetErrMsg( wxT("pulse width value is invalid") );
  if( ! CnvtType::bStrToFlt( m_osPulFall,    &dfPulFall    ) )
    bSetErrMsg( wxT("pulse fall time value is invalid") );
  if( ! CnvtType::bStrToFlt( m_osPulPeriod,  &dfPulPeriod  ) )
    bSetErrMsg( wxT("pulse period value is invalid") );

  // Check the pulse time values
  if( dfPulPeriod < dfPulRise )
    bSetErrMsg( wxT("pulse rise time is greater than the period") );
  if( dfPulPeriod < dfPulWidth )
    bSetErrMsg( wxT("pulse width is greater than the period") );
  if( dfPulPeriod < dfPulFall )
    bSetErrMsg( wxT("pulse fall time is greater than the period") );
  if( dfPulPeriod < dfPulRise+dfPulWidth+dfPulFall )
    bSetErrMsg( wxT("pulse period is less then the width") );

  // Check the pulse level values
  if( dfPulInitial > dfPulMax )
    bSetErrMsg( wxT("initial pulse value is greater than the maximum value") );

  // Check overall pulse source logic
  if( dfPulPeriod!=0.0 && (dfPulInitial==0.0 && dfPulMax==0.0) )
    bSetErrMsg( wxT("pulse timing has been defined but no levels") );
  if( dfPulPeriod==0.0 && (dfPulInitial!=0.0 || dfPulMax!=0.0) )
    bSetErrMsg( wxT("pulse levels have been defined but no timings") );

  return( bIsValid( ) );
}

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

void  CpntNgsIndSrc::ClrValues( void )
{
  m_osSinOffset  = NGS_SINOFFSET;
  m_osSinAmp     = NGS_SINAMP;
  m_osSinFreq    = NGS_SINFREQ;
  m_osSinDelay   = NGS_SINDELAY;
  m_osSinDamp    = NGS_SINDAMP;

  m_osPulInitial = NGS_PULINITIAL;
  m_osPulMax     = NGS_PULMAX;
  m_osPulDelay   = NGS_PULDELAY;
  m_osPulRise    = NGS_PULRISE;
  m_osPulWidth   = NGS_PULWIDTH;
  m_osPulFall    = NGS_PULFALL;
  m_osPulPeriod  = NGS_PULPERIOD;
}

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

bool  CpntNgsIndSrc::bClear( void )
{
  Component::bClear( );

  ClrValues( );

  return( true );
}

//**************************************************************************************************
// Copy and digest the contents of a Component object.
//
// Argument List :
//   roCpnt - A reference to a Component object
//
// Return Values :
//   A reference to this object

CpntNgsIndSrc & CpntNgsIndSrc::operator = ( const Component & roCpnt )
{
  // Copy the component contents
  (Component &) *this = roCpnt;

  // Parse the value part of the component definition
  bParseValue( );

  return( *this );
}

//**************************************************************************************************
// Copy the contents of an CmdGnuCapGEN object.
//
// Argument List :
//   roCmdGEN - A reference to a CmdGnuCapGEN object
//
// Return Values :
//   A reference to this object

CpntNgsIndSrc & CpntNgsIndSrc::operator = ( const CmdGnuCapGEN & roCmdGEN )
{
  double  df1, df2;

  m_osSinOffset  = roCmdGEN.m_osOffset;
  m_osSinAmp     = roCmdGEN.m_osAmplitude;
  m_osSinFreq    = roCmdGEN.m_osSinFreq;
  if( CnvtType::bStrToFlt( roCmdGEN.m_osSinPhase, &df1 ) &&
      CnvtType::bStrToFlt( roCmdGEN.m_osSinFreq,  &df2 ) )
    CnvtType::bFltToStr( df1 / (360.0 * df2), m_osSinDelay );
  else
    m_osSinDelay = wxT("0.0");
  m_osSinDamp    = wxT("0.0");

  m_osPulInitial = roCmdGEN.m_osPulInitial;
  m_osPulMax     = roCmdGEN.m_osPulMax;
  m_osPulDelay   = roCmdGEN.m_osPulDelay;
  m_osPulRise    = roCmdGEN.m_osPulRise;
  m_osPulWidth   = roCmdGEN.m_osPulWidth;
  m_osPulFall    = roCmdGEN.m_osPulFall;
  m_osPulPeriod  = roCmdGEN.m_osPulPeriod;

  bFormat( );

  return( *this );
}

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

void  CpntNgsIndSrc::Print( const wxString & rosPrefix )
{
  Component::Print( rosPrefix + wxT("Component::") );

  std::cout << rosPrefix.mb_str( ) << "m_osSinOffset   : " << m_osSinOffset .mb_str( ) << '\n';
  std::cout << rosPrefix.mb_str( ) << "m_osSinAmp      : " << m_osSinAmp    .mb_str( ) << '\n';
  std::cout << rosPrefix.mb_str( ) << "m_osSinFreq     : " << m_osSinFreq   .mb_str( ) << '\n';
  std::cout << rosPrefix.mb_str( ) << "m_osSinDelay    : " << m_osSinDelay  .mb_str( ) << '\n';
  std::cout << rosPrefix.mb_str( ) << "m_osSinDamp     : " << m_osSinDamp   .mb_str( ) << '\n';

  std::cout << rosPrefix.mb_str( ) << "m_osPulseInitV  : " << m_osPulInitial.mb_str( ) << '\n';
  std::cout << rosPrefix.mb_str( ) << "m_osPulseMaxV   : " << m_osPulMax    .mb_str( ) << '\n';
  std::cout << rosPrefix.mb_str( ) << "m_osPulseDelay  : " << m_osPulDelay  .mb_str( ) << '\n';
  std::cout << rosPrefix.mb_str( ) << "m_osPulseRise   : " << m_osPulRise   .mb_str( ) << '\n';
  std::cout << rosPrefix.mb_str( ) << "m_osPulseWidth  : " << m_osPulWidth  .mb_str( ) << '\n';
  std::cout << rosPrefix.mb_str( ) << "m_osPulseFall   : " << m_osPulFall   .mb_str( ) << '\n';
  std::cout << rosPrefix.mb_str( ) << "m_osPulsePeriod : " << m_osPulPeriod .mb_str( ) << '\n';
}

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