31 using json = nlohmann::json;
38 const json responseJson = json::parse( aJson.utf8_string() );
40 if( !responseJson.is_object() )
43 result.m_Success = responseJson.value(
"success",
false );
45 if( !
result.m_Success || !responseJson.contains(
"matches" ) || !responseJson[
"matches"].is_array() )
51 const json& matches = responseJson[
"matches"];
53 result.m_Matches.reserve( matches.size() );
55 for(
const json& match : matches )
57 if( !match.is_object() )
62 if( match.contains(
"symbol" ) && match[
"symbol"].is_string() )
63 entry.
m_Symbol.
Parse( wxString::FromUTF8( match[
"symbol"].get<std::string>() ) );
66 entry.
m_IsDerived = match.value(
"derived",
false );
68 if( match.contains(
"filter" ) && match[
"filter"].is_string() )
69 entry.
m_MatchedFilter = wxString::FromUTF8( match[
"filter"].get<std::string>() );
73 if( match.contains(
"pin_maps" ) && match[
"pin_maps"].is_array() )
75 for(
const json& mapName : match[
"pin_maps"] )
77 if( mapName.is_string() )
79 entry.
m_MatchedPinMaps.push_back( wxString::FromUTF8( mapName.get<std::string>() ) );
84 result.m_Matches.push_back( std::move( entry ) );
87 result.m_IsLimited = responseJson.value(
"limited",
false );
89 catch(
const std::exception& )
101 using json = nlohmann::json;
103 json output = json::object();
104 output[
"matches"] = json::array();
110 json entry = json::object();
111 entry[
"symbol"] = match.m_Symbol.GetUniStringLibId().utf8_string();
112 entry[
"pins"] = match.m_PinCount;
113 entry[
"derived"] = match.m_IsDerived;
115 if( !match.m_MatchedFilter.IsEmpty() )
116 entry[
"filter"] = match.m_MatchedFilter.utf8_string();
118 entry[
"footprint_field"] = match.m_MatchesFootprintField;
120 if( !match.m_MatchedPinMaps.empty() )
122 json pinMaps = json::array();
124 for(
const wxString& mapName : match.m_MatchedPinMaps )
125 pinMaps.push_back( mapName.utf8_string() );
127 entry[
"pin_maps"] = std::move( pinMaps );
130 output[
"matches"].push_back( std::move( entry ) );
133 return wxString::FromUTF8( output.dump() );
FOOTPRINT_USERS_RESULT QueryFootprintUsers(KIWAY &aKiway, const FOOTPRINT_USERS_QUERY &aQuery)
Ask the symbol libraries, for the symbols that use a given footprint (over the Eeschema kiface).
IFACE KIFACE_BASE kiface("pcb_test_frame", KIWAY::FACE_PCB)
wxString result
Test unit parsing edge cases and error handling.