KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcbnew.cpp File Reference
#include <pgm_base.h>
#include <eda_pattern_match.h>
#include <background_jobs_monitor.h>
#include <cli_progress_reporter.h>
#include <confirm.h>
#include <api/api_handler_footprint.h>
#include <api/api_handler_fp_libraries.h>
#include <api/api_handler_pcb.h>
#include <api/api_server.h>
#include <api/api_utils.h>
#include <api/cross_probe_client.h>
#include <api/headless_footprint_context.h>
#include <api/headless_pcb_context.h>
#include <kiface_base.h>
#include <kiface_ids.h>
#include <kiway_holder.h>
#include <pcb_edit_frame.h>
#include <macros.h>
#include <gestfich.h>
#include <paths.h>
#include <pcbnew_settings.h>
#include <footprint.h>
#include <footprint_editor_settings.h>
#include <settings/settings_manager.h>
#include <settings/cvpcb_settings.h>
#include <footprint_library_adapter.h>
#include <footprint_edit_frame.h>
#include <footprint_viewer_frame.h>
#include <footprint_chooser_frame.h>
#include <footprint_wizard_frame.h>
#include <footprint_preview_panel.h>
#include <footprint_info_impl.h>
#include <board.h>
#include <board_loader.h>
#include <lib_id.h>
#include <nlohmann/json.hpp>
#include <dialogs/dialog_configure_paths.h>
#include <dialogs/panel_grid_settings.h>
#include <panel_display_options.h>
#include <panel_edit_options.h>
#include <dialogs/panel_snapping.h>
#include <panel_fp_editor_field_defaults.h>
#include <panel_fp_editor_graphics_defaults.h>
#include <panel_fp_user_layer_names.h>
#include <panel_fp_editor_color_settings.h>
#include <panel_pcbnew_color_settings.h>
#include <panel_pcbnew_action_plugins.h>
#include <panel_pcbnew_display_origin.h>
#include <panel_3D_display_options.h>
#include <panel_3D_opengl_options.h>
#include <panel_3D_raytracing_options.h>
#include <project_pcb.h>
#include <string_utils.h>
#include <thread_pool.h>
#include <trace_helpers.h>
#include <widgets/kistatusbar.h>
#include <wx/tokenzr.h>
#include <footprint_library_query.h>
#include <invoke_pcb_dialog.h>
#include <wildcards_and_files_ext.h>
#include "pcbnew_jobs_handler.h"
#include <diff_merge/diff_doc_kind.h>
#include <reporter.h>
#include "git/kigit_pcb_merge.h"
#include "git/kigit_fp_merge.h"
#include <git/kigit_driver_registry.h>
#include <dialogs/panel_toolbar_customization.h>
#include <3d_viewer/toolbars_3d.h>
#include <toolbars_footprint_editor.h>
#include <toolbars_pcb_editor.h>
#include <wx/crt.h>

Go to the source code of this file.

Classes

struct  PCB::IFACE
 

Namespaces

namespace  PCB
 

Functions

static PROJECT * footprintLibraryProject ()
 Return the project whose footprint libraries the kiface-level footprint services work with.
 
static wxString filterFootprints (const wxString &aFilterJson)
 Filter footprints based on criteria passed as JSON.
 
static bool startFootprintLibraryLoad ()
 Start loading the footprint libraries in the background.
 
static float footprintLibraryLoadProgress ()
 Return how far a background load has got.
 
static int PCB::pcbnewMergeExport (int aKind, const wxString &aAncestor, const wxString &aOurs, const wxString &aTheirs, const wxString &aOutput, bool aInteractive, bool aSingleFile, REPORTER *aReporter)
 
static int PCB::pcbnewOpenDiffDialogExport (int aKind, const wxString &aFileA, const wxString &aFileB, const wxString &aLabelA, const wxString &aLabelB, wxWindow *aParent, REPORTER *aReporter)
 
PCB::IFACE KIFACE_BASE, UNITS_PROVIDER PCB::kiface ("pcbnew", KIWAY::FACE_PCB)
 
 IFACE (const char *aName, KIWAY::FACE_T aType)
 
bool OnKifaceStart (PGM_BASE *aProgram, int aCtlBits, KIWAY *aKiway) override
 
void Reset () override
 
void OnKifaceEnd () override
 
wxWindow * CreateKiWindow (wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
 
void * IfaceOrAddress (int aDataId) override
 Return a pointer to the requested object.
 
PCBNEW_JOBS_HANDLER * JobHandler () const
 Accessor for the non-job diff/merge exports (pcbnewMergeExport etc.).
 
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 know the internal format of the various files (which may have paths in them that need updating).
 
int HandleJob (JOB *aJob, REPORTER *aReporter, PROGRESS_REPORTER *aProgressReporter) override
 
bool HandleJobConfig (JOB *aJob, wxWindow *aParent) override
 
bool HandleApiOpenDocument (const DOCUMENT_SPEC &aSpec, KICAD_API_SERVER *aServer, wxString *aError) override
 
bool HandleApiCloseDocument (const DOCUMENT_SPEC &aSpec, KICAD_API_SERVER *aServer, wxString *aError) override
 
bool handleOpenPcb (const wxString &aPath, KICAD_API_SERVER *aServer, wxString *aError)
 
bool handleCreatePcb (const wxString &aPath, KICAD_API_SERVER *aServer, wxString *aError)
 
bool handleOpenFootprint (const wxString &aProjectPath, const wxString &aLibIdStr, KICAD_API_SERVER *aServer, wxString *aError)
 
void PreloadLibraries (KIWAY *aKiway) override
 
void ProjectChanged () override
 
void CancelPreload (bool aBlock=true) override
 
void RegisterLibraryHandlers (KICAD_API_SERVER *aServer) override
 
bool LoadAllLibraries () override
 
void closeBoard (KICAD_API_SERVER *aServer)
 
void closeFootprint (KICAD_API_SERVER *aServer)
 
KIFACE_BASE & Kiface ()
 Global KIFACE_BASE "get" accessor.
 
KIFACE_API KIFACE * KIFACE_GETTER (int *aKIFACEversion, int aKiwayVersion, PGM_BASE *aProgram)
 No name mangling. Each KIFACE (DSO/DLL) will implement this once.
 

Variables

std::unique_ptr< PCBNEW_JOBS_HANDLER > m_jobHandler
 
std::shared_ptr< BACKGROUND_JOB > m_libraryPreloadBackgroundJob
 
std::future< void > m_libraryPreloadReturn
 
std::atomic_bool m_libraryPreloadInProgress
 
std::atomic_bool m_libraryPreloadAbort
 
KIWAY * m_kiway = nullptr
 
std::shared_ptr< HEADLESS_PCB_CONTEXT > m_openContext
 
std::unique_ptr< API_HANDLER_PCB > m_openHandler
 
std::shared_ptr< HEADLESS_FOOTPRINT_CONTEXT > m_openFpContext
 
std::unique_ptr< API_HANDLER_FOOTPRINT > m_openFpHandler
 
std::unique_ptr< API_HANDLER_FP_LIBRARIES > m_apiHandlerFpLibs
 

Function Documentation

◆ CancelPreload()

void kiface::CancelPreload ( bool aBlock = true)
override

◆ closeBoard()

void kiface::closeBoard ( KICAD_API_SERVER * aServer)
private

References PANEL_FP_GRIDS.

◆ closeFootprint()

void kiface::closeFootprint ( KICAD_API_SERVER * aServer)
private

References GetAppSettings().

◆ CreateKiWindow()

wxWindow * kiface::CreateKiWindow ( wxWindow * aParent,
int aClassId,
KIWAY * aKiway,
int aCtlBits = 0 )
override

Definition at line 13 of file pcbnew.cpp.

◆ filterFootprints()

static wxString filterFootprints ( const wxString & aFilterJson)
static

Filter footprints based on criteria passed as JSON.

Input JSON format: {"pin_count": N, "filters": ["pattern1", ...], "zero_filters": bool, "max_results": N} A "max_results" of zero or less means no limit.

Output JSON format: the object written by FOOTPRINT_MATCH_RESULT::ToJsonStr(), i.e. {"matches": ["lib:footprint1", "lib:footprint2", ...], "limited": bool, "success": bool} where "success" is false when the query could not be performed.

Parameters
aFilterJsonJSON string with filter parameters
Returns
JSON string describing the matching footprint LIB_IDs

Definition at line 144 of file pcbnew.cpp.

References LIBRARY_MANAGER_ADAPTER::AsyncLoad(), LIBRARY_MANAGER_ADAPTER::BlockUntilLoaded(), PROJECT_PCB::FootprintLibAdapter(), footprintLibraryProject(), FOOTPRINT_LIBRARY_ADAPTER::GetFootprints(), LIBRARY_MANAGER_ADAPTER::GetLibraryNames(), name, and result.

Referenced by PCB::IFACE::IfaceOrAddress(), and QueryMatchingFootprints().

◆ footprintLibraryLoadProgress()

static float footprintLibraryLoadProgress ( )
static

Return how far a background load has got.

Never blocks: callers can poll this while showing a loading indication, and only run filterFootprints() (which does wait for the load) after it returns 1.0.

Definition at line 289 of file pcbnew.cpp.

References LIBRARY_MANAGER_ADAPTER::AsyncLoadProgress(), PROJECT_PCB::FootprintLibAdapter(), and footprintLibraryProject().

Referenced by PCB::IFACE::IfaceOrAddress().

◆ footprintLibraryProject()

static PROJECT * footprintLibraryProject ( )
static

Return the project whose footprint libraries the kiface-level footprint services work with.

Definition at line 107 of file pcbnew.cpp.

References PGM_BASE::GetSettingsManager(), Pgm(), SETTINGS_MANAGER::Prj(), and top().

Referenced by filterFootprints(), footprintLibraryLoadProgress(), and startFootprintLibraryLoad().

◆ HandleApiCloseDocument()

bool kiface::HandleApiCloseDocument ( const DOCUMENT_SPEC & aSpec,
KICAD_API_SERVER * aServer,
wxString * aError )
override

References DIALOG_CONFIGUREPATHS.

◆ HandleApiOpenDocument()

bool kiface::HandleApiOpenDocument ( const DOCUMENT_SPEC & aSpec,
KICAD_API_SERVER * aServer,
wxString * aError )
override

◆ handleCreatePcb()

bool kiface::handleCreatePcb ( const wxString & aPath,
KICAD_API_SERVER * aServer,
wxString * aError )

◆ HandleJob()

int kiface::HandleJob ( JOB * aJob,
REPORTER * aReporter,
PROGRESS_REPORTER * aProgressReporter )
override

◆ HandleJobConfig()

bool kiface::HandleJobConfig ( JOB * aJob,
wxWindow * aParent )
override

◆ handleOpenFootprint()

bool kiface::handleOpenFootprint ( const wxString & aProjectPath,
const wxString & aLibIdStr,
KICAD_API_SERVER * aServer,
wxString * aError )

◆ handleOpenPcb()

bool kiface::handleOpenPcb ( const wxString & aPath,
KICAD_API_SERVER * aServer,
wxString * aError )

◆ IFACE()

kiface::IFACE ( const char * aName,
KIWAY::FACE_T aType )

Definition at line 2 of file pcbnew.cpp.

◆ IfaceOrAddress()

void * kiface::IfaceOrAddress ( int aDataId)
override

Return a pointer to the requested object.

The safest way to use this is to retrieve a pointer to a static instance of an interface, similar to how the KIFACE interface is exported. But if you know what you are doing use it to retrieve anything you want.

Parameters
aDataIdidentifies which object you want the address of.
Returns
the object which must be cast into the know type.

Definition at line 284 of file pcbnew.cpp.

◆ JobHandler()

PCBNEW_JOBS_HANDLER * kiface::JobHandler ( ) const

Accessor for the non-job diff/merge exports (pcbnewMergeExport etc.).

Definition at line 345 of file pcbnew.cpp.

◆ Kiface()

KIFACE_BASE & Kiface ( )

Global KIFACE_BASE "get" accessor.

Definition at line 744 of file pcbnew.cpp.

References PCB::kiface().

◆ KIFACE_GETTER()

KIFACE_API KIFACE * KIFACE_GETTER ( int * aKIFACEversion,
int aKiwayVersion,
PGM_BASE * aProgram )

No name mangling. Each KIFACE (DSO/DLL) will implement this once.

Definition at line 749 of file pcbnew.cpp.

References PCB::kiface(), and KIFACE_API.

◆ LoadAllLibraries()

bool kiface::LoadAllLibraries ( )
override

◆ OnKifaceEnd()

void kiface::OnKifaceEnd ( )
override

Definition at line 11 of file test_app_main.cpp.

◆ OnKifaceStart()

bool kiface::OnKifaceStart ( PGM_BASE * aProgram,
int aCtlBits,
KIWAY * aKiway )
override

Definition at line 6 of file test_app_main.cpp.

◆ PreloadLibraries()

void kiface::PreloadLibraries ( KIWAY * aKiway)
override

References ENVVARS_CHANGED.

◆ ProjectChanged()

void kiface::ProjectChanged ( )
override

◆ RegisterLibraryHandlers()

void kiface::RegisterLibraryHandlers ( KICAD_API_SERVER * aServer)
override

◆ Reset()

void kiface::Reset ( )
override

◆ SaveFileAs()

void kiface::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 know the internal format of the various files (which may have paths in them that need updating).

References FRAME_FOOTPRINT_CHOOSER, and FRAME_FOOTPRINT_VIEWER.

◆ startFootprintLibraryLoad()

static bool startFootprintLibraryLoad ( )
static

Start loading the footprint libraries in the background.

Never blocks.

Definition at line 269 of file pcbnew.cpp.

References LIBRARY_MANAGER_ADAPTER::AsyncLoad(), PROJECT_PCB::FootprintLibAdapter(), and footprintLibraryProject().

Referenced by PCB::IFACE::IfaceOrAddress().

Variable Documentation

◆ m_apiHandlerFpLibs

std::unique_ptr<API_HANDLER_FP_LIBRARIES> m_apiHandlerFpLibs
private

Definition at line 397 of file pcbnew.cpp.

◆ m_jobHandler

std::unique_ptr<PCBNEW_JOBS_HANDLER> m_jobHandler
private

Definition at line 383 of file pcbnew.cpp.

◆ m_kiway

KIWAY* m_kiway = nullptr
private

Definition at line 392 of file pcbnew.cpp.

◆ m_libraryPreloadAbort

std::atomic_bool m_libraryPreloadAbort
private

Definition at line 387 of file pcbnew.cpp.

◆ m_libraryPreloadBackgroundJob

std::shared_ptr<BACKGROUND_JOB> m_libraryPreloadBackgroundJob
private

Definition at line 384 of file pcbnew.cpp.

◆ m_libraryPreloadInProgress

std::atomic_bool m_libraryPreloadInProgress
private

Definition at line 386 of file pcbnew.cpp.

◆ m_libraryPreloadReturn

std::future<void> m_libraryPreloadReturn
private

Definition at line 385 of file pcbnew.cpp.

◆ m_openContext

std::shared_ptr<HEADLESS_PCB_CONTEXT> m_openContext
private

Definition at line 393 of file pcbnew.cpp.

◆ m_openFpContext

std::shared_ptr<HEADLESS_FOOTPRINT_CONTEXT> m_openFpContext
private

Definition at line 395 of file pcbnew.cpp.

◆ m_openFpHandler

std::unique_ptr<API_HANDLER_FOOTPRINT> m_openFpHandler
private

Definition at line 396 of file pcbnew.cpp.

◆ m_openHandler

std::unique_ptr<API_HANDLER_PCB> m_openHandler
private

Definition at line 394 of file pcbnew.cpp.