36#include <wx/validate.h>
37#include <wx/propgrid/property.h>
63#define TYPE_HASH( x ) typeid( x ).hash_code()
64#define TYPE_NAME( x ) typeid( x ).name()
67template<
typename Owner,
typename T>
76template<
typename Owner,
typename T,
typename FuncType>
88 return ( aOwner->*
m_func )();
95template<
typename Owner,
typename T>
104template<
typename Owner,
typename T,
typename FuncType>
116 ( aOwner->*
m_func )( aValue );
124template<
typename Owner,
typename T,
typename Base = Owner>
192 m_writeableFunc( [](
INSPECTABLE*)->bool {
return true; } ),
193 m_validator( NullValidator )
201 const wxString&
Name()
const {
return m_name; }
209 static wxPGChoices
empty;
235 return m_availFunc( aObject );
249 return m_writeableFunc( aObject );
254 m_writeableFunc = aFunc;
286 m_isInternal = aIsInternal;
293 m_isDeprecated = aIsDeprecated;
300 m_hideFromLibraryEditors = aIsHidden;
304 wxString
Group()
const {
return m_group; }
309 m_validator = aValidator;
315 return m_validator( std::move( aValue ), aItem );
325 void set(
void* aObject, T aValue )
332 if( std::is_same<T, wxVariant>::value )
334 wxVariant var =
static_cast<wxVariant
>( aValue );
335 wxAny pv = getter( aObject );
337 if( pv.CheckType<
unsigned>() )
339 a =
static_cast<unsigned>( var.GetLong() );
348 setter( aObject, a );
352 T
get(
const void* aObject )
const
354 wxAny a = getter( aObject );
356 if ( !( std::is_enum<T>::value && a.CheckType<
int>() ) && !a.CheckType<T>() )
357 throw std::invalid_argument(
"Invalid requested type" );
359 return wxANY_AS( a, T );
363 virtual void setter(
void* aObject, wxAny& aValue ) = 0;
364 virtual wxAny
getter(
const void* aObject )
const = 0;
402template<
typename Owner,
typename T,
typename Base = Owner>
408 template<
typename SetType,
typename GetType>
410 void ( Base::*aSetter )( SetType ), GetType( Base::*aGetter )(),
414 METHOD<Owner, T, Base>::Wrap( aGetter ), aDisplay, aCoordType )
418 template<
typename SetType,
typename GetType>
420 void ( Base::*aSetter )( SetType ), GetType( Base::*aGetter )()
const,
424 METHOD<Owner, T, Base>::Wrap( aGetter ), aDisplay, aCoordType )
459 virtual void setter(
void* obj, wxAny& v )
override
463 if( !v.CheckType<T>() )
464 throw std::invalid_argument(
"Invalid type requested" );
466 Owner* o =
reinterpret_cast<Owner*
>( obj );
468 (*m_setter)( o, value );
471 virtual wxAny
getter(
const void* obj )
const override
473 const Owner* o =
reinterpret_cast<const Owner*
>( obj );
474 wxAny
res = (*m_getter)( o );
495template<
typename Owner,
typename T,
typename Base = Owner>
499 template<
typename SetType,
typename GetType>
501 void ( Base::*aSetter )( SetType ), GetType( Base::*aGetter )(),
503 :
PROPERTY<Owner, T, Base>( aName,
METHOD<Owner, T, Base>::Wrap( aSetter ),
504 METHOD<Owner, T, Base>::Wrap( aGetter ), aDisplay )
506 if ( std::is_enum<T>::value )
509 wxASSERT_MSG(
m_choices.GetCount() > 0, wxT(
"No enum choices defined" ) );
513 template<
typename SetType,
typename GetType>
515 void ( Base::*aSetter )( SetType ), GetType( Base::*aGetter )()
const,
518 :
PROPERTY<Owner, T, Base>( aName,
METHOD<Owner, T, Base>::Wrap( aSetter ),
519 METHOD<Owner, T, Base>::Wrap( aGetter ), aDisplay, aCoordType )
521 if ( std::is_enum<T>::value )
524 wxASSERT_MSG(
m_choices.GetCount() > 0, wxT(
"No enum choices defined" ) );
528 void setter(
void* obj, wxAny& v )
override
531 Owner* o =
reinterpret_cast<Owner*
>( obj );
533 if( v.CheckType<T>() )
535 T value = wxANY_AS(v, T);
538 else if (v.CheckType<
int>() )
540 int value = wxANY_AS(v,
int);
545 throw std::invalid_argument(
"Invalid type requested" );
549 wxAny
getter(
const void* obj )
const override
551 const Owner* o =
reinterpret_cast<const Owner*
>( obj );
568 return Choices().GetCount() > 0;
581 virtual const void*
operator()(
const void* aPointer )
const = 0;
587template<
typename Base,
typename Derived>
597 Base* base =
reinterpret_cast<Base*
>( aPointer );
598 return static_cast<Derived*
>( base );
601 const void*
operator()(
const void* aPointer )
const override
603 const Base* base =
reinterpret_cast<const Base*
>( aPointer );
604 return static_cast<const Derived*
>( base );
631 m_choices.Add( aName,
static_cast<int>( aValue ) );
644 static const wxString s_undef =
"UNDEFINED";
646 int idx =
m_choices.Index(
static_cast<int>( value ) );
648 if( idx >= 0 && idx < (
int)
m_choices.GetCount() )
649 return m_choices.GetLabel(
static_cast<int>( idx ) );
656 int idx =
m_choices.Index(
static_cast<int>( value ) );
658 if( idx >= 0 && idx < (
int)
m_choices.GetCount() )
689#define DECLARE_ENUM_TO_WXANY( type ) \
691 class wxAnyValueTypeImpl<type> : public wxAnyValueTypeImplBase<type> \
693 WX_DECLARE_ANY_VALUE_TYPE( wxAnyValueTypeImpl<type> ) \
695 wxAnyValueTypeImpl() : wxAnyValueTypeImplBase<type>() {} \
696 virtual ~wxAnyValueTypeImpl() {} \
697 virtual bool ConvertValue( const wxAnyValueBuffer& src, wxAnyValueType* dstType, \
698 wxAnyValueBuffer& dst ) const override \
700 type value = GetValue( src ); \
701 ENUM_MAP<type>& conv = ENUM_MAP<type>::Instance(); \
702 if( ! conv.IsValueDefined( value ) ) \
706 if( dstType->CheckType<wxString>() ) \
708 wxAnyValueTypeImpl<wxString>::SetValue( conv.ToString( value ), dst ); \
711 if( dstType->CheckType<int>() ) \
713 wxAnyValueTypeImpl<int>::SetValue( static_cast<int>( value ), dst ); \
723#define IMPLEMENT_ENUM_TO_WXANY( type ) WX_IMPLEMENT_ANY_VALUE_TYPE( wxAnyValueTypeImpl<type> )
725#define ENUM_TO_WXANY( type ) \
726 DECLARE_ENUM_TO_WXANY( type ) \
727 IMPLEMENT_ENUM_TO_WXANY( type )
730#define NO_SETTER( owner, type ) ( ( void ( owner::* )( type ) ) nullptr )
const EDA_ANGLE & Angle()
A base class for most all the KiCad significant classes used in schematics and boards.
ENUM_MAP & Map(T aValue, const wxString &aName)
std::unordered_map< wxString, T > m_reverseMap
static ENUM_MAP< T > & Instance()
const wxString & ToString(T value) const
bool IsValueDefined(T value) const
ENUM_MAP & Undefined(T aValue)
const T ToEnum(const wxString value)
virtual T operator()(const Owner *aOwner) const =0
T operator()(const Owner *aOwner) const override
Class that other classes need to inherit from, in order to be inspectable.
static constexpr GETTER_BASE< Owner, T > * Wrap(const T(Base::*aFunc)())
static GETTER_BASE< Owner, T > * Wrap(T(Base::*aFunc)())
static constexpr GETTER_BASE< Owner, T > * Wrap(const T(Base::*aFunc)() const)
static constexpr GETTER_BASE< Owner, T > * Wrap(T(Base::*aFunc)() const)
static constexpr SETTER_BASE< Owner, T > * Wrap(void(Base::*aFunc)(const T &))
static constexpr GETTER_BASE< Owner, T > * Wrap(const T &(Base::*aFunc)())
static constexpr GETTER_BASE< Owner, T > * Wrap(const T &(Base::*aFunc)() const)
static constexpr SETTER_BASE< Owner, T > * Wrap(void(Base::*aFunc)(T))
static constexpr SETTER_BASE< Owner, T > * Wrap(void(Base::*aFunc)(T &))
virtual size_t TypeHash() const =0
Return type-id of the property type.
bool m_hideFromLibraryEditors
This property should only be shown in the design editor, not the library editor.
const wxString m_name
Permanent identifier for this property.
VALIDATOR_RESULT Validate(const wxAny &&aValue, EDA_ITEM *aItem)
std::function< bool(INSPECTABLE *)> m_writeableFunc
Eval to determine if prop is read-only.
std::function< bool(INSPECTABLE *)> m_availFunc
Eval to determine if prop is available.
PROPERTY_VALIDATOR_FN m_validator
PROPERTY_BASE & SetAvailableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Set a callback function to determine whether an object provides this property.
PROPERTY_BASE & SetDisplay(PROPERTY_DISPLAY aDisplay)
PROPERTY_BASE & SetIsDeprecated(bool aIsDeprecated=true)
PROPERTY_DISPLAY Display() const
PROPERTY_BASE(const wxString &aName, PROPERTY_DISPLAY aDisplay=PT_DEFAULT, ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType=ORIGIN_TRANSFORMS::NOT_A_COORD)
< Used to generate unique IDs. Must come up front so it's initialized before ctor.
static VALIDATOR_RESULT NullValidator(const wxAny &&aValue, EDA_ITEM *aItem)
PROPERTY_BASE & SetWriteableFunc(std::function< bool(INSPECTABLE *)> aFunc)
PROPERTY_BASE & SetGroup(const wxString &aGroup)
ORIGIN_TRANSFORMS::COORD_TYPES_T CoordType() const
virtual wxAny getter(const void *aObject) const =0
virtual size_t BaseHash() const =0
Return type-id of the Base class.
PROPERTY_BASE & SetCoordType(ORIGIN_TRANSFORMS::COORD_TYPES_T aType)
PROPERTY_DISPLAY m_display
The display style controls how properties are edited in the properties manager GUI.
virtual bool HasChoices() const
Return true if this PROPERTY has a limited set of possible values.
bool m_isDeprecated
Deprecated properties are hidden from the GUI and rules editor autocomplete.
ORIGIN_TRANSFORMS::COORD_TYPES_T m_coordType
The coordinate type controls how distances are mapped to the user coordinate system.
virtual bool Writeable(INSPECTABLE *aObject) const
virtual void setter(void *aObject, wxAny &aValue)=0
wxString m_group
Optional group identifier.
bool Available(INSPECTABLE *aObject) const
Return true if aObject offers this PROPERTY.
PROPERTY_BASE & SetValidator(PROPERTY_VALIDATOR_FN &&aValidator)
PROPERTY_BASE & SetIsInternal(bool aIsInternal=true)
bool IsDeprecated() const
bool m_isInternal
Internal properties are hidden from the GUI but not from the rules editor autocomplete.
void set(void *aObject, T aValue)
const wxString & Name() const
virtual const wxPGChoices & Choices() const
Return a limited set of possible values (e.g.
virtual void SetChoices(const wxPGChoices &aChoices)
Set the possible values for for the property.
virtual size_t OwnerHash() const =0
Return type-id of the Owner class.
bool IsHiddenFromLibraryEditors() const
T get(const void *aObject) const
PROPERTY_BASE & SetIsHiddenFromLibraryEditors(bool aIsHidden=true)
const wxPGChoices & Choices() const override
Return a limited set of possible values (e.g.
bool HasChoices() const override
Return true if this PROPERTY has a limited set of possible values.
PROPERTY_ENUM(const wxString &aName, void(Base::*aSetter)(SetType), GetType(Base::*aGetter)() const, PROPERTY_DISPLAY aDisplay=PT_DEFAULT, ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType=ORIGIN_TRANSFORMS::NOT_A_COORD)
void setter(void *obj, wxAny &v) override
PROPERTY_ENUM(const wxString &aName, void(Base::*aSetter)(SetType), GetType(Base::*aGetter)(), PROPERTY_DISPLAY aDisplay=PT_DEFAULT)
wxAny getter(const void *obj) const override
Set method.
void SetChoices(const wxPGChoices &aChoices) override
Set the possible values for for the property.
std::unique_ptr< SETTER_BASE< Owner, T > > m_setter
Get method.
const size_t m_baseHash
Property value type-id.
size_t TypeHash() const override
Return type-id of the property type.
typename std::decay< T >::type BASE_TYPE
virtual void setter(void *obj, wxAny &v) override
size_t BaseHash() const override
Return type-id of the Base class.
bool Writeable(INSPECTABLE *aObject) const override
virtual wxAny getter(const void *obj) const override
Set method.
PROPERTY(const wxString &aName, void(Base::*aSetter)(SetType), GetType(Base::*aGetter)() const, PROPERTY_DISPLAY aDisplay=PT_DEFAULT, ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType=ORIGIN_TRANSFORMS::NOT_A_COORD)
std::unique_ptr< GETTER_BASE< Owner, T > > m_getter
Owner class type-id.
PROPERTY(const wxString &aName, void(Base::*aSetter)(SetType), GetType(Base::*aGetter)(), PROPERTY_DISPLAY aDisplay=PT_DEFAULT, ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType=ORIGIN_TRANSFORMS::NOT_A_COORD)
PROPERTY(const wxString &aName, SETTER_BASE< Owner, T > *s, GETTER_BASE< Owner, T > *g, PROPERTY_DISPLAY aDisplay, ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType)
size_t OwnerHash() const override
Return type-id of the Owner class.
const size_t m_ownerHash
Base class type-id.
virtual void operator()(Owner *aOwner, T aValue)=0
void operator()(Owner *aOwner, T aValue) override
virtual const void * operator()(const void *aPointer) const =0
virtual size_t BaseHash() const =0
virtual void * operator()(void *aPointer) const =0
virtual ~TYPE_CAST_BASE()
virtual size_t DerivedHash() const =0
size_t DerivedHash() const override
const void * operator()(const void *aPointer) const override
size_t BaseHash() const override
void * operator()(void *aPointer) const override
static bool empty(const wxTextEntryBase *aCtrl)
PROPERTY_DISPLAY
Common property types.
@ PT_DEGREE
Angle expressed in degrees.
@ PT_COORD
Coordinate expressed in distance units (mm/inch)
@ PT_DECIDEGREE
Angle expressed in decidegrees.
@ PT_DEFAULT
Default property for a given type.
@ PT_SIZE
Size expressed in distance units (mm/inch)
std::function< VALIDATOR_RESULT(const wxAny &&, EDA_ITEM *aItem)> PROPERTY_VALIDATOR_FN
A property validator function takes in the data type of the owning property, and returns a VALIDATOR_...
std::optional< std::unique_ptr< VALIDATION_ERROR > > VALIDATOR_RESULT
Null optional means validation succeeded.