KiCad PCB EDA Suite
pcbnew_scripting_helpers.cpp File Reference

Scripting helper functions for pcbnew functionality. More...

#include <Python.h>
#include <pcbnew_scripting_helpers.h>
#include <pcbnew.h>
#include <pcbnew_id.h>
#include <build_version.h>
#include <class_board.h>
#include <class_drawpanel.h>
#include <kicad_string.h>
#include <io_mgr.h>
#include <macros.h>
#include <stdlib.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)
 
void Refresh ()
 Update the board display after modifying it bu 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 WindowZoom (int xl, int yl, int width, int height)
 
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...
 

Variables

static PCB_EDIT_FRAMEs_PcbEditFrame = NULL
 

Detailed Description

Scripting helper functions for pcbnew functionality.

Definition in file pcbnew_scripting_helpers.cpp.

Function Documentation

BOARD* GetBoard ( )

Definition at line 45 of file pcbnew_scripting_helpers.cpp.

References PCB_BASE_FRAME::GetBoard().

Referenced by EVT_GRID_CMD_CELL_CHANGED(), EVT_TOOL(), EVT_UPDATE_UI(), PCB_EDIT_FRAME::ExportSpecctraFile(), PCB_EDIT_FRAME::ExportToSpecctra(), PCB_EDIT_FRAME::GetLastNetListRead(), PCB_DRAW_PANEL_GAL::GetMsgPanelInfo(), PCB_EDIT_FRAME::ImportSpecctraSession(), PCB_EDIT_FRAME::IsElementVisible(), PCB_EDIT_FRAME::IsMicroViaAcceptable(), PCB_EDIT_FRAME::ListAndSelectModuleName(), FOOTPRINT_EDIT_FRAME::Load_Module_From_BOARD(), PCB_BASE_FRAME::LoadModuleFromLibrary(), FOOTPRINT_EDIT_FRAME::ModeditLocateAndDisplay(), FOOTPRINT_EDIT_FRAME::moveExact(), PCB_EDIT_FRAME::OnCloseWindow(), FOOTPRINT_EDIT_FRAME::OnVerticalToolbar(), FOOTPRINT_EDIT_FRAME::OpenProjectFiles(), FOOTPRINT_EDIT_FRAME::Process_Special_Functions(), PCB_BASE_EDIT_FRAME::PutDataInPreviousState(), PCB_EDIT_FRAME::ReadPcbNetlist(), PCB_EDIT_FRAME::RecreateBOMFileFromBoard(), PCB_BASE_EDIT_FRAME::SaveCopyInUndoList(), PCB_EDIT_FRAME::SetElementVisibility(), PCB_EDIT_FRAME::SetLastNetListRead(), PCB_EDIT_FRAME::SetVisibleAlls(), PCB_EDIT_FRAME::Show3D_Frame(), PCB_EDIT_FRAME::SVG_Print(), PCB_EDIT_FRAME::UpdateTitle(), and PCB_EDIT_FRAME::UpdateUserInterface().

46 {
47  if( s_PcbEditFrame )
48  return s_PcbEditFrame->GetBoard();
49  else
50  return NULL;
51 }
BOARD * GetBoard() const
static PCB_EDIT_FRAME * s_PcbEditFrame
BOARD* LoadBoard ( wxString &  aFileName)

Definition at line 60 of file pcbnew_scripting_helpers.cpp.

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

Referenced by LoadBoard().

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

Definition at line 73 of file pcbnew_scripting_helpers.cpp.

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

74 {
75  BOARD* brd = IO_MGR::Load( aFormat, aFileName );
76 
77  if( brd )
78  brd->BuildConnectivity();
79 
80  return brd;
81 }
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:179
void BuildConnectivity()
Builds or rebuilds the board connectivity database for the board, especially the list of connected it...
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
void Refresh ( )

Update the board display after modifying it bu 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 102 of file pcbnew_scripting_helpers.cpp.

References EDA_DRAW_FRAME::GetCanvas(), EDA_DRAW_FRAME::GetGalCanvas(), EDA_DRAW_FRAME::IsGalCanvasActive(), EDA_DRAW_PANEL_GAL::Refresh(), and EDA_DRAW_PANEL::Refresh().

Referenced by EDA_MSG_PANEL::AppendMessage(), C3D_MODEL_VIEWER::Clear3DModel(), DRCLISTBOX::DeleteAllItems(), DRCLISTBOX::DeleteItem(), LIB_EDIT_FRAME::emptyScreen(), EDA_MSG_PANEL::EraseMsgBox(), PCB_EDIT_FRAME::ImportSpecctraSession(), LIB_EDIT_FRAME::InstallFieldsEditorDialog(), LIB_EDIT_FRAME::LoadOneLibraryPartAux(), PCB_EDIT_FRAME::OnFlipPcbView(), C3D_MODEL_VIEWER::OnMouseMove(), C3D_MODEL_VIEWER::OnMouseWheel(), FOOTPRINT_PREVIEW_WIDGET::OnStatusChange(), DIALOG_FP_LIB_TABLE::optionsEditor(), EDA_DRAW_PANEL::Refresh(), DIALOG_EDIT_LINE_STYLE::resetDefaults(), TEMPLATE_WIDGET::Select(), C3D_MODEL_VIEWER::Set3DModel(), WIDGET_EESCHEMA_COLOR_CONFIG::SetColor(), DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::SetGroupingColumn(), DRCLISTBOX::SetList(), EDA_MSG_PANEL::SetMessage(), FOOTPRINTS_LISTBOX::SetSelection(), LIBRARY_LISTBOX::SetSelection(), EDA_3D_VIEWER::takeScreenshot(), TEMPLATE_WIDGET::Unselect(), mpWindow::UpdateAll(), DIALOG_EDIT_LINE_STYLE::updateColorButton(), KIGFX::OPENGL_GAL::updatedGalDisplayOptions(), KIGFX::CAIRO_GAL::updatedGalDisplayOptions(), DIALOG_PAGES_SETTINGS::UpdatePageLayoutExample(), and PCB_EDIT_FRAME::UseGalCanvas().

103 {
104  if( s_PcbEditFrame )
105  {
108  else
109  // first argument is erase background, second is a wxRect that
110  // defines a reftresh area (all canvas if null)
111  s_PcbEditFrame->GetCanvas()->Refresh( true, NULL );
112  }
113 }
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Update the board display after modifying it bu a python script (note: it is automatically called by a...
Definition: draw_panel.cpp:332
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:331
bool IsGalCanvasActive() const
Function IsGalCanvasActive is used to check which canvas (GAL-based or standard) is currently in use...
Definition: draw_frame.h:856
void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it bu a python script (note: it is automatically called by a...
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Function GetGalCanvas returns a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:864
static PCB_EDIT_FRAME * s_PcbEditFrame
bool SaveBoard ( wxString &  aFileName,
BOARD aBoard,
IO_MGR::PCB_FILE_T  aFormat 
)

Definition at line 84 of file pcbnew_scripting_helpers.cpp.

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

Referenced by SaveBoard().

85 {
86  aBoard->BuildConnectivity();
89 
90  IO_MGR::Save( aFormat, aFileName, aBoard, NULL );
91 
92  return true;
93 }
void SynchronizeNetsAndNetClasses()
Function SynchronizeNetsAndNetClasses copies NETCLASS info to each NET, based on NET membership in a ...
static const char Default[]
the name of the default NETCLASS
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:532
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:194
bool SetCurrentNetClass(const wxString &aNetClassName)
Function SetCurrentNetClass Must be called after a netclass selection (or after a netclass parameter ...
bool SaveBoard ( wxString &  aFileName,
BOARD aBoard 
)

Definition at line 96 of file pcbnew_scripting_helpers.cpp.

References IO_MGR::KICAD_SEXP, and SaveBoard().

97 {
98  return SaveBoard( aFileName, aBoard, IO_MGR::KICAD_SEXP );
99 }
bool SaveBoard(wxString &aFileName, BOARD *aBoard, IO_MGR::PCB_FILE_T aFormat)
S-expression Pcbnew file format.
Definition: io_mgr.h:54
void ScriptingSetPcbEditFrame ( PCB_EDIT_FRAME aPcbEditFrame)

Definition at line 54 of file pcbnew_scripting_helpers.cpp.

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

55 {
56  s_PcbEditFrame = aPcbEditFrame;
57 }
static PCB_EDIT_FRAME * s_PcbEditFrame
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 125 of file pcbnew_scripting_helpers.cpp.

References PCB_EDIT_FRAME::UpdateUserInterface().

Referenced by PCB_EDIT_FRAME::UseGalCanvas().

126 {
127  if( s_PcbEditFrame )
129 }
void UpdateUserInterface()
Update the layer manager and other widgets from the board setup (layer and items visibility, colors ...)
Definition: pcbframe.cpp:1051
static PCB_EDIT_FRAME * s_PcbEditFrame
void WindowZoom ( int  xl,
int  yl,
int  width,
int  height 
)

Definition at line 116 of file pcbnew_scripting_helpers.cpp.

References EDA_DRAW_FRAME::Window_Zoom().

117 {
118  EDA_RECT Rect( wxPoint( xl, yl ), wxSize( width, height )) ;
119 
120  if( s_PcbEditFrame )
121  s_PcbEditFrame->Window_Zoom( Rect );
122 }
Class EDA_RECT handles the component boundary box.
void Window_Zoom(EDA_RECT &Rect)
Compute the zoom factor and the new draw offset to draw the selected area (Rect) in full window scree...
Definition: zoom.cpp:103
static PCB_EDIT_FRAME * s_PcbEditFrame

Variable Documentation

PCB_EDIT_FRAME* s_PcbEditFrame = NULL
static

Definition at line 43 of file pcbnew_scripting_helpers.cpp.