Fix EasyEDA/JLCEDA Pro 2.2 footprint/symbol library import.
Fixes https://gitlab.com/kicad/code/kicad/-/issues/18250
This commit is contained in:
parent
84091b163e
commit
1613816e77
|
@ -140,7 +140,8 @@ EASYEDAPRO::ProjectToSelectorDialog( const nlohmann::json& aProject, bool aPcbOn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
nlohmann::json EASYEDAPRO::ReadProjectOrDeviceFile( const wxString& aZipFileName )
|
nlohmann::json EASYEDAPRO::FindJsonFile( const wxString& aZipFileName,
|
||||||
|
const std::set<wxString>& aFileNames )
|
||||||
{
|
{
|
||||||
std::shared_ptr<wxZipEntry> entry;
|
std::shared_ptr<wxZipEntry> entry;
|
||||||
wxFFileInputStream in( aZipFileName );
|
wxFFileInputStream in( aZipFileName );
|
||||||
|
@ -152,7 +153,7 @@ nlohmann::json EASYEDAPRO::ReadProjectOrDeviceFile( const wxString& aZipFileName
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if( name == wxS( "project.json" ) || name == wxS( "device.json" ) )
|
if( aFileNames.find( name ) != aFileNames.end() )
|
||||||
{
|
{
|
||||||
wxMemoryOutputStream memos;
|
wxMemoryOutputStream memos;
|
||||||
memos << zip;
|
memos << zip;
|
||||||
|
@ -175,6 +176,20 @@ nlohmann::json EASYEDAPRO::ReadProjectOrDeviceFile( const wxString& aZipFileName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nlohmann::json{};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
nlohmann::json EASYEDAPRO::ReadProjectOrDeviceFile( const wxString& aZipFileName )
|
||||||
|
{
|
||||||
|
static const std::set<wxString> c_files = { wxS( "project.json" ), wxS( "device.json" ),
|
||||||
|
wxS( "footprint.json" ), wxS( "symbol.json" ) };
|
||||||
|
|
||||||
|
nlohmann::json j = FindJsonFile( aZipFileName, c_files );
|
||||||
|
|
||||||
|
if( !j.is_null() )
|
||||||
|
return j;
|
||||||
|
|
||||||
THROW_IO_ERROR( wxString::Format(
|
THROW_IO_ERROR( wxString::Format(
|
||||||
_( "'%s' does not appear to be a valid EasyEDA (JLCEDA) Pro "
|
_( "'%s' does not appear to be a valid EasyEDA (JLCEDA) Pro "
|
||||||
"project or library file. Cannot find project.json or device.json." ),
|
"project or library file. Cannot find project.json or device.json." ),
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#ifndef EASYEDAPRO_IMPORT_UTILS_H_
|
#ifndef EASYEDAPRO_IMPORT_UTILS_H_
|
||||||
#define EASYEDAPRO_IMPORT_UTILS_H_
|
#define EASYEDAPRO_IMPORT_UTILS_H_
|
||||||
|
|
||||||
|
#include <set>
|
||||||
#include <wx/stream.h>
|
#include <wx/stream.h>
|
||||||
#include <wx/string.h>
|
#include <wx/string.h>
|
||||||
#include <lib_id.h>
|
#include <lib_id.h>
|
||||||
|
@ -46,6 +47,8 @@ std::vector<IMPORT_PROJECT_DESC> ProjectToSelectorDialog( const nlohmann::json&
|
||||||
bool aPcbOnly = false,
|
bool aPcbOnly = false,
|
||||||
bool aSchOnly = false );
|
bool aSchOnly = false );
|
||||||
|
|
||||||
|
nlohmann::json FindJsonFile( const wxString& aZipFileName, const std::set<wxString>& aFileNames );
|
||||||
|
|
||||||
nlohmann::json ReadProjectOrDeviceFile( const wxString& aZipFileName );
|
nlohmann::json ReadProjectOrDeviceFile( const wxString& aZipFileName );
|
||||||
|
|
||||||
void IterateZipFiles(
|
void IterateZipFiles(
|
||||||
|
|
|
@ -143,8 +143,14 @@ static LIB_SYMBOL* loadSymbol( nlohmann::json project, const wxString& aLibraryP
|
||||||
|| libFname.GetExt() == wxS( "zip" ) )
|
|| libFname.GetExt() == wxS( "zip" ) )
|
||||||
{
|
{
|
||||||
std::map<wxString, EASYEDAPRO::PRJ_SYMBOL> prjSymbols = project.at( "symbols" );
|
std::map<wxString, EASYEDAPRO::PRJ_SYMBOL> prjSymbols = project.at( "symbols" );
|
||||||
std::map<wxString, EASYEDAPRO::PRJ_FOOTPRINT> prjFootprints = project.at( "footprints" );
|
std::map<wxString, EASYEDAPRO::PRJ_FOOTPRINT> prjFootprints;
|
||||||
std::map<wxString, EASYEDAPRO::PRJ_DEVICE> prjDevices = project.at( "devices" );
|
std::map<wxString, EASYEDAPRO::PRJ_DEVICE> prjDevices;
|
||||||
|
|
||||||
|
if( project.contains( "footprints" ) )
|
||||||
|
prjFootprints = project.at( "footprints" );
|
||||||
|
|
||||||
|
if( project.contains( "devices" ) )
|
||||||
|
prjDevices = project.at( "devices" );
|
||||||
|
|
||||||
auto prjSymIt = std::find_if( prjSymbols.begin(), prjSymbols.end(),
|
auto prjSymIt = std::find_if( prjSymbols.begin(), prjSymbols.end(),
|
||||||
[&]( const auto& pair )
|
[&]( const auto& pair )
|
||||||
|
|
|
@ -897,7 +897,7 @@ FOOTPRINT* PCB_IO_EASYEDAPRO_PARSER::ParseFootprint( const nlohmann::json&
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( aProject.is_object() )
|
if( aProject.is_object() && aProject.contains( "devices" ) )
|
||||||
{
|
{
|
||||||
std::map<wxString, EASYEDAPRO::PRJ_DEVICE> devicesMap = aProject.at( "devices" );
|
std::map<wxString, EASYEDAPRO::PRJ_DEVICE> devicesMap = aProject.at( "devices" );
|
||||||
std::map<wxString, wxString> compAttrs;
|
std::map<wxString, wxString> compAttrs;
|
||||||
|
|
Loading…
Reference in New Issue