Entity Relationship Diagram: Electrical Rules Check (ERC)ο
Feature: ERC Validation System Version: 1.0 Date: 2024-10-26
System Overviewο
The ERC system validates electrical connectivity and design rules in KiCAD schematics through interconnected validators and data models.
Entity Relationship Diagramο
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Schematic β
β - uuid: str β
β - components: ComponentCollection β
β - wires: WireCollection β
β - labels: LabelCollection β
β - nets: Dict[str, Net] β
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββ
β
β 1:1
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ElectricalRulesChecker β
β - schematic: Schematic β
β - config: ERCConfig β
β - validators: List[Validator] β
β + run_all_checks() -> ERCResult β
β + run_check(check_type: str) -> List[ERCViolation] β
ββββββ¬βββββββββ¬βββββββββ¬βββββββββ¬βββββββββ¬βββββββββββββββββββββββ
β β β β β
β 1:1 β 1:1 β 1:1 β 1:1 β 1:1
β β β β β
βΌ βΌ βΌ βΌ βΌ
ββββββββ ββββββββββ ββββββββββ ββββββββ ββββββββββββ
β Pin β βConnect β βComp β βPower β βHierarchy β
βType β βivity β βonent β βValid β βValidator β
βValid β βValid β βValid β βator β β β
βator β βator β βator β β β β β
ββββ¬ββββ ββββββ¬ββββ ββββββ¬ββββ ββββ¬ββββ ββββββ¬ββββββ
β β β β β
β β β β β
β uses β creates βcreates βcreates β creates
β β β β β
βΌ βΌ βΌ βΌ βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ERCViolation β
β - violation_type: str β
β - severity: str ("error", "warning", "info") β
β - message: str β
β - component_refs: List[str] β
β - net_name: Optional[str] β
β - pin_numbers: List[str] β
β - location: Optional[Point] β
β - suggested_fix: Optional[str] β
β - error_code: str β
ββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ
β
β N:1 collected by
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ERCResult β
β - errors: List[ERCViolation] β
β - warnings: List[ERCViolation] β
β - info: List[ERCViolation] β
β - total_checks: int β
β - passed_checks: int β
β - duration_ms: float β
β + has_errors() -> bool β
β + summary() -> str β
β + to_dict() -> Dict β
β + to_json() -> str β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ERCConfig β
β - severity_overrides: Dict[str, str] β
β - suppressed_warnings: Set[str] β
β - custom_rules: List[CustomRule] β
β - pin_conflict_matrix: PinConflictMatrix β
β + set_severity(rule: str, severity: str) β
β + suppress_warning(code: str, component: str) β
ββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ
β
β 1:1 uses
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β PinConflictMatrix β
β - matrix: Dict[Tuple[str, str], int] β
β + check_connection(pin1: str, pin2: str) -> int β
β + set_rule(pin1: str, pin2: str, severity: int) β
β + get_default_matrix() -> Dict β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Detailed Entity Descriptionsο
Core Entitiesο
1. ElectricalRulesCheckerο
Purpose: Main orchestrator for all ERC validation
Attributes:
schematic: Schematic- The schematic being validatedconfig: ERCConfig- Configuration for validation rulesvalidators: List[Validator]- All registered validators
Methods:
run_all_checks() -> ERCResult- Execute all validatorsrun_check(check_type: str) -> List[ERCViolation]- Run specific checkadd_validator(validator: Validator)- Register custom validator
Relationships:
1:1 with Schematic (validates one schematic)
1:1 with ERCConfig (uses one configuration)
1:N with Validators (has multiple validators)
Creates ERCResult (output)
2. ERCViolationο
Purpose: Represents a single validation violation
Attributes:
violation_type: str- Category (e.g., βpin_conflictβ, βdangling_wireβ)severity: str- βerrorβ, βwarningβ, or βinfoβmessage: str- Human-readable descriptioncomponent_refs: List[str]- Affected component referencesnet_name: Optional[str]- Affected net namepin_numbers: List[str]- Affected pin numberslocation: Optional[Point]- Schematic coordinatessuggested_fix: Optional[str]- Recommended fixerror_code: str- Unique code (e.g., βE001β, βW042β)
Relationships:
N:1 with ERCResult (many violations in one result)
Created by Validators
3. ERCResultο
Purpose: Aggregates all validation results
Attributes:
errors: List[ERCViolation]- Error-level violationswarnings: List[ERCViolation]- Warning-level violationsinfo: List[ERCViolation]- Info-level violationstotal_checks: int- Total validations performedpassed_checks: int- Number of passed checksduration_ms: float- Execution time
Methods:
has_errors() -> bool- Quick error checksummary() -> str- Human-readable summaryto_dict() -> Dict- JSON-serializable dictto_json() -> str- JSON stringfilter_by_severity(severity: str) -> List[ERCViolation]filter_by_component(ref: str) -> List[ERCViolation]
Relationships:
1:N with ERCViolation (contains many violations)
Created by ElectricalRulesChecker
4. ERCConfigο
Purpose: Configuration for validation rules
Attributes:
severity_overrides: Dict[str, str]- Custom severity levelssuppressed_warnings: Set[str]- Suppressed warning codescustom_rules: List[CustomRule]- User-defined rulespin_conflict_matrix: PinConflictMatrix- Pin compatibility matrix
Methods:
set_severity(rule: str, severity: str)- Override default severitysuppress_warning(code: str, component: str)- Suppress specific warningadd_custom_rule(rule: CustomRule)- Add user ruleload_profile(name: str)- Load rule profile (strict/standard/relaxed)
Relationships:
1:1 with ElectricalRulesChecker (configures one checker)
1:1 with PinConflictMatrix (defines pin rules)
Validator Entitiesο
5. PinTypeValidatorο
Purpose: Validates pin-to-pin connections
Attributes:
pin_matrix: PinConflictMatrix- Pin compatibility rulesschematic: Schematic- Schematic being validated
Methods:
validate_pin_connections() -> List[ERCViolation]check_net_pins(net_name: str) -> List[ERCViolation]get_pin_type(component_ref: str, pin_num: str) -> str
Key Validations:
Output-to-Output conflicts (ERROR)
Power Output shorts (ERROR)
Output-to-Power Output (ERROR)
Unspecified pin warnings (WARNING)
Relationships:
Uses PinConflictMatrix for rules
Creates ERCViolation objects
Accesses Schematic components and nets
6. ConnectivityValidatorο
Purpose: Validates wire connectivity
Attributes:
schematic: Schematicmin_connections: int- Minimum connections for valid net
Methods:
find_dangling_wires() -> List[ERCViolation]find_undriven_nets() -> List[ERCViolation]find_unconnected_pins() -> List[ERCViolation]trace_net(start_point: Point) -> List[Point]
Key Validations:
Wires with only one endpoint (WARNING)
Input pins without drivers (WARNING)
Nets without output pins (WARNING)
Relationships:
Accesses Schematic wires collection
Accesses Schematic components collection
Creates ERCViolation objects
7. ComponentValidatorο
Purpose: Validates component properties
Attributes:
schematic: Schematicreference_pattern: Pattern- Regex for valid references
Methods:
find_duplicate_references() -> List[ERCViolation]validate_component_properties() -> List[ERCViolation]check_reference_format(ref: str) -> bool
Key Validations:
Duplicate reference designators (ERROR)
Missing values (WARNING)
Missing footprints (WARNING)
Invalid reference format (ERROR)
Relationships:
Accesses Schematic components collection
Creates ERCViolation objects
8. PowerValidatorο
Purpose: Validates power supply connections
Attributes:
schematic: Schematicpower_net_names: Set[str]- Known power net names
Methods:
validate_power_flags() -> List[ERCViolation]check_power_continuity() -> List[ERCViolation]find_power_conflicts() -> List[ERCViolation]is_power_net(net_name: str) -> bool
Key Validations:
Power Input without driver (WARNING)
Missing PWR_FLAG (WARNING)
Multiple voltage sources (ERROR)
Power net shorts (ERROR)
Relationships:
Accesses Schematic nets
Accesses Schematic components
Creates ERCViolation objects
9. HierarchyValidatorο
Purpose: Validates hierarchical schematic structure
Attributes:
schematic: Schematicchild_schematics: List[Schematic]
Methods:
validate_sheet_pins() -> List[ERCViolation]validate_bus_aliases() -> List[ERCViolation]check_hierarchical_labels() -> List[ERCViolation]
Key Validations:
Sheet pin mismatches (ERROR)
Hierarchical label mismatches (ERROR)
Bus alias inconsistency (ERROR)
Relationships:
Accesses Schematic sheet instances
May access child schematics
Creates ERCViolation objects
Supporting Entitiesο
10. PinConflictMatrixο
Purpose: Defines pin type compatibility rules
Attributes:
matrix: Dict[Tuple[str, str], int]- Pin type pair β severity
Constants:
OK = 0- Connection allowedWARNING = 1- Connection warnsERROR = 2- Connection forbidden
Methods:
check_connection(pin1_type: str, pin2_type: str) -> intset_rule(pin1_type: str, pin2_type: str, severity: int)get_default_matrix() -> Dict- KiCAD default matrixload_from_file(path: str)- Load custom matrix
Default Matrix (partial):
{
("output", "output"): ERROR,
("power_output", "power_output"): ERROR,
("output", "power_output"): ERROR,
("input", "output"): OK,
("bidirectional", "output"): OK,
("passive", "*"): OK, # Wildcard
("unspecified", "*"): WARNING,
}
Relationships:
1:1 with ERCConfig
Used by PinTypeValidator
11. Netο
Purpose: Represents an electrical net (extended from existing)
Additional Attributes for ERC:
drivers: List[Tuple[str, str]]- (component_ref, pin_num) driving netloads: List[Tuple[str, str]]- Input pins on netpower_flags: List[Point]- PWR_FLAG locationsis_power_net: bool- Detected as power net
Methods:
has_driver() -> bool- Check if net is drivendriver_count() -> int- Number of outputsis_properly_powered() -> bool- Power Input has Power Output
Relationships:
N:1 with Schematic (many nets in one schematic)
Referenced by ERCViolation
12. CustomRule (Abstract)ο
Purpose: Base class for user-defined validation rules
Attributes:
rule_id: str- Unique identifierseverity: str- Default severitydescription: str- Human-readable description
Methods:
validate(schematic: Schematic) -> List[ERCViolation]- Abstractget_metadata() -> Dict- Rule information
Relationships:
N:1 with ERCConfig (multiple rules in config)
Creates ERCViolation objects
Data Flow Diagramο
User Code
β
ββ> Create/Load Schematic
β β
β βΌ
β Schematic Object
β β
βββββββββ΄ββ> ElectricalRulesChecker(schematic, config)
β β
β ββ> Initialize Validators
β β ββ> PinTypeValidator
β β ββ> ConnectivityValidator
β β ββ> ComponentValidator
β β ββ> PowerValidator
β β ββ> HierarchyValidator
β β
βΌ βΌ
run_all_checks() Each Validator:
β β
β ββ> Access Schematic Data
β ββ> Apply Validation Rules
β ββ> Create ERCViolations
β ββ> Return Violations
β β
βΌ β
Collect All Violations βββββββββ
β
ββ> Filter by Severity
ββ> Apply Config Overrides
ββ> Suppress Configured Warnings
β
βΌ
Create ERCResult
β
ββ> errors: List[ERCViolation]
ββ> warnings: List[ERCViolation]
ββ> info: List[ERCViolation]
ββ> Statistics
β
βΌ
Return to User
β
ββ> User processes results
ββ> Print summary
ββ> Fix errors
ββ> Re-run ERC
Validation Flow Sequenceο
ElectricalRulesChecker.run_all_checks()
β
ββ[1]β> PinTypeValidator.validate_pin_connections()
β β
β ββ> For each net in schematic:
β β ββ> Get all pins on net
β β ββ> Get pin types from symbol cache
β β ββ> Check each pin pair against matrix
β β ββ> Create ERCViolation if conflict
β β
β ββ> Return violations
β
ββ[2]β> ConnectivityValidator.find_dangling_wires()
β β
β ββ> For each wire:
β β ββ> Count connections at endpoints
β β ββ> Create violation if <2 connections
β β
β ββ> Return violations
β
ββ[3]β> ConnectivityValidator.find_undriven_nets()
β β
β ββ> For each net:
β β ββ> Check if any output pin on net
β β ββ> Create violation if no driver
β β
β ββ> Return violations
β
ββ[4]β> ComponentValidator.find_duplicate_references()
β β
β ββ> Build reference β component map
β ββ> Find duplicates
β ββ> Create violations for duplicates
β
ββ[5]β> PowerValidator.validate_power_flags()
β β
β ββ> For each power net:
β β ββ> Check for Power Output or PWR_FLAG
β β ββ> Create violation if missing
β β
β ββ> Return violations
β
ββ[6]β> HierarchyValidator.validate_sheet_pins()
β β
β ββ> For each hierarchical sheet:
β β ββ> Match pins to labels in child
β β ββ> Create violation if mismatch
β β
β ββ> Return violations
β
ββ> Aggregate all violations into ERCResult
Database Schema (if persisting results)ο
-- ERC Results Table
CREATE TABLE erc_results (
id INTEGER PRIMARY KEY,
schematic_uuid TEXT NOT NULL,
timestamp DATETIME NOT NULL,
total_checks INTEGER,
passed_checks INTEGER,
duration_ms REAL,
has_errors BOOLEAN
);
-- ERC Violations Table
CREATE TABLE erc_violations (
id INTEGER PRIMARY KEY,
result_id INTEGER REFERENCES erc_results(id),
violation_type TEXT NOT NULL,
severity TEXT NOT NULL, -- 'error', 'warning', 'info'
error_code TEXT NOT NULL,
message TEXT NOT NULL,
net_name TEXT,
location_x REAL,
location_y REAL,
suggested_fix TEXT
);
-- Component References in Violations
CREATE TABLE violation_components (
id INTEGER PRIMARY KEY,
violation_id INTEGER REFERENCES erc_violations(id),
component_ref TEXT NOT NULL,
pin_number TEXT
);
-- Suppressed Warnings
CREATE TABLE suppressed_warnings (
id INTEGER PRIMARY KEY,
schematic_uuid TEXT NOT NULL,
error_code TEXT NOT NULL,
component_ref TEXT,
reason TEXT,
suppressed_at DATETIME
);
Extension Pointsο
Adding Custom Validatorsο
from kicad_sch_api.validation import BaseValidator, ERCViolation
class CustomSignalIntegrityValidator(BaseValidator):
"""Custom validator for signal integrity checks."""
def validate(self, schematic: Schematic) -> List[ERCViolation]:
violations = []
# Custom logic
for component in schematic.components:
if self.has_signal_integrity_issue(component):
violations.append(ERCViolation(
violation_type="signal_integrity",
severity="warning",
message="High-speed signal without termination",
component_refs=[component.reference],
error_code="C001"
))
return violations
# Register with ERC
erc = ElectricalRulesChecker(sch)
erc.add_validator(CustomSignalIntegrityValidator())
Custom Pin Conflict Matrixο
# Create custom matrix
custom_matrix = PinConflictMatrix()
# Set custom rule: Allow Output-to-Output (override default error)
custom_matrix.set_rule("output", "output", PinConflictMatrix.WARNING)
# Use in config
config = ERCConfig()
config.pin_conflict_matrix = custom_matrix
erc = ElectricalRulesChecker(sch, config=config)
Summaryο
This ERD defines a comprehensive, extensible ERC validation system with:
5 Core Validators: Pin Type, Connectivity, Component, Power, Hierarchy
3 Result Types: ERCViolation, ERCResult, ERCConfig
Extensibility: Custom rules, configurable matrix, validator plugins
Performance: Optimized for O(n) complexity
Compatibility: Matches KiCAD 7/8 ERC behavior
The system is designed to be:
Modular: Each validator is independent
Configurable: Users can customize all rules
Testable: Clear interfaces for unit testing
Scalable: Efficient for large schematics
Document Version: 1.0 Last Updated: 2024-10-26 Status: Ready for Implementation