Make an exception for SCH_TEXT in SELECTION::GetCenter()

And undo the previous changes in SCH_TEXT::Rotate().

We continue hitting this with a wrench until it gets fixed or becomes
broken beyond any recognition.
This commit is contained in:
Mikolaj Wielgus 2021-12-04 05:28:14 +01:00
parent 8caf62803d
commit 10be483430
4 changed files with 10 additions and 47 deletions

View File

@ -70,25 +70,25 @@ bool SELECTION::Contains( EDA_ITEM* aItem ) const
/// Returns the center point of the selection area bounding box.
VECTOR2I SELECTION::GetCenter() const
{
KICAD_T labelTypes[] = { SCH_LABEL_T, SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, EOT };
bool hasOnlyLabels = true;
KICAD_T textTypes[] = { SCH_TEXT_T, SCH_LABEL_T, SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, EOT };
bool hasOnlyText = true;
// If the selection contains only labels calculate the center as the mean of all positions
// If the selection contains only texts calculate the center as the mean of all positions
// instead of using the center of the total bounding box. Otherwise rotating the selection will
// also translate it.
for( EDA_ITEM* item : m_items )
{
if( !item->IsType( labelTypes ) )
if( !item->IsType( textTypes ) )
{
hasOnlyLabels = false;
hasOnlyText = false;
break;
}
}
EDA_RECT bbox;
if( hasOnlyLabels )
if( hasOnlyText )
{
wxPoint center( 0, 0 );
@ -101,7 +101,7 @@ VECTOR2I SELECTION::GetCenter() const
for( EDA_ITEM* item : m_items )
{
if( !item->IsType( labelTypes ) )
if( !item->IsType( textTypes ) )
bbox.Merge( item->GetBoundingBox() );
}

View File

@ -299,21 +299,13 @@ void SCH_TEXT::MirrorVertically( int aCenter )
void SCH_TEXT::Rotate( const wxPoint& aCenter )
{
wxPoint pt = GetBoundingBox().GetCenter();
wxPoint pt = GetTextPos();
RotatePoint( &pt, aCenter, 900 );
wxPoint offset = pt - GetTextPos();
RotatePoint( &pt, aCenter, 900 );
// `offset` compensates for `GetTextPos()` not being the item center.
SetTextPos( pt - offset );
pt = GetBoundingBox().GetCenter();
Rotate90( false );
// Compensate for `Rotate90()` shifting the item center.
offset = GetBoundingBox().GetCenter() - pt;
SetTextPos( GetTextPos() - offset );
SetTextPos( GetTextPos() + offset );
}
@ -927,18 +919,6 @@ const EDA_RECT SCH_LABEL::GetBoundingBox() const
}
void SCH_LABEL::Rotate( const wxPoint& aCenter )
{
wxPoint pt = GetTextPos();
RotatePoint( &pt, aCenter, 900 );
wxPoint offset = pt - GetTextPos();
Rotate90( false );
SetTextPos( GetTextPos() + offset );
}
wxString SCH_LABEL::GetSelectMenuText( EDA_UNITS aUnits ) const
{
return wxString::Format( _( "Label '%s'" ), ShortenedShownText() );

View File

@ -300,8 +300,6 @@ public:
const EDA_RECT GetBoundingBox() const override;
void Rotate( const wxPoint& aCenter ) override;
bool IsConnectable() const override { return true; }
bool CanConnect( const SCH_ITEM* aItem ) const override

View File

@ -801,21 +801,6 @@ int SCH_EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
pin->MirrorHorizontally( sheet->GetBoundingBox().GetCenter().x );
}
}
else if( item->Type() == SCH_TEXT_T || item->Type() == SCH_LABEL_T )
{
/// Text and Labels are aligned to their bottom right corners and we don't flip the
/// alignment corner, so we need to offset this in the vertical direction
wxPoint textMirrorPoint = mirrorPoint;
textMirrorPoint.y += item->GetBoundingBox().GetHeight() / 2;
textMirrorPoint = m_frame->GetNearestHalfGridPosition( textMirrorPoint );
if( vertical )
item->MirrorVertically( textMirrorPoint.y );
else
item->MirrorHorizontally( textMirrorPoint.x );
}
else
{
if( vertical )