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();
48 marker.clear_description();
49 marker.clear_severity();
50 marker.clear_excluded();
52 if( marker.has_sheet_specific_path() )
53 marker.mutable_sheet_specific_path()->clear_path_human_readable();
55 if( marker.has_main_item_sheet_path() )
56 marker.mutable_main_item_sheet_path()->clear_path_human_readable();
58 if( marker.has_aux_item_sheet_path() )
59 marker.mutable_aux_item_sheet_path()->clear_path_human_readable();
90 google::protobuf::Any container;
94 if( !container.UnpackTo( ex.
m_impl->message.mutable_marker() ) )
95 wxFAIL_MSG( wxT(
"Failed to unpack ERC_EXCLUSION from internal serialization" ) );
107 ex.
m_impl->message.CopyFrom( aMessage );
114 const wxString& aComment )
117 const wxArrayString props = wxSplit( aMarkerData,
'|' );
119 if( props.size() != 5 && props.size() != 8 )
127 const auto code =
static_cast<ERCE_T>( item->GetErrorCode() );
128 auto& marker = *ex.
m_impl->message.mutable_marker();
130 const VECTOR2I position(
static_cast<int>( std::strtol( props[1].c_str(),
nullptr, 10 ) ),
131 static_cast<int>( std::strtol( props[2].c_str(),
nullptr, 10 ) ) );
137 marker.add_items()->set_value(
main.AsStdString() );
145 marker.mutable_child()->set_text_value( props[4].ToUTF8() );
151 marker.add_items()->set_value( resolved->GetRCItem()->GetMainItemID().AsStdString() );
153 else if( !props[4].IsEmpty() )
155 const KIID auxiliary( props[4] );
158 marker.add_items()->set_value( auxiliary.
AsStdString() );
161 if( props.size() == 8 )
163 if( !props[5].IsEmpty() )
166 if( !props[6].IsEmpty() )
169 if( !props[7].IsEmpty() )
186 google::protobuf::util::JsonPrintOptions jsonOptions;
187 jsonOptions.preserve_proto_field_names =
true;
190 std::ignore = google::protobuf::util::MessageToJsonString( aEx.
m_impl->message, &
json, jsonOptions ).ok();
194 aJson = nlohmann::json::parse(
json );
198 aJson = nlohmann::json{};
205 std::ignore = google::protobuf::util::JsonStringToMessage( aJson.dump(), &aEx.
m_impl->message ).ok();
212 if(
m_impl->message.has_marker() )
213 return m_impl->message.marker().SerializeAsString();
215 return std::string();
221 return wxString::FromUTF8(
m_impl->message.comment() );
227 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