Fix snapping dist when disabling grid
The disable grid hotkey should allow the snap scale to be completely determined by the snapSize and world scale. This prevents snapRange from overriding in the case where grid is disabled. Additionally, we disallow grid snapping when the grid scale is not visible. This means that when zoomed out sufficiently to not show the minor ticks, these minor ticks will not override a snap Fixes https://gitlab.com/kicad/code/kicad/issues/12303
This commit is contained in:
parent
73c4ec0b85
commit
1cc9792cdb
|
@ -1605,23 +1605,11 @@ void OPENGL_GAL::DrawGrid()
|
||||||
if( !m_gridVisibility || m_gridSize.x == 0 || m_gridSize.y == 0 )
|
if( !m_gridVisibility || m_gridSize.x == 0 || m_gridSize.y == 0 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
VECTOR2D gridScreenSize( m_gridSize );
|
VECTOR2D gridScreenSize = GetVisibleGridSize();
|
||||||
|
|
||||||
double gridThreshold = computeMinGridSpacing() / m_worldScale;
|
|
||||||
|
|
||||||
if( m_gridStyle == GRID_STYLE::SMALL_CROSS )
|
|
||||||
gridThreshold *= 2.0;
|
|
||||||
|
|
||||||
// If we cannot display the grid density, scale down by a tick size and
|
|
||||||
// try again. Eventually, we get some representation of the grid
|
|
||||||
while( std::min( gridScreenSize.x, gridScreenSize.y ) <= gridThreshold )
|
|
||||||
{
|
|
||||||
gridScreenSize = gridScreenSize * static_cast<double>( m_gridTick );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compute grid starting and ending indexes to draw grid points on the
|
// Compute grid starting and ending indexes to draw grid points on the
|
||||||
// visible screen area
|
// visible screen area
|
||||||
// Note: later any point coordinate will be offsetted by m_gridOrigin
|
// Note: later any point coordinate will be offset by m_gridOrigin
|
||||||
int gridStartX = KiROUND( ( worldStartPoint.x - m_gridOrigin.x ) / gridScreenSize.x );
|
int gridStartX = KiROUND( ( worldStartPoint.x - m_gridOrigin.x ) / gridScreenSize.x );
|
||||||
int gridEndX = KiROUND( ( worldEndPoint.x - m_gridOrigin.x ) / gridScreenSize.x );
|
int gridEndX = KiROUND( ( worldEndPoint.x - m_gridOrigin.x ) / gridScreenSize.x );
|
||||||
int gridStartY = KiROUND( ( worldStartPoint.y - m_gridOrigin.y ) / gridScreenSize.y );
|
int gridStartY = KiROUND( ( worldStartPoint.y - m_gridOrigin.y ) / gridScreenSize.y );
|
||||||
|
|
|
@ -56,6 +56,14 @@ VECTOR2I GRID_HELPER::GetGrid() const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
VECTOR2I GRID_HELPER::GetVisibleGrid() const
|
||||||
|
{
|
||||||
|
VECTOR2D size = m_toolMgr->GetView()->GetGAL()->GetVisibleGridSize();
|
||||||
|
|
||||||
|
return VECTOR2I( KiROUND( size.x ), KiROUND( size.y ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
VECTOR2I GRID_HELPER::GetOrigin() const
|
VECTOR2I GRID_HELPER::GetOrigin() const
|
||||||
{
|
{
|
||||||
VECTOR2D origin = m_toolMgr->GetView()->GetGAL()->GetGridOrigin();
|
VECTOR2D origin = m_toolMgr->GetView()->GetGAL()->GetGridOrigin();
|
||||||
|
|
|
@ -775,6 +775,30 @@ public:
|
||||||
return m_gridSize;
|
return m_gridSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the visible grid size in x and y directions
|
||||||
|
*
|
||||||
|
* @return A vector containing the spacing of visible grid marks
|
||||||
|
*/
|
||||||
|
inline VECTOR2D GetVisibleGridSize() const
|
||||||
|
{
|
||||||
|
VECTOR2D gridScreenSize( m_gridSize );
|
||||||
|
|
||||||
|
double gridThreshold = computeMinGridSpacing() / m_worldScale;
|
||||||
|
|
||||||
|
if( m_gridStyle == GRID_STYLE::SMALL_CROSS )
|
||||||
|
gridThreshold *= 2.0;
|
||||||
|
|
||||||
|
// If we cannot display the grid density, scale down by a tick size and
|
||||||
|
// try again. Eventually, we get some representation of the grid
|
||||||
|
while( std::min( gridScreenSize.x, gridScreenSize.y ) <= gridThreshold )
|
||||||
|
{
|
||||||
|
gridScreenSize = gridScreenSize * static_cast<double>( m_gridTick );
|
||||||
|
}
|
||||||
|
|
||||||
|
return gridScreenSize;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the grid color.
|
* Set the grid color.
|
||||||
*
|
*
|
||||||
|
|
|
@ -40,6 +40,7 @@ public:
|
||||||
virtual ~GRID_HELPER();
|
virtual ~GRID_HELPER();
|
||||||
|
|
||||||
VECTOR2I GetGrid() const;
|
VECTOR2I GetGrid() const;
|
||||||
|
VECTOR2I GetVisibleGrid() const;
|
||||||
VECTOR2I GetOrigin() const;
|
VECTOR2I GetOrigin() const;
|
||||||
|
|
||||||
void SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin = VECTOR2I( 0, 0 ) );
|
void SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin = VECTOR2I( 0, 0 ) );
|
||||||
|
|
|
@ -285,8 +285,9 @@ VECTOR2I PCB_GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& a
|
||||||
// points that are visible can always be snapped to.
|
// points that are visible can always be snapped to.
|
||||||
// see https://gitlab.com/kicad/code/kicad/-/issues/5638
|
// see https://gitlab.com/kicad/code/kicad/-/issues/5638
|
||||||
// see https://gitlab.com/kicad/code/kicad/-/issues/7125
|
// see https://gitlab.com/kicad/code/kicad/-/issues/7125
|
||||||
double snapScale = snapSize / m_toolMgr->GetView()->GetGAL()->GetWorldScale();
|
// see https://gitlab.com/kicad/code/kicad/-/issues/12303
|
||||||
int snapRange = std::min( KiROUND( snapScale ), GetGrid().x );
|
int snapScale = KiROUND( snapSize / m_toolMgr->GetView()->GetGAL()->GetWorldScale() );
|
||||||
|
int snapRange = m_enableGrid ? std::min( snapScale, GetVisibleGrid().x ) : snapScale;
|
||||||
int snapDist = snapRange;
|
int snapDist = snapRange;
|
||||||
|
|
||||||
//Respect limits of coordinates representation
|
//Respect limits of coordinates representation
|
||||||
|
|
Loading…
Reference in New Issue