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-2023 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 <macros.h>
49#include <project.h>
50#include <project_pcb.h>
54#include <specctra.h>
57#include <locale_io.h>
58#include <wx/app.h>
59#include <wx/crt.h>
60
61
64
65
67{
68 if( s_PcbEditFrame )
69 return s_PcbEditFrame->GetBoard();
70 else
71 return nullptr;
72}
73
74
76{
77 s_PcbEditFrame = aPcbEditFrame;
78}
79
80
82{
83 if( s_PcbEditFrame == aPcbEditFrame )
84 s_PcbEditFrame = nullptr;
85}
86
87
88BOARD* LoadBoard( wxString& aFileName, bool aSetActive )
89{
90 if( aFileName.EndsWith( FILEEXT::KiCadPcbFileExtension ) )
91 return LoadBoard( aFileName, PCB_IO_MGR::KICAD_SEXP, aSetActive );
92 else if( aFileName.EndsWith( FILEEXT::LegacyPcbFileExtension ) )
93 return LoadBoard( aFileName, PCB_IO_MGR::LEGACY, aSetActive );
94
95 // as fall back for any other kind use the legacy format
96 return LoadBoard( aFileName, PCB_IO_MGR::LEGACY, aSetActive );
97}
98
99
100BOARD* LoadBoard( wxString& aFileName )
101{
102 return LoadBoard( aFileName, false );
103}
104
105
107{
108 if( !s_SettingsManager )
109 {
110 if( s_PcbEditFrame )
111 {
113 }
114 else
115 {
116 // Ensure wx system settings stuff is available
117 ignore_unused( wxTheApp );
119 }
120 }
121
122 return s_SettingsManager;
123}
124
125
127{
128 // For some reasons, LoadProject() needs a C locale, so ensure we have the right locale
129 // This is mainly when running QA Python tests
131
133
134 if( !project )
135 {
138 }
139
140 return project;
141}
142
143BOARD* LoadBoard( wxString& aFileName, PCB_IO_MGR::PCB_FILE_T aFormat )
144{
145 return LoadBoard( aFileName, aFormat, false );
146}
147
148BOARD* LoadBoard( wxString& aFileName, PCB_IO_MGR::PCB_FILE_T aFormat, bool aSetActive )
149{
150 wxFileName pro = aFileName;
151 pro.SetExt( FILEEXT::ProjectFileExtension );
152 pro.MakeAbsolute();
153 wxString projectPath = pro.GetFullPath();
154
155 // Ensure the "C" locale is temporary set, before reading any file
156 // It also avoid wxWidget alerts about locale issues, later, when using Python 3
158
159 PROJECT* project = GetSettingsManager()->GetProject( projectPath );
160
161 if( !project )
162 {
163 if( wxFileExists( projectPath ) )
164 {
165 // cli
166 GetSettingsManager()->LoadProject( projectPath, aSetActive );
167 project = GetSettingsManager()->GetProject( projectPath );
168 }
169 }
170 else if( s_PcbEditFrame && project == &GetSettingsManager()->Prj() )
171 {
172 // Project is already loaded? Then so is the board
173 return s_PcbEditFrame->GetBoard();
174 }
175
176 // Board cannot be loaded without a project, so create the default project
177 if( !project )
179
180 BASE_SCREEN::m_DrawingSheetFileName = project->GetProjectFile().m_BoardDrawingSheetFile;
181
182 // Load the drawing sheet from the filename stored in BASE_SCREEN::m_DrawingSheetFileName.
183 // If empty, or not existing, the default drawing sheet is loaded.
185 project->GetProjectPath() );
186
187 if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename ) )
188 wxFprintf( stderr, _( "Error loading drawing sheet." ) );
189
190 BOARD* brd = PCB_IO_MGR::Load( aFormat, aFileName );
191
192 if( brd )
193 {
194 // JEY TODO: move this global to the board
196
197 layerEnum.Choices().Clear();
198 layerEnum.Undefined( UNDEFINED_LAYER );
199
200 for( LSEQ seq = LSET::AllLayersMask().Seq(); seq; ++seq )
201 {
202 // Canonical name
203 layerEnum.Map( *seq, LSET::Name( *seq ) );
204
205 // User name
206 layerEnum.Map( *seq, brd->GetLayerName( *seq ) );
207 }
208
209 brd->SetProject( project );
210
211 // Move legacy view settings to local project settings
212 if( !brd->m_LegacyVisibleLayers.test( Rescue ) )
213 project->GetLocalSettings().m_VisibleLayers = brd->m_LegacyVisibleLayers;
214
216 project->GetLocalSettings().m_VisibleItems = brd->m_LegacyVisibleItems;
217
219 bds.m_DRCEngine = std::make_shared<DRC_ENGINE>( brd, &bds );
220
221 try
222 {
223 wxFileName rules = pro;
224 rules.SetExt( FILEEXT::DesignRulesFileExtension );
225 bds.m_DRCEngine->InitEngine( rules );
226 }
227 catch( ... )
228 {
229 // Best efforts...
230 }
231
232 for( PCB_MARKER* marker : brd->ResolveDRCExclusions( true ) )
233 brd->Add( marker );
234
235 brd->BuildConnectivity();
236 brd->BuildListOfNets();
237 brd->SynchronizeNetsAndNetClasses( false );
238 brd->UpdateUserUnits( brd, nullptr );
239 }
240
241 return brd;
242}
243
244
245BOARD* NewBoard( wxString& aFileName )
246{
247 wxFileName boardFn = aFileName;
248 wxFileName proFn = aFileName;
249 proFn.SetExt( FILEEXT::ProjectFileExtension );
250 proFn.MakeAbsolute();
251
252 wxString projectPath = proFn.GetFullPath();
253
254 // Ensure the "C" locale is temporary set, before reading any file
255 // It also avoids wxWidgets alerts about locale issues, later, when using Python 3
257
258 GetSettingsManager()->LoadProject( projectPath, false );
259 PROJECT* project = GetSettingsManager()->GetProject( projectPath );
260
261 BOARD* brd = new BOARD();
262
263 brd->SetProject( project );
265 bds.m_DRCEngine = std::make_shared<DRC_ENGINE>( brd, &bds );
266
267 SaveBoard( aFileName, brd );
268
269 return brd;
270}
271
272
274{
275 // Creating a new board is not possible if running inside KiCad
276 if( s_PcbEditFrame )
277 return nullptr;
278
279 BOARD* brd = new BOARD();
280
282
283 return brd;
284}
285
286
287bool SaveBoard( wxString& aFileName, BOARD* aBoard, PCB_IO_MGR::PCB_FILE_T aFormat, bool aSkipSettings )
288{
289 aBoard->BuildConnectivity();
290 aBoard->SynchronizeNetsAndNetClasses( false );
291
292 // Ensure the "C" locale is temporary set, before saving any file
293 // It also avoid wxWidget alerts about locale issues, later, when using Python 3
295
296 try
297 {
298 PCB_IO_MGR::Save( aFormat, aFileName, aBoard, nullptr );
299 }
300 catch( ... )
301 {
302 return false;
303 }
304
305 if( !aSkipSettings )
306 {
307 wxFileName pro = aFileName;
308 pro.SetExt( FILEEXT::ProjectFileExtension );
309 pro.MakeAbsolute();
310
311 GetSettingsManager()->SaveProjectAs( pro.GetFullPath(), aBoard->GetProject() );
312 }
313
314 return true;
315}
316
317
318bool SaveBoard( wxString& aFileName, BOARD* aBoard, bool aSkipSettings )
319{
320 return SaveBoard( aFileName, aBoard, PCB_IO_MGR::KICAD_SEXP, aSkipSettings );
321}
322
323
325{
326 BOARD* board = GetBoard();
327
328 if( !board )
329 return nullptr;
330
331 PROJECT* project = board->GetProject();
332
333 if( !project )
334 return nullptr;
335
337}
338
339
341{
342 wxArrayString footprintLibraryNames;
343
345
346 if( !tbl )
347 return footprintLibraryNames;
348
349 for( const wxString& name : tbl->GetLogicalLibs() )
350 footprintLibraryNames.Add( name );
351
352 return footprintLibraryNames;
353}
354
355
356wxArrayString GetFootprints( const wxString& aNickName )
357{
358 wxArrayString footprintNames;
359
361
362 if( !tbl )
363 return footprintNames;
364
365 tbl->FootprintEnumerate( footprintNames, aNickName, true );
366
367 return footprintNames;
368}
369
370
371bool ExportSpecctraDSN( wxString& aFullFilename )
372{
373 if( s_PcbEditFrame )
374 {
375 bool ok = s_PcbEditFrame->ExportSpecctraFile( aFullFilename );
376 return ok;
377 }
378 else
379 {
380 return false;
381 }
382}
383
384
385bool ExportSpecctraDSN( BOARD* aBoard, wxString& aFullFilename )
386{
387 try
388 {
389 DSN::ExportBoardToSpecctraFile( aBoard, aFullFilename );
390 }
391 catch( ... )
392 {
393 return false;
394 }
395
396 return true;
397}
398
399
400bool ExportVRML( const wxString& aFullFileName, double aMMtoWRMLunit, bool aIncludeUnspecified,
401 bool aIncludeDNP, bool aExport3DFiles,
402 bool aUseRelativePaths, const wxString& a3D_Subdir, double aXRef, double aYRef )
403{
404 if( s_PcbEditFrame )
405 {
406 bool ok = s_PcbEditFrame->ExportVRML_File( aFullFileName, aMMtoWRMLunit,
407 aIncludeUnspecified, aIncludeDNP,
408 aExport3DFiles, aUseRelativePaths,
409 a3D_Subdir, aXRef, aYRef );
410 return ok;
411 }
412 else
413 {
414 return false;
415 }
416}
417
418bool ImportSpecctraSES( wxString& aFullFilename )
419{
420 if( s_PcbEditFrame )
421 {
422 bool ok = s_PcbEditFrame->ImportSpecctraSession( aFullFilename );
423 return ok;
424 }
425 else
426 {
427 return false;
428 }
429}
430
431bool ImportSpecctraSES( BOARD* aBoard, wxString& aFullFilename )
432{
433 try
434 {
435 DSN::ImportSpecctraSession( aBoard, aFullFilename );
436 }
437 catch( ... )
438 {
439 return false;
440 }
441
442 return true;
443}
444
445
446bool ExportFootprintsToLibrary( bool aStoreInNewLib, const wxString& aLibName, wxString* aLibPath )
447{
448 if( s_PcbEditFrame )
449 {
450 s_PcbEditFrame->ExportFootprintsToLibrary( aStoreInNewLib, aLibName, aLibPath );
451 return true;
452 }
453 else
454 {
455 return false;
456 }
457}
458
460{
461 if( s_PcbEditFrame )
462 {
464 }
465}
466
467
469{
470 if( s_PcbEditFrame )
472}
473
474
476{
477 if( s_PcbEditFrame )
478 return static_cast<int>( s_PcbEditFrame->GetUserUnits() );
479
480 return -1;
481}
482
483
484std::deque<BOARD_ITEM*> GetCurrentSelection()
485{
486 std::deque<BOARD_ITEM*> items;
487
488 if( s_PcbEditFrame )
489 {
491
492 std::for_each( selection.begin(), selection.end(),
493 [&items]( EDA_ITEM* item )
494 {
495 items.push_back( static_cast<BOARD_ITEM*>( item ) );
496 } );
497 }
498
499 return items;
500}
501
502void FocusOnItem( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer )
503{
504 if( s_PcbEditFrame )
505 {
506 s_PcbEditFrame->FocusOnItem( aItem, aLayer );
507 }
508}
509
510
512{
514}
515
516
517bool WriteDRCReport( BOARD* aBoard, const wxString& aFileName, EDA_UNITS aUnits,
518 bool aReportAllTrackErrors )
519{
520 wxCHECK( aBoard, false );
521
523 std::shared_ptr<DRC_ENGINE> engine = bds.m_DRCEngine;
524 UNITS_PROVIDER unitsProvider( pcbIUScale, aUnits );
525
526 if( !engine )
527 {
528 bds.m_DRCEngine = std::make_shared<DRC_ENGINE>( aBoard, &bds );
529 engine = bds.m_DRCEngine;
530 }
531
532 wxCHECK( engine, false );
533
534 wxFileName fn = aBoard->GetFileName();
536 PROJECT* prj = nullptr;
537
538 if( aBoard->GetProject() )
539 prj = aBoard->GetProject();
540 else if( s_SettingsManager )
541 prj = &s_SettingsManager->Prj();
542
543 wxCHECK( prj, false );
544
545 // Load the global fp-lib-table otherwise we can't check the libs parity
546 wxFileName fn_flp = FP_LIB_TABLE::GetGlobalTableFileName();
547 if( fn_flp.FileExists() ) {
549 GFootprintTable.Load( fn_flp.GetFullPath() );
550 }
551
552 wxString drcRulesPath = prj->AbsolutePath( fn.GetFullName() );
553
554 // Rebuild The Instance of ENUM_MAP<PCB_LAYER_ID> (layer names list), because the DRC
555 // engine can use layer names (canonical and/or user names)
557 layerEnum.Choices().Clear();
558 layerEnum.Undefined( UNDEFINED_LAYER );
559
560 for( LSEQ seq = LSET::AllLayersMask().Seq(); seq; ++seq )
561 {
562 layerEnum.Map( *seq, LSET::Name( *seq ) ); // Add Canonical name
563 layerEnum.Map( *seq, aBoard->GetLayerName( *seq ) ); // Add User name
564 }
565
566 try
567 {
568 engine->InitEngine( drcRulesPath );
569 }
570 catch( PARSE_ERROR& err )
571 {
572 fprintf( stderr, "Init DRC engine: err <%s>\n", TO_UTF8( err.What() ) ); fflush( stderr);
573 return false;
574 }
575
576 std::vector<std::shared_ptr<DRC_ITEM>> footprints;
577 std::vector<std::shared_ptr<DRC_ITEM>> unconnected;
578 std::vector<std::shared_ptr<DRC_ITEM>> violations;
579
580 engine->SetProgressReporter( nullptr );
581
582 engine->SetViolationHandler(
583 [&]( const std::shared_ptr<DRC_ITEM>& aItem, VECTOR2D aPos, int aLayer )
584 {
585 if( aItem->GetErrorCode() == DRCE_MISSING_FOOTPRINT
586 || aItem->GetErrorCode() == DRCE_DUPLICATE_FOOTPRINT
587 || aItem->GetErrorCode() == DRCE_EXTRA_FOOTPRINT
588 || aItem->GetErrorCode() == DRCE_NET_CONFLICT
589 || aItem->GetErrorCode() == DRCE_SCHEMATIC_PARITY_ISSUES )
590 {
591 footprints.push_back( aItem );
592 }
593 else if( aItem->GetErrorCode() == DRCE_UNCONNECTED_ITEMS )
594 {
595 unconnected.push_back( aItem );
596 }
597 else
598 {
599 violations.push_back( aItem );
600 }
601 } );
602
603 aBoard->RecordDRCExclusions();
604 aBoard->DeleteMARKERs( true, true );
605 engine->RunTests( aUnits, aReportAllTrackErrors, false );
606 engine->ClearViolationHandler();
607
608 // Update the exclusion status on any excluded markers that still exist.
609 aBoard->ResolveDRCExclusions( false );
610
611 // TODO: Unify this with DIALOG_DRC::writeReport
612
613 FILE* fp = wxFopen( aFileName, wxT( "w" ) );
614
615 if( fp == nullptr )
616 return false;
617
618 std::map<KIID, EDA_ITEM*> itemMap;
619 aBoard->FillItemMap( itemMap );
620
621 fprintf( fp, "** Drc report for %s **\n", TO_UTF8( aBoard->GetFileName() ) );
622
623 wxDateTime now = wxDateTime::Now();
624
625 fprintf( fp, "** Created on %s **\n", TO_UTF8( now.Format( wxT( "%F %T" ) ) ) );
626
627 fprintf( fp, "\n** Found %d DRC violations **\n", static_cast<int>( violations.size() ) );
628
629 for( const std::shared_ptr<DRC_ITEM>& item : violations )
630 {
631 SEVERITY severity = item->GetParent() ? item->GetParent()->GetSeverity()
632 : bds.GetSeverity( item->GetErrorCode() );
633 fprintf( fp, "%s", TO_UTF8( item->ShowReport( &unitsProvider, severity, itemMap ) ) );
634 }
635
636 fprintf( fp, "\n** Found %d unconnected pads **\n", static_cast<int>( unconnected.size() ) );
637
638 for( const std::shared_ptr<DRC_ITEM>& item : unconnected )
639 {
640 SEVERITY severity = bds.GetSeverity( item->GetErrorCode() );
641 fprintf( fp, "%s", TO_UTF8( item->ShowReport( &unitsProvider, severity, itemMap ) ) );
642 }
643
644 fprintf( fp, "\n** Found %d Footprint errors **\n", static_cast<int>( footprints.size() ) );
645
646 for( const std::shared_ptr<DRC_ITEM>& item : footprints )
647 {
648 SEVERITY severity = bds.GetSeverity( item->GetErrorCode() );
649 fprintf( fp, "%s", TO_UTF8( item->ShowReport( &unitsProvider, severity, itemMap ) ) );
650 }
651
652 fprintf( fp, "\n** End of Report **\n" );
653 fclose( fp );
654
655 return true;
656}
657
658wxString GetLanguage()
659{
660 if( s_PcbEditFrame )
662 else
663 return "";
664}
const char * name
Definition: DXF_plotter.cpp:57
Class PCBNEW_ACTION_PLUGINS.
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:109
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:77
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:276
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition: board.cpp:891
GAL_SET m_LegacyVisibleItems
Definition: board.h:356
void BuildListOfNets()
Definition: board.h:795
void UpdateUserUnits(BOARD_ITEM *aItem, KIGFX::VIEW *aView)
Update any references within aItem (or its descendants) to the user units.
Definition: board.cpp:1095
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:189
void RecordDRCExclusions()
Scan existing markers and record data from any that are Excluded.
Definition: board.cpp:329
void SynchronizeNetsAndNetClasses(bool aResetTrackAndViaSizes)
Copy NETCLASS info to each NET, based on NET membership in a NETCLASS.
Definition: board.cpp:1813
LSET m_LegacyVisibleLayers
Visibility settings stored in board prior to 6.0, only used for loading legacy files.
Definition: board.h:355
void SetProject(PROJECT *aProject, bool aReferenceOnly=false)
Link a board to a given project.
Definition: board.cpp:199
const wxString & GetFileName() const
Definition: board.h:313
std::vector< PCB_MARKER * > ResolveDRCExclusions(bool aCreateMarkers)
Rebuild DRC markers from the serialized data in BOARD_DESIGN_SETTINGS.
Definition: board.cpp:346
void FillItemMap(std::map< KIID, EDA_ITEM * > &aMap)
Definition: board.cpp:1267
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:576
PROJECT * GetProject() const
Definition: board.h:457
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:806
void DeleteMARKERs()
Delete all MARKERS from the board.
Definition: board.cpp:1121
static DS_DATA_MODEL & GetTheInstance()
static function: returns the instance of DS_DATA_MODEL used in the application
static const wxString ResolvePath(const wxString &aPath, const wxString &aProjectPath)
Resolve a path which might be project-relative or contain env variable references.
SETTINGS_MANAGER * GetSettingsManager() const
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
ENUM_MAP & Map(T aValue, const wxString &aName)
Definition: property.h:659
static ENUM_MAP< T > & Instance()
Definition: property.h:653
ENUM_MAP & Undefined(T aValue)
Definition: property.h:666
wxPGChoices & Choices()
Definition: property.h:702
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.
void Clear()
Delete all rows.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:49
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition: layer_ids.h:519
static LSET AllLayersMask()
Definition: lset.cpp:898
static const wxChar * Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:89
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 void Save(PCB_FILE_T aFileType, const wxString &aFileName, BOARD *aBoard, const STRING_UTF8_MAP *aProperties=nullptr)
Write either a full aBoard to a storage file in a format that this implementation knows about,...
Definition: pcb_io_mgr.cpp:172
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 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::LoadBoard() function on it using the argu...
Definition: pcb_io_mgr.cpp:156
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:62
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:320
ITER end()
Definition: selection.h:74
ITER begin()
Definition: selection.h:73
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:169
@ 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
@ DRCE_SCHEMATIC_PARITY_ISSUES
Definition: drc_item.h:74
#define _(s)
EDA_UNITS
Definition: eda_units.h:46
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:591
@ 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:229
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:134
#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:271
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 ...
BOARD * LoadBoard(wxString &aFileName, bool aSetActive)
Loads a board from file This function identifies the file type by extension and determines the correc...
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.
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!...
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:391
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.