40#include <wx/txtstrm.h>
41#include <wx/wfstream.h>
42#include <wx/mstream.h>
43#include <wx/zipstrm.h>
55 std::map<wxString, EASYEDAPRO::BLOB>
m_Blobs;
56 std::map<wxString, std::multimap<wxString, EASYEDAPRO::POURED>>
m_Poured;
74 if( aFileName.Lower().EndsWith( wxS(
".epro" ) ) )
78 else if( aFileName.Lower().EndsWith( wxS(
".zip" ) ) )
80 std::shared_ptr<wxZipEntry> entry;
81 wxFFileInputStream in( aFileName );
82 wxZipInputStream
zip( in );
87 while( entry.reset(
zip.GetNextEntry() ), entry.get() != NULL )
89 wxString
name = entry->GetName();
91 if(
name == wxS(
"project.json" ) )
125 wxFileName fname( aFileName );
127 if( fname.GetExt() == wxS(
"epro" ) || fname.GetExt() == wxS(
"zip" ) )
135 pcbToLoad = wxString::FromUTF8( aProperties->at(
"pcb_id" ) );
139 std::map<wxString, wxString> prjPcbNames =
project.at(
"pcbs" );
141 if( prjPcbNames.size() == 1 )
143 pcbToLoad = prjPcbNames.begin()->first;
150 if( chosen.size() > 0 )
151 pcbToLoad = chosen[0].PCBId;
155 if( pcbToLoad.empty() )
163 auto cb = [&](
const wxString&
name,
const wxString& pcbUuid, wxInputStream&
zip ) ->
bool
165 if( !
name.EndsWith( wxS(
".epcb" ) ) )
168 if( pcbUuid != pcbToLoad )
173 wxString boardKey = pcbUuid + wxS(
"_0" );
174 wxScopedCharBuffer cb = boardKey.ToUTF8();
175 wxString boardPouredKey = wxBase64Encode( cb.data(), cb.length() );
177 const std::multimap<wxString, EASYEDAPRO::POURED>& boardPoured =
200 const wxString& aLibraryPath,
bool aBestEfforts,
203 wxFileName fname( aLibraryPath );
205 if( fname.GetExt() == wxS(
"efoo" ) )
207 wxFFileInputStream ffis( aLibraryPath );
208 wxTextInputStream txt( ffis, wxS(
" " ), wxConvUTF8 );
210 while( ffis.CanRead() )
212 wxString line = txt.ReadLine();
214 if( !line.Contains( wxS(
"ATTR" ) ) )
217 nlohmann::json js = nlohmann::json::parse( line );
218 if( js.at( 0 ) ==
"ATTR" && js.at( 7 ) ==
"Footprint" )
220 aFootprintNames.Add( js.at( 8 ).get<wxString>() );
224 else if( fname.GetExt() == wxS(
"elibz" ) || fname.GetExt() == wxS(
"epro" )
225 || fname.GetExt() == wxS(
"zip" ) )
228 std::map<wxString, nlohmann::json> footprintMap =
project.at(
"footprints" );
230 for(
auto& [key, value] : footprintMap )
234 if( value.contains(
"display_title" ) )
235 title = value.at(
"display_title" ).get<wxString>();
237 title = value.at(
"title" ).get<wxString>();
239 aFootprintNames.Add( title );
246 const nlohmann::json& aProject )
254 wxFileName fname( aProjectPath );
257 std::map<wxString, std::unique_ptr<FOOTPRINT>> result;
259 auto cb = [&](
const wxString&
name,
const wxString& baseName, wxInputStream&
zip ) ->
bool
261 if( !
name.EndsWith( wxS(
".efoo" ) ) && !
name.EndsWith( wxS(
".eblob" ) )
262 && !
name.EndsWith( wxS(
".ecop" ) ) )
269 if(
name.EndsWith( wxS(
".efoo" ) ) )
271 nlohmann::json fpData = aProject.at(
"footprints" ).at( baseName );
272 wxString fpTitle = fpData.at(
"title" );
284 else if(
name.EndsWith( wxS(
".eblob" ) ) )
286 for(
const nlohmann::json& line : lines )
288 if( line.at( 0 ) ==
"BLOB" )
297 for(
const nlohmann::json& line : lines )
299 if( line.at( 0 ) ==
"POURED" )
301 if( !line.at( 2 ).is_string() )
316 const wxString& aFootprintName,
bool aKeepUUID,
324 wxFileName libFname( aLibraryPath );
326 if( libFname.GetExt() == wxS(
"efoo" ) )
328 wxFFileInputStream ffis( aLibraryPath );
329 wxTextInputStream txt( ffis, wxS(
" " ), wxConvUTF8 );
333 for(
const nlohmann::json& js : lines )
335 if( js.at( 0 ) ==
"ATTR" )
339 if( attr.
key == wxS(
"Footprint" ) && attr.
value != aFootprintName )
344 footprint = parser.
ParseFootprint( nlohmann::json(), wxEmptyString, lines );
348 THROW_IO_ERROR( wxString::Format(
_(
"Cannot load footprint '%s' from '%s'" ),
349 aFootprintName, aLibraryPath ) );
360 else if( libFname.GetExt() == wxS(
"elibz" ) || libFname.GetExt() == wxS(
"epro" )
361 || libFname.GetExt() == wxS(
"zip" ) )
367 std::map<wxString, nlohmann::json> footprintMap =
project.at(
"footprints" );
368 for(
auto& [uuid, data] : footprintMap )
372 if( data.contains(
"display_title" ) )
373 title = data.at(
"display_title" ).get<wxString>();
375 title = data.at(
"title" ).get<wxString>();
377 if( title == aFootprintName )
386 THROW_IO_ERROR( wxString::Format(
_(
"Footprint '%s' not found in project '%s'" ),
387 aFootprintName, aLibraryPath ) );
390 auto cb = [&](
const wxString&
name,
const wxString& baseName, wxInputStream&
zip ) ->
bool
392 if( !
name.EndsWith( wxS(
".efoo" ) ) )
395 if( baseName != fpUuid )
404 THROW_IO_ERROR( wxString::Format(
_(
"Cannot load footprint '%s' from '%s'" ),
405 aFootprintName, aLibraryPath ) );
427 std::vector<FOOTPRINT*> result;
434 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
static REPORTER & GetInstance()
static void SetReporter(REPORTER *aReporter)
Set the reporter to use for reporting font substitution warnings.
#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