diff --git a/common/libeval/numeric_evaluator.cpp b/common/libeval/numeric_evaluator.cpp index 946d3b5ee9..ab25728d53 100644 --- a/common/libeval/numeric_evaluator.cpp +++ b/common/libeval/numeric_evaluator.cpp @@ -99,18 +99,21 @@ void NUMERIC_EVALUATOR::LocaleChanged() } +// NOT UNUSED. Called by LEMON grammar. void NUMERIC_EVALUATOR::parseError( const char* s ) { m_parseError = true; } +// NOT UNUSED. Called by LEMON grammar. void NUMERIC_EVALUATOR::parseOk() { m_parseFinished = true; } +// NOT UNUSED. Called by LEMON grammar. void NUMERIC_EVALUATOR::parseSetResult( double val ) { if( std::isnan( val ) ) @@ -429,7 +432,7 @@ NUMERIC_EVALUATOR::Token NUMERIC_EVALUATOR::getToken() const char* cptr = &m_token.input[ m_token.pos ]; cptr++; - while( isalnum( *cptr )) + while( isalnum( *cptr ) ) cptr++; retval.token = VAR; @@ -474,8 +477,15 @@ void NUMERIC_EVALUATOR::SetVar( const wxString& aString, double aValue ) double NUMERIC_EVALUATOR::GetVar( const wxString& aString ) { - if( m_varMap[ aString ] ) - return m_varMap[ aString ]; + auto it = m_varMap.find( aString ); + + if( it != m_varMap.end() ) + { + return it->second; + } else + { + m_parseError = true; return 0.0; + } } diff --git a/eeschema/sim/sim_property.cpp b/eeschema/sim/sim_property.cpp index 6504afd0ed..3f29b5c845 100644 --- a/eeschema/sim/sim_property.cpp +++ b/eeschema/sim/sim_property.cpp @@ -47,8 +47,8 @@ void SIM_PROPERTY::Disable() } -SIM_BOOL_PROPERTY::SIM_BOOL_PROPERTY( const wxString& aLabel, const wxString& aName, SIM_MODEL& aModel, - int aParamIndex ) : +SIM_BOOL_PROPERTY::SIM_BOOL_PROPERTY( const wxString& aLabel, const wxString& aName, + SIM_MODEL& aModel, int aParamIndex ) : wxBoolProperty( aLabel, aName ), SIM_PROPERTY( aModel, aParamIndex ) { @@ -84,8 +84,9 @@ void SIM_BOOL_PROPERTY::OnSetValue() } -SIM_STRING_PROPERTY::SIM_STRING_PROPERTY( const wxString& aLabel, const wxString& aName, SIM_MODEL& aModel, - int aParamIndex, SIM_VALUE::TYPE aValueType, +SIM_STRING_PROPERTY::SIM_STRING_PROPERTY( const wxString& aLabel, const wxString& aName, + SIM_MODEL& aModel, int aParamIndex, + SIM_VALUE::TYPE aValueType, SIM_VALUE_GRAMMAR::NOTATION aNotation ) : wxStringProperty( aLabel, aName ), SIM_PROPERTY( aModel, aParamIndex ), @@ -161,7 +162,8 @@ bool SIM_STRING_PROPERTY::allowEval() const } -bool SIM_STRING_PROPERTY::StringToValue( wxVariant& aVariant, const wxString& aText, int aArgFlags ) const +bool SIM_STRING_PROPERTY::StringToValue( wxVariant& aVariant, const wxString& aText, + int aArgFlags ) const { if( m_disabled ) return false; @@ -191,16 +193,22 @@ static wxArrayString convertStringsToWx( const std::vector& aString } -SIM_ENUM_PROPERTY::SIM_ENUM_PROPERTY( const wxString& aLabel, const wxString& aName, SIM_MODEL& aModel, - int aParamIndex ) : - wxEnumProperty( aLabel, aName, convertStringsToWx( aModel.GetParam( aParamIndex ).info.enumValues ) ), +SIM_ENUM_PROPERTY::SIM_ENUM_PROPERTY( const wxString& aLabel, const wxString& aName, + SIM_MODEL& aModel, int aParamIndex ) : + wxEnumProperty( aLabel, aName, + convertStringsToWx( aModel.GetParam( aParamIndex ).info.enumValues ) ), SIM_PROPERTY( aModel, aParamIndex ) { - auto it = std::find( GetParam().info.enumValues.begin(), GetParam().info.enumValues.end(), - GetParam().value->ToString() ); + for( int ii = 0; ii < (int) GetParam().info.enumValues.size(); ++ii ) + { + if( GetParam().info.enumValues[ii] == GetParam().value->ToString() ) + { + SetValue( ii ); + return; + } + } - // we need the force cast for msvc because wxVariant lacks 64-bit methods due to `long` - SetValue( static_cast( std::distance( GetParam().info.enumValues.begin(), it ) ) ); + SetValue( -1 ); }