27#include <wx/fileconf.h>
29#include <wx/wfstream.h>
53 const std::vector<wxString>& aSchFileExtensions,
54 const std::vector<wxString>& aPcbFileExtensions ) :
73 wxString suffix = wxString::Format(
"_%d", ++attempt );
92 wxString appImportFile;
93 std::vector<wxString> neededExts;
110 std::vector<SCOPED_FILE_REMOVER> copiedFiles;
112 for( wxString ext : neededExts )
114 if( ext == wxS(
"INPUT" ) )
118 candidate.SetExt( ext );
120 if( !candidate.FileExists() )
123 wxFileName targetFile(
m_TargetProj.GetPath(), candidate.GetName(), candidate.GetExt() );
125 if( !targetFile.FileExists() )
127 bool copied = wxCopyFile( candidate.GetFullPath(), targetFile.GetFullPath(),
false );
132 copiedFiles.emplace_back( targetFile.GetFullPath() );
137 if( appImportFile.empty() && targetFile.FileExists() )
138 appImportFile = targetFile.GetFullPath();
141 if( appImportFile.empty() )
144 doImport( appImportFile, frame_type, aImportedFileType );
152 std::stringstream ss;
153 ss << aImportedFileType <<
'\n' <<
TO_UTF8( aFile );
156 ss <<
'\n' << key <<
'\n' << value.wx_str();
158 std::string packet = ss.str();
161 if( !frame->IsShownOnScreen() )
165 if( frame->IsIconized() )
166 frame->Iconize(
false );
177 if( fname.GetExt() == wxS(
"epro" ) || fname.GetExt() == wxS(
"zip" ) )
181 std::map<wxString, EASYEDAPRO::PRJ_SCHEMATIC> prjSchematics =
project.at(
"schematics" );
182 std::map<wxString, EASYEDAPRO::PRJ_BOARD> prjBoards =
project.at(
"boards" );
183 std::map<wxString, wxString> prjPcbNames =
project.at(
"pcbs" );
185 std::vector<IMPORT_PROJECT_DESC> toImport =
188 if( toImport.size() > 1 )
191 if( toImport.size() == 1 )
211 std::stringstream ss;
213 for(
const wxString&
name : aNames )
215 wxFileName fname(
name );
217 ss <<
TO_UTF8( fname.GetFullPath() ) <<
'\n';
220 std::string packet = ss.str();
227 wxFileConfig
config( wxEmptyString, wxEmptyString, wxEmptyString,
m_InputFile.GetFullPath(),
228 wxCONFIG_USE_NO_ESCAPE_CHARACTERS );
233 std::set<wxString> sch_file;
234 std::set<wxString> pcb_file;
235 std::set<wxString> sch_libs;
236 std::set<wxString> pcb_libs;
238 for(
bool more =
config.GetFirstGroup( groupname, groupid ); more;
239 more =
config.GetNextGroup( groupname, groupid ) )
241 if( !groupname.StartsWith( wxS(
"Document" ) ) )
244 wxString number = groupname.Mid( 8 );
247 if( !number.ToLong( &docNumber ) )
250 wxString
path =
config.Read( groupname + wxS(
"/DocumentPath" ), wxEmptyString );
255 wxFileName fname(
path, wxPATH_WIN );
257 if( !fname.IsAbsolute() )
260 if( !fname.GetExt().CmpNoCase(
"PCBDOC" ) )
261 pcb_file.insert( fname.GetFullPath() );
263 if( !fname.GetExt().CmpNoCase(
"SCHDOC" ) )
264 sch_file.insert( fname.GetFullPath() );
266 if( !fname.GetExt().CmpNoCase(
"PCBLIB" ) )
267 pcb_libs.insert( fname.GetFullPath() );
269 if( !fname.GetExt().CmpNoCase(
"SCHLIB" ) )
270 sch_libs.insert( fname.GetFullPath() );
280 for(
auto&
path : sch_file )
282 std::string key =
"sch" + std::to_string( ii++ );
286 if( !sch_file.empty() )
289 if( !pcb_file.empty() )
298 if( aImportedSchFileType == SCH_IO_MGR::SCH_EASYEDAPRO
303 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.