KiCad PCB EDA Suite
property.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2020 CERN
5 * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Tomasz Wlostowski <[email protected]>
8 * @author Maciej Suminski <[email protected]>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 3
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#ifndef PROPERTY_H
25#define PROPERTY_H
26
27#include <core/wx_stl_compat.h>
28#include <origin_transforms.h>
31
32#include <wx/any.h>
33#include <wx/string.h>
34#include <wx/bitmap.h>
35#include <wx/font.h> // required for propgrid
36#include <wx/validate.h> // required for propgrid
37#include <wx/propgrid/property.h>
38
39#include <functional>
40#include <map>
41#include <memory>
42#include <typeindex>
43#include <type_traits>
44
45class wxPGProperty;
46class INSPECTABLE;
47class PROPERTY_BASE;
48
49template<typename T>
50class ENUM_MAP;
51
54{
60};
61
63#define TYPE_HASH( x ) typeid( x ).hash_code()
64#define TYPE_NAME( x ) typeid( x ).name()
65//#define TYPE_HASH( x ) typeid( std::decay<x>::type ).hash_code()
66
67template<typename Owner, typename T>
69{
70public:
71 virtual ~GETTER_BASE() {}
72
73 virtual T operator()( const Owner* aOwner ) const = 0;
74};
75
76template<typename Owner, typename T, typename FuncType>
77class GETTER : public GETTER_BASE<Owner, T>
78{
79public:
80 GETTER( FuncType aFunc )
81 : m_func( aFunc )
82 {
83 wxCHECK( m_func, /*void*/ );
84 }
85
86 T operator()( const Owner* aOwner ) const override
87 {
88 return ( aOwner->*m_func )();
89 }
90
91private:
92 FuncType m_func;
93};
94
95template<typename Owner, typename T>
97{
98public:
99 virtual ~SETTER_BASE() {}
100
101 virtual void operator()( Owner* aOwner, T aValue ) = 0;
102};
103
104template<typename Owner, typename T, typename FuncType>
105class SETTER : public SETTER_BASE<Owner, T>
106{
107public:
108 SETTER( FuncType aFunc )
109 : m_func( aFunc )
110 {
111 wxCHECK( m_func, /*void*/ );
112 }
113
114 void operator()( Owner* aOwner, T aValue ) override
115 {
116 ( aOwner->*m_func )( aValue );
117 }
118
119private:
120 FuncType m_func;
121};
122
123
124template<typename Owner, typename T, typename Base = Owner>
126{
127public:
128 static GETTER_BASE<Owner, T>* Wrap( T (Base::*aFunc)() )
129 {
130 return new GETTER<Owner, T, T (Base::*)()>( aFunc );
131 }
132
133 constexpr static GETTER_BASE<Owner, T>* Wrap( const T (Base::*aFunc)() )
134 {
135 return new GETTER<Owner, T, T (Base::*)()>( aFunc );
136 }
137
138 constexpr static GETTER_BASE<Owner, T>* Wrap( const T& (Base::*aFunc)() )
139 {
140 return new GETTER<Owner, T, const T& (Base::*)()>( aFunc );
141 }
142
143 constexpr static GETTER_BASE<Owner, T>* Wrap( T (Base::*aFunc)() const )
144 {
145 return new GETTER<Owner, T, T (Base::*)() const>( aFunc );
146 }
147
148 constexpr static GETTER_BASE<Owner, T>* Wrap( const T (Base::*aFunc)() const )
149 {
150 return new GETTER<Owner, T, T (Base::*)() const>( aFunc );
151 }
152
153 constexpr static GETTER_BASE<Owner, T>* Wrap( const T& (Base::*aFunc)() const )
154 {
156 }
157
158 constexpr static SETTER_BASE<Owner, T>* Wrap( void (Base::*aFunc)( T ) )
159 {
160 return aFunc ? new SETTER<Owner, T, void (Base::*)( T )>( aFunc ) : nullptr;
161 }
162
163 constexpr static SETTER_BASE<Owner, T>* Wrap( void (Base::*aFunc)( T& ) )
164 {
165 return aFunc ? new SETTER<Owner, T, void (Base::*)( T& )>( aFunc ) : nullptr;
166 }
167
168 constexpr static SETTER_BASE<Owner, T>* Wrap( void (Base::*aFunc)( const T& ) )
169 {
170 return aFunc ? new SETTER<Owner, T, void (Base::*)( const T& )>( aFunc ) : nullptr;
171 }
172
173 METHOD() = delete;
174};
175
176
178{
179private:
181
182public:
183PROPERTY_BASE( const wxString& aName, PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
185 m_name( aName ),
186 m_display( aDisplay ),
187 m_coordType( aCoordType ),
188 m_isInternal( false ),
189 m_isDeprecated( false ),
191 m_availFunc( [](INSPECTABLE*)->bool { return true; } ),
192 m_writeableFunc( [](INSPECTABLE*)->bool { return true; } ),
193 m_validator( NullValidator )
194 {
195 }
196
198 {
199 }
200
201 const wxString& Name() const { return m_name; }
202
207 virtual const wxPGChoices& Choices() const
208 {
209 static wxPGChoices empty;
210 return empty;
211 }
212
216 virtual void SetChoices( const wxPGChoices& aChoices )
217 {
218 wxFAIL; // only possible for PROPERTY_ENUM
219 }
220
225 virtual bool HasChoices() const
226 {
227 return false;
228 }
229
233 bool Available( INSPECTABLE* aObject ) const
234 {
235 return m_availFunc( aObject );
236 }
237
241 PROPERTY_BASE& SetAvailableFunc( std::function<bool(INSPECTABLE*)> aFunc )
242 {
243 m_availFunc = aFunc;
244 return *this;
245 }
246
247 virtual bool Writeable( INSPECTABLE* aObject ) const
248 {
249 return m_writeableFunc( aObject );
250 }
251
252 PROPERTY_BASE& SetWriteableFunc( std::function<bool(INSPECTABLE*)> aFunc )
253 {
254 m_writeableFunc = aFunc;
255 return *this;
256 }
257
261 virtual size_t OwnerHash() const = 0;
262
266 virtual size_t BaseHash() const = 0;
267
271 virtual size_t TypeHash() const = 0;
272
273 PROPERTY_DISPLAY Display() const { return m_display; }
274 PROPERTY_BASE& SetDisplay( PROPERTY_DISPLAY aDisplay ) { m_display = aDisplay; return *this; }
275
276 ORIGIN_TRANSFORMS::COORD_TYPES_T CoordType() const { return m_coordType; }
278 {
279 m_coordType = aType;
280 return *this;
281 }
282
283 bool IsInternal() const { return m_isInternal; }
284 PROPERTY_BASE& SetIsInternal( bool aIsInternal = true )
285 {
286 m_isInternal = aIsInternal;
287 return *this;
288 }
289
290 bool IsDeprecated() const { return m_isDeprecated; }
291 PROPERTY_BASE& SetIsDeprecated( bool aIsDeprecated = true )
292 {
293 m_isDeprecated = aIsDeprecated;
294 return *this;
295 }
296
297 bool IsHiddenFromLibraryEditors() const { return m_hideFromLibraryEditors; }
299 {
300 m_hideFromLibraryEditors = aIsHidden;
301 return *this;
302 }
303
304 wxString Group() const { return m_group; }
305 PROPERTY_BASE& SetGroup( const wxString& aGroup ) { m_group = aGroup; return *this; }
306
308 {
309 m_validator = aValidator;
310 return *this;
311 }
312
313 VALIDATOR_RESULT Validate( const wxAny&& aValue, EDA_ITEM* aItem )
314 {
315 return m_validator( std::move( aValue ), aItem );
316 }
317
318 static VALIDATOR_RESULT NullValidator( const wxAny&& aValue, EDA_ITEM* aItem )
319 {
320 return std::nullopt;
321 }
322
323protected:
324 template<typename T>
325 void set( void* aObject, T aValue )
326 {
327 wxAny a = aValue;
328
329 // wxVariant will be type "long" even if the property is supposed to be
330 // unsigned. Let's trust that we're coming from the property grid where
331 // we used a UInt editor.
332 if( std::is_same<T, wxVariant>::value )
333 {
334 wxVariant var = static_cast<wxVariant>( aValue );
335 wxAny pv = getter( aObject );
336
337 if( pv.CheckType<unsigned>() )
338 {
339 a = static_cast<unsigned>( var.GetLong() );
340 }
341 else if( pv.CheckType<EDA_ANGLE>() )
342 {
343 EDA_ANGLE_VARIANT_DATA* ad = static_cast<EDA_ANGLE_VARIANT_DATA*>( var.GetData() );
344 a = ad->Angle();
345 }
346 }
347
348 setter( aObject, a );
349 }
350
351 template<typename T>
352 T get( const void* aObject ) const
353 {
354 wxAny a = getter( aObject );
355
356 if ( !( std::is_enum<T>::value && a.CheckType<int>() ) && !a.CheckType<T>() )
357 throw std::invalid_argument( "Invalid requested type" );
358
359 return wxANY_AS( a, T );
360 }
361
362private:
363 virtual void setter( void* aObject, wxAny& aValue ) = 0;
364 virtual wxAny getter( const void* aObject ) const = 0;
365
366private:
372 const wxString m_name;
373
376
379
382
385
388
390 wxString m_group;
391
392 std::function<bool(INSPECTABLE*)> m_availFunc;
393
394 std::function<bool(INSPECTABLE*)> m_writeableFunc;
395
397
398 friend class INSPECTABLE;
399};
400
401
402template<typename Owner, typename T, typename Base = Owner>
404{
405public:
406 using BASE_TYPE = typename std::decay<T>::type;
407
408 template<typename SetType, typename GetType>
409 PROPERTY( const wxString& aName,
410 void ( Base::*aSetter )( SetType ), GetType( Base::*aGetter )(),
411 PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
413 : PROPERTY( aName, METHOD<Owner, T, Base>::Wrap( aSetter ),
414 METHOD<Owner, T, Base>::Wrap( aGetter ), aDisplay, aCoordType )
415 {
416 }
417
418 template<typename SetType, typename GetType>
419 PROPERTY( const wxString& aName,
420 void ( Base::*aSetter )( SetType ), GetType( Base::*aGetter )() const,
421 PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
423 : PROPERTY( aName, METHOD<Owner, T, Base>::Wrap( aSetter ),
424 METHOD<Owner, T, Base>::Wrap( aGetter ), aDisplay, aCoordType )
425 {
426 }
427
428 size_t OwnerHash() const override
429 {
430 return m_ownerHash;
431 }
432
433 size_t BaseHash() const override
434 {
435 return m_baseHash;
436 }
437
438 size_t TypeHash() const override
439 {
440 return m_typeHash;
441 }
442
443 bool Writeable( INSPECTABLE* aObject ) const override
444 {
445 return m_setter && PROPERTY_BASE::Writeable( aObject );
446 }
447
448protected:
451 : PROPERTY_BASE( aName, aDisplay, aCoordType ), m_setter( s ), m_getter( g ),
452 m_ownerHash( TYPE_HASH( Owner ) ), m_baseHash( TYPE_HASH( Base ) ),
454 {
455 }
456
457 virtual ~PROPERTY() {}
458
459 virtual void setter( void* obj, wxAny& v ) override
460 {
461 wxCHECK( m_setter, /*void*/ );
462
463 if( !v.CheckType<T>() )
464 throw std::invalid_argument( "Invalid type requested" );
465
466 Owner* o = reinterpret_cast<Owner*>( obj );
467 BASE_TYPE value = wxANY_AS(v, BASE_TYPE);
468 (*m_setter)( o, value );
469 }
470
471 virtual wxAny getter( const void* obj ) const override
472 {
473 const Owner* o = reinterpret_cast<const Owner*>( obj );
474 wxAny res = (*m_getter)( o );
475 return res;
476 }
477
479 std::unique_ptr<SETTER_BASE<Owner, T>> m_setter;
480
482 std::unique_ptr<GETTER_BASE<Owner, T>> m_getter;
483
485 const size_t m_ownerHash;
486
488 const size_t m_baseHash;
489
491 const size_t m_typeHash;
492};
493
494
495template<typename Owner, typename T, typename Base = Owner>
496class PROPERTY_ENUM : public PROPERTY<Owner, T, Base>
497{
498public:
499 template<typename SetType, typename GetType>
500 PROPERTY_ENUM( const wxString& aName,
501 void ( Base::*aSetter )( SetType ), GetType( Base::*aGetter )(),
502 PROPERTY_DISPLAY aDisplay = PT_DEFAULT )
503 : PROPERTY<Owner, T, Base>( aName, METHOD<Owner, T, Base>::Wrap( aSetter ),
504 METHOD<Owner, T, Base>::Wrap( aGetter ), aDisplay )
505 {
506 if ( std::is_enum<T>::value )
507 {
508 m_choices = ENUM_MAP<T>::Instance().Choices();
509 wxASSERT_MSG( m_choices.GetCount() > 0, wxT( "No enum choices defined" ) );
510 }
511 }
512
513 template<typename SetType, typename GetType>
514 PROPERTY_ENUM( const wxString& aName,
515 void ( Base::*aSetter )( SetType ), GetType( Base::*aGetter )() const,
516 PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
518 : PROPERTY<Owner, T, Base>( aName, METHOD<Owner, T, Base>::Wrap( aSetter ),
519 METHOD<Owner, T, Base>::Wrap( aGetter ), aDisplay, aCoordType )
520 {
521 if ( std::is_enum<T>::value )
522 {
523 m_choices = ENUM_MAP<T>::Instance().Choices();
524 wxASSERT_MSG( m_choices.GetCount() > 0, wxT( "No enum choices defined" ) );
525 }
526 }
527
528 void setter( void* obj, wxAny& v ) override
529 {
530 wxCHECK( ( PROPERTY<Owner, T, Base>::m_setter ), /*void*/ );
531 Owner* o = reinterpret_cast<Owner*>( obj );
532
533 if( v.CheckType<T>() )
534 {
535 T value = wxANY_AS(v, T);
537 }
538 else if (v.CheckType<int>() )
539 {
540 int value = wxANY_AS(v, int);
541 (*PROPERTY<Owner, T, Base>::m_setter)( o, static_cast<T>( value ) );
542 }
543 else
544 {
545 throw std::invalid_argument( "Invalid type requested" );
546 }
547 }
548
549 wxAny getter( const void* obj ) const override
550 {
551 const Owner* o = reinterpret_cast<const Owner*>( obj );
552 wxAny res = static_cast<T>( (*PROPERTY<Owner, T, Base>::m_getter)( o ) );
553 return res;
554 }
555
556 const wxPGChoices& Choices() const override
557 {
558 return m_choices.GetCount() > 0 ? m_choices : ENUM_MAP<T>::Instance().Choices();
559 }
560
561 void SetChoices( const wxPGChoices& aChoices ) override
562 {
563 m_choices = aChoices;
564 }
565
566 bool HasChoices() const override
567 {
568 return Choices().GetCount() > 0;
569 }
570
571protected:
572 wxPGChoices m_choices;
573};
574
575
577{
578public:
579 virtual ~TYPE_CAST_BASE() {}
580 virtual void* operator()( void* aPointer ) const = 0;
581 virtual const void* operator()( const void* aPointer ) const = 0;
582 virtual size_t BaseHash() const = 0;
583 virtual size_t DerivedHash() const = 0;
584};
585
586
587template<typename Base, typename Derived>
589{
590public:
592 {
593 }
594
595 void* operator()( void* aPointer ) const override
596 {
597 Base* base = reinterpret_cast<Base*>( aPointer );
598 return static_cast<Derived*>( base );
599 }
600
601 const void* operator()( const void* aPointer ) const override
602 {
603 const Base* base = reinterpret_cast<const Base*>( aPointer );
604 return static_cast<const Derived*>( base );
605 }
606
607 size_t BaseHash() const override
608 {
609 return TYPE_HASH( Base );
610 }
611
612 size_t DerivedHash() const override
613 {
614 return TYPE_HASH( Derived );
615 }
616};
617
618
619template<typename T>
621{
622public:
624 {
625 static ENUM_MAP<T> inst;
626 return inst;
627 }
628
629 ENUM_MAP& Map( T aValue, const wxString& aName )
630 {
631 m_choices.Add( aName, static_cast<int>( aValue ) );
632 m_reverseMap[ aName ] = aValue;
633 return *this;
634 }
635
636 ENUM_MAP& Undefined( T aValue )
637 {
638 m_undefined = aValue;
639 return *this;
640 }
641
642 const wxString& ToString( T value ) const
643 {
644 static const wxString s_undef = "UNDEFINED";
645
646 int idx = m_choices.Index( static_cast<int>( value ) );
647
648 if( idx >= 0 && idx < (int) m_choices.GetCount() )
649 return m_choices.GetLabel( static_cast<int>( idx ) );
650 else
651 return s_undef;
652 }
653
654 bool IsValueDefined( T value ) const
655 {
656 int idx = m_choices.Index( static_cast<int>( value ) );
657
658 if( idx >= 0 && idx < (int) m_choices.GetCount() )
659 return true;
660
661 return false;
662 }
663
664 const T ToEnum( const wxString value )
665 {
666 if( m_reverseMap.count( value ) )
667 return m_reverseMap[ value ];
668 else
669 return m_undefined;
670 }
671
672 wxPGChoices& Choices()
673 {
674 return m_choices;
675 }
676
677private:
678 wxPGChoices m_choices;
679 std::unordered_map<wxString, T> m_reverseMap;
680 T m_undefined; // Returned if the string is not recognized
681
683 {
684 }
685};
686
687
688// Helper macros to handle enum types
689#define DECLARE_ENUM_TO_WXANY( type ) \
690 template <> \
691 class wxAnyValueTypeImpl<type> : public wxAnyValueTypeImplBase<type> \
692 { \
693 WX_DECLARE_ANY_VALUE_TYPE( wxAnyValueTypeImpl<type> ) \
694 public: \
695 wxAnyValueTypeImpl() : wxAnyValueTypeImplBase<type>() {} \
696 virtual ~wxAnyValueTypeImpl() {} \
697 virtual bool ConvertValue( const wxAnyValueBuffer& src, wxAnyValueType* dstType, \
698 wxAnyValueBuffer& dst ) const override \
699 { \
700 type value = GetValue( src ); \
701 ENUM_MAP<type>& conv = ENUM_MAP<type>::Instance(); \
702 if( ! conv.IsValueDefined( value ) ) \
703 { \
704 return false; \
705 } \
706 if( dstType->CheckType<wxString>() ) \
707 { \
708 wxAnyValueTypeImpl<wxString>::SetValue( conv.ToString( value ), dst ); \
709 return true; \
710 } \
711 if( dstType->CheckType<int>() ) \
712 { \
713 wxAnyValueTypeImpl<int>::SetValue( static_cast<int>( value ), dst ); \
714 return true; \
715 } \
716 else \
717 { \
718 return false; \
719 } \
720 } \
721 };
722
723#define IMPLEMENT_ENUM_TO_WXANY( type ) WX_IMPLEMENT_ANY_VALUE_TYPE( wxAnyValueTypeImpl<type> )
724
725#define ENUM_TO_WXANY( type ) \
726 DECLARE_ENUM_TO_WXANY( type ) \
727 IMPLEMENT_ENUM_TO_WXANY( type )
728
730#define NO_SETTER( owner, type ) ( ( void ( owner::* )( type ) ) nullptr )
731
732/*
733#define DECLARE_PROPERTY(owner,type,name,getter,setter) \
734namespace anonymous {\
735static PROPERTY<owner,type> prop##_owner##_name_( "##name#", setter, getter );\
736};
737*/
738#endif /* PROPERTY_H */
const EDA_ANGLE & Angle()
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
ENUM_MAP & Map(T aValue, const wxString &aName)
Definition: property.h:629
std::unordered_map< wxString, T > m_reverseMap
Definition: property.h:679
T m_undefined
Definition: property.h:680
static ENUM_MAP< T > & Instance()
Definition: property.h:623
const wxString & ToString(T value) const
Definition: property.h:642
bool IsValueDefined(T value) const
Definition: property.h:654
ENUM_MAP & Undefined(T aValue)
Definition: property.h:636
wxPGChoices & Choices()
Definition: property.h:672
wxPGChoices m_choices
Definition: property.h:678
const T ToEnum(const wxString value)
Definition: property.h:664
virtual ~GETTER_BASE()
Definition: property.h:71
virtual T operator()(const Owner *aOwner) const =0
GETTER(FuncType aFunc)
Definition: property.h:80
FuncType m_func
Definition: property.h:92
T operator()(const Owner *aOwner) const override
Definition: property.h:86
Class that other classes need to inherit from, in order to be inspectable.
Definition: inspectable.h:36
static constexpr GETTER_BASE< Owner, T > * Wrap(const T(Base::*aFunc)())
Definition: property.h:133
static GETTER_BASE< Owner, T > * Wrap(T(Base::*aFunc)())
Definition: property.h:128
static constexpr GETTER_BASE< Owner, T > * Wrap(const T(Base::*aFunc)() const)
Definition: property.h:148
static constexpr GETTER_BASE< Owner, T > * Wrap(T(Base::*aFunc)() const)
Definition: property.h:143
static constexpr SETTER_BASE< Owner, T > * Wrap(void(Base::*aFunc)(const T &))
Definition: property.h:168
static constexpr GETTER_BASE< Owner, T > * Wrap(const T &(Base::*aFunc)())
Definition: property.h:138
static constexpr GETTER_BASE< Owner, T > * Wrap(const T &(Base::*aFunc)() const)
Definition: property.h:153
static constexpr SETTER_BASE< Owner, T > * Wrap(void(Base::*aFunc)(T))
Definition: property.h:158
static constexpr SETTER_BASE< Owner, T > * Wrap(void(Base::*aFunc)(T &))
Definition: property.h:163
METHOD()=delete
COORD_TYPES_T
The supported Display Origin Transform types.
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.
Definition: property.h:387
const wxString m_name
Permanent identifier for this property.
Definition: property.h:372
VALIDATOR_RESULT Validate(const wxAny &&aValue, EDA_ITEM *aItem)
Definition: property.h:313
std::function< bool(INSPECTABLE *)> m_writeableFunc
Eval to determine if prop is read-only.
Definition: property.h:394
std::function< bool(INSPECTABLE *)> m_availFunc
Eval to determine if prop is available.
Definition: property.h:392
PROPERTY_VALIDATOR_FN m_validator
Definition: property.h:396
PROPERTY_BASE & SetAvailableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Set a callback function to determine whether an object provides this property.
Definition: property.h:241
PROPERTY_BASE & SetDisplay(PROPERTY_DISPLAY aDisplay)
Definition: property.h:274
PROPERTY_BASE & SetIsDeprecated(bool aIsDeprecated=true)
Definition: property.h:291
PROPERTY_DISPLAY Display() const
Definition: property.h:273
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.
Definition: property.h:183
static VALIDATOR_RESULT NullValidator(const wxAny &&aValue, EDA_ITEM *aItem)
Definition: property.h:318
wxString Group() const
Definition: property.h:304
PROPERTY_BASE & SetWriteableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Definition: property.h:252
PROPERTY_BASE & SetGroup(const wxString &aGroup)
Definition: property.h:305
ORIGIN_TRANSFORMS::COORD_TYPES_T CoordType() const
Definition: property.h:276
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)
Definition: property.h:277
PROPERTY_DISPLAY m_display
The display style controls how properties are edited in the properties manager GUI.
Definition: property.h:375
virtual bool HasChoices() const
Return true if this PROPERTY has a limited set of possible values.
Definition: property.h:225
bool m_isDeprecated
Deprecated properties are hidden from the GUI and rules editor autocomplete.
Definition: property.h:384
ORIGIN_TRANSFORMS::COORD_TYPES_T m_coordType
The coordinate type controls how distances are mapped to the user coordinate system.
Definition: property.h:378
virtual bool Writeable(INSPECTABLE *aObject) const
Definition: property.h:247
bool IsInternal() const
Definition: property.h:283
virtual void setter(void *aObject, wxAny &aValue)=0
virtual ~PROPERTY_BASE()
Definition: property.h:197
wxString m_group
Optional group identifier.
Definition: property.h:390
bool Available(INSPECTABLE *aObject) const
Return true if aObject offers this PROPERTY.
Definition: property.h:233
PROPERTY_BASE & SetValidator(PROPERTY_VALIDATOR_FN &&aValidator)
Definition: property.h:307
PROPERTY_BASE & SetIsInternal(bool aIsInternal=true)
Definition: property.h:284
bool IsDeprecated() const
Definition: property.h:290
bool m_isInternal
Internal properties are hidden from the GUI but not from the rules editor autocomplete.
Definition: property.h:381
void set(void *aObject, T aValue)
Definition: property.h:325
const wxString & Name() const
Definition: property.h:201
virtual const wxPGChoices & Choices() const
Return a limited set of possible values (e.g.
Definition: property.h:207
virtual void SetChoices(const wxPGChoices &aChoices)
Set the possible values for for the property.
Definition: property.h:216
virtual size_t OwnerHash() const =0
Return type-id of the Owner class.
bool IsHiddenFromLibraryEditors() const
Definition: property.h:297
T get(const void *aObject) const
Definition: property.h:352
PROPERTY_BASE & SetIsHiddenFromLibraryEditors(bool aIsHidden=true)
Definition: property.h:298
const wxPGChoices & Choices() const override
Return a limited set of possible values (e.g.
Definition: property.h:556
bool HasChoices() const override
Return true if this PROPERTY has a limited set of possible values.
Definition: property.h:566
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)
Definition: property.h:514
void setter(void *obj, wxAny &v) override
Definition: property.h:528
PROPERTY_ENUM(const wxString &aName, void(Base::*aSetter)(SetType), GetType(Base::*aGetter)(), PROPERTY_DISPLAY aDisplay=PT_DEFAULT)
Definition: property.h:500
wxPGChoices m_choices
Definition: property.h:572
wxAny getter(const void *obj) const override
Set method.
Definition: property.h:549
void SetChoices(const wxPGChoices &aChoices) override
Set the possible values for for the property.
Definition: property.h:561
std::unique_ptr< SETTER_BASE< Owner, T > > m_setter
Get method.
Definition: property.h:479
const size_t m_baseHash
Property value type-id.
Definition: property.h:488
size_t TypeHash() const override
Return type-id of the property type.
Definition: property.h:438
typename std::decay< T >::type BASE_TYPE
Definition: property.h:406
const size_t m_typeHash
Definition: property.h:491
virtual ~PROPERTY()
Definition: property.h:457
virtual void setter(void *obj, wxAny &v) override
Definition: property.h:459
size_t BaseHash() const override
Return type-id of the Base class.
Definition: property.h:433
bool Writeable(INSPECTABLE *aObject) const override
Definition: property.h:443
virtual wxAny getter(const void *obj) const override
Set method.
Definition: property.h:471
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)
Definition: property.h:419
std::unique_ptr< GETTER_BASE< Owner, T > > m_getter
Owner class type-id.
Definition: property.h:482
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)
Definition: property.h:409
PROPERTY(const wxString &aName, SETTER_BASE< Owner, T > *s, GETTER_BASE< Owner, T > *g, PROPERTY_DISPLAY aDisplay, ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType)
Definition: property.h:449
size_t OwnerHash() const override
Return type-id of the Owner class.
Definition: property.h:428
const size_t m_ownerHash
Base class type-id.
Definition: property.h:485
virtual void operator()(Owner *aOwner, T aValue)=0
virtual ~SETTER_BASE()
Definition: property.h:99
void operator()(Owner *aOwner, T aValue) override
Definition: property.h:114
FuncType m_func
Definition: property.h:120
SETTER(FuncType aFunc)
Definition: property.h:108
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()
Definition: property.h:579
virtual size_t DerivedHash() const =0
TYPE_CAST()
Definition: property.h:591
size_t DerivedHash() const override
Definition: property.h:612
const void * operator()(const void *aPointer) const override
Definition: property.h:601
size_t BaseHash() const override
Definition: property.h:607
void * operator()(void *aPointer) const override
Definition: property.h:595
static bool empty(const wxTextEntryBase *aCtrl)
#define TYPE_HASH(x)
Definition: property.h:63
PROPERTY_DISPLAY
Common property types.
Definition: property.h:54
@ PT_DEGREE
Angle expressed in degrees.
Definition: property.h:58
@ PT_COORD
Coordinate expressed in distance units (mm/inch)
Definition: property.h:57
@ PT_DECIDEGREE
Angle expressed in decidegrees.
Definition: property.h:59
@ PT_DEFAULT
Default property for a given type.
Definition: property.h:55
@ PT_SIZE
Size expressed in distance units (mm/inch)
Definition: property.h:56
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.
VECTOR3I res