KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_exclusion.cpp
Go to the documentation of this file.
1/*
2* This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 * @author Jon Evans <[email protected]>
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <nlohmann/json.hpp>
22
24#include <pcb_marker.h>
25
26#include <api/board/board_rules.pb.h>
27#include <google/protobuf/any.h>
28#include <google/protobuf/util/json_util.h>
29
30
32{
33 kiapi::board::DrcExclusion message;
34};
35
36
38 m_impl( std::make_unique<IMPL>() )
39{
40}
41
42
44 m_impl( std::make_unique<IMPL>( *aOther.m_impl ) )
45{
46}
47
48
50{
51 *m_impl = *aOther.m_impl;
52 return *this;
53}
54
55
57
58
60{
62 google::protobuf::Any container;
63
64 aMarker.Serialize( container );
65 container.UnpackTo( ex.m_impl->message.mutable_marker() );
66 ex.SetComment( aMarker.GetComment() );
67
68 return ex;
69}
70
71
72DRC_EXCLUSION DRC_EXCLUSION::FromProto( const kiapi::board::DrcExclusion& aMessage )
75 ex.m_impl->message.CopyFrom( aMessage );
76 return ex;
77}
78
79
80DRC_EXCLUSION DRC_EXCLUSION::FromLegacyStrings( const wxString& aMarkerData, const wxString& aComment )
81{
83
84 if( PCB_MARKER* marker = PCB_MARKER::FromLegacyString( aMarkerData ) )
85 {
86 google::protobuf::Any container;
87 marker->Serialize( container );
88 container.UnpackTo( ex.m_impl->message.mutable_marker() );
89 delete marker;
90 }
91
92 ex.SetComment( aComment );
93 return ex;
94}
95
96
97const kiapi::board::DrcExclusion& DRC_EXCLUSION::ToProto() const
98{
99 return m_impl->message;
100}
101
102
103void to_json( nlohmann::json& aJson, const DRC_EXCLUSION& aEx )
104{
105 google::protobuf::util::JsonPrintOptions jsonOptions;
106 jsonOptions.preserve_proto_field_names = true;
107
108 std::string json;
109 std::ignore = google::protobuf::util::MessageToJsonString( aEx.m_impl->message, &json, jsonOptions ).ok();
110
111 try
112 {
113 aJson = nlohmann::json::parse( json );
114 }
115 catch( ... )
116 {
117 aJson = nlohmann::json{};
118 }
119}
120
121
122void from_json( const nlohmann::json& aJson, DRC_EXCLUSION& aEx )
123{
124 std::ignore = google::protobuf::util::JsonStringToMessage( aJson.dump(), &aEx.m_impl->message ).ok();
125}
126
127
128std::string DRC_EXCLUSION::GetSortKey() const
129{
130 if( !m_impl->message.has_marker() )
131 return std::string();
132
133 // Unconnected-item markers may be reported on several layers
134 if( m_impl->message.marker().error_type() == kiapi::board::DRCET_UNCONNECTED_ITEMS )
135 {
136 kiapi::board::DrcMarker marker = m_impl->message.marker();
137 marker.clear_layer();
138 return marker.SerializeAsString();
139 }
140
141 return m_impl->message.marker().SerializeAsString();
142}
143
144
146{
147 return wxString::FromUTF8( m_impl->message.comment() );
148}
149
150
151void DRC_EXCLUSION::SetComment( const wxString& aComment )
152{
153 m_impl->message.set_comment( aComment.ToUTF8() );
154}
Container for an DRC exclusion, which is a PCB_MARKER plus an optional comment.
DRC_EXCLUSION & operator=(const DRC_EXCLUSION &aOther)
static DRC_EXCLUSION FromLegacyStrings(const wxString &aMarkerData, const wxString &aComment)
void SetComment(const wxString &aComment)
std::string GetSortKey() const
static DRC_EXCLUSION FromProto(const kiapi::board::DrcExclusion &aMessage)
std::unique_ptr< IMPL > m_impl
wxString GetComment() const
static DRC_EXCLUSION FromMarker(const PCB_MARKER &aMarker)
const kiapi::board::DrcExclusion & ToProto() const
wxString GetComment() const
Definition marker_base.h:96
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
static PCB_MARKER * FromLegacyString(const wxString &aData)
void to_json(nlohmann::json &aJson, const DRC_EXCLUSION &aEx)
void from_json(const nlohmann::json &aJson, DRC_EXCLUSION &aEx)
nlohmann::json json
Definition gerbview.cpp:50
STL namespace.
kiapi::board::DrcExclusion message