From bae3ccdfb573a166dc9e52511fb262a65eb8bc4d 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. (cherry picked from commit 5d99aaf0a49df3b37986be324f34345988f43307) --- 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 701eb39360..810a620b3b 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 69a59b2bd8..717bcd3e87 100644 --- a/eeschema/sch_sheet_path.cpp +++ b/eeschema/sch_sheet_path.cpp @@ -562,8 +562,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 ); @@ -580,12 +583,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(); @@ -593,6 +600,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(); @@ -1237,10 +1246,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 cd84dd3a50..1097460f2a 100644 --- a/eeschema/sch_sheet_path.h +++ b/eeschema/sch_sheet_path.h @@ -395,8 +395,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 ); @@ -669,8 +674,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 e11bd1da56..a25220992d 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() );