From 85faa0e1018e64b45df7a9c6e5b1b388d05becd5 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 2 Oct 2017 14:53:48 +0200 Subject: [PATCH] Added a dialog to select fields to be updated --- eeschema/CMakeLists.txt | 6 +- .../dialog_edit_component_in_schematic.cpp | 47 +- eeschema/dialogs/dialog_update_fields.cpp | 180 +++++ eeschema/dialogs/dialog_update_fields.h | 82 +++ .../dialogs/dialog_update_fields_base.cpp | 73 ++ .../dialogs/dialog_update_fields_base.fbp | 653 ++++++++++++++++++ eeschema/dialogs/dialog_update_fields_base.h | 63 ++ eeschema/invoke_sch_dialog.h | 7 +- eeschema/schframe.cpp | 24 +- 9 files changed, 1083 insertions(+), 52 deletions(-) create mode 100644 eeschema/dialogs/dialog_update_fields.cpp create mode 100644 eeschema/dialogs/dialog_update_fields.h create mode 100644 eeschema/dialogs/dialog_update_fields_base.cpp create mode 100644 eeschema/dialogs/dialog_update_fields_base.fbp create mode 100644 eeschema/dialogs/dialog_update_fields_base.h diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index dc7c0c050b..c5552187c9 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -46,6 +46,8 @@ set( EESCHEMA_DLGS dialogs/dialog_eeschema_options.cpp dialogs/dialog_erc.cpp dialogs/dialog_erc_base.cpp + dialogs/dialog_global_sym_lib_table_config.cpp + dialogs/dialog_global_sym_lib_table_config_base.cpp dialogs/dialog_lib_edit_draw_item.cpp dialogs/dialog_lib_edit_draw_item_base.cpp dialogs/dialog_libedit_options_base.cpp @@ -74,8 +76,8 @@ set( EESCHEMA_DLGS dialogs/dialog_sym_lib_table_base.cpp dialogs/dialog_symbol_remap.cpp dialogs/dialog_symbol_remap_base.cpp - dialogs/dialog_global_sym_lib_table_config.cpp - dialogs/dialog_global_sym_lib_table_config_base.cpp + dialogs/dialog_update_fields.cpp + dialogs/dialog_update_fields_base.cpp ) set( EESCHEMA_WIDGETS diff --git a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp index 6d9954ce5f..0804f8bba1 100644 --- a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp @@ -47,12 +47,14 @@ #include #include +#include #ifdef KICAD_SPICE #include #include #endif /* KICAD_SPICE */ #include "common.h" +#include /** @@ -154,6 +156,8 @@ private: */ void updateDisplay() { + fieldListCtrl->DeleteAllItems(); + for( unsigned ii = 0; ii < m_FieldsBuf.size(); ii++ ) setRowItem( ii, m_FieldsBuf[ii] ); } @@ -1207,41 +1211,22 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::SetInitCmp( wxCommandEvent& event ) void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::UpdateFields( wxCommandEvent& event ) { - if( !m_cmp ) - return; + SCH_COMPONENT copy( *m_cmp ); + std::list components; + components.push_back( © ); + InvokeDialogUpdateFields( m_parent, components, false ); - LIB_PART* part = Prj().SchLibs()->FindLibPart( m_cmp->GetLibId() ); + // Copy fields from the modified component copy to the dialog buffer + m_FieldsBuf.clear(); - if( !part ) - return; - - LIB_FIELDS fields; - part->GetFields( fields ); - - for( const LIB_FIELD& field : fields ) + for( int i = 0; i < copy.GetFieldCount(); ++i ) { - if( field.GetName().IsEmpty() ) - continue; - - int idx = field.GetId(); - SCH_FIELD* schField; - - if( idx == REFERENCE ) - continue; - else if( idx < MANDATORY_FIELDS ) - schField = &m_FieldsBuf[idx]; - else - schField = findField( field.GetName() ); - - if( !schField ) - { - SCH_FIELD fld( wxPoint( 0, 0 ), m_FieldsBuf.size(), m_cmp, field.GetName() ); - m_FieldsBuf.push_back( fld ); - schField = &m_FieldsBuf.back(); - } - - schField->SetText( field.GetText() ); + copy.m_Fields[i].SetParent( m_cmp ); + m_FieldsBuf.push_back( copy.m_Fields[i] ); + m_FieldsBuf[i].Offset( -m_cmp->m_Pos ); } + // Update the selected field as well + copySelectedFieldToPanel(); updateDisplay(); } diff --git a/eeschema/dialogs/dialog_update_fields.cpp b/eeschema/dialogs/dialog_update_fields.cpp new file mode 100644 index 0000000000..c763e0ca1e --- /dev/null +++ b/eeschema/dialogs/dialog_update_fields.cpp @@ -0,0 +1,180 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2017 CERN + * @author Maciej Suminski + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 3 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * https://www.gnu.org/licenses/gpl-3.0.html + * or you may search the http://www.gnu.org website for the version 3 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "dialog_update_fields.h" + +#include +#include +#include +#include + + +int InvokeDialogUpdateFields( SCH_EDIT_FRAME* aCaller, + const list aComponents, bool aCreateUndoEntry ) +{ + DIALOG_UPDATE_FIELDS dlg( aCaller, aComponents, aCreateUndoEntry ); + return dlg.ShowQuasiModal(); +} + + +DIALOG_UPDATE_FIELDS::DIALOG_UPDATE_FIELDS( SCH_EDIT_FRAME* aParent, + const list& aComponents, bool aCreateUndoEntry ) + : DIALOG_UPDATE_FIELDS_BASE( aParent ), m_frame( aParent ), + m_components( aComponents ), m_createUndo( aCreateUndoEntry ) +{ +} + + +bool DIALOG_UPDATE_FIELDS::TransferDataFromWindow() +{ + if( !wxDialog::TransferDataFromWindow() ) + return false; + + if( m_components.empty() ) + return true; // nothing to process + + + // Create the set of fields to be updated + m_fields.clear(); + + for( int i = 0; i < m_fieldsBox->GetCount(); ++i ) + { + if( m_fieldsBox->IsChecked( i ) ) + m_fields.insert( m_fieldsBox->GetString( i ) ); + } + + + // Undo buffer entry + if( m_createUndo ) + { + PICKED_ITEMS_LIST itemsList; + + for( auto component : m_components ) + itemsList.PushItem( ITEM_PICKER( component, UR_CHANGED ) ); + + m_frame->SaveCopyInUndoList( itemsList, UR_CHANGED ); + } + + + // Do it! + for( auto component : m_components ) + updateFields( component ); + + m_frame->OnModify(); + + return true; +} + + +bool DIALOG_UPDATE_FIELDS::TransferDataToWindow() +{ + if( !wxDialog::TransferDataToWindow() ) + return false; + + // Collect all field names from library parts of components that are going to be updated + { + for( auto component : m_components ) + { + const auto part = component->GetPartRef().lock(); + + if( !part ) + continue; + + const auto& drawItems = part->GetDrawItems(); + + for( auto it = drawItems.begin( LIB_FIELD_T ); it != drawItems.end( LIB_FIELD_T ); ++it ) + { + const LIB_FIELD* field = static_cast( &( *it ) ); + m_fields.insert( field->GetName( false ) ); + } + } + } + + // Update the listbox widget + m_fieldsBox->Clear(); + + for( const auto& field : m_fields ) + { + int idx = m_fieldsBox->Append( field ); + + if( field != "Reference" && field != "Value" ) + m_fieldsBox->Check( idx, true ); + } + + return true; +} + + +void DIALOG_UPDATE_FIELDS::updateFields( SCH_COMPONENT* aComponent ) +{ + std::vector oldFields; + SCH_FIELDS newFields; + + PART_SPTR libPart = aComponent->GetPartRef().lock(); + aComponent->GetFields( oldFields, false ); + + 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() ) ) + newFields.push_back( *compField ); + } + + // Update the requested field values + for( const auto& partField : m_fields ) + { + LIB_FIELD* libField = libPart->FindField( partField ); + + if( !libField ) + continue; + + SCH_FIELD* field = nullptr; + auto it = std::find_if( newFields.begin(), newFields.end(), [&] ( const SCH_FIELD& f ) + { return f.GetName() == partField; } ); + + if( it != newFields.end() ) + { + field = &*it; + } + else + { + // Missing field, it has to be added to the component + SCH_FIELD f( wxPoint( 0, 0 ), newFields.size(), aComponent, partField ); + newFields.push_back( f ); + field = &newFields.back(); + } + + field->SetText( libField->GetText() ); + } + + // Apply changes & clean-up + aComponent->SetFields( newFields ); +} + + +void DIALOG_UPDATE_FIELDS::checkAll( bool aCheck ) +{ + for( int i = 0; i < m_fieldsBox->GetCount(); ++i ) + m_fieldsBox->Check( i, aCheck ); +} diff --git a/eeschema/dialogs/dialog_update_fields.h b/eeschema/dialogs/dialog_update_fields.h new file mode 100644 index 0000000000..442f9e1226 --- /dev/null +++ b/eeschema/dialogs/dialog_update_fields.h @@ -0,0 +1,82 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2017 CERN + * @author Maciej Suminski + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 3 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * https://www.gnu.org/licenses/gpl-3.0.html + * or you may search the http://www.gnu.org website for the version 3 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef DIALOG_UPDATE_FIELDS_H +#define DIALOG_UPDATE_FIELDS_H + +#include "dialog_update_fields_base.h" + +#include +#include + +class SCH_COMPONENT; +class SCH_SCREEN; +class SCH_EDIT_FRAME; + +using std::set; +using std::list; + +/** + * Dialog to update component fields (i.e. restore them from the original library symbols). + */ +class DIALOG_UPDATE_FIELDS : public DIALOG_UPDATE_FIELDS_BASE +{ +public: + DIALOG_UPDATE_FIELDS( SCH_EDIT_FRAME* aParent, const list& aComponents, + bool aCreateUndoEntry = true ); + +private: + bool TransferDataFromWindow() override; + bool TransferDataToWindow() override; + + ///> Update fields for a single component + void updateFields( SCH_COMPONENT* aComponent ); + + ///> Selects or deselects all fields in the listbox widget + void checkAll( bool aCheck ); + + void onSelectAll( wxCommandEvent& event ) override + { + checkAll( true ); + } + + void onSelectNone( wxCommandEvent& event ) override + { + checkAll( false ); + } + + ///> Parent frame + SCH_EDIT_FRAME* m_frame; + + ///> Set of field names that should have values updated + set m_fields; + + ///> Components to update + list m_components; + + ///> Flag indicating whether an undo buffer entry should be created + bool m_createUndo; +}; + +#endif /* DIALOG_UPDATE_FIELDS_H */ diff --git a/eeschema/dialogs/dialog_update_fields_base.cpp b/eeschema/dialogs/dialog_update_fields_base.cpp new file mode 100644 index 0000000000..44c29f559b --- /dev/null +++ b/eeschema/dialogs/dialog_update_fields_base.cpp @@ -0,0 +1,73 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Oct 17 2016) +// http://www.wxformbuilder.org/ +// +// PLEASE DO "NOT" EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#include "dialog_update_fields_base.h" + +/////////////////////////////////////////////////////////////////////////// + +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 ); + + m_infoLabel = new wxStaticText( this, wxID_ANY, _("Select fields to update:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_infoLabel->Wrap( -1 ); + m_mainSizer->Add( m_infoLabel, 0, wxALL, 5 ); + + wxArrayString m_fieldsBoxChoices; + m_fieldsBox = new wxCheckListBox( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_fieldsBoxChoices, 0 ); + m_mainSizer->Add( m_fieldsBox, 1, wxALL|wxEXPAND, 5 ); + + wxBoxSizer* m_selBtnSizer; + m_selBtnSizer = new wxBoxSizer( wxHORIZONTAL ); + + m_selAllBtn = new wxButton( this, wxID_ANY, _("Select all"), wxDefaultPosition, wxDefaultSize, 0 ); + m_selBtnSizer->Add( m_selAllBtn, 1, wxALL|wxEXPAND, 5 ); + + m_selNoneBtn = new wxButton( this, wxID_ANY, _("Select none"), wxDefaultPosition, wxDefaultSize, 0 ); + m_selBtnSizer->Add( m_selNoneBtn, 1, wxALL|wxEXPAND, 5 ); + + + m_mainSizer->Add( m_selBtnSizer, 0, wxEXPAND, 5 ); + + m_removeExtraBox = new wxCheckBox( this, wxID_ANY, _("Remove extra fields"), wxDefaultPosition, wxDefaultSize, 0 ); + m_removeExtraBox->SetToolTip( _("Removes fields that do not occur in the original library symbols") ); + + m_mainSizer->Add( m_removeExtraBox, 0, wxALL, 5 ); + + m_staticline1 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); + m_mainSizer->Add( m_staticline1, 0, wxEXPAND | wxALL, 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, wxEXPAND, 5 ); + + + this->SetSizer( m_mainSizer ); + this->Layout(); + + 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 ); +} + +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 new file mode 100644 index 0000000000..3c4cedea19 --- /dev/null +++ b/eeschema/dialogs/dialog_update_fields_base.fbp @@ -0,0 +1,653 @@ + + + + + + C++ + 1 + source_name + 0 + 0 + res + UTF-8 + connect + dialog_update_fields_base + 1000 + none + 1 + dialog_update_fields_base + + . + + 1 + 1 + 1 + 1 + UI + 0 + 0 + + 0 + wxAUI_MGR_DEFAULT + + wxBOTH + + 1 + 1 + impl_virtual + + + + 0 + wxID_ANY + + + DIALOG_UPDATE_FIELDS_BASE + + 300,600 + wxDEFAULT_DIALOG_STYLE + DIALOG_SHIM; dialog_shim.h + Update symbol fields + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + m_mainSizer + wxVERTICAL + none + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Select fields to update: + + 0 + + + 0 + + 1 + m_infoLabel + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALL|wxEXPAND + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + m_fieldsBox + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxEXPAND + 0 + + + m_selBtnSizer + wxHORIZONTAL + none + + 5 + wxALL|wxEXPAND + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Select all + + 0 + + + 0 + + 1 + m_selAllBtn + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + onSelectAll + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALL|wxEXPAND + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Select none + + 0 + + + 0 + + 1 + m_selNoneBtn + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + onSelectNone + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Remove extra fields + + 0 + + + 0 + + 1 + m_removeExtraBox + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + Removes fields that do not occur in the original library symbols + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxEXPAND | wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + m_staticline1 + 1 + + + protected + 1 + + Resizable + 1 + + wxLI_HORIZONTAL + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxEXPAND + 0 + + 0 + 1 + 0 + 0 + 0 + 1 + 0 + 0 + + m_sdbSizer + protected + + + + + + + + + + + + + + diff --git a/eeschema/dialogs/dialog_update_fields_base.h b/eeschema/dialogs/dialog_update_fields_base.h new file mode 100644 index 0000000000..56fae95a99 --- /dev/null +++ b/eeschema/dialogs/dialog_update_fields_base.h @@ -0,0 +1,63 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Oct 17 2016) +// http://www.wxformbuilder.org/ +// +// PLEASE DO "NOT" EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#ifndef __DIALOG_UPDATE_FIELDS_BASE_H__ +#define __DIALOG_UPDATE_FIELDS_BASE_H__ + +#include +#include +#include +class DIALOG_SHIM; + +#include "dialog_shim.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +/// Class DIALOG_UPDATE_FIELDS_BASE +/////////////////////////////////////////////////////////////////////////////// +class DIALOG_UPDATE_FIELDS_BASE : public DIALOG_SHIM +{ + private: + + protected: + wxStaticText* m_infoLabel; + wxCheckListBox* m_fieldsBox; + wxButton* m_selAllBtn; + wxButton* m_selNoneBtn; + wxCheckBox* m_removeExtraBox; + wxStaticLine* m_staticline1; + 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( 300,600 ), long style = wxDEFAULT_DIALOG_STYLE ); + ~DIALOG_UPDATE_FIELDS_BASE(); + +}; + +#endif //__DIALOG_UPDATE_FIELDS_BASE_H__ diff --git a/eeschema/invoke_sch_dialog.h b/eeschema/invoke_sch_dialog.h index a2692a8da3..eafcb0d2f1 100644 --- a/eeschema/invoke_sch_dialog.h +++ b/eeschema/invoke_sch_dialog.h @@ -42,6 +42,7 @@ #include #include +#include class wxFrame; class wxDialog; @@ -83,13 +84,17 @@ int InvokeDialogCreateBOM( SCH_EDIT_FRAME* aCaller ); /// Create and show DIALOG_BOM_EDITOR void InvokeDialogCreateBOMEditor( SCH_EDIT_FRAME* aCaller ); +/// Update symbol fields +int InvokeDialogUpdateFields( SCH_EDIT_FRAME* aCaller, + const std::list aComponents, bool aCreateUndoEntry ); + /** * Function InvokeDialogNetList * creates and shows NETLIST_DIALOG and returns whatever * NETLIST_DIALOG::ShowModal() returns. * @param int - NET_PLUGIN_CHANGE means user added or deleted a plugin, * wxID_OK, or wxID_CANCEL. -*/ + */ #define NET_PLUGIN_CHANGE 1 int InvokeDialogNetList( SCH_EDIT_FRAME* aCaller ); diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index 8ee308f734..2d5624912d 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -1006,28 +1006,16 @@ void SCH_EDIT_FRAME::OnLoadCmpToFootprintLinkFile( wxCommandEvent& event ) void SCH_EDIT_FRAME::OnUpdateFields( wxCommandEvent& event ) { - PICKED_ITEMS_LIST itemsList; - SCH_TYPE_COLLECTOR c; - c.Collect( GetScreen()->GetDrawItems(), SCH_COLLECTOR::ComponentsOnly ); + std::list components; - // Create a single undo buffer entry for all components - for( int i = 0; i < c.GetCount(); ++i ) + for( SCH_ITEM* item = GetScreen()->GetDrawItems(); item; item = item->Next() ) { - SCH_COMPONENT* component = static_cast( c[i] ); - itemsList.PushItem( ITEM_PICKER( component, UR_CHANGED ) ); + if( item->Type() == SCH_COMPONENT_T ) + components.push_back( static_cast( item ) ); } - SaveCopyInUndoList( itemsList, UR_CHANGED ); - - // Update fields - for( int i = 0; i < c.GetCount(); ++i ) - { - SCH_COMPONENT* component = static_cast( c[i] ); - component->UpdateFields( false ); - } - - m_canvas->Refresh(); - DisplayInfoMessage( this, _( "Fields updated successfully" ) ); + if( InvokeDialogUpdateFields( this, components, true ) ) + m_canvas->Refresh(); }