KiCad PCB EDA Suite
Loading...
Searching...
No Matches
project_file_downgrade.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 *
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
21#include <common.h>
23
24#include <nlohmann/json.hpp>
25
26#include <algorithm>
27#include <cctype>
28#include <charconv>
29#include <cstdint>
30#include <functional>
31#include <iterator>
32#include <limits>
33#include <set>
34#include <string>
35#include <vector>
36
37#include <wx/intl.h>
38
39
40namespace
41{
42struct LEGACY_DRC_ERROR
43{
44 const char* m_protoName;
45 const char* m_settingsKey;
46 bool m_requiresTen = false;
47};
48
49// Frozen 9.0 and 10.0 DRC_ITEM keys, ordered by the protobuf DrcErrorType values.
50// The current error names cannot be lowercased to recover these legacy identifiers.
51constexpr LEGACY_DRC_ERROR legacyDrcErrors[] = {
52 { "DRCET_UNKNOWN", nullptr },
53 { "DRCET_UNCONNECTED_ITEMS", "unconnected_items" },
54 { "DRCET_SHORTING_ITEMS", "shorting_items" },
55 { "DRCET_ALLOWED_ITEMS", "items_not_allowed" },
56 { "DRCET_TEXT_ON_EDGECUTS", "text_on_edge_cuts" },
57 { "DRCET_CLEARANCE", "clearance" },
58 { "DRCET_CREEPAGE", "creepage" },
59 { "DRCET_TRACKS_CROSSING", "tracks_crossing" },
60 { "DRCET_EDGE_CLEARANCE", "copper_edge_clearance" },
61 { "DRCET_ZONES_INTERSECT", "zones_intersect" },
62 { "DRCET_ISOLATED_COPPER", "isolated_copper" },
63 { "DRCET_STARVED_THERMAL", "starved_thermal" },
64 { "DRCET_DANGLING_VIA", "via_dangling" },
65 { "DRCET_DANGLING_TRACK", "track_dangling" },
66 { "DRCET_DRILLED_HOLES_TOO_CLOSE", "hole_to_hole" },
67 { "DRCET_DRILLED_HOLES_COLOCATED", "holes_co_located" },
68 { "DRCET_HOLE_CLEARANCE", "hole_clearance" },
69 { "DRCET_CONNECTION_WIDTH", "connection_width" },
70 { "DRCET_TRACK_WIDTH", "track_width" },
71 { "DRCET_TRACK_ANGLE", "track_angle" },
72 { "DRCET_TRACK_SEGMENT_LENGTH", "track_segment_length" },
73 { "DRCET_ANNULAR_WIDTH", "annular_width" },
74 { "DRCET_DRILL_OUT_OF_RANGE", "drill_out_of_range" },
75 { "DRCET_VIA_DIAMETER", "via_diameter" },
76 { "DRCET_PADSTACK", "padstack" },
77 { "DRCET_PADSTACK_INVALID", "padstack_invalid" },
78 { "DRCET_MICROVIA_DRILL_OUT_OF_RANGE", "microvia_drill_out_of_range" },
79 { "DRCET_OVERLAPPING_FOOTPRINTS", "courtyards_overlap" },
80 { "DRCET_MISSING_COURTYARD", "missing_courtyard" },
81 { "DRCET_MALFORMED_COURTYARD", "malformed_courtyard" },
82 { "DRCET_PTH_IN_COURTYARD", "pth_inside_courtyard" },
83 { "DRCET_NPTH_IN_COURTYARD", "npth_inside_courtyard" },
84 { "DRCET_DISABLED_LAYER_ITEM", "item_on_disabled_layer" },
85 { "DRCET_INVALID_OUTLINE", "invalid_outline" },
86 { "DRCET_MISSING_FOOTPRINT", "missing_footprint" },
87 { "DRCET_DUPLICATE_FOOTPRINT", "duplicate_footprints" },
88 { "DRCET_NET_CONFLICT", "net_conflict" },
89 { "DRCET_EXTRA_FOOTPRINT", "extra_footprint" },
90 { "DRCET_SCHEMATIC_PARITY", "footprint_symbol_mismatch" },
91 { "DRCET_SCHEMATIC_FIELDS_PARITY", "footprint_symbol_field_mismatch", true },
92 { "DRCET_FOOTPRINT_FILTERS", "footprint_filters_mismatch" },
93 { "DRCET_LIB_FOOTPRINT_ISSUES", "lib_footprint_issues" },
94 { "DRCET_LIB_FOOTPRINT_MISMATCH", "lib_footprint_mismatch" },
95 { "DRCET_UNRESOLVED_VARIABLE", "unresolved_variable" },
96 { "DRCET_ASSERTION_FAILURE", "assertion_failure" },
97 { "DRCET_GENERIC_WARNING", "generic_warning" },
98 { "DRCET_GENERIC_ERROR", "generic_error" },
99 { "DRCET_COPPER_SLIVER", "copper_sliver" },
100 { "DRCET_SILK_CLEARANCE", "silk_overlap" },
101 { "DRCET_SILK_MASK_CLEARANCE", "silk_over_copper" },
102 { "DRCET_SILK_EDGE_CLEARANCE", "silk_edge_clearance" },
103 { "DRCET_SOLDERMASK_BRIDGE", "solder_mask_bridge" },
104 { "DRCET_TEXT_HEIGHT", "text_height" },
105 { "DRCET_TEXT_THICKNESS", "text_thickness" },
106 { "DRCET_LENGTH_OUT_OF_RANGE", "length_out_of_range" },
107 { "DRCET_SKEW_OUT_OF_RANGE", "skew_out_of_range" },
108 { "DRCET_VIA_COUNT_OUT_OF_RANGE", "too_many_vias" },
109 { "DRCET_DIFF_PAIR_GAP_OUT_OF_RANGE", "diff_pair_gap_out_of_range" },
110 { "DRCET_DIFF_PAIR_UNCOUPLED_LENGTH_TOO_LONG", "diff_pair_uncoupled_length_too_long" },
111 { "DRCET_FOOTPRINT", "footprint" },
112 { "DRCET_FOOTPRINT_TYPE_MISMATCH", "footprint_type_mismatch" },
113 { "DRCET_PAD_TH_WITH_NO_HOLE", "through_hole_pad_without_hole" },
114 { "DRCET_MIRRORED_TEXT_ON_FRONT_LAYER", "mirrored_text_on_front_layer" },
115 { "DRCET_NONMIRRORED_TEXT_ON_BACK_LAYER", "nonmirrored_text_on_back_layer" },
116 { "DRCET_MISSING_TUNING_PROFILE", "missing_tuning_profile", true },
117 { "DRCET_TUNING_PROFILE_IMPLICIT_RULES", "tuning_profile_track_geometries", true },
118 { "DRCET_TRACK_ON_POST_MACHINED_LAYER", "track_on_post_machined_layer", true },
119 { "DRCET_TRACK_NOT_CENTERED_ON_VIA", "track_not_centered_on_via", true },
120};
121
122
123constexpr LEGACY_DRC_ERROR legacyErcErrors[] = {
124 { "ERCET_UNKNOWN", nullptr },
125 { "ERCET_DUPLICATE_SHEET_NAME", "duplicate_sheet_names" },
126 { "ERCET_ENDPOINT_OFF_GRID", "endpoint_off_grid" },
127 { "ERCET_PIN_NOT_CONNECTED", "pin_not_connected" },
128 { "ERCET_PIN_NOT_DRIVEN", "pin_not_driven" },
129 { "ERCET_POWERPIN_NOT_DRIVEN", "power_pin_not_driven" },
130 { "ERCET_HIERARCHICAL_LABEL", "hier_label_mismatch" },
131 { "ERCET_NOCONNECT_CONNECTED", "no_connect_connected" },
132 { "ERCET_NOCONNECT_NOT_CONNECTED", "no_connect_dangling" },
133 { "ERCET_LABEL_NOT_CONNECTED", "label_dangling" },
134 { "ERCET_SIMILAR_LABELS", "similar_labels" },
135 { "ERCET_SIMILAR_POWER", "similar_power" },
136 { "ERCET_SIMILAR_LABEL_AND_POWER", "similar_label_and_power" },
137 { "ERCET_SINGLE_GLOBAL_LABEL", "single_global_label" },
138 { "ERCET_SAME_LOCAL_GLOBAL_LABEL", "same_local_global_label" },
139 { "ERCET_SAME_LOCAL_GLOBAL_POWER", nullptr },
140 { "ERCET_DIFFERENT_UNIT_FP", "different_unit_footprint" },
141 { "ERCET_MISSING_POWER_INPUT_PIN", "missing_power_pin" },
142 { "ERCET_MISSING_INPUT_PIN", "missing_input_pin" },
143 { "ERCET_MISSING_BIDI_PIN", "missing_bidi_pin" },
144 { "ERCET_MISSING_UNIT", "missing_unit" },
145 { "ERCET_DIFFERENT_UNIT_NET", "different_unit_net" },
146 { "ERCET_BUS_ALIAS_CONFLICT", "bus_definition_conflict" },
147 { "ERCET_DRIVER_CONFLICT", "multiple_net_names" },
148 { "ERCET_BUS_ENTRY_CONFLICT", "net_not_bus_member" },
149 { "ERCET_BUS_TO_BUS_CONFLICT", "bus_to_bus_conflict" },
150 { "ERCET_BUS_TO_NET_CONFLICT", "bus_to_net_conflict" },
151 { "ERCET_GROUND_PIN_NOT_GROUND", "ground_pin_not_ground", true },
152 { "ERCET_LABEL_SINGLE_PIN", "isolated_pin_label", true },
153 { "ERCET_UNRESOLVED_VARIABLE", "unresolved_variable" },
154 { "ERCET_UNDEFINED_NETCLASS", "undefined_netclass" },
155 { "ERCET_SIMULATION_MODEL", "simulation_model_issue" },
156 { "ERCET_WIRE_DANGLING", "wire_dangling" },
157 { "ERCET_LIB_SYMBOL_ISSUES", "lib_symbol_issues" },
158 { "ERCET_LIB_SYMBOL_MISMATCH", "lib_symbol_mismatch" },
159 { "ERCET_FOOTPRINT_LINK_ISSUES", "footprint_link_issues" },
160 { "ERCET_FOOTPRINT_FILTERS", "footprint_filter" },
161 { "ERCET_UNANNOTATED", "unannotated" },
162 { "ERCET_EXTRA_UNITS", "extra_units" },
163 { "ERCET_DIFFERENT_UNIT_VALUE", "unit_value_mismatch" },
164 { "ERCET_DUPLICATE_REFERENCE", "duplicate_reference" },
165 { "ERCET_BUS_ENTRY_NEEDED", "bus_entry_needed" },
166 { "ERCET_FOUR_WAY_JUNCTION", "four_way_junction" },
167 { "ERCET_LABEL_MULTIPLE_WIRES", "label_multiple_wires" },
168 { "ERCET_UNCONNECTED_WIRE_ENDPOINT", "unconnected_wire_endpoint" },
169 { "ERCET_STACKED_PIN_SYNTAX", "stacked_pin_name", true },
170 { "ERCET_PIN_MAP_BAD_PAD", nullptr },
171 { "ERCET_PIN_MAP_UNMAPPED_PIN", nullptr },
172 { "ERCET_PIN_MAP_DUPLICATE_PAD", nullptr },
173 { "ERCET_PIN_MAP_STALE_PIN", nullptr },
174 { "ERCET_EMPTY_LABEL_NAME", nullptr },
175 { "ERCET_VARIANT_SYMBOL_INVALID", nullptr },
176 { "ERCET_VARIANT_SYMBOL_INCOMPATIBLE", nullptr },
177 { "ERCET_DUPLICATE_PIN_ERROR", "duplicate_pins" },
178 { "ERCET_PIN_TO_PIN_WARNING", "pin_to_pin" },
179 { "ERCET_PIN_TO_PIN_ERROR", "pin_to_pin" },
180 { "ERCET_ANNOTATION_ACTION", nullptr },
181 { "ERCET_GENERIC_WARNING", "generic-warning" },
182 { "ERCET_GENERIC_ERROR", "generic-error" },
183 { "ERCET_FIELD_NAME_WHITESPACE", "field_name_whitespace", true },
184 { "ERCET_WIRED_IMPLICIT_POWER", nullptr },
185};
186
187
188bool isUuid( const std::string& aText )
189{
190 if( aText.size() != 36 )
191 return false;
192
193 for( size_t i = 0; i < aText.size(); i++ )
194 {
195 if( i == 8 || i == 13 || i == 18 || i == 23 )
196 {
197 if( aText[i] != '-' )
198 return false;
199 }
200 else if( !std::isxdigit( static_cast<unsigned char>( aText[i] ) ) )
201 {
202 return false;
203 }
204 }
205
206 return true;
207}
208
209
210bool parseCoordinate( const nlohmann::json& aValue, std::string& aText, int64_t aDivisor = 1 )
211{
212 if( !aValue.is_number_integer() && !aValue.is_string() )
213 return false;
214
215 std::string text = aValue.is_string() ? aValue.get<std::string>() : aValue.dump();
216 int64_t value = 0;
217 auto parsed = std::from_chars( text.data(), text.data() + text.size(), value );
218
219 if( parsed.ec != std::errc() || parsed.ptr != text.data() + text.size() || value % aDivisor != 0
220 || value / aDivisor < std::numeric_limits<int32_t>::min()
221 || value / aDivisor > std::numeric_limits<int32_t>::max() )
222 {
223 return false;
224 }
225
226 aText = std::to_string( value / aDivisor );
227 return true;
228}
229
230
231std::string legacyLayerName( const nlohmann::json& aLayer, bool aPreTen )
232{
233 // Protobuf accepts both its canonical enum strings and numeric enum values.
234 static constexpr const char* layers[] = {
235 nullptr, nullptr, nullptr, "F.Cu", "In1.Cu", "In2.Cu", "In3.Cu", "In4.Cu", "In5.Cu",
236 "In6.Cu", "In7.Cu", "In8.Cu", "In9.Cu", "In10.Cu", "In11.Cu", "In12.Cu", "In13.Cu", "In14.Cu",
237 "In15.Cu", "In16.Cu", "In17.Cu", "In18.Cu", "In19.Cu", "In20.Cu", "In21.Cu", "In22.Cu", "In23.Cu",
238 "In24.Cu", "In25.Cu", "In26.Cu", "In27.Cu", "In28.Cu", "In29.Cu", "In30.Cu", "B.Cu", "B.Adhes",
239 "F.Adhes", "B.Paste", "F.Paste", "B.SilkS", "F.SilkS", "B.Mask", "F.Mask", "Dwgs.User", "Cmts.User",
240 "Eco1.User", "Eco2.User", "Edge.Cuts", "Margin", "B.CrtYd", "F.CrtYd", "B.Fab", "F.Fab", "User.1",
241 "User.2", "User.3", "User.4", "User.5", "User.6", "User.7", "User.8", "User.9", nullptr,
242 "User.10", "User.11", "User.12", "User.13", "User.14", "User.15", "User.16", "User.17", "User.18",
243 "User.19", "User.20", "User.21", "User.22", "User.23", "User.24", "User.25", "User.26", "User.27",
244 "User.28", "User.29", "User.30", "User.31", "User.32", "User.33", "User.34", "User.35", "User.36",
245 "User.37", "User.38", "User.39", "User.40", "User.41", "User.42", "User.43", "User.44", "User.45"
246 };
247
248 int index = -1;
249
250 if( aLayer.is_number_integer() && aLayer >= 0 && aLayer < std::size( layers ) )
251 index = aLayer.get<int>();
252 else if( aLayer.is_string() )
253 {
254 std::string name = aLayer.get<std::string>();
255
256 for( size_t i = 3; i < std::size( layers ); i++ )
257 {
258 if( !layers[i] )
259 continue;
260
261 std::string proto = "BL_" + std::string( layers[i] );
262 std::replace( proto.begin(), proto.end(), '.', '_' );
263
264 if( name == proto )
265 index = static_cast<int>( i );
266 }
267 }
268
269 if( index < 3 || ( aPreTen && index > 61 ) || !layers[index] )
270 return {};
271
272 return layers[index];
273}
274
275
276bool downgradeProtoExclusion( const nlohmann::json& aEntry, bool aPreTen, nlohmann::json& aResult )
277{
278 if( !aEntry.is_object() || !aEntry.contains( "marker" ) || !aEntry["marker"].is_object()
279 || ( aEntry.contains( "comment" ) && !aEntry["comment"].is_string() ) )
280 {
281 return false;
282 }
283
284 const nlohmann::json& marker = aEntry["marker"];
285
286 if( !marker.contains( "error_type" ) )
287 return false;
288
289 const LEGACY_DRC_ERROR* error = nullptr;
290 const nlohmann::json& type = marker["error_type"];
291
292 if( type.is_string() )
293 {
294 // DRCET_LINE_WIDTH is a later alias of the frozen DRCET_TEXT_THICKNESS value
295 const std::string name = type == "DRCET_LINE_WIDTH" ? "DRCET_TEXT_THICKNESS" : type.get<std::string>();
296
297 for( const LEGACY_DRC_ERROR& candidate : legacyDrcErrors )
298 {
299 if( name == candidate.m_protoName )
300 error = &candidate;
301 }
302 }
303 else if( type.is_number_integer() && type >= 0 && type < std::size( legacyDrcErrors ) )
304 {
305 error = &legacyDrcErrors[type.get<size_t>()];
306 }
307
308 if( !error || !error->m_settingsKey || ( aPreTen && error->m_requiresTen ) )
309 return false;
310
311 std::string x = "0";
312 std::string y = "0";
313
314 if( marker.contains( "position" ) )
315 {
316 const nlohmann::json& position = marker["position"];
317
318 if( !position.is_object() || ( position.contains( "x_nm" ) && !parseCoordinate( position["x_nm"], x ) )
319 || ( position.contains( "y_nm" ) && !parseCoordinate( position["y_nm"], y ) ) )
320 {
321 return false;
322 }
323 }
324
325 std::vector<std::string> ids;
326
327 if( marker.contains( "items" ) )
328 {
329 if( !marker["items"].is_array() || marker["items"].size() > 2 )
330 return false;
331
332 for( const nlohmann::json& item : marker["items"] )
333 {
334 if( !item.is_object() || !item.contains( "value" ) || !item["value"].is_string()
335 || !isUuid( item["value"].get<std::string>() ) )
336 {
337 return false;
338 }
339
340 ids.push_back( item["value"].get<std::string>() );
341 }
342 }
343
344 const std::string nil = "00000000-0000-0000-0000-000000000000";
345 std::string main = ids.empty() ? nil : ids[0];
346 std::string aux = ids.size() < 2 ? nil : ids[1];
347 std::string key = error->m_settingsKey;
348 std::string value = key + '|' + x + '|' + y + '|';
349
350 if( key == "copper_sliver" || key == "generic_warning" || key == "generic_error" || key == "starved_thermal"
351 || ( key == "unconnected_items" && !aPreTen ) )
352 {
353 std::string layer = marker.contains( "layer" ) ? legacyLayerName( marker["layer"], aPreTen ) : "";
354
355 if( layer.empty() )
356 return false;
357
358 if( key == "unconnected_items" )
359 value += layer + "|4|" + main + '|' + aux;
360 else if( key == "starved_thermal" )
361 value += main + '|' + aux + '|' + layer;
362 else
363 {
364 if( ids.size() > 1 )
365 return false;
366
367 value += main + '|' + layer;
368 }
369 }
370 else
371 {
372 // The ProtoJSON form cannot distinguish a drawing-sheet unresolved variable from
373 // an item-less board marker. The old empty-ID representation would change its type.
374 if( key == "unresolved_variable" && ids.empty() )
375 return false;
376
377 value += main + '|' + aux;
378 }
379
380 aResult = nlohmann::json::array( { value, aEntry.value( "comment", "" ) } );
381 return true;
382}
383
384
385bool downgradeLegacyExclusion( const nlohmann::json& aEntry, bool aPreTen, nlohmann::json& aResult )
386{
387 std::string marker;
388 std::string comment;
389
390 if( aEntry.is_string() )
391 marker = aEntry.get<std::string>();
392 else if( aEntry.is_array() && !aEntry.empty() && aEntry[0].is_string()
393 && ( aEntry.size() == 1 || ( aEntry.size() == 2 && aEntry[1].is_string() ) ) )
394 {
395 marker = aEntry[0].get<std::string>();
396
397 if( aEntry.size() == 2 )
398 comment = aEntry[1].get<std::string>();
399 }
400 else
401 return false;
402
403 std::vector<std::string> parts;
404 size_t start = 0;
405
406 for( size_t end = marker.find( '|' ); end != std::string::npos; end = marker.find( '|', start ) )
407 {
408 parts.push_back( marker.substr( start, end - start ) );
409 start = end + 1;
410 }
411
412 parts.push_back( marker.substr( start ) );
413
414 if( parts.size() < 5 )
415 return false;
416
417 bool supported = parts[0] == "hole_near_hole";
418
419 for( const LEGACY_DRC_ERROR& error : legacyDrcErrors )
420 {
421 if( error.m_settingsKey && parts[0] == error.m_settingsKey && !( aPreTen && error.m_requiresTen ) )
422 supported = true;
423 }
424
425 std::string coordinate;
426
427 if( !supported || !parseCoordinate( parts[1], coordinate ) || !parseCoordinate( parts[2], coordinate ) )
428 return false;
429
430 if( parts[0] == "unconnected_items" && parts.size() == 7 )
431 {
432 if( !isUuid( parts[5] ) || !isUuid( parts[6] ) )
433 return false;
434
435 if( aPreTen )
436 marker = parts[0] + '|' + parts[1] + '|' + parts[2] + '|' + parts[5] + '|' + parts[6];
437 }
438 else if( parts[0] == "starved_thermal" )
439 {
440 if( parts.size() != 6 || !isUuid( parts[3] ) || !isUuid( parts[4] ) )
441 return false;
442 }
443 else if( parts[0] == "copper_sliver" || parts[0] == "generic_warning" || parts[0] == "generic_error" )
444 {
445 if( parts.size() != 5 || !isUuid( parts[3] ) )
446 return false;
447 }
448 else if( parts.size() != 5
449 || !( ( isUuid( parts[3] ) && isUuid( parts[4] ) )
450 || ( parts[0] == "unresolved_variable" && parts[3].empty() && parts[4].empty() ) ) )
451 {
452 return false;
453 }
454
455 aResult = nlohmann::json::array( { marker, comment } );
456 return true;
457}
458
459
460bool legacyErcPath( const nlohmann::json& aPath, std::string& aText )
461{
462 if( !aPath.is_object() || !aPath.contains( "path" ) || !aPath["path"].is_array() || aPath["path"].empty() )
463 return false;
464
465 for( const nlohmann::json& part : aPath["path"] )
466 {
467 if( !part.is_object() || !part.contains( "value" ) || !part["value"].is_string()
468 || !isUuid( part["value"].get<std::string>() ) )
469 {
470 return false;
471 }
472
473 aText += '/' + part["value"].get<std::string>();
474 }
475
476 return true;
477}
478
479
480bool ercChildNeedsTextDowngrade( const wxString& aText, const nlohmann::json& aDoc, bool aPreTen,
481 std::set<std::string>& aVisiting )
482{
483 bool changed = aPreTen && ( aText.Contains( wxT( "\\${" ) ) || aText.Contains( wxT( "\\@{" ) ) );
484 std::function<bool( wxString* )> scan = [&]( wxString* aToken )
485 {
486 const wxString token = aToken->AfterLast( ':' );
487 changed |= token.StartsWith( wxT( "PROPERTY." ) ) || token == wxT( "SYMBOL_IS_POWER" )
488 || token == wxT( "SYMBOL_IS_LOCAL_POWER" );
489
490 if( aDoc.contains( "text_variables" ) && aDoc["text_variables"].is_object() )
491 {
492 const nlohmann::json& variables = aDoc["text_variables"];
493 const std::string key = aToken->ToStdString( wxConvUTF8 );
494
495 if( variables.contains( key ) && variables[key].is_string() && aVisiting.insert( key ).second )
496 {
497 changed |= ercChildNeedsTextDowngrade( wxString::FromUTF8( variables[key].get<std::string>() ), aDoc,
498 aPreTen, aVisiting );
499 aVisiting.erase( key );
500 }
501 }
502
503 return false;
504 };
505
506 const wxString scanned = ExpandTextVars( aText, &scan, INTERNAL );
507 return changed || ( aPreTen && scanned.Contains( wxT( "@{" ) ) );
508}
509
510
511bool downgradeProtoErcExclusion( const nlohmann::json& aEntry, const nlohmann::json& aDoc, bool aPreTen,
512 nlohmann::json& aResult )
513{
514 if( !aEntry.contains( "marker" ) || !aEntry["marker"].is_object()
515 || ( aEntry.contains( "comment" ) && !aEntry["comment"].is_string() ) )
516 {
517 return false;
518 }
519
520 const nlohmann::json& marker = aEntry["marker"];
521
522 if( !marker.contains( "error_type" ) )
523 return false;
524
525 const LEGACY_DRC_ERROR* error = nullptr;
526 const nlohmann::json& type = marker["error_type"];
527
528 if( type.is_string() )
529 {
530 for( const LEGACY_DRC_ERROR& candidate : legacyErcErrors )
531 {
532 if( type == candidate.m_protoName )
533 error = &candidate;
534 }
535 }
536 else if( type.is_number_integer() && type >= 0 && type < std::size( legacyErcErrors ) )
537 error = &legacyErcErrors[type.get<size_t>()];
538
539 if( !error || !error->m_settingsKey || ( aPreTen && error->m_requiresTen ) )
540 return false;
541
542 std::string x = "0";
543 std::string y = "0";
544
545 if( marker.contains( "position" ) )
546 {
547 const nlohmann::json& position = marker["position"];
548
549 // Schematic internal units are 100 nm. Non-integral conversions cannot keep identity.
550 if( !position.is_object() || ( position.contains( "x_nm" ) && !parseCoordinate( position["x_nm"], x, 100 ) )
551 || ( position.contains( "y_nm" ) && !parseCoordinate( position["y_nm"], y, 100 ) ) )
552 {
553 return false;
554 }
555 }
556
557 const std::string nil = "00000000-0000-0000-0000-000000000000";
558 std::vector<std::string> ids;
559
560 if( marker.contains( "items" ) )
561 {
562 if( !marker["items"].is_array() || marker["items"].size() > 2 )
563 return false;
564
565 for( const nlohmann::json& item : marker["items"] )
566 {
567 if( !item.is_object() || !item.contains( "value" ) || !item["value"].is_string()
568 || !isUuid( item["value"].get<std::string>() ) )
569 {
570 return false;
571 }
572
573 ids.push_back( item["value"].get<std::string>() );
574 }
575 }
576
577 std::string main = ids.empty() ? nil : ids[0];
578 std::string aux = ids.size() < 2 ? nil : ids[1];
579 std::string key = error->m_settingsKey;
580
581 if( marker.contains( "child" ) )
582 {
583 const nlohmann::json& child = marker["child"];
584
585 if( ( key != "generic-warning" && key != "generic-error" && key != "unresolved_variable" ) || ids.empty()
586 || main == nil || !child.is_object() || !child.contains( "text_value" )
587 || !child["text_value"].is_string() )
588 {
589 return false;
590 }
591
592 aux = child["text_value"].get<std::string>();
593
594 std::set<std::string> visiting;
595
596 if( aux.empty() || aux.find( '|' ) != std::string::npos || marker.contains( "aux_item_sheet_path" )
597 || ercChildNeedsTextDowngrade( wxString::FromUTF8( aux ), aDoc, aPreTen, visiting ) )
598 return false;
599 }
600
601 std::string value = key + '|' + x + '|' + y + '|' + main + '|' + aux;
602
603 if( marker.contains( "aux_item_sheet_path" ) && !marker.contains( "main_item_sheet_path" ) )
604 return false;
605
606 for( const char* name : { "sheet_specific_path", "main_item_sheet_path", "aux_item_sheet_path" } )
607 {
608 std::string path;
609
610 if( marker.contains( name ) && !legacyErcPath( marker[name], path ) )
611 return false;
612
613 value += '|' + path;
614 }
615
616 aResult = nlohmann::json::array( { value, aEntry.value( "comment", "" ) } );
617 return true;
618}
619
620
621bool downgradeLegacyErcExclusion( const nlohmann::json& aEntry, const nlohmann::json& aDoc, bool aPreTen,
622 nlohmann::json& aResult )
623{
624 std::string marker;
625 std::string comment;
626
627 if( aEntry.is_string() )
628 marker = aEntry.get<std::string>();
629 else if( aEntry.is_array() && !aEntry.empty() && aEntry[0].is_string()
630 && ( aEntry.size() == 1 || ( aEntry.size() == 2 && aEntry[1].is_string() ) ) )
631 {
632 marker = aEntry[0].get<std::string>();
633
634 if( aEntry.size() == 2 )
635 comment = aEntry[1].get<std::string>();
636 }
637 else
638 return false;
639
640 std::vector<std::string> parts;
641 size_t start = 0;
642
643 for( size_t end = marker.find( '|' ); end != std::string::npos; end = marker.find( '|', start ) )
644 {
645 parts.push_back( marker.substr( start, end - start ) );
646 start = end + 1;
647 }
648
649 parts.push_back( marker.substr( start ) );
650
651 if( parts.size() != 5 && parts.size() != 8 )
652 return false;
653
654 bool supported = aPreTen && parts[0] == "global_label_dangling";
655
656 for( const LEGACY_DRC_ERROR& error : legacyErcErrors )
657 {
658 if( error.m_settingsKey && parts[0] == error.m_settingsKey && !( aPreTen && error.m_requiresTen ) )
659 supported = true;
660 }
661
662 std::string coordinate;
663
664 if( !supported || !parseCoordinate( parts[1], coordinate ) || !parseCoordinate( parts[2], coordinate )
665 || !isUuid( parts[3] ) )
666 {
667 return false;
668 }
669
670 bool childText = parts[0] == "generic-warning" || parts[0] == "generic-error" || parts[0] == "unresolved_variable";
671
672 if( !childText && !isUuid( parts[4] ) )
673 return false;
674
675 std::set<std::string> visiting;
676
677 if( childText && ercChildNeedsTextDowngrade( wxString::FromUTF8( parts[4] ), aDoc, aPreTen, visiting ) )
678 return false;
679
680 aResult = nlohmann::json::array( { marker, comment } );
681 return true;
682}
683
684
685void downgradeErcSettings( nlohmann::json& aDoc, bool aPreTen, COMPATIBILITY_REPORT& aReport )
686{
687 if( !aDoc.contains( "erc" ) || !aDoc["erc"].is_object() )
688 return;
689
690 nlohmann::json& settings = aDoc["erc"];
691
692 if( settings.contains( "erc_exclusions" ) && !settings["erc_exclusions"].is_array() )
693 {
694 if( !settings["erc_exclusions"].is_null() && !settings["erc_exclusions"].empty() )
695 aReport.Add( DOWNGRADE_BUCKET::DROP, _( "ERC exclusions" ),
696 _( "The target cannot represent this exclusion. It is removed." ), 1 );
697
698 settings["erc_exclusions"] = nlohmann::json::array();
699 }
700
701 if( settings.contains( "erc_exclusions" ) && settings["erc_exclusions"].is_array() )
702 {
703 nlohmann::json exclusions = nlohmann::json::array();
704
705 for( const nlohmann::json& entry : settings["erc_exclusions"] )
706 {
707 nlohmann::json converted;
708
709 bool ok = entry.is_object() ? downgradeProtoErcExclusion( entry, aDoc, aPreTen, converted )
710 : downgradeLegacyErcExclusion( entry, aDoc, aPreTen, converted );
711
712 if( ok )
713 exclusions.push_back( std::move( converted ) );
714 else
715 aReport.Add( DOWNGRADE_BUCKET::DROP, _( "ERC exclusions" ),
716 _( "The target cannot represent this exclusion. It is removed." ), 1 );
717 }
718
719 settings["erc_exclusions"] = std::move( exclusions );
720 }
721
722 if( settings.contains( "meta" ) && settings["meta"].is_object() )
723 settings["meta"]["version"] = 0;
724}
725
726
727bool hasNonDefaultSettings( const nlohmann::json& aSettings, const nlohmann::json& aDefaults )
728{
729 if( aSettings == aDefaults )
730 return false;
731
732 if( !aSettings.is_object() )
733 return !aSettings.empty() && !aSettings.is_null();
734
735 for( const auto& [key, value] : aSettings.items() )
736 {
737 if( !aDefaults.contains( key ) || value != aDefaults[key] )
738 return true;
739 }
740
741 return false;
742}
743
744
745bool hasConfiguredProjectSettings( const nlohmann::json& aSettings, const nlohmann::json& aDefaults,
746 bool aSectionRoot = true )
747{
748 if( aSettings == aDefaults || aSettings.is_null() || aSettings.empty() )
749 return false;
750
751 if( !aSettings.is_object() || !aDefaults.is_object() )
752 return true;
753
754 for( const auto& [key, value] : aSettings.items() )
755 {
756 if( aSectionRoot && key == "meta" )
757 continue;
758
759 if( aDefaults.contains( key ) )
760 {
761 if( hasConfiguredProjectSettings( value, aDefaults[key], false ) )
762 return true;
763 }
764 else if( !value.is_null() && !value.empty() )
765 {
766 return true;
767 }
768 }
769
770 return false;
771}
772
773
774void downgradeBomSettings( nlohmann::json& aSettings, COMPATIBILITY_REPORT& aReport )
775{
776 auto downgradePreset = [&]( nlohmann::json& aPreset )
777 {
778 if( !aPreset.is_object() )
779 return;
780
781 if( aPreset.contains( "filter_scope" ) && aPreset["filter_scope"] != "reference"
782 && aPreset.contains( "filter_string" ) && aPreset["filter_string"].is_string()
783 && !aPreset["filter_string"].get<std::string>().empty() )
784 {
785 aReport.Add( DOWNGRADE_BUCKET::DROP, _( "BOM field filters" ),
786 _( "The target can only filter references. The field filter is removed." ), 1 );
787 aPreset["filter_string"] = "";
788 }
789
790 aPreset.erase( "filter_scope" );
791 };
792
793 auto downgradeFormat = [&]( nlohmann::json& aFormat )
794 {
795 if( !aFormat.is_object() )
796 return;
797
798 if( aFormat.contains( "include_byte_order_mark" ) && aFormat["include_byte_order_mark"] == true )
799 aReport.Add( DOWNGRADE_BUCKET::DROP, _( "BOM byte order marks" ),
800 _( "The target cannot retain the BOM byte order mark option." ), 1 );
801
802 aFormat.erase( "include_byte_order_mark" );
803 };
804
805 if( aSettings.contains( "bom_settings" ) )
806 downgradePreset( aSettings["bom_settings"] );
807
808 if( aSettings.contains( "bom_presets" ) && aSettings["bom_presets"].is_array() )
809 {
810 for( nlohmann::json& preset : aSettings["bom_presets"] )
811 downgradePreset( preset );
812 }
813
814 if( aSettings.contains( "bom_fmt_settings" ) )
815 downgradeFormat( aSettings["bom_fmt_settings"] );
816
817 if( aSettings.contains( "bom_fmt_presets" ) && aSettings["bom_fmt_presets"].is_array() )
818 {
819 for( nlohmann::json& format : aSettings["bom_fmt_presets"] )
820 downgradeFormat( format );
821 }
822}
823
824
825void downgradeOutputSettings( nlohmann::json& aDoc, COMPATIBILITY_REPORT& aReport )
826{
827 if( aDoc.contains( "schematic" ) && aDoc["schematic"].is_object() )
828 downgradeBomSettings( aDoc["schematic"], aReport );
829
830 if( !aDoc.contains( "board" ) || !aDoc["board"].is_object() )
831 return;
832
833 nlohmann::json& board = aDoc["board"];
834
835 if( board.contains( "ipc2581" ) && board["ipc2581"].is_object() )
836 {
837 nlohmann::json& ipc = board["ipc2581"];
838 bool changed = false;
839 const nlohmann::json defaults = {
840 { "mode", "" }, { "sections", "" }, { "custom_sections", false }, { "net_names", "" }, { "ref_des", "" }
841 };
842
843 for( const auto& [key, value] : defaults.items() )
844 {
845 if( ipc.contains( key ) )
846 {
847 changed |= ipc[key] != value;
848 ipc.erase( key );
849 }
850 }
851
852 if( changed )
853 aReport.Add( DOWNGRADE_BUCKET::DROP, _( "IPC-2581 output customization" ),
854 _( "The target cannot retain the selected output sections or naming rules." ), 1 );
855 }
856
857 if( board.contains( "idf_export" ) )
858 {
859 const nlohmann::json defaults = { { "units", 0 },
860 { "origin_mode", 2 },
861 { "user_origin_x", 0.0 },
862 { "user_origin_y", 0.0 },
863 { "include_unspecified", true },
864 { "include_dnp", true },
865 { "calculate_height_from_models", true },
866 { "part_number_field", "Value" } };
867
868 if( hasNonDefaultSettings( board["idf_export"], defaults ) )
869 aReport.Add( DOWNGRADE_BUCKET::DROP, _( "IDF output customization" ),
870 _( "The target cannot retain the selected IDF export settings." ), 1 );
871
872 board.erase( "idf_export" );
873 }
874
875 if( board.contains( "design_settings" ) && board["design_settings"].is_object() )
876 {
877 nlohmann::json& settings = board["design_settings"];
878 const nlohmann::json defaults = { { "bom_export_filename", "${PROJECTNAME}.csv" },
879 { "bom_settings", BOM_PRESET::DefaultEditing() },
880 { "bom_fmt_settings", BOM_FMT_PRESET::CSV() },
881 { "bom_presets", nlohmann::json::array() },
882 { "bom_fmt_presets", nlohmann::json::array() } };
883 bool changed = false;
884
885 for( const auto& [key, value] : defaults.items() )
886 {
887 if( !settings.contains( key ) )
888 continue;
889
890 changed |= hasNonDefaultSettings( settings[key], value );
891 settings.erase( key );
892 }
893
894 if( changed )
895 aReport.Add( DOWNGRADE_BUCKET::DROP, _( "PCB BOM output customization" ),
896 _( "The target cannot retain the PCB BOM export settings." ), 1 );
897 }
898}
899
900
901void downgradeBoardSettings( nlohmann::json& aDoc, bool aPreTen, COMPATIBILITY_REPORT& aReport )
902{
903 if( !aDoc.contains( "board" ) || !aDoc["board"].is_object() || !aDoc["board"].contains( "design_settings" )
904 || !aDoc["board"]["design_settings"].is_object() )
905 {
906 return;
907 }
908
909 nlohmann::json& settings = aDoc["board"]["design_settings"];
910
911 if( settings.contains( "drc_exclusions" ) )
912 {
913 nlohmann::json exclusions = nlohmann::json::array();
914
915 if( !settings["drc_exclusions"].is_array() )
916 {
917 if( !settings["drc_exclusions"].is_null() && !settings["drc_exclusions"].empty() )
918 aReport.Add( DOWNGRADE_BUCKET::DROP, _( "DRC exclusions" ),
919 _( "The target cannot represent this exclusion. It is removed." ), 1 );
920 }
921 else
922 {
923 for( const nlohmann::json& entry : settings["drc_exclusions"] )
924 {
925 nlohmann::json converted;
926 bool ok = entry.is_object() ? downgradeProtoExclusion( entry, aPreTen, converted )
927 : downgradeLegacyExclusion( entry, aPreTen, converted );
928
929 if( ok )
930 exclusions.push_back( std::move( converted ) );
931 else
932 aReport.Add( DOWNGRADE_BUCKET::DROP, _( "DRC exclusions" ),
933 _( "The target cannot represent this exclusion. It is removed." ), 1 );
934 }
935 }
936
937 settings["drc_exclusions"] = std::move( exclusions );
938 }
939
940 if( settings.contains( "via_stack_presets" ) )
941 {
942 if( !settings["via_stack_presets"].empty() && !settings["via_stack_presets"].is_null() )
943 aReport.Add( DOWNGRADE_BUCKET::DROP, _( "Microvia stack presets" ), _( "Removed from the project file." ),
944 1 );
945
946 settings.erase( "via_stack_presets" );
947 }
948
949 if( settings.contains( "teardrop_parameters" ) && settings["teardrop_parameters"].is_array() )
950 {
951 for( nlohmann::json& entry : settings["teardrop_parameters"] )
952 {
953 if( !entry.is_object() )
954 continue;
955
956 if( entry.contains( "td_enabled" ) && entry["td_enabled"] == true )
957 aReport.Add( DOWNGRADE_BUCKET::DROP, _( "Teardrop enable defaults" ),
958 _( "The target cannot retain enabled teardrop defaults." ), 1 );
959
960 entry.erase( "td_enabled" );
961 }
962 }
963
964 // Schema 4 renamed the text thickness keys to line width
965 auto restoreKey = [&settings]( const char* aParent, const char* aCurrent, const char* aLegacy )
966 {
967 if( !settings.contains( aParent ) || !settings[aParent].is_object() )
968 return;
969
970 nlohmann::json& parent = settings[aParent];
971
972 if( !parent.contains( aCurrent ) )
973 return;
974
975 parent[aLegacy] = parent[aCurrent];
976 parent.erase( aCurrent );
977 };
978
979 restoreKey( "rule_severities", "line_width", "text_thickness" );
980 restoreKey( "rules", "min_silk_line_width", "min_text_thickness" );
981
982 if( settings.contains( "meta" ) && settings["meta"].is_object() )
983 settings["meta"]["version"] = 2;
984}
985} // namespace
986
987
988void DowngradeProjectFileJson( nlohmann::json& aDoc, const DOWNGRADE_TARGET& aTarget, COMPATIBILITY_REPORT& aReport )
989{
990 const PROJECT_SCHEMAS_REVIEWED reviewed;
991
992 auto knownSchema = [&]( const nlohmann::json& aSettings, int aMaximum, const wxString& aName )
993 {
994 if( aSettings.is_object() && aSettings.contains( "meta" ) && aSettings["meta"].is_object()
995 && aSettings["meta"].contains( "version" ) && aSettings["meta"]["version"].is_number()
996 && aSettings["meta"]["version"] > aMaximum )
997 {
998 aReport.Add( DOWNGRADE_BUCKET::BLOCK, _( "Newer project settings schema" ),
999 wxString::Format( _( "The %s schema is newer than the exporter has reviewed." ), aName ) );
1000 return false;
1001 }
1002
1003 return true;
1004 };
1005
1006 bool known = knownSchema( aDoc, reviewed.m_Project, _( "project" ) );
1007
1008 if( aDoc.contains( "net_settings" ) )
1009 known &= knownSchema( aDoc["net_settings"], reviewed.m_NetSettings, _( "net settings" ) );
1010
1011 if( aDoc.contains( "tuning_profiles" ) )
1012 known &= knownSchema( aDoc["tuning_profiles"], reviewed.m_TuningProfiles, _( "tuning profiles" ) );
1013
1014 if( aDoc.contains( "component_class_settings" ) )
1015 known &= knownSchema( aDoc["component_class_settings"], reviewed.m_ComponentClasses,
1016 _( "component class settings" ) );
1017
1018 if( aDoc.contains( "erc" ) )
1019 known &= knownSchema( aDoc["erc"], reviewed.m_Erc, _( "ERC settings" ) );
1020
1021 if( aDoc.contains( "board" ) && aDoc["board"].is_object() && aDoc["board"].contains( "design_settings" ) )
1022 known &= knownSchema( aDoc["board"]["design_settings"], reviewed.m_BoardDesignSettings,
1023 _( "board design settings" ) );
1024
1025 if( !known )
1026 return;
1027
1028 // KiCad 10 introduced board format 20260206. Earlier targets also lose its settings.
1029 bool preTen = aTarget.m_boardVersion < 20260206;
1030 bool tuningLoss = false;
1031
1032 downgradeBoardSettings( aDoc, preTen, aReport );
1033 downgradeErcSettings( aDoc, preTen, aReport );
1034 downgradeOutputSettings( aDoc, aReport );
1035
1036 if( aDoc.contains( "net_settings" ) )
1037 {
1038 nlohmann::json& net = aDoc["net_settings"];
1039
1040 if( net.contains( "net_chain_netclasses" ) )
1041 {
1042 if( !net["net_chain_netclasses"].empty() && !net["net_chain_netclasses"].is_null() )
1043 aReport.Add( DOWNGRADE_BUCKET::DROP, _( "Net chain netclass assignments" ),
1044 _( "Removed from the project file." ), 1 );
1045
1046 net.erase( "net_chain_netclasses" );
1047 }
1048
1049 if( net.contains( "net_chain_classes" ) )
1050 {
1051 bool empty = net["net_chain_classes"].is_null() || net["net_chain_classes"].empty();
1052
1053 net.erase( "net_chain_classes" );
1054
1055 if( !empty )
1056 {
1057 aReport.Add( DOWNGRADE_BUCKET::DROP, _( "Net chain classes" ), _( "Removed from the project file." ),
1058 1 );
1059 }
1060 }
1061
1062 if( preTen )
1063 {
1064 if( net.contains( "classes" ) && net["classes"].is_array() )
1065 {
1066 for( nlohmann::json& netclass : net["classes"] )
1067 {
1068 if( netclass.is_object() )
1069 {
1070 if( netclass.contains( "tuning_profile" ) && netclass["tuning_profile"].is_string()
1071 && !netclass["tuning_profile"].get_ref<const std::string&>().empty() )
1072 {
1073 tuningLoss = true;
1074 }
1075
1076 netclass.erase( "tuning_profile" );
1077 }
1078 }
1079 }
1080
1081 if( net.contains( "meta" ) && net["meta"].is_object() )
1082 net["meta"]["version"] = 4;
1083 }
1084 }
1085
1086 if( aDoc.contains( "tuning_profiles" ) )
1087 {
1088 if( preTen )
1089 {
1090 const nlohmann::json defaults = {
1091 { "tuning_profiles_impedance_geometric", nlohmann::json::array() },
1092 };
1093 tuningLoss |= hasConfiguredProjectSettings( aDoc["tuning_profiles"], defaults );
1094 aDoc.erase( "tuning_profiles" );
1095 }
1096 else
1097 {
1098 nlohmann::json& profiles = aDoc["tuning_profiles"];
1099
1100 if( profiles.contains( "tuning_profiles_impedance_geometric" )
1101 && profiles["tuning_profiles_impedance_geometric"].is_array() )
1102 {
1103 for( nlohmann::json& entry : profiles["tuning_profiles_impedance_geometric"] )
1104 {
1105 if( !entry.is_object() )
1106 continue;
1107
1108 if( entry.contains( "frequency" ) && entry["frequency"].is_number()
1109 && entry["frequency"].get<double>() != 1e9 )
1110 {
1111 aReport.Add( DOWNGRADE_BUCKET::DROP, _( "Tuning profile frequencies" ),
1112 _( "The target uses its default calculation frequency." ), 1 );
1113 }
1114
1115 if( entry.contains( "model_solder_mask" ) && entry["model_solder_mask"].is_boolean()
1116 && entry["model_solder_mask"].get<bool>() )
1117 {
1118 aReport.Add( DOWNGRADE_BUCKET::DROP, _( "Tuning profile solder mask modelling" ),
1119 _( "The target cannot include solder mask in the calculation." ), 1 );
1120 }
1121
1122 entry.erase( "frequency" );
1123 entry.erase( "model_solder_mask" );
1124
1125 if( entry.contains( "net_chain_bridge_prop_delay" )
1126 && entry["net_chain_bridge_prop_delay"].is_number()
1127 && entry["net_chain_bridge_prop_delay"].get<double>() != 0 )
1128 {
1129 aReport.Add( DOWNGRADE_BUCKET::DROP, _( "Net chain bridge propagation delay" ),
1130 _( "The target cannot model delay across net chain bridges." ), 1 );
1131 }
1132
1133 entry.erase( "net_chain_bridge_prop_delay" );
1134 }
1135 }
1136
1137 if( profiles.contains( "meta" ) && profiles["meta"].is_object() )
1138 profiles["meta"]["version"] = 0;
1139 }
1140 }
1141
1142 if( tuningLoss )
1143 {
1144 aReport.Add( DOWNGRADE_BUCKET::DROP, _( "Time-domain tuning profiles" ),
1145 _( "Removed saved profiles or netclass profile selections from the project file." ), 1 );
1146 }
1147
1148 if( preTen )
1149 {
1150 // Layer preset render layers are names. Older readers skip names they do not know.
1151 if( aDoc.contains( "component_class_settings" ) )
1152 {
1153 const nlohmann::json defaults = {
1154 { "assignments", nlohmann::json::array() },
1155 { "sheet_component_classes", { { "enabled", false } } },
1156 };
1157 bool configured = hasConfiguredProjectSettings( aDoc["component_class_settings"], defaults );
1158 aDoc.erase( "component_class_settings" );
1159
1160 if( configured )
1161 {
1162 aReport.Add( DOWNGRADE_BUCKET::DROP, _( "Component class assignment rules" ),
1163 _( "Removed from the project file." ), 1 );
1164 }
1165 }
1166
1167 if( aDoc.contains( "schematic" ) && aDoc["schematic"].is_object() )
1168 {
1169 // More than one top-level sheet blocks the schematic export before this runs.
1170 aDoc["schematic"].erase( "top_level_sheets" );
1171
1172 // The 9.0 schematic writer carries the aliases inside every sheet instead.
1173 aDoc["schematic"].erase( "bus_aliases" );
1174
1175 // The schematic export drops the variant registry, so the descriptions go too.
1176 aDoc["schematic"].erase( "variants" );
1177 }
1178 }
1179
1180 // Both released targets use project schema 3. Rewind after converting nested settings.
1181 if( aDoc.contains( "meta" ) && aDoc["meta"].is_object() )
1182 aDoc["meta"]["version"] = 3;
1183}
int index
const char * name
What an export to a given target will keep, approximate, drop, or block.
void Add(DOWNGRADE_BUCKET aBucket, const wxString &aFeature, const wxString &aDetail=wxEmptyString, int aCount=1)
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject, RESOLUTION_CONTEXT aContext)
Definition common.cpp:60
@ INTERNAL
Definition common.h:96
@ BLOCK
Cannot be represented at all, export to this target is not possible.
@ DROP
No equivalent, left out.
static bool empty(const wxTextEntryBase *aCtrl)
#define _(s)
void DowngradeProjectFileJson(nlohmann::json &aDoc, const DOWNGRADE_TARGET &aTarget, COMPATIBILITY_REPORT &aReport)
Migrate a .kicad_pro document down to what the target release expects.
static BOM_FMT_PRESET CSV()
An older KiCad release we can export a project back to.
int m_boardVersion
SEXPR_BOARD_FILE_VERSION for the target.
The settings schemas the project downgrade rules were written against.
std::string path
VECTOR2I end
wxString dump(const wxArrayString &aArray)
Debug helper for printing wxArrayString contents.