Keep snap line alignment before new snaps

Also fixes the alignment line that was supposed to be dashed and not
solid.
This commit is contained in:
Seth Hillbrand 2020-09-11 10:33:12 -07:00
parent 5424d6fa09
commit d14c6ba71f
3 changed files with 57 additions and 44 deletions

View File

@ -127,7 +127,6 @@ void ORIGIN_VIEWITEM::ViewDraw( int, VIEW* aView ) const
start = next;
}
gal->DrawLine( m_position, m_end );
gal->DrawCircle( m_end, scaledSize.x / 4 );
break;
}

View File

@ -252,7 +252,8 @@ VECTOR2I EE_GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aL
const std::vector<SCH_ITEM*>& aSkip )
{
double worldScale = m_toolMgr->GetView()->GetGAL()->GetWorldScale();
int snapRange = (int) ( m_snapSize / worldScale );
double snapDist = m_snapSize / worldScale;
int snapRange = KiROUND( snapDist );
BOX2I bb( VECTOR2I( aOrigin.x - snapRange / 2, aOrigin.y - snapRange / 2 ),
VECTOR2I( snapRange, snapRange ) );
@ -265,37 +266,23 @@ VECTOR2I EE_GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aL
ANCHOR* nearest = nearestAnchor( aOrigin, SNAPPABLE, aLayers );
VECTOR2I nearestGrid = Align( aOrigin );
if( nearest && m_enableSnap )
{
double snapDist = nearest->Distance( aOrigin );
if( snapDist <= snapRange )
{
m_viewSnapPoint.SetPosition( wxPoint( nearest->pos ) );
m_viewSnapLine.SetPosition( wxPoint( nearest->pos ) );
m_toolMgr->GetView()->SetVisible( &m_viewSnapLine, false );
if( m_toolMgr->GetView()->IsVisible( &m_viewSnapPoint ) )
m_toolMgr->GetView()->Update( &m_viewSnapPoint, KIGFX::GEOMETRY);
else
m_toolMgr->GetView()->SetVisible( &m_viewSnapPoint, true );
m_snapItem = nearest;
return nearest->pos;
}
}
if( nearest )
snapDist = nearest->Distance( aOrigin );
if( m_snapItem && m_enableSnapLine && m_enableSnap )
{
bool snapLine = false;
int x_dist = std::abs( m_viewSnapLine.GetPosition().x - aOrigin.x );
int y_dist = std::abs( m_viewSnapLine.GetPosition().y - aOrigin.y );
if( std::abs( m_viewSnapLine.GetPosition().x - aOrigin.x ) < snapRange )
/// Allows de-snapping from the line if you are closer to another snap point
if( x_dist < snapRange && x_dist < snapDist )
{
nearestGrid.x = m_viewSnapLine.GetPosition().x;
snapLine = true;
}
if( std::abs( m_viewSnapLine.GetPosition().y - aOrigin.y ) < snapRange )
if( y_dist < snapRange && y_dist < snapDist )
{
nearestGrid.y = m_viewSnapLine.GetPosition().y;
snapLine = true;
@ -315,6 +302,25 @@ VECTOR2I EE_GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aL
}
}
if( nearest && m_enableSnap )
{
if( snapDist <= snapRange )
{
m_viewSnapPoint.SetPosition( wxPoint( nearest->pos ) );
m_viewSnapLine.SetPosition( wxPoint( nearest->pos ) );
m_toolMgr->GetView()->SetVisible( &m_viewSnapLine, false );
if( m_toolMgr->GetView()->IsVisible( &m_viewSnapPoint ) )
m_toolMgr->GetView()->Update( &m_viewSnapPoint, KIGFX::GEOMETRY);
else
m_toolMgr->GetView()->SetVisible( &m_viewSnapPoint, true );
m_snapItem = nearest;
return nearest->pos;
}
}
m_snapItem = nullptr;
m_toolMgr->GetView()->SetVisible( &m_viewSnapPoint, false );
m_toolMgr->GetView()->SetVisible( &m_viewSnapLine, false );

View File

@ -306,7 +306,8 @@ VECTOR2I GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLaye
const std::vector<BOARD_ITEM*>& aSkip )
{
double worldScale = m_toolMgr->GetView()->GetGAL()->GetWorldScale();
int snapRange = (int) ( m_snapSize / worldScale );
double snapDist = m_snapSize / worldScale;
int snapRange = KiROUND( snapDist );
BOX2I bb( VECTOR2I( aOrigin.x - snapRange / 2, aOrigin.y - snapRange / 2 ),
VECTOR2I( snapRange, snapRange ) );
@ -319,35 +320,24 @@ VECTOR2I GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLaye
ANCHOR* nearest = nearestAnchor( aOrigin, SNAPPABLE, aLayers );
VECTOR2I nearestGrid = Align( aOrigin );
if( nearest && m_enableSnap )
{
if( nearest->Distance( aOrigin ) <= snapRange )
{
m_viewSnapPoint.SetPosition( wxPoint( nearest->pos ) );
m_viewSnapLine.SetPosition( wxPoint( nearest->pos ) );
m_toolMgr->GetView()->SetVisible( &m_viewSnapLine, false );
if( nearest )
snapDist = nearest->Distance( aOrigin );
if( m_toolMgr->GetView()->IsVisible( &m_viewSnapPoint ) )
m_toolMgr->GetView()->Update( &m_viewSnapPoint, KIGFX::GEOMETRY);
else
m_toolMgr->GetView()->SetVisible( &m_viewSnapPoint, true );
m_snapItem = nearest;
return nearest->pos;
}
}
if( m_snapItem && m_enableSnapLine )
// Existing snap lines need priority over new snaps
if( m_snapItem && m_enableSnapLine && m_enableSnap )
{
bool snapLine = false;
int x_dist = std::abs( m_viewSnapLine.GetPosition().x - aOrigin.x );
int y_dist = std::abs( m_viewSnapLine.GetPosition().y - aOrigin.y );
if( std::abs( m_viewSnapLine.GetPosition().x - aOrigin.x ) < GetGrid().x )
/// Allows de-snapping from the line if you are closer to another snap point
if( x_dist < snapRange && x_dist < snapDist )
{
nearestGrid.x = m_viewSnapLine.GetPosition().x;
snapLine = true;
}
if( std::abs( m_viewSnapLine.GetPosition().y - aOrigin.y ) < GetGrid().y )
if( y_dist < snapRange && y_dist < snapDist )
{
nearestGrid.y = m_viewSnapLine.GetPosition().y;
snapLine = true;
@ -367,6 +357,24 @@ VECTOR2I GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLaye
}
}
if( nearest && m_enableSnap )
{
if( nearest->Distance( aOrigin ) <= snapRange )
{
m_viewSnapPoint.SetPosition( wxPoint( nearest->pos ) );
m_viewSnapLine.SetPosition( wxPoint( nearest->pos ) );
m_toolMgr->GetView()->SetVisible( &m_viewSnapLine, false );
if( m_toolMgr->GetView()->IsVisible( &m_viewSnapPoint ) )
m_toolMgr->GetView()->Update( &m_viewSnapPoint, KIGFX::GEOMETRY);
else
m_toolMgr->GetView()->SetVisible( &m_viewSnapPoint, true );
m_snapItem = nearest;
return nearest->pos;
}
}
m_snapItem = nullptr;
m_toolMgr->GetView()->SetVisible( &m_viewSnapPoint, false );
m_toolMgr->GetView()->SetVisible( &m_viewSnapLine, false );