From 5ff61ae561f1938bda876c499d4cb0594a81106b Mon Sep 17 00:00:00 2001 From: xx Date: Sun, 26 May 2024 21:32:06 +0200 Subject: [PATCH] Add rectangle height and width to properties Fixes https://gitlab.com/kicad/code/kicad/-/issues/17181 --- common/eda_shape.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++ include/eda_shape.h | 4 ++++ 2 files changed, 51 insertions(+) diff --git a/common/eda_shape.cpp b/common/eda_shape.cpp index ae75beeace..0b450d3e3e 100644 --- a/common/eda_shape.cpp +++ b/common/eda_shape.cpp @@ -185,6 +185,32 @@ void EDA_SHAPE::SetLength( const double& aLength ) } } +void EDA_SHAPE::SetRectangleHeight( const int& aHeight ) +{ + switch ( m_shape ) + { + case SHAPE_T::RECTANGLE: + m_rectangleHeight = aHeight; + SetEndY( GetStartY() + m_rectangleHeight ); + break; + + default: UNIMPLEMENTED_FOR( SHAPE_T_asString() ); + } +} + +void EDA_SHAPE::SetRectangleWidth( const int& aWidth ) +{ + switch ( m_shape ) + { + case SHAPE_T::RECTANGLE: + m_rectangleWidth = aWidth; + SetEndX( GetStartX() + m_rectangleWidth ); + break; + + default: UNIMPLEMENTED_FOR( SHAPE_T_asString() ); + } +} + void EDA_SHAPE::SetRectangle( const long long int& aHeight, const long long int& aWidth ) { switch ( m_shape ) @@ -1972,6 +1998,15 @@ static struct EDA_SHAPE_DESC return false; }; + auto isRectangle = []( INSPECTABLE* aItem ) -> bool + { + // Polygons, unlike other shapes, have no meaningful start or end coordinates + if( EDA_SHAPE* shape = dynamic_cast( aItem ) ) + return shape->GetShape() == SHAPE_T::RECTANGLE; + + return false; + }; + const wxString shapeProps = _HKI( "Shape Properties" ); auto shape = new PROPERTY_ENUM( _HKI( "Shape" ), @@ -2019,6 +2054,18 @@ static struct EDA_SHAPE_DESC shapeProps ) .SetAvailableFunc( isNotPolygonOrCircle ); + propMgr.AddProperty( new PROPERTY( _HKI( "Width" ), + &EDA_SHAPE::SetRectangleWidth, &EDA_SHAPE::GetRectangleWidth, PROPERTY_DISPLAY::PT_COORD, + ORIGIN_TRANSFORMS::ABS_Y_COORD ), + shapeProps ) + .SetAvailableFunc( isRectangle ); + + propMgr.AddProperty( new PROPERTY( _HKI( "Height" ), + &EDA_SHAPE::SetRectangleHeight, &EDA_SHAPE::GetRectangleHeight, PROPERTY_DISPLAY::PT_COORD, + ORIGIN_TRANSFORMS::ABS_Y_COORD ), + shapeProps ) + .SetAvailableFunc( isRectangle ); + propMgr.AddProperty( new PROPERTY( _HKI( "Line Width" ), &EDA_SHAPE::SetWidth, &EDA_SHAPE::GetWidth, PROPERTY_DISPLAY::PT_SIZE ), shapeProps ); diff --git a/include/eda_shape.h b/include/eda_shape.h index 74de5ddf40..1a7e898965 100644 --- a/include/eda_shape.h +++ b/include/eda_shape.h @@ -322,6 +322,10 @@ public: void SetLength( const double& aLength ); + void SetRectangleHeight( const int& aHeight ); + + void SetRectangleWidth( const int& aWidth ); + void SetRectangle( const long long int& aHeight, const long long int& aWidth ); void SetSegmentAngle( const EDA_ANGLE& aAngle );