pnlvalue.cpp

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

CPP
764
字号
//*****************************************************************************//                                 PnlValue.cpp                               *//                                --------------                              *//  Started     : 14/09/2004                                                  *//  Last Update : 05/07/2005                                                  *//  Copyright   : (C) 2004 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 "PnlValue.hpp"//*****************************************************************************// Implement an event table.BEGIN_EVENT_TABLE( PnlValue, wxPanel )  EVT_SPIN_UP  ( SpinCtrl::ID_SPINBUTT, PnlValue::OnSpnScroll )  EVT_SPIN_DOWN( SpinCtrl::ID_SPINBUTT, PnlValue::OnSpnScroll )  EVT_CHOICE   ( ID_CHO_UNITS,          PnlValue::OnChoUnits  )END_EVENT_TABLE( )//*****************************************************************************// Constructor.PnlValue::PnlValue( void ) : wxPanel( ){}//*****************************************************************************// Destructor.PnlValue::~PnlValue( ){}//*****************************************************************************// Convert a temperature value to Celcius from the units specified in the units// choice control.// Note: This conversion will only be done if the units are of temperature.//// Argument List://   pfValue - The value to be converted//// Return Values://   TRUE  - Success//   FALSE - Failurebool  PnlValue::bTempToDegC( float * pfValue ){  if( ! bIsCreated( ) )                                  return( FALSE );  if( ! m_oChoUnits.IsShown( ) )                         return( FALSE );  if( m_oChoUnits.eGetUType( ) != ChoUnits::eUNTS_TEMP ) return( FALSE );  switch( m_oChoUnits.GetSelection( ) )  {    case 0:                                       break; // Celcius    case 1: *pfValue = (*pfValue + 32.0) / 2.44 ; break; // Fahrenheit    case 2: *pfValue -= 273.15;                   break; // Kelvin    default: return( FALSE );  }  return( TRUE );}//*****************************************************************************// Convert a phase value to Degree from the units specified in the units// choice control.// Note: This conversion will only be done if the units are of phase.//// Argument List://   pfValue - The value to be converted//// Return Values://   TRUE  - Success//   FALSE - Failurebool  PnlValue::bPhaseToDeg( float * pfValue ){  if( ! bIsCreated( ) )                                   return( FALSE );  if( ! m_oChoUnits.IsShown( ) )                          return( FALSE );  if( m_oChoUnits.eGetUType( ) != ChoUnits::eUNTS_PHASE ) return( FALSE );  switch( m_oChoUnits.GetSelection( ) )  {    case 0:                     break; // Degree    case 1: *pfValue /= 6.2832; break; // Radian    case 2: *pfValue *= 0.9;    break; // Grad    default: return( FALSE );  }  return( TRUE );}//*****************************************************************************// Create an instance of this object.//// Argument List://   poWin  - The parent window//   oWinID - The window identifier//   iWidth - The width of the name label in pixels//   roPosn - The position//// Return Values://   TRUE  - Success//   FALSE - Failurebool  PnlValue::bCreate( wxWindow * poWin, wxWindowID oWinID, int iWidth,                         const wxPoint & roPosn ){  bool    bRtn=TRUE;  wxSize  oSize=wxDefaultSize;  if( bIsCreated( ) )                     return( TRUE );  // Create the base class (wxPanel)  if( ! Create( poWin, oWinID, roPosn ) ) return( FALSE );  if( iWidth > 0 )  { // Create the variable name label    oSize = wxDefaultSize;    oSize.SetWidth( iWidth );    if( ! m_oLblName.Create( this, ID_UNUSED, wxT(""), wxDefaultPosition,                             oSize, wxST_NO_AUTORESIZE ) ) bRtn = FALSE;  }  // Create the spin control  if( ! m_oSpnValue.bCreate( this, ID_SPN_VALUE, 64 ) )    bRtn = FALSE;  // Create the choice box  if( ! m_oChoUnits.bCreate( this, ID_CHO_UNITS ) )        bRtn = FALSE;  // Create the units label ??? 30/06/2005//  if( ! m_oLblUnits.Create(this,ID_UNUSED,wxT(""),oPosn,oSize) )  bRtn = FALSE;//  m_oLblUnits.Show( FALSE );  // Layout manager stuff  wxBoxSizer * poSizer = new wxBoxSizer( wxHORIZONTAL );  wxSizerFlags  oFlags;  oFlags.Expand( );  oFlags.Align( wxALIGN_CENTER_VERTICAL );  oFlags.Border( wxTOP | wxBOTTOM, 2 );  if( m_oLblName.GetParent( ) != NULL )  {    oFlags.Proportion( 1 );    poSizer->Add( &m_oLblName, oFlags );    poSizer->AddSpacer( 5 );  }  oFlags.Proportion( 0 );  poSizer->Add( &m_oSpnValue, oFlags );  poSizer->AddSpacer( 5 );  poSizer->Add( &m_oChoUnits, oFlags );  SetSizer( poSizer );  // Set minimum size and initial size as calculated by the sizer  poSizer->SetSizeHints( this );  return( bRtn );}//*****************************************************************************// Clear the spin and choice values.//// Return Values://   Success - TRUE//   Failure - FALSEbool  PnlValue::bClear( void ){  bool  bRtn=TRUE;  if( ! m_oSpnValue.bClear( ) ) bRtn = FALSE;  if( ! m_oChoUnits.bClear( ) ) bRtn = FALSE;  return( bRtn );}//*****************************************************************************// Set the name label if it has been created by the bCreate( ) function.//// Argument List://   rosName - The name of the variable//// Return Values://   Success - TRUE//   Failure - FALSEbool  PnlValue::bSetName( const wxString & rosName ){  if( ! bIsCreated( ) )                 return( FALSE );  if( m_oLblName.GetParent( ) == NULL ) return( FALSE );  if( rosName.IsEmpty( ) )              return( FALSE );  m_oLblName.SetLabel( rosName );  return( FALSE );}//*****************************************************************************// Set the variable type for the spin control to display.//// Argument List://   eVType - The variable type//// Return Values://   Success - TRUE//   Failure - FALSEbool  PnlValue::bSetVType( SpinCtrl::eVarType eVType ){  if( ! bIsCreated( ) ) return( FALSE );  return( m_oSpnValue.bSetVType( eVType ) );}//*****************************************************************************// Set the spin control range.//// Argument List://   fMinV  - The spin control minimum value//   fMaxV  - The spin control maximum value//// Return Values://   Success - TRUE//   Failure - FALSEbool  PnlValue::bSetRange( float fMinV, float fMaxV ){  if( ! bIsCreated( ) ) return( FALSE );  return( m_oSpnValue.bSetRange( fMinV, fMaxV ) );}//*****************************************************************************// Set the increment sizes of the spin control.//// This spin control can be incremented using two different approaches,// constant or variable step sizes. A constant step size means that the spin// control is incremented by the same amount throughout it's range. A variable// step size means that the spin control is incremented by an amount dependent// on it's current value.//// Argument List://   fMinIncSz - The minimum spin control increment size//   fMaxIncSz - The maximum spin control increment size//// Return Values://   TRUE  - Success//   FALSE - Failurebool  PnlValue::bSetIncSz( float fMinIncSz, float fMaxIncSz ){  if( ! bIsCreated( ) ) return( FALSE );  return( m_oSpnValue.bSetIncSz( fMinIncSz, fMaxIncSz ) );}//*****************************************************************************// Set the spin control parameters.//// Argument List://   fInitV    - The spin control initial value//   fMinV     - The spin control minimum value//   fMaxV     - The spin control maximum value//   fMinIncSz - The spin control minimum increment size//   fMaxIncSz - The spin control maximum increment size//// Return Values://   Success - TRUE//   Failure - FALSEbool  PnlValue::bSetParms( float fInitV, float fMinV, float fMaxV,                           float fMinIncSz, float fMaxIncSz ){  if( ! bIsCreated( ) ) return( FALSE );  return( m_oSpnValue.bSetParms( fInitV, fMinV, fMaxV, fMinIncSz, fMaxIncSz ) );}//*****************************************************************************// Set the spin control value as an integer.//// Argument List://   liValue - The long integer value//// Return Values://   Success - TRUE//   Failure - FALSEbool  PnlValue::bSetValue( long liValue ){  bool    bRtn=TRUE;  float   fMan;  int     iExp;  if( ! bIsCreated( ) ) return( FALSE );  // If this is a temperature or phase value convert to the specified units  fMan = (float) liValue;  if( bTempToDegC( &fMan ) || bPhaseToDeg( &fMan ) )  { // This is a temperature or phase value convert it to an integer    if( fMan >= 0.0 ) liValue = (int) ( fMan + 0.5 );    else              liValue = (int) ( fMan - 0.5 );  }  // Determine the spin control value and the units choice selection  ConvertType::bParseFlt( (double) liValue, &fMan, &iExp );  while( iExp % 3 )  {    iExp--;    fMan *= 10.0;  }  // Set the spin control and choice control values  if( ! m_oSpnValue.bSetValue( fMan ) ) bRtn = FALSE;  if( ! m_oChoUnits.bSetUnits( iExp ) ) bRtn = FALSE;  return( bRtn );}//*****************************************************************************// Set the spin control value as a float.//// Argument List://   dfValue - The double float value//// Return Values://   Success - TRUE//   Failure - FALSEbool  PnlValue::bSetValue( double dfValue ){  bool   bRtn=TRUE;  float  fMan;  int    iExp;  if( ! bIsCreated( ) ) return( FALSE );  fMan = (float) dfValue;  bTempToDegC( &fMan ); // Convert value to Deg.C  if appropriate  bPhaseToDeg( &fMan ); // Convert value to Degree if appropriate  // Determine the spin control value and the units choice selection  ConvertType::bParseFlt( dfValue, &fMan, &iExp );  while( iExp % 3 )  {    iExp--;    fMan *= 10.0;  }  // Set the spin control and choice control values  if( ! m_oSpnValue.bSetValue( fMan ) ) bRtn = FALSE;  if( ! m_oChoUnits.bSetUnits( iExp ) ) bRtn = FALSE;  return( bRtn );}//*****************************************************************************// Set the spin control value as a string//// Argument List://   rosValue - The string value//// Return Values://   Success - TRUE//   Failure - FALSEbool  PnlValue::bSetValue( const wxString & rosValue ){

⌨️ 快捷键说明

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