Don't allow pins on corners.
Fixes https://gitlab.com/kicad/code/kicad/issues/7917
This commit is contained in:
parent
30fdba4cbb
commit
7e682e9948
|
@ -391,82 +391,79 @@ bool SCH_SHEET::HasUndefinedPins() const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int SCH_SHEET::GetMinWidth() const
|
int bumpToNextGrid( const int aVal, const int aDirection )
|
||||||
{
|
{
|
||||||
int width = Mils2iu( MIN_SHEET_WIDTH );
|
constexpr int gridSize = Mils2iu( 50 );
|
||||||
|
|
||||||
for( size_t i = 0; i < m_pins.size(); i++ )
|
return ( KiROUND( aVal / gridSize ) * gridSize ) + ( aDirection * gridSize );
|
||||||
{
|
|
||||||
int edge = m_pins[i]->GetEdge();
|
|
||||||
EDA_RECT pinRect = m_pins[i]->GetBoundingBox();
|
|
||||||
|
|
||||||
wxASSERT( edge != SHEET_UNDEFINED_SIDE );
|
|
||||||
|
|
||||||
if( edge == SHEET_TOP_SIDE || edge == SHEET_BOTTOM_SIDE )
|
|
||||||
{
|
|
||||||
if( width < pinRect.GetRight() - m_pos.x )
|
|
||||||
width = pinRect.GetRight() - m_pos.x;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if( width < pinRect.GetWidth() )
|
|
||||||
width = pinRect.GetWidth();
|
|
||||||
|
|
||||||
for( size_t j = 0; j < m_pins.size(); j++ )
|
|
||||||
{
|
|
||||||
// Check for pin directly across from the current pin.
|
|
||||||
if( (i == j) || (m_pins[i]->GetPosition().y != m_pins[j]->GetPosition().y) )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if( width < pinRect.GetWidth() + m_pins[j]->GetBoundingBox().GetWidth() )
|
|
||||||
{
|
|
||||||
width = pinRect.GetWidth() + m_pins[j]->GetBoundingBox().GetWidth();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return width;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int SCH_SHEET::GetMinHeight() const
|
int SCH_SHEET::GetMinWidth( bool aFromLeft ) const
|
||||||
{
|
{
|
||||||
int height = Mils2iu( MIN_SHEET_HEIGHT );
|
int pinsLeft = m_pos.x + m_size.x;
|
||||||
|
int pinsRight = m_pos.x;
|
||||||
|
|
||||||
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();
|
||||||
|
|
||||||
|
if( edge == SHEET_TOP_SIDE || edge == SHEET_BOTTOM_SIDE )
|
||||||
|
{
|
||||||
EDA_RECT pinRect = m_pins[i]->GetBoundingBox();
|
EDA_RECT pinRect = m_pins[i]->GetBoundingBox();
|
||||||
|
|
||||||
// Make sure pin is on top or bottom side of sheet.
|
pinsLeft = std::min( pinsLeft, pinRect.GetLeft() );
|
||||||
|
pinsRight = std::max( pinsRight, pinRect.GetRight() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pinsLeft = bumpToNextGrid( pinsLeft, -1 );
|
||||||
|
pinsRight = bumpToNextGrid( pinsRight, 1 );
|
||||||
|
|
||||||
|
int pinMinWidth;
|
||||||
|
|
||||||
|
if( pinsLeft >= pinsRight )
|
||||||
|
pinMinWidth = 0;
|
||||||
|
else if( aFromLeft )
|
||||||
|
pinMinWidth = pinsRight - m_pos.x;
|
||||||
|
else
|
||||||
|
pinMinWidth = m_pos.x + m_size.x - pinsLeft;
|
||||||
|
|
||||||
|
return std::max( pinMinWidth, Mils2iu( MIN_SHEET_WIDTH ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int SCH_SHEET::GetMinHeight( bool aFromTop ) const
|
||||||
|
{
|
||||||
|
int pinsTop = m_pos.y + m_size.y;
|
||||||
|
int pinsBottom = m_pos.y;
|
||||||
|
|
||||||
|
for( size_t i = 0; i < m_pins.size(); i++ )
|
||||||
|
{
|
||||||
|
int edge = m_pins[i]->GetEdge();
|
||||||
|
|
||||||
if( edge == SHEET_RIGHT_SIDE || edge == SHEET_LEFT_SIDE )
|
if( edge == SHEET_RIGHT_SIDE || edge == SHEET_LEFT_SIDE )
|
||||||
{
|
{
|
||||||
if( height < pinRect.GetBottom() - m_pos.y )
|
EDA_RECT pinRect = m_pins[i]->GetBoundingBox();
|
||||||
height = pinRect.GetBottom() - m_pos.y;
|
|
||||||
|
pinsTop = std::min( pinsTop, pinRect.GetTop() );
|
||||||
|
pinsBottom = std::max( pinsBottom, pinRect.GetBottom() );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pinsTop = bumpToNextGrid( pinsTop, -1 );
|
||||||
|
pinsBottom = bumpToNextGrid( pinsBottom, 1 );
|
||||||
|
|
||||||
|
int pinMinHeight;
|
||||||
|
|
||||||
|
if( pinsTop >= pinsBottom )
|
||||||
|
pinMinHeight = 0;
|
||||||
|
else if( aFromTop )
|
||||||
|
pinMinHeight = pinsBottom - m_pos.y;
|
||||||
else
|
else
|
||||||
{
|
pinMinHeight = m_pos.y + m_size.y - pinsTop;
|
||||||
if( height < pinRect.GetHeight() )
|
|
||||||
height = pinRect.GetHeight();
|
|
||||||
|
|
||||||
for( size_t j = 0; j < m_pins.size(); j++ )
|
return std::max( pinMinHeight, Mils2iu( MIN_SHEET_HEIGHT ) );
|
||||||
{
|
|
||||||
// Check for pin directly above or below the current pin.
|
|
||||||
if( (i == j) || (m_pins[i]->GetPosition().x != m_pins[j]->GetPosition().x) )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if( height < pinRect.GetHeight() + m_pins[j]->GetBoundingBox().GetHeight() )
|
|
||||||
{
|
|
||||||
height = pinRect.GetHeight() + m_pins[j]->GetBoundingBox().GetHeight();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return height;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -422,7 +422,7 @@ public:
|
||||||
*
|
*
|
||||||
* @return The minimum width the sheet can be resized.
|
* @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.
|
* Return the minimum height that the sheet can be resized based on the sheet pin positions.
|
||||||
|
@ -434,7 +434,7 @@ public:
|
||||||
*
|
*
|
||||||
* @return The minimum height the sheet can be resized.
|
* @return The minimum height the sheet can be resized.
|
||||||
*/
|
*/
|
||||||
int GetMinHeight() const;
|
int GetMinHeight( bool aFromTop ) const;
|
||||||
|
|
||||||
int GetPenWidth() const override;
|
int GetPenWidth() const override;
|
||||||
|
|
||||||
|
|
|
@ -563,7 +563,11 @@ void EE_POINT_EDITOR::updateParentItem() const
|
||||||
// connected items (sheet pins), keep corners coordinates on this grid.
|
// connected items (sheet pins), keep corners coordinates on this grid.
|
||||||
// Otherwise, some sheet pins can be moved off grid
|
// Otherwise, some sheet pins can be moved off grid
|
||||||
int grid_size = Mils2iu( 50 );
|
int grid_size = Mils2iu( 50 );
|
||||||
pinEditedCorner( getEditedPointIndex(), sheet->GetMinWidth(), sheet->GetMinHeight(),
|
int edited = getEditedPointIndex();
|
||||||
|
|
||||||
|
pinEditedCorner( getEditedPointIndex(),
|
||||||
|
sheet->GetMinWidth( edited == RECT_TOPRIGHT || edited == RECT_BOTRIGHT ),
|
||||||
|
sheet->GetMinHeight( edited == RECT_BOTLEFT || edited == RECT_BOTRIGHT ),
|
||||||
topLeft, topRight, botLeft, botRight, grid_size );
|
topLeft, topRight, botLeft, botRight, grid_size );
|
||||||
|
|
||||||
// Pin positions are relative to origin. Attempt to leave them where they
|
// Pin positions are relative to origin. Attempt to leave them where they
|
||||||
|
|
Loading…
Reference in New Issue