|
KiCad PCB EDA Suite
|
Diff two already-parsed SCHEMATICs and produce a DOCUMENT_DIFF. More...
#include <sch_differ.h>
Classes | |
| struct | WalkedItem |
Public Member Functions | |
| SCH_DIFFER (const SCHEMATIC *aBefore, const SCHEMATIC *aAfter, const wxString &aPath=wxEmptyString) | |
| ~SCH_DIFFER () override | |
| void | SetScope (const KIID_PATH &aBeforeScope, const KIID_PATH &aAfterScope) |
| Restrict the diff to one sheet on each side. | |
| DOCUMENT_DIFF | Diff () override |
| Produce a DOCUMENT_DIFF of the inputs the concrete differ was constructed with. | |
| const SCHEMATIC * | Before () const |
| const SCHEMATIC * | After () const |
| void | SetOptions (const OPTIONS &aOptions) |
| const OPTIONS & | GetOptions () const |
Protected Attributes | |
| OPTIONS | m_options |
Private Member Functions | |
| void | walk (const SCHEMATIC *aSchematic, std::vector< WalkedItem > &aOut, std::vector< std::unique_ptr< SCH_SHEET_PATH > > &aStorage, const KIID_PATH &aScope={}) const |
| Walk a schematic and produce a flat list of (KIID_PATH, item) tuples. | |
| std::vector< PROPERTY_DELTA > | diffProperties (const SCH_ITEM *aBefore, const SCH_ITEM *aAfter, const SCH_SHEET_PATH *aBeforePath, const SCH_SHEET_PATH *aAfterPath) const |
| Property-level delta via PROPERTY_MANAGER. | |
Static Private Member Functions | |
| static wxString | itemTypeName (const SCH_ITEM *aItem) |
| Type name for an SCH_ITEM (used in diff records). | |
| static std::optional< wxString > | itemRefdes (const SCH_ITEM *aItem, const SCH_SHEET_PATH *aPath) |
| Refdes if the item is a symbol; nullopt otherwise. | |
| static void | sortChanges (std::vector< ITEM_CHANGE > &aChanges) |
Private Attributes | |
| const SCHEMATIC * | m_before |
| const SCHEMATIC * | m_after |
| wxString | m_path |
| KIID_PATH | m_scopeBefore |
| KIID_PATH | m_scopeAfter |
Diff two already-parsed SCHEMATICs and produce a DOCUMENT_DIFF.
Identity is KIID_PATH-keyed: every item's identifier is the sheet path (a vector of sheet KIIDs from root) plus the item's own KIID. This is the canonical KiCad identity model for hierarchical schematics — the same item KIID can appear in multiple sheet instances with different KIID_PATHs.
The differ walks each schematic's full sheet list, collects items per KIID_PATH, runs IDENTITY_RECONCILER, then per matched pair uses PROPERTY_MANAGER for per-property delta enumeration.
Sheet renames are handled by the identity reconciler's similarity fallback: a renamed sheet's children have a different KIID_PATH prefix, but the same (type, position, key properties) — the reconciler will match them across the rename when the threshold is met.
Definition at line 54 of file sch_differ.h.
| KICAD_DIFF::SCH_DIFFER::SCH_DIFFER | ( | const SCHEMATIC * | aBefore, |
| const SCHEMATIC * | aAfter, | ||
| const wxString & | aPath = wxEmptyString ) |
Definition at line 44 of file sch_differ.cpp.
|
overridedefault |
|
inline |
Definition at line 69 of file sch_differ.h.
References m_after.
|
inline |
Definition at line 68 of file sch_differ.h.
References m_before.
|
overridevirtual |
Produce a DOCUMENT_DIFF of the inputs the concrete differ was constructed with.
Must be deterministic for fixed inputs. Concrete differs sort their output by KIID_PATH so the JSON serialization is bit-stable across runs.
Implements KICAD_DIFF::KICAD_DIFFER.
Definition at line 180 of file sch_differ.cpp.
References KICAD_DIFF::ADDED, KICAD_DIFF::PROPERTY_DELTA::after, KICAD_DIFF::RECONCILIATION::aOnly, KICAD_DIFF::AppendPaperDeltas(), KICAD_DIFF::RECONCILIATION::aToB, KICAD_DIFF::ITEM_CHANGE::bbox, KICAD_DIFF::ITEM_DESCRIPTOR::bbox, KICAD_DIFF::PROPERTY_DELTA::before, KICAD_DIFF::RECONCILIATION::bOnly, diffProperties(), KICAD_DIFF::DOC_PROP_DRAWING_SHEET, KICAD_DIFF::DOC_PROP_ERC_SEVERITIES, KICAD_DIFF::DUPLICATE_UUID, KICAD_DIFF::RECONCILIATION::duplicatesA, KICAD_DIFF::RECONCILIATION::duplicatesB, KICAD_DIFF::DIFF_VALUE::FromString(), SCH_SCREEN::GetPageSettings(), EDA_ITEM::GetPosition(), KICAD_DIFF::ITEM_CHANGE::id, KICAD_DIFF::ITEM_DESCRIPTOR::id, KICAD_DIFF::SCH_DIFFER::WalkedItem::id, KICAD_DIFF::SCH_DIFFER::WalkedItem::item, KICAD_DIFF::ItemProperties(), itemRefdes(), itemTypeName(), KICAD_DIFF::ITEM_DESCRIPTOR::keyProps, KICAD_DIFF::ITEM_CHANGE::kind, m_after, m_before, KICAD_DIFF::KICAD_DIFFER::m_options, m_path, m_scopeAfter, m_scopeBefore, KICAD_DIFF::MODIFIED, KICAD_DIFF::PROPERTY_DELTA::name, path, KICAD_DIFF::ITEM_DESCRIPTOR::position, KICAD_DIFF::ITEM_CHANGE::properties, KICAD_DIFF::IDENTITY_RECONCILER::Reconcile(), KICAD_DIFF::ITEM_CHANGE::refdes, KICAD_DIFF::REMOVED, result, KICAD_DIFF::SchScreenSentinelKiid(), KICAD_DIFF::SCH_DIFFER::WalkedItem::sheetPath, sortChanges(), KICAD_DIFF::SummarizeSeverities(), KICAD_DIFF::ITEM_DESCRIPTOR::type, KICAD_DIFF::ITEM_CHANGE::typeName, and walk().
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), SCH_INSPECTION_TOOL::CompareSchematicWithHistory(), EESCHEMA_JOBS_HANDLER::JobSchDiff(), EESCHEMA_JOBS_HANDLER::OpenDiffDialog(), EESCHEMA_JOBS_HANDLER::runSchMerge(), and SCH_INSPECTION_TOOL::showSchematicComparison().
|
private |
Property-level delta via PROPERTY_MANAGER.
The sheet paths anchor each item to its instance; SCH_SYMBOL property getters (Reference, Value, footprint, unit) read m_schematic->CurrentSheet() under the hood, so the differ has to switch CurrentSheet to the walked path around each read or it would compare the wrong instance on multi-sheet hierarchies / repeated sheets.
Definition at line 127 of file sch_differ.cpp.
References KICAD_DIFF::DiffItemProperties(), m_after, m_before, m_scopeAfter, and m_scopeBefore.
Referenced by Diff().
|
inlineinherited |
Definition at line 67 of file kicad_differ.h.
References m_options.
|
staticprivate |
Refdes if the item is a symbol; nullopt otherwise.
Definition at line 71 of file sch_differ.cpp.
Referenced by Diff().
|
staticprivate |
Type name for an SCH_ITEM (used in diff records).
Definition at line 62 of file sch_differ.cpp.
References SCH_ITEM::GetClass().
Referenced by Diff().
|
inlineinherited |
Definition at line 66 of file kicad_differ.h.
References m_options.
| void KICAD_DIFF::SCH_DIFFER::SetScope | ( | const KIID_PATH & | aBeforeScope, |
| const KIID_PATH & | aAfterScope ) |
Restrict the diff to one sheet on each side.
Items get normalized KIID_PATHs so they align across mismatched hierarchies. Empty paths disable scoping.
Definition at line 55 of file sch_differ.cpp.
References m_scopeAfter, and m_scopeBefore.
Referenced by SCH_INSPECTION_TOOL::CompareSchematicWithHistory(), and SCH_INSPECTION_TOOL::showSchematicComparison().
|
staticprivate |
Definition at line 164 of file sch_differ.cpp.
Referenced by Diff().
|
private |
Walk a schematic and produce a flat list of (KIID_PATH, item) tuples.
aStorage retains the SCH_SHEET_PATH objects for the lifetime of the diff because WalkedItem::sheetPath references them. Non-empty aScope limits the walk to that one SCH_SHEET_PATH.
Definition at line 84 of file sch_differ.cpp.
References KICAD_DIFF::SCH_DIFFER::WalkedItem::id, KICAD_DIFF::SCH_DIFFER::WalkedItem::item, KICAD_DIFF::SCH_DIFFER::WalkedItem::sheetPath, and KICAD_DIFF::WalkSchematic().
Referenced by Diff().
|
private |
Definition at line 108 of file sch_differ.h.
Referenced by After(), Diff(), diffProperties(), and SCH_DIFFER().
|
private |
Definition at line 107 of file sch_differ.h.
Referenced by Before(), Diff(), diffProperties(), and SCH_DIFFER().
|
protectedinherited |
Definition at line 80 of file kicad_differ.h.
Referenced by KICAD_DIFF::FP_LIB_DIFFER::Diff(), KICAD_DIFF::PCB_DIFFER::Diff(), KICAD_DIFF::SCH_DIFFER::Diff(), KICAD_DIFF::SYM_LIB_DIFFER::Diff(), KICAD_DIFF::PCB_DIFFER::diffFootprintChildren(), GetOptions(), and SetOptions().
|
private |
Definition at line 109 of file sch_differ.h.
Referenced by Diff(), and SCH_DIFFER().
|
private |
Definition at line 111 of file sch_differ.h.
Referenced by Diff(), diffProperties(), and SetScope().
|
private |
Definition at line 110 of file sch_differ.h.
Referenced by Diff(), diffProperties(), and SetScope().