Preserve pins positions when resizing sheet

This commit is contained in:
vinsfortunato 2023-01-26 20:56:37 +01:00
parent cf1d17b566
commit 39e85015c2
3 changed files with 44 additions and 7 deletions

View File

@ -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 ) );
}

View File

@ -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;

View File

@ -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;
}