From efbc802f4de73375d6a033e28008c4442281104a Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 2 Sep 2019 22:34:50 +0100 Subject: [PATCH] Fix sheet rotation issues. 1) When sheet pins are on 3 or more sides there's no point in switching the orientation to vertical. 2) Careful that we don't cause the sheet to walk when rotating and the sheet-name or file-name is longer than the side it's on. Fixes: lp:1841714 * https://bugs.launchpad.net/kicad/+bug/1841714 --- eeschema/sch_sheet.cpp | 29 ++++++++++++++++++++--------- eeschema/sch_sheet.h | 8 ++++---- eeschema/tools/sch_edit_tool.cpp | 8 ++++++-- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index 29155bc807..70e9c01b47 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -220,12 +220,22 @@ bool SCH_SHEET::HasPin( const wxString& aName ) bool SCH_SHEET::IsVerticalOrientation() const { + int leftRight = 0; + int topBottom = 0; + for( const SCH_SHEET_PIN& pin : m_pins ) { - if( pin.GetEdge() > 1 ) - return true; + switch( pin.GetEdge() ) + { + case SHEET_LEFT_SIDE: leftRight++; break; + case SHEET_RIGHT_SIDE: leftRight++; break; + case SHEET_TOP_SIDE: topBottom++; break; + case SHEET_BOTTOM_SIDE: topBottom++; break; + default: break; + } } - return false; + + return topBottom > 0 && leftRight == 0; } @@ -509,6 +519,13 @@ const EDA_RECT SCH_SHEET::GetBoundingBox() const } +wxPoint SCH_SHEET::GetRotationCenter() const +{ + EDA_RECT box( m_pos, m_size ); + return box.GetCenter(); +} + + int SCH_SHEET::ComponentCount() { int n = 0; @@ -849,12 +866,6 @@ bool SCH_SHEET::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) } -wxPoint SCH_SHEET::GetResizePosition() const -{ - return wxPoint( m_pos.x + m_size.GetWidth(), m_pos.y + m_size.GetHeight() ); -} - - void SCH_SHEET::GetNetListItem( NETLIST_OBJECT_LIST& aNetListItems, SCH_SHEET_PATH* aSheetPath ) { diff --git a/eeschema/sch_sheet.h b/eeschema/sch_sheet.h index 892a74020b..95a15be945 100644 --- a/eeschema/sch_sheet.h +++ b/eeschema/sch_sheet.h @@ -413,11 +413,11 @@ public: EDA_RECT const GetBoundingBox() const override; /** - * Return the position of the lower right corner of the sheet in drawing units. - * - * @return A wxPoint containing lower right corner of the sheet in drawing units. + * Rotating around the boundingBox's center can cause walking when the sheetname or + * filename is longer than the edge it's on. Use this instead, which always returns + * the center of the sheet itself. */ - wxPoint GetResizePosition() const; + wxPoint GetRotationCenter() const; void SwapData( SCH_ITEM* aItem ) override; diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index b1ea231ac0..c31fade111 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -428,10 +428,14 @@ int SCH_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent ) break; case SCH_SHEET_T: + { + SCH_SHEET* sheet = static_cast( item ); + // Rotate the sheet on itself. Sheets do not have an anchor point. - rotPoint = m_frame->GetNearestGridPosition( item->GetBoundingBox().Centre() ); - item->Rotate( rotPoint ); + rotPoint = m_frame->GetNearestGridPosition( sheet->GetRotationCenter() ); + sheet->Rotate( rotPoint ); break; + } default: break;