33#include <wx/filename.h>
55 std::vector<std::unique_ptr<LIB_SYMBOL>> owners;
60 wxFileName absPath( aPath );
61 absPath.MakeAbsolute();
62 wxString absStr = absPath.GetFullPath();
65 std::vector<LIB_SYMBOL*> rawList;
81 std::unique_ptr<LIB_SYMBOL> owner(
new LIB_SYMBOL( *sym ) );
82 map[owner->GetName()] = owner.get();
83 owners.push_back( std::move( owner ) );
89 std::map<wxString, LIB_SYMBOL*> byName;
91 for(
const std::unique_ptr<LIB_SYMBOL>& owner : owners )
92 byName[owner->GetName()] = owner.get();
94 for(
const std::unique_ptr<LIB_SYMBOL>& owner : owners )
96 if( owner->GetParentName().IsEmpty() )
99 auto it = byName.find( owner->GetParentName() );
101 if( it != byName.end() )
102 owner->SetParent( it->second );
105 return { std::move( owners ), std::move( map ) };
118 wxString before = wxJoin( aBefore->
GetFPFilters(),
' ' );
121 if( before != after )
128 auto unitNames = [](
const LIB_SYMBOL* aSymbol )
132 for(
const auto& [unit,
name] : aSymbol->GetUnitDisplayNames() )
133 names.Add( wxString::Format( wxS(
"%d: %s" ), unit,
name ) );
135 return wxJoin( names,
',' );
138 before = unitNames( aBefore );
139 after = unitNames( aAfter );
141 if( before != after )
147 auto bodyStyleNames = [](
const LIB_SYMBOL* aSymbol )
151 for(
const wxString&
name : aSymbol->GetBodyStyleNames() )
154 return wxJoin( names,
',' );
157 before = bodyStyleNames( aBefore );
158 after = bodyStyleNames( aAfter );
160 if( before != after )
170 bool hasSymbolDifferences(
const LIB_SYMBOL* aBefore,
const LIB_SYMBOL* aAfter )
172 std::unique_ptr<LIB_SYMBOL> before = aBefore->
Flatten();
173 std::unique_ptr<LIB_SYMBOL> after = aAfter->
Flatten();
175 return before->Compare( *after, SYMBOL_COMPARE_FLAGS ) != 0
176 || !symbolDeltas( before.get(), after.get() ).empty()
192 return hasSymbolDifferences( aA, aB );
206 std::unique_ptr<LIB_SYMBOL> before = beforeIt->second->Flatten();
207 std::unique_ptr<LIB_SYMBOL> after = afterIt->second->Flatten();
209 change.
properties = symbolDeltas( before.get(), after.get() );
222 std::map<KIID_PATH, ITEM_CHANGE> applied;
223 std::map<KIID_PATH, ITEM_CHANGE> wanted;
226 applied.emplace( change.id, std::move( change ) );
229 wanted.emplace( change.id, std::move( change ) );
232 return std::equal( applied.begin(), applied.end(), wanted.begin(), wanted.end(),
233 [](
const auto& aA,
const auto& aB )
235 return aA.first == aB.first && aA.second.kind == aB.second.kind
236 && aA.second.properties == aB.second.properties
237 && aA.second.children == aB.second.children;
241 return carries( aOurs, aTheirs ) && carries( aTheirs, aOurs );
static DIFF_VALUE FromString(const wxString &aValue)
const SYMBOL_MAP & m_before
~SYM_LIB_DIFFER() override
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 ...
SYM_LIB_DIFFER(const SYMBOL_MAP &aBefore, const SYMBOL_MAP &aAfter, const wxString &aPath=wxEmptyString)
const SYMBOL_MAP & m_after
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.
std::map< wxString, const LIB_SYMBOL * > SYMBOL_MAP
Library content is a map of (canonical_name -> LIB_SYMBOL*).
Define a library symbol object.
const BOX2I GetUnitBoundingBox(int aUnit, int aBodyStyle, bool aIgnoreHiddenFields=true, bool aIgnoreLabelsOnInvisiblePins=true) const
Get the bounding box for the symbol.
wxArrayString GetFPFilters() const
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
A SCH_IO derivation for loading schematic files using the new s-expression file format.
void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
std::vector< PROPERTY_DELTA > DiffItemProperties(const INSPECTABLE *aBefore, const INSPECTABLE *aAfter)
Enumerate the property deltas between two items of the same dynamic type.
DOCUMENT_DIFF DiffLibraryByName(const MAP &aBefore, const MAP &aAfter, const wxString &aPath, const wxString &aDocType, const wxString &aTypeName, const KICAD_DIFFER::OPTIONS &aOptions, BBoxFn aBBox, ChangedFn aChanged)
Shared name-keyed library diff used by FP_LIB_DIFFER and SYM_LIB_DIFFER.
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.
std::vector< LIB_ELEMENT > DiffSymbolElements(const LIB_SYMBOL *aBefore, const LIB_SYMBOL *aAfter)
Compares the elements of two library symbols.
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
wxString result
Test unit parsing edge cases and error handling.