2021-08-13 19:10:30 +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-13 19:10:30 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2021-08-19 21:28:54 +00:00
|
|
|
#include <macros.h>
|
2021-08-13 19:10:30 +00:00
|
|
|
#include <board_design_settings.h>
|
|
|
|
#include <footprint.h>
|
|
|
|
#include <pad.h>
|
|
|
|
#include <pcb_track.h>
|
2021-08-19 21:28:54 +00:00
|
|
|
#include <pcb_shape.h>
|
2021-08-13 19:10:30 +00:00
|
|
|
#include <zone.h>
|
2021-08-19 21:28:54 +00:00
|
|
|
#include <advanced_config.h>
|
2021-08-13 19:10:30 +00:00
|
|
|
#include <geometry/seg.h>
|
|
|
|
#include <geometry/shape_segment.h>
|
|
|
|
#include <drc/drc_engine.h>
|
|
|
|
#include <drc/drc_rtree.h>
|
|
|
|
#include <drc/drc_item.h>
|
|
|
|
#include <drc/drc_rule.h>
|
|
|
|
#include <drc/drc_test_provider_clearance_base.h>
|
|
|
|
|
|
|
|
/*
|
2022-05-06 13:46:24 +00:00
|
|
|
Physical clearance tests.
|
2021-08-13 19:10:30 +00:00
|
|
|
|
|
|
|
Errors generated:
|
2022-05-06 13:46:24 +00:00
|
|
|
- DRCE_PHYSICAL_CLEARANCE
|
|
|
|
- DRCE_PHYSICAL_HOLE_CLEARANCE
|
2021-08-13 19:10:30 +00:00
|
|
|
*/
|
|
|
|
|
2022-05-06 13:46:24 +00:00
|
|
|
class DRC_TEST_PROVIDER_PHYSICAL_CLEARANCE : public DRC_TEST_PROVIDER_CLEARANCE_BASE
|
2021-08-13 19:10:30 +00:00
|
|
|
{
|
|
|
|
public:
|
2022-05-06 13:46:24 +00:00
|
|
|
DRC_TEST_PROVIDER_PHYSICAL_CLEARANCE () :
|
2021-08-13 19:10:30 +00:00
|
|
|
DRC_TEST_PROVIDER_CLEARANCE_BASE()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-05-06 13:46:24 +00:00
|
|
|
virtual ~DRC_TEST_PROVIDER_PHYSICAL_CLEARANCE()
|
2021-08-13 19:10:30 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool Run() override;
|
|
|
|
|
|
|
|
virtual const wxString GetName() const override
|
|
|
|
{
|
2022-05-06 13:46:24 +00:00
|
|
|
return wxT( "physical_clearance" );
|
2021-08-13 19:10:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual const wxString GetDescription() const override
|
|
|
|
{
|
2022-03-11 21:16:52 +00:00
|
|
|
return wxT( "Tests item clearances irrespective of nets" );
|
2021-08-13 19:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2023-02-15 19:32:51 +00:00
|
|
|
int testItemAgainstItem( BOARD_ITEM* aItem, SHAPE* aItemShape, PCB_LAYER_ID aLayer,
|
2021-08-13 19:10:30 +00:00
|
|
|
BOARD_ITEM* other );
|
|
|
|
|
|
|
|
void testItemAgainstZones( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer );
|
|
|
|
|
2021-12-26 13:47:00 +00:00
|
|
|
void testShapeLineChain( const SHAPE_LINE_CHAIN& aOutline, int aLineWidth, PCB_LAYER_ID aLayer,
|
2021-08-19 21:28:54 +00:00
|
|
|
BOARD_ITEM* aParentItem, DRC_CONSTRAINT& aConstraint );
|
|
|
|
|
|
|
|
void testZoneLayer( ZONE* aZone, PCB_LAYER_ID aLayer, DRC_CONSTRAINT& aConstraint );
|
2021-08-18 21:16:25 +00:00
|
|
|
|
2021-08-13 19:10:30 +00:00
|
|
|
private:
|
2022-03-12 13:34:25 +00:00
|
|
|
DRC_RTREE m_itemTree;
|
2021-08-13 19:10:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-05-06 13:46:24 +00:00
|
|
|
bool DRC_TEST_PROVIDER_PHYSICAL_CLEARANCE::Run()
|
2021-08-13 19:10:30 +00:00
|
|
|
{
|
|
|
|
m_board = m_drcEngine->GetBoard();
|
|
|
|
m_itemTree.clear();
|
|
|
|
|
2022-06-17 21:50:59 +00:00
|
|
|
int errorMax = m_board->GetDesignSettings().m_MaxError;
|
2021-08-13 19:10:30 +00:00
|
|
|
|
2022-06-17 21:50:59 +00:00
|
|
|
if( m_board->m_DRCMaxPhysicalClearance <= 0 )
|
2021-08-13 19:10:30 +00:00
|
|
|
{
|
2022-06-17 21:50:59 +00:00
|
|
|
reportAux( wxT( "No physical clearance constraints found. Tests not run." ) );
|
2021-08-13 19:10:30 +00:00
|
|
|
return true; // continue with other tests
|
|
|
|
}
|
|
|
|
|
2022-06-17 21:50:59 +00:00
|
|
|
reportAux( wxT( "Largest physical clearance : %d nm" ), m_board->m_DRCMaxPhysicalClearance );
|
2021-08-13 19:10:30 +00:00
|
|
|
|
2022-08-03 09:10:23 +00:00
|
|
|
size_t progressDelta = 250;
|
2021-08-13 19:10:30 +00:00
|
|
|
size_t count = 0;
|
|
|
|
size_t ii = 0;
|
|
|
|
|
2022-06-17 21:50:59 +00:00
|
|
|
if( !reportPhase( _( "Gathering physical items..." ) ) )
|
2022-03-09 00:47:37 +00:00
|
|
|
return false; // DRC cancelled
|
|
|
|
|
|
|
|
static const std::vector<KICAD_T> itemTypes = {
|
|
|
|
PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T,
|
2022-05-10 22:01:25 +00:00
|
|
|
PCB_FOOTPRINT_T,
|
2022-03-09 00:47:37 +00:00
|
|
|
PCB_PAD_T,
|
|
|
|
PCB_SHAPE_T, PCB_FP_SHAPE_T,
|
|
|
|
PCB_TEXT_T, PCB_FP_TEXT_T, PCB_TEXTBOX_T, PCB_FP_TEXTBOX_T,
|
|
|
|
PCB_DIMENSION_T
|
|
|
|
};
|
|
|
|
|
2022-05-10 22:01:25 +00:00
|
|
|
static const LSET courtyards( 2, F_CrtYd, B_CrtYd );
|
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
//
|
|
|
|
// Generate a count for use in progress reporting.
|
|
|
|
//
|
|
|
|
|
2022-03-09 00:47:37 +00:00
|
|
|
forEachGeometryItem( itemTypes, LSET::AllLayersMask(),
|
2021-08-13 19:10:30 +00:00
|
|
|
[&]( BOARD_ITEM* item ) -> bool
|
|
|
|
{
|
|
|
|
++count;
|
|
|
|
return true;
|
2022-03-09 00:47:37 +00:00
|
|
|
} );
|
2021-08-13 19:10:30 +00:00
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
//
|
|
|
|
// Generate a BOARD_ITEM RTree.
|
|
|
|
//
|
|
|
|
|
2022-03-09 00:47:37 +00:00
|
|
|
forEachGeometryItem( itemTypes, LSET::AllLayersMask(),
|
2021-08-13 19:10:30 +00:00
|
|
|
[&]( BOARD_ITEM* item ) -> bool
|
|
|
|
{
|
2022-08-03 09:10:23 +00:00
|
|
|
if( !reportProgress( ii++, count, progressDelta ) )
|
2021-08-13 19:10:30 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
LSET layers = item->GetLayerSet();
|
|
|
|
|
2022-03-15 14:18:58 +00:00
|
|
|
// Special-case holes and edge-cuts which pierce all physical layers
|
2022-07-15 15:14:11 +00:00
|
|
|
if( item->HasHole() )
|
2021-08-13 19:10:30 +00:00
|
|
|
{
|
2022-07-15 15:14:11 +00:00
|
|
|
layers |= LSET::PhysicalLayersMask() | courtyards;
|
2022-05-10 22:01:25 +00:00
|
|
|
}
|
|
|
|
else if( item->Type() == PCB_FOOTPRINT_T )
|
|
|
|
{
|
|
|
|
layers = courtyards;
|
2022-03-15 14:18:58 +00:00
|
|
|
}
|
|
|
|
else if( item->IsOnLayer( Edge_Cuts ) )
|
|
|
|
{
|
2022-05-10 22:01:25 +00:00
|
|
|
layers |= LSET::PhysicalLayersMask() | courtyards;
|
2021-08-13 19:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for( PCB_LAYER_ID layer : layers.Seq() )
|
2022-06-17 21:50:59 +00:00
|
|
|
m_itemTree.Insert( item, layer, m_board->m_DRCMaxPhysicalClearance );
|
2021-08-13 19:10:30 +00:00
|
|
|
|
|
|
|
return true;
|
2022-03-09 00:47:37 +00:00
|
|
|
} );
|
2021-08-13 19:10:30 +00:00
|
|
|
|
2022-08-25 16:00:18 +00:00
|
|
|
std::unordered_map<PTR_PTR_CACHE_KEY, LSET> checkedPairs;
|
2022-08-03 09:10:23 +00:00
|
|
|
progressDelta = 100;
|
2022-03-12 13:34:25 +00:00
|
|
|
ii = 0;
|
2021-08-13 19:10:30 +00:00
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
//
|
|
|
|
// Run clearance checks -between- items.
|
|
|
|
//
|
|
|
|
|
2022-03-09 00:47:37 +00:00
|
|
|
if( !m_drcEngine->IsErrorLimitExceeded( DRCE_CLEARANCE )
|
|
|
|
|| !m_drcEngine->IsErrorLimitExceeded( DRCE_HOLE_CLEARANCE ) )
|
|
|
|
{
|
2022-05-10 22:01:25 +00:00
|
|
|
if( !reportPhase( _( "Checking physical clearances..." ) ) )
|
2022-03-09 00:47:37 +00:00
|
|
|
return false; // DRC cancelled
|
2021-08-13 19:10:30 +00:00
|
|
|
|
2022-03-12 13:34:25 +00:00
|
|
|
forEachGeometryItem( itemTypes, LSET::AllLayersMask(),
|
|
|
|
[&]( BOARD_ITEM* item ) -> bool
|
|
|
|
{
|
2022-08-03 09:10:23 +00:00
|
|
|
if( !reportProgress( ii++, count, progressDelta ) )
|
2022-03-12 13:34:25 +00:00
|
|
|
return false;
|
2021-08-13 19:10:30 +00:00
|
|
|
|
2022-05-10 22:01:25 +00:00
|
|
|
LSET layers = item->GetLayerSet();
|
|
|
|
|
|
|
|
if( item->Type() == PCB_FOOTPRINT_T )
|
|
|
|
layers = courtyards;
|
|
|
|
|
|
|
|
for( PCB_LAYER_ID layer : layers.Seq() )
|
2022-03-12 13:34:25 +00:00
|
|
|
{
|
|
|
|
std::shared_ptr<SHAPE> itemShape = item->GetEffectiveShape( layer );
|
|
|
|
|
|
|
|
m_itemTree.QueryColliding( item, layer, layer,
|
|
|
|
// Filter:
|
|
|
|
[&]( BOARD_ITEM* other ) -> bool
|
|
|
|
{
|
|
|
|
BOARD_ITEM* a = item;
|
|
|
|
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 } );
|
|
|
|
|
|
|
|
if( it != checkedPairs.end() && it->second.test( layer ) )
|
2022-03-12 13:34:25 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-25 16:00:18 +00:00
|
|
|
checkedPairs[ { a, b } ].set( layer );
|
2022-03-12 13:34:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// Visitor:
|
|
|
|
[&]( BOARD_ITEM* other ) -> bool
|
|
|
|
{
|
2023-02-15 19:32:51 +00:00
|
|
|
if( testItemAgainstItem( item, itemShape.get(), layer,
|
|
|
|
other ) > 0 )
|
|
|
|
{
|
|
|
|
BOARD_ITEM* a = item;
|
|
|
|
BOARD_ITEM* b = other;
|
|
|
|
|
|
|
|
// store canonical order
|
|
|
|
if( static_cast<void*>( a ) > static_cast<void*>( b ) )
|
|
|
|
std::swap( a, b );
|
|
|
|
|
|
|
|
// Once we record one DRC for error for physical clearance
|
|
|
|
// we don't need to record more
|
|
|
|
checkedPairs[ { a, b } ].set();
|
|
|
|
}
|
|
|
|
|
|
|
|
return !m_drcEngine->IsCancelled();
|
2022-03-12 13:34:25 +00:00
|
|
|
},
|
2022-06-17 21:50:59 +00:00
|
|
|
m_board->m_DRCMaxPhysicalClearance );
|
2022-03-12 13:34:25 +00:00
|
|
|
|
|
|
|
testItemAgainstZones( item, layer );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} );
|
2021-08-13 19:10:30 +00:00
|
|
|
}
|
|
|
|
|
2022-08-03 09:10:23 +00:00
|
|
|
progressDelta = 100;
|
2021-08-18 21:16:25 +00:00
|
|
|
count = 0;
|
2022-03-09 00:47:37 +00:00
|
|
|
ii = 0;
|
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
//
|
|
|
|
// Generate a count for progress reporting.
|
|
|
|
//
|
|
|
|
|
2021-08-19 21:28:54 +00:00
|
|
|
forEachGeometryItem( { PCB_ZONE_T, PCB_FP_ZONE_T, PCB_SHAPE_T, PCB_FP_SHAPE_T },
|
|
|
|
LSET::AllCuMask(),
|
2021-08-18 21:16:25 +00:00
|
|
|
[&]( BOARD_ITEM* item ) -> bool
|
|
|
|
{
|
2022-03-15 14:18:58 +00:00
|
|
|
ZONE* zone = dynamic_cast<ZONE*>( item );
|
2021-08-19 21:28:54 +00:00
|
|
|
|
2022-03-15 14:18:58 +00:00
|
|
|
if( zone && zone->GetIsRuleArea() )
|
|
|
|
return true; // Continue with other items
|
2021-08-19 21:28:54 +00:00
|
|
|
|
2022-03-15 14:18:58 +00:00
|
|
|
count += ( item->GetLayerSet() & LSET::AllCuMask() ).count();
|
2021-08-18 21:16:25 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
} );
|
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
//
|
|
|
|
// Run clearance checks -within- polygonal items.
|
|
|
|
//
|
|
|
|
|
2021-08-19 21:28:54 +00:00
|
|
|
forEachGeometryItem( { PCB_ZONE_T, PCB_FP_ZONE_T, PCB_SHAPE_T, PCB_FP_SHAPE_T },
|
|
|
|
LSET::AllCuMask(),
|
2021-08-18 21:16:25 +00:00
|
|
|
[&]( BOARD_ITEM* item ) -> bool
|
|
|
|
{
|
2022-03-15 14:18:58 +00:00
|
|
|
PCB_SHAPE* shape = dynamic_cast<PCB_SHAPE*>( item );
|
|
|
|
ZONE* zone = dynamic_cast<ZONE*>( item );
|
|
|
|
|
|
|
|
if( zone && zone->GetIsRuleArea() )
|
|
|
|
return true; // Continue with other items
|
|
|
|
|
2021-08-18 21:16:25 +00:00
|
|
|
for( PCB_LAYER_ID layer : item->GetLayerSet().Seq() )
|
|
|
|
{
|
|
|
|
if( IsCopperLayer( layer ) )
|
|
|
|
{
|
2022-08-03 09:10:23 +00:00
|
|
|
if( !reportProgress( ii++, count, progressDelta ) )
|
2021-08-18 21:16:25 +00:00
|
|
|
return false;
|
|
|
|
|
2022-05-06 13:46:24 +00:00
|
|
|
DRC_CONSTRAINT c = m_drcEngine->EvalRules( PHYSICAL_CLEARANCE_CONSTRAINT,
|
2021-08-19 21:28:54 +00:00
|
|
|
item, nullptr, layer );
|
|
|
|
|
|
|
|
if( shape )
|
|
|
|
{
|
|
|
|
switch( shape->GetShape() )
|
|
|
|
{
|
|
|
|
case SHAPE_T::POLY:
|
|
|
|
testShapeLineChain( shape->GetPolyShape().Outline( 0 ),
|
2021-12-26 13:47:00 +00:00
|
|
|
shape->GetWidth(), layer, item, c );
|
2021-08-19 21:28:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::BEZIER:
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN asPoly;
|
|
|
|
|
|
|
|
shape->RebuildBezierToSegmentsPointsList( shape->GetWidth() );
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
for( const VECTOR2I& pt : shape->GetBezierPoints() )
|
2021-08-19 21:28:54 +00:00
|
|
|
asPoly.Append( pt );
|
|
|
|
|
2021-12-26 13:47:00 +00:00
|
|
|
testShapeLineChain( asPoly, shape->GetWidth(), layer, item, c );
|
2021-08-19 21:28:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SHAPE_T::ARC:
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN asPoly;
|
|
|
|
|
2022-01-14 15:34:41 +00:00
|
|
|
VECTOR2I center = shape->GetCenter();
|
|
|
|
EDA_ANGLE angle = -shape->GetArcAngle();
|
|
|
|
double r = shape->GetRadius();
|
|
|
|
int steps = GetArcToSegmentCount( r, errorMax, angle );
|
2021-08-19 21:28:54 +00:00
|
|
|
|
|
|
|
asPoly.Append( shape->GetStart() );
|
|
|
|
|
|
|
|
for( int step = 1; step <= steps; ++step )
|
|
|
|
{
|
2022-01-14 15:34:41 +00:00
|
|
|
EDA_ANGLE rotation = ( angle * step ) / steps;
|
|
|
|
VECTOR2I pt = shape->GetStart();
|
2021-08-19 21:28:54 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
RotatePoint( pt, center, rotation );
|
2021-08-19 21:28:54 +00:00
|
|
|
asPoly.Append( pt );
|
|
|
|
}
|
|
|
|
|
2022-01-08 09:49:47 +00:00
|
|
|
testShapeLineChain( asPoly, shape->GetWidth(), layer, item, c );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SHAPE_T::RECT:
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN asPoly;
|
|
|
|
std::vector<VECTOR2I> pts = shape->GetRectCorners();
|
|
|
|
asPoly.Append( pts[0] );
|
|
|
|
asPoly.Append( pts[1] );
|
|
|
|
asPoly.Append( pts[2] );
|
|
|
|
asPoly.Append( pts[3] );
|
|
|
|
asPoly.SetClosed( true );
|
|
|
|
|
2021-12-26 13:47:00 +00:00
|
|
|
testShapeLineChain( asPoly, shape->GetWidth(), layer, item, c );
|
2021-08-19 21:28:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
UNIMPLEMENTED_FOR( shape->SHAPE_T_asString() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( zone )
|
|
|
|
testZoneLayer( static_cast<ZONE*>( item ), layer, c );
|
2021-08-18 21:16:25 +00:00
|
|
|
}
|
2022-03-11 20:13:47 +00:00
|
|
|
|
|
|
|
if( m_drcEngine->IsCancelled() )
|
|
|
|
return false;
|
2021-08-18 21:16:25 +00:00
|
|
|
}
|
|
|
|
|
2022-03-11 20:13:47 +00:00
|
|
|
return !m_drcEngine->IsCancelled();
|
2021-08-18 21:16:25 +00:00
|
|
|
} );
|
|
|
|
|
2021-08-13 19:10:30 +00:00
|
|
|
reportRuleStatistics();
|
|
|
|
|
2022-03-11 20:13:47 +00:00
|
|
|
return !m_drcEngine->IsCancelled();
|
2021-08-13 19:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-06 13:46:24 +00:00
|
|
|
void DRC_TEST_PROVIDER_PHYSICAL_CLEARANCE::testShapeLineChain( const SHAPE_LINE_CHAIN& aOutline,
|
|
|
|
int aLineWidth, PCB_LAYER_ID aLayer,
|
|
|
|
BOARD_ITEM* aParentItem,
|
|
|
|
DRC_CONSTRAINT& aConstraint )
|
2021-08-18 21:16:25 +00:00
|
|
|
{
|
2021-08-19 21:28:54 +00:00
|
|
|
// We don't want to collide with neighboring segments forming a curve until the concavity
|
|
|
|
// approaches 180 degrees.
|
|
|
|
double angleTolerance = DEG2RAD( 180.0 - ADVANCED_CFG::GetCfg().m_SliverAngleTolerance );
|
|
|
|
int epsilon = m_board->GetDesignSettings().GetDRCEpsilon();
|
|
|
|
int count = aOutline.SegmentCount();
|
|
|
|
int clearance = aConstraint.GetValue().Min();
|
|
|
|
|
2022-06-17 21:50:59 +00:00
|
|
|
if( aConstraint.GetSeverity() == RPT_SEVERITY_IGNORE || clearance - epsilon <= 0 )
|
|
|
|
return;
|
|
|
|
|
2021-08-19 21:28:54 +00:00
|
|
|
// Trigonometry is not cheap; cache seg angles
|
|
|
|
std::vector<double> angles;
|
|
|
|
angles.reserve( count );
|
|
|
|
|
|
|
|
auto angleDiff =
|
|
|
|
[]( double a, double b ) -> double
|
|
|
|
{
|
|
|
|
if( a > b )
|
|
|
|
std::swap( a, b );
|
|
|
|
|
|
|
|
double diff = b - a;
|
|
|
|
|
|
|
|
if( diff > M_PI )
|
|
|
|
return 2 * M_PI - diff;
|
|
|
|
else
|
|
|
|
return diff;
|
|
|
|
};
|
|
|
|
|
|
|
|
for( int ii = 0; ii < count; ++ii )
|
|
|
|
{
|
|
|
|
const SEG& seg = aOutline.CSegment( ii );
|
|
|
|
|
|
|
|
// NB: don't store angles of really short segments (which could point anywhere)
|
|
|
|
|
|
|
|
if( seg.SquaredLength() > SEG::Square( epsilon * 2 ) )
|
|
|
|
{
|
2022-01-20 21:26:04 +00:00
|
|
|
angles.push_back( EDA_ANGLE( seg.B - seg.A ).AsRadians() );
|
2021-08-19 21:28:54 +00:00
|
|
|
}
|
|
|
|
else if( ii > 0 )
|
|
|
|
{
|
|
|
|
angles.push_back( angles.back() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( int jj = 1; jj < count; ++jj )
|
|
|
|
{
|
|
|
|
const SEG& following = aOutline.CSegment( jj );
|
|
|
|
|
|
|
|
if( following.SquaredLength() > SEG::Square( epsilon * 2 ) || jj == count - 1 )
|
|
|
|
{
|
2022-01-20 21:26:04 +00:00
|
|
|
angles.push_back( EDA_ANGLE( following.B - following.A ).AsRadians() );
|
2021-08-19 21:28:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find collisions before reporting so that we can condense them into fewer reports.
|
|
|
|
std::vector< std::pair<VECTOR2I, int> > collisions;
|
|
|
|
|
|
|
|
for( int ii = 0; ii < count; ++ii )
|
|
|
|
{
|
|
|
|
const SEG seg = aOutline.CSegment( ii );
|
|
|
|
double segAngle = angles[ ii ];
|
|
|
|
|
|
|
|
// Exclude segments on either side of us until we reach the angle tolerance
|
|
|
|
int firstCandidate = ii + 1;
|
|
|
|
int lastCandidate = count - 1;
|
|
|
|
|
|
|
|
while( firstCandidate < count )
|
|
|
|
{
|
|
|
|
if( angleDiff( segAngle, angles[ firstCandidate ] ) < angleTolerance )
|
|
|
|
firstCandidate++;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aOutline.IsClosed() )
|
|
|
|
{
|
|
|
|
if( ii > 0 )
|
|
|
|
lastCandidate = ii - 1;
|
|
|
|
|
|
|
|
while( lastCandidate != std::min( firstCandidate, count - 1 ) )
|
|
|
|
{
|
|
|
|
if( angleDiff( segAngle, angles[ lastCandidate ] ) < angleTolerance )
|
|
|
|
lastCandidate = ( lastCandidate == 0 ) ? count - 1 : lastCandidate - 1;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now run the collision between seg and each candidate seg in the candidate range.
|
|
|
|
if( lastCandidate < ii )
|
|
|
|
lastCandidate = count - 1;
|
|
|
|
|
|
|
|
for( int jj = firstCandidate; jj <= lastCandidate; ++jj )
|
|
|
|
{
|
|
|
|
const SEG candidate = aOutline.CSegment( jj );
|
|
|
|
int actual;
|
|
|
|
|
|
|
|
if( seg.Collide( candidate, clearance + aLineWidth - epsilon, &actual ) )
|
|
|
|
{
|
|
|
|
VECTOR2I firstPoint = seg.NearestPoint( candidate );
|
|
|
|
VECTOR2I secondPoint = candidate.NearestPoint( seg );
|
|
|
|
VECTOR2I pos = ( firstPoint + secondPoint ) / 2;
|
|
|
|
|
|
|
|
if( !collisions.empty() &&
|
|
|
|
( pos - collisions.back().first ).EuclideanNorm() < clearance * 2 )
|
|
|
|
{
|
|
|
|
if( actual < collisions.back().second )
|
|
|
|
{
|
|
|
|
collisions.back().first = pos;
|
|
|
|
collisions.back().second = actual;
|
|
|
|
}
|
2022-03-09 00:47:37 +00:00
|
|
|
|
2021-08-19 21:28:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
collisions.push_back( { pos, actual } );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( std::pair<VECTOR2I, int> collision : collisions )
|
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( DRCE_CLEARANCE );
|
2022-06-17 21:50:59 +00:00
|
|
|
VECTOR2I pt = collision.first;
|
|
|
|
|
|
|
|
if( aParentItem->GetParentFootprint() )
|
|
|
|
pt += aParentItem->GetParentFootprint()->GetPosition();
|
2021-08-19 21:28:54 +00:00
|
|
|
|
2022-10-06 20:52:17 +00:00
|
|
|
wxString msg = formatMsg( _( "Internal clearance violation (%s clearance %s; actual %s)" ),
|
|
|
|
aConstraint.GetName(),
|
|
|
|
clearance,
|
|
|
|
collision.second );
|
2021-08-18 21:16:25 +00:00
|
|
|
|
2022-06-17 21:50:59 +00:00
|
|
|
drce->SetErrorMessage( msg );
|
2021-08-19 21:28:54 +00:00
|
|
|
drce->SetItems( aParentItem );
|
|
|
|
drce->SetViolatingRule( aConstraint.GetParentRule() );
|
|
|
|
|
2022-06-17 21:50:59 +00:00
|
|
|
reportViolation( drce, pt, aLayer );
|
2021-08-19 21:28:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-06 13:46:24 +00:00
|
|
|
void DRC_TEST_PROVIDER_PHYSICAL_CLEARANCE::testZoneLayer( ZONE* aZone, PCB_LAYER_ID aLayer,
|
|
|
|
DRC_CONSTRAINT& aConstraint )
|
2021-08-19 21:28:54 +00:00
|
|
|
{
|
2022-06-17 21:50:59 +00:00
|
|
|
int epsilon = m_board->GetDesignSettings().GetDRCEpsilon();
|
|
|
|
int clearance = aConstraint.GetValue().Min();
|
2021-08-18 21:16:25 +00:00
|
|
|
|
2021-09-05 15:06:12 +00:00
|
|
|
if( aConstraint.GetSeverity() == RPT_SEVERITY_IGNORE || clearance - epsilon <= 0 )
|
2021-08-18 21:16:25 +00:00
|
|
|
return;
|
|
|
|
|
2022-06-17 21:50:59 +00:00
|
|
|
SHAPE_POLY_SET fill = aZone->GetFilledPolysList( aLayer )->CloneDropTriangulation();
|
|
|
|
|
2021-08-18 21:16:25 +00:00
|
|
|
// Turn fractured fill into outlines and holes
|
|
|
|
fill.Simplify( SHAPE_POLY_SET::PM_FAST );
|
|
|
|
|
|
|
|
for( int outlineIdx = 0; outlineIdx < fill.OutlineCount(); ++outlineIdx )
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN* firstOutline = &fill.Outline( outlineIdx );
|
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
//
|
2021-08-18 21:16:25 +00:00
|
|
|
// Step one: outline to outline clearance violations
|
2022-08-26 12:21:52 +00:00
|
|
|
//
|
2021-08-18 21:16:25 +00:00
|
|
|
|
|
|
|
for( int ii = outlineIdx + 1; ii < fill.OutlineCount(); ++ii )
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN* secondOutline = &fill.Outline( ii );
|
|
|
|
|
|
|
|
for( int jj = 0; jj < secondOutline->SegmentCount(); ++jj )
|
|
|
|
{
|
|
|
|
SEG secondSeg = secondOutline->Segment( jj );
|
|
|
|
int actual;
|
|
|
|
VECTOR2I pos;
|
|
|
|
|
|
|
|
if( firstOutline->Collide( secondSeg, clearance - epsilon, &actual, &pos ) )
|
|
|
|
{
|
|
|
|
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)" ),
|
|
|
|
aConstraint.GetName(),
|
|
|
|
clearance,
|
|
|
|
actual );
|
2021-08-18 21:16:25 +00:00
|
|
|
|
2022-06-15 23:42:34 +00:00
|
|
|
drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
|
2021-08-18 21:16:25 +00:00
|
|
|
drce->SetItems( aZone );
|
2021-08-19 21:28:54 +00:00
|
|
|
drce->SetViolatingRule( aConstraint.GetParentRule() );
|
2021-08-18 21:16:25 +00:00
|
|
|
|
2022-01-02 02:06:40 +00:00
|
|
|
reportViolation( drce, pos, aLayer );
|
2021-08-18 21:16:25 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-11 20:13:47 +00:00
|
|
|
|
|
|
|
if( m_drcEngine->IsCancelled() )
|
|
|
|
return;
|
2021-08-18 21:16:25 +00:00
|
|
|
}
|
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
//
|
2021-08-18 21:16:25 +00:00
|
|
|
// Step two: interior hole clearance violations
|
2022-08-26 12:21:52 +00:00
|
|
|
//
|
2021-08-18 21:16:25 +00:00
|
|
|
|
|
|
|
for( int holeIdx = 0; holeIdx < fill.HoleCount( outlineIdx ); ++holeIdx )
|
|
|
|
{
|
2021-12-26 13:47:00 +00:00
|
|
|
testShapeLineChain( fill.Hole( outlineIdx, holeIdx ), 0, aLayer, aZone, aConstraint );
|
2022-03-11 20:13:47 +00:00
|
|
|
|
|
|
|
if( m_drcEngine->IsCancelled() )
|
|
|
|
return;
|
2021-08-18 21:16:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-02-15 19:32:51 +00:00
|
|
|
int DRC_TEST_PROVIDER_PHYSICAL_CLEARANCE::testItemAgainstItem( BOARD_ITEM* aItem,
|
2022-08-26 12:21:52 +00:00
|
|
|
SHAPE* aItemShape,
|
|
|
|
PCB_LAYER_ID aLayer,
|
2022-05-06 13:46:24 +00:00
|
|
|
BOARD_ITEM* other )
|
2021-08-13 19:10:30 +00:00
|
|
|
{
|
|
|
|
bool testClearance = !m_drcEngine->IsErrorLimitExceeded( DRCE_CLEARANCE );
|
|
|
|
bool testHoles = !m_drcEngine->IsErrorLimitExceeded( DRCE_HOLE_CLEARANCE );
|
|
|
|
DRC_CONSTRAINT constraint;
|
|
|
|
int clearance = 0;
|
|
|
|
int actual;
|
2023-02-15 19:32:51 +00:00
|
|
|
int violations = 0;
|
2021-08-13 19:10:30 +00:00
|
|
|
VECTOR2I pos;
|
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
std::shared_ptr<SHAPE> otherShape = other->GetEffectiveShape( aLayer );
|
2021-08-13 19:10:30 +00:00
|
|
|
|
|
|
|
if( testClearance )
|
|
|
|
{
|
2022-08-26 12:21:52 +00:00
|
|
|
constraint = m_drcEngine->EvalRules( PHYSICAL_CLEARANCE_CONSTRAINT, aItem, other, aLayer );
|
2021-08-13 19:10:30 +00:00
|
|
|
clearance = constraint.GetValue().Min();
|
|
|
|
}
|
|
|
|
|
2021-09-05 15:06:12 +00:00
|
|
|
if( constraint.GetSeverity() != RPT_SEVERITY_IGNORE && clearance > 0 )
|
2021-08-13 19:10:30 +00:00
|
|
|
{
|
2022-08-26 12:21:52 +00:00
|
|
|
if( aItemShape->Collide( otherShape.get(), clearance, &actual, &pos ) )
|
2021-08-13 19:10:30 +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 );
|
2021-08-13 19:10:30 +00:00
|
|
|
|
2022-06-15 23:42:34 +00:00
|
|
|
drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
|
2022-08-26 12:21:52 +00:00
|
|
|
drce->SetItems( aItem, other );
|
2021-08-13 19:10:30 +00:00
|
|
|
drce->SetViolatingRule( constraint.GetParentRule() );
|
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
reportViolation( drce, pos, aLayer );
|
2023-02-15 19:32:51 +00:00
|
|
|
++violations;
|
2021-08-13 19:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( testHoles )
|
|
|
|
{
|
2022-07-22 22:05:25 +00:00
|
|
|
std::shared_ptr<SHAPE_SEGMENT> itemHoleShape;
|
|
|
|
std::shared_ptr<SHAPE_SEGMENT> otherHoleShape;
|
2021-08-13 19:10:30 +00:00
|
|
|
clearance = 0;
|
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
if( aItem->Type() == PCB_VIA_T )
|
2021-08-13 19:10:30 +00:00
|
|
|
{
|
2022-08-26 12:21:52 +00:00
|
|
|
if( aItem->GetLayerSet().Contains( aLayer ) )
|
|
|
|
itemHoleShape = aItem->GetEffectiveHoleShape();
|
2023-02-15 19:32:51 +00:00
|
|
|
else
|
|
|
|
return violations;
|
2021-08-13 19:10:30 +00:00
|
|
|
}
|
2022-08-26 12:21:52 +00:00
|
|
|
else if( aItem->HasHole() )
|
2021-08-13 19:10:30 +00:00
|
|
|
{
|
2022-08-26 12:21:52 +00:00
|
|
|
itemHoleShape = aItem->GetEffectiveHoleShape();
|
2021-08-13 19:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( other->Type() == PCB_VIA_T )
|
|
|
|
{
|
2022-08-26 12:21:52 +00:00
|
|
|
if( other->GetLayerSet().Contains( aLayer ) )
|
2022-07-22 22:05:25 +00:00
|
|
|
otherHoleShape = other->GetEffectiveHoleShape();
|
2023-02-15 19:32:51 +00:00
|
|
|
else
|
|
|
|
return violations;
|
2021-08-13 19:10:30 +00:00
|
|
|
}
|
2022-07-22 22:05:25 +00:00
|
|
|
else if( other->HasHole() )
|
2021-08-13 19:10:30 +00:00
|
|
|
{
|
2022-07-22 22:05:25 +00:00
|
|
|
otherHoleShape = other->GetEffectiveHoleShape();
|
2021-08-13 19:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( itemHoleShape || otherHoleShape )
|
|
|
|
{
|
2022-08-26 12:21:52 +00:00
|
|
|
constraint = m_drcEngine->EvalRules( PHYSICAL_HOLE_CLEARANCE_CONSTRAINT, other, aItem,
|
|
|
|
aLayer );
|
2021-08-13 19:10:30 +00:00
|
|
|
clearance = constraint.GetValue().Min();
|
|
|
|
}
|
|
|
|
|
2021-09-05 15:06:12 +00:00
|
|
|
if( constraint.GetSeverity() != RPT_SEVERITY_IGNORE && clearance > 0 )
|
2021-08-13 19:10:30 +00:00
|
|
|
{
|
2021-09-05 15:06:12 +00:00
|
|
|
if( itemHoleShape && itemHoleShape->Collide( otherShape.get(), clearance, &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 );
|
2021-08-13 19:10:30 +00:00
|
|
|
|
2022-06-15 23:42:34 +00:00
|
|
|
drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
|
2022-08-26 12:21:52 +00:00
|
|
|
drce->SetItems( aItem, other );
|
2021-09-05 15:06:12 +00:00
|
|
|
drce->SetViolatingRule( constraint.GetParentRule() );
|
2021-08-13 19:10:30 +00:00
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
reportViolation( drce, pos, aLayer );
|
2023-02-15 19:32:51 +00:00
|
|
|
++violations;
|
2021-09-05 15:06:12 +00:00
|
|
|
}
|
2021-08-13 19:10:30 +00:00
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
if( otherHoleShape && otherHoleShape->Collide( aItemShape, clearance, &actual, &pos ) )
|
2021-09-05 15:06:12 +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-13 19:10:30 +00:00
|
|
|
|
2022-06-15 23:42:34 +00:00
|
|
|
drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
|
2022-08-26 12:21:52 +00:00
|
|
|
drce->SetItems( aItem, other );
|
2021-09-05 15:06:12 +00:00
|
|
|
drce->SetViolatingRule( constraint.GetParentRule() );
|
2021-08-13 19:10:30 +00:00
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
reportViolation( drce, pos, aLayer );
|
2023-02-15 19:32:51 +00:00
|
|
|
++violations;
|
2021-09-05 15:06:12 +00:00
|
|
|
}
|
2021-08-13 19:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-15 19:32:51 +00:00
|
|
|
return violations;
|
2021-08-13 19:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-06 13:46:24 +00:00
|
|
|
void DRC_TEST_PROVIDER_PHYSICAL_CLEARANCE::testItemAgainstZones( BOARD_ITEM* aItem,
|
|
|
|
PCB_LAYER_ID aLayer )
|
2021-08-13 19:10:30 +00:00
|
|
|
{
|
2022-06-17 21:50:59 +00:00
|
|
|
for( ZONE* zone : m_board->m_DRCZones )
|
2021-08-13 19:10:30 +00:00
|
|
|
{
|
|
|
|
if( !zone->GetLayerSet().test( aLayer ) )
|
|
|
|
continue;
|
|
|
|
|
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( zone->GetBoundingBox() ) )
|
2022-08-26 12:21:52 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
bool testClearance = !m_drcEngine->IsErrorLimitExceeded( DRCE_CLEARANCE );
|
|
|
|
bool testHoles = !m_drcEngine->IsErrorLimitExceeded( DRCE_HOLE_CLEARANCE );
|
|
|
|
|
|
|
|
if( !testClearance && !testHoles )
|
|
|
|
return;
|
|
|
|
|
|
|
|
DRC_RTREE* zoneTree = m_board->m_CopperZoneRTreeCache[ zone ].get();
|
|
|
|
DRC_CONSTRAINT constraint;
|
|
|
|
bool colliding;
|
|
|
|
int clearance = -1;
|
|
|
|
int actual;
|
|
|
|
VECTOR2I pos;
|
|
|
|
|
|
|
|
if( testClearance )
|
2021-08-13 19:10:30 +00:00
|
|
|
{
|
2022-08-26 12:21:52 +00:00
|
|
|
constraint = m_drcEngine->EvalRules( PHYSICAL_CLEARANCE_CONSTRAINT, aItem, zone,
|
|
|
|
aLayer );
|
|
|
|
clearance = constraint.GetValue().Min();
|
|
|
|
}
|
2021-08-13 19:10:30 +00:00
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
if( constraint.GetSeverity() != RPT_SEVERITY_IGNORE && clearance > 0 )
|
|
|
|
{
|
|
|
|
std::shared_ptr<SHAPE> itemShape = aItem->GetEffectiveShape( aLayer );
|
2021-08-13 19:10:30 +00:00
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
if( aItem->Type() == PCB_PAD_T )
|
|
|
|
{
|
|
|
|
PAD* pad = static_cast<PAD*>( aItem );
|
2021-08-13 19:10:30 +00:00
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
if( !pad->FlashLayer( aLayer ) )
|
|
|
|
{
|
|
|
|
if( pad->GetDrillSize().x == 0 && pad->GetDrillSize().y == 0 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
std::shared_ptr<SHAPE_SEGMENT> hole = pad->GetEffectiveHoleShape();
|
|
|
|
int size = hole->GetWidth();
|
|
|
|
|
|
|
|
itemShape = std::make_shared<SHAPE_SEGMENT>( hole->GetSeg(), size );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( zoneTree )
|
2021-08-13 19:10:30 +00:00
|
|
|
{
|
2022-08-26 12:21:52 +00:00
|
|
|
colliding = zoneTree->QueryColliding( itemBBox, itemShape.get(), aLayer, clearance,
|
|
|
|
&actual, &pos );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
colliding = zone->Outline()->Collide( itemShape.get(), clearance, &actual, &pos );
|
2021-08-13 19:10:30 +00:00
|
|
|
}
|
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
if( colliding )
|
2021-08-13 19:10:30 +00:00
|
|
|
{
|
2022-08-26 12:21:52 +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 );
|
2021-08-13 19:10:30 +00:00
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
|
|
|
|
drce->SetItems( aItem, zone );
|
|
|
|
drce->SetViolatingRule( constraint.GetParentRule() );
|
2021-08-13 19:10:30 +00:00
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
reportViolation( drce, pos, aLayer );
|
|
|
|
}
|
|
|
|
}
|
2021-08-13 19:10:30 +00:00
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
if( testHoles )
|
|
|
|
{
|
|
|
|
std::shared_ptr<SHAPE_SEGMENT> holeShape;
|
2021-08-13 19:10:30 +00:00
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
if( aItem->Type() == PCB_VIA_T )
|
|
|
|
{
|
|
|
|
if( aItem->GetLayerSet().Contains( aLayer ) )
|
|
|
|
holeShape = aItem->GetEffectiveHoleShape();
|
|
|
|
}
|
|
|
|
else if( aItem->HasHole() )
|
|
|
|
{
|
|
|
|
holeShape = aItem->GetEffectiveHoleShape();
|
|
|
|
}
|
2021-08-13 19:10:30 +00:00
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
if( holeShape )
|
|
|
|
{
|
|
|
|
constraint = m_drcEngine->EvalRules( PHYSICAL_HOLE_CLEARANCE_CONSTRAINT, aItem,
|
|
|
|
zone, aLayer );
|
|
|
|
clearance = constraint.GetValue().Min();
|
2021-08-19 21:28:54 +00:00
|
|
|
|
2022-08-26 12:21:52 +00:00
|
|
|
if( constraint.GetSeverity() != RPT_SEVERITY_IGNORE
|
|
|
|
&& clearance > 0
|
|
|
|
&& zoneTree->QueryColliding( itemBBox, holeShape.get(), aLayer, clearance,
|
|
|
|
&actual, &pos ) )
|
2021-08-13 19:10:30 +00:00
|
|
|
{
|
2022-08-26 12:21:52 +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-13 19:10:30 +00:00
|
|
|
|
2022-06-15 23:42:34 +00:00
|
|
|
drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + msg );
|
2021-08-13 19:10:30 +00:00
|
|
|
drce->SetItems( aItem, zone );
|
|
|
|
drce->SetViolatingRule( constraint.GetParentRule() );
|
|
|
|
|
2022-01-02 02:06:40 +00:00
|
|
|
reportViolation( drce, pos, aLayer );
|
2021-08-13 19:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-11 20:13:47 +00:00
|
|
|
|
|
|
|
if( m_drcEngine->IsCancelled() )
|
|
|
|
return;
|
2021-08-13 19:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace detail
|
|
|
|
{
|
2022-05-06 13:46:24 +00:00
|
|
|
static DRC_REGISTER_TEST_PROVIDER<DRC_TEST_PROVIDER_PHYSICAL_CLEARANCE> dummy;
|
2021-08-13 19:10:30 +00:00
|
|
|
}
|