Repair point editing of rotated text boxes.

Fixes https://gitlab.com/kicad/code/kicad/issues/11432
This commit is contained in:
Jeff Young 2022-06-02 10:42:13 +01:00
parent f8829de5ea
commit de12c63de6
6 changed files with 200 additions and 26 deletions

View File

@ -113,8 +113,8 @@ public:
* Return the starting point of the graphic. * Return the starting point of the graphic.
*/ */
const VECTOR2I& GetStart() const { return m_start; } const VECTOR2I& GetStart() const { return m_start; }
int GetStartY() { return m_start.y; } int GetStartY() const { return m_start.y; }
int GetStartX() { return m_start.x; } int GetStartX() const { return m_start.x; }
void SetStart( const VECTOR2I& aStart ) void SetStart( const VECTOR2I& aStart )
{ {
@ -138,8 +138,8 @@ public:
* Return the ending point of the graphic. * Return the ending point of the graphic.
*/ */
const VECTOR2I& GetEnd() const { return m_end; } const VECTOR2I& GetEnd() const { return m_end; }
int GetEndY() { return m_end.y; } int GetEndY() const { return m_end.y; }
int GetEndX() { return m_end.x; } int GetEndX() const { return m_end.x; }
void SetEnd( const VECTOR2I& aEnd ) void SetEnd( const VECTOR2I& aEnd )
{ {
@ -159,6 +159,14 @@ public:
m_endsSwapped = false; m_endsSwapped = false;
} }
virtual VECTOR2I GetTopLeft() const { return GetStart(); }
virtual VECTOR2I GetBotRight() const { return GetEnd(); }
virtual void SetTop( int val ) { SetStartY( val ); }
virtual void SetLeft( int val ) { SetStartX( val ); }
virtual void SetRight( int val ) { SetEndX( val ); }
virtual void SetBottom( int val ) { SetEndY( val ); }
void SetBezierC1( const VECTOR2I& aPt ) { m_bezierC1 = aPt; } void SetBezierC1( const VECTOR2I& aPt ) { m_bezierC1 = aPt; }
const VECTOR2I& GetBezierC1() const { return m_bezierC1; } const VECTOR2I& GetBezierC1() const { return m_bezierC1; }

View File

@ -60,6 +60,80 @@ int FP_TEXTBOX::GetTextMargin() const
} }
VECTOR2I FP_TEXTBOX::GetTopLeft() const
{
EDA_ANGLE rotation = GetDrawRotation();
if( rotation == ANGLE_90 )
return VECTOR2I( GetStartX(), GetEndY() );
else if( rotation == ANGLE_180 )
return GetEnd();
else if( rotation == ANGLE_270 )
return VECTOR2I( GetEndX(), GetStartY() );
else
return GetStart();
}
VECTOR2I FP_TEXTBOX::GetBotRight() const
{
EDA_ANGLE rotation = GetDrawRotation();
if( rotation == ANGLE_90 )
return VECTOR2I( GetEndX(), GetStartY() );
else if( rotation == ANGLE_180 )
return GetStart();
else if( rotation == ANGLE_270 )
return VECTOR2I( GetStartX(), GetEndY() );
else
return GetEnd();
}
void FP_TEXTBOX::SetTop( int aVal )
{
EDA_ANGLE rotation = GetDrawRotation();
if( rotation == ANGLE_90 || rotation == ANGLE_180 )
SetEndY( aVal );
else
SetStartY( aVal );
}
void FP_TEXTBOX::SetBottom( int aVal )
{
EDA_ANGLE rotation = GetDrawRotation();
if( rotation == ANGLE_90 || rotation == ANGLE_180 )
SetStartY( aVal );
else
SetEndY( aVal );
}
void FP_TEXTBOX::SetLeft( int aVal )
{
EDA_ANGLE rotation = GetDrawRotation();
if( rotation == ANGLE_180 || rotation == ANGLE_270 )
SetEndX( aVal );
else
SetStartX( aVal );
}
void FP_TEXTBOX::SetRight( int aVal )
{
EDA_ANGLE rotation = GetDrawRotation();
if( rotation == ANGLE_180 || rotation == ANGLE_270 )
SetStartX( aVal );
else
SetEndX( aVal );
}
EDA_ANGLE FP_TEXTBOX::GetDrawRotation() const EDA_ANGLE FP_TEXTBOX::GetDrawRotation() const
{ {
FOOTPRINT* parentFootprint = static_cast<FOOTPRINT*>( m_parent ); FOOTPRINT* parentFootprint = static_cast<FOOTPRINT*>( m_parent );

View File

@ -64,6 +64,14 @@ public:
return false; return false;
} }
VECTOR2I GetTopLeft() const override;
VECTOR2I GetBotRight() const override;
void SetTop( int aVal ) override;
void SetLeft( int aVal ) override;
void SetRight( int aVal ) override;
void SetBottom( int aVal ) override;
wxString GetParentAsString() const { return m_parent->m_Uuid.AsString(); } wxString GetParentAsString() const { return m_parent->m_Uuid.AsString(); }
bool Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const override bool Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const override

View File

@ -58,6 +58,80 @@ int PCB_TEXTBOX::GetTextMargin() const
} }
VECTOR2I PCB_TEXTBOX::GetTopLeft() const
{
EDA_ANGLE rotation = GetDrawRotation();
if( rotation == ANGLE_90 )
return VECTOR2I( GetStartX(), GetEndY() );
else if( rotation == ANGLE_180 )
return GetEnd();
else if( rotation == ANGLE_270 )
return VECTOR2I( GetEndX(), GetStartY() );
else
return GetStart();
}
VECTOR2I PCB_TEXTBOX::GetBotRight() const
{
EDA_ANGLE rotation = GetDrawRotation();
if( rotation == ANGLE_90 )
return VECTOR2I( GetEndX(), GetStartY() );
else if( rotation == ANGLE_180 )
return GetStart();
else if( rotation == ANGLE_270 )
return VECTOR2I( GetStartX(), GetEndY() );
else
return GetEnd();
}
void PCB_TEXTBOX::SetTop( int aVal )
{
EDA_ANGLE rotation = GetDrawRotation();
if( rotation == ANGLE_90 || rotation == ANGLE_180 )
SetEndY( aVal );
else
SetStartY( aVal );
}
void PCB_TEXTBOX::SetBottom( int aVal )
{
EDA_ANGLE rotation = GetDrawRotation();
if( rotation == ANGLE_90 || rotation == ANGLE_180 )
SetStartY( aVal );
else
SetEndY( aVal );
}
void PCB_TEXTBOX::SetLeft( int aVal )
{
EDA_ANGLE rotation = GetDrawRotation();
if( rotation == ANGLE_180 || rotation == ANGLE_270 )
SetEndX( aVal );
else
SetStartX( aVal );
}
void PCB_TEXTBOX::SetRight( int aVal )
{
EDA_ANGLE rotation = GetDrawRotation();
if( rotation == ANGLE_180 || rotation == ANGLE_270 )
SetStartX( aVal );
else
SetEndX( aVal );
}
std::vector<VECTOR2I> PCB_TEXTBOX::GetAnchorAndOppositeCorner() const std::vector<VECTOR2I> PCB_TEXTBOX::GetAnchorAndOppositeCorner() const
{ {
std::vector<VECTOR2I> pts; std::vector<VECTOR2I> pts;

View File

@ -62,6 +62,14 @@ public:
return false; return false;
} }
VECTOR2I GetTopLeft() const override;
VECTOR2I GetBotRight() const override;
void SetTop( int aVal ) override;
void SetLeft( int aVal ) override;
void SetRight( int aVal ) override;
void SetBottom( int aVal ) override;
int GetTextMargin() const; int GetTextMargin() const;
VECTOR2I GetDrawPos() const override; VECTOR2I GetDrawPos() const override;

View File

@ -210,10 +210,10 @@ std::shared_ptr<EDIT_POINTS> PCB_POINT_EDITOR::makePoints( EDA_ITEM* aItem )
break; break;
case SHAPE_T::RECT: case SHAPE_T::RECT:
points->AddPoint( shape->GetStart() ); points->AddPoint( shape->GetTopLeft() );
points->AddPoint( VECTOR2I( shape->GetEnd().x, shape->GetStart().y ) ); points->AddPoint( VECTOR2I( shape->GetBotRight().x, shape->GetTopLeft().y ) );
points->AddPoint( shape->GetEnd() ); points->AddPoint( shape->GetBotRight() );
points->AddPoint( VECTOR2I( shape->GetStart().x, shape->GetEnd().y ) ); points->AddPoint( VECTOR2I( shape->GetTopLeft().x, shape->GetBotRight().y ) );
points->AddLine( points->Point( RECT_TOP_LEFT ), points->Point( RECT_TOP_RIGHT ) ); points->AddLine( points->Point( RECT_TOP_LEFT ), points->Point( RECT_TOP_RIGHT ) );
points->Line( RECT_TOP ).SetConstraint( new EC_PERPLINE( points->Line( RECT_TOP ) ) ); points->Line( RECT_TOP ).SetConstraint( new EC_PERPLINE( points->Line( RECT_TOP ) ) );
@ -1111,24 +1111,26 @@ void PCB_POINT_EDITOR::updateItem() const
|| isModified( m_editPoints->Point( RECT_BOT_RIGHT ) ) || isModified( m_editPoints->Point( RECT_BOT_RIGHT ) )
|| isModified( m_editPoints->Point( RECT_BOT_LEFT ) ) ) || isModified( m_editPoints->Point( RECT_BOT_LEFT ) ) )
{ {
shape->SetPosition( topLeft ); shape->SetLeft( topLeft.x );
shape->SetEnd( botRight ); shape->SetTop( topLeft.y );
shape->SetRight( botRight.x );
shape->SetBottom( botRight.y );
} }
else if( isModified( m_editPoints->Line( RECT_TOP ) ) ) else if( isModified( m_editPoints->Line( RECT_TOP ) ) )
{ {
shape->SetStartY( topLeft.y ); shape->SetTop( topLeft.y );
} }
else if( isModified( m_editPoints->Line( RECT_LEFT ) ) ) else if( isModified( m_editPoints->Line( RECT_LEFT ) ) )
{ {
shape->SetStartX( topLeft.x ); shape->SetLeft( topLeft.x );
} }
else if( isModified( m_editPoints->Line( RECT_BOT ) ) ) else if( isModified( m_editPoints->Line( RECT_BOT ) ) )
{ {
shape->SetEndY( botRight.y ); shape->SetBottom( botRight.y );
} }
else if( isModified( m_editPoints->Line( RECT_RIGHT ) ) ) else if( isModified( m_editPoints->Line( RECT_RIGHT ) ) )
{ {
shape->SetEndX( botRight.x ); shape->SetRight( botRight.x );
} }
for( unsigned i = 0; i < m_editPoints->LinesSize(); ++i ) for( unsigned i = 0; i < m_editPoints->LinesSize(); ++i )
@ -1666,12 +1668,12 @@ void PCB_POINT_EDITOR::updatePoints()
if( shape->GetShape() == SHAPE_T::RECT ) if( shape->GetShape() == SHAPE_T::RECT )
{ {
m_editPoints->Point( RECT_TOP_LEFT ).SetPosition( shape->GetStart() ); m_editPoints->Point( RECT_TOP_LEFT ).SetPosition( shape->GetTopLeft() );
m_editPoints->Point( RECT_TOP_RIGHT ).SetPosition( shape->GetEnd().x, m_editPoints->Point( RECT_TOP_RIGHT ).SetPosition( shape->GetBotRight().x,
shape->GetStart().y ); shape->GetTopLeft().y );
m_editPoints->Point( RECT_BOT_RIGHT ).SetPosition( shape->GetEnd() ); m_editPoints->Point( RECT_BOT_RIGHT ).SetPosition( shape->GetBotRight() );
m_editPoints->Point( RECT_BOT_LEFT ).SetPosition( shape->GetStart().x, m_editPoints->Point( RECT_BOT_LEFT ).SetPosition( shape->GetTopLeft().x,
shape->GetEnd().y ); shape->GetBotRight().y );
} }
else if( shape->GetShape() == SHAPE_T::POLY ) else if( shape->GetShape() == SHAPE_T::POLY )
{ {
@ -1694,12 +1696,12 @@ void PCB_POINT_EDITOR::updatePoints()
break; break;
case SHAPE_T::RECT: case SHAPE_T::RECT:
m_editPoints->Point( RECT_TOP_LEFT ).SetPosition( shape->GetStart() ); m_editPoints->Point( RECT_TOP_LEFT ).SetPosition( shape->GetTopLeft() );
m_editPoints->Point( RECT_TOP_RIGHT ).SetPosition( shape->GetEnd().x, m_editPoints->Point( RECT_TOP_RIGHT ).SetPosition( shape->GetBotRight().x,
shape->GetStart().y ); shape->GetTopLeft().y );
m_editPoints->Point( RECT_BOT_RIGHT ).SetPosition( shape->GetEnd() ); m_editPoints->Point( RECT_BOT_RIGHT ).SetPosition( shape->GetBotRight() );
m_editPoints->Point( RECT_BOT_LEFT ).SetPosition( shape->GetStart().x, m_editPoints->Point( RECT_BOT_LEFT ).SetPosition( shape->GetTopLeft().x,
shape->GetEnd().y ); shape->GetBotRight().y );
break; break;
case SHAPE_T::ARC: case SHAPE_T::ARC: