From d52d0d0aad5c0d44cc32bafe3959388da862c678 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Mon, 31 Mar 2025 11:17:00 -0400 Subject: [PATCH] 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 --- eeschema/sheet.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/eeschema/sheet.cpp b/eeschema/sheet.cpp index 82394b96d0..1a680783ba 100644 --- a/eeschema/sheet.cpp +++ b/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(); }