Improve shared schematic file churn heuristics.

The previous solution cleared all of the fields and force the unit setting
to unit one which would have less than desirable effects when reusing a
schematic in another project.  This solution forces all of the instance
settings to the first sheet instance of the current project to prevent file
change churn when changing shared sheets in the current project.

This will not prevent shared schematic file changes when the first sheet
instance data differs between projects.
This commit is contained in:
Wayne Stambaugh 2022-03-11 12:37:05 -05:00
parent 8d05ca5982
commit dd1dbb81f6
1 changed files with 26 additions and 9 deletions

View File

@ -685,8 +685,11 @@ void SCH_SEXPR_PLUGIN::saveSymbol( SCH_SYMBOL* aSymbol, SCH_SHEET_PATH* aSheetPa
m_out->Print( 0, ")" );
}
// Always set the unit to 1. The real symbol unit is saved in the sheet instance data.
m_out->Print( 0, " (unit 1)" );
int unit = ( aSymbol->GetInstanceReferences().size() == 0 ) ?
aSymbol->GetUnit() :
aSymbol->GetInstanceReferences()[0].m_Unit;
m_out->Print( 0, " (unit %d)", unit );
if( aSymbol->GetConvert() == LIB_ITEM::LIB_CONVERT::DEMORGAN )
m_out->Print( 0, " (convert %d)", aSymbol->GetConvert() );
@ -710,13 +713,27 @@ void SCH_SEXPR_PLUGIN::saveSymbol( SCH_SYMBOL* aSymbol, SCH_SHEET_PATH* aSheetPa
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.
// The instance fields are always set to the first sheet instance of the project to
// schematic file changes when switching sheet instances with the current project
// schematic. It does not solve the problem for schematics shared between projects.
if( id == REFERENCE_FIELD )
field.SetText( aSymbol->GetPrefix() + wxT( "?" ) );
else if( id == VALUE_FIELD || id == FOOTPRINT_FIELD )
field.SetText( wxEmptyString );
{
field.SetText( ( aSymbol->GetInstanceReferences().size() == 0 ) ?
value :
aSymbol->GetInstanceReferences()[0].m_Reference );
}
else if( id == VALUE_FIELD )
{
field.SetText( ( aSymbol->GetInstanceReferences().size() == 0 ) ?
value :
aSymbol->GetInstanceReferences()[0].m_Value );
}
else if( id == FOOTPRINT_FIELD )
{
field.SetText( ( aSymbol->GetInstanceReferences().size() == 0 ) ?
value :
aSymbol->GetInstanceReferences()[0].m_Footprint );
}
try
{
@ -724,7 +741,7 @@ void SCH_SEXPR_PLUGIN::saveSymbol( SCH_SYMBOL* aSymbol, SCH_SHEET_PATH* aSheetPa
}
catch( ... )
{
// Restore the changed field info on write error.
// Restore the changed field text on write error.
if( id == REFERENCE_FIELD || id == VALUE_FIELD || id == FOOTPRINT_FIELD )
field.SetText( value );