KiCad PCB EDA Suite
Loading...
Searching...
No Matches
DRC_RULE_LOADER Class Reference

Loads DRC rules from .kicad_dru files and converts them to panel entries. More...

#include <drc_re_rule_loader.h>

Public Member Functions

 DRC_RULE_LOADER ()
 
std::vector< DRC_RE_LOADED_PANEL_ENTRYLoadRule (const DRC_RULE &aRule, const wxString &aOriginalText)
 Load a single DRC_RULE and convert it to panel entries.
 
std::vector< DRC_RE_LOADED_PANEL_ENTRYLoadFile (const wxString &aPath)
 Load all rules from a .kicad_dru file.
 
std::vector< DRC_RE_LOADED_PANEL_ENTRYLoadFromString (const wxString &aRulesText)
 Load rules from a text string.
 

Private Member Functions

std::shared_ptr< DRC_RE_BASE_CONSTRAINT_DATAcreateConstraintData (DRC_RULE_EDITOR_CONSTRAINT_NAME aPanel, const DRC_RULE &aRule, const std::set< DRC_CONSTRAINT_T > &aClaimedConstraints)
 Create the appropriate constraint data object for a panel type.
 
const DRC_CONSTRAINTfindConstraint (const DRC_RULE &aRule, DRC_CONSTRAINT_T aType)
 Find a constraint of a specific type in a rule.
 
double toMM (int aValue)
 Convert internal units (nanometers) to millimeters.
 
wxString extractRuleText (const wxString &aContent, const wxString &aRuleName)
 Extract the complete original text of a rule from file content.
 
wxString extractRuleBody (const wxString &aOriginalText)
 Extract the body of a rule from its original text, stripping the (rule "name" ...) wrapper.
 
wxString extractRuleComment (const wxString &aOriginalText)
 Extract comment lines from a rule.
 
wxString cleanStrippedCondition (const wxString &aCondition)
 Clean up a condition string after auto-generated tokens have been removed.
 

Private Attributes

DRC_PANEL_MATCHER m_matcher
 

Detailed Description

Loads DRC rules from .kicad_dru files and converts them to panel entries.

This class handles the conversion of text-based DRC rules into the appropriate graphical panel representations. Rules with multiple constraints may be split across multiple panel entries, with the condition and severity duplicated to each.

Definition at line 47 of file drc_re_rule_loader.h.

Constructor & Destructor Documentation

◆ DRC_RULE_LOADER()

DRC_RULE_LOADER::DRC_RULE_LOADER ( )

Definition at line 48 of file drc_re_rule_loader.cpp.

Member Function Documentation

◆ cleanStrippedCondition()

wxString DRC_RULE_LOADER::cleanStrippedCondition ( const wxString & aCondition)
private

Clean up a condition string after auto-generated tokens have been removed.

Strips empty parentheses, collapsed operators, and dangling leading/trailing operators.

Definition at line 118 of file drc_re_rule_loader.cpp.

Referenced by createConstraintData(), and LoadRule().

◆ createConstraintData()

std::shared_ptr< DRC_RE_BASE_CONSTRAINT_DATA > DRC_RULE_LOADER::createConstraintData ( DRC_RULE_EDITOR_CONSTRAINT_NAME aPanel,
const DRC_RULE & aRule,
const std::set< DRC_CONSTRAINT_T > & aClaimedConstraints )
private

◆ extractRuleBody()

wxString DRC_RULE_LOADER::extractRuleBody ( const wxString & aOriginalText)
private

Extract the body of a rule from its original text, stripping the (rule "name" ...) wrapper.

Handles both quoted and unquoted rule names.

Parameters
aOriginalTextThe full original text of a single rule.
Returns
The inner body (constraints, conditions) without the rule wrapper.

Definition at line 71 of file drc_re_rule_loader.cpp.

Referenced by LoadRule().

◆ extractRuleComment()

wxString DRC_RULE_LOADER::extractRuleComment ( const wxString & aOriginalText)
private

Extract comment lines from a rule.

Comments are lines starting with # inside the rule block.

Parameters
aOriginalTextRule text.
Returns
Extracted comment text (empty if none).

Definition at line 92 of file drc_re_rule_loader.cpp.

Referenced by LoadRule().

◆ extractRuleText()

wxString DRC_RULE_LOADER::extractRuleText ( const wxString & aContent,
const wxString & aRuleName )
private

Extract the complete original text of a rule from file content.

Parameters
aContentThe full file content.
aRuleNameThe name of the rule to extract.
Returns
The complete rule text including (rule ...) wrapper, or empty if not found.

Definition at line 682 of file drc_re_rule_loader.cpp.

Referenced by LoadFromString().

◆ findConstraint()

const DRC_CONSTRAINT * DRC_RULE_LOADER::findConstraint ( const DRC_RULE & aRule,
DRC_CONSTRAINT_T aType )
private

Find a constraint of a specific type in a rule.

Parameters
aRuleThe rule to search.
aTypeThe constraint type to find.
Returns
Pointer to the constraint, or nullptr if not found.

Definition at line 59 of file drc_re_rule_loader.cpp.

References DRC_RULE::m_Constraints, and DRC_CONSTRAINT::m_Type.

Referenced by createConstraintData(), and LoadRule().

◆ LoadFile()

std::vector< DRC_RE_LOADED_PANEL_ENTRY > DRC_RULE_LOADER::LoadFile ( const wxString & aPath)

Load all rules from a .kicad_dru file.

Parameters
aPathPath to the rules file.
Returns
Vector of panel entries for all rules in the file.

Definition at line 773 of file drc_re_rule_loader.cpp.

References LoadFromString().

Referenced by DIALOG_DRC_RULE_EDITOR::LoadExistingRules().

◆ LoadFromString()

◆ LoadRule()

std::vector< DRC_RE_LOADED_PANEL_ENTRY > DRC_RULE_LOADER::LoadRule ( const DRC_RULE & aRule,
const wxString & aOriginalText )

Load a single DRC_RULE and convert it to panel entries.

If the rule contains more constraints than a single panel can handle, it will be split into multiple entries, preserving order.

Parameters
aRuleThe parsed DRC rule to convert.
aOriginalTextThe original text of the rule for round-trip fidelity.
Returns
Vector of panel entries representing the rule.

Definition at line 469 of file drc_re_rule_loader.cpp.

References ALLOWED_ORIENTATION, ASSERTION_CONSTRAINT, B_SilkS, cleanStrippedCondition(), createConstraintData(), CUSTOM_RULE, extractRuleBody(), extractRuleComment(), F_SilkS, findConstraint(), DRC_RULE_CONDITION::GetExpression(), DRC_RE_LOADED_PANEL_ENTRY::layerSource, DRC_RULE::m_Condition, DRC_RULE::m_LayerCondition, DRC_RULE::m_LayerSource, m_matcher, DRC_RULE::m_Name, DRC_RULE::m_Severity, DRC_CONSTRAINT::m_Test, DRC_RE_LOADED_PANEL_ENTRY::originalRuleText, PERMITTED_LAYERS, SILK_CLEARANCE_CONSTRAINT, SILK_TO_SILK_CLEARANCE, SILK_TO_SOLDERMASK_CLEARANCE, VIA_STYLE, and VIAS_UNDER_SMD.

Referenced by LoadFromString().

◆ toMM()

double DRC_RULE_LOADER::toMM ( int aValue)
private

Convert internal units (nanometers) to millimeters.

Definition at line 53 of file drc_re_rule_loader.cpp.

Referenced by createConstraintData().

Member Data Documentation

◆ m_matcher

DRC_PANEL_MATCHER DRC_RULE_LOADER::m_matcher
private

Definition at line 142 of file drc_re_rule_loader.h.

Referenced by LoadRule().


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