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)
 
SETTINGS_MANAGERGetSettingsManager ()
 
BOARDCreateEmptyBoard ()
 Construct a default BOARD with a temporary (no filename) project. More...
 
bool SaveBoard (wxString &aFileName, BOARD *aBoard)
 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...
 
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 195 of file pcbnew_scripting_helpers.cpp.

196 {
197  // Creating a new board is not possible if running inside KiCad
198  if( s_PcbEditFrame )
199  return nullptr;
200 
201  BOARD* brd = new BOARD();
202 
203  brd->SetProject( GetDefaultProject() );
204 
205  return brd;
206 }
PROJECT * GetDefaultProject()
void SetProject(PROJECT *aProject)
Link a board to a given project.
Definition: board.cpp:143
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
static PCB_EDIT_FRAME * s_PcbEditFrame

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

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

347 {
348  if( s_PcbEditFrame )
349  {
350  s_PcbEditFrame->ExportFootprintsToLibrary( aStoreInNewLib, aLibName, aLibPath );
351  return true;
352  }
353  else
354  {
355  return false;
356  }
357 }
void ExportFootprintsToLibrary(bool aStoreInNewLib, const wxString &aLibName=wxEmptyString, wxString *aLibPath=nullptr)
Save footprints in a library:
static PCB_EDIT_FRAME * s_PcbEditFrame

References PCB_EDIT_FRAME::ExportFootprintsToLibrary(), and s_PcbEditFrame.

◆ ExportSpecctraDSN() [1/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 287 of file pcbnew_scripting_helpers.cpp.

288 {
289  if( s_PcbEditFrame )
290  {
291  bool ok = s_PcbEditFrame->ExportSpecctraFile( aFullFilename );
292  return ok;
293  }
294  else
295  {
296  return false;
297  }
298 }
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.

◆ ExportSpecctraDSN() [2/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 301 of file pcbnew_scripting_helpers.cpp.

302 {
303  try
304  {
305  ExportBoardToSpecctraFile( aBoard, aFullFilename );
306  }
307  catch( ... )
308  {
309  return false;
310  }
311 
312  return true;
313 }
void ExportBoardToSpecctraFile(BOARD *aBoard, const wxString &aFullFilename)
Helper method to export board to DSN file.

References ExportBoardToSpecctraFile().

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

318 {
319  if( s_PcbEditFrame )
320  {
321  bool ok = s_PcbEditFrame->ExportVRML_File( aFullFileName, aMMtoWRMLunit,
322  aExport3DFiles, aUseRelativePaths,
323  a3D_Subdir, aXRef, aYRef );
324  return ok;
325  }
326  else
327  {
328  return false;
329  }
330 }
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.
static PCB_EDIT_FRAME * s_PcbEditFrame

References PCB_EDIT_FRAME::ExportVRML_File(), and s_PcbEditFrame.

Referenced by VRML_WRITER::ExportVRML_File().

◆ GetBoard()

BOARD* GetBoard ( )

Definition at line 61 of file pcbnew_scripting_helpers.cpp.

62 {
63  if( s_PcbEditFrame )
64  return s_PcbEditFrame->GetBoard();
65  else
66  return nullptr;
67 }
BOARD * GetBoard() const
static PCB_EDIT_FRAME * s_PcbEditFrame

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

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

257 {
258  wxArrayString footprintLibraryNames;
259 
261 
262  if( !tbl )
263  return footprintLibraryNames;
264 
265  for( const wxString& name : tbl->GetLogicalLibs() )
266  footprintLibraryNames.Add( name );
267 
268  return footprintLibraryNames;
269 }
FP_LIB_TABLE * GetFootprintLibraryTable()
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.

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

273 {
274  wxArrayString footprintNames;
275 
277 
278  if( !tbl )
279  return footprintNames;
280 
281  tbl->FootprintEnumerate( footprintNames, aNickName, true );
282 
283  return footprintNames;
284 }
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 ( )

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

381 {
382  if( s_PcbEditFrame )
383  return static_cast<int>( s_PcbEditFrame->GetUserUnits() );
384 
385  return -1;
386 }
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)

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

333 {
334  if( s_PcbEditFrame )
335  {
336  bool ok = s_PcbEditFrame->ImportSpecctraSession( aFullFilename );
337  return ok;
338  }
339  else
340  {
341  return false;
342  }
343 }
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 389 of file pcbnew_scripting_helpers.cpp.

390 {
392 }
static bool IsActionRunning()

References ACTION_PLUGINS::IsActionRunning().

◆ LoadBoard() [1/2]

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

Definition at line 130 of file pcbnew_scripting_helpers.cpp.

131 {
132  // Loading a new board is not possible if running inside KiCad
133  wxASSERT( !s_PcbEditFrame );
134 
135  wxFileName pro = aFileName;
136  pro.SetExt( ProjectFileExtension );
137  pro.MakeAbsolute();
138  wxString projectPath = pro.GetFullPath();
139 
140  // Ensure the "C" locale is temporary set, before reading any file
141  // It also avoid wxWidget alerts about locale issues, later, when using Python 3
143 
144  PROJECT* project = GetSettingsManager()->GetProject( projectPath );
145 
146  if( !project )
147  {
148  GetSettingsManager()->LoadProject( projectPath );
149  project = GetSettingsManager()->GetProject( projectPath );
150  }
151 
152  // Board cannot be loaded without a project, so create the default project
153  if( !project )
155 
156  BOARD* brd = IO_MGR::Load( aFormat, aFileName );
157 
158  if( brd )
159  {
160  brd->SetProject( project );
161 
162  // Move legacy view settings to local project settings
163  if( !brd->m_LegacyVisibleLayers.test( Rescue ) )
164  project->GetLocalSettings().m_VisibleLayers = brd->m_LegacyVisibleLayers;
165 
167  project->GetLocalSettings().m_VisibleItems = brd->m_LegacyVisibleItems;
168 
170  bds.m_DRCEngine = std::make_shared<DRC_ENGINE>( brd, &bds );
171 
172  try
173  {
174  wxFileName rules = pro;
175  rules.SetExt( DesignRulesFileExtension );
176  bds.m_DRCEngine->InitEngine( rules );
177  }
178  catch( ... )
179  {
180  // Best efforts...
181  }
182 
183  for( PCB_MARKER* marker : brd->ResolveDRCExclusions() )
184  brd->Add( marker );
185 
186  brd->BuildConnectivity();
187  brd->BuildListOfNets();
189  }
190 
191  return brd;
192 }
void BuildListOfNets()
Definition: board.h:658
Container for project specific data.
Definition: project.h:62
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
const std::string ProjectFileExtension
const std::string DesignRulesFileExtension
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:590
This is the end of the layers used for visibility bit masks in Pcbnew.
Definition: layer_ids.h:222
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:72
void SynchronizeNetsAndNetClasses()
Copy NETCLASS info to each NET, based on NET membership in a NETCLASS.
Definition: board.cpp:1391
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
Definition: board.cpp:608
std::vector< PCB_MARKER * > ResolveDRCExclusions()
Rebuild DRC markers from the serialized data in BOARD_DESIGN_SETTINGS.
Definition: board.cpp:208
#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:249
void BuildConnectivity()
Build or rebuild the board connectivity database for the board, especially the list of connected item...
Definition: board.cpp:137
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)
Link a board to a given project.
Definition: board.cpp:143
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
static BOARD * Load(PCB_FILE_T aFileType, const wxString &aFileName, BOARD *aAppendToMe=nullptr, const PROPERTIES *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:158
LSET m_LegacyVisibleLayers
Visibility settings stored in board prior to 6.0, only used for loading legacy files.
Definition: board.h:264
std::shared_ptr< DRC_ENGINE > m_DRCEngine
PROJECT * GetProject(const wxString &aFullPath) const
Retrieves a loaded project by name.
static PCB_EDIT_FRAME * s_PcbEditFrame
Container for design settings for a BOARD object.
GAL_SET m_LegacyVisibleItems
Definition: board.h:265

References BOARD::Add(), BOARD::BuildConnectivity(), BOARD::BuildListOfNets(), DesignRulesFileExtension, dummy(), GAL_LAYER_ID_BITMASK_END, GAL_LAYER_INDEX, GetDefaultProject(), BOARD::GetDesignSettings(), SETTINGS_MANAGER::GetProject(), GetSettingsManager(), IO_MGR::Load(), SETTINGS_MANAGER::LoadProject(), BOARD_DESIGN_SETTINGS::m_DRCEngine, BOARD::m_LegacyVisibleItems, BOARD::m_LegacyVisibleLayers, project, ProjectFileExtension, Rescue, BOARD::ResolveDRCExclusions(), s_PcbEditFrame, BOARD::SetProject(), and BOARD::SynchronizeNetsAndNetClasses().

◆ LoadBoard() [2/2]

BOARD* LoadBoard ( wxString &  aFileName)

Definition at line 76 of file pcbnew_scripting_helpers.cpp.

77 {
78  // Loading a new board is not possible if running inside KiCad
79  if( s_PcbEditFrame )
80  return nullptr;
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:55
static PCB_EDIT_FRAME * s_PcbEditFrame
S-expression Pcbnew file format.
Definition: io_mgr.h:56

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

Referenced by LoadBoard().

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

360 {
361  if( s_PcbEditFrame )
362  {
363  auto board = s_PcbEditFrame->GetBoard();
364  board->BuildConnectivity();
365 
366  // Re-init everything: this is the easy way to do that
369  }
370 }
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()
Build or rebuild the board connectivity database for the board, especially the list of connected item...
Definition: board.cpp:137
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) 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(), EDA_3D_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::LoadOneLibrarySymbolAux(), SYMBOL_EDIT_FRAME::LoadSymbolFromSchematic(), PANEL_ATTENUATORS::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(), BITMAP_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(), EDA_3D_MODEL_VIEWER::OnMouseMove(), EDA_3D_MODEL_VIEWER::OnMouseWheel(), BM2CMP_FRAME::OnNegativeClicked(), DIALOG_TEMPLATE_SELECTOR::onNotebookResize(), BITMAP_BUTTON::OnSetFocus(), BM2CMP_FRAME::OnThresholdChange(), PANEL_TRANSLINE::OnTransLineResetButtonClick(), PANEL_TRANSLINE::OnTranslineSelection(), ACTION_TOOLBAR::RefreshBitmaps(), PANEL_REGULATOR::RegulatorPageUpdate(), DIALOG_JUNCTION_PROPS::resetDefaults(), DIALOG_LINE_WIRE_BUS_PROPERTIES::resetDefaults(), TEMPLATE_WIDGET::Select(), EDA_3D_MODEL_VIEWER::Set3DModel(), WX_COLLAPSIBLE_PANE_HEADER::SetCollapsed(), EDA_MSG_PANEL::SetMessage(), PANEL_PACKAGE::SetSelected(), FOOTPRINTS_LISTBOX::SetSelection(), LIBRARY_LISTBOX::SetSelection(), PANEL_COLOR_CODE::ThemeChanged(), PANEL_ATTENUATORS::ThemeChanged(), PANEL_COLOR_CODE::ToleranceSelection(), TEMPLATE_WIDGET::Unselect(), mpWindow::UpdateAll(), KIGFX::OPENGL_GAL::updatedGalDisplayOptions(), KIGFX::CAIRO_GAL::updatedGalDisplayOptions(), DIALOG_PAGES_SETTINGS::UpdateDrawingSheetExample(), and NUMBER_BADGE::UpdateNumber().

◆ SaveBoard()

bool SaveBoard ( wxString &  aFileName,
BOARD aBoard 
)

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.
Returns
true if the save was completed.

Definition at line 234 of file pcbnew_scripting_helpers.cpp.

235 {
236  return SaveBoard( aFileName, aBoard, IO_MGR::KICAD_SEXP );
237 }
bool SaveBoard(wxString &aFileName, BOARD *aBoard, IO_MGR::PCB_FILE_T aFormat)
S-expression Pcbnew file format.
Definition: io_mgr.h:56

References IO_MGR::KICAD_SEXP, and SaveBoard().

◆ ScriptingSetPcbEditFrame()

void ScriptingSetPcbEditFrame ( PCB_EDIT_FRAME aPCBEdaFrame)

Definition at line 70 of file pcbnew_scripting_helpers.cpp.

71 {
72  s_PcbEditFrame = aPcbEditFrame;
73 }
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 373 of file pcbnew_scripting_helpers.cpp.

374 {
375  if( s_PcbEditFrame )
377 }
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 
)

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

397 {
398  wxCHECK( aBoard, false );
399 
400  BOARD_DESIGN_SETTINGS& bds = aBoard->GetDesignSettings();
401  std::shared_ptr<DRC_ENGINE> engine = bds.m_DRCEngine;
402 
403  if( !engine )
404  {
405  bds.m_DRCEngine = std::make_shared<DRC_ENGINE>( aBoard, &bds );
406  engine = bds.m_DRCEngine;
407  }
408 
409  wxCHECK( engine, false );
410 
411  wxFileName fn = aBoard->GetFileName();
412  fn.SetExt( DesignRulesFileExtension );
413  wxString drcRulesPath = s_SettingsManager->Prj().AbsolutePath( fn.GetFullName() );
414 
415  try
416  {
417  engine->InitEngine( drcRulesPath );
418  }
419  catch( PARSE_ERROR& )
420  {
421  return false;
422  }
423 
424  std::vector<std::shared_ptr<DRC_ITEM>> footprints;
425  std::vector<std::shared_ptr<DRC_ITEM>> unconnected;
426  std::vector<std::shared_ptr<DRC_ITEM>> violations;
427 
428  engine->SetProgressReporter( nullptr );
429 
430  engine->SetViolationHandler(
431  [&]( const std::shared_ptr<DRC_ITEM>& aItem, wxPoint aPos )
432  {
433  if( aItem->GetErrorCode() == DRCE_MISSING_FOOTPRINT
434  || aItem->GetErrorCode() == DRCE_DUPLICATE_FOOTPRINT
435  || aItem->GetErrorCode() == DRCE_EXTRA_FOOTPRINT
436  || aItem->GetErrorCode() == DRCE_NET_CONFLICT )
437  {
438  footprints.push_back( aItem );
439  }
440  else if( aItem->GetErrorCode() == DRCE_UNCONNECTED_ITEMS )
441  {
442  unconnected.push_back( aItem );
443  }
444  else
445  {
446  violations.push_back( aItem );
447  }
448  } );
449 
450  engine->RunTests( aUnits, aReportAllTrackErrors, false );
451  engine->ClearViolationHandler();
452 
453  // TODO: Unify this with DIALOG_DRC::writeReport
454 
455  FILE* fp = wxFopen( aFileName, wxT( "w" ) );
456 
457  if( fp == nullptr )
458  return false;
459 
460  std::map<KIID, EDA_ITEM*> itemMap;
461  aBoard->FillItemMap( itemMap );
462 
463  fprintf( fp, "** Drc report for %s **\n", TO_UTF8( aBoard->GetFileName() ) );
464 
465  wxDateTime now = wxDateTime::Now();
466 
467  fprintf( fp, "** Created on %s **\n", TO_UTF8( now.Format( wxT( "%F %T" ) ) ) );
468 
469  fprintf( fp, "\n** Found %d DRC violations **\n", static_cast<int>( violations.size() ) );
470 
471  for( const std::shared_ptr<DRC_ITEM>& item : violations )
472  {
473  SEVERITY severity = bds.GetSeverity( item->GetErrorCode() );
474  fprintf( fp, "%s", TO_UTF8( item->ShowReport( aUnits, severity, itemMap ) ) );
475  }
476 
477  fprintf( fp, "\n** Found %d unconnected pads **\n", static_cast<int>( unconnected.size() ) );
478 
479  for( const std::shared_ptr<DRC_ITEM>& item : unconnected )
480  {
481  SEVERITY severity = bds.GetSeverity( item->GetErrorCode() );
482  fprintf( fp, "%s", TO_UTF8( item->ShowReport( aUnits, severity, itemMap ) ) );
483  }
484 
485  fprintf( fp, "\n** Found %d Footprint errors **\n", static_cast<int>( footprints.size() ) );
486 
487  for( const std::shared_ptr<DRC_ITEM>& item : footprints )
488  {
489  SEVERITY severity = bds.GetSeverity( item->GetErrorCode() );
490  fprintf( fp, "%s", TO_UTF8( item->ShowReport( aUnits, severity, itemMap ) ) );
491  }
492 
493  fprintf( fp, "\n** End of Report **\n" );
494  fclose( fp );
495 
496  return true;
497 }
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
const std::string DesignRulesFileExtension
const wxString & GetFileName() const
Definition: board.h:228
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:590
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:269
#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)
SEVERITY
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:924
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.