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
21 * along with this program. If not, see <https://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_copyable( false ),
211 m_availFunc( [](INSPECTABLE*)->bool { return true; } ),
212 m_writeableFunc( [](INSPECTABLE*)->bool { return true; } ),
213 m_validator( NullValidator )
214 {
215 }
216
218 {
219 }
220
221 const wxString& Name() const { return m_name; }
222
227 virtual const wxPGChoices& Choices() const
228 {
229 static wxPGChoices empty;
230 return empty;
231 }
232
233 virtual void TranslateChoices() {}
234
238 virtual void SetChoices( const wxPGChoices& aChoices )
239 {
240 wxFAIL; // only possible for PROPERTY_ENUM
241 }
242
247 virtual bool HasChoices() const
248 {
249 return m_choicesFunc != nullptr;
250 }
251
255 bool Available( INSPECTABLE* aObject ) const
256 {
257 return m_availFunc( aObject );
258 }
259
263 PROPERTY_BASE& SetAvailableFunc( std::function<bool(INSPECTABLE*)> aFunc )
264 {
265 m_availFunc = std::move( aFunc );
266 return *this;
267 }
268
269 wxPGChoices GetChoices( INSPECTABLE* aObject ) const
270 {
271 if( m_choicesFunc )
272 return m_choicesFunc( aObject );
273
274 return {};
275 }
276
277 PROPERTY_BASE& SetChoicesFunc( std::function<wxPGChoices(INSPECTABLE*)> aFunc )
278 {
279 m_choicesFunc = std::move( aFunc );
280 return *this;
281 }
282
283 virtual bool IgnoreValue() const
284 {
285 return false;
286 }
287
288 virtual bool Writeable( INSPECTABLE* aObject ) const
289 {
290 return m_writeableFunc( aObject );
291 }
292
293 PROPERTY_BASE& SetWriteableFunc( std::function<bool(INSPECTABLE*)> aFunc )
294 {
295 m_writeableFunc = std::move( aFunc );
296 return *this;
297 }
298
302 virtual size_t OwnerHash() const = 0;
303
307 virtual size_t BaseHash() const = 0;
308
312 virtual size_t TypeHash() const = 0;
313
315 PROPERTY_BASE& SetDisplay( PROPERTY_DISPLAY aDisplay ) { m_display = aDisplay; return *this; }
316
319 {
320 m_coordType = aType;
321 return *this;
322 }
323
326 {
328 return *this;
329 }
330
333 {
334 m_hideFromRulesEditor = aHide;
335 return *this;
336 }
337
340 {
341 m_hideFromLibraryEditors = aIsHidden;
342 return *this;
343 }
344
347 {
348 m_hideFromDesignEditors = aIsHidden;
349 return *this;
350 }
351
358 bool IsCopyable() const { return m_copyable; }
359 PROPERTY_BASE& SetIsCopyable( bool aIsCopyable = true )
360 {
361 m_copyable = aIsCopyable;
362 return *this;
363 }
364
365 wxString Group() const { return m_group; }
366 PROPERTY_BASE& SetGroup( const wxString& aGroup ) { m_group = aGroup; return *this; }
367
369 {
370 m_validator = aValidator;
371 return *this;
372 }
373
374 VALIDATOR_RESULT Validate( const wxAny&& aValue, EDA_ITEM* aItem )
375 {
376 return m_validator( std::move( aValue ), aItem );
377 }
378
379 static VALIDATOR_RESULT NullValidator( const wxAny&& aValue, EDA_ITEM* aItem )
380 {
381 return std::nullopt;
382 }
383
384protected:
385 template<typename T>
386 void set( void* aObject, T aValue )
387 {
388 wxAny a = aValue;
389
390 // wxVariant will be type "long" even if the property is supposed to be
391 // unsigned. Let's trust that we're coming from the property grid where
392 // we used a UInt editor.
393 if( std::is_same<T, wxVariant>::value )
394 {
395 wxVariant var = static_cast<wxVariant>( aValue );
396 wxAny pv = getter( aObject );
397
398 if( pv.CheckType<unsigned>() )
399 {
400 a = static_cast<unsigned>( var.GetLong() );
401 }
402 else if( pv.CheckType<std::optional<int>>() )
403 {
404 auto* data = static_cast<STD_OPTIONAL_INT_VARIANT_DATA*>( var.GetData() );
405
406 if( !data->Value().has_value() )
407 return;
408
409 a = data->Value();
410 }
411 else if( pv.CheckType<std::optional<double>>() )
412 {
413 auto* data = static_cast<STD_OPTIONAL_DOUBLE_VARIANT_DATA*>( var.GetData() );
414
415 if( !data->Value().has_value() )
416 return;
417
418 a = data->Value();
419 }
420 else if( pv.CheckType<EDA_ANGLE>() )
421 {
422 EDA_ANGLE_VARIANT_DATA* ad = static_cast<EDA_ANGLE_VARIANT_DATA*>( var.GetData() );
423 a = ad->Angle();
424 }
425 else if( pv.CheckType<KIGFX::COLOR4D>() )
426 {
427 COLOR4D_VARIANT_DATA* cd = static_cast<COLOR4D_VARIANT_DATA*>( var.GetData() );
428 a = cd->Color();
429 }
430 }
431
432 setter( aObject, a );
433 }
434
435 template<typename T>
436 T get( const void* aObject ) const
437 {
438 wxAny a = getter( aObject );
439
440 // We don't currently have a bool type, so change it to a numeric
441 if( a.CheckType<bool>() )
442 {
443 if constexpr( std::is_same_v<T, bool> )
444 return a.RawAs<bool>();
445
446 a = a.RawAs<bool>() ? 1 : 0;
447 }
448
449 if ( !( std::is_enum<T>::value && a.CheckType<int>() ) && !a.CheckType<T>() )
450 throw std::invalid_argument( "Invalid requested type" );
451
452 return wxANY_AS( a, T );
453 }
454
455private:
456 virtual void setter( void* aObject, wxAny& aValue ) = 0;
457 virtual wxAny getter( const void* aObject ) const = 0;
458
459private:
465 const wxString m_name;
466
469
472
473 bool m_hideFromPropertiesManager; // Do not show in Properties Manager
474 bool m_hideFromLibraryEditors; // Do not show in Properties Manager of symbol or
475 // footprint editors
476 bool m_hideFromDesignEditors; // Do not show in Properties Manager of schematic or
477 // board editors
478 bool m_hideFromRulesEditor; // Do not show in Custom Rules editor autocomplete
479 bool m_copyable; // May be copied from one item to another
480
482 wxString m_group;
483
484 std::function<bool(INSPECTABLE*)> m_availFunc;
485
486 std::function<bool(INSPECTABLE*)> m_writeableFunc;
487
488 std::function<wxPGChoices(INSPECTABLE*)> m_choicesFunc;
489
491
492 friend class INSPECTABLE;
493};
494
495
496template<typename Owner, typename T, typename Base = Owner>
498{
499public:
500 using BASE_TYPE = typename std::decay<T>::type;
501
502 template<typename SetType, typename GetType>
503 PROPERTY( const wxString& aName,
504 void ( Base::*aSetter )( SetType ),
505 GetType( Base::*aGetter )(),
506 PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
508 PROPERTY( aName,
509 METHOD<Owner, T, Base>::Wrap( aSetter ),
510 METHOD<Owner, T, Base>::Wrap( aGetter ),
511 aDisplay, aCoordType )
512 {
513 }
514
515 template<typename SetType, typename GetType>
516 PROPERTY( const wxString& aName,
517 void ( Base::*aSetter )( SetType ),
518 GetType( Base::*aGetter )() const,
519 PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
521 PROPERTY( aName,
522 METHOD<Owner, T, Base>::Wrap( aSetter ),
523 METHOD<Owner, T, Base>::Wrap( aGetter ),
524 aDisplay, aCoordType )
525 {
526 }
527
528 size_t OwnerHash() const override
529 {
530 return m_ownerHash;
531 }
532
533 size_t BaseHash() const override
534 {
535 return m_baseHash;
536 }
537
538 size_t TypeHash() const override
539 {
540 return m_typeHash;
541 }
542
543 bool Writeable( INSPECTABLE* aObject ) const override
544 {
545 return m_setter && PROPERTY_BASE::Writeable( aObject );
546 }
547
548protected:
549 PROPERTY( const wxString& aName,
553 PROPERTY_BASE( aName, aDisplay, aCoordType ),
554 m_setter( s ),
555 m_getter( g ),
556 m_ownerHash( TYPE_HASH( Owner ) ),
557 m_baseHash( TYPE_HASH( Base ) ),
559 {
560 }
561
562 virtual ~PROPERTY() {}
563
564 virtual void setter( void* obj, wxAny& v ) override
565 {
566 wxCHECK( m_setter, /*void*/ );
567
568 BASE_TYPE value;
569
570 if( !v.GetAs( &value ) )
571 throw std::invalid_argument( "Invalid type requested" );
572
573 Owner* o = reinterpret_cast<Owner*>( obj );
574 (*m_setter)( o, value );
575 }
576
577 virtual wxAny getter( const void* obj ) const override
578 {
579 const Owner* o = reinterpret_cast<const Owner*>( obj );
580 wxAny res = (*m_getter)( o );
581 return res;
582 }
583
585 std::unique_ptr<SETTER_BASE<Owner, T>> m_setter;
586
588 std::unique_ptr<GETTER_BASE<Owner, T>> m_getter;
589
591 const size_t m_ownerHash;
592
594 const size_t m_baseHash;
595
597 const size_t m_typeHash;
598};
599
600
601template<typename Owner, typename T, typename Base = Owner>
603{
604public:
605 using BASE_TYPE = typename std::decay<T>::type;
606
607 DUMMY_PROPERTY( const wxString& aName ) :
608 PROPERTY_BASE( aName )
609 {
610 }
611
612 size_t OwnerHash() const override { return TYPE_HASH( Owner ); }
613 size_t BaseHash() const override { return TYPE_HASH( Base ); }
614 size_t TypeHash() const override { return TYPE_HASH( BASE_TYPE ); }
615
616 bool IgnoreValue() const override { return true; }
617
618protected:
619 void setter( void* obj, wxAny& v ) override
620 {
621 }
622
623 wxAny getter( const void* obj ) const override
624 {
625 return wxAny();
626 }
627};
628
629
630template<typename Owner, typename T, typename Base = Owner>
631class PROPERTY_ENUM : public PROPERTY<Owner, T, Base>
632{
633public:
634 template<typename SetType, typename GetType>
635 PROPERTY_ENUM( const wxString& aName,
636 void ( Base::*aSetter )( SetType ),
637 GetType( Base::*aGetter )(),
638 PROPERTY_DISPLAY aDisplay = PT_DEFAULT ) :
639 PROPERTY<Owner, T, Base>( aName,
640 METHOD<Owner, T, Base>::Wrap( aSetter ),
641 METHOD<Owner, T, Base>::Wrap( aGetter ),
642 aDisplay ),
643 m_choicesFromENUM_MAP( false )
644 {
645 if ( std::is_enum<T>::value )
646 {
647 m_choices = ENUM_MAP<T>::Instance().Choices();
649 wxASSERT_MSG( m_choices.GetCount() > 0, wxT( "No enum choices defined" ) );
650 }
651 }
652
653 template<typename SetType, typename GetType>
654 PROPERTY_ENUM( const wxString& aName,
655 void ( Base::*aSetter )( SetType ),
656 GetType( Base::*aGetter )() const,
657 PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
659 PROPERTY<Owner, T, Base>( aName,
660 METHOD<Owner, T, Base>::Wrap( aSetter ),
661 METHOD<Owner, T, Base>::Wrap( aGetter ),
662 aDisplay, aCoordType ),
663 m_choicesFromENUM_MAP( false )
664 {
665 if ( std::is_enum<T>::value )
666 {
667 m_choices = ENUM_MAP<T>::Instance().Choices();
669 wxASSERT_MSG( m_choices.GetCount() > 0, wxT( "No enum choices defined" ) );
670 }
671 }
672
673 void setter( void* obj, wxAny& v ) override
674 {
675 wxCHECK( ( PROPERTY<Owner, T, Base>::m_setter ), /*void*/ );
676 Owner* o = reinterpret_cast<Owner*>( obj );
677
678 if( v.CheckType<T>() )
679 {
680 T value = wxANY_AS(v, T);
682 }
683 else if (v.CheckType<int>() )
684 {
685 int value = wxANY_AS(v, int);
686 (*PROPERTY<Owner, T, Base>::m_setter)( o, static_cast<T>( value ) );
687 }
688 else
689 {
690 throw std::invalid_argument( "Invalid type requested" );
691 }
692 }
693
694 wxAny getter( const void* obj ) const override
695 {
696 const Owner* o = reinterpret_cast<const Owner*>( obj );
697 wxAny res = static_cast<T>( (*PROPERTY<Owner, T, Base>::m_getter)( o ) );
698 return res;
699 }
700
701 const wxPGChoices& Choices() const override
702 {
703 return m_choices.GetCount() > 0 ? m_choices : ENUM_MAP<T>::Instance().Choices();
704 }
705
706 void TranslateChoices() override
707 {
708 if( m_choicesFromENUM_MAP && std::is_enum<T>::value )
709 {
710 m_choices.Clear();
711
712 wxPGChoices& choices = ENUM_MAP<T>::Instance().Choices();
713
714 for( unsigned ii = 0; ii < choices.GetCount(); ++ii )
715 m_choices.Add( wxGetTranslation( choices.GetLabel( ii ) ), choices.GetValue( ii ) );
716 }
717 }
718
719 void SetChoices( const wxPGChoices& aChoices ) override
720 {
721 m_choices = aChoices;
722 m_choicesFromENUM_MAP = false;
723 }
724
725 bool HasChoices() const override
726 {
727 return Choices().GetCount() > 0;
728 }
729
730protected:
732 wxPGChoices m_choices;
733};
734
735
737{
738public:
739 virtual ~TYPE_CAST_BASE() {}
740 virtual void* operator()( void* aPointer ) const = 0;
741 virtual const void* operator()( const void* aPointer ) const = 0;
742 virtual size_t BaseHash() const = 0;
743 virtual size_t DerivedHash() const = 0;
744};
745
746
747template<typename Base, typename Derived>
749{
750public:
752 {
753 }
754
755 void* operator()( void* aPointer ) const override
756 {
757 Base* base = reinterpret_cast<Base*>( aPointer );
758 return static_cast<Derived*>( base );
759 }
760
761 const void* operator()( const void* aPointer ) const override
762 {
763 const Base* base = reinterpret_cast<const Base*>( aPointer );
764 return static_cast<const Derived*>( base );
765 }
766
767 size_t BaseHash() const override
768 {
769 return TYPE_HASH( Base );
770 }
771
772 size_t DerivedHash() const override
773 {
774 return TYPE_HASH( Derived );
775 }
776};
777
778
779template<typename T>
781{
782public:
784 {
785 static ENUM_MAP<T> inst;
786 return inst;
787 }
788
789 ENUM_MAP& Map( T aValue, const wxString& aName )
790 {
791 m_choices.Add( aName, static_cast<int>( aValue ) );
792 m_reverseMap[ aName ] = aValue;
793 return *this;
794 }
795
797 {
798 m_undefined = aValue;
799 return *this;
800 }
801
802 T GetUndefined() const { return m_undefined; }
803
804 const wxString& ToString( T value ) const
805 {
806 static const wxString s_undef = "UNDEFINED";
807
808 int idx = m_choices.Index( static_cast<int>( value ) );
809
810 if( idx >= 0 && idx < (int) m_choices.GetCount() )
811 return m_choices.GetLabel( static_cast<int>( idx ) );
812 else
813 return s_undef;
814 }
815
816 bool IsValueDefined( T value ) const
817 {
818 int idx = m_choices.Index( static_cast<int>( value ) );
819
820 if( idx >= 0 && idx < (int) m_choices.GetCount() )
821 return true;
822
823 return false;
824 }
825
826 T ToEnum( const wxString value )
827 {
828 if( m_reverseMap.count( value ) )
829 return m_reverseMap[ value ];
830 else
831 return m_undefined;
832 }
833
834 wxPGChoices& Choices()
835 {
836 return m_choices;
837 }
838
839private:
840 wxPGChoices m_choices;
841 std::unordered_map<wxString, T> m_reverseMap;
842 T m_undefined; // Returned if the string is not recognized
843
845 {
846 }
847};
848
849
850// Helper macros to handle enum types
851#define DECLARE_ENUM_TO_WXANY( type ) \
852 template <> \
853 class wxAnyValueTypeImpl<type> : public wxAnyValueTypeImplBase<type> \
854 { \
855 WX_DECLARE_ANY_VALUE_TYPE( wxAnyValueTypeImpl<type> ) \
856 public: \
857 wxAnyValueTypeImpl() : \
858 wxAnyValueTypeImplBase<type>() \
859 { \
860 } \
861 virtual ~wxAnyValueTypeImpl() {} \
862 virtual bool ConvertValue( const wxAnyValueBuffer& src, wxAnyValueType* dstType, \
863 wxAnyValueBuffer& dst ) const override \
864 { \
865 type value = GetValue( src ); \
866 ENUM_MAP<type>& conv = ENUM_MAP<type>::Instance(); \
867 if( !conv.IsValueDefined( value ) && value != conv.GetUndefined() ) \
868 { \
869 return false; \
870 } \
871 if( dstType->CheckType<wxString>() ) \
872 { \
873 wxAnyValueTypeImpl<wxString>::SetValue( conv.ToString( value ), dst ); \
874 return true; \
875 } \
876 if( dstType->CheckType<int>() ) \
877 { \
878 wxAnyValueTypeImpl<int>::SetValue( static_cast<int>( value ), dst ); \
879 return true; \
880 } \
881 else \
882 { \
883 return false; \
884 } \
885 } \
886 };
887
888#define IMPLEMENT_ENUM_TO_WXANY( type ) WX_IMPLEMENT_ANY_VALUE_TYPE( wxAnyValueTypeImpl<type> )
889
890#define ENUM_TO_WXANY( type ) \
891 DECLARE_ENUM_TO_WXANY( type ) \
892 IMPLEMENT_ENUM_TO_WXANY( type )
893
895#define NO_SETTER( owner, type ) ( ( void ( owner::* )( type ) ) nullptr )
896
897/*
898#define DECLARE_PROPERTY(owner,type,name,getter,setter) \
899namespace anonymous {\
900static PROPERTY<owner,type> prop##_owner##_name_( "##name#", setter, getter );\
901};
902*/
903#endif /* PROPERTY_H */
const KIGFX::COLOR4D & Color()
size_t BaseHash() const override
Return type-id of the Base class.
Definition property.h:613
size_t TypeHash() const override
Return type-id of the property type.
Definition property.h:614
typename std::decay< T >::type BASE_TYPE
Definition property.h:605
void setter(void *obj, wxAny &v) override
Definition property.h:619
bool IgnoreValue() const override
Definition property.h:616
DUMMY_PROPERTY(const wxString &aName)
Definition property.h:607
size_t OwnerHash() const override
Return type-id of the Owner class.
Definition property.h:612
wxAny getter(const void *obj) const override
Definition property.h:623
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:826
ENUM_MAP & Map(T aValue, const wxString &aName)
Definition property.h:789
std::unordered_map< wxString, T > m_reverseMap
Definition property.h:841
T m_undefined
Definition property.h:842
static ENUM_MAP< T > & Instance()
Definition property.h:783
T GetUndefined() const
Definition property.h:802
const wxString & ToString(T value) const
Definition property.h:804
bool IsValueDefined(T value) const
Definition property.h:816
ENUM_MAP & Undefined(T aValue)
Definition property.h:796
wxPGChoices & Choices()
Definition property.h:834
wxPGChoices m_choices
Definition property.h:840
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:39
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
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:277
bool IsHiddenFromPropertiesManager() const
Definition property.h:324
virtual size_t TypeHash() const =0
Return type-id of the property type.
bool m_hideFromLibraryEditors
Definition property.h:474
const wxString m_name
Permanent identifier for this property.
Definition property.h:465
VALIDATOR_RESULT Validate(const wxAny &&aValue, EDA_ITEM *aItem)
Definition property.h:374
virtual void TranslateChoices()
Definition property.h:233
std::function< bool(INSPECTABLE *)> m_writeableFunc
Eval to determine if prop is read-only.
Definition property.h:486
std::function< bool(INSPECTABLE *)> m_availFunc
Eval to determine if prop is available.
Definition property.h:484
PROPERTY_VALIDATOR_FN m_validator
Definition property.h:490
bool IsHiddenFromDesignEditors() const
Definition property.h:345
PROPERTY_BASE & SetAvailableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Set a callback function to determine whether an object provides this property.
Definition property.h:263
PROPERTY_BASE & SetDisplay(PROPERTY_DISPLAY aDisplay)
Definition property.h:315
std::function< wxPGChoices(INSPECTABLE *)> m_choicesFunc
Definition property.h:488
PROPERTY_DISPLAY Display() const
Definition property.h:314
virtual bool IgnoreValue() const
Definition property.h:283
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:379
wxString Group() const
Definition property.h:365
PROPERTY_BASE & SetWriteableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Definition property.h:293
PROPERTY_BASE & SetGroup(const wxString &aGroup)
Definition property.h:366
ORIGIN_TRANSFORMS::COORD_TYPES_T CoordType() const
Definition property.h:317
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:318
PROPERTY_DISPLAY m_display
The display style controls how properties are edited in the properties manager GUI.
Definition property.h:468
virtual bool HasChoices() const
Return true if this PROPERTY has a limited set of possible values.
Definition property.h:247
ORIGIN_TRANSFORMS::COORD_TYPES_T m_coordType
The coordinate type controls how distances are mapped to the user coordinate system.
Definition property.h:471
virtual bool Writeable(INSPECTABLE *aObject) const
Definition property.h:288
bool IsCopyable() const
True for a property that says how an item looks, not what or where it is.
Definition property.h:358
wxPGChoices GetChoices(INSPECTABLE *aObject) const
Definition property.h:269
virtual void setter(void *aObject, wxAny &aValue)=0
virtual ~PROPERTY_BASE()
Definition property.h:217
wxString m_group
Optional group identifier.
Definition property.h:482
bool Available(INSPECTABLE *aObject) const
Return true if aObject offers this PROPERTY.
Definition property.h:255
PROPERTY_BASE & SetValidator(PROPERTY_VALIDATOR_FN &&aValidator)
Definition property.h:368
PROPERTY_BASE & SetIsCopyable(bool aIsCopyable=true)
Definition property.h:359
bool m_hideFromPropertiesManager
Definition property.h:473
bool m_hideFromDesignEditors
Definition property.h:476
PROPERTY_BASE & SetIsHiddenFromDesignEditors(bool aIsHidden=true)
Definition property.h:346
PROPERTY_BASE & SetIsHiddenFromPropertiesManager(bool aHide=true)
Definition property.h:325
bool m_hideFromRulesEditor
Definition property.h:478
friend class INSPECTABLE
Definition property.h:492
void set(void *aObject, T aValue)
Definition property.h:386
const wxString & Name() const
Definition property.h:221
bool IsHiddenFromRulesEditor() const
Definition property.h:331
virtual const wxPGChoices & Choices() const
Return a limited set of possible values (e.g.
Definition property.h:227
virtual void SetChoices(const wxPGChoices &aChoices)
Set the possible values for for the property.
Definition property.h:238
virtual size_t OwnerHash() const =0
Return type-id of the Owner class.
PROPERTY_BASE & SetIsHiddenFromRulesEditor(bool aHide=true)
Definition property.h:332
bool m_copyable
Definition property.h:479
bool IsHiddenFromLibraryEditors() const
Definition property.h:338
T get(const void *aObject) const
Definition property.h:436
PROPERTY_BASE & SetIsHiddenFromLibraryEditors(bool aIsHidden=true)
Definition property.h:339
const wxPGChoices & Choices() const override
Return a limited set of possible values (e.g.
Definition property.h:701
bool HasChoices() const override
Return true if this PROPERTY has a limited set of possible values.
Definition property.h:725
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:654
void setter(void *obj, wxAny &v) override
Definition property.h:673
PROPERTY_ENUM(const wxString &aName, void(Base::*aSetter)(SetType), GetType(Base::*aGetter)(), PROPERTY_DISPLAY aDisplay=PT_DEFAULT)
Definition property.h:635
wxPGChoices m_choices
Definition property.h:732
wxAny getter(const void *obj) const override
Definition property.h:694
void SetChoices(const wxPGChoices &aChoices) override
Set the possible values for for the property.
Definition property.h:719
void TranslateChoices() override
Definition property.h:706
bool m_choicesFromENUM_MAP
Definition property.h:731
std::unique_ptr< SETTER_BASE< Owner, T > > m_setter
Set method.
Definition property.h:585
const size_t m_baseHash
Base class type-id.
Definition property.h:594
size_t TypeHash() const override
Return type-id of the property type.
Definition property.h:538
typename std::decay< T >::type BASE_TYPE
Definition property.h:500
const size_t m_typeHash
Property value type-id.
Definition property.h:597
virtual ~PROPERTY()
Definition property.h:562
virtual void setter(void *obj, wxAny &v) override
Definition property.h:564
size_t BaseHash() const override
Return type-id of the Base class.
Definition property.h:533
bool Writeable(INSPECTABLE *aObject) const override
Definition property.h:543
virtual wxAny getter(const void *obj) const override
Definition property.h:577
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:516
std::unique_ptr< GETTER_BASE< Owner, T > > m_getter
Get method.
Definition property.h:588
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:503
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:549
size_t OwnerHash() const override
Return type-id of the Owner class.
Definition property.h:528
const size_t m_ownerHash
Owner class type-id.
Definition property.h:591
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:739
virtual size_t DerivedHash() const =0
size_t DerivedHash() const override
Definition property.h:772
const void * operator()(const void *aPointer) const override
Definition property.h:761
size_t BaseHash() const override
Definition property.h:767
void * operator()(void *aPointer) const override
Definition property.h:755
static bool empty(const wxTextEntryBase *aCtrl)
#define TYPE_HASH(x)
Macro to generate unique identifier for a type.
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