diff --git a/eeschema/dialogs/dialog_fields_editor_global.cpp b/eeschema/dialogs/dialog_fields_editor_global.cpp index 65663d371b..25eee75820 100644 --- a/eeschema/dialogs/dialog_fields_editor_global.cpp +++ b/eeschema/dialogs/dialog_fields_editor_global.cpp @@ -585,8 +585,10 @@ public: if( !destField && !srcValue.IsEmpty() ) destField = comp->AddField( SCH_FIELD( wxPoint( 0, 0 ), -1, comp, srcName ) ); - if( destField ) + if( destField && !srcValue.IsEmpty() ) destField->SetText( srcValue ); + else + comp->RemoveField( srcName ); } } diff --git a/eeschema/sch_component.cpp b/eeschema/sch_component.cpp index db26f647cb..c24250c3a3 100644 --- a/eeschema/sch_component.cpp +++ b/eeschema/sch_component.cpp @@ -934,6 +934,19 @@ SCH_FIELD* SCH_COMPONENT::AddField( const SCH_FIELD& aField ) } +void SCH_COMPONENT::RemoveField( const wxString& aFieldName ) +{ + for( unsigned i = MANDATORY_FIELDS; i < m_Fields.size(); ++i ) + { + if( aFieldName == m_Fields[i].GetName( false ) ) + { + m_Fields.erase( m_Fields.begin() + i ); + return; + } + } +} + + SCH_FIELD* SCH_COMPONENT::FindField( const wxString& aFieldName, bool aIncludeDefaultFields ) { unsigned start = aIncludeDefaultFields ? 0 : MANDATORY_FIELDS; diff --git a/eeschema/sch_component.h b/eeschema/sch_component.h index bd72868e89..62f95b151d 100644 --- a/eeschema/sch_component.h +++ b/eeschema/sch_component.h @@ -349,6 +349,13 @@ public: */ SCH_FIELD* AddField( const SCH_FIELD& aField ); + /** + * Removes a user field from the symbol. + * @param aFieldName is the user fieldName to remove. Attempts to remove a mandatory + * field or a non-existant field are silently ignored. + */ + void RemoveField( const wxString& aFieldName ); + /** * Search for a #SCH_FIELD with \a aFieldName *