From e14aef9bd555a65f87273a440056d89640254e41 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 21 Sep 2023 17:02:15 +0100 Subject: [PATCH] Correct path of pcb drawing sheet file on saveAs. Fixes https://gitlab.com/kicad/code/kicad/-/issues/15551 (cherry picked from commit 722a90213cfd45479a897a201963c0cf324596b3) --- common/project/project_file.cpp | 33 +++++++++++++++++++++++++++++++++ include/project/project_file.h | 3 ++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/common/project/project_file.cpp b/common/project/project_file.cpp index 13a2fe0797..034fc7f1c8 100644 --- a/common/project/project_file.cpp +++ b/common/project/project_file.cpp @@ -569,9 +569,42 @@ bool PROJECT_FILE::SaveToFile( const wxString& aDirectory, bool aForce ) bool PROJECT_FILE::SaveAs( const wxString& aDirectory, const wxString& aFile ) { + wxFileName oldFilename( GetFilename() ); + wxString oldProjectName = oldFilename.GetName(); + wxString oldProjectPath = oldFilename.GetPath(); + Set( "meta.filename", aFile + "." + ProjectFileExtension ); SetFilename( aFile ); + auto updatePath = + [&]( wxString& aPath ) + { + if( aPath.StartsWith( oldProjectName + wxS( "." ) ) ) + aPath.Replace( oldProjectName, aFile, false ); + else if( aPath.StartsWith( oldProjectPath + wxS( "/" ) ) ) + aPath.Replace( oldProjectPath, aDirectory, false ); + }; + + updatePath( m_BoardDrawingSheetFile ); + + for( int ii = LAST_PATH_FIRST; ii < (int) LAST_PATH_SIZE; ++ii ) + updatePath( m_PcbLastPath[ ii ] ); + + auto updatePathByPtr = + [&]( const std::string& aPtr ) + { + if( std::optional path = Get( aPtr ) ) + { + updatePath( path.value() ); + Set( aPtr, path.value() ); + } + }; + + updatePathByPtr( "schematic.page_layout_descr_file" ); + updatePathByPtr( "schematic.plot_directory" ); + updatePathByPtr( "schematic.ngspice.workbook_filename" ); + updatePathByPtr( "pcbnew.page_layout_descr_file" ); + // While performing Save As, we have already checked that we can write to the directory // so don't carry the previous flag SetReadOnly( false ); diff --git a/include/project/project_file.h b/include/project/project_file.h index 2d52a42225..39fffb5b29 100644 --- a/include/project/project_file.h +++ b/include/project/project_file.h @@ -45,7 +45,8 @@ typedef std::pair FILE_INFO_PAIR; */ enum LAST_PATH_TYPE : unsigned int { - LAST_PATH_NETLIST = 0, + LAST_PATH_FIRST = 0, + LAST_PATH_NETLIST = LAST_PATH_FIRST, LAST_PATH_STEP, LAST_PATH_IDF, LAST_PATH_VRML,