38#include <wx/txtstrm.h>
39#include <wx/wfstream.h>
40#include <wx/mstream.h>
41#include <wx/zipstrm.h>
53 std::map<wxString, EASYEDAPRO::BLOB>
m_Blobs;
54 std::map<wxString, std::multimap<wxString, EASYEDAPRO::POURED>>
m_Poured;
72 if( aFileName.Lower().EndsWith( wxS(
".epro" ) ) )
76 else if( aFileName.Lower().EndsWith( wxS(
".zip" ) ) )
78 std::shared_ptr<wxZipEntry> entry;
79 wxFFileInputStream in( aFileName );
80 wxZipInputStream
zip( in );
85 while( entry.reset(
zip.GetNextEntry() ), entry.get() != NULL )
87 wxString
name = entry->GetName();
89 if(
name == wxS(
"project.json" ) )
121 wxFileName fname( aFileName );
123 if( fname.GetExt() == wxS(
"epro" ) || fname.GetExt() == wxS(
"zip" ) )
131 pcbToLoad = wxString::FromUTF8( aProperties->at(
"pcb_id" ) );
135 std::map<wxString, wxString> prjPcbNames =
project.at(
"pcbs" );
137 if( prjPcbNames.size() == 1 )
139 pcbToLoad = prjPcbNames.begin()->first;
146 if( chosen.size() > 0 )
147 pcbToLoad = chosen[0].PCBId;
151 if( pcbToLoad.empty() )
159 auto cb = [&](
const wxString&
name,
const wxString& pcbUuid, wxInputStream&
zip ) ->
bool
161 if( !
name.EndsWith( wxS(
".epcb" ) ) )
164 if( pcbUuid != pcbToLoad )
169 wxString boardKey = pcbUuid + wxS(
"_0" );
170 wxScopedCharBuffer cb = boardKey.ToUTF8();
171 wxString boardPouredKey = wxBase64Encode( cb.data(), cb.length() );
173 const std::multimap<wxString, EASYEDAPRO::POURED>& boardPoured =
196 const wxString& aLibraryPath,
bool aBestEfforts,
199 wxFileName fname( aLibraryPath );
201 if( fname.GetExt() == wxS(
"efoo" ) )
203 wxFFileInputStream ffis( aLibraryPath );
204 wxTextInputStream txt( ffis, wxS(
" " ), wxConvUTF8 );
206 while( ffis.CanRead() )
208 wxString line = txt.ReadLine();
210 if( !line.Contains( wxS(
"ATTR" ) ) )
213 nlohmann::json js = nlohmann::json::parse( line );
214 if( js.at( 0 ) ==
"ATTR" && js.at( 7 ) ==
"Footprint" )
216 aFootprintNames.Add( js.at( 8 ).get<wxString>() );
220 else if( fname.GetExt() == wxS(
"elibz" ) || fname.GetExt() == wxS(
"epro" )
221 || fname.GetExt() == wxS(
"zip" ) )
224 std::map<wxString, nlohmann::json> footprintMap =
project.at(
"footprints" );
226 for(
auto& [key, value] : footprintMap )
230 if( value.contains(
"display_title" ) )
231 title = value.at(
"display_title" ).get<wxString>();
233 title = value.at(
"title" ).get<wxString>();
235 aFootprintNames.Add( title );
242 const nlohmann::json& aProject )
250 wxFileName fname( aProjectPath );
253 std::map<wxString, std::unique_ptr<FOOTPRINT>> result;
255 auto cb = [&](
const wxString&
name,
const wxString& baseName, wxInputStream&
zip ) ->
bool
257 if( !
name.EndsWith( wxS(
".efoo" ) ) && !
name.EndsWith( wxS(
".eblob" ) )
258 && !
name.EndsWith( wxS(
".ecop" ) ) )
265 if(
name.EndsWith( wxS(
".efoo" ) ) )
267 nlohmann::json fpData = aProject.at(
"footprints" ).at( baseName );
268 wxString fpTitle = fpData.at(
"title" );
280 else if(
name.EndsWith( wxS(
".eblob" ) ) )
282 for(
const nlohmann::json& line : lines )
284 if( line.at( 0 ) ==
"BLOB" )
293 for(
const nlohmann::json& line : lines )
295 if( line.at( 0 ) ==
"POURED" )
297 if( !line.at( 2 ).is_string() )
312 const wxString& aFootprintName,
bool aKeepUUID,
318 wxFileName libFname( aLibraryPath );
320 if( libFname.GetExt() == wxS(
"efoo" ) )
322 wxFFileInputStream ffis( aLibraryPath );
323 wxTextInputStream txt( ffis, wxS(
" " ), wxConvUTF8 );
327 for(
const nlohmann::json& js : lines )
329 if( js.at( 0 ) ==
"ATTR" )
333 if( attr.
key == wxS(
"Footprint" ) && attr.
value != aFootprintName )
338 footprint = parser.
ParseFootprint( nlohmann::json(), wxEmptyString, lines );
342 THROW_IO_ERROR( wxString::Format(
_(
"Cannot load footprint '%s' from '%s'" ),
343 aFootprintName, aLibraryPath ) );
354 else if( libFname.GetExt() == wxS(
"elibz" ) || libFname.GetExt() == wxS(
"epro" )
355 || libFname.GetExt() == wxS(
"zip" ) )
361 std::map<wxString, nlohmann::json> footprintMap =
project.at(
"footprints" );
362 for(
auto& [uuid, data] : footprintMap )
366 if( data.contains(
"display_title" ) )
367 title = data.at(
"display_title" ).get<wxString>();
369 title = data.at(
"title" ).get<wxString>();
371 if( title == aFootprintName )
380 THROW_IO_ERROR( wxString::Format(
_(
"Footprint '%s' not found in project '%s'" ),
381 aFootprintName, aLibraryPath ) );
384 auto cb = [&](
const wxString&
name,
const wxString& baseName, wxInputStream&
zip ) ->
bool
386 if( !
name.EndsWith( wxS(
".efoo" ) ) )
389 if( baseName != fpUuid )
398 THROW_IO_ERROR( wxString::Format(
_(
"Cannot load footprint '%s' from '%s'" ),
399 aFootprintName, aLibraryPath ) );
421 std::vector<FOOTPRINT*> result;
428 result.push_back(
static_cast<FOOTPRINT*
>( footprint->Clone() ) );
Information pertinent to a Pcbnew printed circuit board.
void SetFileName(const wxString &aFileName)
virtual void SetVisible(bool aVisible)
virtual void SetText(const wxString &aText)
PROGRESS_REPORTER * m_progressReporter
Progress reporter to track the progress of the operation, may be nullptr.
A logical library item identifier and consists of various portions much like a URI.
void ParseBoard(BOARD *aBoard, const nlohmann::json &aProject, std::map< wxString, std::unique_ptr< FOOTPRINT > > &aFootprintMap, const std::map< wxString, EASYEDAPRO::BLOB > &aBlobMap, const std::multimap< wxString, EASYEDAPRO::POURED > &aPouredMap, const std::vector< nlohmann::json > &aLines, const wxString &aFpLibName)
FOOTPRINT * ParseFootprint(const nlohmann::json &aProject, const wxString &aFpUuid, const std::vector< nlohmann::json > &aLines)
BOARD * LoadBoard(const wxString &aFileName, BOARD *aAppendToMe, const STRING_UTF8_MAP *aProperties=nullptr, PROJECT *aProject=nullptr) override
Load information from some input file format that this PCB_IO implementation knows about into either ...
void LoadAllDataFromProject(const wxString &aLibraryPath, const nlohmann::json &aProject)
FOOTPRINT * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, bool aKeepUUID=false, const STRING_UTF8_MAP *aProperties=nullptr) override
Load a footprint having aFootprintName from the aLibraryPath containing a library format that this PC...
std::vector< FOOTPRINT * > GetImportedCachedLibraryFootprints() override
Return a container with the cached library footprints generated in the last call to Load.
bool CanReadBoard(const wxString &aFileName) const override
Checks if this PCB_IO can read the specified board file.
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const STRING_UTF8_MAP *aProperties=nullptr) override
Return a list of footprint names contained within the library at aLibraryPath.
long long GetLibraryTimestamp(const wxString &aLibraryPath) const override
Generate a timestamp representing all the files in the library (including the library directory).
A base class that BOARD loading and saving plugins should derive from.
BOARD * m_board
The board BOARD being worked on, no ownership here.
const STRING_UTF8_MAP * m_props
Properties passed via Save() or Load(), no ownership, may be NULL.
virtual bool KeepRefreshing(bool aWait=false)=0
Update the UI (if any).
virtual void Report(const wxString &aMessage)=0
Display aMessage in the progress bar dialog.
CHOOSE_PROJECT_HANDLER m_choose_project_handler
Callback to choose projects to import.
Container for project specific data.
A name/value tuple with unique names and optional values.
bool Exists(const std::string &aProperty) const
#define THROW_IO_ERROR(msg)
This file contains miscellaneous commonly used macros and functions.
wxString get_def(const std::map< wxString, wxString > &aMap, const char *aKey, const char *aDefval="")
LIB_ID ToKiCadLibID(const wxString &aLibName, const wxString &aLibReference)
void IterateZipFiles(const wxString &aFileName, std::function< bool(const wxString &, const wxString &, wxInputStream &)> aCallback)
std::vector< nlohmann::json > ParseJsonLines(wxInputStream &aInput, const wxString &aSource)
static const bool IMPORT_POURED
std::vector< IMPORT_PROJECT_DESC > ProjectToSelectorDialog(const nlohmann::json &aProject, bool aPcbOnly=false, bool aSchOnly=false)
nlohmann::json ReadProjectOrDeviceFile(const wxString &aZipFileName)
wxString ShortenLibName(wxString aProjectName)
std::map< wxString, std::multimap< wxString, EASYEDAPRO::POURED > > m_Poured
std::map< wxString, EASYEDAPRO::BLOB > m_Blobs
std::map< wxString, std::unique_ptr< FOOTPRINT > > m_Footprints