39#include <wx/filename.h>
56 fn.AppendDir( wxS(
"libraries" ) );
57 fn.SetFullName( wxS(
"Device.kicad_sym" ) );
58 return fn.GetFullPath();
84 wxString victimName = mapB.begin()->first;
85 mapB.erase( mapB.begin() );
117 BOOST_CHECK_GT(
result.changes[0].bbox.GetWidth(), 0 );
118 BOOST_CHECK_GT(
result.changes[0].bbox.GetHeight(), 0 );
141 mapB.erase( mapB.begin() );
146 nlohmann::json j =
result.ToJson();
184 BOOST_REQUIRE_GE( mapB.size(), 3u );
186 std::vector<wxString> victims;
188 for(
int i = 0; i < 3 && !mapB.empty(); ++i )
190 victims.push_back( mapB.begin()->first );
191 mapB.erase( mapB.begin() );
216 BOOST_REQUIRE_GE( mapB1.size(), 2u );
219 mapB1.erase( mapB1.begin() );
220 mapB2.erase( mapB2.begin() );
239 for(
const std::unique_ptr<LIB_SYMBOL>& owner : ownersB )
243 victim = owner.get();
268 bool foundPinChild =
false;
273 foundPinChild =
true;
286 auto victim = std::ranges::find_if( ownersB,
287 [](
const std::unique_ptr<LIB_SYMBOL>& aOwner )
289 return aOwner && !aOwner->IsDerived();
294 ( *victim )->GetUnitDisplayNames()[1] = wxS(
"QA_Unit" );
295 ( *victim )->SetBodyStyleNames( { wxS(
"QA_Normal" ), wxS(
"QA_Alternate" ) } );
297 std::set<wxString> names;
302 names.insert(
delta.name );
305 BOOST_CHECK( names.contains( wxS(
"Unit Names" ) ) );
306 BOOST_CHECK( names.contains( wxS(
"Body Style Names" ) ) );
317 for(
const std::unique_ptr<LIB_SYMBOL>& owner : ownersB )
321 victim = owner.get();
346 bool foundPinDelta =
false;
351 foundPinDelta =
true;
365 for(
const std::unique_ptr<LIB_SYMBOL>& owner : ownersB )
367 if( owner && !owner->IsDerived() )
369 victim = owner.get();
418static void editSymbol(
const std::vector<std::unique_ptr<LIB_SYMBOL>>& aOwners,
size_t aIndex,
419 const std::function<
void(
LIB_SYMBOL& )>& aEdit )
421 for(
const std::unique_ptr<LIB_SYMBOL>& owner : aOwners )
433 BOOST_FAIL(
"the library has too few symbols with pins" );
453 wxString str_filter(
"QA_Filter_*" );
454 aSymbol.SetFPFilters( wxArrayString( 1, &str_filter ) );
473 for(
const auto& [
name, symbol] : symbols )
475 if( !symbol->IsDerived() )
490 auto fieldEdit = [](
const wxString& aField )
497 change.
children.push_back( std::move( child ) );
501 const ITEM_CHANGE ourChange = fieldEdit( wxS(
"Datasheet" ) );
502 const ITEM_CHANGE theirChange = fieldEdit( wxS(
"Footprint" ) );
504 std::unique_ptr<LIB_SYMBOL> merged =
CombineSymbolEdits( *ancestor, ours, theirs, ourChange, theirChange );
507 BOOST_CHECK_EQUAL( merged->GetFootprintField().GetText(), wxS(
"QA:Footprint" ) );
520 auto plain = std::ranges::find_if( owners,
521 [](
const std::unique_ptr<LIB_SYMBOL>& aOwner )
523 return aOwner && !aOwner->IsDerived() && aOwner->GetUnitCount() == 1;
536 pin->SetNumber( wxS(
"QA" ) );
543 auto changeTo = [&](
const LIB_SYMBOL& aAfter )
551 const ITEM_CHANGE theirChange = changeTo( theirs );
569 for(
const std::unique_ptr<LIB_SYMBOL>& sym : owners )
571 if( sym->GetParentName().IsEmpty() )
577 std::shared_ptr<LIB_SYMBOL> parent = sym->GetParent().lock();
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.
Define a library symbol object.
SCH_FIELD & GetDatasheetField()
std::map< int, wxString > & GetUnitDisplayNames()
SCH_FIELD & GetFootprintField()
void SetBodyStyleNames(const std::vector< wxString > &aBodyStyleNames)
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
wxString GetName() const override
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,...
virtual void Move(const VECTOR2I &aMoveVector)
Move the item by aMoveVector to a new position.
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
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.
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.
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()
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.
VECTOR2< int32_t > VECTOR2I
static PIECE rect(double aLeft, double aTop, double aRight, double aBottom, bool aMixed=false)