From 39e85015c2bd270c5ec0b681934bc618cc7a71ae Mon Sep 17 00:00:00 2001 From: vinsfortunato Date: Thu, 26 Jan 2023 20:56:37 +0100 Subject: [PATCH] Preserve pins positions when resizing sheet --- eeschema/sch_sheet.cpp | 12 ++++++---- eeschema/sch_sheet.h | 4 ++-- eeschema/tools/ee_point_editor.cpp | 35 +++++++++++++++++++++++++++++- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index fc7fe5e520..216ffc8d82 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -481,7 +481,7 @@ int bumpToNextGrid( const int aVal, const int aDirection ) } -int SCH_SHEET::GetMinWidth() const +int SCH_SHEET::GetMinWidth( bool aFromLeft ) const { int pinsLeft = m_pos.x + m_size.x; int pinsRight = m_pos.x; @@ -506,14 +506,16 @@ int SCH_SHEET::GetMinWidth() const if( pinsLeft >= pinsRight ) pinMinWidth = 0; - else + else if( aFromLeft ) pinMinWidth = pinsRight - m_pos.x; + else + pinMinWidth = m_pos.x + m_size.x - pinsLeft; return std::max( pinMinWidth, schIUScale.MilsToIU( MIN_SHEET_WIDTH ) ); } -int SCH_SHEET::GetMinHeight() const +int SCH_SHEET::GetMinHeight( bool aFromTop ) const { int pinsTop = m_pos.y + m_size.y; int pinsBottom = m_pos.y; @@ -538,8 +540,10 @@ int SCH_SHEET::GetMinHeight() const if( pinsTop >= pinsBottom ) pinMinHeight = 0; - else + else if( aFromTop ) pinMinHeight = pinsBottom - m_pos.y; + else + pinMinHeight = m_pos.y + m_size.y - pinsTop; return std::max( pinMinHeight, schIUScale.MilsToIU( MIN_SHEET_HEIGHT ) ); } diff --git a/eeschema/sch_sheet.h b/eeschema/sch_sheet.h index 3ff7897cc0..7a4a06ab26 100644 --- a/eeschema/sch_sheet.h +++ b/eeschema/sch_sheet.h @@ -227,7 +227,7 @@ public: * * @return The minimum width the sheet can be resized. */ - int GetMinWidth() const; + int GetMinWidth( bool aFromLeft ) const; /** * Return the minimum height that the sheet can be resized based on the sheet pin positions. @@ -239,7 +239,7 @@ public: * * @return The minimum height the sheet can be resized. */ - int GetMinHeight() const; + int GetMinHeight( bool aFromTop ) const; int GetPenWidth() const override; diff --git a/eeschema/tools/ee_point_editor.cpp b/eeschema/tools/ee_point_editor.cpp index b80f9dcbb4..0f37a65a4e 100644 --- a/eeschema/tools/ee_point_editor.cpp +++ b/eeschema/tools/ee_point_editor.cpp @@ -980,10 +980,21 @@ void EE_POINT_EDITOR::updateParentItem( bool aSnapToGrid ) const VECTOR2I topRight = m_editPoints->Point( RECT_TOPRIGHT ).GetPosition(); VECTOR2I botLeft = m_editPoints->Point( RECT_BOTLEFT ).GetPosition(); VECTOR2I botRight = m_editPoints->Point( RECT_BOTRIGHT ).GetPosition(); + VECTOR2I sheetPrevPos = sheet->GetPosition(); gridHelper.SetSnap( aSnapToGrid ); - pinEditedCorner( sheet->GetMinWidth(), sheet->GetMinHeight(), + int edited = getEditedPointIndex(); + + if( isModified( m_editPoints->Line( RECT_RIGHT ) ) ) + edited = RECT_TOPRIGHT; + else if( isModified( m_editPoints->Line( RECT_BOT ) ) ) + edited = RECT_BOTLEFT; + + gridHelper.SetSnap( aSnapToGrid ); + + pinEditedCorner( sheet->GetMinWidth( edited == RECT_TOPRIGHT || edited == RECT_BOTRIGHT ), + sheet->GetMinHeight( edited == RECT_BOTLEFT || edited == RECT_BOTRIGHT ), topLeft, topRight, botLeft, botRight, &gridHelper ); if( isModified( m_editPoints->Point( RECT_TOPLEFT ) ) @@ -1021,6 +1032,28 @@ void EE_POINT_EDITOR::updateParentItem( bool aSnapToGrid ) const new EC_PERPLINE( m_editPoints->Line( i ) ) ); } } + + //Keep pins in the place they were before resizing + if( sheet->GetPosition() != sheetPrevPos ) + { + for( SCH_SHEET_PIN* pin : sheet->GetPins() ) + { + switch( pin->GetSide() ) + { + case SHEET_SIDE::LEFT: + case SHEET_SIDE::RIGHT: + pin->Move( VECTOR2I( 0, sheetPrevPos.y - sheet->GetPosition().y) ); + break; + case SHEET_SIDE::TOP: + case SHEET_SIDE::BOTTOM: + pin->Move( VECTOR2I( sheetPrevPos.x - sheet->GetPosition().x, 0) ); + break; + case SHEET_SIDE::UNDEFINED: + break; + } + } + } + break; }