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 );
114 wxFileName fileName( aLibraryPath );
116 if( !fileName.FileExists() )
119 wxDateTime modified = fileName.GetModificationTime();
121 if( !modified.IsValid() )
124 return modified.GetTicks();
129 bool aBestEfforts,
const std::map<std::string, UTF8>* aProperties )
133 std::map<wxString, wxString> footprintMap =
136 for(
const auto& [
name, uuid] : footprintMap )
137 aFootprintNames.Add(
name );
143 std::vector<FOOTPRINT*>
result;
155 const wxString& aFootprintName,
bool aKeepUUID,
156 const std::map<std::string, UTF8>* aProperties )
162 std::map<wxString, wxString> footprintMap =
165 auto fpIt = footprintMap.find( aFootprintName );
167 if( fpIt == footprintMap.end() )
175 const nlohmann::json&
index =
v3.GetLibraryIndex();
178 std::unique_ptr<FOOTPRINT> footprint;
184 catch( nlohmann::json::exception& e )
186 THROW_IO_ERRORF(
_(
"Cannot load footprint '%s' from '%s': %s" ), aFootprintName, aLibraryPath, e.what() );
190 THROW_IO_ERRORF(
_(
"Cannot load footprint '%s' from '%s'" ), aFootprintName, aLibraryPath );
193 if(
index.contains(
"devices" ) &&
index.at(
"devices" ).is_object() )
195 for(
const auto& [devUuid, deviceJson] :
index.at(
"devices" ).items() )
197 if( !deviceJson.is_object() || !deviceJson.contains(
"attributes" )
198 || !deviceJson.at(
"attributes" ).is_object() )
203 const nlohmann::json& attrs = deviceJson.at(
"attributes" );
205 if( !attrs.contains(
"Footprint" )
213 wxString modelTransform;
215 if( attrs.contains(
"3D Model" ) )
218 if( attrs.contains(
"3D Model Title" ) )
221 modelTitle = modelUuid;
223 if( attrs.contains(
"3D Model Transform" ) )
234 footprint->Reference().SetVisible(
true );
235 footprint->Value().SetText( aFootprintName );
236 footprint->Value().SetVisible(
true );
237 footprint->AutoPositionFields();
244 const std::map<std::string, UTF8>* aProperties,
PROJECT* aProject )
270 pcbToLoad = wxString::FromUTF8(
m_props->at(
"pcb_id" ) );
274 std::map<wxString, nlohmann::json> prjPcbs =
project.at(
"pcbs" );
276 if( prjPcbs.size() == 1 )
278 pcbToLoad = prjPcbs.begin()->first;
282 std::vector<IMPORT_PROJECT_DESC> chosen =
285 if( !chosen.empty() )
286 pcbToLoad = chosen[0].PCBId;
288 else if( !prjPcbs.empty() )
290 pcbToLoad = prjPcbs.begin()->first;
294 if( pcbToLoad.empty() )
301 wxFileName sourceName( aFileName );
306 std::map<wxString, std::unique_ptr<FOOTPRINT>> footprints;
307 std::set<wxString> usedLibNames;
309 for(
const auto& [uuid, rawDoc] : adapter.
GetRawDocs( wxS(
"FOOTPRINT" ) ) )
311 std::unique_ptr<FOOTPRINT> footprint( parser.
ParseFootprint( blobs, rawDoc ) );
316 std::string uuidKey = std::string( uuid.ToUTF8() );
317 const nlohmann::json& fpMetas =
project.at(
"footprints" );
318 wxString fpTitle = uuid;
320 if( fpMetas.contains( uuidKey ) )
325 footprints.emplace( uuid, std::move( footprint ) );
331 THROW_IO_ERRORF(
_(
"PCB document '%s' not found in '%s'" ), pcbToLoad, aFileName );
333 std::multimap<wxString, EASYEDAPRO::POURED> poured;
342 for(
auto& [uuid, footprint] : footprints )
350 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.
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)
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.