diff --git a/eeschema/eeschema.cpp b/eeschema/eeschema.cpp index c03a08f2aa..b28401d24f 100644 --- a/eeschema/eeschema.cpp +++ b/eeschema/eeschema.cpp @@ -95,12 +95,29 @@ static std::unique_ptr readSchematicFromFile( const std::string& aFil SETTINGS_MANAGER& manager = Pgm().GetSettingsManager(); - // TODO: this must load the schematic's project, not a default project. At the very minimum - // variable resolution won't work without the project, but there might also be issues with - // netclasses, etc. - manager.LoadProject( "" ); + wxFileName pro( aFilename ); + pro.SetExt( FILEEXT::ProjectFileExtension ); + pro.MakeAbsolute(); + wxString projectPath = pro.GetFullPath(); + + PROJECT* project = manager.GetProject( projectPath ); + + if( !project ) + { + if( wxFileExists( projectPath ) ) + { + // cli + manager.LoadProject( projectPath, true ); + project = manager.GetProject( projectPath ); + } + else + { + manager.LoadProject( "" ); + } + } + schematic->Reset(); - schematic->SetProject( &manager.Prj() ); + schematic->SetProject( project ); SCH_SHEET* rootSheet = pi->LoadSchematicFile( aFilename, schematic.get() ); if( !rootSheet ) diff --git a/pcbnew/pcbnew_jobs_handler.cpp b/pcbnew/pcbnew_jobs_handler.cpp index f0934a7d47..bde13fda15 100644 --- a/pcbnew/pcbnew_jobs_handler.cpp +++ b/pcbnew/pcbnew_jobs_handler.cpp @@ -59,6 +59,7 @@ #include #include #include +#include #include #include #include @@ -2288,6 +2289,11 @@ int PCBNEW_JOBS_HANDLER::JobExportDrc( JOB* aJob ) if( !brd ) return CLI::EXIT_CODES::ERR_INVALID_INPUT_FILE; + // Running DRC requires libraries be loaded, so make sure they have been + FOOTPRINT_LIBRARY_ADAPTER* adapter = PROJECT_PCB::FootprintLibAdapter( brd->GetProject() ); + adapter->AsyncLoad(); + adapter->BlockUntilLoaded(); + if( drcJob->GetConfiguredOutputPath().IsEmpty() ) { wxFileName fn = brd->GetFileName(); diff --git a/pcbnew/python/scripting/pcbnew_scripting_helpers.cpp b/pcbnew/python/scripting/pcbnew_scripting_helpers.cpp index 7d9b1b4cb3..ee3d6edd64 100644 --- a/pcbnew/python/scripting/pcbnew_scripting_helpers.cpp +++ b/pcbnew/python/scripting/pcbnew_scripting_helpers.cpp @@ -159,18 +159,20 @@ BOARD* LoadBoard( const wxString& aFileName, PCB_IO_MGR::PCB_FILE_T aFormat, boo // By default only the BMP handler is available. wxInitAllImageHandlers(); - PROJECT* project = GetSettingsManager()->GetProject( projectPath ); + SETTINGS_MANAGER& settingsManager = PgmOrNull() ? Pgm().GetSettingsManager() : *GetSettingsManager(); + + PROJECT* project = settingsManager.GetProject( projectPath ); if( !project ) { if( wxFileExists( projectPath ) ) { // cli - GetSettingsManager()->LoadProject( projectPath, aSetActive ); - project = GetSettingsManager()->GetProject( projectPath ); + settingsManager.LoadProject( projectPath, aSetActive ); + project = settingsManager.GetProject( projectPath ); } } - else if( s_PcbEditFrame && project == &GetSettingsManager()->Prj() ) + else if( s_PcbEditFrame && project == &settingsManager.Prj() ) { // Project is already loaded? Then so is the board return s_PcbEditFrame->GetBoard();