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 validated

  • config: ERCConfig - Configuration for validation rules

  • validators: List[Validator] - All registered validators

Methods:

  • run_all_checks() -> ERCResult - Execute all validators

  • run_check(check_type: str) -> List[ERCViolation] - Run specific check

  • add_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 description

  • component_refs: List[str] - Affected component references

  • net_name: Optional[str] - Affected net name

  • pin_numbers: List[str] - Affected pin numbers

  • location: Optional[Point] - Schematic coordinates

  • suggested_fix: Optional[str] - Recommended fix

  • error_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 violations

  • warnings: List[ERCViolation] - Warning-level violations

  • info: List[ERCViolation] - Info-level violations

  • total_checks: int - Total validations performed

  • passed_checks: int - Number of passed checks

  • duration_ms: float - Execution time

Methods:

  • has_errors() -> bool - Quick error check

  • summary() -> str - Human-readable summary

  • to_dict() -> Dict - JSON-serializable dict

  • to_json() -> str - JSON string

  • filter_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 levels

  • suppressed_warnings: Set[str] - Suppressed warning codes

  • custom_rules: List[CustomRule] - User-defined rules

  • pin_conflict_matrix: PinConflictMatrix - Pin compatibility matrix

Methods:

  • set_severity(rule: str, severity: str) - Override default severity

  • suppress_warning(code: str, component: str) - Suppress specific warning

  • add_custom_rule(rule: CustomRule) - Add user rule

  • load_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 rules

  • schematic: 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: Schematic

  • min_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: Schematic

  • reference_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: Schematic

  • power_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: Schematic

  • child_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 allowed

  • WARNING = 1 - Connection warns

  • ERROR = 2 - Connection forbidden

Methods:

  • check_connection(pin1_type: str, pin2_type: str) -> int

  • set_rule(pin1_type: str, pin2_type: str, severity: int)

  • get_default_matrix() -> Dict - KiCAD default matrix

  • load_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 net

  • loads: List[Tuple[str, str]] - Input pins on net

  • power_flags: List[Point] - PWR_FLAG locations

  • is_power_net: bool - Detected as power net

Methods:

  • has_driver() -> bool - Check if net is driven

  • driver_count() -> int - Number of outputs

  • is_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 identifier

  • severity: str - Default severity

  • description: str - Human-readable description

Methods:

  • validate(schematic: Schematic) -> List[ERCViolation] - Abstract

  • get_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