21#ifndef KICAD_PROPERTY_VALIDATORS_H 
   22#define KICAD_PROPERTY_VALIDATORS_H 
   51        return wxString::Format( wxS( 
"Value must be less than or equal to %s" ),
 
 
 
   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>() || aValue.CheckType<std::optional<int>>(),
 
  110                      "Expecting int-containing value" );
 
  114        if( aValue.CheckType<
int>() )
 
  116            val = aValue.As<
int>();
 
  118        else if( aValue.CheckType<std::optional<int>>() )
 
  120            if( aValue.As<std::optional<int>>().has_value() )
 
  121                val = aValue.As<std::optional<int>>().value();
 
  127            return std::make_unique<VALIDATION_ERROR_TOO_LARGE<int>>( val, Max );
 
  129            return std::make_unique<VALIDATION_ERROR_TOO_SMALL<int>>( val, Min );
 
 
  136        wxASSERT_MSG( aValue.CheckType<
int>() || aValue.CheckType<std::optional<int>>(),
 
  137                      "Expecting int-containing value" );
 
  141        if( aValue.CheckType<
int>() )
 
  143            val = aValue.As<
int>();
 
  145        else if( aValue.CheckType<std::optional<int>>() )
 
  147            if( aValue.As<std::optional<int>>().has_value() )
 
  148                val = aValue.As<std::optional<int>>().value();
 
  154            return std::make_unique<VALIDATION_ERROR_TOO_SMALL<int>>( val, 0 );
 
 
  161        wxASSERT_MSG( aValue.CheckType<
double>(), 
"Expecting double-containing value" );
 
  163        double val = aValue.As<
double>();
 
  167            return std::make_unique<VALIDATION_ERROR_TOO_LARGE<double>>( val, 1.0,
 
  172            return std::make_unique<VALIDATION_ERROR_TOO_SMALL<double>>( val, 0.0,
 
 
 
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.
 
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.