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 if( var.IsNull() )
405 return;
406
407 a = static_cast<STD_OPTIONAL_INT_VARIANT_DATA*>( var.GetData() )->OptValue();
408 }
409 else if( pv.CheckType<std::optional<double>>() )
410 {
411 if( var.IsNull() )
412 return;
413
414 a = static_cast<STD_OPTIONAL_DOUBLE_VARIANT_DATA*>( var.GetData() )->OptValue();
415 }
416 else if( pv.CheckType<EDA_ANGLE>() )
417 {
418 a = static_cast<EDA_ANGLE_VARIANT_DATA*>( var.GetData() )->Angle();
419 }
420 else if( pv.CheckType<KIGFX::COLOR4D>() )
421 {
422 a = static_cast<COLOR4D_VARIANT_DATA*>( var.GetData() )->Color();
423 }
424 }
425
426 setter( aObject, a );
427 }
428
429 template<typename T>
430 T get( const void* aObject ) const
431 {
432 wxAny a = getter( aObject );
433
434 // We don't currently have a bool type, so change it to a numeric
435 if( a.CheckType<bool>() )
436 {
437 if constexpr( std::is_same_v<T, bool> )
438 return a.RawAs<bool>();
439
440 a = a.RawAs<bool>() ? 1 : 0;
441 }
442
443 if ( !( std::is_enum<T>::value && a.CheckType<int>() ) && !a.CheckType<T>() )
444 throw std::invalid_argument( "Invalid requested type" );
445
446 return wxANY_AS( a, T );
447 }
448
449private:
450 virtual void setter( void* aObject, wxAny& aValue ) = 0;
451 virtual wxAny getter( const void* aObject ) const = 0;
452
453private:
459 const wxString m_name;
460
463
466
467 bool m_hideFromPropertiesManager; // Do not show in Properties Manager
468 bool m_hideFromLibraryEditors; // Do not show in Properties Manager of symbol or
469 // footprint editors
470 bool m_hideFromDesignEditors; // Do not show in Properties Manager of schematic or
471 // board editors
472 bool m_hideFromRulesEditor; // Do not show in Custom Rules editor autocomplete
473 bool m_copyable; // May be copied from one item to another
474
476 wxString m_group;
477
478 std::function<bool(INSPECTABLE*)> m_availFunc;
479
480 std::function<bool(INSPECTABLE*)> m_writeableFunc;
481
482 std::function<wxPGChoices(INSPECTABLE*)> m_choicesFunc;
483
485
486 friend class INSPECTABLE;
487};
488
489
490template<typename Owner, typename T, typename Base = Owner>
492{
493public:
494 using BASE_TYPE = typename std::decay<T>::type;
495
496 template<typename SetType, typename GetType>
497 PROPERTY( const wxString& aName,
498 void ( Base::*aSetter )( SetType ),
499 GetType( Base::*aGetter )(),
500 PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
502 PROPERTY( aName,
503 METHOD<Owner, T, Base>::Wrap( aSetter ),
504 METHOD<Owner, T, Base>::Wrap( aGetter ),
505 aDisplay, aCoordType )
506 {
507 }
508
509 template<typename SetType, typename GetType>
510 PROPERTY( const wxString& aName,
511 void ( Base::*aSetter )( SetType ),
512 GetType( Base::*aGetter )() const,
513 PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
515 PROPERTY( aName,
516 METHOD<Owner, T, Base>::Wrap( aSetter ),
517 METHOD<Owner, T, Base>::Wrap( aGetter ),
518 aDisplay, aCoordType )
519 {
520 }
521
522 size_t OwnerHash() const override
523 {
524 return m_ownerHash;
525 }
526
527 size_t BaseHash() const override
528 {
529 return m_baseHash;
530 }
531
532 size_t TypeHash() const override
533 {
534 return m_typeHash;
535 }
536
537 bool Writeable( INSPECTABLE* aObject ) const override
538 {
539 return m_setter && PROPERTY_BASE::Writeable( aObject );
540 }
541
542protected:
543 PROPERTY( const wxString& aName,
547 PROPERTY_BASE( aName, aDisplay, aCoordType ),
548 m_setter( s ),
549 m_getter( g ),
550 m_ownerHash( TYPE_HASH( Owner ) ),
551 m_baseHash( TYPE_HASH( Base ) ),
553 {
554 }
555
556 virtual ~PROPERTY() {}
557
558 virtual void setter( void* obj, wxAny& v ) override
559 {
560 wxCHECK( m_setter, /*void*/ );
561
562 BASE_TYPE value;
563
564 if( !v.GetAs( &value ) )
565 throw std::invalid_argument( "Invalid type requested" );
566
567 Owner* o = reinterpret_cast<Owner*>( obj );
568 (*m_setter)( o, value );
569 }
570
571 virtual wxAny getter( const void* obj ) const override
572 {
573 const Owner* o = reinterpret_cast<const Owner*>( obj );
574 wxAny res = (*m_getter)( o );
575 return res;
576 }
577
579 std::unique_ptr<SETTER_BASE<Owner, T>> m_setter;
580
582 std::unique_ptr<GETTER_BASE<Owner, T>> m_getter;
583
585 const size_t m_ownerHash;
586
588 const size_t m_baseHash;
589
591 const size_t m_typeHash;
592};
593
594
595template<typename Owner, typename T, typename Base = Owner>
597{
598public:
599 using BASE_TYPE = typename std::decay<T>::type;
600
601 DUMMY_PROPERTY( const wxString& aName ) :
602 PROPERTY_BASE( aName )
603 {
604 }
605
606 size_t OwnerHash() const override { return TYPE_HASH( Owner ); }
607 size_t BaseHash() const override { return TYPE_HASH( Base ); }
608 size_t TypeHash() const override { return TYPE_HASH( BASE_TYPE ); }
609
610 bool IgnoreValue() const override { return true; }
611
612protected:
613 void setter( void* obj, wxAny& v ) override
614 {
615 }
616
617 wxAny getter( const void* obj ) const override
618 {
619 return wxAny();
620 }
621};
622
623
624template<typename Owner, typename T, typename Base = Owner>
625class PROPERTY_ENUM : public PROPERTY<Owner, T, Base>
626{
627public:
628 template<typename SetType, typename GetType>
629 PROPERTY_ENUM( const wxString& aName,
630 void ( Base::*aSetter )( SetType ),
631 GetType( Base::*aGetter )(),
632 PROPERTY_DISPLAY aDisplay = PT_DEFAULT ) :
633 PROPERTY<Owner, T, Base>( aName,
634 METHOD<Owner, T, Base>::Wrap( aSetter ),
635 METHOD<Owner, T, Base>::Wrap( aGetter ),
636 aDisplay ),
637 m_choicesFromENUM_MAP( false )
638 {
639 if ( std::is_enum<T>::value )
640 {
641 m_choices = ENUM_MAP<T>::Instance().Choices();
643 wxASSERT_MSG( m_choices.GetCount() > 0, wxT( "No enum choices defined" ) );
644 }
645 }
646
647 template<typename SetType, typename GetType>
648 PROPERTY_ENUM( const wxString& aName,
649 void ( Base::*aSetter )( SetType ),
650 GetType( Base::*aGetter )() const,
651 PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
653 PROPERTY<Owner, T, Base>( aName,
654 METHOD<Owner, T, Base>::Wrap( aSetter ),
655 METHOD<Owner, T, Base>::Wrap( aGetter ),
656 aDisplay, aCoordType ),
657 m_choicesFromENUM_MAP( false )
658 {
659 if ( std::is_enum<T>::value )
660 {
661 m_choices = ENUM_MAP<T>::Instance().Choices();
663 wxASSERT_MSG( m_choices.GetCount() > 0, wxT( "No enum choices defined" ) );
664 }
665 }
666
667 void setter( void* obj, wxAny& v ) override
668 {
669 wxCHECK( ( PROPERTY<Owner, T, Base>::m_setter ), /*void*/ );
670 Owner* o = reinterpret_cast<Owner*>( obj );
671
672 if( v.CheckType<T>() )
673 {
674 T value = wxANY_AS(v, T);
676 }
677 else if (v.CheckType<int>() )
678 {
679 int value = wxANY_AS(v, int);
680 (*PROPERTY<Owner, T, Base>::m_setter)( o, static_cast<T>( value ) );
681 }
682 else
683 {
684 throw std::invalid_argument( "Invalid type requested" );
685 }
686 }
687
688 wxAny getter( const void* obj ) const override
689 {
690 const Owner* o = reinterpret_cast<const Owner*>( obj );
691 wxAny res = static_cast<T>( (*PROPERTY<Owner, T, Base>::m_getter)( o ) );
692 return res;
693 }
694
695 const wxPGChoices& Choices() const override
696 {
697 return m_choices.GetCount() > 0 ? m_choices : ENUM_MAP<T>::Instance().Choices();
698 }
699
700 void TranslateChoices() override
701 {
702 if( m_choicesFromENUM_MAP && std::is_enum<T>::value )
703 {
704 m_choices.Clear();
705
706 wxPGChoices& choices = ENUM_MAP<T>::Instance().Choices();
707
708 for( unsigned ii = 0; ii < choices.GetCount(); ++ii )
709 m_choices.Add( wxGetTranslation( choices.GetLabel( ii ) ), choices.GetValue( ii ) );
710 }
711 }
712
713 void SetChoices( const wxPGChoices& aChoices ) override
714 {
715 m_choices = aChoices;
716 m_choicesFromENUM_MAP = false;
717 }
718
719 bool HasChoices() const override
720 {
721 return Choices().GetCount() > 0;
722 }
723
724protected:
726 wxPGChoices m_choices;
727};
728
729
731{
732public:
733 virtual ~TYPE_CAST_BASE() {}
734 virtual void* operator()( void* aPointer ) const = 0;
735 virtual const void* operator()( const void* aPointer ) const = 0;
736 virtual size_t BaseHash() const = 0;
737 virtual size_t DerivedHash() const = 0;
738};
739
740
741template<typename Base, typename Derived>
743{
744public:
746 {
747 }
748
749 void* operator()( void* aPointer ) const override
750 {
751 Base* base = reinterpret_cast<Base*>( aPointer );
752 return static_cast<Derived*>( base );
753 }
754
755 const void* operator()( const void* aPointer ) const override
756 {
757 const Base* base = reinterpret_cast<const Base*>( aPointer );
758 return static_cast<const Derived*>( base );
759 }
760
761 size_t BaseHash() const override
762 {
763 return TYPE_HASH( Base );
764 }
765
766 size_t DerivedHash() const override
767 {
768 return TYPE_HASH( Derived );
769 }
770};
771
772
773template<typename T>
775{
776public:
778 {
779 static ENUM_MAP<T> inst;
780 return inst;
781 }
782
783 ENUM_MAP& Map( T aValue, const wxString& aName )
784 {
785 m_choices.Add( aName, static_cast<int>( aValue ) );
786 m_reverseMap[ aName ] = aValue;
787 return *this;
788 }
789
791 {
792 m_undefined = aValue;
793 return *this;
794 }
795
796 T GetUndefined() const { return m_undefined; }
797
798 const wxString& ToString( T value ) const
799 {
800 static const wxString s_undef = "UNDEFINED";
801
802 int idx = m_choices.Index( static_cast<int>( value ) );
803
804 if( idx >= 0 && idx < (int) m_choices.GetCount() )
805 return m_choices.GetLabel( static_cast<int>( idx ) );
806 else
807 return s_undef;
808 }
809
810 bool IsValueDefined( T value ) const
811 {
812 int idx = m_choices.Index( static_cast<int>( value ) );
813
814 if( idx >= 0 && idx < (int) m_choices.GetCount() )
815 return true;
816
817 return false;
818 }
819
820 T ToEnum( const wxString value )
821 {
822 if( m_reverseMap.count( value ) )
823 return m_reverseMap[ value ];
824 else
825 return m_undefined;
826 }
827
828 wxPGChoices& Choices()
829 {
830 return m_choices;
831 }
832
833private:
834 wxPGChoices m_choices;
835 std::unordered_map<wxString, T> m_reverseMap;
836 T m_undefined; // Returned if the string is not recognized
837
839 {
840 }
841};
842
843
844// Helper macros to handle enum types
845#define DECLARE_ENUM_TO_WXANY( type ) \
846 template <> \
847 class wxAnyValueTypeImpl<type> : public wxAnyValueTypeImplBase<type> \
848 { \
849 WX_DECLARE_ANY_VALUE_TYPE( wxAnyValueTypeImpl<type> ) \
850 public: \
851 wxAnyValueTypeImpl() : \
852 wxAnyValueTypeImplBase<type>() \
853 { \
854 } \
855 virtual ~wxAnyValueTypeImpl() {} \
856 virtual bool ConvertValue( const wxAnyValueBuffer& src, wxAnyValueType* dstType, \
857 wxAnyValueBuffer& dst ) const override \
858 { \
859 type value = GetValue( src ); \
860 ENUM_MAP<type>& conv = ENUM_MAP<type>::Instance(); \
861 if( !conv.IsValueDefined( value ) && value != conv.GetUndefined() ) \
862 { \
863 return false; \
864 } \
865 if( dstType->CheckType<wxString>() ) \
866 { \
867 wxAnyValueTypeImpl<wxString>::SetValue( conv.ToString( value ), dst ); \
868 return true; \
869 } \
870 if( dstType->CheckType<int>() ) \
871 { \
872 wxAnyValueTypeImpl<int>::SetValue( static_cast<int>( value ), dst ); \
873 return true; \
874 } \
875 else \
876 { \
877 return false; \
878 } \
879 } \
880 };
881
882#define IMPLEMENT_ENUM_TO_WXANY( type ) WX_IMPLEMENT_ANY_VALUE_TYPE( wxAnyValueTypeImpl<type> )
883
884#define ENUM_TO_WXANY( type ) \
885 DECLARE_ENUM_TO_WXANY( type ) \
886 IMPLEMENT_ENUM_TO_WXANY( type )
887
889#define NO_SETTER( owner, type ) ( ( void ( owner::* )( type ) ) nullptr )
890
891/*
892#define DECLARE_PROPERTY(owner,type,name,getter,setter) \
893namespace anonymous {\
894static PROPERTY<owner,type> prop##_owner##_name_( "##name#", setter, getter );\
895};
896*/
897#endif /* PROPERTY_H */
const KIGFX::COLOR4D & Color()
size_t BaseHash() const override
Return type-id of the Base class.
Definition property.h:607
size_t TypeHash() const override
Return type-id of the property type.
Definition property.h:608
typename std::decay< T >::type BASE_TYPE
Definition property.h:599
void setter(void *obj, wxAny &v) override
Definition property.h:613
bool IgnoreValue() const override
Definition property.h:610
DUMMY_PROPERTY(const wxString &aName)
Definition property.h:601
size_t OwnerHash() const override
Return type-id of the Owner class.
Definition property.h:606
wxAny getter(const void *obj) const override
Definition property.h:617
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:820
ENUM_MAP & Map(T aValue, const wxString &aName)
Definition property.h:783
std::unordered_map< wxString, T > m_reverseMap
Definition property.h:835
T m_undefined
Definition property.h:836
static ENUM_MAP< T > & Instance()
Definition property.h:777
T GetUndefined() const
Definition property.h:796
const wxString & ToString(T value) const
Definition property.h:798
bool IsValueDefined(T value) const
Definition property.h:810
ENUM_MAP & Undefined(T aValue)
Definition property.h:790
wxPGChoices & Choices()
Definition property.h:828
wxPGChoices m_choices
Definition property.h:834
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:468
const wxString m_name
Permanent identifier for this property.
Definition property.h:459
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:480
std::function< bool(INSPECTABLE *)> m_availFunc
Eval to determine if prop is available.
Definition property.h:478
PROPERTY_VALIDATOR_FN m_validator
Definition property.h:484
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:482
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:462
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:465
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:476
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:467
bool m_hideFromDesignEditors
Definition property.h:470
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:472
friend class INSPECTABLE
Definition property.h:486
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:473
bool IsHiddenFromLibraryEditors() const
Definition property.h:338
T get(const void *aObject) const
Definition property.h:430
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:695
bool HasChoices() const override
Return true if this PROPERTY has a limited set of possible values.
Definition property.h:719
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:648
void setter(void *obj, wxAny &v) override
Definition property.h:667
PROPERTY_ENUM(const wxString &aName, void(Base::*aSetter)(SetType), GetType(Base::*aGetter)(), PROPERTY_DISPLAY aDisplay=PT_DEFAULT)
Definition property.h:629
wxPGChoices m_choices
Definition property.h:726
wxAny getter(const void *obj) const override
Definition property.h:688
void SetChoices(const wxPGChoices &aChoices) override
Set the possible values for for the property.
Definition property.h:713
void TranslateChoices() override
Definition property.h:700
bool m_choicesFromENUM_MAP
Definition property.h:725
std::unique_ptr< SETTER_BASE< Owner, T > > m_setter
Set method.
Definition property.h:579
const size_t m_baseHash
Base class type-id.
Definition property.h:588
size_t TypeHash() const override
Return type-id of the property type.
Definition property.h:532
typename std::decay< T >::type BASE_TYPE
Definition property.h:494
const size_t m_typeHash
Property value type-id.
Definition property.h:591
virtual ~PROPERTY()
Definition property.h:556
virtual void setter(void *obj, wxAny &v) override
Definition property.h:558
size_t BaseHash() const override
Return type-id of the Base class.
Definition property.h:527
bool Writeable(INSPECTABLE *aObject) const override
Definition property.h:537
virtual wxAny getter(const void *obj) const override
Definition property.h:571
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:510
std::unique_ptr< GETTER_BASE< Owner, T > > m_getter
Get method.
Definition property.h:582
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:497
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:543
size_t OwnerHash() const override
Return type-id of the Owner class.
Definition property.h:522
const size_t m_ownerHash
Owner class type-id.
Definition property.h:585
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:733
virtual size_t DerivedHash() const =0
size_t DerivedHash() const override
Definition property.h:766
const void * operator()(const void *aPointer) const override
Definition property.h:755
size_t BaseHash() const override
Definition property.h:761
void * operator()(void *aPointer) const override
Definition property.h:749
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