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 false;
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 virtual bool Writeable( INSPECTABLE* aObject ) const
265 {
266 return m_writeableFunc( aObject );
267 }
268
269 PROPERTY_BASE& SetWriteableFunc( std::function<bool(INSPECTABLE*)> aFunc )
270 {
271 m_writeableFunc = std::move( aFunc );
272 return *this;
273 }
274
278 virtual size_t OwnerHash() const = 0;
279
283 virtual size_t BaseHash() const = 0;
284
288 virtual size_t TypeHash() const = 0;
289
290 PROPERTY_DISPLAY Display() const { return m_display; }
291 PROPERTY_BASE& SetDisplay( PROPERTY_DISPLAY aDisplay ) { m_display = aDisplay; return *this; }
292
293 ORIGIN_TRANSFORMS::COORD_TYPES_T CoordType() const { return m_coordType; }
295 {
296 m_coordType = aType;
297 return *this;
298 }
299
300 bool IsHiddenFromPropertiesManager() const { return m_hideFromPropertiesManager; }
302 {
303 m_hideFromPropertiesManager = aHide;
304 return *this;
305 }
306
307 bool IsHiddenFromRulesEditor() const { return m_hideFromRulesEditor; }
309 {
310 m_hideFromRulesEditor = aHide;
311 return *this;
312 }
313
314 bool IsHiddenFromLibraryEditors() const { return m_hideFromLibraryEditors; }
316 {
317 m_hideFromLibraryEditors = aIsHidden;
318 return *this;
319 }
320
321 bool IsHiddenFromDesignEditors() const { return m_hideFromDesignEditors; }
323 {
324 m_hideFromDesignEditors = aIsHidden;
325 return *this;
326 }
327
328 wxString Group() const { return m_group; }
329 PROPERTY_BASE& SetGroup( const wxString& aGroup ) { m_group = aGroup; return *this; }
330
332 {
333 m_validator = aValidator;
334 return *this;
335 }
336
337 VALIDATOR_RESULT Validate( const wxAny&& aValue, EDA_ITEM* aItem )
338 {
339 return m_validator( std::move( aValue ), aItem );
340 }
341
342 static VALIDATOR_RESULT NullValidator( const wxAny&& aValue, EDA_ITEM* aItem )
343 {
344 return std::nullopt;
345 }
346
347protected:
348 template<typename T>
349 void set( void* aObject, T aValue )
350 {
351 wxAny a = aValue;
352
353 // wxVariant will be type "long" even if the property is supposed to be
354 // unsigned. Let's trust that we're coming from the property grid where
355 // we used a UInt editor.
356 if( std::is_same<T, wxVariant>::value )
357 {
358 wxVariant var = static_cast<wxVariant>( aValue );
359 wxAny pv = getter( aObject );
360
361 if( pv.CheckType<unsigned>() )
362 {
363 a = static_cast<unsigned>( var.GetLong() );
364 }
365 else if( pv.CheckType<std::optional<int>>() )
366 {
367 auto* data = static_cast<STD_OPTIONAL_INT_VARIANT_DATA*>( var.GetData() );
368 a = data->Value();
369 }
370 else if( pv.CheckType<std::optional<double>>() )
371 {
372 auto* data = static_cast<STD_OPTIONAL_DOUBLE_VARIANT_DATA*>( var.GetData() );
373 a = data->Value();
374 }
375 else if( pv.CheckType<EDA_ANGLE>() )
376 {
377 EDA_ANGLE_VARIANT_DATA* ad = static_cast<EDA_ANGLE_VARIANT_DATA*>( var.GetData() );
378 a = ad->Angle();
379 }
380 else if( pv.CheckType<KIGFX::COLOR4D>() )
381 {
382 COLOR4D_VARIANT_DATA* cd = static_cast<COLOR4D_VARIANT_DATA*>( var.GetData() );
383 a = cd->Color();
384 }
385 }
386
387 setter( aObject, a );
388 }
389
390 template<typename T>
391 T get( const void* aObject ) const
392 {
393 wxAny a = getter( aObject );
394
395 // We don't currently have a bool type, so change it to a numeric
396 if( a.CheckType<bool>() )
397 a = a.RawAs<bool>() ? 1 : 0;
398
399 if ( !( std::is_enum<T>::value && a.CheckType<int>() ) && !a.CheckType<T>() )
400 throw std::invalid_argument( "Invalid requested type" );
401
402 return wxANY_AS( a, T );
403 }
404
405private:
406 virtual void setter( void* aObject, wxAny& aValue ) = 0;
407 virtual wxAny getter( const void* aObject ) const = 0;
408
409private:
415 const wxString m_name;
416
419
422
423 bool m_hideFromPropertiesManager; // Do not show in Properties Manager
424 bool m_hideFromLibraryEditors; // Do not show in Properties Manager of symbol or
425 // footprint editors
426 bool m_hideFromDesignEditors; // Do not show in Properties Manager of schematic or
427 // board editors
428 bool m_hideFromRulesEditor; // Do not show in Custom Rules editor autocomplete
429
431 wxString m_group;
432
433 std::function<bool(INSPECTABLE*)> m_availFunc;
434
435 std::function<bool(INSPECTABLE*)> m_writeableFunc;
436
438
439 friend class INSPECTABLE;
440};
441
442
443template<typename Owner, typename T, typename Base = Owner>
445{
446public:
447 using BASE_TYPE = typename std::decay<T>::type;
448
449 template<typename SetType, typename GetType>
450 PROPERTY( const wxString& aName,
451 void ( Base::*aSetter )( SetType ),
452 GetType( Base::*aGetter )(),
453 PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
455 PROPERTY( aName,
456 METHOD<Owner, T, Base>::Wrap( aSetter ),
457 METHOD<Owner, T, Base>::Wrap( aGetter ),
458 aDisplay, aCoordType )
459 {
460 }
461
462 template<typename SetType, typename GetType>
463 PROPERTY( const wxString& aName,
464 void ( Base::*aSetter )( SetType ),
465 GetType( Base::*aGetter )() const,
466 PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
468 PROPERTY( aName,
469 METHOD<Owner, T, Base>::Wrap( aSetter ),
470 METHOD<Owner, T, Base>::Wrap( aGetter ),
471 aDisplay, aCoordType )
472 {
473 }
474
475 size_t OwnerHash() const override
476 {
477 return m_ownerHash;
478 }
479
480 size_t BaseHash() const override
481 {
482 return m_baseHash;
483 }
484
485 size_t TypeHash() const override
486 {
487 return m_typeHash;
488 }
489
490 bool Writeable( INSPECTABLE* aObject ) const override
491 {
492 return m_setter && PROPERTY_BASE::Writeable( aObject );
493 }
494
495protected:
496 PROPERTY( const wxString& aName,
500 PROPERTY_BASE( aName, aDisplay, aCoordType ),
501 m_setter( s ),
502 m_getter( g ),
503 m_ownerHash( TYPE_HASH( Owner ) ),
504 m_baseHash( TYPE_HASH( Base ) ),
506 {
507 }
508
509 virtual ~PROPERTY() {}
510
511 virtual void setter( void* obj, wxAny& v ) override
512 {
513 wxCHECK( m_setter, /*void*/ );
514
515 if( !v.CheckType<T>() )
516 throw std::invalid_argument( "Invalid type requested" );
517
518 Owner* o = reinterpret_cast<Owner*>( obj );
519 BASE_TYPE value = wxANY_AS(v, BASE_TYPE);
520 (*m_setter)( o, value );
521 }
522
523 virtual wxAny getter( const void* obj ) const override
524 {
525 const Owner* o = reinterpret_cast<const Owner*>( obj );
526 wxAny res = (*m_getter)( o );
527 return res;
528 }
529
531 std::unique_ptr<SETTER_BASE<Owner, T>> m_setter;
532
534 std::unique_ptr<GETTER_BASE<Owner, T>> m_getter;
535
537 const size_t m_ownerHash;
538
540 const size_t m_baseHash;
541
543 const size_t m_typeHash;
544};
545
546
547template<typename Owner, typename T, typename Base = Owner>
548class PROPERTY_ENUM : public PROPERTY<Owner, T, Base>
549{
550public:
551 template<typename SetType, typename GetType>
552 PROPERTY_ENUM( const wxString& aName,
553 void ( Base::*aSetter )( SetType ),
554 GetType( Base::*aGetter )(),
555 PROPERTY_DISPLAY aDisplay = PT_DEFAULT ) :
556 PROPERTY<Owner, T, Base>( aName,
557 METHOD<Owner, T, Base>::Wrap( aSetter ),
558 METHOD<Owner, T, Base>::Wrap( aGetter ),
559 aDisplay )
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 template<typename SetType, typename GetType>
569 PROPERTY_ENUM( const wxString& aName,
570 void ( Base::*aSetter )( SetType ),
571 GetType( Base::*aGetter )() const,
572 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, aCoordType )
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 void setter( void* obj, wxAny& v ) override
587 {
588 wxCHECK( ( PROPERTY<Owner, T, Base>::m_setter ), /*void*/ );
589 Owner* o = reinterpret_cast<Owner*>( obj );
590
591 if( v.CheckType<T>() )
592 {
593 T value = wxANY_AS(v, T);
595 }
596 else if (v.CheckType<int>() )
597 {
598 int value = wxANY_AS(v, int);
599 (*PROPERTY<Owner, T, Base>::m_setter)( o, static_cast<T>( value ) );
600 }
601 else
602 {
603 throw std::invalid_argument( "Invalid type requested" );
604 }
605 }
606
607 wxAny getter( const void* obj ) const override
608 {
609 const Owner* o = reinterpret_cast<const Owner*>( obj );
610 wxAny res = static_cast<T>( (*PROPERTY<Owner, T, Base>::m_getter)( o ) );
611 return res;
612 }
613
614 const wxPGChoices& Choices() const override
615 {
616 return m_choices.GetCount() > 0 ? m_choices : ENUM_MAP<T>::Instance().Choices();
617 }
618
619 void SetChoices( const wxPGChoices& aChoices ) override
620 {
621 m_choices = aChoices;
622 }
623
624 bool HasChoices() const override
625 {
626 return Choices().GetCount() > 0;
627 }
628
629protected:
630 wxPGChoices m_choices;
631};
632
633
635{
636public:
637 virtual ~TYPE_CAST_BASE() {}
638 virtual void* operator()( void* aPointer ) const = 0;
639 virtual const void* operator()( const void* aPointer ) const = 0;
640 virtual size_t BaseHash() const = 0;
641 virtual size_t DerivedHash() const = 0;
642};
643
644
645template<typename Base, typename Derived>
647{
648public:
650 {
651 }
652
653 void* operator()( void* aPointer ) const override
654 {
655 Base* base = reinterpret_cast<Base*>( aPointer );
656 return static_cast<Derived*>( base );
657 }
658
659 const void* operator()( const void* aPointer ) const override
660 {
661 const Base* base = reinterpret_cast<const Base*>( aPointer );
662 return static_cast<const Derived*>( base );
663 }
664
665 size_t BaseHash() const override
666 {
667 return TYPE_HASH( Base );
668 }
669
670 size_t DerivedHash() const override
671 {
672 return TYPE_HASH( Derived );
673 }
674};
675
676
677template<typename T>
679{
680public:
682 {
683 static ENUM_MAP<T> inst;
684 return inst;
685 }
686
687 ENUM_MAP& Map( T aValue, const wxString& aName )
688 {
689 m_choices.Add( aName, static_cast<int>( aValue ) );
690 m_reverseMap[ aName ] = aValue;
691 return *this;
692 }
693
695 {
696 m_undefined = aValue;
697 return *this;
698 }
699
700 const wxString& ToString( T value ) const
701 {
702 static const wxString s_undef = "UNDEFINED";
703
704 int idx = m_choices.Index( static_cast<int>( value ) );
705
706 if( idx >= 0 && idx < (int) m_choices.GetCount() )
707 return m_choices.GetLabel( static_cast<int>( idx ) );
708 else
709 return s_undef;
710 }
711
712 bool IsValueDefined( T value ) const
713 {
714 int idx = m_choices.Index( static_cast<int>( value ) );
715
716 if( idx >= 0 && idx < (int) m_choices.GetCount() )
717 return true;
718
719 return false;
720 }
721
722 T ToEnum( const wxString value )
723 {
724 if( m_reverseMap.count( value ) )
725 return m_reverseMap[ value ];
726 else
727 return m_undefined;
728 }
729
730 wxPGChoices& Choices()
731 {
732 return m_choices;
733 }
734
735private:
736 wxPGChoices m_choices;
737 std::unordered_map<wxString, T> m_reverseMap;
738 T m_undefined; // Returned if the string is not recognized
739
741 {
742 }
743};
744
745
746// Helper macros to handle enum types
747#define DECLARE_ENUM_TO_WXANY( type ) \
748 template <> \
749 class wxAnyValueTypeImpl<type> : public wxAnyValueTypeImplBase<type> \
750 { \
751 WX_DECLARE_ANY_VALUE_TYPE( wxAnyValueTypeImpl<type> ) \
752 public: \
753 wxAnyValueTypeImpl() : wxAnyValueTypeImplBase<type>() {} \
754 virtual ~wxAnyValueTypeImpl() {} \
755 virtual bool ConvertValue( const wxAnyValueBuffer& src, wxAnyValueType* dstType, \
756 wxAnyValueBuffer& dst ) const override \
757 { \
758 type value = GetValue( src ); \
759 ENUM_MAP<type>& conv = ENUM_MAP<type>::Instance(); \
760 if( ! conv.IsValueDefined( value ) ) \
761 { \
762 return false; \
763 } \
764 if( dstType->CheckType<wxString>() ) \
765 { \
766 wxAnyValueTypeImpl<wxString>::SetValue( conv.ToString( value ), dst ); \
767 return true; \
768 } \
769 if( dstType->CheckType<int>() ) \
770 { \
771 wxAnyValueTypeImpl<int>::SetValue( static_cast<int>( value ), dst ); \
772 return true; \
773 } \
774 else \
775 { \
776 return false; \
777 } \
778 } \
779 };
780
781#define IMPLEMENT_ENUM_TO_WXANY( type ) WX_IMPLEMENT_ANY_VALUE_TYPE( wxAnyValueTypeImpl<type> )
782
783#define ENUM_TO_WXANY( type ) \
784 DECLARE_ENUM_TO_WXANY( type ) \
785 IMPLEMENT_ENUM_TO_WXANY( type )
786
788#define NO_SETTER( owner, type ) ( ( void ( owner::* )( type ) ) nullptr )
789
790/*
791#define DECLARE_PROPERTY(owner,type,name,getter,setter) \
792namespace anonymous {\
793static PROPERTY<owner,type> prop##_owner##_name_( "##name#", setter, getter );\
794};
795*/
796#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:97
T ToEnum(const wxString value)
Definition: property.h:722
ENUM_MAP & Map(T aValue, const wxString &aName)
Definition: property.h:687
std::unordered_map< wxString, T > m_reverseMap
Definition: property.h:737
T m_undefined
Definition: property.h:738
static ENUM_MAP< T > & Instance()
Definition: property.h:681
ENUM_MAP()
Definition: property.h:740
const wxString & ToString(T value) const
Definition: property.h:700
bool IsValueDefined(T value) const
Definition: property.h:712
ENUM_MAP & Undefined(T aValue)
Definition: property.h:694
wxPGChoices & Choices()
Definition: property.h:730
wxPGChoices m_choices
Definition: property.h:736
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.
bool IsHiddenFromPropertiesManager() const
Definition: property.h:300
virtual size_t TypeHash() const =0
Return type-id of the property type.
bool m_hideFromLibraryEditors
Definition: property.h:424
const wxString m_name
Permanent identifier for this property.
Definition: property.h:415
VALIDATOR_RESULT Validate(const wxAny &&aValue, EDA_ITEM *aItem)
Definition: property.h:337
std::function< bool(INSPECTABLE *)> m_writeableFunc
Eval to determine if prop is read-only.
Definition: property.h:435
std::function< bool(INSPECTABLE *)> m_availFunc
Eval to determine if prop is available.
Definition: property.h:433
PROPERTY_VALIDATOR_FN m_validator
Definition: property.h:437
bool IsHiddenFromDesignEditors() const
Definition: property.h:321
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:291
PROPERTY_DISPLAY Display() const
Definition: property.h:290
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:342
wxString Group() const
Definition: property.h:328
PROPERTY_BASE & SetWriteableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Definition: property.h:269
PROPERTY_BASE & SetGroup(const wxString &aGroup)
Definition: property.h:329
ORIGIN_TRANSFORMS::COORD_TYPES_T CoordType() const
Definition: property.h:293
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:294
PROPERTY_DISPLAY m_display
The display style controls how properties are edited in the properties manager GUI.
Definition: property.h:418
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:421
virtual bool Writeable(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:431
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:331
bool m_hideFromPropertiesManager
Definition: property.h:423
bool m_hideFromDesignEditors
Definition: property.h:426
PROPERTY_BASE & SetIsHiddenFromDesignEditors(bool aIsHidden=true)
Definition: property.h:322
PROPERTY_BASE & SetIsHiddenFromPropertiesManager(bool aHide=true)
Definition: property.h:301
bool m_hideFromRulesEditor
Definition: property.h:428
void set(void *aObject, T aValue)
Definition: property.h:349
const wxString & Name() const
Definition: property.h:218
bool IsHiddenFromRulesEditor() const
Definition: property.h:307
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:308
bool IsHiddenFromLibraryEditors() const
Definition: property.h:314
T get(const void *aObject) const
Definition: property.h:391
PROPERTY_BASE & SetIsHiddenFromLibraryEditors(bool aIsHidden=true)
Definition: property.h:315
const wxPGChoices & Choices() const override
Return a limited set of possible values (e.g.
Definition: property.h:614
bool HasChoices() const override
Return true if this PROPERTY has a limited set of possible values.
Definition: property.h:624
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:569
void setter(void *obj, wxAny &v) override
Definition: property.h:586
PROPERTY_ENUM(const wxString &aName, void(Base::*aSetter)(SetType), GetType(Base::*aGetter)(), PROPERTY_DISPLAY aDisplay=PT_DEFAULT)
Definition: property.h:552
wxPGChoices m_choices
Definition: property.h:630
wxAny getter(const void *obj) const override
Set method.
Definition: property.h:607
void SetChoices(const wxPGChoices &aChoices) override
Set the possible values for for the property.
Definition: property.h:619
std::unique_ptr< SETTER_BASE< Owner, T > > m_setter
Get method.
Definition: property.h:531
const size_t m_baseHash
Property value type-id.
Definition: property.h:540
size_t TypeHash() const override
Return type-id of the property type.
Definition: property.h:485
typename std::decay< T >::type BASE_TYPE
Definition: property.h:447
const size_t m_typeHash
Definition: property.h:543
virtual ~PROPERTY()
Definition: property.h:509
virtual void setter(void *obj, wxAny &v) override
Definition: property.h:511
size_t BaseHash() const override
Return type-id of the Base class.
Definition: property.h:480
bool Writeable(INSPECTABLE *aObject) const override
Definition: property.h:490
virtual wxAny getter(const void *obj) const override
Set method.
Definition: property.h:523
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:463
std::unique_ptr< GETTER_BASE< Owner, T > > m_getter
Owner class type-id.
Definition: property.h:534
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:450
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:496
size_t OwnerHash() const override
Return type-id of the Owner class.
Definition: property.h:475
const size_t m_ownerHash
Base class type-id.
Definition: property.h:537
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:637
virtual size_t DerivedHash() const =0
TYPE_CAST()
Definition: property.h:649
size_t DerivedHash() const override
Definition: property.h:670
const void * operator()(const void *aPointer) const override
Definition: property.h:659
size_t BaseHash() const override
Definition: property.h:665
void * operator()(void *aPointer) const override
Definition: property.h:653
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