21#ifndef KICAD_PROPERTY_VALIDATORS_H
22#define KICAD_PROPERTY_VALIDATORS_H
50 bool addUnit =
DataType != EDA_DATA_TYPE::UNITLESS;
51 return wxString::Format( wxS(
"Value must be less than or equal to %s" ),
74 bool addUnit =
DataType != EDA_DATA_TYPE::UNITLESS;
75 return wxString::Format( wxS(
"Value must be greater than or equal to %s" ),
106 template<
int Min,
int Max>
109 wxASSERT_MSG( aValue.CheckType<
int>(),
"Expecting int-containing value" );
111 int val = aValue.As<
int>();
114 return std::make_unique<VALIDATION_ERROR_TOO_LARGE<int>>( val, Max );
116 return std::make_unique<VALIDATION_ERROR_TOO_SMALL<int>>( val, Min );
123 wxASSERT_MSG( aValue.CheckType<
int>(),
"Expecting int-containing value" );
125 int val = aValue.As<
int>();
128 return std::make_unique<VALIDATION_ERROR_TOO_SMALL<int>>( val, 0 );
135 wxASSERT_MSG( aValue.CheckType<
double>(),
"Expecting double-containing value" );
137 double val = aValue.As<
double>();
141 return std::make_unique<VALIDATION_ERROR_TOO_LARGE<double>>( val, 1.0,
142 EDA_DATA_TYPE::UNITLESS );
146 return std::make_unique<VALIDATION_ERROR_TOO_SMALL<double>>( val, 0.0,
147 EDA_DATA_TYPE::UNITLESS );
A base class for most all the KiCad significant classes used in schematics and boards.
A set of generic validators.
static VALIDATOR_RESULT PositiveRatioValidator(const wxAny &&aValue, EDA_ITEM *aItem)
static VALIDATOR_RESULT PositiveIntValidator(const wxAny &&aValue, EDA_ITEM *aItem)
static VALIDATOR_RESULT RangeIntValidator(const wxAny &&aValue, EDA_ITEM *aItem)
wxString StringFromValue(double aValue, bool aAddUnitLabel=false, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
Converts aValue in internal units into a united string.
A validator for use when you just need to return an error string rather than also packaging some othe...
wxString Format(UNITS_PROVIDER *aUnits) const override
VALIDATION_ERROR_MSG(const wxString &aMessage)
wxString Format(UNITS_PROVIDER *aUnits) const override
VALIDATION_ERROR_TOO_LARGE(T aActual, T aMaximum, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
VALIDATION_ERROR_TOO_SMALL(T aActual, T aMinimum, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
wxString Format(UNITS_PROVIDER *aUnits) const override
Represents an error returned by a validator and contains enough data to format an error message.
EDA_DATA_TYPE
The type of unit.
std::optional< std::unique_ptr< VALIDATION_ERROR > > VALIDATOR_RESULT
Null optional means validation succeeded.