From d90ac8299d8082a44771502090144cce763e3560 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 25 Aug 2017 13:37:21 +0200 Subject: [PATCH 1/4] Added 'Update Fields' button in schematic component properties --- .../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 ad4f8dc905..6d9954ce5f 100644 --- a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include @@ -126,6 +127,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 - - void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::SetInitCmp( wxCommandEvent& event ) { if( !m_cmp ) @@ -1204,3 +1203,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 c6e399218d..11fe11994b 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 Mar 22 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 ); @@ -309,7 +314,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 ); moveUpButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::moveUpButtonHandler ), NULL, this ); @@ -329,7 +335,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 ); moveUpButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP::moveUpButtonHandler ), 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 20b2332076..192425a9eb 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 @@ DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP - 928,741 + 928,794 wxCAPTION|wxCLOSE_BOX|wxDEFAULT_DIALOG_STYLE|wxMAXIMIZE_BOX|wxMINIMIZE_BOX|wxRESIZE_BORDER|wxSYSTEM_MENU DIALOG_SHIM; dialog_shim.h Component Properties @@ -1400,7 +1400,7 @@ 0 0 wxID_ANY - Reset to Default + Reset Field Properties 0 @@ -1408,7 +1408,7 @@ 0 1 - defaultsButton + resetFieldsStyleButton 1 @@ -1421,7 +1421,7 @@ 0 - Set position and style of fields and component orientation to default lib value. Fields texts are not modified. + Set position and style of fields and component orientation to default library value. Field values are not modified. wxFILTER_NONE wxDefaultValidator @@ -1455,6 +1455,94 @@ + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Update Field Values + + 0 + + + 0 + + 1 + updateFieldValues + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + Sets fields to the original library values + + wxFILTER_NONE + wxDefaultValidator + + + + + UpdateFields + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/eeschema/dialogs/dialog_edit_component_in_schematic_fbp.h b/eeschema/dialogs/dialog_edit_component_in_schematic_fbp.h index b449d2b4ba..52f461349d 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 Mar 22 2017) +// C++ code generated with wxFormBuilder (version Oct 17 2016) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! @@ -60,7 +60,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; wxBitmapButton* moveUpButton; wxBitmapButton* moveDownButton; @@ -96,6 +97,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 moveUpButtonHandler( wxCommandEvent& event ) { event.Skip(); } @@ -109,7 +111,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(); }; From 78c285b83a92439583e3e10aa976c829fba0e41b Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 25 Aug 2017 15:26:35 +0200 Subject: [PATCH 2/4] '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 6543a8ed91..7e882336cd 100644 --- a/bitmaps_png/CMakeLists.txt +++ b/bitmaps_png/CMakeLists.txt @@ -514,8 +514,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 0000000000..e0118a697b --- /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 + +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, 0x89, 0xd0, 0xa0, + 0x27, 0x09, 0xd3, 0x02, 0x11, 0xda, 0x83, 0xd2, 0xec, 0x41, 0xf1, 0xc1, 0x31, 0x47, 0xa5, 0x83, + 0xa5, 0x90, 0x28, 0x73, 0xd0, 0x6c, 0x86, 0xec, 0xcf, 0xe9, 0xfc, 0x6e, 0xfa, 0x63, 0x9b, 0xdb, + 0x9a, 0x7f, 0xe8, 0xa9, 0x03, 0x5f, 0x76, 0x7e, 0x3b, 0xe7, 0x77, 0x3e, 0xbf, 0x7b, 0xef, 0xb9, + 0xf7, 0x12, 0xf2, 0xdf, 0xfe, 0xb5, 0x55, 0x57, 0x57, 0x9f, 0x93, 0xc9, 0x64, 0x2e, 0x14, 0x24, + 0xd0, 0x37, 0x89, 0x44, 0x72, 0xe1, 0xd4, 0xa0, 0xfa, 0xfa, 0x7a, 0x1e, 0x16, 0xb3, 0x27, 0x01, + 0x39, 0x50, 0xe7, 0xcf, 0x7c, 0x84, 0x58, 0x74, 0x07, 0xe5, 0x4f, 0x25, 0x51, 0x83, 0x1a, 0x39, + 0x89, 0x96, 0x97, 0x97, 0xbf, 0xaa, 0x54, 0xaa, 0x90, 0x42, 0xa1, 0x08, 0xa3, 0xff, 0x25, 0x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0x4c, 0x55, 0xc6, 0x16, 0x2f, 0x51, 0x97, 0x40, 0x5e, 0x6b, 0x1e, 0x48, 0x14, + 0x12, 0x66, 0x0b, 0xb8, 0xc9, 0x03, 0x6c, 0x83, 0x53, 0x58, 0x1a, 0x42, 0x2c, 0x31, 0x8b, 0xbd, + 0x8b, 0xda, 0x8b, 0x78, 0x1e, 0x22, 0x23, 0x84, 0x4b, 0x06, 0x49, 0xe6, 0xe9, 0xef, 0x6e, 0x3d, + 0xb9, 0x8a, 0x9a, 0x47, 0x05, 0x23, 0x00, 0xfb, 0xa8, 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 0000000000..e7b8faa436 --- /dev/null +++ b/bitmaps_png/sources/update_fields.svg @@ -0,0 +1,145 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + A + + + + + + + + diff --git a/include/bitmaps.h b/include/bitmaps.h index 2ebf7abdfd..800ec2d1a6 100644 --- a/include/bitmaps.h +++ b/include/bitmaps.h @@ -477,8 +477,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 ) From e29d77c8914ab59cebbb712294860cd34373e4e2 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 25 Aug 2017 15:27:06 +0200 Subject: [PATCH 3/4] '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 d42143c3ff..9317b23c12 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 62042250ce..056a8acb19 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 77ff9477c3..e03b077f00 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 2d6d047f69..82f0bc1b37 100644 --- a/eeschema/sch_component.h +++ b/eeschema/sch_component.h @@ -363,6 +363,13 @@ public: m_Fields = aFields; // vector copying, length is changed possibly } + /** + * 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. */ diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index 0378b2ef36..8ee308f734 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -272,6 +272,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 ) @@ -1003,6 +1004,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( 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( 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 ab07418ea2..c990fc2b0a 100644 --- a/eeschema/schframe.h +++ b/eeschema/schframe.h @@ -864,6 +864,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 ); From 85faa0e1018e64b45df7a9c6e5b1b388d05becd5 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 2 Oct 2017 14:53:48 +0200 Subject: [PATCH 4/4] 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(); }