Better fix for schematic sheet re-sizing bug.

Use sheet pin direction to calculate sheet minimum height and width.

Remove sheet pin offsetting as the new sheet height and width calculation
prevents invalid minimums.
This commit is contained in:
Wayne Stambaugh 2017-08-23 18:33:27 -04:00
parent e176fc181d
commit 33048e709a
2 changed files with 45 additions and 35 deletions

View File

@ -446,15 +446,19 @@ int SCH_SHEET::GetMinWidth() const
for( size_t i = 0; i < m_pins.size(); i++ ) for( size_t i = 0; i < m_pins.size(); i++ )
{ {
int edge = m_pins[i].GetEdge(); int edge = m_pins[i].GetEdge();
EDA_RECT pinRect = m_pins[i].GetBoundingBox();
// Make sure pin is on right or left side of sheet. wxASSERT( edge != SCH_SHEET_PIN::SHEET_UNDEFINED_SIDE );
if( edge >= 2 )
continue;
EDA_RECT rect = m_pins[i].GetBoundingBox(); if( edge == SCH_SHEET_PIN::SHEET_TOP_SIDE || edge == SCH_SHEET_PIN::SHEET_BOTTOM_SIDE )
{
if( width < rect.GetWidth() ) if( width < pinRect.GetRight() - m_pos.x )
width = rect.GetWidth(); width = pinRect.GetRight() - m_pos.x;
}
else
{
if( width < pinRect.GetWidth() )
width = pinRect.GetWidth();
for( size_t j = 0; j < m_pins.size(); j++ ) for( size_t j = 0; j < m_pins.size(); j++ )
{ {
@ -462,13 +466,14 @@ int SCH_SHEET::GetMinWidth() const
if( (i == j) || (m_pins[i].GetPosition().y != m_pins[j].GetPosition().y) ) if( (i == j) || (m_pins[i].GetPosition().y != m_pins[j].GetPosition().y) )
continue; continue;
if( width < rect.GetWidth() + m_pins[j].GetBoundingBox().GetWidth() ) if( width < pinRect.GetWidth() + m_pins[j].GetBoundingBox().GetWidth() )
{ {
width = rect.GetWidth() + m_pins[j].GetBoundingBox().GetWidth(); width = pinRect.GetWidth() + m_pins[j].GetBoundingBox().GetWidth();
break; break;
} }
} }
} }
}
return width; return width;
} }
@ -481,15 +486,18 @@ int SCH_SHEET::GetMinHeight() const
for( size_t i = 0; i < m_pins.size(); i++ ) for( size_t i = 0; i < m_pins.size(); i++ )
{ {
int edge = m_pins[i].GetEdge(); int edge = m_pins[i].GetEdge();
EDA_RECT pinRect = m_pins[i].GetBoundingBox();
// Make sure pin is on top or bottom side of sheet. // Make sure pin is on top or bottom side of sheet.
if( edge < 2 ) if( edge == SCH_SHEET_PIN::SHEET_RIGHT_SIDE || edge == SCH_SHEET_PIN::SHEET_LEFT_SIDE )
continue; {
if( height < pinRect.GetBottom() - m_pos.y )
EDA_RECT rect = m_pins[i].GetBoundingBox(); height = pinRect.GetBottom() - m_pos.y;
}
if( height < rect.GetHeight() ) else
height = rect.GetHeight(); {
if( height < pinRect.GetHeight() )
height = pinRect.GetHeight();
for( size_t j = 0; j < m_pins.size(); j++ ) for( size_t j = 0; j < m_pins.size(); j++ )
{ {
@ -497,13 +505,14 @@ int SCH_SHEET::GetMinHeight() const
if( (i == j) || (m_pins[i].GetPosition().x != m_pins[j].GetPosition().x) ) if( (i == j) || (m_pins[i].GetPosition().x != m_pins[j].GetPosition().x) )
continue; continue;
if( height < rect.GetHeight() + m_pins[j].GetBoundingBox().GetHeight() ) if( height < pinRect.GetHeight() + m_pins[j].GetBoundingBox().GetHeight() )
{ {
height = rect.GetHeight() + m_pins[j].GetBoundingBox().GetHeight(); height = pinRect.GetHeight() + m_pins[j].GetBoundingBox().GetHeight();
break; break;
} }
} }
} }
}
return height; return height;
} }
@ -659,10 +668,11 @@ void SCH_SHEET::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
} }
#if 0 #if 1
// Only for testing purposes, draw the component bounding box // Only for testing purposes, draw the component bounding box
EDA_RECT boundingBox = GetBoundingBox(); EDA_RECT boundingBox = GetBoundingBox();
GRRect( aPanel->GetClipBox(), aDC, boundingBox, 0, BROWN ); GRRect( aPanel->GetClipBox(), aDC, boundingBox, 0, BROWN );
GRFilledCircle( aPanel->GetClipBox(), aDC, m_pos.x, m_pos.y, 10, 0, color, color );
#endif #endif
} }

View File

@ -184,10 +184,10 @@ void SCH_SHEET_PIN::ConstrainOnEdge( wxPoint Pos )
SetTextY( Pos.y ); SetTextY( Pos.y );
if( GetTextPos().y < sheet->m_pos.y ) if( GetTextPos().y < sheet->m_pos.y )
SetTextY( sheet->m_pos.y + 50 ); SetTextY( sheet->m_pos.y );
if( GetTextPos().y > (sheet->m_pos.y + sheet->m_size.y) ) if( GetTextPos().y > (sheet->m_pos.y + sheet->m_size.y) )
SetTextY( sheet->m_pos.y + sheet->m_size.y - 50 ); SetTextY( sheet->m_pos.y + sheet->m_size.y );
} }
else else
{ {
@ -203,10 +203,10 @@ void SCH_SHEET_PIN::ConstrainOnEdge( wxPoint Pos )
SetTextX( Pos.x ); SetTextX( Pos.x );
if( GetTextPos().x < sheet->m_pos.x ) if( GetTextPos().x < sheet->m_pos.x )
SetTextX( sheet->m_pos.x + 50 ); SetTextX( sheet->m_pos.x );
if( GetTextPos().x > (sheet->m_pos.x + sheet->m_size.x) ) if( GetTextPos().x > (sheet->m_pos.x + sheet->m_size.x) )
SetTextX( sheet->m_pos.x + sheet->m_size.x - 50 ); SetTextX( sheet->m_pos.x + sheet->m_size.x );
} }
} }