From c71bb246e62fd71f431861b3bc38e390bd6dbdf5 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 22 Aug 2020 23:45:39 +0100 Subject: [PATCH] Don't allow preview to try and draw empty polygons. Fixes https://gitlab.com/kicad/code/kicad/issues/5314 --- common/preview_items/polygon_item.cpp | 22 +++++++++++++++++----- pcbnew/tools/drawing_tool.cpp | 20 +++++++++++--------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/common/preview_items/polygon_item.cpp b/common/preview_items/polygon_item.cpp index 9698793f33..6f0f57bd9f 100644 --- a/common/preview_items/polygon_item.cpp +++ b/common/preview_items/polygon_item.cpp @@ -57,14 +57,26 @@ void POLYGON_ITEM::drawPreviewShape( KIGFX::VIEW* aView ) const auto& gal = *aView->GetGAL(); auto rs = aView->GetPainter()->GetSettings(); - gal.SetLineWidth( (float) aView->ToWorld( POLY_LINE_WIDTH ) ); - gal.DrawPolyline( m_lockedChain ); + if( m_lockedChain.PointCount() >= 2 ) + { + gal.SetLineWidth( (float) aView->ToWorld( POLY_LINE_WIDTH ) ); + gal.DrawPolyline( m_lockedChain ); + } // draw the leader line in a different color - gal.SetStrokeColor( rs->GetLayerColor( LAYER_AUX_ITEMS ) ); - gal.DrawPolyline( m_leaderChain ); + if( m_leaderChain.PointCount() >= 2 ) + { + gal.SetStrokeColor( rs->GetLayerColor( LAYER_AUX_ITEMS ) ); + gal.DrawPolyline( m_leaderChain ); + } - gal.DrawPolygon( m_polyfill ); + for( int j = 0; j < m_polyfill.OutlineCount(); ++j ) + { + const SHAPE_LINE_CHAIN& outline = m_polyfill.COutline( j ); + + if( outline.PointCount() >= 2 ) + gal.DrawPolygon( outline ); + } } diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index f121481d8d..eda8782449 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -1548,8 +1548,9 @@ int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent ) grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetUseGrid( !evt->Modifier( MD_ALT ) ); m_controls->SetSnapping( !evt->Modifier( MD_ALT ) ); - VECTOR2I cursorPos = grid.BestSnapAnchor( - evt->IsPrime() ? evt->Position() : m_controls->GetMousePosition(), layers ); + VECTOR2I cursorPos = grid.BestSnapAnchor( evt->IsPrime() ? evt->Position() + : m_controls->GetMousePosition(), + layers ); m_controls->ForceCursorPosition( true, cursorPos ); if( ( sourceZone && sourceZone->GetHV45() ) || constrainAngle || evt->Modifier( MD_CTRL ) ) @@ -1557,13 +1558,14 @@ int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent ) else polyGeomMgr.SetLeaderMode( POLYGON_GEOM_MANAGER::LEADER_MODE::DIRECT ); - auto cleanup = [&] () { - polyGeomMgr.Reset(); - started = false; - grid.ClearSkipPoint(); - m_controls->SetAutoPan( false ); - m_controls->CaptureCursor( false ); - }; + auto cleanup = [&] () + { + polyGeomMgr.Reset(); + started = false; + grid.ClearSkipPoint(); + m_controls->SetAutoPan( false ); + m_controls->CaptureCursor( false ); + }; if( evt->IsCancelInteractive()) {