From f17f10d2a63332784e552fcbf70672a39f98a60d Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Fri, 14 Feb 2020 13:07:13 +0100 Subject: [PATCH] Eeschema, DIALOG_UPDATE_FIELDS: ensure mandatory fields are put in list. Add also a comment in common.cpp about using wxLocale instead of setlocale. DIALOG_UPDATE_FIELDS has issues in non English languages, due to its design. The fix for mandatory fields is only a partial fix that avoid major issues. --- common/common.cpp | 8 +- eeschema/dialogs/dialog_update_fields.cpp | 6 +- .../dialogs/dialog_update_fields_base.cpp | 76 ++--- .../dialogs/dialog_update_fields_base.fbp | 263 ++---------------- eeschema/dialogs/dialog_update_fields_base.h | 23 +- eeschema/lib_field.cpp | 6 - 6 files changed, 83 insertions(+), 299 deletions(-) diff --git a/common/common.cpp b/common/common.cpp index 351926d474..687b8f2f7c 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -59,8 +59,13 @@ using KIGFX::COLOR4D; // Works fine to read/write files with floating point numbers. // We can call setlocale( LC_NUMERIC, "C" ) of wxLocale( "C", "C", "C", false ) // wxWidgets discourage a direct call to setlocale +// However, for us, calling wxLocale( "C", "C", "C", false ) has a unwanted effect: +// The I18N translations are no longer active, because the English dixtionary is selected. +// To read files, this is not a major issues, but the resul can differ +// from using setlocale(xx, "C"). // Previouly, we called setlocale( LC_NUMERIC, "C" ) -// The old code will be removed when calling wxLocale( "C", "C", "C", false ) is fully tested +// The old code will be removed when calling wxLocale( "C", "C", "C", false ) +// is fully tested, and all issues fixed #define USE_WXLOCALE 1 /* 0 to call setlocale, 1 to call wxLocale */ // On Windows, when using setlocale, a wx alert is generated @@ -81,7 +86,6 @@ void KiAssertFilter( const wxString &file, int line, #endif #endif - std::atomic LOCALE_IO::m_c_count( 0 ); LOCALE_IO::LOCALE_IO() : m_wxLocale( nullptr ) { diff --git a/eeschema/dialogs/dialog_update_fields.cpp b/eeschema/dialogs/dialog_update_fields.cpp index a1e888a145..da2b121a65 100644 --- a/eeschema/dialogs/dialog_update_fields.cpp +++ b/eeschema/dialogs/dialog_update_fields.cpp @@ -157,7 +157,10 @@ void DIALOG_UPDATE_FIELDS::updateFields( SCH_COMPONENT* aComponent ) for( auto compField : oldFields ) { // If requested, transfer only fields that occur also in the original library part - if( !m_removeExtraBox->IsChecked() || libPart->FindField( compField->GetName() ) ) + // and obviously mandatory fields + if( compField->GetId() < MANDATORY_FIELDS + || !m_removeExtraBox->IsChecked() + || libPart->FindField( compField->GetName() ) ) newFields.push_back( *compField ); } @@ -170,6 +173,7 @@ void DIALOG_UPDATE_FIELDS::updateFields( SCH_COMPONENT* aComponent ) continue; SCH_FIELD* field = nullptr; + auto it = std::find_if( newFields.begin(), newFields.end(), [&] ( const SCH_FIELD& f ) { return f.GetName() == partField; } ); diff --git a/eeschema/dialogs/dialog_update_fields_base.cpp b/eeschema/dialogs/dialog_update_fields_base.cpp index 8a2bead9f9..bdfad6abb4 100644 --- a/eeschema/dialogs/dialog_update_fields_base.cpp +++ b/eeschema/dialogs/dialog_update_fields_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Dec 30 2017) +// C++ code generated with wxFormBuilder (version Jul 10 2019) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -12,84 +12,84 @@ DIALOG_UPDATE_FIELDS_BASE::DIALOG_UPDATE_FIELDS_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style ) { this->SetSizeHints( wxDefaultSize, wxDefaultSize ); - + wxBoxSizer* m_mainSizer; m_mainSizer = new wxBoxSizer( wxVERTICAL ); - + wxBoxSizer* bUpperSizer; bUpperSizer = new wxBoxSizer( wxHORIZONTAL ); - + wxStaticBoxSizer* sbSizer2; - sbSizer2 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Fields to Update:") ), wxVERTICAL ); - + sbSizer2 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Fields to Update") ), wxVERTICAL ); + wxArrayString m_fieldsBoxChoices; m_fieldsBox = new wxCheckListBox( sbSizer2->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, m_fieldsBoxChoices, wxLB_NEEDED_SB ); m_fieldsBox->SetMinSize( wxSize( -1,150 ) ); - + sbSizer2->Add( m_fieldsBox, 1, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); - + wxBoxSizer* m_selBtnSizer; m_selBtnSizer = new wxBoxSizer( wxHORIZONTAL ); - + m_selAllBtn = new wxButton( sbSizer2->GetStaticBox(), wxID_ANY, _("Select All"), wxDefaultPosition, wxDefaultSize, 0 ); m_selBtnSizer->Add( m_selAllBtn, 1, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); - + m_selNoneBtn = new wxButton( sbSizer2->GetStaticBox(), wxID_ANY, _("Select None"), wxDefaultPosition, wxDefaultSize, 0 ); m_selBtnSizer->Add( m_selNoneBtn, 1, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); - - + + sbSizer2->Add( m_selBtnSizer, 0, wxEXPAND, 5 ); - - + + bUpperSizer->Add( sbSizer2, 1, wxEXPAND|wxTOP|wxLEFT, 10 ); - + wxStaticBoxSizer* sbSizer1; - sbSizer1 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Options:") ), wxVERTICAL ); - + sbSizer1 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Options") ), wxVERTICAL ); + m_removeExtraBox = new wxCheckBox( sbSizer1->GetStaticBox(), wxID_ANY, _("Remove fields not in library"), wxDefaultPosition, wxDefaultSize, 0 ); - m_removeExtraBox->SetToolTip( _("Removes fields that do not occur in the original library symbols") ); - + m_removeExtraBox->SetToolTip( _("Removes fields that do not occur in the original library symbol") ); + sbSizer1->Add( m_removeExtraBox, 0, wxBOTTOM|wxRIGHT|wxLEFT, 5 ); - + m_resetEmpty = new wxCheckBox( sbSizer1->GetStaticBox(), wxID_ANY, _("Reset fields which are empty in library"), wxDefaultPosition, wxDefaultSize, 0 ); - m_resetEmpty->SetToolTip( _("Do not clear existing entries if library field is empty") ); - + m_resetEmpty->SetToolTip( _("Clear existing entries if the correspondig library field is empty") ); + sbSizer1->Add( m_resetEmpty, 0, wxALL, 5 ); - - + + sbSizer1->Add( 0, 0, 0, wxEXPAND|wxTOP|wxBOTTOM, 5 ); - + m_resetVisibility = new wxCheckBox( sbSizer1->GetStaticBox(), wxID_ANY, _("Reset field visibilities"), wxDefaultPosition, wxDefaultSize, 0 ); sbSizer1->Add( m_resetVisibility, 0, wxALL, 5 ); - + m_resetSizeAndStyle = new wxCheckBox( sbSizer1->GetStaticBox(), wxID_ANY, _("Reset field text sizes and styles"), wxDefaultPosition, wxDefaultSize, 0 ); sbSizer1->Add( m_resetSizeAndStyle, 0, wxALL, 5 ); - + m_resetPosition = new wxCheckBox( sbSizer1->GetStaticBox(), wxID_ANY, _("Reset field positions"), wxDefaultPosition, wxDefaultSize, 0 ); sbSizer1->Add( m_resetPosition, 0, wxALL, 5 ); - - + + bUpperSizer->Add( sbSizer1, 0, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 10 ); - - + + m_mainSizer->Add( bUpperSizer, 1, wxEXPAND, 5 ); - + m_sdbSizer = new wxStdDialogButtonSizer(); m_sdbSizerOK = new wxButton( this, wxID_OK ); m_sdbSizer->AddButton( m_sdbSizerOK ); m_sdbSizerCancel = new wxButton( this, wxID_CANCEL ); m_sdbSizer->AddButton( m_sdbSizerCancel ); m_sdbSizer->Realize(); - + m_mainSizer->Add( m_sdbSizer, 0, wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT, 5 ); - - + + this->SetSizer( m_mainSizer ); this->Layout(); m_mainSizer->Fit( this ); - + this->Centre( wxBOTH ); - + // Connect Events m_selAllBtn->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_UPDATE_FIELDS_BASE::onSelectAll ), NULL, this ); m_selNoneBtn->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_UPDATE_FIELDS_BASE::onSelectNone ), NULL, this ); @@ -100,5 +100,5 @@ DIALOG_UPDATE_FIELDS_BASE::~DIALOG_UPDATE_FIELDS_BASE() // Disconnect Events m_selAllBtn->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_UPDATE_FIELDS_BASE::onSelectAll ), NULL, this ); m_selNoneBtn->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_UPDATE_FIELDS_BASE::onSelectNone ), NULL, this ); - + } diff --git a/eeschema/dialogs/dialog_update_fields_base.fbp b/eeschema/dialogs/dialog_update_fields_base.fbp index d72d539009..3c877b2a2b 100644 --- a/eeschema/dialogs/dialog_update_fields_base.fbp +++ b/eeschema/dialogs/dialog_update_fields_base.fbp @@ -1,6 +1,6 @@ - + C++ @@ -14,6 +14,8 @@ dialog_update_fields_base 1000 none + + 1 dialog_update_fields_base @@ -24,6 +26,7 @@ 1 1 UI + 0 0 0 @@ -52,42 +55,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - m_mainSizer @@ -114,7 +81,6 @@ wxVERTICAL 1 none - 5 wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT @@ -176,32 +142,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -228,25 +168,31 @@ + 1 0 1 1 + 0 0 + Dock 0 Left 1 1 + 0 0 wxID_ANY Select All + + 0 0 @@ -261,6 +207,8 @@ protected 1 + + Resizable 1 @@ -276,29 +224,6 @@ onSelectAll - - - - - - - - - - - - - - - - - - - - - - - @@ -316,25 +241,31 @@ + 1 0 1 1 + 0 0 + Dock 0 Left 1 1 + 0 0 wxID_ANY Select None + + 0 0 @@ -349,6 +280,8 @@ protected 1 + + Resizable 1 @@ -364,29 +297,6 @@ onSelectNone - - - - - - - - - - - - - - - - - - - - - - - @@ -405,7 +315,6 @@ wxVERTICAL 1 none - 5 wxBOTTOM|wxRIGHT|wxLEFT @@ -460,7 +369,7 @@ 0 - Removes fields that do not occur in the original library symbols + Removes fields that do not occur in the original library symbol wxFILTER_NONE wxDefaultValidator @@ -468,30 +377,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -548,7 +433,7 @@ ; forward_declare 0 - Do not clear existing entries if library field is empty + Clear existing entries if the correspondig library field is empty wxFILTER_NONE wxDefaultValidator @@ -556,30 +441,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -654,30 +515,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -742,30 +579,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -830,30 +643,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -876,14 +665,6 @@ m_sdbSizer protected - - - - - - - - diff --git a/eeschema/dialogs/dialog_update_fields_base.h b/eeschema/dialogs/dialog_update_fields_base.h index ef7d43f25d..a816b1e4ef 100644 --- a/eeschema/dialogs/dialog_update_fields_base.h +++ b/eeschema/dialogs/dialog_update_fields_base.h @@ -1,12 +1,11 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Dec 30 2017) +// C++ code generated with wxFormBuilder (version Jul 10 2019) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// -#ifndef __DIALOG_UPDATE_FIELDS_BASE_H__ -#define __DIALOG_UPDATE_FIELDS_BASE_H__ +#pragma once #include #include @@ -18,6 +17,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -33,7 +35,7 @@ class DIALOG_UPDATE_FIELDS_BASE : public DIALOG_SHIM { private: - + protected: wxCheckListBox* m_fieldsBox; wxButton* m_selAllBtn; @@ -46,17 +48,16 @@ class DIALOG_UPDATE_FIELDS_BASE : public DIALOG_SHIM wxStdDialogButtonSizer* m_sdbSizer; wxButton* m_sdbSizerOK; wxButton* m_sdbSizerCancel; - + // Virtual event handlers, overide them in your derived class virtual void onSelectAll( wxCommandEvent& event ) { event.Skip(); } virtual void onSelectNone( wxCommandEvent& event ) { event.Skip(); } - - + + public: - - DIALOG_UPDATE_FIELDS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Update Symbol Fields"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + + DIALOG_UPDATE_FIELDS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Update Symbol Fields"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); ~DIALOG_UPDATE_FIELDS_BASE(); - + }; -#endif //__DIALOG_UPDATE_FIELDS_BASE_H__ diff --git a/eeschema/lib_field.cpp b/eeschema/lib_field.cpp index 1fd275d37c..09303c4ed1 100644 --- a/eeschema/lib_field.cpp +++ b/eeschema/lib_field.cpp @@ -365,8 +365,6 @@ COLOR4D LIB_FIELD::GetDefaultColor() wxString LIB_FIELD::GetName( bool aTranslate ) const { - wxString name; - switch( m_id ) { case REFERENCE: return aTranslate ? _( "Reference" ) : wxT( "Reference" ); @@ -376,14 +374,10 @@ wxString LIB_FIELD::GetName( bool aTranslate ) const default: if( m_name.IsEmpty() ) - { return aTranslate ? wxString::Format( _( "Field%d" ), m_id ) : wxString::Format( wxT( "Field%d" ), m_id ); - } else - { return m_name; - } } }