KiCad PCB EDA Suite
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 (C) 2004-2022 KiCad Developers, see change_log.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"
31
32#include <advanced_config.h>
33#include <bitmaps.h>
34#include <build_version.h>
36#include <eda_base_frame.h>
37#include <executable_names.h>
38#include <file_history.h>
39#include <policy_keys.h>
40#include <gestfich.h>
41#include <kiplatform/app.h>
42#include <kiplatform/policy.h>
43#include <build_version.h>
44#include <kiway.h>
45#include <kiway_express.h>
46#include <launch_ext.h>
47#include <reporter.h>
49#include <sch_file_versions.h>
51#include <tool/action_manager.h>
52#include <tool/action_toolbar.h>
53#include <tool/common_control.h>
55#include <tool/tool_manager.h>
60#include <wx/ffile.h>
61#include <wx/filedlg.h>
62#include <wx/dcclient.h>
63#include <wx/dnd.h>
64#include <wx/process.h>
65#include <atomic>
66
67
68#include <../pcbnew/plugins/kicad/pcb_plugin.h> // for SEXPR_BOARD_FILE_VERSION def
69
70
71#ifdef __WXMAC__
72#include <MacTypes.h>
73#include <ApplicationServices/ApplicationServices.h>
74#endif
75
76#include "kicad_manager_frame.h"
78
79
80#define SEP() wxFileName::GetPathSeparator()
81
82
83// Menubar and toolbar event table
84BEGIN_EVENT_TABLE( KICAD_MANAGER_FRAME, EDA_BASE_FRAME )
85 // Window events
88
89 // Menu events
90 EVT_MENU( wxID_EXIT, KICAD_MANAGER_FRAME::OnExit )
97
98 // Range menu events
100 KICAD_MANAGER_FRAME::language_change )
101
103 EVT_MENU( ID_FILE_LIST_CLEAR, KICAD_MANAGER_FRAME::OnClearFileHistory )
104
105 // Special functions
106 EVT_MENU( ID_INIT_WATCHED_PATHS, KICAD_MANAGER_FRAME::OnChangeWatchedPaths )
107
108 // Drop files event
109 EVT_DROP_FILES( KICAD_MANAGER_FRAME::OnDropFiles )
110
111END_EVENT_TABLE()
112
113
114// See below the purpose of this include
115#include <wx/xml/xml.h>
116
117KICAD_MANAGER_FRAME::KICAD_MANAGER_FRAME( wxWindow* parent, const wxString& title,
118 const wxPoint& pos, const wxSize& size ) :
121 m_leftWin( nullptr ),
122 m_launcher( nullptr ),
123 m_mainToolBar( nullptr )
124{
125 m_active_project = false;
126 m_leftWinWidth = 250; // Default value
127 m_aboutTitle = "KiCad";
128
129 // JPC: A very ugly hack to fix an issue on Linux: if the wxbase315u_xml_gcc_custom.so is
130 // used **only** in PCM, it is not found in some cases at run time.
131 // So just use it in the main module to avoid a not found issue
132 // wxbase315u_xml_gcc_custom shared object when launching Kicad
133 wxXmlDocument dummy;
134
135 // Create the status line (bottom of the frame). Left half is for project name; right half
136 // is for Reporter (currently used by archiver/unarchiver and PCM).
137 CreateStatusBar( 2 );
138 GetStatusBar()->SetFont( KIUI::GetStatusFont( this ) );
139
140 // Give an icon
141 wxIcon icon;
142 wxIconBundle icon_bundle;
143
144 if( IsNightlyVersion())
145 {
146 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_nightly ) );
147 icon_bundle.AddIcon( icon );
148 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_nightly_32 ) );
149 icon_bundle.AddIcon( icon );
150 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_nightly_16 ) );
151 icon_bundle.AddIcon( icon );
152 }
153 else
154 {
155 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad ) );
156 icon_bundle.AddIcon( icon );
157 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_32 ) );
158 icon_bundle.AddIcon( icon );
159 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_16 ) );
160 icon_bundle.AddIcon( icon );
161 }
162
163 SetIcons( icon_bundle );
164
165 // Load the settings
166 LoadSettings( config() );
167
168 m_pcmButton = nullptr;
169 m_pcmUpdateCount = 0;
170 m_pcm = std::make_shared<PLUGIN_CONTENT_MANAGER>(
171 [this]( int aUpdateCount )
172 {
173 m_pcmUpdateCount = aUpdateCount;
174 CallAfter(
175 [this]()
176 {
177 updatePcmButtonBadge();
178 } );
179 },
180 [this]( const wxString aText )
181 {
182 CallAfter(
183 [aText, this]()
184 {
185 SetStatusText( aText, 1 );
186 } );
187 } );
188 m_pcm->SetRepositoryList( kicadSettings()->m_PcmRepositories );
189
190 // Left window: is the box which display tree project
191 m_leftWin = new PROJECT_TREE_PANE( this );
192
193 setupTools();
194 setupUIConditions();
195
196 m_launcher = new PANEL_KICAD_LAUNCHER( this );
197
198 RecreateBaseHToolbar();
199 ReCreateMenuBar();
200
201 m_auimgr.SetManagedWindow( this );
202 m_auimgr.SetFlags( wxAUI_MGR_LIVE_RESIZE );
203
204 m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Left()
205 .Layer( 2 ) );
206
207 // BestSize() does not always set the actual pane size of m_leftWin to the required value.
208 // It happens when m_leftWin is too large (roughly > 1/3 of the kicad manager frame width.
209 // (Well, BestSize() sets the best size... not the window size)
210 // A trick is to use MinSize() to set the required pane width,
211 // and after give a reasonable MinSize value
212 m_auimgr.AddPane( m_leftWin, EDA_PANE().Palette().Name( "ProjectTree" ).Left().Layer( 1 )
213 .Caption( _( "Project Files" ) ).PaneBorder( false )
214 .MinSize( m_leftWinWidth, -1 ).BestSize( m_leftWinWidth, -1 ) );
215
216 m_auimgr.AddPane( m_launcher, EDA_PANE().Canvas().Name( "Launcher" ).Center()
217 .Caption( _( "Editors" ) ).PaneBorder( false )
218 .MinSize( m_launcher->GetBestSize() ) );
219
220 m_auimgr.Update();
221
222 // Now the actual m_leftWin size is set, give it a reasonable min width
223 m_auimgr.GetPane( m_leftWin ).MinSize( 250, -1 );
224
225 wxSizer* mainSizer = GetSizer();
226
227 // Only fit the initial window size the first time KiCad is run.
228 if( mainSizer && config()->m_Window.state.size_x == 0 && config()->m_Window.state.size_y == 0 )
229 mainSizer->Fit( this );
230
231 if( ADVANCED_CFG::GetCfg().m_HideVersionFromTitle )
232 SetTitle( wxT( "KiCad" ) );
233 else
234 SetTitle( wxString( "KiCad " ) + GetMajorMinorVersion() );
235
236 // Do not let the messages window have initial focus
237 m_leftWin->SetFocus();
238
239 // Init for dropping files
242
243 // Gerber files
244 // Note that all gerber files are aliased as GerberFileExtension
248
249 // Eagle files import
250 m_acceptedExts.emplace( EagleSchematicFileExtension,
253
254 // Cadstar files import
255 m_acceptedExts.emplace( CadstarSchematicFileExtension,
258
259 DragAcceptFiles( true );
260
261 // Ensure the window is on top
262 Raise();
263}
264
265
267{
268 // Shutdown all running tools
269 if( m_toolManager )
271
272 m_pcm->StopBackgroundUpdate();
273
274 delete m_actions;
275 delete m_toolManager;
276 delete m_toolDispatcher;
277
278 m_auimgr.UnInit();
279}
280
281
283{
284 // Create the manager
286 m_toolManager->SetEnvironment( nullptr, nullptr, nullptr, config(), this );
288
290
291 // Attach the events to the tool dispatcher
293 Bind( wxEVT_CHAR_HOOK, &TOOL_DISPATCHER::DispatchWxEvent, m_toolDispatcher );
294
295 // Register tools
299}
300
301
303{
305
307
308 wxASSERT( manager );
309
310 auto activeProject =
311 [this] ( const SELECTION& )
312 {
313 return m_active_project;
314 };
315
316#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
317
318 ACTION_CONDITIONS activeProjectCond;
319 activeProjectCond.Enable( activeProject );
320
321 manager->SetConditions( ACTIONS::saveAs, activeProjectCond );
322 manager->SetConditions( KICAD_MANAGER_ACTIONS::closeProject, activeProjectCond );
323
324 // These are just here for text boxes, search boxes, etc. in places such as the standard
325 // file dialogs.
329
330 // TODO: Switch this to an action
332
333#undef ENABLE
334}
335
336
338{
339 return m_leftWin;
340}
341
342
344{
346 wxASSERT( ret );
347 return ret;
348}
349
350
352{
353 KICAD_SETTINGS* ret = dynamic_cast<KICAD_SETTINGS*>( config() );
354 wxASSERT( ret );
355 return ret;
356}
357
358
360{
361 return Pgm().GetSettingsManager().IsProjectOpen() ? Prj().GetProjectFullName() :
362 wxString( wxEmptyString );
363}
364
365
367{
368 wxFileName fn( GetProjectFileName() );
369
370 fn.SetExt( KiCadSchematicFileExtension );
371 return fn.GetFullPath();
372}
373
374
376{
377 wxFileName fn( GetProjectFileName() );
378
379 fn.SetExt( LegacySchematicFileExtension );
380 return fn.GetFullPath();
381}
382
383
385{
386 wxFileName fn( GetProjectFileName() );
387
388 fn.SetExt( PcbFileExtension );
389 return fn.GetFullPath();
390}
391
392
394{
395 wxFileName fn( GetProjectFileName() );
396
397 fn.SetExt( LegacyPcbFileExtension );
398 return fn.GetFullPath();
399}
400
401
403{
405}
406
407
409{
410 return PgmTop().SysSearch();
411}
412
413
415{
416 return PgmTop().GetHelpFileName();
417}
418
419
420void KICAD_MANAGER_FRAME::OnSize( wxSizeEvent& event )
421{
422 if( m_auimgr.GetManagedWindow() )
423 m_auimgr.Update();
424
425 PrintPrjInfo();
426
427 event.Skip();
428}
429
430
432{
433 // All fileNames are now in m_AcceptedFiles vector.
434 // Check if contains a project file name and load project.
435 // If not, open files in dedicated app.
436 for( const wxFileName& fileName : m_AcceptedFiles )
437 {
438 wxString ext = fileName.GetExt();
439
441 {
442 wxString fn = fileName.GetFullPath();
443 m_toolManager->RunAction( *m_acceptedExts.at( fileName.GetExt() ), true, &fn );
444
445 return;
446 }
447 }
448
449 // Then stock gerber files in gerberFiles and run action for other files.
450 wxString gerberFiles;
451
452 // Gerbview editor should be able to open Gerber and drill files
453 for( const wxFileName& fileName : m_AcceptedFiles )
454 {
455 wxString ext = fileName.GetExt();
456
457 if( ext == GerberJobFileExtension || ext == DrillFileExtension
458 || IsGerberFileExtension( ext ) )
459 {
460 gerberFiles += wxT( '\"' );
461 gerberFiles += fileName.GetFullPath() + wxT( '\"' );
462 gerberFiles = gerberFiles.Pad( 1 );
463 }
464 else
465 {
466 wxString fn = fileName.GetFullPath();
467 m_toolManager->RunAction( *m_acceptedExts.at( fileName.GetExt() ), true, &fn );
468 }
469 }
470
471 // Execute Gerbviewer
472 if( !gerberFiles.IsEmpty() )
473 {
474 wxString fullEditorName = FindKicadFile( GERBVIEW_EXE );
475
476 if( wxFileExists( fullEditorName ) )
477 {
478 wxString command = fullEditorName + " " + gerberFiles;
480 true, &command );
481 }
482 }
483}
484
485
486bool KICAD_MANAGER_FRAME::canCloseWindow( wxCloseEvent& aEvent )
487{
488 KICAD_SETTINGS* settings = kicadSettings();
490
491 // CloseProject will recursively ask all the open editors if they need to save changes.
492 // If any of them cancel then we need to cancel closing the KICAD_MANAGER_FRAME.
493 if( CloseProject( true ) )
494 {
495 // Don't propagate event to frames which have already been closed
496 aEvent.StopPropagation();
497
498 return true;
499 }
500 else
501 {
502 if( aEvent.CanVeto() )
503 aEvent.Veto();
504
505 return false;
506 }
507}
508
509
511{
512#ifdef _WINDOWS_
513 // For some obscure reason, on Windows, when killing Kicad from the Windows task manager
514 // if a editor frame (schematic, library, board editor or fp editor) is open and has
515 // some edition to save, OnCloseWindow is run twice *at the same time*, creating race
516 // conditions between OnCloseWindow() code.
517 // Therefore I added (JPC) a ugly hack to discard the second call (unwanted) during
518 // execution of the first call (only one call is right).
519 // Note also if there is no change made in editors, this behavior does not happen.
520 static std::atomic<unsigned int> lock_close_event( 0 );
521
522 if( ++lock_close_event > 1 ) // Skip extra calls
523 {
524 return;
525 }
526#endif
527
528 m_leftWin->Show( false );
529 Pgm().m_Quitting = true;
530
531 Destroy();
532
533#ifdef _WINDOWS_
534 lock_close_event = 0; // Reenable event management
535#endif
536}
537
538
539void KICAD_MANAGER_FRAME::OnExit( wxCommandEvent& event )
540{
541 Close( true );
542}
543
544
546{
547 if( !Kiway().PlayersClose( false ) )
548 return false;
549
550 // Save the project file for the currently loaded project.
551 if( m_active_project )
552 {
553 SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
554
556
557 if( aSave )
558 mgr.SaveProject();
559
560 m_active_project = false;
561 mgr.UnloadProject( &Prj() );
562 }
563
564 SetStatusText( "" );
565
567
568 return true;
569}
570
571
572void KICAD_MANAGER_FRAME::LoadProject( const wxFileName& aProjectFileName )
573{
574 // The project file should be valid by the time we get here or something has gone wrong.
575 if( !aProjectFileName.Exists() )
576 return;
577
578 // Any open KIFACE's must be closed if they are not part of the new project.
579 // (We never want a KIWAY_PLAYER open on a KIWAY that isn't in the same project.)
580 // User is prompted here to close those KIWAY_PLAYERs:
581 if( !CloseProject( true ) )
582 return;
583
584 m_active_project = true;
585
586 Pgm().GetSettingsManager().LoadProject( aProjectFileName.GetFullPath() );
587
588 LoadWindowState( aProjectFileName.GetFullName() );
589
590 if( aProjectFileName.IsDirWritable() )
591 SetMruPath( Prj().GetProjectPath() ); // Only set MRU path if we have write access. Why?
592
593 UpdateFileHistory( Prj().GetProjectFullName() );
594
596
597 // Rebuild the list of watched paths.
598 // however this is possible only when the main loop event handler is running,
599 // so we use it to run the rebuild function.
600 wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED, ID_INIT_WATCHED_PATHS );
601
602 wxPostEvent( this, cmd );
603
604 PrintPrjInfo();
605
606 KIPLATFORM::APP::RegisterApplicationRestart( aProjectFileName.GetFullPath() );
607 m_openSavedWindows = true;
608}
609
610
611void KICAD_MANAGER_FRAME::CreateNewProject( const wxFileName& aProjectFileName,
612 bool aCreateStubFiles )
613{
614 wxCHECK_RET( aProjectFileName.DirExists() && aProjectFileName.IsDirWritable(),
615 "Project folder must exist and be writable to create a new project." );
616
617 // If the project is legacy, convert it
618 if( !aProjectFileName.FileExists() )
619 {
620 wxFileName legacyPro( aProjectFileName );
621 legacyPro.SetExt( LegacyProjectFileExtension );
622
623 if( legacyPro.FileExists() )
624 {
625 GetSettingsManager()->LoadProject( legacyPro.GetFullPath() );
627
628 wxRemoveFile( legacyPro.GetFullPath() );
629 }
630 else
631 {
632 // Copy template project file from template folder.
633 wxString srcFileName = sys_search().FindValidPath( "kicad.kicad_pro" );
634
635 wxFileName destFileName( aProjectFileName );
636 destFileName.SetExt( ProjectFileExtension );
637
638 // Create a minimal project file if the template project file could not be copied
639 if( !wxFileName::FileExists( srcFileName )
640 || !wxCopyFile( srcFileName, destFileName.GetFullPath() ) )
641 {
642 wxFFile file( destFileName.GetFullPath(), "wb" );
643
644 if( file.IsOpened() )
645 file.Write( wxT( "{\n}\n") );
646
647 // wxFFile dtor will close the file
648 }
649 }
650 }
651
652 // Create a "stub" for a schematic root sheet and a board if requested.
653 // It will avoid messages from the schematic editor or the board editor to create a new file
654 // And forces the user to create main files under the right name for the project manager
655 if( aCreateStubFiles )
656 {
657 wxFileName fn( aProjectFileName.GetFullPath() );
658 fn.SetExt( KiCadSchematicFileExtension );
659
660 // If a <project>.kicad_sch file does not exist, create a "stub" file ( minimal schematic
661 // file ).
662 if( !fn.FileExists() )
663 {
664 wxFFile file( fn.GetFullPath(), "wb" );
665
666 if( file.IsOpened() )
667 file.Write( wxString::Format( "(kicad_sch (version %d) (generator eeschema)\n"
668 " (paper \"A4\")\n (lib_symbols)\n"
669 " (symbol_instances)\n)\n",
671
672 // wxFFile dtor will close the file
673 }
674
675 // If a <project>.kicad_pcb or <project>.brd file does not exist,
676 // create a .kicad_pcb "stub" file
677 fn.SetExt( KiCadPcbFileExtension );
678 wxFileName leg_fn( fn );
679 leg_fn.SetExt( LegacyPcbFileExtension );
680
681 if( !fn.FileExists() && !leg_fn.FileExists() )
682 {
683 wxFFile file( fn.GetFullPath(), "wb" );
684
685 if( file.IsOpened() )
686 // Create a small dummy file as a stub for pcbnew:
687 file.Write( wxString::Format( "(kicad_pcb (version %d) (generator pcbnew)\n)",
689
690 // wxFFile dtor will close the file
691 }
692 }
693
694 UpdateFileHistory( aProjectFileName.GetFullPath() );
695
696 m_openSavedWindows = true;
697}
698
699
701{
702 // show all files in file dialog (in Kicad all files are editable texts):
703 wxString wildcard = AllFilesWildcard();
704
705 wxString default_dir = Prj().GetProjectPath();
706
707 wxFileDialog dlg( this, _( "Load File to Edit" ), default_dir,
708 wxEmptyString, wildcard, wxFD_OPEN );
709
710 if( dlg.ShowModal() == wxID_CANCEL )
711 return;
712
713 wxString filename = dlg.GetPath();
714
715 if( !dlg.GetPath().IsEmpty() && !Pgm().GetTextEditor().IsEmpty() )
717}
718
719
721{
722 // open project directory in host OS's file explorer
723 LaunchExternal( Prj().GetProjectPath() );
724}
725
726
728{
730}
731
732
733void KICAD_MANAGER_FRAME::language_change( wxCommandEvent& event )
734{
735 int id = event.GetId();
736 Kiway().SetLanguage( id );
737}
738
739
741{
742 // call my base class
744
745 // tooltips in toolbars
748
749 PrintPrjInfo();
750}
751
752
753void KICAD_MANAGER_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
754{
755 EDA_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
756
757 if( aEnvVarsChanged )
758 {
759 m_pcm->ReadEnvVar();
760 }
761}
762
763
765{
766 wxString file = GetProjectFileName();
767 wxString title;
768
769 if( !file.IsEmpty() )
770 {
771 wxFileName fn( file );
772
773 title = fn.GetName();
774
775 if( !fn.IsDirWritable() )
776 title += wxS( " " ) + _( "[Read Only]" );
777 }
778 else
779 {
780 title = _( "[no project loaded]" );
781 }
782
783 if( ADVANCED_CFG::GetCfg().m_HideVersionFromTitle )
784 title += wxT( " \u2014 " ) + wxString( wxS( "KiCad" ) );
785 else
786 title += wxT( " \u2014 " ) + wxString( wxS( "KiCad " ) ) + GetMajorMinorVersion();
787
788 SetTitle( title );
789}
790
791
793{
795
796 auto settings = dynamic_cast<KICAD_SETTINGS*>( aCfg );
797
798 wxCHECK( settings, /*void*/ );
799
800 m_leftWinWidth = settings->m_LeftWinWidth;
801}
802
803
805{
807
808 auto settings = dynamic_cast<KICAD_SETTINGS*>( aCfg );
809
810 wxCHECK( settings, /*void*/);
811
812 settings->m_LeftWinWidth = m_leftWin->GetSize().x;
813}
814
815
817{
818 // wxStatusBar's wxELLIPSIZE_MIDDLE flag doesn't work (at least on Mac).
819
820 wxString status = wxString::Format( _( "Project: %s" ), Prj().GetProjectFullName() );
821 wxStatusBar* statusBar = GetStatusBar();
822 int width = statusBar->GetSize().GetWidth() / 2;
823
824 if( width > 20 )
825 {
826 wxClientDC dc( this );
827 status = wxControl::Ellipsize( status, dc, wxELLIPSIZE_MIDDLE, width );
828 }
829
830 SetStatusText( status );
831}
832
833
835{
836 return m_active_project;
837}
838
839
840void KICAD_MANAGER_FRAME::OnIdle( wxIdleEvent& aEvent )
841{
847 if( !m_openSavedWindows )
848 return;
849
850 m_openSavedWindows = false;
851
852 if( Pgm().GetCommonSettings()->m_Session.remember_open_files )
853 {
854 int previousOpenCount =
855 std::count_if( Prj().GetLocalSettings().m_files.begin(),
856 Prj().GetLocalSettings().m_files.end(),
857 [&]( const PROJECT_FILE_STATE& f )
858 {
859 return !f.fileName.EndsWith( ProjectFileExtension ) && f.open;
860 } );
861
862 if( previousOpenCount > 0 )
863 {
864 APP_PROGRESS_DIALOG progressReporter( _( "Restoring session" ), wxEmptyString,
865 previousOpenCount, this );
866
867 int i = 0;
868
869 for( const PROJECT_FILE_STATE& file : Prj().GetLocalSettings().m_files )
870 {
871 if( file.open )
872 {
873 progressReporter.Update( i++,
874 wxString::Format( _( "Restoring '%s'" ), file.fileName ) );
875
876 wxFileName fn( file.fileName );
877
878 if( fn.GetExt() == LegacySchematicFileExtension
879 || fn.GetExt() == KiCadSchematicFileExtension )
880 {
882 }
883 else if( fn.GetExt() == LegacyPcbFileExtension
884 || fn.GetExt() == KiCadPcbFileExtension )
885 {
887 }
888 }
889
890 wxYield();
891 }
892 }
893 }
894
895 // clear file states regardless if we opened windows or not due to setting
897
898 KICAD_SETTINGS* settings = kicadSettings();
899
900 if( settings->m_updateCheck == KICAD_SETTINGS::UPDATE_CHECK::UNINITIALIZED )
901 {
902 if( wxMessageBox( _( "Would you like to automatically check for plugin updates on startup?" ),
903 _( "Check for updates" ), wxICON_QUESTION | wxYES_NO, this )
904 == wxYES )
905 {
906 settings->m_updateCheck = KICAD_SETTINGS::UPDATE_CHECK::ALLOWED;
907 settings->m_PcmUpdateCheck = true;
908 }
909 else
910 {
911 settings->m_updateCheck = KICAD_SETTINGS::UPDATE_CHECK::NOT_ALLOWED;
912 settings->m_PcmUpdateCheck = false;
913 }
914 }
915
917 && settings->m_PcmUpdateCheck )
918 {
919 m_pcm->RunBackgroundUpdate();
920 }
921}
922
923
925{
926 m_pcmButton = aButton;
927
929}
930
931
933{
934 if( m_pcmButton )
935 {
936 if( m_pcmUpdateCount > 0 )
937 {
938 m_pcmButton->SetShowBadge( true );
940 }
941 else
942 {
943 m_pcmButton->SetShowBadge( false );
944 }
945
946 m_pcmButton->Refresh();
947 }
948}
constexpr EDA_IU_SCALE unityScale
Definition: base_units.h:112
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:106
@ icon_kicad_16
@ icon_kicad_nightly
@ icon_kicad_32
@ 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:69
static TOOL_ACTION saveAs
Definition: actions.h:52
static TOOL_ACTION copy
Definition: actions.h:68
static TOOL_ACTION cut
Definition: actions.h:67
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.
Definition: app_settings.h:110
A bitmap button widget that behaves like an AUI toolbar item's button when it is drawn.
Definition: bitmap_button.h:41
void SetBadgeText(const wxString &aText)
void SetShowBadge(bool aShowBadge)
Handle actions that are shared between different applications.
The base frame for deriving all KiCad main window classes.
void LoadWindowState(const wxString &aFileName)
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
void UpdateFileHistory(const wxString &FullFileName, FILE_HISTORY *aFileHistory=nullptr)
Update the list of recently opened files.
wxAuiManager m_auimgr
virtual void LoadSettings(APP_SETTINGS_BASE *aCfg)
Load common frame parameters from a configuration file.
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
std::map< const wxString, TOOL_ACTION * > m_acceptedExts
Associates files 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)
virtual void RegisterUIUpdateHandler(int aID, const ACTION_CONDITIONS &aConditions) override
Register a UI update handler for the control with ID aID.
Specialization of the wxAuiPaneInfo class for KiCad panels.
static TOOL_ACTION viewDroppedGerbers
static TOOL_ACTION editPCB
static TOOL_ACTION loadProject
static TOOL_ACTION editSchematic
static TOOL_ACTION openTextEditor
static TOOL_ACTION closeProject
static TOOL_ACTION importNonKicadProj
Handle actions in the kicad manager frame.
The main KiCad project manager frame.
std::shared_ptr< PLUGIN_CONTENT_MANAGER > m_pcm
void language_change(wxCommandEvent &event)
void SetPcmButton(BITMAP_BUTTON *aButton)
void doCloseWindow() override
void CreateNewProject(const wxFileName &aProjectFileName, bool aCreateStubFiles=true)
Creates a new project by setting up and initial project, schematic, and board files.
void OnUnarchiveFiles(wxCommandEvent &event)
const SEARCH_STACK & sys_search() override
Return a SEARCH_STACK pertaining to entire program.
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.
PROJECT_TREE_PANE * m_leftWin
const wxString GetProjectFileName() const
void OnBrowseInFileExplorer(wxCommandEvent &event)
KICAD_SETTINGS * kicadSettings() const
const wxString SchFileName()
void OnImportEagleFiles(wxCommandEvent &event)
Open dialog to import Eagle schematic and board files.
void OnExit(wxCommandEvent &event)
void LoadProject(const wxFileName &aProjectFileName)
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 DoWithAcceptedFiles() override
Execute action on accepted dropped file.
void OnOpenFileInTextEditor(wxCommandEvent &event)
APP_SETTINGS_BASE * config() const override
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
const wxString PcbLegacyFileName()
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;.
void RecreateBaseHToolbar()
(Re)Create the horizontal toolbar
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
void OnIdle(wxIdleEvent &event)
void PrintPrjInfo()
Prints the current working directory name and the project name on the text panel.
void OnArchiveFiles(wxCommandEvent &event)
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
wxString help_name() override
const wxString PcbFileName()
int m_updateCheck
General setting for various update checks.
std::vector< wxString > m_OpenProjects
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.
Definition: kiway_holder.h:53
virtual void SetLanguage(int aLanguage)
Change the language and then calls ShowChangedLanguage() on all #KIWAY_PLAYERs.
Definition: kiway.cpp:507
static REPORTER & GetInstance()
Definition: reporter.cpp:117
wxString GetHelpFileName()
Definition: pgm_kicad.h:59
SEARCH_STACK & SysSearch()
Definition: pgm_kicad.h:57
APP_SETTINGS_BASE * PgmSettings()
Definition: pgm_kicad.h:55
PROJECT_TREE_PANE Window to display the tree files.
void EmptyTreePrj()
Delete all m_TreeProject entries.
void ReCreateTreePrj()
Create or modify the tree showing project file names.
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
Definition: project.cpp:120
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:126
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
Definition: project.h:155
Look for files in a number of paths.
Definition: search_stack.h:42
static bool ShowNever(const SELECTION &aSelection)
Always returns false.
bool SaveProject(const wxString &aFullPath=wxEmptyString, PROJECT *aProject=nullptr)
Saves a loaded project.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Loads a project or sets up a new project with a specified path.
bool UnloadProject(PROJECT *aProject, bool aSave=true)
Saves, unloads and unregisters the given PROJECT.
std::vector< wxString > GetOpenProjects() const
bool TriggerBackupIfNeeded(REPORTER &aReporter) const
Calls BackupProject if a new backup is needed according to the current backup policy.
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:170
TOOL_DISPATCHER * m_toolDispatcher
Definition: tools_holder.h:172
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
ACTIONS * m_actions
Definition: tools_holder.h:171
virtual void DispatchWxEvent(wxEvent &aEvent)
Process wxEvents (mostly UI events), translate them to TOOL_EVENTs, and make tools handle those.
Master controller class:
Definition: tool_manager.h:55
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:142
ACTION_MANAGER * GetActionManager() const
Definition: tool_manager.h:196
void RegisterTool(TOOL_BASE *aTool)
Add a tool to the manager set and sets it up.
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, APP_SETTINGS_BASE *aSettings, TOOLS_HOLDER *aFrame)
Set the work environment (model, view, view controls and the parent window).
void InitTools()
Initializes all registered tools.
void ShutdownAllTools()
Shutdown all tools with a currently registered event loop in this tool manager by waking them up with...
#define _(s)
Base window classes and related definitions.
#define KICAD_DEFAULT_DRAWFRAME_STYLE
#define KICAD_MANAGER_FRAME_NAME
KiCad executable names.
const wxString GERBVIEW_EXE
@ KICAD_MAIN_FRAME_T
Definition: frame_type.h:64
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:52
const std::string LegacyPcbFileExtension
const std::string CadstarPcbFileExtension
const std::string LegacySchematicFileExtension
const std::string GerberJobFileExtension
const std::string DrillFileExtension
const std::string EagleSchematicFileExtension
const std::string LegacyProjectFileExtension
const std::string KiCadPcbFileExtension
bool IsGerberFileExtension(const wxString &ext)
#define PcbFileExtension
const std::string ProjectFileExtension
const std::string EaglePcbFileExtension
const std::string CadstarSchematicFileExtension
const std::string KiCadSchematicFileExtension
const std::string GerberFileExtension
wxString AllFilesWildcard()
@ ID_FILE_LIST_CLEAR
Definition: id.h:87
@ ID_LANGUAGE_CHOICE
Definition: id.h:105
@ ID_FILEMAX
Definition: id.h:85
@ ID_LANGUAGE_CHOICE_END
Definition: id.h:141
@ ID_FILE1
Definition: id.h:84
PGM_KICAD & PgmTop()
Definition: kicad.cpp:88
IDs used in KiCad main frame foe menuitems and tools.
@ ID_IMPORT_EAGLE_PROJECT
Definition: kicad_id.h:71
@ ID_READ_ZIP_ARCHIVE
Definition: kicad_id.h:69
@ ID_SAVE_AND_ZIP_FILES
Definition: kicad_id.h:68
@ ID_INIT_WATCHED_PATHS
Definition: kicad_id.h:70
@ ID_IMPORT_CADSTAR_ARCHIVE_PROJECT
Definition: kicad_id.h:72
@ ID_EDIT_LOCAL_FILE_IN_TEXT_EDITOR
Definition: kicad_id.h:66
@ ID_BROWSE_IN_FILE_EXPLORER
Definition: kicad_id.h:67
EVT_MENU_RANGE(ID_LANGUAGE_CHOICE, ID_LANGUAGE_CHOICE_END, KICAD_MANAGER_FRAME::language_change) KICAD_MANAGER_FRAME
#define ENABLE(x)
KIWAY Kiway
bool LaunchExternal(const wxString &aPath)
Launches the given file or folder in the host OS.
Definition: launch_ext.cpp:25
bool RegisterApplicationRestart(const wxString &aCommandLine)
Registers the application for restart with the OS with the given command line string to pass as args.
Definition: gtk/app.cpp:58
STATE GetPolicyState(const wxString &aKey)
Definition: gtk/policy.cpp:25
wxFont GetStatusFont(wxWindow *aWindow)
Definition: ui_common.cpp:132
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
Definition: pcb_plugin.h:133
#define POLICY_KEY_PCM
Definition: policy_keys.h:29
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
#define SEXPR_SCHEMATIC_FILE_VERSION
Schematic file version.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111
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)
Definition of file extensions used in Kicad.