34#include <api/schematic/schematic_rules.pb.h>
35#include <google/protobuf/any.h>
36#include <google/protobuf/util/json_util.h>
41 if( !aMessage.has_marker() )
45 auto& marker = *aMessage.mutable_marker();
47 if( marker.has_sheet_specific_path() )
48 marker.mutable_sheet_specific_path()->clear_path_human_readable();
50 if( marker.has_main_item_sheet_path() )
51 marker.mutable_main_item_sheet_path()->clear_path_human_readable();
53 if( marker.has_aux_item_sheet_path() )
54 marker.mutable_aux_item_sheet_path()->clear_path_human_readable();
85 google::protobuf::Any container;
88 container.UnpackTo( ex.
m_impl->message.mutable_marker() );
99 ex.
m_impl->message.CopyFrom( aMessage );
106 const wxString& aComment )
109 const wxArrayString props = wxSplit( aMarkerData,
'|' );
111 if( props.size() != 5 && props.size() != 8 )
119 const auto code =
static_cast<ERCE_T>( item->GetErrorCode() );
120 auto& marker = *ex.
m_impl->message.mutable_marker();
122 const VECTOR2I position(
static_cast<int>( std::strtol( props[1].c_str(),
nullptr, 10 ) ),
123 static_cast<int>( std::strtol( props[2].c_str(),
nullptr, 10 ) ) );
129 marker.add_items()->set_value(
main.AsStdString() );
137 marker.mutable_child()->set_text_value( props[4].ToUTF8() );
143 marker.add_items()->set_value( resolved->GetRCItem()->GetMainItemID().AsStdString() );
145 else if( !props[4].IsEmpty() )
147 const KIID auxiliary( props[4] );
150 marker.add_items()->set_value( auxiliary.
AsStdString() );
153 if( props.size() == 8 )
155 if( !props[5].IsEmpty() )
158 if( !props[6].IsEmpty() )
161 if( !props[7].IsEmpty() )
178 google::protobuf::util::JsonPrintOptions jsonOptions;
179 jsonOptions.preserve_proto_field_names =
true;
182 std::ignore = google::protobuf::util::MessageToJsonString( aEx.
m_impl->message, &
json, jsonOptions ).ok();
186 aJson = nlohmann::json::parse(
json );
190 aJson = nlohmann::json{};
197 std::ignore = google::protobuf::util::JsonStringToMessage( aJson.dump(), &aEx.
m_impl->message ).ok();
204 if(
m_impl->message.has_marker() )
205 return m_impl->message.marker().SerializeAsString();
207 return std::string();
213 return wxString::FromUTF8(
m_impl->message.comment() );
219 m_impl->message.set_comment( aComment.ToUTF8() );
KICOMMON_API types::KiCadObjectType ToProtoEnum(KICAD_T aValue)
constexpr EDA_IU_SCALE schIUScale
static ERC_EXCLUSION FromLegacyStrings(const SCH_SHEET_LIST &aSheetList, const wxString &aMarkerData, const wxString &aComment)
ERC_EXCLUSION & operator=(const ERC_EXCLUSION &aOther)
std::unique_ptr< IMPL > m_impl
const kiapi::schematic::ErcExclusion & ToProto() const
void SetComment(const wxString &aComment)
static ERC_EXCLUSION FromMarker(const SCH_MARKER &aMarker)
wxString GetComment() const
std::string GetSortKey() const
static ERC_EXCLUSION FromProto(const kiapi::schematic::ErcExclusion &aMessage)
static std::shared_ptr< ERC_ITEM > Create(int aErrorCode)
Constructs an ERC_ITEM for the given error code.
std::string AsStdString() const
wxString GetComment() const
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
static SCH_MARKER * FromProto(const kiapi::schematic::ErcMarker &aMsg, const SCH_SHEET_LIST &aSheetList)
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void from_json(const nlohmann::json &aJson, ERC_EXCLUSION &aEx)
static void canonicalizeExclusion(kiapi::schematic::ErcExclusion &aMessage)
void to_json(nlohmann::json &aJson, const ERC_EXCLUSION &aEx)
@ ERCE_UNRESOLVED_VARIABLE
A text variable could not be resolved.
KICOMMON_API void PackVector2(types::Vector2 &aOutput, const VECTOR2I &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackSheetPath(types::SheetPath &aOutput, const KIID_PATH &aInput)
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
kiapi::schematic::ErcExclusion message
VECTOR2< int32_t > VECTOR2I