KiCad PCB EDA Suite
Loading...
Searching...
No Matches
kicad_manager_frame.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) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2013 CERN (www.cern.ch)
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, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include "kicad_id.h"
27#include "pcm.h"
28#include "pgm_kicad.h"
29#include "project_tree_pane.h"
30#include "local_history_pane.h"
32
33#include <advanced_config.h>
35#include <bitmaps.h>
36#include <build_version.h>
37#include <confirm.h>
41#include <local_history.h>
42#include <wx/msgdlg.h>
43#include <eda_base_frame.h>
44#include <executable_names.h>
45#include <file_history.h>
46#include <local_history.h>
47#include <policy_keys.h>
48#include <gestfich.h>
49#include <kiplatform/app.h>
51#include <kiplatform/ui.h>
52#include <kiplatform/policy.h>
53#include <build_version.h>
54#include <kiway.h>
55#include <kiway_mail.h>
56#include <launch_ext.h>
57#include <lockfile.h>
59#include <reporter.h>
61#include <sch_file_versions.h>
64#include <tool/action_manager.h>
65#include <tool/action_toolbar.h>
66#include <tool/common_control.h>
68#include <tool/tool_manager.h>
74#include <widgets/kistatusbar.h>
75#include <wx/ffile.h>
76#include <wx/filedlg.h>
77#include <wx/dnd.h>
78#include <wx/process.h>
79#include <wx/snglinst.h>
80#include <atomic>
81#include <update_manager.h>
82#include <jobs/jobset.h>
84
85#include <../pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr.h> // for SEXPR_BOARD_FILE_VERSION def
86
87
88#ifdef __WXMAC__
89#include <MacTypes.h>
90#include <ApplicationServices/ApplicationServices.h>
91#endif
92
93#include "kicad_manager_frame.h"
95
97
98
99#define EDITORS_CAPTION _( "Editors" )
100#define PROJECT_FILES_CAPTION _( "Project Files" )
101
102#define ID_INIT_WATCHED_PATHS 52913
103
104#define SEP() wxFileName::GetPathSeparator()
105
106
107// Menubar and toolbar event table
108BEGIN_EVENT_TABLE( KICAD_MANAGER_FRAME, EDA_BASE_FRAME )
109 // Window events
112
113 // Menu events
114 EVT_MENU( wxID_EXIT, KICAD_MANAGER_FRAME::OnExit )
124
125 // Range menu events
128
129 // Special functions
131
132 // Drop files event
133 EVT_DROP_FILES( KICAD_MANAGER_FRAME::OnDropFiles )
134
135END_EVENT_TABLE()
136
137// See below the purpose of this include
138#include <wx/xml/xml.h>
139
140KICAD_MANAGER_FRAME::KICAD_MANAGER_FRAME( wxWindow* parent, const wxString& title,
141 const wxPoint& pos, const wxSize& size ) :
144 m_openSavedWindows( false ),
145 m_restoredFromHistory( false ),
146 m_active_project( false ),
147 m_showHistoryPanel( false ),
148 m_projectTreePane( nullptr ),
149 m_historyPane( nullptr ),
150 m_launcher( nullptr ),
152 m_pcmButton( nullptr ),
154{
155 const int defaultLeftWinWidth = FromDIP( 250 );
156
157 m_leftWinWidth = defaultLeftWinWidth; // Default value
158 m_aboutTitle = "KiCad";
159
160 // JPC: A very ugly hack to fix an issue on Linux: if the wxbase315u_xml_gcc_custom.so is
161 // used **only** in PCM, it is not found in some cases at run time.
162 // So just use it in the main module to avoid a not found issue
163 // wxbase315u_xml_gcc_custom shared object when launching Kicad
164 wxXmlDocument dummy;
165
166 // Create the status line (bottom of the frame). Left half is for project name; right half
167 // is for Reporter (currently used by archiver/unarchiver and PCM).
168 // Note: this is a KISTATUSBAR status bar. Therefore the specified number of fields
169 // is the extra number of fields, not the full field count.
170 // We need here 2 fields: the extra fiels to display the project name, and another field
171 // to display a info (specific to Windows) using the FIELD_OFFSET_BGJOB_TEXT id offset (=1)
172 // So the extra field count is 1
173 CreateStatusBar( 2 );
176 Pgm().RegisterLibraryLoadStatusBar( (KISTATUSBAR*) GetStatusBar() );
177 GetStatusBar()->SetFont( KIUI::GetStatusFont( this ) );
178
179 // Give an icon
180 wxIcon icon;
181 wxIconBundle icon_bundle;
182
183 if( IsNightlyVersion())
184 {
185 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_nightly, 48 ) );
186 icon_bundle.AddIcon( icon );
187 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_nightly, 128 ) );
188 icon_bundle.AddIcon( icon );
189 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_nightly, 256 ) );
190 icon_bundle.AddIcon( icon );
191 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_nightly_32 ) );
192 icon_bundle.AddIcon( icon );
193 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_nightly_16 ) );
194 icon_bundle.AddIcon( icon );
195 }
196 else
197 {
198 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad, 48 ) );
199 icon_bundle.AddIcon( icon );
200 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad, 128 ) );
201 icon_bundle.AddIcon( icon );
202 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad, 256 ) );
203 icon_bundle.AddIcon( icon );
204 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_32 ) );
205 icon_bundle.AddIcon( icon );
206 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_16 ) );
207 icon_bundle.AddIcon( icon );
208 }
209
210 SetIcons( icon_bundle );
211
212 // Load the settings
213 LoadSettings( config() );
214
215 // Left window: is the box which display tree project
217
218 setupTools();
220
225
226 m_auimgr.SetManagedWindow( this );
227 m_auimgr.SetFlags( wxAUI_MGR_LIVE_RESIZE );
228
229 m_auimgr.AddPane( m_tbLeft, EDA_PANE().VToolbar().Name( "TopMainToolbar" ).Left().Layer( 2 ) );
230
231 // There is no wxAUIPaneInfo::SetSize(), but a trick is to use MinSize() to set the required pane width,
232 // and after give a reasonable MinSize value.
234 EDA_PANE().Palette().Name( "ProjectTree" ).Left().Layer( 1 )
235 .Caption( PROJECT_FILES_CAPTION ).PaneBorder( false )
236 .MinSize( m_leftWinWidth, -1 ).Floatable( false ).Movable( false ) );
237
238 m_historyPane = new LOCAL_HISTORY_PANE( this );
239 m_auimgr.AddPane( m_historyPane,
240 EDA_PANE().Palette().Name( "LocalHistory" ).Left().Layer( 1 ).Position( 1 )
241 .Caption( _( "Local History" ) ).PaneBorder( false )
242 .Floatable( false ).Movable( false ).CloseButton( true ).Hide() );
243
245 m_auimgr.GetPane( m_historyPane ).Show();
246
247 wxSize client_size = GetClientSize();
248 m_notebook = new wxAuiNotebook( this, wxID_ANY, wxPoint( client_size.x, client_size.y ),
249 FromDIP( wxSize( 700, 590 ) ),
250 wxAUI_NB_TOP | wxAUI_NB_CLOSE_ON_ALL_TABS | wxAUI_NB_TAB_MOVE
251 | wxAUI_NB_SCROLL_BUTTONS | wxNO_BORDER );
252
253 m_notebook->SetArtProvider( new WX_AUI_TAB_ART() );
254
255 m_notebook->Bind( wxEVT_AUINOTEBOOK_PAGE_CLOSE, &KICAD_MANAGER_FRAME::onNotebookPageCloseRequest, this );
256 m_notebook->Bind( wxEVT_AUINOTEBOOK_PAGE_CLOSED, &KICAD_MANAGER_FRAME::onNotebookPageCountChanged, this );
258
259 m_notebook->Freeze();
260 m_launcher->SetClosable( false );
261 m_notebook->AddPage( m_launcher, EDITORS_CAPTION, false );
262 m_notebook->SetTabCtrlHeight( 0 );
263 m_notebook->Thaw();
264
265 m_auimgr.AddPane( m_notebook, EDA_PANE().Canvas().Name( "Editors" ).Center().Caption( EDITORS_CAPTION )
266 .PaneBorder( false ).MinSize( m_notebook->GetBestSize() ) );
267
268 m_auimgr.Update();
269
270 // Now the actual m_projectTreePane size is set, give it a reasonable min width
271 m_auimgr.GetPane( m_projectTreePane ).MinSize( defaultLeftWinWidth, FromDIP( 80 ) );
272
273
274 wxSizer* mainSizer = GetSizer();
275
276 // Only fit the initial window size the first time KiCad is run.
277 if( mainSizer && config()->m_Window.state.size_x == 0 && config()->m_Window.state.size_y == 0 )
278 {
279 Layout();
280 mainSizer->Fit( this );
281 Center();
282 }
283
284 if( ADVANCED_CFG::GetCfg().m_HideVersionFromTitle )
285 SetTitle( wxT( "KiCad" ) );
286 else
287 SetTitle( wxString( "KiCad " ) + GetMajorMinorVersion() );
288
289 // Do not let the messages window have initial focus
290 m_projectTreePane->SetFocus();
291
292 // Init for dropping files
295
296 // Gerber files
297 // Note that all gerber files are aliased as GerberFileExtension
301
302 DragAcceptFiles( true );
303}
304
305
307{
309 Unbind( wxEVT_CHAR_HOOK, &TOOL_DISPATCHER::DispatchWxEvent, m_toolDispatcher );
310
311 m_notebook->Unbind( wxEVT_AUINOTEBOOK_PAGE_CLOSE, &KICAD_MANAGER_FRAME::onNotebookPageCloseRequest, this );
312 m_notebook->Unbind( wxEVT_AUINOTEBOOK_PAGE_CLOSED, &KICAD_MANAGER_FRAME::onNotebookPageCountChanged, this );
313
316 Pgm().UnregisterLibraryLoadStatusBar( (KISTATUSBAR*) GetStatusBar() );
317
318 // Shutdown all running tools
319 if( m_toolManager )
320 m_toolManager->ShutdownAllTools();
321
322 if( m_pcm )
323 m_pcm->StopBackgroundUpdate();
324
325 // Stop update manager before tearing down the AUI framework. The update
326 // task runs on the thread pool and may call CallAfter on this frame, so it
327 // must complete before we uninitialize AUI or destroy child windows.
328 m_updateManager.reset();
329
330 delete m_actions;
331 delete m_toolManager;
332 delete m_toolDispatcher;
333
334 m_auimgr.UnInit();
335}
336
338{
339 if( m_notebook->GetPageCount() == 1 )
340 m_notebook->SetTabCtrlHeight( 0 );
341 else
342 m_notebook->SetTabCtrlHeight( -1 );
343}
344
345
347{
349}
350
351
353{
354 wxAuiNotebook* notebook = (wxAuiNotebook*) evt.GetEventObject();
355 wxWindow* page = notebook->GetPage( evt.GetSelection() );
356
357 if( PANEL_NOTEBOOK_BASE* panel = dynamic_cast<PANEL_NOTEBOOK_BASE*>( page ) )
358 {
359 if( panel->GetClosable() )
360 {
361 if( !panel->GetCanClose() )
362 evt.Veto();
363
364 CallAfter(
365 [this]()
366 {
368 } );
369 }
370 else
371 {
372 evt.Veto();
373 }
374 }
375}
376
377
378wxStatusBar* KICAD_MANAGER_FRAME::OnCreateStatusBar( int number, long style, wxWindowID id,
379 const wxString& name )
380{
381 return new KISTATUSBAR( number, this, id,
385}
386
387
389{
390 // creates the PLUGIN_CONTENT_MANAGER, if not exists
391 if( m_pcm )
392 return;
393
394 m_pcm = std::make_shared<PLUGIN_CONTENT_MANAGER>(
395 [this]( int aUpdateCount )
396 {
397 if( Pgm().m_Quitting )
398 return;
399
400 m_pcmUpdateCount = aUpdateCount;
401
402 if( aUpdateCount > 0 )
403 {
405 wxS( "pcm" ),
406 _( "PCM Updates Available" ),
407 wxString::Format( _( "%d package update(s) available" ), aUpdateCount ),
408 wxT( "" ) );
409 }
410 else
411 {
412 Pgm().GetNotificationsManager().Remove( wxS( "pcm" ) );
413 }
414
415 CallAfter(
416 [this]()
417 {
419 } );
420 });
421
422 m_pcm->SetRepositoryList( kicadSettings()->m_PcmRepositories );
423}
424
425
427{
428 // Create the manager
430 m_toolManager->SetEnvironment( nullptr, nullptr, nullptr, config(), this );
432
434
435 // Attach the events to the tool dispatcher
437 Bind( wxEVT_CHAR_HOOK, &TOOL_DISPATCHER::DispatchWxEvent, m_toolDispatcher );
438
439 // Register tools
440 m_toolManager->RegisterTool( new COMMON_CONTROL );
441 m_toolManager->RegisterTool( new KICAD_MANAGER_CONTROL );
442 m_toolManager->InitTools();
443}
444
445
447{
449
450 ACTION_MANAGER* manager = m_toolManager->GetActionManager();
451
452 wxASSERT( manager );
453
454 auto activeProject =
455 [this] ( const SELECTION& )
456 {
457 return m_active_project;
458 };
459
460#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
461
462 ACTION_CONDITIONS activeProjectCond;
463 activeProjectCond.Enable( activeProject );
464
465 manager->SetConditions( ACTIONS::saveAs, activeProjectCond );
466 manager->SetConditions( KICAD_MANAGER_ACTIONS::closeProject, activeProjectCond );
467 manager->SetConditions( KICAD_MANAGER_ACTIONS::archiveProject, activeProjectCond );
468 manager->SetConditions( KICAD_MANAGER_ACTIONS::newJobsetFile, activeProjectCond );
469 manager->SetConditions( KICAD_MANAGER_ACTIONS::openJobsetFile, activeProjectCond );
470
471 auto historyCond =
472 [this]( const SELECTION& )
473 {
474 return HistoryPanelShown();
475 };
476
478
479 // These are just here for text boxes, search boxes, etc. in places such as the standard
480 // file dialogs.
484
485#undef ENABLE
486}
487
488
490{
491 return m_projectTreePane;
492}
493
494
496{
498 wxASSERT( ret );
499 return ret;
500}
501
502
504{
505 KICAD_SETTINGS* ret = dynamic_cast<KICAD_SETTINGS*>( config() );
506 wxASSERT( ret );
507 return ret;
508}
509
510
512{
513 CallAfter(
514 [&]()
515 {
516 KIFACE *schface = Kiway().KiFACE( KIWAY::FACE_SCH );
517 schface->PreloadLibraries( &Kiway() );
518
519 KIFACE *pcbface = Kiway().KiFACE( KIWAY::FACE_PCB );
520 pcbface->PreloadLibraries( &Kiway() );
521
523 } );
524}
525
526
528{
529 return GetProjectFileName();
530}
531
532
534{
536 : wxString( wxEmptyString );
537}
538
539
541{
542 wxFileName fn( GetProjectFileName() );
543
545 return fn.GetFullPath();
546}
547
548
550{
551 wxFileName fn( GetProjectFileName() );
552
554 return fn.GetFullPath();
555}
556
557
559{
560 wxFileName fn( GetProjectFileName() );
561
562 fn.SetExt( FILEEXT::PcbFileExtension );
563 return fn.GetFullPath();
564}
565
566
568{
569 wxFileName fn( GetProjectFileName() );
570
572 return fn.GetFullPath();
573}
574
575
577{
578 m_projectTreePane->ReCreateTreePrj();
579}
580
581
586
587
589{
590 return PgmTop().GetHelpFileName();
591}
592
593
594void KICAD_MANAGER_FRAME::OnSize( wxSizeEvent& event )
595{
596 if( m_auimgr.GetManagedWindow() )
597 m_auimgr.Update();
598
599 PrintPrjInfo();
600
601#if defined( _WIN32 )
602 KISTATUSBAR* statusBar = static_cast<KISTATUSBAR*>( GetStatusBar() );
604#endif
605
606 event.Skip();
607}
608
609
611{
612 // All fileNames are now in m_AcceptedFiles vector.
613 // Check if contains a project file name and load project.
614 // If not, open files in dedicated app.
615 for( const wxFileName& fileName : m_AcceptedFiles )
616 {
617 wxString ext = fileName.GetExt();
618
620 {
621 wxString fn = fileName.GetFullPath();
622 m_toolManager->RunAction<wxString*>( *m_acceptedExts.at( fileName.GetExt() ), &fn );
623
624 return;
625 }
626 }
627
628 // Then stock gerber files in gerberFiles and run action for other files.
629 wxString gerberFiles;
630
631 // Gerbview editor should be able to open Gerber and drill files
632 for( const wxFileName& fileName : m_AcceptedFiles )
633 {
634 wxString ext = fileName.GetExt();
635
639 {
640 gerberFiles += wxT( '\"' );
641 gerberFiles += fileName.GetFullPath() + wxT( '\"' );
642 gerberFiles = gerberFiles.Pad( 1 );
643 }
644 else
645 {
646 wxString fn = fileName.GetFullPath();
647 m_toolManager->RunAction<wxString*>( *m_acceptedExts.at( fileName.GetExt() ), &fn );
648 }
649 }
650
651 // Execute Gerbviewer
652 if( !gerberFiles.IsEmpty() )
653 {
654 wxString fullEditorName = FindKicadFile( GERBVIEW_EXE );
655
656 if( wxFileExists( fullEditorName ) )
657 {
658 wxString command = fullEditorName + " " + gerberFiles;
659 m_toolManager->RunAction<wxString*>( *m_acceptedExts.at( FILEEXT::GerberFileExtension ), &command );
660 }
661 }
662}
663
664
665bool KICAD_MANAGER_FRAME::canCloseWindow( wxCloseEvent& aEvent )
666{
667 KICAD_SETTINGS* settings = kicadSettings();
669
670 for( size_t i = 0; i < m_notebook->GetPageCount(); i++ )
671 {
672 wxWindow* page = m_notebook->GetPage( i );
673
674 if( PANEL_NOTEBOOK_BASE* panel = dynamic_cast<PANEL_NOTEBOOK_BASE*>( page ) )
675 {
676 if( !panel->GetCanClose() )
677 return false;
678 }
679 }
680
681 // CloseProject will recursively ask all the open editors if they need to save changes.
682 // If any of them cancel then we need to cancel closing the KICAD_MANAGER_FRAME.
683 if( CloseProject( true ) )
684 {
685 // Don't propagate event to frames which have already been closed
686 aEvent.StopPropagation();
687
688 return true;
689 }
690 else
691 {
692 if( aEvent.CanVeto() )
693 aEvent.Veto();
694
695 return false;
696 }
697}
698
699
701{
702#ifdef _WINDOWS_
703 // For some obscure reason, on Windows, when killing Kicad from the Windows task manager
704 // if a editor frame (schematic, library, board editor or fp editor) is open and has
705 // some edition to save, OnCloseWindow is run twice *at the same time*, creating race
706 // conditions between OnCloseWindow() code.
707 // Therefore I added (JPC) a ugly hack to discard the second call (unwanted) during
708 // execution of the first call (only one call is right).
709 // Note also if there is no change made in editors, this behavior does not happen.
710 static std::atomic<unsigned int> lock_close_event( 0 );
711
712 if( ++lock_close_event > 1 ) // Skip extra calls
713 {
714 return;
715 }
716#endif
717
718 m_projectTreePane->Show( false );
719 Pgm().m_Quitting = true;
720
721 Destroy();
722
723#ifdef _WINDOWS_
724 lock_close_event = 0; // Reenable event management
725#endif
726}
727
728
730{
732
733 if( !aIsExplicitUserSave && !cfg.ShouldAutoSave() )
734 return;
735
736 cfg.m_OpenJobSets.clear();
737
738 for( size_t i = 0; i < m_notebook->GetPageCount(); i++ )
739 {
740 if( PANEL_JOBSET* jobset = dynamic_cast<PANEL_JOBSET*>( m_notebook->GetPage( i ) ) )
741 {
742 wxFileName jobsetFn( jobset->GetFilePath() );
743 jobsetFn.MakeRelativeTo( Prj().GetProjectPath() );
744 cfg.m_OpenJobSets.emplace_back( jobsetFn.GetFullPath() );
745 }
746 }
747
748 cfg.SaveToFile( Prj().GetProjectPath() );
749}
750
751
752void KICAD_MANAGER_FRAME::OnExit( wxCommandEvent& event )
753{
754 Close( true );
755}
756
757
759{
760 if( !Kiway().PlayersClose( false ) )
761 return false;
762
763 // Abort any in-progress background load, since the threads depend on the project not changing
764 KIFACE *schface = Kiway().KiFACE( KIWAY::FACE_SCH );
765 schface->CancelPreload();
766
767 KIFACE *pcbface = Kiway().KiFACE( KIWAY::FACE_PCB );
768 pcbface->CancelPreload();
769
770 // Save the project file for the currently loaded project.
771 if( m_active_project )
772 {
774
775 if( Prj().GetLocalSettings().ShouldAutoSave() && Prj().GetProjectFile().ShouldAutoSave() )
776 {
778
779 if( aSave )
780 mgr.SaveProject();
781 }
782
783 // Ensure the Last_Save tag is at HEAD before closing. This handles the case where
784 // autosave commits were made after the last explicit save - without this, the next
785 // project load would offer to restore the autosave state, which is incorrect after
786 // a clean close.
787 wxString projPath = Prj().GetProjectPath();
788
789 if( !projPath.IsEmpty() && Kiway().LocalHistory().HistoryExists( projPath ) )
790 {
791 if( Kiway().LocalHistory().HeadNewerThanLastSave( projPath ) )
792 {
793 // Commit the current on-disk state and tag it so Last_Save matches HEAD
794 if( Kiway().LocalHistory().CommitFullProjectSnapshot( projPath, wxS( "Close" ) ) )
795 {
796 Kiway().LocalHistory().TagSave( projPath, wxS( "project" ) );
797 }
798 }
799 }
800
801 m_active_project = false;
802 // Enforce local history size limit (if enabled) once all pending saves/backups are done.
803 if( Pgm().GetCommonSettings() && Pgm().GetCommonSettings()->m_Backup.enabled )
804 {
805 unsigned long long int limit = Pgm().GetCommonSettings()->m_Backup.limit_total_size;
806
807 if( limit > 0 )
808 Kiway().LocalHistory().EnforceSizeLimit( Prj().GetProjectPath(), (size_t) limit );
809 }
810
811 // Unregister the project saver before unloading the project to prevent
812 // dangling references
814
815 mgr.UnloadProject( &Prj() );
816 }
817
818 SetStatusText( "" );
819
820 // Traverse pages in reverse order so deleting them doesn't mess up our iterator.
821 for( int i = (int) m_notebook->GetPageCount() - 1; i >= 0; i-- )
822 {
823 wxWindow* page = m_notebook->GetPage( i );
824
825 if( PANEL_NOTEBOOK_BASE* panel = dynamic_cast<PANEL_NOTEBOOK_BASE*>( page ) )
826 {
827 if( panel->GetProjectTied() )
828 m_notebook->DeletePage( i );
829 }
830 }
831
832 m_projectTreePane->EmptyTreePrj();
834
835 return true;
836}
837
838
839void KICAD_MANAGER_FRAME::OpenJobsFile( const wxFileName& aFileName, bool aCreate, bool aResaveProjectPreferences )
840{
841 for( size_t i = 0; i < m_notebook->GetPageCount(); i++ )
842 {
843 if( PANEL_JOBSET* panel = dynamic_cast<PANEL_JOBSET*>( m_notebook->GetPage( i ) ) )
844 {
845 if( aFileName.GetFullPath() == panel->GetFilePath() )
846 {
847 m_notebook->SetSelection( i );
848 return;
849 }
850 }
851 }
852
853 try
854 {
855 std::unique_ptr<JOBSET> jobsFile = std::make_unique<JOBSET>( aFileName.GetFullPath().ToStdString() );
856
857 jobsFile->LoadFromFile();
858
859 if( aCreate && !aFileName.FileExists() )
860 {
861 JOBSET_DESTINATION* dest = jobsFile->AddNewDestination( JOBSET_DESTINATION_T::FOLDER );
862 dest->m_outputHandler->SetOutputPath( aFileName.GetName() );
863 jobsFile->SaveToFile( wxEmptyString, true );
864 }
865
866 PANEL_JOBSET* jobPanel = new PANEL_JOBSET( m_notebook, this, std::move( jobsFile ) );
867 jobPanel->SetProjectTied( true );
868 jobPanel->SetClosable( true );
869 m_notebook->AddPage( jobPanel, aFileName.GetFullName(), true );
871
872 if( aResaveProjectPreferences )
874 }
875 catch( ... )
876 {
877 DisplayErrorMessage( this, _( "Error opening jobs file" ) );
878 }
879}
880
881
882bool KICAD_MANAGER_FRAME::LoadProject( const wxFileName& aProjectFileName )
883{
884 // The project file should be valid by the time we get here or something has gone wrong.
885 if( !aProjectFileName.Exists() )
886 return false;
887
888 wxString fullPath = aProjectFileName.GetFullPath();
889
890 // Check if a lock file already exists BEFORE we try to acquire it. We only want to warn
891 // the user if the lock file pre-existed, not if we're about to create it ourselves.
892 // The actual lock acquisition happens in SETTINGS_MANAGER::LoadProject().
893 wxFileName lockFn( fullPath );
894 lockFn.SetName( FILEEXT::LockFilePrefix + lockFn.GetName() );
895 lockFn.SetExt( lockFn.GetExt() + wxS( "." ) + FILEEXT::LockFileExtension );
896 bool lockFilePreExisted = lockFn.FileExists();
897
898 bool lockOverrideGranted = false;
899
900 if( lockFilePreExisted )
901 {
902 // A lock file exists. Create a LOCKFILE to read who owns it and decide what to do.
903 LOCKFILE lockFile( fullPath );
904
905 if( !lockFile.Valid() && lockFile.IsLockedByMe() )
906 {
907 // If we cannot acquire the lock but we appear to be the one who locked it, check to
908 // see if there is another KiCad instance running. If not, then we can override the
909 // lock. This could happen if KiCad crashed or was interrupted.
910 if( !Pgm().SingleInstance()->IsAnotherRunning() )
911 lockFile.OverrideLock();
912 }
913
914 if( !lockFile.Valid() )
915 {
916 wxString msg;
917 msg.Printf( _( "Project '%s' is already open by '%s' at '%s'." ),
918 fullPath,
919 lockFile.GetUsername(),
920 lockFile.GetHostname() );
921
922 if( !AskOverrideLock( this, msg ) )
923 return false; // User clicked Cancel - abort project loading entirely
924
925 lockFile.OverrideLock();
926 lockOverrideGranted = true;
927 }
928
929 // The LOCKFILE goes out of scope here and releases/removes the lock file.
930 // SETTINGS_MANAGER::LoadProject() will create the actual persistent lock.
931 }
932
933 // Any open KIFACE's must be closed if they are not part of the new project.
934 // (We never want a KIWAY_PLAYER open on a KIWAY that isn't in the same project.)
935 // User is prompted here to close those KIWAY_PLAYERs:
936 if( !CloseProject( true ) )
937 return false;
938
939 m_active_project = true;
940
941 // NB: when loading a legacy project SETTINGS_MANAGER::LoadProject() will convert it to
942 // current extension. Be very careful with aProjectFileName vs. Prj().GetProjectPath()
943 // from here on out.
944
945 Pgm().GetSettingsManager().LoadProject( fullPath );
946
947 // Propagate lock override decision to the loaded project
948 if( lockOverrideGranted )
949 Prj().SetLockOverrideGranted( true );
950
951 LoadWindowState( aProjectFileName.GetFullName() );
952
953 if( aProjectFileName.IsDirWritable() )
954 SetMruPath( Prj().GetProjectPath() );
955
956 Kiway().LocalHistory().Init( Prj().GetProjectPath() );
957
958 if( Kiway().LocalHistory().HeadNewerThanLastSave( Prj().GetProjectPath() ) )
959 {
960 wxString head = Kiway().LocalHistory().GetHeadHash( Prj().GetProjectPath() );
961
962 KICAD_MESSAGE_DIALOG dlg( this, _( "KiCad found unsaved changes from your last session that are newer than "
963 "the saved project files." ),
964 _( "Recover Unsaved Changes" ), wxYES_NO | wxICON_QUESTION );
965
966 dlg.SetExtendedMessage( _( "This can happen if your previous session ended unexpectedly.\n\n"
967 "Choose 'Restore' to recover those changes, or 'Discard' to keep the "
968 "currently saved files." ) );
969
970 dlg.SetYesNoLabels( _( "Restore" ), _( "Discard" ) );
971
972 if( dlg.ShowModal() == wxID_YES )
973 {
974 Kiway().LocalHistory().RestoreCommit( Prj().GetProjectPath(), head, this );
975 }
976 else
977 {
978 // User declined to restore - commit the current on-disk state and tag it
979 // so we don't prompt again on next load
980 if( Kiway().LocalHistory().CommitFullProjectSnapshot( Prj().GetProjectPath(), wxS( "Declined restore" ) ) )
981 Kiway().LocalHistory().TagSave( Prj().GetProjectPath(), wxS( "project" ) );
982 }
983 }
984
985 // Save history & window state to disk now. Don't wait around for a crash.
986 KICAD_SETTINGS* settings = kicadSettings();
987 SaveSettings( settings );
988 settings->SaveToFile( Pgm().GetSettingsManager().GetPathForSettingsFile( settings ) );
989
990 m_projectTreePane->ReCreateTreePrj();
991 m_historyPane->RefreshHistory( Prj().GetProjectPath() );
992
993 for( const wxString& jobset : Prj().GetLocalSettings().m_OpenJobSets )
994 {
995 wxFileName jobsetFn( jobset );
996 jobsetFn.MakeAbsolute( Prj().GetProjectPath() );
997
998 if( jobsetFn.Exists() )
999 OpenJobsFile( jobsetFn.GetFullPath(), false, false );
1000 }
1001
1002 // Always start with the apps page
1003 m_notebook->SetSelection( 0 );
1004
1005 // Rebuild the list of watched paths.
1006 // however this is possible only when the main loop event handler is running,
1007 // so we use it to run the rebuild function.
1008 wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED, ID_INIT_WATCHED_PATHS );
1009
1010 wxPostEvent( this, cmd );
1011
1012 PrintPrjInfo();
1013
1014 KIPLATFORM::APP::RegisterApplicationRestart( aProjectFileName.GetFullPath() );
1015 m_openSavedWindows = true;
1016
1017 KIPLATFORM::ENV::AddToRecentDocs( aProjectFileName.GetFullPath() );
1018
1019 // Now that we have a new project, trigger a library preload, which will load in any
1020 // project-specific symbol and footprint libraries into the manager
1022 return true;
1023}
1024
1025
1026void KICAD_MANAGER_FRAME::CreateNewProject( const wxFileName& aProjectFileName, bool aCreateStubFiles )
1027{
1028 wxCHECK_RET( aProjectFileName.DirExists() && aProjectFileName.IsDirWritable(),
1029 "Project folder must exist and be writable to create a new project." );
1030
1031 // If the project is legacy, convert it
1032 if( !aProjectFileName.FileExists() )
1033 {
1034 wxFileName legacyPro( aProjectFileName );
1035 legacyPro.SetExt( FILEEXT::LegacyProjectFileExtension );
1036
1037 if( legacyPro.FileExists() )
1038 {
1039 GetSettingsManager()->LoadProject( legacyPro.GetFullPath() );
1041
1042 wxRemoveFile( legacyPro.GetFullPath() );
1043 }
1044 else
1045 {
1046 // Copy template project file from template folder.
1047 wxString srcFileName = sys_search().FindValidPath( "kicad.kicad_pro" );
1048
1049 wxFileName destFileName( aProjectFileName );
1050 destFileName.SetExt( FILEEXT::ProjectFileExtension );
1051
1052 // Create a minimal project file if the template project file could not be copied
1053 if( !wxFileName::FileExists( srcFileName )
1054 || !wxCopyFile( srcFileName, destFileName.GetFullPath() ) )
1055 {
1056 wxFFile file( destFileName.GetFullPath(), "wb" );
1057
1058 if( file.IsOpened() )
1059 file.Write( wxT( "{\n}\n") );
1060
1061 // wxFFile dtor will close the file
1062 }
1063 }
1064 }
1065
1066 // Create a "stub" for a schematic root sheet and a board if requested.
1067 // It will avoid messages from the schematic editor or the board editor to create a new file
1068 // And forces the user to create main files under the right name for the project manager
1069 if( aCreateStubFiles )
1070 {
1071 wxFileName fn( aProjectFileName.GetFullPath() );
1073
1074 // If a <project>.kicad_sch file does not exist, create a "stub" file ( minimal schematic
1075 // file ).
1076 if( !fn.FileExists() )
1077 {
1078 wxFFile file( fn.GetFullPath(), "wb" );
1079
1080 if( file.IsOpened() )
1081 {
1082 file.Write( wxString::Format( "(kicad_sch\n"
1083 "\t(version %d)\n"
1084 "\t(generator \"eeschema\")\n"
1085 "\t(generator_version \"%s\")\n"
1086 "\t(uuid %s)\n"
1087 "\t(paper \"A4\")\n"
1088 "\t(lib_symbols)\n"
1089 "\t(sheet_instances\n"
1090 "\t\t(path \"/\"\n"
1091 "\t\t\t(page \"1\")\n"
1092 "\t\t)\n"
1093 "\t)\n"
1094 "\t(embedded_fonts no)\n"
1095 ")",
1098 KIID().AsString() ) );
1099 }
1100
1101 // wxFFile dtor will close the file
1102 }
1103
1104 // If a <project>.kicad_pcb or <project>.brd file does not exist,
1105 // create a .kicad_pcb "stub" file
1106 fn.SetExt( FILEEXT::KiCadPcbFileExtension );
1107 wxFileName leg_fn( fn );
1108 leg_fn.SetExt( FILEEXT::LegacyPcbFileExtension );
1109
1110 if( !fn.FileExists() && !leg_fn.FileExists() )
1111 {
1112 wxFFile file( fn.GetFullPath(), "wb" );
1113
1114 if( file.IsOpened() )
1115 {
1116 // Create a small dummy file as a stub for pcbnew:
1117 file.Write( wxString::Format( "(kicad_pcb (version %d) (generator \"pcbnew\") (generator_version \"%s\")\n)",
1119 }
1120
1121 // wxFFile dtor will close the file
1122 }
1123 }
1124
1125 // Save history & window state to disk now. Don't wait around for a crash.
1126 KICAD_SETTINGS* settings = kicadSettings();
1127 SaveSettings( settings );
1128 settings->SaveToFile( Pgm().GetSettingsManager().GetPathForSettingsFile( settings ) );
1129
1130 m_openSavedWindows = true;
1131}
1132
1133
1135{
1136 // show all files in file dialog (in Kicad all files are editable texts):
1137 wxString wildcard = FILEEXT::AllFilesWildcard();
1138
1139 wxString default_dir = Prj().GetProjectPath();
1140
1141 wxFileDialog dlg( this, _( "Edit File in Text Editor" ), default_dir, wxEmptyString, wildcard,
1142 wxFD_OPEN );
1143
1145
1146 if( dlg.ShowModal() == wxID_CANCEL )
1147 return;
1148
1149 wxString filename = dlg.GetPath();
1150
1151 if( !dlg.GetPath().IsEmpty() && !Pgm().GetTextEditor().IsEmpty() )
1152 m_toolManager->RunAction<wxString*>( KICAD_MANAGER_ACTIONS::openTextEditor, &filename );
1153}
1154
1155
1156void KICAD_MANAGER_FRAME::OnEditAdvancedCfg( wxCommandEvent& WXUNUSED( event ) )
1157{
1158 DIALOG_EDIT_CFG dlg( this );
1159 dlg.ShowModal();
1160}
1161
1162
1164{
1165 m_projectTreePane->ReCreateTreePrj();
1166}
1167
1168
1170{
1171 // call my base class
1173
1174 // tooltips in toolbars
1176 m_launcher->CreateLaunchers();
1177
1178 // update captions
1179 int pageId = m_notebook->FindPage( m_launcher );
1180
1181 if( pageId != wxNOT_FOUND )
1182 m_notebook->SetPageText( pageId, EDITORS_CAPTION );
1183
1184 m_auimgr.GetPane( m_projectTreePane ).Caption( PROJECT_FILES_CAPTION );
1185 m_auimgr.Update();
1186
1187 m_projectTreePane->FileWatcherReset();
1188
1189 PrintPrjInfo();
1190}
1191
1192
1194{
1196
1197 if( m_pcm && ( aFlags & ENVVARS_CHANGED ) )
1198 m_pcm->ReadEnvVar();
1199
1200 COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
1201
1202 if( m_lastToolbarIconSize == 0
1204 {
1207 }
1208
1209 m_projectTreePane->ReCreateTreePrj();
1210}
1211
1212
1214{
1215 wxString file = GetProjectFileName();
1216
1217 // empty file string means no project loaded
1218 if( !Prj().IsNullProject() &&
1219 Prj().GetProjectLock() == nullptr )
1220 {
1221 LOCKFILE lockFile( file );
1222
1223 if( !lockFile.Valid() && lockFile.IsLockedByMe() )
1224 {
1225 // If we cannot acquire the lock but we appear to be the one who
1226 // locked it, check to see if there is another KiCad instance running.
1227 // If there is not, then we can override the lock. This could happen if
1228 // KiCad crashed or was interrupted
1229 if( !Pgm().SingleInstance()->IsAnotherRunning() )
1230 {
1231 lockFile.OverrideLock();
1232 }
1233 }
1234
1235 if( !lockFile.Valid() )
1236 {
1237 wxString msg;
1238 msg.Printf( _( "Project '%s' is already open by '%s' at '%s'." ),
1239 file,
1240 lockFile.GetUsername(),
1241 lockFile.GetHostname() );
1242
1243 if( AskOverrideLock( this, msg ) )
1244 {
1245 lockFile.OverrideLock();
1246 }
1247 }
1248
1249 Prj().SetReadOnly( !lockFile.Valid() || Prj().GetProjectFile().IsReadOnly() );
1250 Prj().SetProjectLock( new LOCKFILE( std::move( lockFile ) ) );
1251 }
1252
1253 wxString title;
1254
1255 if( !file.IsEmpty() )
1256 {
1257 wxFileName fn( file );
1258
1259 title = fn.GetName();
1260
1261 if( Prj().IsReadOnly() )
1262 title += wxS( " " ) + _( "[Read Only]" );
1263 }
1264 else
1265 {
1266 title = _( "[no project loaded]" );
1267 }
1268
1269 if( ADVANCED_CFG::GetCfg().m_HideVersionFromTitle )
1270 title += wxT( " \u2014 " ) + wxString( wxS( "KiCad" ) );
1271 else
1272 title += wxT( " \u2014 " ) + wxString( wxS( "KiCad " ) ) + GetMajorMinorVersion();
1273
1274 SetTitle( title );
1275
1276 // Register project file saver. Ensures project file participates in
1277 // autosave history commits without affecting dirty state.
1279 [this]( const wxString& aProjectPath, std::vector<HISTORY_FILE_DATA>& aFileData )
1280 {
1281 Prj().SaveToHistory( aProjectPath, aFileData );
1282 } );
1283}
1284
1285
1287{
1289
1290 auto settings = dynamic_cast<KICAD_SETTINGS*>( aCfg );
1291
1292 wxCHECK( settings, /*void*/ );
1293
1294 m_leftWinWidth = settings->m_LeftWinWidth;
1295 m_showHistoryPanel = settings->m_ShowHistoryPanel;
1296}
1297
1298
1300{
1302
1303 KICAD_SETTINGS* settings = dynamic_cast<KICAD_SETTINGS*>( aCfg );
1304
1305 wxCHECK( settings, /*void*/ );
1306
1307 settings->m_LeftWinWidth = m_projectTreePane->GetSize().x;
1308 settings->m_ShowHistoryPanel = m_historyPane && m_auimgr.GetPane( m_historyPane ).IsShown();
1309
1310 if( !m_isClosing )
1312}
1313
1314
1316{
1317 // wxStatusBar's wxELLIPSIZE_MIDDLE flag doesn't work (at least on Mac).
1318
1319 wxString status = wxString::Format( _( "Project: %s" ), Prj().GetProjectFullName() );
1320 KISTATUSBAR* statusBar = static_cast<KISTATUSBAR*>( GetStatusBar() );
1321 statusBar->SetEllipsedTextField( status, 0 );
1322}
1323
1324
1329
1330
1331void KICAD_MANAGER_FRAME::OnIdle( wxIdleEvent& aEvent )
1332{
1338 if( !m_openSavedWindows )
1339 return;
1340
1341 m_openSavedWindows = false;
1342
1343 if( Pgm().GetCommonSettings()->m_Session.remember_open_files )
1344 {
1345 int previousOpenCount = std::count_if( Prj().GetLocalSettings().m_files.begin(),
1346 Prj().GetLocalSettings().m_files.end(),
1347 [&]( const PROJECT_FILE_STATE& f )
1348 {
1349 return !f.fileName.EndsWith( FILEEXT::ProjectFileExtension ) && f.open;
1350 } );
1351
1352 if( previousOpenCount > 0 )
1353 {
1354 APP_PROGRESS_DIALOG progressReporter( _( "Restoring session" ), wxEmptyString, previousOpenCount, this );
1355
1356 // We don't currently support opening more than one view per file
1357 std::set<wxString> openedFiles;
1358
1359 int i = 0;
1360
1361 for( const PROJECT_FILE_STATE& file : Prj().GetLocalSettings().m_files )
1362 {
1363 if( file.open && !openedFiles.count( file.fileName ) )
1364 {
1365 progressReporter.Update( i++, wxString::Format( _( "Restoring '%s'" ), file.fileName ) );
1366
1367 openedFiles.insert( file.fileName );
1368 wxFileName fn( file.fileName );
1369
1370 if( fn.GetExt() == FILEEXT::LegacySchematicFileExtension
1371 || fn.GetExt() == FILEEXT::KiCadSchematicFileExtension )
1372 {
1374 }
1375 else if( fn.GetExt() == FILEEXT::LegacyPcbFileExtension
1376 || fn.GetExt() == FILEEXT::KiCadPcbFileExtension )
1377 {
1379 }
1380 }
1381
1382 wxYield();
1383 }
1384 }
1385 }
1386
1387 // clear file states regardless if we opened windows or not due to setting
1389
1390 // After restore from history, mark open editors as dirty so user is prompted to save
1392 {
1393 m_restoredFromHistory = false;
1394
1395 // Mark schematic editor as dirty if open
1396 if( KIWAY_PLAYER* schFrame = Kiway().Player( FRAME_SCH, false ) )
1397 schFrame->OnModify();
1398
1399 // Mark PCB editor as dirty if open
1400 if( KIWAY_PLAYER* pcbFrame = Kiway().Player( FRAME_PCB_EDITOR, false ) )
1401 pcbFrame->OnModify();
1402 }
1403
1404 KICAD_SETTINGS* settings = kicadSettings();
1405
1407 && settings->m_PcmUpdateCheck )
1408 {
1409 if( !m_pcm )
1410 CreatePCM();
1411
1412 m_pcm->RunBackgroundUpdate();
1413 }
1414
1415#ifdef KICAD_UPDATE_CHECK
1416 if( !m_updateManager && settings->m_KiCadUpdateCheck )
1417 {
1418 m_updateManager = std::make_unique<UPDATE_MANAGER>();
1419 m_updateManager->CheckForUpdate( this );
1420 }
1421#endif
1422
1423 // This little diddy is needed to get the window put into the Mac dock icon's context menu.
1424 Raise();
1425}
1426
1427
1429{
1430 m_pcmButton = aButton;
1431
1433}
1434
1435
1437{
1438 if( m_pcmButton )
1439 {
1440 if( m_pcmUpdateCount > 0 )
1441 {
1442 m_pcmButton->SetShowBadge( true );
1443 m_pcmButton->SetBadgeText( wxString::Format( "%d", m_pcmUpdateCount ) );
1444 }
1445 else
1446 {
1447 m_pcmButton->SetShowBadge( false );
1448 }
1449
1450 m_pcmButton->Refresh();
1451 }
1452}
1453
1454
1456{
1457 // No idea why, but the same mechanism used in EDA_DRAW_FRAME doesn't work here
1458 // the only thing that seems to work is to blow it all up and start from scratch.
1459 m_auimgr.DetachPane( m_tbLeft );
1460 delete m_tbLeft;
1461 m_tbLeft = nullptr;
1463 m_auimgr.AddPane( m_tbLeft, EDA_PANE().HToolbar().Name( "TopMainToolbar" ).Left().Layer( 2 ) );
1464
1465 m_auimgr.Update();
1466}
1467
1468
1470{
1471 wxAuiPaneInfo& pane = m_auimgr.GetPane( m_historyPane );
1472 bool show = !pane.IsShown();
1473 pane.Show( show );
1474
1475 if( show )
1476 m_historyPane->RefreshHistory( Prj().GetProjectPath() );
1477
1478 m_auimgr.Update();
1479}
1480
1481
1483{
1484 if( !Kiway().PlayersClose( true ) )
1485 return;
1486
1487 if( Kiway().LocalHistory().RestoreCommit( Prj().GetProjectPath(), aHash, this ) )
1488 {
1489 m_restoredFromHistory = true; // Mark editors dirty when they reopen
1490 }
1491
1492 m_projectTreePane->ReCreateTreePrj();
1493 m_openSavedWindows = true;
1494 m_historyPane->RefreshHistory( Prj().GetProjectPath() );
1495}
1496
1497
1499{
1500 return m_historyPane && m_auimgr.GetPane( m_historyPane ).IsShown();
1501}
const char * name
constexpr EDA_IU_SCALE unityScale
Definition base_units.h:115
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition bitmap.cpp:104
@ icon_kicad_nightly
@ icon_kicad_nightly_32
@ icon_kicad_nightly_16
wxString GetMajorMinorVersion()
Get only the major and minor version in a string major.minor.
bool IsNightlyVersion()
Check if the build is meant to be nightly.
static TOOL_ACTION paste
Definition actions.h:80
static TOOL_ACTION saveAs
Definition actions.h:59
static TOOL_ACTION copy
Definition actions.h:78
static TOOL_ACTION cut
Definition actions.h:77
Manage TOOL_ACTION objects.
void SetConditions(const TOOL_ACTION &aAction, const ACTION_CONDITIONS &aConditions)
Set the conditions the UI elements for activating a specific tool action should use for determining t...
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
wxProgressDialog with the option to also update the application progress on the taskbar
virtual bool Update(int aValue, const wxString &aNewMsg=wxEmptyString, bool *aSkip=nullptr) override
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
void UnregisterStatusBar(KISTATUSBAR *aStatusBar)
Removes status bar from handling.
void RegisterStatusBar(KISTATUSBAR *aStatusBar)
Add a status bar for handling.
A bitmap button widget that behaves like an AUI toolbar item's button when it is drawn.
Handle actions that are shared between different applications.
APPEARANCE m_Appearance
AUTO_BACKUP m_Backup
The base frame for deriving all KiCad main window classes.
void LoadWindowState(const wxString &aFileName)
void CommonSettingsChanged(int aFlags) override
Notification event that some of the common (suite-wide) settings have changed.
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
virtual void setupUIConditions()
Setup the UI conditions for the various actions and their controls in this frame.
std::vector< wxFileName > m_AcceptedFiles
SETTINGS_MANAGER * GetSettingsManager() const
EDA_BASE_FRAME(wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName, KIWAY *aKiway, const EDA_IU_SCALE &aIuScale)
TOOLBAR_SETTINGS * m_toolbarSettings
virtual void configureToolbars()
wxAuiManager m_auimgr
virtual void RecreateToolbars()
virtual void LoadSettings(APP_SETTINGS_BASE *aCfg)
Load common frame parameters from a configuration file.
ACTION_TOOLBAR * m_tbLeft
virtual void OnDropFiles(wxDropFilesEvent &aEvent)
Handle event fired when a file is dropped to the window.
std::map< const wxString, TOOL_ACTION * > m_acceptedExts
Associate file extensions with action to execute.
virtual void SaveSettings(APP_SETTINGS_BASE *aCfg)
Save common frame parameters to a configuration data file.
void SetMruPath(const wxString &aPath)
wxString m_aboutTitle
bool m_isClosing
Set by the close window event handler after frames are asked if they can close.
void ReCreateMenuBar()
Recreate the menu bar.
Specialization of the wxAuiPaneInfo class for KiCad panels.
void SetOutputPath(const wxString &aPath)
Definition jobs_output.h:56
virtual bool SaveToFile(const wxString &aDirectory="", bool aForce=false)
Calls Store() and then writes the contents of the JSON document to a file.
static TOOL_ACTION viewDroppedGerbers
static TOOL_ACTION loadProject
static TOOL_ACTION showLocalHistory
static TOOL_ACTION editSchematic
static TOOL_ACTION openTextEditor
static TOOL_ACTION archiveProject
static TOOL_ACTION closeProject
static TOOL_ACTION openJobsetFile
static TOOL_ACTION newJobsetFile
Handle actions in the kicad manager frame.
The main KiCad project manager frame.
std::shared_ptr< PLUGIN_CONTENT_MANAGER > m_pcm
void SetPcmButton(BITMAP_BUTTON *aButton)
void CreateNewProject(const wxFileName &aProjectFileName, bool aCreateStubFiles=true)
Creates a new project by setting up and initial project, schematic, and board files.
const SEARCH_STACK & sys_search() override
Return a SEARCH_STACK pertaining to entire program.
void OnImportEasyEdaProFiles(wxCommandEvent &event)
Open dialog to import EasyEDA Pro schematic and board files.
void ProjectChanged() override
Notification event that the project has changed.
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
const wxString SchLegacyFileName()
wxWindow * GetToolCanvas() const override
Canvas access.
void OnImportEasyEdaFiles(wxCommandEvent &event)
Open dialog to import EasyEDA Std schematic and board files.
void OnImportPadsProjectFiles(wxCommandEvent &event)
Open dialog to import PADS Logic schematic and PCB files.
void OnImportAltiumProjectFiles(wxCommandEvent &event)
Open dialog to import Altium project files.
const wxString GetProjectFileName() const
KICAD_SETTINGS * kicadSettings() const
void OnImportEagleFiles(wxCommandEvent &event)
Open dialog to import Eagle schematic and board files.
wxStatusBar * OnCreateStatusBar(int number, long style, wxWindowID id, const wxString &name) override
Create the status line (like a wxStatusBar).
void OnExit(wxCommandEvent &event)
void OpenJobsFile(const wxFileName &aFileName, bool aCreate=false, bool aResaveProjectPreferences=true)
void OnChangeWatchedPaths(wxCommandEvent &aEvent)
Called by sending a event with id = ID_INIT_WATCHED_PATHS rebuild the list of watched paths.
bool canCloseWindow(wxCloseEvent &aCloseEvent) override
void OnSize(wxSizeEvent &event) override
virtual void setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
void OnFileHistory(wxCommandEvent &event)
PROJECT_TREE_PANE * m_projectTreePane
void OnImportGedaFiles(wxCommandEvent &event)
Open dialog to import gEDA/gaf schematic and PCB files.
void RestoreCommitFromHistory(const wxString &aHash)
void DoWithAcceptedFiles() override
Execute action on accepted dropped file.
void OnOpenFileInTextEditor(wxCommandEvent &event)
APP_SETTINGS_BASE * config() const override
Return the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
const wxString PcbLegacyFileName()
void OnEditAdvancedCfg(wxCommandEvent &event)
KICAD_MANAGER_FRAME(wxWindow *parent, const wxString &title, const wxPoint &pos, const wxSize &size)
bool CloseProject(bool aSave)
Closes the project, and saves it if aSave is true;.
wxString GetCurrentFileName() const override
Get the full filename + path of the currently opened file in the frame.
void onNotebookPageCloseRequest(wxAuiNotebookEvent &evt)
void CommonSettingsChanged(int aFlags) override
Notification event that some of the common (suite-wide) settings have changed.
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void OnIdle(wxIdleEvent &event)
void PrintPrjInfo()
Prints the current working directory name and the project name on the text panel.
void SaveOpenJobSetsToLocalSettings(bool aIsExplicitUserSave=false)
bool LoadProject(const wxFileName &aProjectFileName)
Loads a new project.
bool m_restoredFromHistory
Set after restore to mark editors dirty.
void onNotebookPageCountChanged(wxAuiNotebookEvent &evt)
LOCAL_HISTORY_PANE * m_historyPane
void OnClearFileHistory(wxCommandEvent &aEvent)
void OnImportCadstarArchiveFiles(wxCommandEvent &event)
Open dialog to import CADSTAR Schematic and PCB Archive files.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
BITMAP_BUTTON * m_pcmButton
PANEL_KICAD_LAUNCHER * m_launcher
void HideTabsIfNeeded()
Hides the tabs for Editor notebook if there is only 1 page.
wxString help_name() override
std::unique_ptr< UPDATE_MANAGER > m_updateManager
std::vector< wxString > m_OpenProjects
Definition kiid.h:48
void SetEllipsedTextField(const wxString &aText, int aFieldId)
Set the text in a field using wxELLIPSIZE_MIDDLE option to adjust the text size to the field size.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
virtual KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Return the KIFACE* given a FACE_T.
Definition kiway.cpp:211
@ FACE_SCH
eeschema DSO
Definition kiway.h:322
@ FACE_PCB
pcbnew DSO
Definition kiway.h:323
LOCAL_HISTORY & LocalHistory()
Return the LOCAL_HISTORY associated with this KIWAY.
Definition kiway.h:426
bool TagSave(const wxString &aProjectPath, const wxString &aFileType)
Tag a manual save in the local history repository.
wxString GetHeadHash(const wxString &aProjectPath)
Return the current head commit hash.
bool RestoreCommit(const wxString &aProjectPath, const wxString &aHash, wxWindow *aParent=nullptr)
Restore the project files to the state recorded by the given commit hash.
void RegisterSaver(const void *aSaverObject, const std::function< void(const wxString &, std::vector< HISTORY_FILE_DATA > &)> &aSaver)
Register a saver callback invoked during autosave history commits.
bool EnforceSizeLimit(const wxString &aProjectPath, size_t aMaxBytes)
Enforce total size limit by rebuilding trimmed history keeping newest commits whose cumulative unique...
bool Init(const wxString &aProjectPath)
Initialize the local history repository for the given project path.
void UnregisterSaver(const void *aSaverObject)
Unregister a previously registered saver callback.
bool OverrideLock(bool aRemoveOnRelease=true)
Force the lock, overwriting the data that existed already.
Definition lockfile.h:174
bool Valid() const
Definition lockfile.h:254
wxString GetUsername()
Definition lockfile.h:236
wxString GetHostname()
Definition lockfile.h:242
bool IsLockedByMe()
Definition lockfile.h:227
void RegisterStatusBar(KISTATUSBAR *aStatusBar)
Add a status bar for handling.
void CreateOrUpdate(const wxString &aKey, const wxString &aTitle, const wxString &aDescription, const wxString &aHref=wxEmptyString)
Create a notification with the given parameters or updates an existing one with the same key.
void Remove(const wxString &aKey)
Remove a notification by key.
void UnregisterStatusBar(KISTATUSBAR *aStatusBar)
Remove status bar from handling.
static REPORTER & GetInstance()
Definition reporter.cpp:97
void SetClosable(bool aYes)
void SetProjectTied(bool aYes)
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition pgm_base.cpp:541
void PreloadDesignBlockLibraries(KIWAY *aKiway)
Starts a background job to preload the global and project design block libraries.
Definition pgm_base.cpp:887
virtual BACKGROUND_JOBS_MONITOR & GetBackgroundJobMonitor() const
Definition pgm_base.h:136
void UnregisterLibraryLoadStatusBar(KISTATUSBAR *aStatusBar)
Unregister a status bar from receiving library load warning messages.
Definition pgm_base.cpp:979
bool m_Quitting
Definition pgm_base.h:394
void RegisterLibraryLoadStatusBar(KISTATUSBAR *aStatusBar)
Register a status bar to receive library load warning messages.
Definition pgm_base.cpp:959
virtual NOTIFICATIONS_MANAGER & GetNotificationsManager() const
Definition pgm_base.h:141
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:130
wxString GetHelpFileName()
Definition pgm_kicad.h:63
SEARCH_STACK & SysSearch()
Definition pgm_kicad.h:61
APP_SETTINGS_BASE * PgmSettings()
Definition pgm_kicad.h:59
The project local settings are things that are attached to a particular project, but also might be pa...
bool SaveToFile(const wxString &aDirectory="", bool aForce=false) override
Calls Store() and then writes the contents of the JSON document to a file.
std::vector< wxString > m_OpenJobSets
PROJECT_TREE_PANE Window to display the tree files.
void SetProjectLock(LOCKFILE *aLockFile)
Definition project.cpp:455
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:171
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition project.cpp:177
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
Definition project.h:210
virtual void SetLockOverrideGranted(bool aGranted=true)
Definition project.h:168
void SaveToHistory(const wxString &aProjectPath, std::vector< HISTORY_FILE_DATA > &aFileData)
Produce HISTORY_FILE_DATA entries for project files (.kicad_pro and .kicad_prl).
Definition project.cpp:461
Look for files in a number of paths.
static bool ShowNever(const SELECTION &aSelection)
Always returns false.
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 IsProjectOpen() const
Helper for checking if we have a project open.
bool UnloadProject(PROJECT *aProject, bool aSave=true)
Save, unload and unregister the given PROJECT.
std::vector< wxString > GetOpenProjects() const
bool TriggerBackupIfNeeded(REPORTER &aReporter) const
Call BackupProject() if a new backup is needed according to the current backup policy.
TOOL_MANAGER * m_toolManager
TOOL_DISPATCHER * m_toolDispatcher
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
ACTIONS * m_actions
virtual void DispatchWxEvent(wxEvent &aEvent)
Process wxEvents (mostly UI events), translate them to TOOL_EVENTs, and make tools handle those.
Master controller class:
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
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
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:202
This file is part of the common library.
#define KICAD_MESSAGE_DIALOG
Definition confirm.h:52
#define ENABLE(x)
#define _(s)
Base window classes and related definitions.
#define KICAD_DEFAULT_DRAWFRAME_STYLE
#define KICAD_MANAGER_FRAME_NAME
EVT_MENU_RANGE(ID_GERBVIEW_DRILL_FILE1, ID_GERBVIEW_DRILL_FILEMAX, GERBVIEW_FRAME::OnDrlFileHistory) EVT_MENU_RANGE(ID_GERBVIEW_ZIP_FILE1
KiCad executable names.
const wxString GERBVIEW_EXE
@ FRAME_PCB_EDITOR
Definition frame_type.h:42
@ FRAME_SCH
Definition frame_type.h:34
@ KICAD_MAIN_FRAME_T
Definition frame_type.h:68
wxString FindKicadFile(const wxString &shortname)
Search the executable file shortname in KiCad binary path and return full file name if found or short...
Definition gestfich.cpp:61
static const std::string LegacySchematicFileExtension
static const std::string GerberJobFileExtension
static const std::string GerberFileExtension
static const std::string LockFileExtension
static const std::string ProjectFileExtension
static const std::string LegacyPcbFileExtension
static const std::string LegacyProjectFileExtension
static const std::string KiCadSchematicFileExtension
static const std::string LockFilePrefix
static const std::string DrillFileExtension
static const std::string KiCadPcbFileExtension
static wxString AllFilesWildcard()
static bool IsGerberFileExtension(const wxString &ext)
@ ID_FILE_LIST_CLEAR
Definition id.h:62
@ ID_FILEMAX
Definition id.h:60
@ ID_FILE1
Definition id.h:59
PGM_KICAD & PgmTop()
Definition kicad.cpp:88
@ ID_EDIT_ADVANCED_CFG
Definition kicad_id.h:38
@ ID_IMPORT_EAGLE_PROJECT
Definition kicad_id.h:40
@ ID_IMPORT_EASYEDAPRO_PROJECT
Definition kicad_id.h:42
@ ID_IMPORT_PADS_PROJECT
Definition kicad_id.h:44
@ ID_IMPORT_GEDA_PROJECT
Definition kicad_id.h:45
@ ID_IMPORT_CADSTAR_ARCHIVE_PROJECT
Definition kicad_id.h:39
@ ID_EDIT_LOCAL_FILE_IN_TEXT_EDITOR
Definition kicad_id.h:37
@ ID_IMPORT_EASYEDA_PROJECT
Definition kicad_id.h:41
@ ID_IMPORT_ALTIUM_PROJECT
Definition kicad_id.h:43
#define EDITORS_CAPTION
#define ID_INIT_WATCHED_PATHS
#define PROJECT_FILES_CAPTION
File locking utilities.
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
void AddToRecentDocs(const wxString &aPath)
PBOOL GetPolicyBool(const wxString &aKey)
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:435
KICOMMON_API wxFont GetStatusFont(wxWindow *aWindow)
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
PGM_BASE & Pgm()
The global program "get" accessor.
#define POLICY_KEY_PCM
Definition policy_keys.h:31
#define SEXPR_SCHEMATIC_FILE_VERSION
Schematic file version.
T * GetToolbarSettings(const wxString &aFilename)
std::vector< FAB_LAYER_COLOR > dummy
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...
ACTION_CONDITIONS & Enable(const SELECTION_CONDITION &aCondition)
unsigned long long limit_total_size
Maximum total size of backups (bytes), 0 for unlimited.
std::shared_ptr< JOBS_OUTPUT_HANDLER > m_outputHandler
Definition jobset.h:136
Implement a participant in the KIWAY alchemy.
Definition kiway.h:156
virtual void PreloadLibraries(KIWAY *aKiway)
Definition kiway.h:279
virtual void CancelPreload(bool aBlock=true)
Definition kiway.h:281
#define ENVVARS_CHANGED
Definition of file extensions used in Kicad.