From 0cf11103677583dba25997c9d5d7adfcbbfd15a7 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Fri, 9 Aug 2024 14:52:58 -0400 Subject: [PATCH] Fix missing schematic symbol instance data. This fix adds missing symbol instance data that defaults the instance data to no annotation which will will trigger a annotation request on any operations that require a fully annotated schematic. Fixes https://gitlab.com/kicad/code/kicad/-/issues/18486 --- eeschema/files-io.cpp | 9 ++++++--- eeschema/sch_sheet_path.cpp | 37 ++++++++++++++++++++++++++++++++++++- eeschema/sch_sheet_path.h | 6 +++++- 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index 5bf2b729f5..ff7fdcd22e 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -185,7 +185,8 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in CreateScreens(); } - SCH_IO_MGR::SCH_FILE_T schFileType = SCH_IO_MGR::GuessPluginTypeFromSchPath( fullFileName, KICTL_KICAD_ONLY ); + SCH_IO_MGR::SCH_FILE_T schFileType = SCH_IO_MGR::GuessPluginTypeFromSchPath( fullFileName, + KICTL_KICAD_ONLY ); if( schFileType == SCH_IO_MGR::SCH_LEGACY ) { @@ -498,13 +499,14 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in // Restore all of the loaded symbol and sheet instances from the root sheet. if( Schematic().RootScreen()->GetFileFormatVersionAtLoad() < 20221002 ) - sheetList.UpdateSymbolInstanceData( Schematic().RootScreen()->GetSymbolInstances()); + sheetList.UpdateSymbolInstanceData( Schematic().RootScreen()->GetSymbolInstances() ); if( Schematic().RootScreen()->GetFileFormatVersionAtLoad() < 20221110 ) sheetList.UpdateSheetInstanceData( Schematic().RootScreen()->GetSheetInstances()); if( Schematic().RootScreen()->GetFileFormatVersionAtLoad() < 20230221 ) - for( SCH_SCREEN* screen = schematic.GetFirst(); screen; screen = schematic.GetNext() ) + for( SCH_SCREEN* screen = schematic.GetFirst(); screen; + screen = schematic.GetNext() ) screen->FixLegacyPowerSymbolMismatches(); for( SCH_SCREEN* screen = schematic.GetFirst(); screen; screen = schematic.GetNext() ) @@ -524,6 +526,7 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in schematic.PruneOrphanedSymbolInstances( Prj().GetProjectName(), sheetList ); schematic.PruneOrphanedSheetInstances( Prj().GetProjectName(), sheetList ); + sheetList.CheckForMissingSymbolInstances( Prj().GetProjectName() ); Schematic().ConnectionGraph()->Reset(); diff --git a/eeschema/sch_sheet_path.cpp b/eeschema/sch_sheet_path.cpp index 86d442d0d7..a99dc9c8f0 100644 --- a/eeschema/sch_sheet_path.cpp +++ b/eeschema/sch_sheet_path.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2011 Wayne Stambaugh - * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023, 2024 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 @@ -23,6 +23,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ +#include #include #include #include @@ -667,6 +668,33 @@ void SCH_SHEET_PATH::RemoveSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPa } +void SCH_SHEET_PATH::CheckForMissingSymbolInstances( const wxString& aProjectName ) +{ + wxCHECK( !aProjectName.IsEmpty() && LastScreen(), /* void */ ); + + for( SCH_ITEM* item : LastScreen()->Items().OfType( SCH_SYMBOL_T ) ) + { + SCH_SYMBOL* symbol = static_cast( item ); + + wxCHECK2( symbol, continue ); + + SCH_SYMBOL_INSTANCE symbolInstance; + + if( !symbol->GetInstance( symbolInstance, Path() ) ) + { + wxLogTrace( traceSchSheetPaths, "Adding missing symbol \"%s\" instance data for " + "sheet path '%s'.", + symbol->m_Uuid.AsString(), PathHumanReadable( false ) ); + + symbolInstance.m_Reference = UTIL::GetRefDesUnannotated( symbol->GetPrefix() ); + symbolInstance.m_ProjectName = aProjectName; + symbolInstance.m_Path = Path(); + symbol->AddHierarchicalReference( symbolInstance ); + } + } +} + + void SCH_SHEET_PATH::MakeFilePathRelativeToParentSheet() { wxCHECK( m_sheets.size() > 1, /* void */ ); @@ -1370,6 +1398,13 @@ void SCH_SHEET_LIST::AddNewSheetInstances( const SCH_SHEET_PATH& aPrefixSheetPat } +void SCH_SHEET_LIST::CheckForMissingSymbolInstances( const wxString& aProjectName ) +{ + for( SCH_SHEET_PATH& sheetPath : *this ) + sheetPath.CheckForMissingSymbolInstances( aProjectName ); +} + + int SCH_SHEET_LIST::GetLastVirtualPageNumber() const { int lastVirtualPageNumber = 1; diff --git a/eeschema/sch_sheet_path.h b/eeschema/sch_sheet_path.h index 79883923e5..1cc0dee91c 100644 --- a/eeschema/sch_sheet_path.h +++ b/eeschema/sch_sheet_path.h @@ -3,7 +3,7 @@ * * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2011 Wayne Stambaugh - * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023, 2024 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 @@ -409,6 +409,8 @@ public: void RemoveSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPath ); + void CheckForMissingSymbolInstances( const wxString& aProjectName ); + bool operator==( const SCH_SHEET_PATH& d1 ) const; bool operator!=( const SCH_SHEET_PATH& d1 ) const { return !( *this == d1 ) ; } @@ -688,6 +690,8 @@ public: void RemoveSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPath ); + void CheckForMissingSymbolInstances( const wxString& aProjectName ); + bool HasPath( const KIID_PATH& aPath ) const; bool ContainsSheet( const SCH_SHEET* aSheet ) const;