KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcbnew/files.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) 2004-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2011 Wayne Stambaugh <[email protected]>
6 * Copyright (C) 2023 CERN (www.cern.ch)
7 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, you may find one here:
21 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22 * or you may search the http://www.gnu.org website for the version 2 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
27#include <string>
28#include <vector>
29
30#include <advanced_config.h>
31#include <confirm.h>
32#include <kidialog.h>
33#include <core/arraydim.h>
34#include <core/profile.h>
35#include <thread_pool.h>
36#include <gestfich.h>
37#include <local_history.h>
38#include <pcb_edit_frame.h>
40#include <board_loader.h>
43#include <kiface_base.h>
44#include <macros.h>
45#include <trace_helpers.h>
47#include <lockfile.h>
48#include <wx/snglinst.h>
50#include <pcbnew_id.h>
52#include <tool/tool_manager.h>
53#include <board.h>
54#include <collectors.h>
56#include <kiplatform/app.h>
57#include <kiplatform/ui.h>
59#include <widgets/wx_infobar.h>
62#include <paths.h>
63#include <pgm_base.h>
65#include <project_pcb.h>
69#include <pcb_io/pcb_io_mgr.h>
77#include <tools/pcb_actions.h>
79#include <board_commit.h>
80#include <reporter.h>
81#include <zone_filler.h>
83#include <widgets/kistatusbar.h>
85#include <wx_filename.h> // For ::ResolvePossibleSymlinks()
86#include <kiplatform/io.h>
87
88#include <wx/stdpaths.h>
89#include <wx/ffile.h>
90#include <wx/filedlg.h>
91#include <wx/txtstrm.h>
92#include <wx/wfstream.h>
93#include <wx/zipstrm.h>
94#include <wx/dir.h>
95
97
98//#define USE_INSTRUMENTATION 1
99#define USE_INSTRUMENTATION 0
100
101static const wxChar* const traceAllegroPerf = wxT( "KICAD_ALLEGRO_PERF" );
102
103
113bool AskLoadBoardFileName( PCB_EDIT_FRAME* aParent, wxString* aFileName, int aCtl = 0 )
114{
115 std::vector<IO_BASE::IO_FILE_DESC> descriptions;
116
117 for( const auto& plugin : PCB_IO_MGR::PLUGIN_REGISTRY::Instance()->AllPlugins() )
118 {
119 bool isKiCad = plugin.m_type == PCB_IO_MGR::KICAD_SEXP || plugin.m_type == PCB_IO_MGR::LEGACY;
120
121 if( ( aCtl & KICTL_KICAD_ONLY ) && !isKiCad )
122 continue;
123
124 if( ( aCtl & KICTL_NONKICAD_ONLY ) && isKiCad )
125 continue;
126
127 IO_RELEASER<PCB_IO> pi( plugin.m_createFunc() );
128 wxCHECK( pi, false );
129
130 const IO_BASE::IO_FILE_DESC& desc = pi->GetBoardFileDesc();
131
132 if( desc.m_FileExtensions.empty() || !desc.m_CanRead )
133 continue;
134
135 descriptions.emplace_back( desc );
136 }
137
138 wxString fileFiltersStr;
139 std::vector<std::string> allExtensions;
140 std::set<wxString> allWildcardsSet;
141
142 for( const IO_BASE::IO_FILE_DESC& desc : descriptions )
143 {
144 if( !fileFiltersStr.IsEmpty() )
145 fileFiltersStr += wxChar( '|' );
146
147 fileFiltersStr += desc.FileFilter();
148
149 for( const std::string& ext : desc.m_FileExtensions )
150 {
151 allExtensions.emplace_back( ext );
152 allWildcardsSet.insert( wxT( "*." ) + formatWildcardExt( ext ) + wxT( ";" ) );
153 }
154 }
155
156 wxString allWildcardsStr;
157
158 for( const wxString& wildcard : allWildcardsSet )
159 allWildcardsStr << wildcard;
160
161 if( aCtl & KICTL_KICAD_ONLY )
162 {
163 fileFiltersStr = _( "All KiCad Board Files" ) + AddFileExtListToFilter( allExtensions );
164 }
165 else
166 {
167 fileFiltersStr = _( "All supported formats" ) + wxT( "|" ) + allWildcardsStr + wxT( "|" )
168 + fileFiltersStr;
169 }
170
171 wxFileName fileName( *aFileName );
172 wxString path;
173 wxString name;
174
175 if( fileName.FileExists() )
176 {
177 path = fileName.GetPath();
178 name = fileName.GetFullName();
179 }
180 else
181 {
182 path = aParent->GetMruPath();
183
184 if( path.IsEmpty() )
186 // leave name empty
187 }
188
189 bool kicadFormat = ( aCtl & KICTL_KICAD_ONLY );
190
191 wxFileDialog dlg( aParent, kicadFormat ? _( "Open Board File" ) : _( "Import Non KiCad Board File" ),
192 path, name, fileFiltersStr, wxFD_OPEN | wxFD_FILE_MUST_EXIST );
193
194 FILEDLG_IMPORT_NON_KICAD importOptions( aParent->config()->m_System.show_import_issues );
195
196 if( !kicadFormat )
197 dlg.SetCustomizeHook( importOptions );
198
200
201 if( dlg.ShowModal() == wxID_OK )
202 {
203 *aFileName = dlg.GetPath();
204 aParent->SetMruPath( wxFileName( dlg.GetPath() ).GetPath() );
205
206 if( !kicadFormat )
207 aParent->config()->m_System.show_import_issues = importOptions.GetShowIssues();
208
209 return true;
210 }
211 else
212 {
213 return false;
214 }
215}
216
217
227bool AskSaveBoardFileName( PCB_EDIT_FRAME* aParent, wxString* aFileName, bool* aCreateProject )
228{
229 wxString wildcard = FILEEXT::PcbFileWildcard();
230 wxFileName fn = *aFileName;
231
233
234 wxFileDialog dlg( aParent, _( "Save Board File As" ), fn.GetPath(), fn.GetFullName(), wildcard,
235 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
236
237// Add a "Create a project" checkbox in standalone mode and one isn't loaded
238 FILEDLG_HOOK_SAVE_PROJECT newProjectHook;
239
240 if( Kiface().IsSingle() && aParent->Prj().IsNullProject() )
241 dlg.SetCustomizeHook( newProjectHook );
242
244
245 if( dlg.ShowModal() != wxID_OK )
246 return false;
247
248 *aFileName = dlg.GetPath();
249 *aFileName = EnsureFileExtension( *aFileName, FILEEXT::KiCadPcbFileExtension );
250
251 if( newProjectHook.IsAttachedToDialog() )
252 *aCreateProject = newProjectHook.GetCreateNewProject();
253 else if( !aParent->Prj().IsNullProject() )
254 *aCreateProject = true;
255
256 return true;
257}
258
259
260void PCB_EDIT_FRAME::OnFileHistory( wxCommandEvent& event )
261{
262 wxString filename = GetFileFromHistory( event.GetId(), _( "Printed circuit board" ) );
263
264 if( !filename.IsEmpty() )
265 {
266 if( !wxFileName::IsFileReadable( filename ) )
267 {
268 if( !AskLoadBoardFileName( this, &filename, KICTL_KICAD_ONLY ) )
269 return;
270 }
271
272 OpenProjectFiles( std::vector<wxString>( 1, filename ), KICTL_KICAD_ONLY );
273 }
274}
275
276
277void PCB_EDIT_FRAME::OnClearFileHistory( wxCommandEvent& aEvent )
278{
280}
281
282
284{
285 // Only standalone mode can directly load a new document
286 if( !Kiface().IsSingle() )
287 return false;
288
289 int open_ctl = KICTL_KICAD_ONLY;
290 wxString fileName = m_frame->Prj().AbsolutePath( m_frame->GetBoard()->GetFileName() );
291
292 if( AskLoadBoardFileName( m_frame, &fileName, open_ctl ) )
293 m_frame->OpenProjectFiles( std::vector<wxString>( 1, fileName ), open_ctl );
294
295 return 0;
296}
297
298
300{
301 // Note: we explicitly allow this even if not in standalone mode for now, even though it is dangerous.
302 int open_ctl = KICTL_NONKICAD_ONLY;
303 wxString fileName; // = Prj().AbsolutePath( GetBoard()->GetFileName() );
304
305 if( AskLoadBoardFileName( m_frame, &fileName, open_ctl ) )
306 m_frame->OpenProjectFiles( std::vector<wxString>( 1, fileName ), open_ctl );
307
308 return 0;
309}
310
311
313{
314 wxFileName fn = m_frame->Prj().AbsolutePath( m_frame->GetBoard()->GetFileName() );
315
316 if( !IsOK( m_frame, wxString::Format( _( "Revert '%s' to last version saved?" ), fn.GetFullPath() ) ) )
317 return false;
318
319 m_frame->GetScreen()->SetContentModified( false ); // do not prompt the user for changes
320
321 m_frame->ReleaseFile();
322
323 m_frame->OpenProjectFiles( std::vector<wxString>( 1, fn.GetFullPath() ), KICTL_REVERT );
324
325 return 0;
326}
327
328
330{
331 // Only standalone mode can directly load a new document
332 if( !Kiface().IsSingle() )
333 return false;
334
335 if( m_frame->IsContentModified() )
336 {
337 wxFileName fileName = m_frame->GetBoard()->GetFileName();
338 wxString saveMsg = _( "Current board will be closed, save changes to '%s' before "
339 "continuing?" );
340
341 if( !HandleUnsavedChanges( m_frame, wxString::Format( saveMsg, fileName.GetFullName() ),
342 [&]()->bool
343 {
344 return m_frame->SaveBoard();
345 } ) )
346 {
347 return false;
348 }
349 }
350 else if( !m_frame->GetBoard()->IsEmpty() )
351 {
352 if( !IsOK( m_frame, _( "Current Board will be closed. Continue?" ) ) )
353 return false;
354 }
355
356 m_frame->SaveProjectLocalSettings();
357
358 m_frame->GetBoard()->ClearProject();
359 m_frame->GetSettingsManager()->UnloadProject( &m_frame->Prj() );
360
361 if( !m_frame->Clear_Pcb( false ) )
362 return false;
363
364 m_frame->LoadProjectSettings();
365 m_frame->LoadDrawingSheet();
366
367 m_frame->OnBoardLoaded();
368 m_frame->OnModify();
369
370 return 0;
371}
372
373
374bool PCB_EDIT_FRAME::SaveBoard( bool aSaveAs, bool aSaveCopy )
375{
376 if( !aSaveAs )
377 {
378 if( !GetBoard()->GetFileName().IsEmpty() )
379 {
380 if( SavePcbFile( Prj().AbsolutePath( GetBoard()->GetFileName() ) ) )
381 {
382 m_autoSaveRequired = false;
383 return true;
384 }
385
386 return false;
387 }
388 }
389
390 wxString orig_name;
391
392 wxFileName::SplitPath( GetBoard()->GetFileName(), nullptr, nullptr, &orig_name, nullptr );
393
394 if( orig_name.IsEmpty() )
395 orig_name = NAMELESS_PROJECT;
396
397 wxFileName savePath( Prj().GetProjectFullName() );
398
399 if( !savePath.IsOk() || !savePath.IsDirWritable() )
400 {
401 savePath = GetMruPath();
402
403 if( !savePath.IsOk() || !savePath.IsDirWritable() )
405 }
406
407 wxFileName fn( savePath.GetPath(), orig_name, FILEEXT::KiCadPcbFileExtension );
408 wxString filename = fn.GetFullPath();
409 bool createProject = false;
410 bool success = false;
411
412 if( AskSaveBoardFileName( this, &filename, &createProject ) )
413 {
414 if( aSaveCopy )
415 {
416 success = SavePcbCopy( EnsureFileExtension( filename, FILEEXT::KiCadPcbFileExtension ), createProject );
417 }
418 else
419 {
420 success = SavePcbFile( filename, aSaveAs, createProject );
421
422 if( success )
423 m_autoSaveRequired = false;
424 }
425 }
426
427 return success;
428}
429
430
431int PCB_EDIT_FRAME::inferLegacyEdgeClearance( BOARD* aBoard, bool aShowUserMsg )
432{
433 PCB_LAYER_COLLECTOR collector;
434
435 collector.SetLayerId( Edge_Cuts );
436 collector.Collect( aBoard, GENERAL_COLLECTOR::AllBoardItems );
437
438 int edgeWidth = -1;
439 bool mixed = false;
440
441 for( int i = 0; i < collector.GetCount(); i++ )
442 {
443 if( collector[i]->Type() == PCB_SHAPE_T )
444 {
445 int itemWidth = static_cast<PCB_SHAPE*>( collector[i] )->GetWidth();
446
447 if( edgeWidth != -1 && edgeWidth != itemWidth )
448 {
449 mixed = true;
450 edgeWidth = std::max( edgeWidth, itemWidth );
451 }
452 else
453 {
454 edgeWidth = itemWidth;
455 }
456 }
457 }
458
459 if( mixed && aShowUserMsg )
460 {
461 // If they had different widths then we can't ensure that fills will be the same.
462 DisplayInfoMessage( this,
463 _( "If the zones on this board are refilled the Copper Edge "
464 "Clearance setting will be used (see Board Setup > Design "
465 "Rules > Constraints).\n This may result in different fills "
466 "from previous KiCad versions which used the line thicknesses "
467 "of the board boundary on the Edge Cuts layer." ) );
468 }
469
470 return std::max( 0, edgeWidth / 2 );
471}
472
473
474bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl )
475{
476 // This is for python:
477 if( aFileSet.size() != 1 )
478 {
479 DisplayError( this, wxString::Format( "Pcbnew:%s() takes a single filename", __func__ ) );
480 return false;
481 }
482
483 wxString fullFileName( aFileSet[0] );
484 wxFileName wx_filename( fullFileName );
485 Kiway().LocalHistory().Init( wx_filename.GetPath() );
486 wxString msg;
487
488 if( Kiface().IsSingle() )
490
491 // We insist on caller sending us an absolute path, if it does not, we say it's a bug.
492 wxASSERT_MSG( wx_filename.IsAbsolute(), wxT( "Path is not absolute!" ) );
493
494 std::unique_ptr<LOCKFILE> lock = std::make_unique<LOCKFILE>( fullFileName );
495
496 if( !lock->Valid() && lock->IsLockedByMe() )
497 {
498 // If we cannot acquire the lock but we appear to be the one who locked it, check to
499 // see if there is another KiCad instance running. If not, then we can override the
500 // lock. This could happen if KiCad crashed or was interrupted.
501
502 if( !Pgm().SingleInstance()->IsAnotherRunning() )
503 lock->OverrideLock();
504 }
505
506 if( !lock->Valid() )
507 {
508 // If project-level lock override was already granted, silently override this file's lock
509 if( Prj().IsLockOverrideGranted() )
510 {
511 lock->OverrideLock();
512 }
513 else
514 {
515 msg.Printf( _( "PCB '%s' is already open by '%s' at '%s'." ),
516 wx_filename.GetFullName(),
517 lock->GetUsername(),
518 lock->GetHostname() );
519
520 if( !AskOverrideLock( this, msg ) )
521 return false;
522
523 lock->OverrideLock();
524 }
525 }
526
527 if( IsContentModified() )
528 {
529 if( !HandleUnsavedChanges( this, _( "The current PCB has been modified. Save changes?" ),
530 [&]() -> bool
531 {
532 return SavePcbFile( GetBoard()->GetFileName() );
533 } ) )
534 {
535 return false;
536 }
537 }
538
539 wxFileName pro = fullFileName;
540 pro.SetExt( FILEEXT::ProjectFileExtension );
541
542 bool is_new = !wxFileName::IsFileReadable( fullFileName );
543
544 wxString previousBoardFileName = GetBoard() ? GetBoard()->GetFileName() : wxString();
545
546 // If its a non-existent PCB and caller thinks it exists
547 if( is_new && !( aCtl & KICTL_CREATE ) )
548 {
549 // notify user that fullFileName does not exist, ask if user wants to create it.
550 msg.Printf( _( "PCB '%s' does not exist. Do you wish to create it?" ), fullFileName );
551
552 if( !IsOK( this, msg ) )
553 return false;
554 }
555
556 // Get rid of any existing warnings about the old board
557 GetInfoBar()->Dismiss();
558
559 if( KISTATUSBAR* statusBar = dynamic_cast<KISTATUSBAR*>( GetStatusBar() ) )
560 statusBar->ClearWarningMessages( "load" );
561
562 WX_PROGRESS_REPORTER progressReporter( this, is_new ? _( "Create PCB" ) : _( "Load PCB" ), 1,
563 PR_CAN_ABORT );
564 WX_STRING_REPORTER loadReporter;
565 LOAD_INFO_REPORTER_SCOPE loadReporterScope( &loadReporter );
566
567 // No save prompt (we already prompted above), and only reset to a new blank board if new
568 Clear_Pcb( false, !is_new );
569
571
572 if( !is_new )
573 pluginType = PCB_IO_MGR::FindPluginTypeFromBoardPath( fullFileName, aCtl );
574
575 if( pluginType == PCB_IO_MGR::FILE_TYPE_NONE )
576 {
577 progressReporter.Hide();
578 DisplayErrorMessage( this, _( "File format is not supported" ), wxEmptyString );
579 return false;
580 }
581
582 bool converted = pluginType != PCB_IO_MGR::LEGACY && pluginType != PCB_IO_MGR::KICAD_SEXP;
583
584 // Loading a project should only be done under carefully considered circumstances.
585
586 // The calling code should know not to ask me here to change projects unless
587 // it knows what consequences that will have on other KIFACEs running and using
588 // this same PROJECT. It can be very harmful if that calling code is stupid.
590 bool setProject;
591
592 if( Kiface().IsSingle() || !( aCtl & KICTL_NONKICAD_ONLY ) )
593 setProject = pro.GetFullPath() != mgr->Prj().GetProjectFullName();
594 else
595 setProject = Prj().GetProjectFullName().IsEmpty();
596
597 if( setProject )
598 {
599 // calls SaveProject
601
603 mgr->UnloadProject( &mgr->Prj() );
604
605 mgr->LoadProject( pro.GetFullPath() );
606
607 // Do not allow saving a project if one doesn't exist. This normally happens if we are
608 // opening a board that has been moved from its project folder.
609 // For converted projects, we don't want to set the read-only flag because we want a
610 // project to be saved for the new file in case things like netclasses got migrated.
611 Prj().SetReadOnly( !pro.Exists() && !converted );
612 }
613
614 if( is_new )
615 {
616 // Link the existing blank board to the new project
617 GetBoard()->SetProject( &Prj() );
618
619 GetBoard()->SetFileName( fullFileName );
620
621 OnModify();
622 }
623 else
624 {
625 BOARD* loadedBoard = nullptr; // it will be set to non-NULL if loaded OK
626 bool failedLoad = false;
627
628 try
629 {
630 std::map<std::string, UTF8> props;
631
633 props.insert( m_importProperties->begin(), m_importProperties->end() );
634
635 // PCB_IO_EAGLE can use this info to center the BOARD, but it does not yet.
636 props["page_width"] = std::to_string( GetPageSizeIU().x );
637 props["page_height"] = std::to_string( GetPageSizeIU().y );
638
639#if USE_INSTRUMENTATION
640 // measure the time to load a BOARD.
641 int64_t startTime = GetRunningMicroSecs();
642#endif
643 BOARD_LOADER::OPTIONS loaderOptions;
644 loaderOptions.properties = &props;
645 loaderOptions.progress_reporter = &progressReporter;
646 loaderOptions.reporter = config()->m_System.show_import_issues
647 ? static_cast<REPORTER*>( &loadReporter )
648 : static_cast<REPORTER*>( &NULL_REPORTER::GetInstance() );
649 loaderOptions.initialize_after_load = false;
650 loaderOptions.plugin_configurator =
651 [&]( PCB_IO& aPlugin )
652 {
653 if( LAYER_MAPPABLE_PLUGIN* mappable_pi =
654 dynamic_cast<LAYER_MAPPABLE_PLUGIN*>( &aPlugin ) )
655 {
656 if( !ADVANCED_CFG::GetCfg().m_ImportSkipLayerMapping )
657 {
658 mappable_pi->RegisterCallback( std::bind( DIALOG_MAP_LAYERS::RunModal,
659 this,
660 std::placeholders::_1 ) );
661 }
662 }
663
664 if( PROJECT_CHOOSER_PLUGIN* chooser_pi =
665 dynamic_cast<PROJECT_CHOOSER_PLUGIN*>( &aPlugin ) )
666 {
667 chooser_pi->RegisterCallback(
669 this,
670 std::placeholders::_1 ) );
671 }
672
673 aPlugin.SetQueryUserCallback(
674 [&]( wxString aTitle, int aIcon, wxString aMessage,
675 wxString aAction ) -> bool
676 {
677 KIDIALOG dlg( nullptr, aMessage, aTitle,
678 wxOK | wxCANCEL | aIcon );
679
680 if( !aAction.IsEmpty() )
681 dlg.SetOKLabel( aAction );
682
683 dlg.DoNotShowCheckbox( aMessage, 0 );
684
685 return dlg.ShowModal() == wxID_OK;
686 } );
687 };
688
689 std::unique_ptr<BOARD> loaded =
690 BOARD_LOADER::Load( fullFileName, pluginType, &Prj(), loaderOptions );
691 loadedBoard = loaded.release();
692
693#if USE_INSTRUMENTATION
694 int64_t stopTime = GetRunningMicroSecs();
695 printf( "PCB_IO::Load(): %u usecs\n", stopTime - startTime );
696#endif
697 }
698 catch( const FUTURE_FORMAT_ERROR& ffe )
699 {
700 msg.Printf( _( "Error loading PCB '%s'." ), fullFileName );
701 progressReporter.Hide();
702 DisplayErrorMessage( this, msg, ffe.Problem() );
703
704 failedLoad = true;
705 }
706 catch( const IO_ERROR& ioe )
707 {
708 if( ioe.Problem() != wxT( "CANCEL" ) )
709 {
710 msg.Printf( _( "Error loading PCB '%s'." ), fullFileName );
711 progressReporter.Hide();
712 DisplayErrorMessage( this, msg, ioe.What() );
713 }
714
715 failedLoad = true;
716 }
717 catch( const std::bad_alloc& )
718 {
719 msg.Printf( _( "Memory exhausted loading PCB '%s'" ), fullFileName );
720 progressReporter.Hide();
721 DisplayErrorMessage( this, msg, wxEmptyString );
722
723 failedLoad = true;
724 }
725
726 if( failedLoad || !loadedBoard )
727 {
728 // We didn't create a new blank board above, so do that now
729 Clear_Pcb( false );
730
731 // Show any messages collected before the failure
732 if( KISTATUSBAR* statusBar = dynamic_cast<KISTATUSBAR*>( GetStatusBar() ) )
733 statusBar->AddWarningMessages( "load", loadReporter.GetMessages() );
734
735 return false;
736 }
737
738 if( converted && GetPcbNewSettings()->m_ImportKeepKiCadLayerNames )
739 {
740 for( PCB_LAYER_ID layer : loadedBoard->GetEnabledLayers().Seq() )
741 loadedBoard->SetLayerName( layer, wxEmptyString );
742 }
743
744 // This fixes a focus issue after the progress reporter is done on GTK. It shouldn't
745 // cause any issues on macOS and Windows. If it does, it will have to be conditionally
746 // compiled.
747 Raise();
748
749 // Skip (possibly expensive) connectivity build here; we build it below after load
750 progressReporter.AddPhases( 1 );
751 progressReporter.AdvancePhase( _( "Finalizing board" ) );
752 progressReporter.KeepRefreshing();
753
754 PROF_TIMER postLoadTimer;
755 SetBoard( loadedBoard, false, &progressReporter );
756 wxLogTrace( traceAllegroPerf, wxT( "Post-load SetBoard: %.3f ms" ),
757 postLoadTimer.msecs( true ) );
758
759 if( loadedBoard->m_LegacyDesignSettingsLoaded )
760 {
761 Prj().SetReadOnly( false );
762
763 // Before we had a copper edge clearance setting, the edge line widths could be used
764 // as a kludge to control them. So if there's no setting then infer it from the
765 // edge widths.
766 if( !loadedBoard->m_LegacyCopperEdgeClearanceLoaded )
767 {
768 // Do not show the inferred edge clearance warning dialog when loading third
769 // party boards. For some reason the dialog completely hangs all of KiCad and
770 // the imported board cannot be saved.
771 int edgeClearance = inferLegacyEdgeClearance( loadedBoard, !converted );
772 loadedBoard->GetDesignSettings().m_CopperEdgeClearance = edgeClearance;
773 }
774
775 // On save; design settings will be removed from the board
776 loadedBoard->SetModified();
777 }
778
779 // Move legacy view settings to local project settings
780 if( !loadedBoard->m_LegacyVisibleLayers.test( Rescue ) )
781 {
783 loadedBoard->SetModified();
784 }
785
787 {
789 loadedBoard->SetModified();
790 }
791
792 if( !loadedBoard->SynchronizeComponentClasses( std::unordered_set<wxString>() ) )
793 {
794 m_infoBar->RemoveAllButtons();
795 m_infoBar->AddCloseButton();
796 m_infoBar->ShowMessage( _( "Could not load component class assignment rules" ),
797 wxICON_WARNING, WX_INFOBAR::MESSAGE_TYPE::GENERIC );
798 }
799
800 // we should not ask PCB_IOs to do these items:
801 loadedBoard->BuildListOfNets();
802 wxLogTrace( traceAllegroPerf, wxT( "Post-load BuildListOfNets: %.3f ms" ),
803 postLoadTimer.msecs( true ) );
804
805 progressReporter.KeepRefreshing();
806
807 m_toolManager->RunAction( PCB_ACTIONS::repairBoard, true);
808 wxLogTrace( traceAllegroPerf, wxT( "Post-load repairBoard: %.3f ms" ),
809 postLoadTimer.msecs( true ) );
810
811 progressReporter.KeepRefreshing();
812
814 wxLogTrace( traceAllegroPerf, wxT( "Post-load rehatchShapes: %.3f ms" ),
815 postLoadTimer.msecs( true ) );
816
817 progressReporter.KeepRefreshing();
818
819 if( loadedBoard->IsModified() )
820 OnModify();
821 else
822 GetScreen()->SetContentModified( false );
823
824 if( ( pluginType == PCB_IO_MGR::LEGACY )
825 || ( pluginType == PCB_IO_MGR::KICAD_SEXP
827 && loadedBoard->GetGenerator().Lower() != wxT( "gerbview" ) ) )
828 {
829 m_infoBar->RemoveAllButtons();
830 m_infoBar->AddCloseButton();
831 m_infoBar->ShowMessage( _( "This file was created by an older version of KiCad. "
832 "It will be converted to the new format when saved." ),
833 wxICON_WARNING, WX_INFOBAR::MESSAGE_TYPE::OUTDATED_SAVE );
834 }
835
836 // TODO(JE) library tables -- I think this functionality should be deleted
837#if 0
838
839 // Import footprints into a project-specific library
840 //==================================================
841 // TODO: This should be refactored out of here into somewhere specific to the Project Import
842 // E.g. KICAD_MANAGER_FRAME::ImportNonKiCadProject
843 if( aCtl & KICTL_IMPORT_LIB )
844 {
845 wxFileName loadedBoardFn( fullFileName );
846 wxString libNickName = loadedBoardFn.GetName();
847
848 // Extract a footprint library from the design and add it to the fp-lib-table
849 // The footprints are saved in a new .pretty library.
850 // If this library already exists, all previous footprints will be deleted
851 std::vector<FOOTPRINT*> loadedFootprints = pi->GetImportedCachedLibraryFootprints();
852 wxString newLibPath = CreateNewProjectLibrary( _( "New Footprint Library" ),
853 libNickName );
854
855 // Only create the new library if CreateNewLibrary succeeded (note that this fails if
856 // the library already exists and the user aborts after seeing the warning message
857 // which prompts the user to continue with overwrite or abort)
858 if( newLibPath.Length() > 0 )
859 {
861
862 for( FOOTPRINT* footprint : loadedFootprints )
863 {
864 try
865 {
866 if( !footprint->GetFPID().GetLibItemName().empty() ) // Handle old boards.
867 {
868 footprint->SetReference( "REF**" );
869 piSexpr->FootprintSave( newLibPath, footprint );
870 delete footprint;
871 }
872 }
873 catch( const IO_ERROR& ioe )
874 {
875 wxLogError( _( "Error saving footprint %s to project specific library." )
876 + wxS( "\n%s" ),
877 footprint->GetFPID().GetUniStringLibItemName(),
878 ioe.What() );
879 }
880 }
881
882 FP_LIB_TABLE* prjlibtable = PROJECT_PCB::PcbFootprintLibs( &Prj() );
883 const wxString& project_env = PROJECT_VAR_NAME;
884 wxString rel_path, env_path;
885
886 wxASSERT_MSG( wxGetEnv( project_env, &env_path ),
887 wxT( "There is no project variable?" ) );
888
889 wxString result( newLibPath );
890
891 if( result.Replace( env_path, wxT( "$(" ) + project_env + wxT( ")" ) ) )
892 rel_path = result;
893
894 FP_LIB_TABLE_ROW* row = new FP_LIB_TABLE_ROW( libNickName, rel_path,
895 wxT( "KiCad" ), wxEmptyString );
896 prjlibtable->InsertRow( row );
897
898 wxString tblName = Prj().FootprintLibTblName();
899
900 try
901 {
902 PROJECT_PCB::PcbFootprintLibs( &Prj() )->Save( tblName );
903 }
904 catch( const IO_ERROR& ioe )
905 {
906 wxLogError( _( "Error saving project specific footprint library table." )
907 + wxS( "\n%s" ),
908 ioe.What() );
909 }
910
911 // Update footprint LIB_IDs to point to the just imported library
912 for( FOOTPRINT* footprint : GetBoard()->Footprints() )
913 {
914 LIB_ID libId = footprint->GetFPID();
915
916 if( libId.GetLibItemName().empty() )
917 continue;
918
919 libId.SetLibNickname( libNickName );
920 footprint->SetFPID( libId );
921 }
922 }
923 }
924#endif
925 }
926
927 {
928 wxString fname;
929
930 if( !previousBoardFileName.IsEmpty() && ( aCtl & KICTL_NONKICAD_ONLY ) && !setProject )
931 {
932 fname = previousBoardFileName;
933 }
934 else
935 {
936 wxFileName fn;
937
938 fn.SetPath( Prj().GetProjectPath() );
939 fn.SetName( Prj().GetProjectName() );
941
942 fname = fn.GetFullPath();
943
944 fname.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
945 }
946
947 GetBoard()->SetFileName( fname );
948 }
949
950 // Lock the file newly opened:
951 m_file_checker.reset( lock.release() );
952
953 if( !converted )
954 UpdateFileHistory( GetBoard()->GetFileName() );
955
956 std::vector<ZONE*> toFill;
957
958 // Rebuild list of nets (full ratsnest rebuild)
959 PROF_TIMER connectivityTimer;
960 GetBoard()->BuildConnectivity( &progressReporter );
961 wxLogTrace( traceAllegroPerf, wxT( "Post-load BuildConnectivity: %.3f ms" ),
962 connectivityTimer.msecs( true ) );
963
964 // Load project settings after setting up board; some of them depend on the nets list
967 wxLogTrace( traceAllegroPerf, wxT( "Post-load LoadProjectSettings+DrawingSheet: %.3f ms" ),
968 connectivityTimer.msecs( true ) );
969
970 // Resolve DRC exclusions after project settings are loaded
971 ResolveDRCExclusions( true );
972
973 // Initialise caches used by component classes
975
976 // Initialise time domain tuning caches
978 wxLogTrace( traceAllegroPerf, wxT( "Post-load DRC+ComponentClass+Tuning caches: %.3f ms" ),
979 connectivityTimer.msecs( true ) );
980
981 // Syncs the UI (appearance panel, etc) with the loaded board and project
983 wxLogTrace( traceAllegroPerf, wxT( "Post-load OnBoardLoaded: %.3f ms" ),
984 connectivityTimer.msecs( true ) );
985 wxLogTrace( traceAllegroPerf, wxT( "=== Post-load pipeline total: %.3f ms ===" ),
986 connectivityTimer.msecs() );
987
988 // Refresh the 3D view, if any
989 EDA_3D_VIEWER_FRAME* draw3DFrame = Get3DViewerFrame();
990
991 if( draw3DFrame )
992 draw3DFrame->NewDisplay();
993#if 0 && defined(DEBUG)
994 // Output the board object tree to stdout, but please run from command prompt:
995 GetBoard()->Show( 0, std::cout );
996#endif
997
998 // from EDA_APPL which was first loaded BOARD only:
999 {
1000 /* For an obscure reason the focus is lost after loading a board file
1001 * when starting up the process.
1002 * (seems due to the recreation of the layer manager after loading the file)
1003 * Give focus to main window and Drawpanel
1004 * must be done for these 2 windows (for an obscure reason ...)
1005 * Linux specific
1006 * This is more a workaround than a fix.
1007 */
1008 SetFocus();
1009 GetCanvas()->SetFocus();
1010 }
1011
1012 if( !setProject )
1013 {
1014 // If we didn't reload the project, we still need to call ProjectChanged() to ensure
1015 // frame-specific initialization happens (like registering the autosave saver).
1016 // When running under the project manager, KIWAY::ProjectChanged() was called before
1017 // this frame existed, so we need to call our own ProjectChanged() now.
1019 }
1020
1021 if( KISTATUSBAR* statusBar = dynamic_cast<KISTATUSBAR*>( GetStatusBar() ) )
1022 statusBar->AddWarningMessages( "load", loadReporter.GetMessages() );
1023
1024 return true;
1025}
1026
1027
1028bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool addToHistory,
1029 bool aChangeProject )
1030{
1031 // please, keep it simple. prompting goes elsewhere.
1032 wxFileName pcbFileName = aFileName;
1033
1034 if( pcbFileName.GetExt() == FILEEXT::LegacyPcbFileExtension )
1035 pcbFileName.SetExt( FILEEXT::KiCadPcbFileExtension );
1036
1037 // Write through symlinks, don't replace them
1039
1040 if( !IsWritable( pcbFileName ) )
1041 {
1042 wxString msg = wxString::Format( _( "Insufficient permissions to write file '%s'." ),
1043 pcbFileName.GetFullPath() );
1044
1045 DisplayError( this, msg );
1046 return false;
1047 }
1048
1049 // TODO: these will break if we ever go multi-board
1050 wxFileName projectFile( pcbFileName );
1051 wxFileName rulesFile( pcbFileName );
1052 wxString msg;
1053
1054 projectFile.SetExt( FILEEXT::ProjectFileExtension );
1055 rulesFile.SetExt( FILEEXT::DesignRulesFileExtension );
1056
1057 if( projectFile.FileExists() )
1058 {
1060 }
1061 else if( aChangeProject )
1062 {
1063 Prj().SetReadOnly( false );
1064 GetSettingsManager()->SaveProjectAs( projectFile.GetFullPath() );
1065 }
1066
1067 wxFileName currentRules( GetDesignRulesPath() );
1068
1069 if( currentRules.FileExists() && !rulesFile.FileExists() && aChangeProject )
1070 KiCopyFile( currentRules.GetFullPath(), rulesFile.GetFullPath(), msg );
1071
1072 if( !msg.IsEmpty() )
1073 {
1074 DisplayError( this, wxString::Format( _( "Error saving custom rules file '%s'." ),
1075 rulesFile.GetFullPath() ) );
1076 }
1077
1078 if( projectFile.FileExists() )
1079 {
1080 // Save various DRC parameters, such as violation severities (which may have been
1081 // edited via the DRC dialog as well as the Board Setup dialog), DRC exclusions, etc.
1083
1086 }
1087
1088 wxString upperTxt;
1089 wxString lowerTxt;
1090
1091 // On Windows, ensure the target file is writeable by clearing problematic attributes like
1092 // hidden or read-only. This can happen when files are synced via cloud services.
1093 if( pcbFileName.FileExists() )
1094 KIPLATFORM::IO::MakeWriteable( pcbFileName.GetFullPath() );
1095
1096 try
1097 {
1099
1100 pi->SaveBoard( pcbFileName.GetFullPath(), GetBoard(), nullptr );
1101 }
1102 catch( const IO_ERROR& ioe )
1103 {
1104 DisplayError( this, wxString::Format( _( "Error saving board file '%s'.\n%s" ),
1105 pcbFileName.GetFullPath(),
1106 ioe.What() ) );
1107 return false;
1108 }
1109
1110 if( !Kiface().IsSingle() )
1111 {
1112 WX_STRING_REPORTER backupReporter;
1113
1114 if( !GetSettingsManager()->TriggerBackupIfNeeded( backupReporter ) )
1115 {
1116 upperTxt = backupReporter.GetMessages();
1117 SetStatusText( upperTxt, 1 );
1118 }
1119 }
1120
1121 GetBoard()->SetFileName( pcbFileName.GetFullPath() );
1122
1123 // Update the lock in case it was a Save As
1124 LockFile( pcbFileName.GetFullPath() );
1125
1126 // Put the saved file in File History if requested
1127 if( addToHistory )
1128 UpdateFileHistory( GetBoard()->GetFileName() );
1129
1130 lowerTxt.Printf( _( "File '%s' saved." ), pcbFileName.GetFullPath() );
1131
1132 SetStatusText( lowerTxt, 0 );
1133
1134 // Get rid of the old version conversion warning, or any other dismissable warning :)
1135 if( m_infoBar->GetMessageType() == WX_INFOBAR::MESSAGE_TYPE::OUTDATED_SAVE )
1136 m_infoBar->Dismiss();
1137
1138 if( m_infoBar->IsShownOnScreen() && m_infoBar->HasCloseButton() )
1139 m_infoBar->Dismiss();
1140
1141 GetScreen()->SetContentModified( false );
1142 UpdateTitle();
1144
1145 // Capture entire project state for PCB save events.
1146 Kiway().LocalHistory().CommitFullProjectSnapshot( pcbFileName.GetPath(), wxS( "PCB Save" ) );
1147 Kiway().LocalHistory().TagSave( pcbFileName.GetPath(), wxS( "pcb" ) );
1148
1149 if( m_autoSaveTimer )
1150 m_autoSaveTimer->Stop();
1151
1152 m_autoSavePending = false;
1153 m_autoSaveRequired = false;
1154 return true;
1155}
1156
1157
1158bool PCB_EDIT_FRAME::SavePcbCopy( const wxString& aFileName, bool aCreateProject, bool aHeadless )
1159{
1160 wxFileName pcbFileName( aFileName );
1161
1162 if( !IsWritable( pcbFileName ) )
1163 {
1164 if( !aHeadless )
1165 {
1166 DisplayError( this, wxString::Format( _( "Insufficient permissions to write file '%s'." ),
1167 pcbFileName.GetFullPath() ) );
1168 }
1169 return false;
1170 }
1171
1172 // Save various DRC parameters, such as violation severities (which may have been
1173 // edited via the DRC dialog as well as the Board Setup dialog), DRC exclusions, etc.
1175
1177
1178 // On Windows, ensure the target file is writeable by clearing problematic attributes like
1179 // hidden or read-only. This can happen when files are synced via cloud services.
1180 if( pcbFileName.FileExists() )
1181 KIPLATFORM::IO::MakeWriteable( pcbFileName.GetFullPath() );
1182
1183 try
1184 {
1186
1187 wxASSERT( pcbFileName.IsAbsolute() );
1188
1189 pi->SaveBoard( pcbFileName.GetFullPath(), GetBoard(), nullptr );
1190 }
1191 catch( const IO_ERROR& ioe )
1192 {
1193 if( !aHeadless )
1194 {
1195 DisplayError( this, wxString::Format( _( "Error saving board file '%s'.\n%s" ),
1196 pcbFileName.GetFullPath(),
1197 ioe.What() ) );
1198 }
1199
1200 return false;
1201 }
1202
1203 wxFileName projectFile( pcbFileName );
1204 wxFileName rulesFile( pcbFileName );
1205 wxString msg;
1206
1207 projectFile.SetExt( FILEEXT::ProjectFileExtension );
1208 rulesFile.SetExt( FILEEXT::DesignRulesFileExtension );
1209
1210 if( aCreateProject && !projectFile.FileExists() )
1211 GetSettingsManager()->SaveProjectCopy( projectFile.GetFullPath() );
1212
1213 wxFileName currentRules( GetDesignRulesPath() );
1214
1215 if( aCreateProject && currentRules.FileExists() && !rulesFile.FileExists() )
1216 KiCopyFile( currentRules.GetFullPath(), rulesFile.GetFullPath(), msg );
1217
1218 if( !msg.IsEmpty() && !aHeadless )
1219 {
1220 DisplayError( this, wxString::Format( _( "Error saving custom rules file '%s'." ),
1221 rulesFile.GetFullPath() ) );
1222 }
1223
1224 return true;
1225}
1226
1227
1228bool PCB_EDIT_FRAME::importFile( const wxString& aFileName, int aFileType,
1229 const std::map<std::string, UTF8>* aProperties )
1230{
1231 NULLER raiiNuller( (void*&) m_importProperties );
1232
1233 m_importProperties = aProperties;
1234
1235 switch( (PCB_IO_MGR::PCB_FILE_T) aFileType )
1236 {
1238 case PCB_IO_MGR::EAGLE:
1242 return OpenProjectFiles( std::vector<wxString>( 1, aFileName ), KICTL_NONKICAD_ONLY | KICTL_IMPORT_LIB );
1243
1248 case PCB_IO_MGR::PADS:
1249 return OpenProjectFiles( std::vector<wxString>( 1, aFileName ), KICTL_NONKICAD_ONLY );
1250
1251 default:
1252 return false;
1253 }
1254}
1255
1256
1258{
1260
1261 dlg.ShowModal();
1262
1263 return 0;
1264}
1265
1266
1268{
1270
1271 if( dlg.ShowModal() != wxID_OK )
1272 return 0;
1273
1275
1277 job.m_filename = m_frame->GetBoard()->GetFileName();
1279
1280 job.m_precision = dlg.GetPrecision();
1283
1284 WX_PROGRESS_REPORTER progressReporter( m_frame, _( "Generate ODB++ Files" ), 3, PR_CAN_ABORT );
1285 WX_STRING_REPORTER reporter;
1286
1287 DIALOG_EXPORT_ODBPP::GenerateODBPPFiles( job, m_frame->GetBoard(), m_frame, &progressReporter, &reporter );
1288
1289 if( reporter.HasMessage() )
1290 DisplayError( m_frame, reporter.GetMessages() );
1291
1292 return 0;
1293}
const char * name
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
void SetContentModified(bool aModified=true)
Definition base_screen.h:59
int GenerateODBPPFiles(const TOOL_EVENT &aEvent)
int New(const TOOL_EVENT &aEvent)
int Revert(const TOOL_EVENT &aEvent)
int GenIPC2581File(const TOOL_EVENT &aEvent)
int Open(const TOOL_EVENT &aEvent)
int OpenNonKicadBoard(const TOOL_EVENT &aEvent)
static std::unique_ptr< BOARD > Load(const wxString &aFileName, PCB_IO_MGR::PCB_FILE_T aFormat, PROJECT *aProject, const OPTIONS &aOptions)
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:323
bool m_LegacyDesignSettingsLoaded
True if the legacy board design settings were loaded from a file.
Definition board.h:430
GAL_SET m_LegacyVisibleItems
Definition board.h:427
LENGTH_DELAY_CALCULATION * GetLengthCalculation() const
Returns the track length calculator.
Definition board.h:1408
void BuildListOfNets()
Definition board.h:967
void SetFileName(const wxString &aFileName)
Definition board.h:358
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:203
void SynchronizeNetsAndNetClasses(bool aResetTrackAndViaSizes)
Copy NETCLASS info to each NET, based on NET membership in a NETCLASS.
Definition board.cpp:2912
bool SetLayerName(PCB_LAYER_ID aLayer, const wxString &aLayerName)
Changes the name of the layer given by aLayer.
Definition board.cpp:763
LSET m_LegacyVisibleLayers
Visibility settings stored in board prior to 6.0, only used for loading legacy files.
Definition board.h:426
void SetProject(PROJECT *aProject, bool aReferenceOnly=false)
Link a board to a given project.
Definition board.cpp:213
const wxString & GetFileName() const
Definition board.h:360
int GetFileFormatVersionAtLoad() const
Definition board.h:450
const wxString & GetGenerator() const
Adds an item to the container.
Definition board.h:453
void ClearProject()
Definition board.cpp:254
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition board.cpp:1101
const LSET & GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition board.cpp:986
void SynchronizeProperties()
Copy the current project's text variables into the boards property cache.
Definition board.cpp:2717
COMPONENT_CLASS_MANAGER & GetComponentClassManager()
Gets the component class manager.
Definition board.h:1413
bool SynchronizeComponentClasses(const std::unordered_set< wxString > &aNewSheetPaths) const
Copy component class / component class generator information from the project settings.
Definition board.cpp:2942
bool m_LegacyCopperEdgeClearanceLoaded
Definition board.h:431
int GetCount() const
Return the number of objects in the list.
Definition collector.h:83
void RebuildRequiredCaches(FOOTPRINT *aFootprint=nullptr) const
Rebuilds any caches that may be required by custom assignment rules.
static void GenerateODBPPFiles(const JOB_EXPORT_PCB_ODB &aJob, BOARD *aBoard, PCB_EDIT_FRAME *aParentFrame=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr, REPORTER *aErrorReporter=nullptr)
wxString GetOutputPath() const
wxString GetUnitsString() const
static std::vector< IMPORT_PROJECT_DESC > RunModal(wxWindow *aParent, const std::vector< IMPORT_PROJECT_DESC > &aProjectDesc)
Create and show a dialog (modal) and returns the data from it after completion.
static std::map< wxString, PCB_LAYER_ID > RunModal(wxWindow *aParent, const std::vector< INPUT_LAYER_DESC > &aLayerDesc)
Create and show a dialog (modal) and returns the data from it after completion.
int ShowModal() override
Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard.
void NewDisplay(bool aForceImmediateRedraw=false)
Reload and refresh (rebuild) the 3D scene.
virtual APP_SETTINGS_BASE * config() const
Return the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
SETTINGS_MANAGER * GetSettingsManager() const
WX_INFOBAR * m_infoBar
wxTimer * m_autoSaveTimer
void UpdateFileHistory(const wxString &FullFileName, FILE_HISTORY *aFileHistory=nullptr)
Update the list of recently opened files.
wxString GetMruPath() const
bool IsWritable(const wxFileName &aFileName, bool aVerbose=true)
Check if aFileName can be written.
virtual void ClearFileHistory()
Remove all files from the file history.
wxString GetFileFromHistory(int cmdId, const wxString &type, FILE_HISTORY *aFileHistory=nullptr)
Fetch the file name from the file history list.
void SetMruPath(const wxString &aPath)
WX_INFOBAR * GetInfoBar()
std::unique_ptr< LOCKFILE > m_file_checker
bool LockFile(const wxString &aFileName)
Mark a schematic file as being in use.
void SetFocus() override
void SetModified()
Definition eda_item.cpp:110
bool IsModified() const
Definition eda_item.h:125
bool GetCreateNewProject() const
Gets the selected state of the copy subsheets option.
static const std::vector< KICAD_T > AllBoardItems
A scan list for all editable board items.
Definition collectors.h:41
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()
virtual const wxString Problem() const
what was the problem?
ODB_COMPRESSION m_compressionMode
void SetConfiguredOutputPath(const wxString &aPath)
Sets the configured output path for the job, this path is always saved to file.
Definition job.cpp:157
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition kidialog.h:42
void DoNotShowCheckbox(wxString file, int line)
Shows the 'do not show again' checkbox.
Definition kidialog.cpp:55
int ShowModal() override
Definition kidialog.cpp:93
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
LOCAL_HISTORY & LocalHistory()
Return the LOCAL_HISTORY associated with this KIWAY.
Definition kiway.h:426
Plugin class for import plugins that support remappable layers.
void SynchronizeTuningProfileProperties() const
Ensure time domain properties provider is synced with board / project settings if required.
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:49
int SetLibNickname(const UTF8 &aLibNickname)
Override the logical library name portion of the LIB_ID to aLibNickname.
Definition lib_id.cpp:100
const UTF8 & GetLibItemName() const
Definition lib_id.h:102
bool TagSave(const wxString &aProjectPath, const wxString &aFileType)
Tag a manual save in the local history repository.
bool Init(const wxString &aProjectPath)
Initialize the local history repository for the given project path.
bool CommitFullProjectSnapshot(const wxString &aProjectPath, const wxString &aTitle)
Commit a snapshot of the entire project directory (excluding the .history directory and ignored trans...
LSEQ Seq(const LSEQ &aSequence) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition lset.cpp:313
Definition raii.h:38
static REPORTER & GetInstance()
Definition reporter.cpp:124
static wxString GetDefaultUserProjectsPath()
Gets the default path we point users to create projects.
Definition paths.cpp:137
static TOOL_ACTION repairBoard
static TOOL_ACTION rehatchShapes
wxString GetDesignRulesPath()
Return the absolute path to the design rules file for the currently-loaded board.
wxString CreateNewProjectLibrary(const wxString &aDialogTitle, const wxString &aLibName)
const VECTOR2I GetPageSizeIU() const override
Works off of GetPageSettings() to return the size of the paper page in the internal units of this par...
PCBNEW_SETTINGS * GetPcbNewSettings() const
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
BOARD * GetBoard() const
EDA_3D_VIEWER_FRAME * Get3DViewerFrame()
virtual void UpdateStatusBar() override
Update the status bar information.
The main frame for Pcbnew.
void LoadDrawingSheet()
Load the drawing sheet file.
void ResolveDRCExclusions(bool aCreateMarkers)
If aCreateMarkers then create DRC exclusion markers from the serialized data.
void SetBoard(BOARD *aBoard, PROGRESS_REPORTER *aReporter=nullptr) override
Set the #m_Pcb member in such as way as to ensure deleting any previous BOARD.
void OnModify() override
Must be called after a board change to set the modified flag.
void OnClearFileHistory(wxCommandEvent &aEvent)
bool SaveBoard(bool aSaveAs=false, bool aSaveCopy=false)
bool OpenProjectFiles(const std::vector< wxString > &aFileSet, int aCtl=0) override
Load a KiCad board (.kicad_pcb) from aFileName.
void ProjectChanged() override
Notification event that the project has changed.
void SaveProjectLocalSettings() override
Save changes to the project local settings.
bool SavePcbCopy(const wxString &aFileName, bool aCreateProject=false, bool aHeadless=false)
Write the board data structures to aFileName.
bool IsContentModified() const override
Get if the current board has been modified but not saved.
bool LoadProjectSettings()
Load the current project's file configuration settings which are pertinent to this PCB_EDIT_FRAME ins...
bool Clear_Pcb(bool doAskAboutUnsavedChanges, bool aFinal=false)
Delete all and reinitialize the current board.
Definition initpcb.cpp:42
void OnBoardLoaded()
Update the state of the GUI after a new board is loaded or created.
void UpdateTitle()
Set the main window title bar text.
int inferLegacyEdgeClearance(BOARD *aBoard, bool aShowUserMsg=true)
const std::map< std::string, UTF8 > * m_importProperties
bool SavePcbFile(const wxString &aFileName, bool addToHistory=true, bool aChangeProject=true)
Write the board data structures to a aFileName.
bool importFile(const wxString &aFileName, int aFileType, const std::map< std::string, UTF8 > *aProperties=nullptr)
Load the given filename but sets the path to the current project path.
void saveProjectSettings() override
Save any design-related project settings associated with this frame.
void OnFileHistory(wxCommandEvent &event)
static PLUGIN_REGISTRY * Instance()
Definition pcb_io_mgr.h:98
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
@ GEDA_PCB
Geda PCB file formats.
Definition pcb_io_mgr.h:69
@ ALTIUM_DESIGNER
Definition pcb_io_mgr.h:63
@ LEGACY
Legacy Pcbnew file formats prior to s-expression.
Definition pcb_io_mgr.h:59
@ ALTIUM_CIRCUIT_MAKER
Definition pcb_io_mgr.h:61
@ ALTIUM_CIRCUIT_STUDIO
Definition pcb_io_mgr.h:62
@ CADSTAR_PCB_ARCHIVE
Definition pcb_io_mgr.h:64
static PCB_IO * FindPlugin(PCB_FILE_T aFileType)
Return a #PLUGIN which the caller can use to import, export, save, or load design documents.
static PCB_FILE_T FindPluginTypeFromBoardPath(const wxString &aFileName, int aCtl=0)
Return a plugin type given a path for a board file.
A base class that BOARD loading and saving plugins should derive from.
Definition pcb_io.h:79
Collect all BOARD_ITEM objects on a given layer.
Definition collectors.h:549
void Collect(BOARD_ITEM *aBoard, const std::vector< KICAD_T > &aTypes)
Test a BOARD_ITEM using this class's Inspector method, which does the collection.
void SetLayerId(PCB_LAYER_ID aLayerId)
Definition collectors.h:555
A small class to help profiling.
Definition profile.h:49
double msecs(bool aSinceLast=false)
Definition profile.h:149
virtual void AdvancePhase() override
Use the next available virtual zone of the dialog progress bar.
void AddPhases(int aNumPhases) override
bool KeepRefreshing(bool aWait=false) override
Update the UI dialog.
Plugin class for import plugins that support choosing a project.
LSET m_VisibleLayers
Board settings.
GAL_SET m_VisibleItems
The GAL layers (aka items) that are turned on for viewing (.
virtual void SetReadOnly(bool aReadOnly=true)
Definition project.h:164
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
Definition project.cpp:181
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
Definition project.h:210
virtual const wxString FootprintLibTblName() const
Returns the path and filename of this project's footprint library table.
Definition project.cpp:217
virtual bool IsNullProject() const
Check if this project is a null project (i.e.
Definition project.cpp:205
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:75
virtual bool HasMessage() const
Returns true if any messages were reported.
Definition reporter.h:136
void SaveProjectAs(const wxString &aFullPath, PROJECT *aProject=nullptr)
Set the currently loaded project path and saves it (pointers remain valid).
void SaveProjectCopy(const wxString &aFullPath, PROJECT *aProject=nullptr)
Save a copy of the current project under the given path.
bool SaveProject(const wxString &aFullPath=wxEmptyString, PROJECT *aProject=nullptr)
Save a loaded project.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Load a project or sets up a new project with a specified path.
bool UnloadProject(PROJECT *aProject, bool aSave=true)
Save, unload and unregister the given PROJECT.
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
TOOL_MANAGER * m_toolManager
Generic, UI-independent tool event.
Definition tool_event.h:171
bool empty() const
Definition utf8.h:109
static void ResolvePossibleSymlinks(wxFileName &aFilename)
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
Multi-thread safe progress reporter dialog, intended for use of tasks that parallel reporting back of...
A wrapper for reporting to a wxString object.
Definition reporter.h:193
const wxString & GetMessages() const
Definition reporter.cpp:105
wxString EnsureFileExtension(const wxString &aFilename, const wxString &aExtension)
It's annoying to throw up nag dialogs when the extension isn't right.
Definition common.cpp:778
bool AskOverrideLock(wxWindow *aParent, const wxString &aMessage)
Display a dialog indicating the file is already open, with an option to reset the lock.
Definition confirm.cpp:42
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition confirm.cpp:278
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition confirm.cpp:249
bool HandleUnsavedChanges(wxWindow *aParent, const wxString &aMessage, const std::function< bool()> &aSaveFunction)
Display a dialog with Save, Cancel and Discard Changes buttons.
Definition confirm.cpp:150
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:221
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition confirm.cpp:196
This file is part of the common library.
#define _(s)
Declaration of the eda_3d_viewer class.
void KiCopyFile(const wxString &aSrcPath, const wxString &aDestPath, wxString &aErrors)
Definition gestfich.cpp:294
#define WIN_STRING_DIR_SEP
Definition gestfich.h:38
#define UNIX_STRING_DIR_SEP
Definition gestfich.h:37
static const std::string ProjectFileExtension
static const std::string LegacyPcbFileExtension
static const std::string DesignRulesFileExtension
static const std::string KiCadPcbFileExtension
static wxString PcbFileWildcard()
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
Definition io_mgr.h:33
PROJECT & Prj()
Definition kicad.cpp:644
#define KICTL_CREATE
caller thinks requested project files may not exist.
#define KICTL_REVERT
reverting to a previously-saved (KiCad) file.
#define KICTL_IMPORT_LIB
import all footprints into a project library.
#define KICTL_KICAD_ONLY
chosen file is from KiCad according to user
#define KICTL_NONKICAD_ONLY
chosen file is non-KiCad according to user
@ 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:287
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
@ Edge_Cuts
Definition layer_ids.h:112
@ 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:366
File locking utilities.
This file contains miscellaneous commonly used macros and functions.
bool RegisterApplicationRestart(const wxString &aCommandLine)
Registers the application for restart with the OS with the given command line string to pass as args.
Definition unix/app.cpp:77
bool MakeWriteable(const wxString &aFilePath)
Ensures that a file has write permissions.
Definition unix/io.cpp:78
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:435
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
bool AskLoadBoardFileName(PCB_EDIT_FRAME *aParent, wxString *aFileName, int aCtl=0)
Show a wxFileDialog asking for a BOARD filename to open.
bool AskSaveBoardFileName(PCB_EDIT_FRAME *aParent, wxString *aFileName, bool *aCreateProject)
Put up a wxFileDialog asking for a BOARD filename to save.
static const wxChar *const traceAllegroPerf
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
int64_t GetRunningMicroSecs()
An alternate way to calculate an elapsed time (in microsecondes) to class PROF_COUNTER.
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition project.h:41
#define NAMELESS_PROJECT
default name for nameless projects
Definition project.h:44
KIWAY Kiway(KFCTL_STANDALONE)
bool show_import_issues
Stored value for "show import issues" when importing non-KiCad designs to this application.
std::function< void(PCB_IO &)> plugin_configurator
const std::map< std::string, UTF8 > * properties
PROGRESS_REPORTER * progress_reporter
Variant of PARSE_ERROR indicating that a syntax or related error was likely caused by a file generate...
Container that describes file type info.
Definition io_base.h:43
std::vector< std::string > m_FileExtensions
Filter used for file pickers if m_IsFile is true.
Definition io_base.h:47
bool m_CanRead
Whether the IO can read this file type.
Definition io_base.h:52
std::string path
wxString result
Test unit parsing edge cases and error handling.
wxLogTrace helper definitions.
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:85
wxString AddFileExtListToFilter(const std::vector< std::string > &aExts)
Build the wildcard extension file dialog wildcard filter to add to the base message dialog.
wxString formatWildcardExt(const wxString &aWildcard)
Format wildcard extension to support case sensitive file dialogs.
Definition of file extensions used in Kicad.
#define PR_CAN_ABORT