KiCad PCB EDA Suite
Loading...
Searching...
No Matches
property.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2020 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Tomasz Wlostowski <[email protected]>
8 * @author Maciej Suminski <[email protected]>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 3
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#ifndef PROPERTY_H
25#define PROPERTY_H
26
27#include <core/wx_stl_compat.h>
28#include <origin_transforms.h>
32
33#include <wx/any.h>
34#include <wx/string.h>
35#include <wx/bitmap.h>
36#include <wx/font.h> // required for propgrid
37#include <wx/validate.h> // required for propgrid
38#include <wx/propgrid/property.h>
39
40#ifdef DEBUG
41#include <wx/wxcrt.h>
42#endif
43
44#include <functional>
45#include <unordered_map>
46#include <memory>
47#include <typeindex>
48#include <type_traits>
49#include <wx/translation.h>
51
52class wxPGProperty;
53class INSPECTABLE;
54class PROPERTY_BASE;
55
56template<typename T>
57class ENUM_MAP;
58
72
74#define TYPE_HASH( x ) typeid( x ).hash_code()
75#define TYPE_NAME( x ) typeid( x ).name()
76//#define TYPE_HASH( x ) typeid( std::decay<x>::type ).hash_code()
77
78template<typename Owner, typename T>
80{
81public:
82 virtual ~GETTER_BASE() {}
83
84 virtual T operator()( const Owner* aOwner ) const = 0;
85};
86
87template<typename Owner, typename T, typename FuncType>
88class GETTER : public GETTER_BASE<Owner, T>
89{
90public:
91 GETTER( FuncType aFunc )
92 : m_func( aFunc )
93 {
94 wxCHECK( m_func, /*void*/ );
95 }
96
97 T operator()( const Owner* aOwner ) const override
98 {
99 return ( aOwner->*m_func )();
100 }
101
102private:
103 FuncType m_func;
104};
105
106template<typename Owner, typename T>
108{
109public:
110 virtual ~SETTER_BASE() {}
111
112 virtual void operator()( Owner* aOwner, T aValue ) = 0;
113};
114
115template<typename Owner, typename T, typename FuncType>
116class SETTER : public SETTER_BASE<Owner, T>
117{
118public:
119 SETTER( FuncType aFunc )
120 : m_func( aFunc )
121 {
122 wxCHECK( m_func, /*void*/ );
123 }
124
125 void operator()( Owner* aOwner, T aValue ) override
126 {
127 ( aOwner->*m_func )( aValue );
128 }
129
130private:
131 FuncType m_func;
132};
133
134#if defined( _MSC_VER )
135#pragma warning( push )
136#pragma warning( disable : 5266 ) // 'const' qualifier on return type has no effect
137#endif
138
139template<typename Owner, typename T, typename Base = Owner>
141{
142public:
143 static GETTER_BASE<Owner, T>* Wrap( T (Base::*aFunc)() )
144 {
145 return new GETTER<Owner, T, T (Base::*)()>( aFunc );
146 }
147
148 constexpr static GETTER_BASE<Owner, T>* Wrap( const T (Base::*aFunc)() )
149 {
150 return new GETTER<Owner, T, T (Base::*)()>( aFunc );
151 }
152
153 constexpr static GETTER_BASE<Owner, T>* Wrap( const T& (Base::*aFunc)() )
154 {
155 return new GETTER<Owner, T, const T& (Base::*)()>( aFunc );
156 }
157
158 constexpr static GETTER_BASE<Owner, T>* Wrap( T (Base::*aFunc)() const )
159 {
160 return new GETTER<Owner, T, T (Base::*)() const>( aFunc );
161 }
162
163 constexpr static GETTER_BASE<Owner, T>* Wrap( const T (Base::*aFunc)() const )
164 {
165 return new GETTER<Owner, T, T (Base::*)() const>( aFunc );
166 }
167
168 constexpr static GETTER_BASE<Owner, T>* Wrap( const T& (Base::*aFunc)() const )
169 {
171 }
172
173 constexpr static SETTER_BASE<Owner, T>* Wrap( void (Base::*aFunc)( T ) )
174 {
175 return aFunc ? new SETTER<Owner, T, void (Base::*)( T )>( aFunc ) : nullptr;
176 }
177
178 constexpr static SETTER_BASE<Owner, T>* Wrap( void (Base::*aFunc)( T& ) )
179 {
180 return aFunc ? new SETTER<Owner, T, void (Base::*)( T& )>( aFunc ) : nullptr;
181 }
182
183 constexpr static SETTER_BASE<Owner, T>* Wrap( void (Base::*aFunc)( const T& ) )
184 {
185 return aFunc ? new SETTER<Owner, T, void (Base::*)( const T& )>( aFunc ) : nullptr;
186 }
187
188 METHOD() = delete;
189};
190
191#if defined( _MSC_VER )
192#pragma warning( pop )
193#endif
194
196{
197private:
199
200public:
201 PROPERTY_BASE( const wxString& aName, PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
203 m_name( aName ),
204 m_display( aDisplay ),
205 m_coordType( aCoordType ),
209 m_hideFromRulesEditor( false ),
210 m_copyable( false ),
211 m_availFunc( [](INSPECTABLE*)->bool { return true; } ),
212 m_writeableFunc( [](INSPECTABLE*)->bool { return true; } ),
213 m_validator( NullValidator )
214 {
215 }
216
218 {
219 }
220
221 const wxString& Name() const { return m_name; }
222
227 virtual const wxPGChoices& Choices() const
228 {
229 static wxPGChoices empty;
230 return empty;
231 }
232
233 virtual void TranslateChoices() {}
234
238 virtual void SetChoices( const wxPGChoices& aChoices )
239 {
240 wxFAIL; // only possible for PROPERTY_ENUM
241 }
242
247 virtual bool HasChoices() const
248 {
249 return m_choicesFunc != nullptr;
250 }
251
255 bool Available( INSPECTABLE* aObject ) const
256 {
257 return m_availFunc( aObject );
258 }
259
263 PROPERTY_BASE& SetAvailableFunc( std::function<bool(INSPECTABLE*)> aFunc )
264 {
265 m_availFunc = std::move( aFunc );
266 return *this;
267 }
268
269 wxPGChoices GetChoices( INSPECTABLE* aObject ) const
270 {
271 if( m_choicesFunc )
272 return m_choicesFunc( aObject );
273
274 return {};
275 }
276
277 PROPERTY_BASE& SetChoicesFunc( std::function<wxPGChoices(INSPECTABLE*)> aFunc )
278 {
279 m_choicesFunc = std::move( aFunc );
280 return *this;
281 }
282
283 virtual bool IgnoreValue() const
284 {
285 return false;
286 }
287
288 virtual bool Writeable( INSPECTABLE* aObject ) const
289 {
290 return m_writeableFunc( aObject );
291 }
292
293 PROPERTY_BASE& SetWriteableFunc( std::function<bool(INSPECTABLE*)> aFunc )
294 {
295 m_writeableFunc = std::move( aFunc );
296 return *this;
297 }
298
302 virtual size_t OwnerHash() const = 0;
303
307 virtual size_t BaseHash() const = 0;
308
312 virtual size_t TypeHash() const = 0;
313
315 PROPERTY_BASE& SetDisplay( PROPERTY_DISPLAY aDisplay ) { m_display = aDisplay; return *this; }
316
319 {
320 m_coordType = aType;
321 return *this;
322 }
323
326 {
328 return *this;
329 }
330
333 {
334 m_hideFromRulesEditor = aHide;
335 return *this;
336 }
337
340 {
341 m_hideFromLibraryEditors = aIsHidden;
342 return *this;
343 }
344
347 {
348 m_hideFromDesignEditors = aIsHidden;
349 return *this;
350 }
351
358 bool IsCopyable() const { return m_copyable; }
359 PROPERTY_BASE& SetIsCopyable( bool aIsCopyable = true )
360 {
361 m_copyable = aIsCopyable;
362 return *this;
363 }
364
365 wxString Group() const { return m_group; }
366 PROPERTY_BASE& SetGroup( const wxString& aGroup ) { m_group = aGroup; return *this; }
367
369 {
370 m_validator = aValidator;
371 return *this;
372 }
373
374 VALIDATOR_RESULT Validate( const wxAny&& aValue, EDA_ITEM* aItem )
375 {
376 return m_validator( std::move( aValue ), aItem );
377 }
378
379 static VALIDATOR_RESULT NullValidator( const wxAny&& aValue, EDA_ITEM* aItem )
380 {
381 return std::nullopt;
382 }
383
384protected:
385 template<typename T>
386 void set( void* aObject, T aValue )
387 {
388 wxAny a = aValue;
389
390 // wxVariant will be type "long" even if the property is supposed to be
391 // unsigned. Let's trust that we're coming from the property grid where
392 // we used a UInt editor.
393 if( std::is_same<T, wxVariant>::value )
394 {
395 wxVariant var = static_cast<wxVariant>( aValue );
396 wxAny pv = getter( aObject );
397
398 if( pv.CheckType<unsigned>() )
399 {
400 a = static_cast<unsigned>( var.GetLong() );
401 }
402 else if( pv.CheckType<std::optional<int>>() )
403 {
404 auto* data = static_cast<STD_OPTIONAL_INT_VARIANT_DATA*>( var.GetData() );
405 a = data->Value();
406 }
407 else if( pv.CheckType<std::optional<double>>() )
408 {
409 auto* data = static_cast<STD_OPTIONAL_DOUBLE_VARIANT_DATA*>( var.GetData() );
410 a = data->Value();
411 }
412 else if( pv.CheckType<EDA_ANGLE>() )
413 {
414 EDA_ANGLE_VARIANT_DATA* ad = static_cast<EDA_ANGLE_VARIANT_DATA*>( var.GetData() );
415 a = ad->Angle();
416 }
417 else if( pv.CheckType<KIGFX::COLOR4D>() )
418 {
419 COLOR4D_VARIANT_DATA* cd = static_cast<COLOR4D_VARIANT_DATA*>( var.GetData() );
420 a = cd->Color();
421 }
422 }
423
424 setter( aObject, a );
425 }
426
427 template<typename T>
428 T get( const void* aObject ) const
429 {
430 wxAny a = getter( aObject );
431
432 // We don't currently have a bool type, so change it to a numeric
433 if( a.CheckType<bool>() )
434 a = a.RawAs<bool>() ? 1 : 0;
435
436 if ( !( std::is_enum<T>::value && a.CheckType<int>() ) && !a.CheckType<T>() )
437 throw std::invalid_argument( "Invalid requested type" );
438
439 return wxANY_AS( a, T );
440 }
441
442private:
443 virtual void setter( void* aObject, wxAny& aValue ) = 0;
444 virtual wxAny getter( const void* aObject ) const = 0;
445
446private:
452 const wxString m_name;
453
456
459
460 bool m_hideFromPropertiesManager; // Do not show in Properties Manager
461 bool m_hideFromLibraryEditors; // Do not show in Properties Manager of symbol or
462 // footprint editors
463 bool m_hideFromDesignEditors; // Do not show in Properties Manager of schematic or
464 // board editors
465 bool m_hideFromRulesEditor; // Do not show in Custom Rules editor autocomplete
466 bool m_copyable; // May be copied from one item to another
467
469 wxString m_group;
470
471 std::function<bool(INSPECTABLE*)> m_availFunc;
472
473 std::function<bool(INSPECTABLE*)> m_writeableFunc;
474
475 std::function<wxPGChoices(INSPECTABLE*)> m_choicesFunc;
476
478
479 friend class INSPECTABLE;
480};
481
482
483template<typename Owner, typename T, typename Base = Owner>
485{
486public:
487 using BASE_TYPE = typename std::decay<T>::type;
488
489 template<typename SetType, typename GetType>
490 PROPERTY( const wxString& aName,
491 void ( Base::*aSetter )( SetType ),
492 GetType( Base::*aGetter )(),
493 PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
495 PROPERTY( aName,
496 METHOD<Owner, T, Base>::Wrap( aSetter ),
497 METHOD<Owner, T, Base>::Wrap( aGetter ),
498 aDisplay, aCoordType )
499 {
500 }
501
502 template<typename SetType, typename GetType>
503 PROPERTY( const wxString& aName,
504 void ( Base::*aSetter )( SetType ),
505 GetType( Base::*aGetter )() const,
506 PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
508 PROPERTY( aName,
509 METHOD<Owner, T, Base>::Wrap( aSetter ),
510 METHOD<Owner, T, Base>::Wrap( aGetter ),
511 aDisplay, aCoordType )
512 {
513 }
514
515 size_t OwnerHash() const override
516 {
517 return m_ownerHash;
518 }
519
520 size_t BaseHash() const override
521 {
522 return m_baseHash;
523 }
524
525 size_t TypeHash() const override
526 {
527 return m_typeHash;
528 }
529
530 bool Writeable( INSPECTABLE* aObject ) const override
531 {
532 return m_setter && PROPERTY_BASE::Writeable( aObject );
533 }
534
535protected:
536 PROPERTY( const wxString& aName,
540 PROPERTY_BASE( aName, aDisplay, aCoordType ),
541 m_setter( s ),
542 m_getter( g ),
543 m_ownerHash( TYPE_HASH( Owner ) ),
544 m_baseHash( TYPE_HASH( Base ) ),
546 {
547 }
548
549 virtual ~PROPERTY() {}
550
551 virtual void setter( void* obj, wxAny& v ) override
552 {
553 wxCHECK( m_setter, /*void*/ );
554
555 BASE_TYPE value;
556
557 if( !v.GetAs( &value ) )
558 throw std::invalid_argument( "Invalid type requested" );
559
560 Owner* o = reinterpret_cast<Owner*>( obj );
561 (*m_setter)( o, value );
562 }
563
564 virtual wxAny getter( const void* obj ) const override
565 {
566 const Owner* o = reinterpret_cast<const Owner*>( obj );
567 wxAny res = (*m_getter)( o );
568 return res;
569 }
570
572 std::unique_ptr<SETTER_BASE<Owner, T>> m_setter;
573
575 std::unique_ptr<GETTER_BASE<Owner, T>> m_getter;
576
578 const size_t m_ownerHash;
579
581 const size_t m_baseHash;
582
584 const size_t m_typeHash;
585};
586
587
588template<typename Owner, typename T, typename Base = Owner>
590{
591public:
592 using BASE_TYPE = typename std::decay<T>::type;
593
594 DUMMY_PROPERTY( const wxString& aName ) :
595 PROPERTY_BASE( aName )
596 {
597 }
598
599 size_t OwnerHash() const override { return TYPE_HASH( Owner ); }
600 size_t BaseHash() const override { return TYPE_HASH( Base ); }
601 size_t TypeHash() const override { return TYPE_HASH( BASE_TYPE ); }
602
603 bool IgnoreValue() const override { return true; }
604
605protected:
606 void setter( void* obj, wxAny& v ) override
607 {
608 }
609
610 wxAny getter( const void* obj ) const override
611 {
612 return wxAny();
613 }
614};
615
616
617template<typename Owner, typename T, typename Base = Owner>
618class PROPERTY_ENUM : public PROPERTY<Owner, T, Base>
619{
620public:
621 template<typename SetType, typename GetType>
622 PROPERTY_ENUM( const wxString& aName,
623 void ( Base::*aSetter )( SetType ),
624 GetType( Base::*aGetter )(),
625 PROPERTY_DISPLAY aDisplay = PT_DEFAULT ) :
626 PROPERTY<Owner, T, Base>( aName,
627 METHOD<Owner, T, Base>::Wrap( aSetter ),
628 METHOD<Owner, T, Base>::Wrap( aGetter ),
629 aDisplay ),
630 m_choicesFromENUM_MAP( false )
631 {
632 if ( std::is_enum<T>::value )
633 {
634 m_choices = ENUM_MAP<T>::Instance().Choices();
636 wxASSERT_MSG( m_choices.GetCount() > 0, wxT( "No enum choices defined" ) );
637 }
638 }
639
640 template<typename SetType, typename GetType>
641 PROPERTY_ENUM( const wxString& aName,
642 void ( Base::*aSetter )( SetType ),
643 GetType( Base::*aGetter )() const,
644 PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
646 PROPERTY<Owner, T, Base>( aName,
647 METHOD<Owner, T, Base>::Wrap( aSetter ),
648 METHOD<Owner, T, Base>::Wrap( aGetter ),
649 aDisplay, aCoordType ),
650 m_choicesFromENUM_MAP( false )
651 {
652 if ( std::is_enum<T>::value )
653 {
654 m_choices = ENUM_MAP<T>::Instance().Choices();
656 wxASSERT_MSG( m_choices.GetCount() > 0, wxT( "No enum choices defined" ) );
657 }
658 }
659
660 void setter( void* obj, wxAny& v ) override
661 {
662 wxCHECK( ( PROPERTY<Owner, T, Base>::m_setter ), /*void*/ );
663 Owner* o = reinterpret_cast<Owner*>( obj );
664
665 if( v.CheckType<T>() )
666 {
667 T value = wxANY_AS(v, T);
669 }
670 else if (v.CheckType<int>() )
671 {
672 int value = wxANY_AS(v, int);
673 (*PROPERTY<Owner, T, Base>::m_setter)( o, static_cast<T>( value ) );
674 }
675 else
676 {
677 throw std::invalid_argument( "Invalid type requested" );
678 }
679 }
680
681 wxAny getter( const void* obj ) const override
682 {
683 const Owner* o = reinterpret_cast<const Owner*>( obj );
684 wxAny res = static_cast<T>( (*PROPERTY<Owner, T, Base>::m_getter)( o ) );
685 return res;
686 }
687
688 const wxPGChoices& Choices() const override
689 {
690 return m_choices.GetCount() > 0 ? m_choices : ENUM_MAP<T>::Instance().Choices();
691 }
692
693 void TranslateChoices() override
694 {
695 if( m_choicesFromENUM_MAP && std::is_enum<T>::value )
696 {
697 m_choices.Clear();
698
699 wxPGChoices& choices = ENUM_MAP<T>::Instance().Choices();
700
701 for( unsigned ii = 0; ii < choices.GetCount(); ++ii )
702 m_choices.Add( wxGetTranslation( choices.GetLabel( ii ) ), choices.GetValue( ii ) );
703 }
704 }
705
706 void SetChoices( const wxPGChoices& aChoices ) override
707 {
708 m_choices = aChoices;
709 m_choicesFromENUM_MAP = false;
710 }
711
712 bool HasChoices() const override
713 {
714 return Choices().GetCount() > 0;
715 }
716
717protected:
719 wxPGChoices m_choices;
720};
721
722
724{
725public:
726 virtual ~TYPE_CAST_BASE() {}
727 virtual void* operator()( void* aPointer ) const = 0;
728 virtual const void* operator()( const void* aPointer ) const = 0;
729 virtual size_t BaseHash() const = 0;
730 virtual size_t DerivedHash() const = 0;
731};
732
733
734template<typename Base, typename Derived>
736{
737public:
739 {
740 }
741
742 void* operator()( void* aPointer ) const override
743 {
744 Base* base = reinterpret_cast<Base*>( aPointer );
745 return static_cast<Derived*>( base );
746 }
747
748 const void* operator()( const void* aPointer ) const override
749 {
750 const Base* base = reinterpret_cast<const Base*>( aPointer );
751 return static_cast<const Derived*>( base );
752 }
753
754 size_t BaseHash() const override
755 {
756 return TYPE_HASH( Base );
757 }
758
759 size_t DerivedHash() const override
760 {
761 return TYPE_HASH( Derived );
762 }
763};
764
765
766template<typename T>
768{
769public:
771 {
772 static ENUM_MAP<T> inst;
773 return inst;
774 }
775
776 ENUM_MAP& Map( T aValue, const wxString& aName )
777 {
778 m_choices.Add( aName, static_cast<int>( aValue ) );
779 m_reverseMap[ aName ] = aValue;
780 return *this;
781 }
782
784 {
785 m_undefined = aValue;
786 return *this;
787 }
788
789 T GetUndefined() const { return m_undefined; }
790
791 const wxString& ToString( T value ) const
792 {
793 static const wxString s_undef = "UNDEFINED";
794
795 int idx = m_choices.Index( static_cast<int>( value ) );
796
797 if( idx >= 0 && idx < (int) m_choices.GetCount() )
798 return m_choices.GetLabel( static_cast<int>( idx ) );
799 else
800 return s_undef;
801 }
802
803 bool IsValueDefined( T value ) const
804 {
805 int idx = m_choices.Index( static_cast<int>( value ) );
806
807 if( idx >= 0 && idx < (int) m_choices.GetCount() )
808 return true;
809
810 return false;
811 }
812
813 T ToEnum( const wxString value )
814 {
815 if( m_reverseMap.count( value ) )
816 return m_reverseMap[ value ];
817 else
818 return m_undefined;
819 }
820
821 wxPGChoices& Choices()
822 {
823 return m_choices;
824 }
825
826private:
827 wxPGChoices m_choices;
828 std::unordered_map<wxString, T> m_reverseMap;
829 T m_undefined; // Returned if the string is not recognized
830
832 {
833 }
834};
835
836
837// Helper macros to handle enum types
838#define DECLARE_ENUM_TO_WXANY( type ) \
839 template <> \
840 class wxAnyValueTypeImpl<type> : public wxAnyValueTypeImplBase<type> \
841 { \
842 WX_DECLARE_ANY_VALUE_TYPE( wxAnyValueTypeImpl<type> ) \
843 public: \
844 wxAnyValueTypeImpl() : \
845 wxAnyValueTypeImplBase<type>() \
846 { \
847 } \
848 virtual ~wxAnyValueTypeImpl() {} \
849 virtual bool ConvertValue( const wxAnyValueBuffer& src, wxAnyValueType* dstType, \
850 wxAnyValueBuffer& dst ) const override \
851 { \
852 type value = GetValue( src ); \
853 ENUM_MAP<type>& conv = ENUM_MAP<type>::Instance(); \
854 if( !conv.IsValueDefined( value ) && value != conv.GetUndefined() ) \
855 { \
856 return false; \
857 } \
858 if( dstType->CheckType<wxString>() ) \
859 { \
860 wxAnyValueTypeImpl<wxString>::SetValue( conv.ToString( value ), dst ); \
861 return true; \
862 } \
863 if( dstType->CheckType<int>() ) \
864 { \
865 wxAnyValueTypeImpl<int>::SetValue( static_cast<int>( value ), dst ); \
866 return true; \
867 } \
868 else \
869 { \
870 return false; \
871 } \
872 } \
873 };
874
875#define IMPLEMENT_ENUM_TO_WXANY( type ) WX_IMPLEMENT_ANY_VALUE_TYPE( wxAnyValueTypeImpl<type> )
876
877#define ENUM_TO_WXANY( type ) \
878 DECLARE_ENUM_TO_WXANY( type ) \
879 IMPLEMENT_ENUM_TO_WXANY( type )
880
882#define NO_SETTER( owner, type ) ( ( void ( owner::* )( type ) ) nullptr )
883
884/*
885#define DECLARE_PROPERTY(owner,type,name,getter,setter) \
886namespace anonymous {\
887static PROPERTY<owner,type> prop##_owner##_name_( "##name#", setter, getter );\
888};
889*/
890#endif /* PROPERTY_H */
const KIGFX::COLOR4D & Color()
size_t BaseHash() const override
Return type-id of the Base class.
Definition property.h:600
size_t TypeHash() const override
Return type-id of the property type.
Definition property.h:601
typename std::decay< T >::type BASE_TYPE
Definition property.h:592
void setter(void *obj, wxAny &v) override
Definition property.h:606
bool IgnoreValue() const override
Definition property.h:603
DUMMY_PROPERTY(const wxString &aName)
Definition property.h:594
size_t OwnerHash() const override
Return type-id of the Owner class.
Definition property.h:599
wxAny getter(const void *obj) const override
Definition property.h:610
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:813
ENUM_MAP & Map(T aValue, const wxString &aName)
Definition property.h:776
std::unordered_map< wxString, T > m_reverseMap
Definition property.h:828
T m_undefined
Definition property.h:829
static ENUM_MAP< T > & Instance()
Definition property.h:770
T GetUndefined() const
Definition property.h:789
const wxString & ToString(T value) const
Definition property.h:791
bool IsValueDefined(T value) const
Definition property.h:803
ENUM_MAP & Undefined(T aValue)
Definition property.h:783
wxPGChoices & Choices()
Definition property.h:821
wxPGChoices m_choices
Definition property.h:827
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:461
const wxString m_name
Permanent identifier for this property.
Definition property.h:452
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:473
std::function< bool(INSPECTABLE *)> m_availFunc
Eval to determine if prop is available.
Definition property.h:471
PROPERTY_VALIDATOR_FN m_validator
Definition property.h:477
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:475
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:455
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:458
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:469
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:460
bool m_hideFromDesignEditors
Definition property.h:463
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:465
friend class INSPECTABLE
Definition property.h:479
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:466
bool IsHiddenFromLibraryEditors() const
Definition property.h:338
T get(const void *aObject) const
Definition property.h:428
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:688
bool HasChoices() const override
Return true if this PROPERTY has a limited set of possible values.
Definition property.h:712
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:641
void setter(void *obj, wxAny &v) override
Definition property.h:660
PROPERTY_ENUM(const wxString &aName, void(Base::*aSetter)(SetType), GetType(Base::*aGetter)(), PROPERTY_DISPLAY aDisplay=PT_DEFAULT)
Definition property.h:622
wxPGChoices m_choices
Definition property.h:719
wxAny getter(const void *obj) const override
Set method.
Definition property.h:681
void SetChoices(const wxPGChoices &aChoices) override
Set the possible values for for the property.
Definition property.h:706
void TranslateChoices() override
Definition property.h:693
bool m_choicesFromENUM_MAP
Definition property.h:718
std::unique_ptr< SETTER_BASE< Owner, T > > m_setter
Get method.
Definition property.h:572
const size_t m_baseHash
Property value type-id.
Definition property.h:581
size_t TypeHash() const override
Return type-id of the property type.
Definition property.h:525
typename std::decay< T >::type BASE_TYPE
Definition property.h:487
const size_t m_typeHash
Definition property.h:584
virtual ~PROPERTY()
Definition property.h:549
virtual void setter(void *obj, wxAny &v) override
Definition property.h:551
size_t BaseHash() const override
Return type-id of the Base class.
Definition property.h:520
bool Writeable(INSPECTABLE *aObject) const override
Definition property.h:530
virtual wxAny getter(const void *obj) const override
Set method.
Definition property.h:564
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:503
std::unique_ptr< GETTER_BASE< Owner, T > > m_getter
Owner class type-id.
Definition property.h:575
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:490
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:536
size_t OwnerHash() const override
Return type-id of the Owner class.
Definition property.h:515
const size_t m_ownerHash
Base class type-id.
Definition property.h:578
virtual void operator()(Owner *aOwner, T aValue)=0
virtual ~SETTER_BASE()
Definition property.h:110
void operator()(Owner *aOwner, T aValue) override
Definition property.h:125
FuncType m_func
Definition property.h:131
SETTER(FuncType aFunc)
Definition property.h:119
std::optional< double > Value() const
std::optional< int > Value() const
virtual const void * operator()(const void *aPointer) const =0
virtual size_t BaseHash() const =0
virtual void * operator()(void *aPointer) const =0
virtual ~TYPE_CAST_BASE()
Definition property.h:726
virtual size_t DerivedHash() const =0
size_t DerivedHash() const override
Definition property.h:759
const void * operator()(const void *aPointer) const override
Definition property.h:748
size_t BaseHash() const override
Definition property.h:754
void * operator()(void *aPointer) const override
Definition property.h:742
static bool empty(const wxTextEntryBase *aCtrl)
#define TYPE_HASH(x)
Definition property.h:74
PROPERTY_DISPLAY
Common property types.
Definition property.h:61
@ PT_DEGREE
Angle expressed in degrees.
Definition property.h:66
@ PT_COORD
Coordinate expressed in distance units (mm/inch)
Definition property.h:65
@ PT_RATIO
Definition property.h:68
@ PT_DECIDEGREE
Angle expressed in decidegrees.
Definition property.h:67
@ PT_AREA
Area expressed in distance units-squared (mm/inch)
Definition property.h:64
@ PT_DEFAULT
Default property for a given type.
Definition property.h:62
@ PT_SIZE
Size expressed in distance units (mm/inch)
Definition property.h:63
@ PT_NET
Net selection property.
Definition property.h:70
@ PT_TIME
Time expressed in ps.
Definition property.h:69
std::function< VALIDATOR_RESULT(const wxAny &&, EDA_ITEM *aItem)> PROPERTY_VALIDATOR_FN
A property validator function takes in the data type of the owning property, and returns a VALIDATOR_...
std::optional< std::unique_ptr< VALIDATION_ERROR > > VALIDATOR_RESULT
Null optional means validation succeeded.
VECTOR3I res