Fix yet another symbol instance issue when loading legacy schematics.

This commit is contained in:
Wayne Stambaugh 2022-10-15 14:15:51 -04:00
parent 254dff2813
commit f782323960
4 changed files with 20 additions and 2 deletions

View File

@ -431,7 +431,7 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
// Legacy schematic can have duplicate time stamps so fix that before converting // Legacy schematic can have duplicate time stamps so fix that before converting
// to the s-expression format. // to the s-expression format.
schematic.ReplaceDuplicateTimeStamps(); schematic.ReplaceDuplicateTimeStamps();
schematic.SetLegacySymbolInstanceData(); // schematic.SetLegacySymbolInstanceData();
// Allow the schematic to be saved to new file format without making any edits. // Allow the schematic to be saved to new file format without making any edits.
OnModify(); OnModify();

View File

@ -679,12 +679,15 @@ void SCH_EDIT_FRAME::CreateScreens()
m_schematic->Reset(); m_schematic->Reset();
m_schematic->SetProject( &Prj() ); m_schematic->SetProject( &Prj() );
m_schematic->SetRoot( new SCH_SHEET( m_schematic ) ); SCH_SHEET* rootSheet = new SCH_SHEET( m_schematic );
m_schematic->SetRoot( rootSheet );
SCH_SCREEN* rootScreen = new SCH_SCREEN( m_schematic ); SCH_SCREEN* rootScreen = new SCH_SCREEN( m_schematic );
const_cast<KIID&>( rootSheet->m_Uuid ) = rootScreen->GetUuid();
m_schematic->Root().SetScreen( rootScreen ); m_schematic->Root().SetScreen( rootScreen );
SetScreen( Schematic().RootScreen() ); SetScreen( Schematic().RootScreen() );
m_schematic->RootScreen()->SetFileName( wxEmptyString ); m_schematic->RootScreen()->SetFileName( wxEmptyString );
// Don't leave root page number empty // Don't leave root page number empty

View File

@ -194,6 +194,8 @@ void SCH_LEGACY_PLUGIN::loadHierarchy( SCH_SHEET* aSheet )
{ {
SCH_SCREEN* screen = nullptr; SCH_SCREEN* screen = nullptr;
m_currentSheet = aSheet;
if( !aSheet->GetScreen() ) if( !aSheet->GetScreen() )
{ {
// SCH_SCREEN objects store the full path and file name where the SCH_SHEET object only // SCH_SCREEN objects store the full path and file name where the SCH_SHEET object only
@ -226,6 +228,9 @@ void SCH_LEGACY_PLUGIN::loadHierarchy( SCH_SHEET* aSheet )
aSheet->SetScreen( new SCH_SCREEN( m_schematic ) ); aSheet->SetScreen( new SCH_SCREEN( m_schematic ) );
aSheet->GetScreen()->SetFileName( fileName.GetFullPath() ); aSheet->GetScreen()->SetFileName( fileName.GetFullPath() );
if( aSheet == m_rootSheet )
const_cast<KIID&>( aSheet->m_Uuid ) = aSheet->GetScreen()->GetUuid();
try try
{ {
loadFile( fileName.GetFullPath(), aSheet->GetScreen() ); loadFile( fileName.GetFullPath(), aSheet->GetScreen() );
@ -1338,6 +1343,15 @@ SCH_SYMBOL* SCH_LEGACY_PLUGIN::loadSymbol( LINE_READER& aReader )
} }
else if( strCompare( "$EndComp", line ) ) else if( strCompare( "$EndComp", line ) )
{ {
if( !m_appending && ( m_currentSheet == m_rootSheet ) )
{
KIID_PATH path;
path.push_back( m_rootSheet->GetScreen()->GetUuid() );
symbol->AddHierarchicalReference( path,
symbol->GetField( REFERENCE_FIELD )->GetText(),
symbol->GetUnit() );
}
// Ensure all flags (some are set by previous initializations) are reset: // Ensure all flags (some are set by previous initializations) are reset:
symbol->ClearFlags(); symbol->ClearFlags();
return symbol.release(); return symbol.release();

View File

@ -191,6 +191,7 @@ protected:
wxString m_path; ///< Root project path for loading child sheets. wxString m_path; ///< Root project path for loading child sheets.
std::stack<wxString> m_currentPath; ///< Stack to maintain nested sheet paths std::stack<wxString> m_currentPath; ///< Stack to maintain nested sheet paths
SCH_SHEET* m_rootSheet; ///< The root sheet of the schematic being loaded. SCH_SHEET* m_rootSheet; ///< The root sheet of the schematic being loaded.
SCH_SHEET* m_currentSheet; ///< The sheet currently being loaded.
OUTPUTFORMATTER* m_out; ///< The formatter for saving SCH_SCREEN objects. OUTPUTFORMATTER* m_out; ///< The formatter for saving SCH_SCREEN objects.
SCH_LEGACY_PLUGIN_CACHE* m_cache; SCH_LEGACY_PLUGIN_CACHE* m_cache;
SCHEMATIC* m_schematic; SCHEMATIC* m_schematic;