diff --git a/eeschema/dialogs/dialog_symbol_fields_table.cpp b/eeschema/dialogs/dialog_symbol_fields_table.cpp index dbbf69e174..afa7b2eaf2 100644 --- a/eeschema/dialogs/dialog_symbol_fields_table.cpp +++ b/eeschema/dialogs/dialog_symbol_fields_table.cpp @@ -45,7 +45,7 @@ #include #include "dialog_symbol_fields_table.h" - +#include "eda_list_dialog.h" #define DISPLAY_NAME_COLUMN 0 #define SHOW_FIELD_COLUMN 1 @@ -223,6 +223,19 @@ public: } } + void RemoveColumn( int aCol ) + { + wxString fieldName = m_fieldNames[ aCol ]; + + m_fieldNames.erase( m_fieldNames.begin() + aCol ); + + for( unsigned i = 0; i < m_symbolsList.GetCount(); ++i ) + { + SCH_SYMBOL* symbol = m_symbolsList[ i ].GetSymbol(); + m_dataStore[ symbol->m_Uuid ].erase( fieldName ); + } + } + int GetNumberRows() override { return m_rows.size(); } // Columns are fieldNames + quantity column @@ -282,7 +295,7 @@ public: std::vector references; wxString fieldValue; - for( const auto& ref : group.m_Refs ) + for( const SCH_REFERENCE& ref : group.m_Refs ) { if( aCol == REFERENCE_FIELD || aCol == QUANTITY_COLUMN ) { @@ -348,7 +361,7 @@ public: DATA_MODEL_ROW& rowGroup = m_rows[ aRow ]; wxString fieldName = m_fieldNames[ aCol ]; - for( const auto& ref : rowGroup.m_Refs ) + for( const SCH_REFERENCE& ref : rowGroup.m_Refs ) m_dataStore[ ref.GetSymbol()->m_Uuid ][ fieldName ] = aValue; m_edited = true; @@ -611,21 +624,20 @@ public: for( const std::pair srcData : fieldStore ) { + if( srcData.first == _( "Qty" ) ) + continue; + const wxString& srcName = srcData.first; const wxString& srcValue = srcData.second; SCH_FIELD* destField = symbol.FindField( srcName ); - if( !destField && !srcValue.IsEmpty() ) + if( !destField ) { const VECTOR2I symbolPos = symbol.GetPosition(); destField = symbol.AddField( SCH_FIELD( symbolPos, -1, &symbol, srcName ) ); } - if( !destField ) - { - symbol.RemoveField( srcName ); - } - else if( destField->GetId() == REFERENCE_FIELD ) + if( destField->GetId() == REFERENCE_FIELD ) { // Reference is not editable } @@ -644,6 +656,12 @@ public: destField->SetText( srcValue ); } } + + for( int ii = symbol.GetFields().size() - 1; ii >= MANDATORY_FIELDS; ii-- ) + { + if( fieldStore.count( symbol.GetFields()[ii].GetName() ) == 0 ) + symbol.GetFields().erase( symbol.GetFields().begin() + ii ); + } } m_edited = false; @@ -960,7 +978,7 @@ void DIALOG_SYMBOL_FIELDS_TABLE::LoadFieldNames() } // Force References to always be shown - auto cfg = dynamic_cast( Kiface().KifaceSettings() ); + EESCHEMA_SETTINGS* cfg = dynamic_cast( Kiface().KifaceSettings() ); wxCHECK( cfg, /*void*/ ); cfg->m_FieldEditorPanel.fields_show["Reference"] = true; @@ -986,7 +1004,7 @@ void DIALOG_SYMBOL_FIELDS_TABLE::LoadFieldNames() void DIALOG_SYMBOL_FIELDS_TABLE::OnAddField( wxCommandEvent& event ) { // quantities column will become new field column, so it needs to be reset - auto attr = new wxGridCellAttr; + wxGridCellAttr* attr = new wxGridCellAttr; m_grid->SetColAttr( m_dataModel->GetColsCount() - 1, attr ); m_grid->SetColFormatCustom( m_dataModel->GetColsCount() - 1, wxGRID_VALUE_STRING ); @@ -1015,7 +1033,7 @@ void DIALOG_SYMBOL_FIELDS_TABLE::OnAddField( wxCommandEvent& event ) std::string key( fieldName.ToUTF8() ); - auto cfg = static_cast( Kiface().KifaceSettings() ); + EESCHEMA_SETTINGS* cfg = static_cast( Kiface().KifaceSettings() ); cfg->m_FieldEditorPanel.fields_show[key] = true; AddField( fieldName, fieldName, true, false ); @@ -1033,6 +1051,55 @@ void DIALOG_SYMBOL_FIELDS_TABLE::OnAddField( wxCommandEvent& event ) } +void DIALOG_SYMBOL_FIELDS_TABLE::OnRemoveField( wxCommandEvent& event ) +{ + wxArrayString headers; + std::vector fieldNames; + int col = -1; + + headers.Add( _( "User Fields" ) ); + + for( int ii = MANDATORY_FIELDS; ii < m_fieldsCtrl->GetItemCount(); ++ii ) + { + wxArrayString fieldName; + fieldName.Add( m_fieldsCtrl->GetTextValue( ii, 0 ) ); + fieldNames.emplace_back( fieldName ); + } + + EDA_LIST_DIALOG dlg( this, _( "Delete Field" ), headers, fieldNames, wxEmptyString ); + dlg.SetListLabel( _( "Select field:" ) ); + + if( dlg.ShowModal() == wxID_OK ) + { + wxString fieldName = dlg.GetTextSelection(); + + for( int ii = 0; ii < m_dataModel->GetNumberCols(); ++ii ) + { + if( fieldName == m_dataModel->GetColLabelValue( ii ) ) + col = ii; + } + } + + if( col >= 0 ) + { + m_fieldsCtrl->DeleteItem( col ); + m_dataModel->RemoveColumn( col ); + + wxGridTableMessage msg( m_dataModel, wxGRIDTABLE_NOTIFY_COLS_DELETED, + m_fieldsCtrl->GetItemCount(), 1 ); + m_grid->ProcessTableMessage( msg ); + } + + // set up attributes on the new quantities column + wxGridCellAttr* attr = new wxGridCellAttr; + attr->SetReadOnly(); + + m_grid->SetColAttr( m_dataModel->GetColsCount() - 1, attr ); + m_grid->SetColFormatNumber( m_dataModel->GetColsCount() - 1 ); + m_grid->SetColSize( m_dataModel->GetColsCount() - 1, 50 ); +} + + void DIALOG_SYMBOL_FIELDS_TABLE::OnColumnItemToggled( wxDataViewEvent& event ) { EESCHEMA_SETTINGS* cfg = static_cast( Kiface().KifaceSettings() ); diff --git a/eeschema/dialogs/dialog_symbol_fields_table.h b/eeschema/dialogs/dialog_symbol_fields_table.h index 403c7429d7..7d0c4b5521 100644 --- a/eeschema/dialogs/dialog_symbol_fields_table.h +++ b/eeschema/dialogs/dialog_symbol_fields_table.h @@ -64,6 +64,7 @@ private: void OnTableColSize( wxGridSizeEvent& event ) override; void OnSizeFieldList( wxSizeEvent& event ) override; void OnAddField( wxCommandEvent& event ) override; + void OnRemoveField( wxCommandEvent& event ) override; void OnSaveAndContinue( wxCommandEvent& aEvent ) override; void OnCancel( wxCommandEvent& event ) override; void OnClose( wxCloseEvent& event ) override; diff --git a/eeschema/dialogs/dialog_symbol_fields_table_base.cpp b/eeschema/dialogs/dialog_symbol_fields_table_base.cpp index e0a2cbac84..cca03aa72d 100644 --- a/eeschema/dialogs/dialog_symbol_fields_table_base.cpp +++ b/eeschema/dialogs/dialog_symbol_fields_table_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 3.10.0-4761b0c5) +// C++ code generated with wxFormBuilder (version Oct 26 2018) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -32,7 +32,7 @@ DIALOG_SYMBOL_FIELDS_TABLE_BASE::DIALOG_SYMBOL_FIELDS_TABLE_BASE( wxWindow* pare m_groupSymbolsBox->SetValue(true); m_groupSymbolsBox->SetToolTip( _("Group symbols together based on common properties") ); - bGroupSizer->Add( m_groupSymbolsBox, 0, wxALIGN_CENTER_VERTICAL|wxEXPAND|wxLEFT|wxRIGHT, 5 ); + bGroupSizer->Add( m_groupSymbolsBox, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5 ); bGroupSizer->Add( 0, 0, 1, wxEXPAND|wxRIGHT|wxLEFT, 10 ); @@ -53,6 +53,9 @@ DIALOG_SYMBOL_FIELDS_TABLE_BASE::DIALOG_SYMBOL_FIELDS_TABLE_BASE( wxWindow* pare m_addFieldButton = new wxButton( m_leftPanel, wxID_ANY, _("Add Field..."), wxDefaultPosition, wxDefaultSize, 0 ); bLeftSizer->Add( m_addFieldButton, 0, wxALL|wxEXPAND, 5 ); + m_removeFieldButton = new wxButton( m_leftPanel, wxID_ANY, _("Remove Field..."), wxDefaultPosition, wxDefaultSize, 0 ); + bLeftSizer->Add( m_removeFieldButton, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); + m_leftPanel->SetSizer( bLeftSizer ); m_leftPanel->Layout(); @@ -112,7 +115,7 @@ DIALOG_SYMBOL_FIELDS_TABLE_BASE::DIALOG_SYMBOL_FIELDS_TABLE_BASE( wxWindow* pare m_sdbSizer->AddButton( m_sdbSizerCancel ); m_sdbSizer->Realize(); - bButtonsSizer->Add( m_sdbSizer, 0, wxBOTTOM|wxEXPAND|wxLEFT, 5 ); + bButtonsSizer->Add( m_sdbSizer, 0, wxBOTTOM|wxLEFT, 5 ); bMainSizer->Add( bButtonsSizer, 0, wxEXPAND, 5 ); @@ -131,6 +134,7 @@ DIALOG_SYMBOL_FIELDS_TABLE_BASE::DIALOG_SYMBOL_FIELDS_TABLE_BASE( wxWindow* pare m_fieldsCtrl->Connect( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, wxDataViewEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnColumnItemToggled ), NULL, this ); m_fieldsCtrl->Connect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnSizeFieldList ), NULL, this ); m_addFieldButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnAddField ), NULL, this ); + m_removeFieldButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnRemoveField ), NULL, this ); m_grid->Connect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnTableValueChanged ), NULL, this ); m_grid->Connect( wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnTableCellClick ), NULL, this ); m_grid->Connect( wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnTableCellClick ), NULL, this ); @@ -149,6 +153,7 @@ DIALOG_SYMBOL_FIELDS_TABLE_BASE::~DIALOG_SYMBOL_FIELDS_TABLE_BASE() m_fieldsCtrl->Disconnect( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, wxDataViewEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnColumnItemToggled ), NULL, this ); m_fieldsCtrl->Disconnect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnSizeFieldList ), NULL, this ); m_addFieldButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnAddField ), NULL, this ); + m_removeFieldButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnRemoveField ), NULL, this ); m_grid->Disconnect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnTableValueChanged ), NULL, this ); m_grid->Disconnect( wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnTableCellClick ), NULL, this ); m_grid->Disconnect( wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnTableCellClick ), NULL, this ); diff --git a/eeschema/dialogs/dialog_symbol_fields_table_base.fbp b/eeschema/dialogs/dialog_symbol_fields_table_base.fbp index 18fc1d4b04..45a465236a 100644 --- a/eeschema/dialogs/dialog_symbol_fields_table_base.fbp +++ b/eeschema/dialogs/dialog_symbol_fields_table_base.fbp @@ -1,6 +1,6 @@ - + C++ @@ -14,7 +14,6 @@ dialog_symbol_fields_table_base 1000 none - 1 dialog_symbol_fields_table_base @@ -26,7 +25,6 @@ 1 1 UI - 0 0 0 @@ -52,7 +50,6 @@ DIALOG_SHIM; dialog_shim.h Symbol Fields Table - 0 @@ -191,7 +188,7 @@ none 5 - wxALIGN_CENTER_VERTICAL|wxEXPAND|wxLEFT|wxRIGHT + wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT 0 1 @@ -277,7 +274,6 @@ - 0 @@ -382,7 +378,6 @@ - 0 @@ -443,6 +438,79 @@ OnAddField + + 5 + wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + + 1 + 0 + 1 + + 1 + + 0 + 0 + + Dock + 0 + Left + 1 + + 1 + + + 0 + 0 + wxID_ANY + Remove Field... + + 0 + + 0 + + + 0 + + 1 + m_removeFieldButton + 1 + + + protected + 1 + + + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + OnRemoveField + + @@ -633,7 +701,6 @@ - 0 @@ -696,7 +763,7 @@ 5 - wxBOTTOM|wxEXPAND|wxLEFT + wxBOTTOM|wxLEFT 0 0 diff --git a/eeschema/dialogs/dialog_symbol_fields_table_base.h b/eeschema/dialogs/dialog_symbol_fields_table_base.h index 342f5030bf..1ff50f7a47 100644 --- a/eeschema/dialogs/dialog_symbol_fields_table_base.h +++ b/eeschema/dialogs/dialog_symbol_fields_table_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 3.10.0-4761b0c5) +// C++ code generated with wxFormBuilder (version Oct 26 2018) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -49,6 +49,7 @@ class DIALOG_SYMBOL_FIELDS_TABLE_BASE : public DIALOG_SHIM wxBitmapButton* m_bRefresh; wxDataViewListCtrl* m_fieldsCtrl; wxButton* m_addFieldButton; + wxButton* m_removeFieldButton; wxPanel* m_rightPanel; WX_GRID* m_grid; wxButton* m_buttonApply; @@ -56,13 +57,14 @@ class DIALOG_SYMBOL_FIELDS_TABLE_BASE : public DIALOG_SHIM wxButton* m_sdbSizerOK; wxButton* m_sdbSizerCancel; - // Virtual event handlers, override them in your derived class + // Virtual event handlers, overide them in your derived class virtual void OnClose( wxCloseEvent& event ) { event.Skip(); } virtual void OnGroupSymbolsToggled( wxCommandEvent& event ) { event.Skip(); } virtual void OnRegroupSymbols( wxCommandEvent& event ) { event.Skip(); } virtual void OnColumnItemToggled( wxDataViewEvent& event ) { event.Skip(); } virtual void OnSizeFieldList( wxSizeEvent& event ) { event.Skip(); } virtual void OnAddField( wxCommandEvent& event ) { event.Skip(); } + virtual void OnRemoveField( wxCommandEvent& event ) { event.Skip(); } virtual void OnTableValueChanged( wxGridEvent& event ) { event.Skip(); } virtual void OnTableCellClick( wxGridEvent& event ) { event.Skip(); } virtual void OnTableItemContextMenu( wxGridEvent& event ) { event.Skip(); } @@ -74,7 +76,6 @@ class DIALOG_SYMBOL_FIELDS_TABLE_BASE : public DIALOG_SHIM public: DIALOG_SYMBOL_FIELDS_TABLE_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Symbol Fields Table"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxMAXIMIZE_BOX|wxRESIZE_BORDER ); - ~DIALOG_SYMBOL_FIELDS_TABLE_BASE(); }; diff --git a/eeschema/dialogs/dialog_symbol_properties.cpp b/eeschema/dialogs/dialog_symbol_properties.cpp index 65725865bc..cbc028157c 100644 --- a/eeschema/dialogs/dialog_symbol_properties.cpp +++ b/eeschema/dialogs/dialog_symbol_properties.cpp @@ -677,33 +677,12 @@ bool DIALOG_SYMBOL_PROPERTIES::TransferDataFromWindow() if( entry && entry->IsPower() ) m_fields->at( VALUE_FIELD ).SetText( m_symbol->GetLibId().GetLibItemName() ); - // Push all fields to the symbol -except- for those which are TEMPLATE_FIELDNAMES - // with empty values. SCH_FIELDS& fields = m_symbol->GetFields(); fields.clear(); for( size_t i = 0; i < m_fields->size(); ++i ) - { - SCH_FIELD& field = m_fields->at( i ); - bool emptyTemplateField = false; - - if( i >= MANDATORY_FIELDS ) - { - for( const TEMPLATE_FIELDNAME& fieldname : - schematic.Settings().m_TemplateFieldNames.GetTemplateFieldNames() ) - { - if( field.GetName() == fieldname.m_Name && field.GetText().IsEmpty() ) - { - emptyTemplateField = true; - break; - } - } - } - - if( !emptyTemplateField ) - fields.push_back( field ); - } + fields.push_back( m_fields->at( i ) ); // Reference has a specific initialization, depending on the current active sheet // because for a given symbol, in a complex hierarchy, there are more than one