KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_differ.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
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU 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, you may find one here:
18 * http://www.gnu.org/licenses/gpl-3.0.html
19 */
20
21#include "pcb_differ.h"
22
25#include <hashtables.h>
26
27#include <board.h>
29#include <project.h>
32#include <netclass.h>
33#include <richio.h>
35
36#include <wx/file.h>
37#include <wx/filename.h>
39#include <board_item.h>
40#include <footprint.h>
41#include <pad.h>
42#include <pcb_track.h>
43#include <pcb_shape.h>
44#include <pcb_text.h>
45#include <pcb_field.h>
46#include <zone.h>
47#include <properties/property.h>
49
50#include <algorithm>
51#include <set>
52
53
54namespace KICAD_DIFF
55{
56
58{
59 if( const PCB_FIELD* field = dynamic_cast<const PCB_FIELD*>( &aItem ) )
60 {
61 if( const FOOTPRINT* fp = field->GetParentFootprint() )
62 return KIID::FromDeterministicString( fp->m_Uuid.AsString() + wxS( ":" ) + field->GetUntranslatedName() );
63 }
64
65 return aItem.m_Uuid;
66}
67
68
69BOARD_ITEM* FindPcbDiffItem( const BOARD* aBoard, const KIID& aId )
70{
71 if( !aBoard )
72 return nullptr;
73
74 // ResolveItem uses the board's UUID cache for top-level items and footprint children.
75 // Request nullptr on a miss instead of the DELETED_BOARD_ITEM sentinel so field diff
76 // IDs reach the name-based lookup below and missing items still return nullptr.
77 if( BOARD_ITEM* item = aBoard->ResolveItem( aId, /* aAllowNullptrReturn */ true ) )
78 return item;
79
80 for( FOOTPRINT* fp : aBoard->Footprints() )
81 {
82 for( PCB_FIELD* field : fp->GetFields() )
83 {
84 if( PcbDiffItemId( *field ) == aId )
85 return field;
86 }
87 }
88
89 return nullptr;
90}
91
92
93PCB_DIFFER::PCB_DIFFER( const BOARD* aBefore, const BOARD* aAfter, const wxString& aPath ) :
94 m_before( aBefore ),
95 m_after( aAfter ),
96 m_path( aPath )
97{
98}
99
100
101PCB_DIFFER::~PCB_DIFFER() = default;
102
103
104wxString PCB_DIFFER::itemTypeName( const BOARD_ITEM* aItem )
105{
106 if( !aItem )
107 return wxEmptyString;
108
109 if( const PCB_FIELD* field = dynamic_cast<const PCB_FIELD*>( aItem ) )
110 return field->GetName();
111
112 return aItem->GetClass();
113}
114
115
116wxString PCB_DIFFER::itemTypeLabel( const BOARD_ITEM* aItem )
117{
118 if( !aItem )
119 return wxEmptyString;
120
121 if( const PCB_FIELD* field = dynamic_cast<const PCB_FIELD*>( aItem ) )
122 return field->GetName();
123
124 return aItem->GetFriendlyName();
125}
126
127
128std::optional<wxString> PCB_DIFFER::itemRefdes( const BOARD_ITEM* aItem )
129{
130 if( auto fp = dynamic_cast<const FOOTPRINT*>( aItem ) )
131 return fp->GetReference();
132
133 if( auto track = dynamic_cast<const PCB_TRACK*>( aItem ) )
134 {
135 if( track->GetNetCode() > 0 && !track->GetNetname().IsEmpty() )
136 return track->GetNetname();
137 }
138
139 if( auto fp = dynamic_cast<const FOOTPRINT*>( aItem ? aItem->GetParent() : nullptr ) )
140 {
141 // Pad / footprint-child: borrow the parent's refdes for cross-probing.
142 return fp->GetReference();
143 }
144
145 return std::nullopt;
146}
147
148
150{
152 d.id = KIID_PATH();
153 d.id.push_back( aItem->m_Uuid );
154 d.type = itemTypeName( aItem );
155 d.position = aItem->GetPosition();
156 d.bbox = aItem->GetBoundingBox();
157
158 // keyProps for similarity fallback: identifying fields specific to the
159 // item type. Footprints carry their library id (very stable); tracks
160 // and pads carry net code.
161 if( auto fp = dynamic_cast<const FOOTPRINT*>( aItem ) )
162 {
163 d.keyProps.emplace_back( wxS( "lib_id" ), fp->GetFPIDAsString().ToStdString() );
164 d.keyProps.emplace_back( wxS( "reference" ), fp->GetReference().ToStdString() );
165 }
166 else if( auto track = dynamic_cast<const PCB_TRACK*>( aItem ) )
167 {
168 d.keyProps.emplace_back( wxS( "net" ), std::to_string( track->GetNetCode() ) );
169 d.keyProps.emplace_back( wxS( "layer" ), std::to_string( track->GetLayer() ) );
170 }
171 else if( auto pad = dynamic_cast<const PAD*>( aItem ) )
172 {
173 d.keyProps.emplace_back( wxS( "number" ), pad->GetNumber().ToStdString() );
174 d.keyProps.emplace_back( wxS( "net" ), std::to_string( pad->GetNetCode() ) );
175 }
176 else if( auto zone = dynamic_cast<const ZONE*>( aItem ) )
177 {
178 d.keyProps.emplace_back( wxS( "name" ), zone->GetZoneName().ToStdString() );
179 d.keyProps.emplace_back( wxS( "net" ), std::to_string( zone->GetNetCode() ) );
180 }
181
182 return d;
183}
184
185
186// Library metadata that is never worth showing, for any change kind.
187static bool pcbLibraryMetadataNoise( const wxString& aName )
188{
189 return aName == wxS( "Library Link" ) || aName == wxS( "Library Description" ) || aName == wxS( "Keywords" );
190}
191
192
193// Project-default propagation and library-reorganization noise. Inside a
194// footprint, per-child layout shifts follow the parent's move, so they are
195// noise too.
196static bool pcbDiffPropertyIsNoise( const wxString& aName, bool aInsideFootprint )
197{
198 const bool globalNoise = pcbLibraryMetadataNoise( aName ) || aName == wxS( "Auto Thickness" )
199 || aName == wxS( "Keep Upright" ) || aName == wxS( "Thickness" )
200 || aName == wxS( "Enable Teardrops" ) || aName == wxS( "Thermal Relief Spoke Angle" )
201 || aName == wxS( "Pin Name" ) || aName == wxS( "Net" ) || aName == wxS( "Pad Shape" );
202
203 if( globalNoise )
204 return true;
205
206 const bool childLayoutNoise = aName == wxS( "Position X" ) || aName == wxS( "Position Y" )
207 || aName == wxS( "Start X" ) || aName == wxS( "Start Y" ) || aName == wxS( "End X" )
208 || aName == wxS( "End Y" ) || aName == wxS( "Center X" ) || aName == wxS( "Center Y" )
209 || aName == wxS( "Orientation" ) || aName == wxS( "Height" )
210 || aName == wxS( "Width" ) || aName == wxS( "Layer" ) || aName == wxS( "Line Width" )
211 || aName == wxS( "Hole Size X" ) || aName == wxS( "Hole Size Y" );
212
213 return aInsideFootprint && childLayoutNoise;
214}
215
216
217// Full property list for an added or removed item. Only library metadata is
218// dropped: net, pad shape, geometry and the like describe what was added or
219// removed and are worth showing, unlike in the modified case.
220static std::vector<PROPERTY_DELTA> pcbAddedRemovedProperties( const BOARD_ITEM* aItem, bool aAsAfter )
221{
222 std::vector<PROPERTY_DELTA> deltas = ItemProperties( aItem, aAsAfter );
223
224 std::erase_if( deltas,
225 [&]( const PROPERTY_DELTA& d )
226 {
227 return pcbLibraryMetadataNoise( d.name );
228 } );
229
230 return deltas;
231}
232
233
234std::vector<PROPERTY_DELTA> PCB_DIFFER::diffProperties( const BOARD_ITEM* aBefore, const BOARD_ITEM* aAfter ) const
235{
236 auto deltas = DiffItemProperties( aBefore, aAfter );
237
238 const bool insideFootprint = aBefore && aBefore->GetParent() && aBefore->GetParent()->Type() == PCB_FOOTPRINT_T;
239
240 std::erase_if( deltas,
241 [&]( const PROPERTY_DELTA& d )
242 {
243 return pcbDiffPropertyIsNoise( d.name, insideFootprint );
244 } );
245
246 if( auto zoneA = dynamic_cast<const ZONE*>( aBefore ) )
247 {
248 if( auto zoneB = dynamic_cast<const ZONE*>( aAfter ) )
249 {
250 auto toPolygonSet = []( const SHAPE_POLY_SET* aPoly ) -> DIFF_VALUE::PolygonSet
251 {
253
254 if( !aPoly )
255 return out;
256
257 for( int o = 0; o < aPoly->OutlineCount(); ++o )
258 {
259 const auto& polyA = aPoly->CPolygon( o );
260 std::vector<std::vector<VECTOR2I>> contours;
261
262 for( const auto& contour : polyA )
263 {
264 std::vector<VECTOR2I> pts;
265 pts.reserve( contour.PointCount() );
266
267 for( int p = 0; p < contour.PointCount(); ++p )
268 pts.push_back( contour.CPoint( p ) );
269
270 contours.push_back( std::move( pts ) );
271 }
272
273 out.push_back( std::move( contours ) );
274 }
275
276 return out;
277 };
278
279 DIFF_VALUE::PolygonSet outlineA = toPolygonSet( zoneA->Outline() );
280 DIFF_VALUE::PolygonSet outlineB = toPolygonSet( zoneB->Outline() );
281
282 if( outlineA != outlineB )
283 {
285 d.name = wxS( "Outline" );
286 d.before = DIFF_VALUE::FromPolygonSet( std::move( outlineA ) );
287 d.after = DIFF_VALUE::FromPolygonSet( std::move( outlineB ) );
288 deltas.push_back( std::move( d ) );
289 }
290
291 for( PCB_LAYER_ID layer : zoneB->GetLayerSet().Seq() )
292 {
293 if( !zoneA->GetLayerSet().Contains( layer ) )
294 continue;
295
296 DIFF_VALUE::PolygonSet fillA = toPolygonSet( zoneA->GetFilledPolysList( layer ).get() );
297 DIFF_VALUE::PolygonSet fillB = toPolygonSet( zoneB->GetFilledPolysList( layer ).get() );
298
299 if( fillA == fillB )
300 continue;
301
303 d.name = wxString::Format( wxS( "Filled Area (%s)" ), LayerName( layer ) );
304 d.before = DIFF_VALUE::FromPolygonSet( std::move( fillA ) );
305 d.after = DIFF_VALUE::FromPolygonSet( std::move( fillB ) );
306 deltas.push_back( std::move( d ) );
307 }
308 }
309 }
310
311 return deltas;
312}
313
314
315std::vector<ITEM_CHANGE> PCB_DIFFER::diffFootprintChildren( const FOOTPRINT* aBefore, const FOOTPRINT* aAfter ) const
316{
317 std::vector<ITEM_CHANGE> children;
318
319 if( !aBefore || !aAfter )
320 return children;
321
322 // Keep the parent footprint in the path so consumers can group child changes
323 // and the merge applier can locate their destination footprint.
324 std::vector<ITEM_DESCRIPTOR> beforeDesc;
325 std::vector<ITEM_DESCRIPTOR> afterDesc;
326 std::map<KIID_PATH, const BOARD_ITEM*> beforeMap;
327 std::map<KIID_PATH, const BOARD_ITEM*> afterMap;
328
329 auto childDescriptor = [&]( const FOOTPRINT* aFp, const BOARD_ITEM* aChild ) -> ITEM_DESCRIPTOR
330 {
331 ITEM_DESCRIPTOR d = makeDescriptor( aChild );
332 d.id = KIID_PATH();
333 d.id.push_back( aFp->m_Uuid );
334 d.id.push_back( PcbDiffItemId( *aChild ) );
335
336 return d;
337 };
338
339 auto collect = [&]( const FOOTPRINT* aFp, std::vector<ITEM_DESCRIPTOR>& aOut,
340 std::map<KIID_PATH, const BOARD_ITEM*>& aMap )
341 {
342 for( const PAD* pad : aFp->Pads() )
343 {
344 ITEM_DESCRIPTOR d = childDescriptor( aFp, pad );
345 aOut.push_back( d );
346 aMap[d.id] = pad;
347 }
348
349 for( const BOARD_ITEM* item : aFp->GraphicalItems() )
350 {
351 ITEM_DESCRIPTOR d = childDescriptor( aFp, item );
352 aOut.push_back( d );
353 aMap[d.id] = item;
354 }
355
356 for( const ZONE* zone : aFp->Zones() )
357 {
358 ITEM_DESCRIPTOR d = childDescriptor( aFp, zone );
359 aOut.push_back( d );
360 aMap[d.id] = zone;
361 }
362
363 for( const PCB_FIELD* field : aFp->GetFields() )
364 {
365 ITEM_DESCRIPTOR d = childDescriptor( aFp, field );
366 aOut.push_back( d );
367 aMap[d.id] = field;
368 }
369 };
370
371 collect( aBefore, beforeDesc, beforeMap );
372 collect( aAfter, afterDesc, afterMap );
373
374 IDENTITY_RECONCILER reconciler( m_options.identity );
375 RECONCILIATION recon = reconciler.Reconcile( beforeDesc, afterDesc );
376
377 // Matched pairs: compute property deltas. Items count as "changed" if any
378 // property surfaced a delta OR if their semantic operator== rejects equality
379 // (which covers fields that aren't exposed through PROPERTY_MANAGER).
380 for( const auto& [idA, idB] : recon.aToB )
381 {
382 auto itA = beforeMap.find( idA );
383 auto itB = afterMap.find( idB );
384 const BOARD_ITEM* a = itA == beforeMap.end() ? nullptr : itA->second;
385 const BOARD_ITEM* b = itB == afterMap.end() ? nullptr : itB->second;
386
387 if( !a || !b )
388 continue;
389
390 std::vector<PROPERTY_DELTA> propDeltas;
391
392 if( m_options.deepCompare )
393 propDeltas = diffProperties( a, b );
394
395 if( propDeltas.empty() )
396 continue;
397
398 ITEM_CHANGE c;
399 c.id = idA;
400 c.typeName = itemTypeName( a );
401 c.typeLabel = itemTypeLabel( a );
403 c.bbox = b->GetBoundingBox();
404 c.refdes = itemRefdes( b );
405 c.properties = std::move( propDeltas );
406 children.push_back( std::move( c ) );
407 }
408
409 auto isLibraryUuidNoise = []( const BOARD_ITEM* aItem )
410 {
411 return aItem && ( aItem->Type() == PCB_SHAPE_T || aItem->Type() == PCB_TEXT_T );
412 };
413
414 for( const KIID_PATH& idA : recon.aOnly )
415 {
416 auto it = beforeMap.find( idA );
417
418 if( it == beforeMap.end() || !it->second )
419 continue;
420
421 const BOARD_ITEM* a = it->second;
422
423 if( isLibraryUuidNoise( a ) )
424 continue;
425
426 ITEM_CHANGE c;
427 c.id = idA;
428 c.typeName = itemTypeName( a );
429 c.typeLabel = itemTypeLabel( a );
431 c.bbox = a->GetBoundingBox();
432 c.refdes = itemRefdes( a );
433 c.properties = pcbAddedRemovedProperties( a, /*aAsAfter=*/false );
434 children.push_back( std::move( c ) );
435 }
436
437 for( const KIID_PATH& idB : recon.bOnly )
438 {
439 auto it = afterMap.find( idB );
440
441 if( it == afterMap.end() || !it->second )
442 continue;
443
444 const BOARD_ITEM* b = it->second;
445
446 if( isLibraryUuidNoise( b ) )
447 continue;
448
449 ITEM_CHANGE c;
450 c.id = idB;
451 c.typeName = itemTypeName( b );
452 c.typeLabel = itemTypeLabel( b );
454 c.bbox = b->GetBoundingBox();
455 c.refdes = itemRefdes( b );
456 c.properties = pcbAddedRemovedProperties( b, /*aAsAfter=*/true );
457 children.push_back( std::move( c ) );
458 }
459
460 sortChanges( children );
461 return children;
462}
463
464
465void PCB_DIFFER::sortChanges( std::vector<ITEM_CHANGE>& aChanges )
466{
467 std::sort( aChanges.begin(), aChanges.end(),
468 []( const ITEM_CHANGE& aL, const ITEM_CHANGE& aR )
469 {
470 if( aL.id < aR.id )
471 return true;
472 if( aR.id < aL.id )
473 return false;
474
475 if( aL.typeName != aR.typeName )
476 return aL.typeName < aR.typeName;
477
478 return static_cast<int>( aL.kind ) < static_cast<int>( aR.kind );
479 } );
480}
481
482
484{
486 result.path = m_path;
487 result.docType = wxS( "kicad_pcb" );
488
489 if( !m_before || !m_after )
490 return result;
491
492 // Build descriptors for the top-level item set.
493 const BOARD_ITEM_SET beforeSet = m_before->GetItemSet();
494 const BOARD_ITEM_SET afterSet = m_after->GetItemSet();
495
496 std::vector<ITEM_DESCRIPTOR> beforeDesc;
497 std::vector<ITEM_DESCRIPTOR> afterDesc;
498 std::map<KIID, const BOARD_ITEM*> beforeMap;
499 std::map<KIID, const BOARD_ITEM*> afterMap;
500
501 beforeDesc.reserve( beforeSet.size() );
502 afterDesc.reserve( afterSet.size() );
503
504 for( const BOARD_ITEM* item : beforeSet )
505 {
506 if( !item )
507 continue;
508
509 beforeDesc.push_back( makeDescriptor( item ) );
510 beforeMap[item->m_Uuid] = item;
511 }
512
513 for( const BOARD_ITEM* item : afterSet )
514 {
515 if( !item )
516 continue;
517
518 afterDesc.push_back( makeDescriptor( item ) );
519 afterMap[item->m_Uuid] = item;
520 }
521
522 if( m_options.progress )
523 m_options.progress( 0.2 );
524
525 IDENTITY_RECONCILER reconciler( m_options.identity );
526 RECONCILIATION recon = reconciler.Reconcile( beforeDesc, afterDesc );
527
528 if( m_options.progress )
529 m_options.progress( 0.5 );
530
531 // Duplicate-UUID records (within either side).
532 for( const KIID_PATH& dup : recon.duplicatesA )
533 {
534 ITEM_CHANGE c;
535 c.id = dup;
536 c.typeName = wxS( "BOARD_ITEM" );
537 c.typeLabel = _( "Item" );
539 result.changes.push_back( std::move( c ) );
540 }
541
542 for( const KIID_PATH& dup : recon.duplicatesB )
543 {
544 if( std::find_if( result.changes.begin(), result.changes.end(),
545 [&]( const ITEM_CHANGE& aC )
546 {
547 return aC.id == dup && aC.kind == CHANGE_KIND::DUPLICATE_UUID;
548 } )
549 != result.changes.end() )
550 {
551 continue;
552 }
553
554 ITEM_CHANGE c;
555 c.id = dup;
556 c.typeName = wxS( "BOARD_ITEM" );
557 c.typeLabel = _( "Item" );
559 result.changes.push_back( std::move( c ) );
560 }
561
562 // Matched pairs.
563 for( const auto& [idA, idB] : recon.aToB )
564 {
565 const KIID& uuidA = idA.back();
566 const KIID& uuidB = idB.back();
567 auto itA = beforeMap.find( uuidA );
568 auto itB = afterMap.find( uuidB );
569 const BOARD_ITEM* a = itA == beforeMap.end() ? nullptr : itA->second;
570 const BOARD_ITEM* b = itB == afterMap.end() ? nullptr : itB->second;
571
572 if( !a || !b )
573 continue;
574
575 std::vector<PROPERTY_DELTA> propDeltas;
576
577 if( m_options.deepCompare )
578 propDeltas = diffProperties( a, b );
579
580 // For footprints, also walk children. A footprint may compare unequal
581 // because a child changed, in which case the parent's properties
582 // themselves haven't moved — we still need to record children.
583 std::vector<ITEM_CHANGE> childChanges;
584
585 if( auto fpA = dynamic_cast<const FOOTPRINT*>( a ) )
586 {
587 if( auto fpB = dynamic_cast<const FOOTPRINT*>( b ) )
588 childChanges = diffFootprintChildren( fpA, fpB );
589 }
590
591 if( propDeltas.empty() && childChanges.empty() )
592 continue;
593
594 ITEM_CHANGE c;
595 c.id = idA;
596 c.typeName = itemTypeName( a );
597 c.typeLabel = itemTypeLabel( a );
599 c.bbox = b->GetBoundingBox();
600 c.refdes = itemRefdes( b );
601 c.properties = std::move( propDeltas );
602 c.children = std::move( childChanges );
603 result.changes.push_back( std::move( c ) );
604 }
605
606 // Auto-generated items (teardrops, etc.) flip in lockstep with a global
607 // setting rather than being user-authored. Their presence on one side and
608 // not the other is reported as the Enable Teardrops setting change, not
609 // as N separate add/remove records. Teardrops historically render as
610 // ZONEs flagged with IsTeardropArea, hence the second branch.
611 auto isAutoGenerated = []( const BOARD_ITEM* aItem )
612 {
613 if( !aItem )
614 return false;
615
616 if( aItem->Type() == PCB_GENERATOR_T )
617 return true;
618
619 if( auto zone = dynamic_cast<const ZONE*>( aItem ) )
620 return zone->IsTeardropArea();
621
622 return false;
623 };
624
625 // Items present only in ancestor: REMOVED.
626 for( const KIID_PATH& idA : recon.aOnly )
627 {
628 auto it = beforeMap.find( idA.back() );
629
630 if( it == beforeMap.end() || !it->second )
631 continue;
632
633 const BOARD_ITEM* a = it->second;
634
635 if( isAutoGenerated( a ) )
636 continue;
637
638 ITEM_CHANGE c;
639 c.id = idA;
640 c.typeName = itemTypeName( a );
641 c.typeLabel = itemTypeLabel( a );
643 c.bbox = a->GetBoundingBox();
644 c.refdes = itemRefdes( a );
645 c.properties = pcbAddedRemovedProperties( a, /*aAsAfter=*/false );
646
647 // For footprints, snapshot child items so the consumer can show what's
648 // being removed without re-walking.
649 if( auto fp = dynamic_cast<const FOOTPRINT*>( a ) )
650 {
651 std::vector<ITEM_CHANGE> dummyAfter;
652 FOOTPRINT empty( nullptr );
653 // diffFootprintChildren needs two footprints; producing an empty
654 // "after" gives us a REMOVED record per child.
656 }
657
658 result.changes.push_back( std::move( c ) );
659 }
660
661 // Items present only in after: ADDED.
662 for( const KIID_PATH& idB : recon.bOnly )
663 {
664 auto it = afterMap.find( idB.back() );
665
666 if( it == afterMap.end() || !it->second )
667 continue;
668
669 const BOARD_ITEM* b = it->second;
670
671 if( isAutoGenerated( b ) )
672 continue;
673
674 ITEM_CHANGE c;
675 c.id = idB;
676 c.typeName = itemTypeName( b );
677 c.typeLabel = itemTypeLabel( b );
679 c.bbox = b->GetBoundingBox();
680 c.refdes = itemRefdes( b );
681 c.properties = pcbAddedRemovedProperties( b, /*aAsAfter=*/true );
682
683 if( auto fp = dynamic_cast<const FOOTPRINT*>( b ) )
684 {
685 FOOTPRINT empty( nullptr );
687 }
688
689 result.changes.push_back( std::move( c ) );
690 }
691
692 // Document-level settings — board thickness, paper format. These aren't
693 // walked items so the per-item loop above can't catch a change to them;
694 // emit a single synthetic ITEM_CHANGE with an empty KIID_PATH so the
695 // merge engine can plan a resolution on it and the applier knows which
696 // side's settings to carry over. Without this the applier defaults to
697 // the new (empty) result BOARD's settings and silently reverts both
698 // sides' divergent changes to defaults.
699 std::vector<PROPERTY_DELTA> docDeltas;
700
701 AppendPaperDeltas( docDeltas, m_before->GetPageSettings(), m_after->GetPageSettings() );
702 AppendTitleBlockDeltas( docDeltas, m_before->GetTitleBlock(), m_after->GetTitleBlock() );
703
704 const BOARD_DESIGN_SETTINGS& beforeDS = m_before->GetDesignSettings();
705 const BOARD_DESIGN_SETTINGS& afterDS = m_after->GetDesignSettings();
706
707 const int beforeThickness = beforeDS.GetBoardThickness();
708 const int afterThickness = afterDS.GetBoardThickness();
709
710 if( beforeThickness != afterThickness )
711 {
714 d.before = DIFF_VALUE::FromInt( beforeThickness );
715 d.after = DIFF_VALUE::FromInt( afterThickness );
716 docDeltas.push_back( std::move( d ) );
717 }
718
719 auto summarizePlotOptions = []( const PCB_PLOT_PARAMS& aParams ) -> std::string
720 {
721 STRING_FORMATTER formatter;
722 aParams.Format( &formatter );
723 return wxString::Format( wxS( "hash %zx" ), std::hash<std::string>{}( formatter.GetString() ) )
724 .ToStdString();
725 };
726
727 const std::string beforePlot = summarizePlotOptions( m_before->GetPlotOptions() );
728 const std::string afterPlot = summarizePlotOptions( m_after->GetPlotOptions() );
729
730 if( beforePlot != afterPlot )
731 {
734 d.before = DIFF_VALUE::FromString( beforePlot );
735 d.after = DIFF_VALUE::FromString( afterPlot );
736 docDeltas.push_back( std::move( d ) );
737 }
738
739 if( m_before->LegacyTeardrops() != m_after->LegacyTeardrops() )
740 {
743 d.before = DIFF_VALUE::FromBool( m_before->LegacyTeardrops() );
744 d.after = DIFF_VALUE::FromBool( m_after->LegacyTeardrops() );
745 docDeltas.push_back( std::move( d ) );
746 }
747
748 // Board properties and variants get one property each, so edits to different entries merge cleanly
749 auto appendKeyedDeltas =
750 [&]( const wxString& aPrefix, const std::map<wxString, wxString>& aBefore,
751 const std::map<wxString, wxString>& aAfter )
752 {
753 std::set<wxString> names;
754
755 for( const auto& [name, value] : aBefore )
756 names.insert( name );
757
758 for( const auto& [name, value] : aAfter )
759 names.insert( name );
760
761 auto render = []( const std::map<wxString, wxString>& aMap, const wxString& aName )
762 {
763 auto it = aMap.find( aName );
764
765 if( it == aMap.end() )
766 return wxString( wxS( "(none)" ) );
767
768 return wxS( "\"" ) + it->second + wxS( "\"" );
769 };
770
771 for( const wxString& name : names )
772 {
773 const wxString before = render( aBefore, name );
774 const wxString after = render( aAfter, name );
775
776 if( before != after )
777 {
779 d.name = aPrefix + name;
780 d.before = DIFF_VALUE::FromString( before );
781 d.after = DIFF_VALUE::FromString( after );
782 docDeltas.push_back( std::move( d ) );
783 }
784 }
785 };
786
787 auto boardVariants = []( const BOARD* aBoard )
788 {
789 std::map<wxString, wxString> result;
790
791 for( const wxString& name : aBoard->GetVariantNames() )
792 result[name] = aBoard->GetVariantDescription( name );
793
794 return result;
795 };
796
797 appendKeyedDeltas( DOC_PROP_BOARD_PROPERTY, m_before->GetProperties(), m_after->GetProperties() );
798 appendKeyedDeltas( DOC_PROP_VARIANT, boardVariants( m_before ), boardVariants( m_after ) );
799
800 // Stackup is structural (layer count, dielectric materials, copper
801 // weights) so a per-field walk would explode the change list. Detect
802 // any change with BOARD_STACKUP::operator== and emit a single delta
803 // carrying a human-readable summary; the applier copies whole
804 // BOARD_DESIGN_SETTINGS so a TAKE_OURS / TAKE_THEIRS resolution preserves
805 // the chosen side's full stackup.
806 const BOARD_STACKUP& beforeStackup = beforeDS.GetStackupDescriptor();
807 const BOARD_STACKUP& afterStackup = afterDS.GetStackupDescriptor();
808
809 auto summarizeStackup = []( const BOARD_STACKUP& aStackup ) -> std::string
810 {
811 int copper = 0;
812 int dielectric = 0;
813
814 for( const BOARD_STACKUP_ITEM* item : aStackup.GetList() )
815 {
816 if( !item )
817 continue;
818
819 if( item->GetType() == BS_ITEM_TYPE_COPPER )
820 ++copper;
821 else if( item->GetType() == BS_ITEM_TYPE_DIELECTRIC )
822 ++dielectric;
823 }
824
825 // Content hash matching BOARD_STACKUP::operator== fields so
826 // before/after render differently when any compared field
827 // changed and the copper/dielectric counts didn't.
828 std::size_t h = std::hash<std::string>{}( aStackup.m_FinishType.ToStdString() );
829 h = KiHashCombine( h, std::hash<bool>{}( aStackup.m_HasDielectricConstrains ) );
830 h = KiHashCombine( h, std::hash<bool>{}( aStackup.m_HasThicknessConstrains ) );
831 h = KiHashCombine( h, std::hash<bool>{}( aStackup.m_EdgePlating ) );
832 h = KiHashCombine( h, std::hash<int>{}( static_cast<int>( aStackup.m_EdgeConnectorConstraints ) ) );
833
834 for( const BOARD_STACKUP_ITEM* item : aStackup.GetList() )
835 {
836 if( !item )
837 continue;
838
839 h = KiHashCombine( h, std::hash<int>{}( static_cast<int>( item->GetType() ) ) );
840 h = KiHashCombine( h, std::hash<int>{}( static_cast<int>( item->GetBrdLayerId() ) ) );
841 h = KiHashCombine( h, std::hash<std::string>{}( item->GetLayerName().ToStdString() ) );
842 h = KiHashCombine( h, std::hash<bool>{}( item->IsEnabled() ) );
843
844 for( int sub = 0; sub < item->GetSublayersCount(); ++sub )
845 {
846 h = KiHashCombine( h, std::hash<int>{}( item->GetThickness( sub ) ) );
847 h = KiHashCombine( h, std::hash<std::string>{}( item->GetMaterial( sub ).ToStdString() ) );
848 h = KiHashCombine( h, std::hash<std::string>{}( item->GetColor( sub ).ToStdString() ) );
849
850 if( item->HasEpsilonRValue() )
851 h = KiHashCombine( h, std::hash<double>{}( item->GetEpsilonR( sub ) ) );
852
853 if( item->HasLossTangentValue() )
854 h = KiHashCombine( h, std::hash<double>{}( item->GetLossTangent( sub ) ) );
855 }
856 }
857
858 return wxString::Format( wxS( "%d copper / %d dielectric layers (hash %zx)" ), copper, dielectric, h )
859 .ToStdString();
860 };
861
862 if( beforeStackup != afterStackup )
863 {
866 d.before = DIFF_VALUE::FromString( summarizeStackup( beforeStackup ) );
867 d.after = DIFF_VALUE::FromString( summarizeStackup( afterStackup ) );
868 docDeltas.push_back( std::move( d ) );
869 }
870
871 // DRC severity overrides live in the project file. Diff only fires when
872 // sibling .kicad_pro files were loaded — for plain .kicad_pcb temp blobs
873 // (git mergetool case) both sides see defaults and we never get here.
874 const std::map<int, SEVERITY>& beforeDRC = beforeDS.m_DRCSeverities;
875 const std::map<int, SEVERITY>& afterDRC = afterDS.m_DRCSeverities;
876
877 if( beforeDRC != afterDRC )
878 {
883 docDeltas.push_back( std::move( d ) );
884 }
885
886 // Net classes live in PROJECT_FILE via NET_SETTINGS. Both NET_SETTINGS
887 // instances are reached via BOARD_DESIGN_SETTINGS::m_NetSettings (a
888 // shared_ptr). After A1, NET_SETTINGS::operator== is content-aware
889 // (covers default-netclass in-place edits + per-named-class parameter
890 // edits + label / pattern / color / chain-class maps), so equality
891 // alone is enough to gate the delta. Render a count + content hash
892 // summary so two configurations with the same class count but
893 // different parameters produce distinct before / after strings.
894 auto summarizeNetSettings = []( const NET_SETTINGS& aSettings ) -> std::string
895 {
896 std::size_t h = 0;
897 auto hashCombine = [&h]( std::size_t v )
898 {
899 h = KiHashCombine( h, v );
900 };
901
902 auto hashNetclass = [&]( const NETCLASS* nc )
903 {
904 if( !nc )
905 return;
906
907 hashCombine( std::hash<std::string>{}( nc->GetName().ToStdString() ) );
908 hashCombine( static_cast<std::size_t>( nc->GetPriority() ) );
909 hashCombine( static_cast<std::size_t>( nc->GetClearanceOpt().value_or( -1 ) ) );
910 hashCombine( static_cast<std::size_t>( nc->GetTrackWidthOpt().value_or( -1 ) ) );
911 hashCombine( static_cast<std::size_t>( nc->GetViaDiameterOpt().value_or( -1 ) ) );
912 hashCombine( static_cast<std::size_t>( nc->GetViaDrillOpt().value_or( -1 ) ) );
913 hashCombine( static_cast<std::size_t>( nc->GetuViaDiameterOpt().value_or( -1 ) ) );
914 hashCombine( static_cast<std::size_t>( nc->GetuViaDrillOpt().value_or( -1 ) ) );
915 hashCombine( static_cast<std::size_t>( nc->GetDiffPairWidthOpt().value_or( -1 ) ) );
916 hashCombine( static_cast<std::size_t>( nc->GetDiffPairGapOpt().value_or( -1 ) ) );
917 hashCombine( static_cast<std::size_t>( nc->GetDiffPairViaGapOpt().value_or( -1 ) ) );
918 hashCombine( static_cast<std::size_t>( nc->GetWireWidthOpt().value_or( -1 ) ) );
919 hashCombine( static_cast<std::size_t>( nc->GetBusWidthOpt().value_or( -1 ) ) );
920 hashCombine( static_cast<std::size_t>( nc->GetLineStyleOpt().value_or( -1 ) ) );
921 hashCombine( std::hash<std::string>{}( nc->GetTuningProfile().ToStdString() ) );
922
923 // Per-netclass color overrides are part of NETCLASS::EqualsByPersistedFields;
924 // include them so a color-only edit produces a distinct rendered summary.
925 hashCombine( std::hash<std::string>{}( nc->GetSchematicColor( true ).ToCSSString().ToStdString() ) );
926 hashCombine( std::hash<std::string>{}( nc->GetPcbColor( true ).ToCSSString().ToStdString() ) );
927 };
928
929 hashNetclass( aSettings.GetDefaultNetclass().get() );
930
931 for( const auto& [name, nc] : aSettings.GetNetclasses() )
932 hashNetclass( nc.get() );
933
934 for( const auto& [netname, classes] : aSettings.GetNetclassLabelAssignments() )
935 {
936 hashCombine( std::hash<std::string>{}( netname.ToStdString() ) );
937
938 for( const wxString& c : classes )
939 hashCombine( std::hash<std::string>{}( c.ToStdString() ) );
940 }
941
942 for( const auto& [chain, className] : aSettings.GetNetChainClasses() )
943 {
944 hashCombine( std::hash<std::string>{}( chain.ToStdString() ) );
945 hashCombine( std::hash<std::string>{}( className.ToStdString() ) );
946 }
947
948 for( const auto& [chain, netclass] : aSettings.GetNetChainNetClasses() )
949 {
950 hashCombine( std::hash<std::string>{}( chain.ToStdString() ) );
951 hashCombine( std::hash<std::string>{}( netclass.ToStdString() ) );
952 }
953
954 for( const auto& [netname, color] : aSettings.GetNetColorAssignments() )
955 {
956 hashCombine( std::hash<std::string>{}( netname.ToStdString() ) );
957 hashCombine( std::hash<std::string>{}( color.ToCSSString().ToStdString() ) );
958 }
959
960 const std::size_t classCount = aSettings.GetNetclasses().size() + ( aSettings.GetDefaultNetclass() ? 1u : 0u );
961
962 return wxString::Format( wxS( "%zu netclass(es) (hash %zx)" ), classCount, h ).ToStdString();
963 };
964
965 const std::shared_ptr<NET_SETTINGS>& beforeNet = beforeDS.m_NetSettings;
966 const std::shared_ptr<NET_SETTINGS>& afterNet = afterDS.m_NetSettings;
967
968 // Diff fires only when both sides have NET_SETTINGS instances. A null
969 // pointer on either side means the BOARD wasn't loaded with a project file
970 // (e.g. plain .kicad_pcb temp blob from git mergetool); skip silently —
971 // matches DRC severities behaviour.
972 if( beforeNet && afterNet && *beforeNet != *afterNet )
973 {
976 d.before = DIFF_VALUE::FromString( summarizeNetSettings( *beforeNet ) );
977 d.after = DIFF_VALUE::FromString( summarizeNetSettings( *afterNet ) );
978 docDeltas.push_back( std::move( d ) );
979 }
980
981 // Custom DRC rules live in a sibling .kicad_dru file next to the .kicad_pcb.
982 // The file content isn't stored on BOARD; we read it from disk. For
983 // headless / temp-blob merges (git mergetool) the sibling file usually
984 // isn't present and both sides return empty strings, so no delta fires.
985 auto readSiblingDruContent = []( const BOARD* aBoard ) -> wxString
986 {
987 if( !aBoard )
988 return wxEmptyString;
989
990 wxString boardPath = aBoard->GetFileName();
991
992 if( boardPath.IsEmpty() )
993 return wxEmptyString;
994
995 wxFileName fn( boardPath );
997
998 if( !fn.FileExists() )
999 return wxEmptyString;
1000
1001 wxFile file( fn.GetFullPath() );
1002
1003 if( !file.IsOpened() )
1004 return wxEmptyString;
1005
1006 wxString contents;
1007 file.ReadAll( &contents );
1008 return contents;
1009 };
1010
1011 auto summarizeRules = []( const wxString& aContents ) -> std::string
1012 {
1013 if( aContents.IsEmpty() )
1014 return "(no custom rules)";
1015
1016 std::size_t h = std::hash<std::string>{}( aContents.ToStdString() );
1017 return wxString::Format( wxS( "%zu byte(s) (hash %zx)" ), aContents.size(), h ).ToStdString();
1018 };
1019
1020 const wxString beforeRules = readSiblingDruContent( m_before );
1021 const wxString afterRules = readSiblingDruContent( m_after );
1022
1023 if( beforeRules != afterRules )
1024 {
1027 d.before = DIFF_VALUE::FromString( summarizeRules( beforeRules ) );
1028 d.after = DIFF_VALUE::FromString( summarizeRules( afterRules ) );
1029 docDeltas.push_back( std::move( d ) );
1030 }
1031
1032 // Footprint library table (fp-lib-table) lives in the project directory
1033 // (no extension). Read content directly; the same content-comparison
1034 // pattern as custom DRC rules applies.
1035 auto readProjectFileNamed = []( const BOARD* aBoard, const std::string& aFileName ) -> wxString
1036 {
1037 if( !aBoard )
1038 return wxEmptyString;
1039
1040 wxString boardPath = aBoard->GetFileName();
1041
1042 if( boardPath.IsEmpty() )
1043 return wxEmptyString;
1044
1045 wxFileName fn( boardPath );
1046 fn.SetFullName( wxString::FromUTF8( aFileName ) );
1047
1048 if( !fn.FileExists() )
1049 return wxEmptyString;
1050
1051 wxFile file( fn.GetFullPath() );
1052
1053 if( !file.IsOpened() )
1054 return wxEmptyString;
1055
1056 wxString contents;
1057 file.ReadAll( &contents );
1058 return contents;
1059 };
1060
1061 auto summarizeTable = []( const wxString& aContents, const wxString& aLabel ) -> std::string
1062 {
1063 if( aContents.IsEmpty() )
1064 return wxString::Format( wxS( "(no %s)" ), aLabel ).ToStdString();
1065
1066 std::size_t h = std::hash<std::string>{}( aContents.ToStdString() );
1067 return wxString::Format( wxS( "%zu byte(s) (hash %zx)" ), aContents.size(), h ).ToStdString();
1068 };
1069
1070 const wxString beforeFp = readProjectFileNamed( m_before, FILEEXT::FootprintLibraryTableFileName );
1071 const wxString afterFp = readProjectFileNamed( m_after, FILEEXT::FootprintLibraryTableFileName );
1072
1073 if( beforeFp != afterFp )
1074 {
1077 d.before = DIFF_VALUE::FromString( summarizeTable( beforeFp, wxS( "fp-lib-table" ) ) );
1078 d.after = DIFF_VALUE::FromString( summarizeTable( afterFp, wxS( "fp-lib-table" ) ) );
1079 docDeltas.push_back( std::move( d ) );
1080 }
1081
1082 const wxString beforeSym = readProjectFileNamed( m_before, FILEEXT::SymbolLibraryTableFileName );
1083 const wxString afterSym = readProjectFileNamed( m_after, FILEEXT::SymbolLibraryTableFileName );
1084
1085 if( beforeSym != afterSym )
1086 {
1089 d.before = DIFF_VALUE::FromString( summarizeTable( beforeSym, wxS( "sym-lib-table" ) ) );
1090 d.after = DIFF_VALUE::FromString( summarizeTable( afterSym, wxS( "sym-lib-table" ) ) );
1091 docDeltas.push_back( std::move( d ) );
1092 }
1093
1094 // Drawing sheet file path lives in PROJECT_FILE::m_BoardDrawingSheetFile.
1095 // Resolved to absolute on load; for diff purposes the stored path is
1096 // what serializes back, so compare those strings directly.
1097 auto boardDrawingSheet = []( const BOARD* aBoard ) -> wxString
1098 {
1099 if( !aBoard || !aBoard->GetProject() )
1100 return wxEmptyString;
1101
1103 };
1104
1105 const wxString beforeSheet = boardDrawingSheet( m_before );
1106 const wxString afterSheet = boardDrawingSheet( m_after );
1107
1108 if( beforeSheet != afterSheet )
1109 {
1112 d.before = DIFF_VALUE::FromString( beforeSheet );
1113 d.after = DIFF_VALUE::FromString( afterSheet );
1114 docDeltas.push_back( std::move( d ) );
1115 }
1116
1117 // One property per embedded file, so files added on different sides merge cleanly
1118 const EMBEDDED_FILES* beforeFiles = m_before->GetEmbeddedFiles();
1119 const EMBEDDED_FILES* afterFiles = m_after->GetEmbeddedFiles();
1120 std::set<wxString> fileNames;
1121
1122 for( const auto& [name, file] : beforeFiles->EmbeddedFileMap() )
1123 fileNames.insert( name );
1124
1125 for( const auto& [name, file] : afterFiles->EmbeddedFileMap() )
1126 fileNames.insert( name );
1127
1128 auto fileHash = []( const EMBEDDED_FILES::EMBEDDED_FILE* aFile ) -> wxString
1129 {
1130 return aFile ? wxString::FromUTF8( aFile->data_hash ) : wxString( wxS( "(none)" ) );
1131 };
1132
1133 for( const wxString& name : fileNames )
1134 {
1135 const wxString beforeHash = fileHash( beforeFiles->GetEmbeddedFile( name ) );
1136 const wxString afterHash = fileHash( afterFiles->GetEmbeddedFile( name ) );
1137
1138 if( beforeHash != afterHash )
1139 {
1142 d.before = DIFF_VALUE::FromString( beforeHash );
1143 d.after = DIFF_VALUE::FromString( afterHash );
1144 docDeltas.push_back( std::move( d ) );
1145 }
1146 }
1147
1148 if( beforeFiles->GetAreFontsEmbedded() != afterFiles->GetAreFontsEmbedded() )
1149 {
1152 d.before = DIFF_VALUE::FromBool( beforeFiles->GetAreFontsEmbedded() );
1153 d.after = DIFF_VALUE::FromBool( afterFiles->GetAreFontsEmbedded() );
1154 docDeltas.push_back( std::move( d ) );
1155 }
1156
1157 if( !docDeltas.empty() )
1158 {
1159 ITEM_CHANGE c;
1160 c.id = KIID_PATH(); // empty path = document-scope sentinel
1161 c.typeName = wxS( "BOARD" );
1162 c.typeLabel = _( "Board" );
1164 c.bbox = BOX2I(); // document-scoped, no spatial location
1165 c.properties = std::move( docDeltas );
1166 result.changes.push_back( std::move( c ) );
1167 }
1168
1169 sortChanges( result.changes );
1170
1171 if( m_options.progress )
1172 m_options.progress( 1.0 );
1173
1174 return result;
1175}
1176
1177} // namespace KICAD_DIFF
const char * name
std::set< BOARD_ITEM *, CompareByUuid > BOARD_ITEM_SET
Set of BOARD_ITEMs ordered by UUID.
Definition board.h:395
static void hashCombine(std::size_t &aSeed, std::size_t aValue)
@ BS_ITEM_TYPE_COPPER
@ BS_ITEM_TYPE_DIELECTRIC
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
Container for design settings for a BOARD object.
std::shared_ptr< NET_SETTINGS > m_NetSettings
std::map< int, SEVERITY > m_DRCSeverities
int GetBoardThickness() const
The full thickness of the board including copper and masks.
BOARD_STACKUP & GetStackupDescriptor()
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
BOARD_ITEM_CONTAINER * GetParent() const
Definition board_item.h:281
Manage one layer needed to make a physical board.
Manage layers needed to make a physical board.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
const FOOTPRINTS & Footprints() const
Definition board.h:465
const wxString & GetFileName() const
Definition board.h:454
PROJECT * GetProject() const
Definition board.h:774
BOARD_ITEM * ResolveItem(const KIID &aID, bool aAllowNullptrReturn=false) const
Definition board.cpp:2176
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
virtual VECTOR2I GetPosition() const
Definition eda_item.h:348
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition eda_item.cpp:280
const KIID m_Uuid
Definition eda_item.h:599
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
virtual wxString GetFriendlyName() const
Definition eda_item.cpp:575
EMBEDDED_FILE * GetEmbeddedFile(const wxString &aName) const
Returns the embedded file with the given name or nullptr if it does not exist.
const std::map< wxString, std::shared_ptr< EMBEDDED_FILE > > & EmbeddedFileMap() const
Provide an iterable view of the file collection.
bool GetAreFontsEmbedded() const
ZONES & Zones()
Definition footprint.h:361
std::deque< PAD * > & Pads()
Definition footprint.h:355
void GetFields(std::vector< PCB_FIELD * > &aVector, bool aVisibleOnly) const
Populate a std::vector with PCB_TEXTs.
DRAWINGS & GraphicalItems()
Definition footprint.h:358
static DIFF_VALUE FromInt(int aValue)
static DIFF_VALUE FromBool(bool aValue)
static DIFF_VALUE FromString(const wxString &aValue)
std::vector< std::vector< std::vector< VECTOR2I > > > PolygonSet
static DIFF_VALUE FromPolygonSet(PolygonSet aValue)
Reconciles item identity across two snapshots of the same document.
RECONCILIATION Reconcile(const std::vector< ITEM_DESCRIPTOR > &aA, const std::vector< ITEM_DESCRIPTOR > &aB) const
const BOARD * m_after
Definition pcb_differ.h:100
static void sortChanges(std::vector< ITEM_CHANGE > &aChanges)
Stable, deterministic sort of ITEM_CHANGEs (by id, then typeName, then kind).
const BOARD * m_before
Definition pcb_differ.h:99
PCB_DIFFER(const BOARD *aBefore, const BOARD *aAfter, const wxString &aPath=wxEmptyString)
std::vector< ITEM_CHANGE > diffFootprintChildren(const FOOTPRINT *aBefore, const FOOTPRINT *aAfter) const
Construct a child-level diff for nested items inside a footprint pair.
DOCUMENT_DIFF Diff() override
Produce a DOCUMENT_DIFF of the inputs the concrete differ was constructed with.
static wxString itemTypeLabel(const BOARD_ITEM *aItem)
Translated type name shown to the user.
static std::optional< wxString > itemRefdes(const BOARD_ITEM *aItem)
Extract a presentation label: footprint refdes, or routing net name for tracks/vias.
std::vector< PROPERTY_DELTA > diffProperties(const BOARD_ITEM *aBefore, const BOARD_ITEM *aAfter) const
Compute property deltas between two items of the same dynamic type.
static wxString itemTypeName(const BOARD_ITEM *aItem)
Convert the dynamic class string for an item into the type name used in diffs.
ITEM_DESCRIPTOR makeDescriptor(const BOARD_ITEM *aItem) const
Build the ITEM_DESCRIPTOR for the reconciler from a BOARD_ITEM.
virtual wxString GetClass() const =0
Return the class name.
Definition kiid.h:46
static KIID FromDeterministicString(const wxString &aName)
Build a deterministic UUID from an arbitrary name string.
Definition kiid.cpp:325
A collection of nets and the parameters used to route or test these nets.
Definition netclass.h:44
NET_SETTINGS stores various net-related settings in a project context.
Definition pad.h:61
Parameters and options when plotting/printing a board.
wxString m_BoardDrawingSheetFile
PcbNew params.
virtual PROJECT_FILE & GetProjectFile() const
Definition project.h:201
Represent a set of closed polygons.
Implement an OUTPUTFORMATTER to a memory buffer.
Definition richio.h:430
const std::string & GetString()
Definition richio.h:453
Handle a list of polygons defining a copper zone.
Definition zone.h:70
static bool empty(const wxTextEntryBase *aCtrl)
static std::string ToStdString(const wxString &aStr)
#define _(s)
static const std::string SymbolLibraryTableFileName
static const std::string FootprintLibraryTableFileName
static const std::string DesignRulesFileExtension
std::size_t KiHashCombine(std::size_t aSeed, std::size_t aValue)
Fold aValue into the running hash aSeed using the well-known Boost hash_combine mixing step.
Definition hashtables.h:42
wxString LayerName(int aLayer)
Returns the default display name for a given layer.
Definition layer_id.cpp:31
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
const wxString DOC_PROP_SYM_LIB_TABLE
const wxString DOC_PROP_VARIANT
const wxString DOC_PROP_BOARD_THICKNESS
std::vector< PROPERTY_DELTA > DiffItemProperties(const INSPECTABLE *aBefore, const INSPECTABLE *aAfter)
Enumerate the property deltas between two items of the same dynamic type.
const wxString DOC_PROP_PLOT_OPTIONS
Board-level settings stored in the board file.
const wxString DOC_PROP_NET_CLASSES
std::string SummarizeSeverities(const SeverityMap &aMap)
Format a severity-override map (DRC or ERC, keyed by error code, value is a SEVERITY enum) as a short...
std::vector< PROPERTY_DELTA > ItemProperties(const INSPECTABLE *aItem, bool aAsAfter)
List one item's properties as one-sided deltas for an added or removed item.
void AppendTitleBlockDeltas(std::vector< PROPERTY_DELTA > &aDeltas, const TITLE_BLOCK &aBefore, const TITLE_BLOCK &aAfter)
Append a delta for every title block field that differs between the two documents,...
static bool pcbDiffPropertyIsNoise(const wxString &aName, bool aInsideFootprint)
const wxString DOC_PROP_CUSTOM_RULES
const wxString DOC_PROP_LEGACY_TEARDROPS
const wxString DOC_PROP_FP_LIB_TABLE
void AppendPaperDeltas(std::vector< PROPERTY_DELTA > &aDeltas, const PAGE_INFO &aBefore, const PAGE_INFO &aAfter)
Append DOC_PROP_PAGE_FORMAT and/or DOC_PROP_PAGE_ORIENTATION deltas to aDeltas when the two PAGE_INFO...
const wxString DOC_PROP_EMBED_FONTS
BOARD_ITEM * FindPcbDiffItem(const BOARD *aBoard, const KIID &aId)
Resolve an actual UUID or a footprint field's diff ID on a board.
const wxString DOC_PROP_LAYER_STACKUP
const wxString DOC_PROP_DRAWING_SHEET
static std::vector< PROPERTY_DELTA > pcbAddedRemovedProperties(const BOARD_ITEM *aItem, bool aAsAfter)
const wxString DOC_PROP_DRC_SEVERITIES
KIID PcbDiffItemId(const EDA_ITEM &aItem)
Fields match by parent footprint and untranslated name, including after a library refresh.
const wxString DOC_PROP_EMBEDDED_FILE
Prefix of the property for one embedded file, followed by the file name.
static bool pcbLibraryMetadataNoise(const wxString &aName)
const wxString DOC_PROP_BOARD_PROPERTY
Prefixes of the property for one board property or variant, followed by its name.
The full set of changes between two parsed documents of one type.
One change record on a single item.
std::vector< PROPERTY_DELTA > properties
std::optional< wxString > refdes
std::vector< ITEM_CHANGE > children
Descriptor used by the identity reconciler to compare items across two documents.
std::vector< std::pair< wxString, std::string > > keyProps
Single (name, before, after) triple for one mutated property on an item.
Maps every item in document A to either a peer in document B or to "only-in-A", and vice versa.
std::set< KIID_PATH > aOnly
std::vector< KIID_PATH > duplicatesA
std::map< KIID_PATH, KIID_PATH > aToB
std::vector< KIID_PATH > duplicatesB
std::set< KIID_PATH > bOnly
const SHAPE_LINE_CHAIN chain
static wxString render(const std::vector< TEXT_DIFF_LINE > &aLines)
wxString result
Test unit parsing edge cases and error handling.
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:80
@ PCB_GENERATOR_T
class PCB_GENERATOR, generator on a layer
Definition typeinfo.h:83
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition typeinfo.h:84
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition typeinfo.h:78
Definition of file extensions used in Kicad.