27#include <wx/fileconf.h>
29#include <wx/wfstream.h>
54 const std::vector<wxString>& aSchFileExtensions,
55 const std::vector<wxString>& aPcbFileExtensions ) :
57 m_schExtenstions( aSchFileExtensions ), m_pcbExtenstions( aPcbFileExtensions )
74 wxString suffix = wxString::Format(
"_%d", ++attempt );
93 wxString appImportFile;
94 std::vector<wxString> neededExts;
111 std::vector<SCOPED_FILE_REMOVER> copiedFiles;
113 for( wxString ext : neededExts )
115 if( ext == wxS(
"INPUT" ) )
119 candidate.SetExt( ext );
121 if( !candidate.FileExists() )
124 wxFileName targetFile(
m_TargetProj.GetPath(), candidate.GetName(), candidate.GetExt() );
126 if( !targetFile.FileExists() )
128 bool copied = wxCopyFile( candidate.GetFullPath(), targetFile.GetFullPath(),
false );
133 copiedFiles.emplace_back( targetFile.GetFullPath() );
138 if( appImportFile.empty() && targetFile.FileExists() )
139 appImportFile = targetFile.GetFullPath();
142 if( appImportFile.empty() )
145 doImport( appImportFile, frame_type, aImportedFileType );
153 std::stringstream ss;
154 ss << aImportedFileType <<
'\n' <<
TO_UTF8( aFile );
157 ss <<
'\n' << key <<
'\n' << value.wx_str();
159 std::string packet = ss.str();
162 if( !frame->IsShownOnScreen() )
166 if( frame->IsIconized() )
167 frame->Iconize(
false );
178 if( fname.GetExt() == wxS(
"epro" ) || fname.GetExt() == wxS(
"zip" ) )
182 std::map<wxString, EASYEDAPRO::PRJ_SCHEMATIC> prjSchematics =
project.at(
"schematics" );
183 std::map<wxString, EASYEDAPRO::PRJ_BOARD> prjBoards =
project.at(
"boards" );
184 std::map<wxString, wxString> prjPcbNames =
project.at(
"pcbs" );
186 std::vector<IMPORT_PROJECT_DESC> toImport =
189 if( toImport.size() > 1 )
192 if( toImport.size() == 1 )
212 std::stringstream ss;
214 for(
const wxString&
name : aNames )
216 wxFileName fname(
name );
218 ss <<
TO_UTF8( fname.GetFullPath() ) <<
'\n';
221 std::string packet = ss.str();
228 wxFFileInputStream stream(
m_InputFile.GetFullPath() );
233 wxFileConfig
config( stream );
237 std::set<wxString> sch_file;
238 std::set<wxString> pcb_file;
239 std::set<wxString> sch_libs;
240 std::set<wxString> pcb_libs;
242 for(
bool more =
config.GetFirstGroup( groupname, groupid ); more;
243 more =
config.GetNextGroup( groupname, groupid ) )
245 if( !groupname.StartsWith( wxS(
"Document" ) ) )
248 wxString number = groupname.Mid( 8 );
251 if( !number.ToLong( &docNumber ) )
254 wxString
path =
config.Read( groupname + wxS(
"/DocumentPath" ), wxEmptyString );
259 wxFileName fname(
path );
261 if( !fname.IsAbsolute() )
264 if( !fname.GetExt().CmpNoCase(
"PCBDOC" ) )
265 pcb_file.insert( fname.GetFullPath() );
267 if( !fname.GetExt().CmpNoCase(
"SCHDOC" ) )
268 sch_file.insert( fname.GetFullPath() );
270 if( !fname.GetExt().CmpNoCase(
"PCBLIB" ) )
271 pcb_libs.insert( fname.GetFullPath() );
273 if( !fname.GetExt().CmpNoCase(
"SCHLIB" ) )
274 sch_libs.insert( fname.GetFullPath() );
284 for(
auto&
path : sch_file )
286 std::string key =
"sch" + std::to_string( ii++ );
290 if( !sch_file.empty() )
293 if( !pcb_file.empty() )
302 if( aImportedSchFileType == SCH_IO_MGR::SCH_EASYEDAPRO
307 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 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.
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.