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