From 0f1b514964c2e3a97a96090532faa3fd55b2968e Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Sat, 30 Aug 2025 07:33:00 -0700 Subject: [PATCH] Handle corner radius in Create from selection Fixes https://gitlab.com/kicad/code/kicad/-/issues/21601 --- common/eda_shape.cpp | 47 +++++++++++++++++++++++++---------- pcbnew/tools/convert_tool.cpp | 20 ++++----------- 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/common/eda_shape.cpp b/common/eda_shape.cpp index d7ff03bfd3..bb25a7c1d4 100644 --- a/common/eda_shape.cpp +++ b/common/eda_shape.cpp @@ -2301,23 +2301,44 @@ void EDA_SHAPE::TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, int aClearance case SHAPE_T::RECTANGLE: { - std::vector pts = GetRectCorners(); - - if( solidFill ) + if( GetCornerRadius() > 0 ) { - aBuffer.NewOutline(); + // Use specialized function for rounded rectangles + VECTOR2I size( GetRectangleWidth(), GetRectangleHeight() ); + VECTOR2I position = GetStart() + size / 2; // Center position - for( const VECTOR2I& pt : pts ) - aBuffer.Append( pt ); + TransformRoundChamferedRectToPolygon( aBuffer, position, size, ANGLE_0, + GetCornerRadius(), 0.0, 0, + solidFill ? 0 : width / 2, aError, aErrorLoc ); + + if( solidFill && width > 0 ) + { + // Add outline for filled shapes with border + TransformRoundChamferedRectToPolygon( aBuffer, position, size, ANGLE_0, + GetCornerRadius(), 0.0, 0, + width / 2, aError, aErrorLoc ); + } } - - if( width > 0 || !solidFill ) + else { - // Add in segments - TransformOvalToPolygon( aBuffer, pts[0], pts[1], width, aError, aErrorLoc ); - TransformOvalToPolygon( aBuffer, pts[1], pts[2], width, aError, aErrorLoc ); - TransformOvalToPolygon( aBuffer, pts[2], pts[3], width, aError, aErrorLoc ); - TransformOvalToPolygon( aBuffer, pts[3], pts[0], width, aError, aErrorLoc ); + std::vector pts = GetRectCorners(); + + if( solidFill ) + { + aBuffer.NewOutline(); + + for( const VECTOR2I& pt : pts ) + aBuffer.Append( pt ); + } + + if( width > 0 || !solidFill ) + { + // Add in segments + TransformOvalToPolygon( aBuffer, pts[0], pts[1], width, aError, aErrorLoc ); + TransformOvalToPolygon( aBuffer, pts[1], pts[2], width, aError, aErrorLoc ); + TransformOvalToPolygon( aBuffer, pts[2], pts[3], width, aError, aErrorLoc ); + TransformOvalToPolygon( aBuffer, pts[3], pts[0], width, aError, aErrorLoc ); + } } break; diff --git a/pcbnew/tools/convert_tool.cpp b/pcbnew/tools/convert_tool.cpp index 777251fc5f..e7d56901a2 100644 --- a/pcbnew/tools/convert_tool.cpp +++ b/pcbnew/tools/convert_tool.cpp @@ -978,24 +978,14 @@ int CONVERT_TOOL::CreateLines( const TOOL_EVENT& aEvent ) { PCB_SHAPE* graphic = static_cast( aItem ); - if( graphic->GetShape() == SHAPE_T::POLY ) + if( graphic->GetShape() == SHAPE_T::RECTANGLE ) + { + graphic->TransformShapeToPolygon( set, graphic->GetLayer(), 0, graphic->GetMaxError(), ERROR_INSIDE ); + } + else if( graphic->GetShape() == SHAPE_T::POLY ) { set = graphic->GetPolyShape(); } - else if( graphic->GetShape() == SHAPE_T::RECTANGLE ) - { - SHAPE_LINE_CHAIN outline; - VECTOR2I start( graphic->GetStart() ); - VECTOR2I end( graphic->GetEnd() ); - - outline.Append( start ); - outline.Append( VECTOR2I( end.x, start.y ) ); - outline.Append( end ); - outline.Append( VECTOR2I( start.x, end.y ) ); - outline.SetClosed( true ); - - set.AddOutline( outline ); - } else { wxFAIL_MSG( wxT( "Unhandled graphic shape type in PolyToLines - getPolySet" ) );