27#include <wx/fileconf.h>
29#include <wx/wfstream.h>
51 const std::vector<wxString>& aSchFileExtensions,
52 const std::vector<wxString>& aPcbFileExtensions ) :
71 wxString suffix = wxString::Format(
"_%d", ++attempt );
90 wxString appImportFile;
91 std::vector<wxString> neededExts;
108 std::vector<SCOPED_FILE_REMOVER> copiedFiles;
110 for( wxString ext : neededExts )
112 if( ext == wxS(
"INPUT" ) )
116 candidate.SetExt( ext );
118 if( !candidate.FileExists() )
121 wxFileName targetFile(
m_TargetProj.GetPath(), candidate.GetName(), candidate.GetExt() );
123 if( !targetFile.FileExists() )
125 bool copied = wxCopyFile( candidate.GetFullPath(), targetFile.GetFullPath(),
false );
130 copiedFiles.emplace_back( targetFile.GetFullPath() );
135 if( appImportFile.empty() && targetFile.FileExists() )
136 appImportFile = targetFile.GetFullPath();
139 if( appImportFile.empty() )
142 doImport( appImportFile, frame_type, aImportedFileType );
150 std::stringstream ss;
151 ss << aImportedFileType <<
'\n' <<
TO_UTF8( aFile );
154 ss <<
'\n' << key <<
'\n' << value.wx_str();
156 std::string packet = ss.str();
159 if( !frame->IsShownOnScreen() )
163 if( frame->IsIconized() )
164 frame->Iconize(
false );
175 if( fname.GetExt() == wxS(
"epro" ) || fname.GetExt() == wxS(
"zip" ) )
179 std::map<wxString, EASYEDAPRO::PRJ_SCHEMATIC> prjSchematics =
project.at(
"schematics" );
180 std::map<wxString, EASYEDAPRO::PRJ_BOARD> prjBoards =
project.at(
"boards" );
181 std::map<wxString, wxString> prjPcbNames =
project.at(
"pcbs" );
183 std::vector<IMPORT_PROJECT_DESC> toImport =
186 if( toImport.size() > 1 )
189 if( toImport.size() == 1 )
209 std::stringstream ss;
211 for(
const wxString&
name : aNames )
213 wxFileName fname(
name );
215 ss <<
TO_UTF8( fname.GetFullPath() ) <<
'\n';
218 std::string packet = ss.str();
225 wxFileConfig
config( wxEmptyString, wxEmptyString, wxEmptyString,
m_InputFile.GetFullPath(),
226 wxCONFIG_USE_NO_ESCAPE_CHARACTERS );
231 std::set<wxString> sch_file;
232 std::set<wxString> pcb_file;
233 std::set<wxString> sch_libs;
234 std::set<wxString> pcb_libs;
236 for(
bool more =
config.GetFirstGroup( groupname, groupid ); more;
237 more =
config.GetNextGroup( groupname, groupid ) )
239 if( !groupname.StartsWith( wxS(
"Document" ) ) )
242 wxString number = groupname.Mid( 8 );
245 if( !number.ToLong( &docNumber ) )
248 wxString
path =
config.Read( groupname + wxS(
"/DocumentPath" ), wxEmptyString );
253 wxFileName fname(
path, wxPATH_WIN );
255 if( !fname.IsAbsolute() )
258 if( !fname.GetExt().CmpNoCase(
"PCBDOC" ) )
259 pcb_file.insert( fname.GetFullPath() );
261 if( !fname.GetExt().CmpNoCase(
"SCHDOC" ) )
262 sch_file.insert( fname.GetFullPath() );
264 if( !fname.GetExt().CmpNoCase(
"PCBLIB" ) )
265 pcb_libs.insert( fname.GetFullPath() );
267 if( !fname.GetExt().CmpNoCase(
"SCHLIB" ) )
268 sch_libs.insert( fname.GetFullPath() );
278 for(
auto&
path : sch_file )
280 std::string key =
"sch" + std::to_string( ii++ );
284 if( !sch_file.empty() )
287 if( !pcb_file.empty() )
296 if( aImportedSchFileType == SCH_IO_MGR::SCH_EASYEDAPRO
301 else if( aImportedSchFileType == SCH_IO_MGR::SCH_ALTIUM
static std::vector< IMPORT_PROJECT_DESC > RunModal(wxWindow *aParent, const std::vector< IMPORT_PROJECT_DESC > &aProjectDesc)
Create and show a dialog (modal) and returns the data from it after completion.
void EasyEDAProProjectHandler()
IMPORT_PROJ_HELPER(KICAD_MANAGER_FRAME *aframe, const std::vector< wxString > &aSchFileExtensions, const std::vector< wxString > &aPcbFileExtensions)
std::map< std::string, UTF8 > m_properties
void FindEmptyTargetDir()
Appends a new directory with the name of the project file Keep iterating until an empty directory is ...
std::vector< wxString > m_pcbExtenstions
void AltiumProjectHandler()
KICAD_MANAGER_FRAME * m_frame
void ImportFiles(int aImportedSchFileType, int aImportedPcbFileType)
Converts imported files to kicad type files.
void addLocalLibraries(const std::set< wxString > &aLibName, FRAME_T aFrameType)
void ImportIndividualFile(KICAD_T aKicad_T, int aImportedFileType)
std::vector< wxString > m_schExtenstions
void doImport(const wxString &aFile, FRAME_T aFrameType, int aImportedFileType)
The main KiCad project manager frame.
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.
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr, bool aFromOtherThread=false)
Send aPayload to aDestination from aSource.
SCOPED_FILE_REMOVER(const wxString &aFile)
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
This file contains miscellaneous commonly used macros and functions.
std::vector< IMPORT_PROJECT_DESC > ProjectToSelectorDialog(const nlohmann::json &aProject, bool aPcbOnly=false, bool aSchOnly=false)
nlohmann::json ReadProjectOrDeviceFile(const wxString &aZipFileName)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Describes how non-KiCad boards and schematics should be imported as KiCad projects.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition of file extensions used in Kicad.