From 5475303ec2df057e47a2e1d363e9872c27fedbce Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sun, 24 Oct 2021 14:06:38 -0400 Subject: [PATCH] Allow loading secondary boards from Python Fixes https://gitlab.com/kicad/code/kicad/-/issues/9271 --- .../python/scripting/pcbnew_scripting_helpers.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/pcbnew/python/scripting/pcbnew_scripting_helpers.cpp b/pcbnew/python/scripting/pcbnew_scripting_helpers.cpp index f2b29fcb08..acb3db074b 100644 --- a/pcbnew/python/scripting/pcbnew_scripting_helpers.cpp +++ b/pcbnew/python/scripting/pcbnew_scripting_helpers.cpp @@ -75,10 +75,6 @@ void ScriptingSetPcbEditFrame( PCB_EDIT_FRAME* aPcbEditFrame ) BOARD* LoadBoard( wxString& aFileName ) { - // Loading a new board is not possible if running inside KiCad - if( s_PcbEditFrame ) - return nullptr; - if( aFileName.EndsWith( KiCadPcbFileExtension ) ) return LoadBoard( aFileName, IO_MGR::KICAD_SEXP ); else if( aFileName.EndsWith( LegacyPcbFileExtension ) ) @@ -129,9 +125,6 @@ PROJECT* GetDefaultProject() BOARD* LoadBoard( wxString& aFileName, IO_MGR::PCB_FILE_T aFormat ) { - // Loading a new board is not possible if running inside KiCad - wxASSERT( !s_PcbEditFrame ); - wxFileName pro = aFileName; pro.SetExt( ProjectFileExtension ); pro.MakeAbsolute(); @@ -145,9 +138,14 @@ BOARD* LoadBoard( wxString& aFileName, IO_MGR::PCB_FILE_T aFormat ) if( !project ) { - GetSettingsManager()->LoadProject( projectPath ); + GetSettingsManager()->LoadProject( projectPath, false ); project = GetSettingsManager()->GetProject( projectPath ); } + else if( s_PcbEditFrame && project == &GetSettingsManager()->Prj() ) + { + // Project is already loaded? Then so is the board + return s_PcbEditFrame->GetBoard(); + } // Board cannot be loaded without a project, so create the default project if( !project )