From d174af400650ed6871a439e2fadab356777995f5 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 1 Apr 2022 16:11:42 +0100 Subject: [PATCH] Handle textboxes moving back to RECT shape (ie: cardinal rotation). --- pcbnew/pcb_textbox.cpp | 10 ++++++ pcbnew/tools/pcb_point_editor.cpp | 52 ++++++++++++++++++++++--------- 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/pcbnew/pcb_textbox.cpp b/pcbnew/pcb_textbox.cpp index e0beea3f34..7b1a5ea487 100644 --- a/pcbnew/pcb_textbox.cpp +++ b/pcbnew/pcb_textbox.cpp @@ -251,6 +251,16 @@ void PCB_TEXTBOX::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) { PCB_SHAPE::Rotate( aRotCentre, aAngle ); SetTextAngle( GetTextAngle() + aAngle ); + + if( GetTextAngle().IsCardinal() && GetShape() != SHAPE_T::RECT ) + { + std::vector corners = GetCorners(); + VECTOR2I diag = corners[2] - corners[0]; + + SetShape( SHAPE_T::RECT ); + SetStart( corners[0] ); + SetEnd( VECTOR2I( corners[0].x + abs( diag.x ), corners[0].y + abs( diag.y ) ) ); + } } diff --git a/pcbnew/tools/pcb_point_editor.cpp b/pcbnew/tools/pcb_point_editor.cpp index da015f4904..ca5d6df168 100644 --- a/pcbnew/tools/pcb_point_editor.cpp +++ b/pcbnew/tools/pcb_point_editor.cpp @@ -1631,25 +1631,47 @@ void PCB_POINT_EDITOR::updatePoints() if( !item ) return; - if( item->Type() == PCB_TEXTBOX_T || item->Type() == PCB_FP_TEXTBOX_T ) - { - const PCB_SHAPE* shape = static_cast( item ); - - // We can't currently handle TEXTBOXes that have been turned into SHAPE_T::POLYs due - // to non-cardinal rotations - if( shape->GetShape() != SHAPE_T::RECT ) - { - m_editPoints.reset(); - return; - } - } - switch( item->Type() ) { - case PCB_SHAPE_T: - case PCB_FP_SHAPE_T: case PCB_TEXTBOX_T: case PCB_FP_TEXTBOX_T: + { + const PCB_SHAPE* shape = static_cast( item ); + int target = shape->GetShape() == SHAPE_T::RECT ? 4 : 0; + + // Careful; textbox shape is mutable between cardinal and non-cardinal rotations... + if( int( m_editPoints->PointsSize() ) != target ) + { + getView()->Remove( m_editPoints.get() ); + m_editedPoint = nullptr; + + m_editPoints = makePoints( item ); + + if( m_editPoints ) + getView()->Add( m_editPoints.get() ); + + break; + } + + if( shape->GetShape() == SHAPE_T::RECT ) + { + m_editPoints->Point( RECT_TOP_LEFT ).SetPosition( shape->GetStart() ); + m_editPoints->Point( RECT_TOP_RIGHT ).SetPosition( shape->GetEnd().x, + shape->GetStart().y ); + m_editPoints->Point( RECT_BOT_RIGHT ).SetPosition( shape->GetEnd() ); + m_editPoints->Point( RECT_BOT_LEFT ).SetPosition( shape->GetStart().x, + shape->GetEnd().y ); + } + else if( shape->GetShape() == SHAPE_T::POLY ) + { + // Not currently editable while rotated. + } + + break; + } + + case PCB_SHAPE_T: + case PCB_FP_SHAPE_T: { const PCB_SHAPE* shape = static_cast( item );