38 wxString graphicTypeName(
const SCH_ITEM* aItem )
40 switch( aItem->
Type() )
45 default:
return _(
"Item" );
50 void diffKeyed( std::vector<SYM_ELEMENT>& aOut,
const wxString& aTypeName,
51 const std::map<wxString, const EDA_ITEM*>& aBefore,
52 const std::map<wxString, const EDA_ITEM*>& aAfter )
54 std::set<wxString> keys;
56 for(
const auto& [key, item] : aBefore )
59 for(
const auto& [key, item] : aAfter )
62 for(
const wxString& key : keys )
64 auto beforeIt = aBefore.find( key );
65 auto afterIt = aAfter.find( key );
66 const EDA_ITEM* before = beforeIt != aBefore.end() ? beforeIt->second :
nullptr;
67 const EDA_ITEM* after = afterIt != aAfter.end() ? afterIt->second :
nullptr;
88 std::map<wxString, const EDA_ITEM*> pinsByNumber(
const LIB_SYMBOL* aSym )
90 std::map<wxString, const EDA_ITEM*> out;
97 out[
pin->GetNumber()] =
pin;
105 std::map<wxString, const EDA_ITEM*> fieldsByName(
const LIB_SYMBOL* aSym )
107 std::map<wxString, const EDA_ITEM*> out;
111 std::vector<SCH_FIELD*> fields;
114 for( SCH_FIELD* field : fields )
117 out[field->GetName()] = field;
125 std::vector<const SCH_ITEM*> graphics(
const LIB_SYMBOL* aSym )
127 std::vector<const SCH_ITEM*> out;
134 out.push_back( &item );
145 std::vector<SYM_ELEMENT> out;
147 diffKeyed( out,
_(
"Pin" ), pinsByNumber( aBefore ), pinsByNumber( aAfter ) );
148 diffKeyed( out,
_(
"Field" ), fieldsByName( aBefore ), fieldsByName( aAfter ) );
150 std::vector<const SCH_ITEM*> beforeGraphics = graphics( aBefore );
151 std::vector<const SCH_ITEM*> afterGraphics = graphics( aAfter );
152 std::set<const SCH_ITEM*> matchedBefore;
153 std::set<const SCH_ITEM*> matchedAfter;
157 for(
const SCH_ITEM* after : afterGraphics )
159 for(
const SCH_ITEM* before : beforeGraphics )
161 if( matchedBefore.count( before ) || before->
Type() != after->
Type() )
166 matchedBefore.insert( before );
167 matchedAfter.insert( after );
175 for(
const SCH_ITEM* after : afterGraphics )
177 if( matchedAfter.count( after ) )
181 double bestDist = 0.0;
183 for(
const SCH_ITEM* before : beforeGraphics )
185 if( matchedBefore.count( before ) || before->
Type() != after->
Type() )
191 if( !best || dist < bestDist )
200 matchedBefore.insert( best );
204 if( !deltas.empty() )
206 std::move( deltas ) } );
215 for(
const SCH_ITEM* before : beforeGraphics )
217 if( !matchedBefore.count( before ) )
virtual VECTOR2I GetPosition() const
KICAD_T Type() const
Returns the type of object.
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.
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
std::vector< SCH_PIN * > GetPins() const override
Base class for any item which can be embedded within the SCHEMATIC container class,...
static bool empty(const wxTextEntryBase *aCtrl)
std::vector< SYM_ELEMENT > DiffSymbolElements(const LIB_SYMBOL *aBefore, const LIB_SYMBOL *aAfter)
Compares the elements of two library symbols.
std::vector< PROPERTY_DELTA > DiffItemProperties(const INSPECTABLE *aBefore, const INSPECTABLE *aAfter)
Enumerate the property deltas between two items of the same dynamic type.
std::vector< PROPERTY_DELTA > ItemProperties(const INSPECTABLE *aItem, bool aAsAfter)
List one item's properties as one-sided deltas for an added or removed item.
VECTOR2< int32_t > VECTOR2I