41#include <wx/filename.h>
46 PCB_IO( wxS(
"EasyEDA (JLCEDA) Pro v3" ) )
70std::vector<std::pair<wxString, wxString>>
77 const nlohmann::json& pcbsIndex = sourceProject.at(
"pcbs" );
79 std::vector<std::pair<wxString, wxString>>
result;
82 for(
const auto& [uuid, doc] : parser.
GetRawDocs( wxS(
"PCB" ) ) )
84 wxString title = uuid;
85 auto pcbIt = pcbsIndex.find( std::string( uuid.ToUTF8() ) );
87 if( pcbIt != pcbsIndex.end() )
90 result.emplace_back( uuid, title );
123 wxFileName fileName( aLibraryPath );
125 if( !fileName.FileExists() )
128 wxDateTime modified = fileName.GetModificationTime();
130 if( !modified.IsValid() )
133 return modified.GetTicks();
138 bool aBestEfforts,
const std::map<std::string, UTF8>* aProperties )
142 std::map<wxString, wxString> footprintMap =
145 for(
const auto& [
name, uuid] : footprintMap )
146 aFootprintNames.Add(
name );
152 std::vector<FOOTPRINT*>
result;
164 const wxString& aFootprintName,
bool aKeepUUID,
165 const std::map<std::string, UTF8>* aProperties )
171 std::map<wxString, wxString> footprintMap =
174 auto fpIt = footprintMap.find( aFootprintName );
176 if( fpIt == footprintMap.end() )
184 const nlohmann::json&
index =
v3.GetLibraryIndex();
187 std::unique_ptr<FOOTPRINT> footprint;
193 catch( nlohmann::json::exception& e )
195 THROW_IO_ERRORF(
_(
"Cannot load footprint '%s' from '%s': %s" ), aFootprintName, aLibraryPath, e.what() );
199 THROW_IO_ERRORF(
_(
"Cannot load footprint '%s' from '%s'" ), aFootprintName, aLibraryPath );
202 if(
index.contains(
"devices" ) &&
index.at(
"devices" ).is_object() )
204 for(
const auto& [devUuid, deviceJson] :
index.at(
"devices" ).items() )
206 if( !deviceJson.is_object() || !deviceJson.contains(
"attributes" )
207 || !deviceJson.at(
"attributes" ).is_object() )
212 const nlohmann::json& attrs = deviceJson.at(
"attributes" );
214 if( !attrs.contains(
"Footprint" )
222 wxString modelTransform;
224 if( attrs.contains(
"3D Model" ) )
227 if( attrs.contains(
"3D Model Title" ) )
230 modelTitle = modelUuid;
232 if( attrs.contains(
"3D Model Transform" ) )
243 footprint->Reference().SetVisible(
true );
244 footprint->Value().SetText( aFootprintName );
245 footprint->Value().SetVisible(
true );
246 footprint->AutoPositionFields();
253 const std::map<std::string, UTF8>* aProperties,
PROJECT* aProject )
279 pcbToLoad = wxString::FromUTF8(
m_props->at(
"pcb_id" ) );
283 std::map<wxString, nlohmann::json> prjPcbs =
project.at(
"pcbs" );
285 if( prjPcbs.size() == 1 )
287 pcbToLoad = prjPcbs.begin()->first;
291 std::vector<IMPORT_PROJECT_DESC> chosen =
294 if( !chosen.empty() )
295 pcbToLoad = chosen[0].PCBId;
297 else if( !prjPcbs.empty() )
299 pcbToLoad = prjPcbs.begin()->first;
303 if( pcbToLoad.empty() )
310 wxFileName sourceName( aFileName );
315 std::map<wxString, std::unique_ptr<FOOTPRINT>> footprints;
316 std::set<wxString> usedLibNames;
318 for(
const auto& [uuid, rawDoc] : adapter.
GetRawDocs( wxS(
"FOOTPRINT" ) ) )
320 std::unique_ptr<FOOTPRINT> footprint( parser.
ParseFootprint( blobs, rawDoc ) );
325 std::string uuidKey = std::string( uuid.ToUTF8() );
326 const nlohmann::json& fpMetas =
project.at(
"footprints" );
327 wxString fpTitle = uuid;
329 if( fpMetas.contains( uuidKey ) )
334 footprints.emplace( uuid, std::move( footprint ) );
340 THROW_IO_ERRORF(
_(
"PCB document '%s' not found in '%s'" ), pcbToLoad, aFileName );
342 std::multimap<wxString, EASYEDAPRO::POURED> poured;
351 for(
auto& [uuid, footprint] : footprints )
359 Report( wxString::Format(
_(
"EasyEDA (JLCEDA) Pro v3 import skipped %d unsupported object(s)." ),
Information pertinent to a Pcbnew printed circuit board.
Parses EasyEDA Pro v3 .epro2 archives.
void Load()
Load all v3 docs from the archive.
const V3_DOC_RAW * FindRawDoc(const wxString &aDocType, const wxString &aUuid) const
const std::map< wxString, V3_DOC_RAW > & GetRawDocs(const wxString &aDocType) const
static bool IsV3Library(const wxString &aFileName, const wxString &aRequiredDocType=wxEmptyString)
Return true if aFileName looks like an EasyEDA Pro v3 library archive.
int GetSkippedCount() const
static bool IsV3Archive(const wxString &aFileName)
Return true if aFileName looks like an EasyEDA Pro v3 archive.
RAII class to set and restore the fontconfig reporter.
virtual void Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) const
PROGRESS_REPORTER * m_progressReporter
Progress reporter to track the progress of the operation, may be nullptr.
virtual bool CanReadLibrary(const wxString &aFileName) const
Checks if this IO object can read the specified library file/directory.
static LOAD_INFO_REPORTER & GetInstance()
void FillFootprintModelInfo(FOOTPRINT *footprint, const wxString &modelUuid, const wxString &modelTitle, const wxString &modelTransform) const
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 EASYEDAPRO::V3_DOC_RAW &aDoc, const wxString &aFpLibName)
wxString GenerateSafeSpacingRules() const
std::unique_ptr< FOOTPRINT > ParseFootprint(const std::map< wxString, EASYEDAPRO::BLOB > &aBlobMap, const EASYEDAPRO::V3_DOC_RAW &aDoc)
long long GetLibraryTimestamp(const wxString &aLibraryPath) const override
Generate a timestamp representing all the files in the library (including the library directory).
std::unique_ptr< EASYEDAPRO::V3_DOC_PARSER > m_cachedLibraryParser
bool CanReadBoard(const wxString &aFileName) const override
~PCB_IO_EASYEDAPRO_V3() override
wxString m_importedDesignRules
bool CanReadLibrary(const wxString &aFileName) const override
Checks if this IO object can read the specified library file/directory.
std::vector< IMPORT_PROJECT_DESC > EnumerateProjectEntries(const wxString &aFileName) const override
Return the KiCad projects a project container splits into, one per board entry and one per PCB or sch...
void loadBoard(const wxString &aFileName, BOARD &aBoard, bool aIsNewLoad, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr) override
Parse aFileName into aBoard.
std::vector< FOOTPRINT * > GetImportedCachedLibraryFootprints() override
Return a container with the cached library footprints generated in the last call to Load.
wxString m_cachedLibraryPath
std::vector< std::unique_ptr< FOOTPRINT > > m_importedLibFootprints
Definitions from the last LoadBoard, cloned out to the import reconciler on request.
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Return a list of footprint names contained within the library at aLibraryPath.
std::vector< std::pair< wxString, wxString > > EnumerateProjectBoards(const wxString &aFileName) const override
Check if this PCB_IO can read the specified board file.
std::unique_ptr< FOOTPRINT > FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, bool aKeepUUID=false, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load a footprint having aFootprintName from the aLibraryPath containing a library format that this PC...
const EASYEDAPRO::V3_DOC_PARSER & getCachedLibraryParser(const wxString &aLibraryPath) const
long long m_cachedLibraryTimestamp
BOARD * m_board
The board BOARD being worked on, no ownership here.
PCB_IO(const wxString &aName)
const std::map< std::string, UTF8 > * m_props
Properties passed via Save() or Load(), no ownership, may be NULL.
CHOOSE_PROJECT_HANDLER m_choose_project_handler
Callback to choose projects to import.
Container for project specific data.
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
#define THROW_IO_ERRORF(msg,...)
#define THROW_IO_CANCELLED()
nlohmann::json BuildV3ProjectIndexFromRawDocs(const V3_DOC_PARSER &aParser, bool aIncludeLibraryMetadata=true)
Build a minimal legacy-style project index from parsed v3 raw documents.
LIB_ID ToKiCadLibID(const wxString &aLibName, const wxString &aLibReference)
wxString MakeUniqueLibName(std::set< wxString > &aUsedNames, const wxString &aName, const wxString &aFallback)
Allocate a unique library item name, recording it in aUsedNames.
wxString GetV3LibraryItemTitle(const nlohmann::json &aMetadata, const wxString &aUuid)
std::vector< IMPORT_PROJECT_DESC > ProjectToSelectorDialog(const nlohmann::json &aProject, bool aPcbOnly=false, bool aSchOnly=false)
List the project's board entries, then the PCBs and schematics no entry names.
wxString ShortenLibName(wxString aProjectName)
wxString V3JsonToString(const nlohmann::json &aValue, const wxString &aDefault)
std::map< wxString, wxString > BuildV3LibraryItemMap(const V3_DOC_PARSER &aParser, const char *aIndexKey, const wxString &aDocType)
std::map< wxString, BLOB > BuildV3BlobMap(const V3_DOC_PARSER &aParser)
wxString V3GetString(const nlohmann::json &aObj, const char *aKey, const wxString &aDefault)
Raw parsed document from an EasyEDA Pro v3 .epru stream.
wxString result
Test unit parsing edge cases and error handling.