KiCad PCB EDA Suite
Loading...
Searching...
No Matches
PROPERTY_MANAGER Class Reference

Provide class metadata.Helper macro to map type hashes to names. More...

#include <property_mgr.h>

Classes

struct  CLASS_DESC
 Returns metadata for a specific type. More...
 
struct  CLASS_INFO
 

Public Types

typedef std::vector< CLASS_INFOCLASSES_INFO
 

Public Member Functions

void RegisterType (TYPE_ID aType, const wxString &aName)
 Associate a name with a type. More...
 
const wxString & ResolveType (TYPE_ID aType) const
 Return name of a type. More...
 
PROPERTY_BASEGetProperty (TYPE_ID aType, const wxString &aProperty) const
 Return a property for a specific type. More...
 
const PROPERTY_LISTGetProperties (TYPE_ID aType) const
 Return all properties for a specific type. More...
 
const PROPERTY_DISPLAY_ORDERGetDisplayOrder (TYPE_ID aType) const
 
const std::vector< wxString > & GetGroupDisplayOrder (TYPE_ID aType) const
 
const void * TypeCast (const void *aSource, TYPE_ID aBase, TYPE_ID aTarget) const
 Cast a type to another type. More...
 
void * TypeCast (void *aSource, TYPE_ID aBase, TYPE_ID aTarget) const
 
PROPERTY_BASEAddProperty (PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
 Register a property. More...
 
PROPERTY_BASEReplaceProperty (size_t aBase, const wxString &aName, PROPERTY_BASE *aNew, const wxString &aGroup=wxEmptyString)
 Replace an existing property for a specific type. More...
 
void AddTypeCast (TYPE_CAST_BASE *aCast)
 Register a type converter. More...
 
void InheritsAfter (TYPE_ID aDerived, TYPE_ID aBase)
 Declare an inheritance relationship between types. More...
 
void Mask (TYPE_ID aDerived, TYPE_ID aBase, const wxString &aName)
 Sets a base class property as masked in a derived class. More...
 
void OverrideAvailability (TYPE_ID aDerived, TYPE_ID aBase, const wxString &aName, std::function< bool(INSPECTABLE *)> aFunc)
 Sets an override availability functor for a base class property of a given derived class. More...
 
bool IsAvailableFor (TYPE_ID aItemClass, PROPERTY_BASE *aProp, INSPECTABLE *aItem)
 Checks overriden availability and original availability of a property, returns false if the property is unavailable in either case. More...
 
bool IsOfType (TYPE_ID aDerived, TYPE_ID aBase) const
 Return true if aDerived is inherited from aBase. More...
 
EDA_UNITS GetUnits () const
 
void SetUnits (EDA_UNITS aUnits)
 
ORIGIN_TRANSFORMSGetTransforms () const
 
void SetTransforms (ORIGIN_TRANSFORMS *aTransforms)
 
void Rebuild ()
 Rebuild the list of all registered properties. More...
 
CLASSES_INFO GetAllClasses ()
 
std::vector< TYPE_IDGetMatchingClasses (PROPERTY_BASE *aProperty)
 

Static Public Member Functions

static PROPERTY_MANAGERInstance ()
 

Private Member Functions

 PROPERTY_MANAGER ()
 Structure holding type meta-data. More...
 
CLASS_DESCgetClass (TYPE_ID aTypeId)
 

Private Attributes

std::unordered_map< TYPE_ID, wxString > m_classNames
 Map of all available types. More...
 
std::unordered_map< TYPE_ID, CLASS_DESCm_classes
 
bool m_dirty
 Flag indicating that the list of properties needs to be rebuild (RebuildProperties()) More...
 
EDA_UNITS m_units
 
ORIGIN_TRANSFORMSm_originTransforms
 

Detailed Description

Provide class metadata.Helper macro to map type hashes to names.

Each class handled by PROPERTY_MANAGER needs to be described using AddProperty(), AddTypeCast() and InheritsAfter() methods.

Enum types use a dedicated property type (PROPERTY_ENUM), define its possible values with ENUM_MAP class, then describe the type using macros:

  • DECLARE_ENUM_TO_WXANY (in header files)
  • IMPLEMENT_ENUM_TO_WXANY (in source files)
  • ENUM_TO_WXANY (most often used; combines DECLARE and IMPLEMENT macros, if there is no need to share the description using header files)

Once all classes are described, the property list must be build using Rebuild() method.

Definition at line 73 of file property_mgr.h.

Member Typedef Documentation

◆ CLASSES_INFO

Definition at line 240 of file property_mgr.h.

Constructor & Destructor Documentation

◆ PROPERTY_MANAGER()

PROPERTY_MANAGER::PROPERTY_MANAGER ( )
inlineprivate

Structure holding type meta-data.

Definition at line 247 of file property_mgr.h.

Member Function Documentation

◆ AddProperty()

PROPERTY_BASE & PROPERTY_MANAGER::AddProperty ( PROPERTY_BASE aProperty,
const wxString &  aGroup = wxEmptyString 
)

Register a property.

Properties for a given item will be shown in the order they are added. If a group name is supplied, the group will be created if it does not yet exists. Groups will likewise be shown in the order they are added (so, groups first added by a base class will appear before those of a child class).

Parameters
aPropertyis the property to register.
aGroupis an optional grouping key for the property

Definition at line 133 of file property_mgr.cpp.

References getClass(), m_dirty, PROPERTY_MANAGER::CLASS_DESC::m_groupDisplayOrder, PROPERTY_MANAGER::CLASS_DESC::m_groups, PROPERTY_MANAGER::CLASS_DESC::m_ownDisplayOrder, PROPERTY_MANAGER::CLASS_DESC::m_ownProperties, name, PROPERTY_BASE::Name(), PROPERTY_BASE::OwnerHash(), and PROPERTY_BASE::SetGroup().

Referenced by ALIGNED_DIMENSION_DESC::ALIGNED_DIMENSION_DESC(), BOARD_CONNECTED_ITEM_DESC::BOARD_CONNECTED_ITEM_DESC(), BOARD_ITEM_DESC::BOARD_ITEM_DESC(), CLASS_A_DESC::CLASS_A_DESC(), CLASS_B_DESC::CLASS_B_DESC(), CLASS_C_DESC::CLASS_C_DESC(), CLASS_D_DESC::CLASS_D_DESC(), DIMENSION_DESC::DIMENSION_DESC(), EDA_ITEM_DESC::EDA_ITEM_DESC(), EDA_SHAPE_DESC::EDA_SHAPE_DESC(), EDA_TEXT_DESC::EDA_TEXT_DESC(), FOOTPRINT_DESC::FOOTPRINT_DESC(), LEADER_DIMENSION_DESC::LEADER_DIMENSION_DESC(), PAD_DESC::PAD_DESC(), PCB_BITMAP_DESC::PCB_BITMAP_DESC(), PCB_TARGET_DESC::PCB_TARGET_DESC(), PCB_TEXT_DESC::PCB_TEXT_DESC(), RADIAL_DIMENSION_DESC::RADIAL_DIMENSION_DESC(), ReplaceProperty(), TRACK_VIA_DESC::TRACK_VIA_DESC(), and ZONE_DESC::ZONE_DESC().

◆ AddTypeCast()

◆ GetAllClasses()

PROPERTY_MANAGER::CLASSES_INFO PROPERTY_MANAGER::GetAllClasses ( )

◆ getClass()

PROPERTY_MANAGER::CLASS_DESC & PROPERTY_MANAGER::getClass ( TYPE_ID  aTypeId)
private

◆ GetDisplayOrder()

const PROPERTY_DISPLAY_ORDER & PROPERTY_MANAGER::GetDisplayOrder ( TYPE_ID  aType) const

Definition at line 83 of file property_mgr.cpp.

References empty(), m_classes, m_dirty, and Rebuild().

Referenced by PROPERTIES_PANEL::rebuildProperties().

◆ GetGroupDisplayOrder()

const std::vector< wxString > & PROPERTY_MANAGER::GetGroupDisplayOrder ( TYPE_ID  aType) const

Definition at line 98 of file property_mgr.cpp.

References empty(), m_classes, m_dirty, and Rebuild().

Referenced by PROPERTIES_PANEL::rebuildProperties().

◆ GetMatchingClasses()

std::vector< TYPE_ID > PROPERTY_MANAGER::GetMatchingClasses ( PROPERTY_BASE aProperty)

Definition at line 357 of file property_mgr.cpp.

◆ GetProperties()

const PROPERTY_LIST & PROPERTY_MANAGER::GetProperties ( TYPE_ID  aType) const

Return all properties for a specific type.

Parameters
aTypeis the type identifier (obtained using TYPE_HASH()).
Returns
Vector storing all properties of the requested type.

Definition at line 68 of file property_mgr.cpp.

References empty(), m_classes, m_dirty, and Rebuild().

Referenced by PANEL_SETUP_RULES::onScintillaCharAdded(), and PROPERTIES_PANEL::rebuildProperties().

◆ GetProperty()

PROPERTY_BASE * PROPERTY_MANAGER::GetProperty ( TYPE_ID  aType,
const wxString &  aProperty 
) const

Return a property for a specific type.

Parameters
aTypeis the type identifier (obtained using TYPE_HASH()).
aPropertyis the property name used during class registration.
Returns
Requested property or null pointer if requested property does not exist.

Definition at line 46 of file property_mgr.cpp.

References PROPERTY_MANAGER::CLASS_DESC::m_allProperties, m_classes, m_dirty, PROPERTY_BASE::Name(), and Rebuild().

Referenced by PCB_EXPR_UCODE::CreateVarRef(), INSPECTABLE::Get(), PCB_PROPERTIES_PANEL::getPropertyFromEvent(), PROPERTIES_PANEL::rebuildProperties(), INSPECTABLE::Set(), and PCB_PROPERTIES_PANEL::updateLists().

◆ GetTransforms()

ORIGIN_TRANSFORMS * PROPERTY_MANAGER::GetTransforms ( ) const
inline

Definition at line 224 of file property_mgr.h.

References m_originTransforms.

Referenced by PGPROPERTY_DISTANCE::DistanceToString().

◆ GetUnits()

EDA_UNITS PROPERTY_MANAGER::GetUnits ( ) const
inline

Definition at line 214 of file property_mgr.h.

References m_units.

◆ InheritsAfter()

◆ Instance()

◆ IsAvailableFor()

bool PROPERTY_MANAGER::IsAvailableFor ( TYPE_ID  aItemClass,
PROPERTY_BASE aProp,
INSPECTABLE aItem 
)

Checks overriden availability and original availability of a property, returns false if the property is unavailable in either case.

TODO: This isn't the cleanest API, consider how to merge with PROPERTY_BASE::Available

Definition at line 209 of file property_mgr.cpp.

References PROPERTY_BASE::Available(), PROPERTY_BASE::BaseHash(), getClass(), PROPERTY_MANAGER::CLASS_DESC::m_availabilityOverrides, and PROPERTY_BASE::Name().

Referenced by PROPERTIES_PANEL::extractValueAndWritability(), and PROPERTIES_PANEL::rebuildProperties().

◆ IsOfType()

bool PROPERTY_MANAGER::IsOfType ( TYPE_ID  aDerived,
TYPE_ID  aBase 
) const

Return true if aDerived is inherited from aBase.

Definition at line 227 of file property_mgr.cpp.

References IsOfType(), and m_classes.

Referenced by PCB_EXPR_UCODE::CreateVarRef(), IsOfType(), and TypeCast().

◆ Mask()

void PROPERTY_MANAGER::Mask ( TYPE_ID  aDerived,
TYPE_ID  aBase,
const wxString &  aName 
)

Sets a base class property as masked in a derived class.

Masked properties are hidden from the list of editable properties for this class.

Parameters
aDerivedis the type to apply the mask for.
aBaseis the type that aName belongs to.
aNameis the name of a property on the base class.

Definition at line 187 of file property_mgr.cpp.

References getClass(), m_dirty, and PROPERTY_MANAGER::CLASS_DESC::m_maskedBaseProperties.

Referenced by PAD_DESC::PAD_DESC(), PCB_TEXTBOX_DESC::PCB_TEXTBOX_DESC(), and TRACK_VIA_DESC::TRACK_VIA_DESC().

◆ OverrideAvailability()

void PROPERTY_MANAGER::OverrideAvailability ( TYPE_ID  aDerived,
TYPE_ID  aBase,
const wxString &  aName,
std::function< bool(INSPECTABLE *)>  aFunc 
)

Sets an override availability functor for a base class property of a given derived class.

Parameters
aDerivedis the type to apply the mask for.
aBaseis the type that aName belongs to.
aNameis the name of a property on the base class.
aFuncis the new availability functor to apply.

Definition at line 197 of file property_mgr.cpp.

References getClass(), PROPERTY_MANAGER::CLASS_DESC::m_availabilityOverrides, and m_dirty.

Referenced by ALIGNED_DIMENSION_DESC::ALIGNED_DIMENSION_DESC(), CENTER_DIMENSION_DESC::CENTER_DIMENSION_DESC(), LEADER_DIMENSION_DESC::LEADER_DIMENSION_DESC(), ORTHOGONAL_DIMENSION_DESC::ORTHOGONAL_DIMENSION_DESC(), PAD_DESC::PAD_DESC(), PCB_MARKER_DESC::PCB_MARKER_DESC(), PCB_SHAPE_DESC::PCB_SHAPE_DESC(), PCB_TEXT_DESC::PCB_TEXT_DESC(), RADIAL_DIMENSION_DESC::RADIAL_DIMENSION_DESC(), and ZONE_DESC::ZONE_DESC().

◆ Rebuild()

void PROPERTY_MANAGER::Rebuild ( )

Rebuild the list of all registered properties.

Needs to be called once before GetProperty()/GetProperties() are used.

Definition at line 246 of file property_mgr.cpp.

References m_classes, and m_dirty.

Referenced by BOOST_AUTO_TEST_CASE(), GetDisplayOrder(), GetGroupDisplayOrder(), GetProperties(), GetProperty(), main(), and PCB_PROPERTIES_PANEL::PCB_PROPERTIES_PANEL().

◆ RegisterType()

void PROPERTY_MANAGER::RegisterType ( TYPE_ID  aType,
const wxString &  aName 
)

Associate a name with a type.

Build a map to provide faster type look-up.

Parameters
aTypeis the type identifier (obtained using TYPE_HASH()).
aNameis the type name.

Definition at line 32 of file property_mgr.cpp.

References m_classNames.

◆ ReplaceProperty()

PROPERTY_BASE & PROPERTY_MANAGER::ReplaceProperty ( size_t  aBase,
const wxString &  aName,
PROPERTY_BASE aNew,
const wxString &  aGroup = wxEmptyString 
)

Replace an existing property for a specific type.

It is used to modify a property that has been inherited from a base class. This method is used instead of AddProperty().

Parameters
aBaseis the base class type the delivers the original property.
aNameis the name of the replaced property.
aNewis the property replacing the inherited one.
aGroupis the group to set for the replaced property.

Definition at line 154 of file property_mgr.cpp.

References AddProperty(), getClass(), PROPERTY_MANAGER::CLASS_DESC::m_replaced, and PROPERTY_BASE::OwnerHash().

Referenced by BOARD_CONNECTED_ITEM_DESC::BOARD_CONNECTED_ITEM_DESC(), CLASS_D_DESC::CLASS_D_DESC(), CLASS_E_DESC::CLASS_E_DESC(), FOOTPRINT_DESC::FOOTPRINT_DESC(), PCB_SHAPE_DESC::PCB_SHAPE_DESC(), TRACK_VIA_DESC::TRACK_VIA_DESC(), and ZONE_DESC::ZONE_DESC().

◆ ResolveType()

const wxString & PROPERTY_MANAGER::ResolveType ( TYPE_ID  aType) const

Return name of a type.

Parameters
aTypeis the type identifier (obtained using TYPE_HASH()).
Returns
Name of the type or empty string, if not available.

Definition at line 39 of file property_mgr.cpp.

References EMPTY_STRING(), and m_classNames.

◆ SetTransforms()

void PROPERTY_MANAGER::SetTransforms ( ORIGIN_TRANSFORMS aTransforms)
inline

◆ SetUnits()

void PROPERTY_MANAGER::SetUnits ( EDA_UNITS  aUnits)
inline

◆ TypeCast() [1/2]

const void * PROPERTY_MANAGER::TypeCast ( const void *  aSource,
TYPE_ID  aBase,
TYPE_ID  aTarget 
) const

Cast a type to another type.

Used for correct type-casting of types with multi-inheritance. Requires registration of an appropriate converter (AddTypeCast).

Parameters
aSourceis a pointer to the casted object.
aBaseis aSource type identifier (obtained using TYPE_HASH()).
aTargetis the desired type identifier (obtained using TYPE_HASH()).
Returns
Properly casted pointer of aTarget type. *
See also
AddTypeCast

Definition at line 113 of file property_mgr.cpp.

References IsOfType(), and m_classes.

Referenced by INSPECTABLE::Get(), INSPECTABLE::Set(), and TypeCast().

◆ TypeCast() [2/2]

void * PROPERTY_MANAGER::TypeCast ( void *  aSource,
TYPE_ID  aBase,
TYPE_ID  aTarget 
) const
inline

Definition at line 134 of file property_mgr.h.

References TypeCast().

Member Data Documentation

◆ m_classes

std::unordered_map<TYPE_ID, CLASS_DESC> PROPERTY_MANAGER::m_classes
private

◆ m_classNames

std::unordered_map<TYPE_ID, wxString> PROPERTY_MANAGER::m_classNames
private

Map of all available types.

Definition at line 313 of file property_mgr.h.

Referenced by GetAllClasses(), RegisterType(), and ResolveType().

◆ m_dirty

bool PROPERTY_MANAGER::m_dirty
private

Flag indicating that the list of properties needs to be rebuild (RebuildProperties())

Definition at line 319 of file property_mgr.h.

Referenced by AddProperty(), GetDisplayOrder(), GetGroupDisplayOrder(), GetProperties(), GetProperty(), InheritsAfter(), Mask(), OverrideAvailability(), and Rebuild().

◆ m_originTransforms

ORIGIN_TRANSFORMS* PROPERTY_MANAGER::m_originTransforms
private

Definition at line 323 of file property_mgr.h.

Referenced by GetTransforms(), and SetTransforms().

◆ m_units

EDA_UNITS PROPERTY_MANAGER::m_units
private

Definition at line 321 of file property_mgr.h.

Referenced by GetUnits(), and SetUnits().


The documentation for this class was generated from the following files: