KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_sym_lib_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 * or you may search the http://www.gnu.org website for the version 3 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
26
31
32#include <lib_symbol.h>
33#include <sch_item.h>
34#include <sch_pin.h>
35#include <sch_shape.h>
36
37#include <json_common.h>
38
39#include <wx/filename.h>
40
41#include <functional>
42#include <set>
43
44
45using namespace KICAD_DIFF;
46
47
48BOOST_AUTO_TEST_SUITE( SymLibDiffer )
49
50
51static wxString getFixturePath()
52{
53 // qa/data/eeschema/.. -> qa/data/libraries/Device.kicad_sym
54 wxFileName fn( KI_TEST::GetEeschemaTestDataDir(), wxEmptyString );
55 fn.RemoveLastDir();
56 fn.AppendDir( wxS( "libraries" ) );
57 fn.SetFullName( wxS( "Device.kicad_sym" ) );
58 return fn.GetFullPath();
59}
60
61
62BOOST_AUTO_TEST_CASE( IdenticalLibrariesDiffEmpty )
63{
64 auto [ownersA, mapA] = SYM_LIB_DIFFER::LoadLibrary( getFixturePath() );
65 auto [ownersB, mapB] = SYM_LIB_DIFFER::LoadLibrary( getFixturePath() );
66
67 BOOST_REQUIRE( !mapA.empty() );
68
69 SYM_LIB_DIFFER differ( mapA, mapB, wxS( "Device.kicad_sym" ) );
70 DOCUMENT_DIFF result = differ.Diff();
71
72 BOOST_CHECK( result.Empty() );
73 BOOST_CHECK_EQUAL( result.docType.ToStdString(), "kicad_sym" );
74}
75
76
77BOOST_AUTO_TEST_CASE( SymbolNameOnlyInBeforeShowsRemoved )
78{
79 auto [ownersA, mapA] = SYM_LIB_DIFFER::LoadLibrary( getFixturePath() );
80 auto [ownersB, mapB] = SYM_LIB_DIFFER::LoadLibrary( getFixturePath() );
81
82 // Drop one symbol from after to simulate removal.
83 BOOST_REQUIRE( !mapB.empty() );
84 wxString victimName = mapB.begin()->first;
85 mapB.erase( mapB.begin() );
86
87 SYM_LIB_DIFFER differ( mapA, mapB );
88 DOCUMENT_DIFF result = differ.Diff();
89
90 BOOST_REQUIRE_EQUAL( result.changes.size(), 1u );
91 BOOST_CHECK( result.changes[0].kind == CHANGE_KIND::REMOVED );
92 BOOST_CHECK_EQUAL( result.changes[0].typeName.ToStdString(), "LIB_SYMBOL" );
93 // Identity for library symbols is name-derived; the KIID_PATH carries a
94 // synthetic KIID hash of the name rather than a registered UUID. We
95 // only assert the change exists, not the exact id encoding.
96 (void) victimName;
97}
98
99
100BOOST_AUTO_TEST_CASE( SymbolChangesCarryDrawableBBoxes )
101{
102 auto [ownersA, mapA] = SYM_LIB_DIFFER::LoadLibrary( getFixturePath() );
103 auto [ownersB, mapB] = SYM_LIB_DIFFER::LoadLibrary( getFixturePath() );
104
105 BOOST_REQUIRE( !ownersB.empty() );
106 LIB_SYMBOL* subject = ownersB.front().get();
107 BOOST_REQUIRE( !subject->GetDrawItems().empty() );
108
109 SCH_ITEM& firstItem = *subject->GetDrawItems().begin();
110 firstItem.Move( VECTOR2I( 1000, 0 ) );
111
112 SYM_LIB_DIFFER differ( mapA, mapB );
113 DOCUMENT_DIFF result = differ.Diff();
114
115 BOOST_REQUIRE_EQUAL( result.changes.size(), 1u );
116 BOOST_CHECK( result.changes[0].kind == CHANGE_KIND::MODIFIED );
117 BOOST_CHECK_GT( result.changes[0].bbox.GetWidth(), 0 );
118 BOOST_CHECK_GT( result.changes[0].bbox.GetHeight(), 0 );
119}
120
121
122BOOST_AUTO_TEST_CASE( ExtractSymbolGeometryProducesDrawableContext )
123{
124 auto [owners, map] = SYM_LIB_DIFFER::LoadLibrary( getFixturePath() );
125
126 BOOST_REQUIRE( !owners.empty() );
127
128 DOCUMENT_GEOMETRY geometry = ExtractSymbolGeometry( *owners.front(), KIGFX::COLOR4D( 0.38, 0.38, 0.38, 0.55 ) );
129
130 BOOST_CHECK( !geometry.Empty() );
131 BOOST_CHECK( BBoxFromGeometry( geometry ).has_value() );
132}
133
134
135BOOST_AUTO_TEST_CASE( DiffJsonRoundTrip )
136{
137 auto [ownersA, mapA] = SYM_LIB_DIFFER::LoadLibrary( getFixturePath() );
138 auto [ownersB, mapB] = SYM_LIB_DIFFER::LoadLibrary( getFixturePath() );
139
140 if( !mapB.empty() )
141 mapB.erase( mapB.begin() );
142
143 SYM_LIB_DIFFER differ( mapA, mapB, wxS( "lib.kicad_sym" ) );
144 DOCUMENT_DIFF result = differ.Diff();
145
146 nlohmann::json j = result.ToJson();
148 BOOST_CHECK_EQUAL( back.changes.size(), result.changes.size() );
149 BOOST_CHECK_EQUAL( back.docType.ToStdString(), "kicad_sym" );
150}
151
152
153// Library item KIID_PATH must be deterministic across calls -- LibraryItemKiidPath
154// is a hash-based synthetic UUID, and a regression that swaps the hash
155// algorithm would silently desync differ <-> applier KIID matching.
156BOOST_AUTO_TEST_CASE( LibraryItemKiidPathIsDeterministicForSameName )
157{
158 KIID_PATH a = LibraryItemKiidPath( wxS( "Device:R" ) );
159 KIID_PATH b = LibraryItemKiidPath( wxS( "Device:R" ) );
160
161 BOOST_REQUIRE_EQUAL( a.size(), 1u );
162 BOOST_REQUIRE_EQUAL( b.size(), 1u );
163 BOOST_CHECK( a == b );
164}
165
166
167BOOST_AUTO_TEST_CASE( LibraryItemKiidPathDiffersForDifferentNames )
168{
169 KIID_PATH a = LibraryItemKiidPath( wxS( "Device:R" ) );
170 KIID_PATH b = LibraryItemKiidPath( wxS( "Device:C" ) );
171
172 BOOST_CHECK( !( a == b ) );
173}
174
175
176// Multi-symbol library: every symbol must surface as its own change record
177// when removed. Currently the smoke test removes one symbol; here we
178// remove three and verify all three changes are emitted.
179BOOST_AUTO_TEST_CASE( MultipleSymbolRemovalsAllEmitChanges )
180{
181 auto [ownersA, mapA] = SYM_LIB_DIFFER::LoadLibrary( getFixturePath() );
182 auto [ownersB, mapB] = SYM_LIB_DIFFER::LoadLibrary( getFixturePath() );
183
184 BOOST_REQUIRE_GE( mapB.size(), 3u );
185
186 std::vector<wxString> victims;
187
188 for( int i = 0; i < 3 && !mapB.empty(); ++i )
189 {
190 victims.push_back( mapB.begin()->first );
191 mapB.erase( mapB.begin() );
192 }
193
194 SYM_LIB_DIFFER differ( mapA, mapB );
195 DOCUMENT_DIFF result = differ.Diff();
196
197 BOOST_CHECK_EQUAL( result.changes.size(), victims.size() );
198
199 for( const ITEM_CHANGE& c : result.changes )
200 {
202 BOOST_CHECK_EQUAL( c.typeName.ToStdString(), "LIB_SYMBOL" );
203 }
204}
205
206
207// Output ordering must be deterministic for the same input pair so JSON
208// diffs are byte-stable across runs.
209BOOST_AUTO_TEST_CASE( OutputOrderingIsDeterministicAcrossRuns )
210{
211 auto [ownersA1, mapA1] = SYM_LIB_DIFFER::LoadLibrary( getFixturePath() );
212 auto [ownersB1, mapB1] = SYM_LIB_DIFFER::LoadLibrary( getFixturePath() );
213 auto [ownersA2, mapA2] = SYM_LIB_DIFFER::LoadLibrary( getFixturePath() );
214 auto [ownersB2, mapB2] = SYM_LIB_DIFFER::LoadLibrary( getFixturePath() );
215
216 BOOST_REQUIRE_GE( mapB1.size(), 2u );
217
218 // Same mutation on both run pairs.
219 mapB1.erase( mapB1.begin() );
220 mapB2.erase( mapB2.begin() );
221
222 SYM_LIB_DIFFER differ1( mapA1, mapB1 );
223 SYM_LIB_DIFFER differ2( mapA2, mapB2 );
224
225 DOCUMENT_DIFF r1 = differ1.Diff();
226 DOCUMENT_DIFF r2 = differ2.Diff();
227
228 BOOST_CHECK_EQUAL( r1.ToJson().dump(), r2.ToJson().dump() );
229}
230
231
232BOOST_AUTO_TEST_CASE( ModifiedSymbolCarriesPinChildDelta )
233{
234 auto [ownersA, mapA] = SYM_LIB_DIFFER::LoadLibrary( getFixturePath() );
235 auto [ownersB, mapB] = SYM_LIB_DIFFER::LoadLibrary( getFixturePath() );
236
237 LIB_SYMBOL* victim = nullptr;
238
239 for( const std::unique_ptr<LIB_SYMBOL>& owner : ownersB )
240 {
241 if( owner && !owner->IsDerived() && !owner->GetGraphicalPins( ALL_UNITS, ALL_BODY_STYLES ).empty() )
242 {
243 victim = owner.get();
244 break;
245 }
246 }
247
248 BOOST_REQUIRE( victim );
249
250 victim->GetGraphicalPins( ALL_UNITS, ALL_BODY_STYLES ).front()->Move( VECTOR2I( 1270, 0 ) );
251
252 SYM_LIB_DIFFER differ( mapA, mapB );
253 DOCUMENT_DIFF result = differ.Diff();
254
255 const ITEM_CHANGE* change = nullptr;
256
257 for( const ITEM_CHANGE& c : result.changes )
258 {
259 if( c.kind == CHANGE_KIND::MODIFIED && c.refdes && *c.refdes == victim->GetName() )
260 {
261 change = &c;
262 break;
263 }
264 }
265
266 BOOST_REQUIRE( change );
267
268 bool foundPinChild = false;
269
270 for( const ITEM_CHANGE& child : change->children )
271 {
272 if( child.typeName == wxS( "Pin" ) && !child.properties.empty() )
273 foundPinChild = true;
274 }
275
276 BOOST_CHECK( foundPinChild );
277}
278
279
280// Symbol compare ignores unit and body style names, so only the deltas show a rename
281BOOST_AUTO_TEST_CASE( UnitAndBodyStyleNamesAreDetected )
282{
283 auto [ownersA, mapA] = SYM_LIB_DIFFER::LoadLibrary( getFixturePath() );
284 auto [ownersB, mapB] = SYM_LIB_DIFFER::LoadLibrary( getFixturePath() );
285
286 auto victim = std::ranges::find_if( ownersB,
287 []( const std::unique_ptr<LIB_SYMBOL>& aOwner )
288 {
289 return aOwner && !aOwner->IsDerived();
290 } );
291
292 BOOST_REQUIRE( victim != ownersB.end() );
293
294 ( *victim )->GetUnitDisplayNames()[1] = wxS( "QA_Unit" );
295 ( *victim )->SetBodyStyleNames( { wxS( "QA_Normal" ), wxS( "QA_Alternate" ) } );
296
297 std::set<wxString> names;
298
299 for( const ITEM_CHANGE& change : SYM_LIB_DIFFER( mapA, mapB ).Diff().changes )
300 {
301 for( const PROPERTY_DELTA& delta : change.properties )
302 names.insert( delta.name );
303 }
304
305 BOOST_CHECK( names.contains( wxS( "Unit Names" ) ) );
306 BOOST_CHECK( names.contains( wxS( "Body Style Names" ) ) );
307}
308
309
310BOOST_AUTO_TEST_CASE( PinNameChangeIsDetected )
311{
312 auto [ownersA, mapA] = SYM_LIB_DIFFER::LoadLibrary( getFixturePath() );
313 auto [ownersB, mapB] = SYM_LIB_DIFFER::LoadLibrary( getFixturePath() );
314
315 LIB_SYMBOL* victim = nullptr;
316
317 for( const std::unique_ptr<LIB_SYMBOL>& owner : ownersB )
318 {
319 if( owner && !owner->IsDerived() && !owner->GetGraphicalPins( ALL_UNITS, ALL_BODY_STYLES ).empty() )
320 {
321 victim = owner.get();
322 break;
323 }
324 }
325
326 BOOST_REQUIRE( victim );
327
328 victim->GetGraphicalPins( ALL_UNITS, ALL_BODY_STYLES ).front()->SetName( wxS( "QA_RENAMED_PIN" ) );
329
330 SYM_LIB_DIFFER differ( mapA, mapB );
331 DOCUMENT_DIFF result = differ.Diff();
332
333 const ITEM_CHANGE* change = nullptr;
334
335 for( const ITEM_CHANGE& c : result.changes )
336 {
337 if( c.kind == CHANGE_KIND::MODIFIED && c.refdes && *c.refdes == victim->GetName() )
338 {
339 change = &c;
340 break;
341 }
342 }
343
344 BOOST_REQUIRE( change );
345
346 bool foundPinDelta = false;
347
348 for( const ITEM_CHANGE& child : change->children )
349 {
350 if( child.typeName == wxS( "Pin" ) && !child.properties.empty() )
351 foundPinDelta = true;
352 }
353
354 BOOST_CHECK( foundPinDelta );
355}
356
357
358BOOST_AUTO_TEST_CASE( AddedGraphicYieldsSingleAddedElement )
359{
360 auto [ownersA, mapA] = SYM_LIB_DIFFER::LoadLibrary( getFixturePath() );
361 auto [ownersB, mapB] = SYM_LIB_DIFFER::LoadLibrary( getFixturePath() );
362
363 LIB_SYMBOL* victim = nullptr;
364
365 for( const std::unique_ptr<LIB_SYMBOL>& owner : ownersB )
366 {
367 if( owner && !owner->IsDerived() )
368 {
369 victim = owner.get();
370 break;
371 }
372 }
373
374 BOOST_REQUIRE( victim );
375
377 rect->SetStart( VECTOR2I( 5080, 5080 ) );
378 rect->SetEnd( VECTOR2I( 7620, 7620 ) );
379 victim->AddDrawItem( rect );
380
381 SYM_LIB_DIFFER differ( mapA, mapB );
382 DOCUMENT_DIFF result = differ.Diff();
383
384 const ITEM_CHANGE* change = nullptr;
385
386 for( const ITEM_CHANGE& c : result.changes )
387 {
388 if( c.kind == CHANGE_KIND::MODIFIED && c.refdes && *c.refdes == victim->GetName() )
389 {
390 change = &c;
391 break;
392 }
393 }
394
395 BOOST_REQUIRE( change );
396
397 int added = 0;
398 int removed = 0;
399 int modified = 0;
400
401 for( const ITEM_CHANGE& child : change->children )
402 {
403 if( child.kind == CHANGE_KIND::ADDED )
404 added++;
405 else if( child.kind == CHANGE_KIND::REMOVED )
406 removed++;
407 else if( child.kind == CHANGE_KIND::MODIFIED )
408 modified++;
409 }
410
411 BOOST_CHECK_EQUAL( added, 1 );
412 BOOST_CHECK_EQUAL( removed, 0 );
413 BOOST_CHECK_EQUAL( modified, 0 );
414}
415
416
417// Edit the index'th plain symbol with pins, the same symbol in every load of one library
418static void editSymbol( const std::vector<std::unique_ptr<LIB_SYMBOL>>& aOwners, size_t aIndex,
419 const std::function<void( LIB_SYMBOL& )>& aEdit )
420{
421 for( const std::unique_ptr<LIB_SYMBOL>& owner : aOwners )
422 {
423 if( !owner || owner->IsDerived() || owner->GetGraphicalPins( ALL_UNITS, ALL_BODY_STYLES ).empty() )
424 continue;
425
426 if( aIndex-- == 0 )
427 {
428 aEdit( *owner );
429 return;
430 }
431 }
432
433 BOOST_FAIL( "the library has too few symbols with pins" );
434}
435
436
437// A merge that drops either side's edit to a symbol the other side left alone must not pass for clean
438BOOST_AUTO_TEST_CASE( MergeKeepsBothSidesRejectsADroppedEdit )
439{
440 auto [ancestorOwners, ancestor] = SYM_LIB_DIFFER::LoadLibrary( getFixturePath() );
441 auto [oursOwners, ours] = SYM_LIB_DIFFER::LoadLibrary( getFixturePath() );
442 auto [theirsOwners, theirs] = SYM_LIB_DIFFER::LoadLibrary( getFixturePath() );
443 auto [mergedOwners, merged] = SYM_LIB_DIFFER::LoadLibrary( getFixturePath() );
444
445 auto movePin = []( LIB_SYMBOL& aSymbol )
446 {
447 aSymbol.GetGraphicalPins( ALL_UNITS, ALL_BODY_STYLES ).front()->Move( VECTOR2I( 1270, 0 ) );
448 };
449
450 // Footprint filters are neither a registered property nor an element
451 auto setFilters = []( LIB_SYMBOL& aSymbol )
452 {
453 wxString str_filter( "QA_Filter_*" );
454 aSymbol.SetFPFilters( wxArrayString( 1, &str_filter ) );
455 };
456
457 editSymbol( oursOwners, 0, movePin );
458 editSymbol( theirsOwners, 1, setFilters );
459 editSymbol( mergedOwners, 0, movePin );
460 editSymbol( mergedOwners, 1, setFilters );
461
462 BOOST_CHECK( SYM_LIB_DIFFER::MergeKeepsBothSides( ancestor, ours, theirs, merged ) );
463 BOOST_CHECK( !SYM_LIB_DIFFER::MergeKeepsBothSides( ancestor, ours, theirs, ours ) );
464}
465
466
467// State the change record misses must still block the combine, or the merge drops it silently
468BOOST_AUTO_TEST_CASE( CombineSymbolEditsRejectsUnreportedState )
469{
470 auto [owners, symbols] = SYM_LIB_DIFFER::LoadLibrary( getFixturePath() );
471 const LIB_SYMBOL* ancestor = nullptr;
472
473 for( const auto& [name, symbol] : symbols )
474 {
475 if( !symbol->IsDerived() )
476 {
477 ancestor = symbol;
478 break;
479 }
480 }
481
482 BOOST_REQUIRE( ancestor );
483
484 LIB_SYMBOL ours( *ancestor );
485 LIB_SYMBOL theirs( *ancestor );
486
487 ours.GetDatasheetField().SetText( wxS( "https://example.com/qa.pdf" ) );
488 theirs.GetFootprintField().SetText( wxS( "QA:Footprint" ) );
489
490 auto fieldEdit = []( const wxString& aField )
491 {
492 ITEM_CHANGE child;
493 child.typeName = _( "Field" );
494 child.refdes = aField;
495
496 ITEM_CHANGE change;
497 change.children.push_back( std::move( child ) );
498 return change;
499 };
500
501 const ITEM_CHANGE ourChange = fieldEdit( wxS( "Datasheet" ) );
502 const ITEM_CHANGE theirChange = fieldEdit( wxS( "Footprint" ) );
503
504 std::unique_ptr<LIB_SYMBOL> merged = CombineSymbolEdits( *ancestor, ours, theirs, ourChange, theirChange );
505
506 BOOST_REQUIRE( merged );
507 BOOST_CHECK_EQUAL( merged->GetFootprintField().GetText(), wxS( "QA:Footprint" ) );
508
509 theirs.SetBodyStyleNames( { wxS( "QA_Normal" ), wxS( "QA_Alternate" ) } );
510
511 BOOST_CHECK( !CombineSymbolEdits( *ancestor, ours, theirs, ourChange, theirChange ) );
512}
513
514
515// A lower unit count from one side must not combine with an edit the other side makes to a dropped unit
516BOOST_AUTO_TEST_CASE( CombineSymbolEditsKeepsTheOtherSidesEdits )
517{
518 auto [owners, symbols] = SYM_LIB_DIFFER::LoadLibrary( getFixturePath() );
519
520 auto plain = std::ranges::find_if( owners,
521 []( const std::unique_ptr<LIB_SYMBOL>& aOwner )
522 {
523 return aOwner && !aOwner->IsDerived() && aOwner->GetUnitCount() == 1;
524 } );
525
526 BOOST_REQUIRE( plain != owners.end() );
527
528 LIB_SYMBOL ancestor( **plain );
529 ancestor.SetUnitCount( 2, false );
530
531 LIB_SYMBOL ours( ancestor );
532 LIB_SYMBOL theirs( ancestor );
533
534 SCH_PIN* pin = new SCH_PIN( &ours );
535 pin->SetUnit( 2 );
536 pin->SetNumber( wxS( "QA" ) );
537 ours.AddDrawItem( pin );
538
539 theirs.SetUnitCount( 1, false );
540
541 const wxString name = ancestor.GetName();
542
543 auto changeTo = [&]( const LIB_SYMBOL& aAfter )
544 {
545 DOCUMENT_DIFF diff = SYM_LIB_DIFFER( { { name, &ancestor } }, { { name, &aAfter } } ).Diff();
546 BOOST_REQUIRE_EQUAL( diff.changes.size(), 1 );
547 return diff.changes.front();
548 };
549
550 const ITEM_CHANGE ourChange = changeTo( ours );
551 const ITEM_CHANGE theirChange = changeTo( theirs );
552
553 BOOST_CHECK( !CombineSymbolEdits( ancestor, ours, theirs, ourChange, theirChange ) );
554
555 // The unit count keeps a dropped unit's name in memory but not in the file
556 LIB_SYMBOL named( ancestor );
557 named.GetUnitDisplayNames()[2] = wxS( "QA_Unit" );
558
559 BOOST_CHECK( !CombineSymbolEdits( ancestor, named, theirs, changeTo( named ), theirChange ) );
560}
561
562
563BOOST_AUTO_TEST_CASE( DerivedSymbolKeepsResolvedParentAfterLoad )
564{
565 auto [owners, map] = SYM_LIB_DIFFER::LoadLibrary( getFixturePath() );
566
567 int checked = 0;
568
569 for( const std::unique_ptr<LIB_SYMBOL>& sym : owners )
570 {
571 if( sym->GetParentName().IsEmpty() )
572 continue;
573
574 BOOST_TEST_INFO( sym->GetName().ToStdString() );
575 BOOST_CHECK( sym->IsDerived() );
576
577 std::shared_ptr<LIB_SYMBOL> parent = sym->GetParent().lock();
578 BOOST_REQUIRE( parent );
579 BOOST_CHECK_EQUAL( parent->GetName(), sym->GetParentName() );
580
581 checked++;
582 }
583
584 BOOST_CHECK( checked > 0 );
585}
586
587
const char * name
Diff two .kicad_sym symbol libraries.
static bool MergeKeepsBothSides(const SYMBOL_MAP &aAncestor, const SYMBOL_MAP &aOurs, const SYMBOL_MAP &aTheirs, const SYMBOL_MAP &aMerged)
True when aMerged differs from each side of a three-way merge exactly as the other side differs from ...
DOCUMENT_DIFF Diff() override
Produce a DOCUMENT_DIFF of the inputs the concrete differ was constructed with.
static std::pair< std::vector< std::unique_ptr< LIB_SYMBOL > >, SYMBOL_MAP > LoadLibrary(const wxString &aPath)
Convenience: load a .kicad_sym path into a SYMBOL_MAP using SCH_IO_KICAD_SEXPR::EnumerateSymbolLib.
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
Define a library symbol object.
Definition lib_symbol.h:114
SCH_FIELD & GetDatasheetField()
Definition lib_symbol.h:461
std::map< int, wxString > & GetUnitDisplayNames()
Definition lib_symbol.h:883
SCH_FIELD & GetFootprintField()
Definition lib_symbol.h:457
void SetBodyStyleNames(const std::vector< wxString > &aBodyStyleNames)
Definition lib_symbol.h:915
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition lib_symbol.h:845
wxString GetName() const override
Definition lib_symbol.h:183
void SetUnitCount(int aCount, bool aDuplicateDrawItems)
Set the units per symbol count.
std::vector< SCH_PIN * > GetGraphicalPins(int aUnit=0, int aBodyStyle=0) const override
Graphical pins: Return schematic pin objects as drawn (unexpanded), filtered by unit/body.
void AddDrawItem(SCH_ITEM *aItem, bool aSort=true)
Add a new draw aItem to the draw object list and sort according to aSort.
bool empty(int aType=UNDEFINED_TYPE) const
ITERATOR begin(int aType=UNDEFINED_TYPE)
void SetText(const wxString &aText) override
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
virtual void Move(const VECTOR2I &aMoveVector)
Move the item by aMoveVector to a new position.
Definition sch_item.h:422
#define _(s)
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
Definition eda_shape.h:58
DOCUMENT_GEOMETRY ExtractSymbolGeometry(const LIB_SYMBOL &aSymbol, const KIGFX::COLOR4D &aColor, int aUnit, int aBodyStyle)
Extract coarse drawable context from a library symbol for visual symbol diffs.
KIID_PATH LibraryItemKiidPath(const wxString &aName)
Build a deterministic synthetic KIID_PATH from a library item name (symbol name or footprint name).
std::unique_ptr< LIB_SYMBOL > CombineSymbolEdits(const LIB_SYMBOL &aAncestor, const LIB_SYMBOL &aOurs, const LIB_SYMBOL &aTheirs, const ITEM_CHANGE &aOurChange, const ITEM_CHANGE &aTheirChange)
Combine two edits of one library symbol when neither can lose anything.
std::optional< BOX2I > BBoxFromGeometry(const DOCUMENT_GEOMETRY &aGeometry)
Compute the tight bounding box of a DOCUMENT_GEOMETRY, inflating each primitive by half its stroke so...
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
The full set of changes between two parsed documents of one type.
nlohmann::json ToJson() const
static DOCUMENT_DIFF FromJson(const nlohmann::json &aJson)
std::vector< ITEM_CHANGE > changes
Aggregate of background geometry extracted from one source document.
Definition diff_scene.h:163
One change record on a single item.
std::vector< PROPERTY_DELTA > properties
std::optional< wxString > refdes
std::vector< ITEM_CHANGE > children
Single (name, before, after) triple for one mutated property on an item.
#define ALL_UNITS
Definition symbol.h:150
#define ALL_BODY_STYLES
Definition symbol.h:151
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
BOOST_REQUIRE_EQUAL(rows.size(), 1)
BOOST_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
BOOST_REQUIRE(res.columns()==1)
BOOST_AUTO_TEST_SUITE_END()
KIBIS_PIN * pin
BOOST_TEST_INFO("Two-port Series .op current = "<< iDevice)
static wxString getFixturePath()
static void editSymbol(const std::vector< std::unique_ptr< LIB_SYMBOL > > &aOwners, size_t aIndex, const std::function< void(LIB_SYMBOL &)> &aEdit)
BOOST_AUTO_TEST_CASE(IdenticalLibrariesDiffEmpty)
wxString result
Test unit parsing edge cases and error handling.
int delta
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
static PIECE rect(double aLeft, double aTop, double aRight, double aBottom, bool aMixed=false)