Snap to eeschema lines
Allows easier snapping to lines when drawing in eeschema. Fixes https://gitlab.com/kicad/code/kicad/issues/7378
This commit is contained in:
parent
22d78a5827
commit
238aa2b5b0
|
@ -35,6 +35,7 @@ using namespace std::placeholders;
|
|||
GRID_HELPER::GRID_HELPER( TOOL_MANAGER* aToolMgr ) :
|
||||
m_toolMgr( aToolMgr )
|
||||
{
|
||||
m_maskTypes = ALL;
|
||||
m_enableSnap = true;
|
||||
m_enableSnapLine = true;
|
||||
m_enableGrid = true;
|
||||
|
|
|
@ -25,8 +25,10 @@
|
|||
|
||||
#include <functional>
|
||||
#include <sch_item.h>
|
||||
#include <sch_line.h>
|
||||
#include <sch_painter.h>
|
||||
#include <tool/tool_manager.h>
|
||||
#include <trigo.h>
|
||||
#include <view/view.h>
|
||||
#include "ee_grid_helper.h"
|
||||
|
||||
|
@ -257,25 +259,25 @@ std::set<SCH_ITEM*> EE_GRID_HELPER::queryVisible( const BOX2I& aArea,
|
|||
}
|
||||
|
||||
|
||||
void EE_GRID_HELPER::computeAnchors( SCH_ITEM* aItem, const VECTOR2I& aRefPos, bool aFrom )
|
||||
void EE_GRID_HELPER::computeAnchors( SCH_ITEM *aItem, const VECTOR2I &aRefPos, bool aFrom )
|
||||
{
|
||||
switch( aItem->Type() )
|
||||
switch ( aItem->Type() )
|
||||
{
|
||||
case SCH_COMPONENT_T:
|
||||
case SCH_SHEET_T:
|
||||
case SCH_SHEET_T:
|
||||
addAnchor( aItem->GetPosition(), ORIGIN, aItem );
|
||||
KI_FALLTHROUGH;
|
||||
case SCH_JUNCTION_T:
|
||||
case SCH_NO_CONNECT_T:
|
||||
case SCH_LINE_T:
|
||||
case SCH_GLOBAL_LABEL_T:
|
||||
case SCH_HIER_LABEL_T:
|
||||
case SCH_LABEL_T:
|
||||
case SCH_BUS_WIRE_ENTRY_T:
|
||||
{
|
||||
case SCH_NO_CONNECT_T:
|
||||
case SCH_LINE_T:
|
||||
case SCH_GLOBAL_LABEL_T:
|
||||
case SCH_HIER_LABEL_T:
|
||||
case SCH_LABEL_T:
|
||||
case SCH_BUS_WIRE_ENTRY_T:
|
||||
{
|
||||
std::vector<wxPoint> pts = aItem->GetConnectionPoints();
|
||||
|
||||
for( const wxPoint& pt : pts )
|
||||
for( const wxPoint &pt : pts )
|
||||
addAnchor( VECTOR2I( pt ), SNAPPABLE | CORNER, aItem );
|
||||
|
||||
break;
|
||||
|
@ -283,7 +285,28 @@ void EE_GRID_HELPER::computeAnchors( SCH_ITEM* aItem, const VECTOR2I& aRefPos, b
|
|||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( SCH_LINE* line = dyn_cast<SCH_LINE*>( aItem ) )
|
||||
{
|
||||
VECTOR2I pt = m_enableGrid ? Align( aRefPos ) : aRefPos;
|
||||
|
||||
if( line->GetStartPoint().x == line->GetEndPoint().x )
|
||||
{
|
||||
VECTOR2I possible( line->GetStartPoint().x, pt.y );
|
||||
|
||||
if( TestSegmentHit( wxPoint( possible ), line->GetStartPoint(), line->GetEndPoint(), 0 ) )
|
||||
addAnchor( possible, SNAPPABLE | VERTICAL, aItem );
|
||||
}
|
||||
else if( line->GetStartPoint().y == line->GetEndPoint().y )
|
||||
{
|
||||
VECTOR2I possible( pt.x, line->GetStartPoint().y );
|
||||
|
||||
if( TestSegmentHit( wxPoint( possible ), line->GetStartPoint(), line->GetEndPoint(), 0 ) )
|
||||
addAnchor( possible, SNAPPABLE | HORIZONTAL, aItem );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -508,13 +508,23 @@ int SCH_LINE_WIRE_BUS_TOOL::doDrawSegments( const std::string& aTool, int aType,
|
|||
while( TOOL_EVENT* evt = Wait() )
|
||||
{
|
||||
setCursor();
|
||||
grid.SetMask( GRID_HELPER::ALL );
|
||||
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
|
||||
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->Modifier( MD_ALT ) );
|
||||
|
||||
if( segment )
|
||||
{
|
||||
if( segment->GetStartPoint().x == segment->GetEndPoint().x )
|
||||
grid.ClearMaskFlag( GRID_HELPER::VERTICAL );
|
||||
|
||||
if( segment->GetStartPoint().y == segment->GetEndPoint().y )
|
||||
grid.ClearMaskFlag( GRID_HELPER::HORIZONTAL );
|
||||
}
|
||||
|
||||
wxPoint cursorPos = evt->IsPrime() ? (wxPoint) evt->Position()
|
||||
: (wxPoint) controls->GetMousePosition();
|
||||
|
||||
cursorPos = (wxPoint) grid.BestSnapAnchor( cursorPos, LAYER_CONNECTABLE, nullptr );
|
||||
cursorPos = (wxPoint) grid.BestSnapAnchor( cursorPos, LAYER_CONNECTABLE, segment );
|
||||
controls->ForceCursorPosition( true, cursorPos );
|
||||
|
||||
bool forceHV = m_frame->eeconfig()->m_Drawing.hv_lines_only;
|
||||
|
|
|
@ -36,7 +36,7 @@ class GRID_HELPER
|
|||
{
|
||||
public:
|
||||
GRID_HELPER( TOOL_MANAGER* aToolMgr );
|
||||
~GRID_HELPER();
|
||||
virtual ~GRID_HELPER();
|
||||
|
||||
VECTOR2I GetGrid() const;
|
||||
VECTOR2I GetOrigin() const;
|
||||
|
@ -68,16 +68,22 @@ public:
|
|||
|
||||
void SetSnapLine( bool aSnap ) { m_enableSnapLine = aSnap; }
|
||||
|
||||
protected:
|
||||
void SetMask( int aMask ) { m_maskTypes = aMask; }
|
||||
void SetMaskFlag( int aFlag ) { m_maskTypes |= aFlag; }
|
||||
void ClearMaskFlag( int aFlag ) { m_maskTypes = m_maskTypes & ~aFlag; }
|
||||
|
||||
enum ANCHOR_FLAGS {
|
||||
CORNER = 1,
|
||||
OUTLINE = 2,
|
||||
SNAPPABLE = 4,
|
||||
ORIGIN = 8,
|
||||
VERTICAL = 16,
|
||||
HORIZONTAL = 32
|
||||
HORIZONTAL = 32,
|
||||
ALL = CORNER | OUTLINE | SNAPPABLE | ORIGIN | VERTICAL | HORIZONTAL
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
struct ANCHOR
|
||||
{
|
||||
ANCHOR( VECTOR2I aPos, int aFlags = CORNER | SNAPPABLE, EDA_ITEM* aItem = NULL ) :
|
||||
|
@ -98,7 +104,8 @@ protected:
|
|||
|
||||
void addAnchor( const VECTOR2I& aPos, int aFlags, EDA_ITEM* aItem )
|
||||
{
|
||||
m_anchors.emplace_back( ANCHOR( aPos, aFlags, aItem ) );
|
||||
if( ( aFlags & m_maskTypes ) == aFlags )
|
||||
m_anchors.emplace_back( ANCHOR( aPos, aFlags, aItem ) );
|
||||
}
|
||||
|
||||
void clearAnchors()
|
||||
|
@ -112,6 +119,8 @@ protected:
|
|||
TOOL_MANAGER* m_toolMgr;
|
||||
OPT<VECTOR2I> m_auxAxis;
|
||||
|
||||
int m_maskTypes; // Mask of allowed snap types
|
||||
|
||||
bool m_enableSnap; // Allow snapping to other items on the layers
|
||||
bool m_enableGrid; // If true, allow snapping to grid
|
||||
bool m_enableSnapLine; // Allow drawing lines from snap points
|
||||
|
|
Loading…
Reference in New Issue