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{
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:
198 PROPERTY_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 ),
451 GetType( Base::*aGetter )(),
452 PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
454 PROPERTY( aName,
455 METHOD<Owner, T, Base>::Wrap( aSetter ),
456 METHOD<Owner, T, Base>::Wrap( aGetter ),
457 aDisplay, aCoordType )
458 {
459 }
460
461 template<typename SetType, typename GetType>
462 PROPERTY( const wxString& aName,
463 void ( Base::*aSetter )( SetType ),
464 GetType( Base::*aGetter )() const,
465 PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
467 PROPERTY( aName,
468 METHOD<Owner, T, Base>::Wrap( aSetter ),
469 METHOD<Owner, T, Base>::Wrap( aGetter ),
470 aDisplay, aCoordType )
471 {
472 }
473
474 size_t OwnerHash() const override
475 {
476 return m_ownerHash;
477 }
478
479 size_t BaseHash() const override
480 {
481 return m_baseHash;
482 }
483
484 size_t TypeHash() const override
485 {
486 return m_typeHash;
487 }
488
489 bool Writeable( INSPECTABLE* aObject ) const override
490 {
491 return m_setter && PROPERTY_BASE::Writeable( aObject );
492 }
493
494protected:
495 PROPERTY( const wxString& aName,
499 PROPERTY_BASE( aName, aDisplay, aCoordType ),
500 m_setter( s ),
501 m_getter( g ),
502 m_ownerHash( TYPE_HASH( Owner ) ),
503 m_baseHash( TYPE_HASH( Base ) ),
505 {
506 }
507
508 virtual ~PROPERTY() {}
509
510 virtual void setter( void* obj, wxAny& v ) override
511 {
512 wxCHECK( m_setter, /*void*/ );
513
514 if( !v.CheckType<T>() )
515 throw std::invalid_argument( "Invalid type requested" );
516
517 Owner* o = reinterpret_cast<Owner*>( obj );
518 BASE_TYPE value = wxANY_AS(v, BASE_TYPE);
519 (*m_setter)( o, value );
520 }
521
522 virtual wxAny getter( const void* obj ) const override
523 {
524 const Owner* o = reinterpret_cast<const Owner*>( obj );
525 wxAny res = (*m_getter)( o );
526 return res;
527 }
528
530 std::unique_ptr<SETTER_BASE<Owner, T>> m_setter;
531
533 std::unique_ptr<GETTER_BASE<Owner, T>> m_getter;
534
536 const size_t m_ownerHash;
537
539 const size_t m_baseHash;
540
542 const size_t m_typeHash;
543};
544
545
546template<typename Owner, typename T, typename Base = Owner>
547class PROPERTY_ENUM : public PROPERTY<Owner, T, Base>
548{
549public:
550 template<typename SetType, typename GetType>
551 PROPERTY_ENUM( const wxString& aName,
552 void ( Base::*aSetter )( SetType ),
553 GetType( Base::*aGetter )(),
554 PROPERTY_DISPLAY aDisplay = PT_DEFAULT ) :
555 PROPERTY<Owner, T, Base>( aName,
556 METHOD<Owner, T, Base>::Wrap( aSetter ),
557 METHOD<Owner, T, Base>::Wrap( aGetter ),
558 aDisplay )
559 {
560 if ( std::is_enum<T>::value )
561 {
562 m_choices = ENUM_MAP<T>::Instance().Choices();
563 wxASSERT_MSG( m_choices.GetCount() > 0, wxT( "No enum choices defined" ) );
564 }
565 }
566
567 template<typename SetType, typename GetType>
568 PROPERTY_ENUM( const wxString& aName,
569 void ( Base::*aSetter )( SetType ),
570 GetType( Base::*aGetter )() const,
571 PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
573 PROPERTY<Owner, T, Base>( aName,
574 METHOD<Owner, T, Base>::Wrap( aSetter ),
575 METHOD<Owner, T, Base>::Wrap( aGetter ),
576 aDisplay, aCoordType )
577 {
578 if ( std::is_enum<T>::value )
579 {
580 m_choices = ENUM_MAP<T>::Instance().Choices();
581 wxASSERT_MSG( m_choices.GetCount() > 0, wxT( "No enum choices defined" ) );
582 }
583 }
584
585 void setter( void* obj, wxAny& v ) override
586 {
587 wxCHECK( ( PROPERTY<Owner, T, Base>::m_setter ), /*void*/ );
588 Owner* o = reinterpret_cast<Owner*>( obj );
589
590 if( v.CheckType<T>() )
591 {
592 T value = wxANY_AS(v, T);
594 }
595 else if (v.CheckType<int>() )
596 {
597 int value = wxANY_AS(v, int);
598 (*PROPERTY<Owner, T, Base>::m_setter)( o, static_cast<T>( value ) );
599 }
600 else
601 {
602 throw std::invalid_argument( "Invalid type requested" );
603 }
604 }
605
606 wxAny getter( const void* obj ) const override
607 {
608 const Owner* o = reinterpret_cast<const Owner*>( obj );
609 wxAny res = static_cast<T>( (*PROPERTY<Owner, T, Base>::m_getter)( o ) );
610 return res;
611 }
612
613 const wxPGChoices& Choices() const override
614 {
615 return m_choices.GetCount() > 0 ? m_choices : ENUM_MAP<T>::Instance().Choices();
616 }
617
618 void SetChoices( const wxPGChoices& aChoices ) override
619 {
620 m_choices = aChoices;
621 }
622
623 bool HasChoices() const override
624 {
625 return Choices().GetCount() > 0;
626 }
627
628protected:
629 wxPGChoices m_choices;
630};
631
632
634{
635public:
636 virtual ~TYPE_CAST_BASE() {}
637 virtual void* operator()( void* aPointer ) const = 0;
638 virtual const void* operator()( const void* aPointer ) const = 0;
639 virtual size_t BaseHash() const = 0;
640 virtual size_t DerivedHash() const = 0;
641};
642
643
644template<typename Base, typename Derived>
646{
647public:
649 {
650 }
651
652 void* operator()( void* aPointer ) const override
653 {
654 Base* base = reinterpret_cast<Base*>( aPointer );
655 return static_cast<Derived*>( base );
656 }
657
658 const void* operator()( const void* aPointer ) const override
659 {
660 const Base* base = reinterpret_cast<const Base*>( aPointer );
661 return static_cast<const Derived*>( base );
662 }
663
664 size_t BaseHash() const override
665 {
666 return TYPE_HASH( Base );
667 }
668
669 size_t DerivedHash() const override
670 {
671 return TYPE_HASH( Derived );
672 }
673};
674
675
676template<typename T>
678{
679public:
681 {
682 static ENUM_MAP<T> inst;
683 return inst;
684 }
685
686 ENUM_MAP& Map( T aValue, const wxString& aName )
687 {
688 m_choices.Add( aName, static_cast<int>( aValue ) );
689 m_reverseMap[ aName ] = aValue;
690 return *this;
691 }
692
693 ENUM_MAP& Undefined( T aValue )
694 {
695 m_undefined = aValue;
696 return *this;
697 }
698
699 const wxString& ToString( T value ) const
700 {
701 static const wxString s_undef = "UNDEFINED";
702
703 int idx = m_choices.Index( static_cast<int>( value ) );
704
705 if( idx >= 0 && idx < (int) m_choices.GetCount() )
706 return m_choices.GetLabel( static_cast<int>( idx ) );
707 else
708 return s_undef;
709 }
710
711 bool IsValueDefined( T value ) const
712 {
713 int idx = m_choices.Index( static_cast<int>( value ) );
714
715 if( idx >= 0 && idx < (int) m_choices.GetCount() )
716 return true;
717
718 return false;
719 }
720
721 T ToEnum( const wxString value )
722 {
723 if( m_reverseMap.count( value ) )
724 return m_reverseMap[ value ];
725 else
726 return m_undefined;
727 }
728
729 wxPGChoices& Choices()
730 {
731 return m_choices;
732 }
733
734private:
735 wxPGChoices m_choices;
736 std::unordered_map<wxString, T> m_reverseMap;
737 T m_undefined; // Returned if the string is not recognized
738
740 {
741 }
742};
743
744
745// Helper macros to handle enum types
746#define DECLARE_ENUM_TO_WXANY( type ) \
747 template <> \
748 class wxAnyValueTypeImpl<type> : public wxAnyValueTypeImplBase<type> \
749 { \
750 WX_DECLARE_ANY_VALUE_TYPE( wxAnyValueTypeImpl<type> ) \
751 public: \
752 wxAnyValueTypeImpl() : wxAnyValueTypeImplBase<type>() {} \
753 virtual ~wxAnyValueTypeImpl() {} \
754 virtual bool ConvertValue( const wxAnyValueBuffer& src, wxAnyValueType* dstType, \
755 wxAnyValueBuffer& dst ) const override \
756 { \
757 type value = GetValue( src ); \
758 ENUM_MAP<type>& conv = ENUM_MAP<type>::Instance(); \
759 if( ! conv.IsValueDefined( value ) ) \
760 { \
761 return false; \
762 } \
763 if( dstType->CheckType<wxString>() ) \
764 { \
765 wxAnyValueTypeImpl<wxString>::SetValue( conv.ToString( value ), dst ); \
766 return true; \
767 } \
768 if( dstType->CheckType<int>() ) \
769 { \
770 wxAnyValueTypeImpl<int>::SetValue( static_cast<int>( value ), dst ); \
771 return true; \
772 } \
773 else \
774 { \
775 return false; \
776 } \
777 } \
778 };
779
780#define IMPLEMENT_ENUM_TO_WXANY( type ) WX_IMPLEMENT_ANY_VALUE_TYPE( wxAnyValueTypeImpl<type> )
781
782#define ENUM_TO_WXANY( type ) \
783 DECLARE_ENUM_TO_WXANY( type ) \
784 IMPLEMENT_ENUM_TO_WXANY( type )
785
787#define NO_SETTER( owner, type ) ( ( void ( owner::* )( type ) ) nullptr )
788
789/*
790#define DECLARE_PROPERTY(owner,type,name,getter,setter) \
791namespace anonymous {\
792static PROPERTY<owner,type> prop##_owner##_name_( "##name#", setter, getter );\
793};
794*/
795#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:721
ENUM_MAP & Map(T aValue, const wxString &aName)
Definition: property.h:686
std::unordered_map< wxString, T > m_reverseMap
Definition: property.h:736
T m_undefined
Definition: property.h:737
static ENUM_MAP< T > & Instance()
Definition: property.h:680
ENUM_MAP()
Definition: property.h:739
const wxString & ToString(T value) const
Definition: property.h:699
bool IsValueDefined(T value) const
Definition: property.h:711
ENUM_MAP & Undefined(T aValue)
Definition: property.h:693
wxPGChoices & Choices()
Definition: property.h:729
wxPGChoices m_choices
Definition: property.h:735
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: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: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:613
bool HasChoices() const override
Return true if this PROPERTY has a limited set of possible values.
Definition: property.h:623
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:568
void setter(void *obj, wxAny &v) override
Definition: property.h:585
PROPERTY_ENUM(const wxString &aName, void(Base::*aSetter)(SetType), GetType(Base::*aGetter)(), PROPERTY_DISPLAY aDisplay=PT_DEFAULT)
Definition: property.h:551
wxPGChoices m_choices
Definition: property.h:629
wxAny getter(const void *obj) const override
Set method.
Definition: property.h:606
void SetChoices(const wxPGChoices &aChoices) override
Set the possible values for for the property.
Definition: property.h:618
std::unique_ptr< SETTER_BASE< Owner, T > > m_setter
Get method.
Definition: property.h:530
const size_t m_baseHash
Property value type-id.
Definition: property.h:539
size_t TypeHash() const override
Return type-id of the property type.
Definition: property.h:484
typename std::decay< T >::type BASE_TYPE
Definition: property.h:446
const size_t m_typeHash
Definition: property.h:542
virtual ~PROPERTY()
Definition: property.h:508
virtual void setter(void *obj, wxAny &v) override
Definition: property.h:510
size_t BaseHash() const override
Return type-id of the Base class.
Definition: property.h:479
bool Writeable(INSPECTABLE *aObject) const override
Definition: property.h:489
virtual wxAny getter(const void *obj) const override
Set method.
Definition: property.h:522
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:462
std::unique_ptr< GETTER_BASE< Owner, T > > m_getter
Owner class type-id.
Definition: property.h:533
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:495
size_t OwnerHash() const override
Return type-id of the Owner class.
Definition: property.h:474
const size_t m_ownerHash
Base class type-id.
Definition: property.h:536
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:636
virtual size_t DerivedHash() const =0
TYPE_CAST()
Definition: property.h:648
size_t DerivedHash() const override
Definition: property.h:669
const void * operator()(const void *aPointer) const override
Definition: property.h:658
size_t BaseHash() const override
Definition: property.h:664
void * operator()(void *aPointer) const override
Definition: property.h:652
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