← Back to team overview

kicad-developers team mailing list archive

[RFC] Update Fields in eeschema

 

The attached patches add to eeschema possibility of updating fields for
components already placed on schematics sheet using library values.

It is useful for users maintaining additional fields in libraries to
store information that may change over time (e.g. Obsolete, URL fields).

Regards,
Orson
From baa0ebd20f931dd37a7c0aceed530e9a488ae364 Mon Sep 17 00:00:00 2001
From: Maciej Suminski <maciej.suminski@xxxxxxx>
Date: Fri, 25 Aug 2017 13:37:21 +0200
Subject: [PATCH 1/3] Added 'Update Fields' button in schematic component
 properties

---
 .../dialogs/dialog_edit_component_in_schematic.cpp | 49 ++++++++++-
 .../dialog_edit_component_in_schematic_fbp.cpp     | 19 +++--
 .../dialog_edit_component_in_schematic_fbp.fbp     | 96 +++++++++++++++++++++-
 .../dialog_edit_component_in_schematic_fbp.h       |  8 +-
 4 files changed, 155 insertions(+), 17 deletions(-)

diff --git a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp
index 505b4a90e..ebc2751a6 100644
--- a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp
+++ b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp
@@ -45,6 +45,7 @@
 #include <sch_component.h>
 #include <dialog_helpers.h>
 #include <sch_validators.h>
+#include <kicad_device_context.h>
 
 #include <dialog_edit_component_in_schematic_fbp.h>
 #ifdef KICAD_SPICE
@@ -127,6 +128,7 @@ private:
     void OnCancelButtonClick( wxCommandEvent& event ) override;
     void OnOKButtonClick( wxCommandEvent& event ) override;
     void SetInitCmp( wxCommandEvent& event ) override;
+    void UpdateFields( wxCommandEvent& event ) override;
     void addFieldButtonHandler( wxCommandEvent& event ) override;
     void deleteFieldButtonHandler( wxCommandEvent& event ) override;
     void moveUpButtonHandler( wxCommandEvent& event ) override;
@@ -152,7 +154,7 @@ private:
      */
     void updateDisplay()
     {
-        for( unsigned ii = FIELD1;  ii<m_FieldsBuf.size(); ii++ )
+        for( unsigned ii = 0; ii < m_FieldsBuf.size(); ii++ )
             setRowItem( ii, m_FieldsBuf[ii] );
     }
 };
@@ -1104,9 +1106,6 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyOptionsToPanel()
 }
 
 
-#include <kicad_device_context.h>
-
-
 void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::SetInitCmp( wxCommandEvent& event )
 {
     if( !m_cmp )
@@ -1160,3 +1159,45 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::SetInitCmp( wxCommandEvent& event )
         EndQuasiModal( wxID_OK );
     }
 }
+
+
+void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::UpdateFields( wxCommandEvent& event )
+{
+    if( !m_cmp )
+        return;
+
+    LIB_PART* part = Prj().SchLibs()->FindLibPart( m_cmp->GetLibId() );
+
+    if( !part )
+        return;
+
+    LIB_FIELDS fields;
+    part->GetFields( fields );
+
+    for( const LIB_FIELD& field : fields )
+    {
+        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() );
+    }
+
+    updateDisplay();
+}
diff --git a/eeschema/dialogs/dialog_edit_component_in_schematic_fbp.cpp b/eeschema/dialogs/dialog_edit_component_in_schematic_fbp.cpp
index 08af0ec4c..3c34e269b 100644
--- a/eeschema/dialogs/dialog_edit_component_in_schematic_fbp.cpp
+++ b/eeschema/dialogs/dialog_edit_component_in_schematic_fbp.cpp
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////
-// C++ code generated with wxFormBuilder (version Feb 19 2017)
+// C++ code generated with wxFormBuilder (version Oct 17 2016)
 // http://www.wxformbuilder.org/
 //
 // PLEASE DO "NOT" EDIT THIS FILE!
@@ -104,10 +104,15 @@ DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP(
 	spiceFieldsButton = new wxButton( optionsSizer->GetStaticBox(), wxID_ANY, _("Edit Spice Model"), wxDefaultPosition, wxDefaultSize, 0 );
 	optionsSizer->Add( spiceFieldsButton, 0, wxALL|wxEXPAND, 5 );
 	
-	defaultsButton = new wxButton( optionsSizer->GetStaticBox(), wxID_ANY, _("Reset to Default"), wxDefaultPosition, wxDefaultSize, 0 );
-	defaultsButton->SetToolTip( _("Set position and style of fields and component orientation  to default lib value.\nFields texts are not modified.") );
+	resetFieldsStyleButton = new wxButton( optionsSizer->GetStaticBox(), wxID_ANY, _("Reset Field Properties"), wxDefaultPosition, wxDefaultSize, 0 );
+	resetFieldsStyleButton->SetToolTip( _("Set position and style of fields and component orientation to default library value.\nField values are not modified.") );
 	
-	optionsSizer->Add( defaultsButton, 0, wxALL|wxEXPAND, 5 );
+	optionsSizer->Add( resetFieldsStyleButton, 0, wxALL|wxEXPAND, 5 );
+	
+	updateFieldValues = new wxButton( optionsSizer->GetStaticBox(), wxID_ANY, _("Update Field Values"), wxDefaultPosition, wxDefaultSize, 0 );
+	updateFieldValues->SetToolTip( _("Sets fields to the original library values") );
+	
+	optionsSizer->Add( updateFieldValues, 0, wxALL|wxEXPAND, 5 );
 	
 	
 	upperSizer->Add( optionsSizer, 0, wxEXPAND|wxALL, 5 );
@@ -295,7 +300,8 @@ DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP(
 	m_buttonTestChipName->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::OnTestChipName ), NULL, this );
 	m_buttonSelectChipName->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::OnSelectChipName ), NULL, this );
 	spiceFieldsButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::EditSpiceModel ), NULL, this );
-	defaultsButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::SetInitCmp ), NULL, this );
+	resetFieldsStyleButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::SetInitCmp ), NULL, this );
+	updateFieldValues->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::UpdateFields ), NULL, this );
 	fieldListCtrl->Connect( wxEVT_COMMAND_LIST_ITEM_DESELECTED, wxListEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::OnListItemDeselected ), NULL, this );
 	fieldListCtrl->Connect( wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::OnListItemSelected ), NULL, this );
 	addFieldButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::addFieldButtonHandler ), NULL, this );
@@ -314,7 +320,8 @@ DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::~DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP(
 	m_buttonTestChipName->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::OnTestChipName ), NULL, this );
 	m_buttonSelectChipName->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::OnSelectChipName ), NULL, this );
 	spiceFieldsButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::EditSpiceModel ), NULL, this );
-	defaultsButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::SetInitCmp ), NULL, this );
+	resetFieldsStyleButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::SetInitCmp ), NULL, this );
+	updateFieldValues->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::UpdateFields ), NULL, this );
 	fieldListCtrl->Disconnect( wxEVT_COMMAND_LIST_ITEM_DESELECTED, wxListEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::OnListItemDeselected ), NULL, this );
 	fieldListCtrl->Disconnect( wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::OnListItemSelected ), NULL, this );
 	addFieldButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::addFieldButtonHandler ), NULL, this );
diff --git a/eeschema/dialogs/dialog_edit_component_in_schematic_fbp.fbp b/eeschema/dialogs/dialog_edit_component_in_schematic_fbp.fbp
index 6c1d9b273..79aae80d9 100644
--- a/eeschema/dialogs/dialog_edit_component_in_schematic_fbp.fbp
+++ b/eeschema/dialogs/dialog_edit_component_in_schematic_fbp.fbp
@@ -44,7 +44,7 @@
             <property name="minimum_size"></property>
             <property name="name">DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP</property>
             <property name="pos"></property>
-            <property name="size">928,741</property>
+            <property name="size">928,794</property>
             <property name="style">wxCAPTION|wxCLOSE_BOX|wxDEFAULT_DIALOG_STYLE|wxMAXIMIZE_BOX|wxMINIMIZE_BOX|wxRESIZE_BORDER|wxSYSTEM_MENU</property>
             <property name="subclass">DIALOG_SHIM; dialog_shim.h</property>
             <property name="title">Component Properties</property>
@@ -1400,7 +1400,7 @@
                                         <property name="gripper">0</property>
                                         <property name="hidden">0</property>
                                         <property name="id">wxID_ANY</property>
-                                        <property name="label">Reset to Default</property>
+                                        <property name="label">Reset Field Properties</property>
                                         <property name="max_size"></property>
                                         <property name="maximize_button">0</property>
                                         <property name="maximum_size"></property>
@@ -1408,7 +1408,7 @@
                                         <property name="minimize_button">0</property>
                                         <property name="minimum_size"></property>
                                         <property name="moveable">1</property>
-                                        <property name="name">defaultsButton</property>
+                                        <property name="name">resetFieldsStyleButton</property>
                                         <property name="pane_border">1</property>
                                         <property name="pane_position"></property>
                                         <property name="pane_size"></property>
@@ -1421,7 +1421,7 @@
                                         <property name="style"></property>
                                         <property name="subclass"></property>
                                         <property name="toolbar_pane">0</property>
-                                        <property name="tooltip">Set position and style of fields and component orientation  to default lib value.&#x0A;Fields texts are not modified.</property>
+                                        <property name="tooltip">Set position and style of fields and component orientation to default library value.&#x0A;Field values are not modified.</property>
                                         <property name="validator_data_type"></property>
                                         <property name="validator_style">wxFILTER_NONE</property>
                                         <property name="validator_type">wxDefaultValidator</property>
@@ -1455,6 +1455,94 @@
                                         <event name="OnUpdateUI"></event>
                                     </object>
                                 </object>
+                                <object class="sizeritem" expanded="1">
+                                    <property name="border">5</property>
+                                    <property name="flag">wxALL|wxEXPAND</property>
+                                    <property name="proportion">0</property>
+                                    <object class="wxButton" expanded="1">
+                                        <property name="BottomDockable">1</property>
+                                        <property name="LeftDockable">1</property>
+                                        <property name="RightDockable">1</property>
+                                        <property name="TopDockable">1</property>
+                                        <property name="aui_layer"></property>
+                                        <property name="aui_name"></property>
+                                        <property name="aui_position"></property>
+                                        <property name="aui_row"></property>
+                                        <property name="best_size"></property>
+                                        <property name="bg"></property>
+                                        <property name="caption"></property>
+                                        <property name="caption_visible">1</property>
+                                        <property name="center_pane">0</property>
+                                        <property name="close_button">1</property>
+                                        <property name="context_help"></property>
+                                        <property name="context_menu">1</property>
+                                        <property name="default">0</property>
+                                        <property name="default_pane">0</property>
+                                        <property name="dock">Dock</property>
+                                        <property name="dock_fixed">0</property>
+                                        <property name="docking">Left</property>
+                                        <property name="enabled">1</property>
+                                        <property name="fg"></property>
+                                        <property name="floatable">1</property>
+                                        <property name="font"></property>
+                                        <property name="gripper">0</property>
+                                        <property name="hidden">0</property>
+                                        <property name="id">wxID_ANY</property>
+                                        <property name="label">Update Field Values</property>
+                                        <property name="max_size"></property>
+                                        <property name="maximize_button">0</property>
+                                        <property name="maximum_size"></property>
+                                        <property name="min_size"></property>
+                                        <property name="minimize_button">0</property>
+                                        <property name="minimum_size"></property>
+                                        <property name="moveable">1</property>
+                                        <property name="name">updateFieldValues</property>
+                                        <property name="pane_border">1</property>
+                                        <property name="pane_position"></property>
+                                        <property name="pane_size"></property>
+                                        <property name="permission">protected</property>
+                                        <property name="pin_button">1</property>
+                                        <property name="pos"></property>
+                                        <property name="resize">Resizable</property>
+                                        <property name="show">1</property>
+                                        <property name="size"></property>
+                                        <property name="style"></property>
+                                        <property name="subclass"></property>
+                                        <property name="toolbar_pane">0</property>
+                                        <property name="tooltip">Sets fields to the original library values</property>
+                                        <property name="validator_data_type"></property>
+                                        <property name="validator_style">wxFILTER_NONE</property>
+                                        <property name="validator_type">wxDefaultValidator</property>
+                                        <property name="validator_variable"></property>
+                                        <property name="window_extra_style"></property>
+                                        <property name="window_name"></property>
+                                        <property name="window_style"></property>
+                                        <event name="OnButtonClick">UpdateFields</event>
+                                        <event name="OnChar"></event>
+                                        <event name="OnEnterWindow"></event>
+                                        <event name="OnEraseBackground"></event>
+                                        <event name="OnKeyDown"></event>
+                                        <event name="OnKeyUp"></event>
+                                        <event name="OnKillFocus"></event>
+                                        <event name="OnLeaveWindow"></event>
+                                        <event name="OnLeftDClick"></event>
+                                        <event name="OnLeftDown"></event>
+                                        <event name="OnLeftUp"></event>
+                                        <event name="OnMiddleDClick"></event>
+                                        <event name="OnMiddleDown"></event>
+                                        <event name="OnMiddleUp"></event>
+                                        <event name="OnMotion"></event>
+                                        <event name="OnMouseEvents"></event>
+                                        <event name="OnMouseWheel"></event>
+                                        <event name="OnPaint"></event>
+                                        <event name="OnRightDClick"></event>
+                                        <event name="OnRightDown"></event>
+                                        <event name="OnRightUp"></event>
+                                        <event name="OnSetFocus"></event>
+                                        <event name="OnSize"></event>
+                                        <event name="OnUpdateUI"></event>
+                                    </object>
+                                </object>
                             </object>
                         </object>
                         <object class="sizeritem" expanded="1">
diff --git a/eeschema/dialogs/dialog_edit_component_in_schematic_fbp.h b/eeschema/dialogs/dialog_edit_component_in_schematic_fbp.h
index ce223ac79..60abd929c 100644
--- a/eeschema/dialogs/dialog_edit_component_in_schematic_fbp.h
+++ b/eeschema/dialogs/dialog_edit_component_in_schematic_fbp.h
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////
-// C++ code generated with wxFormBuilder (version Feb 19 2017)
+// C++ code generated with wxFormBuilder (version Oct 17 2016)
 // http://www.wxformbuilder.org/
 //
 // PLEASE DO "NOT" EDIT THIS FILE!
@@ -56,7 +56,8 @@ class DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP : public DIALOG_SHIM
 		wxTextCtrl* m_textCtrlTimeStamp;
 		wxStaticLine* m_staticline1;
 		wxButton* spiceFieldsButton;
-		wxButton* defaultsButton;
+		wxButton* resetFieldsStyleButton;
+		wxButton* updateFieldValues;
 		wxListCtrl* fieldListCtrl;
 		wxButton* addFieldButton;
 		wxButton* deleteFieldButton;
@@ -91,6 +92,7 @@ class DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP : public DIALOG_SHIM
 		virtual void OnSelectChipName( wxCommandEvent& event ) { event.Skip(); }
 		virtual void EditSpiceModel( wxCommandEvent& event ) { event.Skip(); }
 		virtual void SetInitCmp( wxCommandEvent& event ) { event.Skip(); }
+		virtual void UpdateFields( wxCommandEvent& event ) { event.Skip(); }
 		virtual void OnListItemDeselected( wxListEvent& event ) { event.Skip(); }
 		virtual void OnListItemSelected( wxListEvent& event ) { event.Skip(); }
 		virtual void addFieldButtonHandler( wxCommandEvent& event ) { event.Skip(); }
@@ -103,7 +105,7 @@ class DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP : public DIALOG_SHIM
 	
 	public:
 		
-		DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Component Properties"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 928,741 ), long style = wxCAPTION|wxCLOSE_BOX|wxDEFAULT_DIALOG_STYLE|wxMAXIMIZE_BOX|wxMINIMIZE_BOX|wxRESIZE_BORDER|wxSYSTEM_MENU ); 
+		DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Component Properties"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 928,794 ), long style = wxCAPTION|wxCLOSE_BOX|wxDEFAULT_DIALOG_STYLE|wxMAXIMIZE_BOX|wxMINIMIZE_BOX|wxRESIZE_BORDER|wxSYSTEM_MENU ); 
 		~DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP();
 	
 };
-- 
2.13.3

From 776de2365a13365b5043c087cfc743a2dd94814a Mon Sep 17 00:00:00 2001
From: Maciej Suminski <maciej.suminski@xxxxxxx>
Date: Fri, 25 Aug 2017 15:26:35 +0200
Subject: [PATCH 2/3] 'Update Fields' icon for eeschema

---
 bitmaps_png/CMakeLists.txt            |   3 +-
 bitmaps_png/cpp_26/update_fields.cpp  |  66 ++++++++++++++++
 bitmaps_png/sources/update_fields.svg | 145 ++++++++++++++++++++++++++++++++++
 include/bitmaps.h                     |   3 +-
 4 files changed, 215 insertions(+), 2 deletions(-)
 create mode 100644 bitmaps_png/cpp_26/update_fields.cpp
 create mode 100644 bitmaps_png/sources/update_fields.svg

diff --git a/bitmaps_png/CMakeLists.txt b/bitmaps_png/CMakeLists.txt
index 40003dccc..03406fe88 100644
--- a/bitmaps_png/CMakeLists.txt
+++ b/bitmaps_png/CMakeLists.txt
@@ -509,8 +509,9 @@ set( BMAPS_MID
     unknown
     unlocked
     unzip
-    update_module_board
     up
+    update_fields
+    update_module_board
     use_3D_copper_thickness
     via
     via_buried
diff --git a/bitmaps_png/cpp_26/update_fields.cpp b/bitmaps_png/cpp_26/update_fields.cpp
new file mode 100644
index 000000000..e0118a697
--- /dev/null
+++ b/bitmaps_png/cpp_26/update_fields.cpp
@@ -0,0 +1,66 @@
+
+/* Do not modify this file, it was automatically generated by the
+ * PNG2cpp CMake script, using a *.png file as input.
+ */
+
+#include <bitmaps.h>
+
+static const unsigned char png[] = {
+ 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,
+ 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x1a, 0x08, 0x06, 0x00, 0x00, 0x00, 0xa9, 0x4a, 0x4c,
+ 0xce, 0x00, 0x00, 0x03, 0x16, 0x49, 0x44, 0x41, 0x54, 0x48, 0xc7, 0xed, 0x95, 0x5f, 0x48, 0xd3,
+ 0x51, 0x14, 0xc7, 0xaf, 0xb8, 0xad, 0x51, 0x18, 0xb8, 0x17, 0x07, 0x7b, 0x52, 0x7c, 0x09, 0x21,
+ 0x85, 0x1e, 0xa6, 0xa0, 0x88, 0x9a, 0x13, 0x6d, 0x5b, 0x8e, 0xe9, 0xda, 0x9c, 0x89, 0x82, 0x06,
+ 0x09, 0x42, 0x60, 0xa6, 0xa6, 0xae, 0x6d, 0x51, 0x4e, 0x47, 0x2f, 0x8d, 0x08, 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, 0x69, 0x3a, 0xc5, 0x67, 0x6e, 0xcc, 0x1a,
+ 0x18, 0xc9, 0x15, 0x04, 0x5c, 0x46, 0x5d, 0x4c, 0x94, 0xf6, 0x1b, 0x0a, 0x32, 0x84, 0xd2, 0xe0,
+ 0x74, 0x5b, 0xa4, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82,
+};
+
+const BITMAP_OPAQUE update_fields_xpm[1] = {{ png, sizeof( png ), "update_fields_xpm" }};
+
+//EOF
diff --git a/bitmaps_png/sources/update_fields.svg b/bitmaps_png/sources/update_fields.svg
new file mode 100644
index 000000000..e7b8faa43
--- /dev/null
+++ b/bitmaps_png/sources/update_fields.svg
@@ -0,0 +1,145 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/";
+   xmlns:cc="http://creativecommons.org/ns#";
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
+   xmlns:svg="http://www.w3.org/2000/svg";
+   xmlns="http://www.w3.org/2000/svg";
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd";
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape";
+   height="26"
+   width="26"
+   version="1.1"
+   viewBox="0 0 26 26"
+   id="svg2"
+   inkscape:version="0.92.1 r"
+   sodipodi:docname="update_fields.svg">
+  <metadata
+     id="metadata151">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage"; />
+        <dc:title />
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <sodipodi:namedview
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1"
+     objecttolerance="10"
+     gridtolerance="10"
+     guidetolerance="10"
+     inkscape:pageopacity="0"
+     inkscape:pageshadow="2"
+     inkscape:window-width="1916"
+     inkscape:window-height="1176"
+     id="namedview149"
+     showgrid="true"
+     inkscape:zoom="27.812867"
+     inkscape:cx="17.092131"
+     inkscape:cy="17.188066"
+     inkscape:window-x="1920"
+     inkscape:window-y="20"
+     inkscape:window-maximized="1"
+     inkscape:current-layer="g4537"
+     borderlayer="true">
+    <inkscape:grid
+       type="xygrid"
+       id="grid4178" />
+  </sodipodi:namedview>
+  <defs
+     id="defs4" />
+  <rect
+     style="opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#4d4d4d;stroke-width:1.77155519;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+     id="rect4191"
+     width="20.3389"
+     height="11.340246"
+     x="3.3049667"
+     y="7.2907038" />
+  <rect
+     style="opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#ffffff;stroke-width:1.09166384;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+     id="rect4208"
+     width="2.901608"
+     height="0.92410576"
+     x="17.543579"
+     y="18.045984" />
+  <rect
+     style="opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#ffffff;stroke-width:1.09166384;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+     id="rect4208-3"
+     width="2.901608"
+     height="0.92410576"
+     x="17.545834"
+     y="6.9249034" />
+  <path
+     style="fill:#808080;fill-rule:evenodd;stroke:#4d4d4d;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+     d="m 15.889145,3.9765383 6.252697,0"
+     id="path4193"
+     inkscape:connector-curvature="0" />
+  <path
+     style="fill:#808080;fill-rule:evenodd;stroke:#4d4d4d;stroke-width:1.89452231;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+     d="m 19.014689,3.9749505 0,18.7918925"
+     id="path4197"
+     inkscape:connector-curvature="0" />
+  <text
+     xml:space="preserve"
+     style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#4d4d4d;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+     x="4.5411229"
+     y="18.466211"
+     id="text4199"
+     transform="scale(1.0868095,0.92012444)"><tspan
+       sodipodi:role="line"
+       id="tspan4201"
+       x="4.5411229"
+       y="18.466211"
+       style="font-weight:bold;font-size:11.97656155px;line-height:1.25;fill:#4d4d4d">A</tspan></text>
+  <path
+     style="fill:#808080;fill-rule:evenodd;stroke:#4d4d4d;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+     d="m 15.804649,22.003992 6.252697,0"
+     id="path4193-6"
+     inkscape:connector-curvature="0" />
+  <g
+     id="g4537"
+     transform="matrix(0.73019635,0,0,0.73019635,-11.268378,4.4657371)">
+    <path
+       sodipodi:open="true"
+       sodipodi:end="0.18020189"
+       sodipodi:start="4.2559549"
+       d="m 35.974404,11.818961 a 8,8 0 0 1 8.350164,0.799233 8,8 0 0 1 3.046297,7.815632"
+       sodipodi:ry="8"
+       sodipodi:rx="8"
+       sodipodi:cy="19"
+       sodipodi:cx="39.500404"
+       id="path2989"
+       style="display:inline;fill:none;stroke:#008000;stroke-width:2.95172179;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+       sodipodi:type="arc" />
+    <path
+       sodipodi:nodetypes="cccc"
+       inkscape:connector-curvature="0"
+       id="path3768"
+       d="m 47,26 -3.2,-8 h 7 z"
+       style="display:inline;fill:#008000;stroke:none" />
+    <path
+       transform="scale(-1)"
+       sodipodi:open="true"
+       sodipodi:end="0.18020189"
+       sodipodi:start="4.2559549"
+       d="m -43.525596,-26.181037 a 8,8 0 0 1 8.350164,0.799233 8,8 0 0 1 3.046297,7.815631"
+       sodipodi:ry="8"
+       sodipodi:rx="8"
+       sodipodi:cy="-18.999998"
+       sodipodi:cx="-39.999596"
+       id="path2989-5"
+       style="display:inline;fill:none;stroke:#008000;stroke-width:2.95172179;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+       sodipodi:type="arc" />
+    <path
+       sodipodi:nodetypes="cccc"
+       inkscape:connector-curvature="0"
+       id="path3768-9"
+       d="m 32.500001,11.999999 3.2,8 h -7 z"
+       style="display:inline;fill:#008000;stroke:none" />
+  </g>
+</svg>
diff --git a/include/bitmaps.h b/include/bitmaps.h
index 14a7dffc3..5d65a0b99 100644
--- a/include/bitmaps.h
+++ b/include/bitmaps.h
@@ -472,8 +472,9 @@ EXTERN_BITMAP( unit_mm_xpm )
 EXTERN_BITMAP( unknown_xpm )
 EXTERN_BITMAP( unlocked_xpm )
 EXTERN_BITMAP( unzip_xpm )
-EXTERN_BITMAP( update_module_board_xpm )
 EXTERN_BITMAP( up_xpm )
+EXTERN_BITMAP( update_fields_xpm )
+EXTERN_BITMAP( update_module_board_xpm )
 EXTERN_BITMAP( use_3D_copper_thickness_xpm )
 EXTERN_BITMAP( via_xpm )
 EXTERN_BITMAP( via_microvia_xpm )
-- 
2.13.3

From 5a49fd4514b579ecc1de475ac941f101d070b5ab Mon Sep 17 00:00:00 2001
From: Maciej Suminski <maciej.suminski@xxxxxxx>
Date: Fri, 25 Aug 2017 15:27:06 +0200
Subject: [PATCH 3/3] 'Update Field Values' tool for eeschema

---
 eeschema/eeschema_id.h     |  1 +
 eeschema/menubar.cpp       |  6 ++++
 eeschema/sch_component.cpp | 86 ++++++++++++++++++++++++++--------------------
 eeschema/sch_component.h   |  7 ++++
 eeschema/schframe.cpp      | 28 +++++++++++++++
 eeschema/schframe.h        |  1 +
 6 files changed, 92 insertions(+), 37 deletions(-)

diff --git a/eeschema/eeschema_id.h b/eeschema/eeschema_id.h
index f68d5edae..1c66cb7b1 100644
--- a/eeschema/eeschema_id.h
+++ b/eeschema/eeschema_id.h
@@ -71,6 +71,7 @@ enum id_eeschema_frm
     ID_GET_ANNOTATE,
     ID_GET_ERC,
     ID_BACKANNO_ITEMS,
+    ID_UPDATE_FIELDS,
     ID_GEN_PLOT_SCHEMATIC,
 
     /* Schematic editor veritcal toolbar IDs */
diff --git a/eeschema/menubar.cpp b/eeschema/menubar.cpp
index 1ead98328..f42e16376 100644
--- a/eeschema/menubar.cpp
+++ b/eeschema/menubar.cpp
@@ -443,6 +443,12 @@ void prepareEditMenu( wxMenu* aParentMenu )
                  _( "Import Footprint Association File" ),
                  HELP_IMPORT_FOOTPRINTS,
                  KiBitmap( import_footprint_names_xpm ) );
+
+    // Update field values
+    AddMenuItem( aParentMenu, ID_UPDATE_FIELDS,
+                 _( "Update Field Values" ),
+                 _( "Sets component fields to original library values" ),
+                 KiBitmap( update_fields_xpm ) );
 }
 
 
diff --git a/eeschema/sch_component.cpp b/eeschema/sch_component.cpp
index 77ff9477c..e03b077f0 100644
--- a/eeschema/sch_component.cpp
+++ b/eeschema/sch_component.cpp
@@ -143,43 +143,8 @@ SCH_COMPONENT::SCH_COMPONENT( LIB_PART& aPart, SCH_SHEET_PATH* sheet, int unit,
     if( setNewItemFlag )
         m_Flags = IS_NEW | IS_MOVED;
 
-    // Import user defined fields from the library component:
-    LIB_FIELDS libFields;
-
-    aPart.GetFields( libFields );
-
-    for( LIB_FIELDS::iterator it = libFields.begin();  it!=libFields.end();  ++it )
-    {
-        // Can no longer insert an empty name, since names are now keys.  The
-        // field index is not used beyond the first MANDATORY_FIELDS
-        if( it->GetName().IsEmpty() )
-            continue;
-
-        // See if field already exists (mandatory fields always exist).
-        // for mandatory fields, the name and field id are fixed, so we use the
-        // known and fixed id to get them (more reliable than names, which can be translated)
-        // for other fields (custom fields), locate the field by same name
-        // (field id has no known meaning for custom fields)
-        int idx = it->GetId();
-        SCH_FIELD* schField;
-
-        if( idx < MANDATORY_FIELDS )
-            schField = GetField( idx );
-        else
-            schField = FindField( it->GetName() );
-
-        if( !schField )
-        {
-            SCH_FIELD fld( wxPoint( 0, 0 ), GetFieldCount(), this, it->GetName() );
-            schField = AddField( fld );
-        }
-
-        schField->ImportValues( *it );
-        schField->SetText( it->GetText() );
-
-        // Now the field is initialized, place it to the right position:
-        schField->SetTextPos( m_Pos + it->GetTextPos() );
-    }
+    // Import user defined fields from the library component
+    UpdateFields( true, true );
 
     wxString msg = aPart.GetReferenceField().GetText();
 
@@ -885,6 +850,53 @@ SCH_FIELD* SCH_COMPONENT::FindField( const wxString& aFieldName, bool aIncludeDe
 }
 
 
+void SCH_COMPONENT::UpdateFields( bool aResetStyle, bool aResetRef )
+{
+    if( PART_SPTR part = m_part.lock() )
+    {
+        LIB_FIELDS fields;
+        part->GetFields( fields );
+
+        for( const LIB_FIELD& field : fields )
+        {
+            // Can no longer insert an empty name, since names are now keys.  The
+            // field index is not used beyond the first MANDATORY_FIELDS
+            if( field.GetName().IsEmpty() )
+                continue;
+
+            // See if field already exists (mandatory fields always exist).
+            // for mandatory fields, the name and field id are fixed, so we use the
+            // known and fixed id to get them (more reliable than names, which can be translated)
+            // for other fields (custom fields), locate the field by same name
+            // (field id has no known meaning for custom fields)
+            int idx = field.GetId();
+            SCH_FIELD* schField;
+
+            if( idx == REFERENCE && !aResetRef )
+                continue;
+            if( idx < MANDATORY_FIELDS )
+                schField = GetField( idx );
+            else
+                schField = FindField( field.GetName() );
+
+            if( !schField )
+            {
+                SCH_FIELD fld( wxPoint( 0, 0 ), GetFieldCount(), this, field.GetName() );
+                schField = AddField( fld );
+            }
+
+            if( aResetStyle )
+            {
+                schField->ImportValues( field );
+                schField->SetTextPos( m_Pos + field.GetTextPos() );
+            }
+
+            schField->SetText( field.GetText() );
+        }
+    }
+}
+
+
 LIB_PIN* SCH_COMPONENT::GetPin( const wxString& number )
 {
     if( PART_SPTR part = m_part.lock() )
diff --git a/eeschema/sch_component.h b/eeschema/sch_component.h
index 2d6d047f6..82f0bc1b3 100644
--- a/eeschema/sch_component.h
+++ b/eeschema/sch_component.h
@@ -364,6 +364,13 @@ public:
     }
 
     /**
+     * Restores fields to the original library values.
+     * @param aResetStyle selects whether fields should reset the position and text attribute.
+     * @param aResetRef selects whether the reference field should be restored.
+     */
+    void UpdateFields( bool aResetStyle, bool aResetRef = false );
+
+    /**
      * Return the number of fields in this symbol.
      */
     int GetFieldCount() const { return (int)m_Fields.size(); }
diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp
index 0681b9e72..5a0f89b81 100644
--- a/eeschema/schframe.cpp
+++ b/eeschema/schframe.cpp
@@ -271,6 +271,7 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME )
     EVT_TOOL( ID_FIND_ITEMS, SCH_EDIT_FRAME::OnFindItems )
     EVT_TOOL( wxID_REPLACE, SCH_EDIT_FRAME::OnFindItems )
     EVT_TOOL( ID_BACKANNO_ITEMS, SCH_EDIT_FRAME::OnLoadCmpToFootprintLinkFile )
+    EVT_TOOL( ID_UPDATE_FIELDS, SCH_EDIT_FRAME::OnUpdateFields )
     EVT_TOOL( ID_SCH_MOVE_ITEM, SCH_EDIT_FRAME::OnMoveItem )
     EVT_TOOL( ID_AUTOPLACE_FIELDS, SCH_EDIT_FRAME::OnAutoplaceFields )
     EVT_MENU( wxID_HELP, EDA_DRAW_FRAME::GetKicadHelp )
@@ -1002,6 +1003,33 @@ 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 );
+
+    // Create a single undo buffer entry for all components
+    for( int i = 0; i < c.GetCount(); ++i )
+    {
+        SCH_COMPONENT* component = static_cast<SCH_COMPONENT*>( c[i] );
+        itemsList.PushItem( ITEM_PICKER( component, UR_CHANGED ) );
+    }
+
+    SaveCopyInUndoList( itemsList, UR_CHANGED );
+
+    // Update fields
+    for( int i = 0; i < c.GetCount(); ++i )
+    {
+        SCH_COMPONENT* component = static_cast<SCH_COMPONENT*>( c[i] );
+        component->UpdateFields( false );
+    }
+
+    m_canvas->Refresh();
+    DisplayInfoMessage( this, _( "Fields updated successfully" ) );
+}
+
+
 void SCH_EDIT_FRAME::OnNewProject( wxCommandEvent& event )
 {
 //  wxString pro_dir = wxPathOnly( Prj().GetProjectFullName() );
diff --git a/eeschema/schframe.h b/eeschema/schframe.h
index 4bc932901..586c60e9c 100644
--- a/eeschema/schframe.h
+++ b/eeschema/schframe.h
@@ -857,6 +857,7 @@ private:
 
     void OnLoadFile( wxCommandEvent& event );
     void OnLoadCmpToFootprintLinkFile( wxCommandEvent& event );
+    void OnUpdateFields( wxCommandEvent& event );
     void OnNewProject( wxCommandEvent& event );
     void OnLoadProject( wxCommandEvent& event );
     void OnAppendProject( wxCommandEvent& event );
-- 
2.13.3

Attachment: signature.asc
Description: OpenPGP digital signature


Follow ups