KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcbnew_scripting_helpers.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2012 NBEE Embedded Systems, Miguel Angel Ajo <[email protected]>
5 * Copyright (C) 1992-2024 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
30#include <Python.h>
31#undef HAVE_CLOCK_GETTIME // macro is defined in Python.h and causes redefine warning
32
34
35#include <action_plugin.h>
36#include <board.h>
38#include <pcb_marker.h>
39#include <cstdlib>
41#include <drc/drc_engine.h>
42#include <drc/drc_item.h>
43#include <fp_lib_table.h>
44#include <core/ignore.h>
45#include <pcb_io/pcb_io_mgr.h>
46#include <string_utils.h>
47#include <filename_resolver.h>
48#include <macros.h>
50#include <pgm_base.h>
51#include <project.h>
52#include <project_pcb.h>
56#include <specctra.h>
59#include <locale_io.h>
60#include <wx/app.h>
61#include <wx/crt.h>
62#include <wx/image.h>
63
66
67
69{
70 if( s_PcbEditFrame )
71 return s_PcbEditFrame->GetBoard();
72 else
73 return nullptr;
74}
75
76
78{
79 s_PcbEditFrame = aPcbEditFrame;
80}
81
82
84{
85 if( s_PcbEditFrame == aPcbEditFrame )
86 s_PcbEditFrame = nullptr;
87}
88
89
90BOARD* LoadBoard( const wxString& aFileName, bool aSetActive, PROJECT* aProject )
91{
92 if( aFileName.EndsWith( FILEEXT::KiCadPcbFileExtension ) )
93 return LoadBoard( aFileName, PCB_IO_MGR::KICAD_SEXP, aSetActive, aProject );
94 else if( aFileName.EndsWith( FILEEXT::LegacyPcbFileExtension ) )
95 return LoadBoard( aFileName, PCB_IO_MGR::LEGACY, aSetActive, aProject );
96
97 // as fall back for any other kind use the legacy format
98 return LoadBoard( aFileName, PCB_IO_MGR::LEGACY, aSetActive, aProject );
99}
100
101
102BOARD* LoadBoard( const wxString& aFileName )
103{
104 return LoadBoard( aFileName, false );
105}
106
107
109{
110 if( !s_SettingsManager )
111 {
112 if( s_PcbEditFrame )
113 {
115 }
116 else
117 {
118 // Ensure wx system settings stuff is available
119 ignore_unused( wxTheApp );
121 }
122 }
123
124 return s_SettingsManager;
125}
126
127
129{
130 // For some reasons, LoadProject() needs a C locale, so ensure we have the right locale
131 // This is mainly when running QA Python tests
133
135
136 if( !project )
137 {
140 }
141
142 return project;
143}
144
145BOARD* LoadBoard( const wxString& aFileName, PCB_IO_MGR::PCB_FILE_T aFormat )
146{
147 return LoadBoard( aFileName, aFormat, false );
148}
149
150
151BOARD* LoadBoard( const wxString& aFileName, PCB_IO_MGR::PCB_FILE_T aFormat, bool aSetActive,
152 PROJECT* aProject )
153{
154 wxFileName pro = aFileName;
155 pro.SetExt( FILEEXT::ProjectFileExtension );
156 pro.MakeAbsolute();
157 wxString projectPath = pro.GetFullPath();
158
159 // Ensure image handlers are loaded, because a board can include bitmap images
160 // using various formats.
161 // By default only the BMP handler is available.
162 wxInitAllImageHandlers();
163
164
165 // Ensure the "C" locale is temporary set, before reading any file
166 // It also avoid wxWidget alerts about locale issues, later, when using Python 3
168
169 PROJECT* project = aProject;
170
171 if( !project )
172 {
173 GetSettingsManager()->GetProject( projectPath );
174 }
175
176 if( !project )
177 {
178 if( wxFileExists( projectPath ) )
179 {
180 // cli
181 GetSettingsManager()->LoadProject( projectPath, aSetActive );
182 project = GetSettingsManager()->GetProject( projectPath );
183 }
184 }
185 else if( s_PcbEditFrame && project == &GetSettingsManager()->Prj() )
186 {
187 // Project is already loaded? Then so is the board
188 return s_PcbEditFrame->GetBoard();
189 }
190
191 // Board cannot be loaded without a project, so create the default project
192 if( !project )
194
195 BASE_SCREEN::m_DrawingSheetFileName = project->GetProjectFile().m_BoardDrawingSheetFile;
196
197 BOARD* brd = nullptr;
198 try
199 {
200 brd = PCB_IO_MGR::Load( aFormat, aFileName );
201 }
202 catch( ... )
203 {
204 brd = nullptr;
205 }
206
207 if( brd )
208 {
209 // Load the drawing sheet from the filename stored in BASE_SCREEN::m_DrawingSheetFileName.
210 // If empty, or not existing, the default drawing sheet is loaded.
213
214 // a PGM_BASE* process can be nullptr when running from a python script
215 // So use PgmOrNull() instead of &Pgm() to initialize the resolver
217
219 project->GetProjectPath(),
220 brd->GetEmbeddedFiles() );
221
222 wxString msg;
223
224 if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename, &msg ) )
225 {
226 wxFprintf( stderr, _( "Error loading drawing sheet '%s': %s" ),
228 }
229
230 // JEY TODO: move this global to the board
232
233 layerEnum.Choices().Clear();
234 layerEnum.Undefined( UNDEFINED_LAYER );
235
236 for( PCB_LAYER_ID layer : LSET::AllLayersMask().Seq() )
237 {
238 // Canonical name
239 layerEnum.Map( layer, LSET::Name( layer ) );
240
241 // User name
242 layerEnum.Map( layer, brd->GetLayerName( layer ) );
243 }
244
245 brd->SetProject( project );
246
247 // Move legacy view settings to local project settings
248 if( !brd->m_LegacyVisibleLayers.test( Rescue ) )
249 project->GetLocalSettings().m_VisibleLayers = brd->m_LegacyVisibleLayers;
250
252 project->GetLocalSettings().m_VisibleItems = brd->m_LegacyVisibleItems;
253
255 bds.m_DRCEngine = std::make_shared<DRC_ENGINE>( brd, &bds );
256
257 try
258 {
259 wxFileName rules = pro;
260 rules.SetExt( FILEEXT::DesignRulesFileExtension );
261 bds.m_DRCEngine->InitEngine( rules );
262 }
263 catch( ... )
264 {
265 // Best efforts...
266 }
267
268 for( PCB_MARKER* marker : brd->ResolveDRCExclusions( true ) )
269 brd->Add( marker );
270
271 brd->BuildConnectivity();
272 brd->BuildListOfNets();
273 brd->SynchronizeNetsAndNetClasses( true );
274 brd->UpdateUserUnits( brd, nullptr );
275 }
276
277 return brd;
278}
279
280
281BOARD* NewBoard( wxString& aFileName )
282{
283 wxFileName boardFn = aFileName;
284 wxFileName proFn = aFileName;
285 proFn.SetExt( FILEEXT::ProjectFileExtension );
286 proFn.MakeAbsolute();
287
288 wxString projectPath = proFn.GetFullPath();
289
290 // Ensure the "C" locale is temporary set, before reading any file
291 // It also avoids wxWidgets alerts about locale issues, later, when using Python 3
293
294 GetSettingsManager()->LoadProject( projectPath, false );
295 PROJECT* project = GetSettingsManager()->GetProject( projectPath );
296
297 BOARD* brd = new BOARD();
298
299 brd->SetProject( project );
301 bds.m_DRCEngine = std::make_shared<DRC_ENGINE>( brd, &bds );
302
303 SaveBoard( aFileName, brd );
304
305 return brd;
306}
307
308
310{
311 // Creating a new board is not possible if running inside KiCad
312 if( s_PcbEditFrame )
313 return nullptr;
314
315 BOARD* brd = new BOARD();
316
318
319 return brd;
320}
321
322
323bool SaveBoard( wxString& aFileName, BOARD* aBoard, PCB_IO_MGR::PCB_FILE_T aFormat, bool aSkipSettings )
324{
325 aBoard->BuildConnectivity();
326 aBoard->SynchronizeNetsAndNetClasses( false );
327
328 // Ensure the "C" locale is temporary set, before saving any file
329 // It also avoid wxWidget alerts about locale issues, later, when using Python 3
331
332 try
333 {
334 PCB_IO_MGR::Save( aFormat, aFileName, aBoard, nullptr );
335 }
336 catch( ... )
337 {
338 return false;
339 }
340
341 if( !aSkipSettings )
342 {
343 wxFileName pro = aFileName;
344 pro.SetExt( FILEEXT::ProjectFileExtension );
345 pro.MakeAbsolute();
346
347 GetSettingsManager()->SaveProjectAs( pro.GetFullPath(), aBoard->GetProject() );
348 }
349
350 return true;
351}
352
353
354bool SaveBoard( wxString& aFileName, BOARD* aBoard, bool aSkipSettings )
355{
356 return SaveBoard( aFileName, aBoard, PCB_IO_MGR::KICAD_SEXP, aSkipSettings );
357}
358
359
361{
362 BOARD* board = GetBoard();
363
364 if( !board )
365 return nullptr;
366
367 PROJECT* project = board->GetProject();
368
369 if( !project )
370 return nullptr;
371
373}
374
375
377{
378 wxArrayString footprintLibraryNames;
379
381
382 if( !tbl )
383 return footprintLibraryNames;
384
385 for( const wxString& name : tbl->GetLogicalLibs() )
386 footprintLibraryNames.Add( name );
387
388 return footprintLibraryNames;
389}
390
391
392wxArrayString GetFootprints( const wxString& aNickName )
393{
394 wxArrayString footprintNames;
395
397
398 if( !tbl )
399 return footprintNames;
400
401 tbl->FootprintEnumerate( footprintNames, aNickName, true );
402
403 return footprintNames;
404}
405
406
407bool ExportSpecctraDSN( wxString& aFullFilename )
408{
409 if( s_PcbEditFrame )
410 {
411 bool ok = s_PcbEditFrame->ExportSpecctraFile( aFullFilename );
412 return ok;
413 }
414 else
415 {
416 return false;
417 }
418}
419
420
421bool ExportSpecctraDSN( BOARD* aBoard, wxString& aFullFilename )
422{
423 try
424 {
425 DSN::ExportBoardToSpecctraFile( aBoard, aFullFilename );
426 }
427 catch( ... )
428 {
429 return false;
430 }
431
432 return true;
433}
434
435
436bool ExportVRML( const wxString& aFullFileName, double aMMtoWRMLunit, bool aIncludeUnspecified,
437 bool aIncludeDNP, bool aExport3DFiles,
438 bool aUseRelativePaths, const wxString& a3D_Subdir, double aXRef, double aYRef )
439{
440 if( s_PcbEditFrame )
441 {
442 bool ok = s_PcbEditFrame->ExportVRML_File( aFullFileName, aMMtoWRMLunit,
443 aIncludeUnspecified, aIncludeDNP,
444 aExport3DFiles, aUseRelativePaths,
445 a3D_Subdir, aXRef, aYRef );
446 return ok;
447 }
448 else
449 {
450 return false;
451 }
452}
453
454bool ImportSpecctraSES( wxString& aFullFilename )
455{
456 if( s_PcbEditFrame )
457 {
458 bool ok = s_PcbEditFrame->ImportSpecctraSession( aFullFilename );
459 return ok;
460 }
461 else
462 {
463 return false;
464 }
465}
466
467bool ImportSpecctraSES( BOARD* aBoard, wxString& aFullFilename )
468{
469 try
470 {
471 DSN::ImportSpecctraSession( aBoard, aFullFilename );
472 }
473 catch( ... )
474 {
475 return false;
476 }
477
478 return true;
479}
480
481
482bool ExportFootprintsToLibrary( bool aStoreInNewLib, const wxString& aLibName, wxString* aLibPath )
483{
484 if( s_PcbEditFrame )
485 {
486 s_PcbEditFrame->ExportFootprintsToLibrary( aStoreInNewLib, aLibName, aLibPath );
487 return true;
488 }
489 else
490 {
491 return false;
492 }
493}
494
496{
497 if( s_PcbEditFrame )
498 {
500 }
501}
502
503
505{
506 if( s_PcbEditFrame )
508}
509
510
512{
513 if( s_PcbEditFrame )
514 return static_cast<int>( s_PcbEditFrame->GetUserUnits() );
515
516 return -1;
517}
518
519
520std::deque<BOARD_ITEM*> GetCurrentSelection()
521{
522 std::deque<BOARD_ITEM*> items;
523
524 if( s_PcbEditFrame )
525 {
527
528 std::for_each( selection.begin(), selection.end(),
529 [&items]( EDA_ITEM* item )
530 {
531 items.push_back( static_cast<BOARD_ITEM*>( item ) );
532 } );
533 }
534
535 return items;
536}
537
538void FocusOnItem( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer )
539{
540 if( s_PcbEditFrame )
541 {
542 s_PcbEditFrame->FocusOnItem( aItem, aLayer );
543 }
544}
545
546
548{
550}
551
552
553bool WriteDRCReport( BOARD* aBoard, const wxString& aFileName, EDA_UNITS aUnits,
554 bool aReportAllTrackErrors )
555{
556 wxCHECK( aBoard, false );
557
559 std::shared_ptr<DRC_ENGINE> engine = bds.m_DRCEngine;
560 UNITS_PROVIDER unitsProvider( pcbIUScale, aUnits );
561
562 if( !engine )
563 {
564 bds.m_DRCEngine = std::make_shared<DRC_ENGINE>( aBoard, &bds );
565 engine = bds.m_DRCEngine;
566 }
567
568 wxCHECK( engine, false );
569
570 wxFileName fn = aBoard->GetFileName();
572 PROJECT* prj = nullptr;
573
574 if( aBoard->GetProject() )
575 prj = aBoard->GetProject();
576 else if( s_SettingsManager )
577 prj = &s_SettingsManager->Prj();
578
579 wxCHECK( prj, false );
580
581 // Load the global fp-lib-table otherwise we can't check the libs parity
582 wxFileName fn_flp = FP_LIB_TABLE::GetGlobalTableFileName();
583
584 if( fn_flp.FileExists() )
585 GFootprintTable.Load( fn_flp.GetFullPath() );
586
587 wxString drcRulesPath = prj->AbsolutePath( fn.GetFullName() );
588
589 // Rebuild The Instance of ENUM_MAP<PCB_LAYER_ID> (layer names list), because the DRC
590 // engine can use layer names (canonical and/or user names)
592 layerEnum.Choices().Clear();
593 layerEnum.Undefined( UNDEFINED_LAYER );
594
595 for( PCB_LAYER_ID layer : LSET::AllLayersMask().Seq() )
596 {
597 layerEnum.Map( layer, LSET::Name( layer ) ); // Add Canonical name
598 layerEnum.Map( layer, aBoard->GetLayerName( layer ) ); // Add User name
599 }
600
601 try
602 {
603 engine->InitEngine( drcRulesPath );
604 }
605 catch( PARSE_ERROR& err )
606 {
607 fprintf( stderr, "Init DRC engine: err <%s>\n", TO_UTF8( err.What() ) ); fflush( stderr);
608 return false;
609 }
610
611 std::vector<std::shared_ptr<DRC_ITEM>> footprints;
612 std::vector<std::shared_ptr<DRC_ITEM>> unconnected;
613 std::vector<std::shared_ptr<DRC_ITEM>> violations;
614
615 engine->SetProgressReporter( nullptr );
616
617 engine->SetViolationHandler(
618 [&]( const std::shared_ptr<DRC_ITEM>& aItem, VECTOR2D aPos, int aLayer )
619 {
620 if( aItem->GetErrorCode() == DRCE_MISSING_FOOTPRINT
621 || aItem->GetErrorCode() == DRCE_DUPLICATE_FOOTPRINT
622 || aItem->GetErrorCode() == DRCE_EXTRA_FOOTPRINT
623 || aItem->GetErrorCode() == DRCE_NET_CONFLICT
624 || aItem->GetErrorCode() == DRCE_SCHEMATIC_PARITY
625 || aItem->GetErrorCode() == DRCE_FOOTPRINT_FILTERS )
626 {
627 footprints.push_back( aItem );
628 }
629 else if( aItem->GetErrorCode() == DRCE_UNCONNECTED_ITEMS )
630 {
631 unconnected.push_back( aItem );
632 }
633 else
634 {
635 violations.push_back( aItem );
636 }
637 } );
638
639 aBoard->RecordDRCExclusions();
640 aBoard->DeleteMARKERs( true, true );
641 engine->RunTests( aUnits, aReportAllTrackErrors, false );
642 engine->ClearViolationHandler();
643
644 // Update the exclusion status on any excluded markers that still exist.
645 aBoard->ResolveDRCExclusions( false );
646
647 // TODO: Unify this with DIALOG_DRC::writeReport
648
649 FILE* fp = wxFopen( aFileName, wxT( "w" ) );
650
651 if( fp == nullptr )
652 return false;
653
654 std::map<KIID, EDA_ITEM*> itemMap;
655 aBoard->FillItemMap( itemMap );
656
657 fprintf( fp, "** Drc report for %s **\n", TO_UTF8( aBoard->GetFileName() ) );
658
659 wxDateTime now = wxDateTime::Now();
660
661 fprintf( fp, "** Created on %s **\n", TO_UTF8( now.Format( wxT( "%F %T" ) ) ) );
662
663 fprintf( fp, "\n** Found %d DRC violations **\n", static_cast<int>( violations.size() ) );
664
665 for( const std::shared_ptr<DRC_ITEM>& item : violations )
666 {
667 SEVERITY severity = item->GetParent() ? item->GetParent()->GetSeverity()
668 : bds.GetSeverity( item->GetErrorCode() );
669 fprintf( fp, "%s", TO_UTF8( item->ShowReport( &unitsProvider, severity, itemMap ) ) );
670 }
671
672 fprintf( fp, "\n** Found %d unconnected pads **\n", static_cast<int>( unconnected.size() ) );
673
674 for( const std::shared_ptr<DRC_ITEM>& item : unconnected )
675 {
676 SEVERITY severity = bds.GetSeverity( item->GetErrorCode() );
677 fprintf( fp, "%s", TO_UTF8( item->ShowReport( &unitsProvider, severity, itemMap ) ) );
678 }
679
680 fprintf( fp, "\n** Found %d Footprint errors **\n", static_cast<int>( footprints.size() ) );
681
682 for( const std::shared_ptr<DRC_ITEM>& item : footprints )
683 {
684 SEVERITY severity = bds.GetSeverity( item->GetErrorCode() );
685 fprintf( fp, "%s", TO_UTF8( item->ShowReport( &unitsProvider, severity, itemMap ) ) );
686 }
687
688 fprintf( fp, "\n** End of Report **\n" );
689 fclose( fp );
690
691 return true;
692}
693
694wxString GetLanguage()
695{
696 if( s_PcbEditFrame )
698 else
699 return "";
700}
const char * name
Definition: DXF_plotter.cpp:57
Class PCBNEW_ACTION_PLUGINS.
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
static bool IsActionRunning()
static wxString m_DrawingSheetFileName
the name of the drawing sheet file, or empty to use the default drawing sheet
Definition: base_screen.h:85
Container for design settings for a BOARD object.
std::shared_ptr< DRC_ENGINE > m_DRCEngine
SEVERITY GetSeverity(int aDRCErrorCode)
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:79
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
EMBEDDED_FILES * GetEmbeddedFiles() override
Definition: board.cpp:2544
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition: board.cpp:998
GAL_SET m_LegacyVisibleItems
Definition: board.h:370
void BuildListOfNets()
Definition: board.h:834
void UpdateUserUnits(BOARD_ITEM *aItem, KIGFX::VIEW *aView)
Update any references within aItem (or its descendants) to the user units.
Definition: board.cpp:1329
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:187
void RecordDRCExclusions()
Scan existing markers and record data from any that are Excluded.
Definition: board.cpp:327
void SynchronizeNetsAndNetClasses(bool aResetTrackAndViaSizes)
Copy NETCLASS info to each NET, based on NET membership in a NETCLASS.
Definition: board.cpp:2049
LSET m_LegacyVisibleLayers
Visibility settings stored in board prior to 6.0, only used for loading legacy files.
Definition: board.h:369
void SetProject(PROJECT *aProject, bool aReferenceOnly=false)
Link a board to a given project.
Definition: board.cpp:197
const wxString & GetFileName() const
Definition: board.h:327
std::vector< PCB_MARKER * > ResolveDRCExclusions(bool aCreateMarkers)
Rebuild DRC markers from the serialized data in BOARD_DESIGN_SETTINGS.
Definition: board.cpp:344
void FillItemMap(std::map< KIID, EDA_ITEM * > &aMap)
Definition: board.cpp:1510
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:577
PROJECT * GetProject() const
Definition: board.h:491
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:890
void DeleteMARKERs()
Delete all MARKERS from the board.
Definition: board.cpp:1355
static DS_DATA_MODEL & GetTheInstance()
static function: returns the instance of DS_DATA_MODEL used in the application
SETTINGS_MANAGER * GetSettingsManager() const
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:89
ENUM_MAP & Map(T aValue, const wxString &aName)
Definition: property.h:669
static ENUM_MAP< T > & Instance()
Definition: property.h:663
ENUM_MAP & Undefined(T aValue)
Definition: property.h:676
wxPGChoices & Choices()
Definition: property.h:712
Provide an extensible class to resolve 3D model paths.
bool SetProject(PROJECT *aProject, bool *flgChanged=nullptr)
Set the current KiCad project directory as the first entry in the model path list.
void SetProgramBase(PGM_BASE *aBase)
Set a pointer to the application's PGM_BASE instance used to extract the local env vars.
wxString ResolvePath(const wxString &aFileName, const wxString &aWorkingPath, const EMBEDDED_FILES *aFiles)
Determines the full path of the given file name.
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aNickname, bool aBestEfforts)
Return a list of footprint names contained within the library given by aNickname.
static wxString GetGlobalTableFileName()
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.
void Load(const wxString &aFileName)
Load the library table using the path defined by aFileName aFallBackTable.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:49
static LSET AllLayersMask()
Definition: lset.cpp:701
static wxString Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:183
BOARD * GetBoard() const
void FocusOnItem(BOARD_ITEM *aItem, PCB_LAYER_ID aLayer=UNDEFINED_LAYER)
The main frame for Pcbnew.
void UpdateUserInterface()
Update the layer manager and other widgets from the board setup (layer and items visibility,...
void ExportFootprintsToLibrary(bool aStoreInNewLib, const wxString &aLibName=wxEmptyString, wxString *aLibPath=nullptr)
Save footprints in a library:
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 ...
void RebuildAndRefresh()
Rebuilds board connectivity, refreshes canvas.
SELECTION & GetCurrentSelection() override
Get the current selection from the canvas area.
bool ExportVRML_File(const wxString &aFullFileName, double aMMtoWRMLunit, bool aIncludeUnspecified, bool aIncludeDNP, bool aExport3DFiles, bool aUseRelativePaths, const wxString &a3D_Subdir, double aXRef, double aYRef)
Create the file(s) exporting current BOARD to a VRML file.
bool ExportSpecctraFile(const wxString &aFullFilename)
Export the current BOARD to a specctra dsn file.
static BOARD * Load(PCB_FILE_T aFileType, const wxString &aFileName, BOARD *aAppendToMe=nullptr, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)
Find the requested #PLUGIN and if found, calls the #PLUGIN::LoadBoard() function on it using the argu...
Definition: pcb_io_mgr.cpp:160
PCB_FILE_T
The set of file types that the PCB_IO_MGR knows about, and for which there has been a plugin written,...
Definition: pcb_io_mgr.h:56
@ KICAD_SEXP
S-expression Pcbnew file format.
Definition: pcb_io_mgr.h:58
@ LEGACY
Legacy Pcbnew file formats prior to s-expression.
Definition: pcb_io_mgr.h:59
static void Save(PCB_FILE_T aFileType, const wxString &aFileName, BOARD *aBoard, const std::map< std::string, UTF8 > *aProperties=nullptr)
Write either a full aBoard to a storage file in a format that this implementation knows about,...
Definition: pcb_io_mgr.cpp:176
static FP_LIB_TABLE * PcbFootprintLibs(PROJECT *aProject)
Return the table of footprint libraries without Kiway.
Definition: project_pcb.cpp:37
Container for project specific data.
Definition: project.h:64
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:359
ITER end()
Definition: selection.h:75
ITER begin()
Definition: selection.h:74
void SaveProjectAs(const wxString &aFullPath, PROJECT *aProject=nullptr)
Sets the currently loaded project path and saves it (pointers remain valid) Note that this will not m...
COMMON_SETTINGS * GetCommonSettings() const
Retrieves the common settings shared by all applications.
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.
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
EDA_UNITS GetUserUnits() const
FP_LIB_TABLE GFootprintTable
The global footprint library table.
Definition: cvpcb.cpp:150
@ DRCE_FOOTPRINT_FILTERS
Definition: drc_item.h:79
@ DRCE_UNCONNECTED_ITEMS
Definition: drc_item.h:39
@ DRCE_DUPLICATE_FOOTPRINT
Definition: drc_item.h:75
@ DRCE_EXTRA_FOOTPRINT
Definition: drc_item.h:76
@ DRCE_NET_CONFLICT
Definition: drc_item.h:77
@ DRCE_MISSING_FOOTPRINT
Definition: drc_item.h:74
@ DRCE_SCHEMATIC_PARITY
Definition: drc_item.h:78
#define _(s)
EDA_UNITS
Definition: eda_units.h:46
static FILENAME_RESOLVER * resolver
Definition: export_idf.cpp:53
static const std::string ProjectFileExtension
static const std::string LegacyPcbFileExtension
static const std::string DesignRulesFileExtension
static const std::string KiCadPcbFileExtension
void ignore_unused(const T &)
Definition: ignore.h:24
PROJECT & Prj()
Definition: kicad.cpp:595
@ 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:228
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
@ Rescue
Definition: layer_ids.h:121
#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:273
This file contains miscellaneous commonly used macros and functions.
void ExportBoardToSpecctraFile(BOARD *aBoard, const wxString &aFullFilename)
Helper method to export board to DSN file.
bool ImportSpecctraSession(BOARD *aBoard, const wxString &fullFileName)
Helper method to import SES file to a board.
bool ImportSpecctraSES(wxString &aFullFilename)
Import a specctra *.ses file and use it to relocate MODULEs and to replace all vias and tracks in an ...
SETTINGS_MANAGER * GetSettingsManager()
void ScriptingOnDestructPcbEditFrame(PCB_EDIT_FRAME *aPcbEditFrame)
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.
BOARD * CreateEmptyBoard()
Construct a default BOARD with a temporary (no filename) project.
bool ExportVRML(const wxString &aFullFileName, double aMMtoWRMLunit, bool aIncludeUnspecified, bool aIncludeDNP, bool aExport3DFiles, bool aUseRelativePaths, const wxString &a3D_Subdir, double aXRef, double aYRef)
Export the current BOARD to a VRML (wrl) file.
wxArrayString GetFootprintLibraries()
Get the nicknames of all of the footprint libraries configured in pcbnew in both the project and glob...
FP_LIB_TABLE * GetFootprintLibraryTable()
int GetUserUnits()
Return the currently selected user unit value for the interface.
wxArrayString GetFootprints(const wxString &aNickName)
Get the names of all of the footprints available in a footprint library.
void ScriptingSetPcbEditFrame(PCB_EDIT_FRAME *aPcbEditFrame)
static PCB_EDIT_FRAME * s_PcbEditFrame
bool IsActionRunning()
Are we currently in an action plugin?
bool SaveBoard(wxString &aFileName, BOARD *aBoard, PCB_IO_MGR::PCB_FILE_T aFormat, bool aSkipSettings)
void UpdateUserInterface()
Update the layer manager and other widgets from the board setup (layer and items visibility,...
bool ExportSpecctraDSN(wxString &aFullFilename)
Will export the current BOARD to a specctra dsn file.
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
std::deque< BOARD_ITEM * > GetCurrentSelection()
Get the list of selected objects.
wxString GetLanguage()
Get the language string from COMMON_SETTINGS.
void FocusOnItem(BOARD_ITEM *aItem, PCB_LAYER_ID aLayer)
Focus the view on the target item.
BOARD * LoadBoard(const wxString &aFileName, bool aSetActive, PROJECT *aProject)
Loads a board from file This function identifies the file type by extension and determines the correc...
static SETTINGS_MANAGER * s_SettingsManager
BOARD * GetBoard()
bool ExportFootprintsToLibrary(bool aStoreInNewLib, const wxString &aLibName, wxString *aLibPath)
Save footprints in a library:
PROJECT * GetDefaultProject()
BOARD * NewBoard(wxString &aFileName)
Creates a new board and project with the given filename (will overwrite existing files!...
PGM_BASE * PgmOrNull()
similar to PGM_BASE& Pgm(), but return a reference that can be nullptr when running a shared lib from...
Definition: pgm_base.cpp:1067
see class PGM_BASE
SEVERITY
std::vector< FAB_LAYER_COLOR > dummy
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: string_utils.h:398
A filename or source description, a problem input line, a line number, a byte offset,...
Definition: ki_exception.h:120
Definition of file extensions used in Kicad.