From f7823239609bed6d0a315f394f202e61775e68d0 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Sat, 15 Oct 2022 14:15:51 -0400 Subject: [PATCH] Fix yet another symbol instance issue when loading legacy schematics. --- eeschema/files-io.cpp | 2 +- eeschema/sch_edit_frame.cpp | 5 ++++- eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp | 14 ++++++++++++++ eeschema/sch_plugins/legacy/sch_legacy_plugin.h | 1 + 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index a0f2865e20..8994ea4264 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -431,7 +431,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(); + // schematic.SetLegacySymbolInstanceData(); // Allow the schematic to be saved to new file format without making any edits. OnModify(); diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index b15bcad5af..0be2c78ff9 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -679,12 +679,15 @@ void SCH_EDIT_FRAME::CreateScreens() m_schematic->Reset(); m_schematic->SetProject( &Prj() ); - m_schematic->SetRoot( new SCH_SHEET( m_schematic ) ); + SCH_SHEET* rootSheet = new SCH_SHEET( m_schematic ); + m_schematic->SetRoot( rootSheet ); SCH_SCREEN* rootScreen = new SCH_SCREEN( m_schematic ); + const_cast( rootSheet->m_Uuid ) = rootScreen->GetUuid(); m_schematic->Root().SetScreen( rootScreen ); SetScreen( Schematic().RootScreen() ); + m_schematic->RootScreen()->SetFileName( wxEmptyString ); // Don't leave root page number empty diff --git a/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp b/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp index 6a16db4fc7..a95c5bc826 100644 --- a/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp +++ b/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp @@ -194,6 +194,8 @@ void SCH_LEGACY_PLUGIN::loadHierarchy( SCH_SHEET* aSheet ) { SCH_SCREEN* screen = nullptr; + m_currentSheet = aSheet; + if( !aSheet->GetScreen() ) { // SCH_SCREEN objects store the full path and file name where the SCH_SHEET object only @@ -226,6 +228,9 @@ void SCH_LEGACY_PLUGIN::loadHierarchy( SCH_SHEET* aSheet ) aSheet->SetScreen( new SCH_SCREEN( m_schematic ) ); aSheet->GetScreen()->SetFileName( fileName.GetFullPath() ); + if( aSheet == m_rootSheet ) + const_cast( aSheet->m_Uuid ) = aSheet->GetScreen()->GetUuid(); + try { loadFile( fileName.GetFullPath(), aSheet->GetScreen() ); @@ -1338,6 +1343,15 @@ SCH_SYMBOL* SCH_LEGACY_PLUGIN::loadSymbol( LINE_READER& aReader ) } else if( strCompare( "$EndComp", line ) ) { + if( !m_appending && ( m_currentSheet == m_rootSheet ) ) + { + KIID_PATH path; + path.push_back( m_rootSheet->GetScreen()->GetUuid() ); + symbol->AddHierarchicalReference( path, + symbol->GetField( REFERENCE_FIELD )->GetText(), + symbol->GetUnit() ); + } + // Ensure all flags (some are set by previous initializations) are reset: symbol->ClearFlags(); return symbol.release(); diff --git a/eeschema/sch_plugins/legacy/sch_legacy_plugin.h b/eeschema/sch_plugins/legacy/sch_legacy_plugin.h index 871348195a..b7571d5f19 100644 --- a/eeschema/sch_plugins/legacy/sch_legacy_plugin.h +++ b/eeschema/sch_plugins/legacy/sch_legacy_plugin.h @@ -191,6 +191,7 @@ protected: wxString m_path; ///< Root project path for loading child sheets. std::stack m_currentPath; ///< Stack to maintain nested sheet paths SCH_SHEET* m_rootSheet; ///< The root sheet of the schematic being loaded. + SCH_SHEET* m_currentSheet; ///< The sheet currently being loaded. OUTPUTFORMATTER* m_out; ///< The formatter for saving SCH_SCREEN objects. SCH_LEGACY_PLUGIN_CACHE* m_cache; SCHEMATIC* m_schematic;