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.
This commit is contained in:
Wayne Stambaugh 2024-04-19 14:33:22 -04:00
parent b1dcd7ecf8
commit 5d99aaf0a4
4 changed files with 24 additions and 7 deletions

View File

@ -640,7 +640,7 @@ bool DIALOG_SHEET_PROPERTIES::onSheetFilenameChanged( const wxString& aNewFilena
SCH_SHEET_LIST sheetHierarchy( m_sheet ); // The hierarchy of the loaded file. 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, sheetHierarchy.AddNewSheetInstances( currentSheet,
fullHierarchy.GetLastVirtualPageNumber() ); fullHierarchy.GetLastVirtualPageNumber() );
} }

View File

@ -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 newSheetPath( aPrefixSheetPath );
SCH_SHEET_PATH currentSheetPath( *this ); 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 ) ) if( symbol->GetInstance( newSymbolInstance, Path(), true ) )
{ {
newSymbolInstance.m_ProjectName = aProjectName;
// Use an existing symbol instance for this path if it exists. // Use an existing symbol instance for this path if it exists.
newSymbolInstance.m_Path = newSheetPath.Path(); newSymbolInstance.m_Path = newSheetPath.Path();
symbol->AddHierarchicalReference( newSymbolInstance ); symbol->AddHierarchicalReference( newSymbolInstance );
} }
else if( !symbol->GetInstances().empty() ) else if( !symbol->GetInstances().empty() )
{ {
newSymbolInstance.m_ProjectName = aProjectName;
// Use the first symbol instance if any symbol instance data exists. // Use the first symbol instance if any symbol instance data exists.
newSymbolInstance = symbol->GetInstances()[0]; newSymbolInstance = symbol->GetInstances()[0];
newSymbolInstance.m_Path = newSheetPath.Path(); newSymbolInstance.m_Path = newSheetPath.Path();
@ -582,6 +589,8 @@ void SCH_SHEET_PATH::AddNewSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPa
} }
else else
{ {
newSymbolInstance.m_ProjectName = aProjectName;
// Fall back to the last saved symbol field and unit settings if there is no // Fall back to the last saved symbol field and unit settings if there is no
// instance data. // instance data.
newSymbolInstance.m_Path = newSheetPath.Path(); 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 ) for( SCH_SHEET_PATH& sheetPath : *this )
sheetPath.AddNewSymbolInstances( aPrefixSheetPath ); sheetPath.AddNewSymbolInstances( aPrefixSheetPath, aProjectName );
} }

View File

@ -391,8 +391,13 @@ public:
* from the library symbol. * from the library symbol.
* - If all else fails, set the reference to "U?", the unit to 1, and everything else to * - If all else fails, set the reference to "U?", the unit to 1, and everything else to
* an empty string. * 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 ); void RemoveSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPath );
@ -665,8 +670,10 @@ public:
* with \a aPrefixSheetPath. * with \a aPrefixSheetPath.
* *
* @param aPrefixSheetPath is the sheet path to append the new symbol instances to. * @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, void AddNewSheetInstances( const SCH_SHEET_PATH& aPrefixSheetPath,
int aLastVirtualPageNumber ); int aLastVirtualPageNumber );

View File

@ -570,7 +570,7 @@ bool SCH_EDIT_FRAME::LoadSheetFromFile( SCH_SHEET* aSheet, SCH_SHEET_PATH* aCurr
newScreen->MigrateSimModels(); newScreen->MigrateSimModels();
// Attempt to create new symbol instances using the instance data loaded above. // 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. // Add new sheet instance data.
sheetHierarchy.AddNewSheetInstances( *aCurrentSheet, hierarchy.GetLastVirtualPageNumber() ); sheetHierarchy.AddNewSheetInstances( *aCurrentSheet, hierarchy.GetLastVirtualPageNumber() );