KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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>
32
33#include <wx/any.h>
34#include <wx/string.h>
35#include <wx/bitmap.h>
36#include <wx/font.h> // required for propgrid
37#include <wx/validate.h> // required for propgrid
38#include <wx/propgrid/property.h>
39
40#include <functional>
41#include <unordered_map>
42#include <memory>
43#include <typeindex>
44#include <type_traits>
45
46class wxPGProperty;
47class INSPECTABLE;
48class PROPERTY_BASE;
49
50template<typename T>
51class ENUM_MAP;
52
55{
61};
62
64#define TYPE_HASH( x ) typeid( x ).hash_code()
65#define TYPE_NAME( x ) typeid( x ).name()
66//#define TYPE_HASH( x ) typeid( std::decay<x>::type ).hash_code()
67
68template<typename Owner, typename T>
70{
71public:
72 virtual ~GETTER_BASE() {}
73
74 virtual T operator()( const Owner* aOwner ) const = 0;
75};
76
77template<typename Owner, typename T, typename FuncType>
78class GETTER : public GETTER_BASE<Owner, T>
79{
80public:
81 GETTER( FuncType aFunc )
82 : m_func( aFunc )
83 {
84 wxCHECK( m_func, /*void*/ );
85 }
86
87 T operator()( const Owner* aOwner ) const override
88 {
89 return ( aOwner->*m_func )();
90 }
91
92private:
93 FuncType m_func;
94};
95
96template<typename Owner, typename T>
98{
99public:
100 virtual ~SETTER_BASE() {}
101
102 virtual void operator()( Owner* aOwner, T aValue ) = 0;
103};
104
105template<typename Owner, typename T, typename FuncType>
106class SETTER : public SETTER_BASE<Owner, T>
107{
108public:
109 SETTER( FuncType aFunc )
110 : m_func( aFunc )
111 {
112 wxCHECK( m_func, /*void*/ );
113 }
114
115 void operator()( Owner* aOwner, T aValue ) override
116 {
117 ( aOwner->*m_func )( aValue );
118 }
119
120private:
121 FuncType m_func;
122};
123
124
125template<typename Owner, typename T, typename Base = Owner>
127{
128public:
129 static GETTER_BASE<Owner, T>* Wrap( T (Base::*aFunc)() )
130 {
131 return new GETTER<Owner, T, T (Base::*)()>( aFunc );
132 }
133
134 constexpr static GETTER_BASE<Owner, T>* Wrap( const T (Base::*aFunc)() )
135 {
136 return new GETTER<Owner, T, T (Base::*)()>( aFunc );
137 }
138
139 constexpr static GETTER_BASE<Owner, T>* Wrap( const T& (Base::*aFunc)() )
140 {
141 return new GETTER<Owner, T, const T& (Base::*)()>( aFunc );
142 }
143
144 constexpr static GETTER_BASE<Owner, T>* Wrap( T (Base::*aFunc)() const )
145 {
146 return new GETTER<Owner, T, T (Base::*)() const>( aFunc );
147 }
148
149 constexpr static GETTER_BASE<Owner, T>* Wrap( const T (Base::*aFunc)() const )
150 {
151 return new GETTER<Owner, T, T (Base::*)() const>( aFunc );
152 }
153
154 constexpr static GETTER_BASE<Owner, T>* Wrap( const T& (Base::*aFunc)() const )
155 {
157 }
158
159 constexpr static SETTER_BASE<Owner, T>* Wrap( void (Base::*aFunc)( T ) )
160 {
161 return aFunc ? new SETTER<Owner, T, void (Base::*)( T )>( aFunc ) : nullptr;
162 }
163
164 constexpr static SETTER_BASE<Owner, T>* Wrap( void (Base::*aFunc)( T& ) )
165 {
166 return aFunc ? new SETTER<Owner, T, void (Base::*)( T& )>( aFunc ) : nullptr;
167 }
168
169 constexpr static SETTER_BASE<Owner, T>* Wrap( void (Base::*aFunc)( const T& ) )
170 {
171 return aFunc ? new SETTER<Owner, T, void (Base::*)( const T& )>( aFunc ) : nullptr;
172 }
173
174 METHOD() = delete;
175};
176
177
179{
180private:
182
183public:
184PROPERTY_BASE( const wxString& aName, PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
186 m_name( aName ),
187 m_display( aDisplay ),
188 m_coordType( aCoordType ),
190 m_hideFromRulesEditor( false ),
192 m_availFunc( [](INSPECTABLE*)->bool { return true; } ),
193 m_writeableFunc( [](INSPECTABLE*)->bool { return true; } ),
194 m_validator( NullValidator )
195 {
196 }
197
199 {
200 }
201
202 const wxString& Name() const { return m_name; }
203
208 virtual const wxPGChoices& Choices() const
209 {
210 static wxPGChoices empty;
211 return empty;
212 }
213
217 virtual void SetChoices( const wxPGChoices& aChoices )
218 {
219 wxFAIL; // only possible for PROPERTY_ENUM
220 }
221
226 virtual bool HasChoices() const
227 {
228 return false;
229 }
230
234 bool Available( INSPECTABLE* aObject ) const
235 {
236 return m_availFunc( aObject );
237 }
238
242 PROPERTY_BASE& SetAvailableFunc( std::function<bool(INSPECTABLE*)> aFunc )
243 {
244 m_availFunc = aFunc;
245 return *this;
246 }
247
248 virtual bool Writeable( INSPECTABLE* aObject ) const
249 {
250 return m_writeableFunc( aObject );
251 }
252
253 PROPERTY_BASE& SetWriteableFunc( std::function<bool(INSPECTABLE*)> aFunc )
254 {
255 m_writeableFunc = aFunc;
256 return *this;
257 }
258
262 virtual size_t OwnerHash() const = 0;
263
267 virtual size_t BaseHash() const = 0;
268
272 virtual size_t TypeHash() const = 0;
273
274 PROPERTY_DISPLAY Display() const { return m_display; }
275 PROPERTY_BASE& SetDisplay( PROPERTY_DISPLAY aDisplay ) { m_display = aDisplay; return *this; }
276
277 ORIGIN_TRANSFORMS::COORD_TYPES_T CoordType() const { return m_coordType; }
279 {
280 m_coordType = aType;
281 return *this;
282 }
283
284 bool IsHiddenFromPropertiesManager() const { return m_hideFromPropertiesManager; }
286 {
287 m_hideFromPropertiesManager = aHide;
288 return *this;
289 }
290
291 bool IsHiddenFromRulesEditor() const { return m_hideFromRulesEditor; }
293 {
294 m_hideFromRulesEditor = aHide;
295 return *this;
296 }
297
298 bool IsHiddenFromLibraryEditors() const { return m_hideFromLibraryEditors; }
300 {
301 m_hideFromLibraryEditors = aIsHidden;
302 return *this;
303 }
304
305 wxString Group() const { return m_group; }
306 PROPERTY_BASE& SetGroup( const wxString& aGroup ) { m_group = aGroup; return *this; }
307
309 {
310 m_validator = aValidator;
311 return *this;
312 }
313
314 VALIDATOR_RESULT Validate( const wxAny&& aValue, EDA_ITEM* aItem )
315 {
316 return m_validator( std::move( aValue ), aItem );
317 }
318
319 static VALIDATOR_RESULT NullValidator( const wxAny&& aValue, EDA_ITEM* aItem )
320 {
321 return std::nullopt;
322 }
323
324protected:
325 template<typename T>
326 void set( void* aObject, T aValue )
327 {
328 wxAny a = aValue;
329
330 // wxVariant will be type "long" even if the property is supposed to be
331 // unsigned. Let's trust that we're coming from the property grid where
332 // we used a UInt editor.
333 if( std::is_same<T, wxVariant>::value )
334 {
335 wxVariant var = static_cast<wxVariant>( aValue );
336 wxAny pv = getter( aObject );
337
338 if( pv.CheckType<unsigned>() )
339 {
340 a = static_cast<unsigned>( var.GetLong() );
341 }
342 else if( pv.CheckType<EDA_ANGLE>() )
343 {
344 EDA_ANGLE_VARIANT_DATA* ad = static_cast<EDA_ANGLE_VARIANT_DATA*>( var.GetData() );
345 a = ad->Angle();
346 }
347 else if( pv.CheckType<KIGFX::COLOR4D>() )
348 {
349 COLOR4D_VARIANT_DATA* cd = static_cast<COLOR4D_VARIANT_DATA*>( var.GetData() );
350 a = cd->Color();
351 }
352 }
353
354 setter( aObject, a );
355 }
356
357 template<typename T>
358 T get( const void* aObject ) const
359 {
360 wxAny a = getter( aObject );
361
362 // We don't currently have a bool type, so change it to a numeric
363 if( a.CheckType<bool>() )
364 a = a.RawAs<bool>() ? 1 : 0;
365
366 if ( !( std::is_enum<T>::value && a.CheckType<int>() ) && !a.CheckType<T>() )
367 throw std::invalid_argument( "Invalid requested type" );
368
369 return wxANY_AS( a, T );
370 }
371
372private:
373 virtual void setter( void* aObject, wxAny& aValue ) = 0;
374 virtual wxAny getter( const void* aObject ) const = 0;
375
376private:
382 const wxString m_name;
383
386
389
392
395
398
400 wxString m_group;
401
402 std::function<bool(INSPECTABLE*)> m_availFunc;
403
404 std::function<bool(INSPECTABLE*)> m_writeableFunc;
405
407
408 friend class INSPECTABLE;
409};
410
411
412template<typename Owner, typename T, typename Base = Owner>
414{
415public:
416 using BASE_TYPE = typename std::decay<T>::type;
417
418 template<typename SetType, typename GetType>
419 PROPERTY( const wxString& aName,
420 void ( Base::*aSetter )( SetType ), GetType( Base::*aGetter )(),
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 template<typename SetType, typename GetType>
429 PROPERTY( const wxString& aName,
430 void ( Base::*aSetter )( SetType ), GetType( Base::*aGetter )() const,
431 PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
433 : PROPERTY( aName, METHOD<Owner, T, Base>::Wrap( aSetter ),
434 METHOD<Owner, T, Base>::Wrap( aGetter ), aDisplay, aCoordType )
435 {
436 }
437
438 size_t OwnerHash() const override
439 {
440 return m_ownerHash;
441 }
442
443 size_t BaseHash() const override
444 {
445 return m_baseHash;
446 }
447
448 size_t TypeHash() const override
449 {
450 return m_typeHash;
451 }
452
453 bool Writeable( INSPECTABLE* aObject ) const override
454 {
455 return m_setter && PROPERTY_BASE::Writeable( aObject );
456 }
457
458protected:
461 : PROPERTY_BASE( aName, aDisplay, aCoordType ), m_setter( s ), m_getter( g ),
462 m_ownerHash( TYPE_HASH( Owner ) ), m_baseHash( TYPE_HASH( Base ) ),
464 {
465 }
466
467 virtual ~PROPERTY() {}
468
469 virtual void setter( void* obj, wxAny& v ) override
470 {
471 wxCHECK( m_setter, /*void*/ );
472
473 if( !v.CheckType<T>() )
474 throw std::invalid_argument( "Invalid type requested" );
475
476 Owner* o = reinterpret_cast<Owner*>( obj );
477 BASE_TYPE value = wxANY_AS(v, BASE_TYPE);
478 (*m_setter)( o, value );
479 }
480
481 virtual wxAny getter( const void* obj ) const override
482 {
483 const Owner* o = reinterpret_cast<const Owner*>( obj );
484 wxAny res = (*m_getter)( o );
485 return res;
486 }
487
489 std::unique_ptr<SETTER_BASE<Owner, T>> m_setter;
490
492 std::unique_ptr<GETTER_BASE<Owner, T>> m_getter;
493
495 const size_t m_ownerHash;
496
498 const size_t m_baseHash;
499
501 const size_t m_typeHash;
502};
503
504
505template<typename Owner, typename T, typename Base = Owner>
506class PROPERTY_ENUM : public PROPERTY<Owner, T, Base>
507{
508public:
509 template<typename SetType, typename GetType>
510 PROPERTY_ENUM( const wxString& aName,
511 void ( Base::*aSetter )( SetType ), GetType( Base::*aGetter )(),
512 PROPERTY_DISPLAY aDisplay = PT_DEFAULT )
513 : PROPERTY<Owner, T, Base>( aName, METHOD<Owner, T, Base>::Wrap( aSetter ),
514 METHOD<Owner, T, Base>::Wrap( aGetter ), aDisplay )
515 {
516 if ( std::is_enum<T>::value )
517 {
518 m_choices = ENUM_MAP<T>::Instance().Choices();
519 wxASSERT_MSG( m_choices.GetCount() > 0, wxT( "No enum choices defined" ) );
520 }
521 }
522
523 template<typename SetType, typename GetType>
524 PROPERTY_ENUM( const wxString& aName,
525 void ( Base::*aSetter )( SetType ), GetType( Base::*aGetter )() const,
526 PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
528 : PROPERTY<Owner, T, Base>( aName, METHOD<Owner, T, Base>::Wrap( aSetter ),
529 METHOD<Owner, T, Base>::Wrap( aGetter ), aDisplay, aCoordType )
530 {
531 if ( std::is_enum<T>::value )
532 {
533 m_choices = ENUM_MAP<T>::Instance().Choices();
534 wxASSERT_MSG( m_choices.GetCount() > 0, wxT( "No enum choices defined" ) );
535 }
536 }
537
538 void setter( void* obj, wxAny& v ) override
539 {
540 wxCHECK( ( PROPERTY<Owner, T, Base>::m_setter ), /*void*/ );
541 Owner* o = reinterpret_cast<Owner*>( obj );
542
543 if( v.CheckType<T>() )
544 {
545 T value = wxANY_AS(v, T);
547 }
548 else if (v.CheckType<int>() )
549 {
550 int value = wxANY_AS(v, int);
551 (*PROPERTY<Owner, T, Base>::m_setter)( o, static_cast<T>( value ) );
552 }
553 else
554 {
555 throw std::invalid_argument( "Invalid type requested" );
556 }
557 }
558
559 wxAny getter( const void* obj ) const override
560 {
561 const Owner* o = reinterpret_cast<const Owner*>( obj );
562 wxAny res = static_cast<T>( (*PROPERTY<Owner, T, Base>::m_getter)( o ) );
563 return res;
564 }
565
566 const wxPGChoices& Choices() const override
567 {
568 return m_choices.GetCount() > 0 ? m_choices : ENUM_MAP<T>::Instance().Choices();
569 }
570
571 void SetChoices( const wxPGChoices& aChoices ) override
572 {
573 m_choices = aChoices;
574 }
575
576 bool HasChoices() const override
577 {
578 return Choices().GetCount() > 0;
579 }
580
581protected:
582 wxPGChoices m_choices;
583};
584
585
587{
588public:
589 virtual ~TYPE_CAST_BASE() {}
590 virtual void* operator()( void* aPointer ) const = 0;
591 virtual const void* operator()( const void* aPointer ) const = 0;
592 virtual size_t BaseHash() const = 0;
593 virtual size_t DerivedHash() const = 0;
594};
595
596
597template<typename Base, typename Derived>
599{
600public:
602 {
603 }
604
605 void* operator()( void* aPointer ) const override
606 {
607 Base* base = reinterpret_cast<Base*>( aPointer );
608 return static_cast<Derived*>( base );
609 }
610
611 const void* operator()( const void* aPointer ) const override
612 {
613 const Base* base = reinterpret_cast<const Base*>( aPointer );
614 return static_cast<const Derived*>( base );
615 }
616
617 size_t BaseHash() const override
618 {
619 return TYPE_HASH( Base );
620 }
621
622 size_t DerivedHash() const override
623 {
624 return TYPE_HASH( Derived );
625 }
626};
627
628
629template<typename T>
631{
632public:
634 {
635 static ENUM_MAP<T> inst;
636 return inst;
637 }
638
639 ENUM_MAP& Map( T aValue, const wxString& aName )
640 {
641 m_choices.Add( aName, static_cast<int>( aValue ) );
642 m_reverseMap[ aName ] = aValue;
643 return *this;
644 }
645
646 ENUM_MAP& Undefined( T aValue )
647 {
648 m_undefined = aValue;
649 return *this;
650 }
651
652 const wxString& ToString( T value ) const
653 {
654 static const wxString s_undef = "UNDEFINED";
655
656 int idx = m_choices.Index( static_cast<int>( value ) );
657
658 if( idx >= 0 && idx < (int) m_choices.GetCount() )
659 return m_choices.GetLabel( static_cast<int>( idx ) );
660 else
661 return s_undef;
662 }
663
664 bool IsValueDefined( T value ) const
665 {
666 int idx = m_choices.Index( static_cast<int>( value ) );
667
668 if( idx >= 0 && idx < (int) m_choices.GetCount() )
669 return true;
670
671 return false;
672 }
673
674 T ToEnum( const wxString value )
675 {
676 if( m_reverseMap.count( value ) )
677 return m_reverseMap[ value ];
678 else
679 return m_undefined;
680 }
681
682 wxPGChoices& Choices()
683 {
684 return m_choices;
685 }
686
687private:
688 wxPGChoices m_choices;
689 std::unordered_map<wxString, T> m_reverseMap;
690 T m_undefined; // Returned if the string is not recognized
691
693 {
694 }
695};
696
697
698// Helper macros to handle enum types
699#define DECLARE_ENUM_TO_WXANY( type ) \
700 template <> \
701 class wxAnyValueTypeImpl<type> : public wxAnyValueTypeImplBase<type> \
702 { \
703 WX_DECLARE_ANY_VALUE_TYPE( wxAnyValueTypeImpl<type> ) \
704 public: \
705 wxAnyValueTypeImpl() : wxAnyValueTypeImplBase<type>() {} \
706 virtual ~wxAnyValueTypeImpl() {} \
707 virtual bool ConvertValue( const wxAnyValueBuffer& src, wxAnyValueType* dstType, \
708 wxAnyValueBuffer& dst ) const override \
709 { \
710 type value = GetValue( src ); \
711 ENUM_MAP<type>& conv = ENUM_MAP<type>::Instance(); \
712 if( ! conv.IsValueDefined( value ) ) \
713 { \
714 return false; \
715 } \
716 if( dstType->CheckType<wxString>() ) \
717 { \
718 wxAnyValueTypeImpl<wxString>::SetValue( conv.ToString( value ), dst ); \
719 return true; \
720 } \
721 if( dstType->CheckType<int>() ) \
722 { \
723 wxAnyValueTypeImpl<int>::SetValue( static_cast<int>( value ), dst ); \
724 return true; \
725 } \
726 else \
727 { \
728 return false; \
729 } \
730 } \
731 };
732
733#define IMPLEMENT_ENUM_TO_WXANY( type ) WX_IMPLEMENT_ANY_VALUE_TYPE( wxAnyValueTypeImpl<type> )
734
735#define ENUM_TO_WXANY( type ) \
736 DECLARE_ENUM_TO_WXANY( type ) \
737 IMPLEMENT_ENUM_TO_WXANY( type )
738
740#define NO_SETTER( owner, type ) ( ( void ( owner::* )( type ) ) nullptr )
741
742/*
743#define DECLARE_PROPERTY(owner,type,name,getter,setter) \
744namespace anonymous {\
745static PROPERTY<owner,type> prop##_owner##_name_( "##name#", setter, getter );\
746};
747*/
748#endif /* PROPERTY_H */
const KIGFX::COLOR4D & Color()
const EDA_ANGLE & Angle()
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
T ToEnum(const wxString value)
Definition: property.h:674
ENUM_MAP & Map(T aValue, const wxString &aName)
Definition: property.h:639
std::unordered_map< wxString, T > m_reverseMap
Definition: property.h:689
T m_undefined
Definition: property.h:690
static ENUM_MAP< T > & Instance()
Definition: property.h:633
const wxString & ToString(T value) const
Definition: property.h:652
bool IsValueDefined(T value) const
Definition: property.h:664
ENUM_MAP & Undefined(T aValue)
Definition: property.h:646
wxPGChoices & Choices()
Definition: property.h:682
wxPGChoices m_choices
Definition: property.h:688
virtual ~GETTER_BASE()
Definition: property.h:72
virtual T operator()(const Owner *aOwner) const =0
GETTER(FuncType aFunc)
Definition: property.h:81
FuncType m_func
Definition: property.h:93
T operator()(const Owner *aOwner) const override
Definition: property.h:87
Class that other classes need to inherit from, in order to be inspectable.
Definition: inspectable.h:36
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
static constexpr GETTER_BASE< Owner, T > * Wrap(const T(Base::*aFunc)())
Definition: property.h:134
static GETTER_BASE< Owner, T > * Wrap(T(Base::*aFunc)())
Definition: property.h:129
static constexpr GETTER_BASE< Owner, T > * Wrap(const T(Base::*aFunc)() const)
Definition: property.h:149
static constexpr GETTER_BASE< Owner, T > * Wrap(T(Base::*aFunc)() const)
Definition: property.h:144
static constexpr SETTER_BASE< Owner, T > * Wrap(void(Base::*aFunc)(const T &))
Definition: property.h:169
static constexpr GETTER_BASE< Owner, T > * Wrap(const T &(Base::*aFunc)())
Definition: property.h:139
static constexpr GETTER_BASE< Owner, T > * Wrap(const T &(Base::*aFunc)() const)
Definition: property.h:154
static constexpr SETTER_BASE< Owner, T > * Wrap(void(Base::*aFunc)(T))
Definition: property.h:159
static constexpr SETTER_BASE< Owner, T > * Wrap(void(Base::*aFunc)(T &))
Definition: property.h:164
METHOD()=delete
COORD_TYPES_T
The supported Display Origin Transform types.
bool IsHiddenFromPropertiesManager() const
Definition: property.h:284
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:397
const wxString m_name
Permanent identifier for this property.
Definition: property.h:382
VALIDATOR_RESULT Validate(const wxAny &&aValue, EDA_ITEM *aItem)
Definition: property.h:314
std::function< bool(INSPECTABLE *)> m_writeableFunc
Eval to determine if prop is read-only.
Definition: property.h:404
std::function< bool(INSPECTABLE *)> m_availFunc
Eval to determine if prop is available.
Definition: property.h:402
PROPERTY_VALIDATOR_FN m_validator
Definition: property.h:406
PROPERTY_BASE & SetAvailableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Set a callback function to determine whether an object provides this property.
Definition: property.h:242
PROPERTY_BASE & SetDisplay(PROPERTY_DISPLAY aDisplay)
Definition: property.h:275
PROPERTY_DISPLAY Display() const
Definition: property.h:274
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:184
static VALIDATOR_RESULT NullValidator(const wxAny &&aValue, EDA_ITEM *aItem)
Definition: property.h:319
wxString Group() const
Definition: property.h:305
PROPERTY_BASE & SetWriteableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Definition: property.h:253
PROPERTY_BASE & SetGroup(const wxString &aGroup)
Definition: property.h:306
ORIGIN_TRANSFORMS::COORD_TYPES_T CoordType() const
Definition: property.h:277
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:278
PROPERTY_DISPLAY m_display
The display style controls how properties are edited in the properties manager GUI.
Definition: property.h:385
virtual bool HasChoices() const
Return true if this PROPERTY has a limited set of possible values.
Definition: property.h:226
ORIGIN_TRANSFORMS::COORD_TYPES_T m_coordType
The coordinate type controls how distances are mapped to the user coordinate system.
Definition: property.h:388
virtual bool Writeable(INSPECTABLE *aObject) const
Definition: property.h:248
virtual void setter(void *aObject, wxAny &aValue)=0
virtual ~PROPERTY_BASE()
Definition: property.h:198
wxString m_group
Optional group identifier.
Definition: property.h:400
bool Available(INSPECTABLE *aObject) const
Return true if aObject offers this PROPERTY.
Definition: property.h:234
PROPERTY_BASE & SetValidator(PROPERTY_VALIDATOR_FN &&aValidator)
Definition: property.h:308
bool m_hideFromPropertiesManager
Some properties should not be shown in the Properties Manager GUI.
Definition: property.h:391
PROPERTY_BASE & SetIsHiddenFromPropertiesManager(bool aHide=true)
Definition: property.h:285
bool m_hideFromRulesEditor
Some properties should not be shown in the Custom Rules editor autocomplete.
Definition: property.h:394
void set(void *aObject, T aValue)
Definition: property.h:326
const wxString & Name() const
Definition: property.h:202
bool IsHiddenFromRulesEditor() const
Definition: property.h:291
virtual const wxPGChoices & Choices() const
Return a limited set of possible values (e.g.
Definition: property.h:208
virtual void SetChoices(const wxPGChoices &aChoices)
Set the possible values for for the property.
Definition: property.h:217
virtual size_t OwnerHash() const =0
Return type-id of the Owner class.
PROPERTY_BASE & SetIsHiddenFromRulesEditor(bool aHide=true)
Definition: property.h:292
bool IsHiddenFromLibraryEditors() const
Definition: property.h:298
T get(const void *aObject) const
Definition: property.h:358
PROPERTY_BASE & SetIsHiddenFromLibraryEditors(bool aIsHidden=true)
Definition: property.h:299
const wxPGChoices & Choices() const override
Return a limited set of possible values (e.g.
Definition: property.h:566
bool HasChoices() const override
Return true if this PROPERTY has a limited set of possible values.
Definition: property.h:576
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:524
void setter(void *obj, wxAny &v) override
Definition: property.h:538
PROPERTY_ENUM(const wxString &aName, void(Base::*aSetter)(SetType), GetType(Base::*aGetter)(), PROPERTY_DISPLAY aDisplay=PT_DEFAULT)
Definition: property.h:510
wxPGChoices m_choices
Definition: property.h:582
wxAny getter(const void *obj) const override
Set method.
Definition: property.h:559
void SetChoices(const wxPGChoices &aChoices) override
Set the possible values for for the property.
Definition: property.h:571
std::unique_ptr< SETTER_BASE< Owner, T > > m_setter
Get method.
Definition: property.h:489
const size_t m_baseHash
Property value type-id.
Definition: property.h:498
size_t TypeHash() const override
Return type-id of the property type.
Definition: property.h:448
typename std::decay< T >::type BASE_TYPE
Definition: property.h:416
const size_t m_typeHash
Definition: property.h:501
virtual ~PROPERTY()
Definition: property.h:467
virtual void setter(void *obj, wxAny &v) override
Definition: property.h:469
size_t BaseHash() const override
Return type-id of the Base class.
Definition: property.h:443
bool Writeable(INSPECTABLE *aObject) const override
Definition: property.h:453
virtual wxAny getter(const void *obj) const override
Set method.
Definition: property.h:481
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:429
std::unique_ptr< GETTER_BASE< Owner, T > > m_getter
Owner class type-id.
Definition: property.h:492
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:419
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:459
size_t OwnerHash() const override
Return type-id of the Owner class.
Definition: property.h:438
const size_t m_ownerHash
Base class type-id.
Definition: property.h:495
virtual void operator()(Owner *aOwner, T aValue)=0
virtual ~SETTER_BASE()
Definition: property.h:100
void operator()(Owner *aOwner, T aValue) override
Definition: property.h:115
FuncType m_func
Definition: property.h:121
SETTER(FuncType aFunc)
Definition: property.h:109
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:589
virtual size_t DerivedHash() const =0
TYPE_CAST()
Definition: property.h:601
size_t DerivedHash() const override
Definition: property.h:622
const void * operator()(const void *aPointer) const override
Definition: property.h:611
size_t BaseHash() const override
Definition: property.h:617
void * operator()(void *aPointer) const override
Definition: property.h:605
static bool empty(const wxTextEntryBase *aCtrl)
#define TYPE_HASH(x)
Definition: property.h:64
PROPERTY_DISPLAY
Common property types.
Definition: property.h:55
@ PT_DEGREE
Angle expressed in degrees.
Definition: property.h:59
@ PT_COORD
Coordinate expressed in distance units (mm/inch)
Definition: property.h:58
@ PT_DECIDEGREE
Angle expressed in decidegrees.
Definition: property.h:60
@ PT_DEFAULT
Default property for a given type.
Definition: property.h:56
@ PT_SIZE
Size expressed in distance units (mm/inch)
Definition: property.h:57
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