Fix sheet rotation issues.

1) When sheet pins are on 3 or more sides there's no point in switching
the orientation to vertical.
2) Careful that we don't cause the sheet to walk when rotating and the
sheet-name or file-name is longer than the side it's on.

Fixes: lp:1841714
* https://bugs.launchpad.net/kicad/+bug/1841714
This commit is contained in:
Jeff Young 2019-09-02 22:34:50 +01:00
parent 4c9e4c947c
commit efbc802f4d
3 changed files with 30 additions and 15 deletions

View File

@ -220,12 +220,22 @@ bool SCH_SHEET::HasPin( const wxString& aName )
bool SCH_SHEET::IsVerticalOrientation() const bool SCH_SHEET::IsVerticalOrientation() const
{ {
int leftRight = 0;
int topBottom = 0;
for( const SCH_SHEET_PIN& pin : m_pins ) for( const SCH_SHEET_PIN& pin : m_pins )
{ {
if( pin.GetEdge() > 1 ) switch( pin.GetEdge() )
return true; {
case SHEET_LEFT_SIDE: leftRight++; break;
case SHEET_RIGHT_SIDE: leftRight++; break;
case SHEET_TOP_SIDE: topBottom++; break;
case SHEET_BOTTOM_SIDE: topBottom++; break;
default: break;
}
} }
return false;
return topBottom > 0 && leftRight == 0;
} }
@ -509,6 +519,13 @@ const EDA_RECT SCH_SHEET::GetBoundingBox() const
} }
wxPoint SCH_SHEET::GetRotationCenter() const
{
EDA_RECT box( m_pos, m_size );
return box.GetCenter();
}
int SCH_SHEET::ComponentCount() int SCH_SHEET::ComponentCount()
{ {
int n = 0; int n = 0;
@ -849,12 +866,6 @@ bool SCH_SHEET::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy )
} }
wxPoint SCH_SHEET::GetResizePosition() const
{
return wxPoint( m_pos.x + m_size.GetWidth(), m_pos.y + m_size.GetHeight() );
}
void SCH_SHEET::GetNetListItem( NETLIST_OBJECT_LIST& aNetListItems, void SCH_SHEET::GetNetListItem( NETLIST_OBJECT_LIST& aNetListItems,
SCH_SHEET_PATH* aSheetPath ) SCH_SHEET_PATH* aSheetPath )
{ {

View File

@ -413,11 +413,11 @@ public:
EDA_RECT const GetBoundingBox() const override; EDA_RECT const GetBoundingBox() const override;
/** /**
* Return the position of the lower right corner of the sheet in drawing units. * Rotating around the boundingBox's center can cause walking when the sheetname or
* * filename is longer than the edge it's on. Use this instead, which always returns
* @return A wxPoint containing lower right corner of the sheet in drawing units. * the center of the sheet itself.
*/ */
wxPoint GetResizePosition() const; wxPoint GetRotationCenter() const;
void SwapData( SCH_ITEM* aItem ) override; void SwapData( SCH_ITEM* aItem ) override;

View File

@ -428,10 +428,14 @@ int SCH_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
break; break;
case SCH_SHEET_T: case SCH_SHEET_T:
{
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
// Rotate the sheet on itself. Sheets do not have an anchor point. // Rotate the sheet on itself. Sheets do not have an anchor point.
rotPoint = m_frame->GetNearestGridPosition( item->GetBoundingBox().Centre() ); rotPoint = m_frame->GetNearestGridPosition( sheet->GetRotationCenter() );
item->Rotate( rotPoint ); sheet->Rotate( rotPoint );
break; break;
}
default: default:
break; break;