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