From 840b9aebba71a98bfecdf9ac67e3572f1e7a23bf Mon Sep 17 00:00:00 2001 From: Alex Shvartzkop Date: Sun, 27 Oct 2024 04:14:24 +0300 Subject: [PATCH] Fix compatibility with LCEDA/EasyEDA v2.2.32 Now device attributes can contain numbers. Fixes https://gitlab.com/kicad/code/kicad/-/issues/18994 --- .../io/easyedapro/easyedapro_import_utils.cpp | 17 +++++++++++++++++ common/io/easyedapro/easyedapro_import_utils.h | 2 ++ common/io/easyedapro/easyedapro_parser.cpp | 3 ++- .../sch_io/easyedapro/sch_easyedapro_parser.cpp | 4 ++-- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/common/io/easyedapro/easyedapro_import_utils.cpp b/common/io/easyedapro/easyedapro_import_utils.cpp index f2a56d4334..154f05930a 100644 --- a/common/io/easyedapro/easyedapro_import_utils.cpp +++ b/common/io/easyedapro/easyedapro_import_utils.cpp @@ -307,3 +307,20 @@ EASYEDAPRO::ParseJsonLinesWithSeparation( wxInputStream& aInput, const wxString& return lineBlocks; } + + +std::map +EASYEDAPRO::AnyMapToStringMap( const std::map& aInput ) +{ + std::map stringMap; + + for( auto& [key, value] : aInput ) + { + if( value.is_string() ) + stringMap[key] = value.get(); + else if( value.is_number() ) + stringMap[key] = wxString::FromCDouble( value.get() ); + } + + return stringMap; +} diff --git a/common/io/easyedapro/easyedapro_import_utils.h b/common/io/easyedapro/easyedapro_import_utils.h index 5e7c02b31e..69827d1b53 100644 --- a/common/io/easyedapro/easyedapro_import_utils.h +++ b/common/io/easyedapro/easyedapro_import_utils.h @@ -63,6 +63,8 @@ std::vector ParseJsonLines( wxInputStream& aInput, const wxStrin std::vector> ParseJsonLinesWithSeparation( wxInputStream& aInput, const wxString& aSource ); +std::map AnyMapToStringMap( const std::map& aInput ); + } // namespace EASYEDAPRO diff --git a/common/io/easyedapro/easyedapro_parser.cpp b/common/io/easyedapro/easyedapro_parser.cpp index 5544ebac23..3ba90444a1 100644 --- a/common/io/easyedapro/easyedapro_parser.cpp +++ b/common/io/easyedapro/easyedapro_parser.cpp @@ -29,6 +29,7 @@ #include #include #include +#include void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::SCH_ATTR& d ) @@ -273,7 +274,7 @@ void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::PRJ_DEVICE& d ) d.custom_tags = j.at( "custom_tags" ); if( j.at( "attributes" ).is_object() ) - d.attributes = j.at( "attributes" ); + d.attributes = AnyMapToStringMap( j.at( "attributes" ) ); } void EASYEDAPRO::from_json( const nlohmann::json& j, EASYEDAPRO::BLOB& d ) diff --git a/eeschema/sch_io/easyedapro/sch_easyedapro_parser.cpp b/eeschema/sch_io/easyedapro/sch_easyedapro_parser.cpp index caf0bf21ed..01e4c14d24 100644 --- a/eeschema/sch_io/easyedapro/sch_easyedapro_parser.cpp +++ b/eeschema/sch_io/easyedapro/sch_easyedapro_parser.cpp @@ -1128,8 +1128,8 @@ void SCH_EASYEDAPRO_PARSER::ParseSchematic( SCHEMATIC* aSchematic, SCH_SHEET* aR if( !deviceAttr ) continue; - std::map compAttrs = - aProject.at( "devices" ).at( deviceAttr->value ).at( "attributes" ); + std::map compAttrs = EASYEDAPRO::AnyMapToStringMap( + aProject.at( "devices" ).at( deviceAttr->value ).at( "attributes" ) ); wxString symbolId;