KiCad PCB EDA Suite
pcbnew_scripting_helpers.h File Reference
#include <pcb_edit_frame.h>
#include <io_mgr.h>

Go to the source code of this file.

Functions

void ScriptingSetPcbEditFrame (PCB_EDIT_FRAME *aPCBEdaFrame)
 
BOARDGetBoard ()
 
BOARDLoadBoard (wxString &aFileName, IO_MGR::PCB_FILE_T aFormat)
 
BOARDLoadBoard (wxString &aFileName)
 
BOARDNewBoard (wxString &aFileName)
 Creates a new board and project with the given filename (will overwrite existing files!) More...
 
SETTINGS_MANAGERGetSettingsManager ()
 
BOARDCreateEmptyBoard ()
 Construct a default BOARD with a temporary (no filename) project. More...
 
bool SaveBoard (wxString &aFileName, BOARD *aBoard, bool aSkipSettings=false)
 Saves a copy of the given board and its associated project to the given path. More...
 
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=wxEmptyString, wxString *aLibPath=nullptr)
 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...
 
std::deque< BOARD_ITEM * > GetCurrentSelection ()
 Get the list of selected objects. 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...
 

Function Documentation

◆ CreateEmptyBoard()

BOARD * CreateEmptyBoard ( )

Construct a default BOARD with a temporary (no filename) project.

Returns
the created board.

Definition at line 226 of file pcbnew_scripting_helpers.cpp.

227{
228 // Creating a new board is not possible if running inside KiCad
229 if( s_PcbEditFrame )
230 return nullptr;
231
232 BOARD* brd = new BOARD();
233
235
236 return brd;
237}
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:265
void SetProject(PROJECT *aProject, bool aReferenceOnly=false)
Link a board to a given project.
Definition: board.cpp:172
static PCB_EDIT_FRAME * s_PcbEditFrame
PROJECT * GetDefaultProject()

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

Referenced by PCBNEW_JOBS_HANDLER::doFpExportSvg().

◆ ExportFootprintsToLibrary()

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

Save footprints in a library:

Parameters
aStoreInNewLibset 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.
aLibNameis the optional library name to create, stops dialog call. Must be called with aStoreInNewLib as true.

Definition at line 383 of file pcbnew_scripting_helpers.cpp.

384{
385 if( s_PcbEditFrame )
386 {
387 s_PcbEditFrame->ExportFootprintsToLibrary( aStoreInNewLib, aLibName, aLibPath );
388 return true;
389 }
390 else
391 {
392 return false;
393 }
394}
void ExportFootprintsToLibrary(bool aStoreInNewLib, const wxString &aLibName=wxEmptyString, wxString *aLibPath=nullptr)
Save footprints in a library:

References PCB_EDIT_FRAME::ExportFootprintsToLibrary(), and s_PcbEditFrame.

◆ ExportSpecctraDSN() [1/2]

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.

Returns
true if OK

Definition at line 338 of file pcbnew_scripting_helpers.cpp.

339{
340 try
341 {
342 ExportBoardToSpecctraFile( aBoard, aFullFilename );
343 }
344 catch( ... )
345 {
346 return false;
347 }
348
349 return true;
350}
void ExportBoardToSpecctraFile(BOARD *aBoard, const wxString &aFullFilename)
Helper method to export board to DSN file.

References ExportBoardToSpecctraFile().

◆ ExportSpecctraDSN() [2/2]

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

325{
326 if( s_PcbEditFrame )
327 {
328 bool ok = s_PcbEditFrame->ExportSpecctraFile( aFullFilename );
329 return ok;
330 }
331 else
332 {
333 return false;
334 }
335}
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,
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.

Returns
true if OK.

Definition at line 353 of file pcbnew_scripting_helpers.cpp.

355{
356 if( s_PcbEditFrame )
357 {
358 bool ok = s_PcbEditFrame->ExportVRML_File( aFullFileName, aMMtoWRMLunit,
359 aExport3DFiles, aUseRelativePaths,
360 a3D_Subdir, aXRef, aYRef );
361 return ok;
362 }
363 else
364 {
365 return false;
366 }
367}
bool ExportVRML_File(const wxString &aFullFileName, double aMMtoWRMLunit, bool aExport3DFiles, bool aUseRelativePaths, const wxString &a3D_Subdir, double aXRef, double aYRef)
Create the file(s) exporting current BOARD to a VRML file.

References PCB_EDIT_FRAME::ExportVRML_File(), and s_PcbEditFrame.

◆ GetBoard()

◆ GetCurrentSelection()

std::deque< BOARD_ITEM * > GetCurrentSelection ( )

Get the list of selected objects.

Definition at line 421 of file pcbnew_scripting_helpers.cpp.

422{
423 std::deque<BOARD_ITEM*> items;
424
425 if( s_PcbEditFrame )
426 {
428
429 std::for_each( selection.begin(), selection.end(),
430 [&items]( EDA_ITEM* item )
431 {
432 items.push_back( static_cast<BOARD_ITEM*>( item ) );
433 } );
434 }
435
436 return items;
437}
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
SELECTION & GetCurrentSelection() override
Get the current selection from the canvas area.
ITER end()
Definition: selection.h:74
ITER begin()
Definition: selection.h:73

References SELECTION::begin(), SELECTION::end(), PCB_EDIT_FRAME::GetCurrentSelection(), and s_PcbEditFrame.

Referenced by UNIT_SELECTOR_LEN::GetUnitScale(), UNIT_SELECTOR_THICKNESS::GetUnitScale(), UNIT_SELECTOR_FREQUENCY::GetUnitScale(), UNIT_SELECTOR_ANGLE::GetUnitScale(), UNIT_SELECTOR_RESISTOR::GetUnitScale(), UNIT_SELECTOR_LINEAR_RESISTANCE::GetUnitScale(), UNIT_SELECTOR_LEN_CABLE::GetUnitScale(), UNIT_SELECTOR_VOLTAGE::GetUnitScale(), UNIT_SELECTOR_POWER::GetUnitScale(), UNIT_SELECTOR_SPEED::GetUnitScale(), and UNIT_SELECTOR_TIME::GetUnitScale().

◆ GetFootprintLibraries()

wxArrayString GetFootprintLibraries ( )

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

294{
295 wxArrayString footprintLibraryNames;
296
298
299 if( !tbl )
300 return footprintLibraryNames;
301
302 for( const wxString& name : tbl->GetLogicalLibs() )
303 footprintLibraryNames.Add( name );
304
305 return footprintLibraryNames;
306}
const char * name
Definition: DXF_plotter.cpp:56
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.
FP_LIB_TABLE * GetFootprintLibraryTable()

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

◆ GetFootprints()

wxArrayString GetFootprints ( const wxString &  aNickName)

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

310{
311 wxArrayString footprintNames;
312
314
315 if( !tbl )
316 return footprintNames;
317
318 tbl->FootprintEnumerate( footprintNames, aNickName, true );
319
320 return footprintNames;
321}
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aNickname, bool aBestEfforts)
Return a list of footprint names contained within the library given by aNickname.

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

◆ GetSettingsManager()

◆ GetUserUnits()

int GetUserUnits ( )

Return the currently selected user unit value for the interface.

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

Definition at line 412 of file pcbnew_scripting_helpers.cpp.

413{
414 if( s_PcbEditFrame )
415 return static_cast<int>( s_PcbEditFrame->GetUserUnits() );
416
417 return -1;
418}
EDA_UNITS GetUserUnits() const

References UNITS_PROVIDER::GetUserUnits(), and s_PcbEditFrame.

Referenced by DRAWING_TOOL::drawArc(), and DRAWING_TOOL::drawShape().

◆ ImportSpecctraSES()

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.

Returns
true if OK

Definition at line 369 of file pcbnew_scripting_helpers.cpp.

370{
371 if( s_PcbEditFrame )
372 {
373 bool ok = s_PcbEditFrame->ImportSpecctraSession( aFullFilename );
374 return ok;
375 }
376 else
377 {
378 return false;
379 }
380}
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 ...

References PCB_EDIT_FRAME::ImportSpecctraSession(), and s_PcbEditFrame.

◆ IsActionRunning()

bool IsActionRunning ( )

Are we currently in an action plugin?

Definition at line 440 of file pcbnew_scripting_helpers.cpp.

441{
443}
static bool 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( KiCadPcbFileExtension ) )
81 return LoadBoard( aFileName, IO_MGR::KICAD_SEXP );
82 else if( aFileName.EndsWith( LegacyPcbFileExtension ) )
83 return LoadBoard( aFileName, IO_MGR::LEGACY );
84
85 // as fall back for any other kind use the legacy format
86 return LoadBoard( aFileName, IO_MGR::LEGACY );
87}
@ LEGACY
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:55
@ KICAD_SEXP
S-expression Pcbnew file format.
Definition: io_mgr.h:56
const std::string LegacyPcbFileExtension
const std::string KiCadPcbFileExtension
BOARD * LoadBoard(wxString &aFileName)

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

Referenced by PCBNEW_JOBS_HANDLER::JobExportDrill(), PCBNEW_JOBS_HANDLER::JobExportDxf(), PCBNEW_JOBS_HANDLER::JobExportGerber(), PCBNEW_JOBS_HANDLER::JobExportGerbers(), PCBNEW_JOBS_HANDLER::JobExportPdf(), PCBNEW_JOBS_HANDLER::JobExportPos(), PCBNEW_JOBS_HANDLER::JobExportStep(), PCBNEW_JOBS_HANDLER::JobExportSvg(), and LoadBoard().

◆ LoadBoard() [2/2]

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

Definition at line 128 of file pcbnew_scripting_helpers.cpp.

129{
130 wxFileName pro = aFileName;
131 pro.SetExt( ProjectFileExtension );
132 pro.MakeAbsolute();
133 wxString projectPath = pro.GetFullPath();
134
135 // Ensure the "C" locale is temporary set, before reading any file
136 // It also avoid wxWidget alerts about locale issues, later, when using Python 3
138
139 PROJECT* project = GetSettingsManager()->GetProject( projectPath );
140
141 if( !project )
142 {
143 if( wxFileExists( projectPath ) )
144 {
145 GetSettingsManager()->LoadProject( projectPath, false );
146 project = GetSettingsManager()->GetProject( projectPath );
147 }
148 }
149 else if( s_PcbEditFrame && project == &GetSettingsManager()->Prj() )
150 {
151 // Project is already loaded? Then so is the board
152 return s_PcbEditFrame->GetBoard();
153 }
154
155 // Board cannot be loaded without a project, so create the default project
156 if( !project )
158
159 BOARD* brd = IO_MGR::Load( aFormat, aFileName );
160
161 if( brd )
162 {
163 brd->SetProject( project );
164
165 // Move legacy view settings to local project settings
166 if( !brd->m_LegacyVisibleLayers.test( Rescue ) )
167 project->GetLocalSettings().m_VisibleLayers = brd->m_LegacyVisibleLayers;
168
170 project->GetLocalSettings().m_VisibleItems = brd->m_LegacyVisibleItems;
171
173 bds.m_DRCEngine = std::make_shared<DRC_ENGINE>( brd, &bds );
174
175 try
176 {
177 wxFileName rules = pro;
178 rules.SetExt( DesignRulesFileExtension );
179 bds.m_DRCEngine->InitEngine( rules );
180 }
181 catch( ... )
182 {
183 // Best efforts...
184 }
185
186 for( PCB_MARKER* marker : brd->ResolveDRCExclusions() )
187 brd->Add( marker );
188
189 brd->BuildConnectivity();
190 brd->BuildListOfNets();
191 brd->SynchronizeNetsAndNetClasses( false );
192 }
193
194 return brd;
195}
Container for design settings for a BOARD object.
std::shared_ptr< DRC_ENGINE > m_DRCEngine
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition: board.cpp:750
GAL_SET m_LegacyVisibleItems
Definition: board.h:339
void BuildListOfNets()
Definition: board.h:744
bool BuildConnectivity(PROGRESS_REPORTER *aReporter=nullptr)
Build or rebuild the board connectivity database for the board, especially the list of connected item...
Definition: board.cpp:162
void SynchronizeNetsAndNetClasses(bool aResetTrackAndViaSizes)
Copy NETCLASS info to each NET, based on NET membership in a NETCLASS.
Definition: board.cpp:1524
LSET m_LegacyVisibleLayers
Visibility settings stored in board prior to 6.0, only used for loading legacy files.
Definition: board.h:338
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:682
std::vector< PCB_MARKER * > ResolveDRCExclusions()
Rebuild DRC markers from the serialized data in BOARD_DESIGN_SETTINGS.
Definition: board.cpp:296
static BOARD * Load(PCB_FILE_T aFileType, const wxString &aFileName, BOARD *aAppendToMe=nullptr, const STRING_UTF8_MAP *aProperties=nullptr, PROJECT *aProject=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)
Find the requested PLUGIN and if found, calls the PLUGIN::Load() function on it using the arguments p...
Definition: io_mgr.cpp:162
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:41
Container for project specific data.
Definition: project.h:64
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.
const std::string ProjectFileExtension
const std::string DesignRulesFileExtension
PROJECT & Prj()
Definition: kicad.cpp:573
@ GAL_LAYER_ID_BITMASK_END
This is the end of the layers used for visibility bit masks in legacy board files.
Definition: layer_ids.h:226
@ Rescue
Definition: layer_ids.h:133
#define GAL_LAYER_INDEX(x)
Use this macro to convert a GAL layer to a 0-indexed offset from LAYER_VIAS.
Definition: layer_ids.h:264
SETTINGS_MANAGER * GetSettingsManager()
std::vector< FAB_LAYER_COLOR > dummy

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_LegacyVisibleItems, BOARD::m_LegacyVisibleLayers, Prj(), project, ProjectFileExtension, Rescue, BOARD::ResolveDRCExclusions(), s_PcbEditFrame, BOARD::SetProject(), and BOARD::SynchronizeNetsAndNetClasses().

◆ NewBoard()

BOARD * NewBoard ( wxString &  aFileName)

Creates a new board and project with the given filename (will overwrite existing files!)

Parameters
aFileNameis the filename (including full path if desired) of the kicad_pcb to create
Returns
a pointer to the board if it was created, or None if not

Definition at line 198 of file pcbnew_scripting_helpers.cpp.

199{
200 wxFileName boardFn = aFileName;
201 wxFileName proFn = aFileName;
202 proFn.SetExt( ProjectFileExtension );
203 proFn.MakeAbsolute();
204
205 wxString projectPath = proFn.GetFullPath();
206
207 // Ensure the "C" locale is temporary set, before reading any file
208 // It also avoids wxWidgets alerts about locale issues, later, when using Python 3
210
211 GetSettingsManager()->LoadProject( projectPath, false );
212 PROJECT* project = GetSettingsManager()->GetProject( projectPath );
213
214 BOARD* brd = new BOARD();
215
216 brd->SetProject( project );
218 bds.m_DRCEngine = std::make_shared<DRC_ENGINE>( brd, &bds );
219
220 SaveBoard( aFileName, brd );
221
222 return brd;
223}
bool SaveBoard(wxString &aFileName, BOARD *aBoard, IO_MGR::PCB_FILE_T aFormat, bool aSkipSettings)

References dummy, BOARD::GetDesignSettings(), SETTINGS_MANAGER::GetProject(), GetSettingsManager(), SETTINGS_MANAGER::LoadProject(), BOARD_DESIGN_SETTINGS::m_DRCEngine, project, ProjectFileExtension, SaveBoard(), and BOARD::SetProject().

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

397{
398 if( s_PcbEditFrame )
399 {
401 }
402}
void RebuildAndRefresh()
Rebuilds board connectivity, refreshes canvas.

References PCB_EDIT_FRAME::RebuildAndRefresh(), and s_PcbEditFrame.

Referenced by EDA_MSG_PANEL::AppendMessage(), BITMAP_BUTTON::Check(), EDA_3D_MODEL_VIEWER::Clear3DModel(), ACTION_TOOLBAR::doSelectAction(), SYMBOL_EDIT_FRAME::emptyScreen(), BITMAP_BUTTON::Enable(), SPLIT_BUTTON::Enable(), STD_BITMAP_BUTTON::Enable(), EDA_MSG_PANEL::EraseMsgBox(), PANEL_GALVANIC_CORROSION::fillTable(), PCB_EDIT_FRAME::ImportSpecctraSession(), ACTION_TOOLBAR::KiRealize(), SYMBOL_EDIT_FRAME::LoadOneLibrarySymbolAux(), SYMBOL_EDIT_FRAME::LoadSymbolFromSchematic(), PANEL_RF_ATTENUATORS::OnAttenuatorSelection(), APPEARANCE_CONTROLS::OnBoardChanged(), PCB_EDIT_FRAME::onBoardLoaded(), WX_COLLAPSIBLE_PANE_HEADER::onEnterWindow(), EDA_3D_CANVAS::OnEvent(), WX_COLLAPSIBLE_PANE_HEADER::onFocus(), BITMAP_BUTTON::OnKillFocus(), SPLIT_BUTTON::OnKillFocus(), STD_BITMAP_BUTTON::OnKillFocus(), APPEARANCE_CONTROLS::OnLanguageChanged(), APPEARANCE_CONTROLS::OnLayerChanged(), PANEL_SETUP_BOARD_STACKUP::OnLayersOptionsChanged(), WX_COLLAPSIBLE_PANE_HEADER::onLeaveWindow(), BITMAP_BUTTON::OnLeftButtonDown(), SPLIT_BUTTON::OnLeftButtonDown(), STD_BITMAP_BUTTON::OnLeftButtonDown(), BITMAP_BUTTON::OnLeftButtonUp(), SPLIT_BUTTON::OnLeftButtonUp(), STD_BITMAP_BUTTON::OnLeftButtonUp(), BM2CMP_FRAME::OnLoadFile(), BITMAP_BUTTON::OnMouseEnter(), SPLIT_BUTTON::OnMouseEnter(), STD_BITMAP_BUTTON::OnMouseEnter(), BITMAP_BUTTON::OnMouseLeave(), SPLIT_BUTTON::OnMouseLeave(), STD_BITMAP_BUTTON::OnMouseLeave(), EDA_3D_MODEL_VIEWER::OnMouseMove(), EDA_3D_MODEL_VIEWER::OnMouseWheel(), BM2CMP_FRAME::OnNegativeClicked(), DIALOG_TEMPLATE_SELECTOR::onNotebookResize(), LAYERS_MAP_DIALOG::OnResetClick(), LAYERS_MAP_DIALOG::OnSelectLayer(), BITMAP_BUTTON::OnSetFocus(), PANEL_PACKAGES_VIEW::OnSizeInfoBox(), SPLIT_BUTTON::onThemeChanged(), STD_BITMAP_BUTTON::onThemeChanged(), BM2CMP_FRAME::OnThresholdChange(), PANEL_TRANSLINE::OnTransLineResetButtonClick(), PANEL_TRANSLINE::OnTranslineSelection(), ACTION_TOOLBAR::RefreshBitmaps(), PANEL_REGULATOR::RegulatorPageUpdate(), DIALOG_JUNCTION_PROPS::resetDefaults(), DIALOG_LINE_PROPERTIES::resetDefaults(), DIALOG_WIRE_BUS_PROPERTIES::resetDefaults(), TEMPLATE_WIDGET::Select(), EDA_3D_MODEL_VIEWER::Set3DModel(), WX_COLLAPSIBLE_PANE_HEADER::SetCollapsed(), SPLIT_BUTTON::SetLabel(), EDA_MSG_PANEL::SetMessage(), PANEL_PACKAGE::SetSelected(), FOOTPRINTS_LISTBOX::SetSelection(), LIBRARY_LISTBOX::SetSelection(), PANEL_COLOR_CODE::ThemeChanged(), PANEL_RF_ATTENUATORS::ThemeChanged(), PANEL_COLOR_CODE::ToleranceSelection(), TEMPLATE_WIDGET::Unselect(), mpWindow::UpdateAll(), KIGFX::CAIRO_GAL::updatedGalDisplayOptions(), KIGFX::OPENGL_GAL::updatedGalDisplayOptions(), DIALOG_PAGES_SETTINGS::UpdateDrawingSheetExample(), and NUMBER_BADGE::UpdateNumber().

◆ SaveBoard()

bool SaveBoard ( wxString &  aFileName,
BOARD aBoard,
bool  aSkipSettings = false 
)

Saves a copy of the given board and its associated project to the given path.

Boards can only be saved in KiCad native format.

Parameters
aFileNameis the full path to save a copy to.
aBoardis a pointer to a loaded BOARD to save.
aSkipSettingsif true, only save the board file. This will lose settings changes that are saved in the project file
Returns
true if the save was completed.

Definition at line 271 of file pcbnew_scripting_helpers.cpp.

272{
273 return SaveBoard( aFileName, aBoard, IO_MGR::KICAD_SEXP, aSkipSettings );
274}

References IO_MGR::KICAD_SEXP, and SaveBoard().

◆ ScriptingSetPcbEditFrame()

void ScriptingSetPcbEditFrame ( PCB_EDIT_FRAME aPCBEdaFrame)

Definition at line 72 of file pcbnew_scripting_helpers.cpp.

73{
74 s_PcbEditFrame = aPcbEditFrame;
75}

References s_PcbEditFrame.

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

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

406{
407 if( s_PcbEditFrame )
409}
void UpdateUserInterface()
Update the layer manager and other widgets from the board setup (layer and items visibility,...

References s_PcbEditFrame, and PCB_EDIT_FRAME::UpdateUserInterface().

◆ WriteDRCReport()

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.

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

448{
449 wxCHECK( aBoard, false );
450
452 std::shared_ptr<DRC_ENGINE> engine = bds.m_DRCEngine;
453 UNITS_PROVIDER unitsProvider( pcbIUScale, aUnits );
454
455 if( !engine )
456 {
457 bds.m_DRCEngine = std::make_shared<DRC_ENGINE>( aBoard, &bds );
458 engine = bds.m_DRCEngine;
459 }
460
461 wxCHECK( engine, false );
462
463 wxFileName fn = aBoard->GetFileName();
464 fn.SetExt( DesignRulesFileExtension );
465 PROJECT* prj = nullptr;
466
467 if( aBoard->GetProject() )
468 prj = aBoard->GetProject();
469 else if( s_SettingsManager )
470 prj = &s_SettingsManager->Prj();
471
472 wxCHECK( prj, false );
473
474 wxString drcRulesPath = prj->AbsolutePath( fn.GetFullName() );
475
476 // Rebuild The Instance of ENUM_MAP<PCB_LAYER_ID> (layer names list), because the DRC
477 // engine can use layer names (canonical and/or user names)
479 layerEnum.Choices().Clear();
480 layerEnum.Undefined( UNDEFINED_LAYER );
481
482 for( LSEQ seq = LSET::AllLayersMask().Seq(); seq; ++seq )
483 {
484 layerEnum.Map( *seq, LSET::Name( *seq ) ); // Add Canonical name
485 layerEnum.Map( *seq, aBoard->GetLayerName( *seq ) ); // Add User name
486 }
487
488 try
489 {
490 engine->InitEngine( drcRulesPath );
491 }
492 catch( PARSE_ERROR& err )
493 {
494 fprintf( stderr, "Init DRC engine: err <%s>\n", TO_UTF8( err.What() ) ); fflush( stderr);
495 return false;
496 }
497
498 std::vector<std::shared_ptr<DRC_ITEM>> footprints;
499 std::vector<std::shared_ptr<DRC_ITEM>> unconnected;
500 std::vector<std::shared_ptr<DRC_ITEM>> violations;
501
502 engine->SetProgressReporter( nullptr );
503
504 engine->SetViolationHandler(
505 [&]( const std::shared_ptr<DRC_ITEM>& aItem, VECTOR2D aPos, int aLayer )
506 {
507 if( aItem->GetErrorCode() == DRCE_MISSING_FOOTPRINT
508 || aItem->GetErrorCode() == DRCE_DUPLICATE_FOOTPRINT
509 || aItem->GetErrorCode() == DRCE_EXTRA_FOOTPRINT
510 || aItem->GetErrorCode() == DRCE_NET_CONFLICT )
511 {
512 footprints.push_back( aItem );
513 }
514 else if( aItem->GetErrorCode() == DRCE_UNCONNECTED_ITEMS )
515 {
516 unconnected.push_back( aItem );
517 }
518 else
519 {
520 violations.push_back( aItem );
521 }
522 } );
523
524 engine->RunTests( aUnits, aReportAllTrackErrors, false );
525 engine->ClearViolationHandler();
526
527 // TODO: Unify this with DIALOG_DRC::writeReport
528
529 FILE* fp = wxFopen( aFileName, wxT( "w" ) );
530
531 if( fp == nullptr )
532 return false;
533
534 std::map<KIID, EDA_ITEM*> itemMap;
535 aBoard->FillItemMap( itemMap );
536
537 fprintf( fp, "** Drc report for %s **\n", TO_UTF8( aBoard->GetFileName() ) );
538
539 wxDateTime now = wxDateTime::Now();
540
541 fprintf( fp, "** Created on %s **\n", TO_UTF8( now.Format( wxT( "%F %T" ) ) ) );
542
543 fprintf( fp, "\n** Found %d DRC violations **\n", static_cast<int>( violations.size() ) );
544
545 for( const std::shared_ptr<DRC_ITEM>& item : violations )
546 {
547 SEVERITY severity = item->GetParent() ? item->GetParent()->GetSeverity()
548 : bds.GetSeverity( item->GetErrorCode() );
549 fprintf( fp, "%s", TO_UTF8( item->ShowReport( &unitsProvider, severity, itemMap ) ) );
550 }
551
552 fprintf( fp, "\n** Found %d unconnected pads **\n", static_cast<int>( unconnected.size() ) );
553
554 for( const std::shared_ptr<DRC_ITEM>& item : unconnected )
555 {
556 SEVERITY severity = bds.GetSeverity( item->GetErrorCode() );
557 fprintf( fp, "%s", TO_UTF8( item->ShowReport( &unitsProvider, severity, itemMap ) ) );
558 }
559
560 fprintf( fp, "\n** Found %d Footprint errors **\n", static_cast<int>( footprints.size() ) );
561
562 for( const std::shared_ptr<DRC_ITEM>& item : footprints )
563 {
564 SEVERITY severity = bds.GetSeverity( item->GetErrorCode() );
565 fprintf( fp, "%s", TO_UTF8( item->ShowReport( &unitsProvider, severity, itemMap ) ) );
566 }
567
568 fprintf( fp, "\n** End of Report **\n" );
569 fclose( fp );
570
571 return true;
572}
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:109
SEVERITY GetSeverity(int aDRCErrorCode)
const wxString & GetFileName() const
Definition: board.h:302
void FillItemMap(std::map< KIID, EDA_ITEM * > &aMap)
Definition: board.cpp:1076
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:452
PROJECT * GetProject() const
Definition: board.h:440
ENUM_MAP & Map(T aValue, const wxString &aName)
Definition: property.h:579
static ENUM_MAP< T > & Instance()
Definition: property.h:573
ENUM_MAP & Undefined(T aValue)
Definition: property.h:586
wxPGChoices & Choices()
Definition: property.h:622
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition: layer_ids.h:491
static LSET AllLayersMask()
Definition: lset.cpp:808
static const wxChar * Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:82
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.
Definition: project.cpp:305
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
@ DRCE_UNCONNECTED_ITEMS
Definition: drc_item.h:39
@ DRCE_DUPLICATE_FOOTPRINT
Definition: drc_item.h:71
@ DRCE_EXTRA_FOOTPRINT
Definition: drc_item.h:72
@ DRCE_NET_CONFLICT
Definition: drc_item.h:73
@ DRCE_MISSING_FOOTPRINT
Definition: drc_item.h:70
@ UNDEFINED_LAYER
Definition: layer_ids.h:60
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
SEVERITY
A filename or source description, a problem input line, a line number, a byte offset,...
Definition: ki_exception.h:119

References PROJECT::AbsolutePath(), LSET::AllLayersMask(), ENUM_MAP< T >::Choices(), DesignRulesFileExtension, DRCE_DUPLICATE_FOOTPRINT, DRCE_EXTRA_FOOTPRINT, DRCE_MISSING_FOOTPRINT, DRCE_NET_CONFLICT, DRCE_UNCONNECTED_ITEMS, BOARD::FillItemMap(), BOARD::GetDesignSettings(), BOARD::GetFileName(), BOARD::GetLayerName(), BOARD::GetProject(), BOARD_DESIGN_SETTINGS::GetSeverity(), ENUM_MAP< T >::Instance(), BOARD_DESIGN_SETTINGS::m_DRCEngine, ENUM_MAP< T >::Map(), LSET::Name(), pcbIUScale, SETTINGS_MANAGER::Prj(), s_SettingsManager, TO_UTF8, ENUM_MAP< T >::Undefined(), UNDEFINED_LAYER, and IO_ERROR::What().