From 5d99aaf0a49df3b37986be324f34345988f43307 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Fri, 19 Apr 2024 14:33:22 -0400 Subject: [PATCH] Use correct project name when adding new symbol instances. When adding a sheet using a schematic from another project, set the project name for the new symbol instance data to the current project rather than the project name from the copied instance data. --- eeschema/dialogs/dialog_sheet_properties.cpp | 2 +- eeschema/sch_sheet_path.cpp | 16 +++++++++++++--- eeschema/sch_sheet_path.h | 11 +++++++++-- eeschema/sheet.cpp | 2 +- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/eeschema/dialogs/dialog_sheet_properties.cpp b/eeschema/dialogs/dialog_sheet_properties.cpp index af686524a9..902fb83c6f 100644 --- a/eeschema/dialogs/dialog_sheet_properties.cpp +++ b/eeschema/dialogs/dialog_sheet_properties.cpp @@ -640,7 +640,7 @@ bool DIALOG_SHEET_PROPERTIES::onSheetFilenameChanged( const wxString& aNewFilena SCH_SHEET_LIST sheetHierarchy( m_sheet ); // The hierarchy of the loaded file. - sheetHierarchy.AddNewSymbolInstances( currentSheet ); + sheetHierarchy.AddNewSymbolInstances( currentSheet, m_frame->Prj().GetProjectName() ); sheetHierarchy.AddNewSheetInstances( currentSheet, fullHierarchy.GetLastVirtualPageNumber() ); } diff --git a/eeschema/sch_sheet_path.cpp b/eeschema/sch_sheet_path.cpp index 5860e7ebc5..8756469b13 100644 --- a/eeschema/sch_sheet_path.cpp +++ b/eeschema/sch_sheet_path.cpp @@ -551,8 +551,11 @@ void SCH_SHEET_PATH::SetPageNumber( const wxString& aPageNumber ) } -void SCH_SHEET_PATH::AddNewSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPath ) +void SCH_SHEET_PATH::AddNewSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPath, + const wxString& aProjectName ) { + wxCHECK( !aProjectName.IsEmpty(), /* void */ ); + SCH_SHEET_PATH newSheetPath( aPrefixSheetPath ); SCH_SHEET_PATH currentSheetPath( *this ); @@ -569,12 +572,16 @@ void SCH_SHEET_PATH::AddNewSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPa if( symbol->GetInstance( newSymbolInstance, Path(), true ) ) { + newSymbolInstance.m_ProjectName = aProjectName; // Use an existing symbol instance for this path if it exists. + newSymbolInstance.m_Path = newSheetPath.Path(); symbol->AddHierarchicalReference( newSymbolInstance ); } else if( !symbol->GetInstances().empty() ) { + newSymbolInstance.m_ProjectName = aProjectName; + // Use the first symbol instance if any symbol instance data exists. newSymbolInstance = symbol->GetInstances()[0]; newSymbolInstance.m_Path = newSheetPath.Path(); @@ -582,6 +589,8 @@ void SCH_SHEET_PATH::AddNewSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPa } else { + newSymbolInstance.m_ProjectName = aProjectName; + // Fall back to the last saved symbol field and unit settings if there is no // instance data. newSymbolInstance.m_Path = newSheetPath.Path(); @@ -1226,10 +1235,11 @@ void SCH_SHEET_LIST::SetInitialPageNumbers() } -void SCH_SHEET_LIST::AddNewSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPath ) +void SCH_SHEET_LIST::AddNewSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPath, + const wxString& aProjectName ) { for( SCH_SHEET_PATH& sheetPath : *this ) - sheetPath.AddNewSymbolInstances( aPrefixSheetPath ); + sheetPath.AddNewSymbolInstances( aPrefixSheetPath, aProjectName ); } diff --git a/eeschema/sch_sheet_path.h b/eeschema/sch_sheet_path.h index 9fb5b7b411..28a92f96b8 100644 --- a/eeschema/sch_sheet_path.h +++ b/eeschema/sch_sheet_path.h @@ -391,8 +391,13 @@ public: * from the library symbol. * - If all else fails, set the reference to "U?", the unit to 1, and everything else to * an empty string. + * + * @param aPrefixSheetPath is the sheet path to prefix to this sheet path for the new symbol + * instance. + * @param aProjectName is the name of the project for the new symbol instance data. */ - void AddNewSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPath ); + void AddNewSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPath, + const wxString& aProjectName ); void RemoveSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPath ); @@ -665,8 +670,10 @@ public: * with \a aPrefixSheetPath. * * @param aPrefixSheetPath is the sheet path to append the new symbol instances to. + * @param aProjectName is the name of the project for the new symbol instance data. */ - void AddNewSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPath ); + void AddNewSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPath, + const wxString& aProjectName ); void AddNewSheetInstances( const SCH_SHEET_PATH& aPrefixSheetPath, int aLastVirtualPageNumber ); diff --git a/eeschema/sheet.cpp b/eeschema/sheet.cpp index 8f95ec137c..99e3904559 100644 --- a/eeschema/sheet.cpp +++ b/eeschema/sheet.cpp @@ -570,7 +570,7 @@ bool SCH_EDIT_FRAME::LoadSheetFromFile( SCH_SHEET* aSheet, SCH_SHEET_PATH* aCurr newScreen->MigrateSimModels(); // Attempt to create new symbol instances using the instance data loaded above. - sheetHierarchy.AddNewSymbolInstances( *aCurrentSheet ); + sheetHierarchy.AddNewSymbolInstances( *aCurrentSheet, Prj().GetProjectName() ); // Add new sheet instance data. sheetHierarchy.AddNewSheetInstances( *aCurrentSheet, hierarchy.GetLastVirtualPageNumber() );