36#include <wx/snglinst.h>
64#include <python_scripting.h>
95 void Reset()
override;
233 std::vector<TOOL_ACTION*> actions;
234 std::vector<ACTION_TOOLBAR_CONTROL*> controls;
237 actions.push_back( action );
240 controls.push_back( control );
290 BOARD* board =
nullptr;
294 board =
static_cast<PCB_EDIT_FRAME*
>( boardProvider )->
GetBoard();
296 return new PANEL_PCBNEW_COLOR_SETTINGS( aParent, board );
304 std::vector<TOOL_ACTION*> actions;
305 std::vector<ACTION_TOOLBAR_CONTROL*> controls;
308 actions.push_back( action );
311 controls.push_back( control );
333 std::vector<TOOL_ACTION*> actions;
334 std::vector<ACTION_TOOLBAR_CONTROL*> controls;
337 actions.push_back( action );
340 controls.push_back( control );
387 void SaveFileAs(
const wxString& aProjectBasePath,
const wxString& aSrcProjectName,
388 const wxString& aNewProjectBasePath,
const wxString& aNewProjectName,
389 const wxString& aSrcFilePath, wxString& aErrors )
override;
453 m_jobHandler = std::make_unique<PCBNEW_JOBS_HANDLER>( aKiway );
477 const wxString& aNewProjectBasePath,
const wxString& aNewProjectName,
478 const wxString& aSrcFilePath, wxString& aErrors )
480 wxFileName destFile( aSrcFilePath );
481 wxString destPath = destFile.GetPathWithSep();
482 wxUniChar pathSep = wxFileName::GetPathSeparator();
483 wxString ext = destFile.GetExt();
485 if( destPath.StartsWith( aProjectBasePath + pathSep ) )
486 destPath.Replace( aProjectBasePath, aNewProjectBasePath,
false );
488 wxString srcProjectFootprintLib = pathSep + aSrcProjectName + wxT(
".pretty" ) + pathSep;
489 wxString newProjectFootprintLib = pathSep + aNewProjectName + wxT(
".pretty" ) + pathSep;
491 destPath.Replace( srcProjectFootprintLib, newProjectFootprintLib,
true );
493 destFile.SetPath( destPath );
498 if( destFile.GetName() == aSrcProjectName )
499 destFile.SetName( aNewProjectName );
502 [&](
const std::string& token, wxString& value )
504 if( token ==
"sheetfile" )
506 for( const wxString& extension : { wxT(
".sch" ), wxT(
".kicad_sch" ) } )
508 if( value == aSrcProjectName + extension )
510 value = aNewProjectName + extension;
513 else if( value == aProjectBasePath +
"/" + aSrcProjectName + extension )
515 value = aNewProjectBasePath +
"/" + aNewProjectName + extension;
518 else if( value.StartsWith( aProjectBasePath ) )
520 value.Replace( aProjectBasePath, aNewProjectBasePath, false );
532 if( destFile.GetName() == aSrcProjectName )
533 destFile.SetName( aNewProjectName );
535 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
541 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
547 else if( ext == wxT(
"rpt" ) )
553 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
557 wxFileName libTableFn( aSrcFilePath );
559 libTable.SetPath( destFile.GetFullPath() );
562 for( LIBRARY_TABLE_ROW& row : libTable.Rows() )
564 wxString uri = row.URI();
566 uri.Replace( wxT(
"/" ) + aSrcProjectName + wxT(
".pretty" ),
567 wxT(
"/" ) + aNewProjectName + wxT(
".pretty" ) );
572 libTable.Save().map_error(
573 [&](
const LIBRARY_ERROR& aError )
577 if( !aErrors.empty() )
578 aErrors += wxT(
"\n" );
580 msg.Printf(
_(
"Cannot copy file '%s'." ), destFile.GetFullPath() );
586 wxFAIL_MSG( wxT(
"Unexpected filetype for Pcbnew::SaveFileAs()" ) );
593 return m_jobHandler->RunJob( aJob, aReporter, aProgressReporter );
605 constexpr static int interval = 150;
606 constexpr static int timeLimit = 120000;
617 [
this, aKiway]() ->
void
619 std::shared_ptr<BACKGROUND_JOB_REPORTER> reporter =
626 reporter->Report(
_(
"Loading Footprint Libraries" ) );
637 std::this_thread::sleep_for( std::chrono::milliseconds( interval ) );
641 float progress = *loadStatus;
642 reporter->SetCurrentProgress( progress );
649 reporter->SetCurrentProgress( 1 );
655 if( elapsed > timeLimit )
662 GFootprintList.ReadFootprintFiles( adapter,
nullptr, reporter.get() );
668 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.
The main frame for Pcbnew.
Container for data for KiCad programs.
virtual BACKGROUND_JOBS_MONITOR & GetBackgroundJobMonitor() const
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
@ 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)
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 ...
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
Definition of file extensions used in Kicad.