📄 netlist.cpp
字号:
cCpnt = wxToupper( os1.GetChar( 0 ) ); os1 = oStrTok.GetNextToken( ); // First node if( m_oasNodeLbls.Index( os1 ) == wxNOT_FOUND ) m_oasNodeLbls.Add( os1 ); os1 = oStrTok.GetNextToken( ); // Second node if( m_oasNodeLbls.Index( os1 ) == wxNOT_FOUND ) m_oasNodeLbls.Add( os1 ); if( cCpnt == wxT('Q') ) { if( oStrTok.CountTokens( ) > 3 ) { os1 = oStrTok.GetNextToken( ); // Third node if( m_oasNodeLbls.Index( os1 ) == wxNOT_FOUND ) m_oasNodeLbls.Add( os1 ); } continue; } if( cCpnt == wxT('X') ) { for( size_t szt2=3; szt2<oStrTok.CountTokens( )-1; szt2++ ) { os1 = oStrTok.GetNextToken( ); // Nth node if( m_oasNodeLbls.Index( os1 ) == wxNOT_FOUND ) m_oasNodeLbls.Add( os1 ); } continue; } } if( m_oasNodeLbls.IsEmpty( ) ) return( FALSE ); m_oasNodeLbls.Remove( wxT("0") ); // Remove the earth/ground node ??? m_oasNodeLbls.Remove( wxT("GND") ); m_oasNodeLbls.Sort( &iCompare ); return( TRUE );}//*****************************************************************************// Extract all component labels from the component line string array.//// Return Values:// TRUE - Success// FALSE - Failurebool NetList::bExtractCpntLbls( void ){ // Check that there are some components if( m_oasCpnts.GetCount( ) <= 0 ) return( FALSE ); wxStringTokenizer oStrTok; wxString os1; size_t szt1; for( szt1=0; szt1<m_oasCpnts.GetCount( ); szt1++ ) { os1 = m_oasCpnts.Item( szt1 ); oStrTok.SetString( os1 ); if( oStrTok.CountTokens( ) < 1 ) return( FALSE ); os1 = oStrTok.GetNextToken( ); // Only collect two terminal components switch( wxToupper( os1.GetChar(0) ) ) { case 'C': break; // Capacitor case 'D': break; // Diode case 'L': break; // Inductor case 'R': break; // Resistor case 'V': break; // Voltage source case 'Y': break; // Admittance default: continue; } m_oasCpntLbls.Add( os1 ); } m_oasCpntLbls.Sort( &iCompare ); return( TRUE );}//*****************************************************************************// Extract the data that has been loaded into the string array this class is// derived from.//// Return Values:// TRUE - Success// FALSE - Failurebool NetList::bExtract( void ){ bool bRtn=TRUE; if( ! IsEmpty( ) ) { if( ! bExtractTitle( ) ) bRtn = FALSE; if( ! bExtractIncludes( ) ) bRtn = FALSE; if( ! bExtractCpnts( ) ) bRtn = FALSE; if( ! bExtractModels( ) ) bRtn = FALSE; if( ! bExtractSubCcts( ) ) bRtn = FALSE; if( ! bExtractNodeLbls( ) ) bRtn = FALSE; if( ! bExtractCpntLbls( ) ) bRtn = FALSE; } else bRtn = FALSE; return( bRtn );}//*****************************************************************************// Makes the object and its attributes empty and frees memory allocated to it.//// Return Values:// TRUE - Success// FALSE - Failurebool NetList::bClear( void ){ wxArrayString::Clear( ); m_oasTitle .Clear( ); m_oasIncludes.Clear( ); m_oasCpnts .Clear( ); m_oasModels .Clear( ); m_oasSubCcts .Clear( ); m_oasNodeLbls.Clear( ); m_oasCpntLbls.Clear( ); return( TRUE );}//*****************************************************************************// Makes the object and its attributes empty, but doesn't free memory allocated// to it . This function should be used when the object is going to be reused// for storing other data.//// Return Values:// TRUE - Success// FALSE - Failurebool NetList::bEmpty( void ){ wxArrayString::Empty( ); m_oasTitle .Empty( ); m_oasIncludes.Empty( ); m_oasCpnts .Empty( ); m_oasModels .Empty( ); m_oasSubCcts .Empty( ); m_oasNodeLbls.Empty( ); m_oasCpntLbls.Empty( ); return( TRUE );}//*****************************************************************************// Load (or reload) the circuit from file.//// Arguments:// psFName - The name of the file to be loaded//// Return Values:// TRUE - Success// FALSE - Failurebool NetList::bLoadFile( const wxChar * psFName ){ wxString os1; // Is this a load or reload? if( psFName != NULL ) { if( ! bSetLoadFile( psFName ) ) return( FALSE ); } else { if( !m_oFnmLoad.IsOk() || !m_oFnmLoad.FileExists() ) return( FALSE ); } bEmpty( ); // Clear the object attributes // Open the file wxTextFile oFileCct( m_oFnmLoad.GetFullPath( ) ); oFileCct.Open( ); if( ! oFileCct.IsOpened( ) ) { oFileCct.Close( ); return( FALSE ); } if( oFileCct.GetLineCount( ) < 3 ) { oFileCct.Close( ); return( FALSE ); } // Load the file contents for( os1=oFileCct.GetFirstLine(); !oFileCct.Eof(); os1=oFileCct.GetNextLine() ) Add( os1 ); // Need the following line in case the last line in the file is not empty // but has no line termination character if( os1.Length( ) > 0 ) Add( os1 ); oFileCct.Close( ); // Close the file // Attempt to extract the circuit description from file if( ! bExtract( ) ) { Empty( ); return( FALSE ); } return( TRUE );}//*****************************************************************************// Save (or resave) the circuit to file.//// Arguments:// psFName - The name of the file to be saved//// Return Values:// TRUE - Success// FALSE - Failurebool NetList::bSaveFile( const wxChar * psFName ){ wxString os1; wxString os2; size_t szt1; // Is this a load or reload? if( psFName != NULL ) { if( ! bSetSaveFile( psFName ) ) return( FALSE ); } else { if( ! m_oFnmSave.IsOk( ) ) return( FALSE ); } // Open the file wxTextFile oFileCct( m_oFnmSave.GetFullPath( ) ); if( oFileCct.Exists( ) ) { if( ! oFileCct.Open( ) ) return( FALSE ); } else { if( ! oFileCct.Create( ) ) return( FALSE ); } // Clear the file if it contains lines for( szt1=oFileCct.GetLineCount( ); szt1>0; szt1-- ) oFileCct.RemoveLine( 0 ); // Save the circuit description title line/s os1.Empty( ); os1 << wxT("*****************************************************"); oFileCct.AddLine( os1 ); os2.Empty( ); os2 << wxT("* SPICE file generated by ") << APP_NAME << wxT(" *"); oFileCct.AddLine( os2 ); os2.Empty( ); os2 << wxT("* ") << APP_VERSION << wxT(" *"); oFileCct.AddLine( os2 ); oFileCct.AddLine( os1 ); oFileCct.AddLine( wxT("") ); // Save the include directives if( ! m_oasIncludes.IsEmpty( ) ) { oFileCct.AddLine( wxT("* Include Directives") ); for( szt1=0; szt1<m_oasIncludes.Count( ); szt1++ ) oFileCct.AddLine( m_oasIncludes[ szt1 ] ); oFileCct.AddLine( wxT("") ); } // Save the component definition lines oFileCct.AddLine( wxT("* Component Definitions") ); for( szt1=0; szt1<m_oasCpnts.Count( ); szt1++ ) oFileCct.AddLine( m_oasCpnts[ szt1 ] ); oFileCct.AddLine( wxT("") ); // Save the sub-circuit definitions if( ! m_oasSubCcts.IsEmpty( ) ) { oFileCct.AddLine( wxT("* Sub-Circuit Definitions") ); for( szt1=0; szt1<m_oasSubCcts.Count( ); szt1++ ) oFileCct.AddLine( m_oasSubCcts[ szt1 ] ); oFileCct.AddLine( wxT("") ); } // Save the model definition lines if( ! m_oasModels.IsEmpty( ) ) { oFileCct.AddLine( wxT("* Model Definitions") ); for( szt1=0; szt1<m_oasModels.Count( ); szt1++ ) oFileCct.AddLine( m_oasModels[ szt1 ] ); oFileCct.AddLine( wxT("") ); } // Save the circuit description terminator oFileCct.AddLine( wxT(".END") ); // Save the changes to disk oFileCct.Write( ); oFileCct.Close( ); return( TRUE );}//*****************************************************************************// Set the load file name.//// Arguments:// psFName - The load file name//// Return Values:// TRUE - Success// FALSE - Failurebool NetList::bSetLoadFile( const wxChar * psFName ){ wxFileName oFnm1; oFnm1 = psFName; // Is the file name valid and does it exist? if( ! oFnm1.IsOk( ) ) return( FALSE ); if( ! oFnm1.FileExists( ) ) return( FALSE ); m_oFnmLoad = oFnm1; return( TRUE );}//*****************************************************************************// Set the save file name.//// Arguments:// psFName - The save file name//// Return Values:// TRUE - Success// FALSE - Failurebool NetList::bSetSaveFile( const wxChar * psFName ){ wxFileName oFnm1; oFnm1 = psFName; // Is the file name valid? if( ! oFnm1.IsOk( ) ) return( FALSE ); m_oFnmSave = oFnm1; return( TRUE );}//*****************************************************************************// Get a component description associated with a component name.//// Arguments:// psName - The component name (label)//// Return Values:// Success - The complete component description// Failure - An empty stringconst wxString & NetList::rosGetCpnt( const wxChar * psName ){ static wxString osEmpty; wxString os1, os2; size_t szt1; os1 = psName; if( os1.IsEmpty( ) ) return( osEmpty ); if( roasGetCpnts( ).IsEmpty( ) ) return( osEmpty ); for( szt1=0; szt1<roasGetCpnts( ).GetCount( ); szt1++ ) { const wxString & ros1 = roasGetCpnts( ).Item( szt1 ); if( ros1.StartsWith( os1.c_str( ) ) ) return( ros1 ); } return( osEmpty );}//*****************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -