PNS: Use last-segment posture optimization always
Also when auto-posture is enabled, don't flutter until area threshold has been met. Fixes https://gitlab.com/kicad/code/kicad/-/issues/6935
This commit is contained in:
parent
3fd128a75b
commit
111fa99f9f
|
@ -916,7 +916,7 @@ bool LINE_PLACER::Start( const VECTOR2I& aP, ITEM* aStartItem )
|
||||||
m_postureSolver.AddTrailPoint( aP );
|
m_postureSolver.AddTrailPoint( aP );
|
||||||
m_postureSolver.SetTolerance( m_head.Width() );
|
m_postureSolver.SetTolerance( m_head.Width() );
|
||||||
m_postureSolver.SetDefaultDirections( initialDir, lastSegDir );
|
m_postureSolver.SetDefaultDirections( initialDir, lastSegDir );
|
||||||
m_postureSolver.SetDisabled( !Settings().GetAutoPosture() );
|
m_postureSolver.SetMouseDisabled( !Settings().GetAutoPosture() );
|
||||||
|
|
||||||
NODE *n;
|
NODE *n;
|
||||||
|
|
||||||
|
@ -1486,7 +1486,7 @@ int FIXED_TAIL::StageCount() const
|
||||||
POSTURE_SOLVER::POSTURE_SOLVER()
|
POSTURE_SOLVER::POSTURE_SOLVER()
|
||||||
{
|
{
|
||||||
m_tolerance = 0;
|
m_tolerance = 0;
|
||||||
m_disabled = false;
|
m_disableMouse = false;
|
||||||
Clear();
|
Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1549,10 +1549,13 @@ DIRECTION_45 POSTURE_SOLVER::GetPosture( const VECTOR2I& aP )
|
||||||
// Adjusts how close to p0 we unlock the posture again if one was locked already
|
// Adjusts how close to p0 we unlock the posture again if one was locked already
|
||||||
const int unlockDistanceFactor = 4;
|
const int unlockDistanceFactor = 4;
|
||||||
|
|
||||||
if( m_disabled || m_trail.PointCount() < 2 || m_manuallyForced )
|
if( m_trail.PointCount() < 2 || m_manuallyForced )
|
||||||
{
|
{
|
||||||
|
// If mouse trail detection is enabled; using the last seg direction as a starting point
|
||||||
|
// will give the best results. Otherwise, just assume that we switch postures every
|
||||||
|
// segment.
|
||||||
if( !m_manuallyForced && m_lastSegDirection != DIRECTION_45::UNDEFINED )
|
if( !m_manuallyForced && m_lastSegDirection != DIRECTION_45::UNDEFINED )
|
||||||
m_direction = m_lastSegDirection;
|
m_direction = m_disableMouse ? m_lastSegDirection.Right() : m_lastSegDirection;
|
||||||
|
|
||||||
return m_direction;
|
return m_direction;
|
||||||
}
|
}
|
||||||
|
@ -1589,7 +1592,7 @@ DIRECTION_45 POSTURE_SOLVER::GetPosture( const VECTOR2I& aP )
|
||||||
m_trail.Append( start );
|
m_trail.Append( start );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool areaOk = true;
|
bool areaOk = false;
|
||||||
|
|
||||||
// Check the actual trail area against the cutoff. This prevents flutter when the trail is
|
// Check the actual trail area against the cutoff. This prevents flutter when the trail is
|
||||||
// very close to a straight line.
|
// very close to a straight line.
|
||||||
|
@ -1599,8 +1602,8 @@ DIRECTION_45 POSTURE_SOLVER::GetPosture( const VECTOR2I& aP )
|
||||||
SHAPE_LINE_CHAIN trail( m_trail );
|
SHAPE_LINE_CHAIN trail( m_trail );
|
||||||
trail.SetClosed( true );
|
trail.SetClosed( true );
|
||||||
|
|
||||||
if( std::abs( trail.Area() ) < areaCutoff )
|
if( std::abs( trail.Area() ) > areaCutoff )
|
||||||
areaOk = false;
|
areaOk = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
DIRECTION_45 straightDirection;
|
DIRECTION_45 straightDirection;
|
||||||
|
@ -1617,18 +1620,20 @@ DIRECTION_45 POSTURE_SOLVER::GetPosture( const VECTOR2I& aP )
|
||||||
else
|
else
|
||||||
newDirection = m_direction.IsDiagonal() ? diagDirection : straightDirection;
|
newDirection = m_direction.IsDiagonal() ? diagDirection : straightDirection;
|
||||||
|
|
||||||
if( newDirection != m_direction )
|
if( !m_disableMouse && newDirection != m_direction )
|
||||||
{
|
{
|
||||||
wxLogTrace( "PNS", "Posture: direction update %s => %s", m_direction.Format(),
|
wxLogTrace( "PNS", "Posture: direction update %s => %s", m_direction.Format(),
|
||||||
newDirection.Format() );
|
newDirection.Format() );
|
||||||
|
m_direction = newDirection;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_direction = newDirection;
|
|
||||||
|
|
||||||
// If we have a last segment, correct the direction relative to it. For segment exit, we want
|
// If we have a last segment, correct the direction relative to it. For segment exit, we want
|
||||||
// to correct to the least obtuse
|
// to correct to the least obtuse
|
||||||
if( !m_manuallyForced && m_lastSegDirection != DIRECTION_45::UNDEFINED )
|
if( !m_manuallyForced && !m_disableMouse && m_lastSegDirection != DIRECTION_45::UNDEFINED )
|
||||||
{
|
{
|
||||||
|
wxLogTrace( "PNS", "Posture: checking direction %s against last seg %s",
|
||||||
|
m_direction.Format(), m_lastSegDirection.Format() );
|
||||||
|
|
||||||
if( straightDirection == m_lastSegDirection )
|
if( straightDirection == m_lastSegDirection )
|
||||||
{
|
{
|
||||||
if( m_direction != straightDirection )
|
if( m_direction != straightDirection )
|
||||||
|
@ -1695,7 +1700,10 @@ DIRECTION_45 POSTURE_SOLVER::GetPosture( const VECTOR2I& aP )
|
||||||
|
|
||||||
// If we get far away from the initial point, lock in the current solution to prevent flutter
|
// If we get far away from the initial point, lock in the current solution to prevent flutter
|
||||||
if( !m_forced && refLength > lockDistanceFactor * m_tolerance )
|
if( !m_forced && refLength > lockDistanceFactor * m_tolerance )
|
||||||
|
{
|
||||||
|
wxLogTrace( "PNS", "Posture: solution locked" );
|
||||||
m_forced = true;
|
m_forced = true;
|
||||||
|
}
|
||||||
|
|
||||||
return m_direction;
|
return m_direction;
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,11 @@ public:
|
||||||
|
|
||||||
void FlipPosture();
|
void FlipPosture();
|
||||||
|
|
||||||
void SetDisabled( bool aDisabled = true ) { m_disabled = aDisabled; }
|
/**
|
||||||
|
* Disables the mouse-trail portion of the posture solver; leaving only the manual posture
|
||||||
|
* switch and the previous-segment posture algorithm
|
||||||
|
*/
|
||||||
|
void SetMouseDisabled( bool aDisabled = true ) { m_disableMouse = aDisabled; }
|
||||||
|
|
||||||
bool IsManuallyForced() const { return m_manuallyForced; }
|
bool IsManuallyForced() const { return m_manuallyForced; }
|
||||||
|
|
||||||
|
@ -105,7 +109,7 @@ private:
|
||||||
DIRECTION_45 m_direction;
|
DIRECTION_45 m_direction;
|
||||||
DIRECTION_45 m_lastSegDirection;
|
DIRECTION_45 m_lastSegDirection;
|
||||||
bool m_forced;
|
bool m_forced;
|
||||||
bool m_disabled;
|
bool m_disableMouse;
|
||||||
bool m_manuallyForced;
|
bool m_manuallyForced;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue