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

A constraint on a scalar value (counts, dimensions, etc.), supporting exact, min, and max bounds. More...

Classes

struct  PARSED_SCALAR
 

Public Types

enum class  ROLE { COUNT , DIMENSION }
 

Public Member Functions

bool Match (int aValue) const
 Test if a value satisfies this constraint.
 
bool IsExact () const
 
std::optional< int > GetMin () const
 
std::optional< int > GetMax () const
 
std::string Format (int aValue) const
 Format a value for human-readable display.
 
std::string Describe () const
 

Static Public Member Functions

static SCALAR_CONSTRAINT FromJson (const nlohmann::json &aJson, ROLE aKind)
 Parse a scalar constraint from JSON.
 
static SCALAR_CONSTRAINT Exact (int aValue, ROLE aKind=ROLE::COUNT)
 

Static Private Member Functions

static PARSED_SCALAR parseScalar (const nlohmann::json &aJson, ROLE aKind)
 Parse a single bound value from JSON.
 

Private Attributes

std::optional< int > m_min
 
std::optional< int > m_max
 
std::optional< EDA_UNITSm_displayUnits
 Original units for display.
 
ROLE m_kind = ROLE::COUNT
 

Detailed Description

A constraint on a scalar value (counts, dimensions, etc.), supporting exact, min, and max bounds.

For ROLE::COUNT, bare integers are literal count values. For ROLE::DIMENSION, bare integers are interpreted as mm, and strings can specify units (e.g. "5 mil", "0.127 mm"). Internally, dimensions are always stored in KiCad internal units (nm).

JSON input can be:

  • A bare integer: exact match (mm for DIMENSION, count for COUNT)
  • A string with units: exact match, e.g. "5 mil" (DIMENSION only)
  • An object: { "min": ..., "max": ..., "exact": ... }

Definition at line 80 of file board_expectations.cpp.

Member Enumeration Documentation

◆ ROLE

enum class SCALAR_CONSTRAINT::ROLE
strong
Enumerator
COUNT 

A simple count of items (e.g. number of footprints, nets, etc.)

DIMENSION 

A linear dimension (e.g. track width, clearance)

Definition at line 83 of file board_expectations.cpp.

Member Function Documentation

◆ Describe()

std::string SCALAR_CONSTRAINT::Describe ( ) const
inline

Definition at line 197 of file board_expectations.cpp.

References Format(), m_max, and m_min.

◆ Exact()

static SCALAR_CONSTRAINT SCALAR_CONSTRAINT::Exact ( int aValue,
ROLE aKind = ROLE::COUNT )
inlinestatic

Definition at line 149 of file board_expectations.cpp.

References COUNT, m_kind, m_max, and m_min.

Referenced by createLayerExpectation().

◆ Format()

std::string SCALAR_CONSTRAINT::Format ( int aValue) const
inline

Format a value for human-readable display.

Counts are shown as plain integers. Dimensions are shown in the original units from the JSON, with the raw internal-unit value appended for debugging: e.g. "5 mil (127000 nm)"

Definition at line 184 of file board_expectations.cpp.

References COUNT, m_displayUnits, m_kind, MM, pcbIUScale, and EDA_UNIT_UTILS::UI::StringFromValue().

Referenced by CheckConstraint(), and Describe().

◆ FromJson()

static SCALAR_CONSTRAINT SCALAR_CONSTRAINT::FromJson ( const nlohmann::json & aJson,
ROLE aKind )
inlinestatic

Parse a scalar constraint from JSON.

Parameters
aJsonThe JSON value to parse
aKindWhether to interpret bare integers as counts or mm dimensions

Definition at line 97 of file board_expectations.cpp.

References m_displayUnits, m_kind, m_max, m_min, and parseScalar().

Referenced by createItemExprExpectation(), createLayerExpectation(), createNetClassExpectation(), and createNetExpectation().

◆ GetMax()

std::optional< int > SCALAR_CONSTRAINT::GetMax ( ) const
inline

Definition at line 175 of file board_expectations.cpp.

References m_max.

Referenced by CheckConstraint().

◆ GetMin()

std::optional< int > SCALAR_CONSTRAINT::GetMin ( ) const
inline

Definition at line 174 of file board_expectations.cpp.

References m_min.

Referenced by CheckConstraint().

◆ IsExact()

bool SCALAR_CONSTRAINT::IsExact ( ) const
inline

Definition at line 172 of file board_expectations.cpp.

References m_max, and m_min.

Referenced by CheckConstraint().

◆ Match()

bool SCALAR_CONSTRAINT::Match ( int aValue) const
inline

Test if a value satisfies this constraint.

Definition at line 161 of file board_expectations.cpp.

References m_max, and m_min.

◆ parseScalar()

static PARSED_SCALAR SCALAR_CONSTRAINT::parseScalar ( const nlohmann::json & aJson,
ROLE aKind )
inlinestaticprivate

Parse a single bound value from JSON.

For COUNT: must be an integer. For DIMENSION: integer (mm), float (mm), or string with units (e.g. "5 mil").

Returns
The parsed value in internal units, and the detected display units (if a string with explicit units was provided).

Definition at line 234 of file board_expectations.cpp.

References COUNT, DIMENSION, EDA_UNIT_UTILS::UI::DoubleValueFromString(), EDA_UNIT_UTILS::FetchUnitsFromString(), KiROUND(), MM, and pcbIUScale.

Referenced by FromJson().

Member Data Documentation

◆ m_displayUnits

std::optional<EDA_UNITS> SCALAR_CONSTRAINT::m_displayUnits
private

Original units for display.

Definition at line 276 of file board_expectations.cpp.

Referenced by Format(), and FromJson().

◆ m_kind

ROLE SCALAR_CONSTRAINT::m_kind = ROLE::COUNT
private

Definition at line 277 of file board_expectations.cpp.

Referenced by Exact(), Format(), and FromJson().

◆ m_max

std::optional<int> SCALAR_CONSTRAINT::m_max
private

Definition at line 275 of file board_expectations.cpp.

Referenced by Describe(), Exact(), FromJson(), GetMax(), IsExact(), and Match().

◆ m_min

std::optional<int> SCALAR_CONSTRAINT::m_min
private

Definition at line 274 of file board_expectations.cpp.

Referenced by Describe(), Exact(), FromJson(), GetMin(), IsExact(), and Match().


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