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 5d99aaf0a4)
This commit is contained in:
Wayne Stambaugh 2024-04-19 14:33:22 -04:00
parent dd2f15c96d
commit bae3ccdfb5
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.
sheetHierarchy.AddNewSymbolInstances( currentSheet );
sheetHierarchy.AddNewSymbolInstances( currentSheet, m_frame->Prj().GetProjectName() );
sheetHierarchy.AddNewSheetInstances( currentSheet,
fullHierarchy.GetLastVirtualPageNumber() );
}

View File

@ -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 );
}

View File

@ -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 );

View File

@ -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() );