Fix unexpected resizing behaviour when using top left edit corner

This commit is contained in:
vinsfortunato 2023-01-26 17:13:25 +01:00
parent 843600cb7e
commit cf1d17b566
3 changed files with 12 additions and 45 deletions

View File

@ -481,7 +481,7 @@ int bumpToNextGrid( const int aVal, const int aDirection )
} }
int SCH_SHEET::GetMinWidth( bool aFromLeft ) const int SCH_SHEET::GetMinWidth() const
{ {
int pinsLeft = m_pos.x + m_size.x; int pinsLeft = m_pos.x + m_size.x;
int pinsRight = m_pos.x; int pinsRight = m_pos.x;
@ -506,16 +506,14 @@ int SCH_SHEET::GetMinWidth( bool aFromLeft ) const
if( pinsLeft >= pinsRight ) if( pinsLeft >= pinsRight )
pinMinWidth = 0; pinMinWidth = 0;
else if( aFromLeft )
pinMinWidth = pinsRight - m_pos.x;
else else
pinMinWidth = m_pos.x + m_size.x - pinsLeft; pinMinWidth = pinsRight - m_pos.x;
return std::max( pinMinWidth, schIUScale.MilsToIU( MIN_SHEET_WIDTH ) ); return std::max( pinMinWidth, schIUScale.MilsToIU( MIN_SHEET_WIDTH ) );
} }
int SCH_SHEET::GetMinHeight( bool aFromTop ) const int SCH_SHEET::GetMinHeight() const
{ {
int pinsTop = m_pos.y + m_size.y; int pinsTop = m_pos.y + m_size.y;
int pinsBottom = m_pos.y; int pinsBottom = m_pos.y;
@ -540,10 +538,8 @@ int SCH_SHEET::GetMinHeight( bool aFromTop ) const
if( pinsTop >= pinsBottom ) if( pinsTop >= pinsBottom )
pinMinHeight = 0; pinMinHeight = 0;
else if( aFromTop )
pinMinHeight = pinsBottom - m_pos.y;
else else
pinMinHeight = m_pos.y + m_size.y - pinsTop; pinMinHeight = pinsBottom - m_pos.y;
return std::max( pinMinHeight, schIUScale.MilsToIU( MIN_SHEET_HEIGHT ) ); 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. * @return The minimum width the sheet can be resized.
*/ */
int GetMinWidth( bool aFromLeft ) const; int GetMinWidth() const;
/** /**
* Return the minimum height that the sheet can be resized based on the sheet pin positions. * 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. * @return The minimum height the sheet can be resized.
*/ */
int GetMinHeight( bool aFromTop ) const; int GetMinHeight() const;
int GetPenWidth() const override; int GetPenWidth() const override;

View File

@ -980,17 +980,10 @@ void EE_POINT_EDITOR::updateParentItem( bool aSnapToGrid ) const
VECTOR2I topRight = m_editPoints->Point( RECT_TOPRIGHT ).GetPosition(); VECTOR2I topRight = m_editPoints->Point( RECT_TOPRIGHT ).GetPosition();
VECTOR2I botLeft = m_editPoints->Point( RECT_BOTLEFT ).GetPosition(); VECTOR2I botLeft = m_editPoints->Point( RECT_BOTLEFT ).GetPosition();
VECTOR2I botRight = m_editPoints->Point( RECT_BOTRIGHT ).GetPosition(); VECTOR2I botRight = m_editPoints->Point( RECT_BOTRIGHT ).GetPosition();
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 ); gridHelper.SetSnap( aSnapToGrid );
pinEditedCorner( sheet->GetMinWidth( edited == RECT_TOPRIGHT || edited == RECT_BOTRIGHT ), pinEditedCorner( sheet->GetMinWidth(), sheet->GetMinHeight(),
sheet->GetMinHeight( edited == RECT_BOTLEFT || edited == RECT_BOTRIGHT ),
topLeft, topRight, botLeft, botRight, &gridHelper ); topLeft, topRight, botLeft, botRight, &gridHelper );
if( isModified( m_editPoints->Point( RECT_TOPLEFT ) ) if( isModified( m_editPoints->Point( RECT_TOPLEFT ) )
@ -999,25 +992,25 @@ void EE_POINT_EDITOR::updateParentItem( bool aSnapToGrid ) const
|| isModified( m_editPoints->Point( RECT_BOTLEFT ) ) ) || isModified( m_editPoints->Point( RECT_BOTLEFT ) ) )
{ {
sheet->SetPosition( topLeft ); sheet->SetPosition( topLeft );
sheet->SetSize( wxSize( botRight.x - topLeft.x, botRight.y - topLeft.y ) ); sheet->Resize( wxSize( botRight.x - topLeft.x, botRight.y - topLeft.y ) );
} }
else if( isModified( m_editPoints->Line( RECT_TOP ) ) ) else if( isModified( m_editPoints->Line( RECT_TOP ) ) )
{ {
sheet->SetPosition( VECTOR2I( sheet->GetPosition().x, topLeft.y ) ); sheet->SetPosition( VECTOR2I( sheet->GetPosition().x, topLeft.y ) );
sheet->SetSize( wxSize( sheet->GetSize().x, botRight.y - topLeft.y ) ); sheet->Resize( wxSize( sheet->GetSize().x, botRight.y - topLeft.y ) );
} }
else if( isModified( m_editPoints->Line( RECT_LEFT ) ) ) else if( isModified( m_editPoints->Line( RECT_LEFT ) ) )
{ {
sheet->SetPosition( VECTOR2I( topLeft.x, sheet->GetPosition().y ) ); sheet->SetPosition( VECTOR2I( topLeft.x, sheet->GetPosition().y ) );
sheet->SetSize( wxSize( botRight.x - topLeft.x, sheet->GetSize().y ) ); sheet->Resize( wxSize( botRight.x - topLeft.x, sheet->GetSize().y ) );
} }
else if( isModified( m_editPoints->Line( RECT_BOT ) ) ) else if( isModified( m_editPoints->Line( RECT_BOT ) ) )
{ {
sheet->SetSize( wxSize( sheet->GetSize().x, botRight.y - topLeft.y ) ); sheet->Resize( wxSize( sheet->GetSize().x, botRight.y - topLeft.y ) );
} }
else if( isModified( m_editPoints->Line( RECT_RIGHT ) ) ) else if( isModified( m_editPoints->Line( RECT_RIGHT ) ) )
{ {
sheet->SetSize( wxSize( botRight.x - topLeft.x, sheet->GetSize().y ) ); sheet->Resize( wxSize( botRight.x - topLeft.x, sheet->GetSize().y ) );
} }
for( unsigned i = 0; i < m_editPoints->LinesSize(); ++i ) for( unsigned i = 0; i < m_editPoints->LinesSize(); ++i )
@ -1028,28 +1021,6 @@ void EE_POINT_EDITOR::updateParentItem( bool aSnapToGrid ) const
new EC_PERPLINE( m_editPoints->Line( i ) ) ); new EC_PERPLINE( m_editPoints->Line( i ) ) );
} }
} }
// Keep sheet pins attached to edges:
for( SCH_SHEET_PIN* pin : sheet->GetPins() )
{
VECTOR2I pos = pin->GetPosition();
switch( pin->GetSide() )
{
case SHEET_SIDE::LEFT: pos.x = topLeft.x; break;
case SHEET_SIDE::RIGHT: pos.x = topRight.x; break;
case SHEET_SIDE::TOP: pos.y = topLeft.y; break;
case SHEET_SIDE::BOTTOM: pos.y = botLeft.y; break;
case SHEET_SIDE::UNDEFINED: break;
}
pin->SetPosition( pos );
}
// Update the fields if we're in autoplace mode
if( sheet->GetFieldsAutoplaced() == FIELDS_AUTOPLACED_AUTO )
sheet->AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false );
break; break;
} }