KiCad PCB EDA Suite
Loading...
Searching...
No Matches
inspectable.cpp
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 * @author Tomasz Wlostowski <[email protected]>
7 * @author Maciej Suminski <[email protected]>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 3
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#include <inspectable_impl.h>
24
25#include <wx/propgrid/property.h>
26
27
28bool INSPECTABLE::Set( PROPERTY_BASE* aProperty, wxAny& aValue, bool aNotify )
29{
31 void* object = propMgr.TypeCast( this, TYPE_HASH( *this ), aProperty->OwnerHash() );
32
33 if( object )
34 {
35 aProperty->setter( object, aValue );
36
37 if( aNotify )
38 propMgr.PropertyChanged( this, aProperty );
39 }
40
41 return object != nullptr;
42}
43
44
45bool INSPECTABLE::Set( PROPERTY_BASE* aProperty, wxVariant aValue, bool aNotify )
46{
48 void* object = propMgr.TypeCast( this, TYPE_HASH( *this ), aProperty->OwnerHash() );
49
50 if( object )
51 {
52 wxPGChoices choices = aProperty->GetChoices( this );
53
54 if( choices.GetCount() )
55 {
56 if( aProperty->TypeHash() == TYPE_HASH( int ) )
57 aProperty->set<int>( object, aValue.GetInteger() );
58 else
59 aProperty->set<wxString>( object, choices.GetLabel( aValue.GetInteger() ) );
60 }
61 else
62 {
63 aProperty->set<wxVariant>( object, aValue );
64 }
65
66 if( aNotify )
67 propMgr.PropertyChanged( this, aProperty );
68 }
69
70 return object != nullptr;
71}
72
73
74wxAny INSPECTABLE::Get( PROPERTY_BASE* aProperty ) const
75{
77 const void* object = propMgr.TypeCast( this, TYPE_HASH( *this ), aProperty->OwnerHash() );
78 return object ? aProperty->getter( object ) : wxAny();
79}
wxAny Get(PROPERTY_BASE *aProperty) const
bool Set(PROPERTY_BASE *aProperty, wxAny &aValue, bool aNotify=true)
virtual size_t TypeHash() const =0
Return type-id of the property type.
virtual wxAny getter(const void *aObject) const =0
wxPGChoices GetChoices(INSPECTABLE *aObject) const
Definition property.h:268
virtual void setter(void *aObject, wxAny &aValue)=0
void set(void *aObject, T aValue)
Definition property.h:367
virtual size_t OwnerHash() const =0
Return type-id of the Owner class.
Provide class metadata.Helper macro to map type hashes to names.
void PropertyChanged(INSPECTABLE *aObject, PROPERTY_BASE *aProperty)
Callback to alert the notification system that a property has changed.
static PROPERTY_MANAGER & Instance()
const void * TypeCast(const void *aSource, TYPE_ID aBase, TYPE_ID aTarget) const
Cast a type to another type.
#define TYPE_HASH(x)
Definition property.h:74