Change attached-label algorithm.

Rather than try and keep moving with other items, calculate nearest
point on current line to original label at each step.

Fixes https://gitlab.com/kicad/code/kicad/issues/4347
This commit is contained in:
Jeff Young 2020-05-07 18:59:06 +01:00
parent f0cda374a0
commit 73e1496b25
2 changed files with 17 additions and 6 deletions

View File

@ -548,10 +548,10 @@ void SCH_MOVE_TOOL::getConnectedDragItems( SCH_ITEM* aOriginalItem, wxPoint aPoi
if( !label->HasFlag( TEMP_SELECTED ) )
aList.push_back( label );
double scale = GetLineLength( label->GetPosition(), otherEnd ) /
GetLineLength( otherEnd, aPoint );
m_specialCaseLabels[label] = scale;
SPECIAL_CASE_LABEL_INFO info;
info.attachedLine = testLine;
info.originalLabelPos = label->GetPosition();
m_specialCaseLabels[label] = info;
}
}
@ -690,7 +690,11 @@ void SCH_MOVE_TOOL::moveItem( EDA_ITEM* aItem, const VECTOR2I& aDelta )
SCH_TEXT* label = static_cast<SCH_TEXT*>( aItem );
if( m_specialCaseLabels.count( label ) )
label->Move( (wxPoint) aDelta * m_specialCaseLabels[ label ] );
{
SPECIAL_CASE_LABEL_INFO info = m_specialCaseLabels[ label ];
SEG currentLine( info.attachedLine->GetStartPoint(), info.attachedLine->GetEndPoint() );
label->SetPosition( (wxPoint) currentLine.NearestPoint( info.originalLabelPos ) );
}
else
label->Move( (wxPoint) aDelta );

View File

@ -33,6 +33,13 @@ class SCH_EDIT_FRAME;
class EE_SELECTION_TOOL;
struct SPECIAL_CASE_LABEL_INFO
{
SCH_LINE* attachedLine;
wxPoint originalLabelPos;
};
class SCH_MOVE_TOOL : public EE_TOOL_BASE<SCH_EDIT_FRAME>
{
public:
@ -79,7 +86,7 @@ private:
// A map of labels to scaling factors. Used to scale the movement vector for labels that
// are attached to wires which have only one end moving.
std::map<SCH_TEXT*, double> m_specialCaseLabels;
std::map<SCH_TEXT*, SPECIAL_CASE_LABEL_INFO> m_specialCaseLabels;
};