pnlvalue.cpp

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

CPP
764
字号
  double  df1;  if( ! bIsCreated( ) )                            return( FALSE );  if( ! ConvertType::bStrToFlt( rosValue, &df1 ) ) return( FALSE );  if( ! bSetValue( df1 ) )                         return( FALSE );  return( TRUE );}//*****************************************************************************// Set the type of units to be displayed in the choice control.//// Argument List://   eUType  - The units specifier//// Return Values://   Success - TRUE//   Failure - FALSEbool  PnlValue::bSetUType( ChoUnits::eUnitsType eUType ){  if( ! bIsCreated( ) )                   return( FALSE );  if( ! m_oChoUnits.bSetUType( eUType ) ) return( FALSE );  // Automatically set the spin control parameters  switch( eUType )  {    case ChoUnits::eUNTS_CAP  : // Capacitance      m_oSpnValue.bSetParms( 100.0, 0.0, 1000.0, 1.0, 100.0 );      break;    case ChoUnits::eUNTS_IND  : // Inductance      m_oSpnValue.bSetParms( 100.0, 0.0, 1000.0, 1.0, 100.0 );      break;    case ChoUnits::eUNTS_RES  : // Resistance      m_oSpnValue.bSetParms( 100.0, 0.0, 1000.0, 1.0, 100.0 );      break;    case ChoUnits::eUNTS_VOLT : // Voltage      m_oSpnValue.bSetParms( 100.0, -1000.0, 1000.0, 1.0, 100.0 );      break;    case ChoUnits::eUNTS_CURR : // Current      m_oSpnValue.bSetParms( 100.0, -1000.0, 1000.0, 1.0, 100.0 );      break;    case ChoUnits::eUNTS_TIME : // Time      m_oSpnValue.bSetParms( 100.0, 0.0, 1000.0, 1.0, 100.0 );      break;    case ChoUnits::eUNTS_FREQ : // Frequency      m_oSpnValue.bSetParms( 100.0, 0.1, 1000.0, 1.0, 100.0 );      break;    case ChoUnits::eUNTS_PHASE: // Phase      m_oSpnValue.bSetParms( 0.0, 0.0, 360.0, 10.0 );      break;    case ChoUnits::eUNTS_TEMP : // Temperature      m_oSpnValue.bSetParms( 27.0, -100.0, 200.0, 1.0, 10.0 );      break;    case ChoUnits::eUNTS_SCLR : // Scalar      m_oSpnValue.bSetParms( 1.0, -1000.0, 1000.0, 1.0, 100.0 );      break;    default:                    // Default      m_oSpnValue.bSetParms( 100.0, -1000.0, 1000.0, 1.0, 100.0 );      break;  }  return( TRUE );}//*****************************************************************************// Set the units to be displayed in the choice control or static label.//// Argument List://   rosUnits - The units to be displayed//// Return Values://   Success - TRUE//   Failure - FALSEbool  PnlValue::bSetUnits( const wxString & rosUnits ){  if( ! bIsCreated( ) )                        return( FALSE );  if( m_oChoUnits.IsShown( ) )  {    if( ! m_oChoUnits.bSetUnits( rosUnits ) )  return( FALSE );  }  else m_oLblUnits.SetLabel( rosUnits );  return( TRUE );}//*****************************************************************************// Show or hide the units choice control.//// Argument List://   bEnable - The new state for the units choice control//// Return Values://   Success - TRUE//   Failure - FALSEbool  PnlValue::bShowChoUnts( bool bEnable ){  if( ! bIsCreated( ) ) return( FALSE );  if( bEnable )  {    m_oChoUnits.Show( TRUE );    m_oLblUnits.Show( FALSE );  }  else  {    m_oChoUnits.Show( FALSE );    m_oLblUnits.Show( TRUE );  }  return( TRUE );}//*****************************************************************************// Get the variable name.//// Return Values://   Success - The variable name as a string//   Failure - An empty stringconst wxString & PnlValue::rosGetName( void ){  static  wxString  os1;  os1.Empty( );    if( ! bIsCreated( ) ) return( os1 );  os1 = m_oLblName.GetLabel( );    return( os1 );}//*****************************************************************************// Get the spin control value as an integer.//// Return Values://   Success - The integer value (ignoring units)//   Failure - 0int  PnlValue::iGetSpnValue( void ){  if( ! bIsCreated( ) ) return( 0 );  return( m_oSpnValue.iGetValue( ) );}//*****************************************************************************// Get the spin control value as a float.//// Return Values://   Success - The float value (ignoring units)//   Failure - 0.0float  PnlValue::fGetSpnValue( void ){  if( ! bIsCreated( ) ) return( 0.0 );  return( m_oSpnValue.fGetValue( ) );}//*****************************************************************************// Get the spin control value as a string.//// Return Values://   Success - The value as a string (ignoring units)//   Failure - An empty stringconst wxString & PnlValue::rosGetSpnValue( void ){  static  wxString  osValue;  if( bIsCreated( ) ) osValue = m_oSpnValue.rosGetValue( );  else                osValue.Empty( );  return( osValue );}//*****************************************************************************// Get the spin control value including units as an integer.//// Return Values://   Success - The value as a long integer//   Failure - 0long  PnlValue::liGetValue( void ){  float  f1;  long   li1;  if( m_oChoUnits.IsShown( ) )  {    f1 = m_oSpnValue.fGetValue( );    li1 = m_oChoUnits.liGetValue( f1 );  }  else    li1 = (long) m_oSpnValue.iGetValue( );  return( li1 );}//*****************************************************************************// Get the spin control value including units as a float.//// Return Values://   Success - The value as a double precision float//   Failure - 0.0double  PnlValue::dfGetValue( void ){  float   f1;  double  df1;  f1 = m_oSpnValue.fGetValue( );  if( m_oChoUnits.IsShown( ) ) df1 = m_oChoUnits.dfGetValue( f1 );  else                         df1 = (double) f1;  return( df1 );}//*****************************************************************************// Get the spin control value including units as a string.//// Return Values://   Success - The value as a string//   Failure - An empty stringconst wxString & PnlValue::rosGetValue( void ){  static  wxString  osValue;  float   f1;  osValue.Empty( );  if( ! bIsCreated( ) ) return( osValue );  f1 = m_oSpnValue.fGetValue( );  if( m_oChoUnits.IsShown( ) && f1!=0.0 )       osValue = m_oChoUnits.rosGetValue( f1 );  else osValue = m_oSpnValue.rosGetValue( );  return( osValue );}//*****************************************************************************// Get the units type.//// Return Values://   Success - The units type//   Failure - ChoUnits::eUNTS_NONEChoUnits::eUnitsType  PnlValue::eGetUType( void ){  if( ! bIsCreated( ) ) return( ChoUnits::eUNTS_NONE );  return( m_oChoUnits.eGetUType( ) );}//*****************************************************************************// Get the units.//// Return Values://   Success - The currently selected units//   Failure - An empty stringconst wxString & PnlValue::rosGetUnits( void ){  static  wxString  osEmpty;  if( ! bIsCreated( ) ) return( osEmpty );  return( m_oChoUnits.rosGetUnits( ) );}//*****************************************************************************//                                                                            *//                             Event Handlers                                 *//                                                                            *//*****************************************************************************// Spin button scroll event handler.//// Argument List://   roEvtSpn - An object holding information about the eventvoid  PnlValue::OnSpnScroll( wxSpinEvent & roEvtSpn ){  static  bool   bAtLimit=FALSE;  static  bool   bStartup=TRUE;          float  f1;          int    i1;  if( ! m_oChoUnits.IsShown( ) )                          return;  if( m_oChoUnits.eGetUType( ) == ChoUnits::eUNTS_TEMP  ) return;  if( m_oChoUnits.eGetUType( ) == ChoUnits::eUNTS_PHASE ) return;  f1 = m_oSpnValue.fGetValue( );  i1 = m_oChoUnits.iGetUnits( );  // Must set the state of bAtLimit when this function first called  if( bStartup )  {    bStartup = FALSE;    if( f1 == 0.0 )                     bAtLimit = TRUE;    if( f1 == m_oSpnValue.fGetMaxV( ) ) bAtLimit = TRUE;    if( f1 == m_oSpnValue.fGetMinV( ) ) bAtLimit = TRUE;  }  // Determine the event type and act accordingly  if( roEvtSpn.GetEventType( ) == wxEVT_SCROLL_LINEUP )  { // Increment the value    if( f1 > 0.0 )    { // Positive numbers      if( f1 < m_oSpnValue.fGetMaxV( ) ) { bAtLimit = FALSE; return; }      if( ! bAtLimit )                   { bAtLimit = TRUE;  return; }      f1 /= 1000.0;      i1 += 3;    }    else    { // Negative numbers      if( f1 < -1.0 )                    { bAtLimit = FALSE; return; }      if( ! bAtLimit )                   { bAtLimit = TRUE;  return; }      f1 = -1000.0;      i1 -= 3;    }  }  else if( roEvtSpn.GetEventType( ) == wxEVT_SCROLL_LINEDOWN )  { // Decrement the value    if( f1 < 0.0 )    { // Negative numbers      if( f1 > m_oSpnValue.fGetMinV( ) ) { bAtLimit = FALSE; return; }      if( ! bAtLimit )                   { bAtLimit = TRUE;  return; }      f1 /= 1000.0;      i1 += 3;    }    else    { // Positive numbers      if( f1 > 1.0 )                     { bAtLimit = FALSE; return; }      if( ! bAtLimit )                   { bAtLimit = TRUE;  return; }      f1 = 1000.0;      i1 -= 3;    }  }  else return;  if( m_oChoUnits.bSetUnits( i1 ) ) m_oSpnValue.bSetValue( f1 );}//*****************************************************************************// Units choice box event handler.//// Argument List://   roEvtCmd - An object holding information about the eventvoid  PnlValue::OnChoUnits( wxCommandEvent & roEvtCmd ){  if( m_oChoUnits.eGetUType( ) == ChoUnits::eUNTS_TEMP )  {         if( m_oChoUnits.rosGetUnits( ).IsSameAs( wxT("Deg. C") ) )      bSetParms( 27.0, -100.0, 200.0, 1.0 );    else if( m_oChoUnits.rosGetUnits( ).IsSameAs( wxT("Deg. F") ) )      bSetParms( 70.0, -100.0, 400.0, 1.0 );    else if( m_oChoUnits.rosGetUnits( ).IsSameAs( wxT("Deg. K") ) )      bSetParms( 300.0, 200.0, 500.0, 1.0 );  }  else if( m_oChoUnits.eGetUType( ) == ChoUnits::eUNTS_PHASE )  {         if( m_oChoUnits.rosGetUnits( ).IsSameAs( wxT("Degree") ) )      bSetParms( 0.0, 0.0, 360.0, 1.0 );    else if( m_oChoUnits.rosGetUnits( ).IsSameAs( wxT("Radian") ) )      bSetParms( 0.0, 0.0, 6.3, 0.1 );    else if( m_oChoUnits.rosGetUnits( ).IsSameAs( wxT("Grad") ) )      bSetParms( 0.0, 0.0, 400.0, 1.0 );  }}//*****************************************************************************

⌨️ 快捷键说明

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