From 7cca303f6553149959f1f6018465dc660dddcfbd Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 22 Oct 2023 12:15:53 +0100 Subject: [PATCH] Expose missing properties for label shapes. --- eeschema/sch_label.cpp | 73 ++++++++++++++++++++++++++++++++++++++---- eeschema/sch_label.h | 29 ++++++++++++++++- 2 files changed, 95 insertions(+), 7 deletions(-) diff --git a/eeschema/sch_label.cpp b/eeschema/sch_label.cpp index bac0976198..3e11b07a58 100644 --- a/eeschema/sch_label.cpp +++ b/eeschema/sch_label.cpp @@ -2069,34 +2069,95 @@ static struct SCH_LABEL_DESC { SCH_LABEL_DESC() { + auto& labelShapeEnum = ENUM_MAP::Instance(); + + if( labelShapeEnum.Choices().GetCount() == 0 ) + { + labelShapeEnum.Map( LABEL_SHAPE::LABEL_INPUT, _HKI( "Input" ) ) + .Map( LABEL_SHAPE::LABEL_OUTPUT, _HKI( "Output" ) ) + .Map( LABEL_SHAPE::LABEL_BIDI, _HKI( "Bidirectional" ) ) + .Map( LABEL_SHAPE::LABEL_TRISTATE, _HKI( "Tri-state" ) ) + .Map( LABEL_SHAPE::LABEL_PASSIVE, _HKI( "Passive" ) ); + } + PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance(); REGISTER_TYPE( SCH_LABEL_BASE ); REGISTER_TYPE( SCH_LABEL ); REGISTER_TYPE( SCH_HIERLABEL ); - REGISTER_TYPE( SCH_GLOBALLABEL ); - REGISTER_TYPE( SCH_DIRECTIVE_LABEL ); propMgr.AddTypeCast( new TYPE_CAST ); propMgr.AddTypeCast( new TYPE_CAST ); propMgr.AddTypeCast( new TYPE_CAST ); - propMgr.AddTypeCast( new TYPE_CAST ); propMgr.AddTypeCast( new TYPE_CAST ); propMgr.AddTypeCast( new TYPE_CAST ); propMgr.AddTypeCast( new TYPE_CAST ); - propMgr.AddTypeCast( new TYPE_CAST ); propMgr.AddTypeCast( new TYPE_CAST ); propMgr.AddTypeCast( new TYPE_CAST ); propMgr.AddTypeCast( new TYPE_CAST ); - propMgr.AddTypeCast( new TYPE_CAST ); propMgr.InheritsAfter( TYPE_HASH( SCH_LABEL_BASE ), TYPE_HASH( SCH_TEXT ) ); propMgr.InheritsAfter( TYPE_HASH( SCH_LABEL ), TYPE_HASH( SCH_LABEL_BASE ) ); propMgr.InheritsAfter( TYPE_HASH( SCH_HIERLABEL ), TYPE_HASH( SCH_LABEL_BASE ) ); propMgr.InheritsAfter( TYPE_HASH( SCH_GLOBALLABEL ), TYPE_HASH( SCH_LABEL_BASE ) ); - propMgr.InheritsAfter( TYPE_HASH( SCH_DIRECTIVE_LABEL ), TYPE_HASH( SCH_LABEL_BASE ) ); + + auto hasLabelShape = + []( INSPECTABLE* aItem ) -> bool + { + if( SCH_LABEL_BASE* label = dynamic_cast( aItem ) ) + return label->IsType( { SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T } ); + + return false; + }; + + propMgr.AddProperty( new PROPERTY_ENUM( _HKI( "Shape" ), + &SCH_LABEL_BASE::SetLabelShape, &SCH_LABEL_BASE::GetLabelShape ) ) + .SetAvailableFunc( hasLabelShape ); propMgr.Mask( TYPE_HASH( SCH_LABEL_BASE ), TYPE_HASH( EDA_TEXT ), _HKI( "Hyperlink" ) ); } } _SCH_LABEL_DESC; + + +static struct SCH_DIRECTIVE_LABEL_DESC +{ + SCH_DIRECTIVE_LABEL_DESC() + { + auto& flagShapeEnum = ENUM_MAP::Instance(); + + if( flagShapeEnum.Choices().GetCount() == 0 ) + { + flagShapeEnum.Map( FLAG_SHAPE::FLAG_DOT, _HKI( "Dot" ) ) + .Map( FLAG_SHAPE::FLAG_CIRCLE, _HKI( "Circle" ) ) + .Map( FLAG_SHAPE::FLAG_DIAMOND, _HKI( "Diamond" ) ) + .Map( FLAG_SHAPE::FLAG_RECTANGLE, _HKI( "Rectangle" ) ); + } + + PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance(); + REGISTER_TYPE( SCH_DIRECTIVE_LABEL ); + propMgr.AddTypeCast( new TYPE_CAST ); + propMgr.AddTypeCast( new TYPE_CAST ); + propMgr.AddTypeCast( new TYPE_CAST ); + + propMgr.InheritsAfter( TYPE_HASH( SCH_DIRECTIVE_LABEL ), TYPE_HASH( SCH_LABEL_BASE ) ); + + propMgr.AddProperty( new PROPERTY_ENUM( _HKI( "Shape" ), + &SCH_DIRECTIVE_LABEL::SetFlagShape, &SCH_DIRECTIVE_LABEL::GetFlagShape ) ); + + propMgr.AddProperty( new PROPERTY( _HKI( "Pin length" ), + &SCH_DIRECTIVE_LABEL::SetPinLength, &SCH_DIRECTIVE_LABEL::GetPinLength, + PROPERTY_DISPLAY::PT_SIZE ) ); + + propMgr.Mask( TYPE_HASH( SCH_DIRECTIVE_LABEL ), TYPE_HASH( EDA_TEXT ), _HKI( "Text" ) ); + propMgr.Mask( TYPE_HASH( SCH_DIRECTIVE_LABEL ), TYPE_HASH( EDA_TEXT ), _HKI( "Thickness" ) ); + propMgr.Mask( TYPE_HASH( SCH_DIRECTIVE_LABEL ), TYPE_HASH( EDA_TEXT ), _HKI( "Italic" ) ); + propMgr.Mask( TYPE_HASH( SCH_DIRECTIVE_LABEL ), TYPE_HASH( EDA_TEXT ), _HKI( "Bold" ) ); + propMgr.Mask( TYPE_HASH( SCH_DIRECTIVE_LABEL ), TYPE_HASH( EDA_TEXT ), _HKI( "Horizontal Justification" ) ); + propMgr.Mask( TYPE_HASH( SCH_DIRECTIVE_LABEL ), TYPE_HASH( EDA_TEXT ), _HKI( "Vertical Justification" ) ); + } +} _SCH_DIRECTIVE_LABEL_DESC; + + +ENUM_TO_WXANY( LABEL_SHAPE ) +ENUM_TO_WXANY( FLAG_SHAPE ) diff --git a/eeschema/sch_label.h b/eeschema/sch_label.h index 161bd90eb1..f54b69bcbd 100644 --- a/eeschema/sch_label.h +++ b/eeschema/sch_label.h @@ -102,6 +102,26 @@ enum LABEL_FLAG_SHAPE F_RECTANGLE }; +/* + * Specific enums for property manager (not used elsewhere) + */ +enum LABEL_SHAPE +{ + LABEL_INPUT = L_INPUT, + LABEL_OUTPUT = L_OUTPUT, + LABEL_BIDI = L_BIDI, + LABEL_TRISTATE = L_TRISTATE, + LABEL_PASSIVE = L_UNSPECIFIED +}; + +enum FLAG_SHAPE +{ + FLAG_DOT = F_DOT, + FLAG_CIRCLE = F_ROUND, + FLAG_DIAMOND = F_DIAMOND, + FLAG_RECTANGLE = F_RECTANGLE +}; + class SCH_LABEL_BASE : public SCH_TEXT { @@ -147,6 +167,10 @@ public: LABEL_FLAG_SHAPE GetShape() const { return m_shape; } void SetShape( LABEL_FLAG_SHAPE aShape ) { m_shape = aShape; } + // Type-specific versions for property manager + LABEL_SHAPE GetLabelShape() const { return (LABEL_SHAPE) m_shape; } + void SetLabelShape( LABEL_SHAPE aShape ) { m_shape = (LABEL_FLAG_SHAPE) aShape; } + COLOR4D GetLabelColor() const; virtual void SetSpinStyle( SPIN_STYLE aSpinStyle ); @@ -409,7 +433,10 @@ public: void SwapData( SCH_ITEM* aItem ) override; - int GetPinLength() const { return m_pinLength; } + FLAG_SHAPE GetFlagShape() const { return (FLAG_SHAPE) m_shape; } + void SetFlagShape( FLAG_SHAPE aShape ) { m_shape = (LABEL_FLAG_SHAPE) aShape; } + + int GetPinLength() const { return m_pinLength; } void SetPinLength( int aLength ) { m_pinLength = aLength; } int GetPenWidth() const override;