eeschema: Find the closest line end to the mouse when grabbing

Fixes: lp:1842175
* https://bugs.launchpad.net/kicad/+bug/1842175
This commit is contained in:
Ian McInerney 2019-09-06 21:52:52 +02:00 committed by Seth Hillbrand
parent 15d1b6cef0
commit d5275b16aa
3 changed files with 33 additions and 2 deletions

View File

@ -150,7 +150,15 @@ bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu )
return false;
if( item )
SetCrossHairPosition( item->GetPosition(), false );
{
SCH_LINE* line = dynamic_cast<SCH_LINE*>( item );
// The schematic lines have two possible points to use
if( line )
SetCrossHairPosition( line->GetClosestPoint( aPosition ), false );
else
SetCrossHairPosition( item->GetPosition(), false );
}
}
// If a command is in progress: add "cancel" and "end tool" menu

View File

@ -30,6 +30,7 @@
#include <fctsys.h>
#include <gr_basic.h>
#include <macros.h>
#include <trigo.h>
#include <sch_draw_panel.h>
#include <plotter.h>
#include <base_units.h>
@ -299,7 +300,7 @@ int SCH_LINE::GetPenSize() const
{
if( m_size > 0 )
return m_size;
return GetDefaultWidth();
}
@ -487,6 +488,19 @@ EDA_ITEM* SCH_LINE::MergeOverlap( SCH_LINE* aLine )
}
wxPoint SCH_LINE::GetClosestPoint( const wxPoint& aPoint )
{
// Compute the euclidean distance between the reference and the ends
double startDis = GetLineLength( aPoint, m_start );
double endDis = GetLineLength( aPoint, m_end );
if( startDis < endDis )
return m_start;
else
return m_end;
}
void SCH_LINE::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
{
if( GetLayer() == LAYER_NOTES )

View File

@ -81,6 +81,15 @@ public:
void SetEndPoint( const wxPoint& aPosition ) { m_end = aPosition; }
/**
* Find the end point of the line (either start or end) that is closest
* to the provided point.
*
* @param aPoint the point to compare against
* @return The coordinates of the closest end point
*/
wxPoint GetClosestPoint( const wxPoint& aPoint );
int GetDefaultStyle() const;
void SetLineStyle( const int aStyle );