Make sheet pin positions invariant to four rotations more often

This commit is contained in:
Mikolaj Wielgus 2021-11-28 02:16:40 +01:00
parent 4b87c4c21c
commit 65af3a8568
4 changed files with 59 additions and 7 deletions

View File

@ -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;
}
}
}

View File

@ -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).

View File

@ -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<SCH_SHEET_PIN*>( item );
SCH_SHEET* sheet = pin->GetParent();
pin->Rotate( sheet->GetBoundingBox().GetCenter() );
pin->Rotate( sheet->GetBodyBoundingBox().GetCenter() );
}
}
else if( item->Type() == SCH_FIELD_T )

View File

@ -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: