![]() |
KiCad PCB EDA Suite
|
Scripting helper functions for pcbnew functionality. More...
#include <Python.h>
#include "pcbnew_scripting_helpers.h"
#include <tool/tool_manager.h>
#include <action_plugin.h>
#include <board.h>
#include <board_design_settings.h>
#include <pcb_marker.h>
#include <cstdlib>
#include <drc/drc_engine.h>
#include <drc/drc_item.h>
#include <fp_lib_table.h>
#include <ignore.h>
#include <io_mgr.h>
#include <string_utils.h>
#include <macros.h>
#include <project.h>
#include <project/net_settings.h>
#include <project/project_file.h>
#include <settings/settings_manager.h>
#include <specctra.h>
#include <project/project_local_settings.h>
#include <wildcards_and_files_ext.h>
#include <locale_io.h>
#include <wx/app.h>
Go to the source code of this file.
Functions | |
BOARD * | GetBoard () |
void | ScriptingSetPcbEditFrame (PCB_EDIT_FRAME *aPcbEditFrame) |
BOARD * | LoadBoard (wxString &aFileName) |
SETTINGS_MANAGER * | GetSettingsManager () |
PROJECT * | GetDefaultProject () |
BOARD * | LoadBoard (wxString &aFileName, IO_MGR::PCB_FILE_T aFormat) |
BOARD * | NewBoard (wxString &aFileName) |
Creates a new board and project with the given filename (will overwrite existing files!) More... | |
BOARD * | CreateEmptyBoard () |
Construct a default BOARD with a temporary (no filename) project. More... | |
bool | SaveBoard (wxString &aFileName, BOARD *aBoard, IO_MGR::PCB_FILE_T aFormat) |
bool | SaveBoard (wxString &aFileName, BOARD *aBoard) |
Saves a copy of the given board and its associated project to the given path. More... | |
FP_LIB_TABLE * | GetFootprintLibraryTable () |
wxArrayString | GetFootprintLibraries () |
Get the nicknames of all of the footprint libraries configured in pcbnew in both the project and global library tables. More... | |
wxArrayString | GetFootprints (const wxString &aNickName) |
Get the names of all of the footprints available in a footprint library. More... | |
bool | ExportSpecctraDSN (wxString &aFullFilename) |
Will export the current BOARD to a specctra dsn file. More... | |
bool | ExportSpecctraDSN (BOARD *aBoard, wxString &aFullFilename) |
Will export the BOARD to a specctra dsn file. More... | |
bool | ExportVRML (const wxString &aFullFileName, double aMMtoWRMLunit, bool aExport3DFiles, bool aUseRelativePaths, const wxString &a3D_Subdir, double aXRef, double aYRef) |
Export the current BOARD to a VRML (wrl) file. More... | |
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. More... | |
bool | ExportFootprintsToLibrary (bool aStoreInNewLib, const wxString &aLibName, wxString *aLibPath) |
Save footprints in a library: More... | |
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. More... | |
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. More... | |
int | GetUserUnits () |
Return the currently selected user unit value for the interface. More... | |
bool | IsActionRunning () |
Are we currently in an action plugin? More... | |
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. More... | |
Variables | |
static PCB_EDIT_FRAME * | s_PcbEditFrame = nullptr |
static SETTINGS_MANAGER * | s_SettingsManager = nullptr |
Scripting helper functions for pcbnew functionality.
Definition in file pcbnew_scripting_helpers.cpp.
BOARD* CreateEmptyBoard | ( | ) |
Construct a default BOARD with a temporary (no filename) project.
Definition at line 227 of file pcbnew_scripting_helpers.cpp.
References GetDefaultProject(), s_PcbEditFrame, and BOARD::SetProject().
bool ExportFootprintsToLibrary | ( | bool | aStoreInNewLib, |
const wxString & | aLibName = wxEmptyString , |
||
wxString * | aLibPath = nullptr |
||
) |
Save footprints in a library:
aStoreInNewLib | set 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. |
aLibName | is the optional library name to create, stops dialog call. Must be called with aStoreInNewLib as true. |
Definition at line 378 of file pcbnew_scripting_helpers.cpp.
References PCB_EDIT_FRAME::ExportFootprintsToLibrary(), and s_PcbEditFrame.
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.
Definition at line 319 of file pcbnew_scripting_helpers.cpp.
References PCB_EDIT_FRAME::ExportSpecctraFile(), and s_PcbEditFrame.
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.
Definition at line 333 of file pcbnew_scripting_helpers.cpp.
References ExportBoardToSpecctraFile().
bool ExportVRML | ( | const wxString & | aFullFileName, |
double | aMMtoWRMLunit, | ||
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.
Definition at line 348 of file pcbnew_scripting_helpers.cpp.
References PCB_EDIT_FRAME::ExportVRML_File(), and s_PcbEditFrame.
Referenced by VRML_WRITER::ExportVRML_File().
BOARD* GetBoard | ( | ) |
Definition at line 64 of file pcbnew_scripting_helpers.cpp.
References PCB_BASE_FRAME::GetBoard(), and s_PcbEditFrame.
Referenced by PCB_EDIT_FRAME::canCloseWindow(), ZONE_FILLER_TOOL::CheckAllZones(), DISPLAY_FOOTPRINTS_FRAME::DISPLAY_FOOTPRINTS_FRAME(), PCB_EDIT_FRAME::doCloseWindow(), EVT_GRID_CMD_CELL_CHANGED(), EVT_TOOL_RANGE(), PCB_EDIT_FRAME::ExportSpecctraFile(), PCB_EDIT_FRAME::ExportSVG(), EDIT_TOOL::FilletTracks(), FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME(), PCB_EDIT_FRAME::GetCurrentFileName(), PCB_BASE_FRAME::GetFootprintFromBoardByReference(), GetFootprintLibraryTable(), PCB_EDIT_FRAME::GetLastPath(), PCB_EDIT_FRAME::ImportSpecctraSession(), PCB_EDIT_FRAME::IsElementVisible(), FOOTPRINT_EDIT_FRAME::LoadFootprintFromBoard(), PCB_EDIT_FRAME::onBoardLoaded(), PCB_EDIT_FRAME::OnExportHyperlynx(), PCB_EDIT_FRAME::OnNetlistChanged(), FOOTPRINT_EDIT_FRAME::OpenProjectFiles(), PCB_BASE_EDIT_FRAME::PutDataInPreviousState(), PCB_EDIT_FRAME::RecordDRCExclusions(), PCB_EDIT_FRAME::RecreateBOMFileFromBoard(), PCB_EDIT_FRAME::ResolveDRCExclusions(), PCB_BASE_EDIT_FRAME::SaveCopyInUndoList(), ROUTER_TOOL::SelectCopperLayerPair(), PCB_EDIT_FRAME::SetElementVisibility(), PCB_EDIT_FRAME::SetLastPath(), PCB_EDIT_FRAME::SetPageSettings(), PCB_EDIT_FRAME::setupUIConditions(), PCB_EDIT_FRAME::ShowBoardSetupDialog(), GLOBAL_EDIT_TOOL::SwapLayers(), PCB_EDIT_FRAME::UpdateTitle(), PCB_EDIT_FRAME::UpdateUserInterface(), and PCB_EDIT_FRAME::~PCB_EDIT_FRAME().
PROJECT* GetDefaultProject | ( | ) |
Definition at line 111 of file pcbnew_scripting_helpers.cpp.
References dummy(), SETTINGS_MANAGER::GetProject(), GetSettingsManager(), SETTINGS_MANAGER::LoadProject(), and project.
Referenced by CreateEmptyBoard(), and LoadBoard().
wxArrayString GetFootprintLibraries | ( | ) |
Get the nicknames of all of the footprint libraries configured in pcbnew in both the project and global library tables.
Definition at line 288 of file pcbnew_scripting_helpers.cpp.
References GetFootprintLibraryTable(), LIB_TABLE::GetLogicalLibs(), and name.
FP_LIB_TABLE* GetFootprintLibraryTable | ( | ) |
Definition at line 272 of file pcbnew_scripting_helpers.cpp.
References GetBoard(), BOARD::GetProject(), and project.
Referenced by GetFootprintLibraries(), and GetFootprints().
wxArrayString GetFootprints | ( | const wxString & | aNickName | ) |
Get the names of all of the footprints available in a footprint library.
aNickName | is the nickname specifying which footprint library to fetch from. |
Definition at line 304 of file pcbnew_scripting_helpers.cpp.
References FP_LIB_TABLE::FootprintEnumerate(), and GetFootprintLibraryTable().
SETTINGS_MANAGER* GetSettingsManager | ( | ) |
Definition at line 91 of file pcbnew_scripting_helpers.cpp.
References EDA_BASE_FRAME::GetSettingsManager(), ignore_unused(), s_PcbEditFrame, and s_SettingsManager.
Referenced by PANEL_COLOR_SETTINGS::createThemeList(), EDA_3D_CANVAS::EDA_3D_CANVAS(), GERBVIEW_DRAW_PANEL_GAL::GERBVIEW_DRAW_PANEL_GAL(), GetDefaultProject(), LoadBoard(), FOOTPRINT_EDITOR_SETTINGS::migrateSchema0to1(), NewBoard(), PGM_SINGLE_TOP::OnPgmInit(), EDA_3D_CANVAS::ReloadRequest(), SaveBoard(), PCB_EDIT_FRAME::SaveSettings(), SCH_PREVIEW_PANEL::SCH_PREVIEW_PANEL(), PANEL_PL_EDITOR_COLOR_SETTINGS::TransferDataToWindow(), and DIALOG_PRINT_USING_PRINTER::TransferDataToWindow().
int GetUserUnits | ( | ) |
Return the currently selected user unit value for the interface.
Definition at line 427 of file pcbnew_scripting_helpers.cpp.
References EDA_BASE_FRAME::GetUserUnits(), and s_PcbEditFrame.
Referenced by DRAWING_TOOL::drawArc(), and PCB_CONTROL::placeBoardItems().
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.
Definition at line 364 of file pcbnew_scripting_helpers.cpp.
References PCB_EDIT_FRAME::ImportSpecctraSession(), and s_PcbEditFrame.
bool IsActionRunning | ( | ) |
Are we currently in an action plugin?
Definition at line 436 of file pcbnew_scripting_helpers.cpp.
References ACTION_PLUGINS::IsActionRunning().
BOARD* LoadBoard | ( | wxString & | aFileName | ) |
Definition at line 79 of file pcbnew_scripting_helpers.cpp.
References IO_MGR::KICAD_SEXP, KiCadPcbFileExtension, IO_MGR::LEGACY, LegacyPcbFileExtension, and LoadBoard().
Referenced by LoadBoard().
BOARD* LoadBoard | ( | wxString & | aFileName, |
IO_MGR::PCB_FILE_T | aFormat | ||
) |
Definition at line 129 of file pcbnew_scripting_helpers.cpp.
References BOARD::Add(), BOARD::BuildConnectivity(), BOARD::BuildListOfNets(), DesignRulesFileExtension, dummy(), GAL_LAYER_ID_BITMASK_END, GAL_LAYER_INDEX, PCB_BASE_FRAME::GetBoard(), GetDefaultProject(), BOARD::GetDesignSettings(), SETTINGS_MANAGER::GetProject(), GetSettingsManager(), IO_MGR::Load(), SETTINGS_MANAGER::LoadProject(), BOARD_DESIGN_SETTINGS::m_DRCEngine, BOARD::m_LegacyDesignSettingsLoaded, BOARD::m_LegacyVisibleItems, BOARD::m_LegacyVisibleLayers, Prj(), project, ProjectFileExtension, Rescue, BOARD::ResolveDRCExclusions(), s_PcbEditFrame, BOARD::SetProject(), and BOARD::SynchronizeNetsAndNetClasses().
BOARD* NewBoard | ( | wxString & | aFileName | ) |
Creates a new board and project with the given filename (will overwrite existing files!)
aFileName | is the filename (including full path if desired) of the kicad_pcb to create |
Definition at line 199 of file pcbnew_scripting_helpers.cpp.
References dummy(), BOARD::GetDesignSettings(), SETTINGS_MANAGER::GetProject(), GetSettingsManager(), SETTINGS_MANAGER::LoadProject(), BOARD_DESIGN_SETTINGS::m_DRCEngine, project, ProjectFileExtension, SaveBoard(), and BOARD::SetProject().
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 391 of file pcbnew_scripting_helpers.cpp.
References BOARD::BuildConnectivity(), KIGFX::VIEW::Clear(), PCB_DRAW_PANEL_GAL::DisplayBoard(), TOOL_BASE::GAL_SWITCH, PCB_BASE_FRAME::GetBoard(), PCB_BASE_FRAME::GetCanvas(), BOARD::GetDesignSettings(), EDA_DRAW_PANEL_GAL::GetGAL(), BOARD_DESIGN_SETTINGS::GetGridOrigin(), BOARD::GetPageSettings(), TOOLS_HOLDER::GetToolManager(), PCB_DRAW_PANEL_GAL::GetView(), KIGFX::VIEW::InitPreview(), EDA_DRAW_PANEL_GAL::Refresh(), TOOL_MANAGER::ResetTools(), s_PcbEditFrame, KIGFX::GAL::SetGridOrigin(), PCB_EDIT_FRAME::SetPageSettings(), and PCB_DRAW_PANEL_GAL::SyncLayersVisibility().
Referenced by EDA_MSG_PANEL::AppendMessage(), BITMAP_BUTTON::Check(), EDA_3D_MODEL_VIEWER::Clear3DModel(), ACTION_TOOLBAR::doSelectAction(), SYMBOL_EDIT_FRAME::emptyScreen(), SPLIT_BUTTON::Enable(), BITMAP_BUTTON::Enable(), EDA_MSG_PANEL::EraseMsgBox(), PCB_EDIT_FRAME::ImportSpecctraSession(), ACTION_TOOLBAR::KiRealize(), SYMBOL_EDIT_FRAME::LoadOneLibrarySymbolAux(), SYMBOL_EDIT_FRAME::LoadSymbolFromSchematic(), PANEL_ATTENUATORS::OnAttenuatorSelection(), APPEARANCE_CONTROLS::OnBoardChanged(), PCB_EDIT_FRAME::onBoardLoaded(), WX_COLLAPSIBLE_PANE_HEADER::onEnterWindow(), EDA_3D_CANVAS::OnEvent(), WX_COLLAPSIBLE_PANE_HEADER::onFocus(), SPLIT_BUTTON::OnKillFocus(), BITMAP_BUTTON::OnKillFocus(), APPEARANCE_CONTROLS::OnLanguageChanged(), APPEARANCE_CONTROLS::OnLayerChanged(), PANEL_SETUP_BOARD_STACKUP::OnLayersOptionsChanged(), WX_COLLAPSIBLE_PANE_HEADER::onLeaveWindow(), SPLIT_BUTTON::OnLeftButtonDown(), BITMAP_BUTTON::OnLeftButtonDown(), SPLIT_BUTTON::OnLeftButtonUp(), BITMAP_BUTTON::OnLeftButtonUp(), BM2CMP_FRAME::OnLoadFile(), SPLIT_BUTTON::OnMouseEnter(), BITMAP_BUTTON::OnMouseEnter(), SPLIT_BUTTON::OnMouseLeave(), BITMAP_BUTTON::OnMouseLeave(), EDA_3D_MODEL_VIEWER::OnMouseMove(), EDA_3D_MODEL_VIEWER::OnMouseWheel(), BM2CMP_FRAME::OnNegativeClicked(), DIALOG_TEMPLATE_SELECTOR::onNotebookResize(), BITMAP_BUTTON::OnSetFocus(), PANEL_PACKAGES_VIEW::OnSizeInfoBox(), BM2CMP_FRAME::OnThresholdChange(), PANEL_TRANSLINE::OnTransLineResetButtonClick(), PANEL_TRANSLINE::OnTranslineSelection(), ACTION_TOOLBAR::RefreshBitmaps(), PANEL_REGULATOR::RegulatorPageUpdate(), DIALOG_JUNCTION_PROPS::resetDefaults(), DIALOG_LINE_WIRE_BUS_PROPERTIES::resetDefaults(), TEMPLATE_WIDGET::Select(), EDA_3D_MODEL_VIEWER::Set3DModel(), WX_COLLAPSIBLE_PANE_HEADER::SetCollapsed(), EDA_MSG_PANEL::SetMessage(), PANEL_PACKAGE::SetSelected(), FOOTPRINTS_LISTBOX::SetSelection(), LIBRARY_LISTBOX::SetSelection(), PANEL_COLOR_CODE::ThemeChanged(), PANEL_ATTENUATORS::ThemeChanged(), PANEL_COLOR_CODE::ToleranceSelection(), TEMPLATE_WIDGET::Unselect(), mpWindow::UpdateAll(), KIGFX::OPENGL_GAL::updatedGalDisplayOptions(), KIGFX::CAIRO_GAL::updatedGalDisplayOptions(), DIALOG_PAGES_SETTINGS::UpdateDrawingSheetExample(), and NUMBER_BADGE::UpdateNumber().
bool SaveBoard | ( | wxString & | aFileName, |
BOARD * | aBoard, | ||
IO_MGR::PCB_FILE_T | aFormat | ||
) |
Definition at line 241 of file pcbnew_scripting_helpers.cpp.
References BOARD::BuildConnectivity(), BOARD::GetProject(), GetSettingsManager(), ProjectFileExtension, IO_MGR::Save(), SETTINGS_MANAGER::SaveProjectAs(), and BOARD::SynchronizeNetsAndNetClasses().
Referenced by NewBoard(), and SaveBoard().
bool SaveBoard | ( | wxString & | aFileName, |
BOARD * | aBoard | ||
) |
Saves a copy of the given board and its associated project to the given path.
Boards can only be saved in KiCad native format.
aFileName | is the full path to save a copy to. |
aBoard | is a pointer to a loaded BOARD to save. |
Definition at line 266 of file pcbnew_scripting_helpers.cpp.
References IO_MGR::KICAD_SEXP, and SaveBoard().
void ScriptingSetPcbEditFrame | ( | PCB_EDIT_FRAME * | aPcbEditFrame | ) |
Definition at line 73 of file pcbnew_scripting_helpers.cpp.
References s_PcbEditFrame.
Referenced by PCB::IFACE::CreateWindow().
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 420 of file pcbnew_scripting_helpers.cpp.
References s_PcbEditFrame, and PCB_EDIT_FRAME::UpdateUserInterface().
Referenced by PCB_EDIT_FRAME::ShowBoardSetupDialog().
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.
aBoard | is a valid loaded board. |
aFileName | is the full path and name of the report file to write. |
aUnits | is the units to use in the report. |
aReportAllTrackErrors | controls whether all errors or just the first error is reported for each track. |
Definition at line 442 of file pcbnew_scripting_helpers.cpp.
References PROJECT::AbsolutePath(), DesignRulesFileExtension, DRCE_DUPLICATE_FOOTPRINT, DRCE_EXTRA_FOOTPRINT, DRCE_MISSING_FOOTPRINT, DRCE_NET_CONFLICT, DRCE_UNCONNECTED_ITEMS, BOARD::FillItemMap(), BOARD::GetDesignSettings(), BOARD::GetFileName(), BOARD::GetProject(), BOARD_DESIGN_SETTINGS::GetSeverity(), BOARD_DESIGN_SETTINGS::m_DRCEngine, SETTINGS_MANAGER::Prj(), s_SettingsManager, and TO_UTF8.
|
static |
Definition at line 60 of file pcbnew_scripting_helpers.cpp.
Referenced by CreateEmptyBoard(), ExportFootprintsToLibrary(), ExportSpecctraDSN(), ExportVRML(), GetBoard(), GetSettingsManager(), GetUserUnits(), ImportSpecctraSES(), LoadBoard(), Refresh(), ScriptingSetPcbEditFrame(), and UpdateUserInterface().
|
static |
Definition at line 61 of file pcbnew_scripting_helpers.cpp.
Referenced by GetSettingsManager(), and WriteDRCReport().