frmmain.cpp

来自「gspiceui电子CAD仿真程序.用于电路参数模拟仿真」· C++ 代码 · 共 1,136 行 · 第 1/3 页

CPP
1,136
字号
//*****************************************************************************//                                FrmMain.cpp                                 *//                               -------------                                *//  Started     : 18/08/2003                                                  *//  Last Update : 18/07/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 "FrmMain.hpp"// The application icon#if defined( __WXGTK__ ) || defined( __WXMOTIF__ ) || defined( __WXMAC__ ) || \    defined( __WXMGL__ ) || defined( __WXX11__ )  #include "icon/gspiceui.xpm"  #include "icon/fileopen.xpm"  #include "icon/fileimport.xpm"  #include "icon/filereload.xpm"  #include "icon/fileclose.xpm"  #include "icon/create.xpm"  #include "icon/run.xpm"  #include "icon/stop.xpm"  #include "icon/plot.xpm"#endif//*****************************************************************************// Implement an event table in which the events are routed to their respective// handler functions in the class. If -1 is given as the ID, the given handler// will be invoked for any event of the specified type.BEGIN_EVENT_TABLE( FrmMain, wxFrame )  EVT_MENU( ID_MNU_OPEN,    FrmMain::OnOpen    )  EVT_MENU( ID_MNU_IMPORT,  FrmMain::OnImport  )  EVT_MENU( ID_MNU_RELOAD,  FrmMain::OnReload  )  EVT_MENU( ID_MNU_CLOSE,   FrmMain::OnClose   )  EVT_MENU( ID_MNU_EXIT,    FrmMain::OnExit    )  EVT_MENU( ID_MNU_CREATE,  FrmMain::OnCreate  )  EVT_MENU( ID_MNU_RUN,     FrmMain::OnRun     )  EVT_MENU( ID_MNU_STOP,    FrmMain::OnStop    )  EVT_MENU( ID_MNU_PLOT,    FrmMain::OnPlot    )  EVT_MENU( ID_MNU_SELGCAP, FrmMain::OnSelSimr )  EVT_MENU( ID_MNU_SELNGSP, FrmMain::OnSelSimr )  EVT_MENU( ID_MNU_PATHS,   FrmMain::OnPaths   )  EVT_MENU( ID_MNU_TOOLTIP, FrmMain::OnToolTip )  EVT_MENU( ID_MNU_CONTENT, FrmMain::OnContent )  EVT_MENU( ID_MNU_HLPGCAP, FrmMain::OnGnuCap  )  EVT_MENU( ID_MNU_HLPNGSP, FrmMain::OnNgSpice )  EVT_MENU( ID_MNU_ABOUT,   FrmMain::OnAbout   )  EVT_TOOL( ID_TBR_OPEN,    FrmMain::OnOpen    )  EVT_TOOL( ID_TBR_IMPORT,  FrmMain::OnImport  )  EVT_TOOL( ID_TBR_RELOAD,  FrmMain::OnReload  )  EVT_TOOL( ID_TBR_CLOSE,   FrmMain::OnClose   )  EVT_TOOL( ID_TBR_CREATE,  FrmMain::OnCreate  )  EVT_TOOL( ID_TBR_RUN,     FrmMain::OnRun     )  EVT_TOOL( ID_TBR_STOP,    FrmMain::OnStop    )  EVT_TOOL( ID_TBR_PLOT,    FrmMain::OnPlot    )  EVT_CHECKBOX( -1, FrmMain::OnParmCmd )  EVT_NOTEBOOK_PAGE_CHANGED( -1, FrmMain::OnParmNbk )  EVT_SIZE( FrmMain::OnSize )END_EVENT_TABLE( )//*****************************************************************************// Constructor.//// Argument List://   poApp - A pointer to the class that created this objectFrmMain::FrmMain( const wxApp * poApp ) :         wxFrame( (wxFrame *) NULL, -1, wxT(""), wxDefaultPosition, wxSize(FRMMAIN_WIDTH,500),                  wxDEFAULT_FRAME_STYLE & ~(wxRESIZE_BORDER | wxRESIZE_BOX | wxMAXIMIZE_BOX) ){  // Set pointer to parent application  m_poApp = poApp;  // Set frame pointer in helper classes  m_oFileTsks.SetAppFrm( this );  m_oHelpTsks.SetAppFrm( this );  // Initialize pointers  m_poPrcSimr = NULL;  m_poNbkSimr = NULL;}//*****************************************************************************// Destructor.FrmMain::~FrmMain( ){  if( m_poNbkSimr != NULL ) { delete m_poNbkSimr; m_poNbkSimr = NULL; }  if( m_poPrcSimr != NULL ) { delete m_poPrcSimr; m_poPrcSimr = NULL; }}//*****************************************************************************// Initialize the display objects.void  FrmMain::Initialize( void ){  // Set the frame icon  SetIcon( wxICON( gspiceui ) );  InitToolBar ( );  InitMenuBar ( );  InitLstBoxs ( );  InitNbkTCtls( );  InitStatBar ( );  InitToolTips( );  InitLogFiles( );  InitSimrEng ( );}//*****************************************************************************// Initialize the menu bar.void  FrmMain::InitMenuBar( void ){  // Create the menu bar  wxMenuBar * poMenuBar  = new wxMenuBar;  wxMenu    * poMenuFile = new wxMenu;  wxMenu    * poMenuSimu = new wxMenu;  wxMenu    * poMenuOpts = new wxMenu;  wxMenu    * poMenuHelp = new wxMenu;  poMenuFile->Append( ID_MNU_OPEN,   wxT(" &Open ...") );  poMenuFile->Append( ID_MNU_IMPORT, wxT(" &Import ... ") );  poMenuFile->Append( ID_MNU_RELOAD, wxT(" &Reload") );  poMenuFile->Append( ID_MNU_CLOSE,  wxT(" &Close") );  poMenuFile->AppendSeparator( );  poMenuFile->Append( ID_MNU_EXIT,   wxT(" E&xit") );  poMenuSimu->Append( ID_MNU_CREATE, wxT(" &Create    ") );  poMenuSimu->Append( ID_MNU_RUN,    wxT(" &Run") );  poMenuSimu->Append( ID_MNU_STOP,   wxT(" &Stop") );  poMenuSimu->Append( ID_MNU_PLOT,   wxT(" &Plot") );  poMenuOpts->AppendRadioItem( ID_MNU_SELGCAP, wxT("&GNU-Cap ") );  poMenuOpts->AppendRadioItem( ID_MNU_SELNGSP, wxT("&NG-Spice ") );  poMenuOpts->AppendSeparator( );  poMenuOpts->Append         ( ID_MNU_PATHS,   wxT("&Paths ... ") );  poMenuOpts->AppendSeparator( );  poMenuOpts->AppendCheckItem( ID_MNU_TOOLTIP, wxT("&Tool Tips ") );  poMenuHelp->Append( ID_MNU_CONTENT, wxT(" &Contents ... ") );  poMenuHelp->AppendSeparator( );  poMenuHelp->Append( ID_MNU_HLPGCAP, wxT(" &GNU-Cap ... ") );  poMenuHelp->Append( ID_MNU_HLPNGSP, wxT(" &NG-Spice ... ") );  poMenuHelp->AppendSeparator( );  poMenuHelp->Append( ID_MNU_ABOUT,   wxT(" &About ... ") );  poMenuBar->Append( poMenuFile, wxT(" &File ") );  poMenuBar->Append( poMenuSimu, wxT(" &Simulate ") );  poMenuBar->Append( poMenuOpts, wxT(" &Options ") );  poMenuBar->Append( poMenuHelp, wxT(" &Help ") );  SetMenuBar( poMenuBar );}//*****************************************************************************// Initialize the tool bar.void  FrmMain::InitToolBar( void ){  wxBitmap  * poBitmap[ 8 ];  wxToolBar * poToolBar;  // Create the tool bar  poToolBar = CreateToolBar( wxHORIZONTAL | wxTB_FLAT );  // Create the bitmaps for the tools  poBitmap[ 0 ] = new wxBitmap( fileopen_xpm );  poBitmap[ 1 ] = new wxBitmap( fileimport_xpm );  poBitmap[ 2 ] = new wxBitmap( filereload_xpm );  poBitmap[ 3 ] = new wxBitmap( fileclose_xpm );  poBitmap[ 4 ] = new wxBitmap( create_xpm );  poBitmap[ 5 ] = new wxBitmap( run_xpm );  poBitmap[ 6 ] = new wxBitmap( stop_xpm );  poBitmap[ 7 ] = new wxBitmap( plot_xpm );  // Add the tools to the toolbar  poToolBar->AddTool( ID_TBR_OPEN,   wxT(""), *(poBitmap[ 0 ]),                      wxT("Open Netlist") );  poToolBar->AddTool( ID_TBR_IMPORT, wxT(""), *(poBitmap[ 1 ]),                      wxT("Import Schematic") );  poToolBar->AddTool( ID_TBR_RELOAD, wxT(""), *(poBitmap[ 2 ]),                      wxT("Reload Netlist") );  poToolBar->AddTool( ID_TBR_CLOSE,  wxT(""), *(poBitmap[ 3 ]),                      wxT("Close Netlist") );  poToolBar->AddSeparator( );  poToolBar->AddTool( ID_TBR_CREATE, wxT(""), *(poBitmap[ 4 ]),                      wxT("Create Simulation") );  poToolBar->AddTool( ID_TBR_RUN,    wxT(""), *(poBitmap[ 5 ]),                      wxT("Run Simulation") );  poToolBar->AddTool( ID_TBR_STOP,   wxT(""), *(poBitmap[ 6 ]),                      wxT("Stop Simulation") );  poToolBar->AddSeparator( );  poToolBar->AddTool( ID_TBR_PLOT,   wxT(""), *(poBitmap[ 7 ]),                      wxT("Plot Simulation Results") );  // Realize the toolbar  poToolBar->Realize( );  // Can delete the bitmaps since they're reference counted  for( int i1=0; i1<8; i1++ ) delete poBitmap[ i1 ];}//*****************************************************************************// Initialize the test node and component list boxes.void  FrmMain::InitLstBoxs( void ){  long  lStyle;  // Create the node and component list labels  lStyle = wxALIGN_CENTRE | wxST_NO_AUTORESIZE;  m_oLblNodes.Create( this, ID_UNUSED, wxT("Nodes"),      wxPoint( 28, 5 ),                      wxDefaultSize, lStyle );  m_oLblCpnts.Create( this, ID_UNUSED, wxT("Components"), wxPoint( 108, 5 ),                      wxDefaultSize, lStyle );  // Create the node and component list boxes  lStyle = wxLB_MULTIPLE | wxLB_ALWAYS_SB;  m_oLbxNodes.Create( this, ID_LBX_NODES, wxPoint( 5, 27 ),                      wxSize( 93, 248 ), 0, NULL, lStyle );  m_oLbxCpnts.Create( this, ID_LBX_CPNTS, wxPoint( 102, 27 ),                      wxSize( 93, 248 ), 0, NULL, lStyle );}//*****************************************************************************// Initialize the console notebook.void  FrmMain::InitNbkTCtls( void ){  int  i1;  i1 = 40 + TextCtrl::iGetPixelHt( );  m_oNbkTxtCtls.bCreate( this, ID_NBK_TXTCTLS, wxPoint( 5, 281 ),                         wxSize( 730, i1 ) );}//*****************************************************************************// Initialize the status bar.void  FrmMain::InitStatBar( void ){  int    iWidths[2], ix, iy;  float  f1;  // Create the status bar  CreateStatusBar( 2 );  // Determine the status bar field widths  GetSize( &ix, &iy );  f1 = (float) (ix - 5);  iWidths[ 0 ] = (int) (f1 * 0.70 + 0.5);  iWidths[ 1 ] = (int) (f1 * 0.30 + 0.5);  SetStatusWidths( 2, iWidths );  // Set status bar text  SetStatusText( wxT(" Welcome to GNU Spice GUI"), 0 );  SetStatusText( wxT(" Simulation Engine : None"), 1 );}//*****************************************************************************// Initialize the tool tips.void  FrmMain::InitToolTips( void ){  // Define tool tips for each control  m_oLblNodes.SetToolTip( wxT("Test Nodes") );      // ??? 21/02/2004 Doesn't work  m_oLblCpnts.SetToolTip( wxT("Test Components") ); // ??? 21/02/2004 Doesn't work  m_oLbxNodes.SetToolTip( wxT("Test Nodes") );  m_oLbxCpnts.SetToolTip( wxT("Test Components") );  // Set global tool tip attributes  wxToolTip  oToolTip( wxT("") );  oToolTip.Enable( FALSE );  oToolTip.SetDelay( 700 );}//*****************************************************************************// Set the electronic circuit simulator engine to use.//// Argument List://   eType - The simulator engine to usevoid  FrmMain::InitSimrEng( Simulation::eSimrType eType ){  if( eType == Simulation::eSIMR_NONE ) return;  // Delete any previous simulator objects  if( m_poNbkSimr != NULL )  { // Delete the old simulator notebook object    if( m_poNbkSimr->eGetSimrType( ) == eType ) return; // Nothing to do    delete m_poNbkSimr;    m_poNbkSimr = NULL;  }  if( m_poPrcSimr != NULL )  { // Delete the old simulator process object    delete m_poPrcSimr;    m_poPrcSimr = NULL;  }  // Create the new simulator objects  switch( eType )  {    case Simulation::eSIMR_GNUCAP:      // Create the notebook control which holds the various analysis pages      m_poNbkSimr = new NbkGnuCap( this, ID_NBK_ANALYS, wxPoint( 200, 5 ),                                   wxSize( 535, 270 ) );      // Create the simulator process object      m_poPrcSimr = new PrcGnuCap( );      // Check the appropriate simulator item in the Options menu      GetMenuBar( )->FindItem( FrmMain::ID_MNU_SELGCAP )->Check( );      // Set the status bar message      SetStatusText( wxT(" Simulation Engine : GNU-Cap"), 1 );      break;    case Simulation::eSIMR_NGSPICE:      // Create the notebook control which holds the various analysis pages      m_poNbkSimr = new NbkNgSpice( this, ID_NBK_ANALYS, wxPoint( 200, 5 ),                                    wxSize( 535, 270 ) );      // Create the simulator process object      m_poPrcSimr = new PrcNgSpice( );      // Check the appropriate simulator item in the Options menu      GetMenuBar( )->FindItem( FrmMain::ID_MNU_SELNGSP )->Check( );      // Set the status bar message      SetStatusText( wxT(" Simulation Engine : NG-Spice"), 1 );      break;    default:      break;  }  m_oSimn.bSetSimrType( eType );  InitLogFiles( ); // Set the simulator process log file name}//*****************************************************************************// Initialize the log file names in the process objects.void  FrmMain::InitLogFiles( void ){  wxFileName  oFn1;  wxString    os1;  // Check that a schematic or netlist file has been defined  oFn1 = m_oFileTsks.rosGetNetList( );  if( ! oFn1.IsOk( )       ) return;  if( ! oFn1.FileExists( ) ) return;  // Get the path to the schematic or netlist file  os1 = oFn1.GetPath( ) + wxT("/gspiceui.log");  // Set the log file path for the gNetList process object  m_oFileTsks.bSetLogFile( os1 );  // Set the log file path for the simulation process object  if( m_poPrcSimr != NULL ) m_poPrcSimr->bSetLogFile( os1 );  // Set the log file path for the gWave process object

⌨️ 快捷键说明

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