2017-11-30 16:22:45 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014-2017 CERN
|
2021-06-25 17:45:15 +00:00
|
|
|
* Copyright (C) 2014-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-11-30 16:22:45 +00:00
|
|
|
* @author Tomasz Włostowski <tomasz.wlostowski@cern.ch>
|
|
|
|
*
|
2019-01-19 11:35:35 +00:00
|
|
|
* 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 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
2017-11-30 16:22:45 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <thread>
|
2018-11-06 04:22:16 +00:00
|
|
|
#include <future>
|
2021-10-01 10:52:34 +00:00
|
|
|
#include <core/kicad_algo.h>
|
2020-07-26 14:20:24 +00:00
|
|
|
#include <advanced_config.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <board_design_settings.h>
|
2020-11-11 23:05:59 +00:00
|
|
|
#include <zone.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <footprint.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <pad.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <pcb_shape.h>
|
2020-11-11 23:05:59 +00:00
|
|
|
#include <pcb_target.h>
|
2021-06-11 21:07:02 +00:00
|
|
|
#include <pcb_track.h>
|
2018-10-12 06:17:15 +00:00
|
|
|
#include <connectivity/connectivity_data.h>
|
2020-07-27 19:41:50 +00:00
|
|
|
#include <convert_basic_shapes_to_polygon.h>
|
2017-11-30 16:22:45 +00:00
|
|
|
#include <board_commit.h>
|
2021-08-14 20:05:21 +00:00
|
|
|
#include <progress_reporter.h>
|
2017-12-04 18:06:47 +00:00
|
|
|
#include <geometry/shape_poly_set.h>
|
|
|
|
#include <geometry/convex_hull.h>
|
2018-03-08 12:48:29 +00:00
|
|
|
#include <geometry/geometry_utils.h>
|
2018-04-06 10:24:23 +00:00
|
|
|
#include <confirm.h>
|
2019-10-12 09:03:44 +00:00
|
|
|
#include <convert_to_biu.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/util.h> // for KiROUND
|
2017-11-30 16:22:45 +00:00
|
|
|
#include "zone_filler.h"
|
|
|
|
|
2020-09-18 12:13:34 +00:00
|
|
|
static const double s_RoundPadThermalSpokeAngle = 450; // in deci-degrees
|
2017-11-30 16:22:45 +00:00
|
|
|
|
2019-04-10 09:19:16 +00:00
|
|
|
|
2017-11-30 16:22:45 +00:00
|
|
|
ZONE_FILLER::ZONE_FILLER( BOARD* aBoard, COMMIT* aCommit ) :
|
2020-09-10 23:05:20 +00:00
|
|
|
m_board( aBoard ),
|
|
|
|
m_brdOutlinesValid( false ),
|
|
|
|
m_commit( aCommit ),
|
|
|
|
m_progressReporter( nullptr ),
|
2020-10-25 09:02:07 +00:00
|
|
|
m_maxError( ARC_HIGH_DEF ),
|
|
|
|
m_worstClearance( 0 )
|
2017-11-30 16:22:45 +00:00
|
|
|
{
|
2020-09-29 11:33:44 +00:00
|
|
|
// To enable add "DebugZoneFiller=1" to kicad_advanced settings file.
|
2020-09-23 09:35:13 +00:00
|
|
|
m_debugZoneFiller = ADVANCED_CFG::GetCfg().m_DebugZoneFiller;
|
2017-11-30 16:22:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ZONE_FILLER::~ZONE_FILLER()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-16 15:03:55 +00:00
|
|
|
void ZONE_FILLER::SetProgressReporter( PROGRESS_REPORTER* aReporter )
|
2020-09-14 17:54:14 +00:00
|
|
|
{
|
|
|
|
m_progressReporter = aReporter;
|
2022-02-04 22:44:59 +00:00
|
|
|
wxASSERT_MSG( m_commit, wxT( "ZONE_FILLER must have a valid commit to call "
|
|
|
|
"SetProgressReporter" ) );
|
2019-06-29 19:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
bool ZONE_FILLER::Fill( std::vector<ZONE*>& aZones, bool aCheck, wxWindow* aParent )
|
2017-11-30 16:22:45 +00:00
|
|
|
{
|
2021-12-14 21:35:46 +00:00
|
|
|
std::lock_guard<KISPINLOCK> lock( m_board->GetConnectivity()->GetLock() );
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
std::vector<std::pair<ZONE*, PCB_LAYER_ID>> toFill;
|
2020-07-01 02:21:59 +00:00
|
|
|
std::vector<CN_ZONE_ISOLATED_ISLAND_LIST> islandsList;
|
|
|
|
|
2020-09-17 13:14:45 +00:00
|
|
|
std::shared_ptr<CONNECTIVITY_DATA> connectivity = m_board->GetConnectivity();
|
2020-12-28 18:18:23 +00:00
|
|
|
|
2020-12-29 19:58:38 +00:00
|
|
|
// Rebuild just in case. This really needs to be reliable.
|
|
|
|
connectivity->Clear();
|
|
|
|
connectivity->Build( m_board, m_progressReporter );
|
|
|
|
|
2020-09-17 13:14:45 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
|
2020-10-24 15:32:37 +00:00
|
|
|
|
|
|
|
m_worstClearance = bds.GetBiggestClearanceValue();
|
2020-09-17 13:14:45 +00:00
|
|
|
|
2019-04-10 09:19:16 +00:00
|
|
|
if( m_progressReporter )
|
|
|
|
{
|
2020-08-05 15:50:32 +00:00
|
|
|
m_progressReporter->Report( aCheck ? _( "Checking zone fills..." )
|
|
|
|
: _( "Building zone fills..." ) );
|
2020-07-01 02:21:59 +00:00
|
|
|
m_progressReporter->SetMaxProgress( aZones.size() );
|
2020-09-14 17:54:14 +00:00
|
|
|
m_progressReporter->KeepRefreshing();
|
2019-04-10 09:19:16 +00:00
|
|
|
}
|
|
|
|
|
2019-06-22 07:55:25 +00:00
|
|
|
// The board outlines is used to clip solid areas inside the board (when outlines are valid)
|
|
|
|
m_boardOutline.RemoveAllContours();
|
|
|
|
m_brdOutlinesValid = m_board->GetBoardPolygonOutlines( m_boardOutline );
|
|
|
|
|
2020-10-24 15:32:37 +00:00
|
|
|
// Update and cache zone bounding boxes and pad effective shapes so that we don't have to
|
|
|
|
// make them thread-safe.
|
2020-11-11 23:05:59 +00:00
|
|
|
for( ZONE* zone : m_board->Zones() )
|
2020-10-24 15:32:37 +00:00
|
|
|
{
|
|
|
|
zone->CacheBoundingBox();
|
|
|
|
m_worstClearance = std::max( m_worstClearance, zone->GetLocalClearance() );
|
|
|
|
}
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2020-06-28 18:00:40 +00:00
|
|
|
{
|
2020-11-13 02:57:11 +00:00
|
|
|
for( PAD* pad : footprint->Pads() )
|
2020-06-28 18:00:40 +00:00
|
|
|
{
|
|
|
|
if( pad->IsDirty() )
|
2021-01-08 00:26:32 +00:00
|
|
|
{
|
2020-08-12 21:18:13 +00:00
|
|
|
pad->BuildEffectiveShapes( UNDEFINED_LAYER );
|
2021-01-08 00:26:32 +00:00
|
|
|
pad->BuildEffectivePolygon();
|
|
|
|
}
|
2021-01-13 12:27:58 +00:00
|
|
|
|
|
|
|
m_worstClearance = std::max( m_worstClearance, pad->GetLocalClearance() );
|
2020-06-28 18:00:40 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
for( ZONE* zone : footprint->Zones() )
|
2020-10-23 13:26:46 +00:00
|
|
|
{
|
|
|
|
zone->CacheBoundingBox();
|
2020-10-24 15:32:37 +00:00
|
|
|
m_worstClearance = std::max( m_worstClearance, zone->GetLocalClearance() );
|
2020-10-23 13:26:46 +00:00
|
|
|
}
|
2021-04-25 11:44:30 +00:00
|
|
|
|
|
|
|
// Rules may depend on insideCourtyard() or other expressions
|
2022-07-31 21:14:24 +00:00
|
|
|
footprint->BuildCourtyardCaches();
|
2020-10-23 13:26:46 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 19:20:20 +00:00
|
|
|
// Sort by priority to reduce deferrals waiting on higher priority zones.
|
|
|
|
std::sort( aZones.begin(), aZones.end(),
|
2020-11-11 23:05:59 +00:00
|
|
|
[]( const ZONE* lhs, const ZONE* rhs )
|
2020-09-21 19:20:20 +00:00
|
|
|
{
|
|
|
|
return lhs->GetPriority() > rhs->GetPriority();
|
|
|
|
} );
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
for( ZONE* zone : aZones )
|
2017-11-30 16:22:45 +00:00
|
|
|
{
|
2020-09-21 23:32:07 +00:00
|
|
|
// Rule areas are not filled
|
|
|
|
if( zone->GetIsRuleArea() )
|
2017-11-30 16:22:45 +00:00
|
|
|
continue;
|
|
|
|
|
2020-09-24 22:08:23 +00:00
|
|
|
if( m_commit )
|
|
|
|
m_commit->Modify( zone );
|
2019-03-12 00:07:00 +00:00
|
|
|
|
2019-03-21 14:27:05 +00:00
|
|
|
// calculate the hash value for filled areas. it will be used later
|
|
|
|
// to know if the current filled areas are up to date
|
2020-06-24 02:19:08 +00:00
|
|
|
for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
|
|
|
|
{
|
|
|
|
zone->BuildHashValue( layer );
|
2019-03-21 14:27:05 +00:00
|
|
|
|
2020-06-24 02:19:08 +00:00
|
|
|
// Add the zone to the list of zones to test or refill
|
2020-07-01 02:21:59 +00:00
|
|
|
toFill.emplace_back( std::make_pair( zone, layer ) );
|
2020-06-24 02:19:08 +00:00
|
|
|
}
|
2019-03-21 14:27:05 +00:00
|
|
|
|
2020-07-01 02:21:59 +00:00
|
|
|
islandsList.emplace_back( CN_ZONE_ISOLATED_ISLAND_LIST( zone ) );
|
|
|
|
|
2019-03-12 00:07:00 +00:00
|
|
|
// Remove existing fill first to prevent drawing invalid polygons
|
2019-03-21 14:27:05 +00:00
|
|
|
// on some platforms
|
2019-03-12 00:07:00 +00:00
|
|
|
zone->UnFill();
|
2020-09-17 13:14:45 +00:00
|
|
|
|
|
|
|
zone->SetFillVersion( bds.m_ZoneFillVersion );
|
2017-11-30 16:22:45 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 19:20:20 +00:00
|
|
|
size_t cores = std::thread::hardware_concurrency();
|
|
|
|
std::atomic<size_t> nextItem;
|
2018-09-21 12:21:12 +00:00
|
|
|
|
2020-09-21 19:20:20 +00:00
|
|
|
auto check_fill_dependency =
|
2020-11-11 23:05:59 +00:00
|
|
|
[&]( ZONE* aZone, PCB_LAYER_ID aLayer, ZONE* aOtherZone ) -> bool
|
2020-08-05 15:50:32 +00:00
|
|
|
{
|
2020-09-21 19:20:20 +00:00
|
|
|
// Check to see if we have to knock-out the filled areas of a higher-priority
|
|
|
|
// zone. If so we have to wait until said zone is filled before we can fill.
|
2020-09-17 13:14:45 +00:00
|
|
|
|
2020-09-21 19:20:20 +00:00
|
|
|
// If the other zone is already filled then we're good-to-go
|
|
|
|
if( aOtherZone->GetFillFlag( aLayer ) )
|
|
|
|
return false;
|
2018-11-06 04:22:16 +00:00
|
|
|
|
2020-09-21 19:20:20 +00:00
|
|
|
// Even if keepouts exclude copper pours the exclusion is by outline, not by
|
|
|
|
// filled area, so we're good-to-go here too.
|
2020-09-21 23:32:07 +00:00
|
|
|
if( aOtherZone->GetIsRuleArea() )
|
2020-09-21 19:20:20 +00:00
|
|
|
return false;
|
2020-09-17 13:14:45 +00:00
|
|
|
|
2020-09-21 19:20:20 +00:00
|
|
|
// If the zones share no common layers
|
|
|
|
if( !aOtherZone->GetLayerSet().test( aLayer ) )
|
|
|
|
return false;
|
2020-09-17 13:14:45 +00:00
|
|
|
|
2020-09-21 19:20:20 +00:00
|
|
|
if( aOtherZone->GetPriority() <= aZone->GetPriority() )
|
|
|
|
return false;
|
2020-06-24 02:19:08 +00:00
|
|
|
|
2020-09-21 19:20:20 +00:00
|
|
|
// Same-net zones always use outline to produce predictable results
|
|
|
|
if( aOtherZone->GetNetCode() == aZone->GetNetCode() )
|
|
|
|
return false;
|
2020-06-24 02:19:08 +00:00
|
|
|
|
2020-09-21 19:20:20 +00:00
|
|
|
// A higher priority zone is found: if we intersect and it's not filled yet
|
|
|
|
// then we have to wait.
|
|
|
|
EDA_RECT inflatedBBox = aZone->GetCachedBoundingBox();
|
2020-10-24 15:32:37 +00:00
|
|
|
inflatedBBox.Inflate( m_worstClearance );
|
2020-09-17 13:14:45 +00:00
|
|
|
|
2020-09-21 19:20:20 +00:00
|
|
|
return inflatedBBox.Intersects( aOtherZone->GetCachedBoundingBox() );
|
|
|
|
};
|
2020-09-17 13:14:45 +00:00
|
|
|
|
2020-09-21 19:20:20 +00:00
|
|
|
auto fill_lambda =
|
|
|
|
[&]( PROGRESS_REPORTER* aReporter )
|
|
|
|
{
|
|
|
|
size_t num = 0;
|
2020-09-17 13:14:45 +00:00
|
|
|
|
2020-09-21 19:20:20 +00:00
|
|
|
for( size_t i = nextItem++; i < toFill.size(); i = nextItem++ )
|
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
PCB_LAYER_ID layer = toFill[i].second;
|
|
|
|
ZONE* zone = toFill[i].first;
|
|
|
|
bool canFill = true;
|
2020-09-21 19:20:20 +00:00
|
|
|
|
|
|
|
// Check for any fill dependencies. If our zone needs to be clipped by
|
|
|
|
// another zone then we can't fill until that zone is filled.
|
2020-11-11 23:05:59 +00:00
|
|
|
for( ZONE* otherZone : aZones )
|
2020-09-21 19:20:20 +00:00
|
|
|
{
|
|
|
|
if( otherZone == zone )
|
2020-09-17 13:14:45 +00:00
|
|
|
continue;
|
|
|
|
|
2020-09-21 19:20:20 +00:00
|
|
|
if( check_fill_dependency( zone, layer, otherZone ) )
|
2020-09-17 13:14:45 +00:00
|
|
|
{
|
|
|
|
canFill = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-21 19:20:20 +00:00
|
|
|
if( m_progressReporter && m_progressReporter->IsCancelled() )
|
|
|
|
break;
|
|
|
|
|
|
|
|
if( !canFill )
|
|
|
|
continue;
|
|
|
|
|
2020-09-17 13:14:45 +00:00
|
|
|
// Now we're ready to fill.
|
2020-08-05 15:50:32 +00:00
|
|
|
SHAPE_POLY_SET rawPolys, finalPolys;
|
|
|
|
fillSingleZone( zone, layer, rawPolys, finalPolys );
|
2019-04-10 15:49:40 +00:00
|
|
|
|
2020-08-05 15:50:32 +00:00
|
|
|
std::unique_lock<std::mutex> zoneLock( zone->GetLock() );
|
2020-07-01 02:21:59 +00:00
|
|
|
|
2020-08-05 15:50:32 +00:00
|
|
|
zone->SetRawPolysList( layer, rawPolys );
|
|
|
|
zone->SetFilledPolysList( layer, finalPolys );
|
2020-09-17 13:14:45 +00:00
|
|
|
zone->SetFillFlag( layer, true );
|
2018-09-21 12:21:12 +00:00
|
|
|
|
2020-08-05 15:50:32 +00:00
|
|
|
if( m_progressReporter )
|
|
|
|
m_progressReporter->AdvanceProgress();
|
2018-11-06 04:22:16 +00:00
|
|
|
|
2020-08-05 15:50:32 +00:00
|
|
|
num++;
|
|
|
|
}
|
2018-02-10 13:32:57 +00:00
|
|
|
|
2020-08-05 15:50:32 +00:00
|
|
|
return num;
|
|
|
|
};
|
2018-09-21 12:21:12 +00:00
|
|
|
|
2020-09-21 19:20:20 +00:00
|
|
|
while( !toFill.empty() )
|
2018-02-10 13:32:57 +00:00
|
|
|
{
|
2020-09-21 19:20:20 +00:00
|
|
|
size_t parallelThreadCount = std::min( cores, toFill.size() );
|
|
|
|
std::vector<std::future<size_t>> returns( parallelThreadCount );
|
2018-06-04 20:44:43 +00:00
|
|
|
|
2020-09-21 19:20:20 +00:00
|
|
|
nextItem = 0;
|
|
|
|
|
|
|
|
if( parallelThreadCount <= 1 )
|
|
|
|
fill_lambda( m_progressReporter );
|
|
|
|
else
|
2018-11-06 04:22:16 +00:00
|
|
|
{
|
2020-09-21 19:20:20 +00:00
|
|
|
for( size_t ii = 0; ii < parallelThreadCount; ++ii )
|
|
|
|
returns[ii] = std::async( std::launch::async, fill_lambda, m_progressReporter );
|
|
|
|
|
|
|
|
for( size_t ii = 0; ii < parallelThreadCount; ++ii )
|
2018-11-06 04:22:16 +00:00
|
|
|
{
|
2020-09-21 19:20:20 +00:00
|
|
|
// Here we balance returns with a 100ms timeout to allow UI updating
|
|
|
|
std::future_status status;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if( m_progressReporter )
|
|
|
|
m_progressReporter->KeepRefreshing();
|
2018-11-06 04:22:16 +00:00
|
|
|
|
2020-09-21 19:20:20 +00:00
|
|
|
status = returns[ii].wait_for( std::chrono::milliseconds( 100 ) );
|
|
|
|
} while( status != std::future_status::ready );
|
|
|
|
}
|
2018-11-06 04:22:16 +00:00
|
|
|
}
|
2020-09-21 19:20:20 +00:00
|
|
|
|
2021-10-01 10:52:34 +00:00
|
|
|
alg::delete_if( toFill, [&]( const std::pair<ZONE*, PCB_LAYER_ID> pair ) -> bool
|
|
|
|
{
|
|
|
|
return pair.first->GetFillFlag( pair.second );
|
|
|
|
} );
|
2020-09-21 19:20:20 +00:00
|
|
|
|
|
|
|
if( m_progressReporter && m_progressReporter->IsCancelled() )
|
|
|
|
break;
|
2017-11-30 16:22:45 +00:00
|
|
|
}
|
|
|
|
|
2018-09-21 12:21:12 +00:00
|
|
|
// Now update the connectivity to check for copper islands
|
2017-11-30 16:22:45 +00:00
|
|
|
if( m_progressReporter )
|
|
|
|
{
|
2020-08-04 18:53:16 +00:00
|
|
|
if( m_progressReporter->IsCancelled() )
|
|
|
|
return false;
|
2020-08-05 15:50:32 +00:00
|
|
|
|
|
|
|
m_progressReporter->AdvancePhase();
|
2020-11-18 23:28:16 +00:00
|
|
|
m_progressReporter->Report( _( "Removing isolated copper islands..." ) );
|
2020-08-05 15:50:32 +00:00
|
|
|
m_progressReporter->KeepRefreshing();
|
2017-11-30 16:22:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
connectivity->SetProgressReporter( m_progressReporter );
|
2020-07-01 02:21:59 +00:00
|
|
|
connectivity->FindIsolatedCopperIslands( islandsList );
|
2020-08-05 15:50:32 +00:00
|
|
|
connectivity->SetProgressReporter( nullptr );
|
2017-11-30 16:22:45 +00:00
|
|
|
|
2020-08-04 18:53:16 +00:00
|
|
|
if( m_progressReporter && m_progressReporter->IsCancelled() )
|
|
|
|
return false;
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
for( ZONE* zone : aZones )
|
2020-09-17 13:14:45 +00:00
|
|
|
{
|
|
|
|
// Keepout zones are not filled
|
2020-09-21 23:32:07 +00:00
|
|
|
if( zone->GetIsRuleArea() )
|
2020-09-17 13:14:45 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
zone->SetIsFilled( true );
|
|
|
|
}
|
|
|
|
|
2020-09-20 19:34:01 +00:00
|
|
|
// Now remove insulated copper islands
|
|
|
|
for( CN_ZONE_ISOLATED_ISLAND_LIST& zone : islandsList )
|
2017-11-30 16:22:45 +00:00
|
|
|
{
|
2020-07-01 02:21:59 +00:00
|
|
|
for( PCB_LAYER_ID layer : zone.m_zone->GetLayerSet().Seq() )
|
|
|
|
{
|
2020-09-23 09:35:13 +00:00
|
|
|
if( m_debugZoneFiller && LSET::InternalCuMask().Contains( layer ) )
|
2020-09-22 21:05:24 +00:00
|
|
|
continue;
|
|
|
|
|
2020-07-01 02:21:59 +00:00
|
|
|
if( !zone.m_islands.count( layer ) )
|
|
|
|
continue;
|
2017-11-30 16:22:45 +00:00
|
|
|
|
2020-07-01 02:21:59 +00:00
|
|
|
std::vector<int>& islands = zone.m_islands.at( layer );
|
2020-06-26 02:19:51 +00:00
|
|
|
|
2020-09-13 08:30:38 +00:00
|
|
|
// The list of polygons to delete must be explored from last to first in list,
|
|
|
|
// to allow deleting a polygon from list without breaking the remaining of the list
|
2020-07-01 02:21:59 +00:00
|
|
|
std::sort( islands.begin(), islands.end(), std::greater<int>() );
|
2020-09-13 08:30:38 +00:00
|
|
|
|
2020-09-20 19:34:01 +00:00
|
|
|
SHAPE_POLY_SET poly = zone.m_zone->GetFilledPolysList( layer );
|
2020-07-01 02:21:59 +00:00
|
|
|
long long int minArea = zone.m_zone->GetMinIslandArea();
|
|
|
|
ISLAND_REMOVAL_MODE mode = zone.m_zone->GetIslandRemovalMode();
|
|
|
|
|
2020-09-20 19:34:01 +00:00
|
|
|
for( int idx : islands )
|
2019-02-27 10:27:18 +00:00
|
|
|
{
|
2020-09-20 19:34:01 +00:00
|
|
|
SHAPE_LINE_CHAIN& outline = poly.Outline( idx );
|
|
|
|
|
|
|
|
if( mode == ISLAND_REMOVAL_MODE::ALWAYS )
|
|
|
|
poly.DeletePolygon( idx );
|
|
|
|
else if ( mode == ISLAND_REMOVAL_MODE::AREA && outline.Area() < minArea )
|
|
|
|
poly.DeletePolygon( idx );
|
|
|
|
else
|
|
|
|
zone.m_zone->SetIsIsland( layer, idx );
|
2019-05-14 12:39:34 +00:00
|
|
|
}
|
2019-04-08 12:10:08 +00:00
|
|
|
|
2020-07-01 02:21:59 +00:00
|
|
|
zone.m_zone->SetFilledPolysList( layer, poly );
|
|
|
|
zone.m_zone->CalculateFilledArea();
|
2018-04-09 14:07:53 +00:00
|
|
|
|
2020-08-04 18:53:16 +00:00
|
|
|
if( m_progressReporter && m_progressReporter->IsCancelled() )
|
|
|
|
return false;
|
2020-07-01 02:21:59 +00:00
|
|
|
}
|
2017-11-30 16:22:45 +00:00
|
|
|
}
|
|
|
|
|
2022-03-05 15:18:24 +00:00
|
|
|
// Now remove islands which are either outside the board edge or fail to meet the minimum
|
|
|
|
// area requirements
|
2020-11-11 23:05:59 +00:00
|
|
|
for( ZONE* zone : aZones )
|
2020-09-20 19:34:01 +00:00
|
|
|
{
|
2022-03-05 15:18:24 +00:00
|
|
|
LSET zoneCopperLayers = zone->GetLayerSet() & LSET::AllCuMask( MAX_CU_LAYERS );
|
|
|
|
|
|
|
|
// Min-thickness is the web thickness. On the other hand, a blob min-thickness by
|
|
|
|
// min-thickness is not useful. Since there's no obvious definition of web vs. blob, we
|
|
|
|
// arbitrarily choose "at least 2X the area".
|
|
|
|
double minArea = (double) zone->GetMinThickness() * zone->GetMinThickness() * 2;
|
2020-09-30 10:48:44 +00:00
|
|
|
|
|
|
|
for( PCB_LAYER_ID layer : zoneCopperLayers.Seq() )
|
2020-09-20 19:34:01 +00:00
|
|
|
{
|
2020-09-23 09:35:13 +00:00
|
|
|
if( m_debugZoneFiller && LSET::InternalCuMask().Contains( layer ) )
|
2020-09-22 21:05:24 +00:00
|
|
|
continue;
|
|
|
|
|
2020-09-20 19:34:01 +00:00
|
|
|
SHAPE_POLY_SET poly = zone->GetFilledPolysList( layer );
|
|
|
|
|
2020-09-29 13:08:10 +00:00
|
|
|
for( int ii = poly.OutlineCount() - 1; ii >= 0; ii-- )
|
2020-09-20 19:34:01 +00:00
|
|
|
{
|
|
|
|
std::vector<SHAPE_LINE_CHAIN>& island = poly.Polygon( ii );
|
|
|
|
|
2022-03-05 15:18:24 +00:00
|
|
|
if( island.empty()
|
|
|
|
|| !m_boardOutline.Contains( island.front().CPoint( 0 ) )
|
|
|
|
|| island.front().Area() < minArea )
|
|
|
|
{
|
2020-09-20 19:34:01 +00:00
|
|
|
poly.DeletePolygon( ii );
|
2022-03-05 15:18:24 +00:00
|
|
|
}
|
2020-09-20 19:34:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
zone->SetFilledPolysList( layer, poly );
|
|
|
|
zone->CalculateFilledArea();
|
|
|
|
|
|
|
|
if( m_progressReporter && m_progressReporter->IsCancelled() )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
if( aCheck )
|
2018-04-06 10:24:23 +00:00
|
|
|
{
|
2020-09-14 17:54:14 +00:00
|
|
|
bool outOfDate = false;
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
for( ZONE* zone : aZones )
|
2020-09-14 17:54:14 +00:00
|
|
|
{
|
|
|
|
// Keepout zones are not filled
|
2020-09-21 23:32:07 +00:00
|
|
|
if( zone->GetIsRuleArea() )
|
2020-09-14 17:54:14 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
|
|
|
|
{
|
|
|
|
MD5_HASH was = zone->GetHashValue( layer );
|
|
|
|
zone->CacheTriangulation( layer );
|
|
|
|
zone->BuildHashValue( layer );
|
|
|
|
MD5_HASH is = zone->GetHashValue( layer );
|
|
|
|
|
|
|
|
if( is != was )
|
|
|
|
outOfDate = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( outOfDate )
|
|
|
|
{
|
2020-09-16 15:03:55 +00:00
|
|
|
KIDIALOG dlg( aParent, _( "Zone fills are out-of-date. Refill?" ),
|
2020-09-14 17:54:14 +00:00
|
|
|
_( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
|
|
|
|
dlg.SetOKCancelLabels( _( "Refill" ), _( "Continue without Refill" ) );
|
|
|
|
dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return false;
|
|
|
|
}
|
2021-12-22 15:15:25 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// No need to commit something that hasn't changed (and committing will set
|
|
|
|
// the modified flag).
|
|
|
|
return false;
|
|
|
|
}
|
2018-04-06 10:24:23 +00:00
|
|
|
}
|
|
|
|
|
2017-11-30 16:22:45 +00:00
|
|
|
if( m_progressReporter )
|
|
|
|
{
|
|
|
|
m_progressReporter->AdvancePhase();
|
2018-04-06 10:24:23 +00:00
|
|
|
m_progressReporter->Report( _( "Performing polygon fills..." ) );
|
2020-09-21 19:20:20 +00:00
|
|
|
m_progressReporter->SetMaxProgress( islandsList.size() );
|
2017-11-30 16:22:45 +00:00
|
|
|
}
|
2018-02-10 13:32:57 +00:00
|
|
|
|
2018-09-21 12:21:12 +00:00
|
|
|
nextItem = 0;
|
2018-02-10 13:32:57 +00:00
|
|
|
|
2020-08-05 15:50:32 +00:00
|
|
|
auto tri_lambda =
|
|
|
|
[&]( PROGRESS_REPORTER* aReporter ) -> size_t
|
|
|
|
{
|
|
|
|
size_t num = 0;
|
2018-06-04 20:44:43 +00:00
|
|
|
|
2020-08-05 15:50:32 +00:00
|
|
|
for( size_t i = nextItem++; i < islandsList.size(); i = nextItem++ )
|
|
|
|
{
|
|
|
|
islandsList[i].m_zone->CacheTriangulation();
|
|
|
|
num++;
|
2018-01-14 08:51:32 +00:00
|
|
|
|
2020-08-05 15:50:32 +00:00
|
|
|
if( m_progressReporter )
|
|
|
|
{
|
|
|
|
m_progressReporter->AdvanceProgress();
|
2020-08-04 18:53:16 +00:00
|
|
|
|
2020-08-05 15:50:32 +00:00
|
|
|
if( m_progressReporter->IsCancelled() )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-01-14 08:51:32 +00:00
|
|
|
|
2020-08-05 15:50:32 +00:00
|
|
|
return num;
|
|
|
|
};
|
2018-10-07 04:05:04 +00:00
|
|
|
|
2020-09-21 19:20:20 +00:00
|
|
|
size_t parallelThreadCount = std::min( cores, islandsList.size() );
|
|
|
|
std::vector<std::future<size_t>> returns( parallelThreadCount );
|
|
|
|
|
2018-11-06 04:22:16 +00:00
|
|
|
if( parallelThreadCount <= 1 )
|
|
|
|
tri_lambda( m_progressReporter );
|
|
|
|
else
|
2018-01-14 08:51:32 +00:00
|
|
|
{
|
2018-11-06 04:22:16 +00:00
|
|
|
for( size_t ii = 0; ii < parallelThreadCount; ++ii )
|
|
|
|
returns[ii] = std::async( std::launch::async, tri_lambda, m_progressReporter );
|
2018-01-14 08:51:32 +00:00
|
|
|
|
2018-09-21 12:21:12 +00:00
|
|
|
for( size_t ii = 0; ii < parallelThreadCount; ++ii )
|
2018-01-14 08:51:32 +00:00
|
|
|
{
|
2018-11-06 04:22:16 +00:00
|
|
|
// Here we balance returns with a 100ms timeout to allow UI updating
|
|
|
|
std::future_status status;
|
|
|
|
do
|
2018-09-21 12:21:12 +00:00
|
|
|
{
|
2018-11-06 04:22:16 +00:00
|
|
|
if( m_progressReporter )
|
2020-08-04 18:53:16 +00:00
|
|
|
{
|
2018-11-06 04:22:16 +00:00
|
|
|
m_progressReporter->KeepRefreshing();
|
2018-09-21 12:21:12 +00:00
|
|
|
|
2020-08-04 18:53:16 +00:00
|
|
|
if( m_progressReporter->IsCancelled() )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-11-06 04:22:16 +00:00
|
|
|
status = returns[ii].wait_for( std::chrono::milliseconds( 100 ) );
|
|
|
|
} while( status != std::future_status::ready );
|
|
|
|
}
|
2018-01-14 08:51:32 +00:00
|
|
|
}
|
|
|
|
|
2017-11-30 16:22:45 +00:00
|
|
|
if( m_progressReporter )
|
|
|
|
{
|
2020-08-04 18:53:16 +00:00
|
|
|
if( m_progressReporter->IsCancelled() )
|
|
|
|
return false;
|
2020-08-05 15:50:32 +00:00
|
|
|
|
|
|
|
m_progressReporter->AdvancePhase();
|
|
|
|
m_progressReporter->KeepRefreshing();
|
2017-11-30 16:22:45 +00:00
|
|
|
}
|
|
|
|
|
2018-05-03 22:23:47 +00:00
|
|
|
return true;
|
2017-11-30 16:22:45 +00:00
|
|
|
}
|
2017-12-04 18:06:47 +00:00
|
|
|
|
|
|
|
|
2019-06-20 22:35:01 +00:00
|
|
|
/**
|
|
|
|
* Return true if the given pad has a thermal connection with the given zone.
|
|
|
|
*/
|
2020-11-12 22:30:02 +00:00
|
|
|
bool hasThermalConnection( PAD* pad, const ZONE* aZone )
|
2019-06-20 22:35:01 +00:00
|
|
|
{
|
|
|
|
// Rejects non-standard pads with tht-only thermal reliefs
|
2019-12-28 00:55:11 +00:00
|
|
|
if( aZone->GetPadConnection( pad ) == ZONE_CONNECTION::THT_THERMAL
|
2021-05-01 14:46:50 +00:00
|
|
|
&& pad->GetAttribute() != PAD_ATTRIB::PTH )
|
2019-06-20 22:35:01 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
if( aZone->GetPadConnection( pad ) != ZONE_CONNECTION::THERMAL
|
|
|
|
&& aZone->GetPadConnection( pad ) != ZONE_CONNECTION::THT_THERMAL )
|
2019-06-20 22:35:01 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( pad->GetNetCode() != aZone->GetNetCode() || pad->GetNetCode() <= 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
EDA_RECT item_boundingbox = pad->GetBoundingBox();
|
|
|
|
int thermalGap = aZone->GetThermalReliefGap( pad );
|
|
|
|
item_boundingbox.Inflate( thermalGap, thermalGap );
|
|
|
|
|
2020-09-21 19:20:20 +00:00
|
|
|
return item_boundingbox.Intersects( aZone->GetCachedBoundingBox() );
|
2019-06-20 22:35:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a knockout for a pad. The knockout is 'aGap' larger than the pad (which might be
|
|
|
|
* either the thermal clearance or the electrical clearance).
|
|
|
|
*/
|
2020-11-12 22:30:02 +00:00
|
|
|
void ZONE_FILLER::addKnockout( PAD* aPad, PCB_LAYER_ID aLayer, int aGap, SHAPE_POLY_SET& aHoles )
|
2019-06-20 22:35:01 +00:00
|
|
|
{
|
2021-05-01 12:22:35 +00:00
|
|
|
if( aPad->GetShape() == PAD_SHAPE::CUSTOM )
|
2019-06-20 22:35:01 +00:00
|
|
|
{
|
2020-06-22 19:35:09 +00:00
|
|
|
SHAPE_POLY_SET poly;
|
2020-10-13 10:55:24 +00:00
|
|
|
aPad->TransformShapeWithClearanceToPolygon( poly, aLayer, aGap, m_maxError,
|
|
|
|
ERROR_OUTSIDE );
|
2019-06-20 22:35:01 +00:00
|
|
|
|
2020-06-22 19:35:09 +00:00
|
|
|
// the pad shape in zone can be its convex hull or the shape itself
|
2019-06-20 22:35:01 +00:00
|
|
|
if( aPad->GetCustomShapeInZoneOpt() == CUST_PAD_SHAPE_IN_ZONE_CONVEXHULL )
|
|
|
|
{
|
|
|
|
std::vector<wxPoint> convex_hull;
|
2020-06-22 19:35:09 +00:00
|
|
|
BuildConvexHull( convex_hull, poly );
|
2019-06-20 22:35:01 +00:00
|
|
|
|
|
|
|
aHoles.NewOutline();
|
|
|
|
|
|
|
|
for( const wxPoint& pt : convex_hull )
|
|
|
|
aHoles.Append( pt );
|
|
|
|
}
|
|
|
|
else
|
2020-06-22 19:35:09 +00:00
|
|
|
aHoles.Append( poly );
|
2019-06-20 22:35:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-13 10:55:24 +00:00
|
|
|
aPad->TransformShapeWithClearanceToPolygon( aHoles, aLayer, aGap, m_maxError,
|
|
|
|
ERROR_OUTSIDE );
|
2019-06-20 22:35:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-09 21:25:16 +00:00
|
|
|
/**
|
|
|
|
* Add a knockout for a pad's hole.
|
|
|
|
*/
|
|
|
|
void ZONE_FILLER::addHoleKnockout( PAD* aPad, int aGap, SHAPE_POLY_SET& aHoles )
|
|
|
|
{
|
|
|
|
// Note: drill size represents finish size, which means the actual hole size is the plating
|
|
|
|
// thickness larger.
|
|
|
|
if( aPad->GetAttribute() == PAD_ATTRIB::PTH )
|
|
|
|
aGap += aPad->GetBoard()->GetDesignSettings().GetHolePlatingThickness();
|
|
|
|
|
|
|
|
aPad->TransformHoleWithClearanceToPolygon( aHoles, aGap, m_maxError, ERROR_OUTSIDE );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-20 22:35:01 +00:00
|
|
|
/**
|
|
|
|
* Add a knockout for a graphic item. The knockout is 'aGap' larger than the item (which
|
|
|
|
* might be either the electrical clearance or the board edge clearance).
|
|
|
|
*/
|
2020-08-12 21:18:13 +00:00
|
|
|
void ZONE_FILLER::addKnockout( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer, int aGap,
|
|
|
|
bool aIgnoreLineWidth, SHAPE_POLY_SET& aHoles )
|
2019-06-20 22:35:01 +00:00
|
|
|
{
|
|
|
|
switch( aItem->Type() )
|
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_SHAPE_T:
|
2019-06-20 22:35:01 +00:00
|
|
|
case PCB_TEXT_T:
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_FP_SHAPE_T:
|
2022-01-29 17:19:22 +00:00
|
|
|
case PCB_TARGET_T:
|
2020-11-29 14:00:39 +00:00
|
|
|
aItem->TransformShapeWithClearanceToPolygon( aHoles, aLayer, aGap, m_maxError,
|
2020-10-13 10:55:24 +00:00
|
|
|
ERROR_OUTSIDE, aIgnoreLineWidth );
|
2019-06-20 22:35:01 +00:00
|
|
|
break;
|
2020-11-29 14:00:39 +00:00
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_FP_TEXT_T:
|
2019-06-20 22:35:01 +00:00
|
|
|
{
|
2020-11-29 14:00:39 +00:00
|
|
|
FP_TEXT* text = static_cast<FP_TEXT*>( aItem );
|
2019-06-20 22:35:01 +00:00
|
|
|
|
|
|
|
if( text->IsVisible() )
|
2020-11-29 14:00:39 +00:00
|
|
|
{
|
|
|
|
text->TransformShapeWithClearanceToPolygon( aHoles, aLayer, aGap, m_maxError,
|
|
|
|
ERROR_OUTSIDE, aIgnoreLineWidth );
|
|
|
|
}
|
2019-06-20 22:35:01 +00:00
|
|
|
}
|
2020-11-29 14:00:39 +00:00
|
|
|
break;
|
|
|
|
|
2019-06-20 22:35:01 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes thermal reliefs from the shape for any pads connected to the zone. Does NOT add
|
|
|
|
* in spokes, which must be done later.
|
|
|
|
*/
|
2020-11-11 23:05:59 +00:00
|
|
|
void ZONE_FILLER::knockoutThermalReliefs( const ZONE* aZone, PCB_LAYER_ID aLayer,
|
2020-06-24 02:19:08 +00:00
|
|
|
SHAPE_POLY_SET& aFill )
|
2017-12-04 18:06:47 +00:00
|
|
|
{
|
2019-06-21 17:01:17 +00:00
|
|
|
SHAPE_POLY_SET holes;
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2019-06-20 22:35:01 +00:00
|
|
|
{
|
2020-11-13 02:57:11 +00:00
|
|
|
for( PAD* pad : footprint->Pads() )
|
2019-06-20 22:35:01 +00:00
|
|
|
{
|
2019-07-14 22:14:43 +00:00
|
|
|
if( !hasThermalConnection( pad, aZone ) )
|
|
|
|
continue;
|
|
|
|
|
2020-11-06 23:45:12 +00:00
|
|
|
int gap = aZone->GetThermalReliefGap( pad );
|
|
|
|
|
2021-01-30 16:13:33 +00:00
|
|
|
// If the pad is flashed to the current layer, or is on the same layer and shares a netcode, then
|
|
|
|
// we need to knock out the thermal relief.
|
|
|
|
if( pad->FlashLayer( aLayer ) || ( pad->IsOnLayer( aLayer ) && pad->GetNetCode() == aZone->GetNetCode() ) )
|
2019-07-14 22:14:43 +00:00
|
|
|
{
|
2021-01-30 16:13:33 +00:00
|
|
|
addKnockout( pad, aLayer, gap, holes );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If the pad isn't on the current layer but has a hole, knock out a thermal relief
|
|
|
|
// for the hole.
|
2019-07-14 22:14:43 +00:00
|
|
|
if( pad->GetDrillSize().x == 0 && pad->GetDrillSize().y == 0 )
|
|
|
|
continue;
|
|
|
|
|
2020-11-06 23:45:12 +00:00
|
|
|
// Note: drill size represents finish size, which means the actual holes size is
|
|
|
|
// the plating thickness larger.
|
2021-05-01 14:46:50 +00:00
|
|
|
if( pad->GetAttribute() == PAD_ATTRIB::PTH )
|
2020-11-06 23:45:12 +00:00
|
|
|
gap += pad->GetBoard()->GetDesignSettings().GetHolePlatingThickness();
|
2019-07-14 22:14:43 +00:00
|
|
|
|
2020-11-06 23:45:12 +00:00
|
|
|
pad->TransformHoleWithClearanceToPolygon( holes, gap, m_maxError, ERROR_OUTSIDE );
|
|
|
|
}
|
2019-06-20 22:35:01 +00:00
|
|
|
}
|
|
|
|
}
|
2019-06-21 17:01:17 +00:00
|
|
|
|
2019-06-25 20:09:03 +00:00
|
|
|
aFill.BooleanSubtract( holes, SHAPE_POLY_SET::PM_FAST );
|
2019-06-20 22:35:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes clearance from the shape for copper items which share the zone's layer but are
|
|
|
|
* not connected to it.
|
|
|
|
*/
|
2020-11-11 23:05:59 +00:00
|
|
|
void ZONE_FILLER::buildCopperItemClearances( const ZONE* aZone, PCB_LAYER_ID aLayer,
|
2020-06-24 02:19:08 +00:00
|
|
|
SHAPE_POLY_SET& aHoles )
|
2019-06-20 22:35:01 +00:00
|
|
|
{
|
2020-10-26 12:54:30 +00:00
|
|
|
long ticker = 0;
|
|
|
|
|
|
|
|
auto checkForCancel =
|
|
|
|
[&ticker]( PROGRESS_REPORTER* aReporter ) -> bool
|
|
|
|
{
|
|
|
|
return aReporter && ( ticker++ % 50 ) == 0 && aReporter->IsCancelled();
|
|
|
|
};
|
|
|
|
|
2020-08-25 18:03:21 +00:00
|
|
|
// A small extra clearance to be sure actual track clearances are not smaller than
|
|
|
|
// requested clearance due to many approximations in calculations, like arc to segment
|
|
|
|
// approx, rounding issues, etc.
|
2020-09-08 19:18:50 +00:00
|
|
|
int extra_margin = Millimeter2iu( ADVANCED_CFG::GetCfg().m_ExtraClearance );
|
2020-01-26 17:01:11 +00:00
|
|
|
|
2020-05-15 23:25:33 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
|
2020-05-29 12:36:45 +00:00
|
|
|
int zone_clearance = aZone->GetLocalClearance();
|
2020-09-21 19:20:20 +00:00
|
|
|
EDA_RECT zone_boundingbox = aZone->GetCachedBoundingBox();
|
2020-05-15 23:25:33 +00:00
|
|
|
|
2020-08-25 18:03:21 +00:00
|
|
|
// Items outside the zone bounding box are skipped, so it needs to be inflated by the
|
|
|
|
// largest clearance value found in the netclasses and rules
|
2020-10-24 15:32:37 +00:00
|
|
|
zone_boundingbox.Inflate( m_worstClearance + extra_margin );
|
2017-12-04 18:06:47 +00:00
|
|
|
|
2020-10-12 17:29:54 +00:00
|
|
|
auto evalRulesForItems =
|
2021-01-01 22:29:15 +00:00
|
|
|
[&bds]( DRC_CONSTRAINT_T aConstraint, const BOARD_ITEM* a, const BOARD_ITEM* b,
|
2020-11-11 00:18:35 +00:00
|
|
|
PCB_LAYER_ID aEvalLayer ) -> int
|
2020-10-12 17:29:54 +00:00
|
|
|
{
|
2021-02-08 14:53:49 +00:00
|
|
|
auto c = bds.m_DRCEngine->EvalRules( aConstraint, a, b, aEvalLayer );
|
2021-01-01 22:29:15 +00:00
|
|
|
return c.Value().Min();
|
2020-10-12 17:29:54 +00:00
|
|
|
};
|
|
|
|
|
2019-06-20 22:35:01 +00:00
|
|
|
// Add non-connected pad clearances
|
|
|
|
//
|
2020-11-06 23:45:12 +00:00
|
|
|
auto knockoutPadClearance =
|
2020-11-12 22:30:02 +00:00
|
|
|
[&]( PAD* aPad )
|
2020-10-26 12:53:26 +00:00
|
|
|
{
|
|
|
|
if( aPad->GetBoundingBox().Intersects( zone_boundingbox ) )
|
|
|
|
{
|
2021-08-09 21:25:16 +00:00
|
|
|
int gap = 0;
|
|
|
|
bool knockoutHoleClearance = true;
|
2020-10-26 12:53:26 +00:00
|
|
|
|
|
|
|
if( aPad->GetNetCode() > 0 && aPad->GetNetCode() == aZone->GetNetCode() )
|
2021-08-09 21:25:16 +00:00
|
|
|
{
|
2022-03-05 15:18:24 +00:00
|
|
|
// For unconnected but same-net pads, electrical clearances don't apply.
|
|
|
|
// Use the greater of the zone's local clearance and thermal relief.
|
2020-10-26 12:53:26 +00:00
|
|
|
gap = std::max( zone_clearance, aZone->GetThermalReliefGap( aPad ) );
|
2021-08-09 21:25:16 +00:00
|
|
|
knockoutHoleClearance = false;
|
|
|
|
}
|
2020-10-26 12:53:26 +00:00
|
|
|
else
|
2021-08-09 21:25:16 +00:00
|
|
|
{
|
2020-11-02 16:20:00 +00:00
|
|
|
gap = evalRulesForItems( CLEARANCE_CONSTRAINT, aZone, aPad, aLayer );
|
2021-08-09 21:25:16 +00:00
|
|
|
}
|
2020-10-26 12:53:26 +00:00
|
|
|
|
2020-11-02 17:42:47 +00:00
|
|
|
gap += extra_margin;
|
|
|
|
|
2021-08-09 21:25:16 +00:00
|
|
|
if( aPad->FlashLayer( aLayer ) )
|
|
|
|
addKnockout( aPad, aLayer, gap, aHoles );
|
|
|
|
else if( aPad->GetDrillSize().x > 0 )
|
|
|
|
addHoleKnockout( aPad, gap, aHoles );
|
2020-11-06 23:45:12 +00:00
|
|
|
|
2021-08-09 21:25:16 +00:00
|
|
|
if( knockoutHoleClearance && aPad->GetDrillSize().x > 0 )
|
2020-11-06 23:45:12 +00:00
|
|
|
{
|
2021-08-09 21:25:16 +00:00
|
|
|
gap = evalRulesForItems( HOLE_CLEARANCE_CONSTRAINT, aZone, aPad, aLayer );
|
|
|
|
gap += extra_margin;
|
|
|
|
|
|
|
|
addHoleKnockout( aPad, gap, aHoles );
|
2020-11-06 23:45:12 +00:00
|
|
|
}
|
2020-10-26 12:53:26 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2017-12-04 18:06:47 +00:00
|
|
|
{
|
2020-11-13 02:57:11 +00:00
|
|
|
for( PAD* pad : footprint->Pads() )
|
2017-12-04 18:06:47 +00:00
|
|
|
{
|
2020-10-26 12:54:30 +00:00
|
|
|
if( checkForCancel( m_progressReporter ) )
|
|
|
|
return;
|
|
|
|
|
2020-11-06 23:45:12 +00:00
|
|
|
if( pad->GetNetCode() != aZone->GetNetCode()
|
|
|
|
|| pad->GetNetCode() <= 0
|
2019-12-28 00:55:11 +00:00
|
|
|
|| aZone->GetPadConnection( pad ) == ZONE_CONNECTION::NONE )
|
2017-12-04 18:06:47 +00:00
|
|
|
{
|
2020-11-06 23:45:12 +00:00
|
|
|
knockoutPadClearance( pad );
|
2020-10-26 12:53:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add non-connected track clearances
|
|
|
|
//
|
2020-11-06 23:45:12 +00:00
|
|
|
auto knockoutTrackClearance =
|
2021-06-11 21:07:02 +00:00
|
|
|
[&]( PCB_TRACK* aTrack )
|
2020-10-26 12:53:26 +00:00
|
|
|
{
|
|
|
|
if( aTrack->GetBoundingBox().Intersects( zone_boundingbox ) )
|
2020-02-14 16:00:08 +00:00
|
|
|
{
|
2020-10-26 12:53:26 +00:00
|
|
|
if( aTrack->Type() == PCB_VIA_T )
|
2020-10-12 17:29:54 +00:00
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
PCB_VIA* via = static_cast<PCB_VIA*>( aTrack );
|
2021-08-09 21:25:16 +00:00
|
|
|
int gap = 0;
|
|
|
|
bool checkHoleClearance = true;
|
2020-10-26 12:53:26 +00:00
|
|
|
|
2022-03-05 15:18:24 +00:00
|
|
|
gap = evalRulesForItems( CLEARANCE_CONSTRAINT, aZone, aTrack, aLayer );
|
2021-08-09 21:25:16 +00:00
|
|
|
|
|
|
|
if( via->FlashLayer( aLayer ) )
|
|
|
|
{
|
|
|
|
via->TransformShapeWithClearanceToPolygon( aHoles, aLayer,
|
|
|
|
gap + extra_margin,
|
2020-10-26 12:53:26 +00:00
|
|
|
m_maxError, ERROR_OUTSIDE );
|
|
|
|
}
|
2021-08-09 21:25:16 +00:00
|
|
|
|
|
|
|
if( checkHoleClearance )
|
|
|
|
{
|
|
|
|
gap = std::max( gap, evalRulesForItems( HOLE_CLEARANCE_CONSTRAINT,
|
|
|
|
aZone, via, aLayer ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
int radius = via->GetDrillValue() / 2 + bds.GetHolePlatingThickness();
|
|
|
|
|
|
|
|
TransformCircleToPolygon( aHoles, via->GetPosition(),
|
|
|
|
radius + gap + extra_margin,
|
|
|
|
m_maxError, ERROR_OUTSIDE );
|
2020-10-12 17:29:54 +00:00
|
|
|
}
|
2020-05-18 16:11:57 +00:00
|
|
|
else
|
2020-10-12 17:29:54 +00:00
|
|
|
{
|
2021-08-09 21:25:16 +00:00
|
|
|
int gap = evalRulesForItems( CLEARANCE_CONSTRAINT, aZone, aTrack, aLayer );
|
|
|
|
|
|
|
|
aTrack->TransformShapeWithClearanceToPolygon( aHoles, aLayer,
|
|
|
|
gap + extra_margin,
|
2020-10-26 12:53:26 +00:00
|
|
|
m_maxError, ERROR_OUTSIDE );
|
2020-10-12 17:29:54 +00:00
|
|
|
}
|
2020-05-18 16:11:57 +00:00
|
|
|
}
|
2020-10-26 12:53:26 +00:00
|
|
|
};
|
2017-12-04 18:06:47 +00:00
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_TRACK* track : m_board->Tracks() )
|
2017-12-04 18:06:47 +00:00
|
|
|
{
|
2020-06-24 02:19:08 +00:00
|
|
|
if( !track->IsOnLayer( aLayer ) )
|
2017-12-04 18:06:47 +00:00
|
|
|
continue;
|
|
|
|
|
2022-03-05 15:18:24 +00:00
|
|
|
if( track->GetNetCode() == aZone->GetNetCode() && ( aZone->GetNetCode() != 0) )
|
2017-12-04 18:06:47 +00:00
|
|
|
continue;
|
|
|
|
|
2020-10-26 12:54:30 +00:00
|
|
|
if( checkForCancel( m_progressReporter ) )
|
|
|
|
return;
|
|
|
|
|
2020-11-06 23:45:12 +00:00
|
|
|
knockoutTrackClearance( track );
|
2017-12-04 18:06:47 +00:00
|
|
|
}
|
|
|
|
|
2019-06-20 22:35:01 +00:00
|
|
|
// Add graphic item clearances. They are by definition unconnected, and have no clearance
|
|
|
|
// definitions of their own.
|
|
|
|
//
|
2020-11-06 23:45:12 +00:00
|
|
|
auto knockoutGraphicClearance =
|
2020-05-18 16:11:57 +00:00
|
|
|
[&]( BOARD_ITEM* aItem )
|
|
|
|
{
|
2020-11-20 21:22:27 +00:00
|
|
|
// A item on the Edge_Cuts or Margin is always seen as on any layer:
|
|
|
|
if( aItem->IsOnLayer( aLayer )
|
|
|
|
|| aItem->IsOnLayer( Edge_Cuts )
|
|
|
|
|| aItem->IsOnLayer( Margin ) )
|
2020-05-18 16:11:57 +00:00
|
|
|
{
|
2020-11-20 21:22:27 +00:00
|
|
|
if( aItem->GetBoundingBox().Intersects( zone_boundingbox ) )
|
2020-08-12 23:17:44 +00:00
|
|
|
{
|
2021-10-20 11:28:01 +00:00
|
|
|
bool ignoreLineWidths = false;
|
|
|
|
int gap = evalRulesForItems( CLEARANCE_CONSTRAINT, aZone, aItem, aLayer );
|
2020-11-20 21:22:27 +00:00
|
|
|
|
|
|
|
if( aItem->IsOnLayer( Edge_Cuts ) )
|
|
|
|
{
|
|
|
|
gap = std::max( gap, evalRulesForItems( EDGE_CLEARANCE_CONSTRAINT,
|
|
|
|
aZone, aItem, Edge_Cuts ) );
|
2021-10-20 11:28:01 +00:00
|
|
|
|
|
|
|
ignoreLineWidths = true;
|
|
|
|
gap = std::max( gap, bds.GetDRCEpsilon() );
|
2020-11-20 21:22:27 +00:00
|
|
|
}
|
2020-08-12 23:17:44 +00:00
|
|
|
|
2020-11-20 21:22:27 +00:00
|
|
|
if( aItem->IsOnLayer( Margin ) )
|
|
|
|
{
|
|
|
|
gap = std::max( gap, evalRulesForItems( EDGE_CLEARANCE_CONSTRAINT,
|
|
|
|
aZone, aItem, Margin ) );
|
|
|
|
}
|
|
|
|
|
2022-02-18 12:49:13 +00:00
|
|
|
addKnockout( aItem, aLayer, gap + extra_margin, ignoreLineWidths, aHoles );
|
2020-11-20 21:22:27 +00:00
|
|
|
}
|
2020-05-18 16:11:57 +00:00
|
|
|
}
|
|
|
|
};
|
2018-08-23 22:41:57 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2018-08-23 22:41:57 +00:00
|
|
|
{
|
2021-02-01 00:15:24 +00:00
|
|
|
bool skipFootprint = false;
|
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
knockoutGraphicClearance( &footprint->Reference() );
|
|
|
|
knockoutGraphicClearance( &footprint->Value() );
|
2018-08-23 22:41:57 +00:00
|
|
|
|
2022-03-05 15:18:24 +00:00
|
|
|
// Don't knock out holes in zones that share a net with a nettie footprint
|
2021-02-01 00:15:24 +00:00
|
|
|
if( footprint->IsNetTie() )
|
|
|
|
{
|
|
|
|
for( PAD* pad : footprint->Pads() )
|
|
|
|
{
|
|
|
|
if( aZone->GetNetCode() == pad->GetNetCode() )
|
|
|
|
{
|
|
|
|
skipFootprint = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( skipFootprint )
|
|
|
|
continue;
|
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
for( BOARD_ITEM* item : footprint->GraphicalItems() )
|
2020-10-26 12:54:30 +00:00
|
|
|
{
|
|
|
|
if( checkForCancel( m_progressReporter ) )
|
|
|
|
return;
|
|
|
|
|
2020-11-06 23:45:12 +00:00
|
|
|
knockoutGraphicClearance( item );
|
2020-10-26 12:54:30 +00:00
|
|
|
}
|
2017-12-04 18:06:47 +00:00
|
|
|
}
|
|
|
|
|
2020-08-07 14:04:34 +00:00
|
|
|
for( BOARD_ITEM* item : m_board->Drawings() )
|
2020-10-26 12:54:30 +00:00
|
|
|
{
|
|
|
|
if( checkForCancel( m_progressReporter ) )
|
|
|
|
return;
|
|
|
|
|
2020-11-06 23:45:12 +00:00
|
|
|
knockoutGraphicClearance( item );
|
2020-10-26 12:54:30 +00:00
|
|
|
}
|
2018-08-23 22:41:57 +00:00
|
|
|
|
2020-10-24 15:32:37 +00:00
|
|
|
// Add non-connected zone clearances
|
2019-06-20 22:35:01 +00:00
|
|
|
//
|
2020-11-06 23:45:12 +00:00
|
|
|
auto knockoutZoneClearance =
|
2020-11-11 23:05:59 +00:00
|
|
|
[&]( ZONE* aKnockout )
|
2020-09-21 19:20:20 +00:00
|
|
|
{
|
|
|
|
// If the zones share no common layers
|
|
|
|
if( !aKnockout->GetLayerSet().test( aLayer ) )
|
|
|
|
return;
|
2017-12-04 18:06:47 +00:00
|
|
|
|
2020-10-24 15:32:37 +00:00
|
|
|
if( aKnockout->GetCachedBoundingBox().Intersects( zone_boundingbox ) )
|
2020-09-21 19:20:20 +00:00
|
|
|
{
|
2020-10-24 15:32:37 +00:00
|
|
|
if( aKnockout->GetIsRuleArea() )
|
2020-09-21 19:20:20 +00:00
|
|
|
{
|
2020-10-24 15:32:37 +00:00
|
|
|
// Keepouts use outline with no clearance
|
2022-02-21 15:19:20 +00:00
|
|
|
aKnockout->TransformSmoothedOutlineToPolygon( aHoles, 0, m_maxError,
|
|
|
|
ERROR_OUTSIDE, nullptr );
|
2020-09-21 19:20:20 +00:00
|
|
|
}
|
2020-10-24 15:32:37 +00:00
|
|
|
else if( bds.m_ZoneFillVersion == 5 )
|
|
|
|
{
|
|
|
|
// 5.x used outline with clearance
|
2020-11-02 16:20:00 +00:00
|
|
|
int gap = evalRulesForItems( CLEARANCE_CONSTRAINT, aZone, aKnockout,
|
|
|
|
aLayer );
|
2020-10-24 15:32:37 +00:00
|
|
|
|
2022-02-21 15:19:20 +00:00
|
|
|
aKnockout->TransformSmoothedOutlineToPolygon( aHoles, gap, m_maxError,
|
|
|
|
ERROR_OUTSIDE, nullptr );
|
2020-10-24 15:32:37 +00:00
|
|
|
}
|
2020-09-21 19:20:20 +00:00
|
|
|
else
|
|
|
|
{
|
2020-10-24 15:32:37 +00:00
|
|
|
// 6.0 uses filled areas with clearance
|
2020-11-02 16:20:00 +00:00
|
|
|
int gap = evalRulesForItems( CLEARANCE_CONSTRAINT, aZone, aKnockout,
|
|
|
|
aLayer );
|
2020-09-21 19:20:20 +00:00
|
|
|
|
2020-10-24 15:32:37 +00:00
|
|
|
SHAPE_POLY_SET poly;
|
2022-02-18 12:49:13 +00:00
|
|
|
aKnockout->TransformShapeWithClearanceToPolygon( poly, aLayer,
|
|
|
|
gap + extra_margin,
|
2020-10-24 15:32:37 +00:00
|
|
|
m_maxError,
|
|
|
|
ERROR_OUTSIDE );
|
|
|
|
aHoles.Append( poly );
|
2020-09-21 19:20:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2017-12-04 18:06:47 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
for( ZONE* otherZone : m_board->Zones() )
|
2020-09-21 19:20:20 +00:00
|
|
|
{
|
2020-10-26 12:54:30 +00:00
|
|
|
if( checkForCancel( m_progressReporter ) )
|
|
|
|
return;
|
|
|
|
|
2021-10-26 16:19:45 +00:00
|
|
|
if( otherZone->GetIsRuleArea() )
|
2020-09-21 19:20:20 +00:00
|
|
|
{
|
2021-10-26 16:19:45 +00:00
|
|
|
if( otherZone->GetDoNotAllowCopperPour() )
|
|
|
|
knockoutZoneClearance( otherZone );
|
2020-09-21 19:20:20 +00:00
|
|
|
}
|
2021-10-26 16:19:45 +00:00
|
|
|
else
|
2020-09-21 19:20:20 +00:00
|
|
|
{
|
2021-10-26 16:19:45 +00:00
|
|
|
if( otherZone->GetNetCode() != aZone->GetNetCode()
|
|
|
|
&& otherZone->GetPriority() > aZone->GetPriority() )
|
|
|
|
{
|
|
|
|
knockoutZoneClearance( otherZone );
|
|
|
|
}
|
2020-09-21 19:20:20 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-04 18:06:47 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2020-09-21 19:20:20 +00:00
|
|
|
{
|
2020-11-13 02:57:11 +00:00
|
|
|
for( ZONE* otherZone : footprint->Zones() )
|
2020-05-18 16:11:57 +00:00
|
|
|
{
|
2020-10-26 12:54:30 +00:00
|
|
|
if( checkForCancel( m_progressReporter ) )
|
|
|
|
return;
|
|
|
|
|
2021-10-26 16:19:45 +00:00
|
|
|
if( otherZone->GetIsRuleArea() )
|
2020-09-17 13:14:45 +00:00
|
|
|
{
|
2021-10-26 16:19:45 +00:00
|
|
|
if( otherZone->GetDoNotAllowCopperPour() )
|
|
|
|
knockoutZoneClearance( otherZone );
|
2020-09-17 13:14:45 +00:00
|
|
|
}
|
2021-10-26 16:19:45 +00:00
|
|
|
else
|
2020-09-17 13:14:45 +00:00
|
|
|
{
|
2021-10-26 16:19:45 +00:00
|
|
|
if( otherZone->GetNetCode() != aZone->GetNetCode()
|
|
|
|
&& otherZone->GetPriority() > aZone->GetPriority() )
|
|
|
|
{
|
|
|
|
knockoutZoneClearance( otherZone );
|
|
|
|
}
|
2020-09-17 13:14:45 +00:00
|
|
|
}
|
2019-07-03 11:07:11 +00:00
|
|
|
}
|
2017-12-04 18:06:47 +00:00
|
|
|
}
|
|
|
|
|
2019-06-25 20:09:03 +00:00
|
|
|
aHoles.Simplify( SHAPE_POLY_SET::PM_FAST );
|
2017-12-04 18:06:47 +00:00
|
|
|
}
|
|
|
|
|
2019-06-20 22:35:01 +00:00
|
|
|
|
2020-10-24 15:32:37 +00:00
|
|
|
/**
|
|
|
|
* Removes the outlines of higher-proirity zones with the same net. These zones should be
|
|
|
|
* in charge of the fill parameters within their own outlines.
|
|
|
|
*/
|
2020-11-11 23:05:59 +00:00
|
|
|
void ZONE_FILLER::subtractHigherPriorityZones( const ZONE* aZone, PCB_LAYER_ID aLayer,
|
2020-10-24 15:32:37 +00:00
|
|
|
SHAPE_POLY_SET& aRawFill )
|
|
|
|
{
|
2020-11-06 23:45:12 +00:00
|
|
|
auto knockoutZoneOutline =
|
2020-11-11 23:05:59 +00:00
|
|
|
[&]( ZONE* aKnockout )
|
2020-10-24 15:32:37 +00:00
|
|
|
{
|
|
|
|
// If the zones share no common layers
|
|
|
|
if( !aKnockout->GetLayerSet().test( aLayer ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( aKnockout->GetCachedBoundingBox().Intersects( aZone->GetCachedBoundingBox() ) )
|
|
|
|
{
|
2022-03-04 12:11:07 +00:00
|
|
|
// Processing of arc shapes in zones is not yet supported because Clipper
|
|
|
|
// can't do boolean operations on them. The poly outline must be converted to
|
|
|
|
// segments first.
|
|
|
|
SHAPE_POLY_SET outline = *aKnockout->Outline();
|
|
|
|
outline.ClearArcs();
|
|
|
|
|
|
|
|
aRawFill.BooleanSubtract( outline, SHAPE_POLY_SET::PM_FAST );
|
2020-10-24 15:32:37 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
for( ZONE* otherZone : m_board->Zones() )
|
2020-10-24 15:32:37 +00:00
|
|
|
{
|
|
|
|
if( otherZone->GetNetCode() == aZone->GetNetCode()
|
|
|
|
&& otherZone->GetPriority() > aZone->GetPriority() )
|
|
|
|
{
|
2020-11-06 23:45:12 +00:00
|
|
|
knockoutZoneOutline( otherZone );
|
2020-10-24 15:32:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2020-10-24 15:32:37 +00:00
|
|
|
{
|
2020-11-13 02:57:11 +00:00
|
|
|
for( ZONE* otherZone : footprint->Zones() )
|
2020-10-24 15:32:37 +00:00
|
|
|
{
|
|
|
|
if( otherZone->GetNetCode() == aZone->GetNetCode()
|
|
|
|
&& otherZone->GetPriority() > aZone->GetPriority() )
|
|
|
|
{
|
2020-11-06 23:45:12 +00:00
|
|
|
knockoutZoneOutline( otherZone );
|
2020-10-24 15:32:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-22 21:05:24 +00:00
|
|
|
#define DUMP_POLYS_TO_COPPER_LAYER( a, b, c ) \
|
2020-10-29 21:17:57 +00:00
|
|
|
{ if( m_debugZoneFiller && aDebugLayer == b ) \
|
2020-09-22 21:05:24 +00:00
|
|
|
{ \
|
|
|
|
m_board->SetLayerName( b, c ); \
|
2020-10-24 13:19:37 +00:00
|
|
|
SHAPE_POLY_SET d = a; \
|
|
|
|
d.Simplify( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE ); \
|
|
|
|
d.Fracture( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE ); \
|
|
|
|
aRawPolys = d; \
|
2020-10-29 21:17:57 +00:00
|
|
|
return false; \
|
2020-09-22 21:05:24 +00:00
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2020-10-29 21:17:57 +00:00
|
|
|
|
2017-12-04 18:06:47 +00:00
|
|
|
/**
|
2019-06-20 22:35:01 +00:00
|
|
|
* 1 - Creates the main zone outline using a correction to shrink the resulting area by
|
|
|
|
* m_ZoneMinThickness / 2. The result is areas with a margin of m_ZoneMinThickness / 2
|
|
|
|
* so that when drawing outline with segments having a thickness of m_ZoneMinThickness the
|
|
|
|
* outlines will match exactly the initial outlines
|
|
|
|
* 2 - Knocks out thermal reliefs around thermally-connected pads
|
2019-06-22 14:03:17 +00:00
|
|
|
* 3 - Builds a set of thermal spoke for the whole zone
|
|
|
|
* 4 - Knocks out unconnected copper items, deleting any affected spokes
|
|
|
|
* 5 - Removes unconnected copper islands, deleting any affected spokes
|
|
|
|
* 6 - Adds in the remaining spokes
|
2017-12-04 18:06:47 +00:00
|
|
|
*/
|
2020-11-11 23:05:59 +00:00
|
|
|
bool ZONE_FILLER::computeRawFilledArea( const ZONE* aZone,
|
2020-10-29 21:17:57 +00:00
|
|
|
PCB_LAYER_ID aLayer, PCB_LAYER_ID aDebugLayer,
|
2019-06-20 22:35:01 +00:00
|
|
|
const SHAPE_POLY_SET& aSmoothedOutline,
|
2020-10-29 21:17:57 +00:00
|
|
|
const SHAPE_POLY_SET& aMaxExtents,
|
|
|
|
SHAPE_POLY_SET& aRawPolys )
|
2017-12-04 18:06:47 +00:00
|
|
|
{
|
2020-09-10 23:05:20 +00:00
|
|
|
m_maxError = m_board->GetDesignSettings().m_MaxError;
|
2019-07-12 12:56:02 +00:00
|
|
|
|
|
|
|
// Features which are min_width should survive pruning; features that are *less* than
|
|
|
|
// min_width should not. Therefore we subtract epsilon from the min_width when
|
|
|
|
// deflating/inflating.
|
|
|
|
int half_min_width = aZone->GetMinThickness() / 2;
|
|
|
|
int epsilon = Millimeter2iu( 0.001 );
|
2020-09-10 23:05:20 +00:00
|
|
|
int numSegs = GetArcToSegmentCount( half_min_width, m_maxError, 360.0 );
|
2019-07-12 12:56:02 +00:00
|
|
|
|
2020-09-28 23:50:25 +00:00
|
|
|
// Solid polygons are deflated and inflated during calculations. Deflating doesn't cause
|
|
|
|
// issues, but inflate is tricky as it can create excessively long and narrow spikes for
|
|
|
|
// acute angles.
|
|
|
|
// ALLOW_ACUTE_CORNERS cannot be used due to the spike problem.
|
|
|
|
// CHAMFER_ACUTE_CORNERS is tempting, but can still produce spikes in some unusual
|
|
|
|
// circumstances (https://gitlab.com/kicad/code/kicad/-/issues/5581).
|
|
|
|
// It's unclear if ROUND_ACUTE_CORNERS would have the same issues, but is currently avoided
|
|
|
|
// as a "less-safe" option.
|
|
|
|
// ROUND_ALL_CORNERS produces the uniformly nicest shapes, but also a lot of segments.
|
2021-06-09 19:32:58 +00:00
|
|
|
// CHAMFER_ALL_CORNERS improves the segment count.
|
2020-09-28 23:50:25 +00:00
|
|
|
SHAPE_POLY_SET::CORNER_STRATEGY fastCornerStrategy = SHAPE_POLY_SET::CHAMFER_ALL_CORNERS;
|
|
|
|
SHAPE_POLY_SET::CORNER_STRATEGY cornerStrategy = SHAPE_POLY_SET::ROUND_ALL_CORNERS;
|
2019-07-16 15:41:21 +00:00
|
|
|
|
2019-07-12 12:56:02 +00:00
|
|
|
std::deque<SHAPE_LINE_CHAIN> thermalSpokes;
|
|
|
|
SHAPE_POLY_SET clearanceHoles;
|
2017-12-04 18:06:47 +00:00
|
|
|
|
2019-07-12 12:56:02 +00:00
|
|
|
aRawPolys = aSmoothedOutline;
|
2022-02-04 22:44:59 +00:00
|
|
|
DUMP_POLYS_TO_COPPER_LAYER( aRawPolys, In1_Cu, wxT( "smoothed-outline" ) );
|
2017-12-04 18:06:47 +00:00
|
|
|
|
2020-08-04 18:53:16 +00:00
|
|
|
if( m_progressReporter && m_progressReporter->IsCancelled() )
|
2020-10-29 21:17:57 +00:00
|
|
|
return false;
|
2020-08-04 18:53:16 +00:00
|
|
|
|
2020-06-24 02:19:08 +00:00
|
|
|
knockoutThermalReliefs( aZone, aLayer, aRawPolys );
|
2022-02-04 22:44:59 +00:00
|
|
|
DUMP_POLYS_TO_COPPER_LAYER( aRawPolys, In2_Cu, wxT( "minus-thermal-reliefs" ) );
|
2017-12-04 18:06:47 +00:00
|
|
|
|
2020-08-04 18:53:16 +00:00
|
|
|
if( m_progressReporter && m_progressReporter->IsCancelled() )
|
2020-10-29 21:17:57 +00:00
|
|
|
return false;
|
2020-08-04 18:53:16 +00:00
|
|
|
|
2020-06-24 02:19:08 +00:00
|
|
|
buildCopperItemClearances( aZone, aLayer, clearanceHoles );
|
2022-02-04 22:44:59 +00:00
|
|
|
DUMP_POLYS_TO_COPPER_LAYER( clearanceHoles, In3_Cu, wxT( "clearance-holes" ) );
|
2019-06-20 22:35:01 +00:00
|
|
|
|
2020-08-04 18:53:16 +00:00
|
|
|
if( m_progressReporter && m_progressReporter->IsCancelled() )
|
2020-10-29 21:17:57 +00:00
|
|
|
return false;
|
2020-08-04 18:53:16 +00:00
|
|
|
|
2020-06-24 02:19:08 +00:00
|
|
|
buildThermalSpokes( aZone, aLayer, thermalSpokes );
|
2019-07-11 23:28:46 +00:00
|
|
|
|
2020-08-04 18:53:16 +00:00
|
|
|
if( m_progressReporter && m_progressReporter->IsCancelled() )
|
2020-10-29 21:17:57 +00:00
|
|
|
return false;
|
2020-08-04 18:53:16 +00:00
|
|
|
|
2019-07-11 23:28:46 +00:00
|
|
|
// Create a temporary zone that we can hit-test spoke-ends against. It's only temporary
|
|
|
|
// because the "real" subtract-clearance-holes has to be done after the spokes are added.
|
|
|
|
static const bool USE_BBOX_CACHES = true;
|
2019-07-12 12:56:02 +00:00
|
|
|
SHAPE_POLY_SET testAreas = aRawPolys;
|
2019-06-25 20:09:03 +00:00
|
|
|
testAreas.BooleanSubtract( clearanceHoles, SHAPE_POLY_SET::PM_FAST );
|
2022-02-04 22:44:59 +00:00
|
|
|
DUMP_POLYS_TO_COPPER_LAYER( testAreas, In4_Cu, wxT( "minus-clearance-holes" ) );
|
2019-06-25 20:09:03 +00:00
|
|
|
|
2019-07-12 12:56:02 +00:00
|
|
|
// Prune features that don't meet minimum-width criteria
|
2019-07-16 15:41:21 +00:00
|
|
|
if( half_min_width - epsilon > epsilon )
|
|
|
|
{
|
2020-09-28 23:50:25 +00:00
|
|
|
testAreas.Deflate( half_min_width - epsilon, numSegs, fastCornerStrategy );
|
2022-02-04 22:44:59 +00:00
|
|
|
DUMP_POLYS_TO_COPPER_LAYER( testAreas, In5_Cu, wxT( "spoke-test-deflated" ) );
|
2020-09-22 21:05:24 +00:00
|
|
|
|
2020-09-28 23:50:25 +00:00
|
|
|
testAreas.Inflate( half_min_width - epsilon, numSegs, fastCornerStrategy );
|
2022-02-04 22:44:59 +00:00
|
|
|
DUMP_POLYS_TO_COPPER_LAYER( testAreas, In6_Cu, wxT( "spoke-test-reinflated" ) );
|
2019-07-16 15:41:21 +00:00
|
|
|
}
|
2019-06-22 14:03:17 +00:00
|
|
|
|
2020-08-04 18:53:16 +00:00
|
|
|
if( m_progressReporter && m_progressReporter->IsCancelled() )
|
2020-10-29 21:17:57 +00:00
|
|
|
return false;
|
2020-08-04 18:53:16 +00:00
|
|
|
|
2019-07-11 23:28:46 +00:00
|
|
|
// Spoke-end-testing is hugely expensive so we generate cached bounding-boxes to speed
|
|
|
|
// things up a bit.
|
|
|
|
testAreas.BuildBBoxCaches();
|
2020-08-04 18:53:16 +00:00
|
|
|
int interval = 0;
|
2019-06-25 20:09:03 +00:00
|
|
|
|
2020-10-24 13:19:37 +00:00
|
|
|
SHAPE_POLY_SET debugSpokes;
|
|
|
|
|
2019-06-25 20:09:03 +00:00
|
|
|
for( const SHAPE_LINE_CHAIN& spoke : thermalSpokes )
|
2019-06-22 14:03:17 +00:00
|
|
|
{
|
2019-07-05 22:45:57 +00:00
|
|
|
const VECTOR2I& testPt = spoke.CPoint( 3 );
|
|
|
|
|
2019-07-11 23:28:46 +00:00
|
|
|
// Hit-test against zone body
|
2019-07-13 16:35:57 +00:00
|
|
|
if( testAreas.Contains( testPt, -1, 1, USE_BBOX_CACHES ) )
|
2019-06-25 20:09:03 +00:00
|
|
|
{
|
2020-10-24 13:19:37 +00:00
|
|
|
if( m_debugZoneFiller )
|
|
|
|
debugSpokes.AddOutline( spoke );
|
|
|
|
|
2019-07-12 12:56:02 +00:00
|
|
|
aRawPolys.AddOutline( spoke );
|
2019-06-25 20:09:03 +00:00
|
|
|
continue;
|
|
|
|
}
|
2019-06-22 14:03:17 +00:00
|
|
|
|
2020-08-04 18:53:16 +00:00
|
|
|
if( interval++ > 400 )
|
|
|
|
{
|
|
|
|
if( m_progressReporter && m_progressReporter->IsCancelled() )
|
2020-10-29 21:17:57 +00:00
|
|
|
return false;
|
2020-08-04 18:53:16 +00:00
|
|
|
|
|
|
|
interval = 0;
|
|
|
|
}
|
|
|
|
|
2019-07-11 23:28:46 +00:00
|
|
|
// Hit-test against other spokes
|
2019-06-25 20:09:03 +00:00
|
|
|
for( const SHAPE_LINE_CHAIN& other : thermalSpokes )
|
2019-06-22 14:03:17 +00:00
|
|
|
{
|
2019-07-05 22:45:57 +00:00
|
|
|
if( &other != &spoke && other.PointInside( testPt, 1, USE_BBOX_CACHES ) )
|
2019-06-23 18:22:34 +00:00
|
|
|
{
|
2020-10-24 13:19:37 +00:00
|
|
|
if( m_debugZoneFiller )
|
|
|
|
debugSpokes.AddOutline( spoke );
|
|
|
|
|
2019-07-12 12:56:02 +00:00
|
|
|
aRawPolys.AddOutline( spoke );
|
2019-06-25 20:09:03 +00:00
|
|
|
break;
|
2019-06-23 18:22:34 +00:00
|
|
|
}
|
2019-06-22 14:03:17 +00:00
|
|
|
}
|
|
|
|
}
|
2019-06-20 22:35:01 +00:00
|
|
|
|
2022-02-04 22:44:59 +00:00
|
|
|
DUMP_POLYS_TO_COPPER_LAYER( debugSpokes, In7_Cu, wxT( "spokes" ) );
|
2017-12-04 18:06:47 +00:00
|
|
|
|
2020-08-04 18:53:16 +00:00
|
|
|
if( m_progressReporter && m_progressReporter->IsCancelled() )
|
2020-10-29 21:17:57 +00:00
|
|
|
return false;
|
2020-08-04 18:53:16 +00:00
|
|
|
|
2019-07-12 12:56:02 +00:00
|
|
|
aRawPolys.BooleanSubtract( clearanceHoles, SHAPE_POLY_SET::PM_FAST );
|
2022-02-04 22:44:59 +00:00
|
|
|
DUMP_POLYS_TO_COPPER_LAYER( aRawPolys, In8_Cu, wxT( "after-spoke-trimming" ) );
|
2020-08-25 18:03:21 +00:00
|
|
|
|
2019-07-12 12:56:02 +00:00
|
|
|
// Prune features that don't meet minimum-width criteria
|
2019-07-16 15:41:21 +00:00
|
|
|
if( half_min_width - epsilon > epsilon )
|
2020-08-25 18:03:21 +00:00
|
|
|
aRawPolys.Deflate( half_min_width - epsilon, numSegs, cornerStrategy );
|
2019-06-25 20:09:03 +00:00
|
|
|
|
2022-04-10 17:20:34 +00:00
|
|
|
// Min-thickness is the web thickness. On the other hand, a blob min-thickness by
|
|
|
|
// min-thickness is not useful. Since there's no obvious definition of web vs. blob, we
|
2022-04-10 18:48:45 +00:00
|
|
|
// arbitrarily choose "at least 1/2 min-thickness on one axis".
|
|
|
|
for( int ii = aRawPolys.OutlineCount() - 1; ii >= 0; ii-- )
|
2022-04-10 17:20:34 +00:00
|
|
|
{
|
2022-04-10 18:48:45 +00:00
|
|
|
std::vector<SHAPE_LINE_CHAIN>& island = aRawPolys.Polygon( ii );
|
|
|
|
EDA_RECT islandExtents = island.front().BBox();
|
2022-04-10 17:20:34 +00:00
|
|
|
|
2022-04-10 18:48:45 +00:00
|
|
|
if( islandExtents.GetSizeMax() < half_min_width )
|
|
|
|
aRawPolys.DeletePolygon( ii );
|
2022-04-10 17:20:34 +00:00
|
|
|
}
|
|
|
|
|
2022-02-04 22:44:59 +00:00
|
|
|
DUMP_POLYS_TO_COPPER_LAYER( aRawPolys, In9_Cu, wxT( "deflated" ) );
|
2019-06-25 20:09:03 +00:00
|
|
|
|
2020-08-04 18:53:16 +00:00
|
|
|
if( m_progressReporter && m_progressReporter->IsCancelled() )
|
2020-10-29 21:17:57 +00:00
|
|
|
return false;
|
2020-08-04 18:53:16 +00:00
|
|
|
|
2018-02-18 09:09:13 +00:00
|
|
|
// Now remove the non filled areas due to the hatch pattern
|
2019-12-20 14:11:39 +00:00
|
|
|
if( aZone->GetFillMode() == ZONE_FILL_MODE::HATCH_PATTERN )
|
2020-10-29 21:17:57 +00:00
|
|
|
{
|
|
|
|
if( !addHatchFillTypeOnZone( aZone, aLayer, aDebugLayer, aRawPolys ) )
|
|
|
|
return false;
|
|
|
|
}
|
2017-12-04 18:06:47 +00:00
|
|
|
|
2020-08-04 18:53:16 +00:00
|
|
|
if( m_progressReporter && m_progressReporter->IsCancelled() )
|
2020-10-29 21:17:57 +00:00
|
|
|
return false;
|
2020-08-04 18:53:16 +00:00
|
|
|
|
2019-07-12 12:56:02 +00:00
|
|
|
// Re-inflate after pruning of areas that don't meet minimum-width criteria
|
|
|
|
if( aZone->GetFilledPolysUseThickness() )
|
2019-03-10 16:57:26 +00:00
|
|
|
{
|
2020-08-25 18:03:21 +00:00
|
|
|
// If we're stroking the zone with a min_width stroke then this will naturally inflate
|
|
|
|
// the zone by half_min_width
|
2019-07-12 12:56:02 +00:00
|
|
|
}
|
2019-07-16 15:41:21 +00:00
|
|
|
else if( half_min_width - epsilon > epsilon )
|
2019-07-12 12:56:02 +00:00
|
|
|
{
|
2020-08-25 18:03:21 +00:00
|
|
|
aRawPolys.Inflate( half_min_width - epsilon, numSegs, cornerStrategy );
|
2019-06-22 14:03:17 +00:00
|
|
|
}
|
2019-05-23 14:27:07 +00:00
|
|
|
|
2022-02-04 22:44:59 +00:00
|
|
|
DUMP_POLYS_TO_COPPER_LAYER( aRawPolys, In15_Cu, wxT( "after-reinflating" ) );
|
2020-09-22 21:05:24 +00:00
|
|
|
|
2020-08-25 18:03:21 +00:00
|
|
|
// Ensure additive changes (thermal stubs and particularly inflating acute corners) do not
|
|
|
|
// add copper outside the zone boundary or inside the clearance holes
|
2020-10-29 21:17:57 +00:00
|
|
|
aRawPolys.BooleanIntersection( aMaxExtents, SHAPE_POLY_SET::PM_FAST );
|
2022-02-04 22:44:59 +00:00
|
|
|
DUMP_POLYS_TO_COPPER_LAYER( aRawPolys, In16_Cu, wxT( "after-trim-to-outline" ) );
|
2020-08-25 18:03:21 +00:00
|
|
|
aRawPolys.BooleanSubtract( clearanceHoles, SHAPE_POLY_SET::PM_FAST );
|
2022-02-04 22:44:59 +00:00
|
|
|
DUMP_POLYS_TO_COPPER_LAYER( aRawPolys, In17_Cu, wxT( "after-trim-to-clearance-holes" ) );
|
2020-08-25 18:03:21 +00:00
|
|
|
|
2020-10-24 15:32:37 +00:00
|
|
|
// Lastly give any same-net but higher-priority zones control over their own area.
|
|
|
|
subtractHigherPriorityZones( aZone, aLayer, aRawPolys );
|
2022-02-04 22:44:59 +00:00
|
|
|
DUMP_POLYS_TO_COPPER_LAYER( aRawPolys, In18_Cu, wxT( "minus-higher-priority-zones" ) );
|
2020-10-24 15:32:37 +00:00
|
|
|
|
2019-07-12 12:56:02 +00:00
|
|
|
aRawPolys.Fracture( SHAPE_POLY_SET::PM_FAST );
|
2020-10-29 21:17:57 +00:00
|
|
|
return true;
|
2017-12-04 18:06:47 +00:00
|
|
|
}
|
|
|
|
|
2019-06-20 22:35:01 +00:00
|
|
|
|
2019-07-13 16:35:57 +00:00
|
|
|
/*
|
|
|
|
* Build the filled solid areas data from real outlines (stored in m_Poly)
|
2017-12-04 18:06:47 +00:00
|
|
|
* The solid areas can be more than one on copper layers, and do not have holes
|
2018-01-14 08:51:32 +00:00
|
|
|
* ( holes are linked by overlapping segments to the main outline)
|
2017-12-04 18:06:47 +00:00
|
|
|
*/
|
2020-11-11 23:05:59 +00:00
|
|
|
bool ZONE_FILLER::fillSingleZone( ZONE* aZone, PCB_LAYER_ID aLayer, SHAPE_POLY_SET& aRawPolys,
|
|
|
|
SHAPE_POLY_SET& aFinalPolys )
|
2017-12-04 18:06:47 +00:00
|
|
|
{
|
2020-10-10 22:09:00 +00:00
|
|
|
SHAPE_POLY_SET* boardOutline = m_brdOutlinesValid ? &m_boardOutline : nullptr;
|
2020-10-29 21:17:57 +00:00
|
|
|
SHAPE_POLY_SET maxExtents;
|
2020-10-10 22:09:00 +00:00
|
|
|
SHAPE_POLY_SET smoothedPoly;
|
2020-10-29 21:17:57 +00:00
|
|
|
PCB_LAYER_ID debugLayer = UNDEFINED_LAYER;
|
|
|
|
|
|
|
|
if( m_debugZoneFiller && LSET::InternalCuMask().Contains( aLayer ) )
|
|
|
|
{
|
|
|
|
debugLayer = aLayer;
|
|
|
|
aLayer = F_Cu;
|
|
|
|
}
|
2017-12-04 18:06:47 +00:00
|
|
|
|
2020-10-29 21:17:57 +00:00
|
|
|
if ( !aZone->BuildSmoothedPoly( maxExtents, aLayer, boardOutline, &smoothedPoly ) )
|
2017-12-04 18:06:47 +00:00
|
|
|
return false;
|
|
|
|
|
2020-08-04 18:53:16 +00:00
|
|
|
if( m_progressReporter && m_progressReporter->IsCancelled() )
|
|
|
|
return false;
|
|
|
|
|
2017-12-04 18:06:47 +00:00
|
|
|
if( aZone->IsOnCopperLayer() )
|
|
|
|
{
|
2020-10-29 21:17:57 +00:00
|
|
|
if( computeRawFilledArea( aZone, aLayer, debugLayer, smoothedPoly, maxExtents, aRawPolys ) )
|
|
|
|
aZone->SetNeedRefill( false );
|
|
|
|
|
|
|
|
aFinalPolys = aRawPolys;
|
2017-12-04 18:06:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-12 12:56:02 +00:00
|
|
|
// Features which are min_width should survive pruning; features that are *less* than
|
|
|
|
// min_width should not. Therefore we subtract epsilon from the min_width when
|
|
|
|
// deflating/inflating.
|
|
|
|
int half_min_width = aZone->GetMinThickness() / 2;
|
|
|
|
int epsilon = Millimeter2iu( 0.001 );
|
2020-09-10 23:05:20 +00:00
|
|
|
int numSegs = GetArcToSegmentCount( half_min_width, m_maxError, 360.0 );
|
2019-07-12 12:56:02 +00:00
|
|
|
|
2020-08-25 18:03:21 +00:00
|
|
|
smoothedPoly.Deflate( half_min_width - epsilon, numSegs );
|
2019-04-30 11:16:29 +00:00
|
|
|
|
|
|
|
// Remove the non filled areas due to the hatch pattern
|
2019-12-20 14:11:39 +00:00
|
|
|
if( aZone->GetFillMode() == ZONE_FILL_MODE::HATCH_PATTERN )
|
2020-10-29 21:17:57 +00:00
|
|
|
addHatchFillTypeOnZone( aZone, aLayer, debugLayer, smoothedPoly );
|
2019-04-30 11:16:29 +00:00
|
|
|
|
2019-07-17 11:24:10 +00:00
|
|
|
// Re-inflate after pruning of areas that don't meet minimum-width criteria
|
|
|
|
if( aZone->GetFilledPolysUseThickness() )
|
|
|
|
{
|
|
|
|
// If we're stroking the zone with a min_width stroke then this will naturally
|
|
|
|
// inflate the zone by half_min_width
|
|
|
|
}
|
|
|
|
else if( half_min_width - epsilon > epsilon )
|
2020-10-29 21:17:57 +00:00
|
|
|
{
|
2021-02-03 11:56:15 +00:00
|
|
|
smoothedPoly.Inflate( half_min_width - epsilon, numSegs );
|
2020-10-29 21:17:57 +00:00
|
|
|
}
|
2019-07-17 11:24:10 +00:00
|
|
|
|
2017-12-04 18:06:47 +00:00
|
|
|
aRawPolys = smoothedPoly;
|
|
|
|
aFinalPolys = smoothedPoly;
|
2019-06-22 07:55:25 +00:00
|
|
|
|
2019-04-30 11:16:29 +00:00
|
|
|
aFinalPolys.Fracture( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
2020-10-29 21:17:57 +00:00
|
|
|
aZone->SetNeedRefill( false );
|
2017-12-04 18:06:47 +00:00
|
|
|
}
|
2019-04-30 11:16:29 +00:00
|
|
|
|
2017-12-04 18:06:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-13 23:33:20 +00:00
|
|
|
|
|
|
|
/**
|
2019-06-20 22:35:01 +00:00
|
|
|
* Function buildThermalSpokes
|
2017-12-13 23:33:20 +00:00
|
|
|
*/
|
2020-11-11 23:05:59 +00:00
|
|
|
void ZONE_FILLER::buildThermalSpokes( const ZONE* aZone, PCB_LAYER_ID aLayer,
|
2019-06-25 20:09:03 +00:00
|
|
|
std::deque<SHAPE_LINE_CHAIN>& aSpokesList )
|
2017-12-13 23:33:20 +00:00
|
|
|
{
|
2020-09-21 19:20:20 +00:00
|
|
|
auto zoneBB = aZone->GetCachedBoundingBox();
|
2020-09-05 16:00:29 +00:00
|
|
|
int zone_clearance = aZone->GetLocalClearance();
|
2019-06-20 22:35:01 +00:00
|
|
|
int biggest_clearance = m_board->GetDesignSettings().GetBiggestClearanceValue();
|
2017-12-13 23:33:20 +00:00
|
|
|
biggest_clearance = std::max( biggest_clearance, zone_clearance );
|
|
|
|
zoneBB.Inflate( biggest_clearance );
|
|
|
|
|
2019-06-23 18:22:34 +00:00
|
|
|
// Is a point on the boundary of the polygon inside or outside? This small epsilon lets
|
|
|
|
// us avoid the question.
|
2019-06-25 00:06:51 +00:00
|
|
|
int epsilon = KiROUND( IU_PER_MM * 0.04 ); // about 1.5 mil
|
2017-12-13 23:33:20 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2017-12-13 23:33:20 +00:00
|
|
|
{
|
2020-11-13 02:57:11 +00:00
|
|
|
for( PAD* pad : footprint->Pads() )
|
2017-12-13 23:33:20 +00:00
|
|
|
{
|
2019-06-20 22:35:01 +00:00
|
|
|
if( !hasThermalConnection( pad, aZone ) )
|
2017-12-13 23:33:20 +00:00
|
|
|
continue;
|
|
|
|
|
2019-07-14 22:14:43 +00:00
|
|
|
// We currently only connect to pads, not pad holes
|
2020-06-24 02:19:08 +00:00
|
|
|
if( !pad->IsOnLayer( aLayer ) )
|
2019-07-14 22:14:43 +00:00
|
|
|
continue;
|
|
|
|
|
2019-06-20 22:35:01 +00:00
|
|
|
int thermalReliefGap = aZone->GetThermalReliefGap( pad );
|
2017-12-13 23:33:20 +00:00
|
|
|
|
|
|
|
// Calculate thermal bridge half width
|
2020-09-17 13:14:45 +00:00
|
|
|
int spoke_w = aZone->GetThermalReliefSpokeWidth( pad );
|
2019-07-23 18:32:38 +00:00
|
|
|
// Avoid spoke_w bigger than the smaller pad size, because
|
|
|
|
// it is not possible to create stubs bigger than the pad.
|
|
|
|
// Possible refinement: have a separate size for vertical and horizontal stubs
|
|
|
|
spoke_w = std::min( spoke_w, pad->GetSize().x );
|
|
|
|
spoke_w = std::min( spoke_w, pad->GetSize().y );
|
|
|
|
|
2019-12-04 12:23:09 +00:00
|
|
|
// Cannot create stubs having a width < zone min thickness
|
2020-10-11 18:13:38 +00:00
|
|
|
if( spoke_w < aZone->GetMinThickness() )
|
2019-12-04 12:23:09 +00:00
|
|
|
continue;
|
|
|
|
|
2019-07-23 18:32:38 +00:00
|
|
|
int spoke_half_w = spoke_w / 2;
|
2019-06-20 22:35:01 +00:00
|
|
|
|
2019-06-22 16:34:24 +00:00
|
|
|
// Quick test here to possibly save us some work
|
|
|
|
BOX2I itemBB = pad->GetBoundingBox();
|
2019-06-25 00:06:51 +00:00
|
|
|
itemBB.Inflate( thermalReliefGap + epsilon );
|
2019-06-22 16:34:24 +00:00
|
|
|
|
|
|
|
if( !( itemBB.Intersects( zoneBB ) ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Thermal spokes consist of segments from the pad center to points just outside
|
2019-06-22 14:03:17 +00:00
|
|
|
// the thermal relief.
|
2019-06-25 23:04:35 +00:00
|
|
|
//
|
|
|
|
// We use the bounding-box to lay out the spokes, but for this to work the
|
|
|
|
// bounding box has to be built at the same rotation as the spokes.
|
2020-06-28 18:00:40 +00:00
|
|
|
// We have to use a dummy pad to avoid dirtying the cached shapes
|
2019-06-25 23:04:35 +00:00
|
|
|
wxPoint shapePos = pad->ShapePos();
|
2020-06-28 18:00:40 +00:00
|
|
|
double padAngle = pad->GetOrientation();
|
2020-11-12 22:30:02 +00:00
|
|
|
PAD dummy_pad( *pad );
|
2020-06-28 18:00:40 +00:00
|
|
|
dummy_pad.SetOrientation( 0.0 );
|
2021-04-14 10:33:46 +00:00
|
|
|
|
|
|
|
// Spokes are from center of pad, not from hole
|
|
|
|
dummy_pad.SetPosition( -pad->GetOffset() );
|
2019-06-25 23:04:35 +00:00
|
|
|
|
2020-06-28 18:00:40 +00:00
|
|
|
BOX2I reliefBB = dummy_pad.GetBoundingBox();
|
2019-06-25 00:06:51 +00:00
|
|
|
reliefBB.Inflate( thermalReliefGap + epsilon );
|
2017-12-13 23:33:20 +00:00
|
|
|
|
2019-06-25 23:04:35 +00:00
|
|
|
// For circle pads, the thermal spoke orientation is 45 deg
|
2021-05-01 12:22:35 +00:00
|
|
|
if( pad->GetShape() == PAD_SHAPE::CIRCLE )
|
2022-06-08 14:46:29 +00:00
|
|
|
padAngle += s_RoundPadThermalSpokeAngle;
|
2017-12-13 23:33:20 +00:00
|
|
|
|
2019-06-22 14:03:17 +00:00
|
|
|
for( int i = 0; i < 4; i++ )
|
|
|
|
{
|
2019-06-25 20:09:03 +00:00
|
|
|
SHAPE_LINE_CHAIN spoke;
|
2019-06-22 14:03:17 +00:00
|
|
|
switch( i )
|
2017-12-13 23:33:20 +00:00
|
|
|
{
|
|
|
|
case 0: // lower stub
|
2019-06-25 23:04:35 +00:00
|
|
|
spoke.Append( +spoke_half_w, -spoke_half_w );
|
|
|
|
spoke.Append( -spoke_half_w, -spoke_half_w );
|
|
|
|
spoke.Append( -spoke_half_w, reliefBB.GetBottom() );
|
|
|
|
spoke.Append( 0, reliefBB.GetBottom() ); // test pt
|
|
|
|
spoke.Append( +spoke_half_w, reliefBB.GetBottom() );
|
2017-12-13 23:33:20 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: // upper stub
|
2019-06-25 23:04:35 +00:00
|
|
|
spoke.Append( +spoke_half_w, spoke_half_w );
|
|
|
|
spoke.Append( -spoke_half_w, spoke_half_w );
|
|
|
|
spoke.Append( -spoke_half_w, reliefBB.GetTop() );
|
|
|
|
spoke.Append( 0, reliefBB.GetTop() ); // test pt
|
|
|
|
spoke.Append( +spoke_half_w, reliefBB.GetTop() );
|
2017-12-13 23:33:20 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: // right stub
|
2019-06-25 23:04:35 +00:00
|
|
|
spoke.Append( -spoke_half_w, spoke_half_w );
|
|
|
|
spoke.Append( -spoke_half_w, -spoke_half_w );
|
2019-06-25 20:09:03 +00:00
|
|
|
spoke.Append( reliefBB.GetRight(), -spoke_half_w );
|
2019-06-25 23:04:35 +00:00
|
|
|
spoke.Append( reliefBB.GetRight(), 0 ); // test pt
|
2019-06-25 20:09:03 +00:00
|
|
|
spoke.Append( reliefBB.GetRight(), spoke_half_w );
|
2017-12-13 23:33:20 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3: // left stub
|
2019-06-25 23:04:35 +00:00
|
|
|
spoke.Append( spoke_half_w, spoke_half_w );
|
|
|
|
spoke.Append( spoke_half_w, -spoke_half_w );
|
|
|
|
spoke.Append( reliefBB.GetLeft(), -spoke_half_w );
|
|
|
|
spoke.Append( reliefBB.GetLeft(), 0 ); // test pt
|
|
|
|
spoke.Append( reliefBB.GetLeft(), spoke_half_w );
|
2017-12-13 23:33:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-12-13 16:41:20 +00:00
|
|
|
spoke.Rotate( -DECIDEG2RAD( padAngle ) );
|
2019-03-23 18:26:44 +00:00
|
|
|
spoke.Move( shapePos );
|
2019-06-20 22:35:01 +00:00
|
|
|
|
2019-06-25 20:09:03 +00:00
|
|
|
spoke.SetClosed( true );
|
2019-07-05 22:45:57 +00:00
|
|
|
spoke.GenerateBBoxCache();
|
2019-06-23 18:22:34 +00:00
|
|
|
aSpokesList.push_back( std::move( spoke ) );
|
2017-12-13 23:33:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-02-18 09:09:13 +00:00
|
|
|
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
bool ZONE_FILLER::addHatchFillTypeOnZone( const ZONE* aZone, PCB_LAYER_ID aLayer,
|
2020-10-29 21:17:57 +00:00
|
|
|
PCB_LAYER_ID aDebugLayer, SHAPE_POLY_SET& aRawPolys )
|
2018-02-18 09:09:13 +00:00
|
|
|
{
|
|
|
|
// Build grid:
|
|
|
|
|
2019-10-12 09:03:44 +00:00
|
|
|
// obviously line thickness must be > zone min thickness.
|
|
|
|
// It can happens if a board file was edited by hand by a python script
|
|
|
|
// Use 1 micron margin to be *sure* there is no issue in Gerber files
|
|
|
|
// (Gbr file unit = 1 or 10 nm) due to some truncation in coordinates or calculations
|
|
|
|
// This margin also avoid problems due to rounding coordinates in next calculations
|
|
|
|
// that can create incorrect polygons
|
2020-08-07 14:04:34 +00:00
|
|
|
int thickness = std::max( aZone->GetHatchThickness(),
|
|
|
|
aZone->GetMinThickness() + Millimeter2iu( 0.001 ) );
|
2019-10-12 09:03:44 +00:00
|
|
|
|
2018-02-18 09:09:13 +00:00
|
|
|
int linethickness = thickness - aZone->GetMinThickness();
|
2020-08-07 14:04:34 +00:00
|
|
|
int gridsize = thickness + aZone->GetHatchGap();
|
|
|
|
double orientation = aZone->GetHatchOrientation();
|
2018-02-18 09:09:13 +00:00
|
|
|
|
|
|
|
SHAPE_POLY_SET filledPolys = aRawPolys;
|
|
|
|
// Use a area that contains the rotated bbox by orientation,
|
|
|
|
// and after rotate the result by -orientation.
|
|
|
|
if( orientation != 0.0 )
|
2020-10-29 21:17:57 +00:00
|
|
|
filledPolys.Rotate( M_PI / 180.0 * orientation, VECTOR2I( 0, 0 ) );
|
2018-02-18 09:09:13 +00:00
|
|
|
|
|
|
|
BOX2I bbox = filledPolys.BBox( 0 );
|
|
|
|
|
|
|
|
// Build hole shape
|
2020-08-07 14:04:34 +00:00
|
|
|
// the hole size is aZone->GetHatchGap(), but because the outline thickness
|
2018-02-18 09:09:13 +00:00
|
|
|
// is aZone->GetMinThickness(), the hole shape size must be larger
|
|
|
|
SHAPE_LINE_CHAIN hole_base;
|
2020-08-07 14:04:34 +00:00
|
|
|
int hole_size = aZone->GetHatchGap() + aZone->GetMinThickness();
|
2018-02-18 09:09:13 +00:00
|
|
|
VECTOR2I corner( 0, 0 );;
|
|
|
|
hole_base.Append( corner );
|
|
|
|
corner.x += hole_size;
|
|
|
|
hole_base.Append( corner );
|
|
|
|
corner.y += hole_size;
|
|
|
|
hole_base.Append( corner );
|
|
|
|
corner.x = 0;
|
|
|
|
hole_base.Append( corner );
|
|
|
|
hole_base.SetClosed( true );
|
|
|
|
|
|
|
|
// Calculate minimal area of a grid hole.
|
|
|
|
// All holes smaller than a threshold will be removed
|
2020-08-07 14:04:34 +00:00
|
|
|
double minimal_hole_area = hole_base.Area() * aZone->GetHatchHoleMinArea();
|
2018-02-18 09:09:13 +00:00
|
|
|
|
|
|
|
// Now convert this hole to a smoothed shape:
|
2020-08-07 14:04:34 +00:00
|
|
|
if( aZone->GetHatchSmoothingLevel() > 0 )
|
2018-02-18 09:09:13 +00:00
|
|
|
{
|
|
|
|
// the actual size of chamfer, or rounded corner radius is the half size
|
2020-08-07 14:04:34 +00:00
|
|
|
// of the HatchFillTypeGap scaled by aZone->GetHatchSmoothingValue()
|
|
|
|
// aZone->GetHatchSmoothingValue() = 1.0 is the max value for the chamfer or the
|
2018-02-18 09:09:13 +00:00
|
|
|
// radius of corner (radius = half size of the hole)
|
2020-08-07 14:04:34 +00:00
|
|
|
int smooth_value = KiROUND( aZone->GetHatchGap()
|
|
|
|
* aZone->GetHatchSmoothingValue() / 2 );
|
2018-02-18 09:09:13 +00:00
|
|
|
|
|
|
|
// Minimal optimization:
|
2021-06-09 19:32:58 +00:00
|
|
|
// make smoothing only for reasonable smooth values, to avoid a lot of useless segments
|
2018-02-18 09:09:13 +00:00
|
|
|
// and if the smooth value is small, use chamfer even if fillet is requested
|
|
|
|
#define SMOOTH_MIN_VAL_MM 0.02
|
|
|
|
#define SMOOTH_SMALL_VAL_MM 0.04
|
2020-08-07 14:04:34 +00:00
|
|
|
|
2018-02-18 09:09:13 +00:00
|
|
|
if( smooth_value > Millimeter2iu( SMOOTH_MIN_VAL_MM ) )
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET smooth_hole;
|
|
|
|
smooth_hole.AddOutline( hole_base );
|
2020-08-07 14:04:34 +00:00
|
|
|
int smooth_level = aZone->GetHatchSmoothingLevel();
|
2018-02-18 09:09:13 +00:00
|
|
|
|
|
|
|
if( smooth_value < Millimeter2iu( SMOOTH_SMALL_VAL_MM ) && smooth_level > 1 )
|
|
|
|
smooth_level = 1;
|
2020-08-07 14:04:34 +00:00
|
|
|
|
2018-02-18 09:09:13 +00:00
|
|
|
// Use a larger smooth_value to compensate the outline tickness
|
|
|
|
// (chamfer is not visible is smooth value < outline thickess)
|
2020-08-07 14:04:34 +00:00
|
|
|
smooth_value += aZone->GetMinThickness() / 2;
|
2018-02-18 09:09:13 +00:00
|
|
|
|
|
|
|
// smooth_value cannot be bigger than the half size oh the hole:
|
2020-08-07 14:04:34 +00:00
|
|
|
smooth_value = std::min( smooth_value, aZone->GetHatchGap() / 2 );
|
|
|
|
|
2018-02-18 09:09:13 +00:00
|
|
|
// the error to approximate a circle by segments when smoothing corners by a arc
|
2020-08-07 14:04:34 +00:00
|
|
|
int error_max = std::max( Millimeter2iu( 0.01 ), smooth_value / 20 );
|
2018-02-18 09:09:13 +00:00
|
|
|
|
|
|
|
switch( smooth_level )
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
// Chamfer() uses the distance from a corner to create a end point
|
|
|
|
// for the chamfer.
|
|
|
|
hole_base = smooth_hole.Chamfer( smooth_value ).Outline( 0 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2020-08-07 14:04:34 +00:00
|
|
|
if( aZone->GetHatchSmoothingLevel() > 2 )
|
2018-02-18 09:09:13 +00:00
|
|
|
error_max /= 2; // Force better smoothing
|
2020-08-07 14:04:34 +00:00
|
|
|
|
2018-02-18 09:09:13 +00:00
|
|
|
hole_base = smooth_hole.Fillet( smooth_value, error_max ).Outline( 0 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build holes
|
|
|
|
SHAPE_POLY_SET holes;
|
|
|
|
|
|
|
|
for( int xx = 0; ; xx++ )
|
|
|
|
{
|
|
|
|
int xpos = xx * gridsize;
|
|
|
|
|
|
|
|
if( xpos > bbox.GetWidth() )
|
|
|
|
break;
|
|
|
|
|
|
|
|
for( int yy = 0; ; yy++ )
|
|
|
|
{
|
|
|
|
int ypos = yy * gridsize;
|
|
|
|
|
|
|
|
if( ypos > bbox.GetHeight() )
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Generate hole
|
|
|
|
SHAPE_LINE_CHAIN hole( hole_base );
|
|
|
|
hole.Move( VECTOR2I( xpos, ypos ) );
|
|
|
|
holes.AddOutline( hole );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
holes.Move( bbox.GetPosition() );
|
|
|
|
|
2020-10-29 21:17:57 +00:00
|
|
|
if( orientation != 0.0 )
|
|
|
|
holes.Rotate( -M_PI/180.0 * orientation, VECTOR2I( 0,0 ) );
|
2020-08-07 14:04:34 +00:00
|
|
|
|
2022-02-04 22:44:59 +00:00
|
|
|
DUMP_POLYS_TO_COPPER_LAYER( holes, In10_Cu, wxT( "hatch-holes" ) );
|
2020-08-07 14:04:34 +00:00
|
|
|
|
2020-10-29 21:17:57 +00:00
|
|
|
int outline_margin = aZone->GetMinThickness() * 1.1;
|
2020-08-07 14:04:34 +00:00
|
|
|
|
2020-10-29 21:17:57 +00:00
|
|
|
// Using GetHatchThickness() can look more consistent than GetMinThickness().
|
|
|
|
if( aZone->GetHatchBorderAlgorithm() && aZone->GetHatchThickness() > outline_margin )
|
|
|
|
outline_margin = aZone->GetHatchThickness();
|
2018-02-18 09:09:13 +00:00
|
|
|
|
2020-10-29 21:17:57 +00:00
|
|
|
// The fill has already been deflated to ensure GetMinThickness() so we just have to
|
|
|
|
// account for anything beyond that.
|
|
|
|
SHAPE_POLY_SET deflatedFilledPolys = aRawPolys;
|
|
|
|
deflatedFilledPolys.Deflate( outline_margin - aZone->GetMinThickness(), 16 );
|
|
|
|
holes.BooleanIntersection( deflatedFilledPolys, SHAPE_POLY_SET::PM_FAST );
|
2022-02-04 22:44:59 +00:00
|
|
|
DUMP_POLYS_TO_COPPER_LAYER( holes, In11_Cu, wxT( "fill-clipped-hatch-holes" ) );
|
2020-10-29 21:17:57 +00:00
|
|
|
|
|
|
|
SHAPE_POLY_SET deflatedOutline = *aZone->Outline();
|
|
|
|
deflatedOutline.Deflate( outline_margin, 16 );
|
|
|
|
holes.BooleanIntersection( deflatedOutline, SHAPE_POLY_SET::PM_FAST );
|
2022-02-04 22:44:59 +00:00
|
|
|
DUMP_POLYS_TO_COPPER_LAYER( holes, In12_Cu, wxT( "outline-clipped-hatch-holes" ) );
|
2018-02-18 09:09:13 +00:00
|
|
|
|
2020-08-07 14:04:34 +00:00
|
|
|
if( aZone->GetNetCode() != 0 )
|
|
|
|
{
|
|
|
|
// Vias and pads connected to the zone must not be allowed to become isolated inside
|
|
|
|
// one of the holes. Effectively this means their copper outline needs to be expanded
|
|
|
|
// to be at least as wide as the gap so that it is guaranteed to touch at least one
|
|
|
|
// edge.
|
2020-09-21 19:20:20 +00:00
|
|
|
EDA_RECT zone_boundingbox = aZone->GetCachedBoundingBox();
|
2020-08-07 14:04:34 +00:00
|
|
|
SHAPE_POLY_SET aprons;
|
|
|
|
int min_apron_radius = ( aZone->GetHatchGap() * 10 ) / 19;
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_TRACK* track : m_board->Tracks() )
|
2020-08-07 14:04:34 +00:00
|
|
|
{
|
|
|
|
if( track->Type() == PCB_VIA_T )
|
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
PCB_VIA* via = static_cast<PCB_VIA*>( track );
|
2020-08-07 14:04:34 +00:00
|
|
|
|
|
|
|
if( via->GetNetCode() == aZone->GetNetCode()
|
|
|
|
&& via->IsOnLayer( aLayer )
|
|
|
|
&& via->GetBoundingBox().Intersects( zone_boundingbox ) )
|
|
|
|
{
|
|
|
|
int r = std::max( min_apron_radius,
|
|
|
|
via->GetDrillValue() / 2 + outline_margin );
|
|
|
|
|
2020-10-13 10:55:24 +00:00
|
|
|
TransformCircleToPolygon( aprons, via->GetPosition(), r, ARC_HIGH_DEF,
|
|
|
|
ERROR_OUTSIDE );
|
2020-08-07 14:04:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2020-08-07 14:04:34 +00:00
|
|
|
{
|
2020-11-13 02:57:11 +00:00
|
|
|
for( PAD* pad : footprint->Pads() )
|
2020-08-07 14:04:34 +00:00
|
|
|
{
|
|
|
|
if( pad->GetNetCode() == aZone->GetNetCode()
|
|
|
|
&& pad->IsOnLayer( aLayer )
|
|
|
|
&& pad->GetBoundingBox().Intersects( zone_boundingbox ) )
|
|
|
|
{
|
|
|
|
// What we want is to bulk up the pad shape so that the narrowest bit of
|
|
|
|
// copper between the hole and the apron edge is at least outline_margin
|
|
|
|
// wide (and that the apron itself meets min_apron_radius. But that would
|
|
|
|
// take a lot of code and math, and the following approximation is close
|
|
|
|
// enough.
|
|
|
|
int pad_width = std::min( pad->GetSize().x, pad->GetSize().y );
|
|
|
|
int slot_width = std::min( pad->GetDrillSize().x, pad->GetDrillSize().y );
|
2021-06-26 09:11:22 +00:00
|
|
|
int min_annular_ring_width = ( pad_width - slot_width ) / 2;
|
2020-08-07 14:04:34 +00:00
|
|
|
int clearance = std::max( min_apron_radius - pad_width / 2,
|
2021-06-26 09:11:22 +00:00
|
|
|
outline_margin - min_annular_ring_width );
|
2020-08-07 14:04:34 +00:00
|
|
|
|
|
|
|
clearance = std::max( 0, clearance - linethickness / 2 );
|
2020-08-12 21:18:13 +00:00
|
|
|
pad->TransformShapeWithClearanceToPolygon( aprons, aLayer, clearance,
|
2020-10-13 10:55:24 +00:00
|
|
|
ARC_HIGH_DEF, ERROR_OUTSIDE );
|
2020-08-07 14:04:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
holes.BooleanSubtract( aprons, SHAPE_POLY_SET::PM_FAST );
|
|
|
|
}
|
2022-02-04 22:44:59 +00:00
|
|
|
DUMP_POLYS_TO_COPPER_LAYER( holes, In13_Cu, wxT( "pad-via-clipped-hatch-holes" ) );
|
2020-08-07 14:04:34 +00:00
|
|
|
|
2018-02-18 09:09:13 +00:00
|
|
|
// Now filter truncated holes to avoid small holes in pattern
|
|
|
|
// It happens for holes near the zone outline
|
|
|
|
for( int ii = 0; ii < holes.OutlineCount(); )
|
|
|
|
{
|
|
|
|
double area = holes.Outline( ii ).Area();
|
|
|
|
|
|
|
|
if( area < minimal_hole_area ) // The current hole is too small: remove it
|
|
|
|
holes.DeletePolygon( ii );
|
|
|
|
else
|
|
|
|
++ii;
|
|
|
|
}
|
|
|
|
|
|
|
|
// create grid. Use SHAPE_POLY_SET::PM_STRICTLY_SIMPLE to
|
|
|
|
// generate strictly simple polygons needed by Gerber files and Fracture()
|
|
|
|
aRawPolys.BooleanSubtract( aRawPolys, holes, SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
2022-02-04 22:44:59 +00:00
|
|
|
DUMP_POLYS_TO_COPPER_LAYER( aRawPolys, In14_Cu, wxT( "after-hatching" ) );
|
2020-10-29 21:17:57 +00:00
|
|
|
|
|
|
|
return true;
|
2018-02-18 09:09:13 +00:00
|
|
|
}
|