Fix automatic wire tool in gridless mode
The automatic wire tool was not working in the gridless mode because the grid snapping on/off logic present in `EE_GRID_HELPER`, based on the value of `m_enableGrid`, was not taking into account that another check, but for the global KiCad setting, would be performed in the `Align()` method, which is inherited from `GRID_HELPER`. I've modified all tests of `m_enableGrid` value to also take the global setting into account, and moved checks for it to `Align()` method, as it's more consistent this way. I've also removed an override of the `Align()` method in the `PCB_GRID_HELPER` class, as it was made redundant by my changes. Fixes https://gitlab.com/kicad/code/kicad/issues/7402
This commit is contained in:
parent
05ff0fb658
commit
1dc0ef01b3
|
@ -94,7 +94,7 @@ VECTOR2I GRID_HELPER::AlignGrid( const VECTOR2I& aPoint ) const
|
||||||
|
|
||||||
VECTOR2I GRID_HELPER::Align( const VECTOR2I& aPoint ) const
|
VECTOR2I GRID_HELPER::Align( const VECTOR2I& aPoint ) const
|
||||||
{
|
{
|
||||||
if( !m_toolMgr->GetView()->GetGAL()->GetGridSnapping() )
|
if( !canUseGrid() )
|
||||||
return aPoint;
|
return aPoint;
|
||||||
|
|
||||||
VECTOR2I nearest = AlignGrid( aPoint );
|
VECTOR2I nearest = AlignGrid( aPoint );
|
||||||
|
|
|
@ -135,7 +135,7 @@ VECTOR2I EE_GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, int aLayer,
|
||||||
computeAnchors( item, aOrigin );
|
computeAnchors( item, aOrigin );
|
||||||
|
|
||||||
ANCHOR* nearest = nearestAnchor( aOrigin, SNAPPABLE, aLayer );
|
ANCHOR* nearest = nearestAnchor( aOrigin, SNAPPABLE, aLayer );
|
||||||
VECTOR2I nearestGrid = m_enableGrid ? Align( aOrigin ) : aOrigin;
|
VECTOR2I nearestGrid = Align( aOrigin );
|
||||||
|
|
||||||
if( m_enableSnapLine && m_snapItem && m_skipPoint != VECTOR2I( m_viewSnapLine.GetPosition() ) )
|
if( m_enableSnapLine && m_snapItem && m_skipPoint != VECTOR2I( m_viewSnapLine.GetPosition() ) )
|
||||||
{
|
{
|
||||||
|
@ -153,14 +153,14 @@ VECTOR2I EE_GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, int aLayer,
|
||||||
snapLineY = true;
|
snapLineY = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( m_enableGrid && std::abs( nearestGrid.x - aOrigin.x ) < snapDist.x )
|
if( canUseGrid() && std::abs( nearestGrid.x - aOrigin.x ) < snapDist.x )
|
||||||
{
|
{
|
||||||
pt.x = nearestGrid.x;
|
pt.x = nearestGrid.x;
|
||||||
snapDist.x = std::abs( nearestGrid.x - aOrigin.x );
|
snapDist.x = std::abs( nearestGrid.x - aOrigin.x );
|
||||||
snapLineX = false;
|
snapLineX = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( m_enableGrid && std::abs( nearestGrid.y - aOrigin.y ) < snapDist.y )
|
if( canUseGrid() && std::abs( nearestGrid.y - aOrigin.y ) < snapDist.y )
|
||||||
{
|
{
|
||||||
pt.y = nearestGrid.y;
|
pt.y = nearestGrid.y;
|
||||||
snapDist.y = std::abs( nearestGrid.y - aOrigin.y );
|
snapDist.y = std::abs( nearestGrid.y - aOrigin.y );
|
||||||
|
@ -172,24 +172,27 @@ VECTOR2I EE_GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, int aLayer,
|
||||||
|
|
||||||
if( m_enableSnap && nearest && nearest->Distance( aOrigin ) < snapDist.EuclideanNorm() )
|
if( m_enableSnap && nearest && nearest->Distance( aOrigin ) < snapDist.EuclideanNorm() )
|
||||||
{
|
{
|
||||||
pt = nearest->pos;
|
|
||||||
snapDist.x = std::abs( nearest->pos.x - aOrigin.x );
|
|
||||||
snapDist.y = std::abs( nearest->pos.y - aOrigin.y );
|
|
||||||
snapLineX = snapLineY = false;
|
|
||||||
snapPoint = true;
|
|
||||||
|
|
||||||
if( m_enableGrid && ( nearestGrid - aOrigin ).EuclideanNorm() < snapDist.EuclideanNorm() )
|
if( canUseGrid() && ( nearestGrid - aOrigin ).EuclideanNorm() < snapDist.EuclideanNorm() )
|
||||||
{
|
{
|
||||||
pt = nearestGrid;
|
pt = nearestGrid;
|
||||||
snapDist.x = std::abs( nearestGrid.x - aOrigin.x );
|
snapDist.x = std::abs( nearestGrid.x - aOrigin.x );
|
||||||
snapDist.y = std::abs( nearestGrid.y - aOrigin.y );
|
snapDist.y = std::abs( nearestGrid.y - aOrigin.y );
|
||||||
snapPoint = false;
|
snapPoint = false;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pt = nearest->pos;
|
||||||
|
snapDist.x = std::abs( nearest->pos.x - aOrigin.x );
|
||||||
|
snapDist.y = std::abs( nearest->pos.y - aOrigin.y );
|
||||||
|
snapPoint = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
snapLineX = snapLineY = false;
|
||||||
gridChecked = true;
|
gridChecked = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( m_enableGrid && !gridChecked )
|
if( canUseGrid() && !gridChecked )
|
||||||
pt = nearestGrid;
|
pt = nearestGrid;
|
||||||
|
|
||||||
if( snapLineX || snapLineY )
|
if( snapLineX || snapLineY )
|
||||||
|
@ -223,7 +226,6 @@ VECTOR2I EE_GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, int aLayer,
|
||||||
return pt;
|
return pt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SCH_ITEM* EE_GRID_HELPER::GetSnapped() const
|
SCH_ITEM* EE_GRID_HELPER::GetSnapped() const
|
||||||
{
|
{
|
||||||
if( !m_snapItem )
|
if( !m_snapItem )
|
||||||
|
@ -289,7 +291,7 @@ void EE_GRID_HELPER::computeAnchors( SCH_ITEM *aItem, const VECTOR2I &aRefPos, b
|
||||||
|
|
||||||
if( SCH_LINE* line = dyn_cast<SCH_LINE*>( aItem ) )
|
if( SCH_LINE* line = dyn_cast<SCH_LINE*>( aItem ) )
|
||||||
{
|
{
|
||||||
VECTOR2I pt = m_enableGrid ? Align( aRefPos ) : aRefPos;
|
VECTOR2I pt = Align( aRefPos );
|
||||||
|
|
||||||
if( line->GetStartPoint().x == line->GetEndPoint().x )
|
if( line->GetStartPoint().x == line->GetEndPoint().x )
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#ifndef GRID_HELPER_H
|
#ifndef GRID_HELPER_H
|
||||||
#define GRID_HELPER_H
|
#define GRID_HELPER_H
|
||||||
|
|
||||||
|
#include <tool/tool_manager.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <math/vector2d.h>
|
#include <math/vector2d.h>
|
||||||
#include <origin_viewitem.h>
|
#include <origin_viewitem.h>
|
||||||
|
@ -113,6 +114,15 @@ protected:
|
||||||
m_anchors.clear();
|
m_anchors.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether it is possible to use the grid -- this depends both on local grid helper
|
||||||
|
* settings and global (tool manager) KiCad settings.
|
||||||
|
*/
|
||||||
|
bool canUseGrid() const
|
||||||
|
{
|
||||||
|
return m_enableGrid && m_toolMgr->GetView()->GetGAL()->GetGridSnapping();
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::vector<ANCHOR> m_anchors;
|
std::vector<ANCHOR> m_anchors;
|
||||||
|
|
||||||
|
|
|
@ -46,14 +46,6 @@ public:
|
||||||
*/
|
*/
|
||||||
BOARD_ITEM* GetSnapped() const;
|
BOARD_ITEM* GetSnapped() const;
|
||||||
|
|
||||||
VECTOR2I Align( const VECTOR2I& aPoint ) const override
|
|
||||||
{
|
|
||||||
if( !m_enableGrid )
|
|
||||||
return aPoint;
|
|
||||||
|
|
||||||
return GRID_HELPER::Align( aPoint );
|
|
||||||
}
|
|
||||||
|
|
||||||
VECTOR2I AlignToSegment ( const VECTOR2I& aPoint, const SEG& aSeg );
|
VECTOR2I AlignToSegment ( const VECTOR2I& aPoint, const SEG& aSeg );
|
||||||
|
|
||||||
VECTOR2I BestDragOrigin( const VECTOR2I& aMousePos, std::vector<BOARD_ITEM*>& aItem );
|
VECTOR2I BestDragOrigin( const VECTOR2I& aMousePos, std::vector<BOARD_ITEM*>& aItem );
|
||||||
|
|
Loading…
Reference in New Issue