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