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 <class_board.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 <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 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...
 
bool WriteDRCReport (BOARD *aBoard, const wxString &aFileName, EDA_UNITS aUnits, bool aTestTracksAgainstZones, 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

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

279 {
280  if( s_PcbEditFrame )
281  {
282  s_PcbEditFrame->ArchiveModulesOnBoard( aStoreInNewLib, aLibName, aLibPath );
283  return true;
284  }
285  else
286  {
287  return false;
288  }
289 }
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.

◆ CreateEmptyBoard()

BOARD* CreateEmptyBoard ( )

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

Returns
the created board

Definition at line 151 of file pcbnew_scripting_helpers.cpp.

152 {
153  BOARD* brd = new BOARD();
154 
155  brd->SetProject( GetDefaultProject() );
156 
157  return brd;
158 }
PROJECT * GetDefaultProject()
void SetProject(PROJECT *aProject)
Links a board to a given project.
Information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:176

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

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

234 {
235  if( s_PcbEditFrame )
236  {
237  bool ok = s_PcbEditFrame->ExportSpecctraFile( aFullFilename );
238  return ok;
239  }
240  else
241  {
242  return false;
243  }
244 }
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.

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

250 {
251  if( s_PcbEditFrame )
252  {
253  bool ok = s_PcbEditFrame->ExportVRML_File( aFullFileName, aMMtoWRMLunit,
254  aExport3DFiles, aUseRelativePaths,
255  aUsePlainPCB, a3D_Subdir, aXRef, aYRef );
256  return ok;
257  }
258  else
259  {
260  return false;
261  }
262 }
bool ExportVRML_File(const wxString &aFullFileName, double aMMtoWRMLunit, bool aExport3DFiles, bool aUseRelativePaths, bool aUsePlainPCB, const wxString &a3D_Subdir, double aXRef, double aYRef)
Function ExportVRML_File 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 54 of file pcbnew_scripting_helpers.cpp.

55 {
56  if( !s_WxApp )
57  s_WxApp = new wxApp();
58 
59  return s_WxApp;
60 }
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 63 of file pcbnew_scripting_helpers.cpp.

64 {
65  if( s_PcbEditFrame )
66  return s_PcbEditFrame->GetBoard();
67  else
68  return NULL;
69 }
#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(), PCB_EDIT_FRAME::DoUpdatePCBFromNetlist(), EVT_GRID_CMD_CELL_CHANGED(), EVT_TOOL_RANGE(), PCB_EDIT_FRAME::ExportSpecctraFile(), PCB_EDIT_FRAME::ExportSVG(), 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::Load_Module_From_BOARD(), FOOTPRINT_EDIT_FRAME::LoadModuleFromLibrary(), PCB_EDIT_FRAME::LockModule(), PCB_EDIT_FRAME::onBoardLoaded(), 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::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 104 of file pcbnew_scripting_helpers.cpp.

105 {
106  PROJECT* project = GetSettingsManager()->GetProject( "" );
107 
108  if( !project )
109  {
111  project = GetSettingsManager()->GetProject( "" );
112  }
113 
114  return project;
115 }
PROJECT holds project specific data.
Definition: project.h:61
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 202 of file pcbnew_scripting_helpers.cpp.

203 {
204  wxArrayString footprintLibraryNames;
205 
207 
208  if( !tbl )
209  return footprintLibraryNames;
210 
211  for( const wxString& name : tbl->GetLogicalLibs() )
212  footprintLibraryNames.Add( name );
213 
214  return footprintLibraryNames;
215 }
FP_LIB_TABLE * GetFootprintLibraryTable()
const char * name
Definition: DXF_plotter.cpp:60
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 186 of file pcbnew_scripting_helpers.cpp.

187 {
188  BOARD* board = GetBoard();
189 
190  if( !board )
191  return nullptr;
192 
193  PROJECT* project = board->GetProject();
194 
195  if( !project )
196  return nullptr;
197 
198  return project->PcbFootprintLibs();
199 }
PROJECT holds project specific data.
Definition: project.h:61
PROJECT * GetProject() const
Definition: class_board.h:359
BOARD * GetBoard()
VTBL_ENTRY FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
Definition: project.cpp:286
Information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:176

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

219 {
220  wxArrayString footprintNames;
221 
223 
224  if( !tbl )
225  return footprintNames;
226 
227  tbl->FootprintEnumerate( footprintNames, aNickName, true );
228 
229  return footprintNames;
230 }
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 312 of file pcbnew_scripting_helpers.cpp.

313 {
314  if( s_PcbEditFrame )
315  return static_cast<int>( s_PcbEditFrame->GetUserUnits() );
316 
317  return -1;
318 }
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 264 of file pcbnew_scripting_helpers.cpp.

265 {
266  if( s_PcbEditFrame )
267  {
268  bool ok = s_PcbEditFrame->ImportSpecctraSession( aFullFilename );
269  return ok;
270  }
271  else
272  {
273  return false;
274  }
275 }
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 321 of file pcbnew_scripting_helpers.cpp.

322 {
324 }
static bool IsActionRunning()
Function IsActionRunning.

References ACTION_PLUGINS::IsActionRunning().

◆ LoadBoard() [1/2]

BOARD* LoadBoard ( wxString &  aFileName)

Definition at line 78 of file pcbnew_scripting_helpers.cpp.

79 {
80  if( aFileName.EndsWith( wxT( ".kicad_pcb" ) ) )
81  return LoadBoard( aFileName, IO_MGR::KICAD_SEXP );
82 
83  else if( aFileName.EndsWith( wxT( ".brd" ) ) )
84  return LoadBoard( aFileName, IO_MGR::LEGACY );
85 
86  // as fall back for any other kind use the legacy format
87  return LoadBoard( aFileName, IO_MGR::LEGACY );
88 }
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 118 of file pcbnew_scripting_helpers.cpp.

119 {
120  wxFileName pro = aFileName;
121  pro.SetExt( ProjectFileExtension );
122  pro.MakeAbsolute();
123  wxString projectPath = pro.GetFullPath();
124 
125  PROJECT* project = GetSettingsManager()->GetProject( projectPath );
126 
127  if( !project )
128  {
129  GetSettingsManager()->LoadProject( projectPath );
130  project = GetSettingsManager()->GetProject( projectPath );
131  }
132 
133  // Board cannot be loaded without a project, so create the default project
134  if( !project )
135  project = GetDefaultProject();
136 
137  BOARD* brd = IO_MGR::Load( aFormat, aFileName );
138 
139  if( brd )
140  {
141  brd->SetProject( project );
142  brd->BuildConnectivity();
143  brd->BuildListOfNets();
145  }
146 
147  return brd;
148 }
void BuildListOfNets()
Definition: class_board.h:663
PROJECT holds project specific data.
Definition: project.h:61
const std::string ProjectFileExtension
void SynchronizeNetsAndNetClasses()
Copy NETCLASS info to each NET, based on NET membership in a NETCLASS.
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:177
void BuildConnectivity()
Builds or rebuilds the board connectivity database for the board, especially the list of connected it...
SETTINGS_MANAGER * GetSettingsManager()
PROJECT * GetDefaultProject()
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.
Information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:176
PROJECT * GetProject(const wxString &aFullPath) const
Retrieves a loaded project by name.

References BOARD::BuildConnectivity(), BOARD::BuildListOfNets(), GetDefaultProject(), SETTINGS_MANAGER::GetProject(), GetSettingsManager(), IO_MGR::Load(), SETTINGS_MANAGER::LoadProject(), ProjectFileExtension, 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 291 of file pcbnew_scripting_helpers.cpp.

292 {
293  if( s_PcbEditFrame )
294  {
295  auto board = s_PcbEditFrame->GetBoard();
296  board->BuildConnectivity();
297 
298  // Re-init everything: this is the easy way to do that
301  }
302 }
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(), BITMAP_BUTTON::Check(), C3D_MODEL_VIEWER::Clear3DModel(), LIB_EDIT_FRAME::emptyScreen(), SPLIT_BUTTON::Enable(), BITMAP_BUTTON::Enable(), EDA_MSG_PANEL::EraseMsgBox(), PCB_EDIT_FRAME::ImportSpecctraSession(), LIB_EDIT_FRAME::LoadOneLibraryPartAux(), LIB_EDIT_FRAME::LoadSymbolFromSchematic(), PCB_CALCULATOR_FRAME::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(), 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(), C3D_MODEL_VIEWER::OnMouseMove(), C3D_MODEL_VIEWER::OnMouseWheel(), BM2CMP_FRAME::OnNegativeClicked(), FOOTPRINT_PREVIEW_WIDGET::OnStatusChange(), 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(), and DIALOG_PAGES_SETTINGS::UpdatePageLayoutExample().

◆ SaveBoard() [1/2]

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

Definition at line 161 of file pcbnew_scripting_helpers.cpp.

162 {
163  aBoard->BuildConnectivity();
166 
167  IO_MGR::Save( aFormat, aFileName, aBoard, NULL );
168 
169  wxFileName pro = aFileName;
170  pro.SetExt( ProjectFileExtension );
171  pro.MakeAbsolute();
172  wxString projectPath = pro.GetFullPath();
173 
174  GetSettingsManager()->SaveProject( pro.GetFullPath() );
175 
176  return true;
177 }
const std::string ProjectFileExtension
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: class_board.h:515
void SynchronizeNetsAndNetClasses()
Copy NETCLASS info to each NET, based on NET membership in a NETCLASS.
#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...
SETTINGS_MANAGER * GetSettingsManager()
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:192
bool SetCurrentNetClass(const wxString &aNetClassName)
Function SetCurrentNetClass Must be called after a netclass selection (or after a netclass parameter ...
bool SaveProject(const wxString &aFullPath=wxEmptyString)
Saves a loaded project.

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

Referenced by SaveBoard().

◆ SaveBoard() [2/2]

bool SaveBoard ( wxString &  aFileName,
BOARD aBoard 
)

Definition at line 180 of file pcbnew_scripting_helpers.cpp.

181 {
182  return SaveBoard( aFileName, aBoard, IO_MGR::KICAD_SEXP );
183 }
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 72 of file pcbnew_scripting_helpers.cpp.

73 {
74  s_PcbEditFrame = aPcbEditFrame;
75 }
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 305 of file pcbnew_scripting_helpers.cpp.

306 {
307  if( s_PcbEditFrame )
309 }
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  aTestTracksAgainstZones,
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
aTestTracksAgainstZonescontrols whether full track/zone checking is done (slow)
aReportAllTrackErrorscontrols whether all errors or just the first error is reported for each track
Returns
true if successful, false if not

Definition at line 327 of file pcbnew_scripting_helpers.cpp.

329 {
330  wxCHECK( aBoard, false );
331 
332  BOARD_DESIGN_SETTINGS& bds = aBoard->GetDesignSettings();
333  std::shared_ptr<DRC_ENGINE> engine = bds.m_DRCEngine;
334 
335  if( !engine )
336  {
337  bds.m_DRCEngine = std::make_shared<DRC_ENGINE>( aBoard, &bds );
338  engine = bds.m_DRCEngine;
339  }
340 
341  wxCHECK( engine, false );
342 
343  wxFileName fn = aBoard->GetFileName();
344  fn.SetExt( DesignRulesFileExtension );
345  wxString drcRulesPath = s_SettingsManager->Prj().AbsolutePath( fn.GetFullName() );
346 
347  try
348  {
349  engine->InitEngine( drcRulesPath );
350  }
351  catch( PARSE_ERROR& pe )
352  {
353  return false;
354  }
355 
356  std::vector<std::shared_ptr<DRC_ITEM>> footprints;
357  std::vector<std::shared_ptr<DRC_ITEM>> unconnected;
358  std::vector<std::shared_ptr<DRC_ITEM>> violations;
359 
360  engine->SetProgressReporter( nullptr );
361 
362  engine->SetViolationHandler(
363  [&]( const std::shared_ptr<DRC_ITEM>& aItem, wxPoint aPos )
364  {
365  if( aItem->GetErrorCode() == DRCE_MISSING_FOOTPRINT
366  || aItem->GetErrorCode() == DRCE_DUPLICATE_FOOTPRINT
367  || aItem->GetErrorCode() == DRCE_EXTRA_FOOTPRINT
368  || aItem->GetErrorCode() == DRCE_NET_CONFLICT )
369  {
370  footprints.push_back( aItem );
371  }
372  else if( aItem->GetErrorCode() == DRCE_UNCONNECTED_ITEMS )
373  {
374  unconnected.push_back( aItem );
375  }
376  else
377  {
378  violations.push_back( aItem );
379  }
380  } );
381 
382  engine->RunTests( aUnits, aTestTracksAgainstZones, aReportAllTrackErrors, false );
383  engine->ClearViolationHandler();
384 
385  // TODO: Unify this with DIALOG_DRC::writeReport
386 
387  FILE* fp = wxFopen( aFileName, wxT( "w" ) );
388 
389  if( fp == nullptr )
390  return false;
391 
392  std::map<KIID, EDA_ITEM*> itemMap;
393  aBoard->FillItemMap( itemMap );
394 
395  fprintf( fp, "** Drc report for %s **\n", TO_UTF8( aBoard->GetFileName() ) );
396 
397  wxDateTime now = wxDateTime::Now();
398 
399  fprintf( fp, "** Created on %s **\n", TO_UTF8( now.Format( wxT( "%F %T" ) ) ) );
400 
401  fprintf( fp, "\n** Found %d DRC violations **\n", static_cast<int>( violations.size() ) );
402 
403  for( const std::shared_ptr<DRC_ITEM>& item : violations )
404  {
405  SEVERITY severity = static_cast<SEVERITY>( bds.GetSeverity( item->GetErrorCode() ) );
406  fprintf( fp, "%s", TO_UTF8( item->ShowReport( aUnits, severity, itemMap ) ) );
407  }
408 
409  fprintf( fp, "\n** Found %d unconnected pads **\n", static_cast<int>( unconnected.size() ) );
410 
411  for( const std::shared_ptr<DRC_ITEM>& item : unconnected )
412  {
413  SEVERITY severity = static_cast<SEVERITY>( bds.GetSeverity( item->GetErrorCode() ) );
414  fprintf( fp, "%s", TO_UTF8( item->ShowReport( aUnits, severity, itemMap ) ) );
415  }
416 
417  fprintf( fp, "\n** Found %d Footprint errors **\n", static_cast<int>( footprints.size() ) );
418 
419  for( const std::shared_ptr<DRC_ITEM>& item : footprints )
420  {
421  SEVERITY severity = static_cast<SEVERITY>( bds.GetSeverity( item->GetErrorCode() ) );
422  fprintf( fp, "%s", TO_UTF8( item->ShowReport( aUnits, severity, itemMap ) ) );
423  }
424 
425  fprintf( fp, "\n** End of Report **\n" );
426  fclose( fp );
427 
428  return true;
429 }
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
SEVERITY
Definition: ui_common.h:45
const std::string DesignRulesFileExtension
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: class_board.h:515
const wxString & GetFileName() const
Definition: class_board.h:242
VTBL_ENTRY const wxString AbsolutePath(const wxString &aFileName) const
Function AbsolutePath fixes up aFileName if it is relative to the project's directory to be an absolu...
Definition: project.cpp:272
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:100
static SETTINGS_MANAGER * s_SettingsManager
Struct PARSE_ERROR contains a filename or source description, a problem input line,...
Definition: ki_exception.h:123
int GetSeverity(int aDRCErrorCode)
void FillItemMap(std::map< KIID, EDA_ITEM * > &aMap)
std::shared_ptr< DRC_ENGINE > m_DRCEngine
BOARD_DESIGN_SETTINGS contains 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 48 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 51 of file pcbnew_scripting_helpers.cpp.

Referenced by GetApp().