⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chounits.cpp

📁 gspiceui电子CAD仿真程序.用于电路参数模拟仿真
💻 CPP
字号:
//*****************************************************************************//                                  ChoUnits.cpp                              *//                                 --------------                             *//  Started     : 27/03/2004                                                  *//  Last Update : 01/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 "ChoUnits.hpp"//*****************************************************************************// Constructor.ChoUnits::ChoUnits( void ){  m_eUnitsType = eUNTS_NONE;  m_osDefUnits = wxT("Units");}//*****************************************************************************// Destructor.ChoUnits::~ChoUnits( ){}//*****************************************************************************// Create an instance of this object.//// Argument List://   poWin  - The parent window//   oWinID - The window identifier//   iWidth - The width of the choice control in pixels//// Return Values://   TRUE  - Success//   FALSE - Failurebool  ChoUnits::bCreate( wxWindow * poWin, wxWindowID oWinID, int iWidth ){  wxSize  oSize=wxDefaultSize;  // Check if the object has already been created  if( bIsCreated( ) )                                       return( TRUE );  // Create the object  if( iWidth > 0 ) oSize.SetWidth( iWidth );  if( ! Create( poWin, oWinID, wxDefaultPosition, oSize ) ) return( FALSE );  // Set the units  eUnitsType  eTmpUnits = m_eUnitsType;  m_eUnitsType = eUNTS_INVALID;  if( ! bSetUType( eTmpUnits ) )                            return( FALSE );  if( ! bSetUnits( m_osDefUnits ) )                         return( FALSE );  return( TRUE );}//*****************************************************************************// Clear object attributes.bool  ChoUnits::bClear( void ){  if( ! bIsCreated( ) )                                return( FALSE );  SetStringSelection( m_osDefUnits );  if( GetStringSelection( ).IsSameAs( m_osDefUnits ) ) return( TRUE );  else                                                 return( FALSE );}//*****************************************************************************// Set the type of units to be displayed.//// Argument List://   eUType - The type of units to be displayed//// Return Values://   Success - TRUE//   Failure - FALSEbool  ChoUnits::bSetUType( eUnitsType eUType ){  if( eUType<eUNTS_FST || eUType>eUNTS_LST ) return( FALSE );  if( m_eUnitsType == eUType )               return( TRUE );  m_eUnitsType = eUType;  if( bIsCreated( ) )  {    Clear( ); // Delete existing choice items from the list    // Load the new choice items into the control    switch( m_eUnitsType )    {      case eUNTS_NONE:  // No units specified        Append( wxT("Units"), new wxStringClientData( wxT("0") ) );        bSetDefUs( wxT("Units") );        break;      case eUNTS_CAP:  // Capacitance        Append( wxT("mF"), new wxStringClientData( wxT("-3") ) );        Append( wxT("uF"), new wxStringClientData( wxT("-6") ) );        Append( wxT("nF"), new wxStringClientData( wxT("-9") ) );        Append( wxT("pF"), new wxStringClientData( wxT("-12") ) );        bSetDefUs( wxT("uF") );        break;      case eUNTS_IND:  // Inductance        Append( wxT("H"),  new wxStringClientData( wxT("0") ) );        Append( wxT("mH"), new wxStringClientData( wxT("-3") ) );        Append( wxT("uH"), new wxStringClientData( wxT("-6") ) );        bSetDefUs( wxT("mH") );        break;      case eUNTS_RES:  // Resistance        Append( wxT("MOhm"), new wxStringClientData( wxT("6") ) );        Append( wxT("kOhm"), new wxStringClientData( wxT("3") ) );        Append( wxT("Ohm"),  new wxStringClientData( wxT("0") ) );        bSetDefUs( wxT("kOhm") );        break;      case eUNTS_VOLT: // Voltage        Append( wxT("V"),  new wxStringClientData( wxT("0") ) );        Append( wxT("mV"), new wxStringClientData( wxT("-3") ) );        Append( wxT("uV"), new wxStringClientData( wxT("-6") ) );        bSetDefUs( wxT("mV") );        break;      case eUNTS_CURR: // Current        Append( wxT("A"),  new wxStringClientData( wxT("0") ) );        Append( wxT("mA"), new wxStringClientData( wxT("-3") ) );        Append( wxT("uA"), new wxStringClientData( wxT("-6") ) );        bSetDefUs( wxT("mA") );        break;      case eUNTS_TIME: // Time        Append( wxT("sec"),  new wxStringClientData( wxT("0") ) );        Append( wxT("msec"), new wxStringClientData( wxT("-3") ) );        Append( wxT("usec"), new wxStringClientData( wxT("-6") ) );        Append( wxT("nsec"), new wxStringClientData( wxT("-9") ) );        bSetDefUs( wxT("msec") );        break;      case eUNTS_FREQ: // Frequency        Append( wxT("MHz"), new wxStringClientData( wxT("6") ) );        Append( wxT("kHz"), new wxStringClientData( wxT("3") ) );        Append( wxT("Hz"),  new wxStringClientData( wxT("0") ) );        bSetDefUs( wxT("kHz") );        break;      case eUNTS_PHASE: // Phase        Append( wxT("Degree"), new wxStringClientData( wxT("0") ) );        Append( wxT("Radian"), new wxStringClientData( wxT("0") ) );        Append( wxT("Grad")  , new wxStringClientData( wxT("0") ) );        bSetDefUs( wxT("Degree") );        break;      case eUNTS_TEMP: // Temperature        Append( wxT("Deg. C"), new wxStringClientData( wxT("0") ) );        Append( wxT("Deg. F"), new wxStringClientData( wxT("0") ) );        Append( wxT("Deg. K"), new wxStringClientData( wxT("0") ) );        bSetDefUs( wxT("Deg. C") );        break;      case eUNTS_SCLR: // Scalar        Append( wxT("x 1T"), new wxStringClientData( wxT("12") ) );        Append( wxT("x 1G"), new wxStringClientData( wxT("9") ) );        Append( wxT("x 1M"), new wxStringClientData( wxT("6") ) );        Append( wxT("x 1K"), new wxStringClientData( wxT("3") ) );        Append( wxT("x 1"),  new wxStringClientData( wxT("0") ) );        Append( wxT("x 1m"), new wxStringClientData( wxT("-3") ) );        Append( wxT("x 1u"), new wxStringClientData( wxT("-6") ) );        Append( wxT("x 1n"), new wxStringClientData( wxT("-9") ) );        Append( wxT("x 1p"), new wxStringClientData( wxT("-12") ) );        Append( wxT("x 1f"), new wxStringClientData( wxT("-15") ) );        bSetDefUs( wxT("x 1") );        break;      default:        return( FALSE );    }    bClear( );  }  return( TRUE );}//*****************************************************************************// Set the default units to be displayed (ie. at startup and after bClear( ) is// called).//// Argument List://   rosUnits - The default units to be used//// Return Values://   Success - TRUE//   Failure - FALSEbool  ChoUnits::bSetDefUs( const wxString rosUnits ){  int  i1;  if( ! bIsCreated( ) )   return( FALSE );  i1 = FindString( rosUnits );  if( i1 == wxNOT_FOUND ) return( FALSE );  m_osDefUnits = rosUnits;  return( TRUE );}//*****************************************************************************// Set the units to be displayed.//// Argument List://   rosUnits - The units to be displayed as a string//// Return Values://   Success - TRUE//   Failure - FALSEbool  ChoUnits::bSetUnits( const wxString rosUnits ){  int  i1;  if( ! bIsCreated( ) )   return( FALSE );  i1 = FindString( rosUnits );  if( i1 == wxNOT_FOUND ) return( FALSE );  SetSelection( i1 );  return( TRUE );}//*****************************************************************************// Set the units to be displayed.//// Argument List://   rosUnits - The exponent associated with the units to be displayed//// Return Values://   Success - TRUE//   Failure - FALSEbool  ChoUnits::bSetUnits( int iExponent ){  wxString  os1;  long  li1;  int   i1;  if( ! bIsCreated( ) ) return( FALSE );  for( i1=0; i1<GetCount( ); i1++ )  {    li1 = 0;    os1 = ( (wxStringClientData *) GetClientObject( i1 ) )->GetData( );    os1.ToLong( &li1 );    if( (int) li1 == iExponent )    {      SetSelection( i1 );      return( TRUE );    }  }  if( ! IsShown( ) ) return( TRUE );   return( FALSE );}//*****************************************************************************// Get the currently selected units.//// Return Values://   Success - The selected units//   Failure - An empty stringconst wxString & ChoUnits::rosGetUnits( void ){  static  wxString  os1;  os1.Empty( );  if( ! bIsCreated( ) ) return( os1 );  os1 = GetStringSelection( );  return( os1 );}//*****************************************************************************// Get the currently selected units as an exponent eg. if the units are mV// return -3.//// Return Values://   Success - The units exponent//   Failure - 0int  ChoUnits::iGetUnits( void ){  wxString  os1;  long int  li1;  if( ! bIsCreated( ) ) return( 0 );  li1 = (long) GetSelection( );  os1 = ( (wxStringClientData *) GetClientObject( (int) li1 ) )->GetData( );  os1.ToLong( &li1 );   return( (int) li1 );}//*****************************************************************************// Combine a value with it's units to produce the equivalent long value.//// Argument List://   fValue - The float value//// Return Values://   Success - The value & units as a long//   Failure - 0long  ChoUnits::liGetValue( float fValue ){  double  df1;  long    li1;  df1 = dfGetValue( fValue );  if( df1 >= 0.0 ) li1 = (long) ( df1 + 0.5 );  else             li1 = (long) ( df1 - 0.5 );  return( li1 );}//*****************************************************************************// Combine a value with it's units to produce the equivalent double value.//// Argument List://   fValue  - The float value//// Return Values://   Success - The value & units as a double//   Failure - 0.0double  ChoUnits::dfGetValue( float fValue ){  double  df1;  int     i1;  if( ! bIsCreated( ) ) return( 0.0 );  df1 = fValue;  i1 = GetSelection( );  switch( m_eUnitsType )  {    case eUNTS_CAP:  // Capacitance      switch( i1 )      {        case  0: df1 /= 1.0E03; break;        case  1: df1 /= 1.0E06; break;        case  2: df1 /= 1.0E09; break;        case  3: df1 /= 1.0E12; break;        default: df1 = 0.0;      }      break;    case eUNTS_IND:  // Inductance      switch( i1 )      {        case 0:                 break;        case 1:  df1 /= 1.0E03; break;        case 2:  df1 /= 1.0E06; break;        default: df1 = 0.0;      }      break;    case eUNTS_RES:  // Resistance      switch( i1 )      {        case 0:  df1 *= 1.0E06; break;        case 1:  df1 *= 1.0E03; break;        case 2:                 break;        default: df1 = 0.0;      }      break;    case eUNTS_VOLT: // Voltage      switch( i1 )      {        case 0:                 break;        case 1:  df1 /= 1.0E03; break;        case 2:  df1 /= 1.0E06; break;        default: df1 = 0.0;      }      break;    case eUNTS_CURR: // Current      switch( i1 )      {        case 0:                 break;        case 1:  df1 /= 1.0E03; break;        case 2:  df1 /= 1.0E06; break;        default: df1 = 0.0;      }      break;    case eUNTS_TIME: // Time      switch( i1 )      {        case 0:                 break;        case 1:  df1 /= 1.0E03; break;        case 2:  df1 /= 1.0E06; break;        case 3:  df1 /= 1.0E09; break;        default: df1 = 0.0;      }      break;    case eUNTS_FREQ: // Frequency      switch( i1 )      {        case 0:  df1 *= 1.0E06; break;        case 1:  df1 *= 1.0E03; break;        case 2:                 break;        default: df1 = 0.0;      }      break;    case eUNTS_PHASE: // Phase (convert phase to Degree)      switch( i1 )      {        case 0:                       break; // Degree (360 degree per cycle)        case 1:  df1 *= 180.0/3.1416; break; // Radian (2Pi radian per cycle)        case 2:  df1 *= 9.0/10.0;     break; // Grad   (400 grad   per cycle)        default: df1  = 0.0;      }      break;    case eUNTS_TEMP: // Temperature (convert temperature to Deg. C)      switch( i1 )      {        case 0:                             break; // Celcius        case 1:  df1  = (df1 - 32.0) / 1.8; break; // Fahrenheit        case 2:  df1 -= 273.15;             break; // Kelvin        default: df1  = 0.0;      }      break;    case eUNTS_SCLR: // Scalar      switch( i1 )      {        case 0:  df1 *= 1.0E12; break;        case 1:  df1 *= 1.0E09; break;        case 2:  df1 *= 1.0E06; break;        case 3:  df1 *= 1.0E03; break;        case 4:                 break;        case 5:  df1 /= 1.0E03; break;        case 6:  df1 /= 1.0E06; break;        case 7:  df1 /= 1.0E09; break;        case 8:  df1 /= 1.0E12; break;        case 9:  df1 /= 1.0E15; break;        default: df1 = 0.0;      }      break;    default:      df1 = 0.0;  }  return( df1 );}//*****************************************************************************// Combine a value with it's units to produce the equivalent string value.//// Argument List://   fValue - The float value//// Return Values://   Success - The string containing the engineering format//   Failure - An empty stringconst wxString & ChoUnits::rosGetValue( float fValue ){  static  wxString  osValue;  wxString  osUnits;  osValue.Empty( );  if( ! bIsCreated( ) )    return( osValue );  osValue.Printf( wxT("%#.2f"), fValue );  osUnits = rosGetUnits( );  if( osUnits.IsEmpty( ) ) return( osValue );  switch( osUnits.GetChar( 0 ) )  {    case wxT('T'): osValue << wxT("Tera"); break;    case wxT('G'): osValue << wxT("Giga"); break;    case wxT('M'): osValue << wxT("Meg");  break;    case wxT('K'): osValue << wxT('K');    break;    case wxT('k'): osValue << wxT('k');    break;    case wxT('m'): osValue << wxT('m');    break;    case wxT('u'): osValue << wxT('u');    break;    case wxT('n'): osValue << wxT('n');    break;    case wxT('p'): osValue << wxT('p');    break;    case wxT('f'): osValue << wxT('f');    break;    default:                               break;  }  return( osValue );}//*****************************************************************************

⌨️ 快捷键说明

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