41#include <wx/checkbox.h>
43#include <wx/filedlg.h>
50#if wxCHECK_VERSION( 3, 1, 7 )
65 m_frame = getEditFrame<KICAD_MANAGER_FRAME>();
72 wxFileDialog dlg(
m_frame,
_(
"Create New Project" ), default_dir, wxEmptyString,
76#if wxCHECK_VERSION( 3, 1, 7 )
78 dlg.SetCustomizeHook( newProjectHook );
83 if( dlg.ShowModal() == wxID_CANCEL )
86 wxFileName pro( dlg.GetPath() );
91 pro.SetName( pro.GetName() + wxT(
"." ) + pro.GetExt() );
95 if( !pro.IsAbsolute() )
99 bool createNewDir =
false;
101#if wxCHECK_VERSION( 3, 1, 7 )
108 pro.AppendDir( pro.GetName() );
113 if( !pro.DirExists() )
118 msg.Printf(
_(
"Folder '%s' could not be created.\n\n"
119 "Make sure you have write permissions and try again." ),
127 wxString msg =
_(
"The selected folder is not empty. It is recommended that you "
128 "create projects in their own empty folder.\n\n"
129 "Do you want to continue?" );
146 wxFileName templatePath;
151 if( it !=
Pgm().GetLocalEnvVariables().end() && it->second.GetValue() != wxEmptyString )
153 templatePath.AssignDir( it->second.GetValue() );
158 it =
Pgm().GetLocalEnvVariables().find(
"KICAD_USER_TEMPLATE_DIR" );
160 if( it !=
Pgm().GetLocalEnvVariables().end() && it->second.GetValue() != wxEmptyString )
162 templatePath.AssignDir( it->second.GetValue() );
167 if( ps->ShowModal() != wxID_OK )
172 wxMessageBox(
_(
"No project template was selected. Cannot generate new project." ),
173 _(
"Error" ), wxOK | wxICON_ERROR,
m_frame );
179 wxString default_dir = wxFileName(
Prj().GetProjectFullName() ).GetPathWithSep();
180 wxString title =
_(
"New Project Folder" );
182 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
185#if wxCHECK_VERSION( 3, 1, 7 )
187 dlg.SetCustomizeHook( newProjectHook );
193 if( dlg.ShowModal() == wxID_CANCEL )
196 wxFileName fn( dlg.GetPath() );
201 fn.SetName( fn.GetName() + wxT(
"." ) + fn.GetExt() );
205 if( !fn.IsAbsolute() )
208 bool createNewDir =
false;
209#if wxCHECK_VERSION( 3, 1, 7 )
217 fn.AppendDir( fn.GetName() );
221 if( !fn.DirExists() )
226 msg.Printf(
_(
"Folder '%s' could not be created.\n\n"
227 "Make sure you have write permissions and try again." ),
234 if( !fn.IsDirWritable() )
238 msg.Printf(
_(
"Insufficient permissions to write to folder '%s'." ), fn.GetPath() );
239 wxMessageDialog msgDlg(
m_frame, msg,
_(
"Error" ), wxICON_ERROR | wxOK | wxCENTER );
245 std::vector< wxFileName > destFiles;
249 std::vector<wxFileName> overwrittenFiles;
251 for(
const wxFileName& file : destFiles )
253 if( file.FileExists() )
254 overwrittenFiles.push_back( file );
257 if( !overwrittenFiles.empty() )
259 wxString extendedMsg =
_(
"Overwriting files:" ) +
"\n";
261 for(
const wxFileName& file : overwrittenFiles )
262 extendedMsg +=
"\n" + file.GetFullName();
265 _(
"Similar files already exist in the destination folder." ),
267 wxOK | wxCANCEL | wxICON_WARNING );
268 msgDlg.SetExtendedMessage( extendedMsg );
269 msgDlg.SetOKLabel(
_(
"Overwrite" ) );
283 wxMessageDialog createDlg(
m_frame,
284 _(
"A problem occurred creating new project from template." ),
286 wxOK | wxICON_ERROR );
288 if( !errorMsg.empty() )
289 createDlg.SetExtendedMessage( errorMsg );
291 createDlg.ShowModal();
307 wxFileDialog dlg(
m_frame,
_(
"Open Existing Project" ), aDefaultDir, wxEmptyString, wildcard,
308 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
310 if( dlg.ShowModal() == wxID_CANCEL )
313 wxFileName pro( dlg.GetPath() );
315 if( !pro.IsAbsolute() )
318 if( !pro.FileExists() )
351 wxFileName droppedFileName( *aEvent.
Parameter<wxString*>() );
353 wxString schFileExtension, pcbFileExtension;
354 int schFileType, pcbFileType;
368 schFileType = SCH_IO_MGR::SCH_EAGLE;
377 schFileType = SCH_IO_MGR::SCH_CADSTAR_ARCHIVE;
430 wxExecute( *aEvent.
Parameter<wxString*>(), wxEXEC_ASYNC );
438 const wxString& aSrcProjectDirPath,
439 const wxString& aSrcProjectName,
440 const wxString& aNewProjectDirPath,
441 const wxString& aNewProjectName ) :
450 virtual wxDirTraverseResult
OnFile(
const wxString& aSrcFilePath )
override
454 return wxDIR_CONTINUE;
456 wxFileName destFile( aSrcFilePath );
457 wxString ext = destFile.GetExt();
464 wxString destPath = destFile.GetPath();
469 destFile.SetPath( destPath );
489 projectFile.
SaveAs( destFile.GetPath(), destFile.GetName() );
495 projectLocalSettings.
SaveAs( destFile.GetPath(), destFile.GetName() );
507 || destFile.GetName() ==
"sym-lib-table" )
519 || destFile.GetName() ==
"fp-lib-table" )
542 wxString destPath = destFile.GetPathWithSep();
543 wxString destName = destFile.GetName();
544 wxUniChar pathSep = wxFileName::GetPathSeparator();
546 wxString srcProjectFootprintLib = pathSep +
m_projectName +
".pretty" + pathSep;
547 wxString newProjectFootprintLib = pathSep +
m_newProjectName +
".pretty" + pathSep;
552 destPath.Replace( srcProjectFootprintLib, newProjectFootprintLib,
true );
557 destFile.SetPath( destPath );
562 return wxDIR_CONTINUE;
565 virtual wxDirTraverseResult
OnDir(
const wxString& aSrcDirPath )
override
569 return wxDIR_CONTINUE;
571 wxFileName destDir( aSrcDirPath );
572 wxString destDirPath = destDir.GetPathWithSep();
573 wxUniChar pathSep = wxFileName::GetPathSeparator();
579 destDir.SetPath( destDirPath );
584 if( destDir.GetExt() ==
"pretty" )
589 else if( destDir.GetExt() ==
"sym_lib_dir_extension" )
594 if( !wxMkdir( destDir.GetFullPath() ) )
601 msg.Printf(
_(
"Cannot copy folder '%s'." ), destDir.GetFullPath() );
605 return wxDIR_CONTINUE;
629 wxFileName currentProjectFile(
Prj().GetProjectFullName() );
630 wxString currentProjectDirPath = currentProjectFile.GetPath();
638 if( default_dir == currentProjectDirPath
639 || default_dir == currentProjectDirPath + wxFileName::GetPathSeparator() )
642 wxFileName default_dir_fn( default_dir );
643 default_dir_fn.RemoveLastDir();
644 default_dir = default_dir_fn.GetPath();
647 wxFileDialog dlg(
m_frame,
_(
"Save Project To" ), default_dir, wxEmptyString, wxEmptyString,
650 if( dlg.ShowModal() == wxID_CANCEL )
653 wxFileName newProjectDir( dlg.GetPath(), wxEmptyString );
655 if( !newProjectDir.IsAbsolute() )
656 newProjectDir.MakeAbsolute();
658 if( wxDirExists( newProjectDir.GetFullPath() ) )
660 msg.Printf(
_(
"'%s' already exists." ), newProjectDir.GetFullPath() );
665 if( !wxMkdir( newProjectDir.GetFullPath() ) )
667 msg.Printf(
_(
"Folder '%s' could not be created.\n\n"
668 "Please make sure you have write permissions and try again." ),
669 newProjectDir.GetPath() );
674 if( !newProjectDir.IsDirWritable() )
676 msg.Printf(
_(
"Insufficient permissions to write to folder '%s'." ),
677 newProjectDir.GetFullPath() );
678 wxMessageDialog msgDlg(
m_frame, msg,
_(
"Error!" ), wxICON_ERROR | wxOK | wxCENTER );
683 const wxString& newProjectDirPath = newProjectDir.GetFullPath();
684 const wxString& newProjectName = newProjectDir.GetDirs().Last();
685 wxDir currentProjectDir( currentProjectDirPath );
688 newProjectDirPath, newProjectName );
690 currentProjectDir.Traverse( traverser );
717 if( conditionalMenu )
718 conditionalMenu->Evaluate( dummySel );
749 const std::lock_guard<std::mutex> lock(
m_loading, std::adopt_lock );
757 wxMessageBox(
_(
"Application failed to load:\n" ) + err.
What(),
_(
"KiCad Error" ),
758 wxOK | wxICON_ERROR,
m_frame );
764 wxMessageBox(
_(
"Application failed to load." ),
_(
"KiCad Error" ),
765 wxOK | wxICON_ERROR,
m_frame );
769 if( !player->IsVisible() )
778 if( !legacy_schematic.FileExists() || kicad_schematic.FileExists() )
779 filepath = kicad_schematic.GetFullPath();
781 filepath = legacy_schematic.GetFullPath();
788 if( !legacy_board.FileExists() || kicad_board.FileExists() )
789 filepath = kicad_board.GetFullPath();
791 filepath = legacy_board.GetFullPath();
794 if( !filepath.IsEmpty() )
796 if( !player->OpenProjectFiles( std::vector<wxString>( 1, filepath ) ) )
804 player->Show(
true );
808 if( player->IsIconized() )
809 player->Iconize(
false );
815 if( wxWindow::FindFocus() != player )
849 execFile =
Pgm().GetTextEditor();
855 wxFAIL_MSG(
"Execute(): unexpected request" );
857 if( execFile.IsEmpty() )
867 long pid =
ExecuteFile( execFile, param, callback );
874 wxExecute(
"osascript -e 'activate application \"" + execFile +
"\"'" );
908 std::string payload =
"";
933 std::string payload =
"";
943 Pgm().GetSettingsManager().ReloadColorSettings();
static TOOL_ACTION zoomRedraw
static TOOL_ACTION saveAs
static TOOL_ACTION updateMenu
Implementing pcm main dialog.
const std::unordered_set< PCM_PACKAGE_TYPE > & GetChangedPackageTypes() const
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
A helper class to import non Kicad project.
void AssociateFilesWithProj(int aImportedSchFileType, int aImportedPcbFileType)
Converts imported files to kicad type files.
wxString GetProjFullPath()
const wxFileName & GetProj()
void CreateEmptyDirForProject()
Appends a new directory with the name of the project file Keep iterating until an empty directory is ...
void SetProjAbsolutePath()
bool CopyImportedFiles(bool displayError=true)
Copies project files to the destination directory.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
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 importNonKicadProj
static TOOL_ACTION viewGerbers
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)
int NewFromTemplate(const TOOL_EVENT &aEvent)
int ShowPluginManager(const TOOL_EVENT &aEvent)
Set up handlers for various events.
int UpdateMenu(const TOOL_EVENT &aEvent)
int ImportNonKicadProj(const TOOL_EVENT &aEvent)
Imports a non kicad project from a sch/pcb dropped file.
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;.
void RefreshProjectTree()
const wxString PcbFileName()
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
void DoNotShowCheckbox(wxString file, int line)
Checks the 'do not show again' setting for the dialog.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
virtual KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Return the KIFACE* given a FACE_T.
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr)
Send aPayload to aDestination from aSource.
‍Helper widget to select whether a new directory should be created for a project.
static wxWindow * Create(wxWindow *aParent)
static wxString GetStockDemosPath()
Gets the stock (install) demos path.
The backing store for a PROJECT, in JSON format.
bool SaveAs(const wxString &aDirectory, const wxString &aFile)
bool SaveToFile(const wxString &aDirectory="", bool aForce=false) override
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
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.
virtual const wxString GetProjectName() const
Return the short name of the project.
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
virtual PROJECT_FILE & GetProjectFile() const
virtual void SetElem(ELEM_T aIndex, _ELEM *aElem)
wxString m_newProjectName
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
wxString m_projectDirPath
wxFileName GetNewProjectFile()
wxString m_newProjectDirPath
wxFileName m_newProjectFile
void OnTerminate(int pid, int status) override
TERMINATE_HANDLER(const wxString &appName)
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
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.
@ FRAME_SCH_SYMBOL_EDITOR
void KiCopyFile(const wxString &aSrcPath, const wxString &aDestPath, wxString &aErrors)
int ExecuteFile(const wxString &aEditorName, const wxString &aFileName, wxProcess *aCallback)
Call the executable file aEditorName with the parameter aFileName.
const std::string LegacyPcbFileExtension
const std::string CadstarPcbFileExtension
const std::string BackupFileSuffix
const std::string KiCadSymbolLibFileExtension
const std::string LegacySchematicFileExtension
const std::string FootprintAssignmentFileExtension
const std::string GerberJobFileExtension
const std::string LegacySymbolDocumentFileExtension
const std::string DrillFileExtension
const std::string EagleSchematicFileExtension
const std::string KiCadFootprintFileExtension
const std::string LegacyProjectFileExtension
const std::string KiCadPcbFileExtension
bool IsGerberFileExtension(const wxString &ext)
const std::string LegacyFootprintLibPathExtension
const std::string ProjectLocalSettingsFileExtension
const std::string ProjectFileExtension
const std::string NetlistFileExtension
const std::string EaglePcbFileExtension
const std::string CadstarSchematicFileExtension
const std::string KiCadSchematicFileExtension
const std::string DrawingSheetFileExtension
const std::string SchematicSymbolFileExtension
const std::string LegacySymbolLibFileExtension
wxString AllProjectFilesWildcard()
wxString LegacyProjectFileWildcard()
wxString ProjectFileWildcard()
std::map< wxString, ENV_VAR_ITEM >::const_iterator ENV_VAR_MAP_CITER
This file contains miscellaneous commonly used macros and functions.
#define PROJECT_BACKUPS_DIR_SUFFIX
Project settings path will be <projectname> + this.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Implement a participant in the KIWAY alchemy.
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 of file extensions used in Kicad.