KiCad PCB EDA Suite
Loading...
Searching...
No Matches
kicad_manager_control.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) 2019 CERN
5 * Copyright (C) 2019-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
22#include <env_vars.h>
23#include <executable_names.h>
24#include <pgm_base.h>
25#include <policy_keys.h>
26#include <kiway.h>
27#include <kicad_manager_frame.h>
28#include <kiplatform/policy.h>
29#include <confirm.h>
30#include <kidialog.h>
35#include <tool/selection.h>
36#include <tool/tool_event.h>
42#include <gestfich.h>
43#include <paths.h>
44#include <wx/dir.h>
45#include <wx/filedlg.h>
46#include "dialog_pcm.h"
47
49
51 TOOL_INTERACTIVE( "kicad.Control" ),
52 m_frame( nullptr )
53{
54}
55
56
58{
59 m_frame = getEditFrame<KICAD_MANAGER_FRAME>();
60}
61
62
63wxFileName KICAD_MANAGER_CONTROL::newProjectDirectory( wxString* aFileName, bool isRepo )
64{
65 wxString default_filename = aFileName ? *aFileName : wxString();
66
67 wxString default_dir = m_frame->GetMruPath();
68 wxFileDialog dlg( m_frame, _( "Create New Project" ), default_dir, default_filename,
69 ( isRepo ? wxString( "" ) : FILEEXT::ProjectFileWildcard() ),
70 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
71
72 // Add a "Create a new directory" checkbox
73 FILEDLG_NEW_PROJECT newProjectHook;
74 dlg.SetCustomizeHook( newProjectHook );
75
76 if( dlg.ShowModal() == wxID_CANCEL )
77 return wxFileName();
78
79 wxFileName pro( dlg.GetPath() );
80
81 // wxFileName automatically extracts an extension. But if it isn't
82 // a .pro extension, we should keep it as part of the filename
83 if( !pro.GetExt().IsEmpty() && pro.GetExt().ToStdString() != FILEEXT::ProjectFileExtension )
84 pro.SetName( pro.GetName() + wxT( "." ) + pro.GetExt() );
85
86 pro.SetExt( FILEEXT::ProjectFileExtension ); // enforce extension
87
88 if( !pro.IsAbsolute() )
89 pro.MakeAbsolute();
90
91 // Append a new directory with the same name of the project file.
92 bool createNewDir = false;
93
94 createNewDir = newProjectHook.GetCreateNewDir();
95
96 if( createNewDir )
97 pro.AppendDir( pro.GetName() );
98
99 // Check if the project directory is empty if it already exists.
100 wxDir directory( pro.GetPath() );
101
102 if( !pro.DirExists() )
103 {
104 if( !pro.Mkdir() )
105 {
106 wxString msg;
107 msg.Printf( _( "Folder '%s' could not be created.\n\n"
108 "Make sure you have write permissions and try again." ),
109 pro.GetPath() );
111 return wxFileName();
112 }
113 }
114 else if( directory.HasFiles() )
115 {
116 wxString msg = _( "The selected folder is not empty. It is recommended that you "
117 "create projects in their own empty folder.\n\n"
118 "Do you want to continue?" );
119
120 if( !IsOK( m_frame, msg ) )
121 return wxFileName();
122 }
123
124 return pro;
125}
126
127
129{
130
131 wxFileName pro = newProjectDirectory();
132
133 if( !pro.IsOk() )
134 return -1;
135
137 m_frame->LoadProject( pro );
138
139 return 0;
140}
141
142
144{
145 DIALOG_GIT_REPOSITORY dlg( m_frame, nullptr );
146
147 dlg.SetTitle( _( "Clone Project from Git Repository" ) );
148
149 int ret = dlg.ShowModal();
150
151 if( ret != wxID_OK )
152 return -1;
153
154 wxString project_name = dlg.GetRepoName();
155 wxFileName pro = newProjectDirectory( &project_name, true );
156
157 if( !pro.IsOk() )
158 return -1;
159
160 GIT_CLONE_HANDLER cloneHandler;
161
162 cloneHandler.SetURL( dlg.GetRepoURL() );
163 cloneHandler.SetClonePath( pro.GetPath() );
164 cloneHandler.SetConnType( dlg.GetRepoType() );
165 cloneHandler.SetUsername( dlg.GetUsername() );
166 cloneHandler.SetPassword( dlg.GetPassword() );
167 cloneHandler.SetSSHKey( dlg.GetRepoSSHPath() );
168
169 cloneHandler.SetProgressReporter( std::make_unique<WX_PROGRESS_REPORTER>( m_frame, _( "Cloning Repository" ), 1 ) );
170
171 if( !cloneHandler.PerformClone() )
172 {
173 DisplayErrorMessage( m_frame, cloneHandler.GetErrorString() );
174 return -1;
175 }
176
177 std::vector<wxString> projects = cloneHandler.GetProjectDirs();
178
179 if( projects.empty() )
180 {
181 DisplayErrorMessage( m_frame, _( "No project files were found in the repository." ) );
182 return -1;
183 }
184
185 // Currently, we pick the first project file we find in the repository.
186 // TODO: Look into spare checkout to allow the user to pick a partial repository
187 wxString dest = pro.GetPath() + wxFileName::GetPathSeparator() + projects.front();
188 m_frame->LoadProject( dest );
189
193
197 Prj().GetLocalSettings().m_GitRepoType = "https";
198 else
199 Prj().GetLocalSettings().m_GitRepoType = "local";
200
201 return 0;
202}
203
204
206{
208
209 wxFileName templatePath;
210
211 // KiCad system template path.
212 std::optional<wxString> v = ENV_VAR::GetVersionedEnvVarValue( Pgm().GetLocalEnvVariables(),
213 wxT( "TEMPLATE_DIR" ) );
214
215 if( v && !v->IsEmpty() )
216 {
217 templatePath.AssignDir( *v );
218 ps->AddTemplatesPage( _( "System Templates" ), templatePath );
219 }
220
221 // User template path.
222 ENV_VAR_MAP_CITER it = Pgm().GetLocalEnvVariables().find( "KICAD_USER_TEMPLATE_DIR" );
223
224 if( it != Pgm().GetLocalEnvVariables().end() && it->second.GetValue() != wxEmptyString )
225 {
226 templatePath.AssignDir( it->second.GetValue() );
227 ps->AddTemplatesPage( _( "User Templates" ), templatePath );
228 }
229
230 // Show the project template selector dialog
231 if( ps->ShowModal() != wxID_OK )
232 return -1;
233
234 if( !ps->GetSelectedTemplate() )
235 {
236 wxMessageBox( _( "No project template was selected. Cannot generate new project." ),
237 _( "Error" ), wxOK | wxICON_ERROR, m_frame );
238
239 return -1;
240 }
241
242 // Get project destination folder and project file name.
243 wxString default_dir = wxFileName( Prj().GetProjectFullName() ).GetPathWithSep();
244 wxString title = _( "New Project Folder" );
245 wxFileDialog dlg( m_frame, title, default_dir, wxEmptyString, FILEEXT::ProjectFileWildcard(),
246 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
247
248 // Add a "Create a new directory" checkbox
249 FILEDLG_NEW_PROJECT newProjectHook;
250 dlg.SetCustomizeHook( newProjectHook );
251
252 if( dlg.ShowModal() == wxID_CANCEL )
253 return -1;
254
255 wxFileName fn( dlg.GetPath() );
256
257 // wxFileName automatically extracts an extension. But if it isn't a .kicad_pro extension,
258 // we should keep it as part of the filename
259 if( !fn.GetExt().IsEmpty() && fn.GetExt().ToStdString() != FILEEXT::ProjectFileExtension )
260 fn.SetName( fn.GetName() + wxT( "." ) + fn.GetExt() );
261
263
264 if( !fn.IsAbsolute() )
265 fn.MakeAbsolute();
266
267 bool createNewDir = false;
268 createNewDir = newProjectHook.GetCreateNewDir();
269
270 // Append a new directory with the same name of the project file.
271 if( createNewDir )
272 fn.AppendDir( fn.GetName() );
273
274 // Check if the project directory is empty if it already exists.
275
276 if( !fn.DirExists() )
277 {
278 if( !fn.Mkdir() )
279 {
280 wxString msg;
281 msg.Printf( _( "Folder '%s' could not be created.\n\n"
282 "Make sure you have write permissions and try again." ),
283 fn.GetPath() );
285 return -1;
286 }
287 }
288
289 if( !fn.IsDirWritable() )
290 {
291 wxString msg;
292
293 msg.Printf( _( "Insufficient permissions to write to folder '%s'." ), fn.GetPath() );
294 wxMessageDialog msgDlg( m_frame, msg, _( "Error" ), wxICON_ERROR | wxOK | wxCENTER );
295 msgDlg.ShowModal();
296 return -1;
297 }
298
299 // Make sure we are not overwriting anything in the destination folder.
300 std::vector< wxFileName > destFiles;
301
302 if( ps->GetSelectedTemplate()->GetDestinationFiles( fn, destFiles ) )
303 {
304 std::vector<wxFileName> overwrittenFiles;
305
306 for( const wxFileName& file : destFiles )
307 {
308 if( file.FileExists() )
309 overwrittenFiles.push_back( file );
310 }
311
312 if( !overwrittenFiles.empty() )
313 {
314 wxString extendedMsg = _( "Overwriting files:" ) + "\n";
315
316 for( const wxFileName& file : overwrittenFiles )
317 extendedMsg += "\n" + file.GetFullName();
318
319 KIDIALOG msgDlg( m_frame,
320 _( "Similar files already exist in the destination folder." ),
321 _( "Confirmation" ),
322 wxOK | wxCANCEL | wxICON_WARNING );
323 msgDlg.SetExtendedMessage( extendedMsg );
324 msgDlg.SetOKLabel( _( "Overwrite" ) );
325 msgDlg.DoNotShowCheckbox( __FILE__, __LINE__ );
326
327 if( msgDlg.ShowModal() == wxID_CANCEL )
328 return -1;
329 }
330 }
331
332 wxString errorMsg;
333
334 // The selected template widget contains the template we're attempting to use to
335 // create a project
336 if( !ps->GetSelectedTemplate()->CreateProject( fn, &errorMsg ) )
337 {
338 wxMessageDialog createDlg( m_frame,
339 _( "A problem occurred creating new project from template." ),
340 _( "Error" ),
341 wxOK | wxICON_ERROR );
342
343 if( !errorMsg.empty() )
344 createDlg.SetExtendedMessage( errorMsg );
345
346 createDlg.ShowModal();
347 return -1;
348 }
349
350 m_frame->CreateNewProject( fn.GetFullPath() );
351 m_frame->LoadProject( fn );
352 return 0;
353}
354
355
356int KICAD_MANAGER_CONTROL::openProject( const wxString& aDefaultDir )
357{
358 wxString wildcard = FILEEXT::AllProjectFilesWildcard()
361
362 wxFileDialog dlg( m_frame, _( "Open Existing Project" ), aDefaultDir, wxEmptyString, wildcard,
363 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
364
365 if( dlg.ShowModal() == wxID_CANCEL )
366 return -1;
367
368 wxFileName pro( dlg.GetPath() );
369
370 if( !pro.IsAbsolute() )
371 pro.MakeAbsolute();
372
373 if( !pro.FileExists() )
374 return -1;
375
376 m_frame->LoadProject( pro );
377
378 return 0;
379}
380
381
383{
385}
386
387
389{
390 return openProject( m_frame->GetMruPath() );
391}
392
393
395{
396 m_frame->CloseProject( true );
397 return 0;
398}
399
400
402{
403 if( aEvent.Parameter<wxString*>() )
404 m_frame->LoadProject( wxFileName( *aEvent.Parameter<wxString*>() ) );
405 return 0;
406}
407
409{
410 if( aEvent.Parameter<wxString*>() )
411 wxExecute( *aEvent.Parameter<wxString*>(), wxEXEC_ASYNC );
412 return 0;
413}
414
415class SAVE_AS_TRAVERSER : public wxDirTraverser
416{
417public:
419 const wxString& aSrcProjectDirPath,
420 const wxString& aSrcProjectName,
421 const wxString& aNewProjectDirPath,
422 const wxString& aNewProjectName ) :
423 m_frame( aFrame ),
424 m_projectDirPath( aSrcProjectDirPath ),
425 m_projectName( aSrcProjectName ),
426 m_newProjectDirPath( aNewProjectDirPath ),
427 m_newProjectName( aNewProjectName )
428 {
429 }
430
431 virtual wxDirTraverseResult OnFile( const wxString& aSrcFilePath ) override
432 {
433 // Recursion guard for a Save As to a location inside the source project.
434 if( aSrcFilePath.StartsWith( m_newProjectDirPath + wxFileName::GetPathSeparator() ) )
435 return wxDIR_CONTINUE;
436
437 wxFileName destFile( aSrcFilePath );
438 wxString ext = destFile.GetExt();
439 bool atRoot = destFile.GetPath() == m_projectDirPath;
440
444 {
445 wxString destPath = destFile.GetPath();
446
447 if( destPath.StartsWith( m_projectDirPath ) )
448 {
449 destPath.Replace( m_projectDirPath, m_newProjectDirPath, false );
450 destFile.SetPath( destPath );
451 }
452
453 if( destFile.GetName() == m_projectName )
454 {
455 destFile.SetName( m_newProjectName );
456
457 if( atRoot && ext != FILEEXT::ProjectLocalSettingsFileExtension )
458 m_newProjectFile = destFile;
459 }
460
462 {
463 // All paths in the settings file are relative so we can just do a straight copy
464 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), m_errors );
465 }
466 else if( ext == FILEEXT::ProjectFileExtension )
467 {
468 PROJECT_FILE projectFile( aSrcFilePath );
469 projectFile.LoadFromFile();
470 projectFile.SaveAs( destFile.GetPath(), destFile.GetName() );
471 }
473 {
474 PROJECT_LOCAL_SETTINGS projectLocalSettings( nullptr, aSrcFilePath );
475 projectLocalSettings.LoadFromFile();
476 projectLocalSettings.SaveAs( destFile.GetPath(), destFile.GetName() );
477 }
478 }
488 || destFile.GetName() == "sym-lib-table" )
489 {
492 m_newProjectName, aSrcFilePath, m_errors );
493 }
494 else if( ext == FILEEXT::KiCadPcbFileExtension
500 || destFile.GetName() == "fp-lib-table" )
501 {
504 m_newProjectName, aSrcFilePath, m_errors );
505 }
506 else if( ext == FILEEXT::DrawingSheetFileExtension )
507 {
510 m_newProjectName, aSrcFilePath, m_errors );
511 }
512 else if( ext == FILEEXT::GerberJobFileExtension
515 {
518 m_newProjectName, aSrcFilePath, m_errors );
519 }
520 else if( destFile.GetName().StartsWith( FILEEXT::LockFilePrefix )
522 {
523 // Ignore lock files
524 }
525 else
526 {
527 // Everything we don't recognize just gets a straight copy.
528 wxString destPath = destFile.GetPathWithSep();
529 wxString destName = destFile.GetName();
530 wxUniChar pathSep = wxFileName::GetPathSeparator();
531
532 wxString srcProjectFootprintLib = pathSep + m_projectName + ".pretty" + pathSep;
533 wxString newProjectFootprintLib = pathSep + m_newProjectName + ".pretty" + pathSep;
534
535 if( destPath.StartsWith( m_projectDirPath ) )
536 destPath.Replace( m_projectDirPath, m_newProjectDirPath, false );
537
538 destPath.Replace( srcProjectFootprintLib, newProjectFootprintLib, true );
539
540 if( destName == m_projectName && ext != wxT( "zip" ) /* don't rename archives */ )
541 destFile.SetName( m_newProjectName );
542
543 destFile.SetPath( destPath );
544
545 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), m_errors );
546 }
547
548 return wxDIR_CONTINUE;
549 }
550
551 virtual wxDirTraverseResult OnDir( const wxString& aSrcDirPath ) override
552 {
553 // Recursion guard for a Save As to a location inside the source project.
554 if( aSrcDirPath.StartsWith( m_newProjectDirPath ) )
555 return wxDIR_CONTINUE;
556
557 wxFileName destDir( aSrcDirPath );
558 wxString destDirPath = destDir.GetPathWithSep();
559 wxUniChar pathSep = wxFileName::GetPathSeparator();
560
561 if( destDirPath.StartsWith( m_projectDirPath + pathSep )
562 || destDirPath.StartsWith( m_projectDirPath + PROJECT_BACKUPS_DIR_SUFFIX ) )
563 {
564 destDirPath.Replace( m_projectDirPath, m_newProjectDirPath, false );
565 destDir.SetPath( destDirPath );
566 }
567
568 if( destDir.GetName() == m_projectName )
569 {
570 if( destDir.GetExt() == "pretty" )
571 destDir.SetName( m_newProjectName );
572#if 0
573 // WAYNE STAMBAUGH TODO:
574 // If we end up with a symbol equivalent to ".pretty" we'll want to handle it here....
575 else if( destDir.GetExt() == "sym_lib_dir_extension" )
576 destDir.SetName( m_newProjectName );
577#endif
578 }
579
580 if( !wxMkdir( destDir.GetFullPath() ) )
581 {
582 wxString msg;
583
584 if( !m_errors.empty() )
585 m_errors += "\n";
586
587 msg.Printf( _( "Cannot copy folder '%s'." ), destDir.GetFullPath() );
588 m_errors += msg;
589 }
590
591 return wxDIR_CONTINUE;
592 }
593
594 wxString GetErrors() { return m_errors; }
595
596 wxFileName GetNewProjectFile() { return m_newProjectFile; }
597
598private:
600
605
607 wxString m_errors;
608};
609
610
612{
613 wxString msg;
614
615 wxFileName currentProjectFile( Prj().GetProjectFullName() );
616 wxString currentProjectDirPath = currentProjectFile.GetPath();
617 wxString currentProjectName = Prj().GetProjectName();
618
619 wxString default_dir = m_frame->GetMruPath();
620
621 Prj().GetProjectFile().SaveToFile( currentProjectDirPath );
622 Prj().GetLocalSettings().SaveToFile( currentProjectDirPath );
623
624 if( default_dir == currentProjectDirPath
625 || default_dir == currentProjectDirPath + wxFileName::GetPathSeparator() )
626 {
627 // Don't start within the current project
628 wxFileName default_dir_fn( default_dir );
629 default_dir_fn.RemoveLastDir();
630 default_dir = default_dir_fn.GetPath();
631 }
632
633 wxFileDialog dlg( m_frame, _( "Save Project To" ), default_dir, wxEmptyString, wxEmptyString,
634 wxFD_SAVE );
635
636 if( dlg.ShowModal() == wxID_CANCEL )
637 return -1;
638
639 wxFileName newProjectDir( dlg.GetPath(), wxEmptyString );
640
641 if( !newProjectDir.IsAbsolute() )
642 newProjectDir.MakeAbsolute();
643
644 if( wxDirExists( newProjectDir.GetFullPath() ) )
645 {
646 msg.Printf( _( "'%s' already exists." ), newProjectDir.GetFullPath() );
648 return -1;
649 }
650
651 if( !wxMkdir( newProjectDir.GetFullPath() ) )
652 {
653 msg.Printf( _( "Folder '%s' could not be created.\n\n"
654 "Please make sure you have write permissions and try again." ),
655 newProjectDir.GetPath() );
657 return -1;
658 }
659
660 if( !newProjectDir.IsDirWritable() )
661 {
662 msg.Printf( _( "Insufficient permissions to write to folder '%s'." ),
663 newProjectDir.GetFullPath() );
664 wxMessageDialog msgDlg( m_frame, msg, _( "Error!" ), wxICON_ERROR | wxOK | wxCENTER );
665 msgDlg.ShowModal();
666 return -1;
667 }
668
669 const wxString& newProjectDirPath = newProjectDir.GetFullPath();
670 const wxString& newProjectName = newProjectDir.GetDirs().Last();
671 wxDir currentProjectDir( currentProjectDirPath );
672
673 SAVE_AS_TRAVERSER traverser( m_frame, currentProjectDirPath, currentProjectName,
674 newProjectDirPath, newProjectName );
675
676 currentProjectDir.Traverse( traverser );
677
678 if( !traverser.GetErrors().empty() )
679 DisplayErrorMessage( m_frame, traverser.GetErrors() );
680
681 if( !traverser.GetNewProjectFile().FileExists() )
683
684 m_frame->LoadProject( traverser.GetNewProjectFile() );
685
686 return 0;
687}
688
689
691{
693 return 0;
694}
695
696
698{
699 ACTION_MENU* actionMenu = aEvent.Parameter<ACTION_MENU*>();
700 CONDITIONAL_MENU* conditionalMenu = dynamic_cast<CONDITIONAL_MENU*>( actionMenu );
701 SELECTION dummySel;
702
703 if( conditionalMenu )
704 conditionalMenu->Evaluate( dummySel );
705
706 if( actionMenu )
707 actionMenu->UpdateAll();
708
709 return 0;
710}
711
712
714{
715 FRAME_T playerType = aEvent.Parameter<FRAME_T>();
716 KIWAY_PLAYER* player;
717
718 if( playerType == FRAME_SCH && !m_frame->IsProjectActive() )
719 {
720 DisplayInfoMessage( m_frame, _( "Create (or open) a project to edit a schematic." ),
721 wxEmptyString );
722 return -1;
723 }
724 else if( playerType == FRAME_PCB_EDITOR && !m_frame->IsProjectActive() )
725 {
726 DisplayInfoMessage( m_frame, _( "Create (or open) a project to edit a pcb." ),
727 wxEmptyString );
728 return -1;
729 }
730
731 // Prevent multiple KIWAY_PLAYER loading at one time
732 if( !m_loading.try_lock() )
733 return -1;
734
735 const std::lock_guard<std::mutex> lock( m_loading, std::adopt_lock );
736
737 try
738 {
739 player = m_frame->Kiway().Player( playerType, true );
740 }
741 catch( const IO_ERROR& err )
742 {
743 wxLogError( _( "Application failed to load:\n" ) + err.What() );
744 return -1;
745 }
746
747 if ( !player )
748 {
749 wxLogError( _( "Application cannot start." ) );
750 return -1;
751 }
752
753 if( !player->IsVisible() ) // A hidden frame might not have the document loaded.
754 {
755 wxString filepath;
756
757 if( playerType == FRAME_SCH )
758 {
759 wxFileName kicad_schematic( m_frame->SchFileName() );
760 wxFileName legacy_schematic( m_frame->SchLegacyFileName() );
761
762 if( !legacy_schematic.FileExists() || kicad_schematic.FileExists() )
763 filepath = kicad_schematic.GetFullPath();
764 else
765 filepath = legacy_schematic.GetFullPath();
766 }
767 else if( playerType == FRAME_PCB_EDITOR )
768 {
769 wxFileName kicad_board( m_frame->PcbFileName() );
770 wxFileName legacy_board( m_frame->PcbLegacyFileName() );
771
772 if( !legacy_board.FileExists() || kicad_board.FileExists() )
773 filepath = kicad_board.GetFullPath();
774 else
775 filepath = legacy_board.GetFullPath();
776 }
777
778 if( !filepath.IsEmpty() )
779 {
780 std::vector<wxString> file_list{ filepath };
781
782 if( !player->OpenProjectFiles( file_list ) )
783 {
784 player->Destroy();
785 return -1;
786 }
787 }
788
789 wxBusyCursor busy;
790 player->Show( true );
791 }
792
793 // Needed on Windows, other platforms do not use it, but it creates no issue
794 if( player->IsIconized() )
795 player->Iconize( false );
796
797 player->Raise();
798
799 // Raising the window does not set the focus on Linux. This should work on
800 // any platform.
801 if( wxWindow::FindFocus() != player )
802 player->SetFocus();
803
804 // Save window state to disk now. Don't wait around for a crash.
805 if( Pgm().GetCommonSettings()->m_Session.remember_open_files
806 && !player->GetCurrentFileName().IsEmpty() )
807 {
808 wxFileName rfn( player->GetCurrentFileName() );
809 rfn.MakeRelativeTo( Prj().GetProjectPath() );
810
811 WINDOW_SETTINGS windowSettings;
812 player->SaveWindowSettings( &windowSettings );
813
814 Prj().GetLocalSettings().SaveFileState( rfn.GetFullPath(), &windowSettings, true );
815 Prj().GetLocalSettings().SaveToFile( Prj().GetProjectPath() );
816 }
817
818 return 0;
819}
820
821
822class TERMINATE_HANDLER : public wxProcess
823{
824public:
825 TERMINATE_HANDLER( const wxString& appName )
826 { }
827
828 void OnTerminate( int pid, int status ) override
829 {
830 delete this;
831 }
832};
833
834
836{
837 wxString execFile;
838 wxString param;
839
841 execFile = GERBVIEW_EXE;
843 execFile = BITMAPCONVERTER_EXE;
845 execFile = PCB_CALCULATOR_EXE;
847 execFile = PL_EDITOR_EXE;
849 execFile = Pgm().GetTextEditor();
851 execFile = EESCHEMA_EXE;
853 execFile = PCBNEW_EXE;
854 else
855 wxFAIL_MSG( "Execute(): unexpected request" );
856
857 if( execFile.IsEmpty() )
858 return 0;
859
860 if( aEvent.Parameter<wxString*>() )
861 param = *aEvent.Parameter<wxString*>();
863 param = m_frame->Prj().GetProjectPath();
864
865 TERMINATE_HANDLER* callback = new TERMINATE_HANDLER( execFile );
866
867 long pid = ExecuteFile( execFile, param, callback );
868
869 if( pid > 0 )
870 {
871#ifdef __WXMAC__
872 wxString script = wxString::Format( wxS( "tell application \"System Events\"\n"
873 " set frontmost of the first process whose unix id is %l to true\n"
874 "end tell" ), pid );
875
876 // This non-parameterized use of wxExecute is fine because script is not derived
877 // from user input.
878 wxExecute( wxString::Format( "osascript -e '%s'", script ) );
879#endif
880 }
881 else
882 {
883 delete callback;
884 }
885
886 return 0;
887}
888
889
891{
894 {
895 // policy disables the plugin manager
896 return 0;
897 }
898
899 // For some reason, after a click or a double click the bitmap button calling
900 // PCM keeps the focus althougt the focus was not set to this button.
901 // This hack force removing the focus from this button
902 m_frame->SetFocus();
903 wxSafeYield();
904
905 if( !m_frame->GetPcm() )
907
908 DIALOG_PCM pcm( m_frame, m_frame->GetPcm() );
909 pcm.ShowModal();
910
911 const std::unordered_set<PCM_PACKAGE_TYPE>& changed = pcm.GetChangedPackageTypes();
912
913 if( changed.count( PCM_PACKAGE_TYPE::PT_PLUGIN ) )
914 {
915 std::string payload = "";
917 }
918
920
921 if( changed.count( PCM_PACKAGE_TYPE::PT_LIBRARY )
922 && ( settings->m_PcmLibAutoAdd || settings->m_PcmLibAutoRemove ) )
923 {
924 // Reset project tables
926 Prj().SetElem( PROJECT::ELEM_FPTBL, nullptr );
927
928 KIWAY& kiway = m_frame->Kiway();
929
930 // Reset state containing global lib tables
931 if( KIFACE* kiface = kiway.KiFACE( KIWAY::FACE_SCH, false ) )
932 kiface->Reset();
933
934 if( KIFACE* kiface = kiway.KiFACE( KIWAY::FACE_PCB, false ) )
935 kiface->Reset();
936
937 // Reload lib tables
938 std::string payload = "";
939
942 kiway.ExpressMail( FRAME_CVPCB, MAIL_RELOAD_LIB, payload );
945 }
946
947 if( changed.count( PCM_PACKAGE_TYPE::PT_COLORTHEME ) )
949
950 return 0;
951}
952
953
955{
965
968
978
981
983}
static TOOL_ACTION zoomRedraw
Definition: actions.h:115
static TOOL_ACTION saveAs
Definition: actions.h:52
static TOOL_ACTION updateMenu
Definition: actions.h:208
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:49
void UpdateAll()
Run update handlers for the menu and its submenus.
KIGIT_COMMON::GIT_CONN_TYPE GetRepoType() const
wxString GetRepoSSHPath() const
wxString GetUsername() const
wxString GetRepoName() const
wxString GetPassword() const
Implementing pcm main dialog.
Definition: dialog_pcm.h:36
const std::unordered_set< PCM_PACKAGE_TYPE > & GetChangedPackageTypes() const
Definition: dialog_pcm.h:77
void AddTemplatesPage(const wxString &aTitle, wxFileName &aPath)
Add a new page with aTitle, populated with templates from aPath.
PROJECT_TEMPLATE * GetSelectedTemplate()
wxString GetMruPath() const
bool GetCreateNewDir() const
void SetURL(const wxString &aURL)
void SetClonePath(const wxString &aPath)
void SetProgressReporter(std::unique_ptr< WX_PROGRESS_REPORTER > aProgressReporter)
Definition: git_progress.h:40
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:77
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
virtual bool LoadFromFile(const wxString &aDirectory="")
Loads the backing file from disk and then calls Load()
static TOOL_ACTION viewDroppedGerbers
static TOOL_ACTION openDemoProject
static TOOL_ACTION editPCB
static TOOL_ACTION loadProject
static TOOL_ACTION editOtherPCB
static TOOL_ACTION newProject
static TOOL_ACTION editOtherSch
static TOOL_ACTION editSchematic
static TOOL_ACTION openTextEditor
static TOOL_ACTION openProject
static TOOL_ACTION closeProject
static TOOL_ACTION convertImage
static TOOL_ACTION editDrawingSheet
static TOOL_ACTION editFootprints
static TOOL_ACTION showPluginManager
static TOOL_ACTION showCalculator
static TOOL_ACTION viewGerbers
static TOOL_ACTION newFromRepository
static TOOL_ACTION newFromTemplate
static TOOL_ACTION editSymbols
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
int OpenProject(const TOOL_EVENT &aEvent)
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
int OpenDemoProject(const TOOL_EVENT &aEvent)
int CloseProject(const TOOL_EVENT &aEvent)
int SaveProjectAs(const TOOL_EVENT &aEvent)
int NewProject(const TOOL_EVENT &aEvent)
int ViewDroppedViewers(const TOOL_EVENT &aEvent)
Imports a non kicad project from a sch/pcb dropped file.
int NewFromTemplate(const TOOL_EVENT &aEvent)
int ShowPluginManager(const TOOL_EVENT &aEvent)
Set up handlers for various events.
int UpdateMenu(const TOOL_EVENT &aEvent)
wxFileName newProjectDirectory(wxString *aFileName=nullptr, bool isRepo=false)
int NewFromRepository(const TOOL_EVENT &aEvent)
int LoadProject(const TOOL_EVENT &aEvent)
KICAD_MANAGER_FRAME * m_frame
< Pointer to the currently used edit/draw frame.
int ShowPlayer(const TOOL_EVENT &aEvent)
int Refresh(const TOOL_EVENT &aEvent)
int openProject(const wxString &aDefaultDir)
int Execute(const TOOL_EVENT &aEvent)
The main KiCad project manager frame.
void CreateNewProject(const wxFileName &aProjectFileName, bool aCreateStubFiles=true)
Creates a new project by setting up and initial project, schematic, and board files.
const wxString SchLegacyFileName()
const wxString SchFileName()
void LoadProject(const wxFileName &aProjectFileName)
std::shared_ptr< PLUGIN_CONTENT_MANAGER > GetPcm()
const wxString PcbLegacyFileName()
bool CloseProject(bool aSave)
Closes the project, and saves it if aSave is true;.
const wxString PcbFileName()
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition: kidialog.h:43
void DoNotShowCheckbox(wxString file, int line)
Checks the 'do not show again' setting for the dialog.
Definition: kidialog.cpp:51
int ShowModal() override
Definition: kidialog.cpp:95
virtual void Reset() override
Reloads global state.
Definition: kiface_base.h:55
void SetConnType(GIT_CONN_TYPE aConnType)
void SetSSHKey(const wxString &aSSHKey)
void SetUsername(const wxString &aUsername)
std::vector< wxString > GetProjectDirs()
Return a vector of project files in the repository.
void SetPassword(const wxString &aPassword)
wxString GetErrorString()
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:55
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:65
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:279
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:406
virtual KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Return the KIFACE* given a FACE_T.
Definition: kiway.cpp:202
@ FACE_SCH
eeschema DSO
Definition: kiway.h:286
@ FACE_PL_EDITOR
Definition: kiway.h:290
@ FACE_PCB
pcbnew DSO
Definition: kiway.h:287
@ FACE_GERBVIEW
Definition: kiway.h:289
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr)
Send aPayload to aDestination from aSource.
Definition: kiway.cpp:527
static wxString GetStockDemosPath()
Gets the stock (install) demos path.
Definition: paths.cpp:333
virtual ENV_VAR_MAP & GetLocalEnvVariables() const
Definition: pgm_base.cpp:923
virtual const wxString & GetTextEditor(bool aCanShowFileChooser=true)
Return the path to the preferred text editor application.
Definition: pgm_base.cpp:195
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:142
The backing store for a PROJECT, in JSON format.
Definition: project_file.h:70
bool SaveAs(const wxString &aDirectory, const wxString &aFile)
bool SaveToFile(const wxString &aDirectory="", bool aForce=false) override
Calls Store() and then writes the contents of the JSON document to a file.
The project local settings are things that are attached to a particular project, but also might be pa...
bool SaveAs(const wxString &aDirectory, const wxString &aFile)
bool SaveToFile(const wxString &aDirectory="", bool aForce=false) override
Calls Store() and then writes the contents of the JSON document to a file.
void SaveFileState(const wxString &aFileName, const WINDOW_SETTINGS *aWindowCfg, bool aOpen)
size_t GetDestinationFiles(const wxFileName &aNewProjectPath, std::vector< wxFileName > &aDestFiles)
Fetch the list of destination files to be copied when the new project is created.
bool CreateProject(wxFileName &aNewProjectPath, wxString *aErrorMsg=nullptr)
Copies and renames all template files to create a new project.
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:135
virtual const wxString GetProjectName() const
Return the short name of the project.
Definition: project.cpp:147
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
Definition: project.h:172
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:166
virtual void SetElem(ELEM_T aIndex, _ELEM *aElem)
Definition: project.cpp:309
@ ELEM_SYMBOL_LIB_TABLE
Definition: project.h:228
@ ELEM_FPTBL
Definition: project.h:223
KICAD_MANAGER_FRAME * m_frame
virtual wxDirTraverseResult OnFile(const wxString &aSrcFilePath) override
SAVE_AS_TRAVERSER(KICAD_MANAGER_FRAME *aFrame, const wxString &aSrcProjectDirPath, const wxString &aSrcProjectName, const wxString &aNewProjectDirPath, const wxString &aNewProjectName)
virtual wxDirTraverseResult OnDir(const wxString &aSrcDirPath) override
T * GetAppSettings()
Returns a handle to the a given settings by type If the settings have already been loaded,...
void ReloadColorSettings()
Re-scans the color themes directory, reloading any changes it finds.
void OnTerminate(int pid, int status) override
TERMINATE_HANDLER(const wxString &appName)
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:78
Generic, UI-independent tool event.
Definition: tool_event.h:167
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
Definition: tool_event.cpp:82
T Parameter() const
Return a parameter assigned to the event.
Definition: tool_event.h:460
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Define which state (aStateFunc) to go when a certain event arrives (aConditions).
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:250
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition: confirm.cpp:222
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:195
This file is part of the common library.
#define _(s)
Functions related to environment variables, including help functions.
KiCad executable names.
const wxString EESCHEMA_EXE
const wxString GERBVIEW_EXE
const wxString PL_EDITOR_EXE
const wxString BITMAPCONVERTER_EXE
const wxString PCBNEW_EXE
const wxString PCB_CALCULATOR_EXE
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:33
@ FRAME_PCB_EDITOR
Definition: frame_type.h:42
@ FRAME_SCH_SYMBOL_EDITOR
Definition: frame_type.h:35
@ FRAME_FOOTPRINT_VIEWER
Definition: frame_type.h:45
@ FRAME_SCH_VIEWER
Definition: frame_type.h:36
@ FRAME_SCH
Definition: frame_type.h:34
@ FRAME_FOOTPRINT_EDITOR
Definition: frame_type.h:43
@ FRAME_CVPCB
Definition: frame_type.h:52
void KiCopyFile(const wxString &aSrcPath, const wxString &aDestPath, wxString &aErrors)
Definition: gestfich.cpp:305
int ExecuteFile(const wxString &aEditorName, const wxString &aFileName, wxProcess *aCallback, bool aFileForKicad)
Call the executable file aEditorName with the parameter aFileName.
Definition: gestfich.cpp:139
static const std::string LegacySchematicFileExtension
static const std::string NetlistFileExtension
static const std::string GerberJobFileExtension
static const std::string LockFileExtension
static const std::string ProjectFileExtension
static const std::string LegacyPcbFileExtension
static const std::string SchematicSymbolFileExtension
static const std::string LegacyProjectFileExtension
static const std::string ProjectLocalSettingsFileExtension
static const std::string KiCadSchematicFileExtension
static const std::string LegacySymbolLibFileExtension
static const std::string LockFilePrefix
static const std::string KiCadSymbolLibFileExtension
static const std::string DrawingSheetFileExtension
static const std::string BackupFileSuffix
static const std::string LegacyFootprintLibPathExtension
static const std::string LegacySymbolDocumentFileExtension
static const std::string FootprintAssignmentFileExtension
static const std::string DrillFileExtension
static const std::string KiCadFootprintFileExtension
static const std::string KiCadPcbFileExtension
static wxString ProjectFileWildcard()
static bool IsGerberFileExtension(const wxString &ext)
static wxString LegacyProjectFileWildcard()
static wxString AllProjectFilesWildcard()
std::map< wxString, ENV_VAR_ITEM >::const_iterator ENV_VAR_MAP_CITER
PROJECT & Prj()
Definition: kicad.cpp:595
This file is part of the common library.
@ MAIL_RELOAD_PLUGINS
Definition: mail_type.h:57
@ MAIL_RELOAD_LIB
Definition: mail_type.h:56
KICOMMON_API std::optional< wxString > GetVersionedEnvVarValue(const std::map< wxString, ENV_VAR_ITEM > &aMap, const wxString &aBaseName)
Attempts to retrieve the value of a versioned environment variable, such as KICAD8_TEMPLATE_DIR.
Definition: env_vars.cpp:83
PBOOL GetPolicyBool(const wxString &aKey)
Definition: unix/policy.cpp:26
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1059
see class PGM_BASE
#define POLICY_KEY_PCM
Definition: policy_keys.h:31
#define PROJECT_BACKUPS_DIR_SUFFIX
Project settings path will be <projectname> + this.
Implement a participant in the KIWAY alchemy.
Definition: kiway.h:151
virtual void SaveFileAs(const wxString &srcProjectBasePath, const wxString &srcProjectName, const wxString &newProjectBasePath, const wxString &newProjectName, const wxString &srcFilePath, wxString &aErrors)
Saving a file under a different name is delegated to the various KIFACEs because the project doesn't ...
Definition: kiway.h:216
Stores the common settings that are saved and loaded for each window / frame.
Definition: app_settings.h:74
IFACE KIFACE_BASE kiface("pcb_test_frame", KIWAY::FACE_PCB)
Definition of file extensions used in Kicad.