Move setting derived symbol field properties from parent symbol.

In order allow the new file format to support derived symbols with
field properties that are different than the parent symbol, the code
that copied the parent field properties to the derive symbol field
properties had to moved out of LIB_PART::SetParent() into the legacy
symbol library plugin and the symbol library editor add new symbol
code to preserve the current behavior and not overwrite derived
symbol field properties.

This lays the ground work for allowing field properties of derived
symbols to be different than their parent symbol.
This commit is contained in:
Wayne Stambaugh 2020-05-30 10:33:05 -04:00
parent 57e35c9a60
commit dd1a7627f8
3 changed files with 40 additions and 28 deletions

View File

@ -319,37 +319,9 @@ void LIB_PART::SetName( const wxString& aName )
void LIB_PART::SetParent( LIB_PART* aParent )
{
if( aParent )
{
m_parent = aParent->SharedPtr();
// Inherit the parent mandatory field attributes.
for( int id=0; id<MANDATORY_FIELDS; ++id )
{
LIB_FIELD* field = GetField( id );
// the MANDATORY_FIELDS are exactly that in RAM.
wxASSERT( field );
LIB_FIELD* parentField = aParent->GetField( id );
wxASSERT( parentField );
wxString name = field->GetText();
*field = *parentField;
if( id == VALUE )
field->SetText( name );
else if( id == DATASHEET && !GetDocFileName().IsEmpty() )
field->SetText( GetDocFileName() );
field->SetParent( this );
}
}
else
{
m_parent.reset();
}
}

View File

@ -360,6 +360,26 @@ void LIB_EDIT_FRAME::CreateNewPart()
LIB_PART* parent = m_libMgr->GetAlias( parentSymbolName, lib );
wxCHECK( parent, /* void */ );
new_part.SetParent( parent );
// Inherit the parent mandatory field attributes.
for( int id=0; id<MANDATORY_FIELDS; ++id )
{
LIB_FIELD* field = new_part.GetField( id );
// the MANDATORY_FIELDS are exactly that in RAM.
wxCHECK( field, /* void */ );
LIB_FIELD* parentField = parent->GetField( id );
wxCHECK( parentField, /* void */ );
*field = *parentField;
if( id == VALUE )
field->SetText( name );
field->SetParent( &new_part );
}
}
m_libMgr->UpdatePart( &new_part, lib );

View File

@ -2965,6 +2965,26 @@ void SCH_LEGACY_PLUGIN_CACHE::loadAliases( std::unique_ptr<LIB_PART>& aPart,
{
LIB_PART* newPart = new LIB_PART( newAliasName );
// Inherit the parent mandatory field attributes.
for( int id=0; id<MANDATORY_FIELDS; ++id )
{
LIB_FIELD* field = newPart->GetField( id );
// the MANDATORY_FIELDS are exactly that in RAM.
wxASSERT( field );
LIB_FIELD* parentField = aPart->GetField( id );
wxASSERT( parentField );
*field = *parentField;
if( id == VALUE )
field->SetText( newAliasName );
field->SetParent( newPart );
}
newPart->SetParent( aPart.get() );
// This will prevent duplicate aliases.