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 <filehistory.h>
39#include <policy_keys.h>
40#include <gestfich.h>
41#include <kiplatform/app.h>
42#include <kiplatform/policy.h>
43#include <kicad_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 KICAD_IS_NIGHTLY
145 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_nightly ) );
146 icon_bundle.AddIcon( icon );
147 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_nightly_32 ) );
148 icon_bundle.AddIcon( icon );
149 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_nightly_16 ) );
150 icon_bundle.AddIcon( icon );
151#else
152 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad ) );
153 icon_bundle.AddIcon( icon );
154 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_32 ) );
155 icon_bundle.AddIcon( icon );
156 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad_16 ) );
157 icon_bundle.AddIcon( icon );
158#endif
159
160 SetIcons( icon_bundle );
161
162 // Load the settings
163 LoadSettings( config() );
164
165 m_pcmButton = nullptr;
166 m_pcmUpdateCount = 0;
167 m_pcm = std::make_shared<PLUGIN_CONTENT_MANAGER>(
168 [this]( int aUpdateCount )
169 {
170 m_pcmUpdateCount = aUpdateCount;
171 CallAfter(
172 [this]()
173 {
174 updatePcmButtonBadge();
175 } );
176 },
177 [this]( const wxString aText )
178 {
179 CallAfter(
180 [aText, this]()
181 {
182 SetStatusText( aText, 1 );
183 } );
184 } );
185 m_pcm->SetRepositoryList( kicadSettings()->m_PcmRepositories );
186
187 // Left window: is the box which display tree project
188 m_leftWin = new PROJECT_TREE_PANE( this );
189
190 setupTools();
191 setupUIConditions();
192
193 m_launcher = new PANEL_KICAD_LAUNCHER( this );
194
195 RecreateBaseHToolbar();
196 ReCreateMenuBar();
197
198 m_auimgr.SetManagedWindow( this );
199 m_auimgr.SetFlags( wxAUI_MGR_LIVE_RESIZE );
200
201 m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Left()
202 .Layer( 2 ) );
203
204 // BestSize() does not always set the actual pane size of m_leftWin to the required value.
205 // It happens when m_leftWin is too large (roughly > 1/3 of the kicad manager frame width.
206 // (Well, BestSize() sets the best size... not the window size)
207 // A trick is to use MinSize() to set the required pane width,
208 // and after give a reasonable MinSize value
209 m_auimgr.AddPane( m_leftWin, EDA_PANE().Palette().Name( "ProjectTree" ).Left().Layer( 1 )
210 .Caption( _( "Project Files" ) ).PaneBorder( false )
211 .MinSize( m_leftWinWidth, -1 ).BestSize( m_leftWinWidth, -1 ) );
212
213 m_auimgr.AddPane( m_launcher, EDA_PANE().Canvas().Name( "Launcher" ).Center()
214 .Caption( _( "Editors" ) ).PaneBorder( false )
215 .MinSize( m_launcher->GetBestSize() ) );
216
217 m_auimgr.Update();
218
219 // Now the actual m_leftWin size is set, give it a reasonable min width
220 m_auimgr.GetPane( m_leftWin ).MinSize( 250, -1 );
221
222 wxSizer* mainSizer = GetSizer();
223
224 // Only fit the initial window size the first time KiCad is run.
225 if( mainSizer && config()->m_Window.state.size_x == 0 && config()->m_Window.state.size_y == 0 )
226 mainSizer->Fit( this );
227
228 if( ADVANCED_CFG::GetCfg().m_HideVersionFromTitle )
229 SetTitle( wxT( "KiCad" ) );
230 else
231 SetTitle( wxString( "KiCad " ) + GetMajorMinorVersion() );
232
233 // Do not let the messages window have initial focus
234 m_leftWin->SetFocus();
235
236 // Init for dropping files
239
240 // Gerber files
241 // Note that all gerber files are aliased as GerberFileExtension
245
246 // Eagle files import
247 m_acceptedExts.emplace( EagleSchematicFileExtension,
250
251 // Cadstar files import
252 m_acceptedExts.emplace( CadstarSchematicFileExtension,
255
256 DragAcceptFiles( true );
257
258 // Ensure the window is on top
259 Raise();
260}
261
262
264{
265 // Shutdown all running tools
266 if( m_toolManager )
268
269 m_pcm->StopBackgroundUpdate();
270
271 delete m_actions;
272 delete m_toolManager;
273 delete m_toolDispatcher;
274
275 m_auimgr.UnInit();
276}
277
278
280{
281 // Create the manager
283 m_toolManager->SetEnvironment( nullptr, nullptr, nullptr, config(), this );
285
287
288 // Attach the events to the tool dispatcher
290 Bind( wxEVT_CHAR_HOOK, &TOOL_DISPATCHER::DispatchWxEvent, m_toolDispatcher );
291
292 // Register tools
296}
297
298
300{
302
304
305 wxASSERT( manager );
306
307 auto activeProject =
308 [this] ( const SELECTION& )
309 {
310 return m_active_project;
311 };
312
313#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
314
315 ACTION_CONDITIONS activeProjectCond;
316 activeProjectCond.Enable( activeProject );
317
318 manager->SetConditions( ACTIONS::saveAs, activeProjectCond );
319 manager->SetConditions( KICAD_MANAGER_ACTIONS::closeProject, activeProjectCond );
320
321 // These are just here for text boxes, search boxes, etc. in places such as the standard
322 // file dialogs.
326
327 // TODO: Switch this to an action
329
330#undef ENABLE
331}
332
333
335{
336 return m_leftWin;
337}
338
339
341{
343 wxASSERT( ret );
344 return ret;
345}
346
347
349{
350 KICAD_SETTINGS* ret = dynamic_cast<KICAD_SETTINGS*>( config() );
351 wxASSERT( ret );
352 return ret;
353}
354
355
357{
358 return Pgm().GetSettingsManager().IsProjectOpen() ? Prj().GetProjectFullName() :
359 wxString( wxEmptyString );
360}
361
362
364{
365 wxFileName fn( GetProjectFileName() );
366
367 fn.SetExt( KiCadSchematicFileExtension );
368 return fn.GetFullPath();
369}
370
371
373{
374 wxFileName fn( GetProjectFileName() );
375
376 fn.SetExt( LegacySchematicFileExtension );
377 return fn.GetFullPath();
378}
379
380
382{
383 wxFileName fn( GetProjectFileName() );
384
385 fn.SetExt( PcbFileExtension );
386 return fn.GetFullPath();
387}
388
389
391{
392 wxFileName fn( GetProjectFileName() );
393
394 fn.SetExt( LegacyPcbFileExtension );
395 return fn.GetFullPath();
396}
397
398
400{
402}
403
404
406{
407 return PgmTop().SysSearch();
408}
409
410
412{
413 return PgmTop().GetHelpFileName();
414}
415
416
417void KICAD_MANAGER_FRAME::OnSize( wxSizeEvent& event )
418{
419 if( m_auimgr.GetManagedWindow() )
420 m_auimgr.Update();
421
422 PrintPrjInfo();
423
424 event.Skip();
425}
426
427
429{
430 // All fileNames are now in m_AcceptedFiles vector.
431 // Check if contains a project file name and load project.
432 // If not, open files in dedicated app.
433 for( const wxFileName& fileName : m_AcceptedFiles )
434 {
435 wxString ext = fileName.GetExt();
436
438 {
439 wxString fn = fileName.GetFullPath();
440 m_toolManager->RunAction( *m_acceptedExts.at( fileName.GetExt() ), true, &fn );
441
442 return;
443 }
444 }
445
446 // Then stock gerber files in gerberFiles and run action for other files.
447 wxString gerberFiles;
448
449 // Gerbview editor should be able to open Gerber and drill files
450 for( const wxFileName& fileName : m_AcceptedFiles )
451 {
452 wxString ext = fileName.GetExt();
453
454 if( ext == GerberJobFileExtension || ext == DrillFileExtension
455 || IsGerberFileExtension( ext ) )
456 {
457 gerberFiles += wxT( '\"' );
458 gerberFiles += fileName.GetFullPath() + wxT( '\"' );
459 gerberFiles = gerberFiles.Pad( 1 );
460 }
461 else
462 {
463 wxString fn = fileName.GetFullPath();
464 m_toolManager->RunAction( *m_acceptedExts.at( fileName.GetExt() ), true, &fn );
465 }
466 }
467
468 // Execute Gerbviewer
469 if( !gerberFiles.IsEmpty() )
470 {
471 wxString fullEditorName = FindKicadFile( GERBVIEW_EXE );
472
473 if( wxFileExists( fullEditorName ) )
474 {
475 wxString command = fullEditorName + " " + gerberFiles;
477 true, &command );
478 }
479 }
480}
481
482
483bool KICAD_MANAGER_FRAME::canCloseWindow( wxCloseEvent& aEvent )
484{
485 KICAD_SETTINGS* settings = kicadSettings();
487
488 // CloseProject will recursively ask all the open editors if they need to save changes.
489 // If any of them cancel then we need to cancel closing the KICAD_MANAGER_FRAME.
490 if( CloseProject( true ) )
491 {
492 // Don't propagate event to frames which have already been closed
493 aEvent.StopPropagation();
494
495 return true;
496 }
497 else
498 {
499 if( aEvent.CanVeto() )
500 aEvent.Veto();
501
502 return false;
503 }
504}
505
506
508{
509#ifdef _WINDOWS_
510 // For some obscure reason, on Windows, when killing Kicad from the Windows task manager
511 // if a editor frame (schematic, library, board editor or fp editor) is open and has
512 // some edition to save, OnCloseWindow is run twice *at the same time*, creating race
513 // conditions between OnCloseWindow() code.
514 // Therefore I added (JPC) a ugly hack to discard the second call (unwanted) during
515 // execution of the first call (only one call is right).
516 // Note also if there is no change made in editors, this behavior does not happen.
517 static std::atomic<unsigned int> lock_close_event( 0 );
518
519 if( ++lock_close_event > 1 ) // Skip extra calls
520 {
521 return;
522 }
523#endif
524
525 m_leftWin->Show( false );
526 Pgm().m_Quitting = true;
527
528 Destroy();
529
530#ifdef _WINDOWS_
531 lock_close_event = 0; // Reenable event management
532#endif
533}
534
535
536void KICAD_MANAGER_FRAME::OnExit( wxCommandEvent& event )
537{
538 Close( true );
539}
540
541
543{
544 if( !Kiway().PlayersClose( false ) )
545 return false;
546
547 // Save the project file for the currently loaded project.
548 if( m_active_project )
549 {
550 SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
551
553
554 if( aSave )
555 mgr.SaveProject();
556
557 m_active_project = false;
558 mgr.UnloadProject( &Prj() );
559 }
560
561 SetStatusText( "" );
562
564
565 return true;
566}
567
568
569void KICAD_MANAGER_FRAME::LoadProject( const wxFileName& aProjectFileName )
570{
571 // The project file should be valid by the time we get here or something has gone wrong.
572 if( !aProjectFileName.Exists() )
573 return;
574
575 // Any open KIFACE's must be closed if they are not part of the new project.
576 // (We never want a KIWAY_PLAYER open on a KIWAY that isn't in the same project.)
577 // User is prompted here to close those KIWAY_PLAYERs:
578 if( !CloseProject( true ) )
579 return;
580
581 m_active_project = true;
582
583 Pgm().GetSettingsManager().LoadProject( aProjectFileName.GetFullPath() );
584
585 LoadWindowState( aProjectFileName.GetFullName() );
586
587 if( aProjectFileName.IsDirWritable() )
588 SetMruPath( Prj().GetProjectPath() ); // Only set MRU path if we have write access. Why?
589
590 UpdateFileHistory( Prj().GetProjectFullName() );
591
593
594 // Rebuild the list of watched paths.
595 // however this is possible only when the main loop event handler is running,
596 // so we use it to run the rebuild function.
597 wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED, ID_INIT_WATCHED_PATHS );
598
599 wxPostEvent( this, cmd );
600
601 PrintPrjInfo();
602
603 KIPLATFORM::APP::RegisterApplicationRestart( aProjectFileName.GetFullPath() );
604 m_openSavedWindows = true;
605}
606
607
608void KICAD_MANAGER_FRAME::CreateNewProject( const wxFileName& aProjectFileName,
609 bool aCreateStubFiles )
610{
611 wxCHECK_RET( aProjectFileName.DirExists() && aProjectFileName.IsDirWritable(),
612 "Project folder must exist and be writable to create a new project." );
613
614 // If the project is legacy, convert it
615 if( !aProjectFileName.FileExists() )
616 {
617 wxFileName legacyPro( aProjectFileName );
618 legacyPro.SetExt( LegacyProjectFileExtension );
619
620 if( legacyPro.FileExists() )
621 {
622 GetSettingsManager()->LoadProject( legacyPro.GetFullPath() );
624
625 wxRemoveFile( legacyPro.GetFullPath() );
626 }
627 else
628 {
629 // Copy template project file from template folder.
630 wxString srcFileName = sys_search().FindValidPath( "kicad.kicad_pro" );
631
632 wxFileName destFileName( aProjectFileName );
633 destFileName.SetExt( ProjectFileExtension );
634
635 // Create a minimal project file if the template project file could not be copied
636 if( !wxFileName::FileExists( srcFileName )
637 || !wxCopyFile( srcFileName, destFileName.GetFullPath() ) )
638 {
639 wxFFile file( destFileName.GetFullPath(), "wb" );
640
641 if( file.IsOpened() )
642 file.Write( wxT( "{\n}\n") );
643
644 // wxFFile dtor will close the file
645 }
646 }
647 }
648
649 // Create a "stub" for a schematic root sheet and a board if requested.
650 // It will avoid messages from the schematic editor or the board editor to create a new file
651 // And forces the user to create main files under the right name for the project manager
652 if( aCreateStubFiles )
653 {
654 wxFileName fn( aProjectFileName.GetFullPath() );
655 fn.SetExt( KiCadSchematicFileExtension );
656
657 // If a <project>.kicad_sch file does not exist, create a "stub" file ( minimal schematic
658 // file ).
659 if( !fn.FileExists() )
660 {
661 wxFFile file( fn.GetFullPath(), "wb" );
662
663 if( file.IsOpened() )
664 file.Write( wxString::Format( "(kicad_sch (version %d) (generator eeschema)\n"
665 " (paper \"A4\")\n (lib_symbols)\n"
666 " (symbol_instances)\n)\n",
668
669 // wxFFile dtor will close the file
670 }
671
672 // If a <project>.kicad_pcb or <project>.brd file does not exist,
673 // create a .kicad_pcb "stub" file
674 fn.SetExt( KiCadPcbFileExtension );
675 wxFileName leg_fn( fn );
676 leg_fn.SetExt( LegacyPcbFileExtension );
677
678 if( !fn.FileExists() && !leg_fn.FileExists() )
679 {
680 wxFFile file( fn.GetFullPath(), "wb" );
681
682 if( file.IsOpened() )
683 // Create a small dummy file as a stub for pcbnew:
684 file.Write( wxString::Format( "(kicad_pcb (version %d) (generator pcbnew)\n)",
686
687 // wxFFile dtor will close the file
688 }
689 }
690
691 UpdateFileHistory( aProjectFileName.GetFullPath() );
692
693 m_openSavedWindows = true;
694}
695
696
698{
699 // show all files in file dialog (in Kicad all files are editable texts):
700 wxString wildcard = AllFilesWildcard();
701
702 wxString default_dir = Prj().GetProjectPath();
703
704 wxFileDialog dlg( this, _( "Load File to Edit" ), default_dir,
705 wxEmptyString, wildcard, wxFD_OPEN );
706
707 if( dlg.ShowModal() == wxID_CANCEL )
708 return;
709
710 wxString filename = wxT( "\"" );
711 filename += dlg.GetPath() + wxT( "\"" );
712
713 if( !dlg.GetPath().IsEmpty() && !Pgm().GetTextEditor().IsEmpty() )
715}
716
717
719{
720 // open project directory in host OS's file explorer
721 LaunchExternal( Prj().GetProjectPath() );
722}
723
724
726{
728}
729
730
731void KICAD_MANAGER_FRAME::language_change( wxCommandEvent& event )
732{
733 int id = event.GetId();
734 Kiway().SetLanguage( id );
735}
736
737
739{
740 // call my base class
742
743 // tooltips in toolbars
746
747 PrintPrjInfo();
748}
749
750
751void KICAD_MANAGER_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
752{
753 EDA_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
754
755 if( aEnvVarsChanged )
756 {
757 m_pcm->ReadEnvVar();
758 }
759}
760
761
763{
764 wxString file = GetProjectFileName();
765 wxString title;
766
767 if( !file.IsEmpty() )
768 {
769 wxFileName fn( file );
770
771 title = fn.GetName();
772
773 if( !fn.IsDirWritable() )
774 title += wxS( " " ) + _( "[Read Only]" );
775 }
776 else
777 {
778 title = _( "[no project loaded]" );
779 }
780
781 if( ADVANCED_CFG::GetCfg().m_HideVersionFromTitle )
782 title += wxT( " \u2014 " ) + wxString( "KiCad" );
783 else
784 title += wxT( " \u2014 " ) + wxString( "KiCad " ) + GetMajorMinorVersion();
785
786 SetTitle( title );
787}
788
789
791{
793
794 auto settings = dynamic_cast<KICAD_SETTINGS*>( aCfg );
795
796 wxCHECK( settings, /*void*/ );
797
798 m_leftWinWidth = settings->m_LeftWinWidth;
799}
800
801
803{
805
806 auto settings = dynamic_cast<KICAD_SETTINGS*>( aCfg );
807
808 wxCHECK( settings, /*void*/);
809
810 settings->m_LeftWinWidth = m_leftWin->GetSize().x;
811}
812
813
815{
816 // wxStatusBar's wxELLIPSIZE_MIDDLE flag doesn't work (at least on Mac).
817
818 wxString status = wxString::Format( _( "Project: %s" ), Prj().GetProjectFullName() );
819 wxStatusBar* statusBar = GetStatusBar();
820 int width = statusBar->GetSize().GetWidth() / 2;
821
822 if( width > 20 )
823 {
824 wxClientDC dc( this );
825 status = wxControl::Ellipsize( status, dc, wxELLIPSIZE_MIDDLE, width );
826 }
827
828 SetStatusText( status );
829}
830
831
833{
834 return m_active_project;
835}
836
837
838void KICAD_MANAGER_FRAME::OnIdle( wxIdleEvent& aEvent )
839{
845 if( !m_openSavedWindows )
846 return;
847
848 m_openSavedWindows = false;
849
850 if( Pgm().GetCommonSettings()->m_Session.remember_open_files )
851 {
852 int previousOpenCount =
853 std::count_if( Prj().GetLocalSettings().m_files.begin(),
854 Prj().GetLocalSettings().m_files.end(),
855 [&]( const PROJECT_FILE_STATE& f )
856 {
857 return !f.fileName.EndsWith( ProjectFileExtension ) && f.open;
858 } );
859
860 if( previousOpenCount > 0 )
861 {
862 APP_PROGRESS_DIALOG progressReporter( _( "Restoring session" ), wxEmptyString,
863 previousOpenCount, this );
864
865 int i = 0;
866
867 for( const PROJECT_FILE_STATE& file : Prj().GetLocalSettings().m_files )
868 {
869 if( file.open )
870 {
871 progressReporter.Update( i++,
872 wxString::Format( _( "Restoring '%s'" ), file.fileName ) );
873
874 wxFileName fn( file.fileName );
875
876 if( fn.GetExt() == LegacySchematicFileExtension
877 || fn.GetExt() == KiCadSchematicFileExtension )
878 {
880 }
881 else if( fn.GetExt() == LegacyPcbFileExtension
882 || fn.GetExt() == KiCadPcbFileExtension )
883 {
885 }
886 }
887
888 wxYield();
889 }
890 }
891 }
892
893 // clear file states regardless if we opened windows or not due to setting
895
896 KICAD_SETTINGS* settings = kicadSettings();
897
898 if( settings->m_updateCheck == KICAD_SETTINGS::UPDATE_CHECK::UNINITIALIZED )
899 {
900 if( wxMessageBox( _( "Would you like to automatically check for plugin updates on startup?" ),
901 _( "Check for updates" ), wxICON_QUESTION | wxYES_NO, this )
902 == wxYES )
903 {
904 settings->m_updateCheck = KICAD_SETTINGS::UPDATE_CHECK::ALLOWED;
905 settings->m_PcmUpdateCheck = true;
906 }
907 else
908 {
909 settings->m_updateCheck = KICAD_SETTINGS::UPDATE_CHECK::NOT_ALLOWED;
910 settings->m_PcmUpdateCheck = false;
911 }
912 }
913
915 && settings->m_PcmUpdateCheck )
916 {
917 m_pcm->RunBackgroundUpdate();
918 }
919}
920
921
923{
924 m_pcmButton = aButton;
925
927}
928
929
931{
932 if( m_pcmButton )
933 {
934 if( m_pcmUpdateCount > 0 )
935 {
936 m_pcmButton->SetShowBadge( true );
938 }
939 else
940 {
941 m_pcmButton->SetShowBadge( false );
942 }
943
944 m_pcmButton->Refresh();
945 }
946}
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:105
@ 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.
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:101
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:504
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:154
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.
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:74
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111
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.