From 35f15f016d98f15c3903cf8ef17b155993077931 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Fri, 11 Mar 2022 12:37:05 -0500 Subject: [PATCH] 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. (cherry picked from commit dd1dbb81f6803838852231744fe47267d5ac97db) --- .../sch_plugins/kicad/sch_sexpr_plugin.cpp | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp index 4bc4a752ac..22c6397c1e 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp @@ -1090,8 +1090,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() ); @@ -1115,13 +1118,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 { @@ -1129,7 +1146,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 );