KiCad PCB EDA Suite
Loading...
Searching...
No Matches
rc_json_schema.h
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 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef RC_JSON_SCHEMA_H
21#define RC_JSON_SCHEMA_H
22
23#include <json_common.h>
24#include <wx/string.h>
25#include <optional>
26#include <vector>
27#include <json_conversions.h>
28
35namespace RC_JSON
36{
38{
39 double x;
40 double y;
41};
42
44
45
47{
48 wxString uuid;
49 wxString description;
51};
52
54
55
57{
58 wxString type;
59 wxString description;
60 wxString severity;
61 std::vector<AFFECTED_ITEM> items;
62 std::optional<COORDINATE> pos;
63 wxString layer;
65 wxString comment; // exclusion comment; if any
66};
67
68inline void to_json( nlohmann::json& aJson, const VIOLATION& aViolation )
69{
70 aJson["type"] = aViolation.type;
71 aJson["description"] = aViolation.description;
72 aJson["severity"] = aViolation.severity;
73 aJson["items"] = aViolation.items;
74
75 if( aViolation.pos )
76 aJson["pos"] = *aViolation.pos;
77
78 if( !aViolation.layer.IsEmpty() )
79 aJson["layer"] = aViolation.layer;
80
81 if( aViolation.excluded )
82 {
83 aJson["excluded"] = aViolation.excluded;
84 aJson["comment"] = aViolation.comment;
85 }
86}
87
88inline void from_json( const nlohmann::json& aJson, VIOLATION& aViolation )
89{
90 aJson.at( "type" ).get_to( aViolation.type );
91 aJson.at( "description" ).get_to( aViolation.description );
92 aJson.at( "severity" ).get_to( aViolation.severity );
93 aJson.at( "items" ).get_to( aViolation.items );
94
95 if( aJson.contains( "pos" ) )
96 aViolation.pos = aJson.at( "pos" ).get<COORDINATE>();
97 else
98 aViolation.pos.reset();
99
100 if( aJson.contains( "layer" ) )
101 aJson.at( "layer" ).get_to( aViolation.layer );
102 else
103 aViolation.layer.clear();
104
105 aJson.at( "excluded" ).get_to( aViolation.excluded );
106 aJson.at( "comment" ).get_to( aViolation.comment );
107}
108
109
111{
112 wxString key;
113 wxString description;
114};
115
117
118
120{
121 wxString $schema;
122 wxString source;
123 wxString date;
125 wxString type;
127};
128
129
131{
132 DRC_REPORT() { type = wxS( "drc" ); }
133
134 std::vector<VIOLATION> violations;
135 std::vector<VIOLATION> unconnected_items;
136 std::vector<VIOLATION> schematic_parity;
137 std::vector<wxString> included_severities;
138 std::vector<IGNORED_CHECK> ignored_checks;
139};
140
141NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE( DRC_REPORT, $schema, source, date, kicad_version, violations,
142 unconnected_items, schematic_parity, coordinate_units,
143 included_severities, ignored_checks )
144
145
146struct ERC_SHEET
147{
148 wxString uuid_path;
149 wxString path;
150 std::vector<VIOLATION> violations;
151};
152
153NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE( ERC_SHEET, uuid_path, path, violations )
154
155
157{
158 ERC_REPORT() { type = wxS( "erc" ); }
159
160 std::vector<ERC_SHEET> sheets;
161 std::vector<wxString> included_severities;
162 std::vector<IGNORED_CHECK> ignored_checks;
163};
164
165NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE( ERC_REPORT, $schema, source, date, kicad_version, sheets,
166 coordinate_units, included_severities, ignored_checks )
167
168} // namespace RC_JSON
169
170#endif
std::string source
Contains the json serialization structs for DRC and ERC reports If you are trying to change the outpu...
Definition rc_item.h:39
void from_json(const nlohmann::json &aJson, VIOLATION &aViolation)
void to_json(nlohmann::json &aJson, const VIOLATION &aViolation)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(DRC_REPORT, $schema, source, date, kicad_version, violations, unconnected_items, schematic_parity, coordinate_units, included_severities, ignored_checks) struct ERC_SHEET
std::vector< wxString > included_severities
std::vector< VIOLATION > unconnected_items
std::vector< IGNORED_CHECK > ignored_checks
std::vector< VIOLATION > violations
std::vector< VIOLATION > schematic_parity
std::vector< wxString > included_severities
std::vector< ERC_SHEET > sheets
std::vector< IGNORED_CHECK > ignored_checks
std::optional< COORDINATE > pos
std::vector< AFFECTED_ITEM > items
std::string path