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 along
21 * with this program. If not, see <http://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>
50
51class wxPGProperty;
52class INSPECTABLE;
53class PROPERTY_BASE;
54
55template<typename T>
56class ENUM_MAP;
57
60{
69};
70
72#define TYPE_HASH( x ) typeid( x ).hash_code()
73#define TYPE_NAME( x ) typeid( x ).name()
74//#define TYPE_HASH( x ) typeid( std::decay<x>::type ).hash_code()
75
76template<typename Owner, typename T>
78{
79public:
80 virtual ~GETTER_BASE() {}
81
82 virtual T operator()( const Owner* aOwner ) const = 0;
83};
84
85template<typename Owner, typename T, typename FuncType>
86class GETTER : public GETTER_BASE<Owner, T>
87{
88public:
89 GETTER( FuncType aFunc )
90 : m_func( aFunc )
91 {
92 wxCHECK( m_func, /*void*/ );
93 }
94
95 T operator()( const Owner* aOwner ) const override
96 {
97 return ( aOwner->*m_func )();
98 }
99
100private:
101 FuncType m_func;
102};
103
104template<typename Owner, typename T>
106{
107public:
108 virtual ~SETTER_BASE() {}
109
110 virtual void operator()( Owner* aOwner, T aValue ) = 0;
111};
112
113template<typename Owner, typename T, typename FuncType>
114class SETTER : public SETTER_BASE<Owner, T>
115{
116public:
117 SETTER( FuncType aFunc )
118 : m_func( aFunc )
119 {
120 wxCHECK( m_func, /*void*/ );
121 }
122
123 void operator()( Owner* aOwner, T aValue ) override
124 {
125 ( aOwner->*m_func )( aValue );
126 }
127
128private:
129 FuncType m_func;
130};
131
132#if defined( _MSC_VER )
133#pragma warning( push )
134#pragma warning( disable : 5266 ) // 'const' qualifier on return type has no effect
135#endif
136
137template<typename Owner, typename T, typename Base = Owner>
139{
140public:
141 static GETTER_BASE<Owner, T>* Wrap( T (Base::*aFunc)() )
142 {
143 return new GETTER<Owner, T, T (Base::*)()>( aFunc );
144 }
145
146 constexpr static GETTER_BASE<Owner, T>* Wrap( const T (Base::*aFunc)() )
147 {
148 return new GETTER<Owner, T, T (Base::*)()>( aFunc );
149 }
150
151 constexpr static GETTER_BASE<Owner, T>* Wrap( const T& (Base::*aFunc)() )
152 {
153 return new GETTER<Owner, T, const T& (Base::*)()>( aFunc );
154 }
155
156 constexpr static GETTER_BASE<Owner, T>* Wrap( T (Base::*aFunc)() const )
157 {
158 return new GETTER<Owner, T, T (Base::*)() const>( aFunc );
159 }
160
161 constexpr static GETTER_BASE<Owner, T>* Wrap( const T (Base::*aFunc)() const )
162 {
163 return new GETTER<Owner, T, T (Base::*)() const>( aFunc );
164 }
165
166 constexpr static GETTER_BASE<Owner, T>* Wrap( const T& (Base::*aFunc)() const )
167 {
169 }
170
171 constexpr static SETTER_BASE<Owner, T>* Wrap( void (Base::*aFunc)( T ) )
172 {
173 return aFunc ? new SETTER<Owner, T, void (Base::*)( T )>( aFunc ) : nullptr;
174 }
175
176 constexpr static SETTER_BASE<Owner, T>* Wrap( void (Base::*aFunc)( T& ) )
177 {
178 return aFunc ? new SETTER<Owner, T, void (Base::*)( T& )>( aFunc ) : nullptr;
179 }
180
181 constexpr static SETTER_BASE<Owner, T>* Wrap( void (Base::*aFunc)( const T& ) )
182 {
183 return aFunc ? new SETTER<Owner, T, void (Base::*)( const T& )>( aFunc ) : nullptr;
184 }
185
186 METHOD() = delete;
187};
188
189#if defined( _MSC_VER )
190#pragma warning( pop )
191#endif
192
194{
195private:
197
198public:
199 PROPERTY_BASE( const wxString& aName, PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
201 m_name( aName ),
202 m_display( aDisplay ),
203 m_coordType( aCoordType ),
207 m_hideFromRulesEditor( false ),
208 m_availFunc( [](INSPECTABLE*)->bool { return true; } ),
209 m_writeableFunc( [](INSPECTABLE*)->bool { return true; } ),
210 m_validator( NullValidator )
211 {
212 }
213
215 {
216 }
217
218 const wxString& Name() const { return m_name; }
219
224 virtual const wxPGChoices& Choices() const
225 {
226 static wxPGChoices empty;
227 return empty;
228 }
229
233 virtual void SetChoices( const wxPGChoices& aChoices )
234 {
235 wxFAIL; // only possible for PROPERTY_ENUM
236 }
237
242 virtual bool HasChoices() const
243 {
244 return m_choicesFunc != nullptr;
245 }
246
250 bool Available( INSPECTABLE* aObject ) const
251 {
252 return m_availFunc( aObject );
253 }
254
258 PROPERTY_BASE& SetAvailableFunc( std::function<bool(INSPECTABLE*)> aFunc )
259 {
260 m_availFunc = std::move( aFunc );
261 return *this;
262 }
263
264 wxPGChoices GetChoices( INSPECTABLE* aObject ) const
265 {
266 if( m_choicesFunc )
267 return m_choicesFunc( aObject );
268
269 return {};
270 }
271
272 PROPERTY_BASE& SetChoicesFunc( std::function<wxPGChoices(INSPECTABLE*)> aFunc )
273 {
274 m_choicesFunc = std::move( aFunc );
275 return *this;
276 }
277
278 virtual bool Writeable( INSPECTABLE* aObject ) const
279 {
280 return m_writeableFunc( aObject );
281 }
282
283 PROPERTY_BASE& SetWriteableFunc( std::function<bool(INSPECTABLE*)> aFunc )
284 {
285 m_writeableFunc = std::move( aFunc );
286 return *this;
287 }
288
292 virtual size_t OwnerHash() const = 0;
293
297 virtual size_t BaseHash() const = 0;
298
302 virtual size_t TypeHash() const = 0;
303
304 PROPERTY_DISPLAY Display() const { return m_display; }
305 PROPERTY_BASE& SetDisplay( PROPERTY_DISPLAY aDisplay ) { m_display = aDisplay; return *this; }
306
307 ORIGIN_TRANSFORMS::COORD_TYPES_T CoordType() const { return m_coordType; }
309 {
310 m_coordType = aType;
311 return *this;
312 }
313
314 bool IsHiddenFromPropertiesManager() const { return m_hideFromPropertiesManager; }
316 {
317 m_hideFromPropertiesManager = aHide;
318 return *this;
319 }
320
321 bool IsHiddenFromRulesEditor() const { return m_hideFromRulesEditor; }
323 {
324 m_hideFromRulesEditor = aHide;
325 return *this;
326 }
327
328 bool IsHiddenFromLibraryEditors() const { return m_hideFromLibraryEditors; }
330 {
331 m_hideFromLibraryEditors = aIsHidden;
332 return *this;
333 }
334
335 bool IsHiddenFromDesignEditors() const { return m_hideFromDesignEditors; }
337 {
338 m_hideFromDesignEditors = aIsHidden;
339 return *this;
340 }
341
342 wxString Group() const { return m_group; }
343 PROPERTY_BASE& SetGroup( const wxString& aGroup ) { m_group = aGroup; return *this; }
344
346 {
347 m_validator = aValidator;
348 return *this;
349 }
350
351 VALIDATOR_RESULT Validate( const wxAny&& aValue, EDA_ITEM* aItem )
352 {
353 return m_validator( std::move( aValue ), aItem );
354 }
355
356 static VALIDATOR_RESULT NullValidator( const wxAny&& aValue, EDA_ITEM* aItem )
357 {
358 return std::nullopt;
359 }
360
361protected:
362 template<typename T>
363 void set( void* aObject, T aValue )
364 {
365 wxAny a = aValue;
366
367 // wxVariant will be type "long" even if the property is supposed to be
368 // unsigned. Let's trust that we're coming from the property grid where
369 // we used a UInt editor.
370 if( std::is_same<T, wxVariant>::value )
371 {
372 wxVariant var = static_cast<wxVariant>( aValue );
373 wxAny pv = getter( aObject );
374
375 if( pv.CheckType<unsigned>() )
376 {
377 a = static_cast<unsigned>( var.GetLong() );
378 }
379 else if( pv.CheckType<std::optional<int>>() )
380 {
381 auto* data = static_cast<STD_OPTIONAL_INT_VARIANT_DATA*>( var.GetData() );
382 a = data->Value();
383 }
384 else if( pv.CheckType<std::optional<double>>() )
385 {
386 auto* data = static_cast<STD_OPTIONAL_DOUBLE_VARIANT_DATA*>( var.GetData() );
387 a = data->Value();
388 }
389 else if( pv.CheckType<EDA_ANGLE>() )
390 {
391 EDA_ANGLE_VARIANT_DATA* ad = static_cast<EDA_ANGLE_VARIANT_DATA*>( var.GetData() );
392 a = ad->Angle();
393 }
394 else if( pv.CheckType<KIGFX::COLOR4D>() )
395 {
396 COLOR4D_VARIANT_DATA* cd = static_cast<COLOR4D_VARIANT_DATA*>( var.GetData() );
397 a = cd->Color();
398 }
399 }
400
401 setter( aObject, a );
402 }
403
404 template<typename T>
405 T get( const void* aObject ) const
406 {
407 wxAny a = getter( aObject );
408
409 // We don't currently have a bool type, so change it to a numeric
410 if( a.CheckType<bool>() )
411 a = a.RawAs<bool>() ? 1 : 0;
412
413 if ( !( std::is_enum<T>::value && a.CheckType<int>() ) && !a.CheckType<T>() )
414 throw std::invalid_argument( "Invalid requested type" );
415
416 return wxANY_AS( a, T );
417 }
418
419private:
420 virtual void setter( void* aObject, wxAny& aValue ) = 0;
421 virtual wxAny getter( const void* aObject ) const = 0;
422
423private:
429 const wxString m_name;
430
433
436
437 bool m_hideFromPropertiesManager; // Do not show in Properties Manager
438 bool m_hideFromLibraryEditors; // Do not show in Properties Manager of symbol or
439 // footprint editors
440 bool m_hideFromDesignEditors; // Do not show in Properties Manager of schematic or
441 // board editors
442 bool m_hideFromRulesEditor; // Do not show in Custom Rules editor autocomplete
443
445 wxString m_group;
446
447 std::function<bool(INSPECTABLE*)> m_availFunc;
448
449 std::function<bool(INSPECTABLE*)> m_writeableFunc;
450
451 std::function<wxPGChoices(INSPECTABLE*)> m_choicesFunc;
452
454
455 friend class INSPECTABLE;
456};
457
458
459template<typename Owner, typename T, typename Base = Owner>
461{
462public:
463 using BASE_TYPE = typename std::decay<T>::type;
464
465 template<typename SetType, typename GetType>
466 PROPERTY( const wxString& aName,
467 void ( Base::*aSetter )( SetType ),
468 GetType( Base::*aGetter )(),
469 PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
471 PROPERTY( aName,
472 METHOD<Owner, T, Base>::Wrap( aSetter ),
473 METHOD<Owner, T, Base>::Wrap( aGetter ),
474 aDisplay, aCoordType )
475 {
476 }
477
478 template<typename SetType, typename GetType>
479 PROPERTY( const wxString& aName,
480 void ( Base::*aSetter )( SetType ),
481 GetType( Base::*aGetter )() const,
482 PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
484 PROPERTY( aName,
485 METHOD<Owner, T, Base>::Wrap( aSetter ),
486 METHOD<Owner, T, Base>::Wrap( aGetter ),
487 aDisplay, aCoordType )
488 {
489 }
490
491 size_t OwnerHash() const override
492 {
493 return m_ownerHash;
494 }
495
496 size_t BaseHash() const override
497 {
498 return m_baseHash;
499 }
500
501 size_t TypeHash() const override
502 {
503 return m_typeHash;
504 }
505
506 bool Writeable( INSPECTABLE* aObject ) const override
507 {
508 return m_setter && PROPERTY_BASE::Writeable( aObject );
509 }
510
511protected:
512 PROPERTY( const wxString& aName,
516 PROPERTY_BASE( aName, aDisplay, aCoordType ),
517 m_setter( s ),
518 m_getter( g ),
519 m_ownerHash( TYPE_HASH( Owner ) ),
520 m_baseHash( TYPE_HASH( Base ) ),
522 {
523 }
524
525 virtual ~PROPERTY() {}
526
527 virtual void setter( void* obj, wxAny& v ) override
528 {
529 wxCHECK( m_setter, /*void*/ );
530
531 if( !v.CheckType<T>() )
532 throw std::invalid_argument( "Invalid type requested" );
533
534 Owner* o = reinterpret_cast<Owner*>( obj );
535 BASE_TYPE value = wxANY_AS(v, BASE_TYPE);
536 (*m_setter)( o, value );
537 }
538
539 virtual wxAny getter( const void* obj ) const override
540 {
541 const Owner* o = reinterpret_cast<const Owner*>( obj );
542 wxAny res = (*m_getter)( o );
543 return res;
544 }
545
547 std::unique_ptr<SETTER_BASE<Owner, T>> m_setter;
548
550 std::unique_ptr<GETTER_BASE<Owner, T>> m_getter;
551
553 const size_t m_ownerHash;
554
556 const size_t m_baseHash;
557
559 const size_t m_typeHash;
560};
561
562
563template<typename Owner, typename T, typename Base = Owner>
564class PROPERTY_ENUM : public PROPERTY<Owner, T, Base>
565{
566public:
567 template<typename SetType, typename GetType>
568 PROPERTY_ENUM( const wxString& aName,
569 void ( Base::*aSetter )( SetType ),
570 GetType( Base::*aGetter )(),
571 PROPERTY_DISPLAY aDisplay = PT_DEFAULT ) :
572 PROPERTY<Owner, T, Base>( aName,
573 METHOD<Owner, T, Base>::Wrap( aSetter ),
574 METHOD<Owner, T, Base>::Wrap( aGetter ),
575 aDisplay )
576 {
577 if ( std::is_enum<T>::value )
578 {
579 m_choices = ENUM_MAP<T>::Instance().Choices();
580 wxASSERT_MSG( m_choices.GetCount() > 0, wxT( "No enum choices defined" ) );
581 }
582 }
583
584 template<typename SetType, typename GetType>
585 PROPERTY_ENUM( const wxString& aName,
586 void ( Base::*aSetter )( SetType ),
587 GetType( Base::*aGetter )() const,
588 PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
590 PROPERTY<Owner, T, Base>( aName,
591 METHOD<Owner, T, Base>::Wrap( aSetter ),
592 METHOD<Owner, T, Base>::Wrap( aGetter ),
593 aDisplay, aCoordType )
594 {
595 if ( std::is_enum<T>::value )
596 {
597 m_choices = ENUM_MAP<T>::Instance().Choices();
598 wxASSERT_MSG( m_choices.GetCount() > 0, wxT( "No enum choices defined" ) );
599 }
600 }
601
602 void setter( void* obj, wxAny& v ) override
603 {
604 wxCHECK( ( PROPERTY<Owner, T, Base>::m_setter ), /*void*/ );
605 Owner* o = reinterpret_cast<Owner*>( obj );
606
607 if( v.CheckType<T>() )
608 {
609 T value = wxANY_AS(v, T);
611 }
612 else if (v.CheckType<int>() )
613 {
614 int value = wxANY_AS(v, int);
615 (*PROPERTY<Owner, T, Base>::m_setter)( o, static_cast<T>( value ) );
616 }
617 else
618 {
619 throw std::invalid_argument( "Invalid type requested" );
620 }
621 }
622
623 wxAny getter( const void* obj ) const override
624 {
625 const Owner* o = reinterpret_cast<const Owner*>( obj );
626 wxAny res = static_cast<T>( (*PROPERTY<Owner, T, Base>::m_getter)( o ) );
627 return res;
628 }
629
630 const wxPGChoices& Choices() const override
631 {
632 return m_choices.GetCount() > 0 ? m_choices : ENUM_MAP<T>::Instance().Choices();
633 }
634
635 void SetChoices( const wxPGChoices& aChoices ) override
636 {
637 m_choices = aChoices;
638 }
639
640 bool HasChoices() const override
641 {
642 return Choices().GetCount() > 0;
643 }
644
645protected:
646 wxPGChoices m_choices;
647};
648
649
651{
652public:
653 virtual ~TYPE_CAST_BASE() {}
654 virtual void* operator()( void* aPointer ) const = 0;
655 virtual const void* operator()( const void* aPointer ) const = 0;
656 virtual size_t BaseHash() const = 0;
657 virtual size_t DerivedHash() const = 0;
658};
659
660
661template<typename Base, typename Derived>
663{
664public:
666 {
667 }
668
669 void* operator()( void* aPointer ) const override
670 {
671 Base* base = reinterpret_cast<Base*>( aPointer );
672 return static_cast<Derived*>( base );
673 }
674
675 const void* operator()( const void* aPointer ) const override
676 {
677 const Base* base = reinterpret_cast<const Base*>( aPointer );
678 return static_cast<const Derived*>( base );
679 }
680
681 size_t BaseHash() const override
682 {
683 return TYPE_HASH( Base );
684 }
685
686 size_t DerivedHash() const override
687 {
688 return TYPE_HASH( Derived );
689 }
690};
691
692
693template<typename T>
695{
696public:
698 {
699 static ENUM_MAP<T> inst;
700 return inst;
701 }
702
703 ENUM_MAP& Map( T aValue, const wxString& aName )
704 {
705 m_choices.Add( aName, static_cast<int>( aValue ) );
706 m_reverseMap[ aName ] = aValue;
707 return *this;
708 }
709
711 {
712 m_undefined = aValue;
713 return *this;
714 }
715
716 const wxString& ToString( T value ) const
717 {
718 static const wxString s_undef = "UNDEFINED";
719
720 int idx = m_choices.Index( static_cast<int>( value ) );
721
722 if( idx >= 0 && idx < (int) m_choices.GetCount() )
723 return m_choices.GetLabel( static_cast<int>( idx ) );
724 else
725 return s_undef;
726 }
727
728 bool IsValueDefined( T value ) const
729 {
730 int idx = m_choices.Index( static_cast<int>( value ) );
731
732 if( idx >= 0 && idx < (int) m_choices.GetCount() )
733 return true;
734
735 return false;
736 }
737
738 T ToEnum( const wxString value )
739 {
740 if( m_reverseMap.count( value ) )
741 return m_reverseMap[ value ];
742 else
743 return m_undefined;
744 }
745
746 wxPGChoices& Choices()
747 {
748 return m_choices;
749 }
750
751private:
752 wxPGChoices m_choices;
753 std::unordered_map<wxString, T> m_reverseMap;
754 T m_undefined; // Returned if the string is not recognized
755
757 {
758 }
759};
760
761
762// Helper macros to handle enum types
763#define DECLARE_ENUM_TO_WXANY( type ) \
764 template <> \
765 class wxAnyValueTypeImpl<type> : public wxAnyValueTypeImplBase<type> \
766 { \
767 WX_DECLARE_ANY_VALUE_TYPE( wxAnyValueTypeImpl<type> ) \
768 public: \
769 wxAnyValueTypeImpl() : wxAnyValueTypeImplBase<type>() {} \
770 virtual ~wxAnyValueTypeImpl() {} \
771 virtual bool ConvertValue( const wxAnyValueBuffer& src, wxAnyValueType* dstType, \
772 wxAnyValueBuffer& dst ) const override \
773 { \
774 type value = GetValue( src ); \
775 ENUM_MAP<type>& conv = ENUM_MAP<type>::Instance(); \
776 if( ! conv.IsValueDefined( value ) ) \
777 { \
778 return false; \
779 } \
780 if( dstType->CheckType<wxString>() ) \
781 { \
782 wxAnyValueTypeImpl<wxString>::SetValue( conv.ToString( value ), dst ); \
783 return true; \
784 } \
785 if( dstType->CheckType<int>() ) \
786 { \
787 wxAnyValueTypeImpl<int>::SetValue( static_cast<int>( value ), dst ); \
788 return true; \
789 } \
790 else \
791 { \
792 return false; \
793 } \
794 } \
795 };
796
797#define IMPLEMENT_ENUM_TO_WXANY( type ) WX_IMPLEMENT_ANY_VALUE_TYPE( wxAnyValueTypeImpl<type> )
798
799#define ENUM_TO_WXANY( type ) \
800 DECLARE_ENUM_TO_WXANY( type ) \
801 IMPLEMENT_ENUM_TO_WXANY( type )
802
804#define NO_SETTER( owner, type ) ( ( void ( owner::* )( type ) ) nullptr )
805
806/*
807#define DECLARE_PROPERTY(owner,type,name,getter,setter) \
808namespace anonymous {\
809static PROPERTY<owner,type> prop##_owner##_name_( "##name#", setter, getter );\
810};
811*/
812#endif /* PROPERTY_H */
const KIGFX::COLOR4D & Color()
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:738
ENUM_MAP & Map(T aValue, const wxString &aName)
Definition: property.h:703
std::unordered_map< wxString, T > m_reverseMap
Definition: property.h:753
T m_undefined
Definition: property.h:754
static ENUM_MAP< T > & Instance()
Definition: property.h:697
ENUM_MAP()
Definition: property.h:756
const wxString & ToString(T value) const
Definition: property.h:716
bool IsValueDefined(T value) const
Definition: property.h:728
ENUM_MAP & Undefined(T aValue)
Definition: property.h:710
wxPGChoices & Choices()
Definition: property.h:746
wxPGChoices m_choices
Definition: property.h:752
virtual ~GETTER_BASE()
Definition: property.h:80
virtual T operator()(const Owner *aOwner) const =0
GETTER(FuncType aFunc)
Definition: property.h:89
FuncType m_func
Definition: property.h:101
T operator()(const Owner *aOwner) const override
Definition: property.h:95
Class that other classes need to inherit from, in order to be inspectable.
Definition: inspectable.h:37
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
static constexpr GETTER_BASE< Owner, T > * Wrap(const T(Base::*aFunc)())
Definition: property.h:146
static GETTER_BASE< Owner, T > * Wrap(T(Base::*aFunc)())
Definition: property.h:141
static constexpr GETTER_BASE< Owner, T > * Wrap(const T(Base::*aFunc)() const)
Definition: property.h:161
static constexpr GETTER_BASE< Owner, T > * Wrap(T(Base::*aFunc)() const)
Definition: property.h:156
static constexpr SETTER_BASE< Owner, T > * Wrap(void(Base::*aFunc)(const T &))
Definition: property.h:181
static constexpr GETTER_BASE< Owner, T > * Wrap(const T &(Base::*aFunc)())
Definition: property.h:151
static constexpr GETTER_BASE< Owner, T > * Wrap(const T &(Base::*aFunc)() const)
Definition: property.h:166
static constexpr SETTER_BASE< Owner, T > * Wrap(void(Base::*aFunc)(T))
Definition: property.h:171
static constexpr SETTER_BASE< Owner, T > * Wrap(void(Base::*aFunc)(T &))
Definition: property.h:176
METHOD()=delete
COORD_TYPES_T
The supported Display Origin Transform types.
PROPERTY_BASE & SetChoicesFunc(std::function< wxPGChoices(INSPECTABLE *)> aFunc)
Definition: property.h:272
bool IsHiddenFromPropertiesManager() const
Definition: property.h:314
virtual size_t TypeHash() const =0
Return type-id of the property type.
bool m_hideFromLibraryEditors
Definition: property.h:438
const wxString m_name
Permanent identifier for this property.
Definition: property.h:429
VALIDATOR_RESULT Validate(const wxAny &&aValue, EDA_ITEM *aItem)
Definition: property.h:351
std::function< bool(INSPECTABLE *)> m_writeableFunc
Eval to determine if prop is read-only.
Definition: property.h:449
std::function< bool(INSPECTABLE *)> m_availFunc
Eval to determine if prop is available.
Definition: property.h:447
PROPERTY_VALIDATOR_FN m_validator
Definition: property.h:453
bool IsHiddenFromDesignEditors() const
Definition: property.h:335
PROPERTY_BASE & SetAvailableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Set a callback function to determine whether an object provides this property.
Definition: property.h:258
PROPERTY_BASE & SetDisplay(PROPERTY_DISPLAY aDisplay)
Definition: property.h:305
std::function< wxPGChoices(INSPECTABLE *)> m_choicesFunc
Definition: property.h:451
PROPERTY_DISPLAY Display() const
Definition: property.h:304
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:199
static VALIDATOR_RESULT NullValidator(const wxAny &&aValue, EDA_ITEM *aItem)
Definition: property.h:356
wxString Group() const
Definition: property.h:342
PROPERTY_BASE & SetWriteableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Definition: property.h:283
PROPERTY_BASE & SetGroup(const wxString &aGroup)
Definition: property.h:343
ORIGIN_TRANSFORMS::COORD_TYPES_T CoordType() const
Definition: property.h:307
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:308
PROPERTY_DISPLAY m_display
The display style controls how properties are edited in the properties manager GUI.
Definition: property.h:432
virtual bool HasChoices() const
Return true if this PROPERTY has a limited set of possible values.
Definition: property.h:242
ORIGIN_TRANSFORMS::COORD_TYPES_T m_coordType
The coordinate type controls how distances are mapped to the user coordinate system.
Definition: property.h:435
virtual bool Writeable(INSPECTABLE *aObject) const
Definition: property.h:278
wxPGChoices GetChoices(INSPECTABLE *aObject) const
Definition: property.h:264
virtual void setter(void *aObject, wxAny &aValue)=0
virtual ~PROPERTY_BASE()
Definition: property.h:214
wxString m_group
Optional group identifier.
Definition: property.h:445
bool Available(INSPECTABLE *aObject) const
Return true if aObject offers this PROPERTY.
Definition: property.h:250
PROPERTY_BASE & SetValidator(PROPERTY_VALIDATOR_FN &&aValidator)
Definition: property.h:345
bool m_hideFromPropertiesManager
Definition: property.h:437
bool m_hideFromDesignEditors
Definition: property.h:440
PROPERTY_BASE & SetIsHiddenFromDesignEditors(bool aIsHidden=true)
Definition: property.h:336
PROPERTY_BASE & SetIsHiddenFromPropertiesManager(bool aHide=true)
Definition: property.h:315
bool m_hideFromRulesEditor
Definition: property.h:442
void set(void *aObject, T aValue)
Definition: property.h:363
const wxString & Name() const
Definition: property.h:218
bool IsHiddenFromRulesEditor() const
Definition: property.h:321
virtual const wxPGChoices & Choices() const
Return a limited set of possible values (e.g.
Definition: property.h:224
virtual void SetChoices(const wxPGChoices &aChoices)
Set the possible values for for the property.
Definition: property.h:233
virtual size_t OwnerHash() const =0
Return type-id of the Owner class.
PROPERTY_BASE & SetIsHiddenFromRulesEditor(bool aHide=true)
Definition: property.h:322
bool IsHiddenFromLibraryEditors() const
Definition: property.h:328
T get(const void *aObject) const
Definition: property.h:405
PROPERTY_BASE & SetIsHiddenFromLibraryEditors(bool aIsHidden=true)
Definition: property.h:329
const wxPGChoices & Choices() const override
Return a limited set of possible values (e.g.
Definition: property.h:630
bool HasChoices() const override
Return true if this PROPERTY has a limited set of possible values.
Definition: property.h:640
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:585
void setter(void *obj, wxAny &v) override
Definition: property.h:602
PROPERTY_ENUM(const wxString &aName, void(Base::*aSetter)(SetType), GetType(Base::*aGetter)(), PROPERTY_DISPLAY aDisplay=PT_DEFAULT)
Definition: property.h:568
wxPGChoices m_choices
Definition: property.h:646
wxAny getter(const void *obj) const override
Set method.
Definition: property.h:623
void SetChoices(const wxPGChoices &aChoices) override
Set the possible values for for the property.
Definition: property.h:635
std::unique_ptr< SETTER_BASE< Owner, T > > m_setter
Get method.
Definition: property.h:547
const size_t m_baseHash
Property value type-id.
Definition: property.h:556
size_t TypeHash() const override
Return type-id of the property type.
Definition: property.h:501
typename std::decay< T >::type BASE_TYPE
Definition: property.h:463
const size_t m_typeHash
Definition: property.h:559
virtual ~PROPERTY()
Definition: property.h:525
virtual void setter(void *obj, wxAny &v) override
Definition: property.h:527
size_t BaseHash() const override
Return type-id of the Base class.
Definition: property.h:496
bool Writeable(INSPECTABLE *aObject) const override
Definition: property.h:506
virtual wxAny getter(const void *obj) const override
Set method.
Definition: property.h:539
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:479
std::unique_ptr< GETTER_BASE< Owner, T > > m_getter
Owner class type-id.
Definition: property.h:550
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:466
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:512
size_t OwnerHash() const override
Return type-id of the Owner class.
Definition: property.h:491
const size_t m_ownerHash
Base class type-id.
Definition: property.h:553
virtual void operator()(Owner *aOwner, T aValue)=0
virtual ~SETTER_BASE()
Definition: property.h:108
void operator()(Owner *aOwner, T aValue) override
Definition: property.h:123
FuncType m_func
Definition: property.h:129
SETTER(FuncType aFunc)
Definition: property.h:117
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:653
virtual size_t DerivedHash() const =0
TYPE_CAST()
Definition: property.h:665
size_t DerivedHash() const override
Definition: property.h:686
const void * operator()(const void *aPointer) const override
Definition: property.h:675
size_t BaseHash() const override
Definition: property.h:681
void * operator()(void *aPointer) const override
Definition: property.h:669
static bool empty(const wxTextEntryBase *aCtrl)
#define TYPE_HASH(x)
Definition: property.h:72
PROPERTY_DISPLAY
Common property types.
Definition: property.h:60
@ PT_DEGREE
Angle expressed in degrees.
Definition: property.h:65
@ PT_COORD
Coordinate expressed in distance units (mm/inch)
Definition: property.h:64
@ PT_RATIO
Definition: property.h:67
@ PT_DECIDEGREE
Angle expressed in decidegrees.
Definition: property.h:66
@ PT_AREA
Area expressed in distance units-squared (mm/inch)
Definition: property.h:63
@ PT_DEFAULT
Default property for a given type.
Definition: property.h:61
@ PT_SIZE
Size expressed in distance units (mm/inch)
Definition: property.h:62
@ PT_TIME
Time expressed in ps.
Definition: property.h:68
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