📄 filetasks.cpp
字号:
//*****************************************************************************// FileTasks.cpp *// --------------- *// Started : 28/05/2005 *// Last Update : 18/07/2005 *// Copyright : (C) 2005 by M.S.Waters *// 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 "FileTasks.hpp"#include "FrmMain.hpp"//*****************************************************************************// Constructor.FileTasks::FileTasks( void ){ m_poFrmMain = NULL; bSetTmpFileMgnt( eTFM_DELETE ); // Set default temp. file management strategy bClear( ); // Clear object attributes}//*****************************************************************************// Destructor.FileTasks::~FileTasks( ){}//*****************************************************************************// Display an open file dialog and set the net list file name.//// Return Values:// TRUE - Success// FALSE - Failurebool FileTasks::bDlgOpen( void ){ wxFileDialog * poDlgOpen; wxString os1; bool bRtn=TRUE; // Can't display dialogue unless the application main frame has been created if( m_poFrmMain == NULL ) return( FALSE ); // Create the different file filters os1 << wxT("All files (*)|*|") << wxT("Circuit files (*.ckt)|*.ckt|") << wxT("Circuit files (*.cir)|*.cir|") << wxT("Netlist files (*.net)|*.net"); // Create and configure the file open dialog poDlgOpen = new wxFileDialog( m_poFrmMain ); poDlgOpen->SetMessage( wxT("Open a Circuit Description File") ); poDlgOpen->SetWildcard( os1 ); poDlgOpen->SetStyle( wxOPEN | wxCHANGE_DIR | wxFILE_MUST_EXIST ); poDlgOpen->SetFilterIndex( 1 ); // Display file open dialog if( poDlgOpen->ShowModal( ) != wxID_OK ) return( FALSE ); os1 = poDlgOpen->GetPath( ); // Set the net list file name if( ! bClear( ) ) bRtn = FALSE; if( ! bSetNetList( os1 ) ) bRtn = FALSE; return( bRtn );}//*****************************************************************************// Display an import file/s dialog and set the schematic file name/s.//// Return Values:// TRUE - Success// FALSE - Failurebool FileTasks::bDlgImport( void ){ wxFileDialog * poDlgImport; wxArrayString oas1; wxString os1; bool bRtn=TRUE; // Can't display dialogue unless the application main frame has been created if( m_poFrmMain == NULL ) return( FALSE ); // Create the different file filters os1 << wxT("gSchem files (*.sch)|*.sch|") << wxT("Protel II files (*.\?\?\?)|*.\?\?\?"); // Create and configure the file import dialog poDlgImport = new wxFileDialog( m_poFrmMain ); poDlgImport->SetMessage( wxT("Import Schematic File") ); poDlgImport->SetWildcard( os1 ); poDlgImport->SetStyle( wxOPEN | wxCHANGE_DIR | wxMULTIPLE | wxFILE_MUST_EXIST ); poDlgImport->SetFilterIndex( 0 ); // Display file import dialog if( poDlgImport->ShowModal( ) != wxID_OK ) return( FALSE ); bSetGuileProc( wxT("spice-sdb") ); poDlgImport->GetPaths( oas1 ); // Set the schematic file name/s if( ! bClear( ) ) bRtn = FALSE; if( ! bSetSchems( oas1 ) ) bRtn = FALSE; return( bRtn );}//*****************************************************************************// Load the net list data into a Simulation object.//// Argument List:// roSim - The Simulation object to be loaded//// Return Values:// TRUE - Success// FALSE - Failurebool FileTasks::bLoadFile( Simulation & roSim ){ wxString os1; // Attempt to load the circuit description file if( ! roSim.bLoadFile( m_oPrcGNetList.roGetNetList( ).GetFullPath( ) ) ) { os1 << wxT("The file ") << m_oPrcGNetList.roGetNetList( ).GetFullPath( ) << wxT(" could not be loaded."); m_poFrmMain->DlgErrMsg( wxT("Load Net List Error"), os1 ); return( FALSE ); } return( TRUE );}//*****************************************************************************// Execute the schematic importation process.//// Return Values:// TRUE - Success// FALSE - Failurebool FileTasks::bExecImport( void ){ TextCtrl * poTxtCtl; wxString os1; os1.Empty( ); // Convert the schematic file/s to a net list file if( ! m_oPrcGNetList.bExec( ) ) os1 << wxT("Error/s encountered executing gnetlist process.\n\n") << m_oPrcGNetList.psGetError( ); // Display the console page m_poFrmMain->m_oNbkTxtCtls.bSetPage( NbkTxtCtls::ePAGE_CONSOLE ); DELAY_MS( 100 ); // Allow time for the GUI to be updated // Print the results poTxtCtl = m_poFrmMain->m_oNbkTxtCtls.poGetPage( NbkTxtCtls::ePAGE_CONSOLE ); m_oPrcGNetList.Print( *poTxtCtl ); // Check for errors if( ! os1.IsEmpty( ) ) { m_poFrmMain->DlgErrMsg( wxT("Import Schematic Error"), os1 ); return( FALSE ); } return( TRUE );}//*****************************************************************************// Delete temporary files which may have been generated by this application.// Ie. given the circuit description file "<netlist>.ckt" delete files of the// following form:// <netlist>.ngspice.DC, <netlist>.ngspice.AC, etc.// <netlist>.gnucap.OP, <netlist>.gnucap.DC, etc.// gnetlist.logvoid FileTasks::DelTmpFiles( void ){ wxArrayString oas1; wxFileName ofn1; wxString os1, os2; size_t szt1; int i1; if( m_eTmpFileMgnt == eTFM_KEEP ) return; // Get the path to the schematic or circuit description file ofn1 = m_oPrcGNetList.roGetNetList( ); ofn1.Normalize( ); if( ofn1.IsOk( ) && ofn1.FileExists( ) ) { // Look for the gnetlist log file os1 = ofn1.GetPath( ) + wxT("/gnetlist.log"); if( wxFileExists( os1 ) ) oas1.Add( os1 ); os1 = ofn1.GetName( ); i1 = os1.Find( wxT(".gspiceui") ); if( i1 > 0 ) os1 = os1.Truncate( (size_t) i1 ); ofn1.SetFullName( os1 ); // Look for any GNU-Cap results file os1 = ofn1.GetFullPath( ) + wxT(".gnucap.??"); for( os2=wxFindFirstFile( os1 ); !os2.IsEmpty( ); os2=wxFindNextFile( ) ) oas1.Add( os2 ); // Look for any Ng-Spice results files os1 = ofn1.GetFullPath( ) + wxT(".ngspice.??"); for( os2=wxFindFirstFile( os1 ); !os2.IsEmpty( ); os2=wxFindNextFile( ) ) oas1.Add( os2 ); // Prompt the user for permission to delete files if( oas1.GetCount( ) > 0 ) { if( m_poFrmMain!=NULL && m_poFrmMain->IsShown( ) ) { if( m_eTmpFileMgnt == eTFM_PROMPT ) { os1 = wxT("Delete Temporary Files"); os2 = wxT("\nDelete the following temporary files:\n\n"); for( szt1=0; szt1<oas1.GetCount( ); szt1++ ) os2 << oas1.Item( szt1 ) << wxT(" \n"); os2 << '\n'; long lStyle = wxYES_NO | wxICON_QUESTION; i1 = wxMessageBox( os2, os1, lStyle, m_poFrmMain ); } else i1 = wxYES; if( i1 == wxYES ) { for( szt1=0; szt1<oas1.GetCount( ); szt1++ ) wxRemoveFile( oas1.Item( szt1 ) ); } } } }}//*****************************************************************************// Clear the object attributes.//// Return Values:// TRUE - Success// FALSE - Failurebool FileTasks::bClear( void ){ bool bRtn=TRUE; // Clear the GNetList process object attributes if( ! m_oPrcGNetList.bClear( ) ) bRtn = FALSE; return( bRtn );}//*****************************************************************************// Check that GNetList is present and accounted for, if not display an error// message.//// Return Values:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -