36#include <wx/snglinst.h>
64#include <python_scripting.h>
70#include <wx/tokenzr.h>
100 void Reset()
override;
238 std::vector<TOOL_ACTION*> actions;
239 std::vector<ACTION_TOOLBAR_CONTROL*> controls;
242 actions.push_back( action );
245 controls.push_back( control );
295 BOARD* board =
nullptr;
299 board =
static_cast<PCB_EDIT_FRAME*
>( boardProvider )->
GetBoard();
309 std::vector<TOOL_ACTION*> actions;
310 std::vector<ACTION_TOOLBAR_CONTROL*> controls;
313 actions.push_back( action );
316 controls.push_back( control );
322 return new PANEL_PCBNEW_ACTION_PLUGINS( aParent );
325 return new PANEL_3D_DISPLAY_OPTIONS( aParent );
328 return new PANEL_3D_OPENGL_OPTIONS( aParent );
331 return new PANEL_3D_RAYTRACING_OPTIONS( aParent );
338 std::vector<TOOL_ACTION*> actions;
339 std::vector<ACTION_TOOLBAR_CONTROL*> controls;
342 actions.push_back( action );
345 controls.push_back( control );
347 return new PANEL_TOOLBAR_CUSTOMIZATION( aParent, cfg, tb, actions, controls );
392 void SaveFileAs(
const wxString& aProjectBasePath,
const wxString& aSrcProjectName,
393 const wxString& aNewProjectBasePath,
const wxString& aNewProjectName,
394 const wxString& aSrcFilePath, wxString& aErrors )
override;
459 m_jobHandler = std::make_unique<PCBNEW_JOBS_HANDLER>( aKiway );
483 const wxString& aNewProjectBasePath,
const wxString& aNewProjectName,
484 const wxString& aSrcFilePath, wxString& aErrors )
486 wxFileName destFile( aSrcFilePath );
487 wxString destPath = destFile.GetPathWithSep();
488 wxUniChar pathSep = wxFileName::GetPathSeparator();
489 wxString ext = destFile.GetExt();
491 if( destPath.StartsWith( aProjectBasePath + pathSep ) )
492 destPath.Replace( aProjectBasePath, aNewProjectBasePath,
false );
494 wxString srcProjectFootprintLib = pathSep + aSrcProjectName + wxT(
".pretty" ) + pathSep;
495 wxString newProjectFootprintLib = pathSep + aNewProjectName + wxT(
".pretty" ) + pathSep;
497 destPath.Replace( srcProjectFootprintLib, newProjectFootprintLib,
true );
499 destFile.SetPath( destPath );
504 if( destFile.GetName() == aSrcProjectName )
505 destFile.SetName( aNewProjectName );
508 [&](
const std::string& token, wxString& value )
510 if( token ==
"sheetfile" )
512 for( const wxString& extension : { wxT(
".sch" ), wxT(
".kicad_sch" ) } )
514 if( value == aSrcProjectName + extension )
516 value = aNewProjectName + extension;
519 else if( value == aProjectBasePath +
"/" + aSrcProjectName + extension )
521 value = aNewProjectBasePath +
"/" + aNewProjectName + extension;
524 else if( value.StartsWith( aProjectBasePath ) )
526 value.Replace( aProjectBasePath, aNewProjectBasePath, false );
538 if( destFile.GetName() == aSrcProjectName )
539 destFile.SetName( aNewProjectName );
541 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
547 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
553 else if( ext == wxT(
"rpt" ) )
559 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
563 wxFileName libTableFn( aSrcFilePath );
565 libTable.SetPath( destFile.GetFullPath() );
568 for( LIBRARY_TABLE_ROW& row : libTable.Rows() )
570 wxString uri = row.URI();
572 uri.Replace( wxT(
"/" ) + aSrcProjectName + wxT(
".pretty" ),
573 wxT(
"/" ) + aNewProjectName + wxT(
".pretty" ) );
578 libTable.Save().map_error(
579 [&](
const LIBRARY_ERROR& aError )
583 if( !aErrors.empty() )
584 aErrors += wxT(
"\n" );
586 msg.Printf(
_(
"Cannot copy file '%s'." ), destFile.GetFullPath() );
592 wxFAIL_MSG( wxT(
"Unexpected filetype for Pcbnew::SaveFileAs()" ) );
599 return m_jobHandler->RunJob( aJob, aReporter, aProgressReporter );
611 constexpr static int interval = 150;
612 constexpr static int timeLimit = 120000;
625 [
this, aKiway]() ->
void
627 std::shared_ptr<BACKGROUND_JOB_REPORTER> reporter =
634 reporter->Report(
_(
"Loading Footprint Libraries" ) );
645 std::this_thread::sleep_for( std::chrono::milliseconds( interval ) );
649 float progress = *loadStatus;
650 reporter->SetCurrentProgress( progress );
657 reporter->SetCurrentProgress( 1 );
663 if( elapsed > timeLimit )
672 wxLogTrace(
traceLibraries,
"pcbnew PreloadLibraries: adapter errors.IsEmpty()=%d, length=%zu",
673 errors.IsEmpty(), errors.length() );
675 if( !errors.IsEmpty() )
679 wxLogTrace(
traceLibraries,
" -> adapter: collected %zu messages", messages.size() );
681 if( !messages.empty() )
686 wxLogTrace(
traceLibraries,
" -> no errors from footprint adapter" );
690 GFootprintList.ReadFootprintFiles( adapter,
nullptr, reporter.get() );
697 std::vector<LOAD_MESSAGE> messages =
700 wxLogTrace(
traceLibraries,
" -> GFootprintList: collected %zu messages", messages.size() );
702 if( !messages.empty() )
707 wxLogTrace(
traceLibraries,
" -> no errors from GFootprintList" );
714 std::string payload =
"";
constexpr EDA_IU_SCALE pcbIUScale
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
static std::list< TOOL_ACTION * > & GetActionList()
Return list of TOOL_ACTIONs.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
std::shared_ptr< BACKGROUND_JOB > Create(const wxString &aName)
Creates a background job with the given name.
void Remove(std::shared_ptr< BACKGROUND_JOB > job)
Removes the given background job from any lists and frees it.
static PROGRESS_REPORTER & GetInstance()
static REPORTER & GetInstance()
The base frame for deriving all KiCad main window classes.
An simple container class that lets us dispatch output jobs to kifaces.
KIFACE_BASE(const char *aKifaceName, KIWAY::FACE_T aId)
void InitSettings(APP_SETTINGS_BASE *aSettings)
void end_common()
Common things to do for a top program module, during OnKifaceEnd();.
APP_SETTINGS_BASE * KifaceSettings() const
bool start_common(int aCtlBits)
Common things to do for a top program module, during OnKifaceStart().
int m_start_flags
flags provided in OnKifaceStart()
bool IsSingle() const
Is this KIFACE running under single_top?
void SetKiway(wxWindow *aDest, KIWAY *aKiway)
It is only used for debugging, since "this" is not a wxWindow*.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr, bool aFromOtherThread=false)
Send aPayload to aDestination from aSource.
FACE_T
Known KIFACE implementations.
virtual void CommonSettingsChanged(int aFlags=0)
Call CommonSettingsChanged() on all KIWAY_PLAYERs.
virtual PROJECT & Prj() const
Return the PROJECT associated with this KIWAY.
std::optional< float > AsyncLoadProgress() const
Returns async load progress between 0.0 and 1.0, or nullopt if load is not in progress.
wxString GetLibraryLoadErrors() const
Returns all library load errors as newline-separated strings for display.
The main frame for Pcbnew.
Container for data for KiCad programs.
virtual BACKGROUND_JOBS_MONITOR & GetBackgroundJobMonitor() const
void ClearLibraryLoadMessages()
Clear library load messages from all registered status bars.
void AddLibraryLoadMessages(const std::vector< LOAD_MESSAGE > &aMessages)
Add library load messages to all registered status bars.
virtual SETTINGS_MANAGER & GetSettingsManager() const
A progress reporter interface for use in multi-threaded environments.
static FOOTPRINT_LIBRARY_ADAPTER * FootprintLibAdapter(PROJECT *aProject)
A pure virtual class used to derive REPORTER objects from.
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Take ownership of the pointer passed in.
UNITS_PROVIDER(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits)
EDA_UNITS GetUserUnits() const
void SetUserUnits(EDA_UNITS aUnits)
This file is part of the common library.
#define KICAD_PCB_PORT_SERVICE_NUMBER
Pcbnew listens on this port for commands from Eeschema.
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
@ PANEL_FP_DEFAULT_GRAPHICS_VALUES
@ PANEL_FP_DISPLAY_OPTIONS
@ DIALOG_PCB_LIBRARY_TABLE
@ FRAME_FOOTPRINT_PREVIEW
@ FRAME_FOOTPRINT_CHOOSER
@ PANEL_FP_DEFAULT_FIELDS
@ PANEL_PCB_ACTION_PLUGINS
@ PANEL_3DV_DISPLAY_OPTIONS
void CopySexprFile(const wxString &aSrcPath, const wxString &aDestPath, std::function< bool(const std::string &token, wxString &value)> aCallback, wxString &aErrors)
void KiCopyFile(const wxString &aSrcPath, const wxString &aDestPath, wxString &aErrors)
static const std::string LegacyPcbFileExtension
static const std::string FootprintLibraryTableFileName
static const std::string BackupFileSuffix
static const std::string LegacyFootprintLibPathExtension
static const std::string FootprintAssignmentFileExtension
static const std::string KiCadFootprintFileExtension
static const std::string KiCadPcbFileExtension
const wxChar *const traceLibraries
Flag to enable library table and library manager tracing.
@ KIFACE_SCRIPTING_LEGACY
@ KIFACE_FOOTPRINT_LIBRARY_ADAPTER
@ KIFACE_FOOTPRINT_LIST
Return a pointer to the global instance of FOOTPRINT_LIST from pcbnew.
#define KFCTL_CLI
Running as CLI app.
This file contains miscellaneous commonly used macros and functions.
PCB::IFACE KIFACE_BASE, UNITS_PROVIDER kiface("pcbnew", KIWAY::FACE_PCB)
void InvokePcbLibTableEditor(KIWAY *aKiway, wxWindow *aCaller)
Function InvokePcbLibTableEditor shows the modal DIALOG_FP_LIB_TABLE for purposes of editing the glob...
PyObject * PyInit__pcbnew(void)
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
SETTINGS_MANAGER * GetSettingsManager()
void ScriptingSetPcbEditFrame(PCB_EDIT_FRAME *aPcbEditFrame)
PGM_BASE & Pgm()
The global program "get" accessor.
T * GetToolbarSettings(const wxString &aFilename)
T * GetAppSettings(const char *aFilename)
std::vector< LOAD_MESSAGE > ExtractLibraryLoadErrors(const wxString &aErrorString, int aSeverity)
Parse library load error messages, extracting user-facing information while stripping internal code l...
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits, KIWAY *aKiway) override
Typically start_common() is called from here.
Implement a participant in the KIWAY alchemy.
std::atomic_bool m_libraryPreloadInProgress
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits, KIWAY *aKiway) override
Typically start_common() is called from here.
void PreloadLibraries(KIWAY *aKiway) override
void ProjectChanged() override
void SaveFileAs(const wxString &aProjectBasePath, const wxString &aSrcProjectName, const wxString &aNewProjectBasePath, const wxString &aNewProjectName, const wxString &aSrcFilePath, wxString &aErrors) override
Saving a file under a different name is delegated to the various KIFACEs because the project doesn't ...
void CancelPreload(bool aBlock=true) override
std::shared_ptr< BACKGROUND_JOB > m_libraryPreloadBackgroundJob
void * IfaceOrAddress(int aDataId) override
Return a pointer to the requested object.
void Reset() override
Reloads global state.
wxWindow * CreateKiWindow(wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
Create a wxWindow for the current project.
IFACE(const char *aName, KIWAY::FACE_T aType)
std::atomic_bool m_libraryPreloadAbort
int HandleJob(JOB *aJob, REPORTER *aReporter, PROGRESS_REPORTER *aProgressReporter) override
std::unique_ptr< PCBNEW_JOBS_HANDLER > m_jobHandler
bool HandleJobConfig(JOB *aJob, wxWindow *aParent) override
void OnKifaceEnd() override
Called just once just before the DSO is to be unloaded.
std::future< void > m_libraryPreloadReturn
thread_pool & GetKiCadThreadPool()
Get a reference to the current thread pool.
BS::priority_thread_pool thread_pool
wxLogTrace helper definitions.
Definition of file extensions used in Kicad.