2020-07-27 13:33:06 +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) 2004-2022 KiCad Developers.
|
2020-07-27 13:33:06 +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
|
|
|
|
*/
|
|
|
|
|
2020-06-13 23:28:08 +00:00
|
|
|
#include <common.h>
|
2021-07-18 23:08:54 +00:00
|
|
|
#include <math_for_graphics.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <board_design_settings.h>
|
2021-06-03 18:05:43 +00:00
|
|
|
#include <footprint.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <pcb_shape.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <pad.h>
|
2021-06-11 21:07:02 +00:00
|
|
|
#include <pcb_track.h>
|
2023-07-07 02:23:28 +00:00
|
|
|
#include <thread_pool.h>
|
2021-06-03 18:05:43 +00:00
|
|
|
#include <zone.h>
|
2020-06-13 23:28:08 +00:00
|
|
|
|
|
|
|
#include <geometry/seg.h>
|
|
|
|
#include <geometry/shape_poly_set.h>
|
2020-07-15 16:23:56 +00:00
|
|
|
#include <geometry/shape_segment.h>
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <drc/drc_engine.h>
|
2020-10-27 17:09:27 +00:00
|
|
|
#include <drc/drc_rtree.h>
|
2020-09-11 15:04:11 +00:00
|
|
|
#include <drc/drc_item.h>
|
|
|
|
#include <drc/drc_rule.h>
|
2020-09-11 16:24:27 +00:00
|
|
|
#include <drc/drc_test_provider_clearance_base.h>
|
2021-06-11 16:59:28 +00:00
|
|
|
#include <pcb_dimension.h>
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2023-07-07 02:23:28 +00:00
|
|
|
#include <future>
|
|
|
|
|
2020-07-27 13:33:06 +00:00
|
|
|
/*
|
2021-08-09 21:25:16 +00:00
|
|
|
Copper clearance test. Checks all copper items (pads, vias, tracks, drawings, zones) for their
|
|
|
|
electrical clearance.
|
|
|
|
|
2020-07-27 13:33:06 +00:00
|
|
|
Errors generated:
|
|
|
|
- DRCE_CLEARANCE
|
2021-08-09 21:25:16 +00:00
|
|
|
- DRCE_HOLE_CLEARANCE
|
2020-07-27 13:33:06 +00:00
|
|
|
- DRCE_TRACKS_CROSSING
|
|
|
|
- DRCE_ZONES_INTERSECT
|
2020-08-25 17:42:52 +00:00
|
|
|
- DRCE_SHORTING_ITEMS
|
2020-07-27 13:33:06 +00:00
|
|
|
*/
|
|
|
|
|
2020-06-19 21:34:19 +00:00
|
|
|
class DRC_TEST_PROVIDER_COPPER_CLEARANCE : public DRC_TEST_PROVIDER_CLEARANCE_BASE
|
2020-06-13 23:28:08 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-06-19 21:34:19 +00:00
|
|
|
DRC_TEST_PROVIDER_COPPER_CLEARANCE () :
|
2020-11-01 11:39:14 +00:00
|
|
|
DRC_TEST_PROVIDER_CLEARANCE_BASE(),
|
|
|
|
m_drcEpsilon( 0 )
|
2020-09-11 16:24:27 +00:00
|
|
|
{
|
|
|
|
}
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2020-08-11 23:50:56 +00:00
|
|
|
virtual ~DRC_TEST_PROVIDER_COPPER_CLEARANCE()
|
2020-06-13 23:28:08 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool Run() override;
|
|
|
|
|
2020-08-11 23:50:56 +00:00
|
|
|
virtual const wxString GetName() const override
|
2020-06-19 21:34:19 +00:00
|
|
|
{
|
2022-03-11 21:16:52 +00:00
|
|
|
return wxT( "clearance" );
|
2020-06-19 21:34:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual const wxString GetDescription() const override
|
|
|
|
{
|
2022-03-11 21:16:52 +00:00
|
|
|
return wxT( "Tests copper item clearance" );
|
2020-06-19 21:34:19 +00:00
|
|
|
}
|
|
|
|
|
2020-06-13 23:28:08 +00:00
|
|
|
private:
|
2022-12-12 18:53:44 +00:00
|
|
|
/**
|
|
|
|
* Checks for track/via/hole <-> clearance
|
2023-07-30 19:39:07 +00:00
|
|
|
* @param item Track to text
|
|
|
|
* @param itemShape Primitive track shape
|
2022-12-12 18:53:44 +00:00
|
|
|
* @param layer Which layer to test (in case of vias this can be multiple
|
|
|
|
* @param other item against which to test the track item
|
|
|
|
* @return false if there is a clearance violation reported, true if there is none
|
|
|
|
*/
|
2023-07-30 19:39:07 +00:00
|
|
|
bool testSingleLayerItemAgainstItem( BOARD_CONNECTED_ITEM* item, SHAPE* itemShape,
|
|
|
|
PCB_LAYER_ID layer, BOARD_ITEM* other );
|
2020-09-11 16:24:27 +00:00
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
void testTrackClearances();
|
2020-09-11 16:24:27 +00:00
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
bool testPadAgainstItem( PAD* pad, SHAPE* padShape, PCB_LAYER_ID layer, BOARD_ITEM* other );
|
2020-10-27 17:09:27 +00:00
|
|
|
|
|
|
|
void testPadClearances();
|
2020-09-11 16:24:27 +00:00
|
|
|
|
2023-06-30 10:56:36 +00:00
|
|
|
void testGraphicClearances();
|
|
|
|
|
2021-08-09 21:25:16 +00:00
|
|
|
void testZonesToZones();
|
2020-09-11 16:24:27 +00:00
|
|
|
|
2021-09-05 15:06:12 +00:00
|
|
|
void testItemAgainstZone( BOARD_ITEM* aItem, ZONE* aZone, PCB_LAYER_ID aLayer );
|
2020-10-27 17:09:27 +00:00
|
|
|
|
2023-06-30 10:56:36 +00:00
|
|
|
void testKnockoutTextAgainstZone( BOARD_ITEM* aText, NETINFO_ITEM** aInheritedNet, ZONE* aZone );
|
|
|
|
|
2022-12-12 18:53:44 +00:00
|
|
|
typedef struct checked
|
|
|
|
{
|
|
|
|
checked()
|
|
|
|
: layers(), has_error( false ) {}
|
|
|
|
|
|
|
|
checked( PCB_LAYER_ID aLayer )
|
|
|
|
: layers( aLayer ), has_error( false ) {}
|
|
|
|
|
|
|
|
LSET layers;
|
|
|
|
bool has_error;
|
|
|
|
} layers_checked;
|
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
private:
|
2022-06-17 21:50:59 +00:00
|
|
|
int m_drcEpsilon;
|
2020-06-13 23:28:08 +00:00
|
|
|
};
|
|
|
|
|
2020-06-17 22:36:54 +00:00
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
bool DRC_TEST_PROVIDER_COPPER_CLEARANCE::Run()
|
2020-06-13 23:28:08 +00:00
|
|
|
{
|
|
|
|
m_board = m_drcEngine->GetBoard();
|
2021-02-27 13:43:41 +00:00
|
|
|
|
2022-06-17 21:50:59 +00:00
|
|
|
if( m_board->m_DRCMaxClearance <= 0 )
|
2021-02-27 13:43:41 +00:00
|
|
|
{
|
2022-03-11 21:16:52 +00:00
|
|
|
reportAux( wxT( "No Clearance constraints found. Tests not run." ) );
|
2021-02-27 13:43:41 +00:00
|
|
|
return true; // continue with other tests
|
2020-12-25 22:13:47 +00:00
|
|
|
}
|
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
m_drcEpsilon = m_board->GetDesignSettings().GetDRCEpsilon();
|
|
|
|
|
2021-02-27 13:43:41 +00:00
|
|
|
if( !m_drcEngine->IsErrorLimitExceeded( DRCE_CLEARANCE ) )
|
|
|
|
{
|
|
|
|
if( !reportPhase( _( "Checking track & via clearances..." ) ) )
|
|
|
|
return false; // DRC cancelled
|
|
|
|
|
|
|
|
testTrackClearances();
|
|
|
|
}
|
|
|
|
else if( !m_drcEngine->IsErrorLimitExceeded( DRCE_HOLE_CLEARANCE ) )
|
|
|
|
{
|
|
|
|
if( !reportPhase( _( "Checking hole clearances..." ) ) )
|
|
|
|
return false; // DRC cancelled
|
|
|
|
|
|
|
|
testTrackClearances();
|
|
|
|
}
|
2020-09-18 19:57:54 +00:00
|
|
|
|
2021-02-27 13:43:41 +00:00
|
|
|
if( !m_drcEngine->IsErrorLimitExceeded( DRCE_CLEARANCE ) )
|
|
|
|
{
|
|
|
|
if( !reportPhase( _( "Checking pad clearances..." ) ) )
|
|
|
|
return false; // DRC cancelled
|
2020-09-11 16:24:27 +00:00
|
|
|
|
2021-02-27 13:43:41 +00:00
|
|
|
testPadClearances();
|
|
|
|
}
|
|
|
|
else if( !m_drcEngine->IsErrorLimitExceeded( DRCE_SHORTING_ITEMS )
|
|
|
|
|| !m_drcEngine->IsErrorLimitExceeded( DRCE_HOLE_CLEARANCE ) )
|
|
|
|
{
|
|
|
|
if( !reportPhase( _( "Checking pads..." ) ) )
|
|
|
|
return false; // DRC cancelled
|
2020-09-18 19:57:54 +00:00
|
|
|
|
2021-02-27 13:43:41 +00:00
|
|
|
testPadClearances();
|
|
|
|
}
|
2020-09-11 16:24:27 +00:00
|
|
|
|
2023-06-30 10:56:36 +00:00
|
|
|
if( !m_drcEngine->IsErrorLimitExceeded( DRCE_CLEARANCE ) )
|
|
|
|
{
|
|
|
|
if( !reportPhase( _( "Checking copper graphic clearances..." ) ) )
|
|
|
|
return false; // DRC cancelled
|
|
|
|
|
|
|
|
testGraphicClearances();
|
|
|
|
}
|
|
|
|
|
2021-02-27 13:43:41 +00:00
|
|
|
if( !m_drcEngine->IsErrorLimitExceeded( DRCE_CLEARANCE ) )
|
|
|
|
{
|
|
|
|
if( !reportPhase( _( "Checking copper zone clearances..." ) ) )
|
|
|
|
return false; // DRC cancelled
|
2020-09-18 19:57:54 +00:00
|
|
|
|
2021-08-11 06:16:26 +00:00
|
|
|
testZonesToZones();
|
2021-02-27 13:43:41 +00:00
|
|
|
}
|
|
|
|
else if( !m_drcEngine->IsErrorLimitExceeded( DRCE_ZONES_INTERSECT ) )
|
|
|
|
{
|
|
|
|
if( !reportPhase( _( "Checking zones..." ) ) )
|
|
|
|
return false; // DRC cancelled
|
|
|
|
|
2021-08-11 06:16:26 +00:00
|
|
|
testZonesToZones();
|
2021-02-27 13:43:41 +00:00
|
|
|
}
|
2020-06-17 22:36:54 +00:00
|
|
|
|
2020-08-25 17:42:52 +00:00
|
|
|
reportRuleStatistics();
|
|
|
|
|
2022-03-11 20:13:47 +00:00
|
|
|
return !m_drcEngine->IsCancelled();
|
2020-06-17 22:36:54 +00:00
|
|
|
}
|
|
|
|
|
2020-11-17 17:53:21 +00:00
|
|
|
|
2023-07-30 19:39:07 +00:00
|
|
|
bool DRC_TEST_PROVIDER_COPPER_CLEARANCE::testSingleLayerItemAgainstItem( BOARD_CONNECTED_ITEM* item,
|
|
|
|
SHAPE* itemShape,
|
|
|
|
PCB_LAYER_ID layer,
|
|
|
|
BOARD_ITEM* other )
|
2020-06-18 16:55:22 +00:00
|
|
|
{
|
2020-12-25 22:13:47 +00:00
|
|
|
bool testClearance = !m_drcEngine->IsErrorLimitExceeded( DRCE_CLEARANCE );
|
2023-04-02 20:07:14 +00:00
|
|
|
bool testShorting = !m_drcEngine->IsErrorLimitExceeded( DRCE_SHORTING_ITEMS );
|
2020-12-25 22:13:47 +00:00
|
|
|
bool testHoles = !m_drcEngine->IsErrorLimitExceeded( DRCE_HOLE_CLEARANCE );
|
|
|
|
DRC_CONSTRAINT constraint;
|
2021-01-23 00:09:18 +00:00
|
|
|
int clearance = -1;
|
2020-12-25 22:13:47 +00:00
|
|
|
int actual;
|
|
|
|
VECTOR2I pos;
|
2022-12-12 18:53:44 +00:00
|
|
|
bool has_error = false;
|
2023-04-02 20:07:14 +00:00
|
|
|
int otherNet = 0;
|
|
|
|
|
|
|
|
if( BOARD_CONNECTED_ITEM* connectedItem = dynamic_cast<BOARD_CONNECTED_ITEM*>( other ) )
|
|
|
|
otherNet = connectedItem->GetNetCode();
|
2020-12-25 22:13:47 +00:00
|
|
|
|
2022-09-20 20:40:45 +00:00
|
|
|
std::shared_ptr<SHAPE> otherShape = other->GetEffectiveShape( layer );
|
|
|
|
|
2021-01-03 23:26:42 +00:00
|
|
|
if( other->Type() == PCB_PAD_T )
|
|
|
|
{
|
|
|
|
PAD* pad = static_cast<PAD*>( other );
|
|
|
|
|
2021-05-01 14:46:50 +00:00
|
|
|
if( pad->GetAttribute() == PAD_ATTRIB::NPTH && !pad->FlashLayer( layer ) )
|
2023-04-02 20:07:14 +00:00
|
|
|
testClearance = testShorting = false;
|
2021-01-03 23:26:42 +00:00
|
|
|
}
|
|
|
|
|
2023-04-02 20:07:14 +00:00
|
|
|
if( testClearance || testShorting )
|
2020-06-18 16:55:22 +00:00
|
|
|
{
|
2023-07-30 19:39:07 +00:00
|
|
|
constraint = m_drcEngine->EvalRules( CLEARANCE_CONSTRAINT, item, other, layer );
|
2020-12-25 22:13:47 +00:00
|
|
|
clearance = constraint.GetValue().Min();
|
2021-01-23 00:09:18 +00:00
|
|
|
}
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2022-05-05 17:00:17 +00:00
|
|
|
if( constraint.GetSeverity() != RPT_SEVERITY_IGNORE && clearance > 0 )
|
2021-01-23 00:09:18 +00:00
|
|
|
{
|
2020-12-25 22:13:47 +00:00
|
|
|
// Special processing for track:track intersections
|
2023-07-30 19:39:07 +00:00
|
|
|
if( item->Type() == PCB_TRACE_T && other->Type() == PCB_TRACE_T )
|
2020-06-18 16:55:22 +00:00
|
|
|
{
|
2023-07-30 19:39:07 +00:00
|
|
|
PCB_TRACK* track = static_cast<PCB_TRACK*>( item );
|
|
|
|
PCB_TRACK* otherTrack = static_cast<PCB_TRACK*>( other );
|
|
|
|
|
2020-12-25 22:13:47 +00:00
|
|
|
SEG trackSeg( track->GetStart(), track->GetEnd() );
|
2023-07-30 19:39:07 +00:00
|
|
|
SEG otherSeg( otherTrack->GetStart(), otherTrack->GetEnd() );
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-12-25 22:13:47 +00:00
|
|
|
if( OPT_VECTOR2I intersection = trackSeg.Intersect( otherSeg ) )
|
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_TRACKS_CROSSING );
|
2023-07-30 19:39:07 +00:00
|
|
|
drcItem->SetItems( item, other );
|
2020-12-25 22:13:47 +00:00
|
|
|
drcItem->SetViolatingRule( constraint.GetParentRule() );
|
|
|
|
|
2022-08-30 20:58:43 +00:00
|
|
|
reportViolation( drcItem, *intersection, layer );
|
2021-01-23 00:09:18 +00:00
|
|
|
|
2022-12-12 18:53:44 +00:00
|
|
|
return false;
|
2020-12-25 22:13:47 +00:00
|
|
|
}
|
2020-06-18 16:55:22 +00:00
|
|
|
}
|
2020-12-25 22:13:47 +00:00
|
|
|
|
2023-07-30 19:39:07 +00:00
|
|
|
if( itemShape->Collide( otherShape.get(), clearance - m_drcEpsilon, &actual, &pos ) )
|
2021-02-01 17:53:41 +00:00
|
|
|
{
|
2023-07-30 19:39:07 +00:00
|
|
|
if( m_drcEngine->IsNetTieExclusion( item->GetNetCode(), layer, pos, other ) )
|
2022-08-19 17:34:53 +00:00
|
|
|
{
|
|
|
|
// Collision occurred as track was entering a pad marked as a net-tie. We
|
|
|
|
// allow these.
|
|
|
|
}
|
2023-04-02 20:07:14 +00:00
|
|
|
else if( actual == 0 && otherNet && testShorting )
|
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( DRCE_SHORTING_ITEMS );
|
|
|
|
wxString msg;
|
|
|
|
|
2023-07-30 19:39:07 +00:00
|
|
|
msg.Printf( _( "(nets %s and %s)" ), item->GetNetname(),
|
2023-04-02 20:07:14 +00:00
|
|
|
static_cast<BOARD_CONNECTED_ITEM*>( other )->GetNetname() );
|
|
|
|
|
|
|
|
drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
|
2023-07-30 19:39:07 +00:00
|
|
|
drce->SetItems( item, other );
|
2023-04-02 20:07:14 +00:00
|
|
|
|
|
|
|
reportViolation( drce, pos, layer );
|
|
|
|
has_error = true;
|
|
|
|
|
|
|
|
if( !m_drcEngine->GetReportAllTrackErrors() )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if( testClearance )
|
2022-08-19 17:34:53 +00:00
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( DRCE_CLEARANCE );
|
2022-10-06 20:52:17 +00:00
|
|
|
wxString msg = formatMsg( _( "(%s clearance %s; actual %s)" ),
|
|
|
|
constraint.GetName(),
|
|
|
|
clearance,
|
|
|
|
actual );
|
2020-12-25 22:13:47 +00:00
|
|
|
|
2022-08-19 17:34:53 +00:00
|
|
|
drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
|
2023-07-30 19:39:07 +00:00
|
|
|
drce->SetItems( item, other );
|
2022-08-19 17:34:53 +00:00
|
|
|
drce->SetViolatingRule( constraint.GetParentRule() );
|
2021-01-23 00:09:18 +00:00
|
|
|
|
2022-08-19 17:34:53 +00:00
|
|
|
reportViolation( drce, pos, layer );
|
2022-12-12 18:53:44 +00:00
|
|
|
has_error = true;
|
2020-12-25 22:13:47 +00:00
|
|
|
|
2022-08-19 17:34:53 +00:00
|
|
|
if( !m_drcEngine->GetReportAllTrackErrors() )
|
|
|
|
return false;
|
|
|
|
}
|
2020-12-25 22:13:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-30 19:39:07 +00:00
|
|
|
if( testHoles && ( item->HasHole() || other->HasHole() ) )
|
2020-10-27 17:09:27 +00:00
|
|
|
{
|
2023-07-30 19:39:07 +00:00
|
|
|
std::array<BOARD_ITEM*, 2> a{ item, other };
|
|
|
|
std::array<BOARD_ITEM*, 2> b{ other, item };
|
|
|
|
std::array<SHAPE*, 2> a_shape{ itemShape, otherShape.get() };
|
2020-12-25 22:13:47 +00:00
|
|
|
|
2022-12-12 18:53:44 +00:00
|
|
|
for( size_t ii = 0; ii < 2; ++ii )
|
2020-12-25 22:13:47 +00:00
|
|
|
{
|
2022-09-20 20:40:45 +00:00
|
|
|
std::shared_ptr<SHAPE_SEGMENT> holeShape;
|
|
|
|
|
|
|
|
// We only test a track item here against an item with a hole.
|
|
|
|
// If either case is not valid, simply move on
|
|
|
|
if( !( dynamic_cast<PCB_TRACK*>( a[ii] ) ) || !b[ii]->HasHole() )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if( b[ii]->Type() == PCB_VIA_T )
|
|
|
|
{
|
|
|
|
if( b[ii]->GetLayerSet().Contains( layer ) )
|
|
|
|
holeShape = b[ii]->GetEffectiveHoleShape();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
holeShape = b[ii]->GetEffectiveHoleShape();
|
|
|
|
}
|
|
|
|
|
|
|
|
constraint = m_drcEngine->EvalRules( HOLE_CLEARANCE_CONSTRAINT, b[ii], a[ii], layer );
|
2020-12-25 22:13:47 +00:00
|
|
|
clearance = constraint.GetValue().Min();
|
|
|
|
|
2022-12-23 13:06:10 +00:00
|
|
|
// Test for hole to item clearance even if clearance is 0, because the item cannot be
|
|
|
|
// inside (or intersect) the hole.
|
|
|
|
if( constraint.GetSeverity() != RPT_SEVERITY_IGNORE )
|
2020-12-25 22:13:47 +00:00
|
|
|
{
|
2022-09-20 20:40:45 +00:00
|
|
|
if( a_shape[ii]->Collide( holeShape.get(), std::max( 0, clearance - m_drcEpsilon ),
|
2022-10-06 20:52:17 +00:00
|
|
|
&actual, &pos ) )
|
2021-09-05 15:06:12 +00:00
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( DRCE_HOLE_CLEARANCE );
|
2022-12-23 13:06:10 +00:00
|
|
|
wxString msg = formatMsg( clearance ? _( "(%s clearance %s; actual %s)" )
|
|
|
|
: _( "(%s clearance %s; actual < 0)" ),
|
2022-10-06 20:52:17 +00:00
|
|
|
constraint.GetName(),
|
|
|
|
clearance,
|
|
|
|
actual );
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2022-06-15 23:42:34 +00:00
|
|
|
drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
|
2022-09-20 20:40:45 +00:00
|
|
|
drce->SetItems( a[ii], b[ii] );
|
2021-09-05 15:06:12 +00:00
|
|
|
drce->SetViolatingRule( constraint.GetParentRule() );
|
2020-06-17 22:36:54 +00:00
|
|
|
|
2022-01-02 02:06:40 +00:00
|
|
|
reportViolation( drce, pos, layer );
|
2022-12-12 18:53:44 +00:00
|
|
|
return false;
|
2021-09-05 15:06:12 +00:00
|
|
|
}
|
2020-12-25 22:13:47 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-17 22:36:54 +00:00
|
|
|
}
|
2020-10-27 17:09:27 +00:00
|
|
|
|
2022-12-12 18:53:44 +00:00
|
|
|
return !has_error;
|
2020-06-13 23:28:08 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 22:27:33 +00:00
|
|
|
|
2021-09-05 15:06:12 +00:00
|
|
|
void DRC_TEST_PROVIDER_COPPER_CLEARANCE::testItemAgainstZone( BOARD_ITEM* aItem, ZONE* aZone,
|
2022-07-22 22:05:25 +00:00
|
|
|
PCB_LAYER_ID aLayer )
|
2020-06-17 22:36:54 +00:00
|
|
|
{
|
2021-09-05 15:06:12 +00:00
|
|
|
if( !aZone->GetLayerSet().test( aLayer ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( aZone->GetNetCode() && aItem->IsConnected() )
|
2020-06-17 22:36:54 +00:00
|
|
|
{
|
2021-09-05 15:06:12 +00:00
|
|
|
if( aZone->GetNetCode() == static_cast<BOARD_CONNECTED_ITEM*>( aItem )->GetNetCode() )
|
|
|
|
return;
|
|
|
|
}
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
BOX2I itemBBox = aItem->GetBoundingBox();
|
|
|
|
BOX2I worstCaseBBox = itemBBox;
|
2022-08-26 12:21:52 +00:00
|
|
|
|
|
|
|
worstCaseBBox.Inflate( m_board->m_DRCMaxClearance );
|
|
|
|
|
2022-10-01 21:09:38 +00:00
|
|
|
if( !worstCaseBBox.Intersects( aZone->GetBoundingBox() ) )
|
2021-09-05 15:06:12 +00:00
|
|
|
return;
|
2020-09-17 16:32:42 +00:00
|
|
|
|
2021-09-05 15:06:12 +00:00
|
|
|
bool testClearance = !m_drcEngine->IsErrorLimitExceeded( DRCE_CLEARANCE );
|
|
|
|
bool testHoles = !m_drcEngine->IsErrorLimitExceeded( DRCE_HOLE_CLEARANCE );
|
2021-01-23 00:09:18 +00:00
|
|
|
|
2021-09-05 15:06:12 +00:00
|
|
|
if( !testClearance && !testHoles )
|
|
|
|
return;
|
2021-01-23 00:09:18 +00:00
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
DRC_RTREE* zoneTree = m_board->m_CopperZoneRTreeCache[ aZone ].get();
|
|
|
|
|
|
|
|
if( !zoneTree )
|
|
|
|
return;
|
|
|
|
|
|
|
|
DRC_CONSTRAINT constraint;
|
|
|
|
int clearance = -1;
|
|
|
|
int actual;
|
|
|
|
VECTOR2I pos;
|
2022-04-04 19:42:00 +00:00
|
|
|
|
2022-07-22 22:05:25 +00:00
|
|
|
if( aItem->Type() == PCB_PAD_T )
|
2022-04-09 19:39:35 +00:00
|
|
|
{
|
2022-08-26 12:21:52 +00:00
|
|
|
PAD* pad = static_cast<PAD*>( aItem );
|
|
|
|
bool flashedPad = pad->FlashLayer( aLayer );
|
|
|
|
bool platedHole = pad->HasHole() && pad->GetAttribute() == PAD_ATTRIB::PTH;
|
2022-04-04 19:42:00 +00:00
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
if( !flashedPad && !platedHole )
|
|
|
|
testClearance = false;
|
2022-04-04 19:42:00 +00:00
|
|
|
}
|
2020-11-19 23:51:48 +00:00
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
if( testClearance )
|
2021-09-05 15:06:12 +00:00
|
|
|
{
|
2022-08-26 12:21:52 +00:00
|
|
|
constraint = m_drcEngine->EvalRules( CLEARANCE_CONSTRAINT, aItem, aZone, aLayer );
|
2021-09-05 15:06:12 +00:00
|
|
|
clearance = constraint.GetValue().Min();
|
|
|
|
}
|
|
|
|
|
2022-05-05 17:00:17 +00:00
|
|
|
if( constraint.GetSeverity() != RPT_SEVERITY_IGNORE && clearance > 0 )
|
2021-09-05 15:06:12 +00:00
|
|
|
{
|
2022-08-26 12:21:52 +00:00
|
|
|
std::shared_ptr<SHAPE> itemShape = aItem->GetEffectiveShape( aLayer, FLASHING::DEFAULT );
|
2021-08-09 21:25:16 +00:00
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
if( zoneTree->QueryColliding( itemBBox, itemShape.get(), aLayer,
|
|
|
|
std::max( 0, clearance - m_drcEpsilon ), &actual, &pos ) )
|
2021-09-05 15:06:12 +00:00
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( DRCE_CLEARANCE );
|
2022-10-06 20:52:17 +00:00
|
|
|
wxString msg = formatMsg( _( "(%s clearance %s; actual %s)" ),
|
|
|
|
constraint.GetName(),
|
|
|
|
clearance,
|
|
|
|
actual );
|
2020-11-19 23:51:48 +00:00
|
|
|
|
2022-06-15 23:42:34 +00:00
|
|
|
drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
|
2021-09-05 15:06:12 +00:00
|
|
|
drce->SetItems( aItem, aZone );
|
|
|
|
drce->SetViolatingRule( constraint.GetParentRule() );
|
|
|
|
|
2022-01-02 02:06:40 +00:00
|
|
|
reportViolation( drce, pos, aLayer );
|
2021-09-05 15:06:12 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-09 21:25:16 +00:00
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
if( testHoles && aItem->HasHole() )
|
2021-09-05 15:06:12 +00:00
|
|
|
{
|
2022-07-22 22:05:25 +00:00
|
|
|
std::shared_ptr<SHAPE_SEGMENT> holeShape;
|
2021-08-09 21:25:16 +00:00
|
|
|
|
2022-07-22 22:05:25 +00:00
|
|
|
if( aItem->Type() == PCB_VIA_T )
|
2021-09-05 15:06:12 +00:00
|
|
|
{
|
2022-07-22 22:05:25 +00:00
|
|
|
if( aItem->GetLayerSet().Contains( aLayer ) )
|
|
|
|
holeShape = aItem->GetEffectiveHoleShape();
|
2021-09-05 15:06:12 +00:00
|
|
|
}
|
2022-07-22 22:05:25 +00:00
|
|
|
else
|
2021-09-05 15:06:12 +00:00
|
|
|
{
|
2022-07-22 22:05:25 +00:00
|
|
|
holeShape = aItem->GetEffectiveHoleShape();
|
2021-09-05 15:06:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( holeShape )
|
|
|
|
{
|
|
|
|
constraint = m_drcEngine->EvalRules( HOLE_CLEARANCE_CONSTRAINT, aItem, aZone, aLayer );
|
|
|
|
clearance = constraint.GetValue().Min();
|
|
|
|
|
2022-05-05 17:00:17 +00:00
|
|
|
if( constraint.GetSeverity() != RPT_SEVERITY_IGNORE && clearance > 0 )
|
2021-09-05 15:06:12 +00:00
|
|
|
{
|
|
|
|
if( zoneTree->QueryColliding( itemBBox, holeShape.get(), aLayer,
|
|
|
|
std::max( 0, clearance - m_drcEpsilon ),
|
|
|
|
&actual, &pos ) )
|
2020-11-19 23:51:48 +00:00
|
|
|
{
|
2022-10-06 20:52:17 +00:00
|
|
|
std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( DRCE_HOLE_CLEARANCE );
|
|
|
|
wxString msg = formatMsg( _( "(%s clearance %s; actual %s)" ),
|
|
|
|
constraint.GetName(),
|
|
|
|
clearance,
|
|
|
|
actual );
|
2020-11-19 23:51:48 +00:00
|
|
|
|
2022-06-15 23:42:34 +00:00
|
|
|
drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
|
2021-09-05 15:06:12 +00:00
|
|
|
drce->SetItems( aItem, aZone );
|
2021-08-09 21:25:16 +00:00
|
|
|
drce->SetViolatingRule( constraint.GetParentRule() );
|
2020-11-19 23:51:48 +00:00
|
|
|
|
2022-01-02 02:06:40 +00:00
|
|
|
reportViolation( drce, pos, aLayer );
|
2020-11-19 23:51:48 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-17 22:36:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-13 23:28:08 +00:00
|
|
|
|
|
|
|
|
2023-06-30 10:56:36 +00:00
|
|
|
/*
|
|
|
|
* We have to special-case knockout text as it's most often knocked-out of a zone, so it's
|
|
|
|
* presumed to collide with one. However, if it collides with more than one, and they have
|
|
|
|
* different nets, then we have a short.
|
|
|
|
*/
|
|
|
|
void DRC_TEST_PROVIDER_COPPER_CLEARANCE::testKnockoutTextAgainstZone( BOARD_ITEM* aText,
|
|
|
|
NETINFO_ITEM** aInheritedNet,
|
|
|
|
ZONE* aZone )
|
|
|
|
{
|
|
|
|
bool testClearance = !m_drcEngine->IsErrorLimitExceeded( DRCE_CLEARANCE );
|
|
|
|
bool testShorts = !m_drcEngine->IsErrorLimitExceeded( DRCE_SHORTING_ITEMS );
|
|
|
|
|
|
|
|
if( !testClearance && !testShorts )
|
|
|
|
return;
|
|
|
|
|
|
|
|
PCB_LAYER_ID layer = aText->GetLayer();
|
|
|
|
|
|
|
|
if( !aZone->GetLayerSet().test( layer ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
BOX2I itemBBox = aText->GetBoundingBox();
|
|
|
|
BOX2I worstCaseBBox = itemBBox;
|
|
|
|
|
|
|
|
worstCaseBBox.Inflate( m_board->m_DRCMaxClearance );
|
|
|
|
|
|
|
|
if( !worstCaseBBox.Intersects( aZone->GetBoundingBox() ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
DRC_RTREE* zoneTree = m_board->m_CopperZoneRTreeCache[ aZone ].get();
|
|
|
|
|
|
|
|
if( !zoneTree )
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::shared_ptr<SHAPE> itemShape = aText->GetEffectiveShape( layer, FLASHING::DEFAULT );
|
|
|
|
|
|
|
|
if( *aInheritedNet == nullptr )
|
|
|
|
{
|
|
|
|
if( zoneTree->QueryColliding( itemBBox, itemShape.get(), layer ) )
|
|
|
|
*aInheritedNet = aZone->GetNet();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( *aInheritedNet == aZone->GetNet() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
DRC_CONSTRAINT constraint = m_drcEngine->EvalRules( CLEARANCE_CONSTRAINT, aText, aZone, layer );
|
|
|
|
int clearance = constraint.GetValue().Min();
|
|
|
|
int actual;
|
|
|
|
VECTOR2I pos;
|
|
|
|
|
|
|
|
if( constraint.GetSeverity() != RPT_SEVERITY_IGNORE && clearance >= 0 )
|
|
|
|
{
|
|
|
|
if( zoneTree->QueryColliding( itemBBox, itemShape.get(), layer,
|
|
|
|
std::max( 0, clearance - m_drcEpsilon ), &actual, &pos ) )
|
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> drce;
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
if( testShorts && actual == 0 && *aInheritedNet )
|
|
|
|
{
|
|
|
|
drce = DRC_ITEM::Create( DRCE_SHORTING_ITEMS );
|
|
|
|
msg.Printf( _( "(nets %s and %s)" ),
|
|
|
|
( *aInheritedNet )->GetNetname(),
|
|
|
|
aZone->GetNetname() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
drce = DRC_ITEM::Create( DRCE_CLEARANCE );
|
|
|
|
msg = formatMsg( _( "(%s clearance %s; actual %s)" ),
|
|
|
|
constraint.GetName(),
|
|
|
|
clearance,
|
|
|
|
actual );
|
|
|
|
}
|
|
|
|
|
|
|
|
drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
|
|
|
|
drce->SetItems( aText, aZone );
|
|
|
|
drce->SetViolatingRule( constraint.GetParentRule() );
|
|
|
|
|
|
|
|
reportViolation( drce, pos, layer );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
void DRC_TEST_PROVIDER_COPPER_CLEARANCE::testTrackClearances()
|
2020-06-13 23:28:08 +00:00
|
|
|
{
|
2020-10-27 17:09:27 +00:00
|
|
|
// This is the number of tests between 2 calls to the progress bar
|
2022-08-03 09:10:23 +00:00
|
|
|
const int progressDelta = 100;
|
2020-10-27 17:09:27 +00:00
|
|
|
int ii = 0;
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2022-03-11 21:16:52 +00:00
|
|
|
reportAux( wxT( "Testing %d tracks & vias..." ), m_board->Tracks().size() );
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2022-12-12 18:53:44 +00:00
|
|
|
std::map<BOARD_ITEM*, int> freePadsUsageMap;
|
|
|
|
std::unordered_map<PTR_PTR_CACHE_KEY, layers_checked> checkedPairs;
|
2020-11-17 16:58:14 +00:00
|
|
|
|
2023-02-03 13:20:45 +00:00
|
|
|
LSET boardCopperLayers = LSET::AllCuMask( m_board->GetCopperLayerCount() );
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_TRACK* track : m_board->Tracks() )
|
2020-06-13 23:28:08 +00:00
|
|
|
{
|
2022-08-03 09:10:23 +00:00
|
|
|
if( !reportProgress( ii++, m_board->Tracks().size(), progressDelta ) )
|
2020-10-27 17:09:27 +00:00
|
|
|
break;
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2023-02-03 13:20:45 +00:00
|
|
|
for( PCB_LAYER_ID layer : LSET( track->GetLayerSet() & boardCopperLayers ).Seq() )
|
2020-10-27 17:09:27 +00:00
|
|
|
{
|
|
|
|
std::shared_ptr<SHAPE> trackShape = track->GetEffectiveShape( layer );
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2022-06-17 21:50:59 +00:00
|
|
|
m_board->m_CopperItemRTreeCache->QueryColliding( track, layer, layer,
|
2020-11-02 16:20:00 +00:00
|
|
|
// Filter:
|
2020-10-27 17:09:27 +00:00
|
|
|
[&]( BOARD_ITEM* other ) -> bool
|
|
|
|
{
|
2020-12-26 16:05:07 +00:00
|
|
|
auto otherCItem = dynamic_cast<BOARD_CONNECTED_ITEM*>( other );
|
|
|
|
|
|
|
|
if( otherCItem && otherCItem->GetNetCode() == track->GetNetCode() )
|
|
|
|
return false;
|
|
|
|
|
2020-11-17 16:58:14 +00:00
|
|
|
BOARD_ITEM* a = track;
|
|
|
|
BOARD_ITEM* b = other;
|
|
|
|
|
|
|
|
// store canonical order so we don't collide in both directions
|
|
|
|
// (a:b and b:a)
|
|
|
|
if( static_cast<void*>( a ) > static_cast<void*>( b ) )
|
|
|
|
std::swap( a, b );
|
|
|
|
|
2022-08-25 16:00:18 +00:00
|
|
|
auto it = checkedPairs.find( { a, b } );
|
|
|
|
|
2022-12-12 18:53:44 +00:00
|
|
|
if( it != checkedPairs.end() && ( it->second.layers.test( layer )
|
|
|
|
|| ( it->second.has_error && !m_drcEngine->GetReportAllTrackErrors() ) ) )
|
2020-11-17 16:58:14 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-12 18:53:44 +00:00
|
|
|
checkedPairs[ { a, b } ].layers.set( layer );
|
2020-11-17 16:58:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
2020-10-27 17:09:27 +00:00
|
|
|
},
|
2020-11-02 16:20:00 +00:00
|
|
|
// Visitor:
|
2020-10-28 13:52:30 +00:00
|
|
|
[&]( BOARD_ITEM* other ) -> bool
|
2020-10-27 17:09:27 +00:00
|
|
|
{
|
2022-09-05 17:22:11 +00:00
|
|
|
if( other->Type() == PCB_PAD_T && static_cast<PAD*>( other )->IsFreePad() )
|
|
|
|
{
|
|
|
|
if( other->GetEffectiveShape( layer )->Collide( trackShape.get() ) )
|
|
|
|
{
|
|
|
|
auto it = freePadsUsageMap.find( other );
|
|
|
|
|
|
|
|
if( it == freePadsUsageMap.end() )
|
|
|
|
{
|
|
|
|
freePadsUsageMap[ other ] = track->GetNetCode();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if( it->second == track->GetNetCode() )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-12 18:53:44 +00:00
|
|
|
BOARD_ITEM* a = track;
|
|
|
|
BOARD_ITEM* b = other;
|
|
|
|
|
|
|
|
// store canonical order so we don't collide in both directions
|
|
|
|
// (a:b and b:a)
|
|
|
|
if( static_cast<void*>( a ) > static_cast<void*>( b ) )
|
|
|
|
std::swap( a, b );
|
|
|
|
|
|
|
|
auto it = checkedPairs.find( { a, b } );
|
|
|
|
|
|
|
|
// If we get an error, mark the pair as having a clearance error already
|
|
|
|
// Only continue if we are reporting all track errors
|
2023-07-30 19:39:07 +00:00
|
|
|
if( !testSingleLayerItemAgainstItem( track, trackShape.get(), layer,
|
|
|
|
other ) )
|
2022-12-12 18:53:44 +00:00
|
|
|
{
|
|
|
|
if( it != checkedPairs.end() )
|
|
|
|
it->second.has_error = true;
|
|
|
|
|
|
|
|
return m_drcEngine->GetReportAllTrackErrors() && !m_drcEngine->IsCancelled();
|
|
|
|
}
|
|
|
|
|
|
|
|
return !m_drcEngine->IsCancelled();
|
2020-10-27 17:09:27 +00:00
|
|
|
},
|
2022-06-17 21:50:59 +00:00
|
|
|
m_board->m_DRCMaxClearance );
|
2020-10-27 17:09:27 +00:00
|
|
|
|
2022-06-17 21:50:59 +00:00
|
|
|
for( ZONE* zone : m_board->m_DRCCopperZones )
|
2022-03-11 20:13:47 +00:00
|
|
|
{
|
2021-09-05 15:06:12 +00:00
|
|
|
testItemAgainstZone( track, zone, layer );
|
2022-03-11 20:13:47 +00:00
|
|
|
|
|
|
|
if( m_drcEngine->IsCancelled() )
|
|
|
|
break;
|
|
|
|
}
|
2020-10-27 17:09:27 +00:00
|
|
|
}
|
2020-06-13 23:28:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-12 19:28:22 +00:00
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
bool DRC_TEST_PROVIDER_COPPER_CLEARANCE::testPadAgainstItem( PAD* pad, SHAPE* padShape,
|
2021-12-26 13:47:00 +00:00
|
|
|
PCB_LAYER_ID aLayer,
|
2020-10-28 12:24:10 +00:00
|
|
|
BOARD_ITEM* other )
|
2020-10-27 17:09:27 +00:00
|
|
|
{
|
|
|
|
bool testClearance = !m_drcEngine->IsErrorLimitExceeded( DRCE_CLEARANCE );
|
|
|
|
bool testShorting = !m_drcEngine->IsErrorLimitExceeded( DRCE_SHORTING_ITEMS );
|
|
|
|
bool testHoles = !m_drcEngine->IsErrorLimitExceeded( DRCE_HOLE_CLEARANCE );
|
2020-09-12 19:28:22 +00:00
|
|
|
|
2022-09-25 16:23:14 +00:00
|
|
|
// Disable some tests for net-tie objects in a footprint
|
2021-04-09 12:48:59 +00:00
|
|
|
if( other->GetParent() == pad->GetParent() )
|
2020-12-05 19:24:18 +00:00
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
FOOTPRINT* fp = pad->GetParentFootprint();
|
2022-09-25 16:23:14 +00:00
|
|
|
std::map<wxString, int> padToNetTieGroupMap = fp->MapPadNumbersToNetTieGroups();
|
|
|
|
int padGroupIdx = padToNetTieGroupMap[ pad->GetNumber() ];
|
2021-04-09 12:48:59 +00:00
|
|
|
|
2022-09-25 16:23:14 +00:00
|
|
|
if( other->Type() == PCB_PAD_T )
|
|
|
|
{
|
|
|
|
PAD* otherPad = static_cast<PAD*>( other );
|
|
|
|
|
|
|
|
if( padGroupIdx >= 0 && padGroupIdx == padToNetTieGroupMap[ otherPad->GetNumber() ] )
|
2023-04-02 20:07:14 +00:00
|
|
|
testClearance = testShorting = false;
|
2021-04-09 12:48:59 +00:00
|
|
|
|
2022-09-25 16:23:14 +00:00
|
|
|
if( pad->SameLogicalPadAs( otherPad ) )
|
|
|
|
testHoles = false;
|
|
|
|
}
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
if( other->Type() == PCB_SHAPE_T && padGroupIdx >= 0 )
|
2023-04-02 20:07:14 +00:00
|
|
|
testClearance = testShorting = false;
|
2020-12-05 19:24:18 +00:00
|
|
|
}
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2021-08-09 21:25:16 +00:00
|
|
|
PAD* otherPad = nullptr;
|
|
|
|
PCB_VIA* otherVia = nullptr;
|
|
|
|
|
|
|
|
if( other->Type() == PCB_PAD_T )
|
|
|
|
otherPad = static_cast<PAD*>( other );
|
|
|
|
|
|
|
|
if( other->Type() == PCB_VIA_T )
|
|
|
|
otherVia = static_cast<PCB_VIA*>( other );
|
|
|
|
|
2021-12-26 13:47:00 +00:00
|
|
|
if( !IsCopperLayer( aLayer ) )
|
2023-04-02 20:07:14 +00:00
|
|
|
testClearance = testShorting = false;
|
2021-08-09 21:25:16 +00:00
|
|
|
|
2021-04-26 15:26:18 +00:00
|
|
|
// A NPTH has no cylinder, but it may still have pads on some layers
|
2021-12-26 13:47:00 +00:00
|
|
|
if( pad->GetAttribute() == PAD_ATTRIB::NPTH && !pad->FlashLayer( aLayer ) )
|
2023-04-02 20:07:14 +00:00
|
|
|
testClearance = testShorting = false;
|
2021-01-03 23:26:42 +00:00
|
|
|
|
2021-12-26 13:47:00 +00:00
|
|
|
if( otherPad && otherPad->GetAttribute() == PAD_ATTRIB::NPTH && !otherPad->FlashLayer( aLayer ) )
|
2023-04-02 20:07:14 +00:00
|
|
|
testClearance = testShorting = false;
|
2021-01-03 23:26:42 +00:00
|
|
|
|
2020-11-30 12:08:59 +00:00
|
|
|
// Track clearances are tested in testTrackClearances()
|
2021-06-11 21:07:02 +00:00
|
|
|
if( dynamic_cast<PCB_TRACK*>( other) )
|
2023-04-02 20:07:14 +00:00
|
|
|
testClearance = testShorting = false;
|
2020-11-30 12:08:59 +00:00
|
|
|
|
2021-10-18 17:04:54 +00:00
|
|
|
int padNet = pad->GetNetCode();
|
2023-04-02 20:07:14 +00:00
|
|
|
int otherNet = 0;
|
|
|
|
|
|
|
|
if( BOARD_CONNECTED_ITEM* connectedItem = dynamic_cast<BOARD_CONNECTED_ITEM*>( other ) )
|
|
|
|
otherNet = connectedItem->GetNetCode();
|
2021-10-18 17:04:54 +00:00
|
|
|
|
2023-07-30 19:39:07 +00:00
|
|
|
// Other objects of the same (defined) net get a waiver on clearance and hole tests
|
|
|
|
if( otherNet && otherNet == padNet )
|
2021-08-09 21:25:16 +00:00
|
|
|
{
|
2023-04-02 20:07:14 +00:00
|
|
|
testClearance = testShorting = false;
|
2021-08-09 21:25:16 +00:00
|
|
|
testHoles = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !( pad->GetDrillSize().x > 0 )
|
|
|
|
&& !( otherPad && otherPad->GetDrillSize().x > 0 )
|
|
|
|
&& !( otherVia && otherVia->GetDrill() > 0 ) )
|
|
|
|
{
|
|
|
|
testHoles = false;
|
|
|
|
}
|
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
if( !testClearance && !testShorting && !testHoles )
|
|
|
|
return false;
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2022-02-11 00:51:01 +00:00
|
|
|
std::shared_ptr<SHAPE> otherShape = other->GetEffectiveShape( aLayer );
|
2020-10-27 17:09:27 +00:00
|
|
|
DRC_CONSTRAINT constraint;
|
2023-04-11 08:53:35 +00:00
|
|
|
int clearance = 0;
|
|
|
|
int actual = 0;
|
2020-10-27 17:09:27 +00:00
|
|
|
VECTOR2I pos;
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2021-08-09 21:25:16 +00:00
|
|
|
if( otherPad && pad->SameLogicalPadAs( otherPad ) )
|
2020-10-27 17:09:27 +00:00
|
|
|
{
|
2020-09-11 16:24:27 +00:00
|
|
|
// If pads are equivalent (ie: from the same footprint with the same pad number)...
|
2021-08-09 21:25:16 +00:00
|
|
|
// ... and have nets...
|
|
|
|
// then they must be the same net
|
|
|
|
if( pad->GetNetCode() && otherPad->GetNetCode()
|
|
|
|
&& pad->GetNetCode() != otherPad->GetNetCode()
|
|
|
|
&& testShorting )
|
2020-06-13 23:28:08 +00:00
|
|
|
{
|
2021-08-09 21:25:16 +00:00
|
|
|
std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( DRCE_SHORTING_ITEMS );
|
2022-06-15 23:42:34 +00:00
|
|
|
wxString msg;
|
2020-09-11 16:24:27 +00:00
|
|
|
|
2022-06-15 23:42:34 +00:00
|
|
|
msg.Printf( _( "(nets %s and %s)" ),
|
2023-04-02 20:07:14 +00:00
|
|
|
pad->GetNetname(),
|
|
|
|
otherPad->GetNetname() );
|
2020-07-30 20:41:52 +00:00
|
|
|
|
2022-06-15 23:42:34 +00:00
|
|
|
drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
|
2021-08-09 21:25:16 +00:00
|
|
|
drce->SetItems( pad, otherPad );
|
2020-09-11 16:24:27 +00:00
|
|
|
|
2021-12-26 13:47:00 +00:00
|
|
|
reportViolation( drce, otherPad->GetPosition(), aLayer );
|
2020-06-13 23:28:08 +00:00
|
|
|
}
|
|
|
|
|
2022-03-11 20:13:47 +00:00
|
|
|
return !m_drcEngine->IsCancelled();
|
2021-08-09 21:25:16 +00:00
|
|
|
}
|
2020-12-25 22:13:47 +00:00
|
|
|
|
2023-04-02 20:07:14 +00:00
|
|
|
if( testClearance || testShorting )
|
2021-08-09 21:25:16 +00:00
|
|
|
{
|
2021-12-26 13:47:00 +00:00
|
|
|
constraint = m_drcEngine->EvalRules( CLEARANCE_CONSTRAINT, pad, other, aLayer );
|
2021-08-09 21:25:16 +00:00
|
|
|
clearance = constraint.GetValue().Min();
|
2020-10-27 17:09:27 +00:00
|
|
|
|
2021-09-05 15:06:12 +00:00
|
|
|
if( constraint.GetSeverity() != RPT_SEVERITY_IGNORE && clearance > 0 )
|
2021-08-09 21:25:16 +00:00
|
|
|
{
|
2021-09-05 15:06:12 +00:00
|
|
|
if( padShape->Collide( otherShape.get(), std::max( 0, clearance - m_drcEpsilon ),
|
|
|
|
&actual, &pos ) )
|
|
|
|
{
|
2022-11-26 15:02:42 +00:00
|
|
|
if( m_drcEngine->IsNetTieExclusion( pad->GetNetCode(), aLayer, pos, other ) )
|
|
|
|
{
|
|
|
|
// Pads connected to pads of a net-tie footprint are allowed to collide
|
|
|
|
// with the net-tie footprint's graphics.
|
|
|
|
}
|
2023-04-02 20:07:14 +00:00
|
|
|
else if( actual == 0 && otherNet && testShorting )
|
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( DRCE_SHORTING_ITEMS );
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
msg.Printf( _( "(nets %s and %s)" ),
|
|
|
|
pad->GetNetname(),
|
|
|
|
static_cast<BOARD_CONNECTED_ITEM*>( other )->GetNetname() );
|
|
|
|
|
|
|
|
drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
|
|
|
|
drce->SetItems( pad, other );
|
|
|
|
|
|
|
|
reportViolation( drce, pos, aLayer );
|
|
|
|
testHoles = false; // No need for multiple violations
|
|
|
|
}
|
|
|
|
else if( testClearance )
|
2022-11-26 15:02:42 +00:00
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( DRCE_CLEARANCE );
|
|
|
|
wxString msg = formatMsg( _( "(%s clearance %s; actual %s)" ),
|
|
|
|
constraint.GetName(),
|
|
|
|
clearance,
|
|
|
|
actual );
|
2020-12-25 22:13:47 +00:00
|
|
|
|
2022-11-26 15:02:42 +00:00
|
|
|
drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
|
|
|
|
drce->SetItems( pad, other );
|
|
|
|
drce->SetViolatingRule( constraint.GetParentRule() );
|
2021-08-09 21:25:16 +00:00
|
|
|
|
2022-11-26 15:02:42 +00:00
|
|
|
reportViolation( drce, pos, aLayer );
|
|
|
|
testHoles = false; // No need for multiple violations
|
|
|
|
}
|
2021-09-05 15:06:12 +00:00
|
|
|
}
|
2020-12-25 22:13:47 +00:00
|
|
|
}
|
2021-08-09 21:25:16 +00:00
|
|
|
}
|
2020-10-27 17:09:27 +00:00
|
|
|
|
2021-08-09 21:25:16 +00:00
|
|
|
if( testHoles )
|
|
|
|
{
|
2021-12-26 13:47:00 +00:00
|
|
|
constraint = m_drcEngine->EvalRules( HOLE_CLEARANCE_CONSTRAINT, pad, other, aLayer );
|
2021-08-09 21:25:16 +00:00
|
|
|
clearance = constraint.GetValue().Min();
|
2021-09-05 15:06:12 +00:00
|
|
|
|
|
|
|
if( constraint.GetSeverity() == RPT_SEVERITY_IGNORE )
|
|
|
|
testHoles = false;
|
2021-08-09 21:25:16 +00:00
|
|
|
}
|
2020-10-27 17:09:27 +00:00
|
|
|
|
2022-07-22 22:05:25 +00:00
|
|
|
if( testHoles && otherPad && pad->FlashLayer( aLayer ) && otherPad->HasHole() )
|
2021-08-09 21:25:16 +00:00
|
|
|
{
|
2022-07-22 22:05:25 +00:00
|
|
|
if( clearance > 0 && padShape->Collide( otherPad->GetEffectiveHoleShape().get(),
|
2021-08-09 21:25:16 +00:00
|
|
|
std::max( 0, clearance - m_drcEpsilon ),
|
|
|
|
&actual, &pos ) )
|
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( DRCE_HOLE_CLEARANCE );
|
2022-10-06 20:52:17 +00:00
|
|
|
wxString msg = formatMsg( _( "(%s clearance %s; actual %s)" ),
|
|
|
|
constraint.GetName(),
|
|
|
|
clearance,
|
|
|
|
actual );
|
2020-12-25 22:13:47 +00:00
|
|
|
|
2022-06-15 23:42:34 +00:00
|
|
|
drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
|
2021-08-09 21:25:16 +00:00
|
|
|
drce->SetItems( pad, other );
|
|
|
|
drce->SetViolatingRule( constraint.GetParentRule() );
|
2020-12-25 22:13:47 +00:00
|
|
|
|
2022-01-02 02:06:40 +00:00
|
|
|
reportViolation( drce, pos, aLayer );
|
2021-08-09 21:25:16 +00:00
|
|
|
testHoles = false; // No need for multiple violations
|
2020-06-13 23:28:08 +00:00
|
|
|
}
|
2021-08-09 21:25:16 +00:00
|
|
|
}
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2022-07-22 22:05:25 +00:00
|
|
|
if( testHoles && otherPad && otherPad->FlashLayer( aLayer ) && pad->HasHole() )
|
2021-08-09 21:25:16 +00:00
|
|
|
{
|
2022-07-22 22:05:25 +00:00
|
|
|
if( clearance > 0 && otherShape->Collide( pad->GetEffectiveHoleShape().get(),
|
2022-05-05 17:00:17 +00:00
|
|
|
std::max( 0, clearance - m_drcEpsilon ),
|
|
|
|
&actual, &pos ) )
|
2021-08-09 21:25:16 +00:00
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( DRCE_HOLE_CLEARANCE );
|
2022-10-06 20:52:17 +00:00
|
|
|
wxString msg = formatMsg( _( "(%s clearance %s; actual %s)" ),
|
|
|
|
constraint.GetName(),
|
|
|
|
clearance,
|
|
|
|
actual );
|
2021-08-09 21:25:16 +00:00
|
|
|
|
2022-06-15 23:42:34 +00:00
|
|
|
drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
|
2021-08-09 21:25:16 +00:00
|
|
|
drce->SetItems( pad, other );
|
|
|
|
drce->SetViolatingRule( constraint.GetParentRule() );
|
|
|
|
|
2022-01-02 02:06:40 +00:00
|
|
|
reportViolation( drce, pos, aLayer );
|
2021-08-09 21:25:16 +00:00
|
|
|
testHoles = false; // No need for multiple violations
|
|
|
|
}
|
2020-10-27 17:09:27 +00:00
|
|
|
}
|
2020-09-17 16:32:42 +00:00
|
|
|
|
2021-12-26 13:47:00 +00:00
|
|
|
if( testHoles && otherVia && otherVia->IsOnLayer( aLayer ) )
|
2020-10-27 17:09:27 +00:00
|
|
|
{
|
2022-07-22 22:05:25 +00:00
|
|
|
if( clearance > 0 && padShape->Collide( otherVia->GetEffectiveHoleShape().get(),
|
2021-09-08 18:51:10 +00:00
|
|
|
std::max( 0, clearance - m_drcEpsilon ),
|
|
|
|
&actual, &pos ) )
|
2020-09-11 16:24:27 +00:00
|
|
|
{
|
2021-08-09 21:25:16 +00:00
|
|
|
std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( DRCE_HOLE_CLEARANCE );
|
2022-10-06 20:52:17 +00:00
|
|
|
wxString msg = formatMsg( _( "(%s clearance %s; actual %s)" ),
|
|
|
|
constraint.GetName(),
|
|
|
|
clearance,
|
|
|
|
actual );
|
2020-09-07 12:31:19 +00:00
|
|
|
|
2022-06-15 23:42:34 +00:00
|
|
|
drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
|
2021-08-09 21:25:16 +00:00
|
|
|
drce->SetItems( pad, otherVia );
|
2020-10-27 17:09:27 +00:00
|
|
|
drce->SetViolatingRule( constraint.GetParentRule() );
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2022-01-02 02:06:40 +00:00
|
|
|
reportViolation( drce, pos, aLayer );
|
2020-10-27 17:09:27 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-29 17:18:19 +00:00
|
|
|
|
2022-03-11 20:13:47 +00:00
|
|
|
return !m_drcEngine->IsCancelled();
|
2020-10-27 17:09:27 +00:00
|
|
|
}
|
2020-09-29 17:18:19 +00:00
|
|
|
|
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
void DRC_TEST_PROVIDER_COPPER_CLEARANCE::testPadClearances( )
|
|
|
|
{
|
2022-08-03 09:10:23 +00:00
|
|
|
const int progressDelta = 100;
|
|
|
|
size_t count = 0;
|
|
|
|
int ii = 0;
|
2020-07-22 23:05:37 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2020-11-12 23:50:33 +00:00
|
|
|
count += footprint->Pads().size();
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2022-03-11 21:16:52 +00:00
|
|
|
reportAux( wxT( "Testing %d pads..." ), count );
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2022-08-03 09:10:23 +00:00
|
|
|
std::unordered_map<PTR_PTR_CACHE_KEY, int> checkedPairs;
|
2020-10-27 17:09:27 +00:00
|
|
|
|
2023-02-03 13:20:45 +00:00
|
|
|
LSET boardCopperLayers = LSET::AllCuMask( m_board->GetCopperLayerCount() );
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2020-10-27 17:09:27 +00:00
|
|
|
{
|
2020-11-12 23:50:33 +00:00
|
|
|
for( PAD* pad : footprint->Pads() )
|
2020-10-27 17:09:27 +00:00
|
|
|
{
|
2023-02-03 13:20:45 +00:00
|
|
|
for( PCB_LAYER_ID layer : LSET( pad->GetLayerSet() & boardCopperLayers ).Seq() )
|
2020-10-27 17:09:27 +00:00
|
|
|
{
|
2022-02-11 00:51:01 +00:00
|
|
|
std::shared_ptr<SHAPE> padShape = pad->GetEffectiveShape( layer );
|
2020-10-27 17:09:27 +00:00
|
|
|
|
2022-06-17 21:50:59 +00:00
|
|
|
m_board->m_CopperItemRTreeCache->QueryColliding( pad, layer, layer,
|
2020-11-02 16:20:00 +00:00
|
|
|
// Filter:
|
2020-10-27 17:09:27 +00:00
|
|
|
[&]( BOARD_ITEM* other ) -> bool
|
|
|
|
{
|
2020-11-17 16:58:14 +00:00
|
|
|
BOARD_ITEM* a = pad;
|
|
|
|
BOARD_ITEM* b = other;
|
|
|
|
|
|
|
|
// store canonical order so we don't collide in both directions
|
|
|
|
// (a:b and b:a)
|
|
|
|
if( static_cast<void*>( a ) > static_cast<void*>( b ) )
|
|
|
|
std::swap( a, b );
|
|
|
|
|
2022-08-25 14:03:44 +00:00
|
|
|
if( checkedPairs.find( { a, b } ) != checkedPairs.end() )
|
2020-11-17 16:58:14 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
checkedPairs[ { a, b } ] = 1;
|
|
|
|
return true;
|
|
|
|
}
|
2020-10-27 17:09:27 +00:00
|
|
|
},
|
2020-11-02 16:20:00 +00:00
|
|
|
// Visitor
|
2020-10-28 13:52:30 +00:00
|
|
|
[&]( BOARD_ITEM* other ) -> bool
|
2020-10-27 17:09:27 +00:00
|
|
|
{
|
2020-10-28 12:24:10 +00:00
|
|
|
return testPadAgainstItem( pad, padShape.get(), layer, other );
|
2020-10-27 17:09:27 +00:00
|
|
|
},
|
2022-06-17 21:50:59 +00:00
|
|
|
m_board->m_DRCMaxClearance );
|
2020-10-28 17:55:57 +00:00
|
|
|
|
2022-06-17 21:50:59 +00:00
|
|
|
for( ZONE* zone : m_board->m_DRCCopperZones )
|
2022-03-11 20:13:47 +00:00
|
|
|
{
|
2021-09-05 15:06:12 +00:00
|
|
|
testItemAgainstZone( pad, zone, layer );
|
2022-03-11 20:13:47 +00:00
|
|
|
|
|
|
|
if( m_drcEngine->IsCancelled() )
|
|
|
|
return;
|
|
|
|
}
|
2020-09-11 16:24:27 +00:00
|
|
|
}
|
2022-03-11 20:13:47 +00:00
|
|
|
|
2023-06-30 10:56:36 +00:00
|
|
|
if( !reportProgress( ii++, (int) count, progressDelta ) )
|
2022-03-11 20:13:47 +00:00
|
|
|
return;
|
2020-06-13 23:28:08 +00:00
|
|
|
}
|
2022-03-11 20:13:47 +00:00
|
|
|
|
|
|
|
if( m_drcEngine->IsCancelled() )
|
|
|
|
return;
|
2020-06-13 23:28:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-30 10:56:36 +00:00
|
|
|
void DRC_TEST_PROVIDER_COPPER_CLEARANCE::testGraphicClearances( )
|
|
|
|
{
|
|
|
|
const int progressDelta = 100;
|
|
|
|
size_t count = m_board->Drawings().size();
|
|
|
|
int ii = 0;
|
|
|
|
|
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
|
|
|
count += footprint->GraphicalItems().size();
|
|
|
|
|
|
|
|
reportAux( wxT( "Testing %d graphics..." ), count );
|
|
|
|
|
|
|
|
auto isKnockoutText =
|
|
|
|
[]( BOARD_ITEM* item )
|
|
|
|
{
|
|
|
|
return item->Type() == PCB_TEXT_T && static_cast<PCB_TEXT*>( item )->IsKnockout();
|
|
|
|
};
|
|
|
|
|
|
|
|
auto testGraphicAgainstZone =
|
|
|
|
[&]( BOARD_ITEM* item )
|
|
|
|
{
|
|
|
|
if( !IsCopperLayer( item->GetLayer() ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Knockout text is most often knocked-out of a zone, so it's presumed to
|
|
|
|
// collide with one. However, if it collides with more than one, and they
|
|
|
|
// have different nets, then we have a short.
|
|
|
|
NETINFO_ITEM* inheritedNet = nullptr;
|
|
|
|
|
|
|
|
for( ZONE* zone : m_board->m_DRCCopperZones )
|
|
|
|
{
|
|
|
|
if( isKnockoutText( item ) )
|
|
|
|
testKnockoutTextAgainstZone( item, &inheritedNet, zone );
|
|
|
|
else
|
|
|
|
testItemAgainstZone( item, zone, item->GetLayer() );
|
|
|
|
|
|
|
|
if( m_drcEngine->IsCancelled() )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-07-30 19:39:07 +00:00
|
|
|
std::unordered_map<PTR_PTR_CACHE_KEY, layers_checked> checkedPairs;
|
|
|
|
|
|
|
|
auto testCopperGraphic =
|
|
|
|
[&]( PCB_SHAPE* aShape )
|
|
|
|
{
|
|
|
|
PCB_LAYER_ID layer = aShape->GetLayer();
|
|
|
|
|
|
|
|
m_board->m_CopperItemRTreeCache->QueryColliding( aShape, layer, layer,
|
|
|
|
// Filter:
|
|
|
|
[&]( BOARD_ITEM* other ) -> bool
|
|
|
|
{
|
|
|
|
auto otherCItem = dynamic_cast<BOARD_CONNECTED_ITEM*>( other );
|
|
|
|
|
|
|
|
if( otherCItem && otherCItem->GetNetCode() == aShape->GetNetCode() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Pads and tracks handled separately
|
|
|
|
if( other->Type() == PCB_PAD_T || other->Type() == PCB_ARC_T ||
|
|
|
|
other->Type() == PCB_TRACE_T || other->Type() == PCB_VIA_T )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOARD_ITEM* a = aShape;
|
|
|
|
BOARD_ITEM* b = other;
|
|
|
|
|
|
|
|
// store canonical order so we don't collide in both directions
|
|
|
|
// (a:b and b:a)
|
|
|
|
if( static_cast<void*>( a ) > static_cast<void*>( b ) )
|
|
|
|
std::swap( a, b );
|
|
|
|
|
|
|
|
auto it = checkedPairs.find( { a, b } );
|
|
|
|
|
|
|
|
if( it != checkedPairs.end() && it->second.layers.test( layer ) )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
checkedPairs[ { a, b } ].layers.set( layer );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// Visitor:
|
|
|
|
[&]( BOARD_ITEM* other ) -> bool
|
|
|
|
{
|
|
|
|
BOARD_ITEM* a = aShape;
|
|
|
|
BOARD_ITEM* b = other;
|
|
|
|
|
|
|
|
// store canonical order so we don't collide in both directions
|
|
|
|
// (a:b and b:a)
|
|
|
|
if( static_cast<void*>( a ) > static_cast<void*>( b ) )
|
|
|
|
std::swap( a, b );
|
|
|
|
|
|
|
|
auto it = checkedPairs.find( { a, b } );
|
|
|
|
|
|
|
|
if( !testSingleLayerItemAgainstItem( aShape,
|
|
|
|
aShape->GetEffectiveShape().get(),
|
|
|
|
layer, other ) )
|
|
|
|
{
|
|
|
|
if( it != checkedPairs.end() )
|
|
|
|
it->second.has_error = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !m_drcEngine->IsCancelled();
|
|
|
|
},
|
|
|
|
m_board->m_DRCMaxClearance );
|
|
|
|
};
|
|
|
|
|
2023-06-30 10:56:36 +00:00
|
|
|
for( BOARD_ITEM* item : m_board->Drawings() )
|
|
|
|
{
|
|
|
|
testGraphicAgainstZone( item );
|
|
|
|
|
2023-07-30 19:39:07 +00:00
|
|
|
if( item->Type() == PCB_SHAPE_T && item->IsOnCopperLayer() )
|
|
|
|
testCopperGraphic( static_cast<PCB_SHAPE*>( item ) );
|
|
|
|
|
2023-06-30 10:56:36 +00:00
|
|
|
if( !reportProgress( ii++, (int) count, progressDelta ) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
|
|
|
{
|
|
|
|
for( BOARD_ITEM* item : footprint->GraphicalItems() )
|
|
|
|
{
|
|
|
|
testGraphicAgainstZone( item );
|
|
|
|
|
|
|
|
if( !reportProgress( ii++, (int) count, progressDelta ) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-09 21:25:16 +00:00
|
|
|
void DRC_TEST_PROVIDER_COPPER_CLEARANCE::testZonesToZones()
|
2020-06-18 16:55:22 +00:00
|
|
|
{
|
2022-08-03 09:10:23 +00:00
|
|
|
const int progressDelta = 50;
|
2020-09-18 19:57:54 +00:00
|
|
|
|
2022-09-11 17:01:38 +00:00
|
|
|
bool testClearance = !m_drcEngine->IsErrorLimitExceeded( DRCE_CLEARANCE );
|
|
|
|
bool testIntersects = !m_drcEngine->IsErrorLimitExceeded( DRCE_ZONES_INTERSECT );
|
|
|
|
|
2021-09-05 15:06:12 +00:00
|
|
|
DRC_CONSTRAINT constraint;
|
2023-07-07 02:23:28 +00:00
|
|
|
bool cancelled = false;
|
|
|
|
std::vector<std::map<PCB_LAYER_ID, std::vector<SEG>>> poly_segments;
|
|
|
|
|
|
|
|
poly_segments.resize( m_board->m_DRCCopperZones.size() );
|
|
|
|
|
|
|
|
// Contains the index for zoneA, zoneB, the conflict point, the actual clearance, the required clearance, and the layer
|
|
|
|
using report_data = std::tuple<int, int, VECTOR2I, int, int, PCB_LAYER_ID>;
|
|
|
|
const int invalid_zone = -1;
|
|
|
|
|
|
|
|
std::vector<std::future<report_data>> futures;
|
|
|
|
thread_pool& tp = GetKiCadThreadPool();
|
|
|
|
|
|
|
|
auto checkZones = [testClearance, testIntersects, &poly_segments, &cancelled, invalid_zone]
|
|
|
|
( int zoneA, int zoneB,
|
|
|
|
int zone2zoneClearance, PCB_LAYER_ID layer ) -> report_data
|
|
|
|
{
|
|
|
|
// Iterate through all the segments of refSmoothedPoly
|
|
|
|
std::map<VECTOR2I, int> conflictPoints;
|
|
|
|
|
|
|
|
std::vector<SEG>& refSegments = poly_segments[zoneA][layer];
|
|
|
|
std::vector<SEG>& testSegments = poly_segments[zoneB][layer];
|
|
|
|
bool reported = false;
|
|
|
|
auto invalid_result = std::make_tuple( invalid_zone, invalid_zone, VECTOR2I(), 0, 0, F_Cu );
|
|
|
|
|
|
|
|
for( SEG& refSegment : refSegments )
|
|
|
|
{
|
|
|
|
int ax1 = refSegment.A.x;
|
|
|
|
int ay1 = refSegment.A.y;
|
|
|
|
int ax2 = refSegment.B.x;
|
|
|
|
int ay2 = refSegment.B.y;
|
|
|
|
|
|
|
|
// Iterate through all the segments in smoothed_polys[ia2]
|
|
|
|
for( SEG& testSegment : testSegments )
|
|
|
|
{
|
|
|
|
// Build test segment
|
|
|
|
VECTOR2I pt;
|
|
|
|
|
|
|
|
int bx1 = testSegment.A.x;
|
|
|
|
int by1 = testSegment.A.y;
|
|
|
|
int bx2 = testSegment.B.x;
|
|
|
|
int by2 = testSegment.B.y;
|
|
|
|
|
|
|
|
// We have ensured that the A segment starts before the B segment, so if the
|
|
|
|
// A segment ends before the B segment starts, we can skip to the next A
|
|
|
|
if( ax2 < bx1 )
|
|
|
|
break;
|
|
|
|
|
|
|
|
int d = GetClearanceBetweenSegments( bx1, by1, bx2, by2, 0,
|
|
|
|
ax1, ay1, ax2, ay2, 0,
|
|
|
|
zone2zoneClearance, &pt.x, &pt.y );
|
|
|
|
|
|
|
|
if( d < zone2zoneClearance )
|
|
|
|
{
|
|
|
|
if( d == 0 && testIntersects )
|
|
|
|
reported = true;
|
|
|
|
else if( testClearance )
|
|
|
|
reported = true;
|
|
|
|
|
|
|
|
if( reported )
|
|
|
|
return std::make_tuple( zoneA, zoneB, pt, d, zone2zoneClearance, layer );
|
|
|
|
}
|
2020-10-10 22:09:00 +00:00
|
|
|
|
2023-07-07 02:23:28 +00:00
|
|
|
if( cancelled )
|
|
|
|
return invalid_result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return invalid_result;
|
|
|
|
};
|
2020-10-10 22:09:00 +00:00
|
|
|
|
2020-09-22 03:40:05 +00:00
|
|
|
for( int layer_id = F_Cu; layer_id <= B_Cu; ++layer_id )
|
2020-06-18 16:55:22 +00:00
|
|
|
{
|
2020-09-22 03:40:05 +00:00
|
|
|
PCB_LAYER_ID layer = static_cast<PCB_LAYER_ID>( layer_id );
|
2023-07-07 02:23:28 +00:00
|
|
|
int zone2zoneClearance;
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-22 03:40:05 +00:00
|
|
|
// Skip over layers not used on the current board
|
|
|
|
if( !m_board->IsLayerEnabled( layer ) )
|
2020-06-18 16:55:22 +00:00
|
|
|
continue;
|
|
|
|
|
2022-06-17 21:50:59 +00:00
|
|
|
for( size_t ii = 0; ii < m_board->m_DRCCopperZones.size(); ii++ )
|
2020-06-18 16:55:22 +00:00
|
|
|
{
|
2022-06-17 21:50:59 +00:00
|
|
|
if( m_board->m_DRCCopperZones[ii]->IsOnLayer( layer ) )
|
|
|
|
{
|
2023-07-07 02:23:28 +00:00
|
|
|
SHAPE_POLY_SET poly =
|
|
|
|
*m_board->m_DRCCopperZones[ii]->GetFilledPolysList( layer );
|
|
|
|
std::vector<SEG>& poly_segs = poly_segments[ii][layer];
|
|
|
|
|
|
|
|
poly.Fracture( SHAPE_POLY_SET::PM_FAST );
|
|
|
|
poly.BuildBBoxCaches();
|
|
|
|
poly_segs.reserve( poly.FullPointCount() );
|
|
|
|
|
|
|
|
for( auto it = poly.IterateSegmentsWithHoles(); it; it++ )
|
|
|
|
{
|
|
|
|
SEG seg = *it;
|
|
|
|
|
|
|
|
if( seg.A.x > seg.B.x )
|
|
|
|
seg.Reverse();
|
|
|
|
|
|
|
|
poly_segs.push_back( seg );
|
|
|
|
}
|
|
|
|
|
|
|
|
std::sort( poly_segs.begin(), poly_segs.end() );
|
2022-06-17 21:50:59 +00:00
|
|
|
}
|
2020-09-22 03:40:05 +00:00
|
|
|
}
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2023-07-07 02:23:28 +00:00
|
|
|
std::vector<std::pair<int, int>> zonePairs;
|
|
|
|
|
2022-06-17 21:50:59 +00:00
|
|
|
for( size_t ia = 0; ia < m_board->m_DRCCopperZones.size(); ia++ )
|
2020-09-22 03:40:05 +00:00
|
|
|
{
|
2022-06-17 21:50:59 +00:00
|
|
|
if( !reportProgress( layer_id * m_board->m_DRCCopperZones.size() + ia,
|
2022-08-03 09:10:23 +00:00
|
|
|
B_Cu * m_board->m_DRCCopperZones.size(), progressDelta ) )
|
2022-06-17 21:50:59 +00:00
|
|
|
{
|
2022-03-11 20:13:47 +00:00
|
|
|
return; // DRC cancelled
|
2022-06-17 21:50:59 +00:00
|
|
|
}
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2022-06-17 21:50:59 +00:00
|
|
|
ZONE* zoneA = m_board->m_DRCCopperZones[ia];
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2021-09-05 15:06:12 +00:00
|
|
|
if( !zoneA->IsOnLayer( layer ) )
|
2020-06-18 16:55:22 +00:00
|
|
|
continue;
|
|
|
|
|
2022-06-17 21:50:59 +00:00
|
|
|
for( size_t ia2 = ia + 1; ia2 < m_board->m_DRCCopperZones.size(); ia2++ )
|
2020-09-22 03:40:05 +00:00
|
|
|
{
|
2022-06-17 21:50:59 +00:00
|
|
|
ZONE* zoneB = m_board->m_DRCCopperZones[ia2];
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-22 03:40:05 +00:00
|
|
|
// test for same layer
|
2021-09-05 15:06:12 +00:00
|
|
|
if( !zoneB->IsOnLayer( layer ) )
|
2020-09-22 03:40:05 +00:00
|
|
|
continue;
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-22 03:40:05 +00:00
|
|
|
// Test for same net
|
2021-09-05 15:06:12 +00:00
|
|
|
if( zoneA->GetNetCode() == zoneB->GetNetCode() && zoneA->GetNetCode() >= 0 )
|
2020-09-22 03:40:05 +00:00
|
|
|
continue;
|
2020-09-07 12:31:19 +00:00
|
|
|
|
2021-01-23 00:09:18 +00:00
|
|
|
// rule areas may overlap at will
|
2021-09-05 15:06:12 +00:00
|
|
|
if( zoneA->GetIsRuleArea() || zoneB->GetIsRuleArea() )
|
2020-09-22 03:40:05 +00:00
|
|
|
continue;
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2021-09-05 15:06:12 +00:00
|
|
|
// Examine a candidate zone: compare zoneB to zoneA
|
2023-07-07 02:23:28 +00:00
|
|
|
SHAPE_POLY_SET* polyA = m_board->m_DRCCopperZones[ia]->GetFill( layer );
|
|
|
|
SHAPE_POLY_SET* polyB = m_board->m_DRCCopperZones[ia2]->GetFill( layer );
|
|
|
|
|
|
|
|
if( !polyA->BBoxFromCaches().Intersects( polyB->BBoxFromCaches() ) )
|
|
|
|
continue;
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-22 03:40:05 +00:00
|
|
|
// Get clearance used in zone to zone test.
|
2021-09-05 15:06:12 +00:00
|
|
|
constraint = m_drcEngine->EvalRules( CLEARANCE_CONSTRAINT, zoneA, zoneB, layer );
|
|
|
|
zone2zoneClearance = constraint.GetValue().Min();
|
|
|
|
|
2023-07-07 02:23:28 +00:00
|
|
|
if( constraint.GetSeverity() == RPT_SEVERITY_IGNORE || zone2zoneClearance <= 0 )
|
2021-09-05 15:06:12 +00:00
|
|
|
continue;
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2023-07-07 02:23:28 +00:00
|
|
|
futures.push_back( tp.submit( checkZones, ia, ia2, zone2zoneClearance, layer ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-22 03:40:05 +00:00
|
|
|
|
2023-07-07 02:23:28 +00:00
|
|
|
for( auto& task : futures )
|
|
|
|
{
|
|
|
|
if( !task.valid() )
|
|
|
|
continue;
|
2022-09-11 17:01:38 +00:00
|
|
|
|
2023-07-07 02:23:28 +00:00
|
|
|
std::future_status result;
|
2020-09-22 03:40:05 +00:00
|
|
|
|
2023-07-07 02:23:28 +00:00
|
|
|
while( true )
|
|
|
|
{
|
|
|
|
result = task.wait_for( std::chrono::milliseconds( 200 ) );
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2023-07-07 02:23:28 +00:00
|
|
|
if( m_drcEngine->IsCancelled() )
|
|
|
|
{
|
|
|
|
cancelled = true;
|
|
|
|
break;
|
|
|
|
}
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2023-07-07 02:23:28 +00:00
|
|
|
if( result == std::future_status::ready )
|
|
|
|
{
|
|
|
|
report_data data = task.get();
|
|
|
|
int zoneA_id = std::get<0>( data );
|
|
|
|
int zoneB_id = std::get<1>( data );
|
|
|
|
VECTOR2I pt = std::get<2>( data );
|
|
|
|
int actual = std::get<3>( data );
|
|
|
|
int required = std::get<4>( data );
|
|
|
|
PCB_LAYER_ID layer = std::get<5>( data );
|
|
|
|
|
|
|
|
if( zoneA_id != invalid_zone )
|
2020-06-18 16:55:22 +00:00
|
|
|
{
|
2023-07-07 02:23:28 +00:00
|
|
|
ZONE* zoneA = m_board->m_DRCCopperZones[zoneA_id];
|
|
|
|
ZONE* zoneB = m_board->m_DRCCopperZones[zoneB_id];
|
2020-09-22 03:40:05 +00:00
|
|
|
|
2023-07-07 02:23:28 +00:00
|
|
|
constraint = m_drcEngine->EvalRules( CLEARANCE_CONSTRAINT, zoneA, zoneB, layer );
|
2020-10-27 17:09:27 +00:00
|
|
|
std::shared_ptr<DRC_ITEM> drce;
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2022-09-11 17:01:38 +00:00
|
|
|
if( actual <= 0 && testIntersects )
|
2020-09-22 03:40:05 +00:00
|
|
|
{
|
2020-10-27 17:09:27 +00:00
|
|
|
drce = DRC_ITEM::Create( DRCE_ZONES_INTERSECT );
|
2020-09-22 03:40:05 +00:00
|
|
|
}
|
2022-09-11 17:01:38 +00:00
|
|
|
else if( testClearance )
|
2020-09-22 03:40:05 +00:00
|
|
|
{
|
2020-10-27 17:09:27 +00:00
|
|
|
drce = DRC_ITEM::Create( DRCE_CLEARANCE );
|
2022-10-06 20:52:17 +00:00
|
|
|
wxString msg = formatMsg( _( "(%s clearance %s; actual %s)" ),
|
|
|
|
constraint.GetName(),
|
2023-07-07 02:23:28 +00:00
|
|
|
required,
|
2022-10-06 20:52:17 +00:00
|
|
|
std::max( actual, 0 ) );
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2022-06-15 23:42:34 +00:00
|
|
|
drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
|
2020-09-22 03:40:05 +00:00
|
|
|
}
|
|
|
|
|
2022-09-11 17:01:38 +00:00
|
|
|
if( drce )
|
|
|
|
{
|
|
|
|
drce->SetItems( zoneA, zoneB );
|
|
|
|
drce->SetViolatingRule( constraint.GetParentRule() );
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2023-07-07 02:23:28 +00:00
|
|
|
reportViolation( drce, pt, layer );
|
2022-09-11 17:01:38 +00:00
|
|
|
}
|
2020-09-22 03:40:05 +00:00
|
|
|
}
|
2022-03-11 20:13:47 +00:00
|
|
|
|
2023-07-07 02:23:28 +00:00
|
|
|
break;
|
2020-06-18 16:55:22 +00:00
|
|
|
}
|
2023-07-07 02:23:28 +00:00
|
|
|
|
2020-06-18 16:55:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-17 22:36:54 +00:00
|
|
|
namespace detail
|
2020-06-13 23:28:08 +00:00
|
|
|
{
|
2020-09-11 16:24:27 +00:00
|
|
|
static DRC_REGISTER_TEST_PROVIDER<DRC_TEST_PROVIDER_COPPER_CLEARANCE> dummy;
|
2020-07-15 16:23:56 +00:00
|
|
|
}
|