From d03e92a3a2cc1fbe69ceff825dfb18589b6453ca Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 29 May 2018 22:46:13 +0100 Subject: [PATCH] Field Name Template (aka Default Fields) fixes. Move from a "default" fields model to a "seed" fields model. See discussion on devlist: https://lists.launchpad.net/kicad-developers/msg35823.html. --- .../dialog_edit_component_in_schematic.cpp | 7 +------ .../dialog_edit_libentry_fields_in_lib.cpp | 7 +------ eeschema/dialogs/dialog_eeschema_options.cpp | 15 +++++-------- .../dialogs/dialog_eeschema_options_base.cpp | 18 +++++++--------- .../dialogs/dialog_eeschema_options_base.fbp | 21 +++++++++---------- .../dialogs/dialog_eeschema_options_base.h | 2 +- .../dialogs/dialog_fields_editor_global.cpp | 17 +-------------- .../netlist_exporter_generic.cpp | 11 +++------- eeschema/sch_component.cpp | 10 +-------- eeschema/sch_component.h | 5 +---- 10 files changed, 31 insertions(+), 82 deletions(-) diff --git a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp index 2c255e0e14..405e76afbe 100644 --- a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp @@ -824,12 +824,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::InitBuffers( SCH_COMPONENT* aComponent // values from the component will be set. if( !schField ) { - if( !it->m_Visible ) - fld.SetVisible( false ); - else - fld.SetVisible( true ); - - fld.SetText( it->m_Value ); // empty? ok too. + fld.SetVisible( it->m_Visible ); } else { diff --git a/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp b/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp index 30ca15f633..15217937af 100644 --- a/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp +++ b/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp @@ -650,12 +650,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::initBuffers() if( !libField ) { fld.SetName( it->m_Name ); - fld.SetText( it->m_Value ); // empty? ok too. - - if( !it->m_Visible ) - fld.SetVisible( false ); - else - fld.SetVisible( true ); + fld.SetVisible( it->m_Visible ); } else { diff --git a/eeschema/dialogs/dialog_eeschema_options.cpp b/eeschema/dialogs/dialog_eeschema_options.cpp index d2df9408e0..56bb00bf02 100644 --- a/eeschema/dialogs/dialog_eeschema_options.cpp +++ b/eeschema/dialogs/dialog_eeschema_options.cpp @@ -207,7 +207,6 @@ void DIALOG_EESCHEMA_OPTIONS::OnAddButtonClick( wxCommandEvent& event ) // Add a new fieldname to the fieldname list TEMPLATE_FIELDNAME newFieldname = TEMPLATE_FIELDNAME( "Fieldname" ); - newFieldname.m_Value = wxT( "Value" ); newFieldname.m_Visible = false; templateFields.insert( pos, newFieldname ); TransferDataToFieldGrid(); @@ -345,18 +344,15 @@ bool DIALOG_EESCHEMA_OPTIONS::TransferDataToFieldGrid() for( int row = 0; row < m_fieldGrid->GetNumberRows(); ++row ) { m_fieldGrid->SetCellValue( row, 0, templateFields[row].m_Name ); - m_fieldGrid->SetCellValue( row, 1, templateFields[row].m_Value ); - m_fieldGrid->SetCellValue( row, 2, - templateFields[row].m_Visible ? wxT( "1" ) : wxEmptyString ); + m_fieldGrid->SetCellValue( row, 1, templateFields[row].m_Visible ? wxT( "1" ) : wxEmptyString ); // Set cell properties m_fieldGrid->SetCellAlignment( row, 0, wxALIGN_LEFT, wxALIGN_CENTRE ); - m_fieldGrid->SetCellAlignment( row, 1, wxALIGN_LEFT, wxALIGN_CENTRE ); // Render the Visible column as a check box - m_fieldGrid->SetCellEditor( row, 2, new wxGridCellBoolEditor() ); - m_fieldGrid->SetCellRenderer( row, 2, new wxGridCellBoolRenderer() ); - m_fieldGrid->SetCellAlignment( row, 2, wxALIGN_CENTRE, wxALIGN_CENTRE ); + m_fieldGrid->SetCellEditor( row, 1, new wxGridCellBoolEditor() ); + m_fieldGrid->SetCellRenderer( row, 1, new wxGridCellBoolRenderer() ); + m_fieldGrid->SetCellAlignment( row, 1, wxALIGN_CENTRE, wxALIGN_CENTRE ); } m_fieldGrid->AutoSizeRows(); @@ -374,8 +370,7 @@ bool DIALOG_EESCHEMA_OPTIONS::TransferDataFromFieldGrid() for( int row = 0; row < m_fieldGrid->GetNumberRows(); ++row ) { templateFields[row].m_Name = m_fieldGrid->GetCellValue( row, 0 ); - templateFields[row].m_Value = m_fieldGrid->GetCellValue( row, 1 ); - templateFields[row].m_Visible = ( m_fieldGrid->GetCellValue( row, 2 ) != wxEmptyString ); + templateFields[row].m_Visible = ( m_fieldGrid->GetCellValue( row, 1 ) != wxEmptyString ); } return true; diff --git a/eeschema/dialogs/dialog_eeschema_options_base.cpp b/eeschema/dialogs/dialog_eeschema_options_base.cpp index e3119d8bbd..e75aab50ff 100644 --- a/eeschema/dialogs/dialog_eeschema_options_base.cpp +++ b/eeschema/dialogs/dialog_eeschema_options_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Apr 19 2018) +// C++ code generated with wxFormBuilder (version Dec 30 2017) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -327,24 +327,20 @@ DIALOG_EESCHEMA_OPTIONS_BASE::DIALOG_EESCHEMA_OPTIONS_BASE( wxWindow* parent, wx m_fieldGrid = new wxGrid( m_panel2, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); // Grid - m_fieldGrid->CreateGrid( 0, 3 ); + m_fieldGrid->CreateGrid( 0, 2 ); m_fieldGrid->EnableEditing( true ); m_fieldGrid->EnableGridLines( true ); m_fieldGrid->EnableDragGridSize( false ); m_fieldGrid->SetMargins( 0, 0 ); // Columns - m_fieldGrid->SetColSize( 0, 150 ); - m_fieldGrid->SetColSize( 1, 150 ); - m_fieldGrid->SetColSize( 2, 75 ); + m_fieldGrid->SetColSize( 0, 300 ); + m_fieldGrid->SetColSize( 1, 75 ); m_fieldGrid->EnableDragColMove( false ); m_fieldGrid->EnableDragColSize( true ); - m_fieldGrid->SetColLabelSize( 30 ); + m_fieldGrid->SetColLabelSize( 22 ); m_fieldGrid->SetColLabelValue( 0, _("Name") ); - m_fieldGrid->SetColLabelValue( 1, _("Default Value") ); - m_fieldGrid->SetColLabelValue( 2, _("Visible") ); - m_fieldGrid->SetColLabelValue( 3, _("Name") ); - m_fieldGrid->SetColLabelValue( 4, wxEmptyString ); + m_fieldGrid->SetColLabelValue( 1, _("Visible") ); m_fieldGrid->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); // Rows @@ -380,7 +376,7 @@ DIALOG_EESCHEMA_OPTIONS_BASE::DIALOG_EESCHEMA_OPTIONS_BASE( wxWindow* parent, wx m_panel2->SetSizer( bSizer6 ); m_panel2->Layout(); bSizer6->Fit( m_panel2 ); - m_notebook->AddPage( m_panel2, _("Default Fields"), false ); + m_notebook->AddPage( m_panel2, _("Field Name Templates"), false ); bOptionsSizer->Add( m_notebook, 1, wxALL|wxEXPAND, 5 ); diff --git a/eeschema/dialogs/dialog_eeschema_options_base.fbp b/eeschema/dialogs/dialog_eeschema_options_base.fbp index ffe0b27226..6f77c893da 100644 --- a/eeschema/dialogs/dialog_eeschema_options_base.fbp +++ b/eeschema/dialogs/dialog_eeschema_options_base.fbp @@ -14,7 +14,6 @@ dialog_eeschema_options_base 1000 none - 1 dialog_eeschema_options @@ -4786,11 +4785,11 @@ - + - Default Fields + Field Name Templates 0 - + 1 1 1 @@ -4864,16 +4863,16 @@ - + bSizer6 wxHORIZONTAL none - + 5 wxEXPAND 1 - + bSizer11 wxVERTICAL @@ -4905,11 +4904,11 @@ 0 1 wxALIGN_CENTRE - 30 - "Name" "Default Value" "Visible" "Name" "" + 22 + "Name" "Visible" wxALIGN_CENTRE - 3 - 150,150,75 + 2 + 300,75 1 0 diff --git a/eeschema/dialogs/dialog_eeschema_options_base.h b/eeschema/dialogs/dialog_eeschema_options_base.h index 15c9adf7af..d5ef39be00 100644 --- a/eeschema/dialogs/dialog_eeschema_options_base.h +++ b/eeschema/dialogs/dialog_eeschema_options_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Apr 19 2018) +// C++ code generated with wxFormBuilder (version Dec 30 2017) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! diff --git a/eeschema/dialogs/dialog_fields_editor_global.cpp b/eeschema/dialogs/dialog_fields_editor_global.cpp index f9e179452b..5a4855ac74 100644 --- a/eeschema/dialogs/dialog_fields_editor_global.cpp +++ b/eeschema/dialogs/dialog_fields_editor_global.cpp @@ -488,21 +488,6 @@ public: } - bool isModifiedDefaultField( std::pair aFieldData ) - { - wxString name = aFieldData.first; - wxString value = aFieldData.second; - - for( auto defaultField : m_frame->GetTemplateFieldNames() ) - { - if( name == defaultField.m_Name && value != defaultField.m_Value ) - return true; - } - - return false; - } - - void ApplyData() { for( unsigned i = 0; i < m_componentRefs.GetCount(); ++i ) @@ -520,7 +505,7 @@ public: wxString srcValue = srcData.second; SCH_FIELD* destField = comp->FindField( srcName ); - if( !destField && ( !srcValue.IsEmpty() || isModifiedDefaultField( srcData ) ) ) + if( !destField && !srcValue.IsEmpty() ) destField = comp->AddField( SCH_FIELD( wxPoint( 0, 0 ), -1, comp, srcName ) ); if( destField ) diff --git a/eeschema/netlist_exporters/netlist_exporter_generic.cpp b/eeschema/netlist_exporters/netlist_exporter_generic.cpp index 26b1988d58..0043d183f9 100644 --- a/eeschema/netlist_exporters/netlist_exporter_generic.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_generic.cpp @@ -160,15 +160,10 @@ void NETLIST_EXPORTER_GENERIC::addComponentFields( XNODE* xcomp, SCH_COMPONENT* for( int fldNdx = MANDATORY_FIELDS; fldNdx < comp->GetFieldCount(); ++fldNdx ) { SCH_FIELD* f = comp->GetField( fldNdx ); - fields.f[ f->GetName() ] = f->GetText(); - } - } - // Add in non-empty default fields which have not been explicitly defined - for( auto defaultField : m_frame->GetTemplateFieldNames() ) - { - if( defaultField.m_Value.size() && fields.f.count( defaultField.m_Name ) == 0 ) - fields.f[ defaultField.m_Name ] = defaultField.m_Value; + if( f->GetText().size() ) + fields.f[ f->GetName() ] = f->GetText(); + } } // Do not output field values blank in netlist: diff --git a/eeschema/sch_component.cpp b/eeschema/sch_component.cpp index 2d60ffee41..0e028bbd2c 100644 --- a/eeschema/sch_component.cpp +++ b/eeschema/sch_component.cpp @@ -902,8 +902,7 @@ SCH_FIELD* SCH_COMPONENT::GetField( int aFieldNdx ) const } -wxString SCH_COMPONENT::GetFieldText( const wxString& aFieldName, SCH_EDIT_FRAME* aFrame, - bool aIncludeDefaultFields ) const +wxString SCH_COMPONENT::GetFieldText( const wxString& aFieldName, SCH_EDIT_FRAME* aFrame ) const { for( unsigned int ii = 0; ii < m_Fields.size(); ii++ ) { @@ -911,13 +910,6 @@ wxString SCH_COMPONENT::GetFieldText( const wxString& aFieldName, SCH_EDIT_FRAME return m_Fields[ii].GetText(); } - if( aIncludeDefaultFields ) - { - for( auto defaultField : aFrame->GetTemplateFieldNames() ) - if( aFieldName == defaultField.m_Name ) - return defaultField.m_Value; - } - return wxEmptyString; } diff --git a/eeschema/sch_component.h b/eeschema/sch_component.h index 866b33fd8c..b6872b6b75 100644 --- a/eeschema/sch_component.h +++ b/eeschema/sch_component.h @@ -331,11 +331,8 @@ public: * Search for a field named \a aFieldName and returns text associated with this field. * * @param aFieldName is the name of the field - * @param aIncludeDefaultFields is used to search the default library symbol fields in the - * search. */ - wxString GetFieldText( const wxString& aFieldName, SCH_EDIT_FRAME* aFrame, - bool aIncludeDefaultFields = true ) const; + wxString GetFieldText( const wxString& aFieldName, SCH_EDIT_FRAME* aFrame ) const; /** * Populates a std::vector with SCH_FIELDs.