44 wxString graphicTypeName(
const EDA_ITEM* aItem )
46 switch( aItem->
Type() )
51 default:
return _(
"Item" );
56 std::map<wxString, const EDA_ITEM*> pinsByNumber(
const LIB_SYMBOL* aSym )
58 std::map<wxString, const EDA_ITEM*> out;
65 out[
pin->GetNumber()] =
pin;
73 std::map<wxString, const EDA_ITEM*> fieldsByName(
const LIB_SYMBOL* aSym )
75 std::map<wxString, const EDA_ITEM*> out;
79 std::vector<SCH_FIELD*> fields;
82 for( SCH_FIELD* field : fields )
85 out[field->GetName()] = field;
93 std::vector<const EDA_ITEM*> graphics(
const LIB_SYMBOL* aSym )
95 std::vector<const EDA_ITEM*> out;
102 out.push_back( &item );
113 std::vector<LIB_ELEMENT> out;
115 DiffKeyedElements( out,
_(
"Pin" ), pinsByNumber( aBefore ), pinsByNumber( aAfter ) );
116 DiffKeyedElements( out,
_(
"Field" ), fieldsByName( aBefore ), fieldsByName( aAfter ) );
133 return std::ranges::all_of( aChange.children,
136 return aChild.typeName == _(
"Field" ) && aChild.refdes
137 && aChild.kind != CHANGE_KIND::REMOVED;
141 const bool theirsDonates = onlyFields( aTheirChange );
143 if( !theirsDonates && !onlyFields( aOurChange ) )
146 const std::set<wxString> ourNames =
EditedNames( aOurChange );
147 const std::set<wxString> theirNames =
EditedNames( aTheirChange );
150 if( ourNames.contains( wxS(
"Name" ) ) || theirNames.contains( wxS(
"Name" ) ) )
153 if( std::ranges::any_of( ourNames, [&](
const wxString& aName ) {
return theirNames.contains( aName ); } ) )
156 const LIB_SYMBOL& donor = theirsDonates ? aTheirs : aOurs;
157 const ITEM_CHANGE& donation = theirsDonates ? aTheirChange : aOurChange;
159 auto donate = [&](
const LIB_SYMBOL& aBase ) -> std::unique_ptr<LIB_SYMBOL>
161 auto target = std::make_unique<LIB_SYMBOL>( aBase );
173 target->AddField(
new SCH_FIELD( *from ) );
176 std::vector<PROPERTY_RESOLUTION> props;
183 props.push_back( std::move( prop ) );
203 auto reload = [&](
const LIB_SYMBOL& aSymbol ) -> std::unique_ptr<LIB_SYMBOL>
205 std::string
text = saved( aSymbol );
210 std::vector<std::unique_ptr<LIB_SYMBOL>> owned( parsed.begin(), parsed.end() );
212 if( owned.size() == 1 )
213 return std::move( owned.front() );
223 std::unique_ptr<LIB_SYMBOL> replay = donate( aAncestor );
225 if( !replay || saved( *replay ) != saved( donor ) )
228 std::unique_ptr<LIB_SYMBOL> merged = donate( theirsDonates ? aOurs : aTheirs );
231 merged =
reload( *merged );
238 { {
name, &aTheirs } }, { {
name, merged.get() } } ) )
KICAD_T Type() const
Returns the type of object.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
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 ...
Define a library symbol object.
void GetFields(std::vector< SCH_FIELD * > &aList, bool aVisibleOnly=false) const override
Populate a std::vector with SCH_FIELDs, sorted in ordinal order.
SCH_FIELD * GetField(const wxString &aFieldName)
Find a field within this symbol matching aFieldName; return nullptr if not found.
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
wxString GetName() const override
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.
static void FormatLibSymbol(LIB_SYMBOL *aPart, OUTPUTFORMATTER &aFormatter)
static std::vector< LIB_SYMBOL * > ParseLibSymbols(std::string &aSymbolText, std::string aSource, int aFileVersion=SEXPR_SCHEMATIC_FILE_VERSION)
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.
std::vector< LIB_ELEMENT > DiffSymbolElements(const LIB_SYMBOL *aBefore, const LIB_SYMBOL *aAfter)
Compares the elements of two library symbols.
PROPERTY_APPLY_COUNTS ApplyPropertyResolutions(INSPECTABLE *aTarget, const std::vector< PROPERTY_RESOLUTION > &aProps, const INSPECTABLE *aOurs, const INSPECTABLE *aTheirs, const INSPECTABLE *aAncestor)
Apply per-property merge resolutions to aTarget, sourcing OURS/THEIRS/ANCESTOR values from the matchi...
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.
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::set< wxString > EditedNames(const ITEM_CHANGE &aChange)
The properties and elements aChange edits, by the names a user would know them by.
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.