Reduce shared schematic file change churn.

(cherry picked from commit bf5d585e24)
This commit is contained in:
Wayne Stambaugh 2022-03-11 00:32:34 +00:00
parent 2874688281
commit 70277e5514
1 changed files with 29 additions and 8 deletions

View File

@ -1090,12 +1090,8 @@ void SCH_SEXPR_PLUGIN::saveSymbol( SCH_SYMBOL* aSymbol, SCH_SHEET_PATH* aSheetPa
m_out->Print( 0, ")" ); m_out->Print( 0, ")" );
} }
int unit = aSymbol->GetUnit(); // Always set the unit to 1. The real symbol unit is saved in the sheet instance data.
m_out->Print( 0, " (unit 1)" );
if( ( aSymbol->GetInstanceReferences().size() > 1 ) && aSheetPath )
unit = aSymbol->GetUnitSelection( aSheetPath );
m_out->Print( 0, " (unit %d)", unit );
if( aSymbol->GetConvert() == LIB_ITEM::LIB_CONVERT::DEMORGAN ) if( aSymbol->GetConvert() == LIB_ITEM::LIB_CONVERT::DEMORGAN )
m_out->Print( 0, " (convert %d)", aSymbol->GetConvert() ); m_out->Print( 0, " (convert %d)", aSymbol->GetConvert() );
@ -1115,11 +1111,36 @@ void SCH_SEXPR_PLUGIN::saveSymbol( SCH_SYMBOL* aSymbol, SCH_SHEET_PATH* aSheetPa
m_nextFreeFieldId = MANDATORY_FIELDS; m_nextFreeFieldId = MANDATORY_FIELDS;
for( SCH_FIELD& field : aSymbol->GetFields() ) for( SCH_FIELD& field : aSymbol->GetFields() )
{
int id = field.GetId();
wxString value = field.GetText();
// The reference field is always set to uninitialized and the value and footprint fields
// are always empty. The actual reference, value, and footprint field values are stored
// in the instance data. This prevents unwanted file change churn in shared schematics.
if( id == REFERENCE_FIELD )
field.SetText( aSymbol->GetPrefix() + wxT( "?" ) );
else if( id == VALUE_FIELD || id == FOOTPRINT_FIELD )
field.SetText( wxEmptyString );
try
{ {
saveField( &field, aNestLevel + 1 ); saveField( &field, aNestLevel + 1 );
} }
catch( ... )
{
// Restore the changed field info on write error.
if( id == REFERENCE_FIELD || id == VALUE_FIELD || id == FOOTPRINT_FIELD )
field.SetText( value );
for( const SCH_PIN* pin : aSymbol->GetPins() ) throw;
}
if( id == REFERENCE_FIELD || id == VALUE_FIELD || id == FOOTPRINT_FIELD )
field.SetText( value );
}
for( const std::unique_ptr<SCH_PIN>& pin : aSymbol->GetRawPins() )
{ {
if( pin->GetAlt().IsEmpty() ) if( pin->GetAlt().IsEmpty() )
{ {