KiCad PCB EDA Suite
pcbnew_scripting_helpers.cpp File Reference

Scripting helper functions for pcbnew functionality. More...

#include <Python.h>
#include <action_plugin.h>
#include <build_version.h>
#include <class_board.h>
#include <cstdlib>
#include <io_mgr.h>
#include <kicad_string.h>
#include <macros.h>
#include <pcb_draw_panel_gal.h>
#include <pcbnew.h>
#include <pcbnew_scripting_helpers.h>

Go to the source code of this file.

Functions

BOARDGetBoard ()
 
void ScriptingSetPcbEditFrame (PCB_EDIT_FRAME *aPcbEditFrame)
 
BOARDLoadBoard (wxString &aFileName)
 
BOARDLoadBoard (wxString &aFileName, IO_MGR::PCB_FILE_T aFormat)
 
bool SaveBoard (wxString &aFileName, BOARD *aBoard, IO_MGR::PCB_FILE_T aFormat)
 
bool SaveBoard (wxString &aFileName, BOARD *aBoard)
 
bool ExportSpecctraDSN (wxString &aFullFilename)
 will export the current BOARD to a specctra dsn file. More...
 
bool ImportSpecctraSES (wxString &aFullFilename)
 will 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 ArchiveModulesOnBoard (bool aStoreInNewLib, const wxString &aLibName, wxString *aLibPath)
 Function ArchiveModulesOnBoard Save modules 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 ()
 Returns the currently selected user unit value for the interface. More...
 
bool IsActionRunning ()
 Are we currently in an action plugin? More...
 

Variables

static PCB_EDIT_FRAMEs_PcbEditFrame = NULL
 

Detailed Description

Scripting helper functions for pcbnew functionality.

Definition in file pcbnew_scripting_helpers.cpp.

Function Documentation

◆ ArchiveModulesOnBoard()

bool ArchiveModulesOnBoard ( bool  aStoreInNewLib,
const wxString &  aLibName = wxEmptyString,
wxString *  aLibPath = NULL 
)

Function ArchiveModulesOnBoard Save modules in a library:

Parameters
aStoreInNewLibtrue : save modules in a existing lib. Existing footprints will be kept or updated. This lib should be in fp lib table, and is type is .pretty false: save modules in a new lib. It it is an existing lib, previous footprints will be removed
aLibNameoptional library name to create, stops dialog call. must be called with aStoreInNewLib as true

Definition at line 136 of file pcbnew_scripting_helpers.cpp.

137 {
138  if( s_PcbEditFrame )
139  {
140  s_PcbEditFrame->ArchiveModulesOnBoard( aStoreInNewLib, aLibName, aLibPath );
141  return true;
142  }
143  else
144  {
145  return false;
146  }
147 }
void ArchiveModulesOnBoard(bool aStoreInNewLib, const wxString &aLibName=wxEmptyString, wxString *aLibPath=NULL)
Function ArchiveModulesOnBoard Save modules in a library:
static PCB_EDIT_FRAME * s_PcbEditFrame

References PCB_EDIT_FRAME::ArchiveModulesOnBoard(), and s_PcbEditFrame.

◆ ExportSpecctraDSN()

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 108 of file pcbnew_scripting_helpers.cpp.

109 {
110  if( s_PcbEditFrame )
111  {
112  bool ok = s_PcbEditFrame->ExportSpecctraFile( aFullFilename );
113  return ok;
114  }
115  else
116  {
117  return false;
118  }
119 }
static PCB_EDIT_FRAME * s_PcbEditFrame
bool ExportSpecctraFile(const wxString &aFullFilename)
Function ExportSpecctraFile will export the current BOARD to a specctra dsn file.

References PCB_EDIT_FRAME::ExportSpecctraFile(), and s_PcbEditFrame.

◆ GetBoard()

BOARD* GetBoard ( )

Definition at line 46 of file pcbnew_scripting_helpers.cpp.

47 {
48  if( s_PcbEditFrame )
49  return s_PcbEditFrame->GetBoard();
50  else
51  return NULL;
52 }
#define NULL
BOARD * GetBoard() const
static PCB_EDIT_FRAME * s_PcbEditFrame

References PCB_BASE_FRAME::GetBoard(), NULL, and s_PcbEditFrame.

Referenced by ZONE_FILLER_TOOL::CheckAllZones(), DISPLAY_FOOTPRINTS_FRAME::DISPLAY_FOOTPRINTS_FRAME(), PCB_EDIT_FRAME::DoShowBoardSetupDialog(), PCB_EDIT_FRAME::DoUpdatePCBFromNetlist(), EDA_3D_VIEWER::EDA_3D_VIEWER(), EVT_GRID_CMD_CELL_CHANGED(), PCB_EDIT_FRAME::ExportSpecctraFile(), PCB_EDIT_FRAME::ExportSVG(), FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME(), PCB_BASE_FRAME::GetFootprintFromBoardByReference(), PCB_EDIT_FRAME::GetLastPath(), PCB_EDIT_FRAME::GetSeverity(), PCB_EDIT_FRAME::ImportSpecctraSession(), PCB_EDIT_FRAME::IsContentModified(), PCB_EDIT_FRAME::IsElementVisible(), FOOTPRINT_EDIT_FRAME::Load_Module_From_BOARD(), FOOTPRINT_EDIT_FRAME::LoadModuleFromLibrary(), PCB_EDIT_FRAME::LockModule(), PCB_EDIT_FRAME::onBoardLoaded(), PCB_EDIT_FRAME::OnCloseWindow(), PCB_EDIT_FRAME::OnExportHyperlynx(), PCB_EDIT_FRAME::OnNetlistChanged(), FOOTPRINT_EDIT_FRAME::OpenProjectFiles(), FOOTPRINT_EDIT_FRAME::Process_Special_Functions(), 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::SetVisibleAlls(), GLOBAL_EDIT_TOOL::SwapLayers(), PCB_EDIT_FRAME::UpdateTitle(), and PCB_EDIT_FRAME::UpdateUserInterface().

◆ GetUserUnits()

int GetUserUnits ( )

Returns the currently selected user unit value for the interface.

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

Definition at line 170 of file pcbnew_scripting_helpers.cpp.

171 {
172  if( s_PcbEditFrame )
173  return static_cast<int>( s_PcbEditFrame->GetUserUnits() );
174 
175  return -1;
176 }
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
static PCB_EDIT_FRAME * s_PcbEditFrame

References EDA_BASE_FRAME::GetUserUnits(), and s_PcbEditFrame.

◆ ImportSpecctraSES()

bool ImportSpecctraSES ( wxString &  aFullFilename)

will 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 122 of file pcbnew_scripting_helpers.cpp.

123 {
124  if( s_PcbEditFrame )
125  {
126  bool ok = s_PcbEditFrame->ImportSpecctraSession( aFullFilename );
127  return ok;
128  }
129  else
130  {
131  return false;
132  }
133 }
bool ImportSpecctraSession(const wxString &aFullFilename)
Function ImportSpecctraSession will import a specctra *.ses file and use it to relocate MODULEs and t...
static PCB_EDIT_FRAME * s_PcbEditFrame

References PCB_EDIT_FRAME::ImportSpecctraSession(), and s_PcbEditFrame.

◆ IsActionRunning()

bool IsActionRunning ( )

Are we currently in an action plugin?

Definition at line 179 of file pcbnew_scripting_helpers.cpp.

180 {
182 }
static bool IsActionRunning()
Function IsActionRunning.

References ACTION_PLUGINS::IsActionRunning().

◆ LoadBoard() [1/2]

BOARD* LoadBoard ( wxString &  aFileName)

Definition at line 61 of file pcbnew_scripting_helpers.cpp.

62 {
63  if( aFileName.EndsWith( wxT( ".kicad_pcb" ) ) )
64  return LoadBoard( aFileName, IO_MGR::KICAD_SEXP );
65 
66  else if( aFileName.EndsWith( wxT( ".brd" ) ) )
67  return LoadBoard( aFileName, IO_MGR::LEGACY );
68 
69  // as fall back for any other kind use the legacy format
70  return LoadBoard( aFileName, IO_MGR::LEGACY );
71 }
BOARD * LoadBoard(wxString &aFileName)
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:56
S-expression Pcbnew file format.
Definition: io_mgr.h:57

References IO_MGR::KICAD_SEXP, IO_MGR::LEGACY, and LoadBoard().

Referenced by LoadBoard().

◆ LoadBoard() [2/2]

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

Definition at line 74 of file pcbnew_scripting_helpers.cpp.

75 {
76  BOARD* brd = IO_MGR::Load( aFormat, aFileName );
77 
78  if( brd )
79  {
80  brd->BuildConnectivity();
81  brd->BuildListOfNets();
83  }
84 
85 
86  return brd;
87 }
void BuildListOfNets()
Definition: class_board.h:692
void SynchronizeNetsAndNetClasses()
Function SynchronizeNetsAndNetClasses copies NETCLASS info to each NET, based on NET membership in a ...
Definition: netclass.cpp:155
static BOARD * Load(PCB_FILE_T aFileType, const wxString &aFileName, BOARD *aAppendToMe=NULL, const PROPERTIES *aProperties=NULL)
Function Load finds the requested PLUGIN and if found, calls the PLUGIN->Load(..) funtion on it using...
Definition: io_mgr.cpp:173
void BuildConnectivity()
Builds or rebuilds the board connectivity database for the board, especially the list of connected it...
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:163

References BOARD::BuildConnectivity(), BOARD::BuildListOfNets(), IO_MGR::Load(), and BOARD::SynchronizeNetsAndNetClasses().

◆ 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 149 of file pcbnew_scripting_helpers.cpp.

150 {
151  if( s_PcbEditFrame )
152  {
153  auto board = s_PcbEditFrame->GetBoard();
154  board->BuildConnectivity();
155 
156  // Re-init everything: this is the easy way to do that
159  }
160 }
void ActivateGalCanvas() override
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void BuildConnectivity()
Builds or rebuilds the board connectivity database for the board, especially the list of connected it...
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
BOARD * GetBoard() const
static PCB_EDIT_FRAME * s_PcbEditFrame

References PCB_EDIT_FRAME::ActivateGalCanvas(), BOARD::BuildConnectivity(), PCB_BASE_FRAME::GetBoard(), PCB_BASE_FRAME::GetCanvas(), EDA_DRAW_PANEL_GAL::Refresh(), and s_PcbEditFrame.

Referenced by EDA_MSG_PANEL::AppendMessage(), C3D_MODEL_VIEWER::Clear3DModel(), LIB_EDIT_FRAME::emptyScreen(), SPLIT_BUTTON::Enable(), EDA_MSG_PANEL::EraseMsgBox(), PCB_EDIT_FRAME::ImportSpecctraSession(), LIB_EDIT_FRAME::LoadOneLibraryPartAux(), PCB_CALCULATOR_FRAME::OnAttenuatorSelection(), PCB_EDIT_FRAME::onBoardLoaded(), EDA_3D_CANVAS::OnEvent(), SPLIT_BUTTON::OnKillFocus(), PANEL_SETUP_BOARD_STACKUP::OnLayersOptionsChanged(), SPLIT_BUTTON::OnLeftButtonDown(), SPLIT_BUTTON::OnLeftButtonUp(), BM2CMP_FRAME::OnLoadFile(), SPLIT_BUTTON::OnMouseEnter(), SPLIT_BUTTON::OnMouseLeave(), C3D_MODEL_VIEWER::OnMouseMove(), C3D_MODEL_VIEWER::OnMouseWheel(), BM2CMP_FRAME::OnNegativeClicked(), FOOTPRINT_PREVIEW_WIDGET::OnStatusChange(), BM2CMP_FRAME::OnThresholdChange(), DIALOG_EDIT_LINE_STYLE::resetDefaults(), TEMPLATE_WIDGET::Select(), C3D_MODEL_VIEWER::Set3DModel(), EDA_MSG_PANEL::SetMessage(), FOOTPRINTS_LISTBOX::SetSelection(), LIBRARY_LISTBOX::SetSelection(), TEMPLATE_WIDGET::Unselect(), mpWindow::UpdateAll(), DIALOG_EDIT_LINE_STYLE::updateColorButton(), KIGFX::OPENGL_GAL::updatedGalDisplayOptions(), KIGFX::CAIRO_GAL::updatedGalDisplayOptions(), and DIALOG_PAGES_SETTINGS::UpdatePageLayoutExample().

◆ SaveBoard() [1/2]

bool SaveBoard ( wxString &  aFileName,
BOARD aBoard,
IO_MGR::PCB_FILE_T  aFormat 
)

Definition at line 90 of file pcbnew_scripting_helpers.cpp.

91 {
92  aBoard->BuildConnectivity();
95 
96  IO_MGR::Save( aFormat, aFileName, aBoard, NULL );
97 
98  return true;
99 }
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:512
void SynchronizeNetsAndNetClasses()
Function SynchronizeNetsAndNetClasses copies NETCLASS info to each NET, based on NET membership in a ...
Definition: netclass.cpp:155
#define NULL
static const char Default[]
the name of the default NETCLASS
Definition: netclass.h:80
void BuildConnectivity()
Builds or rebuilds the board connectivity database for the board, especially the list of connected it...
static void Save(PCB_FILE_T aFileType, const wxString &aFileName, BOARD *aBoard, const PROPERTIES *aProperties=NULL)
Function Save will write either a full aBoard to a storage file in a format that this implementation ...
Definition: io_mgr.cpp:188
bool SetCurrentNetClass(const wxString &aNetClassName)
Function SetCurrentNetClass Must be called after a netclass selection (or after a netclass parameter ...

References BOARD::BuildConnectivity(), NETCLASS::Default, BOARD::GetDesignSettings(), NULL, IO_MGR::Save(), BOARD_DESIGN_SETTINGS::SetCurrentNetClass(), and BOARD::SynchronizeNetsAndNetClasses().

Referenced by SaveBoard().

◆ SaveBoard() [2/2]

bool SaveBoard ( wxString &  aFileName,
BOARD aBoard 
)

Definition at line 102 of file pcbnew_scripting_helpers.cpp.

103 {
104  return SaveBoard( aFileName, aBoard, IO_MGR::KICAD_SEXP );
105 }
bool SaveBoard(wxString &aFileName, BOARD *aBoard, IO_MGR::PCB_FILE_T aFormat)
S-expression Pcbnew file format.
Definition: io_mgr.h:57

References IO_MGR::KICAD_SEXP, and SaveBoard().

◆ ScriptingSetPcbEditFrame()

void ScriptingSetPcbEditFrame ( PCB_EDIT_FRAME aPcbEditFrame)

Definition at line 55 of file pcbnew_scripting_helpers.cpp.

56 {
57  s_PcbEditFrame = aPcbEditFrame;
58 }
static PCB_EDIT_FRAME * s_PcbEditFrame

References s_PcbEditFrame.

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

◆ 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 163 of file pcbnew_scripting_helpers.cpp.

164 {
165  if( s_PcbEditFrame )
167 }
void UpdateUserInterface()
Update the layer manager and other widgets from the board setup (layer and items visibility,...
static PCB_EDIT_FRAME * s_PcbEditFrame

References s_PcbEditFrame, and PCB_EDIT_FRAME::UpdateUserInterface().

Referenced by PCB_EDIT_FRAME::DoShowBoardSetupDialog().

Variable Documentation

◆ s_PcbEditFrame