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 <pgm_kicad.h>
26#include <policy_keys.h>
27#include <kiway.h>
28#include <kicad_manager_frame.h>
29#include <kiplatform/policy.h>
30#include <confirm.h>
31#include <kidialog.h>
36#include <tool/selection.h>
37#include <tool/tool_event.h>
44#include <gestfich.h>
45#include <paths.h>
46#include <wx/dir.h>
47#include <wx/filedlg.h>
49#include "dialog_pcm.h"
50
52
54 TOOL_INTERACTIVE( "kicad.Control" ),
55 m_frame( nullptr )
56{
57}
58
59
61{
62 m_frame = getEditFrame<KICAD_MANAGER_FRAME>();
63}
64
65
66wxFileName KICAD_MANAGER_CONTROL::newProjectDirectory( wxString* aFileName, bool isRepo )
67{
68 wxString default_filename = aFileName ? *aFileName : wxString();
69
70 wxString default_dir = m_frame->GetMruPath();
71 wxFileDialog dlg( m_frame, _( "Create New Project" ), default_dir, default_filename,
72 ( isRepo ? wxString( "" ) : FILEEXT::ProjectFileWildcard() ),
73 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
74
75 // Add a "Create a new directory" checkbox
76 FILEDLG_NEW_PROJECT newProjectHook;
77 dlg.SetCustomizeHook( newProjectHook );
78
79 if( dlg.ShowModal() == wxID_CANCEL )
80 return wxFileName();
81
82 wxFileName pro( dlg.GetPath() );
83
84 // wxFileName automatically extracts an extension. But if it isn't
85 // a .pro extension, we should keep it as part of the filename
86 if( !pro.GetExt().IsEmpty() && pro.GetExt().ToStdString() != FILEEXT::ProjectFileExtension )
87 pro.SetName( pro.GetName() + wxT( "." ) + pro.GetExt() );
88
89 pro.SetExt( FILEEXT::ProjectFileExtension ); // enforce extension
90
91 if( !pro.IsAbsolute() )
92 pro.MakeAbsolute();
93
94 // Append a new directory with the same name of the project file.
95 bool createNewDir = false;
96
97 createNewDir = newProjectHook.GetCreateNewDir();
98
99 if( createNewDir )
100 pro.AppendDir( pro.GetName() );
101
102 // Check if the project directory is empty if it already exists.
103 wxDir directory( pro.GetPath() );
104
105 if( !pro.DirExists() )
106 {
107 if( !pro.Mkdir() )
108 {
109 wxString msg;
110 msg.Printf( _( "Folder '%s' could not be created.\n\n"
111 "Make sure you have write permissions and try again." ),
112 pro.GetPath() );
114 return wxFileName();
115 }
116 }
117 else if( directory.HasFiles() )
118 {
119 wxString msg = _( "The selected folder is not empty. It is recommended that you "
120 "create projects in their own empty folder.\n\n"
121 "Do you want to continue?" );
122
123 if( !IsOK( m_frame, msg ) )
124 return wxFileName();
125 }
126
127 return pro;
128}
129
130
132{
133
134 wxFileName pro = newProjectDirectory();
135
136 if( !pro.IsOk() )
137 return -1;
138
140 m_frame->LoadProject( pro );
141
142 return 0;
143}
144
145
147{
148 DIALOG_GIT_REPOSITORY dlg( m_frame, nullptr );
149
150 dlg.SetTitle( _( "Clone Project from Git Repository" ) );
151
152 int ret = dlg.ShowModal();
153
154 if( ret != wxID_OK )
155 return -1;
156
157 wxString project_name = dlg.GetRepoName();
158 wxFileName pro = newProjectDirectory( &project_name, true );
159
160 if( !pro.IsOk() )
161 return -1;
162
163 GIT_CLONE_HANDLER cloneHandler;
164
165 cloneHandler.SetURL( dlg.GetRepoURL() );
166 cloneHandler.SetClonePath( pro.GetPath() );
167 cloneHandler.SetConnType( dlg.GetRepoType() );
168 cloneHandler.SetUsername( dlg.GetUsername() );
169 cloneHandler.SetPassword( dlg.GetPassword() );
170 cloneHandler.SetSSHKey( dlg.GetRepoSSHPath() );
171
172 cloneHandler.SetProgressReporter( std::make_unique<WX_PROGRESS_REPORTER>( m_frame, _( "Cloning Repository" ), 1 ) );
173
174 if( !cloneHandler.PerformClone() )
175 {
176 DisplayErrorMessage( m_frame, cloneHandler.GetErrorString() );
177 return -1;
178 }
179
180 std::vector<wxString> projects = cloneHandler.GetProjectDirs();
181
182 if( projects.empty() )
183 {
184 DisplayErrorMessage( m_frame, _( "No project files were found in the repository." ) );
185 return -1;
186 }
187
188 // Currently, we pick the first project file we find in the repository.
189 // TODO: Look into spare checkout to allow the user to pick a partial repository
190 wxString dest = pro.GetPath() + wxFileName::GetPathSeparator() + projects.front();
191 m_frame->LoadProject( dest );
192
196
200 Prj().GetLocalSettings().m_GitRepoType = "https";
201 else
202 Prj().GetLocalSettings().m_GitRepoType = "local";
203
204 return 0;
205}
206
207
209{
210 wxString default_dir = wxFileName( Prj().GetProjectFullName() ).GetPathWithSep();
211 wxFileDialog dlg( m_frame, _( "Create New Jobset" ), default_dir, wxEmptyString,
213 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
214
215 if( dlg.ShowModal() == wxID_CANCEL )
216 return -1;
217
218 wxFileName jobsetFn( dlg.GetPath() );
219
220 m_frame->OpenJobsFile( jobsetFn.GetFullPath(), true );
221
222 return 0;
223}
224
225
227{
229 KICAD_SETTINGS* settings = mgr.GetAppSettings<KICAD_SETTINGS>( "kicad" );
231 settings->m_TemplateWindowSize );
232
233 wxFileName templatePath;
234
235 // KiCad system template path.
236 std::optional<wxString> v = ENV_VAR::GetVersionedEnvVarValue( Pgm().GetLocalEnvVariables(),
237 wxT( "TEMPLATE_DIR" ) );
238
239 if( v && !v->IsEmpty() )
240 {
241 templatePath.AssignDir( *v );
242 ps->AddTemplatesPage( _( "System Templates" ), templatePath );
243 }
244
245 // User template path.
246 ENV_VAR_MAP_CITER it = Pgm().GetLocalEnvVariables().find( "KICAD_USER_TEMPLATE_DIR" );
247
248 if( it != Pgm().GetLocalEnvVariables().end() && it->second.GetValue() != wxEmptyString )
249 {
250 templatePath.AssignDir( it->second.GetValue() );
251 ps->AddTemplatesPage( _( "User Templates" ), templatePath );
252 }
253
254 // Show the project template selector dialog
255 int result = ps->ShowModal();
256
257 settings->m_TemplateWindowPos = ps->GetPosition();
258 settings->m_TemplateWindowSize = ps->GetSize();
259
260 if( result != wxID_OK )
261 return -1;
262
263 if( !ps->GetSelectedTemplate() )
264 {
265 wxMessageBox( _( "No project template was selected. Cannot generate new project." ),
266 _( "Error" ), wxOK | wxICON_ERROR, m_frame );
267
268 return -1;
269 }
270
271 // Get project destination folder and project file name.
272 wxString default_dir = wxFileName( Prj().GetProjectFullName() ).GetPathWithSep();
273 wxString title = _( "New Project Folder" );
274 wxFileDialog dlg( m_frame, title, default_dir, wxEmptyString, FILEEXT::ProjectFileWildcard(),
275 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
276
277 // Add a "Create a new directory" checkbox
278 FILEDLG_NEW_PROJECT newProjectHook;
279 dlg.SetCustomizeHook( newProjectHook );
280
281 if( dlg.ShowModal() == wxID_CANCEL )
282 return -1;
283
284 wxFileName fn( dlg.GetPath() );
285
286 // wxFileName automatically extracts an extension. But if it isn't a .kicad_pro extension,
287 // we should keep it as part of the filename
288 if( !fn.GetExt().IsEmpty() && fn.GetExt().ToStdString() != FILEEXT::ProjectFileExtension )
289 fn.SetName( fn.GetName() + wxT( "." ) + fn.GetExt() );
290
292
293 if( !fn.IsAbsolute() )
294 fn.MakeAbsolute();
295
296 bool createNewDir = false;
297 createNewDir = newProjectHook.GetCreateNewDir();
298
299 // Append a new directory with the same name of the project file.
300 if( createNewDir )
301 fn.AppendDir( fn.GetName() );
302
303 // Check if the project directory is empty if it already exists.
304
305 if( !fn.DirExists() )
306 {
307 if( !fn.Mkdir() )
308 {
309 wxString msg;
310 msg.Printf( _( "Folder '%s' could not be created.\n\n"
311 "Make sure you have write permissions and try again." ),
312 fn.GetPath() );
314 return -1;
315 }
316 }
317
318 if( !fn.IsDirWritable() )
319 {
320 wxString msg;
321
322 msg.Printf( _( "Insufficient permissions to write to folder '%s'." ), fn.GetPath() );
323 wxMessageDialog msgDlg( m_frame, msg, _( "Error" ), wxICON_ERROR | wxOK | wxCENTER );
324 msgDlg.ShowModal();
325 return -1;
326 }
327
328 // Make sure we are not overwriting anything in the destination folder.
329 std::vector< wxFileName > destFiles;
330
331 if( ps->GetSelectedTemplate()->GetDestinationFiles( fn, destFiles ) )
332 {
333 std::vector<wxFileName> overwrittenFiles;
334
335 for( const wxFileName& file : destFiles )
336 {
337 if( file.FileExists() )
338 overwrittenFiles.push_back( file );
339 }
340
341 if( !overwrittenFiles.empty() )
342 {
343 wxString extendedMsg = _( "Overwriting files:" ) + "\n";
344
345 for( const wxFileName& file : overwrittenFiles )
346 extendedMsg += "\n" + file.GetFullName();
347
348 KIDIALOG msgDlg( m_frame,
349 _( "Similar files already exist in the destination folder." ),
350 _( "Confirmation" ),
351 wxOK | wxCANCEL | wxICON_WARNING );
352 msgDlg.SetExtendedMessage( extendedMsg );
353 msgDlg.SetOKLabel( _( "Overwrite" ) );
354 msgDlg.DoNotShowCheckbox( __FILE__, __LINE__ );
355
356 if( msgDlg.ShowModal() == wxID_CANCEL )
357 return -1;
358 }
359 }
360
361 wxString errorMsg;
362
363 // The selected template widget contains the template we're attempting to use to
364 // create a project
365 if( !ps->GetSelectedTemplate()->CreateProject( fn, &errorMsg ) )
366 {
367 wxMessageDialog createDlg( m_frame,
368 _( "A problem occurred creating new project from template." ),
369 _( "Error" ),
370 wxOK | wxICON_ERROR );
371
372 if( !errorMsg.empty() )
373 createDlg.SetExtendedMessage( errorMsg );
374
375 createDlg.ShowModal();
376 return -1;
377 }
378
379 m_frame->CreateNewProject( fn.GetFullPath() );
380 m_frame->LoadProject( fn );
381 return 0;
382}
383
384
385int KICAD_MANAGER_CONTROL::openProject( const wxString& aDefaultDir )
386{
387 wxString wildcard = FILEEXT::AllProjectFilesWildcard()
390
391 wxFileDialog dlg( m_frame, _( "Open Existing Project" ), aDefaultDir, wxEmptyString, wildcard,
392 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
393
394 if( dlg.ShowModal() == wxID_CANCEL )
395 return -1;
396
397 wxFileName pro( dlg.GetPath() );
398
399 if( !pro.IsAbsolute() )
400 pro.MakeAbsolute();
401
402 if( !pro.FileExists() )
403 return -1;
404
405 m_frame->LoadProject( pro );
406
407 return 0;
408}
409
410
412{
414}
415
416
418{
419 return openProject( m_frame->GetMruPath() );
420}
421
422
424{
425 m_frame->CloseProject( true );
426 return 0;
427}
428
429
431{
432 if( aEvent.Parameter<wxString*>() )
433 m_frame->LoadProject( wxFileName( *aEvent.Parameter<wxString*>() ) );
434 return 0;
435}
436
438{
439 if( aEvent.Parameter<wxString*>() )
440 wxExecute( *aEvent.Parameter<wxString*>(), wxEXEC_ASYNC );
441 return 0;
442}
443
444class SAVE_AS_TRAVERSER : public wxDirTraverser
445{
446public:
448 const wxString& aSrcProjectDirPath,
449 const wxString& aSrcProjectName,
450 const wxString& aNewProjectDirPath,
451 const wxString& aNewProjectName ) :
452 m_frame( aFrame ),
453 m_projectDirPath( aSrcProjectDirPath ),
454 m_projectName( aSrcProjectName ),
455 m_newProjectDirPath( aNewProjectDirPath ),
456 m_newProjectName( aNewProjectName )
457 {
458 }
459
460 virtual wxDirTraverseResult OnFile( const wxString& aSrcFilePath ) override
461 {
462 // Recursion guard for a Save As to a location inside the source project.
463 if( aSrcFilePath.StartsWith( m_newProjectDirPath + wxFileName::GetPathSeparator() ) )
464 return wxDIR_CONTINUE;
465
466 wxFileName destFile( aSrcFilePath );
467 wxString ext = destFile.GetExt();
468 bool atRoot = destFile.GetPath() == m_projectDirPath;
469
473 {
474 wxString destPath = destFile.GetPath();
475
476 if( destPath.StartsWith( m_projectDirPath ) )
477 {
478 destPath.Replace( m_projectDirPath, m_newProjectDirPath, false );
479 destFile.SetPath( destPath );
480 }
481
482 if( destFile.GetName() == m_projectName )
483 {
484 destFile.SetName( m_newProjectName );
485
486 if( atRoot && ext != FILEEXT::ProjectLocalSettingsFileExtension )
487 m_newProjectFile = destFile;
488 }
489
491 {
492 // All paths in the settings file are relative so we can just do a straight copy
493 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), m_errors );
494 }
495 else if( ext == FILEEXT::ProjectFileExtension )
496 {
497 PROJECT_FILE projectFile( aSrcFilePath );
498 projectFile.LoadFromFile();
499 projectFile.SaveAs( destFile.GetPath(), destFile.GetName() );
500 }
502 {
503 PROJECT_LOCAL_SETTINGS projectLocalSettings( nullptr, aSrcFilePath );
504 projectLocalSettings.LoadFromFile();
505 projectLocalSettings.SaveAs( destFile.GetPath(), destFile.GetName() );
506 }
507 }
517 || destFile.GetName() == "sym-lib-table" )
518 {
521 m_newProjectName, aSrcFilePath, m_errors );
522 }
523 else if( ext == FILEEXT::KiCadPcbFileExtension
529 || destFile.GetName() == "fp-lib-table" )
530 {
533 m_newProjectName, aSrcFilePath, m_errors );
534 }
535 else if( ext == FILEEXT::DrawingSheetFileExtension )
536 {
539 m_newProjectName, aSrcFilePath, m_errors );
540 }
541 else if( ext == FILEEXT::GerberJobFileExtension
544 {
547 m_newProjectName, aSrcFilePath, m_errors );
548 }
549 else if( destFile.GetName().StartsWith( FILEEXT::LockFilePrefix )
551 {
552 // Ignore lock files
553 }
554 else
555 {
556 // Everything we don't recognize just gets a straight copy.
557 wxString destPath = destFile.GetPathWithSep();
558 wxString destName = destFile.GetName();
559 wxUniChar pathSep = wxFileName::GetPathSeparator();
560
561 wxString srcProjectFootprintLib = pathSep + m_projectName + ".pretty" + pathSep;
562 wxString newProjectFootprintLib = pathSep + m_newProjectName + ".pretty" + pathSep;
563
564 if( destPath.StartsWith( m_projectDirPath ) )
565 destPath.Replace( m_projectDirPath, m_newProjectDirPath, false );
566
567 destPath.Replace( srcProjectFootprintLib, newProjectFootprintLib, true );
568
569 if( destName == m_projectName && ext != wxT( "zip" ) /* don't rename archives */ )
570 destFile.SetName( m_newProjectName );
571
572 destFile.SetPath( destPath );
573
574 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), m_errors );
575 }
576
577 return wxDIR_CONTINUE;
578 }
579
580 virtual wxDirTraverseResult OnDir( const wxString& aSrcDirPath ) override
581 {
582 // Recursion guard for a Save As to a location inside the source project.
583 if( aSrcDirPath.StartsWith( m_newProjectDirPath ) )
584 return wxDIR_CONTINUE;
585
586 wxFileName destDir( aSrcDirPath );
587 wxString destDirPath = destDir.GetPathWithSep();
588 wxUniChar pathSep = wxFileName::GetPathSeparator();
589
590 if( destDirPath.StartsWith( m_projectDirPath + pathSep )
591 || destDirPath.StartsWith( m_projectDirPath + PROJECT_BACKUPS_DIR_SUFFIX ) )
592 {
593 destDirPath.Replace( m_projectDirPath, m_newProjectDirPath, false );
594 destDir.SetPath( destDirPath );
595 }
596
597 if( destDir.GetName() == m_projectName )
598 {
599 if( destDir.GetExt() == "pretty" )
600 destDir.SetName( m_newProjectName );
601#if 0
602 // WAYNE STAMBAUGH TODO:
603 // If we end up with a symbol equivalent to ".pretty" we'll want to handle it here....
604 else if( destDir.GetExt() == "sym_lib_dir_extension" )
605 destDir.SetName( m_newProjectName );
606#endif
607 }
608
609 if( !wxMkdir( destDir.GetFullPath() ) )
610 {
611 wxString msg;
612
613 if( !m_errors.empty() )
614 m_errors += "\n";
615
616 msg.Printf( _( "Cannot copy folder '%s'." ), destDir.GetFullPath() );
617 m_errors += msg;
618 }
619
620 return wxDIR_CONTINUE;
621 }
622
623 wxString GetErrors() { return m_errors; }
624
625 wxFileName GetNewProjectFile() { return m_newProjectFile; }
626
627private:
629
634
636 wxString m_errors;
637};
638
639
641{
642 wxString msg;
643
644 wxFileName currentProjectFile( Prj().GetProjectFullName() );
645 wxString currentProjectDirPath = currentProjectFile.GetPath();
646 wxString currentProjectName = Prj().GetProjectName();
647
648 wxString default_dir = m_frame->GetMruPath();
649
650 Prj().GetProjectFile().SaveToFile( currentProjectDirPath );
651 Prj().GetLocalSettings().SaveToFile( currentProjectDirPath );
652
653 if( default_dir == currentProjectDirPath
654 || default_dir == currentProjectDirPath + wxFileName::GetPathSeparator() )
655 {
656 // Don't start within the current project
657 wxFileName default_dir_fn( default_dir );
658 default_dir_fn.RemoveLastDir();
659 default_dir = default_dir_fn.GetPath();
660 }
661
662 wxFileDialog dlg( m_frame, _( "Save Project To" ), default_dir, wxEmptyString, wxEmptyString,
663 wxFD_SAVE );
664
665 if( dlg.ShowModal() == wxID_CANCEL )
666 return -1;
667
668 wxFileName newProjectDir( dlg.GetPath(), wxEmptyString );
669
670 if( !newProjectDir.IsAbsolute() )
671 newProjectDir.MakeAbsolute();
672
673 if( wxDirExists( newProjectDir.GetFullPath() ) )
674 {
675 msg.Printf( _( "'%s' already exists." ), newProjectDir.GetFullPath() );
677 return -1;
678 }
679
680 if( !wxMkdir( newProjectDir.GetFullPath() ) )
681 {
682 msg.Printf( _( "Folder '%s' could not be created.\n\n"
683 "Please make sure you have write permissions and try again." ),
684 newProjectDir.GetPath() );
686 return -1;
687 }
688
689 if( !newProjectDir.IsDirWritable() )
690 {
691 msg.Printf( _( "Insufficient permissions to write to folder '%s'." ),
692 newProjectDir.GetFullPath() );
693 wxMessageDialog msgDlg( m_frame, msg, _( "Error!" ), wxICON_ERROR | wxOK | wxCENTER );
694 msgDlg.ShowModal();
695 return -1;
696 }
697
698 const wxString& newProjectDirPath = newProjectDir.GetFullPath();
699 const wxString& newProjectName = newProjectDir.GetDirs().Last();
700 wxDir currentProjectDir( currentProjectDirPath );
701
702 SAVE_AS_TRAVERSER traverser( m_frame, currentProjectDirPath, currentProjectName,
703 newProjectDirPath, newProjectName );
704
705 currentProjectDir.Traverse( traverser );
706
707 if( !traverser.GetErrors().empty() )
708 DisplayErrorMessage( m_frame, traverser.GetErrors() );
709
710 if( !traverser.GetNewProjectFile().FileExists() )
712
713 m_frame->LoadProject( traverser.GetNewProjectFile() );
714
715 return 0;
716}
717
718
720{
722 return 0;
723}
724
725
727{
728 ACTION_MENU* actionMenu = aEvent.Parameter<ACTION_MENU*>();
729 CONDITIONAL_MENU* conditionalMenu = dynamic_cast<CONDITIONAL_MENU*>( actionMenu );
730 SELECTION dummySel;
731
732 if( conditionalMenu )
733 conditionalMenu->Evaluate( dummySel );
734
735 if( actionMenu )
736 actionMenu->UpdateAll();
737
738 return 0;
739}
740
741
743{
744 FRAME_T playerType = aEvent.Parameter<FRAME_T>();
745 KIWAY_PLAYER* player;
746
747 if( playerType == FRAME_SCH && !m_frame->IsProjectActive() )
748 {
749 DisplayInfoMessage( m_frame, _( "Create (or open) a project to edit a schematic." ),
750 wxEmptyString );
751 return -1;
752 }
753 else if( playerType == FRAME_PCB_EDITOR && !m_frame->IsProjectActive() )
754 {
755 DisplayInfoMessage( m_frame, _( "Create (or open) a project to edit a pcb." ),
756 wxEmptyString );
757 return -1;
758 }
759
760 // Prevent multiple KIWAY_PLAYER loading at one time
761 if( !m_loading.try_lock() )
762 return -1;
763
764 const std::lock_guard<std::mutex> lock( m_loading, std::adopt_lock );
765
766 try
767 {
768 player = m_frame->Kiway().Player( playerType, true );
769 }
770 catch( const IO_ERROR& err )
771 {
772 wxLogError( _( "Application failed to load:\n" ) + err.What() );
773 return -1;
774 }
775
776 if ( !player )
777 {
778 wxLogError( _( "Application cannot start." ) );
779 return -1;
780 }
781
782 if( !player->IsVisible() ) // A hidden frame might not have the document loaded.
783 {
784 wxString filepath;
785
786 if( playerType == FRAME_SCH )
787 {
788 wxFileName kicad_schematic( m_frame->SchFileName() );
789 wxFileName legacy_schematic( m_frame->SchLegacyFileName() );
790
791 if( !legacy_schematic.FileExists() || kicad_schematic.FileExists() )
792 filepath = kicad_schematic.GetFullPath();
793 else
794 filepath = legacy_schematic.GetFullPath();
795 }
796 else if( playerType == FRAME_PCB_EDITOR )
797 {
798 wxFileName kicad_board( m_frame->PcbFileName() );
799 wxFileName legacy_board( m_frame->PcbLegacyFileName() );
800
801 if( !legacy_board.FileExists() || kicad_board.FileExists() )
802 filepath = kicad_board.GetFullPath();
803 else
804 filepath = legacy_board.GetFullPath();
805 }
806
807 if( !filepath.IsEmpty() )
808 {
809 std::vector<wxString> file_list{ filepath };
810
811 if( !player->OpenProjectFiles( file_list ) )
812 {
813 player->Destroy();
814 return -1;
815 }
816 }
817
818 wxBusyCursor busy;
819 player->Show( true );
820 }
821
822 // Needed on Windows, other platforms do not use it, but it creates no issue
823 if( player->IsIconized() )
824 player->Iconize( false );
825
826 player->Raise();
827
828 // Raising the window does not set the focus on Linux. This should work on
829 // any platform.
830 if( wxWindow::FindFocus() != player )
831 player->SetFocus();
832
833 // Save window state to disk now. Don't wait around for a crash.
834 if( Pgm().GetCommonSettings()->m_Session.remember_open_files
835 && !player->GetCurrentFileName().IsEmpty() )
836 {
837 wxFileName rfn( player->GetCurrentFileName() );
838 rfn.MakeRelativeTo( Prj().GetProjectPath() );
839
840 WINDOW_SETTINGS windowSettings;
841 player->SaveWindowSettings( &windowSettings );
842
843 Prj().GetLocalSettings().SaveFileState( rfn.GetFullPath(), &windowSettings, true );
844 Prj().GetLocalSettings().SaveToFile( Prj().GetProjectPath() );
845 }
846
847 return 0;
848}
849
850
851class TERMINATE_HANDLER : public wxProcess
852{
853public:
854 TERMINATE_HANDLER( const wxString& appName )
855 { }
856
857 void OnTerminate( int pid, int status ) override
858 {
859 delete this;
860 }
861};
862
863
865{
866 wxString execFile;
867 wxString param;
868
870 execFile = GERBVIEW_EXE;
872 execFile = BITMAPCONVERTER_EXE;
874 execFile = PCB_CALCULATOR_EXE;
876 execFile = PL_EDITOR_EXE;
878 execFile = Pgm().GetTextEditor();
880 execFile = EESCHEMA_EXE;
882 execFile = PCBNEW_EXE;
883 else
884 wxFAIL_MSG( "Execute(): unexpected request" );
885
886 if( execFile.IsEmpty() )
887 return 0;
888
889 if( aEvent.Parameter<wxString*>() )
890 param = *aEvent.Parameter<wxString*>();
892 param = m_frame->Prj().GetProjectPath();
893
894 TERMINATE_HANDLER* callback = new TERMINATE_HANDLER( execFile );
895
896 long pid = ExecuteFile( execFile, param, callback );
897
898 if( pid > 0 )
899 {
900#ifdef __WXMAC__
901 wxString script = wxString::Format( wxS( "tell application \"System Events\"\n"
902 " set frontmost of the first process whose unix id is %l to true\n"
903 "end tell" ), pid );
904
905 // This non-parameterized use of wxExecute is fine because script is not derived
906 // from user input.
907 wxExecute( wxString::Format( "osascript -e '%s'", script ) );
908#endif
909 }
910 else
911 {
912 delete callback;
913 }
914
915 return 0;
916}
917
918
920{
923 {
924 // policy disables the plugin manager
925 return 0;
926 }
927
928 // For some reason, after a click or a double click the bitmap button calling
929 // PCM keeps the focus althougt the focus was not set to this button.
930 // This hack force removing the focus from this button
931 m_frame->SetFocus();
932 wxSafeYield();
933
934 if( !m_frame->GetPcm() )
936
937 DIALOG_PCM pcm( m_frame, m_frame->GetPcm() );
938 pcm.ShowModal();
939
940 const std::unordered_set<PCM_PACKAGE_TYPE>& changed = pcm.GetChangedPackageTypes();
941
942 if( changed.count( PCM_PACKAGE_TYPE::PT_PLUGIN ) || changed.count( PCM_PACKAGE_TYPE::PT_FAB ) )
943 {
944 std::string payload = "";
946 }
947
949 KICAD_SETTINGS* settings = mgr.GetAppSettings<KICAD_SETTINGS>( "kicad" );
950
951 if( changed.count( PCM_PACKAGE_TYPE::PT_LIBRARY )
952 && ( settings->m_PcmLibAutoAdd || settings->m_PcmLibAutoRemove ) )
953 {
954 // Reset project tables
956 Prj().SetElem( PROJECT::ELEM::FPTBL, nullptr );
958
959 KIWAY& kiway = m_frame->Kiway();
960
961 // Reset state containing global lib tables
962 if( KIFACE* kiface = kiway.KiFACE( KIWAY::FACE_SCH, false ) )
963 kiface->Reset();
964
965 if( KIFACE* kiface = kiway.KiFACE( KIWAY::FACE_PCB, false ) )
966 kiface->Reset();
967
968 // Reload lib tables
969 std::string payload = "";
970
973 kiway.ExpressMail( FRAME_CVPCB, MAIL_RELOAD_LIB, payload );
976 }
977
978 if( changed.count( PCM_PACKAGE_TYPE::PT_COLORTHEME ) )
980
981 return 0;
982}
983
984
986{
997
1000
1010
1013
1015}
static TOOL_ACTION zoomRedraw
Definition: actions.h:124
static TOOL_ACTION saveAs
Definition: actions.h:52
static TOOL_ACTION updateMenu
Definition: actions.h:220
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
int ShowModal() override
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 newJobsetFile
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)
int NewJobsetFile(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()
void OpenJobsFile(const wxFileName &aFileName, bool aCreate=false)
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()
wxSize m_TemplateWindowSize
wxPoint m_TemplateWindowPos
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:284
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:291
@ FACE_PL_EDITOR
Definition: kiway.h:295
@ FACE_PCB
pcbnew DSO
Definition: kiway.h:292
@ FACE_GERBVIEW
Definition: kiway.h:294
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:354
virtual ENV_VAR_MAP & GetLocalEnvVariables() const
Definition: pgm_base.cpp:924
virtual const wxString & GetTextEditor(bool aCanShowFileChooser=true)
Return the path to the preferred text editor application.
Definition: pgm_base.cpp:196
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:142
The backing store for a PROJECT, in JSON format.
Definition: project_file.h:72
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)
virtual void SetElem(PROJECT::ELEM aIndex, _ELEM *aElem)
Definition: project.cpp:348
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:206
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:200
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(const wxString &aFilename)
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:309
int ExecuteFile(const wxString &aEditorName, const wxString &aFileName, wxProcess *aCallback, bool aFileForKicad)
Call the executable file aEditorName with the parameter aFileName.
Definition: gestfich.cpp:143
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 JobsetFileWildcard()
static wxString LegacyProjectFileWildcard()
static wxString AllProjectFilesWildcard()
std::map< wxString, ENV_VAR_ITEM >::const_iterator ENV_VAR_MAP_CITER
PROJECT & Prj()
Definition: kicad.cpp:597
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:1060
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.