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
This commit is contained in:
Wayne Stambaugh 2024-08-09 14:52:58 -04:00
parent 55b3ef2ff2
commit 0cf1110367
3 changed files with 47 additions and 5 deletions

View File

@ -185,7 +185,8 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& 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 )
{
@ -504,7 +505,8 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
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<wxString>& aFileSet, in
schematic.PruneOrphanedSymbolInstances( Prj().GetProjectName(), sheetList );
schematic.PruneOrphanedSheetInstances( Prj().GetProjectName(), sheetList );
sheetList.CheckForMissingSymbolInstances( Prj().GetProjectName() );
Schematic().ConnectionGraph()->Reset();

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
* 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 <refdes_utils.h>
#include <sch_screen.h>
#include <sch_item.h>
#include <sch_marker.h>
@ -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<SCH_SYMBOL*>( 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;

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
* 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;