KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcbnew.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) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#include <pgm_base.h>
23#include <eda_pattern_match.h>
26#include <confirm.h>
28#include <api/api_handler_pcb.h>
29#include <api/api_server.h>
30#include <api/api_utils.h>
33#include <kiface_base.h>
34#include <kiface_ids.h>
35#include <kiway_holder.h>
36#include <pcb_edit_frame.h>
37#include <eda_dde.h>
38#include <macros.h>
39#include <wx/snglinst.h>
40#include <gestfich.h>
41#include <paths.h>
42#include <pcbnew_settings.h>
43#include <footprint.h>
53#include <footprint_info_impl.h>
54#include <footprint.h>
55#include <board.h>
56#include <board_loader.h>
57#include <lib_id.h>
58#include <nlohmann/json.hpp>
62#include <panel_edit_options.h>
74#include <project_pcb.h>
75#include <string_utils.h>
76#include <thread_pool.h>
77#include <trace_helpers.h>
78#include <widgets/kistatusbar.h>
79
80#include <wx/tokenzr.h>
81
82#include "invoke_pcb_dialog.h"
84#include "pcbnew_jobs_handler.h"
86#include <reporter.h>
87#include "git/kigit_pcb_merge.h"
88#include "git/kigit_fp_merge.h"
90
94#include <toolbars_pcb_editor.h>
95
96#include <wx/crt.h>
97
98
111static wxString filterFootprints( const wxString& aFilterJson )
112{
113 using json = nlohmann::json;
114
115 try
116 {
117 json input = json::parse( aFilterJson.ToStdString() );
118
119 int pinCount = input.value( "pin_count", 0 );
120 bool zeroFilters = input.value( "zero_filters", true );
121 int maxResults = input.value( "max_results", 400 );
122
123 std::vector<std::unique_ptr<EDA_PATTERN_MATCH>> filterMatchers;
124
125 if( input.contains( "filters" ) && input["filters"].is_array() )
126 {
127 for( const auto& f : input["filters"] )
128 {
129 if( f.is_string() )
130 {
131 wxString pattern = wxString::FromUTF8( f.get<std::string>() );
132 auto matcher = std::make_unique<EDA_PATTERN_MATCH_WILDCARD_ANCHORED>();
133 matcher->SetPattern( pattern.Lower() );
134 filterMatchers.push_back( std::move( matcher ) );
135 }
136 }
137 }
138
139 bool hasFilters = ( pinCount > 0 || !filterMatchers.empty() );
140
141 if( zeroFilters && !hasFilters )
142 return wxS( "[]" );
143
144 PROJECT* project = nullptr;
145
146 if( wxTheApp )
147 {
148 wxWindow* focus = wxWindow::FindFocus();
149 wxWindow* top = focus ? wxGetTopLevelParent( focus ) : wxTheApp->GetTopWindow();
150
151 if( top )
152 {
153 if( KIWAY_HOLDER* holder = dynamic_cast<KIWAY_HOLDER*>( top ) )
154 project = &holder->Prj();
155 }
156 }
157
158 if( !project )
160
162
163 if( !adapter )
164 return wxS( "[]" );
165
166 adapter->AsyncLoad();
167 adapter->BlockUntilLoaded();
168
169 // Iterate through preloaded footprints directly instead of re-reading from disk
170 json output = json::array();
171 int count = 0;
172
173 for( const wxString& nickname : adapter->GetLibraryNames() )
174 {
175 std::vector<FOOTPRINT*> footprints = adapter->GetFootprints( nickname, true );
176
177 for( FOOTPRINT* fp : footprints )
178 {
179 if( !fp )
180 continue;
181
182 // Pin count filter
183 if( pinCount > 0 )
184 {
185 int fpPadCount = fp->GetUniquePadCount( DO_NOT_INCLUDE_NPTH );
186
187 if( fpPadCount != pinCount )
188 continue;
189 }
190
191 // Footprint filter patterns with case-insensitive matching
192 if( !filterMatchers.empty() )
193 {
194 bool matches = false;
195
196 for( const auto& matcher : filterMatchers )
197 {
198 wxString name;
199
200 // If filter contains ':', include library nickname in match string
201 if( matcher->GetPattern().Contains( wxS( ":" ) ) )
202 name = fp->GetFPID().GetLibNickname().wx_str().Lower() + wxS( ":" );
203
204 name += fp->GetFPID().GetLibItemName().wx_str().Lower();
205
206 if( matcher->Find( name ) )
207 {
208 matches = true;
209 break;
210 }
211 }
212
213 if( !matches )
214 continue;
215 }
216
217 wxString libId = fp->GetFPID().Format();
218 output.push_back( libId.ToStdString() );
219
220 if( ++count >= maxResults )
221 break;
222 }
223
224 if( count >= maxResults )
225 break;
226 }
227
228 return wxString::FromUTF8( output.dump() );
229 }
230 catch( const std::exception& )
231 {
232 return wxS( "[]" );
233 }
234}
235
236
237namespace PCB {
238
239// Non-job kiface exports for diff/merge (returned by IfaceOrAddress). Defined
240// after the kiface instance so they can route into its jobs handler.
241static int pcbnewMergeExport( int aKind, const wxString& aAncestor, const wxString& aOurs,
242 const wxString& aTheirs, const wxString& aOutput, bool aInteractive,
243 bool aSingleFile, REPORTER* aReporter );
244static int pcbnewOpenDiffDialogExport( int aKind, const wxString& aFileA, const wxString& aFileB,
245 const wxString& aLabelA, const wxString& aLabelB,
246 wxWindow* aParent, REPORTER* aReporter );
247
248
249static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER
250{
251 // Of course all are virtual overloads, implementations of the KIFACE.
252
253 IFACE( const char* aName, KIWAY::FACE_T aType ) :
254 KIFACE_BASE( aName, aType ),
256 {}
257
258 bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits, KIWAY* aKiway ) override;
259
260 void Reset() override;
261
262 void OnKifaceEnd() override;
263
264 wxWindow* CreateKiWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway, int aCtlBits = 0 ) override
265 {
266 switch( aClassId )
267 {
268 case FRAME_PCB_EDITOR:
269 {
270 auto frame = new PCB_EDIT_FRAME( aKiway, aParent );
271
272 if( Kiface().IsSingle() )
273 {
274 // only run this under single_top, not under a project manager.
275 frame->CreateServer( KICAD_PCB_PORT_SERVICE_NUMBER );
276 }
277
278 return frame;
279 }
280
282 return new FOOTPRINT_EDIT_FRAME( aKiway, aParent );
285 return new FOOTPRINT_VIEWER_FRAME( aKiway, aParent );
286
288 return new FOOTPRINT_CHOOSER_FRAME( aKiway, aParent );
289
291 return new FOOTPRINT_WIZARD_FRAME( aKiway, aParent, FRAME_T( aClassId ) );
292
294 return FOOTPRINT_PREVIEW_PANEL::New( aKiway, aParent, this );
295
297 {
298 DIALOG_CONFIGURE_PATHS dlg( aParent );
299
300 // The dialog's constructor probably failed to set its Kiway because the
301 // dynamic_cast fails when aParent was allocated by a separate compilation
302 // module. So set it directly.
303 dlg.SetKiway( &dlg, aKiway );
304
305 // Use QuasiModal so that HTML help window will work
306 if( dlg.ShowQuasiModal() == wxID_OK )
308
309 // Dialog has completed; nothing to return.
310 return nullptr;
311 }
312
314 InvokePcbLibTableEditor( aKiway, aParent );
315 // Dialog has completed; nothing to return.
316 return nullptr;
317
319 return new PANEL_DISPLAY_OPTIONS( aParent, GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>( "fpedit" ) );
320
321 case PANEL_FP_GRIDS:
322 {
323 FOOTPRINT_EDITOR_SETTINGS* cfg = GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>( "fpedit" );
324 EDA_BASE_FRAME* frame = aKiway->Player( FRAME_FOOTPRINT_EDITOR, false );
325
326 if( !frame )
327 frame = aKiway->Player( FRAME_FOOTPRINT_VIEWER, false );
328
329 if( !frame )
330 frame = aKiway->Player( FRAME_PCB_EDITOR, false );
331
332 if( frame )
333 SetUserUnits( frame->GetUserUnits() );
334
335 return new PANEL_GRID_SETTINGS( aParent, this, frame, cfg, FRAME_FOOTPRINT_EDITOR );
336 }
342
346
348 {
349 EDA_BASE_FRAME* frame = aKiway->Player( FRAME_FOOTPRINT_EDITOR, false );
350
351 if( !frame )
352 frame = aKiway->Player( FRAME_FOOTPRINT_VIEWER, false );
354 if( !frame )
355 frame = aKiway->Player( FRAME_PCB_EDITOR, false );
356
357 if( frame )
360 return new PANEL_EDIT_OPTIONS( aParent, this, frame, true );
361 }
362
365 EDA_BASE_FRAME* frame = aKiway->Player( FRAME_FOOTPRINT_EDITOR, false );
367 if( !frame )
368 frame = aKiway->Player( FRAME_FOOTPRINT_VIEWER, false );
370 if( !frame )
371 frame = aKiway->Player( FRAME_PCB_EDITOR, false );
373 if( frame )
376 return new PANEL_FP_EDITOR_FIELD_DEFAULTS( aParent );
377 }
378
380 {
381 EDA_BASE_FRAME* frame = aKiway->Player( FRAME_FOOTPRINT_EDITOR, false );
382
383 if( !frame )
384 frame = aKiway->Player( FRAME_FOOTPRINT_VIEWER, false );
385
386 if( !frame )
387 frame = aKiway->Player( FRAME_PCB_EDITOR, false );
388
389 if( frame )
390 SetUserUnits( frame->GetUserUnits() );
391
392 return new PANEL_FP_EDITOR_GRAPHICS_DEFAULTS( aParent, this );
393 }
394
396 return new class PANEL_FP_USER_LAYER_NAMES( aParent );
397
399 {
400 APP_SETTINGS_BASE* cfg = GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>( "fpedit" );
401 TOOLBAR_SETTINGS* tb = GetToolbarSettings<FOOTPRINT_EDIT_TOOLBAR_SETTINGS>( "fpedit-toolbars" );
402
403 std::vector<TOOL_ACTION*> actions;
404 std::vector<ACTION_TOOLBAR_CONTROL*> controls;
405
406 for( TOOL_ACTION* action : ACTION_MANAGER::GetActionList() )
407 actions.push_back( action );
408
409 for( ACTION_TOOLBAR_CONTROL* control : ACTION_TOOLBAR::GetCustomControlList( FRAME_FOOTPRINT_EDITOR ) )
410 controls.push_back( control );
411
412 return new PANEL_TOOLBAR_CUSTOMIZATION( aParent, cfg, tb, FRAME_FOOTPRINT_EDITOR, actions, controls );
413 }
414
415 case PANEL_FP_COLORS:
416 return new PANEL_FP_EDITOR_COLOR_SETTINGS( aParent );
417
419 return new PANEL_DISPLAY_OPTIONS( aParent, GetAppSettings<PCBNEW_SETTINGS>( "pcbnew" ) );
420
421 case PANEL_PCB_GRIDS:
422 {
423 PCBNEW_SETTINGS* cfg = GetAppSettings<PCBNEW_SETTINGS>( "pcbnew" );
424 EDA_BASE_FRAME* frame = aKiway->Player( FRAME_PCB_EDITOR, false );
425
426 if( !frame )
427 frame = aKiway->Player( FRAME_FOOTPRINT_EDITOR, false );
428
429 if( !frame )
430 frame = aKiway->Player( FRAME_FOOTPRINT_VIEWER, false );
431
432 if( frame )
433 SetUserUnits( frame->GetUserUnits() );
434
435 return new PANEL_GRID_SETTINGS( aParent, this, frame, cfg, FRAME_PCB_EDITOR );
436 }
437
441
443 return new PANEL_PCBNEW_DISPLAY_ORIGIN( aParent, GetAppSettings<PCBNEW_SETTINGS>( "pcbnew" ),
445
447 {
448 EDA_BASE_FRAME* frame = aKiway->Player( FRAME_PCB_EDITOR, false );
449
450 if( !frame )
451 frame = aKiway->Player( FRAME_FOOTPRINT_EDITOR, false );
452
453 if( !frame )
454 frame = aKiway->Player( FRAME_FOOTPRINT_VIEWER, false );
455
456 if( frame )
457 SetUserUnits( frame->GetUserUnits() );
458
459 return new PANEL_EDIT_OPTIONS( aParent, this, frame, false );
460 }
461
462 case PANEL_PCB_COLORS:
463 {
464 BOARD* board = nullptr;
465 EDA_BASE_FRAME* boardProvider = aKiway->Player( FRAME_PCB_EDITOR, false );
466
467 if( boardProvider )
468 board = static_cast<PCB_EDIT_FRAME*>( boardProvider )->GetBoard();
469
470 return new PANEL_PCBNEW_COLOR_SETTINGS( aParent, board );
471 }
472
474 {
475 APP_SETTINGS_BASE* cfg = GetAppSettings<PCBNEW_SETTINGS>( "pcbnew" );
476 TOOLBAR_SETTINGS* tb = GetToolbarSettings<PCB_EDIT_TOOLBAR_SETTINGS>( "pcbnew-toolbars" );
477
478 std::vector<TOOL_ACTION*> actions;
479 std::vector<ACTION_TOOLBAR_CONTROL*> controls;
480
481 for( TOOL_ACTION* action : ACTION_MANAGER::GetActionList() )
482 actions.push_back( action );
483
484 for( ACTION_TOOLBAR_CONTROL* control : ACTION_TOOLBAR::GetCustomControlList( FRAME_PCB_EDITOR ) )
485 controls.push_back( control );
486
487 return new PANEL_TOOLBAR_CUSTOMIZATION( aParent, cfg, tb, FRAME_PCB_EDITOR, actions, controls );
488 }
489
491 return new PANEL_PCBNEW_ACTION_PLUGINS( aParent );
492
494 return new PANEL_3D_DISPLAY_OPTIONS( aParent );
495
496 case PANEL_3DV_OPENGL:
497 return new PANEL_3D_OPENGL_OPTIONS( aParent );
498
500 return new PANEL_3D_RAYTRACING_OPTIONS( aParent );
501
503 {
504 APP_SETTINGS_BASE* cfg = GetAppSettings<EDA_3D_VIEWER_SETTINGS>( "3d_viewer" );
505 TOOLBAR_SETTINGS* tb = GetToolbarSettings<EDA_3D_VIEWER_TOOLBAR_SETTINGS>( "3d_viewer-toolbars" );
506
507 std::vector<TOOL_ACTION*> actions;
508 std::vector<ACTION_TOOLBAR_CONTROL*> controls;
509
510 for( TOOL_ACTION* action : ACTION_MANAGER::GetActionList() )
511 actions.push_back( action );
512
513 for( ACTION_TOOLBAR_CONTROL* control : ACTION_TOOLBAR::GetCustomControlList( FRAME_PCB_DISPLAY3D ) )
514 controls.push_back( control );
515
516 return new PANEL_TOOLBAR_CUSTOMIZATION( aParent, cfg, tb, FRAME_PCB_DISPLAY3D, actions, controls );
517 }
518
519 default:
520 return nullptr;
521 }
522 }
523
534 void* IfaceOrAddress( int aDataId ) override
535 {
536 switch( aDataId )
537 {
539 {
540 // This is the mechanism by which FOOTPRINT_SELECT_WIDGET can get access to the adapter
541 // without directly linking to pcbnew or pcbcommon, going through PROJECT::FootprintLibAdapter
542 PROJECT* project = nullptr;
543
544 if( wxTheApp )
545 {
546 wxWindow* focus = wxWindow::FindFocus();
547 wxWindow* top = focus ? wxGetTopLevelParent( focus ) : wxTheApp->GetTopWindow();
548
549 if( top )
550 {
551 if( KIWAY_HOLDER* holder = dynamic_cast<KIWAY_HOLDER*>( top ) )
552 project = &holder->Prj();
553 }
554 }
555
556 if( !project )
558
560 }
561
563 {
564 // Return function pointer for filtering footprints
565 // Signature: wxString (*)(const wxString& aFilterJson)
566 return reinterpret_cast<void*>( &filterFootprints );
567 }
568
570 return reinterpret_cast<void*>( &pcbnewMergeExport );
571
573 return reinterpret_cast<void*>( &pcbnewOpenDiffDialogExport );
574
575 default:
576 return nullptr;
577 }
578 }
579
581 PCBNEW_JOBS_HANDLER* JobHandler() const { return m_jobHandler.get(); }
582
588 void SaveFileAs( const wxString& aProjectBasePath, const wxString& aSrcProjectName,
589 const wxString& aNewProjectBasePath, const wxString& aNewProjectName,
590 const wxString& aSrcFilePath, wxString& aErrors ) override;
591
592 int HandleJob( JOB* aJob, REPORTER* aReporter, PROGRESS_REPORTER* aProgressReporter ) override;
593
594 bool HandleJobConfig( JOB* aJob, wxWindow* aParent ) override;
595
596 bool HandleApiOpenDocument( const wxString& aPath,
597 KICAD_API_SERVER* aServer,
598 wxString* aError ) override;
599
600 bool HandleApiCloseDocument( const wxString& aBoardFileName,
601 KICAD_API_SERVER* aServer,
602 wxString* aError ) override;
603
604 bool handleOpenPcb( const wxString& aPath, KICAD_API_SERVER* aServer, wxString* aError );
605
606 bool handleOpenFootprint( const wxString& aProjectPath, const wxString& aLibIdStr, KICAD_API_SERVER* aServer,
607 wxString* aError );
608
609 void PreloadLibraries( KIWAY* aKiway ) override;
610 void ProjectChanged() override;
611 void CancelPreload( bool aBlock = true ) override;
612
613private:
614 std::unique_ptr<PCBNEW_JOBS_HANDLER> m_jobHandler;
615 std::shared_ptr<BACKGROUND_JOB> m_libraryPreloadBackgroundJob;
616 std::future<void> m_libraryPreloadReturn;
618 std::atomic_bool m_libraryPreloadAbort;
619
620 void closeCurrentDocument( KICAD_API_SERVER* aServer );
621
622 KIWAY* m_kiway = nullptr;
623 std::shared_ptr<HEADLESS_PCB_CONTEXT> m_openContext;
624 std::unique_ptr<API_HANDLER_PCB> m_openHandler;
625 std::shared_ptr<HEADLESS_FOOTPRINT_CONTEXT> m_openFpContext;
626 std::unique_ptr<API_HANDLER_FOOTPRINT> m_openFpHandler;
627
628} kiface( "pcbnew", KIWAY::FACE_PCB );
629
630
631int pcbnewMergeExport( int aKind, const wxString& aAncestor, const wxString& aOurs,
632 const wxString& aTheirs, const wxString& aOutput, bool aInteractive,
633 bool aSingleFile, REPORTER* aReporter )
634{
635 return kiface.JobHandler()->RunMerge( static_cast<KICAD_DIFF::DOC_KIND>( aKind ), aAncestor,
636 aOurs, aTheirs, aOutput, aInteractive, aSingleFile,
637 aReporter );
638}
639
640
641int pcbnewOpenDiffDialogExport( int aKind, const wxString& aFileA, const wxString& aFileB,
642 const wxString& aLabelA, const wxString& aLabelB,
643 wxWindow* aParent, REPORTER* aReporter )
644{
645 return kiface.JobHandler()->OpenDiffDialog( static_cast<KICAD_DIFF::DOC_KIND>( aKind ), aFileA,
646 aFileB, aLabelA, aLabelB, aParent, aReporter );
647}
648
649} // namespace
650
651
652using namespace PCB;
653
654
656
657
658// KIFACE_GETTER's actual spelling is a substitution macro found in kiway.h.
659// KIFACE_GETTER will not have name mangling due to declaration in kiway.h.
660KIFACE_API KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKiwayVersion, PGM_BASE* aProgram )
661{
662 return &kiface;
663}
664
665
666bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits, KIWAY* aKiway )
667{
668 // This is process-level-initialization, not project-level-initialization of the DSO.
669 // Do nothing in here pertinent to a project!
671
672 SETTINGS_MANAGER& mgr = aProgram->GetSettingsManager();
673
676
677 // We intentionally register KifaceSettings after FOOTPRINT_EDITOR_SETTINGS and EDA_3D_VIEWER_SETTINGS
678 // In legacy configs, many settings were in a single editor config and the migration routine
679 // for the main editor file will try and call into the now separate settings stores
680 // to move the settings into them
682
683 // Register the footprint editor settings as well because they share a KiFACE and need to be
684 // loaded prior to use to avoid threading deadlocks
686
687 start_common( aCtlBits );
688
689 m_kiway = aKiway;
690
691 m_jobHandler = std::make_unique<PCBNEW_JOBS_HANDLER>( aKiway );
692
694 {
695 m_jobHandler->SetReporter( &CLI_REPORTER::GetInstance() );
696 m_jobHandler->SetProgressReporter( &CLI_PROGRESS_REPORTER::GetInstance() );
697 }
698
699 // Register the PCB and footprint merge drivers with libgit2 so
700 // .gitattributes entries `merge=kicad-pcb` and `merge=kicad-fp` route
701 // through our 3-way merge pipeline. git_merge_driver_register is not
702 // thread-safe; this runs once at kiface init before any background work
703 // spawns. The registry is idempotent so re-loads of the kiface are safe.
706
707 return true;
708}
709
710
712{
713}
714
715
717{
718 // Release the CLI-cached board while the static DRC_ITEM tables it serializes against are
719 // still alive; deferring to static teardown crashes reading dangling severity keys
720 if( m_jobHandler )
721 m_jobHandler->ClearCachedBoard();
722
723 end_common();
724}
725
726
727void IFACE::SaveFileAs( const wxString& aProjectBasePath, const wxString& aSrcProjectName,
728 const wxString& aNewProjectBasePath, const wxString& aNewProjectName,
729 const wxString& aSrcFilePath, wxString& aErrors )
730{
731 wxFileName destFile( aSrcFilePath );
732 wxString destPath = destFile.GetPathWithSep();
733 wxUniChar pathSep = wxFileName::GetPathSeparator();
734 wxString ext = destFile.GetExt();
735
736 if( destPath.StartsWith( aProjectBasePath + pathSep ) )
737 destPath.Replace( aProjectBasePath, aNewProjectBasePath, false );
738
739 wxString srcProjectFootprintLib = pathSep + aSrcProjectName + wxT( ".pretty" ) + pathSep;
740 wxString newProjectFootprintLib = pathSep + aNewProjectName + wxT( ".pretty" ) + pathSep;
741
742 destPath.Replace( srcProjectFootprintLib, newProjectFootprintLib, true );
743
744 destFile.SetPath( destPath );
745
748 {
749 if( destFile.GetName() == aSrcProjectName )
750 destFile.SetName( aNewProjectName );
751
752 CopySexprFile( aSrcFilePath, destFile.GetFullPath(),
753 [&]( const std::string& token, wxString& value )
754 {
755 if( token == "sheetfile" )
756 {
757 for( const wxString extension : { wxT( ".sch" ), wxT( ".kicad_sch" ) } )
758 {
759 if( value == aSrcProjectName + extension )
760 {
761 value = aNewProjectName + extension;
762 return true;
763 }
764 else if( value == aProjectBasePath + "/" + aSrcProjectName + extension )
765 {
766 value = aNewProjectBasePath + "/" + aNewProjectName + extension;
767 return true;
768 }
769 else if( value.StartsWith( aProjectBasePath ) )
770 {
771 value.Replace( aProjectBasePath, aNewProjectBasePath, false );
772 return true;
773 }
774 }
775 }
776
777 return false;
778 },
779 aErrors );
780 }
781 else if( ext == FILEEXT::LegacyPcbFileExtension )
782 {
783 if( destFile.GetName() == aSrcProjectName )
784 destFile.SetName( aNewProjectName );
785
786 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
787 }
790 {
791 // Footprints are not project-specific. Keep their source names.
792 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
793 }
795 {
796 // TODO
797 }
798 else if( ext == wxT( "rpt" ) )
799 {
800 // DRC must be the "gold standard". Since we can't guarantee that there aren't
801 // any non-deterministic cases in the save-as algorithm, we don't want to certify
802 // the result with the source's DRC report. Therefore copy it under the old
803 // name.
804 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
805 }
806 else if( destFile.GetName() == FILEEXT::FootprintLibraryTableFileName )
807 {
808 wxFileName libTableFn( aSrcFilePath );
809 LIBRARY_TABLE libTable( libTableFn, LIBRARY_TABLE_SCOPE::PROJECT );
810 libTable.SetPath( destFile.GetFullPath() );
811 libTable.SetType( LIBRARY_TABLE_TYPE::FOOTPRINT );
812
813 for( LIBRARY_TABLE_ROW& row : libTable.Rows() )
814 {
815 wxString uri = row.URI();
816
817 uri.Replace( wxT( "/" ) + aSrcProjectName + wxT( ".pretty" ),
818 wxT( "/" ) + aNewProjectName + wxT( ".pretty" ) );
819
820 row.SetURI( uri );
821 }
822
823 libTable.Save().map_error(
824 [&]( const LIBRARY_ERROR& aError )
825 {
826 wxString msg;
827
828 if( !aErrors.empty() )
829 aErrors += wxT( "\n" );
830
831 msg.Printf( _( "Cannot copy file '%s'." ), destFile.GetFullPath() );
832 aErrors += msg;
833 } );
834 }
835 else
836 {
837 wxFAIL_MSG( wxT( "Unexpected filetype for Pcbnew::SaveFileAs()" ) );
838 }
839}
840
841
842int IFACE::HandleJob( JOB* aJob, REPORTER* aReporter, PROGRESS_REPORTER* aProgressReporter )
843{
844 return m_jobHandler->RunJob( aJob, aReporter, aProgressReporter );
845}
846
847
848bool IFACE::HandleJobConfig( JOB* aJob, wxWindow* aParent )
849{
850 return m_jobHandler->HandleJobConfig( aJob, aParent );
851}
852
853
855{
856 if( m_openHandler )
857 {
858 if( aServer )
859 aServer->DeregisterHandler( m_openHandler.get() );
860
861 m_openHandler.reset();
862 }
863
864 m_openContext.reset();
865
866 // The jobs handler caches the last-loaded board. Clear it so the next job
867 // uses the board from the newly opened document rather than a stale copy.
868 m_jobHandler->ClearCachedBoard();
869
870 if( m_openFpHandler )
871 {
872 if( aServer )
873 aServer->DeregisterHandler( m_openFpHandler.get() );
874
875 m_openFpHandler.reset();
876 }
877
878 m_openFpContext.reset();
879}
880
881
882bool IFACE::HandleApiOpenDocument( const wxString& aPath, KICAD_API_SERVER* aServer, wxString* aError )
883{
884 wxCHECK( aServer, false );
885
886 if( aPath.IsEmpty() )
887 {
888 if( aError )
889 *aError = wxS( "No path specified to open" );
890
891 return false;
892 }
893
894 return handleOpenPcb( aPath, aServer, aError );
895}
896
897
898bool IFACE::handleOpenFootprint( const wxString& aProjectPath, const wxString& aLibIdStr, KICAD_API_SERVER* aServer,
899 wxString* aError )
900{
901 LIB_ID fpid;
902
903 if( fpid.Parse( aLibIdStr ) >= 0 )
904 {
905 if( aError )
906 *aError = wxString::Format( wxS( "Invalid footprint LIB_ID: %s" ), aLibIdStr );
907
908 return false;
909 }
910
911 wxFileName projectPath( aProjectPath );
912 projectPath.MakeAbsolute();
913
914 SETTINGS_MANAGER& settingsManager = Pgm().GetSettingsManager();
915
916 if( !settingsManager.LoadProject( projectPath.GetFullPath(), true ) )
917 {
918 wxLogTrace( traceApi, "Warning: no project file found for %s", aProjectPath );
919 }
920
921 PROJECT* project = settingsManager.GetProject( projectPath.GetFullPath() );
922
923 if( !project )
924 {
925 if( aError )
926 *aError = wxString::Format( wxS( "Error loading project for %s" ), aProjectPath );
927
928 return false;
929 }
930
931 std::shared_ptr<HEADLESS_FOOTPRINT_CONTEXT> newContext;
932
933 try
934 {
936 adapter->AsyncLoad();
937 adapter->BlockUntilLoaded();
938 std::unique_ptr<FOOTPRINT> footprint( adapter->LoadFootprintWithOptionalNickname( fpid, true ) );
939
940 if( !footprint )
941 {
942 if( aError )
943 *aError = wxString::Format( wxS( "Footprint not found: %s" ), aLibIdStr );
944
945 return false;
946 }
947
948 newContext = std::make_shared<HEADLESS_FOOTPRINT_CONTEXT>(
949 std::move( footprint ), fpid, project, GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>( "fpedit" ), m_kiway );
950 }
951 catch( ... )
952 {
953 if( aError )
954 *aError = wxString::Format( wxS( "Failed to load footprint: %s" ), aLibIdStr );
955
956 return false;
957 }
958
959 closeCurrentDocument( aServer );
960 m_openFpContext = std::move( newContext );
961
962 m_openFpHandler = std::make_unique<API_HANDLER_FOOTPRINT>( m_openFpContext, nullptr );
963 aServer->RegisterHandler( m_openFpHandler.get() );
964
965 return true;
966}
967
968
969bool IFACE::handleOpenPcb( const wxString& aPath, KICAD_API_SERVER* aServer, wxString* aError )
970{
971 wxFileName projectPath( aPath );
972
973 if( projectPath.GetExt() == FILEEXT::KiCadPcbFileExtension )
974 projectPath.SetExt( FILEEXT::ProjectFileExtension );
975 else if( projectPath.GetExt() != FILEEXT::ProjectFileExtension )
976 projectPath.SetExt( FILEEXT::ProjectFileExtension );
977
978 projectPath.MakeAbsolute();
979
980 // Close any existing document before loading a new project. LoadProject with
981 // aSetActive=true destroys the old PROJECT, which would leave the old board and
982 // context holding dangling m_project pointers.
983 closeCurrentDocument( aServer );
984
985 SETTINGS_MANAGER& settingsManager = Pgm().GetSettingsManager();
986
987 if( !settingsManager.LoadProject( projectPath.GetFullPath(), true ) )
988 {
989 wxLogTrace( traceApi, "Warning: no project file found for %s", aPath );
990 }
991
992 PROJECT* project = settingsManager.GetProject( projectPath.GetFullPath() );
993
994 if( !project )
995 {
996 if( aError )
997 *aError = wxString::Format( wxS( "Error loading project for %s" ), aPath );
998
999 return false;
1000 }
1001
1002 wxFileName boardPath( projectPath );
1003 boardPath.SetExt( FILEEXT::KiCadPcbFileExtension );
1004
1005 if( !boardPath.FileExists() )
1006 {
1007 if( aError )
1008 *aError = wxString::Format( wxS( "File not found: %s" ), aPath );
1009
1010 return false;
1011 }
1012
1013 PCB_IO_MGR::PCB_FILE_T pluginType =
1015
1016 if( pluginType == PCB_IO_MGR::FILE_TYPE_NONE )
1017 {
1018 if( aError )
1019 *aError = wxString::Format( wxS( "%s is not a recognized file type" ), aPath );
1020
1021 return false;
1022 }
1023
1024 std::shared_ptr<HEADLESS_PCB_CONTEXT> newContext;
1025
1026 try
1027 {
1028 std::unique_ptr<BOARD> loadedBoard = BOARD_LOADER::Load( boardPath.GetFullPath(), pluginType, project );
1029
1030 if( !loadedBoard )
1031 {
1032 if( aError )
1033 *aError = wxS( "Failed to load board" );
1034
1035 return false;
1036 }
1037
1038 newContext = std::make_shared<HEADLESS_PCB_CONTEXT>( std::move( loadedBoard ), project,
1040 }
1041 catch( const IO_ERROR& ioe )
1042 {
1043 if( aError )
1044 *aError = wxString::Format( wxS( "Failed to load board: %s" ), ioe.What() );
1045
1046 return false;
1047 }
1048 catch( ... )
1049 {
1050 if( aError )
1051 *aError = wxS( "Failed to load board" );
1052
1053 return false;
1054 }
1055
1056 m_openContext = std::move( newContext );
1057
1058 m_openHandler = std::make_unique<API_HANDLER_PCB>( m_openContext, nullptr );
1059 aServer->RegisterHandler( m_openHandler.get() );
1060
1061 return true;
1062}
1063
1064
1065bool IFACE::HandleApiCloseDocument( const wxString& aFileName, KICAD_API_SERVER* aServer, wxString* aError )
1066{
1067 wxCHECK( aServer, false );
1068
1070 {
1071 if( aError )
1072 *aError = wxS( "No document is currently open" );
1073
1074 return false;
1075 }
1076
1077 if( !aFileName.IsEmpty() && m_openContext )
1078 {
1079 wxFileName currentBoard( m_openContext->GetCurrentFileName() );
1080
1081 if( currentBoard.GetFullName() != aFileName )
1082 {
1083 if( aError )
1084 *aError = wxS( "Requested document does not match the open document" );
1085
1086 return false;
1087 }
1088 }
1089
1090 closeCurrentDocument( aServer );
1091 return true;
1092}
1093
1094
1096{
1097 constexpr static int interval = 150;
1098 constexpr static int timeLimit = 120000;
1099
1100 wxCHECK( aKiway, /* void */ );
1101
1102 // Use compare_exchange to atomically check and set the flag to prevent race conditions
1103 // when PreloadLibraries is called multiple times concurrently (e.g., from project manager
1104 // and pcb editor both scheduling via CallAfter)
1105 bool expected = false;
1106
1107 if( !m_libraryPreloadInProgress.compare_exchange_strong( expected, true ) )
1108 return;
1109
1111
1113 Pgm().GetBackgroundJobMonitor().Create( _( "Loading Footprint Libraries" ) );
1114
1115 auto preload =
1116 [this, aKiway]() -> void
1117 {
1118 std::shared_ptr<BACKGROUND_JOB_REPORTER> reporter =
1120
1122
1123 int elapsed = 0;
1124 bool aborted = false;
1125
1126 reporter->Report( _( "Loading Footprint Libraries" ) );
1127 adapter->AsyncLoad();
1128
1129 while( true )
1130 {
1131 if( m_libraryPreloadAbort.load() )
1132 {
1133 m_libraryPreloadAbort.store( false );
1134 aborted = true;
1135 break;
1136 }
1137
1138 std::this_thread::sleep_for( std::chrono::milliseconds( interval ) );
1139
1140 if( std::optional<float> loadStatus = adapter->AsyncLoadProgress() )
1141 {
1142 float progress = *loadStatus;
1143 reporter->SetCurrentProgress( progress );
1144
1145 if( progress >= 1 )
1146 break;
1147 }
1148 else
1149 {
1150 reporter->SetCurrentProgress( 1 );
1151 break;
1152 }
1153
1154 elapsed += interval;
1155
1156 if( elapsed > timeLimit )
1157 break;
1158 }
1159
1160 // AbortAsyncLoad() sets the adapter's worker abort flag and then blocks,
1161 // so workers exit at their next checkpoint. BlockUntilLoaded() alone just
1162 // waits for each future to complete naturally, which can hang indefinitely
1163 // if a worker is stuck on a stalled network or filesystem operation.
1164 if( aborted )
1165 adapter->AbortAsyncLoad();
1166 else
1167 adapter->BlockUntilLoaded();
1168
1169 // If aborted, skip operations that use the adapter since the project may have changed
1170 // and the adapter's project reference could be stale. This prevents use-after-free
1171 // crashes when switching projects during library preload.
1172 if( !aborted )
1173 {
1174 // Collect and report library load errors from adapter
1175 wxString errors = adapter->GetLibraryLoadErrors();
1176
1177 wxLogTrace( traceLibraries,
1178 "pcbnew PreloadLibraries: adapter errors.IsEmpty()=%d, length=%zu",
1179 errors.IsEmpty(), errors.length() );
1180
1181 if( !errors.IsEmpty() )
1182 {
1183 std::vector<LOAD_MESSAGE> messages =
1185
1186 wxLogTrace( traceLibraries, " -> adapter: collected %zu messages",
1187 messages.size() );
1188
1189 if( !messages.empty() )
1190 Pgm().AddLibraryLoadMessages( messages );
1191 }
1192 else
1193 {
1194 wxLogTrace( traceLibraries, " -> no errors from footprint adapter" );
1195 }
1196 }
1197 else
1198 {
1199 wxLogTrace( traceLibraries, "pcbnew PreloadLibraries: aborted, skipping footprint processing" );
1200 }
1201
1202 m_libraryPreloadAbort.store( false );
1205 m_libraryPreloadInProgress.store( false );
1206
1207 // Only send reload notifications if we weren't aborted
1208 if( !aborted )
1209 {
1210 std::string payload = "";
1211 aKiway->ExpressMail( FRAME_PCB_EDITOR, MAIL_RELOAD_LIB, payload, nullptr, true );
1212 aKiway->ExpressMail( FRAME_FOOTPRINT_EDITOR, MAIL_RELOAD_LIB, payload, nullptr, true );
1213 aKiway->ExpressMail( FRAME_CVPCB, MAIL_RELOAD_LIB, payload, nullptr, true );
1214 }
1215 };
1216
1217 std::future<void> preloadFuture = std::async( std::launch::async, preload );
1218 m_libraryPreloadReturn = std::move( preloadFuture );
1219}
1220
1221
1223{
1224 if( m_libraryPreloadInProgress.load() )
1225 m_libraryPreloadAbort.store( true );
1226}
1227
1228
1229void IFACE::CancelPreload( bool aBlock )
1230{
1231 if( m_libraryPreloadInProgress.load() )
1232 {
1233 m_libraryPreloadAbort.store( true );
1234
1235 if( aBlock )
1237 }
1238}
const char * name
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
static std::list< TOOL_ACTION * > & GetActionList()
Return list of TOOL_ACTIONs.
static std::list< ACTION_TOOLBAR_CONTROL * > GetCustomControlList(FRAME_T aContext)
Get the list of custom controls that could be used on a particular frame type.
std::shared_ptr< BACKGROUND_JOB > Create(const wxString &aName)
Creates a background job with the given name.
void Remove(std::shared_ptr< BACKGROUND_JOB > job)
Removes the given background job from any lists and frees it.
static std::unique_ptr< BOARD > Load(const wxString &aFileName, PCB_IO_MGR::PCB_FILE_T aFormat, PROJECT *aProject, const OPTIONS &aOptions)
static CLI_PROGRESS_REPORTER & GetInstance()
static CLI_REPORTER & GetInstance()
Definition reporter.cpp:216
The base frame for deriving all KiCad main window classes.
SNAP_INFERENCE_SETTINGS m_SnapInference
An interface to the global shared library manager that is schematic-specific and linked to one projec...
std::vector< FOOTPRINT * > GetFootprints(const wxString &aNickname, bool aBestEfforts=false)
Retrieves a list of footprints contained in a given loaded library.
FOOTPRINT * LoadFootprintWithOptionalNickname(const LIB_ID &aFootprintId, bool aKeepUUID)
Load a footprint having aFootprintId with possibly an empty nickname.
static FOOTPRINT_PREVIEW_PANEL * New(KIWAY *aKiway, wxWindow *aParent, UNITS_PROVIDER *aUnitsProvider)
Component library viewer main window.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
An simple container class that lets us dispatch output jobs to kifaces.
Definition job.h:184
void RegisterHandler(API_HANDLER *aHandler)
Adds a new request handler to the server.
void DeregisterHandler(API_HANDLER *aHandler)
A KIFACE implementation.
Definition kiface_base.h:35
KIFACE_BASE(const char *aKifaceName, KIWAY::FACE_T aId)
Definition kiface_base.h:63
void InitSettings(APP_SETTINGS_BASE *aSettings)
Definition kiface_base.h:93
void end_common()
Common things to do for a top program module, during OnKifaceEnd();.
APP_SETTINGS_BASE * KifaceSettings() const
Definition kiface_base.h:91
bool start_common(int aCtlBits)
Common things to do for a top program module, during OnKifaceStart().
int m_start_flags
flags provided in OnKifaceStart()
bool IsSingle() const
Is this KIFACE running under single_top?
static int Apply(const git_merge_driver_source *aSrc, const char **aPathOut, unsigned int *aModeOut, git_buf *aMergedOut)
libgit2 merge-driver apply callback shim.
static int Apply(const git_merge_driver_source *aSrc, const char **aPathOut, unsigned int *aModeOut, git_buf *aMergedOut)
A mix in class which holds the location of a wxWindow's KIWAY.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:311
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition kiway.cpp:388
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr, bool aFromOtherThread=false)
Send aPayload to aDestination from aSource.
Definition kiway.cpp:486
FACE_T
Known KIFACE implementations.
Definition kiway.h:317
@ FACE_PCB
pcbnew DSO
Definition kiway.h:319
virtual void CommonSettingsChanged(int aFlags=0)
Call CommonSettingsChanged() on all KIWAY_PLAYERs.
Definition kiway.cpp:580
virtual PROJECT & Prj() const
Return the PROJECT associated with this KIWAY.
Definition kiway.cpp:201
std::optional< float > AsyncLoadProgress() const
Returns async load progress between 0.0 and 1.0, or nullopt if load is not in progress.
void AbortAsyncLoad()
Aborts any async load in progress; blocks until fully done aborting.
wxString GetLibraryLoadErrors() const
Returns all library load errors as newline-separated strings for display.
std::vector< wxString > GetLibraryNames() const
Returns a list of library nicknames that are available (skips any that failed to load)
void AsyncLoad()
Loads all available libraries for this adapter type in the background.
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition lib_id.cpp:65
MAGNETIC_SETTINGS m_MagneticItems
SNAP_INFERENCE_SETTINGS m_SnapInference
The main frame for Pcbnew.
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:52
static PCB_FILE_T FindPluginTypeFromBoardPath(const wxString &aFileName, int aCtl=0)
Return a plugin type given a path for a board file.
Container for data for KiCad programs.
Definition pgm_base.h:102
virtual BACKGROUND_JOBS_MONITOR & GetBackgroundJobMonitor() const
Definition pgm_base.h:130
void ClearLibraryLoadMessages()
Clear library load messages from all registered status bars.
void AddLibraryLoadMessages(const std::vector< LOAD_MESSAGE > &aMessages)
Add library load messages to all registered status bars.
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:124
A progress reporter interface for use in multi-threaded environments.
static FOOTPRINT_LIBRARY_ADAPTER * FootprintLibAdapter(PROJECT *aProject)
Container for project specific data.
Definition project.h:63
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:72
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Take ownership of the pointer passed in.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Load a project or sets up a new project with a specified path.
PROJECT * GetProject(const wxString &aFullPath) const
Retrieve a loaded project by name.
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
UNITS_PROVIDER(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits)
EDA_UNITS GetUserUnits() const
void SetUserUnits(EDA_UNITS aUnits)
This file is part of the common library.
#define _(s)
DDE server & client.
#define KICAD_PCB_PORT_SERVICE_NUMBER
Pcbnew listens on this port for commands from Eeschema.
Definition eda_dde.h:36
Abstract pattern-matching tool and implementations.
EDA_UNITS
Definition eda_units.h:44
@ DO_NOT_INCLUDE_NPTH
Definition footprint.h:72
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition frame_type.h:29
@ PANEL_PCB_GRIDS
Definition frame_type.h:102
@ FRAME_PCB_EDITOR
Definition frame_type.h:38
@ PANEL_3DV_TOOLBARS
Definition frame_type.h:113
@ FRAME_FOOTPRINT_VIEWER
Definition frame_type.h:41
@ PANEL_3DV_OPENGL
Definition frame_type.h:111
@ PANEL_FP_DEFAULT_GRAPHICS_VALUES
Definition frame_type.h:97
@ PANEL_PCB_TOOLBARS
Definition frame_type.h:106
@ PANEL_PCB_ORIGINS_AXES
Definition frame_type.h:108
@ FRAME_FOOTPRINT_WIZARD
Definition frame_type.h:42
@ PANEL_PCB_EDIT_OPTIONS
Definition frame_type.h:104
@ PANEL_FP_DISPLAY_OPTIONS
Definition frame_type.h:90
@ PANEL_PCB_COLORS
Definition frame_type.h:105
@ PANEL_FP_SNAPPING
Definition frame_type.h:92
@ PANEL_FP_USER_LAYER_NAMES
Definition frame_type.h:98
@ PANEL_3DV_RAYTRACING
Definition frame_type.h:112
@ DIALOG_PCB_LIBRARY_TABLE
Definition frame_type.h:133
@ FRAME_FOOTPRINT_PREVIEW
Definition frame_type.h:44
@ FRAME_FOOTPRINT_CHOOSER
Definition frame_type.h:40
@ PANEL_FP_GRIDS
Definition frame_type.h:91
@ PANEL_FP_ORIGINS_AXES
Definition frame_type.h:99
@ PANEL_PCB_DISPLAY_OPTS
Definition frame_type.h:101
@ DIALOG_CONFIGUREPATHS
Definition frame_type.h:130
@ PANEL_FP_COLORS
Definition frame_type.h:94
@ PANEL_FP_DEFAULT_FIELDS
Definition frame_type.h:96
@ FRAME_FOOTPRINT_EDITOR
Definition frame_type.h:39
@ FRAME_PCB_DISPLAY3D
Definition frame_type.h:43
@ PANEL_FP_EDIT_OPTIONS
Definition frame_type.h:93
@ PANEL_FP_TOOLBARS
Definition frame_type.h:95
@ PANEL_PCB_ACTION_PLUGINS
Definition frame_type.h:107
@ PANEL_3DV_DISPLAY_OPTIONS
Definition frame_type.h:110
@ FRAME_CVPCB
Definition frame_type.h:48
@ PANEL_PCB_SNAPPING
Definition frame_type.h:103
nlohmann::json json
Definition gerbview.cpp:50
void CopySexprFile(const wxString &aSrcPath, const wxString &aDestPath, std::function< bool(const std::string &token, wxString &value)> aCallback, wxString &aErrors)
Definition gestfich.cpp:370
void KiCopyFile(const wxString &aSrcPath, const wxString &aDestPath, wxString &aErrors)
Definition gestfich.cpp:343
static const std::string ProjectFileExtension
static const std::string LegacyPcbFileExtension
static const std::string FootprintLibraryTableFileName
static const std::string BackupFileSuffix
static const std::string LegacyFootprintLibPathExtension
static const std::string FootprintAssignmentFileExtension
static const std::string KiCadFootprintFileExtension
static const std::string KiCadPcbFileExtension
const wxChar *const traceLibraries
Flag to enable library table and library manager tracing.
const wxChar *const traceApi
Flag to enable debug output related to the IPC API and its plugin system.
Definition api_utils.cpp:29
#define KIFACE_API
@ KIFACE_MERGE_DOCUMENT
int (*)( int aKind, const wxString& aAncestor, const wxString& aOurs, const wxString& aTheirs,...
Definition kiface_ids.h:45
@ KIFACE_FOOTPRINT_LIBRARY_ADAPTER
Definition kiface_ids.h:30
@ KIFACE_FILTER_FOOTPRINTS
Function pointer type: wxString (*)(const wxString& aFilterJson) Input JSON: {"pin_count": N,...
Definition kiface_ids.h:35
@ KIFACE_OPEN_DIFF_DIALOG
int (*)( int aKind, const wxString& aFileA, const wxString& aFileB, const wxString& aLabelA,...
Definition kiface_ids.h:52
#define KFCTL_CLI
Running as CLI app.
Definition kiway.h:161
#define KIFACE_GETTER
Definition kiway.h:109
#define KICTL_KICAD_ONLY
chosen file is from KiCad according to user
This file contains miscellaneous commonly used macros and functions.
@ MAIL_RELOAD_LIB
Definition mail_type.h:54
DOC_KIND
Document type a diff/merge entry point should route to, derived from a file path's extension.
bool RegisterMergeDriver(const char *aName, MERGE_APPLY_FN aApply)
Register a KiCad merge driver with libgit2.
PCB::IFACE KIFACE_BASE, UNITS_PROVIDER kiface("pcbnew", KIWAY::FACE_PCB)
static int pcbnewOpenDiffDialogExport(int aKind, const wxString &aFileA, const wxString &aFileB, const wxString &aLabelA, const wxString &aLabelB, wxWindow *aParent, REPORTER *aReporter)
Definition pcbnew.cpp:641
static int pcbnewMergeExport(int aKind, const wxString &aAncestor, const wxString &aOurs, const wxString &aTheirs, const wxString &aOutput, bool aInteractive, bool aSingleFile, REPORTER *aReporter)
Definition pcbnew.cpp:631
void InvokePcbLibTableEditor(KIWAY *aKiway, wxWindow *aCaller)
Function InvokePcbLibTableEditor shows the modal DIALOG_FP_LIB_TABLE for purposes of editing the glob...
PANEL_SNAPPING * CreateSnappingPanel(wxWindow *aParent, SETTINGS_T *aCfg, FRAME_T aFrameType, SNAP_INFERENCE_SETTINGS SETTINGS_T::*aInference=nullptr, MAGNETIC_SETTINGS SETTINGS_T::*aMagnetics=nullptr)
Build the snapping page for an editor.
static wxString filterFootprints(const wxString &aFilterJson)
Filter footprints based on criteria passed as JSON.
Definition pcbnew.cpp:111
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
Definition pcbnew.cpp:655
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
@ RPT_SEVERITY_ERROR
T * GetToolbarSettings(const wxString &aFilename)
T * GetAppSettings(const char *aFilename)
std::vector< LOAD_MESSAGE > ExtractLibraryLoadErrors(const wxString &aErrorString, int aSeverity)
Parse library load error messages, extracting user-facing information while stripping internal code l...
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits, KIWAY *aKiway) override
Typically start_common() is called from here.
Implement a participant in the KIWAY alchemy.
Definition kiway.h:152
std::atomic_bool m_libraryPreloadInProgress
Definition pcbnew.cpp:617
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits, KIWAY *aKiway) override
Typically start_common() is called from here.
Definition pcbnew.cpp:666
void PreloadLibraries(KIWAY *aKiway) override
Definition pcbnew.cpp:1095
KIWAY * m_kiway
Definition pcbnew.cpp:622
void ProjectChanged() override
Definition pcbnew.cpp:1222
void SaveFileAs(const wxString &aProjectBasePath, const wxString &aSrcProjectName, const wxString &aNewProjectBasePath, const wxString &aNewProjectName, const wxString &aSrcFilePath, wxString &aErrors) override
Saving a file under a different name is delegated to the various KIFACEs because the project doesn't ...
Definition pcbnew.cpp:727
void CancelPreload(bool aBlock=true) override
Definition pcbnew.cpp:1229
void closeCurrentDocument(KICAD_API_SERVER *aServer)
Definition pcbnew.cpp:854
std::shared_ptr< BACKGROUND_JOB > m_libraryPreloadBackgroundJob
Definition pcbnew.cpp:615
void * IfaceOrAddress(int aDataId) override
Return a pointer to the requested object.
Definition pcbnew.cpp:534
void Reset() override
Reloads global state.
Definition pcbnew.cpp:711
std::unique_ptr< API_HANDLER_FOOTPRINT > m_openFpHandler
Definition pcbnew.cpp:626
wxWindow * CreateKiWindow(wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
Create a wxWindow for the current project.
Definition pcbnew.cpp:264
bool HandleApiOpenDocument(const wxString &aPath, KICAD_API_SERVER *aServer, wxString *aError) override
Definition pcbnew.cpp:882
bool handleOpenFootprint(const wxString &aProjectPath, const wxString &aLibIdStr, KICAD_API_SERVER *aServer, wxString *aError)
Definition pcbnew.cpp:898
IFACE(const char *aName, KIWAY::FACE_T aType)
Definition pcbnew.cpp:253
std::unique_ptr< API_HANDLER_PCB > m_openHandler
Definition pcbnew.cpp:624
std::atomic_bool m_libraryPreloadAbort
Definition pcbnew.cpp:618
bool HandleApiCloseDocument(const wxString &aBoardFileName, KICAD_API_SERVER *aServer, wxString *aError) override
Definition pcbnew.cpp:1065
int HandleJob(JOB *aJob, REPORTER *aReporter, PROGRESS_REPORTER *aProgressReporter) override
Definition pcbnew.cpp:842
std::shared_ptr< HEADLESS_FOOTPRINT_CONTEXT > m_openFpContext
Definition pcbnew.cpp:625
std::shared_ptr< HEADLESS_PCB_CONTEXT > m_openContext
Definition pcbnew.cpp:623
PCBNEW_JOBS_HANDLER * JobHandler() const
Accessor for the non-job diff/merge exports (pcbnewMergeExport etc.).
Definition pcbnew.cpp:581
std::unique_ptr< PCBNEW_JOBS_HANDLER > m_jobHandler
Definition pcbnew.cpp:614
bool HandleJobConfig(JOB *aJob, wxWindow *aParent) override
Definition pcbnew.cpp:848
bool handleOpenPcb(const wxString &aPath, KICAD_API_SERVER *aServer, wxString *aError)
Definition pcbnew.cpp:969
void OnKifaceEnd() override
Called just once just before the DSO is to be unloaded.
Definition pcbnew.cpp:716
std::future< void > m_libraryPreloadReturn
Definition pcbnew.cpp:616
IbisParser parser & reporter
KIBIS top(path, &reporter)
VECTOR3I expected(15, 30, 45)
static const long long MM
#define ENVVARS_CHANGED
wxLogTrace helper definitions.
Definition of file extensions used in Kicad.