diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index c0815aa402..f8d4c659bb 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -456,6 +456,7 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in // Legacy schematic can have duplicate time stamps so fix that before converting // to the s-expression format. schematic.ReplaceDuplicateTimeStamps(); + schematic.SetLegacySymbolInstanceData(); // Allow the schematic to be saved to new file format without making any edits. OnModify(); diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp index 12283b5f88..4a1e924804 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp @@ -2193,6 +2193,9 @@ void SCH_SEXPR_PARSER::ParseSchematic( SCH_SHEET* aSheet, bool aIsCopyableOnly, } screen->UpdateLocalLibSymbolLinks(); + + if( m_requiredVersion < 20200828 ) + screen->SetLegacySymbolInstanceData(); } diff --git a/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp b/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp index 5b0cfa3a55..b3e528c2d7 100644 --- a/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp +++ b/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp @@ -1692,7 +1692,6 @@ SCH_SYMBOL* SCH_LEGACY_PLUGIN::loadSymbol( LINE_READER& aReader ) symbol->AddHierarchicalReference( path, reference, (int)tmp ); symbol->GetField( REFERENCE_FIELD )->SetText( reference ); - } else if( strCompare( "F", line, &line ) ) { diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index 630510aeb1..126e828346 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -1179,6 +1179,24 @@ void SCH_SCREEN::AddBusAlias( std::shared_ptr aAlias ) } +void SCH_SCREEN::SetLegacySymbolInstanceData() +{ + for( SCH_ITEM* item : Items().OfType( SCH_SYMBOL_T ) ) + { + SCH_SYMBOL* symbol = static_cast( item ); + + // Add missing value and footprint instance data for legacy schematics. + for( const SYMBOL_INSTANCE_REFERENCE& instance : symbol->GetInstanceReferences() ) + { + symbol->AddHierarchicalReference( instance.m_Path, instance.m_Reference, + instance.m_Unit, + symbol->GetField( VALUE_FIELD )->GetText(), + symbol->GetField( FOOTPRINT_FIELD )->GetText() ); + } + } +} + + #if defined(DEBUG) void SCH_SCREEN::Show( int nestLevel, std::ostream& os ) const { @@ -1569,3 +1587,11 @@ void SCH_SCREENS::BuildClientSheetPathList() } } } + + +void SCH_SCREENS::SetLegacySymbolInstanceData() +{ + + for( SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() ) + screen->SetLegacySymbolInstanceData(); +} diff --git a/eeschema/sch_screen.h b/eeschema/sch_screen.h index 9456d54faa..6a7d3537eb 100644 --- a/eeschema/sch_screen.h +++ b/eeschema/sch_screen.h @@ -497,6 +497,11 @@ public: void AssignNewUuid() { m_uuid = KIID(); } + /** + * Update the symbol value and footprint instance data for legacy designs. + */ + void SetLegacySymbolInstanceData(); + #if defined(DEBUG) void Show( int nestLevel, std::ostream& os ) const override; #endif @@ -715,6 +720,11 @@ public: */ bool CanCauseCaseSensitivityIssue( const wxString& aSchematicFileName ) const; + /** + * Update the symbol value and footprint instance data for legacy designs. + */ + void SetLegacySymbolInstanceData(); + private: void addScreenToList( SCH_SCREEN* aScreen, SCH_SHEET* aSheet ); void buildScreenList( SCH_SHEET* aSheet); diff --git a/eeschema/sch_symbol.cpp b/eeschema/sch_symbol.cpp index 33d6598292..251328cec6 100644 --- a/eeschema/sch_symbol.cpp +++ b/eeschema/sch_symbol.cpp @@ -518,7 +518,8 @@ void SCH_SYMBOL::SetRef( const SCH_SHEET_PATH* sheet, const wxString& ref ) } if( !found ) - AddHierarchicalReference( path, ref, m_unit ); + AddHierarchicalReference( path, ref, m_unit, GetField( VALUE_FIELD )->GetText(), + GetField( FOOTPRINT_FIELD )->GetText() ); for( std::unique_ptr& pin : m_pins ) pin->ClearDefaultNetName( sheet ); diff --git a/eeschema/schematic.cpp b/eeschema/schematic.cpp index 15c4684c09..e8a4caab16 100644 --- a/eeschema/schematic.cpp +++ b/eeschema/schematic.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -401,3 +401,11 @@ SCH_SHEET_LIST& SCHEMATIC::GetFullHierarchy() const return hierarchy; } + + +void SCHEMATIC::SetLegacySymbolInstanceData() +{ + SCH_SCREENS screens( m_rootSheet ); + + screens.SetLegacySymbolInstanceData(); +} diff --git a/eeschema/schematic.h b/eeschema/schematic.h index 3d793729d0..a76c59a523 100644 --- a/eeschema/schematic.h +++ b/eeschema/schematic.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -169,6 +169,14 @@ public: */ SCH_SHEET_LIST& GetFullHierarchy() const; + /** + * Update the symbol value and footprint instance data for legacy designs. + * + * Prior to schematic file format version 20200828 and legacy file format version, only + * symbol reference field and unit were saved in the instance data. The value and footprint + * fields must be carried forward from the original symbol to prevent data loss. + */ + void SetLegacySymbolInstanceData(); #if defined(DEBUG) void Show( int nestLevel, std::ostream& os ) const override {}