Handle derived library symbol optional field inheritance.

CHANGED: Derived library symbols will inherit optional fields defined by
their parent symbol and override existing optional fields.

CHANGED: The symbol editor will now only display the fields defined in
derived symbols rather than show mandatory fields inherited from the
parent symbol.  Showing fields that cannot be edited would be confusing.
This commit is contained in:
Wayne Stambaugh 2020-06-01 13:45:46 -04:00
parent 52078a4b1b
commit 354d53a6c5
4 changed files with 49 additions and 15 deletions

View File

@ -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<const LIB_FIELD*>( &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 );
}

View File

@ -271,6 +271,11 @@ public:
*/
LIB_FIELD* FindField( const wxString& aFieldName );
const LIB_FIELD* FindField( const wxString& aFieldName ) const
{
return const_cast<LIB_FIELD*>( FindField( aFieldName ) );
}
/**
* Return pointer to the requested field.
*

View File

@ -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 );

View File

@ -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 );
}