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.
This commit is contained in:
jean-pierre charras 2016-09-17 18:34:44 +02:00
parent e5064231f9
commit 0719f8d214
4 changed files with 708 additions and 309 deletions

View File

@ -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/ // http://www.wxformbuilder.org/
// //
// PLEASE DO "NOT" EDIT THIS FILE! // 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_notebook = new wxNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
m_passive = new wxPanel( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); m_passive = new wxPanel( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
wxBoxSizer* bSizer41;
bSizer41 = new wxBoxSizer( wxVERTICAL );
wxFlexGridSizer* fgSizer1; wxFlexGridSizer* fgSizer1;
fgSizer1 = new wxFlexGridSizer( 0, 2, 0, 0 ); fgSizer1 = new wxFlexGridSizer( 0, 2, 0, 0 );
fgSizer1->AddGrowableCol( 1 ); fgSizer1->AddGrowableCol( 1 );
@ -28,10 +31,11 @@ DIALOG_SPICE_MODEL_BASE::DIALOG_SPICE_MODEL_BASE( wxWindow* parent, wxWindowID i
m_staticText2->Wrap( -1 ); m_staticText2->Wrap( -1 );
fgSizer1->Add( m_staticText2, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); 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( _("Resistor") );
m_pasType->Append( _("Capacitor") ); m_pasType->Append( _("Capacitor") );
m_pasType->Append( _("Inductor") ); m_pasType->Append( _("Inductor") );
m_pasType->SetSelection( 0 );
fgSizer1->Add( m_pasType, 0, wxALL|wxEXPAND, 5 ); fgSizer1->Add( m_pasType, 0, wxALL|wxEXPAND, 5 );
m_staticText3 = new wxStaticText( m_passive, wxID_ANY, _("Value"), wxDefaultPosition, wxDefaultSize, 0 ); 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 ); 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(); m_passive->Layout();
fgSizer1->Fit( m_passive ); bSizer41->Fit( m_passive );
m_notebook->AddPage( m_passive, _("Passive"), false ); m_notebook->AddPage( m_passive, _("Passive"), true );
m_semiconductor = new wxPanel( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); m_semiconductor = new wxPanel( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
wxFlexGridSizer* fgSizer3; wxFlexGridSizer* fgSizer3;
fgSizer3 = new wxFlexGridSizer( 0, 3, 0, 0 ); 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->SetSizer( bSizer4 );
m_power->Layout(); m_power->Layout();
bSizer4->Fit( m_power ); 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 ); bSizer1->Add( m_notebook, 1, wxEXPAND | wxALL, 5 );

File diff suppressed because it is too large Load Diff

View File

@ -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/ // http://www.wxformbuilder.org/
// //
// PLEASE DO "NOT" EDIT THIS FILE! // PLEASE DO "NOT" EDIT THIS FILE!
@ -23,6 +23,7 @@ class DIALOG_SHIM;
#include <wx/combobox.h> #include <wx/combobox.h>
#include <wx/textctrl.h> #include <wx/textctrl.h>
#include <wx/sizer.h> #include <wx/sizer.h>
#include <wx/statline.h>
#include <wx/panel.h> #include <wx/panel.h>
#include <wx/bitmap.h> #include <wx/bitmap.h>
#include <wx/image.h> #include <wx/image.h>
@ -44,7 +45,7 @@ class DIALOG_SHIM;
class DIALOG_SPICE_MODEL_BASE : public DIALOG_SHIM class DIALOG_SPICE_MODEL_BASE : public DIALOG_SHIM
{ {
private: private:
protected: protected:
wxNotebook* m_notebook; wxNotebook* m_notebook;
wxPanel* m_passive; wxPanel* m_passive;
@ -52,6 +53,10 @@ class DIALOG_SPICE_MODEL_BASE : public DIALOG_SHIM
wxComboBox* m_pasType; wxComboBox* m_pasType;
wxStaticText* m_staticText3; wxStaticText* m_staticText3;
wxTextCtrl* m_pasValue; wxTextCtrl* m_pasValue;
wxStaticLine* m_staticline1;
wxStaticText* m_staticText32;
wxStaticText* m_staticText321;
wxStaticText* m_staticTextUnitsSymbolsInfo;
wxPanel* m_semiconductor; wxPanel* m_semiconductor;
wxStaticText* m_staticText4; wxStaticText* m_staticText4;
wxComboBox* m_semiType; wxComboBox* m_semiType;
@ -133,20 +138,20 @@ class DIALOG_SPICE_MODEL_BASE : public DIALOG_SHIM
wxStdDialogButtonSizer* m_sdbSizer; wxStdDialogButtonSizer* m_sdbSizer;
wxButton* m_sdbSizerOK; wxButton* m_sdbSizerOK;
wxButton* m_sdbSizerCancel; wxButton* m_sdbSizerCancel;
// Virtual event handlers, overide them in your derived class // Virtual event handlers, overide them in your derived class
virtual void onInitDlg( wxInitDialogEvent& event ) { event.Skip(); } virtual void onInitDlg( wxInitDialogEvent& event ) { event.Skip(); }
virtual void onSemiSelectLib( wxCommandEvent& event ) { event.Skip(); } virtual void onSemiSelectLib( wxCommandEvent& event ) { event.Skip(); }
virtual void onSelectIcLib( wxCommandEvent& event ) { event.Skip(); } virtual void onSelectIcLib( wxCommandEvent& event ) { event.Skip(); }
virtual void onPwlAdd( wxCommandEvent& event ) { event.Skip(); } virtual void onPwlAdd( wxCommandEvent& event ) { event.Skip(); }
virtual void onPwlRemove( wxCommandEvent& event ) { event.Skip(); } virtual void onPwlRemove( wxCommandEvent& event ) { event.Skip(); }
public: 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(); ~DIALOG_SPICE_MODEL_BASE();
}; };
#endif //__DIALOG_SPICE_MODEL_BASE_H__ #endif //__DIALOG_SPICE_MODEL_BASE_H__

View File

@ -28,7 +28,9 @@
#include <cmath> #include <cmath>
#include <wx/textentry.h> #include <wx/textentry.h>
#include <wx/numformatter.h>
#include <confirm.h> #include <confirm.h>
#include <common.h>
SPICE_VALUE::SPICE_VALUE( const wxString& aString ) SPICE_VALUE::SPICE_VALUE( const wxString& aString )
{ {
@ -37,6 +39,8 @@ SPICE_VALUE::SPICE_VALUE( const wxString& aString )
if( aString.IsEmpty() ) if( aString.IsEmpty() )
throw std::invalid_argument( "Spice value cannot be empty" ); 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 ) if( sscanf( (const char*) aString.c_str(), "%lf%7s", &m_base, buf ) == 0 )
throw std::invalid_argument( "Invalid Spice value string" ); throw std::invalid_argument( "Invalid Spice value string" );
@ -244,22 +248,32 @@ bool SPICE_VALIDATOR::Validate( wxWindow* aParent )
if( m_emptyAllowed ) if( m_emptyAllowed )
return true; return true;
DisplayError( aParent, wxString::Format( wxT( "Fill required fields" ) ) ); DisplayError( aParent, wxString::Format( _( "Please, fill required fields" ) ) );
return false; 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 try
{ {
// If SPICE_VALUE can be constructed, then it is a valid Spice value // If SPICE_VALUE can be constructed, then it is a valid Spice value
SPICE_VALUE val( text->GetValue() ); SPICE_VALUE val( svalue );
} }
catch( ... ) catch( ... )
{ {
DisplayError( aParent, 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; return false;
} }
if( svalue != text->GetValue() )
text->SetValue( svalue );
return true; return true;
} }