Dialog Export step: fix an issue when exorting a modified board file.

the DIALOG_EXPORT_STEP uses a auto saved copy of the current board to
create the step file (using kicad_cli).
But this file is not associated to a corresponding .kicad_pro file, and
this can create some issues (like the KIPRJMOD not defined)
So create a copy of the current board to export associated to the auto saved board file.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/16973
This commit is contained in:
jean-pierre charras 2024-05-20 20:58:18 +02:00
parent 0ff59bc60e
commit 59a2de7408
1 changed files with 19 additions and 1 deletions

View File

@ -47,6 +47,7 @@
#include <widgets/text_ctrl_eval.h>
#include <wildcards_and_files_ext.h>
#include <filename_resolver.h>
#include <settings/settings_manager.h>
class DIALOG_EXPORT_STEP : public DIALOG_EXPORT_STEP_BASE
@ -318,6 +319,9 @@ void PCB_EDIT_FRAME::OnExportSTEP( wxCommandEvent& event )
{
wxFileName brdFile = GetBoard()->GetFileName();
// The project filename (.kicad_pro) of the auto saved board filename, if it is created
wxFileName autosaveProjFile;
if( GetScreen()->IsContentModified() || brdFile.GetFullPath().empty() )
{
if( !doAutoSave() )
@ -327,12 +331,26 @@ void PCB_EDIT_FRAME::OnExportSTEP( wxCommandEvent& event )
return;
}
wxString autosaveFileName = FILEEXT::AutoSaveFilePrefix + brdFile.GetName();
// Create a dummy .kicad_pro file for this auto saved board file.
// this is useful to use some settings (like project path and name)
// Because doAutoSave() works, the target directory exists and is writable
autosaveProjFile = brdFile;
autosaveProjFile.SetName( autosaveFileName );
autosaveProjFile.SetExt( "kicad_pro" );
// Use auto-saved board for export
brdFile.SetName( FILEEXT::AutoSaveFilePrefix + brdFile.GetName() );
GetSettingsManager()->SaveProjectCopy( autosaveProjFile.GetFullPath(), GetBoard()->GetProject() );
brdFile.SetName( autosaveFileName );
}
DIALOG_EXPORT_STEP dlg( this, brdFile.GetFullPath() );
dlg.ShowModal();
// If a dummy .kicad_pro file is created, delete it now it is useless.
if( !autosaveProjFile.GetFullPath().IsEmpty() )
wxRemoveFile( autosaveProjFile.GetFullPath() );
}