32 #include <wx/filefn.h> 33 #include <wx/filename.h> 35 #include <wx/filedlg.h> 36 #include <wx/dirdlg.h> 55 const wxString& aFilesWildcard,
56 const wxString& aSchFileExtension,
57 const wxString& aPcbFileExtension,
58 int aSchFileType,
int aPcbFileType )
62 int style = wxFD_OPEN | wxFD_FILE_MUST_EXIST;
64 wxFileDialog schdlg(
this, aWindowTitle, default_dir, wxEmptyString, aFilesWildcard, style );
66 if( schdlg.ShowModal() == wxID_CANCEL )
74 wxFileName sch( schdlg.GetPath() );
75 sch.SetExt( aSchFileExtension );
77 wxFileName pcb( sch );
78 pcb.SetExt( aPcbFileExtension );
80 wxFileName pro( sch );
83 wxString protitle =
_(
"KiCad Project Destination" );
87 wxDirDialog prodlg(
this, protitle, pro.GetPath(), wxDD_DEFAULT_STYLE );
89 if( prodlg.ShowModal() == wxID_CANCEL )
92 pro.SetPath( prodlg.GetPath() );
99 msg =
_(
"The selected directory is not empty. We recommend you " 100 "create projects in their own clean directory.\n\nDo you " 101 "want to create a new empty directory for the project?" );
103 KIDIALOG dlg(
this, msg,
_(
"Confirmation" ), wxYES_NO | wxICON_WARNING );
110 wxString newDir = pro.GetName();
113 pro.AppendDir( newDir );
115 while( pro.DirExists() )
119 pro.AppendDir( newDir + suffix );
122 if( !wxMkdir( pro.GetPath() ) )
124 msg =
_(
"Error creating new directory. Please try a different path. The " 125 "project cannot be imported." );
127 wxMessageDialog dirErrorDlg(
this, msg,
_(
"Error" ), wxOK_DEFAULT | wxICON_ERROR );
128 dirErrorDlg.ShowModal();
138 if( !pro.IsAbsolute() )
141 wxFileName schCopy( pro );
142 schCopy.SetExt( aSchFileExtension );
144 if( sch.Exists() && !schCopy.SameAs( sch ) )
146 if( !wxCopyFile( sch.GetFullPath(), schCopy.GetFullPath(), true ) )
149 msg.Printf(
_(
"Cannot copy file '%s'\n" 151 "The project cannot be imported." ),
152 sch.GetFullPath(), schCopy.GetFullPath() );
154 wxMessageDialog schCopyErrorDlg(
this, msg,
_(
"Error" ), wxOK_DEFAULT | wxICON_ERROR );
155 schCopyErrorDlg.ShowModal();
160 wxFileName pcbCopy( pro );
161 pcbCopy.SetExt( aPcbFileExtension );
163 if( pcb.Exists() && !pcbCopy.SameAs( pcb ) )
165 if( !wxCopyFile( pcb.GetFullPath(), pcbCopy.GetFullPath(), true ) )
168 msg.Printf(
_(
"Cannot copy file '%s'\n" 170 "The project cannot be imported." ),
171 pcb.GetFullPath(), pcbCopy.GetFullPath() );
173 wxMessageDialog brdCopyErrorDlg(
this, msg,
_(
"Error" ), wxOK_DEFAULT | wxICON_ERROR );
174 brdCopyErrorDlg.ShowModal();
182 if( schCopy.FileExists() )
186 packet =
StrPrintf(
"%d\n%s", aSchFileType,
TO_UTF8( schCopy.GetFullPath() ) );
189 if( !schframe->IsShown() )
190 schframe->Show(
true );
193 if( schframe->IsIconized() )
194 schframe->Iconize(
false );
198 if( !schCopy.SameAs( sch ) )
199 wxRemoveFile( schCopy.GetFullPath() );
202 if( pcbCopy.FileExists() )
206 if( !pcbframe->IsVisible() )
207 pcbframe->Show(
true );
209 packet =
StrPrintf(
"%d\n%s", aPcbFileType,
TO_UTF8( pcbCopy.GetFullPath() ) );
213 if( pcbframe->IsIconized() )
214 pcbframe->Iconize(
false );
218 if( !pcbCopy.SameAs( pcb ) )
219 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 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.
void ImportNonKiCadProject(const wxString &aWindowTitle, const wxString &aFilesWildcard, const wxString &aSchFileExtension, const wxString &aPcbFileExtension, int aSchFileType, int aPcbFileType)
Creates a project and imports a non-KiCad Schematic and PCB.
This file contains miscellaneous commonly used macros and functions.
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()