32 #include <wx/filefn.h> 33 #include <wx/filename.h> 52 wxString aSchFileExtension, wxString aPcbFileExtension,
int aSchFileType,
int aPcbFileType )
56 int style = wxFD_OPEN | wxFD_FILE_MUST_EXIST;
58 wxFileDialog schdlg(
this, aWindowTitle, default_dir, wxEmptyString, aFilesWildcard, style );
60 if( schdlg.ShowModal() == wxID_CANCEL )
63 wxFileName sch( schdlg.GetPath() );
64 sch.SetExt( aSchFileExtension );
66 wxFileName pcb( sch );
67 pcb.SetExt( aPcbFileExtension );
69 wxFileName pro( sch );
72 wxString protitle =
_(
"KiCad Project Destination" );
76 wxDirDialog prodlg(
this, protitle, pro.GetPath(), wxDD_DEFAULT_STYLE );
78 if( prodlg.ShowModal() == wxID_CANCEL )
81 pro.SetPath( prodlg.GetPath() );
84 wxDir directory( pro.GetPath() );
86 if( directory.HasFiles() )
88 msg =
_(
"The selected directory is not empty. We recommend you " 89 "create projects in their own clean directory.\n\nDo you " 90 "want to create a new empty directory for the project?" );
92 KIDIALOG dlg(
this, msg,
_(
"Confirmation" ), wxYES_NO | wxICON_WARNING );
99 wxString newDir = pro.GetName();
102 pro.AppendDir( newDir );
104 while( pro.DirExists() )
108 pro.AppendDir( newDir + suffix );
111 if( !wxMkdir( pro.GetPath() ) )
113 msg =
_(
"Error creating new directory. Please try a different path. The " 114 "project cannot be imported." );
116 wxMessageDialog dirErrorDlg(
this, msg,
_(
"Error" ), wxOK_DEFAULT | wxICON_ERROR );
117 dirErrorDlg.ShowModal();
127 if( !pro.IsAbsolute() )
130 wxFileName schCopy( pro );
131 schCopy.SetExt( aSchFileExtension );
133 if( sch.Exists() && !schCopy.SameAs( sch ) )
135 if( !wxCopyFile( sch.GetFullPath(), schCopy.GetFullPath(), true ) )
138 msg.Printf(
_(
"Cannot copy file '%s'\n" 140 "The project cannot be imported." ),
141 sch.GetFullPath(), schCopy.GetFullPath() );
143 wxMessageDialog schCopyErrorDlg(
this, msg,
_(
"Error" ), wxOK_DEFAULT | wxICON_ERROR );
144 schCopyErrorDlg.ShowModal();
149 wxFileName pcbCopy( pro );
150 pcbCopy.SetExt( aPcbFileExtension );
152 if( pcb.Exists() && !pcbCopy.SameAs( pcb ) )
154 if( !wxCopyFile( pcb.GetFullPath(), pcbCopy.GetFullPath(), true ) )
157 msg.Printf(
_(
"Cannot copy file '%s'\n" 159 "The project cannot be imported." ),
160 pcb.GetFullPath(), pcbCopy.GetFullPath() );
162 wxMessageDialog brdCopyErrorDlg(
this, msg,
_(
"Error" ), wxOK_DEFAULT | wxICON_ERROR );
163 brdCopyErrorDlg.ShowModal();
173 if( schCopy.FileExists() )
177 packet =
StrPrintf(
"%d\n%s", aSchFileType,
TO_UTF8( schCopy.GetFullPath() ) );
180 if( !schframe->IsShown() )
181 schframe->Show(
true );
184 if( schframe->IsIconized() )
185 schframe->Iconize(
false );
189 if( !schCopy.SameAs( sch ) )
190 wxRemoveFile( schCopy.GetFullPath() );
193 if( pcbCopy.FileExists() )
197 if( !pcbframe->IsVisible() )
198 pcbframe->Show(
true );
200 packet =
StrPrintf(
"%d\n%s", aPcbFileType,
TO_UTF8( pcbCopy.GetFullPath() ) );
204 if( pcbframe->IsIconized() )
205 pcbframe->Iconize(
false );
209 if( !pcbCopy.SameAs( pcb ) )
210 wxRemoveFile( pcbCopy.GetFullPath() );
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
void DoNotShowCheckbox(wxString file, int line)
Checks the 'do not show again' setting for the dialog.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
This file is part of the common library.
const std::string ProjectFileExtension
const std::string LegacyPcbFileExtension
void ImportNonKiCadProject(wxString aWindowTitle, wxString aFilesWildcard, wxString aSchFileExtension, wxString aPcbFileExtension, int aSchFileType, int aPcbFileType)
Creates a project and imports a non-KiCad Schematic and PCB.
void OnImportEagleFiles(wxCommandEvent &event)
Open dialog to import Eagle schematic and board files.
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr)
Send aPayload to aDestination from aSource.
int StrPrintf(std::string *result, const char *format,...)
This is like sprintf() but the output is appended to a std::string instead of to a character array.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
void OnImportCadstarArchiveFiles(wxCommandEvent &event)
Open dialog to import CADSTAR Schematic and PCB Archive files.
wxString GetMruPath() const
Definition of file extensions used in Kicad.
const std::string LegacySchematicFileExtension
void CreateNewProject(const wxFileName &aProjectFileName, bool aCreateStubFiles=true)
Creates a new project by setting up and initial project, schematic, and board files.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
bool CloseProject(bool aSave)
Closes the project, and saves it if aSave is true;.
wxString EagleFilesWildcard()
void LoadProject(const wxFileName &aProjectFileName)
wxString CadstarArchiveFilesWildcard()