KiCad PCB EDA Suite
|
Unit registry that provides centralized unit string mapping and conversion. More...
#include <text_eval_units.h>
Classes | |
struct | UnitInfo |
Unit information structure. More... | |
Static Public Member Functions | |
static constexpr Unit | parseUnit (std::string_view unitStr) noexcept |
Parse a unit string and return the corresponding Unit enum. | |
static constexpr std::string_view | getUnitString (Unit unit) noexcept |
Get the unit string for a given Unit enum. | |
static std::vector< std::string > | getAllUnitStrings () |
Get all unit strings in parsing order (longest first) | |
static constexpr double | getConversionFactor (Unit fromUnit, Unit toUnit) noexcept |
Get conversion factor from one unit to another. | |
static constexpr Unit | fromEdaUnits (EDA_UNITS edaUnits) noexcept |
Convert EDA_UNITS to text evaluator Unit enum. | |
static constexpr double | convertValue (double value, Unit fromUnit, Unit toUnit) noexcept |
Convert a value with units to target units. | |
static double | convertToEdaUnits (double value, std::string_view unitStr, EDA_UNITS targetUnits) |
Convert a value with unit string to target EDA_UNITS. | |
static constexpr bool | isValidUnit (std::string_view unitStr) noexcept |
Check if a string is a valid unit. | |
static std::optional< UnitInfo > | getUnitInfo (Unit unit) noexcept |
Get unit information for debugging/display purposes. | |
Static Private Attributes | |
static constexpr std::array< UnitInfo, 15 > | s_unitTable |
Unit registry that provides centralized unit string mapping and conversion.
This class uses magic_enum to provide compile-time unit string mapping and runtime unit parsing/conversion capabilities. All unit-related operations in the text evaluator should use this registry to ensure consistency.
Definition at line 74 of file text_eval_units.h.
|
inlinestatic |
Convert a value with unit string to target EDA_UNITS.
value | The value to convert |
unitStr | Source unit string |
targetUnits | Target EDA_UNITS |
Definition at line 233 of file text_eval_units.h.
References convertValue(), fromEdaUnits(), text_eval_units::INVALID, and parseUnit().
Referenced by KIEVAL_UNIT_CONV::convertToDefaultUnits().
|
inlinestaticconstexprnoexcept |
Convert a value with units to target units.
value | The value to convert |
fromUnit | Source unit |
toUnit | Target unit |
Definition at line 222 of file text_eval_units.h.
References getConversionFactor().
Referenced by convertToEdaUnits().
|
inlinestaticconstexprnoexcept |
Convert EDA_UNITS to text evaluator Unit enum.
edaUnits | The EDA_UNITS value |
Definition at line 198 of file text_eval_units.h.
References CM, text_eval_units::CM, text_eval_units::DEG, DEGREES, FS, text_eval_units::FS, INCH, text_eval_units::INCH, text_eval_units::MIL, MILS, MM, text_eval_units::MM, PS, text_eval_units::PS, PS_PER_CM, text_eval_units::PS_PER_CM, text_eval_units::PS_PER_IN, PS_PER_INCH, PS_PER_MM, text_eval_units::PS_PER_MM, UM, and text_eval_units::UM.
Referenced by convertToEdaUnits().
|
inlinestatic |
Get all unit strings in parsing order (longest first)
Definition at line 154 of file text_eval_units.h.
References info, text_eval_units::INVALID, and s_unitTable.
Referenced by EXPRESSION_EVALUATOR::expandVariablesOutsideExpressions().
|
inlinestaticconstexprnoexcept |
Get conversion factor from one unit to another.
fromUnit | Source unit |
toUnit | Target unit |
Definition at line 173 of file text_eval_units.h.
References info, and s_unitTable.
Referenced by convertValue().
|
inlinestaticnoexcept |
Get unit information for debugging/display purposes.
unit | The unit to get information for |
Definition at line 257 of file text_eval_units.h.
References info, and s_unitTable.
|
inlinestaticconstexprnoexcept |
Get the unit string for a given Unit enum.
unit | The Unit enum value |
Definition at line 141 of file text_eval_units.h.
References info, and s_unitTable.
|
inlinestaticconstexprnoexcept |
Check if a string is a valid unit.
unitStr | The string to check |
Definition at line 248 of file text_eval_units.h.
References text_eval_units::INVALID, and parseUnit().
|
inlinestaticconstexprnoexcept |
Parse a unit string and return the corresponding Unit enum.
unitStr | The unit string to parse |
Definition at line 121 of file text_eval_units.h.
References info, text_eval_units::INVALID, and s_unitTable.
Referenced by convertToEdaUnits(), isValidUnit(), and KIEVAL_UNIT_CONV::parseUnit().
|
staticconstexprprivate |
Definition at line 88 of file text_eval_units.h.
Referenced by getAllUnitStrings(), getConversionFactor(), getUnitInfo(), getUnitString(), and parseUnit().