⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simulation.cpp

📁 gspiceui电子CAD仿真程序.用于电路参数模拟仿真
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//*****************************************************************************//                                Simulation.cpp                              *//                               ----------------                             *//  Started     : 23/09/2003                                                  *//  Last Update : 21/06/2005                                                  *//  Copyright   : (C) 2003 by MSWaters                                        *//  Email       : M.Waters@bom.gov.au                                         *//*****************************************************************************//*****************************************************************************//                                                                            *//    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 2 of the License, or       *//    (at your option) any later version.                                     *//                                                                            *//*****************************************************************************#include "Simulation.hpp"//*****************************************************************************// Constructor.Simulation::Simulation( void ){  // Initialize all object attributes  Clear( );}//*****************************************************************************// Destructor.Simulation::~Simulation( ){}//*****************************************************************************// Extract the simulator type.//// Return Values://   TRUE  - Success//   FALSE - Failurebool  Simulation::bExtractSimrType( void ){  wxString  os1;  size_t    szt1;  // Scan the circuit description for simulator type  for( szt1=0; szt1<GetCount( ); szt1++ )  {    os1 = Item( szt1 );    if( os1.IsEmpty( ) ) continue;    os1.MakeUpper( );    if( os1.Contains( wxT("GNU-CAP") ) )    {      m_eSimrType = eSIMR_GNUCAP;      return( TRUE );    }    if( os1.Contains( wxT("NG-SPICE") ) )    {      m_eSimrType = eSIMR_NGSPICE;      return( TRUE );    }  }  return( FALSE );}//*****************************************************************************// Extract all the simulator command lines from the circuit description.// The following commands are currently detected and extracted:////   .OPTIONS//   .GENERATOR//   .IC//   .OP//   .DC//   .AC//   .TRANSIENT//   .PRINT//// Return Values://   TRUE  - Success//   FALSE - Failurebool  Simulation::bExtractSimCmds( void ){  wxString  os1, os2;  size_t    szt1;  m_oasSimCmds.Empty( );  // Scan the circuit description for simulation commands  for( szt1=0; szt1<GetCount( ); szt1++ )  {    os1 = Item( szt1 );    if( os1.IsEmpty( ) )               continue;    if( ! os1.StartsWith( wxT(".") ) ) continue;    os1.MakeUpper( );    if(      os1.StartsWith( wxT(".OPT") ) ) ;    else if( os1.StartsWith( wxT(".GEN") ) ) ;    else if( os1.StartsWith( wxT(".IC")  ) ) ;    else if( os1.StartsWith( wxT(".OP")  ) ) ;    else if( os1.StartsWith( wxT(".DC")  ) ) ;    else if( os1.StartsWith( wxT(".AC")  ) ) ;    else if( os1.StartsWith( wxT(".TR")  ) ) ;    else if( os1.StartsWith( wxT(".PR")  ) ) ;    else continue;    os1 << wxT('\n');    m_oasSimCmds.Add( Item( szt1 ) );  }  return( TRUE );}//*****************************************************************************// Extract the source component.//// Return Values://   TRUE  - Success//   FALSE - Failurebool  Simulation::bExtractSrcCpnt( void ){  wxString  os1;  size_t    szt1;  m_osSrcCpnt[ 0 ].Empty( );  m_osSrcCpnt[ 1 ].Empty( );  // Scan the circuit description for a source component  for( szt1=0; szt1<GetCount( )-1; szt1++ )  {    os1 = Item( szt1 );    if( os1.IsEmpty( ) )                   continue;    if( ! os1.StartsWith( wxT("*") ) )     continue;    if( os1.Mid( 2, 6 ) != wxT("Source") ) continue;    os1 = os1.AfterFirst( wxT('(') );    os1 = os1.BeforeLast( wxT(')') );    if( os1.Length( ) < 7 )                continue; // Min. line eg. "R 0 1 5"    m_osSrcCpnt[ 0 ] = Item( szt1 + 1 );    m_osSrcCpnt[ 1 ] = os1;    break;  }  // Was a source component found?  if( m_osSrcCpnt[ 0 ].IsEmpty( ) ) return( FALSE );  return( TRUE );}//*****************************************************************************// Clear all object attributes.bool  Simulation::bClear( void ){  bool  bRtn=TRUE;  uint  ui1;  // Clear all parameter specifiers  for( ui1=ePAR_FST; ui1<=ePAR_LST; ui1++ )    if( ! bSetOutPar( (eParType) ui1, FALSE ) )      bRtn = FALSE;  // Clear all parameter specifiers  for( ui1=eCPX_FST; ui1<=eCPX_LST; ui1++ )    if( ! bSetOutCpx( (eCpxType) ui1, FALSE ) )      bRtn = FALSE;  // Clear the simulation engine and analysis type specifiers  if( ! bSetSimrType( eSIMR_NONE ) ) bRtn = FALSE;  if( ! bSetAnaType( eANA_NONE ) )   bRtn = FALSE;  // Clear the sweep parameter array  for( ui1=0; ui1<eSWP_SIZE; ui1++ ) m_fSwp[ ui1 ] = -FLT_MAX;  // Clear temperature  m_fTempC = 27.0;  // Clear everything else  m_oasTstNodes .Clear( );  m_oasTstCpnts .Clear( );  m_oasSimCmds  .Clear( );  m_osSrcCpnt[0].Clear( );  m_osSrcCpnt[1].Clear( );  m_osErrMsg    .Clear( );  return( bRtn );}//*****************************************************************************// Do the current simulation settings constitute a valid simulation?//// Return Values://   TRUE  - Settings are     valid//   FALSE - Settings are not validbool  Simulation::bIsValid( void ){  uint  ui1;  m_osErrMsg.Clear( );  // Have any test components or test nodes been specified?  if( m_oasTstNodes.GetCount( )>0 || m_oasTstCpnts.GetCount( )>0 )  {    m_osErrMsg = wxT("No nodes or components have been selected.");    return( FALSE );  }    // Has at least one parameter been specified?  for( ui1=ePAR_FST; ui1<=ePAR_LST; ui1++ )  {    if( bGetOutPar( (eParType) ui1 ) ) break;    if( ui1>=ePAR_LST )    {      m_osErrMsg = wxT("No calculation parameters have been specified.");      return( FALSE );    }  }  return( TRUE );}//*****************************************************************************// Load (or reload) the simulation from file.//// Arguments://   psFName - The name of the file to be loaded//// Return Values://   TRUE  - Success//   FALSE - Failurebool  Simulation::bLoadFile( const wxChar * psFName ){  if( ! NetList::bLoadFile( psFName ) ) return( FALSE );  bExtractSimrType( );  bExtractSimCmds( );  bExtractSrcCpnt( );    return( TRUE );}//*****************************************************************************// Save (or resave) the simulation to file.//// Arguments://   psFName - The name of the file to be saved//// Return Values://   TRUE  - Success//   FALSE - Failurebool  Simulation::bSaveFile( const wxChar * psFName ){  wxString  os1;  size_t    szt1;  // Save the net list to file  if( ! NetList::bSaveFile( psFName ) ) return( FALSE );  // Open the file  wxTextFile  oFileCct( m_oFnmSave.GetFullPath( ) );  if( ! oFileCct.Open( ) )              return( FALSE );  // Find the source component and insert a comment before it  if( !m_osSrcCpnt[ 0 ].IsEmpty( ) && !m_osSrcCpnt[ 1 ].IsEmpty( ) )  {    for( os1=oFileCct.GetFirstLine(); !oFileCct.Eof(); os1=oFileCct.GetNextLine() )    {      if( m_osSrcCpnt[ 0 ].BeforeFirst( wxT(' ') ) == os1.BeforeFirst( wxT(' ') ) )      {        os1.Empty( );        os1 << wxT("* Source (") << m_osSrcCpnt[ 1 ] << wxT(')');        szt1 = oFileCct.GetCurrentLine( );        oFileCct.InsertLine( os1, szt1 );        break;      }    }  }  // Temporarily remove the circuit description terminator ie. ".END"  oFileCct.RemoveLine( oFileCct.GetLineCount( )-1 );  // Append the simulation command lines to the end of the file  os1 = wxT("* ");  switch( m_eSimrType )  {    case eSIMR_GNUCAP:  os1 << wxT("GNU-Cap ");  break;    case eSIMR_NGSPICE: os1 << wxT("Ng-Spice "); break;    default: break;  }  os1 << wxT("Simulation Commands");  oFileCct.AddLine( os1 );  for( szt1=0; szt1<m_oasSimCmds.Count( ); szt1++ )    oFileCct.AddLine( m_oasSimCmds[ szt1 ] );  oFileCct.AddLine( wxT("") );  // Add the circuit description terminator  oFileCct.AddLine( wxT(".END") );  oFileCct.AddLine( wxT("") );  // Save the changes to disk  oFileCct.Write( );  oFileCct.Close( );  return( TRUE );}//*****************************************************************************// Select the simulation engine used.//// Arguments://   eSimr - The simulation engine type//// Return Values://   TRUE  - Success//   FALSE - Failurebool  Simulation::bSetSimrType( eSimrType eSimr ){  if( eSimr<eSIMR_FST || eSimr>eSIMR_LST ) return( FALSE );  m_eSimrType = eSimr;  return( TRUE );}//*****************************************************************************// Select the analysis to be performed.//// Arguments://   eAna - The analysis type//// Return Values:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -