diff --git a/common/eda_item.cpp b/common/eda_item.cpp index b4bf6de121..cf769092f9 100644 --- a/common/eda_item.cpp +++ b/common/eda_item.cpp @@ -392,10 +392,9 @@ static struct EDA_ITEM_DESC PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance(); REGISTER_TYPE( EDA_ITEM ); - auto typeProp = new PROPERTY_ENUM( wxS( "Type" ), - NO_SETTER( EDA_ITEM, KICAD_T ), &EDA_ITEM::Type ); - typeProp->SetIsInternal( true ); - propMgr.AddProperty( typeProp ); + propMgr.AddProperty( new PROPERTY_ENUM( wxS( "Type" ), + NO_SETTER( EDA_ITEM, KICAD_T ), &EDA_ITEM::Type ) ) + .SetIsInternal(); } } _EDA_ITEM_DESC; diff --git a/common/properties/property_mgr.cpp b/common/properties/property_mgr.cpp index 68d322f5b9..d9e300057c 100644 --- a/common/properties/property_mgr.cpp +++ b/common/properties/property_mgr.cpp @@ -130,7 +130,7 @@ const void* PROPERTY_MANAGER::TypeCast( const void* aSource, TYPE_ID aBase, TYPE } -void PROPERTY_MANAGER::AddProperty( PROPERTY_BASE* aProperty, const wxString& aGroup ) +PROPERTY_BASE& PROPERTY_MANAGER::AddProperty( PROPERTY_BASE* aProperty, const wxString& aGroup ) { const wxString& name = aProperty->Name(); TYPE_ID hash = aProperty->OwnerHash(); @@ -147,15 +147,16 @@ void PROPERTY_MANAGER::AddProperty( PROPERTY_BASE* aProperty, const wxString& aG } m_dirty = true; + return *aProperty; } -void PROPERTY_MANAGER::ReplaceProperty( size_t aBase, const wxString& aName, PROPERTY_BASE* aNew, - const wxString& aGroup ) +PROPERTY_BASE& PROPERTY_MANAGER::ReplaceProperty( size_t aBase, const wxString& aName, PROPERTY_BASE* aNew, + const wxString& aGroup ) { CLASS_DESC& classDesc = getClass( aNew->OwnerHash() ); classDesc.m_replaced.insert( std::make_pair( aBase, aName ) ); - AddProperty( aNew, aGroup ); + return AddProperty( aNew, aGroup ); } diff --git a/include/properties/property.h b/include/properties/property.h index f38b57081c..caefa33719 100644 --- a/include/properties/property.h +++ b/include/properties/property.h @@ -195,10 +195,7 @@ PROPERTY_BASE( const wxString& aName, PROPERTY_DISPLAY aDisplay = PT_DEFAULT, { } - const wxString& Name() const - { - return m_name; - } + const wxString& Name() const { return m_name; } /** * Return a limited set of possible values (e.g. enum). Check with HasChoices() if a particular @@ -238,9 +235,10 @@ PROPERTY_BASE( const wxString& aName, PROPERTY_DISPLAY aDisplay = PT_DEFAULT, /** * Set a callback function to determine whether an object provides this property. */ - void SetAvailableFunc( std::function aFunc ) + PROPERTY_BASE& SetAvailableFunc( std::function aFunc ) { m_availFunc = aFunc; + return *this; } virtual bool Writeable( INSPECTABLE* aObject ) const @@ -248,9 +246,10 @@ PROPERTY_BASE( const wxString& aName, PROPERTY_DISPLAY aDisplay = PT_DEFAULT, return m_writeableFunc( aObject ); } - void SetWriteableFunc( std::function aFunc ) + PROPERTY_BASE& SetWriteableFunc( std::function aFunc ) { m_writeableFunc = aFunc; + return *this; } /** @@ -268,21 +267,32 @@ PROPERTY_BASE( const wxString& aName, PROPERTY_DISPLAY aDisplay = PT_DEFAULT, */ virtual size_t TypeHash() const = 0; - PROPERTY_DISPLAY Display() const - { - return m_display; - } + PROPERTY_DISPLAY Display() const { return m_display; } + PROPERTY_BASE& SetDisplay( PROPERTY_DISPLAY aDisplay ) { m_display = aDisplay; return *this; } ORIGIN_TRANSFORMS::COORD_TYPES_T CoordType() const { return m_coordType; } + PROPERTY_BASE& SetCoordType( ORIGIN_TRANSFORMS::COORD_TYPES_T aType ) + { + m_coordType = aType; + return *this; + } - void SetIsInternal( bool aIsInternal = true ) { m_isInternal = aIsInternal; } bool IsInternal() const { return m_isInternal; } + PROPERTY_BASE& SetIsInternal( bool aIsInternal = true ) + { + m_isInternal = aIsInternal; + return *this; + } - void SetIsDeprecated( bool aIsDeprecated = true ) { m_isDeprecated = aIsDeprecated; } bool IsDeprecated() const { return m_isDeprecated; } + PROPERTY_BASE& SetIsDeprecated( bool aIsDeprecated = true ) + { + m_isDeprecated = aIsDeprecated; + return *this; + } wxString Group() const { return m_group; } - void SetGroup( const wxString& aGroup ) { m_group = aGroup; } + PROPERTY_BASE& SetGroup( const wxString& aGroup ) { m_group = aGroup; return *this; } protected: template @@ -329,8 +339,8 @@ private: private: const wxString m_name; - const PROPERTY_DISPLAY m_display; - const ORIGIN_TRANSFORMS::COORD_TYPES_T m_coordType; + PROPERTY_DISPLAY m_display; + ORIGIN_TRANSFORMS::COORD_TYPES_T m_coordType; /// Internal properties are hidden from the GUI but not from the rules editor autocomplete bool m_isInternal; diff --git a/include/properties/property_mgr.h b/include/properties/property_mgr.h index a766028d85..c0eeb6632c 100644 --- a/include/properties/property_mgr.h +++ b/include/properties/property_mgr.h @@ -146,7 +146,7 @@ public: * @param aProperty is the property to register. * @param aGroup is an optional grouping key for the property */ - void AddProperty( PROPERTY_BASE* aProperty, const wxString& aGroup = wxEmptyString ); + PROPERTY_BASE& AddProperty( PROPERTY_BASE* aProperty, const wxString& aGroup = wxEmptyString ); /** * Replace an existing property for a specific type. @@ -159,8 +159,8 @@ public: * @param aNew is the property replacing the inherited one. * @param aGroup is the group to set for the replaced property. */ - void ReplaceProperty( size_t aBase, const wxString& aName, PROPERTY_BASE* aNew, - const wxString& aGroup = wxEmptyString ); + PROPERTY_BASE& ReplaceProperty( size_t aBase, const wxString& aName, PROPERTY_BASE* aNew, + const wxString& aGroup = wxEmptyString ); /** * Register a type converter. Required prior TypeCast() usage. diff --git a/pcbnew/zone.cpp b/pcbnew/zone.cpp index 0192fb802e..db8e531909 100644 --- a/pcbnew/zone.cpp +++ b/pcbnew/zone.cpp @@ -1431,55 +1431,57 @@ static struct ZONE_DESC return false; }; - auto layer = new PROPERTY_ENUM( _HKI( "Layer" ), - &ZONE::SetLayer, &ZONE::GetLayer ); - layer->SetIsInternal( true ); - propMgr.ReplaceProperty( TYPE_HASH( BOARD_CONNECTED_ITEM ), _HKI( "Layer" ), layer ); + propMgr.ReplaceProperty( TYPE_HASH( BOARD_CONNECTED_ITEM ), _HKI( "Layer" ), + new PROPERTY_ENUM( _HKI( "Layer" ), + &ZONE::SetLayer, + &ZONE::GetLayer ) ) + .SetIsInternal(); propMgr.OverrideAvailability( TYPE_HASH( ZONE ), TYPE_HASH( BOARD_CONNECTED_ITEM ), _HKI( "Net" ), isCopperZone ); propMgr.OverrideAvailability( TYPE_HASH( ZONE ), TYPE_HASH( BOARD_CONNECTED_ITEM ), _HKI( "Net Class" ), isCopperZone ); - auto priority = new PROPERTY( _HKI( "Priority" ), - &ZONE::SetAssignedPriority, &ZONE::GetAssignedPriority ); - priority->SetAvailableFunc( isCopperZone ); - propMgr.AddProperty( priority ); + propMgr.AddProperty( new PROPERTY( _HKI( "Priority" ), + &ZONE::SetAssignedPriority, + &ZONE::GetAssignedPriority ) ) + .SetAvailableFunc( isCopperZone ); propMgr.AddProperty( new PROPERTY( _HKI( "Name" ), &ZONE::SetZoneName, &ZONE::GetZoneName ) ); const wxString groupFill = _HKI( "Fill Style" ); - auto fillMode = new PROPERTY_ENUM( _HKI( "Fill Mode" ), - &ZONE::SetFillMode, &ZONE::GetFillMode ); // Fill mode can't be exposed to the UI until validation is moved to the ZONE class. // see https://gitlab.com/kicad/code/kicad/-/issues/13811 - fillMode->SetIsInternal(); - propMgr.AddProperty( fillMode, groupFill ); + propMgr.AddProperty( new PROPERTY_ENUM( + _HKI( "Fill Mode" ), &ZONE::SetFillMode, &ZONE::GetFillMode ), + groupFill ) + .SetIsInternal(); - auto hatchOrientation = new PROPERTY( _HKI( "Orientation" ), - &ZONE::SetHatchOrientation, &ZONE::GetHatchOrientation, - PROPERTY_DISPLAY::PT_DEGREE ); - hatchOrientation->SetWriteableFunc( isHatchedFill ); - hatchOrientation->SetIsInternal(); - propMgr.AddProperty( hatchOrientation, groupFill ); + propMgr.AddProperty( new PROPERTY( + _HKI( "Orientation" ), &ZONE::SetHatchOrientation, + &ZONE::GetHatchOrientation, PROPERTY_DISPLAY::PT_DEGREE ), + groupFill ) + .SetWriteableFunc( isHatchedFill ) + .SetIsInternal(); //TODO: Switch to translated - auto hatchWidth = new PROPERTY( wxT( "Hatch Width" ), - &ZONE::SetHatchThickness, &ZONE::GetHatchThickness, - PROPERTY_DISPLAY::PT_SIZE ); - hatchWidth->SetWriteableFunc( isHatchedFill ); - hatchWidth->SetIsInternal(); - propMgr.AddProperty( hatchWidth, groupFill ); + propMgr.AddProperty( new PROPERTY( wxT( "Hatch Width" ), + &ZONE::SetHatchThickness, + &ZONE::GetHatchThickness, + PROPERTY_DISPLAY::PT_SIZE ), + groupFill ) + .SetWriteableFunc( isHatchedFill ) + .SetIsInternal(); //TODO: Switch to translated - auto hatchGap = new PROPERTY( wxT( "Hatch Gap" ), - &ZONE::SetHatchGap, &ZONE::GetHatchGap, - PROPERTY_DISPLAY::PT_SIZE ); - hatchGap->SetWriteableFunc( isHatchedFill ); - hatchGap->SetIsInternal(); - propMgr.AddProperty( hatchGap, groupFill ); + propMgr.AddProperty( new PROPERTY( wxT( "Hatch Gap" ), &ZONE::SetHatchGap, + &ZONE::GetHatchGap, + PROPERTY_DISPLAY::PT_SIZE ), + groupFill ) + .SetWriteableFunc( isHatchedFill ) + .SetIsInternal(); // TODO: Smoothing effort needs to change to enum (in dialog too) // TODO: Smoothing amount (double)