2021-08-08 13:37:14 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-03-11 21:16:52 +00:00
|
|
|
* Copyright (C) 2021-2022 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>
|
|
|
|
#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
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-08-09 10:10:09 +00:00
|
|
|
bool DRC_TEST_PROVIDER_ZONE_CONNECTIONS::Run()
|
|
|
|
{
|
|
|
|
const int delta = 5; // This is the number of tests between 2 calls to the progress bar
|
|
|
|
int ii = 0;
|
|
|
|
|
|
|
|
BOARD* board = m_drcEngine->GetBoard();
|
|
|
|
BOARD_DESIGN_SETTINGS& bds = board->GetDesignSettings();
|
|
|
|
std::shared_ptr<CONNECTIVITY_DATA> connectivity = board->GetConnectivity();
|
|
|
|
DRC_CONSTRAINT constraint;
|
|
|
|
std::vector<ZONE*> zones;
|
|
|
|
|
|
|
|
if( !reportPhase( _( "Checking thermal reliefs..." ) ) )
|
|
|
|
return false; // DRC cancelled
|
|
|
|
|
|
|
|
for( ZONE* zone : board->Zones() )
|
|
|
|
zones.push_back( zone );
|
|
|
|
|
|
|
|
for( FOOTPRINT* footprint : board->Footprints() )
|
|
|
|
{
|
|
|
|
for( ZONE* zone : footprint->Zones() )
|
|
|
|
zones.push_back( zone );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( ZONE* zone : zones )
|
|
|
|
{
|
|
|
|
if( !reportProgress( ii++, zones.size(), delta ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
|
|
|
|
{
|
2022-02-15 17:34:38 +00:00
|
|
|
const std::shared_ptr<SHAPE_POLY_SET>& zoneFill = zone->GetFilledPolysList( layer );
|
2021-08-09 10:10:09 +00:00
|
|
|
|
|
|
|
for( FOOTPRINT* footprint : board->Footprints() )
|
|
|
|
{
|
|
|
|
for( PAD* pad : footprint->Pads() )
|
|
|
|
{
|
|
|
|
if( m_drcEngine->IsErrorLimitExceeded( DRCE_STARVED_THERMAL ) )
|
|
|
|
return true;
|
|
|
|
|
2022-03-11 20:13:47 +00:00
|
|
|
if( m_drcEngine->IsCancelled() )
|
|
|
|
return false;
|
|
|
|
|
2022-02-07 20:39:39 +00:00
|
|
|
// Quick tests for "connected":
|
|
|
|
//
|
|
|
|
if( !pad->FlashLayer( layer ) )
|
|
|
|
continue;
|
|
|
|
|
2021-08-09 10:10:09 +00:00
|
|
|
if( pad->GetNetCode() != zone->GetNetCode() || pad->GetNetCode() <= 0 )
|
|
|
|
continue;
|
|
|
|
|
2022-02-07 20:39:39 +00:00
|
|
|
EDA_RECT item_boundingbox = pad->GetBoundingBox();
|
2021-08-09 10:10:09 +00:00
|
|
|
|
2022-02-07 20:39:39 +00:00
|
|
|
if( !item_boundingbox.Intersects( zone->GetCachedBoundingBox() ) )
|
2021-08-09 10:10:09 +00:00
|
|
|
continue;
|
|
|
|
|
2022-02-07 20:39:39 +00:00
|
|
|
// If those passed, do a thorough test:
|
|
|
|
//
|
2021-08-09 10:10:09 +00:00
|
|
|
constraint = bds.m_DRCEngine->EvalZoneConnection( pad, zone, layer );
|
|
|
|
ZONE_CONNECTION conn = constraint.m_ZoneConnection;
|
|
|
|
|
|
|
|
if( conn != ZONE_CONNECTION::THERMAL )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
constraint = bds.m_DRCEngine->EvalRules( MIN_RESOLVED_SPOKES_CONSTRAINT,
|
|
|
|
pad, zone, layer );
|
|
|
|
int minCount = constraint.m_Value.Min();
|
|
|
|
|
2021-09-05 15:06:12 +00:00
|
|
|
if( constraint.GetSeverity() == RPT_SEVERITY_IGNORE || minCount <= 0 )
|
2021-08-09 10:10:09 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
SHAPE_POLY_SET padPoly;
|
|
|
|
pad->TransformShapeWithClearanceToPolygon( padPoly, layer, 0, ARC_LOW_DEF,
|
|
|
|
ERROR_OUTSIDE );
|
|
|
|
|
|
|
|
SHAPE_LINE_CHAIN& padOutline = padPoly.Outline( 0 );
|
|
|
|
std::vector<SHAPE_LINE_CHAIN::INTERSECTION> intersections;
|
|
|
|
int spokes = 0;
|
|
|
|
|
2022-02-15 17:34:38 +00:00
|
|
|
for( int jj = 0; jj < zoneFill->OutlineCount(); ++jj )
|
|
|
|
padOutline.Intersect( zoneFill->Outline( jj ), intersections, true );
|
2021-08-09 10:10:09 +00:00
|
|
|
|
|
|
|
spokes += intersections.size() / 2;
|
|
|
|
|
2022-02-07 17:49:01 +00:00
|
|
|
if( spokes <= 0 )
|
|
|
|
continue;
|
|
|
|
|
2022-02-07 20:39:39 +00:00
|
|
|
// Now we know we're connected, so see if there are any other manual spokes
|
|
|
|
// added:
|
|
|
|
//
|
2021-08-09 10:10:09 +00:00
|
|
|
for( PCB_TRACK* track : connectivity->GetConnectedTracks( pad ) )
|
|
|
|
{
|
|
|
|
if( padOutline.PointInside( track->GetStart() ) )
|
|
|
|
{
|
2022-02-15 17:34:38 +00:00
|
|
|
if( zone->GetFilledPolysList( layer )->Collide( track->GetEnd() ) )
|
2021-08-09 10:10:09 +00:00
|
|
|
spokes++;
|
|
|
|
}
|
|
|
|
else if( padOutline.PointInside( track->GetEnd() ) )
|
|
|
|
{
|
2022-02-15 17:34:38 +00:00
|
|
|
if( zone->GetFilledPolysList( layer )->Collide( track->GetStart() ) )
|
2021-08-09 10:10:09 +00:00
|
|
|
spokes++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-07 20:39:39 +00:00
|
|
|
// And finally report it if there aren't enough:
|
|
|
|
//
|
2022-02-07 17:49:01 +00:00
|
|
|
if( spokes < minCount )
|
2021-08-09 10:10:09 +00:00
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( DRCE_STARVED_THERMAL );
|
|
|
|
|
|
|
|
m_msg.Printf( _( "(%s min spoke count %d; actual %d)" ),
|
|
|
|
constraint.GetName(),
|
|
|
|
minCount,
|
|
|
|
spokes );
|
|
|
|
|
|
|
|
drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + m_msg );
|
|
|
|
drce->SetItems( zone, pad );
|
|
|
|
drce->SetViolatingRule( constraint.GetParentRule() );
|
|
|
|
|
2021-12-26 13:47:00 +00:00
|
|
|
reportViolation( drce, pad->GetPosition(), UNDEFINED_LAYER );
|
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;
|
|
|
|
}
|