diff --git a/eeschema/class_libentry.cpp b/eeschema/class_libentry.cpp index 84da0ab8c7..67ef4c8a2c 100644 --- a/eeschema/class_libentry.cpp +++ b/eeschema/class_libentry.cpp @@ -332,9 +332,9 @@ std::unique_ptr< LIB_PART > LIB_PART::Flatten() const // Copy the parent. retv.reset( new LIB_PART( *parent.get() ) ); - // Now add the inherited part mandator field (this) information. retv->SetName( m_name ); + // Now add the inherited part mandatory field (this) information. for( int i = 0; i < MANDATORY_FIELDS; i++ ) { wxString tmp = GetField( i )->GetText(); @@ -346,6 +346,33 @@ std::unique_ptr< LIB_PART > LIB_PART::Flatten() const *retv->GetField( i ) = *GetField( i ); } + // Grab all the rest of derived symbol fields. + for( const LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] ) + { + const LIB_FIELD* aliasField = dynamic_cast( &item ); + + wxCHECK2( aliasField, continue ); + + // Mandatory fields were already resolved. + if( aliasField->IsMandatory() ) + continue; + + LIB_FIELD* newField = new LIB_FIELD( *aliasField ); + newField->SetParent( retv.get() ); + + LIB_FIELD* parentField = retv->FindField( aliasField->GetName() ); + + if( !parentField ) // Derived symbol field does not exist in parent symbol. + { + retv->AddDrawItem( newField ); + } + else // Derived symbol field overrides the parent symbol field. + { + retv->RemoveDrawItem( parentField ); + retv->AddDrawItem( newField ); + } + } + retv->SetKeyWords( m_keyWords ); retv->SetDescription( m_description ); } diff --git a/eeschema/class_libentry.h b/eeschema/class_libentry.h index 270b1294ea..4c31e92cfc 100644 --- a/eeschema/class_libentry.h +++ b/eeschema/class_libentry.h @@ -271,6 +271,11 @@ public: */ LIB_FIELD* FindField( const wxString& aFieldName ); + const LIB_FIELD* FindField( const wxString& aFieldName ) const + { + return const_cast( FindField( aFieldName ) ); + } + /** * Return pointer to the requested field. * diff --git a/eeschema/dialogs/dialog_edit_component_in_lib.cpp b/eeschema/dialogs/dialog_edit_component_in_lib.cpp index 4b19ef2e24..f5b7a02078 100644 --- a/eeschema/dialogs/dialog_edit_component_in_lib.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_lib.cpp @@ -198,10 +198,6 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::TransferDataToWindow() wxCHECK( selection != wxNOT_FOUND, false ); m_inheritanceSelectCombo->SetSelection( selection ); - // Copy the reference field from the root symbol to prevent validation errors. - if( m_fields->at( REFERENCE ).GetText().IsEmpty() ) - m_fields->at( REFERENCE ).SetText( rootPart->GetReferenceField().GetText() ); - m_lastOpenedPage = 0; } @@ -216,7 +212,9 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::Validate() if( !m_grid->CommitPendingChanges() ) return false; - if( !SCH_COMPONENT::IsReferenceStringValid( m_fields->at( REFERENCE ).GetText() ) ) + // Alias symbol reference can be empty because it inherits from the parent symbol. + if( m_libEntry->IsRoot() && + !SCH_COMPONENT::IsReferenceStringValid( m_fields->at( REFERENCE ).GetText() ) ) { if( m_NoteBook->GetSelection() != 0 ) m_NoteBook->SetSelection( 0 ); @@ -711,7 +709,7 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::syncControlStates( bool aIsAlias ) m_NoteBook->RemovePage( 1 ); bSizerLowerBasicPanel->Show( !aIsAlias ); - bButtonSize->Show( !aIsAlias ); + // bButtonSize->Show( !aIsAlias ); #ifdef KICAD_SPICE m_spiceFieldsButton->Show( !aIsAlias ); diff --git a/eeschema/sch_view.cpp b/eeschema/sch_view.cpp index 5e5099e4a4..7e27a07093 100644 --- a/eeschema/sch_view.cpp +++ b/eeschema/sch_view.cpp @@ -143,8 +143,14 @@ void SCH_VIEW::DisplayComponent( LIB_PART* aPart ) if( item.Type() != LIB_FIELD_T ) continue; - if( static_cast< LIB_FIELD* >( &item )->IsMandatory() ) - Add( &item ); + LIB_FIELD* field = static_cast< LIB_FIELD* >( &item ); + + wxCHECK2( field, continue ); + + if( field->GetText().IsEmpty() ) + continue; + + Add( &item ); } // Draw the parent items if the symbol is inherited from another symbol. @@ -159,12 +165,10 @@ void SCH_VIEW::DisplayComponent( LIB_PART* aPart ) for( auto& item : drawnPart->GetDrawItems() ) { - // The mandatory fields are already in place so we only add user defined fields. - if( item.Type() == LIB_FIELD_T ) - { - if( static_cast< LIB_FIELD* >( &item )->IsMandatory() ) - continue; - } + // Don't show parent symbol fields. Users may be confused by shown fields that can not + // be edited. + if( aPart->IsAlias() && item.Type() == LIB_FIELD_T ) + continue; Add( &item ); }