Disallow sheet pins from changing sides when edited by point editor.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/15057
This commit is contained in:
Jeff Young 2023-06-25 19:54:58 +01:00
parent 40fcfe891d
commit ed6487da1e
6 changed files with 38 additions and 37 deletions

View File

@ -813,6 +813,17 @@ void SCH_SHEET::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_I
}
void SCH_SHEET::SetPositionIgnoringPins( const VECTOR2I& aPosition )
{
VECTOR2I delta = aPosition - m_pos;
m_pos = aPosition;
for( SCH_FIELD& field : m_fields )
field.Move( delta );
}
void SCH_SHEET::Move( const VECTOR2I& aMoveVector )
{
m_pos += aMoveVector;
@ -928,7 +939,7 @@ void SCH_SHEET::Resize( const VECTOR2I& aSize )
// Move the sheet labels according to the new sheet size.
for( SCH_SHEET_PIN* sheetPin : m_pins )
sheetPin->ConstrainOnEdge( sheetPin->GetPosition() );
sheetPin->ConstrainOnEdge( sheetPin->GetPosition(), false );
}

View File

@ -169,6 +169,8 @@ public:
*/
bool IsVerticalOrientation() const;
void SetPositionIgnoringPins( const VECTOR2I& aPosition );
/**
* Add aSheetPin to the sheet.
*

View File

@ -153,7 +153,7 @@ enum SHEET_SIDE SCH_SHEET_PIN::GetSide() const
}
void SCH_SHEET_PIN::ConstrainOnEdge( VECTOR2I Pos )
void SCH_SHEET_PIN::ConstrainOnEdge( VECTOR2I aPos, bool aAllowEdgeSwitch )
{
SCH_SHEET* sheet = GetParent();
@ -173,20 +173,27 @@ void SCH_SHEET_PIN::ConstrainOnEdge( VECTOR2I Pos )
sheetEdge.Append( leftSide, botSide );
sheetEdge.Append( leftSide, topSide );
switch( sheetEdge.NearestSegment( Pos ) )
if( aAllowEdgeSwitch )
{
case 0: SetSide( SHEET_SIDE::TOP ); break;
case 1: SetSide( SHEET_SIDE::RIGHT ); break;
case 2: SetSide( SHEET_SIDE::BOTTOM ); break;
case 3: SetSide( SHEET_SIDE::LEFT ); break;
default: wxASSERT( "Invalid segment number" );
switch( sheetEdge.NearestSegment( aPos ) )
{
case 0: SetSide( SHEET_SIDE::TOP ); break;
case 1: SetSide( SHEET_SIDE::RIGHT ); break;
case 2: SetSide( SHEET_SIDE::BOTTOM ); break;
case 3: SetSide( SHEET_SIDE::LEFT ); break;
default: wxASSERT( "Invalid segment number" );
}
}
else
{
SetSide( GetSide() );
}
switch( GetSide() )
{
case SHEET_SIDE::RIGHT:
case SHEET_SIDE::LEFT:
SetTextY( Pos.y );
SetTextY( aPos.y );
if( GetTextPos().y < topSide )
SetTextY( topSide );
@ -198,7 +205,7 @@ void SCH_SHEET_PIN::ConstrainOnEdge( VECTOR2I Pos )
case SHEET_SIDE::BOTTOM:
case SHEET_SIDE::TOP:
SetTextX( Pos.x );
SetTextX( aPos.x );
if( GetTextPos().x < leftSide )
SetTextX( leftSide );
@ -252,7 +259,7 @@ void SCH_SHEET_PIN::Rotate( const VECTOR2I& aCenter )
RotatePoint( pt, aCenter, ANGLE_90 );
SHEET_SIDE oldSide = GetSide();
ConstrainOnEdge( pt );
ConstrainOnEdge( pt, true );
// If the new side is the same as the old side, instead mirror across the center of that side.
if( GetSide() == oldSide )

View File

@ -141,7 +141,7 @@ public:
* Adjust label position to edge based on proximity to vertical or horizontal edge
* of the parent sheet.
*/
void ConstrainOnEdge( VECTOR2I Pos );
void ConstrainOnEdge( VECTOR2I aPos, bool aAllowEdgeSwitch );
/**
* Get the parent sheet object of this sheet pin.
@ -186,7 +186,10 @@ public:
BITMAPS GetMenuImage() const override;
void SetPosition( const VECTOR2I& aPosition ) override { ConstrainOnEdge( aPosition ); }
void SetPosition( const VECTOR2I& aPosition ) override
{
ConstrainOnEdge( aPosition, true );
}
bool IsPointClickableAnchor( const VECTOR2I& aPos ) const override
{

View File

@ -1035,32 +1035,10 @@ void EE_POINT_EDITOR::updateParentItem( bool aSnapToGrid ) const
}
if( sheet->GetPosition() != sheetNewPos )
{
//Keep pins in the place they were before resizing
for( SCH_SHEET_PIN* pin : sheet->GetPins() )
{
switch( pin->GetSide() )
{
case SHEET_SIDE::LEFT:
case SHEET_SIDE::RIGHT:
pin->Move( VECTOR2I( 0, sheet->GetPosition().y - sheetNewPos.y ) );
break;
case SHEET_SIDE::TOP:
case SHEET_SIDE::BOTTOM:
pin->Move( VECTOR2I( sheet->GetPosition().x - sheetNewPos.x, 0 ) );
break;
case SHEET_SIDE::UNDEFINED:
break;
}
}
sheet->SetPosition( sheetNewPos );
}
sheet->SetPositionIgnoringPins( sheetNewPos );
if( sheet->GetSize() != sheetNewSize )
{
sheet->Resize( sheetNewSize );
}
break;
}

View File

@ -1555,7 +1555,7 @@ void SCH_MOVE_TOOL::moveItem( EDA_ITEM* aItem, const VECTOR2I& aDelta )
SCH_SHEET_PIN* pin = (SCH_SHEET_PIN*) aItem;
pin->SetStoredPos( pin->GetStoredPos() + aDelta );
pin->ConstrainOnEdge( pin->GetStoredPos() );
pin->ConstrainOnEdge( pin->GetStoredPos(), true );
break;
}