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 <board.h>
#include <pcb_marker.h>
#include <cstdlib>
#include <drc/drc_engine.h>
#include <drc/drc_item.h>
#include <fp_lib_table.h>
#include <io_mgr.h>
#include <kicad_string.h>
#include <pcbnew_scripting_helpers.h>
#include <project.h>
#include <settings/settings_manager.h>
#include <project/project_local_settings.h>
#include <wildcards_and_files_ext.h>

Go to the source code of this file.

Functions

wxApp * GetApp ()
 
BOARDGetBoard ()
 
void ScriptingSetPcbEditFrame (PCB_EDIT_FRAME *aPcbEditFrame)
 
BOARDLoadBoard (wxString &aFileName)
 
SETTINGS_MANAGERGetSettingsManager ()
 
PROJECTGetDefaultProject ()
 
BOARDLoadBoard (wxString &aFileName, IO_MGR::PCB_FILE_T aFormat)
 
BOARDCreateEmptyBoard ()
 Constructs a default BOARD with a tempoary (no filename) project. More...
 
bool SaveBoard (wxString &aFileName, BOARD *aBoard, IO_MGR::PCB_FILE_T aFormat)
 
bool SaveBoard (wxString &aFileName, BOARD *aBoard)
 
FP_LIB_TABLEGetFootprintLibraryTable ()
 
wxArrayString GetFootprintLibraries ()
 will 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)
 will 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 ExportVRML (const wxString &aFullFileName, double aMMtoWRMLunit, bool aExport3DFiles, bool aUseRelativePaths, bool aUsePlainPCB, const wxString &a3D_Subdir, double aXRef, double aYRef)
 will export the current BOARD to a VRML (wrl) 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 ExportFootprintsToLibrary (bool aStoreInNewLib, const wxString &aLibName, wxString *aLibPath)
 Function ExportFootprintsToLibrary 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 ()
 Returns 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)
 Runs the DRC check on the given board and writes the results to a report file. More...
 

Variables

static PCB_EDIT_FRAMEs_PcbEditFrame = NULL
 
static SETTINGS_MANAGERs_SettingsManager = nullptr
 
static wxApp * s_WxApp = nullptr
 A valid app is needed for preventing some asserts when opening the settings manager. More...
 

Detailed Description

Scripting helper functions for pcbnew functionality.

Definition in file pcbnew_scripting_helpers.cpp.

Function Documentation

◆ CreateEmptyBoard()

BOARD* CreateEmptyBoard ( )

Constructs a default BOARD with a tempoary (no filename) project.

Returns
the created board

Definition at line 177 of file pcbnew_scripting_helpers.cpp.

178 {
179  BOARD* brd = new BOARD();
180 
181  brd->SetProject( GetDefaultProject() );
182 
183  return brd;
184 }
PROJECT * GetDefaultProject()
void SetProject(PROJECT *aProject)
Links a board to a given project.
Definition: board.cpp:139
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190

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

◆ ExportFootprintsToLibrary()

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

Function ExportFootprintsToLibrary Save footprints in a library:

Parameters
aStoreInNewLibtrue : 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 false: save footprints 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 303 of file pcbnew_scripting_helpers.cpp.

304 {
305  if( s_PcbEditFrame )
306  {
307  s_PcbEditFrame->ExportFootprintsToLibrary( aStoreInNewLib, aLibName, aLibPath );
308  return true;
309  }
310  else
311  {
312  return false;
313  }
314 }
void ExportFootprintsToLibrary(bool aStoreInNewLib, const wxString &aLibName=wxEmptyString, wxString *aLibPath=NULL)
Save footprints in a library:
static PCB_EDIT_FRAME * s_PcbEditFrame

References PCB_EDIT_FRAME::ExportFootprintsToLibrary(), 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 258 of file pcbnew_scripting_helpers.cpp.

259 {
260  if( s_PcbEditFrame )
261  {
262  bool ok = s_PcbEditFrame->ExportSpecctraFile( aFullFilename );
263  return ok;
264  }
265  else
266  {
267  return false;
268  }
269 }
static PCB_EDIT_FRAME * s_PcbEditFrame
bool ExportSpecctraFile(const wxString &aFullFilename)
Export the current BOARD to a specctra dsn file.

References PCB_EDIT_FRAME::ExportSpecctraFile(), and s_PcbEditFrame.

◆ ExportVRML()

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

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

275 {
276  if( s_PcbEditFrame )
277  {
278  bool ok = s_PcbEditFrame->ExportVRML_File( aFullFileName, aMMtoWRMLunit,
279  aExport3DFiles, aUseRelativePaths,
280  aUsePlainPCB, a3D_Subdir, aXRef, aYRef );
281  return ok;
282  }
283  else
284  {
285  return false;
286  }
287 }
bool ExportVRML_File(const wxString &aFullFileName, double aMMtoWRMLunit, bool aExport3DFiles, bool aUseRelativePaths, bool aUsePlainPCB, const wxString &a3D_Subdir, double aXRef, double aYRef)
Creates the file(s) exporting current BOARD to a VRML file.
static PCB_EDIT_FRAME * s_PcbEditFrame

References PCB_EDIT_FRAME::ExportVRML_File(), and s_PcbEditFrame.

Referenced by VRML_WRITER::ExportVRML_File().

◆ GetApp()

wxApp* GetApp ( )

Definition at line 56 of file pcbnew_scripting_helpers.cpp.

57 {
58  if( !s_WxApp )
59  s_WxApp = new wxApp();
60 
61  return s_WxApp;
62 }
static wxApp * s_WxApp
A valid app is needed for preventing some asserts when opening the settings manager.

References s_WxApp.

Referenced by GetSettingsManager().

◆ GetBoard()

BOARD* GetBoard ( )

Definition at line 65 of file pcbnew_scripting_helpers.cpp.

66 {
67  if( s_PcbEditFrame )
68  return s_PcbEditFrame->GetBoard();
69  else
70  return NULL;
71 }
#define NULL
BOARD * GetBoard() const
static PCB_EDIT_FRAME * s_PcbEditFrame

References PCB_BASE_FRAME::GetBoard(), NULL, 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().

◆ GetDefaultProject()

PROJECT* GetDefaultProject ( )

Definition at line 105 of file pcbnew_scripting_helpers.cpp.

106 {
107  PROJECT* project = GetSettingsManager()->GetProject( "" );
108 
109  if( !project )
110  {
112  project = GetSettingsManager()->GetProject( "" );
113  }
114 
115  return project;
116 }
Container for project specific data.
Definition: project.h:62
SETTINGS_MANAGER * GetSettingsManager()
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Loads a project or sets up a new project with a specified path.
PROJECT * GetProject(const wxString &aFullPath) const
Retrieves a loaded project by name.

References SETTINGS_MANAGER::GetProject(), GetSettingsManager(), and SETTINGS_MANAGER::LoadProject().

Referenced by CreateEmptyBoard(), and LoadBoard().

◆ GetFootprintLibraries()

wxArrayString GetFootprintLibraries ( )

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

228 {
229  wxArrayString footprintLibraryNames;
230 
232 
233  if( !tbl )
234  return footprintLibraryNames;
235 
236  for( const wxString& name : tbl->GetLogicalLibs() )
237  footprintLibraryNames.Add( name );
238 
239  return footprintLibraryNames;
240 }
FP_LIB_TABLE * GetFootprintLibraryTable()
const char * name
Definition: DXF_plotter.cpp:59
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.

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

◆ GetFootprintLibraryTable()

FP_LIB_TABLE* GetFootprintLibraryTable ( )

Definition at line 211 of file pcbnew_scripting_helpers.cpp.

212 {
213  BOARD* board = GetBoard();
214 
215  if( !board )
216  return nullptr;
217 
218  PROJECT* project = board->GetProject();
219 
220  if( !project )
221  return nullptr;
222 
223  return project->PcbFootprintLibs();
224 }
Container for project specific data.
Definition: project.h:62
PROJECT * GetProject() const
Definition: board.h:430
BOARD * GetBoard()
virtual FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190

References GetBoard(), BOARD::GetProject(), and PROJECT::PcbFootprintLibs().

Referenced by GetFootprintLibraries(), and GetFootprints().

◆ GetFootprints()

wxArrayString GetFootprints ( const wxString &  aNickName)

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

244 {
245  wxArrayString footprintNames;
246 
248 
249  if( !tbl )
250  return footprintNames;
251 
252  tbl->FootprintEnumerate( footprintNames, aNickName, true );
253 
254  return footprintNames;
255 }
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aNickname, bool aBestEfforts)
Return a list of footprint names contained within the library given by aNickname.
FP_LIB_TABLE * GetFootprintLibraryTable()

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

◆ GetSettingsManager()

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

338 {
339  if( s_PcbEditFrame )
340  return static_cast<int>( s_PcbEditFrame->GetUserUnits() );
341 
342  return -1;
343 }
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.

Referenced by DRAWING_TOOL::drawArc(), and PCB_CONTROL::placeBoardItems().

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

290 {
291  if( s_PcbEditFrame )
292  {
293  bool ok = s_PcbEditFrame->ImportSpecctraSession( aFullFilename );
294  return ok;
295  }
296  else
297  {
298  return false;
299  }
300 }
bool ImportSpecctraSession(const wxString &aFullFilename)
Import a specctra *.ses file and use it to relocate MODULEs and to replace all vias and tracks in an ...
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 346 of file pcbnew_scripting_helpers.cpp.

347 {
349 }
static bool IsActionRunning()
Function IsActionRunning.

References ACTION_PLUGINS::IsActionRunning().

◆ LoadBoard() [1/2]

BOARD* LoadBoard ( wxString &  aFileName)

Definition at line 80 of file pcbnew_scripting_helpers.cpp.

81 {
82  if( aFileName.EndsWith( KiCadPcbFileExtension ) )
83  return LoadBoard( aFileName, IO_MGR::KICAD_SEXP );
84  else if( aFileName.EndsWith( LegacyPcbFileExtension ) )
85  return LoadBoard( aFileName, IO_MGR::LEGACY );
86 
87  // as fall back for any other kind use the legacy format
88  return LoadBoard( aFileName, IO_MGR::LEGACY );
89 }
BOARD * LoadBoard(wxString &aFileName)
const std::string LegacyPcbFileExtension
const std::string KiCadPcbFileExtension
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:54
S-expression Pcbnew file format.
Definition: io_mgr.h:55

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

Referenced by LoadBoard().

◆ LoadBoard() [2/2]

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

Definition at line 119 of file pcbnew_scripting_helpers.cpp.

120 {
121  wxFileName pro = aFileName;
122  pro.SetExt( ProjectFileExtension );
123  pro.MakeAbsolute();
124  wxString projectPath = pro.GetFullPath();
125 
126  PROJECT* project = GetSettingsManager()->GetProject( projectPath );
127 
128  if( !project )
129  {
130  GetSettingsManager()->LoadProject( projectPath );
131  project = GetSettingsManager()->GetProject( projectPath );
132  }
133 
134  // Board cannot be loaded without a project, so create the default project
135  if( !project )
136  project = GetDefaultProject();
137 
138  BOARD* brd = IO_MGR::Load( aFormat, aFileName );
139 
140  if( brd )
141  {
142  brd->SetProject( project );
143 
144  // Move legacy view settings to local project settings
145  if( !brd->m_LegacyVisibleLayers.test( Rescue ) )
147 
150 
152  bds.m_DRCEngine = std::make_shared<DRC_ENGINE>( brd, &bds );
153 
154  try
155  {
156  wxFileName rules = pro;
157  rules.SetExt( DesignRulesFileExtension );
158  bds.m_DRCEngine->InitEngine( rules );
159  }
160  catch( ... )
161  {
162  // Best efforts...
163  }
164 
165  for( PCB_MARKER* marker : brd->ResolveDRCExclusions() )
166  brd->Add( marker );
167 
168  brd->BuildConnectivity();
169  brd->BuildListOfNets();
171  }
172 
173  return brd;
174 }
LSET m_VisibleLayers
Board settings.
void BuildListOfNets()
Definition: board.h:733
Container for project specific data.
Definition: project.h:62
const std::string ProjectFileExtension
const std::string DesignRulesFileExtension
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.h:591
This is the end of the layers used for visibility bit masks in Pcbnew.
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
Definition: project.h:151
void SynchronizeNetsAndNetClasses()
Copy NETCLASS info to each NET, based on NET membership in a NETCLASS.
Definition: board.cpp:1413
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
Definition: board.cpp:563
std::vector< PCB_MARKER * > ResolveDRCExclusions()
Rebuild DRC markers from the serialized data in BOARD_DESIGN_SETTINGS.
Definition: board.cpp:188
GAL_SET m_VisibleItems
The GAL layers (aka items) that are turned on for viewing (.
#define GAL_LAYER_INDEX(x)
Use this macro to convert a GAL layer to a 0-indexed offset from LAYER_VIAS.
void BuildConnectivity()
Builds or rebuilds the board connectivity database for the board, especially the list of connected it...
Definition: board.cpp:133
SETTINGS_MANAGER * GetSettingsManager()
PROJECT * GetDefaultProject()
static BOARD * Load(PCB_FILE_T aFileType, const wxString &aFileName, BOARD *aAppendToMe=nullptr, const PROPERTIES *aProperties=nullptr, PROJECT *aProject=nullptr)
Find the requested PLUGIN and if found, calls the PLUGIN::Load() function on it using the arguments p...
Definition: io_mgr.cpp:158
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Loads a project or sets up a new project with a specified path.
void SetProject(PROJECT *aProject)
Links a board to a given project.
Definition: board.cpp:139
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
LSET m_LegacyVisibleLayers
Visibility settings stored in board prior to 6.0, only used for loading legacy files.
Definition: board.h:334
std::shared_ptr< DRC_ENGINE > m_DRCEngine
PROJECT * GetProject(const wxString &aFullPath) const
Retrieves a loaded project by name.
Container for design settings for a BOARD object.
GAL_SET m_LegacyVisibleItems
Definition: board.h:335

References BOARD::Add(), BOARD::BuildConnectivity(), BOARD::BuildListOfNets(), DesignRulesFileExtension, GAL_LAYER_ID_BITMASK_END, GAL_LAYER_INDEX, GetDefaultProject(), BOARD::GetDesignSettings(), PROJECT::GetLocalSettings(), SETTINGS_MANAGER::GetProject(), GetSettingsManager(), IO_MGR::Load(), SETTINGS_MANAGER::LoadProject(), BOARD_DESIGN_SETTINGS::m_DRCEngine, BOARD::m_LegacyVisibleItems, BOARD::m_LegacyVisibleLayers, PROJECT_LOCAL_SETTINGS::m_VisibleItems, PROJECT_LOCAL_SETTINGS::m_VisibleLayers, ProjectFileExtension, Rescue, BOARD::ResolveDRCExclusions(), BOARD::SetProject(), 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 316 of file pcbnew_scripting_helpers.cpp.

317 {
318  if( s_PcbEditFrame )
319  {
320  auto board = s_PcbEditFrame->GetBoard();
321  board->BuildConnectivity();
322 
323  // Re-init everything: this is the easy way to do that
326  }
327 }
void ActivateGalCanvas() override
Set the #m_Pcb member in such as way as to ensure deleting any previous BOARD.
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...
Definition: board.cpp:133
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(), BITMAP_BUTTON::Check(), C3D_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::LoadOneLibraryPartAux(), SYMBOL_EDIT_FRAME::LoadSymbolFromSchematic(), PCB_CALCULATOR_FRAME::OnAttenuatorSelection(), APPEARANCE_CONTROLS::OnBoardChanged(), PCB_EDIT_FRAME::onBoardLoaded(), BITMAP_BUTTON::OnEnter(), WX_COLLAPSIBLE_PANE_HEADER::onEnterWindow(), EDA_3D_CANVAS::OnEvent(), WX_COLLAPSIBLE_PANE_HEADER::onFocus(), SPLIT_BUTTON::OnKillFocus(), APPEARANCE_CONTROLS::OnLayerChanged(), PANEL_SETUP_BOARD_STACKUP::OnLayersOptionsChanged(), BITMAP_BUTTON::OnLeave(), WX_COLLAPSIBLE_PANE_HEADER::onLeaveWindow(), SPLIT_BUTTON::OnLeftButtonDown(), BITMAP_BUTTON::OnLeftButtonDown(), SPLIT_BUTTON::OnLeftButtonUp(), BITMAP_BUTTON::OnLeftButtonUp(), BM2CMP_FRAME::OnLoadFile(), SPLIT_BUTTON::OnMouseEnter(), SPLIT_BUTTON::OnMouseLeave(), C3D_MODEL_VIEWER::OnMouseMove(), C3D_MODEL_VIEWER::OnMouseWheel(), BM2CMP_FRAME::OnNegativeClicked(), BM2CMP_FRAME::OnThresholdChange(), DIALOG_JUNCTION_PROPS::resetDefaults(), DIALOG_EDIT_LINE_STYLE::resetDefaults(), TEMPLATE_WIDGET::Select(), C3D_MODEL_VIEWER::Set3DModel(), WX_COLLAPSIBLE_PANE_HEADER::SetCollapsed(), EDA_MSG_PANEL::SetMessage(), FOOTPRINTS_LISTBOX::SetSelection(), LIBRARY_LISTBOX::SetSelection(), TEMPLATE_WIDGET::Unselect(), mpWindow::UpdateAll(), KIGFX::OPENGL_GAL::updatedGalDisplayOptions(), KIGFX::CAIRO_GAL::updatedGalDisplayOptions(), NUMBER_BADGE::UpdateNumber(), and DIALOG_PAGES_SETTINGS::UpdatePageLayoutExample().

◆ SaveBoard() [1/2]

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

Definition at line 187 of file pcbnew_scripting_helpers.cpp.

188 {
189  aBoard->BuildConnectivity();
191 
192  IO_MGR::Save( aFormat, aFileName, aBoard, NULL );
193 
194  wxFileName pro = aFileName;
195  pro.SetExt( ProjectFileExtension );
196  pro.MakeAbsolute();
197  wxString projectPath = pro.GetFullPath();
198 
199  GetSettingsManager()->SaveProject( pro.GetFullPath() );
200 
201  return true;
202 }
const std::string ProjectFileExtension
void SynchronizeNetsAndNetClasses()
Copy NETCLASS info to each NET, based on NET membership in a NETCLASS.
Definition: board.cpp:1413
#define NULL
void BuildConnectivity()
Builds or rebuilds the board connectivity database for the board, especially the list of connected it...
Definition: board.cpp:133
SETTINGS_MANAGER * GetSettingsManager()
static void Save(PCB_FILE_T aFileType, const wxString &aFileName, BOARD *aBoard, const PROPERTIES *aProperties=nullptr)
Write either a full aBoard to a storage file in a format that this implementation knows about,...
Definition: io_mgr.cpp:173
bool SaveProject(const wxString &aFullPath=wxEmptyString)
Saves a loaded project.

References BOARD::BuildConnectivity(), GetSettingsManager(), NULL, ProjectFileExtension, IO_MGR::Save(), SETTINGS_MANAGER::SaveProject(), and BOARD::SynchronizeNetsAndNetClasses().

Referenced by SaveBoard().

◆ SaveBoard() [2/2]

bool SaveBoard ( wxString &  aFileName,
BOARD aBoard 
)

Definition at line 205 of file pcbnew_scripting_helpers.cpp.

206 {
207  return SaveBoard( aFileName, aBoard, IO_MGR::KICAD_SEXP );
208 }
bool SaveBoard(wxString &aFileName, BOARD *aBoard, IO_MGR::PCB_FILE_T aFormat)
S-expression Pcbnew file format.
Definition: io_mgr.h:55

References IO_MGR::KICAD_SEXP, and SaveBoard().

◆ ScriptingSetPcbEditFrame()

void ScriptingSetPcbEditFrame ( PCB_EDIT_FRAME aPcbEditFrame)

Definition at line 74 of file pcbnew_scripting_helpers.cpp.

75 {
76  s_PcbEditFrame = aPcbEditFrame;
77 }
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 330 of file pcbnew_scripting_helpers.cpp.

331 {
332  if( s_PcbEditFrame )
334 }
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::ShowBoardSetupDialog().

◆ WriteDRCReport()

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

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

354 {
355  wxCHECK( aBoard, false );
356 
357  BOARD_DESIGN_SETTINGS& bds = aBoard->GetDesignSettings();
358  std::shared_ptr<DRC_ENGINE> engine = bds.m_DRCEngine;
359 
360  if( !engine )
361  {
362  bds.m_DRCEngine = std::make_shared<DRC_ENGINE>( aBoard, &bds );
363  engine = bds.m_DRCEngine;
364  }
365 
366  wxCHECK( engine, false );
367 
368  wxFileName fn = aBoard->GetFileName();
369  fn.SetExt( DesignRulesFileExtension );
370  wxString drcRulesPath = s_SettingsManager->Prj().AbsolutePath( fn.GetFullName() );
371 
372  try
373  {
374  engine->InitEngine( drcRulesPath );
375  }
376  catch( PARSE_ERROR& )
377  {
378  return false;
379  }
380 
381  std::vector<std::shared_ptr<DRC_ITEM>> footprints;
382  std::vector<std::shared_ptr<DRC_ITEM>> unconnected;
383  std::vector<std::shared_ptr<DRC_ITEM>> violations;
384 
385  engine->SetProgressReporter( nullptr );
386 
387  engine->SetViolationHandler(
388  [&]( const std::shared_ptr<DRC_ITEM>& aItem, wxPoint aPos )
389  {
390  if( aItem->GetErrorCode() == DRCE_MISSING_FOOTPRINT
391  || aItem->GetErrorCode() == DRCE_DUPLICATE_FOOTPRINT
392  || aItem->GetErrorCode() == DRCE_EXTRA_FOOTPRINT
393  || aItem->GetErrorCode() == DRCE_NET_CONFLICT )
394  {
395  footprints.push_back( aItem );
396  }
397  else if( aItem->GetErrorCode() == DRCE_UNCONNECTED_ITEMS )
398  {
399  unconnected.push_back( aItem );
400  }
401  else
402  {
403  violations.push_back( aItem );
404  }
405  } );
406 
407  engine->RunTests( aUnits, aReportAllTrackErrors, false );
408  engine->ClearViolationHandler();
409 
410  // TODO: Unify this with DIALOG_DRC::writeReport
411 
412  FILE* fp = wxFopen( aFileName, wxT( "w" ) );
413 
414  if( fp == nullptr )
415  return false;
416 
417  std::map<KIID, EDA_ITEM*> itemMap;
418  aBoard->FillItemMap( itemMap );
419 
420  fprintf( fp, "** Drc report for %s **\n", TO_UTF8( aBoard->GetFileName() ) );
421 
422  wxDateTime now = wxDateTime::Now();
423 
424  fprintf( fp, "** Created on %s **\n", TO_UTF8( now.Format( wxT( "%F %T" ) ) ) );
425 
426  fprintf( fp, "\n** Found %d DRC violations **\n", static_cast<int>( violations.size() ) );
427 
428  for( const std::shared_ptr<DRC_ITEM>& item : violations )
429  {
430  SEVERITY severity = bds.GetSeverity( item->GetErrorCode() );
431  fprintf( fp, "%s", TO_UTF8( item->ShowReport( aUnits, severity, itemMap ) ) );
432  }
433 
434  fprintf( fp, "\n** Found %d unconnected pads **\n", static_cast<int>( unconnected.size() ) );
435 
436  for( const std::shared_ptr<DRC_ITEM>& item : unconnected )
437  {
438  SEVERITY severity = bds.GetSeverity( item->GetErrorCode() );
439  fprintf( fp, "%s", TO_UTF8( item->ShowReport( aUnits, severity, itemMap ) ) );
440  }
441 
442  fprintf( fp, "\n** Found %d Footprint errors **\n", static_cast<int>( footprints.size() ) );
443 
444  for( const std::shared_ptr<DRC_ITEM>& item : footprints )
445  {
446  SEVERITY severity = bds.GetSeverity( item->GetErrorCode() );
447  fprintf( fp, "%s", TO_UTF8( item->ShowReport( aUnits, severity, itemMap ) ) );
448  }
449 
450  fprintf( fp, "\n** End of Report **\n" );
451  fclose( fp );
452 
453  return true;
454 }
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
SEVERITY
Definition: ui_common.h:83
const std::string DesignRulesFileExtension
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.h:591
const wxString & GetFileName() const
Definition: board.h:298
virtual const wxString AbsolutePath(const wxString &aFileName) const
Fix up aFileName if it is relative to the project's directory to be an absolute path and filename.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
static SETTINGS_MANAGER * s_SettingsManager
SEVERITY GetSeverity(int aDRCErrorCode)
A filename or source description, a problem input line, a line number, a byte offset,...
Definition: ki_exception.h:118
void FillItemMap(std::map< KIID, EDA_ITEM * > &aMap)
Definition: board.cpp:871
std::shared_ptr< DRC_ENGINE > m_DRCEngine
Container for design settings for a BOARD object.

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_DESIGN_SETTINGS::GetSeverity(), BOARD_DESIGN_SETTINGS::m_DRCEngine, SETTINGS_MANAGER::Prj(), s_SettingsManager, and TO_UTF8.

Variable Documentation

◆ s_PcbEditFrame

◆ s_SettingsManager

SETTINGS_MANAGER* s_SettingsManager = nullptr
static

Definition at line 50 of file pcbnew_scripting_helpers.cpp.

Referenced by GetSettingsManager(), and WriteDRCReport().

◆ s_WxApp

wxApp* s_WxApp = nullptr
static

A valid app is needed for preventing some asserts when opening the settings manager.

Definition at line 53 of file pcbnew_scripting_helpers.cpp.

Referenced by GetApp().