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