diff --git a/eeschema/sim/sim_property.cpp b/eeschema/sim/sim_property.cpp index 8ab69f4d3c..3a6b6c6a34 100644 --- a/eeschema/sim/sim_property.cpp +++ b/eeschema/sim/sim_property.cpp @@ -121,8 +121,7 @@ bool SIM_STRING_PROPERTY::OnEvent( wxPropertyGrid* propgrid, wxWindow* wnd_prima { double value = SIM_VALUE::ToDouble( m_eval.Result().ToStdString() ); - if( isnan( value ) - || value == SIM_VALUE::ToDouble( textEntry->GetValue().ToStdString() ) ) + if( isnan( value ) || SIM_VALUE::Equal( value, textEntry->GetValue().ToStdString() ) ) { // Don't mess up user formatting if eval'ing didn't actually change the value. } @@ -149,25 +148,23 @@ bool SIM_STRING_PROPERTY::OnEvent( wxPropertyGrid* propgrid, wxWindow* wnd_prima keyEvent.m_keyCode = keyEvent.ShiftDown() ? WXK_UP : WXK_DOWN; keyEvent.m_shiftDown = false; } - } - } #ifdef __WXMAC__ - if( wxPropertyGrid* propGrid = dynamic_cast( wnd_primary->GetParent() ) ) - { - // This shouldn't be required, as wxPGTextCtrlEditor::OnTextCtrlEvent() should be setting - // the value to modified. But it doesn't on Mac (or the modified flag is cleared at some - // point later), and even if it is set, the changes don't get committed. - // (We used to have code in DIALOG_SIM_MODEL to commit things on *some* actions, but it - // wasn't complete and this appears to have at least a better hit rate.) - propGrid->CallAfter( - [propGrid]() - { - propGrid->EditorsValueWasModified(); - propGrid->CommitChangesFromEditor(); - } ); - } + // This shouldn't be required, as wxPGTextCtrlEditor::OnTextCtrlEvent() should be + // setting the value to modified. But it doesn't on Mac (or the modified flag is + // cleared at some point later), and even if it is set, the changes don't get + // committed. + // (We used to have code in DIALOG_SIM_MODEL to commit things on *some* actions, but + // it wasn't complete and this appears to have at least a better hit rate.) + propGrid->CallAfter( + [propGrid]() + { + propGrid->EditorsValueWasModified(); + propGrid->CommitChangesFromEditor(); + } ); #endif + } + } return false; } @@ -198,7 +195,7 @@ bool SIM_STRING_PROPERTY::StringToValue( wxVariant& aVariant, const wxString& aT { double value = SIM_VALUE::ToDouble( m_eval.Result().ToStdString() ); - if( isnan( value ) || value == SIM_VALUE::ToDouble( aText.ToStdString() ) ) + if( isnan( value ) || SIM_VALUE::Equal( value, aText.ToStdString() ) ) { // Don't mess up user formatting if eval'ing didn't actually change the value. } diff --git a/eeschema/sim/sim_value.cpp b/eeschema/sim/sim_value.cpp index 7007ba26ae..118f40ec7b 100644 --- a/eeschema/sim/sim_value.cpp +++ b/eeschema/sim/sim_value.cpp @@ -451,3 +451,9 @@ int SIM_VALUE::ToInt( const std::string& aString, int aDefault ) return aDefault; } + + +bool SIM_VALUE::Equal( double aLH, const std::string& aRH ) +{ + return std::abs( aLH - ToDouble( aRH ) ) <= std::numeric_limits::epsilon(); +} diff --git a/eeschema/sim/sim_value.h b/eeschema/sim/sim_value.h index 2f9f23618c..873ccde802 100644 --- a/eeschema/sim/sim_value.h +++ b/eeschema/sim/sim_value.h @@ -89,6 +89,8 @@ public: static double ToDouble( const std::string& aString, double aDefault = NAN ); static int ToInt( const std::string& aString, int aDefault = -1 ); + + static bool Equal( double aLH, const std::string& aRH ); };