Zones: fix a crash when adding a zone cutout to a zone having already holes.

Fixes #4039
https://gitlab.com/kicad/code/kicad/issues/4039
This commit is contained in:
jean-pierre charras 2020-03-12 14:42:32 +01:00
parent 9de7547c25
commit 78a7c7dfe0
2 changed files with 12 additions and 5 deletions

View File

@ -427,6 +427,8 @@ int SHAPE_POLY_SET::AddHole( const SHAPE_LINE_CHAIN& aHole, int aOutline )
if( aOutline < 0 )
aOutline += m_polys.size();
assert( aOutline < (int)m_polys.size() );
POLYGON& poly = m_polys[aOutline];
assert( poly.size() );

View File

@ -53,7 +53,7 @@ std::unique_ptr<ZONE_CONTAINER> ZONE_CREATE_HELPER::createNewZone( bool aKeepout
{
auto& frame = *m_tool.getEditFrame<PCB_BASE_EDIT_FRAME>();
auto& board = *m_tool.getModel<BOARD>();
BOARD_ITEM_CONTAINER* parent = m_tool.m_frame->GetModel();
BOARD_ITEM_CONTAINER* parent = m_tool.m_frame->GetModel();
KIGFX::VIEW_CONTROLS* controls = m_tool.GetManager()->GetViewControls();
// Get the current default settings for zones
@ -130,13 +130,18 @@ void ZONE_CREATE_HELPER::performZoneCutout( ZONE_CONTAINER& aZone, ZONE_CONTAINE
SHAPE_POLY_SET originalOutline( *aZone.Outline() );
originalOutline.BooleanSubtract( *aCutout.Outline(), SHAPE_POLY_SET::PM_FAST );
for( int i = 0; i < originalOutline.OutlineCount(); i++ )
// After substracting the hole, originalOutline can have more than one
// main outline.
// But a zone can have only one main outline, so create as many zones as
// originalOutline contains main outlines:
for( int outline = 0; outline < originalOutline.OutlineCount(); outline++ )
{
auto newZoneOutline = new SHAPE_POLY_SET;
newZoneOutline->AddOutline( originalOutline.Outline( i ) );
newZoneOutline->AddOutline( originalOutline.Outline( outline ) );
for (int j = 0; j < originalOutline.HoleCount(i) ; j++ )
newZoneOutline->AddHole( originalOutline.CHole(i, j), i );
// Add holes (if any) to thez new zone outline:
for (int hole = 0; hole < originalOutline.HoleCount( outline ) ; hole++ )
newZoneOutline->AddHole( originalOutline.CHole( outline, hole ) );
auto newZone = new ZONE_CONTAINER( aZone );
newZone->SetOutline( newZoneOutline );