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
|
2019-01-19 11:35:35 +00:00
|
|
|
* Copyright (C) 2014-2019 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 <cstdint>
|
|
|
|
#include <thread>
|
|
|
|
#include <mutex>
|
2018-11-06 04:22:16 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <future>
|
2017-11-30 16:22:45 +00:00
|
|
|
|
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_zone.h>
|
|
|
|
#include <class_module.h>
|
2017-12-04 18:06:47 +00:00
|
|
|
#include <class_edge_mod.h>
|
|
|
|
#include <class_drawsegment.h>
|
|
|
|
#include <class_track.h>
|
|
|
|
#include <class_pcb_text.h>
|
|
|
|
#include <class_pcb_target.h>
|
|
|
|
|
2018-10-12 06:17:15 +00:00
|
|
|
#include <connectivity/connectivity_data.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/shape_file_io.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>
|
2017-12-04 18:06:47 +00:00
|
|
|
|
2017-11-30 16:22:45 +00:00
|
|
|
#include "zone_filler.h"
|
|
|
|
|
2019-05-23 14:27:07 +00:00
|
|
|
#include <advanced_config.h> // To be removed later, when the zone fill option will be always allowed
|
2017-11-30 16:22:45 +00:00
|
|
|
|
2019-04-10 09:19:16 +00:00
|
|
|
class PROGRESS_REPORTER_HIDER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PROGRESS_REPORTER_HIDER( WX_PROGRESS_REPORTER* aReporter )
|
|
|
|
{
|
|
|
|
m_reporter = aReporter;
|
|
|
|
|
|
|
|
if( aReporter )
|
|
|
|
aReporter->Hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
~PROGRESS_REPORTER_HIDER()
|
|
|
|
{
|
|
|
|
if( m_reporter )
|
|
|
|
m_reporter->Show();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
WX_PROGRESS_REPORTER* m_reporter;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-06-25 23:04:35 +00:00
|
|
|
static const double s_RoundPadThermalSpokeAngle = 450;
|
2017-12-04 18:06:47 +00:00
|
|
|
static const bool s_DumpZonesWhenFilling = false;
|
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 ) :
|
2019-06-22 17:56:37 +00:00
|
|
|
m_board( aBoard ), m_brdOutlinesValid( false ), m_commit( aCommit ),
|
|
|
|
m_progressReporter( nullptr )
|
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 );
|
2019-06-29 19:14:43 +00:00
|
|
|
m_progressReporter = m_uniqueReporter.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-10 09:19:16 +00:00
|
|
|
bool ZONE_FILLER::Fill( const std::vector<ZONE_CONTAINER*>& aZones, bool aCheck )
|
2017-11-30 16:22:45 +00:00
|
|
|
{
|
|
|
|
std::vector<CN_ZONE_ISOLATED_ISLAND_LIST> toFill;
|
|
|
|
auto connectivity = m_board->GetConnectivity();
|
2019-05-23 14:27:07 +00:00
|
|
|
bool filledPolyWithOutline = not m_board->GetDesignSettings().m_ZoneUseNoOutlineInFill;
|
|
|
|
|
2018-12-20 05:15:53 +00:00
|
|
|
std::unique_lock<std::mutex> lock( connectivity->GetLock(), std::try_to_lock );
|
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
2019-05-23 14:27:07 +00:00
|
|
|
m_progressReporter->Report( aCheck ? _( "Checking zone fills..." ) : _( "Building zone fills..." ) );
|
2019-04-10 09:19:16 +00:00
|
|
|
m_progressReporter->SetMaxProgress( toFill.size() );
|
|
|
|
}
|
|
|
|
|
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 );
|
|
|
|
|
2017-11-30 16:22:45 +00:00
|
|
|
for( auto zone : aZones )
|
|
|
|
{
|
|
|
|
// Keepout zones are not filled
|
|
|
|
if( zone->GetIsKeepout() )
|
|
|
|
continue;
|
|
|
|
|
2017-12-04 18:06:47 +00:00
|
|
|
if( m_commit )
|
2019-03-12 00:07:00 +00:00
|
|
|
m_commit->Modify( zone );
|
|
|
|
|
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
|
|
|
|
zone->BuildHashValue();
|
|
|
|
|
|
|
|
// Add the zone to the list of zones to test or refill
|
|
|
|
toFill.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();
|
2017-11-30 16:22:45 +00:00
|
|
|
}
|
|
|
|
|
2018-09-21 12:21:12 +00:00
|
|
|
std::atomic<size_t> nextItem( 0 );
|
2019-05-14 12:39:34 +00:00
|
|
|
size_t parallelThreadCount =
|
|
|
|
std::min<size_t>( std::thread::hardware_concurrency(), aZones.size() );
|
2018-11-06 04:22:16 +00:00
|
|
|
std::vector<std::future<size_t>> returns( parallelThreadCount );
|
2018-09-21 12:21:12 +00:00
|
|
|
|
2018-11-06 04:22:16 +00:00
|
|
|
auto fill_lambda = [&] ( PROGRESS_REPORTER* aReporter ) -> size_t
|
2017-11-30 16:22:45 +00:00
|
|
|
{
|
2018-11-06 04:22:16 +00:00
|
|
|
size_t num = 0;
|
|
|
|
|
|
|
|
for( size_t i = nextItem++; i < toFill.size(); i = nextItem++ )
|
2017-12-05 00:37:26 +00:00
|
|
|
{
|
2018-11-06 04:22:16 +00:00
|
|
|
ZONE_CONTAINER* zone = toFill[i].m_zone;
|
2019-05-23 14:27:07 +00:00
|
|
|
zone->SetFilledPolysUseThickness( filledPolyWithOutline );
|
2019-04-10 15:49:40 +00:00
|
|
|
SHAPE_POLY_SET rawPolys, finalPolys;
|
|
|
|
fillSingleZone( zone, rawPolys, finalPolys );
|
|
|
|
|
|
|
|
zone->SetRawPolysList( rawPolys );
|
|
|
|
zone->SetFilledPolysList( finalPolys );
|
2018-11-06 04:22:16 +00:00
|
|
|
zone->SetIsFilled( true );
|
2018-09-21 12:21:12 +00:00
|
|
|
|
2018-11-06 04:22:16 +00:00
|
|
|
if( m_progressReporter )
|
|
|
|
m_progressReporter->AdvanceProgress();
|
|
|
|
|
|
|
|
num++;
|
|
|
|
}
|
2018-02-10 13:32:57 +00:00
|
|
|
|
2018-11-06 04:22:16 +00:00
|
|
|
return num;
|
|
|
|
};
|
2018-09-21 12:21:12 +00:00
|
|
|
|
2018-11-06 04:22:16 +00:00
|
|
|
if( parallelThreadCount <= 1 )
|
|
|
|
fill_lambda( m_progressReporter );
|
|
|
|
else
|
2018-02-10 13:32:57 +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, fill_lambda, m_progressReporter );
|
2018-06-04 20:44:43 +00:00
|
|
|
|
2018-11-06 04:22:16 +00:00
|
|
|
for( size_t ii = 0; ii < parallelThreadCount; ++ii )
|
|
|
|
{
|
|
|
|
// Here we balance returns with a 100ms timeout to allow UI updating
|
|
|
|
std::future_status status;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if( m_progressReporter )
|
|
|
|
m_progressReporter->KeepRefreshing();
|
|
|
|
|
|
|
|
status = returns[ii].wait_for( std::chrono::milliseconds( 100 ) );
|
|
|
|
} while( status != std::future_status::ready );
|
|
|
|
}
|
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 )
|
|
|
|
{
|
|
|
|
m_progressReporter->AdvancePhase();
|
|
|
|
m_progressReporter->Report( _( "Removing insulated copper islands..." ) );
|
2018-02-10 13:32:57 +00:00
|
|
|
m_progressReporter->KeepRefreshing();
|
2017-11-30 16:22:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
connectivity->SetProgressReporter( m_progressReporter );
|
|
|
|
connectivity->FindIsolatedCopperIslands( toFill );
|
|
|
|
|
2019-04-08 12:10:08 +00:00
|
|
|
// Now remove insulated copper islands and islands outside the board edge
|
2018-04-09 14:07:53 +00:00
|
|
|
bool outOfDate = false;
|
|
|
|
|
2017-11-30 16:22:45 +00:00
|
|
|
for( auto& zone : toFill )
|
|
|
|
{
|
|
|
|
std::sort( zone.m_islands.begin(), zone.m_islands.end(), std::greater<int>() );
|
|
|
|
SHAPE_POLY_SET poly = zone.m_zone->GetFilledPolysList();
|
|
|
|
|
2019-04-09 09:38:18 +00:00
|
|
|
// Remove solid areas outside the board cutouts and the insulated islands
|
2019-04-08 12:10:08 +00:00
|
|
|
// only zones with net code > 0 can have insulated islands by definition
|
2019-02-27 10:27:18 +00:00
|
|
|
if( zone.m_zone->GetNetCode() > 0 )
|
2017-11-30 16:22:45 +00:00
|
|
|
{
|
2019-04-09 09:38:18 +00:00
|
|
|
// solid areas outside the board cutouts are also removed, because they are usually
|
|
|
|
// insulated islands
|
2019-02-27 10:27:18 +00:00
|
|
|
for( auto idx : zone.m_islands )
|
|
|
|
{
|
|
|
|
poly.DeletePolygon( idx );
|
|
|
|
}
|
2017-11-30 16:22:45 +00:00
|
|
|
}
|
2019-04-10 09:19:16 +00:00
|
|
|
// Zones with no net can have areas outside the board cutouts.
|
2019-05-23 18:19:35 +00:00
|
|
|
// By definition, Zones with no net have no isolated island
|
|
|
|
// (in fact all filled areas are isolated islands)
|
|
|
|
// but they can have some areas outside the board cutouts.
|
|
|
|
// A filled area outside the board cutouts has all points outside cutouts,
|
|
|
|
// so we only need to check one point for each filled polygon.
|
2019-06-22 07:55:25 +00:00
|
|
|
// Note also non copper zones are already clipped
|
2019-06-22 14:41:20 +00:00
|
|
|
else if( m_brdOutlinesValid && zone.m_zone->IsOnCopperLayer() )
|
2019-04-09 09:38:18 +00:00
|
|
|
{
|
2019-06-22 07:55:25 +00:00
|
|
|
for( int idx = 0; idx < poly.OutlineCount(); )
|
2019-05-14 12:39:34 +00:00
|
|
|
{
|
2019-05-23 18:19:35 +00:00
|
|
|
if( poly.Polygon( idx ).empty() ||
|
2019-06-22 07:55:25 +00:00
|
|
|
!m_boardOutline.Contains( poly.Polygon( idx ).front().CPoint( 0 ) ) )
|
2019-05-14 12:39:34 +00:00
|
|
|
{
|
|
|
|
poly.DeletePolygon( idx );
|
|
|
|
}
|
2019-05-23 18:19:35 +00:00
|
|
|
else
|
|
|
|
idx++;
|
2019-05-14 12:39:34 +00:00
|
|
|
}
|
2019-04-09 09:38:18 +00:00
|
|
|
}
|
2019-04-08 12:10:08 +00:00
|
|
|
|
2017-12-04 18:06:47 +00:00
|
|
|
zone.m_zone->SetFilledPolysList( poly );
|
2018-04-09 14:07:53 +00:00
|
|
|
|
2019-03-21 14:27:05 +00:00
|
|
|
if( aCheck && zone.m_zone->GetHashValue() != poly.GetHash() )
|
2018-04-09 14:07:53 +00:00
|
|
|
outOfDate = true;
|
2017-11-30 16:22:45 +00:00
|
|
|
}
|
|
|
|
|
2019-04-10 09:19:16 +00:00
|
|
|
if( aCheck && outOfDate )
|
2018-04-06 10:24:23 +00:00
|
|
|
{
|
2019-04-10 09:19:16 +00:00
|
|
|
PROGRESS_REPORTER_HIDER raii( m_progressReporter );
|
|
|
|
KIDIALOG dlg( m_progressReporter->GetParent(),
|
|
|
|
_( "Zone fills are out-of-date. Refill?" ),
|
|
|
|
_( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
|
|
|
|
dlg.SetOKCancelLabels( _( "Refill" ), _( "Continue without Refill" ) );
|
|
|
|
dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2018-04-06 10:24:23 +00:00
|
|
|
{
|
|
|
|
if( m_commit )
|
|
|
|
m_commit->Revert();
|
|
|
|
|
|
|
|
connectivity->SetProgressReporter( nullptr );
|
2018-05-03 22:23:47 +00:00
|
|
|
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..." ) );
|
2017-11-30 16:22:45 +00:00
|
|
|
m_progressReporter->SetMaxProgress( toFill.size() );
|
|
|
|
}
|
2018-02-10 13:32:57 +00:00
|
|
|
|
2018-03-03 17:40:57 +00:00
|
|
|
|
2018-09-21 12:21:12 +00:00
|
|
|
nextItem = 0;
|
2018-02-10 13:32:57 +00:00
|
|
|
|
2018-11-06 04:22:16 +00:00
|
|
|
auto tri_lambda = [&] ( PROGRESS_REPORTER* aReporter ) -> size_t
|
|
|
|
{
|
|
|
|
size_t num = 0;
|
2018-06-04 20:44:43 +00:00
|
|
|
|
2018-11-06 04:22:16 +00:00
|
|
|
for( size_t i = nextItem++; i < toFill.size(); i = nextItem++ )
|
|
|
|
{
|
|
|
|
toFill[i].m_zone->CacheTriangulation();
|
|
|
|
num++;
|
2018-01-14 08:51:32 +00:00
|
|
|
|
2018-11-06 04:22:16 +00:00
|
|
|
if( m_progressReporter )
|
|
|
|
m_progressReporter->AdvanceProgress();
|
|
|
|
}
|
2018-01-14 08:51:32 +00:00
|
|
|
|
2018-11-06 04:22:16 +00:00
|
|
|
return num;
|
|
|
|
};
|
2018-10-07 04:05:04 +00:00
|
|
|
|
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 )
|
|
|
|
m_progressReporter->KeepRefreshing();
|
2018-09-21 12:21:12 +00:00
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
m_progressReporter->AdvancePhase();
|
|
|
|
m_progressReporter->Report( _( "Committing changes..." ) );
|
2018-09-21 12:21:12 +00:00
|
|
|
m_progressReporter->KeepRefreshing();
|
2017-11-30 16:22:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
connectivity->SetProgressReporter( nullptr );
|
|
|
|
|
|
|
|
if( m_commit )
|
|
|
|
{
|
|
|
|
m_commit->Push( _( "Fill Zone(s)" ), false );
|
2017-12-04 18:06:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-04-10 09:19:16 +00:00
|
|
|
for( auto& i : toFill )
|
|
|
|
connectivity->Update( i.m_zone );
|
2017-12-14 22:49:46 +00:00
|
|
|
|
|
|
|
connectivity->RecalculateRatsnest();
|
2017-11-30 16:22:45 +00:00
|
|
|
}
|
2017-12-14 22:49:46 +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.
|
|
|
|
*/
|
|
|
|
bool hasThermalConnection( D_PAD* pad, const ZONE_CONTAINER* aZone )
|
|
|
|
{
|
|
|
|
// Rejects non-standard pads with tht-only thermal reliefs
|
|
|
|
if( aZone->GetPadConnection( pad ) == PAD_ZONE_CONN_THT_THERMAL
|
|
|
|
&& pad->GetAttribute() != PAD_ATTRIB_STANDARD )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aZone->GetPadConnection( pad ) != PAD_ZONE_CONN_THERMAL
|
|
|
|
&& aZone->GetPadConnection( pad ) != PAD_ZONE_CONN_THT_THERMAL )
|
|
|
|
{
|
|
|
|
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 );
|
|
|
|
|
|
|
|
return item_boundingbox.Intersects( aZone->GetBoundingBox() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
aDummyPad.SetNetCode( aPad->GetNetCode() );
|
|
|
|
aDummyPad.SetSize( aPad->GetDrillSize() );
|
|
|
|
aDummyPad.SetOrientation( aPad->GetOrientation() );
|
|
|
|
aDummyPad.SetShape( aPad->GetDrillShape() == PAD_DRILL_SHAPE_OBLONG ? PAD_SHAPE_OVAL
|
|
|
|
: PAD_SHAPE_CIRCLE );
|
|
|
|
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).
|
|
|
|
*/
|
|
|
|
void ZONE_FILLER::addKnockout( D_PAD* aPad, int aGap, SHAPE_POLY_SET& aHoles )
|
|
|
|
{
|
|
|
|
if( aPad->GetShape() == PAD_SHAPE_CUSTOM )
|
|
|
|
{
|
|
|
|
// the pad shape in zone can be its convex hull or the shape itself
|
|
|
|
SHAPE_POLY_SET outline( aPad->GetCustomShapeAsPolygon() );
|
|
|
|
int numSegs = std::max( GetArcToSegmentCount( aGap, m_high_def, 360.0 ), 6 );
|
|
|
|
double correction = GetCircletoPolyCorrectionFactor( numSegs );
|
|
|
|
outline.Inflate( KiROUND( aGap * correction ), numSegs );
|
|
|
|
aPad->CustomShapeAsPolygonToBoardPosition( &outline, aPad->GetPosition(),
|
|
|
|
aPad->GetOrientation() );
|
|
|
|
|
|
|
|
if( aPad->GetCustomShapeInZoneOpt() == CUST_PAD_SHAPE_IN_ZONE_CONVEXHULL )
|
|
|
|
{
|
|
|
|
std::vector<wxPoint> convex_hull;
|
|
|
|
BuildConvexHull( convex_hull, outline );
|
|
|
|
|
|
|
|
aHoles.NewOutline();
|
|
|
|
|
|
|
|
for( const wxPoint& pt : convex_hull )
|
|
|
|
aHoles.Append( pt );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
aHoles.Append( outline );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Optimizing polygon vertex count: the high definition is used for round
|
|
|
|
// and oval pads (pads with large arcs) but low def for other shapes (with
|
|
|
|
// small arcs)
|
2019-06-25 00:06:51 +00:00
|
|
|
if( aPad->GetShape() == PAD_SHAPE_CIRCLE || aPad->GetShape() == PAD_SHAPE_OVAL ||
|
|
|
|
( aPad->GetShape() == PAD_SHAPE_ROUNDRECT && aPad->GetRoundRectRadiusRatio() > 0.4 ) )
|
2019-06-20 22:35:01 +00:00
|
|
|
aPad->TransformShapeWithClearanceToPolygon( aHoles, aGap, m_high_def );
|
|
|
|
else
|
|
|
|
aPad->TransformShapeWithClearanceToPolygon( aHoles, aGap, m_low_def );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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).
|
|
|
|
*/
|
|
|
|
void ZONE_FILLER::addKnockout( BOARD_ITEM* aItem, int aGap, bool aIgnoreLineWidth,
|
|
|
|
SHAPE_POLY_SET& aHoles )
|
|
|
|
{
|
|
|
|
switch( aItem->Type() )
|
|
|
|
{
|
|
|
|
case PCB_LINE_T:
|
|
|
|
{
|
|
|
|
DRAWSEGMENT* seg = (DRAWSEGMENT*) aItem;
|
|
|
|
seg->TransformShapeWithClearanceToPolygon( aHoles, aGap, m_high_def, aIgnoreLineWidth );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PCB_TEXT_T:
|
|
|
|
{
|
|
|
|
TEXTE_PCB* text = (TEXTE_PCB*) aItem;
|
|
|
|
text->TransformBoundingBoxWithClearanceToPolygon( &aHoles, aGap );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PCB_MODULE_EDGE_T:
|
|
|
|
{
|
|
|
|
EDGE_MODULE* edge = (EDGE_MODULE*) aItem;
|
|
|
|
edge->TransformShapeWithClearanceToPolygon( aHoles, aGap, m_high_def, aIgnoreLineWidth );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PCB_MODULE_TEXT_T:
|
|
|
|
{
|
|
|
|
TEXTE_MODULE* text = (TEXTE_MODULE*) aItem;
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2019-06-25 20:09:03 +00:00
|
|
|
void ZONE_FILLER::knockoutThermalReliefs( const ZONE_CONTAINER* aZone, 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.
|
|
|
|
if( !pad->IsOnLayer( aZone->GetLayer() ) )
|
|
|
|
{
|
|
|
|
if( pad->GetDrillSize().x == 0 && pad->GetDrillSize().y == 0 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
setupDummyPadForHole( pad, dummypad );
|
|
|
|
pad = &dummypad;
|
|
|
|
}
|
|
|
|
|
|
|
|
addKnockout( pad, aZone->GetThermalReliefGap( pad ), holes );
|
2019-06-20 22:35:01 +00:00
|
|
|
}
|
|
|
|
}
|
2019-06-21 17:01:17 +00:00
|
|
|
|
|
|
|
holes.Simplify( SHAPE_POLY_SET::PM_FAST );
|
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.
|
|
|
|
*/
|
2019-06-25 20:09:03 +00:00
|
|
|
void ZONE_FILLER::buildCopperItemClearances( const ZONE_CONTAINER* aZone, SHAPE_POLY_SET& aHoles )
|
2019-06-20 22:35:01 +00:00
|
|
|
{
|
2019-04-05 16:10:59 +00:00
|
|
|
int zone_clearance = aZone->GetClearance();
|
|
|
|
int edgeClearance = m_board->GetDesignSettings().m_CopperEdgeClearance;
|
|
|
|
int zone_to_edgecut_clearance = std::max( aZone->GetZoneClearance(), edgeClearance );
|
2017-12-04 18:06:47 +00:00
|
|
|
|
2019-06-20 22:35:01 +00:00
|
|
|
// items outside the zone bounding box are skipped
|
|
|
|
// the bounding box is the zone bounding box + the biggest clearance found in Netclass list
|
|
|
|
EDA_RECT zone_boundingbox = aZone->GetBoundingBox();
|
2017-12-04 18:06:47 +00:00
|
|
|
int biggest_clearance = m_board->GetDesignSettings().GetBiggestClearanceValue();
|
|
|
|
biggest_clearance = std::max( biggest_clearance, zone_clearance );
|
|
|
|
zone_boundingbox.Inflate( biggest_clearance );
|
|
|
|
|
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 );
|
|
|
|
|
2019-06-20 22:35:01 +00:00
|
|
|
// Add non-connected pad clearances
|
|
|
|
//
|
2019-05-31 00:15:57 +00:00
|
|
|
for( auto module : m_board->Modules() )
|
2017-12-04 18:06:47 +00:00
|
|
|
{
|
2019-06-01 23:23:36 +00:00
|
|
|
for( auto pad : module->Pads() )
|
2017-12-04 18:06:47 +00:00
|
|
|
{
|
|
|
|
if( !pad->IsOnLayer( aZone->GetLayer() ) )
|
|
|
|
{
|
|
|
|
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-06-22 14:03:17 +00:00
|
|
|
if( pad->GetNetCode() != aZone->GetNetCode()
|
2019-06-20 22:35:01 +00:00
|
|
|
|| pad->GetNetCode() <= 0
|
|
|
|
|| aZone->GetPadConnection( pad ) == PAD_ZONE_CONN_NONE )
|
2017-12-04 18:06:47 +00:00
|
|
|
{
|
2019-06-25 00:06:51 +00:00
|
|
|
int gap = std::max( zone_clearance, pad->GetClearance() );
|
2019-06-20 22:35:01 +00:00
|
|
|
EDA_RECT item_boundingbox = pad->GetBoundingBox();
|
2019-06-25 00:06:51 +00:00
|
|
|
item_boundingbox.Inflate( pad->GetClearance() );
|
2017-12-04 18:06:47 +00:00
|
|
|
|
|
|
|
if( item_boundingbox.Intersects( zone_boundingbox ) )
|
2019-06-25 20:09:03 +00:00
|
|
|
addKnockout( pad, gap, aHoles );
|
2017-12-04 18:06:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-20 22:35:01 +00:00
|
|
|
// Add non-connected track clearances
|
|
|
|
//
|
2017-12-04 18:06:47 +00:00
|
|
|
for( auto track : m_board->Tracks() )
|
|
|
|
{
|
|
|
|
if( !track->IsOnLayer( aZone->GetLayer() ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( track->GetNetCode() == aZone->GetNetCode() && ( aZone->GetNetCode() != 0) )
|
|
|
|
continue;
|
|
|
|
|
2019-06-25 00:06:51 +00:00
|
|
|
int gap = std::max( zone_clearance, track->GetClearance() );
|
2019-06-20 22:35:01 +00:00
|
|
|
EDA_RECT item_boundingbox = track->GetBoundingBox();
|
2017-12-04 18:06:47 +00:00
|
|
|
|
|
|
|
if( item_boundingbox.Intersects( zone_boundingbox ) )
|
2019-06-25 20:09:03 +00:00
|
|
|
track->TransformShapeWithClearanceToPolygon( aHoles, gap, m_low_def );
|
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.
|
|
|
|
//
|
2018-08-23 22:41:57 +00:00
|
|
|
auto doGraphicItem = [&]( BOARD_ITEM* aItem )
|
2017-12-04 18:06:47 +00:00
|
|
|
{
|
2018-08-28 07:49:11 +00:00
|
|
|
// A item on the Edge_Cuts is always seen as on any layer:
|
|
|
|
if( !aItem->IsOnLayer( aZone->GetLayer() ) && !aItem->IsOnLayer( Edge_Cuts ) )
|
2018-08-23 22:41:57 +00:00
|
|
|
return;
|
2017-12-04 18:06:47 +00:00
|
|
|
|
2018-08-23 22:41:57 +00:00
|
|
|
if( !aItem->GetBoundingBox().Intersects( zone_boundingbox ) )
|
|
|
|
return;
|
2017-12-04 18:06:47 +00:00
|
|
|
|
2018-11-14 23:34:32 +00:00
|
|
|
bool ignoreLineWidth = false;
|
2019-06-20 22:35:01 +00:00
|
|
|
int gap = zone_clearance;
|
2017-12-04 18:06:47 +00:00
|
|
|
|
2018-08-23 22:41:57 +00:00
|
|
|
if( aItem->IsOnLayer( Edge_Cuts ) )
|
2018-11-14 23:34:32 +00:00
|
|
|
{
|
2019-06-20 22:35:01 +00:00
|
|
|
gap = zone_to_edgecut_clearance;
|
2017-12-04 18:06:47 +00:00
|
|
|
|
2018-11-14 23:34:32 +00:00
|
|
|
// edge cuts by definition don't have a width
|
|
|
|
ignoreLineWidth = true;
|
|
|
|
}
|
|
|
|
|
2019-06-25 20:09:03 +00:00
|
|
|
addKnockout( aItem, gap, ignoreLineWidth, aHoles );
|
2018-08-23 22:41:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for( auto module : m_board->Modules() )
|
|
|
|
{
|
|
|
|
doGraphicItem( &module->Reference() );
|
|
|
|
doGraphicItem( &module->Value() );
|
|
|
|
|
|
|
|
for( auto item : module->GraphicalItems() )
|
|
|
|
doGraphicItem( item );
|
2017-12-04 18:06:47 +00:00
|
|
|
}
|
|
|
|
|
2018-08-23 22:41:57 +00:00
|
|
|
for( auto item : m_board->Drawings() )
|
|
|
|
doGraphicItem( item );
|
|
|
|
|
2019-06-20 22:35:01 +00:00
|
|
|
// Add zones outlines having an higher priority and keepout
|
|
|
|
//
|
2017-12-04 18:06:47 +00:00
|
|
|
for( int ii = 0; ii < m_board->GetAreaCount(); ii++ )
|
|
|
|
{
|
|
|
|
ZONE_CONTAINER* zone = m_board->GetArea( ii );
|
|
|
|
|
|
|
|
// If the zones share no common layers
|
|
|
|
if( !aZone->CommonLayerExists( zone->GetLayerSet() ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( !zone->GetIsKeepout() && zone->GetPriority() <= aZone->GetPriority() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( zone->GetIsKeepout() && !zone->GetDoNotAllowCopperPour() )
|
|
|
|
continue;
|
|
|
|
|
2019-08-20 17:22:30 +00:00
|
|
|
// A higher priority zone or keepout area is found: remove this area
|
2019-06-20 22:35:01 +00:00
|
|
|
EDA_RECT item_boundingbox = zone->GetBoundingBox();
|
2017-12-04 18:06:47 +00:00
|
|
|
|
|
|
|
if( !item_boundingbox.Intersects( zone_boundingbox ) )
|
|
|
|
continue;
|
|
|
|
|
2019-07-03 11:07:11 +00:00
|
|
|
// Add the zone outline area. Don't use any clearance for keepouts, or for zones with
|
|
|
|
// the same net (they will be connected but will honor their own clearance, thermal
|
|
|
|
// connections, etc.).
|
2019-06-20 22:35:01 +00:00
|
|
|
bool sameNet = aZone->GetNetCode() == zone->GetNetCode();
|
|
|
|
bool useNetClearance = true;
|
|
|
|
int minClearance = zone_clearance;
|
2017-12-04 18:06:47 +00:00
|
|
|
|
|
|
|
// The final clearance is obviously the max value of each zone clearance
|
2019-06-25 00:06:51 +00:00
|
|
|
minClearance = std::max( minClearance, zone->GetClearance() );
|
2017-12-04 18:06:47 +00:00
|
|
|
|
2019-06-20 22:35:01 +00:00
|
|
|
if( zone->GetIsKeepout() || sameNet )
|
2019-07-03 11:07:11 +00:00
|
|
|
{
|
|
|
|
minClearance = 0;
|
2019-06-20 22:35:01 +00:00
|
|
|
useNetClearance = false;
|
2019-07-03 11:07:11 +00:00
|
|
|
}
|
2017-12-04 18:06:47 +00:00
|
|
|
|
2019-06-25 20:09:03 +00:00
|
|
|
zone->TransformOutlinesShapeWithClearanceToPolygon( aHoles, minClearance, useNetClearance );
|
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
|
|
|
|
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
|
|
|
*/
|
2019-06-20 22:35:01 +00:00
|
|
|
void ZONE_FILLER::computeRawFilledArea( const ZONE_CONTAINER* aZone,
|
|
|
|
const SHAPE_POLY_SET& aSmoothedOutline,
|
2019-07-13 22:34:09 +00:00
|
|
|
std::set<VECTOR2I>* aPreserveCorners,
|
2019-06-20 22:35:01 +00:00
|
|
|
SHAPE_POLY_SET& aRawPolys,
|
|
|
|
SHAPE_POLY_SET& aFinalPolys )
|
2017-12-04 18:06:47 +00:00
|
|
|
{
|
2019-06-20 22:35:01 +00:00
|
|
|
m_high_def = m_board->GetDesignSettings().m_MaxError;
|
|
|
|
m_low_def = std::min( ARC_LOW_DEF, int( m_high_def*1.5 ) ); // Reasonable value
|
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 );
|
|
|
|
int numSegs = std::max( GetArcToSegmentCount( half_min_width, m_high_def, 360.0 ), 6 );
|
|
|
|
|
2019-07-16 15:41:21 +00:00
|
|
|
SHAPE_POLY_SET::CORNER_STRATEGY cornerStrategy = SHAPE_POLY_SET::CHOP_ACUTE_CORNERS;
|
|
|
|
|
|
|
|
if( aZone->GetCornerSmoothingType() == ZONE_SETTINGS::SMOOTHING_FILLET )
|
|
|
|
cornerStrategy = SHAPE_POLY_SET::ROUND_ACUTE_CORNERS;
|
|
|
|
|
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
|
|
|
|
|
|
|
std::unique_ptr<SHAPE_FILE_IO> dumper( new SHAPE_FILE_IO(
|
|
|
|
s_DumpZonesWhenFilling ? "zones_dump.txt" : "", SHAPE_FILE_IO::IOM_APPEND ) );
|
|
|
|
|
2019-07-12 12:56:02 +00:00
|
|
|
aRawPolys = aSmoothedOutline;
|
|
|
|
|
2017-12-04 18:06:47 +00:00
|
|
|
if( s_DumpZonesWhenFilling )
|
|
|
|
dumper->BeginGroup( "clipper-zone" );
|
|
|
|
|
2019-07-12 12:56:02 +00:00
|
|
|
knockoutThermalReliefs( aZone, aRawPolys );
|
2017-12-04 18:06:47 +00:00
|
|
|
|
|
|
|
if( s_DumpZonesWhenFilling )
|
2019-07-12 12:56:02 +00:00
|
|
|
dumper->Write( &aRawPolys, "solid-areas-minus-thermal-reliefs" );
|
2017-12-04 18:06:47 +00:00
|
|
|
|
2019-06-25 20:09:03 +00:00
|
|
|
buildCopperItemClearances( aZone, clearanceHoles );
|
2019-06-20 22:35:01 +00:00
|
|
|
|
|
|
|
if( s_DumpZonesWhenFilling )
|
2019-07-12 12:56:02 +00:00
|
|
|
dumper->Write( &aRawPolys, "clearance holes" );
|
2019-06-25 20:09:03 +00:00
|
|
|
|
2019-07-11 23:28:46 +00:00
|
|
|
buildThermalSpokes( aZone, thermalSpokes );
|
|
|
|
|
|
|
|
// 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 );
|
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
testAreas.Deflate( half_min_width - epsilon, numSegs, cornerStrategy );
|
|
|
|
testAreas.Inflate( half_min_width - epsilon, numSegs, cornerStrategy );
|
|
|
|
}
|
2019-06-22 14:03:17 +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();
|
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
|
|
|
{
|
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
|
|
|
|
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
|
|
|
{
|
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
|
|
|
|
2019-07-23 18:32:38 +00:00
|
|
|
// Ensure previous changes (adding thermal stubs) do not add
|
|
|
|
// filled areas outside the zone boundary
|
|
|
|
aRawPolys.BooleanIntersection( aSmoothedOutline, SHAPE_POLY_SET::PM_FAST );
|
2019-07-12 12:56:02 +00:00
|
|
|
aRawPolys.Simplify( SHAPE_POLY_SET::PM_FAST );
|
2019-06-25 00:06:51 +00:00
|
|
|
|
2019-06-20 22:35:01 +00:00
|
|
|
if( s_DumpZonesWhenFilling )
|
2019-07-12 12:56:02 +00:00
|
|
|
dumper->Write( &aRawPolys, "solid-areas-with-thermal-spokes" );
|
2017-12-04 18:06:47 +00:00
|
|
|
|
2019-07-12 12:56:02 +00:00
|
|
|
aRawPolys.BooleanSubtract( clearanceHoles, SHAPE_POLY_SET::PM_FAST );
|
|
|
|
// Prune features that don't meet minimum-width criteria
|
2019-07-16 15:41:21 +00:00
|
|
|
if( half_min_width - epsilon > epsilon )
|
|
|
|
aRawPolys.Deflate( half_min_width - epsilon, numSegs, cornerStrategy );
|
2019-06-25 20:09:03 +00:00
|
|
|
|
|
|
|
if( s_DumpZonesWhenFilling )
|
2019-07-12 12:56:02 +00:00
|
|
|
dumper->Write( &aRawPolys, "solid-areas-before-hatching" );
|
2019-06-25 20:09:03 +00:00
|
|
|
|
2018-02-18 09:09:13 +00:00
|
|
|
// Now remove the non filled areas due to the hatch pattern
|
|
|
|
if( aZone->GetFillMode() == ZFM_HATCH_PATTERN )
|
2019-07-12 12:56:02 +00:00
|
|
|
addHatchFillTypeOnZone( aZone, aRawPolys );
|
2018-02-18 09:09:13 +00:00
|
|
|
|
2017-12-04 18:06:47 +00:00
|
|
|
if( s_DumpZonesWhenFilling )
|
2019-07-12 12:56:02 +00:00
|
|
|
dumper->Write( &aRawPolys, "solid-areas-after-hatching" );
|
2017-12-04 18:06:47 +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
|
|
|
{
|
2019-07-13 22:34:09 +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
|
|
|
{
|
|
|
|
aRawPolys.Simplify( SHAPE_POLY_SET::PM_FAST );
|
2019-07-16 15:41:21 +00:00
|
|
|
aRawPolys.Inflate( half_min_width - epsilon, numSegs, cornerStrategy );
|
|
|
|
|
|
|
|
// If we've deflated/inflated by something near our corner radius then we will have
|
|
|
|
// ended up with too-sharp corners. Apply outline smoothing again.
|
2019-07-23 18:32:38 +00:00
|
|
|
if( aZone->GetMinThickness() > (int)aZone->GetCornerRadius() )
|
2019-07-16 15:41:21 +00:00
|
|
|
aRawPolys.BooleanIntersection( aSmoothedOutline, SHAPE_POLY_SET::PM_FAST );
|
2019-06-22 14:03:17 +00:00
|
|
|
}
|
2019-05-23 14:27:07 +00:00
|
|
|
|
2019-07-12 12:56:02 +00:00
|
|
|
aRawPolys.Fracture( SHAPE_POLY_SET::PM_FAST );
|
2019-03-10 16:57:26 +00:00
|
|
|
|
2019-06-22 14:03:17 +00:00
|
|
|
if( s_DumpZonesWhenFilling )
|
2019-07-12 12:56:02 +00:00
|
|
|
dumper->Write( &aRawPolys, "areas_fractured" );
|
2017-12-04 18:06:47 +00:00
|
|
|
|
2019-07-12 12:56:02 +00:00
|
|
|
aFinalPolys = aRawPolys;
|
2017-12-04 18:06:47 +00:00
|
|
|
|
|
|
|
if( s_DumpZonesWhenFilling )
|
|
|
|
dumper->EndGroup();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2019-03-14 13:35:55 +00:00
|
|
|
bool ZONE_FILLER::fillSingleZone( ZONE_CONTAINER* aZone, SHAPE_POLY_SET& aRawPolys,
|
2019-06-20 22:35:01 +00:00
|
|
|
SHAPE_POLY_SET& aFinalPolys )
|
2017-12-04 18:06:47 +00:00
|
|
|
{
|
|
|
|
SHAPE_POLY_SET smoothedPoly;
|
2019-07-13 22:34:09 +00:00
|
|
|
std::set<VECTOR2I> colinearCorners;
|
|
|
|
aZone->GetColinearCorners( m_board, colinearCorners );
|
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
|
|
|
|
*/
|
2019-07-13 22:34:09 +00:00
|
|
|
if ( !aZone->BuildSmoothedPoly( smoothedPoly, &colinearCorners ) )
|
2017-12-04 18:06:47 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if( aZone->IsOnCopperLayer() )
|
|
|
|
{
|
2019-07-13 22:34:09 +00:00
|
|
|
computeRawFilledArea( aZone, smoothedPoly, &colinearCorners, 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 );
|
|
|
|
int numSegs = std::max( GetArcToSegmentCount( half_min_width, m_high_def, 360.0 ), 6 );
|
|
|
|
|
2019-06-22 07:55:25 +00:00
|
|
|
if( m_brdOutlinesValid )
|
|
|
|
smoothedPoly.BooleanIntersection( m_boardOutline, SHAPE_POLY_SET::PM_FAST );
|
|
|
|
|
2019-07-12 12:56:02 +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
|
|
|
|
if( aZone->GetFillMode() == ZFM_HATCH_PATTERN )
|
|
|
|
addHatchFillTypeOnZone( aZone, smoothedPoly );
|
|
|
|
|
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
|
|
|
*/
|
2019-06-22 14:03:17 +00:00
|
|
|
void ZONE_FILLER::buildThermalSpokes( const ZONE_CONTAINER* aZone,
|
2019-06-25 20:09:03 +00:00
|
|
|
std::deque<SHAPE_LINE_CHAIN>& aSpokesList )
|
2017-12-13 23:33:20 +00:00
|
|
|
{
|
2019-06-22 14:03:17 +00:00
|
|
|
auto zoneBB = aZone->GetBoundingBox();
|
2019-06-20 22:35:01 +00:00
|
|
|
int zone_clearance = aZone->GetZoneClearance();
|
|
|
|
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
|
|
|
|
if( !pad->IsOnLayer( aZone->GetLayer() ) )
|
|
|
|
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
|
2019-07-23 18:32:38 +00:00
|
|
|
int spoke_w = aZone->GetThermalReliefCopperBridge( pad );
|
|
|
|
// 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 );
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
wxPoint shapePos = pad->ShapePos();
|
2019-06-22 16:34:24 +00:00
|
|
|
wxPoint padPos = pad->GetPosition();
|
|
|
|
double padAngle = pad->GetOrientation();
|
|
|
|
pad->SetOrientation( 0.0 );
|
2019-06-25 23:04:35 +00:00
|
|
|
pad->SetPosition( { 0, 0 } );
|
2019-06-22 14:03:17 +00:00
|
|
|
BOX2I reliefBB = pad->GetBoundingBox();
|
2019-06-25 23:04:35 +00:00
|
|
|
pad->SetPosition( padPos );
|
|
|
|
pad->SetOrientation( padAngle );
|
|
|
|
|
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-06-25 20:09:03 +00:00
|
|
|
for( int j = 0; j < spoke.PointCount(); j++ )
|
2019-06-20 22:35:01 +00:00
|
|
|
{
|
2019-06-25 23:04:35 +00:00
|
|
|
RotatePoint( spoke.Point( j ), padAngle );
|
|
|
|
spoke.Point( j ) += 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
|
|
|
|
|
|
|
|
2019-06-20 22:35:01 +00:00
|
|
|
void ZONE_FILLER::addHatchFillTypeOnZone( const ZONE_CONTAINER* aZone, SHAPE_POLY_SET& aRawPolys )
|
2018-02-18 09:09:13 +00:00
|
|
|
{
|
|
|
|
// Build grid:
|
|
|
|
|
|
|
|
// obvously line thickness must be > zone min thickness. However, it should be
|
|
|
|
// the case because the zone dialog setup ensure that. However, it can happens
|
|
|
|
// if a board file was edited by hand by a python script
|
|
|
|
int thickness = std::max( aZone->GetHatchFillTypeThickness(), aZone->GetMinThickness()+2 );
|
|
|
|
int linethickness = thickness - aZone->GetMinThickness();
|
|
|
|
int gridsize = thickness + aZone->GetHatchFillTypeGap();
|
|
|
|
double orientation = aZone->GetHatchFillTypeOrientation();
|
|
|
|
|
|
|
|
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
|
|
|
|
// the hole size is aZone->GetHatchFillTypeGap(), but because the outline thickness
|
|
|
|
// is aZone->GetMinThickness(), the hole shape size must be larger
|
|
|
|
SHAPE_LINE_CHAIN hole_base;
|
|
|
|
int hole_size = aZone->GetHatchFillTypeGap() + aZone->GetMinThickness();
|
|
|
|
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
|
|
|
|
double minimal_hole_area = hole_base.Area() / 2;
|
|
|
|
|
|
|
|
// Now convert this hole to a smoothed shape:
|
|
|
|
if( aZone->GetHatchFillTypeSmoothingLevel() > 0 )
|
|
|
|
{
|
|
|
|
// the actual size of chamfer, or rounded corner radius is the half size
|
|
|
|
// of the HatchFillTypeGap scaled by aZone->GetHatchFillTypeSmoothingValue()
|
|
|
|
// aZone->GetHatchFillTypeSmoothingValue() = 1.0 is the max value for the chamfer or the
|
|
|
|
// radius of corner (radius = half size of the hole)
|
|
|
|
int smooth_value = KiROUND( aZone->GetHatchFillTypeGap()
|
|
|
|
* aZone->GetHatchFillTypeSmoothingValue() / 2 );
|
|
|
|
|
|
|
|
// 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
|
|
|
|
if( smooth_value > Millimeter2iu( SMOOTH_MIN_VAL_MM ) )
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET smooth_hole;
|
|
|
|
smooth_hole.AddOutline( hole_base );
|
|
|
|
int smooth_level = aZone->GetHatchFillTypeSmoothingLevel();
|
|
|
|
|
|
|
|
if( smooth_value < Millimeter2iu( SMOOTH_SMALL_VAL_MM ) && smooth_level > 1 )
|
|
|
|
smooth_level = 1;
|
|
|
|
// Use a larger smooth_value to compensate the outline tickness
|
|
|
|
// (chamfer is not visible is smooth value < outline thickess)
|
|
|
|
smooth_value += aZone->GetMinThickness()/2;
|
|
|
|
|
|
|
|
// smooth_value cannot be bigger than the half size oh the hole:
|
|
|
|
smooth_value = std::min( smooth_value, aZone->GetHatchFillTypeGap()/2 );
|
|
|
|
// the error to approximate a circle by segments when smoothing corners by a arc
|
|
|
|
int error_max = std::max( Millimeter2iu( 0.01), smooth_value/20 );
|
|
|
|
|
|
|
|
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:
|
|
|
|
if( aZone->GetHatchFillTypeSmoothingLevel() > 2 )
|
|
|
|
error_max /= 2; // Force better smoothing
|
|
|
|
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() );
|
|
|
|
|
|
|
|
// Clamp holes to the area of filled zones with a outline thickness
|
|
|
|
// > aZone->GetMinThickness() to be sure the thermal pads can be built
|
|
|
|
int outline_margin = std::max( (aZone->GetMinThickness()*10)/9, linethickness/2 );
|
2019-07-12 12:56:02 +00:00
|
|
|
filledPolys.Deflate( outline_margin, 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 ) );
|
|
|
|
|
|
|
|
// 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 );
|
|
|
|
}
|