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 The 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#ifdef DEBUG
41#include <wx/wxcrt.h>
42#endif
43
44#include <functional>
45#include <unordered_map>
46#include <memory>
47#include <typeindex>
48#include <type_traits>
49#include <wx/translation.h>
51
52class wxPGProperty;
53class INSPECTABLE;
54class PROPERTY_BASE;
55
56template<typename T>
57class ENUM_MAP;
58
72
74#define TYPE_HASH( x ) typeid( x ).hash_code()
75#define TYPE_NAME( x ) typeid( x ).name()
76//#define TYPE_HASH( x ) typeid( std::decay<x>::type ).hash_code()
77
78template<typename Owner, typename T>
80{
81public:
82 virtual ~GETTER_BASE() {}
83
84 virtual T operator()( const Owner* aOwner ) const = 0;
85};
86
87template<typename Owner, typename T, typename FuncType>
88class GETTER : public GETTER_BASE<Owner, T>
89{
90public:
91 GETTER( FuncType aFunc )
92 : m_func( aFunc )
93 {
94 wxCHECK( m_func, /*void*/ );
95 }
96
97 T operator()( const Owner* aOwner ) const override
98 {
99 return ( aOwner->*m_func )();
100 }
101
102private:
103 FuncType m_func;
104};
105
106template<typename Owner, typename T>
108{
109public:
110 virtual ~SETTER_BASE() {}
111
112 virtual void operator()( Owner* aOwner, T aValue ) = 0;
113};
114
115template<typename Owner, typename T, typename FuncType>
116class SETTER : public SETTER_BASE<Owner, T>
117{
118public:
119 SETTER( FuncType aFunc )
120 : m_func( aFunc )
121 {
122 wxCHECK( m_func, /*void*/ );
123 }
124
125 void operator()( Owner* aOwner, T aValue ) override
126 {
127 ( aOwner->*m_func )( aValue );
128 }
129
130private:
131 FuncType m_func;
132};
133
134#if defined( _MSC_VER )
135#pragma warning( push )
136#pragma warning( disable : 5266 ) // 'const' qualifier on return type has no effect
137#endif
138
139template<typename Owner, typename T, typename Base = Owner>
141{
142public:
143 static GETTER_BASE<Owner, T>* Wrap( T (Base::*aFunc)() )
144 {
145 return new GETTER<Owner, T, T (Base::*)()>( aFunc );
146 }
147
148 constexpr static GETTER_BASE<Owner, T>* Wrap( const T (Base::*aFunc)() )
149 {
150 return new GETTER<Owner, T, T (Base::*)()>( aFunc );
151 }
152
153 constexpr static GETTER_BASE<Owner, T>* Wrap( const T& (Base::*aFunc)() )
154 {
155 return new GETTER<Owner, T, const T& (Base::*)()>( aFunc );
156 }
157
158 constexpr static GETTER_BASE<Owner, T>* Wrap( T (Base::*aFunc)() const )
159 {
160 return new GETTER<Owner, T, T (Base::*)() const>( aFunc );
161 }
162
163 constexpr static GETTER_BASE<Owner, T>* Wrap( const T (Base::*aFunc)() const )
164 {
165 return new GETTER<Owner, T, T (Base::*)() const>( aFunc );
166 }
167
168 constexpr static GETTER_BASE<Owner, T>* Wrap( const T& (Base::*aFunc)() const )
169 {
171 }
172
173 constexpr static SETTER_BASE<Owner, T>* Wrap( void (Base::*aFunc)( T ) )
174 {
175 return aFunc ? new SETTER<Owner, T, void (Base::*)( T )>( aFunc ) : nullptr;
176 }
177
178 constexpr static SETTER_BASE<Owner, T>* Wrap( void (Base::*aFunc)( T& ) )
179 {
180 return aFunc ? new SETTER<Owner, T, void (Base::*)( T& )>( aFunc ) : nullptr;
181 }
182
183 constexpr static SETTER_BASE<Owner, T>* Wrap( void (Base::*aFunc)( const T& ) )
184 {
185 return aFunc ? new SETTER<Owner, T, void (Base::*)( const T& )>( aFunc ) : nullptr;
186 }
187
188 METHOD() = delete;
189};
190
191#if defined( _MSC_VER )
192#pragma warning( pop )
193#endif
194
196{
197private:
199
200public:
201 PROPERTY_BASE( const wxString& aName, PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
203 m_name( aName ),
204 m_display( aDisplay ),
205 m_coordType( aCoordType ),
209 m_hideFromRulesEditor( false ),
210 m_availFunc( [](INSPECTABLE*)->bool { return true; } ),
211 m_writeableFunc( [](INSPECTABLE*)->bool { return true; } ),
212 m_validator( NullValidator )
213 {
214 }
215
217 {
218 }
219
220 const wxString& Name() const { return m_name; }
221
226 virtual const wxPGChoices& Choices() const
227 {
228 static wxPGChoices empty;
229 return empty;
230 }
231
232 virtual void TranslateChoices() {}
233
237 virtual void SetChoices( const wxPGChoices& aChoices )
238 {
239 wxFAIL; // only possible for PROPERTY_ENUM
240 }
241
246 virtual bool HasChoices() const
247 {
248 return m_choicesFunc != nullptr;
249 }
250
254 bool Available( INSPECTABLE* aObject ) const
255 {
256 return m_availFunc( aObject );
257 }
258
262 PROPERTY_BASE& SetAvailableFunc( std::function<bool(INSPECTABLE*)> aFunc )
263 {
264 m_availFunc = std::move( aFunc );
265 return *this;
266 }
267
268 wxPGChoices GetChoices( INSPECTABLE* aObject ) const
269 {
270 if( m_choicesFunc )
271 return m_choicesFunc( aObject );
272
273 return {};
274 }
275
276 PROPERTY_BASE& SetChoicesFunc( std::function<wxPGChoices(INSPECTABLE*)> aFunc )
277 {
278 m_choicesFunc = std::move( aFunc );
279 return *this;
280 }
281
282 virtual bool Writeable( INSPECTABLE* aObject ) const
283 {
284 return m_writeableFunc( aObject );
285 }
286
287 PROPERTY_BASE& SetWriteableFunc( std::function<bool(INSPECTABLE*)> aFunc )
288 {
289 m_writeableFunc = std::move( aFunc );
290 return *this;
291 }
292
296 virtual size_t OwnerHash() const = 0;
297
301 virtual size_t BaseHash() const = 0;
302
306 virtual size_t TypeHash() const = 0;
307
309 PROPERTY_BASE& SetDisplay( PROPERTY_DISPLAY aDisplay ) { m_display = aDisplay; return *this; }
310
313 {
314 m_coordType = aType;
315 return *this;
316 }
317
320 {
322 return *this;
323 }
324
327 {
328 m_hideFromRulesEditor = aHide;
329 return *this;
330 }
331
334 {
335 m_hideFromLibraryEditors = aIsHidden;
336 return *this;
337 }
338
341 {
342 m_hideFromDesignEditors = aIsHidden;
343 return *this;
344 }
345
346 wxString Group() const { return m_group; }
347 PROPERTY_BASE& SetGroup( const wxString& aGroup ) { m_group = aGroup; return *this; }
348
350 {
351 m_validator = aValidator;
352 return *this;
353 }
354
355 VALIDATOR_RESULT Validate( const wxAny&& aValue, EDA_ITEM* aItem )
356 {
357 return m_validator( std::move( aValue ), aItem );
358 }
359
360 static VALIDATOR_RESULT NullValidator( const wxAny&& aValue, EDA_ITEM* aItem )
361 {
362 return std::nullopt;
363 }
364
365protected:
366 template<typename T>
367 void set( void* aObject, T aValue )
368 {
369 wxAny a = aValue;
370
371 // wxVariant will be type "long" even if the property is supposed to be
372 // unsigned. Let's trust that we're coming from the property grid where
373 // we used a UInt editor.
374 if( std::is_same<T, wxVariant>::value )
375 {
376 wxVariant var = static_cast<wxVariant>( aValue );
377 wxAny pv = getter( aObject );
378
379 if( pv.CheckType<unsigned>() )
380 {
381 a = static_cast<unsigned>( var.GetLong() );
382 }
383 else if( pv.CheckType<std::optional<int>>() )
384 {
385 auto* data = static_cast<STD_OPTIONAL_INT_VARIANT_DATA*>( var.GetData() );
386 a = data->Value();
387 }
388 else if( pv.CheckType<std::optional<double>>() )
389 {
390 auto* data = static_cast<STD_OPTIONAL_DOUBLE_VARIANT_DATA*>( var.GetData() );
391 a = data->Value();
392 }
393 else if( pv.CheckType<EDA_ANGLE>() )
394 {
395 EDA_ANGLE_VARIANT_DATA* ad = static_cast<EDA_ANGLE_VARIANT_DATA*>( var.GetData() );
396 a = ad->Angle();
397 }
398 else if( pv.CheckType<KIGFX::COLOR4D>() )
399 {
400 COLOR4D_VARIANT_DATA* cd = static_cast<COLOR4D_VARIANT_DATA*>( var.GetData() );
401 a = cd->Color();
402 }
403 }
404
405 setter( aObject, a );
406 }
407
408 template<typename T>
409 T get( const void* aObject ) const
410 {
411 wxAny a = getter( aObject );
412
413 // We don't currently have a bool type, so change it to a numeric
414 if( a.CheckType<bool>() )
415 a = a.RawAs<bool>() ? 1 : 0;
416
417 if ( !( std::is_enum<T>::value && a.CheckType<int>() ) && !a.CheckType<T>() )
418 throw std::invalid_argument( "Invalid requested type" );
419
420 return wxANY_AS( a, T );
421 }
422
423private:
424 virtual void setter( void* aObject, wxAny& aValue ) = 0;
425 virtual wxAny getter( const void* aObject ) const = 0;
426
427private:
433 const wxString m_name;
434
437
440
441 bool m_hideFromPropertiesManager; // Do not show in Properties Manager
442 bool m_hideFromLibraryEditors; // Do not show in Properties Manager of symbol or
443 // footprint editors
444 bool m_hideFromDesignEditors; // Do not show in Properties Manager of schematic or
445 // board editors
446 bool m_hideFromRulesEditor; // Do not show in Custom Rules editor autocomplete
447
449 wxString m_group;
450
451 std::function<bool(INSPECTABLE*)> m_availFunc;
452
453 std::function<bool(INSPECTABLE*)> m_writeableFunc;
454
455 std::function<wxPGChoices(INSPECTABLE*)> m_choicesFunc;
456
458
459 friend class INSPECTABLE;
460};
461
462
463template<typename Owner, typename T, typename Base = Owner>
465{
466public:
467 using BASE_TYPE = typename std::decay<T>::type;
468
469 template<typename SetType, typename GetType>
470 PROPERTY( const wxString& aName,
471 void ( Base::*aSetter )( SetType ),
472 GetType( Base::*aGetter )(),
473 PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
475 PROPERTY( aName,
476 METHOD<Owner, T, Base>::Wrap( aSetter ),
477 METHOD<Owner, T, Base>::Wrap( aGetter ),
478 aDisplay, aCoordType )
479 {
480 }
481
482 template<typename SetType, typename GetType>
483 PROPERTY( const wxString& aName,
484 void ( Base::*aSetter )( SetType ),
485 GetType( Base::*aGetter )() const,
486 PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
488 PROPERTY( aName,
489 METHOD<Owner, T, Base>::Wrap( aSetter ),
490 METHOD<Owner, T, Base>::Wrap( aGetter ),
491 aDisplay, aCoordType )
492 {
493 }
494
495 size_t OwnerHash() const override
496 {
497 return m_ownerHash;
498 }
499
500 size_t BaseHash() const override
501 {
502 return m_baseHash;
503 }
504
505 size_t TypeHash() const override
506 {
507 return m_typeHash;
508 }
509
510 bool Writeable( INSPECTABLE* aObject ) const override
511 {
512 return m_setter && PROPERTY_BASE::Writeable( aObject );
513 }
514
515protected:
516 PROPERTY( const wxString& aName,
520 PROPERTY_BASE( aName, aDisplay, aCoordType ),
521 m_setter( s ),
522 m_getter( g ),
523 m_ownerHash( TYPE_HASH( Owner ) ),
524 m_baseHash( TYPE_HASH( Base ) ),
526 {
527 }
528
529 virtual ~PROPERTY() {}
530
531 virtual void setter( void* obj, wxAny& v ) override
532 {
533 wxCHECK( m_setter, /*void*/ );
534
535 BASE_TYPE value;
536
537 if( !v.GetAs( &value ) )
538 throw std::invalid_argument( "Invalid type requested" );
539
540 Owner* o = reinterpret_cast<Owner*>( obj );
541 (*m_setter)( o, value );
542 }
543
544 virtual wxAny getter( const void* obj ) const override
545 {
546 const Owner* o = reinterpret_cast<const Owner*>( obj );
547 wxAny res = (*m_getter)( o );
548 return res;
549 }
550
552 std::unique_ptr<SETTER_BASE<Owner, T>> m_setter;
553
555 std::unique_ptr<GETTER_BASE<Owner, T>> m_getter;
556
558 const size_t m_ownerHash;
559
561 const size_t m_baseHash;
562
564 const size_t m_typeHash;
565};
566
567
568template<typename Owner, typename T, typename Base = Owner>
569class PROPERTY_ENUM : public PROPERTY<Owner, T, Base>
570{
571public:
572 template<typename SetType, typename GetType>
573 PROPERTY_ENUM( const wxString& aName,
574 void ( Base::*aSetter )( SetType ),
575 GetType( Base::*aGetter )(),
576 PROPERTY_DISPLAY aDisplay = PT_DEFAULT ) :
577 PROPERTY<Owner, T, Base>( aName,
578 METHOD<Owner, T, Base>::Wrap( aSetter ),
579 METHOD<Owner, T, Base>::Wrap( aGetter ),
580 aDisplay ),
581 m_choicesFromENUM_MAP( false )
582 {
583 if ( std::is_enum<T>::value )
584 {
585 m_choices = ENUM_MAP<T>::Instance().Choices();
587 wxASSERT_MSG( m_choices.GetCount() > 0, wxT( "No enum choices defined" ) );
588 }
589 }
590
591 template<typename SetType, typename GetType>
592 PROPERTY_ENUM( const wxString& aName,
593 void ( Base::*aSetter )( SetType ),
594 GetType( Base::*aGetter )() const,
595 PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
597 PROPERTY<Owner, T, Base>( aName,
598 METHOD<Owner, T, Base>::Wrap( aSetter ),
599 METHOD<Owner, T, Base>::Wrap( aGetter ),
600 aDisplay, aCoordType ),
601 m_choicesFromENUM_MAP( false )
602 {
603 if ( std::is_enum<T>::value )
604 {
605 m_choices = ENUM_MAP<T>::Instance().Choices();
607 wxASSERT_MSG( m_choices.GetCount() > 0, wxT( "No enum choices defined" ) );
608 }
609 }
610
611 void setter( void* obj, wxAny& v ) override
612 {
613 wxCHECK( ( PROPERTY<Owner, T, Base>::m_setter ), /*void*/ );
614 Owner* o = reinterpret_cast<Owner*>( obj );
615
616 if( v.CheckType<T>() )
617 {
618 T value = wxANY_AS(v, T);
620 }
621 else if (v.CheckType<int>() )
622 {
623 int value = wxANY_AS(v, int);
624 (*PROPERTY<Owner, T, Base>::m_setter)( o, static_cast<T>( value ) );
625 }
626 else
627 {
628 throw std::invalid_argument( "Invalid type requested" );
629 }
630 }
631
632 wxAny getter( const void* obj ) const override
633 {
634 const Owner* o = reinterpret_cast<const Owner*>( obj );
635 wxAny res = static_cast<T>( (*PROPERTY<Owner, T, Base>::m_getter)( o ) );
636 return res;
637 }
638
639 const wxPGChoices& Choices() const override
640 {
641 return m_choices.GetCount() > 0 ? m_choices : ENUM_MAP<T>::Instance().Choices();
642 }
643
644 void TranslateChoices() override
645 {
646 if( m_choicesFromENUM_MAP && std::is_enum<T>::value )
647 {
648 m_choices.Clear();
649
650 wxPGChoices& choices = ENUM_MAP<T>::Instance().Choices();
651
652 for( unsigned ii = 0; ii < choices.GetCount(); ++ii )
653 m_choices.Add( wxGetTranslation( choices.GetLabel( ii ) ), choices.GetValue( ii ) );
654 }
655 }
656
657 void SetChoices( const wxPGChoices& aChoices ) override
658 {
659 m_choices = aChoices;
660 m_choicesFromENUM_MAP = false;
661 }
662
663 bool HasChoices() const override
664 {
665 return Choices().GetCount() > 0;
666 }
667
668protected:
670 wxPGChoices m_choices;
671};
672
673
675{
676public:
677 virtual ~TYPE_CAST_BASE() {}
678 virtual void* operator()( void* aPointer ) const = 0;
679 virtual const void* operator()( const void* aPointer ) const = 0;
680 virtual size_t BaseHash() const = 0;
681 virtual size_t DerivedHash() const = 0;
682};
683
684
685template<typename Base, typename Derived>
687{
688public:
690 {
691 }
692
693 void* operator()( void* aPointer ) const override
694 {
695 Base* base = reinterpret_cast<Base*>( aPointer );
696 return static_cast<Derived*>( base );
697 }
698
699 const void* operator()( const void* aPointer ) const override
700 {
701 const Base* base = reinterpret_cast<const Base*>( aPointer );
702 return static_cast<const Derived*>( base );
703 }
704
705 size_t BaseHash() const override
706 {
707 return TYPE_HASH( Base );
708 }
709
710 size_t DerivedHash() const override
711 {
712 return TYPE_HASH( Derived );
713 }
714};
715
716
717template<typename T>
719{
720public:
722 {
723 static ENUM_MAP<T> inst;
724 return inst;
725 }
726
727 ENUM_MAP& Map( T aValue, const wxString& aName )
728 {
729 m_choices.Add( aName, static_cast<int>( aValue ) );
730 m_reverseMap[ aName ] = aValue;
731 return *this;
732 }
733
735 {
736 m_undefined = aValue;
737 return *this;
738 }
739
740 const wxString& ToString( T value ) const
741 {
742 static const wxString s_undef = "UNDEFINED";
743
744 int idx = m_choices.Index( static_cast<int>( value ) );
745
746 if( idx >= 0 && idx < (int) m_choices.GetCount() )
747 return m_choices.GetLabel( static_cast<int>( idx ) );
748 else
749 return s_undef;
750 }
751
752 bool IsValueDefined( T value ) const
753 {
754 int idx = m_choices.Index( static_cast<int>( value ) );
755
756 if( idx >= 0 && idx < (int) m_choices.GetCount() )
757 return true;
758
759 return false;
760 }
761
762 T ToEnum( const wxString value )
763 {
764 if( m_reverseMap.count( value ) )
765 return m_reverseMap[ value ];
766 else
767 return m_undefined;
768 }
769
770 wxPGChoices& Choices()
771 {
772 return m_choices;
773 }
774
775private:
776 wxPGChoices m_choices;
777 std::unordered_map<wxString, T> m_reverseMap;
778 T m_undefined; // Returned if the string is not recognized
779
781 {
782 }
783};
784
785
786// Helper macros to handle enum types
787#define DECLARE_ENUM_TO_WXANY( type ) \
788 template <> \
789 class wxAnyValueTypeImpl<type> : public wxAnyValueTypeImplBase<type> \
790 { \
791 WX_DECLARE_ANY_VALUE_TYPE( wxAnyValueTypeImpl<type> ) \
792 public: \
793 wxAnyValueTypeImpl() : wxAnyValueTypeImplBase<type>() {} \
794 virtual ~wxAnyValueTypeImpl() {} \
795 virtual bool ConvertValue( const wxAnyValueBuffer& src, wxAnyValueType* dstType, \
796 wxAnyValueBuffer& dst ) const override \
797 { \
798 type value = GetValue( src ); \
799 ENUM_MAP<type>& conv = ENUM_MAP<type>::Instance(); \
800 if( ! conv.IsValueDefined( value ) ) \
801 { \
802 return false; \
803 } \
804 if( dstType->CheckType<wxString>() ) \
805 { \
806 wxAnyValueTypeImpl<wxString>::SetValue( conv.ToString( value ), dst ); \
807 return true; \
808 } \
809 if( dstType->CheckType<int>() ) \
810 { \
811 wxAnyValueTypeImpl<int>::SetValue( static_cast<int>( value ), dst ); \
812 return true; \
813 } \
814 else \
815 { \
816 return false; \
817 } \
818 } \
819 };
820
821#define IMPLEMENT_ENUM_TO_WXANY( type ) WX_IMPLEMENT_ANY_VALUE_TYPE( wxAnyValueTypeImpl<type> )
822
823#define ENUM_TO_WXANY( type ) \
824 DECLARE_ENUM_TO_WXANY( type ) \
825 IMPLEMENT_ENUM_TO_WXANY( type )
826
828#define NO_SETTER( owner, type ) ( ( void ( owner::* )( type ) ) nullptr )
829
830/*
831#define DECLARE_PROPERTY(owner,type,name,getter,setter) \
832namespace anonymous {\
833static PROPERTY<owner,type> prop##_owner##_name_( "##name#", setter, getter );\
834};
835*/
836#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:98
T ToEnum(const wxString value)
Definition property.h:762
ENUM_MAP & Map(T aValue, const wxString &aName)
Definition property.h:727
std::unordered_map< wxString, T > m_reverseMap
Definition property.h:777
T m_undefined
Definition property.h:778
static ENUM_MAP< T > & Instance()
Definition property.h:721
const wxString & ToString(T value) const
Definition property.h:740
bool IsValueDefined(T value) const
Definition property.h:752
ENUM_MAP & Undefined(T aValue)
Definition property.h:734
wxPGChoices & Choices()
Definition property.h:770
wxPGChoices m_choices
Definition property.h:776
virtual ~GETTER_BASE()
Definition property.h:82
virtual T operator()(const Owner *aOwner) const =0
GETTER(FuncType aFunc)
Definition property.h:91
FuncType m_func
Definition property.h:103
T operator()(const Owner *aOwner) const override
Definition property.h:97
Class that other classes need to inherit from, in order to be inspectable.
Definition inspectable.h:37
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:148
static GETTER_BASE< Owner, T > * Wrap(T(Base::*aFunc)())
Definition property.h:143
static constexpr GETTER_BASE< Owner, T > * Wrap(const T(Base::*aFunc)() const)
Definition property.h:163
static constexpr GETTER_BASE< Owner, T > * Wrap(T(Base::*aFunc)() const)
Definition property.h:158
static constexpr SETTER_BASE< Owner, T > * Wrap(void(Base::*aFunc)(const T &))
Definition property.h:183
static constexpr GETTER_BASE< Owner, T > * Wrap(const T &(Base::*aFunc)())
Definition property.h:153
static constexpr GETTER_BASE< Owner, T > * Wrap(const T &(Base::*aFunc)() const)
Definition property.h:168
static constexpr SETTER_BASE< Owner, T > * Wrap(void(Base::*aFunc)(T))
Definition property.h:173
static constexpr SETTER_BASE< Owner, T > * Wrap(void(Base::*aFunc)(T &))
Definition property.h:178
METHOD()=delete
COORD_TYPES_T
The supported Display Origin Transform types.
PROPERTY_BASE & SetChoicesFunc(std::function< wxPGChoices(INSPECTABLE *)> aFunc)
Definition property.h:276
bool IsHiddenFromPropertiesManager() const
Definition property.h:318
virtual size_t TypeHash() const =0
Return type-id of the property type.
bool m_hideFromLibraryEditors
Definition property.h:442
const wxString m_name
Permanent identifier for this property.
Definition property.h:433
VALIDATOR_RESULT Validate(const wxAny &&aValue, EDA_ITEM *aItem)
Definition property.h:355
virtual void TranslateChoices()
Definition property.h:232
std::function< bool(INSPECTABLE *)> m_writeableFunc
Eval to determine if prop is read-only.
Definition property.h:453
std::function< bool(INSPECTABLE *)> m_availFunc
Eval to determine if prop is available.
Definition property.h:451
PROPERTY_VALIDATOR_FN m_validator
Definition property.h:457
bool IsHiddenFromDesignEditors() const
Definition property.h:339
PROPERTY_BASE & SetAvailableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Set a callback function to determine whether an object provides this property.
Definition property.h:262
PROPERTY_BASE & SetDisplay(PROPERTY_DISPLAY aDisplay)
Definition property.h:309
std::function< wxPGChoices(INSPECTABLE *)> m_choicesFunc
Definition property.h:455
PROPERTY_DISPLAY Display() const
Definition property.h:308
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:201
static VALIDATOR_RESULT NullValidator(const wxAny &&aValue, EDA_ITEM *aItem)
Definition property.h:360
wxString Group() const
Definition property.h:346
PROPERTY_BASE & SetWriteableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Definition property.h:287
PROPERTY_BASE & SetGroup(const wxString &aGroup)
Definition property.h:347
ORIGIN_TRANSFORMS::COORD_TYPES_T CoordType() const
Definition property.h:311
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:312
PROPERTY_DISPLAY m_display
The display style controls how properties are edited in the properties manager GUI.
Definition property.h:436
virtual bool HasChoices() const
Return true if this PROPERTY has a limited set of possible values.
Definition property.h:246
ORIGIN_TRANSFORMS::COORD_TYPES_T m_coordType
The coordinate type controls how distances are mapped to the user coordinate system.
Definition property.h:439
virtual bool Writeable(INSPECTABLE *aObject) const
Definition property.h:282
wxPGChoices GetChoices(INSPECTABLE *aObject) const
Definition property.h:268
virtual void setter(void *aObject, wxAny &aValue)=0
virtual ~PROPERTY_BASE()
Definition property.h:216
wxString m_group
Optional group identifier.
Definition property.h:449
bool Available(INSPECTABLE *aObject) const
Return true if aObject offers this PROPERTY.
Definition property.h:254
PROPERTY_BASE & SetValidator(PROPERTY_VALIDATOR_FN &&aValidator)
Definition property.h:349
bool m_hideFromPropertiesManager
Definition property.h:441
bool m_hideFromDesignEditors
Definition property.h:444
PROPERTY_BASE & SetIsHiddenFromDesignEditors(bool aIsHidden=true)
Definition property.h:340
PROPERTY_BASE & SetIsHiddenFromPropertiesManager(bool aHide=true)
Definition property.h:319
bool m_hideFromRulesEditor
Definition property.h:446
friend class INSPECTABLE
Definition property.h:459
void set(void *aObject, T aValue)
Definition property.h:367
const wxString & Name() const
Definition property.h:220
bool IsHiddenFromRulesEditor() const
Definition property.h:325
virtual const wxPGChoices & Choices() const
Return a limited set of possible values (e.g.
Definition property.h:226
virtual void SetChoices(const wxPGChoices &aChoices)
Set the possible values for for the property.
Definition property.h:237
virtual size_t OwnerHash() const =0
Return type-id of the Owner class.
PROPERTY_BASE & SetIsHiddenFromRulesEditor(bool aHide=true)
Definition property.h:326
bool IsHiddenFromLibraryEditors() const
Definition property.h:332
T get(const void *aObject) const
Definition property.h:409
PROPERTY_BASE & SetIsHiddenFromLibraryEditors(bool aIsHidden=true)
Definition property.h:333
const wxPGChoices & Choices() const override
Return a limited set of possible values (e.g.
Definition property.h:639
bool HasChoices() const override
Return true if this PROPERTY has a limited set of possible values.
Definition property.h:663
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:592
void setter(void *obj, wxAny &v) override
Definition property.h:611
PROPERTY_ENUM(const wxString &aName, void(Base::*aSetter)(SetType), GetType(Base::*aGetter)(), PROPERTY_DISPLAY aDisplay=PT_DEFAULT)
Definition property.h:573
wxPGChoices m_choices
Definition property.h:670
wxAny getter(const void *obj) const override
Set method.
Definition property.h:632
void SetChoices(const wxPGChoices &aChoices) override
Set the possible values for for the property.
Definition property.h:657
void TranslateChoices() override
Definition property.h:644
bool m_choicesFromENUM_MAP
Definition property.h:669
std::unique_ptr< SETTER_BASE< Owner, T > > m_setter
Get method.
Definition property.h:552
const size_t m_baseHash
Property value type-id.
Definition property.h:561
size_t TypeHash() const override
Return type-id of the property type.
Definition property.h:505
typename std::decay< T >::type BASE_TYPE
Definition property.h:467
const size_t m_typeHash
Definition property.h:564
virtual ~PROPERTY()
Definition property.h:529
virtual void setter(void *obj, wxAny &v) override
Definition property.h:531
size_t BaseHash() const override
Return type-id of the Base class.
Definition property.h:500
bool Writeable(INSPECTABLE *aObject) const override
Definition property.h:510
virtual wxAny getter(const void *obj) const override
Set method.
Definition property.h:544
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:483
std::unique_ptr< GETTER_BASE< Owner, T > > m_getter
Owner class type-id.
Definition property.h:555
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:470
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:516
size_t OwnerHash() const override
Return type-id of the Owner class.
Definition property.h:495
const size_t m_ownerHash
Base class type-id.
Definition property.h:558
virtual void operator()(Owner *aOwner, T aValue)=0
virtual ~SETTER_BASE()
Definition property.h:110
void operator()(Owner *aOwner, T aValue) override
Definition property.h:125
FuncType m_func
Definition property.h:131
SETTER(FuncType aFunc)
Definition property.h:119
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()
Definition property.h:677
virtual size_t DerivedHash() const =0
size_t DerivedHash() const override
Definition property.h:710
const void * operator()(const void *aPointer) const override
Definition property.h:699
size_t BaseHash() const override
Definition property.h:705
void * operator()(void *aPointer) const override
Definition property.h:693
static bool empty(const wxTextEntryBase *aCtrl)
#define TYPE_HASH(x)
Definition property.h:74
PROPERTY_DISPLAY
Common property types.
Definition property.h:61
@ PT_DEGREE
Angle expressed in degrees.
Definition property.h:66
@ PT_COORD
Coordinate expressed in distance units (mm/inch)
Definition property.h:65
@ PT_RATIO
Definition property.h:68
@ PT_DECIDEGREE
Angle expressed in decidegrees.
Definition property.h:67
@ PT_AREA
Area expressed in distance units-squared (mm/inch)
Definition property.h:64
@ PT_DEFAULT
Default property for a given type.
Definition property.h:62
@ PT_SIZE
Size expressed in distance units (mm/inch)
Definition property.h:63
@ PT_NET
Net selection property.
Definition property.h:70
@ PT_TIME
Time expressed in ps.
Definition property.h:69
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