KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcbnew_scripting_helpers.h File Reference
#include <deque>
#include <pcb_io/pcb_io_mgr.h>
#include <layer_ids.h>

Go to the source code of this file.

Functions

void ScriptingSetPcbEditFrame (PCB_EDIT_FRAME *aPCBEdaFrame)
 
void ScriptingOnDestructPcbEditFrame (PCB_EDIT_FRAME *aPCBEdaFrame)
 
BOARDGetBoard ()
 
BOARDLoadBoard (const wxString &aFileName, PCB_IO_MGR::PCB_FILE_T aFormat)
 Loads a board from file using the specified file io handler.
 
BOARDLoadBoard (const wxString &aFileName, PCB_IO_MGR::PCB_FILE_T aFormat, bool aSetActive, PROJECT *aProject=nullptr)
 Loads a board from file using the specified file io handler.
 
BOARDLoadBoard (const wxString &aFileName, bool aSetActive, PROJECT *aProject=nullptr)
 Loads a board from file This function identifies the file type by extension and determines the correct file io to use.
 
BOARDLoadBoard (const wxString &aFileName)
 Loads a board from file This function identifies the file type by extension and determines the correct file io to use.
 
BOARDNewBoard (wxString &aFileName)
 Creates a new board and project with the given filename (will overwrite existing files!)
 
SETTINGS_MANAGERGetSettingsManager ()
 
BOARDCreateEmptyBoard ()
 Construct a default BOARD with a temporary (no filename) project.
 
bool SaveBoard (wxString &aFileName, BOARD *aBoard, bool aSkipSettings=false)
 Saves a copy of the given board and its associated project to the given path.
 
wxArrayString GetFootprintLibraries ()
 Get the nicknames of all of the footprint libraries configured in pcbnew in both the project and global library tables.
 
wxArrayString GetFootprints (const wxString &aNickName)
 Get the names of all of the footprints available in a footprint library.
 
bool ExportSpecctraDSN (wxString &aFullFilename)
 Will export the current BOARD to a specctra dsn file.
 
bool ExportSpecctraDSN (BOARD *aBoard, wxString &aFullFilename)
 Will export the BOARD to a specctra dsn file.
 
bool ExportVRML (const wxString &aFullFileName, double aMMtoWRMLunit, bool aIncludeUnspecified, bool aIncludeDNP, bool aExport3DFiles, bool aUseRelativePaths, const wxString &a3D_Subdir, double aXRef, double aYRef)
 Export the current BOARD to a VRML (wrl) file.
 
bool ImportSpecctraSES (wxString &aFullFilename)
 Import a specctra *.ses file and use it to relocate MODULEs and to replace all vias and tracks in an existing and loaded BOARD.
 
bool ImportSpecctraSES (BOARD *aBoard, wxString &aFullFilename)
 Import a specctra *.ses file and use it to relocate MODULEs and to replace all vias and Unlike first overload doesn't need a valid PCB_EDIT_FRAME set and can be used in a standalone python script.
 
bool ExportFootprintsToLibrary (bool aStoreInNewLib, const wxString &aLibName=wxEmptyString, wxString *aLibPath=nullptr)
 Save footprints in a library:
 
void Refresh ()
 Update the board display after modifying it by a python script (note: it is automatically called by action plugins, after running the plugin, so call this function is usually not needed inside action plugins.
 
void UpdateUserInterface ()
 Update the layer manager and other widgets from the board setup (layer and items visibility, colors ...) (note: it is automatically called by action plugins, after running the plugin, so call this function is usually not needed inside action plugins.
 
int GetUserUnits ()
 Return the currently selected user unit value for the interface.
 
std::deque< BOARD_ITEM * > GetCurrentSelection ()
 Get the list of selected objects.
 
void FocusOnItem (BOARD_ITEM *aItem, PCB_LAYER_ID aLayer=UNDEFINED_LAYER)
 Focus the view on the target item.
 
bool IsActionRunning ()
 Are we currently in an action plugin?
 
bool WriteDRCReport (BOARD *aBoard, const wxString &aFileName, EDA_UNITS aUnits, bool aReportAllTrackErrors)
 Run the DRC check on the given board and writes the results to a report file.
 
wxString GetLanguage ()
 Get the language string from COMMON_SETTINGS.
 

Function Documentation

◆ CreateEmptyBoard()

BOARD * CreateEmptyBoard ( )

Construct a default BOARD with a temporary (no filename) project.

Returns
the created board.

Definition at line 309 of file pcbnew_scripting_helpers.cpp.

References GetDefaultProject(), s_PcbEditFrame, and BOARD::SetProject().

Referenced by PCBNEW_JOBS_HANDLER::doFpExportSvg().

◆ ExportFootprintsToLibrary()

bool ExportFootprintsToLibrary ( bool  aStoreInNewLib,
const wxString &  aLibName = wxEmptyString,
wxString *  aLibPath = nullptr 
)

Save footprints in a library:

Parameters
aStoreInNewLibset to true to save footprints in a existing lib. Existing footprints will be kept or updated. This lib should be in fp lib table, and is type is .pretty. Set to false to save footprints in a new lib. If it is an existing lib, previous footprints will be removed.
aLibNameis the optional library name to create, stops dialog call. Must be called with aStoreInNewLib as true.

Definition at line 482 of file pcbnew_scripting_helpers.cpp.

References PCB_EDIT_FRAME::ExportFootprintsToLibrary(), and s_PcbEditFrame.

◆ ExportSpecctraDSN() [1/2]

bool ExportSpecctraDSN ( BOARD aBoard,
wxString &  aFullFilename 
)

Will export the BOARD to a specctra dsn file.

Unlike first overload doesn't need a valid PCB_EDIT_FRAME set and can be used in a standalone python script.

See http://www.autotraxeda.com/docs/SPECCTRA/SPECCTRA.pdf for the specification.

Returns
true if OK

Definition at line 421 of file pcbnew_scripting_helpers.cpp.

References DSN::ExportBoardToSpecctraFile().

◆ ExportSpecctraDSN() [2/2]

bool ExportSpecctraDSN ( wxString &  aFullFilename)

Will export the current BOARD to a specctra dsn file.

See http://www.autotraxeda.com/docs/SPECCTRA/SPECCTRA.pdf for the specification.

Returns
true if OK

Definition at line 407 of file pcbnew_scripting_helpers.cpp.

References PCB_EDIT_FRAME::ExportSpecctraFile(), and s_PcbEditFrame.

◆ ExportVRML()

bool ExportVRML ( const wxString &  aFullFileName,
double  aMMtoWRMLunit,
bool  aIncludeUnspecified,
bool  aIncludeDNP,
bool  aExport3DFiles,
bool  aUseRelativePaths,
const wxString &  a3D_Subdir,
double  aXRef,
double  aYRef 
)

Export the current BOARD to a VRML (wrl) file.

See ExportVRML_File in pcb_edit_frame.h for detailed documentation.

Returns
true if OK.

Definition at line 436 of file pcbnew_scripting_helpers.cpp.

References PCB_EDIT_FRAME::ExportVRML_File(), and s_PcbEditFrame.

◆ FocusOnItem()

void FocusOnItem ( BOARD_ITEM aItem,
PCB_LAYER_ID  aLayer = UNDEFINED_LAYER 
)

Focus the view on the target item.

Parameters
aItemis the target board item.
aLayeris the layer ID of the target item.

Definition at line 538 of file pcbnew_scripting_helpers.cpp.

References PCB_BASE_FRAME::FocusOnItem(), and s_PcbEditFrame.

◆ GetBoard()

◆ GetCurrentSelection()

◆ GetFootprintLibraries()

wxArrayString GetFootprintLibraries ( )

Get the nicknames of all of the footprint libraries configured in pcbnew in both the project and global library tables.

Returns
the list of footprint library nicknames, empty on error.

Definition at line 376 of file pcbnew_scripting_helpers.cpp.

References GetFootprintLibraryTable(), LIB_TABLE::GetLogicalLibs(), and name.

◆ GetFootprints()

wxArrayString GetFootprints ( const wxString &  aNickName)

Get the names of all of the footprints available in a footprint library.

Parameters
aNickNameis the nickname specifying which footprint library to fetch from.
Returns
the list of footprint names, empty on error.

Definition at line 392 of file pcbnew_scripting_helpers.cpp.

References FP_LIB_TABLE::FootprintEnumerate(), and GetFootprintLibraryTable().

◆ GetLanguage()

wxString GetLanguage ( )

Get the language string from COMMON_SETTINGS.

Returns
the current language string.

Definition at line 694 of file pcbnew_scripting_helpers.cpp.

References SETTINGS_MANAGER::GetCommonSettings(), GetSettingsManager(), COMMON_SETTINGS::SYSTEM::language, COMMON_SETTINGS::m_System, and s_PcbEditFrame.

◆ GetSettingsManager()

◆ GetUserUnits()

int GetUserUnits ( )

Return the currently selected user unit value for the interface.

Returns
0 = Inches, 1=mm, -1 if the frame isn't set

Definition at line 511 of file pcbnew_scripting_helpers.cpp.

References UNITS_PROVIDER::GetUserUnits(), and s_PcbEditFrame.

Referenced by DRAWING_TOOL::drawArc(), DRAWING_TOOL::drawOneBezier(), DRAWING_TOOL::drawShape(), PCB_EDIT_FRAME::GenFootprintsReport(), SCH_EDIT_FRAME::SaveSettings(), and PCB_EDIT_FRAME::UpdateViaSizeSelectBox().

◆ ImportSpecctraSES() [1/2]

bool ImportSpecctraSES ( BOARD aBoard,
wxString &  aFullFilename 
)

Import a specctra *.ses file and use it to relocate MODULEs and to replace all vias and Unlike first overload doesn't need a valid PCB_EDIT_FRAME set and can be used in a standalone python script.

See http://www.autotraxeda.com/docs/SPECCTRA/SPECCTRA.pdf for the specification.

Returns
true if OK

Definition at line 467 of file pcbnew_scripting_helpers.cpp.

References DSN::ImportSpecctraSession().

◆ ImportSpecctraSES() [2/2]

bool ImportSpecctraSES ( wxString &  aFullFilename)

Import a specctra *.ses file and use it to relocate MODULEs and to replace all vias and tracks in an existing and loaded BOARD.

See http://www.autotraxeda.com/docs/SPECCTRA/SPECCTRA.pdf for the specification.

Returns
true if OK

Definition at line 454 of file pcbnew_scripting_helpers.cpp.

References PCB_EDIT_FRAME::ImportSpecctraSession(), and s_PcbEditFrame.

◆ IsActionRunning()

bool IsActionRunning ( )

Are we currently in an action plugin?

Definition at line 547 of file pcbnew_scripting_helpers.cpp.

References ACTION_PLUGINS::IsActionRunning().

◆ LoadBoard() [1/4]

BOARD * LoadBoard ( const wxString &  aFileName)

Loads a board from file This function identifies the file type by extension and determines the correct file io to use.

This function does not set the board project as the active one

Returns
a pointer to the board if it was created, or None if not

Definition at line 102 of file pcbnew_scripting_helpers.cpp.

References LoadBoard().

◆ LoadBoard() [2/4]

BOARD * LoadBoard ( const wxString &  aFileName,
bool  aSetActive,
PROJECT aProject = nullptr 
)

Loads a board from file This function identifies the file type by extension and determines the correct file io to use.

Hidden from SWIG as aSetActive should not be used by python, but cli also leverages this function

Definition at line 90 of file pcbnew_scripting_helpers.cpp.

References PCB_IO_MGR::KICAD_SEXP, FILEEXT::KiCadPcbFileExtension, PCB_IO_MGR::LEGACY, FILEEXT::LegacyPcbFileExtension, and LoadBoard().

Referenced by PCBNEW_JOBS_HANDLER::getBoard(), PCBNEW_JOBS_HANDLER::JobExportGencad(), and LoadBoard().

◆ LoadBoard() [3/4]

BOARD * LoadBoard ( const wxString &  aFileName,
PCB_IO_MGR::PCB_FILE_T  aFormat 
)

Loads a board from file using the specified file io handler.

This function does not set the board project as the active one

Returns
a pointer to the board if it was created, or None if not

Definition at line 145 of file pcbnew_scripting_helpers.cpp.

References LoadBoard().

◆ LoadBoard() [4/4]

◆ NewBoard()

BOARD * NewBoard ( wxString &  aFileName)

Creates a new board and project with the given filename (will overwrite existing files!)

Parameters
aFileNameis the filename (including full path if desired) of the kicad_pcb to create
Returns
a pointer to the board if it was created, or None if not

Definition at line 281 of file pcbnew_scripting_helpers.cpp.

References dummy, BOARD::GetDesignSettings(), SETTINGS_MANAGER::GetProject(), GetSettingsManager(), SETTINGS_MANAGER::LoadProject(), BOARD_DESIGN_SETTINGS::m_DRCEngine, project, FILEEXT::ProjectFileExtension, SaveBoard(), and BOARD::SetProject().

◆ Refresh()

void Refresh ( )

Update the board display after modifying it by a python script (note: it is automatically called by action plugins, after running the plugin, so call this function is usually not needed inside action plugins.

Could be deprecated because modifying a board (especially deleting items) outside a action plugin can crash Pcbnew.

Definition at line 495 of file pcbnew_scripting_helpers.cpp.

References PCB_EDIT_FRAME::RebuildAndRefresh(), and s_PcbEditFrame.

Referenced by PANEL_ZONE_GAL::ActivateSelectedZone(), EDA_MSG_PANEL::AppendMessage(), BITMAP_BUTTON::Check(), EDA_3D_MODEL_VIEWER::Clear3DModel(), ACTION_TOOLBAR::doSelectAction(), SYMBOL_EDIT_FRAME::emptyScreen(), BITMAP_BUTTON::Enable(), SPLIT_BUTTON::Enable(), STD_BITMAP_BUTTON::Enable(), KIGFX::CAIRO_GAL::EndDrawing(), EDA_MSG_PANEL::EraseMsgBox(), FOOTPRINT_PREVIEW_PANEL::fitToCurrentFootprint(), PCB_EDIT_FRAME::ImportSpecctraSession(), ACTION_TOOLBAR::KiRealize(), SYMBOL_EDIT_FRAME::LoadOneLibrarySymbolAux(), PANEL_RF_ATTENUATORS::OnAttenuatorSelection(), APPEARANCE_CONTROLS::OnBoardChanged(), PCB_EDIT_FRAME::onBoardLoaded(), SEARCH_PANE_LISTVIEW::OnColClicked(), WX_COLLAPSIBLE_PANE_HEADER::onEnterWindow(), EDA_3D_CANVAS::OnEvent(), EDA_DRAW_PANEL_GAL::OnEvent(), BITMAP2CMP_FRAME::OnFileHistory(), WX_COLLAPSIBLE_PANE_HEADER::onFocus(), EDA_DRAW_PANEL_GAL::onIdle(), BITMAP_BUTTON::OnKillFocus(), SPLIT_BUTTON::OnKillFocus(), STD_BITMAP_BUTTON::OnKillFocus(), APPEARANCE_CONTROLS::OnLanguageChanged(), APPEARANCE_CONTROLS::OnLayerChanged(), PANEL_ZONE_GAL::OnLayerSelected(), PANEL_SETUP_BOARD_STACKUP::OnLayersOptionsChanged(), WX_COLLAPSIBLE_PANE_HEADER::onLeaveWindow(), BITMAP_BUTTON::OnLeftButtonDown(), SPLIT_BUTTON::OnLeftButtonDown(), STD_BITMAP_BUTTON::OnLeftButtonDown(), BITMAP_BUTTON::OnLeftButtonUp(), SPLIT_BUTTON::OnLeftButtonUp(), STD_BITMAP_BUTTON::OnLeftButtonUp(), BITMAP2CMP_FRAME::OnLoadFile(), BITMAP_BUTTON::OnMouseEnter(), SPLIT_BUTTON::OnMouseEnter(), STD_BITMAP_BUTTON::OnMouseEnter(), BITMAP_BUTTON::OnMouseLeave(), SPLIT_BUTTON::OnMouseLeave(), STD_BITMAP_BUTTON::OnMouseLeave(), EDA_3D_MODEL_VIEWER::OnMouseMove(), EDA_3D_MODEL_VIEWER::OnMouseWheel(), BITMAP2CMP_PANEL::OnNegativeClicked(), DIALOG_TEMPLATE_SELECTOR::onNotebookResize(), EDA_3D_CANVAS::OnRefreshRequest(), LAYERS_MAP_DIALOG::OnResetClick(), LAYERS_MAP_DIALOG::OnSelectLayer(), BITMAP_BUTTON::OnSetFocus(), PANEL_PACKAGES_VIEW::OnSizeInfoBox(), SPLIT_BUTTON::onThemeChanged(), STD_BITMAP_BUTTON::onThemeChanged(), BITMAP2CMP_PANEL::OnThresholdChange(), PANEL_TRANSLINE::OnTransLineResetButtonClick(), PANEL_TRANSLINE::OnTranslineSelection(), APPEARANCE_CONTROLS_3D::rebuildControls(), ACTION_TOOLBAR::RefreshBitmaps(), PANEL_REGULATOR::RegulatorPageUpdate(), DIALOG_JUNCTION_PROPS::resetDefaults(), DIALOG_LINE_PROPERTIES::resetDefaults(), DIALOG_WIRE_BUS_PROPERTIES::resetDefaults(), TEMPLATE_WIDGET::Select(), EDA_3D_MODEL_VIEWER::Set3DModel(), WX_COLLAPSIBLE_PANE_HEADER::SetCollapsed(), SPLIT_BUTTON::SetLabel(), EDA_MSG_PANEL::SetMessage(), KISTATUSBAR::SetNotificationCount(), PANEL_PACKAGE::SetSelected(), FOOTPRINTS_LISTBOX::SetSelection(), LIBRARY_LISTBOX::SetSelection(), BITMAP2CMP_FRAME::ShowChangedLanguage(), PCB_CALCULATOR_FRAME::ShowChangedLanguage(), SCH_DRAW_PANEL::SwitchBackend(), PANEL_COLOR_CODE::ThemeChanged(), PANEL_RF_ATTENUATORS::ThemeChanged(), SYMBOL_EDIT_FRAME::ToggleLibraryTree(), SYMBOL_EDIT_FRAME::ToggleProperties(), PANEL_COLOR_CODE::ToleranceSelection(), TEMPLATE_WIDGET::Unselect(), mpWindow::UpdateAll(), KIGFX::CAIRO_GAL::updatedGalDisplayOptions(), KIGFX::OPENGL_GAL::updatedGalDisplayOptions(), DIALOG_PAGES_SETTINGS::UpdateDrawingSheetExample(), NUMBER_BADGE::UpdateNumber(), and PANEL_ZONE_GAL::ZoomFitScreen().

◆ SaveBoard()

bool SaveBoard ( wxString &  aFileName,
BOARD aBoard,
bool  aSkipSettings = false 
)

Saves a copy of the given board and its associated project to the given path.

Boards can only be saved in KiCad native format.

Parameters
aFileNameis the full path to save a copy to.
aBoardis a pointer to a loaded BOARD to save.
aSkipSettingsif true, only save the board file. This will lose settings changes that are saved in the project file
Returns
true if the save was completed.

Definition at line 354 of file pcbnew_scripting_helpers.cpp.

References PCB_IO_MGR::KICAD_SEXP, and SaveBoard().

◆ ScriptingOnDestructPcbEditFrame()

void ScriptingOnDestructPcbEditFrame ( PCB_EDIT_FRAME aPCBEdaFrame)

Definition at line 83 of file pcbnew_scripting_helpers.cpp.

References s_PcbEditFrame.

Referenced by PCB_EDIT_FRAME::~PCB_EDIT_FRAME().

◆ ScriptingSetPcbEditFrame()

void ScriptingSetPcbEditFrame ( PCB_EDIT_FRAME aPCBEdaFrame)

Definition at line 77 of file pcbnew_scripting_helpers.cpp.

References s_PcbEditFrame.

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

◆ UpdateUserInterface()

void UpdateUserInterface ( )

Update the layer manager and other widgets from the board setup (layer and items visibility, colors ...) (note: it is automatically called by action plugins, after running the plugin, so call this function is usually not needed inside action plugins.

Definition at line 504 of file pcbnew_scripting_helpers.cpp.

References s_PcbEditFrame, and PCB_EDIT_FRAME::UpdateUserInterface().

◆ WriteDRCReport()

bool WriteDRCReport ( BOARD aBoard,
const wxString &  aFileName,
EDA_UNITS  aUnits,
bool  aReportAllTrackErrors 
)

Run the DRC check on the given board and writes the results to a report file.

Requires that the project for the board be loaded, and note that unlike the DRC dialog this does not attempt to fill zones, so zones must be valid before calling.

Parameters
aBoardis a valid loaded board.
aFileNameis the full path and name of the report file to write.
aUnitsis the units to use in the report.
aReportAllTrackErrorscontrols whether all errors or just the first error is reported for each track.
Returns
true if successful, false if not.

Definition at line 553 of file pcbnew_scripting_helpers.cpp.

References PROJECT::AbsolutePath(), LSET::AllLayersMask(), ENUM_MAP< T >::Choices(), BOARD::DeleteMARKERs(), FILEEXT::DesignRulesFileExtension, DRCE_DUPLICATE_FOOTPRINT, DRCE_EXTRA_FOOTPRINT, DRCE_FOOTPRINT_FILTERS, DRCE_MISSING_FOOTPRINT, DRCE_NET_CONFLICT, DRCE_SCHEMATIC_PARITY, DRCE_UNCONNECTED_ITEMS, BOARD::FillItemMap(), BOARD::GetDesignSettings(), BOARD::GetFileName(), FP_LIB_TABLE::GetGlobalTableFileName(), BOARD::GetLayerName(), BOARD::GetProject(), BOARD_DESIGN_SETTINGS::GetSeverity(), GFootprintTable, ENUM_MAP< T >::Instance(), LIB_TABLE::Load(), BOARD_DESIGN_SETTINGS::m_DRCEngine, ENUM_MAP< T >::Map(), LSET::Name(), pcbIUScale, SETTINGS_MANAGER::Prj(), BOARD::RecordDRCExclusions(), BOARD::ResolveDRCExclusions(), s_SettingsManager, TO_UTF8, ENUM_MAP< T >::Undefined(), UNDEFINED_LAYER, and IO_ERROR::What().