2021-08-08 13:37:14 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2024-01-04 11:49:06 +00:00
|
|
|
* Copyright (C) 2021-2024 KiCad Developers.
|
2021-08-08 13:37:14 +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 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2021-08-09 10:10:09 +00:00
|
|
|
#include <board.h>
|
|
|
|
#include <board_design_settings.h>
|
|
|
|
#include <connectivity/connectivity_data.h>
|
|
|
|
#include <zone.h>
|
|
|
|
#include <footprint.h>
|
|
|
|
#include <pad.h>
|
|
|
|
#include <pcb_track.h>
|
2023-09-06 21:19:38 +00:00
|
|
|
#include <core/thread_pool.h>
|
2022-06-15 00:41:10 +00:00
|
|
|
|
2021-08-09 10:10:09 +00:00
|
|
|
#include <geometry/shape_line_chain.h>
|
|
|
|
#include <geometry/shape_poly_set.h>
|
2021-08-08 13:37:14 +00:00
|
|
|
#include <drc/drc_rule.h>
|
2021-12-01 14:42:44 +00:00
|
|
|
#include <drc/drc_item.h>
|
2021-08-08 13:37:14 +00:00
|
|
|
#include <drc/drc_test_provider.h>
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2021-08-09 10:10:09 +00:00
|
|
|
This loads some rule resolvers for the ZONE_FILLER, and checks that pad thermal relief
|
|
|
|
connections have at least the required number of spokes.
|
|
|
|
|
|
|
|
Errors generated:
|
|
|
|
- DRCE_STARVED_THERMAL
|
2021-08-08 13:37:14 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
class DRC_TEST_PROVIDER_ZONE_CONNECTIONS : public DRC_TEST_PROVIDER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DRC_TEST_PROVIDER_ZONE_CONNECTIONS()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~DRC_TEST_PROVIDER_ZONE_CONNECTIONS()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-08-09 10:10:09 +00:00
|
|
|
virtual bool Run() override;
|
2021-08-08 13:37:14 +00:00
|
|
|
|
|
|
|
virtual const wxString GetName() const override
|
|
|
|
{
|
2022-03-11 21:16:52 +00:00
|
|
|
return wxT( "zone connections" );
|
2021-08-08 13:37:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual const wxString GetDescription() const override
|
|
|
|
{
|
2022-03-11 21:16:52 +00:00
|
|
|
return wxT( "Checks thermal reliefs for a sufficient number of connecting spokes" );
|
2021-08-08 13:37:14 +00:00
|
|
|
}
|
2022-06-18 18:47:11 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void testZoneLayer( ZONE* aZone, PCB_LAYER_ID aLayer );
|
2021-08-08 13:37:14 +00:00
|
|
|
};
|
|
|
|
|
2021-08-09 10:10:09 +00:00
|
|
|
|
2022-06-18 18:47:11 +00:00
|
|
|
void DRC_TEST_PROVIDER_ZONE_CONNECTIONS::testZoneLayer( ZONE* aZone, PCB_LAYER_ID aLayer )
|
|
|
|
{
|
2021-08-09 10:10:09 +00:00
|
|
|
BOARD* board = m_drcEngine->GetBoard();
|
|
|
|
BOARD_DESIGN_SETTINGS& bds = board->GetDesignSettings();
|
|
|
|
std::shared_ptr<CONNECTIVITY_DATA> connectivity = board->GetConnectivity();
|
|
|
|
DRC_CONSTRAINT constraint;
|
2023-08-03 23:35:04 +00:00
|
|
|
wxString msg;
|
2021-08-09 10:10:09 +00:00
|
|
|
|
2022-06-18 18:47:11 +00:00
|
|
|
const std::shared_ptr<SHAPE_POLY_SET>& zoneFill = aZone->GetFilledPolysList( aLayer );
|
2023-03-25 10:44:46 +00:00
|
|
|
ISOLATED_ISLANDS isolatedIslands;
|
|
|
|
|
|
|
|
auto zoneIter = board->m_ZoneIsolatedIslandsMap.find( aZone );
|
|
|
|
|
|
|
|
if( zoneIter != board->m_ZoneIsolatedIslandsMap.end() )
|
|
|
|
{
|
|
|
|
auto layerIter = zoneIter->second.find( aLayer );
|
|
|
|
|
|
|
|
if( layerIter != zoneIter->second.end() )
|
|
|
|
isolatedIslands = layerIter->second;
|
|
|
|
}
|
2021-08-09 10:10:09 +00:00
|
|
|
|
|
|
|
for( FOOTPRINT* footprint : board->Footprints() )
|
|
|
|
{
|
2022-06-18 18:47:11 +00:00
|
|
|
for( PAD* pad : footprint->Pads() )
|
|
|
|
{
|
|
|
|
if( m_drcEngine->IsErrorLimitExceeded( DRCE_STARVED_THERMAL ) )
|
|
|
|
return;
|
2021-08-09 10:10:09 +00:00
|
|
|
|
2022-06-18 18:47:11 +00:00
|
|
|
if( m_drcEngine->IsCancelled() )
|
|
|
|
return;
|
2021-08-09 10:10:09 +00:00
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
//
|
2022-06-18 18:47:11 +00:00
|
|
|
// Quick tests for "connected":
|
|
|
|
//
|
2022-08-26 12:21:52 +00:00
|
|
|
|
2022-06-18 18:47:11 +00:00
|
|
|
if( pad->GetNetCode() != aZone->GetNetCode() || pad->GetNetCode() <= 0 )
|
|
|
|
continue;
|
2021-08-09 10:10:09 +00:00
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
BOX2I item_bbox = pad->GetBoundingBox();
|
2022-08-03 09:10:23 +00:00
|
|
|
|
2022-10-01 21:09:38 +00:00
|
|
|
if( !item_bbox.Intersects( aZone->GetBoundingBox() ) )
|
2022-08-03 09:10:23 +00:00
|
|
|
continue;
|
2022-03-11 20:13:47 +00:00
|
|
|
|
2022-08-03 09:10:23 +00:00
|
|
|
if( !pad->FlashLayer( aLayer ) )
|
2022-06-18 18:47:11 +00:00
|
|
|
continue;
|
2022-02-07 20:39:39 +00:00
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
//
|
2022-06-18 18:47:11 +00:00
|
|
|
// If those passed, do a thorough test:
|
|
|
|
//
|
2022-08-26 12:21:52 +00:00
|
|
|
|
2022-06-18 18:47:11 +00:00
|
|
|
constraint = bds.m_DRCEngine->EvalZoneConnection( pad, aZone, aLayer );
|
|
|
|
ZONE_CONNECTION conn = constraint.m_ZoneConnection;
|
2021-08-09 10:10:09 +00:00
|
|
|
|
2022-06-18 18:47:11 +00:00
|
|
|
if( conn != ZONE_CONNECTION::THERMAL )
|
|
|
|
continue;
|
2021-08-09 10:10:09 +00:00
|
|
|
|
2022-06-18 18:47:11 +00:00
|
|
|
constraint = bds.m_DRCEngine->EvalRules( MIN_RESOLVED_SPOKES_CONSTRAINT, pad, aZone,
|
|
|
|
aLayer );
|
|
|
|
int minCount = constraint.m_Value.Min();
|
2021-08-09 10:10:09 +00:00
|
|
|
|
2022-06-18 18:47:11 +00:00
|
|
|
if( constraint.GetSeverity() == RPT_SEVERITY_IGNORE || minCount <= 0 )
|
|
|
|
continue;
|
2021-08-09 10:10:09 +00:00
|
|
|
|
2023-08-04 14:37:23 +00:00
|
|
|
constraint = bds.m_DRCEngine->EvalRules( THERMAL_RELIEF_GAP_CONSTRAINT, pad, aZone,
|
|
|
|
aLayer );
|
|
|
|
int mid_gap = constraint.m_Value.Min() / 2;
|
|
|
|
|
2022-06-18 18:47:11 +00:00
|
|
|
SHAPE_POLY_SET padPoly;
|
2023-08-04 14:37:23 +00:00
|
|
|
pad->TransformShapeToPolygon( padPoly, aLayer, mid_gap, ARC_LOW_DEF, ERROR_OUTSIDE );
|
2021-08-09 10:10:09 +00:00
|
|
|
|
2022-06-18 18:47:11 +00:00
|
|
|
SHAPE_LINE_CHAIN& padOutline = padPoly.Outline( 0 );
|
2023-12-23 17:44:25 +00:00
|
|
|
BOX2I padBBox( padOutline.BBox() );
|
2023-08-03 14:03:04 +00:00
|
|
|
int spokes = 0;
|
|
|
|
int ignoredSpokes = 0;
|
2023-11-10 12:48:14 +00:00
|
|
|
VECTOR2I ignoredSpokePos;
|
2021-08-09 10:10:09 +00:00
|
|
|
|
2022-06-18 18:47:11 +00:00
|
|
|
for( int jj = 0; jj < zoneFill->OutlineCount(); ++jj )
|
2023-03-25 10:44:46 +00:00
|
|
|
{
|
2023-08-03 14:03:04 +00:00
|
|
|
std::vector<SHAPE_LINE_CHAIN::INTERSECTION> intersections;
|
|
|
|
|
|
|
|
zoneFill->Outline( jj ).Intersect( padOutline, intersections, true, &padBBox );
|
|
|
|
|
2023-03-25 10:44:46 +00:00
|
|
|
// If we connect to an island that only connects to a single item then we *are*
|
|
|
|
// that item. Thermal spokes to this (otherwise isolated) island don't provide
|
|
|
|
// electrical connectivity to anything, so we don't count them.
|
2023-11-10 12:48:14 +00:00
|
|
|
if( intersections.size() >= 2 )
|
|
|
|
{
|
|
|
|
if( alg::contains( isolatedIslands.m_SingleConnectionOutlines, jj ) )
|
|
|
|
{
|
|
|
|
ignoredSpokes += (int) intersections.size() / 2;
|
|
|
|
ignoredSpokePos = ( intersections[0].p + intersections[1].p ) / 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
spokes += (int) intersections.size() / 2;
|
|
|
|
}
|
|
|
|
}
|
2023-03-25 10:44:46 +00:00
|
|
|
}
|
2022-08-03 09:10:23 +00:00
|
|
|
|
2023-08-03 14:03:04 +00:00
|
|
|
if( spokes == 0 && ignoredSpokes == 0 ) // Not connected at all
|
2022-08-03 09:10:23 +00:00
|
|
|
continue;
|
2021-08-09 10:10:09 +00:00
|
|
|
|
2023-08-03 14:03:04 +00:00
|
|
|
if( spokes >= minCount ) // We already have enough
|
2022-06-18 18:47:11 +00:00
|
|
|
continue;
|
2021-08-09 10:10:09 +00:00
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
//
|
2022-08-03 09:10:23 +00:00
|
|
|
// See if there are any other manual spokes added:
|
2022-06-18 18:47:11 +00:00
|
|
|
//
|
2022-08-26 12:21:52 +00:00
|
|
|
|
2022-06-18 18:47:11 +00:00
|
|
|
for( PCB_TRACK* track : connectivity->GetConnectedTracks( pad ) )
|
|
|
|
{
|
|
|
|
if( padOutline.PointInside( track->GetStart() ) )
|
|
|
|
{
|
|
|
|
if( aZone->GetFilledPolysList( aLayer )->Collide( track->GetEnd() ) )
|
|
|
|
spokes++;
|
|
|
|
}
|
|
|
|
else if( padOutline.PointInside( track->GetEnd() ) )
|
|
|
|
{
|
|
|
|
if( aZone->GetFilledPolysList( aLayer )->Collide( track->GetStart() ) )
|
|
|
|
spokes++;
|
|
|
|
}
|
|
|
|
}
|
2021-08-09 10:10:09 +00:00
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
//
|
2022-06-18 18:47:11 +00:00
|
|
|
// And finally report it if there aren't enough:
|
|
|
|
//
|
2022-08-26 12:21:52 +00:00
|
|
|
|
2022-06-18 18:47:11 +00:00
|
|
|
if( spokes < minCount )
|
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( DRCE_STARVED_THERMAL );
|
2023-11-10 12:48:14 +00:00
|
|
|
VECTOR2I pos;
|
2023-08-03 23:35:04 +00:00
|
|
|
|
|
|
|
if( ignoredSpokes )
|
|
|
|
{
|
|
|
|
msg = wxString::Format( _( "(layer %s; %d spokes connected to isolated island)" ),
|
|
|
|
board->GetLayerName( aLayer ),
|
|
|
|
ignoredSpokes );
|
2023-11-10 12:48:14 +00:00
|
|
|
pos = ignoredSpokePos;
|
2023-08-03 23:35:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg = wxString::Format( _( "(layer %s; %s min spoke count %d; actual %d)" ),
|
|
|
|
board->GetLayerName( aLayer ),
|
|
|
|
constraint.GetName(),
|
|
|
|
minCount,
|
|
|
|
spokes );
|
2023-11-10 12:48:14 +00:00
|
|
|
pos = pad->GetPosition();
|
2023-08-03 23:35:04 +00:00
|
|
|
}
|
2022-02-07 17:49:01 +00:00
|
|
|
|
2022-06-18 18:47:11 +00:00
|
|
|
drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
|
|
|
|
drce->SetItems( aZone, pad );
|
|
|
|
drce->SetViolatingRule( constraint.GetParentRule() );
|
2021-08-09 10:10:09 +00:00
|
|
|
|
2023-11-10 12:48:14 +00:00
|
|
|
reportViolation( drce, pos, aLayer );
|
2022-06-18 18:47:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-08-09 10:10:09 +00:00
|
|
|
|
|
|
|
|
2022-06-18 18:47:11 +00:00
|
|
|
bool DRC_TEST_PROVIDER_ZONE_CONNECTIONS::Run()
|
|
|
|
{
|
|
|
|
BOARD* board = m_drcEngine->GetBoard();
|
|
|
|
std::shared_ptr<CONNECTIVITY_DATA> connectivity = board->GetConnectivity();
|
|
|
|
DRC_CONSTRAINT constraint;
|
|
|
|
|
|
|
|
if( !reportPhase( _( "Checking thermal reliefs..." ) ) )
|
|
|
|
return false; // DRC cancelled
|
|
|
|
|
|
|
|
std::vector< std::pair<ZONE*, PCB_LAYER_ID> > zoneLayers;
|
2022-07-30 22:37:10 +00:00
|
|
|
std::atomic<size_t> done( 1 );
|
|
|
|
size_t total_effort = 0;
|
2022-06-18 18:47:11 +00:00
|
|
|
|
|
|
|
for( ZONE* zone : board->m_DRCCopperZones )
|
|
|
|
{
|
2023-03-25 10:44:46 +00:00
|
|
|
if( !zone->IsTeardropArea() )
|
2022-07-30 22:37:10 +00:00
|
|
|
{
|
2023-03-25 10:44:46 +00:00
|
|
|
for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
|
|
|
|
{
|
|
|
|
zoneLayers.push_back( { zone, layer } );
|
|
|
|
total_effort += zone->GetFilledPolysList( layer )->FullPointCount();
|
|
|
|
}
|
2022-07-30 22:37:10 +00:00
|
|
|
}
|
2022-06-18 18:47:11 +00:00
|
|
|
}
|
2021-08-09 10:10:09 +00:00
|
|
|
|
2022-08-03 09:10:23 +00:00
|
|
|
total_effort = std::max( (size_t) 1, total_effort );
|
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
thread_pool& tp = GetKiCadThreadPool();
|
|
|
|
std::vector<std::future<int>> returns;
|
|
|
|
|
|
|
|
returns.reserve( zoneLayers.size() );
|
2022-06-18 18:47:11 +00:00
|
|
|
|
2022-07-30 22:37:10 +00:00
|
|
|
for( const std::pair<ZONE*, PCB_LAYER_ID>& zonelayer : zoneLayers )
|
2022-06-18 18:47:11 +00:00
|
|
|
{
|
2022-07-30 22:37:10 +00:00
|
|
|
returns.emplace_back( tp.submit(
|
|
|
|
[&]( ZONE* aZone, PCB_LAYER_ID aLayer ) -> int
|
2022-06-18 18:47:11 +00:00
|
|
|
{
|
2022-06-15 00:41:10 +00:00
|
|
|
if( !m_drcEngine->IsCancelled() )
|
2022-06-18 18:47:11 +00:00
|
|
|
{
|
2022-06-15 00:41:10 +00:00
|
|
|
testZoneLayer( aZone, aLayer );
|
2022-07-30 22:37:10 +00:00
|
|
|
done.fetch_add( aZone->GetFilledPolysList( aLayer )->FullPointCount() );
|
2021-08-09 10:10:09 +00:00
|
|
|
}
|
2022-07-30 22:37:10 +00:00
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
return 0;
|
2022-07-30 22:37:10 +00:00
|
|
|
},
|
|
|
|
zonelayer.first, zonelayer.second ) );
|
2022-06-18 18:47:11 +00:00
|
|
|
}
|
|
|
|
|
2022-09-14 20:28:46 +00:00
|
|
|
for( const std::future<int>& ret : returns )
|
2022-06-18 18:47:11 +00:00
|
|
|
{
|
2022-09-14 20:28:46 +00:00
|
|
|
std::future_status status = ret.wait_for( std::chrono::milliseconds( 250 ) );
|
2022-06-15 00:41:10 +00:00
|
|
|
|
2022-09-14 20:28:46 +00:00
|
|
|
while( status != std::future_status::ready )
|
2022-06-15 00:41:10 +00:00
|
|
|
{
|
2024-01-04 11:49:06 +00:00
|
|
|
reportProgress( done, total_effort );
|
2022-09-14 20:28:46 +00:00
|
|
|
status = ret.wait_for( std::chrono::milliseconds( 250 ) );
|
2022-08-03 09:10:23 +00:00
|
|
|
}
|
2021-08-09 10:10:09 +00:00
|
|
|
}
|
|
|
|
|
2022-03-11 20:13:47 +00:00
|
|
|
return !m_drcEngine->IsCancelled();
|
2021-08-09 10:10:09 +00:00
|
|
|
}
|
|
|
|
|
2021-08-08 13:37:14 +00:00
|
|
|
|
|
|
|
namespace detail
|
|
|
|
{
|
|
|
|
static DRC_REGISTER_TEST_PROVIDER<DRC_TEST_PROVIDER_ZONE_CONNECTIONS> dummy;
|
|
|
|
}
|