47#include <wx/filename.h>
52 PCB_IO( wxS(
"EasyEDA (JLCEDA) Pro v3" ) )
93 wxFileName fileName( aLibraryPath );
95 if( !fileName.FileExists() )
98 wxDateTime modified = fileName.GetModificationTime();
100 if( !modified.IsValid() )
103 return modified.GetTicks();
108 bool aBestEfforts,
const std::map<std::string, UTF8>* aProperties )
112 std::map<wxString, wxString> footprintMap =
115 for(
const auto& [
name, uuid] : footprintMap )
116 aFootprintNames.Add(
name );
121 bool aKeepUUID,
const std::map<std::string, UTF8>* aProperties )
127 std::map<wxString, wxString> footprintMap =
130 auto fpIt = footprintMap.find( aFootprintName );
132 if( fpIt == footprintMap.end() )
140 const nlohmann::json&
index =
v3.GetLibraryIndex();
149 catch( nlohmann::json::exception& e )
151 THROW_IO_ERROR( wxString::Format(
_(
"Cannot load footprint '%s' from '%s': %s" ), aFootprintName, aLibraryPath,
157 THROW_IO_ERROR( wxString::Format(
_(
"Cannot load footprint '%s' from '%s'" ), aFootprintName, aLibraryPath ) );
161 if(
index.contains(
"devices" ) &&
index.at(
"devices" ).is_object() )
163 for(
const auto& [devUuid, deviceJson] :
index.at(
"devices" ).items() )
165 if( !deviceJson.is_object() || !deviceJson.contains(
"attributes" )
166 || !deviceJson.at(
"attributes" ).is_object() )
171 const nlohmann::json& attrs = deviceJson.at(
"attributes" );
173 if( !attrs.contains(
"Footprint" )
181 wxString modelTransform;
183 if( attrs.contains(
"3D Model" ) )
186 if( attrs.contains(
"3D Model Title" ) )
189 modelTitle = modelUuid;
191 if( attrs.contains(
"3D Model Transform" ) )
212 const std::map<std::string, UTF8>* aProperties,
PROJECT* aProject )
219 m_board->SetFileName( aFileName );
240 pcbToLoad = wxString::FromUTF8(
m_props->at(
"pcb_id" ) );
244 std::map<wxString, nlohmann::json> prjPcbs =
project.at(
"pcbs" );
246 if( prjPcbs.size() == 1 )
248 pcbToLoad = prjPcbs.begin()->first;
252 std::vector<IMPORT_PROJECT_DESC> chosen =
255 if( !chosen.empty() )
256 pcbToLoad = chosen[0].PCBId;
258 else if( !prjPcbs.empty() )
260 pcbToLoad = prjPcbs.begin()->first;
264 if( pcbToLoad.empty() )
271 wxFileName sourceName( aFileName );
275 wxFileName libDirName;
276 libDirName.AssignDir( sourceName.GetPath() );
277 libDirName.AppendDir( prettyDirName );
278 wxString libPath = libDirName.GetPath();
282 std::map<wxString, std::unique_ptr<FOOTPRINT>> footprints;
283 std::set<wxString> usedLibNames;
285 for(
const auto& [uuid, rawDoc] : adapter.
GetRawDocs( wxS(
"FOOTPRINT" ) ) )
287 std::unique_ptr<FOOTPRINT> footprint( parser.
ParseFootprint( blobs, rawDoc ) );
292 std::string uuidKey = std::string( uuid.ToUTF8() );
293 const nlohmann::json& fpMetas =
project.at(
"footprints" );
294 wxString fpTitle = uuid;
296 if( fpMetas.contains( uuidKey ) )
301 footprints.emplace( uuid, std::move( footprint ) );
308 THROW_IO_ERROR( wxString::Format(
_(
"PCB document '%s' not found in '%s'" ), pcbToLoad, aFileName ) );
311 std::multimap<wxString, EASYEDAPRO::POURED> poured;
316 if( !footprints.empty() )
320 if( !wxDir::Exists( libPath ) )
321 pcbPlugin->CreateLibrary( libPath );
332 wxString libTableUri = wxS(
"${KIPRJMOD}/" ) + prettyDirName;
336 row.
SetURI( libTableUri );
340 fpAdapter->
LoadOne( fpLibName );
344 for(
auto& [uuid, footprint] : footprints )
347 pcbPlugin->FootprintSave( libPath, footprint.get() );
353 wxLogWarning( 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.
virtual void SetVisible(bool aVisible)
virtual void SetText(const wxString &aText)
RAII class to set and restore the fontconfig reporter.
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.
std::optional< LIBRARY_TABLE * > ProjectTable() const
Retrieves the project library table for this adapter type, or nullopt if one doesn't exist.
void SetNickname(const wxString &aNickname)
void SetType(const wxString &aType)
void SetURI(const wxString &aUri)
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)
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
Checks if this PCB_IO can read the specified board file.
~PCB_IO_EASYEDAPRO_V3() override
bool CanReadLibrary(const wxString &aFileName) const override
Checks if this IO object can read the specified library file/directory.
wxString m_cachedLibraryPath
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.
const EASYEDAPRO::V3_DOC_PARSER & getCachedLibraryParser(const wxString &aLibraryPath) const
long long m_cachedLibraryTimestamp
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...
BOARD * LoadBoard(const wxString &aFileName, BOARD *aAppendToMe, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr) override
Load information from some input file format that this PCB_IO implementation knows about into either ...
@ KICAD_SEXP
S-expression Pcbnew file format.
static PCB_IO * FindPlugin(PCB_FILE_T aFileType)
Return a #PLUGIN which the caller can use to import, export, save, or load design documents.
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.
static FOOTPRINT_LIBRARY_ADAPTER * FootprintLibAdapter(PROJECT *aProject)
Container for project specific data.
static const std::string KiCadFootprintLibPathExtension
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
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)
Raw parsed document from an EasyEDA Pro v3 .epru stream.
std::vector< std::vector< std::string > > table
Definition of file extensions used in Kicad.