Browse Source

Don't clobber SCH_SCREEN paths when adding new sheet from existing file.

The screen path will always be the correct absolute path.  Otherwise it
would not be possible to load it.

Don't reset the first sheet file path to relative if the user did not
request it.

Don't use results of a failed call to wxFileName::MakeRelative() to set
sub-sheet file paths.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/20502
revert-0c36e162
Wayne Stambaugh 9 months ago
parent
commit
d52d0d0aad
  1. 16
      eeschema/sheet.cpp

16
eeschema/sheet.cpp

@ -248,9 +248,14 @@ bool SCH_EDIT_FRAME::LoadSheetFromFile( SCH_SHEET* aSheet, SCH_SHEET_PATH* aCurr
for( const SCH_SHEET_PATH& sheetPath : loadedSheets )
{
// Skip the loaded sheet since the user already determined if the file path should
// be relative or absolute.
if( sheetPath.size() == 1 )
continue;
wxString lastSheetPath = Prj().GetProjectPath();
for( unsigned i = 0; i < sheetPath.size(); i++ )
for( unsigned i = 1; i < sheetPath.size(); i++ )
{
SCH_SHEET* sheet = sheetPath.at( i );
wxCHECK2( sheet, continue );
@ -258,14 +263,6 @@ bool SCH_EDIT_FRAME::LoadSheetFromFile( SCH_SHEET* aSheet, SCH_SHEET_PATH* aCurr
SCH_SCREEN* screen = sheet->GetScreen();
wxCHECK2( screen, continue );
// Fix screen path to be based on the current project path.
// Basically, make an absolute screen path relative to the schematic file
// we started with, then make it absolute again using the current project path.
wxFileName screenFileName = screen->GetFileName();
screenFileName.MakeRelativeTo( fileName.GetPath() );
screenFileName.MakeAbsolute( Prj().GetProjectPath() );
screen->SetFileName( screenFileName.GetFullPath() );
// Use the screen file name which should always be absolute.
wxFileName loadedSheetFileName = screen->GetFileName();
wxCHECK2( loadedSheetFileName.IsAbsolute(), continue );
@ -278,6 +275,7 @@ bool SCH_EDIT_FRAME::LoadSheetFromFile( SCH_SHEET* aSheet, SCH_SHEET_PATH* aCurr
else
sheetFileName = loadedSheetFileName.GetFullPath();
sheetFileName.Replace( wxT( "\\" ), wxT( "/" ) );
sheet->SetFileName( sheetFileName );
lastSheetPath = loadedSheetFileName.GetPath();
}

Loading…
Cancel
Save