37#include <wx/validate.h>     
   38#include <wx/propgrid/property.h> 
   45#include <unordered_map> 
   49#include <wx/translation.h> 
   74#define TYPE_HASH( x ) typeid( x ).hash_code() 
   75#define TYPE_NAME( x ) typeid( x ).name() 
   78template<
typename Owner, 
typename T>
 
   87template<
typename Owner, 
typename T, 
typename FuncType>
 
   99        return ( aOwner->*
m_func )();
 
 
 
  106template<
typename Owner, 
typename T>
 
  115template<
typename Owner, 
typename T, 
typename FuncType>
 
  127        ( aOwner->*
m_func )( aValue );
 
 
 
  134#if defined( _MSC_VER ) 
  135#pragma warning( push ) 
  136#pragma warning( disable : 5266 )  
  139template<
typename Owner, 
typename T, 
typename Base = Owner>
 
  191#if defined( _MSC_VER ) 
  192#pragma warning( pop ) 
  211            m_writeableFunc( [](
INSPECTABLE*)->
bool { 
return true; } ),
 
  212            m_validator( NullValidator )
 
 
  228        static wxPGChoices 
empty;
 
 
  367    void set( 
void* aObject, 
T aValue )
 
  374        if( std::is_same<T, wxVariant>::value )
 
  376            wxVariant var = 
static_cast<wxVariant
>( aValue );
 
  377            wxAny pv = 
getter( aObject );
 
  379            if( pv.CheckType<
unsigned>() )
 
  381                a = 
static_cast<unsigned>( var.GetLong() );
 
  383            else if( pv.CheckType<std::optional<int>>() )
 
  388            else if( pv.CheckType<std::optional<double>>() )
 
 
  409    T get( 
const void* aObject )
 const 
  411        wxAny a = 
getter( aObject );
 
  414        if( a.CheckType<
bool>() )
 
  415            a = a.RawAs<
bool>() ? 1 : 0;
 
  417        if ( !( std::is_enum<T>::value && a.CheckType<
int>() ) && !a.CheckType<
T>() )
 
  418            throw std::invalid_argument( 
"Invalid requested type" );
 
  420        return wxANY_AS( a, 
T );
 
 
  424    virtual void setter( 
void* aObject, wxAny& aValue ) = 0;
 
  425    virtual wxAny 
getter( 
const void* aObject ) 
const = 0;
 
 
  463template<
typename Owner, 
typename T, 
typename Base = Owner>
 
  469    template<
typename SetType, 
typename GetType>
 
  471              void ( Base::*aSetter )( SetType ),
 
  472              GetType( Base::*aGetter )(),
 
  476                  METHOD<Owner, 
T, Base>::Wrap( aSetter ),
 
  477                  METHOD<Owner, 
T, Base>::Wrap( aGetter ),
 
  478                  aDisplay, aCoordType )
 
 
  482    template<
typename SetType, 
typename GetType>
 
  484              void ( Base::*aSetter )( SetType ),
 
  485              GetType( Base::*aGetter )() 
const,
 
  489                  METHOD<Owner, 
T, Base>::Wrap( aSetter ),
 
  490                  METHOD<Owner, 
T, Base>::Wrap( aGetter ),
 
  491                  aDisplay, aCoordType )
 
 
  531    virtual void setter( 
void* obj, wxAny& v )
 override 
  537        if( !v.GetAs( &value ) )
 
  538            throw std::invalid_argument( 
"Invalid type requested" );
 
  540        Owner* o = 
reinterpret_cast<Owner*
>( obj );
 
  541        (*m_setter)( o, value );
 
 
  544    virtual wxAny 
getter( 
const void* obj )
 const override 
  546        const Owner* o = 
reinterpret_cast<const Owner*
>( obj );
 
  547        wxAny 
res = (*m_getter)( o );
 
  568template<
typename Owner, 
typename T, 
typename Base = Owner>
 
  572    template<
typename SetType, 
typename GetType>
 
  574                   void ( Base::*aSetter )( SetType ),
 
  575                   GetType( Base::*aGetter )(),
 
  578                                    METHOD<Owner, 
T, Base>::Wrap( aSetter ),
 
  579                                    METHOD<Owner, 
T, Base>::Wrap( aGetter ),
 
  583        if ( std::is_enum<T>::value )
 
  587            wxASSERT_MSG( 
m_choices.GetCount() > 0, wxT( 
"No enum choices defined" ) );
 
 
  591    template<
typename SetType, 
typename GetType>
 
  593                   void ( Base::*aSetter )( SetType ),
 
  594                   GetType( Base::*aGetter )() 
const,
 
  598                                      METHOD<Owner, 
T, Base>::Wrap( aSetter ),
 
  599                                      METHOD<Owner, 
T, Base>::Wrap( aGetter ),
 
  600                                      aDisplay, aCoordType ),
 
  603        if ( std::is_enum<T>::value )
 
  607            wxASSERT_MSG( 
m_choices.GetCount() > 0, wxT( 
"No enum choices defined" ) );
 
 
  611    void setter( 
void* obj, wxAny& v )
 override 
  614        Owner* o = 
reinterpret_cast<Owner*
>( obj );
 
  616        if( v.CheckType<
T>() )
 
  618            T value = wxANY_AS(v, 
T);
 
  621        else if (v.CheckType<
int>() )
 
  623            int value = wxANY_AS(v, 
int);
 
  628            throw std::invalid_argument( 
"Invalid type requested" );
 
 
  632    wxAny 
getter( 
const void* obj )
 const override 
  634        const Owner* o = 
reinterpret_cast<const Owner*
>( obj );
 
 
  652            for( 
unsigned ii = 0; ii < choices.GetCount(); ++ii )
 
  653                m_choices.Add( wxGetTranslation( choices.GetLabel( ii ) ), choices.GetValue( ii ) );
 
 
  665        return Choices().GetCount() > 0;
 
 
 
  679    virtual const void* 
operator()( 
const void* aPointer ) 
const = 0;
 
 
  685template<
typename Base, 
typename Derived>
 
  695        Base* base = 
reinterpret_cast<Base*
>( aPointer );
 
  696        return static_cast<Derived*
>( base );
 
 
  699    const void* 
operator()( 
const void* aPointer )
 const override 
  701        const Base* base = 
reinterpret_cast<const Base*
>( aPointer );
 
  702        return static_cast<const Derived*
>( base );
 
 
 
  729        m_choices.Add( aName, 
static_cast<int>( aValue ) );
 
 
  742        static const wxString s_undef = 
"UNDEFINED";
 
  744        int idx = 
m_choices.Index( 
static_cast<int>( value ) );
 
  746        if( idx >= 0 && idx < (
int) 
m_choices.GetCount() )
 
  747            return m_choices.GetLabel( 
static_cast<int>( idx ) );
 
 
  754        int idx = 
m_choices.Index( 
static_cast<int>( value ) );
 
  756        if( idx >= 0 && idx < (
int) 
m_choices.GetCount() )
 
 
 
  787#define DECLARE_ENUM_TO_WXANY( type )                                                       \ 
  789    class wxAnyValueTypeImpl<type> : public wxAnyValueTypeImplBase<type>                    \ 
  791        WX_DECLARE_ANY_VALUE_TYPE( wxAnyValueTypeImpl<type> )                               \ 
  793        wxAnyValueTypeImpl() : wxAnyValueTypeImplBase<type>() {}                            \ 
  794        virtual ~wxAnyValueTypeImpl() {}                                                    \ 
  795        virtual bool ConvertValue( const wxAnyValueBuffer& src, wxAnyValueType* dstType,    \ 
  796                                   wxAnyValueBuffer& dst ) const override                   \ 
  798            type            value = GetValue( src );                                        \ 
  799            ENUM_MAP<type>& conv = ENUM_MAP<type>::Instance();                              \ 
  800            if( ! conv.IsValueDefined( value ) )                                            \ 
  804            if( dstType->CheckType<wxString>() )                                            \ 
  806                wxAnyValueTypeImpl<wxString>::SetValue( conv.ToString( value ), dst );      \ 
  809            if( dstType->CheckType<int>() )                                                 \ 
  811                wxAnyValueTypeImpl<int>::SetValue( static_cast<int>( value ), dst );        \ 
 
  821#define IMPLEMENT_ENUM_TO_WXANY( type ) WX_IMPLEMENT_ANY_VALUE_TYPE( wxAnyValueTypeImpl<type> ) 
  823#define ENUM_TO_WXANY( type )                                                               \ 
  824    DECLARE_ENUM_TO_WXANY( type )                                                           \ 
  825    IMPLEMENT_ENUM_TO_WXANY( type ) 
 
  828#define NO_SETTER( owner, type ) ( ( void ( owner::* )( type ) ) nullptr ) 
 
 
const KIGFX::COLOR4D & Color()
 
const EDA_ANGLE & Angle()
 
A base class for most all the KiCad significant classes used in schematics and boards.
 
T ToEnum(const wxString value)
 
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)
 
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.
 
A color representation with 4 components: red, green, blue, alpha.
 
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 &))
 
PROPERTY_BASE & SetChoicesFunc(std::function< wxPGChoices(INSPECTABLE *)> aFunc)
 
bool IsHiddenFromPropertiesManager() const
 
virtual size_t TypeHash() const =0
Return type-id of the property type.
 
bool m_hideFromLibraryEditors
 
const wxString m_name
Permanent identifier for this property.
 
VALIDATOR_RESULT Validate(const wxAny &&aValue, EDA_ITEM *aItem)
 
virtual void TranslateChoices()
 
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
 
bool IsHiddenFromDesignEditors() const
 
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)
 
std::function< wxPGChoices(INSPECTABLE *)> m_choicesFunc
 
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.
 
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
 
wxPGChoices GetChoices(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)
 
bool m_hideFromPropertiesManager
 
bool m_hideFromDesignEditors
 
PROPERTY_BASE & SetIsHiddenFromDesignEditors(bool aIsHidden=true)
 
PROPERTY_BASE & SetIsHiddenFromPropertiesManager(bool aHide=true)
 
bool m_hideFromRulesEditor
 
void set(void *aObject, T aValue)
 
const wxString & Name() const
 
bool IsHiddenFromRulesEditor() 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.
 
PROPERTY_BASE & SetIsHiddenFromRulesEditor(bool aHide=true)
 
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.
 
void TranslateChoices() override
 
bool m_choicesFromENUM_MAP
 
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
 
std::optional< double > Value() const
 
std::optional< int > Value() const
 
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_AREA
Area expressed in distance units-squared (mm/inch)
 
@ PT_DEFAULT
Default property for a given type.
 
@ PT_SIZE
Size expressed in distance units (mm/inch)
 
@ PT_NET
Net selection property.
 
@ PT_TIME
Time expressed in ps.
 
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.