From 0719f8d21489c3939bd3789cddd3b653227f237e Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sat, 17 Sep 2016 18:34:44 +0200 Subject: [PATCH] Fixes: lp:1624659 (fix some issues in countries which are not using a point as decimal separator) https://bugs.launchpad.net/kicad/+bug/1624659 Small enhancement in dialog_spice_model_base.cpp: add comments about spice values notation. --- eeschema/dialogs/dialog_spice_model_base.cpp | 40 +- eeschema/dialogs/dialog_spice_model_base.fbp | 936 +++++++++++++------ eeschema/dialogs/dialog_spice_model_base.h | 21 +- eeschema/sim/spice_value.cpp | 20 +- 4 files changed, 708 insertions(+), 309 deletions(-) diff --git a/eeschema/dialogs/dialog_spice_model_base.cpp b/eeschema/dialogs/dialog_spice_model_base.cpp index 07ac72fd16..fad032d072 100644 --- a/eeschema/dialogs/dialog_spice_model_base.cpp +++ b/eeschema/dialogs/dialog_spice_model_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Jul 31 2016) +// C++ code generated with wxFormBuilder (version Sep 8 2016) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! @@ -18,6 +18,9 @@ DIALOG_SPICE_MODEL_BASE::DIALOG_SPICE_MODEL_BASE( wxWindow* parent, wxWindowID i m_notebook = new wxNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); m_passive = new wxPanel( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); + wxBoxSizer* bSizer41; + bSizer41 = new wxBoxSizer( wxVERTICAL ); + wxFlexGridSizer* fgSizer1; fgSizer1 = new wxFlexGridSizer( 0, 2, 0, 0 ); fgSizer1->AddGrowableCol( 1 ); @@ -28,10 +31,11 @@ DIALOG_SPICE_MODEL_BASE::DIALOG_SPICE_MODEL_BASE( wxWindow* parent, wxWindowID i m_staticText2->Wrap( -1 ); fgSizer1->Add( m_staticText2, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - m_pasType = new wxComboBox( m_passive, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY ); + m_pasType = new wxComboBox( m_passive, wxID_ANY, _("Resistor"), wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY ); m_pasType->Append( _("Resistor") ); m_pasType->Append( _("Capacitor") ); m_pasType->Append( _("Inductor") ); + m_pasType->SetSelection( 0 ); fgSizer1->Add( m_pasType, 0, wxALL|wxEXPAND, 5 ); m_staticText3 = new wxStaticText( m_passive, wxID_ANY, _("Value"), wxDefaultPosition, wxDefaultSize, 0 ); @@ -44,10 +48,34 @@ DIALOG_SPICE_MODEL_BASE::DIALOG_SPICE_MODEL_BASE( wxWindow* parent, wxWindowID i fgSizer1->Add( m_pasValue, 0, wxALL|wxEXPAND, 5 ); - m_passive->SetSizer( fgSizer1 ); + bSizer41->Add( fgSizer1, 0, wxEXPAND|wxALL, 5 ); + + m_staticline1 = new wxStaticLine( m_passive, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); + bSizer41->Add( m_staticline1, 0, wxEXPAND | wxALL, 5 ); + + wxBoxSizer* bSizer5; + bSizer5 = new wxBoxSizer( wxVERTICAL ); + + m_staticText32 = new wxStaticText( m_passive, wxID_ANY, _("In Spice values,the decimal separator is the point.\nValues can use Spice unit symbols."), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticText32->Wrap( -1 ); + bSizer5->Add( m_staticText32, 0, wxALL, 5 ); + + m_staticText321 = new wxStaticText( m_passive, wxID_ANY, _("Spice unit symbols in values (case insensitive):"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticText321->Wrap( -1 ); + bSizer5->Add( m_staticText321, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); + + m_staticTextUnitsSymbolsInfo = new wxStaticText( m_passive, wxID_ANY, _("f = FEMTO\np = PICO\nn = NANO\nu = MICRO\nm = MILI\nk = KILO\nmeg = MEGA\ng = GIGA\nt = TERA"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticTextUnitsSymbolsInfo->Wrap( -1 ); + bSizer5->Add( m_staticTextUnitsSymbolsInfo, 0, wxALL, 5 ); + + + bSizer41->Add( bSizer5, 0, wxALIGN_CENTER_HORIZONTAL, 5 ); + + + m_passive->SetSizer( bSizer41 ); m_passive->Layout(); - fgSizer1->Fit( m_passive ); - m_notebook->AddPage( m_passive, _("Passive"), false ); + bSizer41->Fit( m_passive ); + m_notebook->AddPage( m_passive, _("Passive"), true ); m_semiconductor = new wxPanel( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); wxFlexGridSizer* fgSizer3; fgSizer3 = new wxFlexGridSizer( 0, 3, 0, 0 ); @@ -441,7 +469,7 @@ DIALOG_SPICE_MODEL_BASE::DIALOG_SPICE_MODEL_BASE( wxWindow* parent, wxWindowID i m_power->SetSizer( bSizer4 ); m_power->Layout(); bSizer4->Fit( m_power ); - m_notebook->AddPage( m_power, _("Source"), true ); + m_notebook->AddPage( m_power, _("Source"), false ); bSizer1->Add( m_notebook, 1, wxEXPAND | wxALL, 5 ); diff --git a/eeschema/dialogs/dialog_spice_model_base.fbp b/eeschema/dialogs/dialog_spice_model_base.fbp index 3f004d58c0..612820f7aa 100644 --- a/eeschema/dialogs/dialog_spice_model_base.fbp +++ b/eeschema/dialogs/dialog_spice_model_base.fbp @@ -178,7 +178,7 @@ Passive - 0 + 1 1 1 @@ -253,23 +253,382 @@ - - 2 - wxBOTH - 1 - - 0 + - fgSizer1 - wxFLEX_GROWMODE_SPECIFIED + bSizer41 + wxVERTICAL none - 0 - 0 - + 5 - wxALIGN_CENTER_VERTICAL|wxALL + wxEXPAND|wxALL 0 - + + 2 + wxBOTH + 1 + + 0 + + fgSizer1 + wxFLEX_GROWMODE_SPECIFIED + none + 0 + 0 + + 5 + wxALIGN_CENTER_VERTICAL|wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Type + + 0 + + + 0 + + 1 + m_staticText2 + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + "Resistor" "Capacitor" "Inductor" + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + m_pasType + 1 + + + protected + 1 + + Resizable + 0 + 1 + + wxCB_READONLY + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + Resistor + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALIGN_CENTER_VERTICAL|wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Value + + 0 + + + 0 + + 1 + m_staticText3 + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + 0 + + 0 + 200,-1 + 1 + m_pasValue + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxEXPAND | wxALL + 0 + 1 1 1 @@ -297,7 +656,6 @@ 0 0 wxID_ANY - Type 0 @@ -305,7 +663,7 @@ 0 1 - m_staticText2 + m_staticline1 1 @@ -315,14 +673,13 @@ Resizable 1 - + wxLI_HORIZONTAL 0 - -1 @@ -348,269 +705,264 @@ - + 5 - wxALL|wxEXPAND + wxALIGN_CENTER_HORIZONTAL 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - "Resistor" "Capacitor" "Inductor" - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - - 0 + - 1 - m_pasType - 1 - - - protected - 1 - - Resizable - -1 - 1 - - wxCB_READONLY - - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 - wxALIGN_CENTER_VERTICAL|wxALL - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - Value - - 0 - - - 0 - - 1 - m_staticText3 - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - - - - - -1 - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 - wxALL|wxEXPAND - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - 0 - - 0 - 200,-1 - 1 - m_pasValue - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + bSizer5 + wxVERTICAL + none + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + In Spice values,the decimal separator is the point. Values can use Spice unit symbols. + + 0 + + + 0 + + 1 + m_staticText32 + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxTOP|wxRIGHT|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Spice unit symbols in values (case insensitive): + + 0 + + + 0 + + 1 + m_staticText321 + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + f = FEMTO p = PICO n = NANO u = MICRO m = MILI k = KILO meg = MEGA g = GIGA t = TERA + + 0 + + + 0 + + 1 + m_staticTextUnitsSymbolsInfo + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + -1 + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1881,8 +2233,8 @@ Source - 1 - + 0 + 1 1 1 @@ -1956,12 +2308,12 @@ - + bSizer4 wxVERTICAL none - + 5 wxALL|wxEXPAND 0 @@ -2536,11 +2888,11 @@ - + 5 wxALL|wxEXPAND 0 - + wxID_ANY Transient analysis @@ -2549,11 +2901,11 @@ 1 none - + 5 wxEXPAND | wxALL 0 - + 1 1 1 @@ -3942,11 +4294,11 @@ - + Sinusoidal 0 - + 1 1 1 @@ -4905,11 +5257,11 @@ - + Exponential 0 - + 1 1 1 @@ -6042,11 +6394,11 @@ - + Piece-wise Linear 0 - + 1 1 1 diff --git a/eeschema/dialogs/dialog_spice_model_base.h b/eeschema/dialogs/dialog_spice_model_base.h index 6a12fb10eb..ce19fab181 100644 --- a/eeschema/dialogs/dialog_spice_model_base.h +++ b/eeschema/dialogs/dialog_spice_model_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Jul 31 2016) +// C++ code generated with wxFormBuilder (version Sep 8 2016) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! @@ -23,6 +23,7 @@ class DIALOG_SHIM; #include #include #include +#include #include #include #include @@ -44,7 +45,7 @@ class DIALOG_SHIM; class DIALOG_SPICE_MODEL_BASE : public DIALOG_SHIM { private: - + protected: wxNotebook* m_notebook; wxPanel* m_passive; @@ -52,6 +53,10 @@ class DIALOG_SPICE_MODEL_BASE : public DIALOG_SHIM wxComboBox* m_pasType; wxStaticText* m_staticText3; wxTextCtrl* m_pasValue; + wxStaticLine* m_staticline1; + wxStaticText* m_staticText32; + wxStaticText* m_staticText321; + wxStaticText* m_staticTextUnitsSymbolsInfo; wxPanel* m_semiconductor; wxStaticText* m_staticText4; wxComboBox* m_semiType; @@ -133,20 +138,20 @@ class DIALOG_SPICE_MODEL_BASE : public DIALOG_SHIM wxStdDialogButtonSizer* m_sdbSizer; wxButton* m_sdbSizerOK; wxButton* m_sdbSizerCancel; - + // Virtual event handlers, overide them in your derived class virtual void onInitDlg( wxInitDialogEvent& event ) { event.Skip(); } virtual void onSemiSelectLib( wxCommandEvent& event ) { event.Skip(); } virtual void onSelectIcLib( wxCommandEvent& event ) { event.Skip(); } virtual void onPwlAdd( wxCommandEvent& event ) { event.Skip(); } virtual void onPwlRemove( wxCommandEvent& event ) { event.Skip(); } - - + + public: - - DIALOG_SPICE_MODEL_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 640,582 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + + DIALOG_SPICE_MODEL_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 640,582 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); ~DIALOG_SPICE_MODEL_BASE(); - + }; #endif //__DIALOG_SPICE_MODEL_BASE_H__ diff --git a/eeschema/sim/spice_value.cpp b/eeschema/sim/spice_value.cpp index 383589779f..348653744b 100644 --- a/eeschema/sim/spice_value.cpp +++ b/eeschema/sim/spice_value.cpp @@ -28,7 +28,9 @@ #include #include +#include #include +#include SPICE_VALUE::SPICE_VALUE( const wxString& aString ) { @@ -37,6 +39,8 @@ SPICE_VALUE::SPICE_VALUE( const wxString& aString ) if( aString.IsEmpty() ) throw std::invalid_argument( "Spice value cannot be empty" ); + LOCALE_IO dummy; // All numeric values should be in "C" locale(decimal separator = .) + if( sscanf( (const char*) aString.c_str(), "%lf%7s", &m_base, buf ) == 0 ) throw std::invalid_argument( "Invalid Spice value string" ); @@ -244,22 +248,32 @@ bool SPICE_VALIDATOR::Validate( wxWindow* aParent ) if( m_emptyAllowed ) return true; - DisplayError( aParent, wxString::Format( wxT( "Fill required fields" ) ) ); + DisplayError( aParent, wxString::Format( _( "Please, fill required fields" ) ) ); return false; } + wxString svalue = text->GetValue(); + + // In countries where the decimal separator is not a point, if the user + // has not used a point, replace the decimal separator by the point, as needed + // by spice simulator which uses the "C" decimal separator + svalue.Replace(",", "." ); + try { // If SPICE_VALUE can be constructed, then it is a valid Spice value - SPICE_VALUE val( text->GetValue() ); + SPICE_VALUE val( svalue ); } catch( ... ) { DisplayError( aParent, - wxString::Format( wxT( "'%s' is not a valid Spice value" ), text->GetValue() ) ); + wxString::Format( _( "'%s' is not a valid Spice value" ), text->GetValue() ) ); return false; } + if( svalue != text->GetValue() ) + text->SetValue( svalue ); + return true; }