Properties: introduce method chaining for initialization
(cherry picked from commit 254168c788
)
This commit is contained in:
parent
eed7ede376
commit
d403e92315
|
@ -392,10 +392,9 @@ static struct EDA_ITEM_DESC
|
||||||
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
|
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
|
||||||
REGISTER_TYPE( EDA_ITEM );
|
REGISTER_TYPE( EDA_ITEM );
|
||||||
|
|
||||||
auto typeProp = new PROPERTY_ENUM<EDA_ITEM, KICAD_T>( wxS( "Type" ),
|
propMgr.AddProperty( new PROPERTY_ENUM<EDA_ITEM, KICAD_T>( wxS( "Type" ),
|
||||||
NO_SETTER( EDA_ITEM, KICAD_T ), &EDA_ITEM::Type );
|
NO_SETTER( EDA_ITEM, KICAD_T ), &EDA_ITEM::Type ) )
|
||||||
typeProp->SetIsInternal( true );
|
.SetIsInternal();
|
||||||
propMgr.AddProperty( typeProp );
|
|
||||||
}
|
}
|
||||||
} _EDA_ITEM_DESC;
|
} _EDA_ITEM_DESC;
|
||||||
|
|
||||||
|
|
|
@ -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();
|
const wxString& name = aProperty->Name();
|
||||||
TYPE_ID hash = aProperty->OwnerHash();
|
TYPE_ID hash = aProperty->OwnerHash();
|
||||||
|
@ -147,15 +147,16 @@ void PROPERTY_MANAGER::AddProperty( PROPERTY_BASE* aProperty, const wxString& aG
|
||||||
}
|
}
|
||||||
|
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
|
return *aProperty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PROPERTY_MANAGER::ReplaceProperty( size_t aBase, const wxString& aName, PROPERTY_BASE* aNew,
|
PROPERTY_BASE& PROPERTY_MANAGER::ReplaceProperty( size_t aBase, const wxString& aName, PROPERTY_BASE* aNew,
|
||||||
const wxString& aGroup )
|
const wxString& aGroup )
|
||||||
{
|
{
|
||||||
CLASS_DESC& classDesc = getClass( aNew->OwnerHash() );
|
CLASS_DESC& classDesc = getClass( aNew->OwnerHash() );
|
||||||
classDesc.m_replaced.insert( std::make_pair( aBase, aName ) );
|
classDesc.m_replaced.insert( std::make_pair( aBase, aName ) );
|
||||||
AddProperty( aNew, aGroup );
|
return AddProperty( aNew, aGroup );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -195,10 +195,7 @@ PROPERTY_BASE( const wxString& aName, PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
const wxString& Name() const
|
const wxString& Name() const { return m_name; }
|
||||||
{
|
|
||||||
return m_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a limited set of possible values (e.g. enum). Check with HasChoices() if a particular
|
* 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.
|
* Set a callback function to determine whether an object provides this property.
|
||||||
*/
|
*/
|
||||||
void SetAvailableFunc( std::function<bool(INSPECTABLE*)> aFunc )
|
PROPERTY_BASE& SetAvailableFunc( std::function<bool(INSPECTABLE*)> aFunc )
|
||||||
{
|
{
|
||||||
m_availFunc = aFunc;
|
m_availFunc = aFunc;
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool Writeable( INSPECTABLE* aObject ) const
|
virtual bool Writeable( INSPECTABLE* aObject ) const
|
||||||
|
@ -248,9 +246,10 @@ PROPERTY_BASE( const wxString& aName, PROPERTY_DISPLAY aDisplay = PT_DEFAULT,
|
||||||
return m_writeableFunc( aObject );
|
return m_writeableFunc( aObject );
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetWriteableFunc( std::function<bool(INSPECTABLE*)> aFunc )
|
PROPERTY_BASE& SetWriteableFunc( std::function<bool(INSPECTABLE*)> aFunc )
|
||||||
{
|
{
|
||||||
m_writeableFunc = 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;
|
virtual size_t TypeHash() const = 0;
|
||||||
|
|
||||||
PROPERTY_DISPLAY Display() const
|
PROPERTY_DISPLAY Display() const { return m_display; }
|
||||||
{
|
PROPERTY_BASE& SetDisplay( PROPERTY_DISPLAY aDisplay ) { m_display = aDisplay; return *this; }
|
||||||
return m_display;
|
|
||||||
}
|
|
||||||
|
|
||||||
ORIGIN_TRANSFORMS::COORD_TYPES_T CoordType() const { return m_coordType; }
|
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; }
|
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; }
|
bool IsDeprecated() const { return m_isDeprecated; }
|
||||||
|
PROPERTY_BASE& SetIsDeprecated( bool aIsDeprecated = true )
|
||||||
|
{
|
||||||
|
m_isDeprecated = aIsDeprecated;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
wxString Group() const { return m_group; }
|
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:
|
protected:
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -329,8 +339,8 @@ private:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const wxString m_name;
|
const wxString m_name;
|
||||||
const PROPERTY_DISPLAY m_display;
|
PROPERTY_DISPLAY m_display;
|
||||||
const ORIGIN_TRANSFORMS::COORD_TYPES_T m_coordType;
|
ORIGIN_TRANSFORMS::COORD_TYPES_T m_coordType;
|
||||||
|
|
||||||
/// Internal properties are hidden from the GUI but not from the rules editor autocomplete
|
/// Internal properties are hidden from the GUI but not from the rules editor autocomplete
|
||||||
bool m_isInternal;
|
bool m_isInternal;
|
||||||
|
|
|
@ -146,7 +146,7 @@ public:
|
||||||
* @param aProperty is the property to register.
|
* @param aProperty is the property to register.
|
||||||
* @param aGroup is an optional grouping key for the property
|
* @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.
|
* Replace an existing property for a specific type.
|
||||||
|
@ -159,7 +159,7 @@ public:
|
||||||
* @param aNew is the property replacing the inherited one.
|
* @param aNew is the property replacing the inherited one.
|
||||||
* @param aGroup is the group to set for the replaced property.
|
* @param aGroup is the group to set for the replaced property.
|
||||||
*/
|
*/
|
||||||
void ReplaceProperty( size_t aBase, const wxString& aName, PROPERTY_BASE* aNew,
|
PROPERTY_BASE& ReplaceProperty( size_t aBase, const wxString& aName, PROPERTY_BASE* aNew,
|
||||||
const wxString& aGroup = wxEmptyString );
|
const wxString& aGroup = wxEmptyString );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1431,55 +1431,57 @@ static struct ZONE_DESC
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
auto layer = new PROPERTY_ENUM<ZONE, PCB_LAYER_ID>( _HKI( "Layer" ),
|
propMgr.ReplaceProperty( TYPE_HASH( BOARD_CONNECTED_ITEM ), _HKI( "Layer" ),
|
||||||
&ZONE::SetLayer, &ZONE::GetLayer );
|
new PROPERTY_ENUM<ZONE, PCB_LAYER_ID>( _HKI( "Layer" ),
|
||||||
layer->SetIsInternal( true );
|
&ZONE::SetLayer,
|
||||||
propMgr.ReplaceProperty( TYPE_HASH( BOARD_CONNECTED_ITEM ), _HKI( "Layer" ), layer );
|
&ZONE::GetLayer ) )
|
||||||
|
.SetIsInternal();
|
||||||
|
|
||||||
propMgr.OverrideAvailability( TYPE_HASH( ZONE ), TYPE_HASH( BOARD_CONNECTED_ITEM ),
|
propMgr.OverrideAvailability( TYPE_HASH( ZONE ), TYPE_HASH( BOARD_CONNECTED_ITEM ),
|
||||||
_HKI( "Net" ), isCopperZone );
|
_HKI( "Net" ), isCopperZone );
|
||||||
propMgr.OverrideAvailability( TYPE_HASH( ZONE ), TYPE_HASH( BOARD_CONNECTED_ITEM ),
|
propMgr.OverrideAvailability( TYPE_HASH( ZONE ), TYPE_HASH( BOARD_CONNECTED_ITEM ),
|
||||||
_HKI( "Net Class" ), isCopperZone );
|
_HKI( "Net Class" ), isCopperZone );
|
||||||
|
|
||||||
auto priority = new PROPERTY<ZONE, unsigned>( _HKI( "Priority" ),
|
propMgr.AddProperty( new PROPERTY<ZONE, unsigned>( _HKI( "Priority" ),
|
||||||
&ZONE::SetAssignedPriority, &ZONE::GetAssignedPriority );
|
&ZONE::SetAssignedPriority,
|
||||||
priority->SetAvailableFunc( isCopperZone );
|
&ZONE::GetAssignedPriority ) )
|
||||||
propMgr.AddProperty( priority );
|
.SetAvailableFunc( isCopperZone );
|
||||||
|
|
||||||
propMgr.AddProperty( new PROPERTY<ZONE, wxString>( _HKI( "Name" ),
|
propMgr.AddProperty( new PROPERTY<ZONE, wxString>( _HKI( "Name" ),
|
||||||
&ZONE::SetZoneName, &ZONE::GetZoneName ) );
|
&ZONE::SetZoneName, &ZONE::GetZoneName ) );
|
||||||
|
|
||||||
const wxString groupFill = _HKI( "Fill Style" );
|
const wxString groupFill = _HKI( "Fill Style" );
|
||||||
|
|
||||||
auto fillMode = new PROPERTY_ENUM<ZONE, ZONE_FILL_MODE>( _HKI( "Fill Mode" ),
|
|
||||||
&ZONE::SetFillMode, &ZONE::GetFillMode );
|
|
||||||
// Fill mode can't be exposed to the UI until validation is moved to the ZONE class.
|
// 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
|
// see https://gitlab.com/kicad/code/kicad/-/issues/13811
|
||||||
fillMode->SetIsInternal();
|
propMgr.AddProperty( new PROPERTY_ENUM<ZONE, ZONE_FILL_MODE>(
|
||||||
propMgr.AddProperty( fillMode, groupFill );
|
_HKI( "Fill Mode" ), &ZONE::SetFillMode, &ZONE::GetFillMode ),
|
||||||
|
groupFill )
|
||||||
|
.SetIsInternal();
|
||||||
|
|
||||||
auto hatchOrientation = new PROPERTY<ZONE, EDA_ANGLE>( _HKI( "Orientation" ),
|
propMgr.AddProperty( new PROPERTY<ZONE, EDA_ANGLE>(
|
||||||
&ZONE::SetHatchOrientation, &ZONE::GetHatchOrientation,
|
_HKI( "Orientation" ), &ZONE::SetHatchOrientation,
|
||||||
PROPERTY_DISPLAY::PT_DEGREE );
|
&ZONE::GetHatchOrientation, PROPERTY_DISPLAY::PT_DEGREE ),
|
||||||
hatchOrientation->SetWriteableFunc( isHatchedFill );
|
groupFill )
|
||||||
hatchOrientation->SetIsInternal();
|
.SetWriteableFunc( isHatchedFill )
|
||||||
propMgr.AddProperty( hatchOrientation, groupFill );
|
.SetIsInternal();
|
||||||
|
|
||||||
//TODO: Switch to translated
|
//TODO: Switch to translated
|
||||||
auto hatchWidth = new PROPERTY<ZONE, int>( wxT( "Hatch Width" ),
|
propMgr.AddProperty( new PROPERTY<ZONE, int>( wxT( "Hatch Width" ),
|
||||||
&ZONE::SetHatchThickness, &ZONE::GetHatchThickness,
|
&ZONE::SetHatchThickness,
|
||||||
PROPERTY_DISPLAY::PT_SIZE );
|
&ZONE::GetHatchThickness,
|
||||||
hatchWidth->SetWriteableFunc( isHatchedFill );
|
PROPERTY_DISPLAY::PT_SIZE ),
|
||||||
hatchWidth->SetIsInternal();
|
groupFill )
|
||||||
propMgr.AddProperty( hatchWidth, groupFill );
|
.SetWriteableFunc( isHatchedFill )
|
||||||
|
.SetIsInternal();
|
||||||
|
|
||||||
//TODO: Switch to translated
|
//TODO: Switch to translated
|
||||||
auto hatchGap = new PROPERTY<ZONE, int>( wxT( "Hatch Gap" ),
|
propMgr.AddProperty( new PROPERTY<ZONE, int>( wxT( "Hatch Gap" ), &ZONE::SetHatchGap,
|
||||||
&ZONE::SetHatchGap, &ZONE::GetHatchGap,
|
&ZONE::GetHatchGap,
|
||||||
PROPERTY_DISPLAY::PT_SIZE );
|
PROPERTY_DISPLAY::PT_SIZE ),
|
||||||
hatchGap->SetWriteableFunc( isHatchedFill );
|
groupFill )
|
||||||
hatchGap->SetIsInternal();
|
.SetWriteableFunc( isHatchedFill )
|
||||||
propMgr.AddProperty( hatchGap, groupFill );
|
.SetIsInternal();
|
||||||
|
|
||||||
// TODO: Smoothing effort needs to change to enum (in dialog too)
|
// TODO: Smoothing effort needs to change to enum (in dialog too)
|
||||||
// TODO: Smoothing amount (double)
|
// TODO: Smoothing amount (double)
|
||||||
|
|
Loading…
Reference in New Issue