Eeschema: fix broken sheet paths when adding existing schematic.

All existing sheet schematic file paths were completely trashed when adding
a new sheet from an existing file outside of the project path.
This commit is contained in:
Wayne Stambaugh 2021-05-27 14:04:56 -04:00
parent 2817c3b3de
commit b1572dd56b
1 changed files with 5 additions and 16 deletions

View File

@ -110,7 +110,6 @@ bool SCH_EDIT_FRAME::LoadSheetFromFile( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHier
wxFileName tmp; wxFileName tmp;
wxFileName currentSheetFileName; wxFileName currentSheetFileName;
bool libTableChanged = false; bool libTableChanged = false;
SCH_SCREEN* currentScreen = aHierarchy->LastScreen();
SCH_IO_MGR::SCH_FILE_T schFileType = SCH_IO_MGR::GuessPluginTypeFromSchPath( aFileName ); SCH_IO_MGR::SCH_FILE_T schFileType = SCH_IO_MGR::GuessPluginTypeFromSchPath( aFileName );
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( schFileType ) ); SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( schFileType ) );
std::unique_ptr< SCH_SHEET> newSheet = std::make_unique<SCH_SHEET>( &Schematic() ); std::unique_ptr< SCH_SHEET> newSheet = std::make_unique<SCH_SHEET>( &Schematic() );
@ -206,11 +205,11 @@ bool SCH_EDIT_FRAME::LoadSheetFromFile( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHier
wxMessageDialog::ButtonLabel cancelButtonLabel( _( "Cancel Load" ) ); wxMessageDialog::ButtonLabel cancelButtonLabel( _( "Cancel Load" ) );
if( fileName.GetPathWithSep() == Prj().GetProjectPath() if( fileName.GetPathWithSep() == Prj().GetProjectPath()
&& !prjScreens.HasSchematic( fullFilename ) ) && !prjScreens.HasSchematic( fullFilename ) )
{ {
// A schematic in the current project path that isn't part of the current project. // A schematic in the current project path that isn't part of the current project.
// It's possible the user copied this schematic from another project so the library // It's possible the user copied this schematic from another project so the library
// links may not be avaible. Even this is check is no guarantee that all symbol // links may not be available. Even this is check is no guarantee that all symbol
// library links are valid but it's better than nothing. // library links are valid but it's better than nothing.
for( const auto& name : names ) for( const auto& name : names )
{ {
@ -282,7 +281,7 @@ bool SCH_EDIT_FRAME::LoadSheetFromFile( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHier
{ {
msg.Printf( _( "An error occurred loading the symbol library table \"%s\"." ), msg.Printf( _( "An error occurred loading the symbol library table \"%s\"." ),
symLibTableFn.GetFullPath() ); symLibTableFn.GetFullPath() );
DisplayErrorMessage( NULL, msg, ioe.What() ); DisplayErrorMessage( nullptr, msg, ioe.What() );
return false; return false;
} }
} }
@ -435,16 +434,6 @@ bool SCH_EDIT_FRAME::LoadSheetFromFile( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHier
SCH_SCREEN* newScreen = newSheet->GetScreen(); SCH_SCREEN* newScreen = newSheet->GetScreen();
wxCHECK_MSG( newScreen, false, "No screen defined for sheet." ); wxCHECK_MSG( newScreen, false, "No screen defined for sheet." );
// Set all sheets loaded into the correct sheet file paths.
for( SCH_ITEM* aItem : currentScreen->Items().OfType( SCH_SHEET_T ) )
{
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( aItem );
if( wxFileName( sheet->GetFileName() ).IsRelative( wxPATH_UNIX ) )
sheet->SetFileName( topLevelSheetPath + sheet->GetFileName() );
}
if( libTableChanged ) if( libTableChanged )
{ {
Prj().SchSymbolLibTable()->Save( Prj().GetProjectPath() + Prj().SchSymbolLibTable()->Save( Prj().GetProjectPath() +
@ -467,7 +456,7 @@ bool SCH_EDIT_FRAME::LoadSheetFromFile( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHier
bool SCH_EDIT_FRAME::EditSheetProperties( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHierarchy, bool SCH_EDIT_FRAME::EditSheetProperties( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHierarchy,
bool* aClearAnnotationNewItems ) bool* aClearAnnotationNewItems )
{ {
if( aSheet == NULL || aHierarchy == NULL ) if( aSheet == nullptr || aHierarchy == nullptr )
return false; return false;
// Get the new texts // Get the new texts
@ -578,7 +567,7 @@ bool SCH_EDIT_FRAME::AllowCaseSensitiveFileNameClashes( const wxString& aSchemat
wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION ); wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION );
dlg.ShowCheckBox( _( "Do not show this message again." ) ); dlg.ShowCheckBox( _( "Do not show this message again." ) );
dlg.SetYesNoLabels( wxMessageDialog::ButtonLabel( _( "Create New Sheet" ) ), dlg.SetYesNoLabels( wxMessageDialog::ButtonLabel( _( "Create New Sheet" ) ),
wxMessageDialog::ButtonLabel( _( "Discard New Sheet" ) ) ); wxMessageDialog::ButtonLabel( _( "Discard New Sheet" ) ) );
if( dlg.ShowModal() == wxID_NO ) if( dlg.ShowModal() == wxID_NO )
return false; return false;