KiCad PCB EDA Suite
Loading...
Searching...
No Matches
KICAD_DIFF::SCH_DIFFER Class Reference

Diff two already-parsed SCHEMATICs and produce a DOCUMENT_DIFF. More...

#include <sch_differ.h>

Inheritance diagram for KICAD_DIFF::SCH_DIFFER:
KICAD_DIFF::KICAD_DIFFER

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 SCHEMATICBefore () const
 
const SCHEMATICAfter () const
 
void SetOptions (const OPTIONS &aOptions)
 
const OPTIONSGetOptions () 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_DELTAdiffProperties (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 SCHEMATICm_before
 
const SCHEMATICm_after
 
wxString m_path
 
KIID_PATH m_scopeBefore
 
KIID_PATH m_scopeAfter
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ SCH_DIFFER()

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.

References m_after, m_before, and m_path.

◆ ~SCH_DIFFER()

KICAD_DIFF::SCH_DIFFER::~SCH_DIFFER ( )
overridedefault

Member Function Documentation

◆ After()

const SCHEMATIC * KICAD_DIFF::SCH_DIFFER::After ( ) const
inline

Definition at line 69 of file sch_differ.h.

References m_after.

◆ Before()

const SCHEMATIC * KICAD_DIFF::SCH_DIFFER::Before ( ) const
inline

Definition at line 68 of file sch_differ.h.

References m_before.

◆ Diff()

DOCUMENT_DIFF KICAD_DIFF::SCH_DIFFER::Diff ( )
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().

◆ diffProperties()

std::vector< PROPERTY_DELTA > KICAD_DIFF::SCH_DIFFER::diffProperties ( const SCH_ITEM * aBefore,
const SCH_ITEM * aAfter,
const SCH_SHEET_PATH * aBeforePath,
const SCH_SHEET_PATH * aAfterPath ) const
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().

◆ GetOptions()

const OPTIONS & KICAD_DIFF::KICAD_DIFFER::GetOptions ( ) const
inlineinherited

Definition at line 67 of file kicad_differ.h.

References m_options.

◆ itemRefdes()

std::optional< wxString > KICAD_DIFF::SCH_DIFFER::itemRefdes ( const SCH_ITEM * aItem,
const SCH_SHEET_PATH * aPath )
staticprivate

Refdes if the item is a symbol; nullopt otherwise.

Definition at line 71 of file sch_differ.cpp.

Referenced by Diff().

◆ itemTypeName()

wxString KICAD_DIFF::SCH_DIFFER::itemTypeName ( const SCH_ITEM * aItem)
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().

◆ SetOptions()

void KICAD_DIFF::KICAD_DIFFER::SetOptions ( const OPTIONS & aOptions)
inlineinherited

Definition at line 66 of file kicad_differ.h.

References m_options.

◆ SetScope()

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().

◆ sortChanges()

void KICAD_DIFF::SCH_DIFFER::sortChanges ( std::vector< ITEM_CHANGE > & aChanges)
staticprivate

Definition at line 164 of file sch_differ.cpp.

Referenced by Diff().

◆ walk()

void KICAD_DIFF::SCH_DIFFER::walk ( const SCHEMATIC * aSchematic,
std::vector< WalkedItem > & aOut,
std::vector< std::unique_ptr< SCH_SHEET_PATH > > & aStorage,
const KIID_PATH & aScope = {} ) const
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().

Member Data Documentation

◆ m_after

const SCHEMATIC* KICAD_DIFF::SCH_DIFFER::m_after
private

Definition at line 108 of file sch_differ.h.

Referenced by After(), Diff(), diffProperties(), and SCH_DIFFER().

◆ m_before

const SCHEMATIC* KICAD_DIFF::SCH_DIFFER::m_before
private

Definition at line 107 of file sch_differ.h.

Referenced by Before(), Diff(), diffProperties(), and SCH_DIFFER().

◆ m_options

◆ m_path

wxString KICAD_DIFF::SCH_DIFFER::m_path
private

Definition at line 109 of file sch_differ.h.

Referenced by Diff(), and SCH_DIFFER().

◆ m_scopeAfter

KIID_PATH KICAD_DIFF::SCH_DIFFER::m_scopeAfter
private

Definition at line 111 of file sch_differ.h.

Referenced by Diff(), diffProperties(), and SetScope().

◆ m_scopeBefore

KIID_PATH KICAD_DIFF::SCH_DIFFER::m_scopeBefore
private

Definition at line 110 of file sch_differ.h.

Referenced by Diff(), diffProperties(), and SetScope().


The documentation for this class was generated from the following files: