pcbnew: Commit polygon points to new constrained zone

Adds leader points if they are not already existing in the zone

Fixes: lp:1846028
* https://bugs.launchpad.net/kicad/+bug/1846028

(cherry picked from commit 2e1af66a2b)
This commit is contained in:
Seth Hillbrand 2019-10-20 09:27:44 -07:00 committed by Seth Hillbrand
parent 6f71183d0e
commit 322eb2b8a8
5 changed files with 32 additions and 12 deletions

View File

@ -97,9 +97,9 @@ bool POLYGON_GEOM_MANAGER::IsSelfIntersecting( bool aIncludeLeaderPts ) const
}
void POLYGON_GEOM_MANAGER::SetCursorPosition( const VECTOR2I& aPos, LEADER_MODE aModifier )
void POLYGON_GEOM_MANAGER::SetCursorPosition( const VECTOR2I& aPos )
{
updateLeaderPoints( aPos, aModifier );
updateLeaderPoints( aPos );
}
@ -181,8 +181,14 @@ void POLYGON_GEOM_MANAGER::updateLeaderPoints( const VECTOR2I& aEndPoint, LEADER
m_leaderPts = SHAPE_LINE_CHAIN( lastPt, newEnd );
if( pt )
{
// This checks for backtracking from the point to intersection
if( SEG( lastPt, newEnd ).Collinear( SEG( newEnd, *pt ) ) )
m_leaderPts = SHAPE_LINE_CHAIN( lastPt, *pt );
else
m_leaderPts.Append( *pt );
}
}
else
{
// direct segment

View File

@ -128,7 +128,7 @@ public:
/**
* Set the current cursor position
*/
void SetCursorPosition( const VECTOR2I& aPos, LEADER_MODE aModifier );
void SetCursorPosition( const VECTOR2I& aPos );
/**
* @return true if the polygon in "in progress", i.e. it has at least

View File

@ -1383,6 +1383,7 @@ int DRAWING_TOOL::drawZone( bool aKeepout, ZONE_MODE aMode )
// the geometry manager which handles the zone geometry, and
// hands the calculated points over to the zone creator tool
POLYGON_GEOM_MANAGER polyGeomMgr( zoneTool );
bool constrainAngle = false;
Activate(); // register for events
@ -1406,6 +1407,11 @@ int DRAWING_TOOL::drawZone( bool aKeepout, ZONE_MODE aMode )
VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), layers );
m_controls->ForceCursorPosition( true, cursorPos );
if( ( sourceZone && sourceZone->GetHV45() ) || constrainAngle || evt->Modifier( MD_CTRL ) )
polyGeomMgr.SetLeaderMode( POLYGON_GEOM_MANAGER::LEADER_MODE::DEG45 );
else
polyGeomMgr.SetLeaderMode( POLYGON_GEOM_MANAGER::LEADER_MODE::DIRECT );
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
{
// pre-empted by another tool, give up
@ -1459,6 +1465,8 @@ int DRAWING_TOOL::drawZone( bool aKeepout, ZONE_MODE aMode )
if( !started )
{
started = true;
constrainAngle = ( polyGeomMgr.GetLeaderMode() ==
POLYGON_GEOM_MANAGER::LEADER_MODE::DEG45 );
m_controls->SetAutoPan( true );
m_controls->CaptureCursor( true );
}
@ -1483,9 +1491,7 @@ int DRAWING_TOOL::drawZone( bool aKeepout, ZONE_MODE aMode )
else if( polyGeomMgr.IsPolygonInProgress()
&& ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) )
{
polyGeomMgr.SetCursorPosition( cursorPos, evt->Modifier( MD_CTRL )
? POLYGON_GEOM_MANAGER::LEADER_MODE::DEG45
: POLYGON_GEOM_MANAGER::LEADER_MODE::DIRECT );
polyGeomMgr.SetCursorPosition( cursorPos );
if( polyGeomMgr.IsSelfIntersecting( true ) )
{

View File

@ -65,6 +65,7 @@ std::unique_ptr<ZONE_CONTAINER> ZONE_CREATE_HELPER::createNewZone( bool aKeepout
zoneInfo.m_CurrentZone_Layer = m_params.m_layer;
zoneInfo.m_NetcodeSelection = board.GetHighLightNetCode();
zoneInfo.SetIsKeepout( m_params.m_keepout );
zoneInfo.m_Zone_45_Only = ( m_params.m_leaderMode == POLYGON_GEOM_MANAGER::LEADER_MODE::DEG45 );
if( m_params.m_mode != DRAWING_TOOL::ZONE_MODE::GRAPHIC_POLYGON )
{
@ -302,14 +303,18 @@ void ZONE_CREATE_HELPER::OnComplete( const POLYGON_GEOM_MANAGER& aMgr )
{
auto pts = aMgr.GetLeaderLinePoints();
if( outline->TotalVertices() > 0 )
outline->RemoveVertex( outline->TotalVertices() - 1 );
// The first 2 points of the leader are the continuation of the previous segment
// The third point is where it intersects with the extension from the 0-th segment
for( int i = 2; i < pts.PointCount(); i++ )
for( int i = 0; i < pts.PointCount(); i++ )
{
auto pt = pts.CPoint( i );
// If we have at least 2 points, then we need to check if the leader points
// already exist before re-adding them to the finalized polygon
if( pts.PointCount() < 2 || ( pts.CPoint( -1 ) != pt && pts.CPoint( -2 ) != pt ) )
outline->Append( pts.CPoint( i ) );
}
}
outline->Outline( 0 ).SetClosed( true );
outline->RemoveNullSegments();

View File

@ -60,6 +60,9 @@ public:
///> Zone settings source (for similar and cutout zones)
ZONE_CONTAINER* m_sourceZone;
///> Zone leader mode
POLYGON_GEOM_MANAGER::LEADER_MODE m_leaderMode;
};
/**