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
|
2020-01-12 21:07:41 +00:00
|
|
|
* Copyright (C) 2014-2020 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 <algorithm>
|
|
|
|
#include <future>
|
2017-11-30 16:22:45 +00:00
|
|
|
|
2020-07-26 14:20:24 +00:00
|
|
|
#include <advanced_config.h>
|
2017-11-30 16:22:45 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_zone.h>
|
|
|
|
#include <class_module.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <fp_shape.h>
|
|
|
|
#include <pcb_shape.h>
|
|
|
|
#include <pcb_text.h>
|
2017-12-04 18:06:47 +00:00
|
|
|
#include <class_pcb_target.h>
|
2019-05-17 00:13:21 +00:00
|
|
|
#include <class_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>
|
|
|
|
#include <widgets/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()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-14 11:06:30 +00:00
|
|
|
void ZONE_FILLER::InstallNewProgressReporter( wxWindow* aParent, const wxString& aTitle,
|
|
|
|
int aNumPhases )
|
2017-11-30 16:22:45 +00:00
|
|
|
{
|
2019-07-14 11:06:30 +00:00
|
|
|
m_uniqueReporter = std::make_unique<WX_PROGRESS_REPORTER>( aParent, aTitle, aNumPhases );
|
2020-09-14 17:54:14 +00:00
|
|
|
SetProgressReporter( m_uniqueReporter.get() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2020-09-24 22:08:23 +00:00
|
|
|
wxASSERT_MSG( m_commit, "ZONE_FILLER must have a valid commit to call SetProgressReporter" );
|
2019-06-29 19:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-21 19:20:20 +00:00
|
|
|
bool ZONE_FILLER::Fill( std::vector<ZONE_CONTAINER*>& aZones, bool aCheck, wxWindow* aParent )
|
2017-11-30 16:22:45 +00:00
|
|
|
{
|
2020-07-01 02:21:59 +00:00
|
|
|
std::vector<std::pair<ZONE_CONTAINER*, PCB_LAYER_ID>> toFill;
|
|
|
|
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();
|
2018-12-20 05:15:53 +00:00
|
|
|
std::unique_lock<std::mutex> lock( connectivity->GetLock(), std::try_to_lock );
|
|
|
|
|
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
|
|
|
|
2018-12-20 05:15:53 +00:00
|
|
|
if( !lock )
|
2018-05-03 22:23:47 +00:00
|
|
|
return false;
|
2017-12-14 22:49:46 +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.
|
|
|
|
for( ZONE_CONTAINER* zone : m_board->Zones() )
|
|
|
|
{
|
|
|
|
zone->CacheBoundingBox();
|
|
|
|
m_worstClearance = std::max( m_worstClearance, zone->GetLocalClearance() );
|
|
|
|
}
|
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
for( MODULE* module : m_board->Modules() )
|
2020-06-28 18:00:40 +00:00
|
|
|
{
|
2020-09-14 17:54:14 +00:00
|
|
|
for( D_PAD* pad : module->Pads() )
|
2020-06-28 18:00:40 +00:00
|
|
|
{
|
|
|
|
if( pad->IsDirty() )
|
2020-08-12 21:18:13 +00:00
|
|
|
pad->BuildEffectiveShapes( UNDEFINED_LAYER );
|
2020-06-28 18:00:40 +00:00
|
|
|
}
|
|
|
|
|
2020-10-23 13:26:46 +00:00
|
|
|
for( ZONE_CONTAINER* zone : module->Zones() )
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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(),
|
|
|
|
[]( const ZONE_CONTAINER* lhs, const ZONE_CONTAINER* rhs )
|
|
|
|
{
|
|
|
|
return lhs->GetPriority() > rhs->GetPriority();
|
|
|
|
} );
|
|
|
|
|
2020-08-05 15:50:32 +00:00
|
|
|
for( ZONE_CONTAINER* 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 =
|
|
|
|
[&]( ZONE_CONTAINER* aZone, PCB_LAYER_ID aLayer, ZONE_CONTAINER* 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++ )
|
|
|
|
{
|
|
|
|
PCB_LAYER_ID layer = toFill[i].second;
|
|
|
|
ZONE_CONTAINER* zone = toFill[i].first;
|
|
|
|
bool canFill = true;
|
|
|
|
|
|
|
|
// 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-10-24 13:18:15 +00:00
|
|
|
for( ZONE_CONTAINER* 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
|
|
|
|
|
|
|
toFill.erase( std::remove_if( toFill.begin(), toFill.end(),
|
|
|
|
[&] ( const std::pair<ZONE_CONTAINER*, PCB_LAYER_ID> pair ) -> bool
|
|
|
|
{
|
|
|
|
return pair.first->GetFillFlag( pair.second );
|
|
|
|
} ),
|
|
|
|
toFill.end() );
|
|
|
|
|
|
|
|
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();
|
|
|
|
m_progressReporter->Report( _( "Removing insulated copper islands..." ) );
|
|
|
|
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-09-17 13:14:45 +00:00
|
|
|
for( ZONE_CONTAINER* zone : aZones )
|
|
|
|
{
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2020-09-20 19:34:01 +00:00
|
|
|
// Now remove islands outside the board edge
|
|
|
|
for( ZONE_CONTAINER* zone : aZones )
|
|
|
|
{
|
2020-09-30 10:48:44 +00:00
|
|
|
LSET zoneCopperLayers = zone->GetLayerSet() & LSET::AllCuMask( MAX_CU_LAYERS );
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
|
|
|
if( island.empty() || !m_boardOutline.Contains( island.front().CPoint( 0 ) ) )
|
|
|
|
poly.DeletePolygon( ii );
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
for( ZONE_CONTAINER* zone : aZones )
|
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
connectivity->SetProgressReporter( nullptr );
|
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.
|
|
|
|
*/
|
|
|
|
bool hasThermalConnection( D_PAD* pad, const ZONE_CONTAINER* aZone )
|
|
|
|
{
|
|
|
|
// 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
|
2020-09-30 15:38:35 +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
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-14 22:14:43 +00:00
|
|
|
/**
|
|
|
|
* Setup aDummyPad to have the same size and shape of aPad's hole. This allows us to create
|
|
|
|
* thermal reliefs and clearances for holes using the pad code.
|
|
|
|
*/
|
|
|
|
static void setupDummyPadForHole( const D_PAD* aPad, D_PAD& aDummyPad )
|
|
|
|
{
|
2020-09-03 13:21:20 +00:00
|
|
|
// People may author clearance rules that look at a bunch of different stuff so we need
|
|
|
|
// to copy over pretty much everything except the shape info, which we fill from the drill
|
|
|
|
// info.
|
|
|
|
aDummyPad.SetLayerSet( aPad->GetLayerSet() );
|
|
|
|
aDummyPad.SetAttribute( aPad->GetAttribute() );
|
|
|
|
aDummyPad.SetProperty( aPad->GetProperty() );
|
|
|
|
|
2019-07-14 22:14:43 +00:00
|
|
|
aDummyPad.SetNetCode( aPad->GetNetCode() );
|
2020-09-03 13:21:20 +00:00
|
|
|
aDummyPad.SetLocalClearance( aPad->GetLocalClearance() );
|
|
|
|
aDummyPad.SetLocalSolderMaskMargin( aPad->GetLocalSolderMaskMargin() );
|
|
|
|
aDummyPad.SetLocalSolderPasteMargin( aPad->GetLocalSolderPasteMargin() );
|
|
|
|
aDummyPad.SetLocalSolderPasteMarginRatio( aPad->GetLocalSolderPasteMarginRatio() );
|
|
|
|
|
|
|
|
aDummyPad.SetZoneConnection( aPad->GetEffectiveZoneConnection() );
|
2020-09-10 18:35:11 +00:00
|
|
|
aDummyPad.SetThermalSpokeWidth( aPad->GetEffectiveThermalSpokeWidth() );
|
|
|
|
aDummyPad.SetThermalGap( aPad->GetEffectiveThermalGap() );
|
2020-09-03 13:21:20 +00:00
|
|
|
|
|
|
|
aDummyPad.SetCustomShapeInZoneOpt( aPad->GetCustomShapeInZoneOpt() );
|
2020-09-03 14:58:49 +00:00
|
|
|
|
|
|
|
// Note: drill size represents finish size, which means the actual holes size is the
|
|
|
|
// plating thickness larger.
|
|
|
|
int platingThickness = 0;
|
|
|
|
|
2020-09-30 15:38:35 +00:00
|
|
|
if( aPad->GetAttribute() == PAD_ATTRIB_PTH )
|
2020-09-03 14:58:49 +00:00
|
|
|
platingThickness = aPad->GetBoard()->GetDesignSettings().GetHolePlatingThickness();
|
|
|
|
|
2020-09-03 13:21:20 +00:00
|
|
|
aDummyPad.SetOffset( wxPoint( 0, 0 ) );
|
2020-09-03 14:58:49 +00:00
|
|
|
aDummyPad.SetSize( aPad->GetDrillSize() + wxSize( platingThickness, platingThickness ) );
|
2019-07-14 22:14:43 +00:00
|
|
|
aDummyPad.SetShape( aPad->GetDrillShape() == PAD_DRILL_SHAPE_OBLONG ? PAD_SHAPE_OVAL
|
|
|
|
: PAD_SHAPE_CIRCLE );
|
2020-09-03 13:21:20 +00:00
|
|
|
aDummyPad.SetOrientation( aPad->GetOrientation() );
|
2019-07-14 22:14:43 +00:00
|
|
|
aDummyPad.SetPosition( aPad->GetPosition() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-08-12 21:18:13 +00:00
|
|
|
void ZONE_FILLER::addKnockout( D_PAD* aPad, PCB_LAYER_ID aLayer, int aGap, SHAPE_POLY_SET& aHoles )
|
2019-06-20 22:35:01 +00:00
|
|
|
{
|
|
|
|
if( aPad->GetShape() == PAD_SHAPE_CUSTOM )
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* shape = (PCB_SHAPE*) aItem;
|
|
|
|
shape->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;
|
|
|
|
}
|
|
|
|
case PCB_TEXT_T:
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_TEXT* text = (PCB_TEXT*) aItem;
|
2019-06-20 22:35:01 +00:00
|
|
|
text->TransformBoundingBoxWithClearanceToPolygon( &aHoles, aGap );
|
|
|
|
break;
|
|
|
|
}
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_FP_SHAPE_T:
|
2019-06-20 22:35:01 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
FP_SHAPE* shape = (FP_SHAPE*) aItem;
|
|
|
|
shape->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-10-04 14:19:33 +00:00
|
|
|
case PCB_FP_TEXT_T:
|
2019-06-20 22:35:01 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
FP_TEXT* text = (FP_TEXT*) aItem;
|
2019-06-20 22:35:01 +00:00
|
|
|
|
|
|
|
if( text->IsVisible() )
|
|
|
|
text->TransformBoundingBoxWithClearanceToPolygon( &aHoles, aGap );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
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-06-24 02:19:08 +00:00
|
|
|
void ZONE_FILLER::knockoutThermalReliefs( const ZONE_CONTAINER* aZone, PCB_LAYER_ID aLayer,
|
|
|
|
SHAPE_POLY_SET& aFill )
|
2017-12-04 18:06:47 +00:00
|
|
|
{
|
2019-06-21 17:01:17 +00:00
|
|
|
SHAPE_POLY_SET holes;
|
|
|
|
|
2019-07-14 22:14:43 +00:00
|
|
|
// Use a dummy pad to calculate relief when a pad has a hole but is not on the zone's
|
|
|
|
// copper layer. The dummy pad has the size and shape of the original pad's hole. We have
|
|
|
|
// to give it a parent because some functions expect a non-null parent to find clearance
|
|
|
|
// data, etc.
|
|
|
|
MODULE dummymodule( m_board );
|
|
|
|
D_PAD dummypad( &dummymodule );
|
|
|
|
|
2019-06-20 22:35:01 +00:00
|
|
|
for( auto module : m_board->Modules() )
|
|
|
|
{
|
|
|
|
for( auto pad : module->Pads() )
|
|
|
|
{
|
2019-07-14 22:14:43 +00:00
|
|
|
if( !hasThermalConnection( pad, aZone ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// If the pad isn't on the current layer but has a hole, knock out a thermal relief
|
|
|
|
// for the hole.
|
2020-06-24 02:19:08 +00:00
|
|
|
if( !pad->IsOnLayer( aLayer ) )
|
2019-07-14 22:14:43 +00:00
|
|
|
{
|
|
|
|
if( pad->GetDrillSize().x == 0 && pad->GetDrillSize().y == 0 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
setupDummyPadForHole( pad, dummypad );
|
|
|
|
pad = &dummypad;
|
|
|
|
}
|
|
|
|
|
2020-08-12 21:18:13 +00:00
|
|
|
addKnockout( pad, aLayer, aZone->GetThermalReliefGap( pad ), holes );
|
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-06-24 02:19:08 +00:00
|
|
|
void ZONE_FILLER::buildCopperItemClearances( const ZONE_CONTAINER* aZone, PCB_LAYER_ID aLayer,
|
|
|
|
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-10-04 23:34:59 +00:00
|
|
|
static PCB_SHAPE dummyEdge;
|
2020-08-12 23:17:44 +00:00
|
|
|
dummyEdge.SetParent( m_board );
|
2020-05-15 23:25:33 +00:00
|
|
|
dummyEdge.SetLayer( Edge_Cuts );
|
|
|
|
|
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.
|
|
|
|
// 1 micron is a good value
|
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
|
|
|
|
2019-06-20 22:35:01 +00:00
|
|
|
// Use a dummy pad to calculate hole clearance when a pad has a hole but is not on the
|
|
|
|
// zone's copper layer. The dummy pad has the size and shape of the original pad's hole.
|
|
|
|
// We have to give it a parent because some functions expect a non-null parent to find
|
|
|
|
// clearance data, etc.
|
|
|
|
MODULE dummymodule( m_board );
|
2017-12-04 18:06:47 +00:00
|
|
|
D_PAD dummypad( &dummymodule );
|
|
|
|
|
2020-10-12 17:29:54 +00:00
|
|
|
auto evalRulesForItems =
|
|
|
|
[&]( DRC_CONSTRAINT_TYPE_T aConstraint, const BOARD_ITEM* a, const BOARD_ITEM* b,
|
2020-10-13 15:35:38 +00:00
|
|
|
PCB_LAYER_ID aCtLayer ) -> int
|
2020-10-12 17:29:54 +00:00
|
|
|
{
|
2020-10-13 15:35:38 +00:00
|
|
|
DRC_CONSTRAINT c = bds.m_DRCEngine->EvalRulesForItems( aConstraint, a, b, aCtLayer );
|
2020-10-12 17:29:54 +00:00
|
|
|
return c.Value().HasMin() ? c.Value().Min() : 0;
|
|
|
|
};
|
|
|
|
|
2019-06-20 22:35:01 +00:00
|
|
|
// Add non-connected pad clearances
|
|
|
|
//
|
2020-10-26 12:53:26 +00:00
|
|
|
auto knockoutPad =
|
|
|
|
[&]( D_PAD* aPad )
|
|
|
|
{
|
|
|
|
if( aPad->GetBoundingBox().Intersects( zone_boundingbox ) )
|
|
|
|
{
|
|
|
|
int gap;
|
|
|
|
|
|
|
|
// for pads having the same netcode as the zone, the net clearance has no
|
|
|
|
// meaning so use the greater of the zone clearance and the thermal relief
|
|
|
|
if( aPad->GetNetCode() > 0 && aPad->GetNetCode() == aZone->GetNetCode() )
|
|
|
|
{
|
|
|
|
gap = std::max( zone_clearance, aZone->GetThermalReliefGap( aPad ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gap = evalRulesForItems( DRC_CONSTRAINT_TYPE_CLEARANCE, aZone, aPad,
|
|
|
|
aLayer );
|
|
|
|
}
|
|
|
|
|
|
|
|
addKnockout( aPad, aLayer, gap, aHoles );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-08-07 14:04:34 +00:00
|
|
|
for( MODULE* module : m_board->Modules() )
|
2017-12-04 18:06:47 +00:00
|
|
|
{
|
2020-08-07 14:04:34 +00:00
|
|
|
for( D_PAD* pad : module->Pads() )
|
2017-12-04 18:06:47 +00:00
|
|
|
{
|
2020-10-26 12:54:30 +00:00
|
|
|
if( checkForCancel( m_progressReporter ) )
|
|
|
|
return;
|
|
|
|
|
2020-09-29 20:40:17 +00:00
|
|
|
if( !pad->FlashLayer( aLayer ) )
|
2017-12-04 18:06:47 +00:00
|
|
|
{
|
|
|
|
if( pad->GetDrillSize().x == 0 && pad->GetDrillSize().y == 0 )
|
|
|
|
continue;
|
|
|
|
|
2019-07-14 22:14:43 +00:00
|
|
|
setupDummyPadForHole( pad, dummypad );
|
2017-12-04 18:06:47 +00:00
|
|
|
pad = &dummypad;
|
|
|
|
}
|
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
if( pad->GetNetCode() != aZone->GetNetCode() || pad->GetNetCode() <= 0
|
|
|
|
|| aZone->GetPadConnection( pad ) == ZONE_CONNECTION::NONE )
|
2017-12-04 18:06:47 +00:00
|
|
|
{
|
2020-10-26 12:53:26 +00:00
|
|
|
knockoutPad( pad );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add non-connected track clearances
|
|
|
|
//
|
|
|
|
auto knockoutTrack =
|
|
|
|
[&]( TRACK* aTrack )
|
|
|
|
{
|
|
|
|
if( aTrack->GetBoundingBox().Intersects( zone_boundingbox ) )
|
2020-02-14 16:00:08 +00:00
|
|
|
{
|
2020-10-26 12:53:26 +00:00
|
|
|
int gap = evalRulesForItems( DRC_CONSTRAINT_TYPE_CLEARANCE, aZone, aTrack,
|
|
|
|
aLayer );
|
2020-02-14 16:00:08 +00:00
|
|
|
|
2020-10-26 12:53:26 +00:00
|
|
|
gap += extra_margin;
|
|
|
|
|
|
|
|
if( aTrack->Type() == PCB_VIA_T )
|
2020-10-12 17:29:54 +00:00
|
|
|
{
|
2020-10-26 12:53:26 +00:00
|
|
|
VIA* via = static_cast<VIA*>( aTrack );
|
|
|
|
|
|
|
|
if( !via->FlashLayer( aLayer ) )
|
|
|
|
{
|
|
|
|
int radius = via->GetDrillValue() / 2 + bds.GetHolePlatingThickness();
|
|
|
|
TransformCircleToPolygon( aHoles, via->GetPosition(), radius + gap,
|
|
|
|
m_maxError, ERROR_OUTSIDE );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
via->TransformShapeWithClearanceToPolygon( aHoles, aLayer, gap,
|
|
|
|
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
|
|
|
{
|
2020-10-26 12:53:26 +00:00
|
|
|
aTrack->TransformShapeWithClearanceToPolygon( aHoles, aLayer, gap,
|
|
|
|
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
|
|
|
|
2020-08-07 14:04:34 +00:00
|
|
|
for( 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;
|
|
|
|
|
|
|
|
if( track->GetNetCode() == aZone->GetNetCode() && ( aZone->GetNetCode() != 0) )
|
|
|
|
continue;
|
|
|
|
|
2020-10-26 12:54:30 +00:00
|
|
|
if( checkForCancel( m_progressReporter ) )
|
|
|
|
return;
|
|
|
|
|
2020-10-26 12:53:26 +00:00
|
|
|
knockoutTrack( 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-10-26 12:53:26 +00:00
|
|
|
auto knockoutGraphic =
|
2020-05-18 16:11:57 +00:00
|
|
|
[&]( BOARD_ITEM* aItem )
|
|
|
|
{
|
|
|
|
// A item on the Edge_Cuts is always seen as on any layer:
|
2020-06-24 02:19:08 +00:00
|
|
|
if( !aItem->IsOnLayer( aLayer ) && !aItem->IsOnLayer( Edge_Cuts ) )
|
2020-05-18 16:11:57 +00:00
|
|
|
return;
|
2017-12-04 18:06:47 +00:00
|
|
|
|
2020-05-18 16:11:57 +00:00
|
|
|
if( aItem->GetBoundingBox().Intersects( zone_boundingbox ) )
|
|
|
|
{
|
2020-10-12 17:29:54 +00:00
|
|
|
int gap = evalRulesForItems( DRC_CONSTRAINT_TYPE_CLEARANCE, aZone, aItem,
|
|
|
|
aLayer );
|
2020-08-12 23:17:44 +00:00
|
|
|
|
|
|
|
if( aItem->IsOnLayer( Edge_Cuts ) )
|
|
|
|
{
|
2020-10-12 17:29:54 +00:00
|
|
|
gap = std::max( gap, evalRulesForItems( DRC_CONSTRAINT_TYPE_EDGE_CLEARANCE,
|
|
|
|
aZone, aItem, Edge_Cuts ) );
|
2020-08-12 23:17:44 +00:00
|
|
|
}
|
|
|
|
|
2020-10-12 17:29:54 +00:00
|
|
|
addKnockout( aItem, aLayer, gap, aItem->IsOnLayer( Edge_Cuts ), aHoles );
|
2020-05-18 16:11:57 +00:00
|
|
|
}
|
|
|
|
};
|
2018-08-23 22:41:57 +00:00
|
|
|
|
2020-08-07 14:04:34 +00:00
|
|
|
for( MODULE* module : m_board->Modules() )
|
2018-08-23 22:41:57 +00:00
|
|
|
{
|
2020-10-26 12:53:26 +00:00
|
|
|
knockoutGraphic( &module->Reference() );
|
|
|
|
knockoutGraphic( &module->Value() );
|
2018-08-23 22:41:57 +00:00
|
|
|
|
2020-08-07 14:04:34 +00:00
|
|
|
for( BOARD_ITEM* item : module->GraphicalItems() )
|
2020-10-26 12:54:30 +00:00
|
|
|
{
|
|
|
|
if( checkForCancel( m_progressReporter ) )
|
|
|
|
return;
|
|
|
|
|
2020-10-26 12:53:26 +00:00
|
|
|
knockoutGraphic( 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-10-26 12:53:26 +00:00
|
|
|
knockoutGraphic( 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-09-21 19:20:20 +00:00
|
|
|
auto knockoutZone =
|
|
|
|
[&]( ZONE_CONTAINER* aKnockout )
|
|
|
|
{
|
|
|
|
// 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
|
2020-10-10 22:09:00 +00:00
|
|
|
aKnockout->TransformSmoothedOutlineToPolygon( aHoles, 0, 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
|
|
|
|
int gap = evalRulesForItems( DRC_CONSTRAINT_TYPE_CLEARANCE, aZone,
|
|
|
|
aKnockout, aLayer );
|
|
|
|
|
|
|
|
aKnockout->TransformSmoothedOutlineToPolygon( aHoles, gap, nullptr );
|
|
|
|
}
|
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-10-12 17:29:54 +00:00
|
|
|
int gap = evalRulesForItems( DRC_CONSTRAINT_TYPE_CLEARANCE, aZone,
|
|
|
|
aKnockout, aLayer );
|
2020-09-21 19:20:20 +00:00
|
|
|
|
2020-10-24 15:32:37 +00:00
|
|
|
SHAPE_POLY_SET poly;
|
|
|
|
aKnockout->TransformShapeWithClearanceToPolygon( poly, aLayer, gap,
|
|
|
|
m_maxError,
|
|
|
|
ERROR_OUTSIDE );
|
|
|
|
aHoles.Append( poly );
|
2020-09-21 19:20:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2017-12-04 18:06:47 +00:00
|
|
|
|
2020-09-21 19:20:20 +00:00
|
|
|
for( ZONE_CONTAINER* otherZone : m_board->Zones() )
|
|
|
|
{
|
2020-10-26 12:54:30 +00:00
|
|
|
if( checkForCancel( m_progressReporter ) )
|
|
|
|
return;
|
|
|
|
|
2020-10-24 15:32:37 +00:00
|
|
|
if( otherZone->GetNetCode() != aZone->GetNetCode()
|
|
|
|
&& otherZone->GetPriority() > aZone->GetPriority() )
|
2020-09-21 19:20:20 +00:00
|
|
|
{
|
2020-10-24 15:32:37 +00:00
|
|
|
knockoutZone( otherZone );
|
2020-09-21 19:20:20 +00:00
|
|
|
}
|
2020-10-24 15:32:37 +00:00
|
|
|
else if( otherZone->GetIsRuleArea() && otherZone->GetDoNotAllowCopperPour() )
|
2020-09-21 19:20:20 +00:00
|
|
|
{
|
2020-10-24 15:32:37 +00:00
|
|
|
knockoutZone( otherZone );
|
2020-09-21 19:20:20 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-04 18:06:47 +00:00
|
|
|
|
2020-09-21 19:20:20 +00:00
|
|
|
for( MODULE* module : m_board->Modules() )
|
|
|
|
{
|
|
|
|
for( ZONE_CONTAINER* otherZone : module->Zones() )
|
2020-05-18 16:11:57 +00:00
|
|
|
{
|
2020-10-26 12:54:30 +00:00
|
|
|
if( checkForCancel( m_progressReporter ) )
|
|
|
|
return;
|
|
|
|
|
2020-10-24 15:32:37 +00:00
|
|
|
if( otherZone->GetNetCode() != aZone->GetNetCode()
|
|
|
|
&& otherZone->GetPriority() > aZone->GetPriority() )
|
2020-09-17 13:14:45 +00:00
|
|
|
{
|
2020-10-24 15:32:37 +00:00
|
|
|
knockoutZone( otherZone );
|
2020-09-17 13:14:45 +00:00
|
|
|
}
|
2020-10-24 15:32:37 +00:00
|
|
|
else if( otherZone->GetIsRuleArea() && otherZone->GetDoNotAllowCopperPour() )
|
2020-09-17 13:14:45 +00:00
|
|
|
{
|
2020-10-24 15:32:37 +00:00
|
|
|
knockoutZone( 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.
|
|
|
|
*/
|
|
|
|
void ZONE_FILLER::subtractHigherPriorityZones( const ZONE_CONTAINER* aZone, PCB_LAYER_ID aLayer,
|
|
|
|
SHAPE_POLY_SET& aRawFill )
|
|
|
|
{
|
|
|
|
auto knockoutZone =
|
|
|
|
[&]( ZONE_CONTAINER* aKnockout )
|
|
|
|
{
|
|
|
|
// If the zones share no common layers
|
|
|
|
if( !aKnockout->GetLayerSet().test( aLayer ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( aKnockout->GetCachedBoundingBox().Intersects( aZone->GetCachedBoundingBox() ) )
|
|
|
|
{
|
|
|
|
aRawFill.BooleanSubtract( *aKnockout->Outline(), SHAPE_POLY_SET::PM_FAST );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
for( ZONE_CONTAINER* otherZone : m_board->Zones() )
|
|
|
|
{
|
|
|
|
if( otherZone->GetNetCode() == aZone->GetNetCode()
|
|
|
|
&& otherZone->GetPriority() > aZone->GetPriority() )
|
|
|
|
{
|
|
|
|
knockoutZone( otherZone );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( MODULE* module : m_board->Modules() )
|
|
|
|
{
|
|
|
|
for( ZONE_CONTAINER* otherZone : module->Zones() )
|
|
|
|
{
|
|
|
|
if( otherZone->GetNetCode() == aZone->GetNetCode()
|
|
|
|
&& otherZone->GetPriority() > aZone->GetPriority() )
|
|
|
|
{
|
|
|
|
knockoutZone( otherZone );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-22 21:05:24 +00:00
|
|
|
#define DUMP_POLYS_TO_COPPER_LAYER( a, b, c ) \
|
2020-09-23 09:35:13 +00:00
|
|
|
{ if( m_debugZoneFiller && dumpLayer == 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; \
|
|
|
|
aFinalPolys = d; \
|
2020-09-22 21:05:24 +00:00
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
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-06-24 02:19:08 +00:00
|
|
|
void ZONE_FILLER::computeRawFilledArea( const ZONE_CONTAINER* aZone, PCB_LAYER_ID aLayer,
|
2019-06-20 22:35:01 +00:00
|
|
|
const SHAPE_POLY_SET& aSmoothedOutline,
|
|
|
|
SHAPE_POLY_SET& aRawPolys,
|
|
|
|
SHAPE_POLY_SET& aFinalPolys )
|
2017-12-04 18:06:47 +00:00
|
|
|
{
|
2020-09-22 21:05:24 +00:00
|
|
|
PCB_LAYER_ID dumpLayer = aLayer;
|
|
|
|
|
2020-09-23 09:35:13 +00:00
|
|
|
if( m_debugZoneFiller && LSET::InternalCuMask().Contains( aLayer ) )
|
2020-09-22 21:05:24 +00:00
|
|
|
aLayer = F_Cu;
|
|
|
|
|
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.
|
|
|
|
// CHAMFER_ALL_CORNERS improves the segement count.
|
|
|
|
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;
|
2020-09-22 21:05:24 +00:00
|
|
|
DUMP_POLYS_TO_COPPER_LAYER( aRawPolys, In1_Cu, "smoothed-outline" );
|
2017-12-04 18:06:47 +00:00
|
|
|
|
2020-08-04 18:53:16 +00:00
|
|
|
if( m_progressReporter && m_progressReporter->IsCancelled() )
|
|
|
|
return;
|
|
|
|
|
2020-06-24 02:19:08 +00:00
|
|
|
knockoutThermalReliefs( aZone, aLayer, aRawPolys );
|
2020-09-22 21:05:24 +00:00
|
|
|
DUMP_POLYS_TO_COPPER_LAYER( aRawPolys, In2_Cu, "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() )
|
|
|
|
return;
|
|
|
|
|
2020-06-24 02:19:08 +00:00
|
|
|
buildCopperItemClearances( aZone, aLayer, clearanceHoles );
|
2020-10-24 13:19:37 +00:00
|
|
|
DUMP_POLYS_TO_COPPER_LAYER( clearanceHoles, In3_Cu, "clearance-holes" );
|
2019-06-20 22:35:01 +00:00
|
|
|
|
2020-08-04 18:53:16 +00:00
|
|
|
if( m_progressReporter && m_progressReporter->IsCancelled() )
|
|
|
|
return;
|
|
|
|
|
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() )
|
|
|
|
return;
|
|
|
|
|
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 );
|
2020-10-24 13:19:37 +00:00
|
|
|
DUMP_POLYS_TO_COPPER_LAYER( testAreas, In4_Cu, "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 );
|
2020-10-24 13:19:37 +00:00
|
|
|
DUMP_POLYS_TO_COPPER_LAYER( testAreas, In5_Cu, "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 );
|
2020-10-24 13:19:37 +00:00
|
|
|
DUMP_POLYS_TO_COPPER_LAYER( testAreas, In6_Cu, "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() )
|
|
|
|
return;
|
|
|
|
|
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() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
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
|
|
|
|
2020-10-24 13:19:37 +00:00
|
|
|
DUMP_POLYS_TO_COPPER_LAYER( debugSpokes, In7_Cu, "spokes" );
|
2017-12-04 18:06:47 +00:00
|
|
|
|
2020-08-04 18:53:16 +00:00
|
|
|
if( m_progressReporter && m_progressReporter->IsCancelled() )
|
|
|
|
return;
|
|
|
|
|
2019-07-12 12:56:02 +00:00
|
|
|
aRawPolys.BooleanSubtract( clearanceHoles, SHAPE_POLY_SET::PM_FAST );
|
2020-10-24 13:19:37 +00:00
|
|
|
DUMP_POLYS_TO_COPPER_LAYER( aRawPolys, In8_Cu, "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
|
|
|
|
2020-10-24 13:19:37 +00:00
|
|
|
DUMP_POLYS_TO_COPPER_LAYER( aRawPolys, In9_Cu, "deflated" );
|
2019-06-25 20:09:03 +00:00
|
|
|
|
2020-08-04 18:53:16 +00:00
|
|
|
if( m_progressReporter && m_progressReporter->IsCancelled() )
|
|
|
|
return;
|
|
|
|
|
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-06-24 02:19:08 +00:00
|
|
|
addHatchFillTypeOnZone( aZone, aLayer, aRawPolys );
|
2018-02-18 09:09:13 +00:00
|
|
|
|
2020-10-24 13:19:37 +00:00
|
|
|
DUMP_POLYS_TO_COPPER_LAYER( aRawPolys, In10_Cu, "after-hatching" );
|
2017-12-04 18:06:47 +00:00
|
|
|
|
2020-08-04 18:53:16 +00:00
|
|
|
if( m_progressReporter && m_progressReporter->IsCancelled() )
|
|
|
|
return;
|
|
|
|
|
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
|
|
|
|
2020-10-24 13:19:37 +00:00
|
|
|
DUMP_POLYS_TO_COPPER_LAYER( aRawPolys, In11_Cu, "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
|
|
|
|
aRawPolys.BooleanIntersection( aSmoothedOutline, SHAPE_POLY_SET::PM_FAST );
|
2020-10-24 13:19:37 +00:00
|
|
|
DUMP_POLYS_TO_COPPER_LAYER( aRawPolys, In12_Cu, "after-trim-to-outline" );
|
2020-08-25 18:03:21 +00:00
|
|
|
aRawPolys.BooleanSubtract( clearanceHoles, SHAPE_POLY_SET::PM_FAST );
|
2020-10-24 13:19:37 +00:00
|
|
|
DUMP_POLYS_TO_COPPER_LAYER( aRawPolys, In13_Cu, "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 );
|
|
|
|
|
2019-07-12 12:56:02 +00:00
|
|
|
aRawPolys.Fracture( SHAPE_POLY_SET::PM_FAST );
|
2019-03-10 16:57:26 +00:00
|
|
|
|
2019-07-12 12:56:02 +00:00
|
|
|
aFinalPolys = aRawPolys;
|
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-06-24 02:19:08 +00:00
|
|
|
bool ZONE_FILLER::fillSingleZone( ZONE_CONTAINER* 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;
|
|
|
|
SHAPE_POLY_SET smoothedPoly;
|
2017-12-04 18:06:47 +00:00
|
|
|
|
2019-07-13 16:35:57 +00:00
|
|
|
/*
|
|
|
|
* convert outlines + holes to outlines without holes (adding extra segments if necessary)
|
2017-12-04 18:06:47 +00:00
|
|
|
* m_Poly data is expected normalized, i.e. NormalizeAreaOutlines was used after building
|
|
|
|
* this zone
|
|
|
|
*/
|
2020-10-10 22:09:00 +00:00
|
|
|
if ( !aZone->BuildSmoothedPoly( smoothedPoly, aLayer, boardOutline ) )
|
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-08-12 18:42:40 +00:00
|
|
|
computeRawFilledArea( aZone, aLayer, smoothedPoly, aRawPolys, aFinalPolys );
|
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-06-24 02:19:08 +00:00
|
|
|
addHatchFillTypeOnZone( aZone, aLayer, 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 )
|
|
|
|
smoothedPoly.Deflate( -( half_min_width - epsilon ), numSegs );
|
|
|
|
|
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 );
|
2017-12-04 18:06:47 +00:00
|
|
|
}
|
2019-04-30 11:16:29 +00:00
|
|
|
|
2019-03-14 13:35:55 +00:00
|
|
|
aZone->SetNeedRefill( false );
|
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-06-24 02:19:08 +00:00
|
|
|
void ZONE_FILLER::buildThermalSpokes( const ZONE_CONTAINER* 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
|
|
|
|
|
|
|
for( auto module : m_board->Modules() )
|
|
|
|
{
|
|
|
|
for( auto pad : module->Pads() )
|
|
|
|
{
|
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();
|
|
|
|
D_PAD dummy_pad( *pad );
|
|
|
|
dummy_pad.SetOrientation( 0.0 );
|
|
|
|
dummy_pad.SetPosition( { 0, 0 } );
|
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
|
2017-12-13 23:33:20 +00:00
|
|
|
if( pad->GetShape() == PAD_SHAPE_CIRCLE )
|
2019-06-25 23:04:35 +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-06-24 02:19:08 +00:00
|
|
|
void ZONE_FILLER::addHatchFillTypeOnZone( const ZONE_CONTAINER* aZone, PCB_LAYER_ID aLayer,
|
|
|
|
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 )
|
|
|
|
filledPolys.Rotate( M_PI/180.0 * orientation, VECTOR2I( 0,0 ) );
|
|
|
|
|
|
|
|
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:
|
|
|
|
// make smoothing only for reasonnable smooth values, to avoid a lot of useless segments
|
|
|
|
// 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-08-07 14:04:34 +00:00
|
|
|
// We must buffer holes by at least aZone->GetMinThickness() to guarantee that thermal
|
|
|
|
// reliefs can be built (and to give the zone a solid outline). However, it looks more
|
|
|
|
// visually consistent if the buffer width is the same as the hatch width.
|
|
|
|
int outline_margin = KiROUND( aZone->GetMinThickness() * 1.1 );
|
|
|
|
|
|
|
|
if( aZone->GetHatchBorderAlgorithm() )
|
|
|
|
outline_margin = std::max( outline_margin, aZone->GetHatchThickness() );
|
|
|
|
|
|
|
|
if( outline_margin > linethickness / 2 )
|
|
|
|
filledPolys.Deflate( outline_margin - linethickness / 2, 16 );
|
|
|
|
|
2018-02-18 09:09:13 +00:00
|
|
|
holes.BooleanIntersection( filledPolys, SHAPE_POLY_SET::PM_FAST );
|
|
|
|
|
|
|
|
if( orientation != 0.0 )
|
|
|
|
holes.Rotate( -M_PI/180.0 * orientation, VECTOR2I( 0,0 ) );
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
for( TRACK* track : m_board->Tracks() )
|
|
|
|
{
|
|
|
|
if( track->Type() == PCB_VIA_T )
|
|
|
|
{
|
|
|
|
VIA* via = static_cast<VIA*>( track );
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( MODULE* module : m_board->Modules() )
|
|
|
|
{
|
|
|
|
for( D_PAD* pad : module->Pads() )
|
|
|
|
{
|
|
|
|
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 );
|
|
|
|
int min_annulus = ( pad_width - slot_width ) / 2;
|
|
|
|
int clearance = std::max( min_apron_radius - pad_width / 2,
|
|
|
|
outline_margin - min_annulus );
|
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
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 );
|
|
|
|
}
|