33 const std::map<wxString, const EDA_ITEM*>& aBefore,
34 const std::map<wxString, const EDA_ITEM*>& aAfter )
36 std::set<wxString> keys;
38 for(
const auto& [key, item] : aBefore )
41 for(
const auto& [key, item] : aAfter )
44 for(
const wxString& key : keys )
46 auto beforeIt = aBefore.find( key );
47 auto afterIt = aAfter.find( key );
48 const EDA_ITEM* before = beforeIt != aBefore.end() ? beforeIt->second :
nullptr;
49 const EDA_ITEM* after = afterIt != aAfter.end() ? afterIt->second :
nullptr;
71 const std::vector<const EDA_ITEM*>& aAfter,
72 const std::function<wxString(
const EDA_ITEM* )>& aTypeName,
73 const std::function<
bool(
const EDA_ITEM*,
const EDA_ITEM* )>& aSameGeometry )
75 auto sameGeometry = [&](
const EDA_ITEM* aBeforeItem,
const EDA_ITEM* aAfterItem )
77 return !aSameGeometry || aSameGeometry( aBeforeItem, aAfterItem );
80 std::set<const EDA_ITEM*> matchedBefore;
81 std::set<const EDA_ITEM*> matchedAfter;
84 for(
const EDA_ITEM* after : aAfter )
86 for(
const EDA_ITEM* before : aBefore )
88 if( matchedBefore.count( before ) || before->Type() != after->Type() )
93 matchedBefore.insert( before );
94 matchedAfter.insert( after );
101 for(
const EDA_ITEM* after : aAfter )
103 if( matchedAfter.count( after ) )
107 double bestDist = 0.0;
109 for(
const EDA_ITEM* before : aBefore )
111 if( matchedBefore.count( before ) || before->Type() != after->Type() )
114 VECTOR2I delta = before->GetPosition() - after->GetPosition();
117 if( !best || dist < bestDist )
126 matchedBefore.insert( best );
130 if( !deltas.empty() || !sameGeometry( best, after ) )
143 for(
const EDA_ITEM* before : aBefore )
145 if( !matchedBefore.count( before ) )
void DiffKeyedElements(std::vector< LIB_ELEMENT > &aOut, const wxString &aTypeName, const std::map< wxString, const EDA_ITEM * > &aBefore, const std::map< wxString, const EDA_ITEM * > &aAfter)
Elements that are matched by a key, such as pins by number or fields by name.
void AppendElementChanges(ITEM_CHANGE &aChange, const std::vector< LIB_ELEMENT > &aElements)
Add each element to aChange as a child change, which is how a library item reports its elements.
void DiffUnkeyedElements(std::vector< LIB_ELEMENT > &aOut, const std::vector< const EDA_ITEM * > &aBefore, const std::vector< const EDA_ITEM * > &aAfter, const std::function< wxString(const EDA_ITEM *)> &aTypeName, const std::function< bool(const EDA_ITEM *, const EDA_ITEM *)> &aSameGeometry)
Elements with no key.