dlgsrccfg.cpp
来自「gspiceui电子CAD仿真程序.用于电路参数模拟仿真」· C++ 代码 · 共 357 行
CPP
357 行
//*****************************************************************************// DlgSrcCfg.cpp *// --------------- *// Started : 10/05/2005 *// Last Update : 21/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 "DlgSrcCfg.hpp"//*****************************************************************************// Implement an event table.BEGIN_EVENT_TABLE( DlgSrcCfg, wxDialog ) EVT_BUTTON( ID_BTN_OK, DlgSrcCfg::OnBtnOk ) EVT_BUTTON( ID_BTN_CANCEL, DlgSrcCfg::OnBtnCancel )END_EVENT_TABLE( )//*****************************************************************************// Constructor.DlgSrcCfg::DlgSrcCfg( wxWindow * poWin ) : wxDialog( poWin, -1, wxT(""), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, wxDialogNameStr ){ SetTitle( wxT("Voltage Source Setup") ); SetSize( wxSize( 275, 253 ) ); Init( ); bClear( );}//*****************************************************************************// Destructor.DlgSrcCfg::~DlgSrcCfg( ){}//*****************************************************************************// Initialize object attributes.void DlgSrcCfg::Init( void ){ wxPanel * poPnl; wxBoxSizer * poSzr; wxSizerFlags oFlags; // Create and set the underlying dialogue sizer poSzr = new wxBoxSizer( wxVERTICAL ); SetSizer( poSzr ); // Create a panel to contain the pulse parameter controls poPnl = new wxPanel( this ); m_oPnlInitV .bCreate( poPnl, ID_PNL_INITV, 80 ); m_oPnlPulseV.bCreate( poPnl, ID_PNL_PULSEV, 80 ); m_oPnlDelay .bCreate( poPnl, ID_PNL_DELAY, 80 ); m_oPnlRise .bCreate( poPnl, ID_PNL_RISE, 80 ); m_oPnlWidth .bCreate( poPnl, ID_PNL_WIDTH, 80 ); m_oPnlFall .bCreate( poPnl, ID_PNL_FALL, 80 ); m_oPnlPeriod.bCreate( poPnl, ID_PNL_PERIOD, 80 ); m_oPnlInitV .bSetName( wxT("Initial Value") ); m_oPnlPulseV.bSetName( wxT("Pulsed Value") ); m_oPnlDelay .bSetName( wxT("Initial Delay") ); m_oPnlRise .bSetName( wxT("Rise Time") ); m_oPnlWidth .bSetName( wxT("Pulse Width") ); m_oPnlFall .bSetName( wxT("Fall Time") ); m_oPnlPeriod.bSetName( wxT("Period") ); m_oPnlInitV .bSetUType( ChoUnits::eUNTS_VOLT ); m_oPnlPulseV.bSetUType( ChoUnits::eUNTS_VOLT ); m_oPnlDelay .bSetUType( ChoUnits::eUNTS_TIME ); m_oPnlRise .bSetUType( ChoUnits::eUNTS_TIME ); m_oPnlWidth .bSetUType( ChoUnits::eUNTS_TIME ); m_oPnlFall .bSetUType( ChoUnits::eUNTS_TIME ); m_oPnlPeriod.bSetUType( ChoUnits::eUNTS_TIME ); // Create and set the sizer for the pulse parameter controls poSzr = new wxStaticBoxSizer( wxVERTICAL, poPnl, wxT("Pulse") ); oFlags.Center( ); oFlags.Border( wxTOP, 10 ); poSzr->Add( &m_oPnlInitV, oFlags ); oFlags.Border( wxLEFT | wxRIGHT, 10 ); poSzr->Add( &m_oPnlPulseV, oFlags ); poSzr->Add( &m_oPnlDelay, oFlags ); poSzr->Add( &m_oPnlRise, oFlags ); poSzr->Add( &m_oPnlWidth, oFlags ); poSzr->Add( &m_oPnlFall, oFlags ); oFlags.Border( wxBOTTOM, 5 ); poSzr->Add( &m_oPnlPeriod, oFlags ); poPnl->SetSizer( poSzr ); poSzr->SetSizeHints( poPnl ); oFlags.Border( wxALL, 10 ); GetSizer( )->Add( poPnl, oFlags ); // Create a panel for the buttons poPnl = new wxPanel( this ); m_oBtnOk .Create( poPnl, ID_BTN_OK, wxT("Ok") ); m_oBtnCancel.Create( poPnl, ID_BTN_CANCEL, wxT("Cancel") ); // Create and set the sizer for the buttons poSzr = new wxBoxSizer( wxHORIZONTAL ); oFlags.Border( wxTOP | wxLEFT | wxRIGHT, 10 ); poSzr->Add( &m_oBtnOk, oFlags ); poSzr->AddSpacer( 10 ); poSzr->Add( &m_oBtnCancel, oFlags ); poPnl->SetSizer( poSzr ); poSzr->SetSizeHints( poPnl ); oFlags.Border( wxBOTTOM, 20 ); GetSizer( )->Add( poPnl, oFlags ); // Set dialogues minimum size and initial size as calculated by the sizer GetSizer( )->SetSizeHints( this ); // Initialize temporary storage with the spin control values GetPnlValues( );}//*****************************************************************************// Get a reference to a value panel associated with a control ID number.//// Argument List:// iPnlID - The control ID number//// Return Values:// A reference to a value panelPnlValue & DlgSrcCfg::roGetPanel( int iPnlID ){ // No argument tests here so use this function responsibly or suffer the pain switch( iPnlID ) { case ID_PNL_INITV : return( m_oPnlInitV ); case ID_PNL_PULSEV : return( m_oPnlPulseV ); case ID_PNL_DELAY : return( m_oPnlDelay ); case ID_PNL_RISE : return( m_oPnlRise ); case ID_PNL_WIDTH : return( m_oPnlWidth ); case ID_PNL_FALL : return( m_oPnlFall ); case ID_PNL_PERIOD : return( m_oPnlPeriod ); default : return( m_oPnlInitV ); }}//*****************************************************************************// Set the values in the spin controls from temporary storage.void DlgSrcCfg::SetPnlValues( void ){ int i1; SetEvtHandlerEnabled( FALSE ); for( i1=ID_PNL_FST; i1<=ID_PNL_LST; i1++ ) roGetPanel( i1 ).bSetValue( (float) m_dfPnlValue[ i1 ] ); SetEvtHandlerEnabled( TRUE );}//*****************************************************************************// Get the values from the spin controls and put them in temporary storage.void DlgSrcCfg::GetPnlValues( void ){ int i1; SetEvtHandlerEnabled( FALSE ); for( i1=ID_PNL_FST; i1<=ID_PNL_LST; i1++ ) m_dfPnlValue[ i1 ] = roGetPanel( i1 ).dfGetValue( ); SetEvtHandlerEnabled( TRUE );}//*****************************************************************************// Parse a independent source definition string.//// Argument List:// rosCmd - The independent source definition to be parsed//// Return Values:// TRUE - Success// FALSE - Failurebool DlgSrcCfg::bSetSrcCmd( const wxString & rosCmd ){ wxStringTokenizer ostk1; wxString os1; size_t szt1, szt2; // Extract the pulse function parameter list os1 = rosCmd.Upper( ); if( (szt1=os1.find( wxT("PULSE") )) == wxString::npos ) return( FALSE ); if( (szt1=rosCmd.find( wxT('('), szt1 )) == wxString::npos ) return( FALSE ); if( (szt2=rosCmd.find( wxT(')'), szt1 )) == wxString::npos ) return( FALSE ); os1 = rosCmd.substr( szt1+1, szt2-szt1-1 ); ostk1 = os1; if( ostk1.CountTokens( ) != 7 ) return( FALSE ); // Extract each pulse function parameter value m_oPnlInitV .bSetValue( ostk1.GetNextToken( ) ); m_oPnlPulseV.bSetValue( ostk1.GetNextToken( ) ); m_oPnlDelay .bSetValue( ostk1.GetNextToken( ) ); m_oPnlRise .bSetValue( ostk1.GetNextToken( ) ); m_oPnlFall .bSetValue( ostk1.GetNextToken( ) ); m_oPnlWidth .bSetValue( ostk1.GetNextToken( ) ); m_oPnlPeriod.bSetValue( ostk1.GetNextToken( ) ); return( TRUE );}//*****************************************************************************// Create the independent voltage source definition string.//// Return Values:// The generator commandconst wxString & DlgSrcCfg::rosGetSrcCmd( void ){ m_osSrcCmd = wxT("PULSE( "); if( roGetPanel( ID_PNL_INITV ).IsEnabled( ) ) m_osSrcCmd << roGetPanel( ID_PNL_INITV ).rosGetValue( ) << wxT(' '); if( roGetPanel( ID_PNL_PULSEV ).IsEnabled( ) ) m_osSrcCmd << roGetPanel( ID_PNL_PULSEV ).rosGetValue( ) << wxT(' '); if( roGetPanel( ID_PNL_DELAY ).IsEnabled( ) ) m_osSrcCmd << roGetPanel( ID_PNL_DELAY ).rosGetValue( ) << wxT(' '); if( roGetPanel( ID_PNL_RISE ).IsEnabled( ) ) m_osSrcCmd << roGetPanel( ID_PNL_RISE ).rosGetValue( ) << wxT(' '); if( roGetPanel( ID_PNL_FALL ).IsEnabled( ) ) m_osSrcCmd << roGetPanel( ID_PNL_FALL ).rosGetValue( ) << wxT(' '); if( roGetPanel( ID_PNL_WIDTH ).IsEnabled( ) ) m_osSrcCmd << roGetPanel( ID_PNL_WIDTH ).rosGetValue( ) << wxT(' '); if( roGetPanel( ID_PNL_PERIOD ).IsEnabled( ) ) m_osSrcCmd << roGetPanel( ID_PNL_PERIOD ).rosGetValue( ) << wxT(' '); m_osSrcCmd << wxT(')'); return( m_osSrcCmd );}//*****************************************************************************// Reset all dialog settings to defaults.//// Return Values:// TRUE - Success// FALSE - Failurebool DlgSrcCfg::bClear( void ){ bool bRtn=TRUE; // Set default spin control values if( ! m_oPnlInitV .bClear( ) ) bRtn = FALSE; if( ! m_oPnlPulseV.bClear( ) ) bRtn = FALSE; if( ! m_oPnlDelay .bClear( ) ) bRtn = FALSE; if( ! m_oPnlRise .bClear( ) ) bRtn = FALSE; if( ! m_oPnlWidth .bClear( ) ) bRtn = FALSE; if( ! m_oPnlFall .bClear( ) ) bRtn = FALSE; if( ! m_oPnlPeriod.bClear( ) ) bRtn = FALSE; return( bRtn );}//*****************************************************************************// Set the value on a panel.//// Argument List:// iPnlID - Spin control identifier// fValue - The value to set the spin control// rosUnits - The units to display//// Return Values:// TRUE - Success// FALSE - Failurebool DlgSrcCfg::bSetPnlValue( int iPnlID, float fValue, const wxString & rosUnits ){ // Check for a valid panel identifier if( iPnlID<ID_PNL_FST || iPnlID>ID_PNL_LST ) return( FALSE ); // Set the panel value if( ! roGetPanel( iPnlID ).bSetValue( (float) fValue ) ) return( FALSE ); m_dfPnlValue[ iPnlID ] = fValue; if( ! rosUnits.IsEmpty( ) ) { // Set the units if( ! roGetPanel( iPnlID ).bSetUnits( rosUnits ) ) return( FALSE ); m_dfPnlValue[ iPnlID ] = roGetPanel( iPnlID ).dfGetValue( ); } return( TRUE );}//*****************************************************************************// Enable or disable a value panel.//// Return Values:// TRUE - Success// FALSE - Failurebool DlgSrcCfg::bEnablePanel( int iPnlID, bool bState ){ if( iPnlID<ID_PNL_FST || iPnlID>ID_PNL_LST ) return( FALSE ); if( roGetPanel( iPnlID ).Enable( bState ) ) return( FALSE ); return( TRUE );}//*****************************************************************************//// Event Handlers////*****************************************************************************// Ok button event handler.//// Argument List:// roEvtCmd - An object holding information about the event (not used)void DlgSrcCfg::OnBtnOk( wxCommandEvent & roEvtCmd ){ GetPnlValues( ); EndModal( wxID_OK ); rosGetSrcCmd( );}//*****************************************************************************// Cancel button event handler.//// Argument List:// roEvtCmd - An object holding information about the event (not used)void DlgSrcCfg::OnBtnCancel( wxCommandEvent & roEvtCmd ){ SetPnlValues( ); EndModal( wxID_CANCEL );}//*****************************************************************************
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?