Fix KIPRJMOD by setting the project as active by modifying the board loading helper

Fixes https://gitlab.com/kicad/code/kicad/-/issues/16973
This commit is contained in:
Marek Roszko 2024-02-15 23:06:11 -05:00
parent 08bdf1abae
commit 762c159b96
3 changed files with 62 additions and 17 deletions

View File

@ -107,7 +107,7 @@ int PCBNEW_JOBS_HANDLER::JobExportStep( JOB* aJob )
if( aJob->IsCli() )
m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
BOARD* brd = LoadBoard( aStepJob->m_filename );
BOARD* brd = LoadBoard( aStepJob->m_filename, true );
brd->GetProject()->ApplyTextVars( aJob->GetVarOverrides() );
if( aStepJob->m_outputFile.IsEmpty() )
@ -231,7 +231,7 @@ int PCBNEW_JOBS_HANDLER::JobExportSvg( JOB* aJob )
if( aJob->IsCli() )
m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
BOARD* brd = LoadBoard( aSvgJob->m_filename );
BOARD* brd = LoadBoard( aSvgJob->m_filename, true );
loadOverrideDrawingSheet( brd, aSvgJob->m_drawingSheet );
brd->GetProject()->ApplyTextVars( aJob->GetVarOverrides() );
@ -257,7 +257,7 @@ int PCBNEW_JOBS_HANDLER::JobExportDxf( JOB* aJob )
if( aJob->IsCli() )
m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
BOARD* brd = LoadBoard( aDxfJob->m_filename );
BOARD* brd = LoadBoard( aDxfJob->m_filename, true );
loadOverrideDrawingSheet( brd, aDxfJob->m_drawingSheet );
brd->GetProject()->ApplyTextVars( aJob->GetVarOverrides() );
@ -314,7 +314,7 @@ int PCBNEW_JOBS_HANDLER::JobExportPdf( JOB* aJob )
if( aJob->IsCli() )
m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
BOARD* brd = LoadBoard( aPdfJob->m_filename );
BOARD* brd = LoadBoard( aPdfJob->m_filename, true );
loadOverrideDrawingSheet( brd, aPdfJob->m_drawingSheet );
brd->GetProject()->ApplyTextVars( aJob->GetVarOverrides() );
@ -385,7 +385,7 @@ int PCBNEW_JOBS_HANDLER::JobExportGerbers( JOB* aJob )
if( aJob->IsCli() )
m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
BOARD* brd = LoadBoard( aGerberJob->m_filename );
BOARD* brd = LoadBoard( aGerberJob->m_filename, true );
loadOverrideDrawingSheet( brd, aGerberJob->m_drawingSheet );
PCB_PLOT_PARAMS boardPlotOptions = brd->GetPlotOptions();
@ -519,7 +519,7 @@ int PCBNEW_JOBS_HANDLER::JobExportGerber( JOB* aJob )
if( aJob->IsCli() )
m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
BOARD* brd = LoadBoard( aGerberJob->m_filename );
BOARD* brd = LoadBoard( aGerberJob->m_filename, true );
brd->GetProject()->ApplyTextVars( aJob->GetVarOverrides() );
if( aGerberJob->m_outputFile.IsEmpty() )
@ -572,7 +572,7 @@ int PCBNEW_JOBS_HANDLER::JobExportDrill( JOB* aJob )
if( aJob->IsCli() )
m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
BOARD* brd = LoadBoard( aDrillJob->m_filename );
BOARD* brd = LoadBoard( aDrillJob->m_filename, true );
// ensure output dir exists
wxFileName fn( aDrillJob->m_outputDir + wxT( "/" ) );
@ -694,7 +694,7 @@ int PCBNEW_JOBS_HANDLER::JobExportPos( JOB* aJob )
if( aJob->IsCli() )
m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
BOARD* brd = LoadBoard( aPosJob->m_filename );
BOARD* brd = LoadBoard( aPosJob->m_filename, true );
if( aPosJob->m_outputFile.IsEmpty() )
{
@ -964,7 +964,7 @@ int PCBNEW_JOBS_HANDLER::JobExportDrc( JOB* aJob )
if( aJob->IsCli() )
m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
BOARD* brd = LoadBoard( drcJob->m_filename );
BOARD* brd = LoadBoard( drcJob->m_filename, true );
brd->GetProject()->ApplyTextVars( aJob->GetVarOverrides() );
if( drcJob->m_outputFile.IsEmpty() )
@ -1134,7 +1134,7 @@ int PCBNEW_JOBS_HANDLER::JobExportIpc2581( JOB* aJob )
if( job->IsCli() )
m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
BOARD* brd = LoadBoard( job->m_filename );
BOARD* brd = LoadBoard( job->m_filename, true );
if( job->m_outputFile.IsEmpty() )
{

View File

@ -84,15 +84,22 @@ void ScriptingOnDestructPcbEditFrame( PCB_EDIT_FRAME* aPcbEditFrame )
s_PcbEditFrame = nullptr;
}
BOARD* LoadBoard( wxString& aFileName )
BOARD* LoadBoard( wxString& aFileName, bool aSetActive )
{
if( aFileName.EndsWith( FILEEXT::KiCadPcbFileExtension ) )
return LoadBoard( aFileName, PCB_IO_MGR::KICAD_SEXP );
return LoadBoard( aFileName, PCB_IO_MGR::KICAD_SEXP, aSetActive );
else if( aFileName.EndsWith( FILEEXT::LegacyPcbFileExtension ) )
return LoadBoard( aFileName, PCB_IO_MGR::LEGACY );
return LoadBoard( aFileName, PCB_IO_MGR::LEGACY, aSetActive );
// as fall back for any other kind use the legacy format
return LoadBoard( aFileName, PCB_IO_MGR::LEGACY );
return LoadBoard( aFileName, PCB_IO_MGR::LEGACY, aSetActive );
}
BOARD* LoadBoard( wxString& aFileName )
{
return LoadBoard( aFileName, false );
}
@ -133,8 +140,12 @@ PROJECT* GetDefaultProject()
return project;
}
BOARD* LoadBoard( wxString& aFileName, PCB_IO_MGR::PCB_FILE_T aFormat )
{
return LoadBoard( aFileName, aFormat, false );
}
BOARD* LoadBoard( wxString& aFileName, PCB_IO_MGR::PCB_FILE_T aFormat, bool aSetActive )
{
wxFileName pro = aFileName;
pro.SetExt( FILEEXT::ProjectFileExtension );
@ -151,7 +162,8 @@ BOARD* LoadBoard( wxString& aFileName, PCB_IO_MGR::PCB_FILE_T aFormat )
{
if( wxFileExists( projectPath ) )
{
GetSettingsManager()->LoadProject( projectPath, false );
// cli
GetSettingsManager()->LoadProject( projectPath, aSetActive );
project = GetSettingsManager()->GetProject( projectPath );
}
}

View File

@ -49,10 +49,43 @@ void ScriptingOnDestructPcbEditFrame( PCB_EDIT_FRAME* aPCBEdaFrame );
// For Python scripts: return the current board.
BOARD* GetBoard();
/**
* Loads a board from file using the specified file io handler
*
* This function does not set the board project as the active one
* @return a pointer to the board if it was created, or None if not
*/
BOARD* LoadBoard( wxString& aFileName, PCB_IO_MGR::PCB_FILE_T aFormat );
#ifndef SWIG
/**
* Loads a board from file using the specified file io handler
*
* Hidden from SWIG as aSetActive should not be used by python, but cli also leverages this function
*/
BOARD* LoadBoard( wxString& aFileName, PCB_IO_MGR::PCB_FILE_T aFormat, bool aSetActive );
#endif
// Default LoadBoard() to load .kicad_pcb files:.
BOARD* LoadBoard( wxString& aFileName );
#ifndef SWIG
/**
* Loads a board from file
* This function identifies the file type by extension and determines the correct file io to use
*
* Hidden from SWIG as aSetActive should not be used by python, but cli also leverages this function
*/
BOARD* LoadBoard( wxString& aFileName, bool aSetActive );
#endif
/**
* Loads a board from file
* This function identifies the file type by extension and determines the correct file io to use
*
* This function does not set the board project as the active one
* @return a pointer to the board if it was created, or None if not
*/
BOARD* LoadBoard( wxString& aFileName );
/**
* Creates a new board and project with the given filename (will overwrite existing files!)