diff --git a/eeschema/sch_sheet_pin.cpp b/eeschema/sch_sheet_pin.cpp index 06519555f7..8f02c8439b 100644 --- a/eeschema/sch_sheet_pin.cpp +++ b/eeschema/sch_sheet_pin.cpp @@ -250,8 +250,52 @@ void SCH_SHEET_PIN::MirrorHorizontally( int aCenter ) void SCH_SHEET_PIN::Rotate( const wxPoint& aCenter ) { wxPoint pt = GetTextPos(); + wxPoint delta = pt - aCenter; + RotatePoint( &pt, aCenter, 900 ); + + SHEET_SIDE oldSide = GetEdge(); ConstrainOnEdge( pt ); + + // If the new side is the same as the old side, instead mirror across the center of that side. + if( GetEdge() == oldSide ) + { + switch( GetEdge() ) + { + case SHEET_SIDE::TOP: + case SHEET_SIDE::BOTTOM: + SetTextPos( wxPoint( aCenter.x - delta.x, GetTextPos().y ) ); + break; + + case SHEET_SIDE::LEFT: + case SHEET_SIDE::RIGHT: + SetTextPos( wxPoint( GetTextPos().x, aCenter.y - delta.y ) ); + break; + + default: + break; + } + } + // If the new side is opposite to the old side, instead mirror across the center of an adjacent + // side. + else if( GetEdge() == GetOppositeSide( oldSide ) ) + { + switch( GetEdge() ) + { + case SHEET_SIDE::TOP: + case SHEET_SIDE::BOTTOM: + SetTextPos( wxPoint( aCenter.x + delta.x, GetTextPos().y ) ); + break; + + case SHEET_SIDE::LEFT: + case SHEET_SIDE::RIGHT: + SetTextPos( wxPoint( GetTextPos().x, aCenter.y + delta.y ) ); + break; + + default: + break; + } + } } diff --git a/eeschema/sch_sheet_pin.h b/eeschema/sch_sheet_pin.h index 335ce37a6e..15f5b6829b 100644 --- a/eeschema/sch_sheet_pin.h +++ b/eeschema/sch_sheet_pin.h @@ -84,6 +84,18 @@ public: bool operator ==( const SCH_SHEET_PIN* aPin ) const; + static SHEET_SIDE GetOppositeSide( SHEET_SIDE aSide ) + { + switch( aSide ) + { + case SHEET_SIDE::TOP: return SHEET_SIDE::BOTTOM; + case SHEET_SIDE::BOTTOM: return SHEET_SIDE::TOP; + case SHEET_SIDE::LEFT: return SHEET_SIDE::RIGHT; + case SHEET_SIDE::RIGHT: return SHEET_SIDE::LEFT; + default: return SHEET_SIDE::UNDEFINED; + } + } + /** * Return true for items which are moved with the anchor point at mouse cursor * and false for items moved with no reference to anchor (usually large items). diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index 6bda0149e2..115a55ad22 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -505,7 +505,7 @@ int SCH_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent ) SCH_SHEET* sheet = pin->GetParent(); for( int i = 0; clockwise ? i < 3 : i < 1; ++i ) - pin->Rotate( sheet->GetBoundingBox().GetCenter() ); + pin->Rotate( sheet->GetBodyBoundingBox().GetCenter() ); break; } @@ -606,7 +606,7 @@ int SCH_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent ) SCH_SHEET_PIN* pin = static_cast( item ); SCH_SHEET* sheet = pin->GetParent(); - pin->Rotate( sheet->GetBoundingBox().GetCenter() ); + pin->Rotate( sheet->GetBodyBoundingBox().GetCenter() ); } } else if( item->Type() == SCH_FIELD_T ) diff --git a/qa/eeschema/test_sch_item.cpp b/qa/eeschema/test_sch_item.cpp index 1fecfd57cb..0b42183957 100644 --- a/qa/eeschema/test_sch_item.cpp +++ b/qa/eeschema/test_sch_item.cpp @@ -78,16 +78,12 @@ static SCH_ITEM* Instatiate( KICAD_T aType, SCH_SHEET* sheet ) case SCH_SYMBOL_T: return new SCH_SYMBOL(); case SCH_SHEET_PIN_T: - { // XXX: Sheet pins need to be manually placed on sheet item side. - SCH_SHEET_PIN* pin = new SCH_SHEET_PIN( + return new SCH_SHEET_PIN( sheet, wxPoint( sheet->GetPosition().x, sheet->GetPosition().y + Millimeter2iu( 40 ) ), "test pin" ); - return pin; - } - case SCH_SHEET_T: case SCH_PIN_T: case SCHEMATIC_T: