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

#include <drc_rule_editor_utils.h>

Public Types

using RuleConverter = std::function<std::shared_ptr<DRC_RE_BASE_CONSTRAINT_DATA>( const std::shared_ptr<DRC_RULE>& )>
 

Static Public Member Functions

static void RegisterRuleConverter (RuleConverter aConverter)
 
static bool IsBoolInputType (const DRC_RULE_EDITOR_CONSTRAINT_NAME &aConstraintType)
 
static bool IsNumericInputType (const DRC_RULE_EDITOR_CONSTRAINT_NAME &aConstraintType)
 
static std::string FormatErrorMessage (const int &aErrorCount, const std::string aErrorMessage)
 
static std::vector< std::shared_ptr< DRC_RE_BASE_CONSTRAINT_DATA > > ParseRules (const wxString &aRules)
 
static bool SaveRules (const wxString &aFilename, const std::vector< std::shared_ptr< DRC_RE_BASE_CONSTRAINT_DATA > > &aRules, const BOARD *aBoard)
 
static wxString GetConstraintCode (DRC_RULE_EDITOR_CONSTRAINT_NAME aConstraintType)
 Translate a rule tree node type into the keyword used by the rules file for that constraint.
 
static std::optional< DRC_RULE_EDITOR_CONSTRAINT_NAMEGetConstraintTypeFromCode (const wxString &aCode)
 Resolve a constraint keyword from a rules file into the corresponding rule tree enumeration value.
 
static wxString ConstraintToKicadDrc (DRC_RULE_EDITOR_CONSTRAINT_NAME aType)
 Convert a constraint type into the keyword used in a .kicad_drc file.
 
static bool ConstraintFromKicadDrc (const wxString &aCode, DRC_RE_BASE_CONSTRAINT_DATA *aData)
 Populate a constraint data object using a keyword from a .kicad_drc file.
 
static bool ValidateNumericCtrl (wxTextCtrl *aTextCtrl, std::string aLabel, bool aCanBeZero, int *aErrorCount, std::string *aValidationMessage)
 Validates a numeric input control, checking if the value is valid, non-empty, and greater than zero.
 
static bool ValidateIntegerCtrl (wxTextCtrl *aTextCtrl, std::string aLabel, bool aCanBeZero, int *aErrorCount, std::string *aValidationMessage)
 Validates an integer input control, ensuring the value is a valid integer, non-empty, and greater than zero.
 
static bool ValidateComboCtrl (wxComboBox *aComboBox, std::string aLabel, int *aErrorCount, std::string *aValidationMessage)
 Validates a combo box control, ensuring that a selection has been made.
 
static bool ValidateMinMaxCtrl (wxTextCtrl *aMinTextCtrl, wxTextCtrl *aMaxTextCtrl, std::string aMinLabel, std::string aMaxLabel, int *aErrorCount, std::string *aValidationMessage)
 Validates the minimum and maximum value controls, ensuring that the minimum value is not greater than the maximum value.
 
static bool ValidateMinPreferredMaxCtrl (wxTextCtrl *aMinTextCtrl, wxTextCtrl *aPreferredTextCtrl, wxTextCtrl *aMaxTextCtrl, std::string aMinLabel, std::string aPreferredLabel, std::string aMaxLabel, int *aErrorCount, std::string *aValidationMessage)
 Validates the minimum, preferred, and maximum value controls, ensuring that:
 
static bool ValidateCheckBoxCtrls (const std::vector< wxCheckBox * > &aCheckboxes, std::string aLabel, int *aErrorCount, std::string *aValidationMessage)
 Validates a list of checkboxes, ensuring that at least one option is selected.
 
static bool ValidateNumericValue (double aValue, bool aCanBeZero, const std::string &aLabel, VALIDATION_RESULT *aResult)
 Validates a numeric value.
 
static bool ValidateNumericString (const std::string &aValueStr, bool aCanBeZero, bool aIntegerOnly, const std::string &aLabel, VALIDATION_RESULT *aResult)
 Validates that a string represents a valid numeric value.
 
static bool ValidateMinMax (double aMin, double aMax, const std::string &aMinLabel, const std::string &aMaxLabel, VALIDATION_RESULT *aResult)
 Validates that min <= max.
 
static bool ValidateMinPreferredMax (double aMin, double aPreferred, double aMax, const std::string &aMinLabel, const std::string &aPrefLabel, const std::string &aMaxLabel, VALIDATION_RESULT *aResult)
 Validates that min <= preferred <= max.
 
static bool ValidateAtLeastOneSelected (const std::vector< bool > &aSelected, const std::string &aLabel, VALIDATION_RESULT *aResult)
 Validates that at least one option is selected.
 
static bool ValidateSelection (int aSelectionIndex, const std::string &aLabel, VALIDATION_RESULT *aResult)
 Validates that a selection has been made (index >= 0).
 

Detailed Description

Definition at line 42 of file drc_rule_editor_utils.h.

Member Typedef Documentation

◆ RuleConverter

using DRC_RULE_EDITOR_UTILS::RuleConverter = std::function<std::shared_ptr<DRC_RE_BASE_CONSTRAINT_DATA>( const std::shared_ptr<DRC_RULE>& )>

Definition at line 45 of file drc_rule_editor_utils.h.

Member Function Documentation

◆ ConstraintFromKicadDrc()

bool DRC_RULE_EDITOR_UTILS::ConstraintFromKicadDrc ( const wxString & aCode,
DRC_RE_BASE_CONSTRAINT_DATA * aData )
static

Populate a constraint data object using a keyword from a .kicad_drc file.

Parameters
aCodeThe keyword read from the rules file.
aDataThe constraint data instance to update.
Returns
True if a matching constraint type was found.

Definition at line 248 of file drc_rule_editor_utils.cpp.

References GetConstraintCode(), GetConstraintTypeFromCode(), and DRC_RE_BASE_CONSTRAINT_DATA::SetConstraintCode().

Referenced by DIALOG_DRC_RULE_EDITOR::buildRuleNodeFromKicadDrc().

◆ ConstraintToKicadDrc()

wxString DRC_RULE_EDITOR_UTILS::ConstraintToKicadDrc ( DRC_RULE_EDITOR_CONSTRAINT_NAME aType)
static

Convert a constraint type into the keyword used in a .kicad_drc file.

Parameters
aTypeThe constraint type to convert.
Returns
The textual representation suitable for a rules file.

Definition at line 242 of file drc_rule_editor_utils.cpp.

References GetConstraintCode().

Referenced by DIALOG_DRC_RULE_EDITOR::buildRuleTreeNode().

◆ FormatErrorMessage()

◆ GetConstraintCode()

wxString DRC_RULE_EDITOR_UTILS::GetConstraintCode ( DRC_RULE_EDITOR_CONSTRAINT_NAME aConstraintType)
static

Translate a rule tree node type into the keyword used by the rules file for that constraint.

Parameters
aConstraintTypeThe constraint type selected in the rule tree.
Returns
The textual keyword for the constraint, or an empty string if no mapping exists.

Definition at line 222 of file drc_rule_editor_utils.cpp.

References sCodeMap.

Referenced by ConstraintFromKicadDrc(), ConstraintToKicadDrc(), and DRC_RULE_LOADER::createConstraintData().

◆ GetConstraintTypeFromCode()

std::optional< DRC_RULE_EDITOR_CONSTRAINT_NAME > DRC_RULE_EDITOR_UTILS::GetConstraintTypeFromCode ( const wxString & aCode)
static

Resolve a constraint keyword from a rules file into the corresponding rule tree enumeration value.

Parameters
aCodeThe textual keyword for the constraint.
Returns
The associated constraint enumeration if found; otherwise an empty optional.

Definition at line 232 of file drc_rule_editor_utils.cpp.

References sCodeReverse.

Referenced by DIALOG_DRC_RULE_EDITOR::buildRuleNodeFromKicadDrc(), and ConstraintFromKicadDrc().

◆ IsBoolInputType()

bool DRC_RULE_EDITOR_UTILS::IsBoolInputType ( const DRC_RULE_EDITOR_CONSTRAINT_NAME & aConstraintType)
static

◆ IsNumericInputType()

◆ ParseRules()

std::vector< std::shared_ptr< DRC_RE_BASE_CONSTRAINT_DATA > > DRC_RULE_EDITOR_UTILS::ParseRules ( const wxString & aRules)
static

◆ RegisterRuleConverter()

void DRC_RULE_EDITOR_UTILS::RegisterRuleConverter ( RuleConverter aConverter)
static

◆ SaveRules()

bool DRC_RULE_EDITOR_UTILS::SaveRules ( const wxString & aFilename,
const std::vector< std::shared_ptr< DRC_RE_BASE_CONSTRAINT_DATA > > & aRules,
const BOARD * aBoard )
static

◆ ValidateAtLeastOneSelected()

bool DRC_RULE_EDITOR_UTILS::ValidateAtLeastOneSelected ( const std::vector< bool > & aSelected,
const std::string & aLabel,
VALIDATION_RESULT * aResult )
static

Validates that at least one option is selected.

Parameters
aSelectedVector of boolean values indicating selection state.
aLabelThe label for error messages.
aResultThe validation result to update.
Returns
True if at least one option is selected; otherwise, false.

Definition at line 659 of file drc_rule_editor_utils.cpp.

References VALIDATION_RESULT::AddError().

◆ ValidateCheckBoxCtrls()

bool DRC_RULE_EDITOR_UTILS::ValidateCheckBoxCtrls ( const std::vector< wxCheckBox * > & aCheckboxes,
std::string aLabel,
int * aErrorCount,
std::string * aValidationMessage )
static

Validates a list of checkboxes, ensuring that at least one option is selected.

Parameters
aCheckboxesA vector of wxCheckBox controls to validate.
aLabelThe label for the checkbox list.
aErrorCountThe count of errors encountered during validation.
aValidationMessageThe validation error messages accumulated.
Returns
True if the validation passes; otherwise, false.

Definition at line 506 of file drc_rule_editor_utils.cpp.

References FormatErrorMessage(), VALIDATE_CHECKBOX_LIST::GetValidationState(), and VALIDATE_CHECKBOX_LIST::NotSelected.

◆ ValidateComboCtrl()

bool DRC_RULE_EDITOR_UTILS::ValidateComboCtrl ( wxComboBox * aComboBox,
std::string aLabel,
int * aErrorCount,
std::string * aValidationMessage )
static

Validates a combo box control, ensuring that a selection has been made.

Parameters
aComboBoxThe combo box control to validate.
aLabelThe label of the combo box for error messages.
aErrorCountThe count of errors encountered during validation.
aValidationMessageThe validation error messages accumulated.
Returns
True if the control value is valid; otherwise, false.

Definition at line 396 of file drc_rule_editor_utils.cpp.

References FormatErrorMessage(), VALIDATOR_COMBO_CTRL::GetValidationState(), and VALIDATOR_COMBO_CTRL::NothingSelected.

◆ ValidateIntegerCtrl()

bool DRC_RULE_EDITOR_UTILS::ValidateIntegerCtrl ( wxTextCtrl * aTextCtrl,
std::string aLabel,
bool aCanBeZero,
int * aErrorCount,
std::string * aValidationMessage )
static

Validates an integer input control, ensuring the value is a valid integer, non-empty, and greater than zero.

Parameters
aTextCtrlThe text control to validate.
aLabelThe label of the control for error messages.
aCanBeZeroIf true, zero is allowed; otherwise, the value must be greater than zero.
aErrorCountThe count of errors encountered during validation.
aValidationMessageThe validation error messages accumulated.
Returns
True if the control value is valid; otherwise, false.

Definition at line 355 of file drc_rule_editor_utils.cpp.

References VALIDATOR_NUMERIC_CTRL::Empty, FormatErrorMessage(), VALIDATOR_NUMERIC_CTRL::GetValidationState(), VALIDATOR_NUMERIC_CTRL::NotGreaterThanZero, and VALIDATOR_NUMERIC_CTRL::NotInteger.

◆ ValidateMinMax()

bool DRC_RULE_EDITOR_UTILS::ValidateMinMax ( double aMin,
double aMax,
const std::string & aMinLabel,
const std::string & aMaxLabel,
VALIDATION_RESULT * aResult )
static

Validates that min <= max.

Parameters
aMinThe minimum value.
aMaxThe maximum value.
aMinLabelThe label for the minimum value.
aMaxLabelThe label for the maximum value.
aResultThe validation result to update.
Returns
True if min <= max; otherwise, false.

Definition at line 616 of file drc_rule_editor_utils.cpp.

References VALIDATION_RESULT::AddError().

◆ ValidateMinMaxCtrl()

bool DRC_RULE_EDITOR_UTILS::ValidateMinMaxCtrl ( wxTextCtrl * aMinTextCtrl,
wxTextCtrl * aMaxTextCtrl,
std::string aMinLabel,
std::string aMaxLabel,
int * aErrorCount,
std::string * aValidationMessage )
static

Validates the minimum and maximum value controls, ensuring that the minimum value is not greater than the maximum value.

Parameters
aMinTextCtrlThe minimum value text control to validate.
aMaxTextCtrlThe maximum value text control to validate.
aMinLabelThe label for the minimum value text control.
aMaxLabelThe label for the maximum value text control.
aErrorCountThe count of errors encountered during validation.
aValidationMessageThe validation error messages accumulated.
Returns
True if the validation passes; otherwise, false.

Definition at line 422 of file drc_rule_editor_utils.cpp.

References FormatErrorMessage(), VALIDATE_MIN_MAX_CTRL::GetValidationState(), and VALIDATE_MIN_MAX_CTRL::MinGreaterThanMax.

◆ ValidateMinPreferredMax()

bool DRC_RULE_EDITOR_UTILS::ValidateMinPreferredMax ( double aMin,
double aPreferred,
double aMax,
const std::string & aMinLabel,
const std::string & aPrefLabel,
const std::string & aMaxLabel,
VALIDATION_RESULT * aResult )
static

Validates that min <= preferred <= max.

Parameters
aMinThe minimum value.
aPreferredThe preferred value.
aMaxThe maximum value.
aMinLabelThe label for the minimum value.
aPrefLabelThe label for the preferred value.
aMaxLabelThe label for the maximum value.
aResultThe validation result to update.
Returns
True if min <= preferred <= max; otherwise, false.

Definition at line 629 of file drc_rule_editor_utils.cpp.

References VALIDATION_RESULT::AddError().

◆ ValidateMinPreferredMaxCtrl()

bool DRC_RULE_EDITOR_UTILS::ValidateMinPreferredMaxCtrl ( wxTextCtrl * aMinTextCtrl,
wxTextCtrl * aPreferredTextCtrl,
wxTextCtrl * aMaxTextCtrl,
std::string aMinLabel,
std::string aPreferredLabel,
std::string aMaxLabel,
int * aErrorCount,
std::string * aValidationMessage )
static

Validates the minimum, preferred, and maximum value controls, ensuring that:

  • The minimum value is not greater than the preferred value.
  • The preferred value is not greater than the maximum value.
  • The minimum value is not greater than the maximum value.
Parameters
aMinTextCtrlThe minimum value text control to validate.
aPreferredTextCtrlThe preferred value text control to validate.
aMaxTextCtrlThe maximum value text control to validate.
aMinLabelThe label for the minimum value text control.
aPreferredLabelThe label for the preferred value text control.
aMaxLabelThe label for the maximum value text control.
aErrorCountThe count of errors encountered during validation.
aValidationMessageThe validation error messages accumulated.
Returns
True if the validation passes; otherwise, false.

Definition at line 455 of file drc_rule_editor_utils.cpp.

References FormatErrorMessage(), VALIDATE_MIN_PREFERRED_MAX_CTRL::GetValidationState(), VALIDATE_MIN_PREFERRED_MAX_CTRL::MinGreaterThanMax, VALIDATE_MIN_PREFERRED_MAX_CTRL::MinGreaterThanPreferred, and VALIDATE_MIN_PREFERRED_MAX_CTRL::PreferredGreaterThanMax.

◆ ValidateNumericCtrl()

bool DRC_RULE_EDITOR_UTILS::ValidateNumericCtrl ( wxTextCtrl * aTextCtrl,
std::string aLabel,
bool aCanBeZero,
int * aErrorCount,
std::string * aValidationMessage )
static

Validates a numeric input control, checking if the value is valid, non-empty, and greater than zero.

Parameters
aTextCtrlThe text control to validate.
aLabelThe label of the control for error messages.
aCanBeZeroIf true, zero is allowed; otherwise, the value must be greater than zero.
aErrorCountThe count of errors encountered during validation.
aValidationMessageThe validation error messages accumulated.
Returns
True if the control value is valid; otherwise, false.

Definition at line 314 of file drc_rule_editor_utils.cpp.

References VALIDATOR_NUMERIC_CTRL::Empty, FormatErrorMessage(), VALIDATOR_NUMERIC_CTRL::GetValidationState(), VALIDATOR_NUMERIC_CTRL::NotGreaterThanZero, and VALIDATOR_NUMERIC_CTRL::NotNumeric.

◆ ValidateNumericString()

bool DRC_RULE_EDITOR_UTILS::ValidateNumericString ( const std::string & aValueStr,
bool aCanBeZero,
bool aIntegerOnly,
const std::string & aLabel,
VALIDATION_RESULT * aResult )
static

Validates that a string represents a valid numeric value.

Parameters
aValueStrThe string to validate.
aCanBeZeroIf true, zero is allowed; otherwise, the value must be greater than zero.
aIntegerOnlyIf true, only integer values are accepted.
aLabelThe label for error messages.
aResultThe validation result to update.
Returns
True if the string is a valid number; otherwise, false.

Definition at line 555 of file drc_rule_editor_utils.cpp.

References VALIDATION_RESULT::AddError().

◆ ValidateNumericValue()

bool DRC_RULE_EDITOR_UTILS::ValidateNumericValue ( double aValue,
bool aCanBeZero,
const std::string & aLabel,
VALIDATION_RESULT * aResult )
static

Validates a numeric value.

Parameters
aValueThe value to validate.
aCanBeZeroIf true, zero is allowed; otherwise, the value must be greater than zero.
aLabelThe label for error messages.
aResultThe validation result to update.
Returns
True if the value is valid; otherwise, false.

Definition at line 542 of file drc_rule_editor_utils.cpp.

References VALIDATION_RESULT::AddError().

◆ ValidateSelection()

bool DRC_RULE_EDITOR_UTILS::ValidateSelection ( int aSelectionIndex,
const std::string & aLabel,
VALIDATION_RESULT * aResult )
static

Validates that a selection has been made (index >= 0).

Parameters
aSelectionIndexThe selection index (-1 for no selection).
aLabelThe label for error messages.
aResultThe validation result to update.
Returns
True if a selection has been made; otherwise, false.

Definition at line 674 of file drc_rule_editor_utils.cpp.

References VALIDATION_RESULT::AddError().


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