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:
parent
52078a4b1b
commit
354d53a6c5
|
@ -332,9 +332,9 @@ std::unique_ptr< LIB_PART > LIB_PART::Flatten() const
|
||||||
// Copy the parent.
|
// Copy the parent.
|
||||||
retv.reset( new LIB_PART( *parent.get() ) );
|
retv.reset( new LIB_PART( *parent.get() ) );
|
||||||
|
|
||||||
// Now add the inherited part mandator field (this) information.
|
|
||||||
retv->SetName( m_name );
|
retv->SetName( m_name );
|
||||||
|
|
||||||
|
// Now add the inherited part mandatory field (this) information.
|
||||||
for( int i = 0; i < MANDATORY_FIELDS; i++ )
|
for( int i = 0; i < MANDATORY_FIELDS; i++ )
|
||||||
{
|
{
|
||||||
wxString tmp = GetField( i )->GetText();
|
wxString tmp = GetField( i )->GetText();
|
||||||
|
@ -346,6 +346,33 @@ std::unique_ptr< LIB_PART > LIB_PART::Flatten() const
|
||||||
*retv->GetField( i ) = *GetField( i );
|
*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->SetKeyWords( m_keyWords );
|
||||||
retv->SetDescription( m_description );
|
retv->SetDescription( m_description );
|
||||||
}
|
}
|
||||||
|
|
|
@ -271,6 +271,11 @@ public:
|
||||||
*/
|
*/
|
||||||
LIB_FIELD* FindField( const wxString& aFieldName );
|
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.
|
* Return pointer to the requested field.
|
||||||
*
|
*
|
||||||
|
|
|
@ -198,10 +198,6 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::TransferDataToWindow()
|
||||||
wxCHECK( selection != wxNOT_FOUND, false );
|
wxCHECK( selection != wxNOT_FOUND, false );
|
||||||
m_inheritanceSelectCombo->SetSelection( selection );
|
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;
|
m_lastOpenedPage = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,7 +212,9 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::Validate()
|
||||||
if( !m_grid->CommitPendingChanges() )
|
if( !m_grid->CommitPendingChanges() )
|
||||||
return false;
|
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 )
|
if( m_NoteBook->GetSelection() != 0 )
|
||||||
m_NoteBook->SetSelection( 0 );
|
m_NoteBook->SetSelection( 0 );
|
||||||
|
@ -711,7 +709,7 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::syncControlStates( bool aIsAlias )
|
||||||
m_NoteBook->RemovePage( 1 );
|
m_NoteBook->RemovePage( 1 );
|
||||||
|
|
||||||
bSizerLowerBasicPanel->Show( !aIsAlias );
|
bSizerLowerBasicPanel->Show( !aIsAlias );
|
||||||
bButtonSize->Show( !aIsAlias );
|
// bButtonSize->Show( !aIsAlias );
|
||||||
|
|
||||||
#ifdef KICAD_SPICE
|
#ifdef KICAD_SPICE
|
||||||
m_spiceFieldsButton->Show( !aIsAlias );
|
m_spiceFieldsButton->Show( !aIsAlias );
|
||||||
|
|
|
@ -143,8 +143,14 @@ void SCH_VIEW::DisplayComponent( LIB_PART* aPart )
|
||||||
if( item.Type() != LIB_FIELD_T )
|
if( item.Type() != LIB_FIELD_T )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if( static_cast< LIB_FIELD* >( &item )->IsMandatory() )
|
LIB_FIELD* field = static_cast< LIB_FIELD* >( &item );
|
||||||
Add( &item );
|
|
||||||
|
wxCHECK2( field, continue );
|
||||||
|
|
||||||
|
if( field->GetText().IsEmpty() )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Add( &item );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw the parent items if the symbol is inherited from another symbol.
|
// 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() )
|
for( auto& item : drawnPart->GetDrawItems() )
|
||||||
{
|
{
|
||||||
// The mandatory fields are already in place so we only add user defined fields.
|
// Don't show parent symbol fields. Users may be confused by shown fields that can not
|
||||||
if( item.Type() == LIB_FIELD_T )
|
// be edited.
|
||||||
{
|
if( aPart->IsAlias() && item.Type() == LIB_FIELD_T )
|
||||||
if( static_cast< LIB_FIELD* >( &item )->IsMandatory() )
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Add( &item );
|
Add( &item );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue