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:
parent
15d1b6cef0
commit
d5275b16aa
|
@ -150,8 +150,16 @@ bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu )
|
|||
return false;
|
||||
|
||||
if( item )
|
||||
{
|
||||
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
|
||||
if( GetToolId() != ID_NO_TOOL_SELECTED )
|
||||
|
|
|
@ -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>
|
||||
|
@ -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 )
|
||||
|
|
|
@ -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 );
|
||||
|
|
Loading…
Reference in New Issue