2012-06-08 09:56:42 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
|
|
|
|
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* Some code comes from FreePCB.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2020-11-11 23:05:59 +00:00
|
|
|
#include <zone.h>
|
2008-01-04 12:32:10 +00:00
|
|
|
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
bool BOARD::OnAreaPolygonModified( PICKED_ITEMS_LIST* aModifiedZonesList, ZONE* modified_area )
|
2008-01-04 12:32:10 +00:00
|
|
|
{
|
|
|
|
// clip polygon against itself
|
2012-07-31 13:12:51 +00:00
|
|
|
bool modified = NormalizeAreaPolygon( aModifiedZonesList, modified_area );
|
2008-01-04 12:32:10 +00:00
|
|
|
|
|
|
|
// now see if we need to clip against other areas
|
2020-11-11 23:05:59 +00:00
|
|
|
if( TestZoneIntersections( modified_area ) )
|
2012-07-31 13:12:51 +00:00
|
|
|
{
|
|
|
|
modified = true;
|
2020-11-11 23:05:59 +00:00
|
|
|
CombineAllZonesInNet( aModifiedZonesList, modified_area->GetNetCode(), true );
|
2012-07-31 13:12:51 +00:00
|
|
|
}
|
2008-01-04 12:32:10 +00:00
|
|
|
|
2008-11-28 20:10:05 +00:00
|
|
|
// Test for bad areas: all zones must have more than 2 corners:
|
|
|
|
// Note: should not happen, but just in case.
|
2020-11-11 23:05:59 +00:00
|
|
|
for( ZONE* zone : m_zones )
|
2008-11-28 20:10:05 +00:00
|
|
|
{
|
2020-08-26 23:52:12 +00:00
|
|
|
if( zone->GetNumCorners() < 3 )
|
2020-11-11 23:05:59 +00:00
|
|
|
RemoveZone( aModifiedZonesList, zone );
|
2008-11-28 20:10:05 +00:00
|
|
|
}
|
2009-03-11 13:29:10 +00:00
|
|
|
|
2012-07-31 13:12:51 +00:00
|
|
|
return modified;
|
2008-01-04 12:32:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
bool BOARD::CombineAllZonesInNet( PICKED_ITEMS_LIST* aDeletedList, int aNetCode,
|
2013-03-26 09:58:40 +00:00
|
|
|
bool aUseLocalFlags )
|
2008-01-04 12:32:10 +00:00
|
|
|
{
|
2020-08-26 23:52:12 +00:00
|
|
|
if( m_zones.size() <= 1 )
|
2012-07-31 13:12:51 +00:00
|
|
|
return false;
|
2009-03-11 13:29:10 +00:00
|
|
|
|
2012-07-31 13:12:51 +00:00
|
|
|
bool modified = false;
|
2009-03-11 13:29:10 +00:00
|
|
|
|
2014-11-08 12:25:29 +00:00
|
|
|
// Loop through all combinations
|
2020-08-26 23:52:12 +00:00
|
|
|
for( unsigned ia1 = 0; ia1 < m_zones.size() - 1; ia1++ )
|
2008-01-04 12:32:10 +00:00
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* refZone = m_zones[ia1];
|
2013-03-20 14:50:12 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
if( refZone->GetNetCode() != aNetCode )
|
2009-03-11 13:29:10 +00:00
|
|
|
continue;
|
2008-01-04 12:32:10 +00:00
|
|
|
|
2009-03-11 13:29:10 +00:00
|
|
|
// legal polygon
|
2020-11-11 23:05:59 +00:00
|
|
|
BOX2I b1 = refZone->Outline()->BBox();
|
2009-03-11 13:29:10 +00:00
|
|
|
bool mod_ia1 = false;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2020-08-26 23:52:12 +00:00
|
|
|
for( unsigned ia2 = m_zones.size() - 1; ia2 > ia1; ia2-- )
|
2008-01-04 12:32:10 +00:00
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* otherZone = m_zones[ia2];
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
if( otherZone->GetNetCode() != aNetCode )
|
2008-01-04 12:32:10 +00:00
|
|
|
continue;
|
2012-07-13 18:55:29 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
if( refZone->GetPriority() != otherZone->GetPriority() )
|
2012-01-29 19:29:19 +00:00
|
|
|
continue;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
if( refZone->GetIsRuleArea() != otherZone->GetIsRuleArea() )
|
2012-07-13 18:55:29 +00:00
|
|
|
continue;
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
if( refZone->GetLayerSet() != otherZone->GetLayerSet() )
|
2012-08-04 09:43:27 +00:00
|
|
|
continue;
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
BOX2I b2 = otherZone->Outline()->BBox();
|
2013-03-20 14:50:12 +00:00
|
|
|
|
2014-11-08 12:25:29 +00:00
|
|
|
if( b1.Intersects( b2 ) )
|
2008-01-04 12:32:10 +00:00
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
// check otherZone against refZone
|
|
|
|
if( refZone->GetLocalFlags() || otherZone->GetLocalFlags() || !aUseLocalFlags )
|
2008-01-04 12:32:10 +00:00
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
bool ret = TestZoneIntersection( refZone, otherZone );
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-08-04 09:43:27 +00:00
|
|
|
if( ret )
|
2020-11-11 23:05:59 +00:00
|
|
|
ret = CombineZones( aDeletedList, refZone, otherZone );
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-08-04 09:43:27 +00:00
|
|
|
if( ret )
|
|
|
|
{
|
|
|
|
mod_ia1 = true;
|
|
|
|
modified = true;
|
2008-01-04 12:32:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-03-11 13:29:10 +00:00
|
|
|
|
|
|
|
if( mod_ia1 )
|
|
|
|
ia1--; // if modified, we need to check it again
|
2008-01-04 12:32:10 +00:00
|
|
|
}
|
2008-11-28 20:10:05 +00:00
|
|
|
|
2012-07-31 13:12:51 +00:00
|
|
|
return modified;
|
2008-01-04 12:32:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
bool BOARD::TestZoneIntersections( ZONE* aZone )
|
2008-01-04 12:32:10 +00:00
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
for( ZONE* otherZone : m_zones )
|
2008-01-04 12:32:10 +00:00
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
if( aZone->GetNetCode() != otherZone->GetNetCode() )
|
2008-01-04 12:32:10 +00:00
|
|
|
continue;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
if( aZone == otherZone )
|
2008-01-20 19:55:22 +00:00
|
|
|
continue;
|
|
|
|
|
2018-09-16 20:54:43 +00:00
|
|
|
// see if areas are on same layers
|
2020-11-11 23:05:59 +00:00
|
|
|
if( aZone->GetLayerSet() != otherZone->GetLayerSet() )
|
2008-01-20 19:55:22 +00:00
|
|
|
continue;
|
|
|
|
|
2012-07-13 18:55:29 +00:00
|
|
|
// test for different priorities
|
2020-11-11 23:05:59 +00:00
|
|
|
if( aZone->GetPriority() != otherZone->GetPriority() )
|
2012-01-29 19:29:19 +00:00
|
|
|
continue;
|
|
|
|
|
2012-07-13 18:55:29 +00:00
|
|
|
// test for different types
|
2020-11-11 23:05:59 +00:00
|
|
|
if( aZone->GetIsRuleArea() != otherZone->GetIsRuleArea() )
|
2012-07-13 18:55:29 +00:00
|
|
|
continue;
|
|
|
|
|
2018-09-16 20:54:43 +00:00
|
|
|
// Keepout area-specific tests
|
2020-11-11 23:05:59 +00:00
|
|
|
if( aZone->GetIsRuleArea() )
|
2018-09-16 20:54:43 +00:00
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
if( aZone->GetDoNotAllowCopperPour() != otherZone->GetDoNotAllowCopperPour() )
|
2018-09-16 20:54:43 +00:00
|
|
|
continue;
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
if( aZone->GetDoNotAllowTracks() != otherZone->GetDoNotAllowTracks() )
|
2018-09-16 20:54:43 +00:00
|
|
|
continue;
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
if( aZone->GetDoNotAllowVias() != otherZone->GetDoNotAllowVias() )
|
2018-09-16 20:54:43 +00:00
|
|
|
continue;
|
2020-05-07 00:30:46 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
if( aZone->GetDoNotAllowPads() != otherZone->GetDoNotAllowPads() )
|
2020-05-07 00:30:46 +00:00
|
|
|
continue;
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
if( aZone->GetDoNotAllowFootprints() != otherZone->GetDoNotAllowFootprints() )
|
2020-05-07 00:30:46 +00:00
|
|
|
continue;
|
2018-09-16 20:54:43 +00:00
|
|
|
}
|
2018-09-17 00:14:10 +00:00
|
|
|
// Filled zone specific tests
|
|
|
|
else
|
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
if( aZone->GetLocalClearance() != otherZone->GetLocalClearance() )
|
2018-09-17 00:14:10 +00:00
|
|
|
continue;
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
if( aZone->GetThermalReliefGap() != otherZone->GetThermalReliefGap() )
|
2018-09-17 00:14:10 +00:00
|
|
|
continue;
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
if( aZone->GetThermalReliefSpokeWidth() != otherZone->GetThermalReliefSpokeWidth() )
|
2018-09-17 00:14:10 +00:00
|
|
|
continue;
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
if( aZone->GetLocalClearance() != otherZone->GetLocalClearance() )
|
2018-09-17 00:14:10 +00:00
|
|
|
continue;
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
if( aZone->GetPadConnection() != otherZone->GetPadConnection() )
|
2018-09-17 00:14:10 +00:00
|
|
|
continue;
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
if( aZone->GetMinThickness() != otherZone->GetMinThickness() )
|
2018-09-17 00:14:10 +00:00
|
|
|
continue;
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
if( aZone->GetCornerSmoothingType() != otherZone->GetCornerSmoothingType() )
|
2018-09-17 00:14:10 +00:00
|
|
|
continue;
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
if( aZone->GetCornerRadius() != otherZone->GetCornerRadius() )
|
2018-09-17 00:14:10 +00:00
|
|
|
continue;
|
|
|
|
}
|
2018-09-16 20:54:43 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
if( TestZoneIntersection( aZone, otherZone ) )
|
2012-08-02 13:23:53 +00:00
|
|
|
return true;
|
2008-01-20 19:55:22 +00:00
|
|
|
}
|
2008-01-04 12:32:10 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
bool BOARD::TestZoneIntersection( ZONE* aZone1, ZONE* aZone2 )
|
2008-01-04 12:32:10 +00:00
|
|
|
{
|
|
|
|
// see if areas are on same layer
|
2020-11-11 23:05:59 +00:00
|
|
|
if( aZone1->GetLayer() != aZone2->GetLayer() )
|
2012-08-02 13:23:53 +00:00
|
|
|
return false;
|
2008-01-04 12:32:10 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
SHAPE_POLY_SET* poly1 = aZone1->Outline();
|
|
|
|
SHAPE_POLY_SET* poly2 = aZone2->Outline();
|
2008-01-04 12:32:10 +00:00
|
|
|
|
|
|
|
// test bounding rects
|
2017-03-07 12:06:00 +00:00
|
|
|
BOX2I b1 = poly1->BBox();
|
|
|
|
BOX2I b2 = poly2->BBox();
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2014-11-08 12:25:29 +00:00
|
|
|
if( ! b1.Intersects( b2 ) )
|
2012-08-02 13:23:53 +00:00
|
|
|
return false;
|
2008-01-04 12:32:10 +00:00
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
// Now test for intersecting segments
|
|
|
|
for( auto segIterator1 = poly1->IterateSegmentsWithHoles(); segIterator1; segIterator1++ )
|
2008-01-04 12:32:10 +00:00
|
|
|
{
|
2017-03-07 12:06:00 +00:00
|
|
|
// Build segment
|
|
|
|
SEG firstSegment = *segIterator1;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
for( auto segIterator2 = poly2->IterateSegmentsWithHoles(); segIterator2; segIterator2++ )
|
2008-01-04 12:32:10 +00:00
|
|
|
{
|
2017-03-07 12:06:00 +00:00
|
|
|
// Build second segment
|
|
|
|
SEG secondSegment = *segIterator2;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
// Check whether the two segments built collide
|
|
|
|
if( firstSegment.Collide( secondSegment, 0 ) )
|
|
|
|
return true;
|
2008-01-04 12:32:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
// If a contour is inside another contour, no segments intersects, but the zones
|
|
|
|
// can be combined if a corner is inside an outline (only one corner is enough)
|
|
|
|
for( auto iter = poly2->IterateWithHoles(); iter; iter++ )
|
2008-01-20 19:55:22 +00:00
|
|
|
{
|
2017-03-07 12:06:00 +00:00
|
|
|
if( poly1->Contains( *iter ) )
|
2012-08-04 09:43:27 +00:00
|
|
|
return true;
|
2012-08-02 13:23:53 +00:00
|
|
|
}
|
2008-01-20 19:55:22 +00:00
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
for( auto iter = poly1->IterateWithHoles(); iter; iter++ )
|
2012-08-02 13:23:53 +00:00
|
|
|
{
|
2017-03-07 12:06:00 +00:00
|
|
|
if( poly2->Contains( *iter ) )
|
2012-08-04 09:43:27 +00:00
|
|
|
return true;
|
2008-01-20 19:55:22 +00:00
|
|
|
}
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-08-04 09:43:27 +00:00
|
|
|
return false;
|
2008-01-04 12:32:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
bool BOARD::CombineZones( PICKED_ITEMS_LIST* aDeletedList, ZONE* aRefZone, ZONE* aZoneToCombine )
|
2008-01-04 12:32:10 +00:00
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
if( aRefZone == aZoneToCombine )
|
2009-05-21 17:42:42 +00:00
|
|
|
{
|
2009-08-12 10:40:01 +00:00
|
|
|
wxASSERT( 0 );
|
2012-07-31 13:12:51 +00:00
|
|
|
return false;
|
2009-05-21 17:42:42 +00:00
|
|
|
}
|
2008-01-04 12:32:10 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
SHAPE_POLY_SET mergedOutlines = *aRefZone->Outline();
|
|
|
|
SHAPE_POLY_SET areaToMergePoly = *aZoneToCombine->Outline();
|
2012-07-25 07:36:56 +00:00
|
|
|
|
2015-12-15 20:21:25 +00:00
|
|
|
mergedOutlines.BooleanAdd( areaToMergePoly, SHAPE_POLY_SET::PM_FAST );
|
|
|
|
mergedOutlines.Simplify( SHAPE_POLY_SET::PM_FAST );
|
2012-07-25 07:36:56 +00:00
|
|
|
|
2012-08-04 09:43:27 +00:00
|
|
|
// We should have one polygon with hole
|
|
|
|
// We can have 2 polygons with hole, if the 2 initial polygons have only one common corner
|
|
|
|
// and therefore cannot be merged (they are dectected as intersecting)
|
|
|
|
// but we should never have more than 2 polys
|
2015-07-27 19:45:57 +00:00
|
|
|
if( mergedOutlines.OutlineCount() > 2 )
|
2012-08-04 09:43:27 +00:00
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
wxLogMessage( "BOARD::CombineZones error: more than 2 polys after merging" );
|
2012-08-04 09:43:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
if( mergedOutlines.OutlineCount() > 1 )
|
2012-08-04 09:43:27 +00:00
|
|
|
return false;
|
2008-05-15 11:20:19 +00:00
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
// Update the area with the new merged outline
|
2020-11-11 23:05:59 +00:00
|
|
|
delete aRefZone->Outline();
|
|
|
|
aRefZone->SetOutline( new SHAPE_POLY_SET( mergedOutlines ) );
|
2012-07-30 07:40:25 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
RemoveZone( aDeletedList, aZoneToCombine );
|
2008-05-30 18:06:21 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
aRefZone->SetLocalFlags( 1 );
|
|
|
|
aRefZone->HatchBorder();
|
2012-07-25 07:36:56 +00:00
|
|
|
|
2012-07-31 13:12:51 +00:00
|
|
|
return true;
|
2008-01-04 12:32:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|