Fix missing legacy value and footprint field instance data.

The legacy and s-expression (prior to version 20200828) file formats only
supported symbol unit and reference fields so the newly added value and
footprint fields must be updated from the original symbol fields.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/12226

(cherry picked from commit 797827b833)
This commit is contained in:
Wayne Stambaugh 2022-08-17 11:31:49 -04:00
parent 40977514ce
commit 39940fe5ab
8 changed files with 60 additions and 4 deletions

View File

@ -456,6 +456,7 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& 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();

View File

@ -2193,6 +2193,9 @@ void SCH_SEXPR_PARSER::ParseSchematic( SCH_SHEET* aSheet, bool aIsCopyableOnly,
}
screen->UpdateLocalLibSymbolLinks();
if( m_requiredVersion < 20200828 )
screen->SetLegacySymbolInstanceData();
}

View File

@ -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 ) )
{

View File

@ -1179,6 +1179,24 @@ void SCH_SCREEN::AddBusAlias( std::shared_ptr<BUS_ALIAS> aAlias )
}
void SCH_SCREEN::SetLegacySymbolInstanceData()
{
for( SCH_ITEM* item : Items().OfType( SCH_SYMBOL_T ) )
{
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( 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();
}

View File

@ -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);

View File

@ -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<SCH_PIN>& pin : m_pins )
pin->ClearDefaultNetName( sheet );

View File

@ -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();
}

View File

@ -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 {}