2020-07-27 13:33:06 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004-2020 KiCad Developers.
|
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
#include <class_board.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <pcb_shape.h>
|
2020-06-13 23:28:08 +00:00
|
|
|
#include <class_pad.h>
|
2020-09-15 19:13:45 +00:00
|
|
|
#include <class_track.h>
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2020-09-15 19:13:45 +00:00
|
|
|
//#include <geometry/polygon_test_point_inside.h>
|
2020-06-13 23:28:08 +00:00
|
|
|
#include <geometry/seg.h>
|
|
|
|
#include <geometry/shape_poly_set.h>
|
|
|
|
#include <geometry/shape_rect.h>
|
2020-07-15 16:23:56 +00:00
|
|
|
#include <geometry/shape_segment.h>
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
#include <drc/drc_engine.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>
|
2020-09-19 11:47:43 +00:00
|
|
|
#include <class_dimension.h>
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2020-07-27 13:33:06 +00:00
|
|
|
/*
|
|
|
|
Copper clearance test. Checks all copper items (pads, vias, tracks, drawings, zones) for their electrical clearance.
|
|
|
|
Errors generated:
|
|
|
|
- DRCE_CLEARANCE
|
|
|
|
- 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
|
|
|
|
|
|
|
TODO: improve zone clearance check (super slow)
|
|
|
|
*/
|
|
|
|
|
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-09-11 16:24:27 +00:00
|
|
|
DRC_TEST_PROVIDER_CLEARANCE_BASE()
|
|
|
|
{
|
|
|
|
}
|
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
|
|
|
{
|
2020-08-11 23:50:56 +00:00
|
|
|
return "clearance";
|
2020-06-19 21:34:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual const wxString GetDescription() const override
|
|
|
|
{
|
|
|
|
return "Tests copper item clearance";
|
|
|
|
}
|
|
|
|
|
2020-09-13 10:37:20 +00:00
|
|
|
virtual std::set<DRC_CONSTRAINT_TYPE_T> GetConstraintTypes() const override;
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
int GetNumPhases() const override;
|
|
|
|
|
2020-06-13 23:28:08 +00:00
|
|
|
private:
|
2020-06-17 22:36:54 +00:00
|
|
|
void testPadClearances();
|
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-06-18 16:55:22 +00:00
|
|
|
void testCopperTextAndGraphics();
|
2020-09-11 16:24:27 +00:00
|
|
|
|
2020-06-18 16:55:22 +00:00
|
|
|
void testZones();
|
2020-09-11 16:24:27 +00:00
|
|
|
|
2020-06-18 16:55:22 +00:00
|
|
|
void testCopperDrawItem( BOARD_ITEM* aItem );
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
void doTrackDrc( TRACK* aRefSeg, PCB_LAYER_ID aLayer, TRACKS::iterator aStartIt,
|
2020-09-14 17:54:14 +00:00
|
|
|
TRACKS::iterator aEndIt );
|
2020-09-11 16:24:27 +00:00
|
|
|
|
2020-09-16 09:15:04 +00:00
|
|
|
/**
|
|
|
|
* Test clearance of a pad hole with the pad hole of other pads.
|
|
|
|
* @param aSortedPadsList is the sorted by X pos of all pads
|
|
|
|
* @param aRefPadIdx is the index of pad to test inside aSortedPadsList
|
|
|
|
* @param aX_limit is the max X pos of others pads that need to be tested
|
|
|
|
* To speed up the test, aSortedPadsList is a pad list sorted by X position,
|
|
|
|
* and only pads after the pad to test are tested, so this function must be called
|
|
|
|
* for each pad for the first in list to the last in list
|
|
|
|
*/
|
|
|
|
void doPadToPadsDrc( int aRefPadIdx, std::vector<D_PAD*>& aSortedPadsList, int aX_limit );
|
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();
|
2020-08-11 22:17:43 +00:00
|
|
|
DRC_CONSTRAINT worstClearanceConstraint;
|
2020-06-30 08:42:43 +00:00
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
if( m_drcEngine->QueryWorstConstraint( DRC_CONSTRAINT_TYPE_CLEARANCE,
|
2020-09-11 15:04:11 +00:00
|
|
|
worstClearanceConstraint, DRCCQ_LARGEST_MINIMUM ) )
|
2020-06-30 08:42:43 +00:00
|
|
|
{
|
2020-08-11 22:17:43 +00:00
|
|
|
m_largestClearance = worstClearanceConstraint.GetValue().Min();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-09-14 17:54:14 +00:00
|
|
|
reportAux( "No Clearance constraints found..." );
|
2020-08-11 22:17:43 +00:00
|
|
|
return false;
|
2020-06-30 08:42:43 +00:00
|
|
|
}
|
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
reportAux( "Worst clearance : %d nm", m_largestClearance );
|
2020-06-30 08:42:43 +00:00
|
|
|
|
2020-09-18 19:57:54 +00:00
|
|
|
if( !reportPhase( _( "Checking pad clearances..." ) ) )
|
|
|
|
return false;
|
|
|
|
|
2020-06-13 23:28:08 +00:00
|
|
|
testPadClearances();
|
2020-09-11 16:24:27 +00:00
|
|
|
|
2020-09-18 19:57:54 +00:00
|
|
|
if( !reportPhase( _( "Checking track & via clearances..." ) ) )
|
|
|
|
return false;
|
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
testTrackClearances();
|
2020-09-11 16:24:27 +00:00
|
|
|
|
2020-09-18 19:57:54 +00:00
|
|
|
if( !reportPhase( _( "Checking copper graphic & text clearances..." ) ) )
|
|
|
|
return false;
|
|
|
|
|
2020-06-18 16:55:22 +00:00
|
|
|
testCopperTextAndGraphics();
|
2020-09-11 16:24:27 +00:00
|
|
|
|
2020-09-18 19:57:54 +00:00
|
|
|
if( !reportPhase( _( "Checking copper zone clearances..." ) ) )
|
|
|
|
return false;
|
|
|
|
|
2020-06-18 16:55:22 +00:00
|
|
|
testZones();
|
2020-06-17 22:36:54 +00:00
|
|
|
|
2020-08-25 17:42:52 +00:00
|
|
|
reportRuleStatistics();
|
|
|
|
|
2020-06-17 22:36:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
void DRC_TEST_PROVIDER_COPPER_CLEARANCE::testCopperTextAndGraphics()
|
2020-06-18 16:55:22 +00:00
|
|
|
{
|
|
|
|
// Test copper items for clearance violations with vias, tracks and pads
|
|
|
|
|
|
|
|
for( BOARD_ITEM* brdItem : m_board->Drawings() )
|
|
|
|
{
|
|
|
|
if( IsCopperLayer( brdItem->GetLayer() ) )
|
|
|
|
testCopperDrawItem( brdItem );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( MODULE* module : m_board->Modules() )
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
FP_TEXT& ref = module->Reference();
|
|
|
|
FP_TEXT& val = module->Value();
|
2020-06-18 16:55:22 +00:00
|
|
|
|
|
|
|
if( ref.IsVisible() && IsCopperLayer( ref.GetLayer() ) )
|
|
|
|
testCopperDrawItem( &ref );
|
|
|
|
|
|
|
|
if( val.IsVisible() && IsCopperLayer( val.GetLayer() ) )
|
|
|
|
testCopperDrawItem( &val );
|
|
|
|
|
|
|
|
if( module->IsNetTie() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for( BOARD_ITEM* item : module->GraphicalItems() )
|
|
|
|
{
|
|
|
|
if( IsCopperLayer( item->GetLayer() ) )
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
if( item->Type() == PCB_FP_TEXT_T && ( (FP_TEXT*) item )->IsVisible() )
|
2020-06-18 16:55:22 +00:00
|
|
|
testCopperDrawItem( item );
|
2020-10-04 14:19:33 +00:00
|
|
|
else if( item->Type() == PCB_FP_SHAPE_T )
|
2020-06-18 16:55:22 +00:00
|
|
|
testCopperDrawItem( item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
void DRC_TEST_PROVIDER_COPPER_CLEARANCE::testCopperDrawItem( BOARD_ITEM* aItem )
|
2020-06-18 16:55:22 +00:00
|
|
|
{
|
2020-09-11 16:24:27 +00:00
|
|
|
EDA_RECT bbox;
|
2020-07-15 16:23:56 +00:00
|
|
|
std::shared_ptr<SHAPE> itemShape;
|
2020-09-11 16:24:27 +00:00
|
|
|
EDA_TEXT* textItem = dynamic_cast<EDA_TEXT*>( aItem );
|
|
|
|
PCB_LAYER_ID layer = aItem->GetLayer();
|
2020-09-29 17:18:19 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-19 11:47:43 +00:00
|
|
|
if( textItem )
|
2020-06-18 16:55:22 +00:00
|
|
|
{
|
|
|
|
bbox = textItem->GetTextBox();
|
2020-08-11 22:15:50 +00:00
|
|
|
itemShape = textItem->GetEffectiveTextShape();
|
2020-06-18 16:55:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-09-19 11:47:43 +00:00
|
|
|
bbox = aItem->GetBoundingBox();
|
|
|
|
itemShape = aItem->GetEffectiveShape( layer );
|
2020-06-18 16:55:22 +00:00
|
|
|
}
|
|
|
|
|
2020-07-15 16:23:56 +00:00
|
|
|
SHAPE_RECT bboxShape( bbox.GetX(), bbox.GetY(), bbox.GetWidth(), bbox.GetHeight() );
|
2020-06-18 16:55:22 +00:00
|
|
|
|
|
|
|
// Test tracks and vias
|
2020-09-11 16:24:27 +00:00
|
|
|
for( TRACK* track : m_board->Tracks() )
|
2020-06-18 16:55:22 +00:00
|
|
|
{
|
|
|
|
if( !track->IsOnLayer( aItem->GetLayer() ) )
|
|
|
|
continue;
|
|
|
|
|
2020-09-29 17:18:19 +00:00
|
|
|
SHAPE_SEGMENT trackSeg( track->GetStart(), track->GetEnd(), track->GetWidth() );
|
|
|
|
|
|
|
|
// Fast test to detect a track segment candidate inside the text bounding box
|
|
|
|
if( !bboxShape.Collide( &trackSeg, m_largestClearance ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
auto constraint = m_drcEngine->EvalRulesForItems( DRC_CONSTRAINT_TYPE_CLEARANCE,
|
|
|
|
aItem, track, layer );
|
2020-09-28 22:27:33 +00:00
|
|
|
int minClearance = constraint.GetValue().Min();
|
|
|
|
int actual = INT_MAX;
|
|
|
|
VECTOR2I pos;
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-07 12:31:19 +00:00
|
|
|
accountCheck( constraint );
|
|
|
|
|
2020-09-28 22:27:33 +00:00
|
|
|
if( !itemShape->Collide( &trackSeg, minClearance, &actual, &pos ) )
|
2020-07-15 16:23:56 +00:00
|
|
|
continue;
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-07-15 16:23:56 +00:00
|
|
|
if( actual < INT_MAX )
|
2020-06-18 16:55:22 +00:00
|
|
|
{
|
2020-08-11 22:15:50 +00:00
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_CLEARANCE );
|
2020-07-15 16:23:56 +00:00
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
m_msg.Printf( drcItem->GetErrorText() + _( " (%s clearance %s; actual %s)" ),
|
|
|
|
constraint.GetName(),
|
2020-10-02 20:51:24 +00:00
|
|
|
MessageTextFromValue( userUnits(), minClearance ),
|
|
|
|
MessageTextFromValue( userUnits(), std::max( 0, actual ) ) );
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
drcItem->SetErrorMessage( m_msg );
|
2020-06-18 16:55:22 +00:00
|
|
|
drcItem->SetItems( track, aItem );
|
2020-08-11 22:17:43 +00:00
|
|
|
drcItem->SetViolatingRule( constraint.GetParentRule() );
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-28 22:27:33 +00:00
|
|
|
reportViolation( drcItem, (wxPoint) pos );
|
2020-06-18 16:55:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test pads
|
2020-09-11 16:24:27 +00:00
|
|
|
for( D_PAD* pad : m_board->GetPads() )
|
2020-06-18 16:55:22 +00:00
|
|
|
{
|
2020-09-11 16:24:27 +00:00
|
|
|
if( !pad->IsOnLayer( layer ) )
|
2020-06-18 16:55:22 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Graphic items are allowed to act as net-ties within their own footprint
|
2020-10-04 14:19:33 +00:00
|
|
|
if( aItem->Type() == PCB_FP_SHAPE_T && pad->GetParent() == aItem->GetParent() )
|
2020-06-18 16:55:22 +00:00
|
|
|
continue;
|
|
|
|
|
2020-09-29 17:18:19 +00:00
|
|
|
// Fast test to detect a pad candidate inside the text bounding box
|
|
|
|
// Finer test (time consuming) is made only for pads near the text.
|
|
|
|
int bb_radius = pad->GetBoundingRadius() + m_largestClearance;
|
|
|
|
|
|
|
|
if( !bboxShape.Collide( SEG( pad->GetPosition(), pad->GetPosition() ), bb_radius ) )
|
|
|
|
continue;
|
|
|
|
|
2020-09-28 22:27:33 +00:00
|
|
|
auto constraint = m_drcEngine->EvalRulesForItems( DRC_CONSTRAINT_TYPE_CLEARANCE,
|
|
|
|
aItem, pad, layer );
|
|
|
|
int minClearance = constraint.GetValue().Min();
|
|
|
|
int actual;
|
|
|
|
VECTOR2I pos;
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-07 12:31:19 +00:00
|
|
|
accountCheck( constraint );
|
2020-07-15 16:23:56 +00:00
|
|
|
|
2020-09-29 17:18:19 +00:00
|
|
|
SHAPE_SEGMENT padCylinder;
|
|
|
|
const SHAPE* padShape;
|
2020-09-11 16:24:27 +00:00
|
|
|
|
2020-09-29 20:40:17 +00:00
|
|
|
if( pad->FlashLayer( layer ) )
|
2020-09-29 17:18:19 +00:00
|
|
|
{
|
|
|
|
padShape = pad->GetEffectiveShape().get();
|
|
|
|
}
|
2020-09-30 15:38:35 +00:00
|
|
|
else if( pad->GetAttribute() == PAD_ATTRIB_PTH )
|
2020-09-29 17:18:19 +00:00
|
|
|
{
|
|
|
|
// Note: drill size represents finish size, which means the actual holes size is the
|
|
|
|
// plating thickness larger.
|
|
|
|
padCylinder = *pad->GetEffectiveHoleShape();
|
|
|
|
padCylinder.SetWidth( padCylinder.GetWidth() + bds.GetHolePlatingThickness() );
|
|
|
|
padShape = &padCylinder;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-18 16:55:22 +00:00
|
|
|
continue;
|
2020-09-29 17:18:19 +00:00
|
|
|
}
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-29 17:18:19 +00:00
|
|
|
if( !itemShape->Collide( padShape, minClearance, &actual, &pos ) )
|
2020-07-15 16:23:56 +00:00
|
|
|
continue;
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_CLEARANCE );
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
m_msg.Printf( drcItem->GetErrorText() + _( " (%s clearance %s; actual %s)" ),
|
|
|
|
constraint.GetName(),
|
2020-10-02 20:51:24 +00:00
|
|
|
MessageTextFromValue( userUnits(), minClearance ),
|
|
|
|
MessageTextFromValue( userUnits(), actual ) );
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
drcItem->SetErrorMessage( m_msg );
|
|
|
|
drcItem->SetItems( pad, aItem );
|
|
|
|
drcItem->SetViolatingRule( constraint.GetParentRule() );
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-28 22:27:33 +00:00
|
|
|
reportViolation( drcItem, (wxPoint) pos );
|
2020-06-18 16:55:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
void DRC_TEST_PROVIDER_COPPER_CLEARANCE::testTrackClearances()
|
2020-06-17 22:36:54 +00:00
|
|
|
{
|
2020-09-16 15:03:55 +00:00
|
|
|
// This is the number of tests between 2 calls to the progress bar
|
2020-09-17 16:32:42 +00:00
|
|
|
const int delta = m_drcEngine->GetTestTracksAgainstZones() ? 25 : 100;
|
2020-09-11 16:24:27 +00:00
|
|
|
int count = m_board->Tracks().size();
|
2020-06-17 22:36:54 +00:00
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
reportAux( "Testing %d tracks...", count );
|
2020-06-17 22:36:54 +00:00
|
|
|
|
|
|
|
int ii = 0;
|
|
|
|
|
|
|
|
for( auto seg_it = m_board->Tracks().begin(); seg_it != m_board->Tracks().end(); seg_it++ )
|
|
|
|
{
|
2020-09-18 19:57:54 +00:00
|
|
|
if( !reportProgress( ii++, m_board->Tracks().size(), delta ) )
|
|
|
|
break;
|
2020-09-11 16:24:27 +00:00
|
|
|
|
|
|
|
// Test segment against tracks and pads, optionally against copper zones
|
|
|
|
for( PCB_LAYER_ID layer : (*seg_it)->GetLayerSet().Seq() )
|
|
|
|
{
|
2020-09-14 17:54:14 +00:00
|
|
|
doTrackDrc( *seg_it, layer, seg_it + 1, m_board->Tracks().end() );
|
2020-09-11 16:24:27 +00:00
|
|
|
}
|
2020-06-17 22:36:54 +00:00
|
|
|
}
|
2020-06-13 23:28:08 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 22:27:33 +00:00
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
void DRC_TEST_PROVIDER_COPPER_CLEARANCE::doTrackDrc( TRACK* aRefSeg, PCB_LAYER_ID aLayer,
|
|
|
|
TRACKS::iterator aStartIt,
|
2020-09-14 17:54:14 +00:00
|
|
|
TRACKS::iterator aEndIt )
|
2020-06-17 22:36:54 +00:00
|
|
|
{
|
2020-09-11 16:24:27 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
|
2020-06-17 22:36:54 +00:00
|
|
|
|
2020-07-15 16:23:56 +00:00
|
|
|
SHAPE_SEGMENT refSeg( aRefSeg->GetStart(), aRefSeg->GetEnd(), aRefSeg->GetWidth() );
|
2020-09-17 16:32:42 +00:00
|
|
|
EDA_RECT refSegInflatedBB = aRefSeg->GetBoundingBox();
|
2020-09-11 16:24:27 +00:00
|
|
|
int refSegWidth = aRefSeg->GetWidth();
|
2020-06-17 22:36:54 +00:00
|
|
|
|
2020-09-17 16:32:42 +00:00
|
|
|
refSegInflatedBB.Inflate( m_largestClearance );
|
|
|
|
|
2020-06-17 22:36:54 +00:00
|
|
|
/******************************************/
|
|
|
|
/* Phase 1 : test DRC track to pads : */
|
|
|
|
/******************************************/
|
|
|
|
|
|
|
|
// Compute the min distance to pads
|
|
|
|
for( MODULE* mod : m_board->Modules() )
|
|
|
|
{
|
2020-09-12 19:28:22 +00:00
|
|
|
if( m_drcEngine->IsErrorLimitExceeded( DRCE_CLEARANCE ) )
|
|
|
|
break;
|
|
|
|
|
2020-06-17 22:36:54 +00:00
|
|
|
// Don't preflight at the module level. Getting a module's bounding box goes
|
|
|
|
// through all its pads anyway (so it's no faster), and also all its drawings
|
|
|
|
// (so it's in fact slower).
|
|
|
|
|
|
|
|
for( D_PAD* pad : mod->Pads() )
|
|
|
|
{
|
2020-09-12 19:28:22 +00:00
|
|
|
if( m_drcEngine->IsErrorLimitExceeded( DRCE_CLEARANCE ) )
|
|
|
|
break;
|
|
|
|
|
2020-06-17 22:36:54 +00:00
|
|
|
// Preflight based on bounding boxes.
|
2020-09-17 16:32:42 +00:00
|
|
|
if( !refSegInflatedBB.Intersects( pad->GetBoundingBox() ) )
|
2020-06-17 22:36:54 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// No need to check pads with the same net as the refSeg.
|
|
|
|
if( pad->GetNetCode() && aRefSeg->GetNetCode() == pad->GetNetCode() )
|
|
|
|
continue;
|
|
|
|
|
2020-09-29 17:18:19 +00:00
|
|
|
SHAPE_SEGMENT padCylinder;
|
|
|
|
const SHAPE* padShape;
|
|
|
|
|
2020-09-29 20:40:17 +00:00
|
|
|
if( pad->FlashLayer( aLayer ) )
|
2020-09-29 17:18:19 +00:00
|
|
|
{
|
|
|
|
padShape = pad->GetEffectiveShape().get();
|
|
|
|
}
|
2020-09-30 15:38:35 +00:00
|
|
|
else if( pad->GetAttribute() == PAD_ATTRIB_PTH )
|
2020-09-29 17:18:19 +00:00
|
|
|
{
|
|
|
|
// Note: drill size represents finish size, which means the actual holes size is the
|
|
|
|
// plating thickness larger.
|
|
|
|
padCylinder = *pad->GetEffectiveHoleShape();
|
|
|
|
padCylinder.SetWidth( padCylinder.GetWidth() + bds.GetHolePlatingThickness() );
|
|
|
|
padShape = &padCylinder;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-09-28 22:27:33 +00:00
|
|
|
auto constraint = m_drcEngine->EvalRulesForItems( DRC_CONSTRAINT_TYPE_CLEARANCE,
|
|
|
|
aRefSeg, pad, aLayer );
|
|
|
|
int minClearance = constraint.GetValue().Min();
|
|
|
|
int actual;
|
|
|
|
VECTOR2I pos;
|
2020-06-17 22:36:54 +00:00
|
|
|
|
2020-09-07 12:31:19 +00:00
|
|
|
accountCheck( constraint );
|
|
|
|
|
2020-09-28 22:27:33 +00:00
|
|
|
if( padShape->Collide( &refSeg, minClearance - bds.GetDRCEpsilon(), &actual, &pos ) )
|
2020-06-17 22:36:54 +00:00
|
|
|
{
|
2020-08-11 22:15:50 +00:00
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_CLEARANCE );
|
2020-06-17 22:36:54 +00:00
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
m_msg.Printf( drcItem->GetErrorText() + _( " (%s clearance %s; actual %s)" ),
|
|
|
|
constraint.GetName(),
|
2020-10-02 20:51:24 +00:00
|
|
|
MessageTextFromValue( userUnits(), minClearance ),
|
|
|
|
MessageTextFromValue( userUnits(), actual ) );
|
2020-06-17 22:36:54 +00:00
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
drcItem->SetErrorMessage( m_msg );
|
2020-06-17 22:36:54 +00:00
|
|
|
drcItem->SetItems( aRefSeg, pad );
|
2020-08-11 22:17:43 +00:00
|
|
|
drcItem->SetViolatingRule( constraint.GetParentRule() );
|
2020-06-17 22:36:54 +00:00
|
|
|
|
2020-09-28 22:27:33 +00:00
|
|
|
reportViolation( drcItem, (wxPoint) pos );
|
2020-06-17 22:36:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************/
|
|
|
|
/* Phase 2: test DRC with other track segments */
|
|
|
|
/***********************************************/
|
|
|
|
|
|
|
|
// Test the reference segment with other track segments
|
|
|
|
for( auto it = aStartIt; it != aEndIt; it++ )
|
|
|
|
{
|
2020-09-12 19:28:22 +00:00
|
|
|
if( m_drcEngine->IsErrorLimitExceeded( DRCE_CLEARANCE ) )
|
|
|
|
break;
|
|
|
|
|
2020-06-17 22:36:54 +00:00
|
|
|
TRACK* track = *it;
|
|
|
|
|
2020-09-17 16:32:42 +00:00
|
|
|
if( track->Type() == PCB_VIA_T )
|
|
|
|
{
|
|
|
|
if( !track->GetLayerSet().test( aLayer ) )
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( track->GetLayer() != aLayer )
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-06-17 22:36:54 +00:00
|
|
|
// No problem if segments have the same net code:
|
|
|
|
if( aRefSeg->GetNetCode() == track->GetNetCode() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Preflight based on worst-case inflated bounding boxes:
|
2020-09-17 16:32:42 +00:00
|
|
|
if( !refSegInflatedBB.Intersects( track->GetBoundingBox() ) )
|
2020-06-17 22:36:54 +00:00
|
|
|
continue;
|
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
auto constraint = m_drcEngine->EvalRulesForItems( DRC_CONSTRAINT_TYPE_CLEARANCE,
|
|
|
|
aRefSeg, track, aLayer );
|
|
|
|
int minClearance = constraint.GetValue().Min();
|
|
|
|
int actual;
|
|
|
|
SHAPE_SEGMENT trackSeg( track->GetStart(), track->GetEnd(), track->GetWidth() );
|
2020-09-28 22:27:33 +00:00
|
|
|
VECTOR2I pos;
|
2020-06-17 22:36:54 +00:00
|
|
|
|
2020-09-07 12:31:19 +00:00
|
|
|
accountCheck( constraint );
|
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
/// Check to see if the via has a pad on this layer
|
|
|
|
if( track->Type() == PCB_VIA_T )
|
|
|
|
{
|
|
|
|
VIA* via = static_cast<VIA*>( track );
|
2020-08-11 23:50:56 +00:00
|
|
|
|
2020-09-29 20:40:17 +00:00
|
|
|
if( !via->FlashLayer( aLayer ) )
|
2020-09-11 16:24:27 +00:00
|
|
|
trackSeg.SetWidth( via->GetDrillValue() );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check two tracks crossing first as it reports a DRCE without distances
|
2020-07-15 16:23:56 +00:00
|
|
|
if( OPT_VECTOR2I intersection = refSeg.GetSeg().Intersect( trackSeg.GetSeg() ) )
|
2020-06-17 22:36:54 +00:00
|
|
|
{
|
2020-08-11 22:15:50 +00:00
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_TRACKS_CROSSING );
|
2020-06-17 22:36:54 +00:00
|
|
|
drcItem->SetItems( aRefSeg, track );
|
2020-08-11 22:17:43 +00:00
|
|
|
drcItem->SetViolatingRule( constraint.GetParentRule() );
|
2020-06-17 22:36:54 +00:00
|
|
|
|
2020-09-28 22:27:33 +00:00
|
|
|
reportViolation( drcItem, (wxPoint) intersection.get() );
|
2020-06-17 22:36:54 +00:00
|
|
|
}
|
2020-09-28 22:27:33 +00:00
|
|
|
else if( refSeg.Collide( &trackSeg, minClearance - bds.GetDRCEpsilon(), &actual, &pos ) )
|
2020-06-17 22:36:54 +00:00
|
|
|
{
|
2020-08-11 22:15:50 +00:00
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_CLEARANCE );
|
2020-06-17 22:36:54 +00:00
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
m_msg.Printf( drcItem->GetErrorText() + _( " (%s clearance %s; actual %s)" ),
|
|
|
|
constraint.GetName(),
|
2020-10-02 20:51:24 +00:00
|
|
|
MessageTextFromValue( userUnits(), minClearance ),
|
|
|
|
MessageTextFromValue( userUnits(), actual ) );
|
2020-06-17 22:36:54 +00:00
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
drcItem->SetErrorMessage( m_msg );
|
2020-06-17 22:36:54 +00:00
|
|
|
drcItem->SetItems( aRefSeg, track );
|
2020-08-11 22:17:43 +00:00
|
|
|
drcItem->SetViolatingRule( constraint.GetParentRule() );
|
2020-06-17 22:36:54 +00:00
|
|
|
|
2020-09-28 22:27:33 +00:00
|
|
|
reportViolation( drcItem, (wxPoint) pos );
|
2020-09-14 17:54:14 +00:00
|
|
|
|
|
|
|
if( !m_drcEngine->GetReportAllTrackErrors() )
|
|
|
|
break;
|
2020-06-17 22:36:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************/
|
|
|
|
/* Phase 3: test DRC with copper zones */
|
|
|
|
/***************************************/
|
2020-09-14 17:54:14 +00:00
|
|
|
// Can be *very* time consuming.
|
2020-09-11 16:24:27 +00:00
|
|
|
|
2020-10-03 13:19:42 +00:00
|
|
|
if( m_drcEngine->GetTestTracksAgainstZones()
|
|
|
|
&& ( aRefSeg->Type() != PCB_VIA_T
|
|
|
|
|| static_cast<VIA*>( aRefSeg )->FlashLayer( aLayer )
|
|
|
|
|| static_cast<VIA*>( aRefSeg )->GetDrill() > 0 ) )
|
2020-06-17 22:36:54 +00:00
|
|
|
{
|
|
|
|
SEG testSeg( aRefSeg->GetStart(), aRefSeg->GetEnd() );
|
|
|
|
|
2020-06-18 16:55:22 +00:00
|
|
|
for( ZONE_CONTAINER* zone : m_board->Zones() )
|
2020-06-17 22:36:54 +00:00
|
|
|
{
|
2020-09-12 19:28:22 +00:00
|
|
|
if( m_drcEngine->IsErrorLimitExceeded( DRCE_CLEARANCE ) )
|
|
|
|
break;
|
|
|
|
|
2020-09-21 23:32:07 +00:00
|
|
|
if( !zone->GetLayerSet().test( aLayer ) || zone->GetIsRuleArea() )
|
2020-06-17 22:36:54 +00:00
|
|
|
continue;
|
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
if( zone->GetNetCode() && zone->GetNetCode() == aRefSeg->GetNetCode() )
|
|
|
|
continue;
|
2020-07-03 16:37:08 +00:00
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
if( zone->GetFilledPolysList( aLayer ).IsEmpty() )
|
|
|
|
continue;
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-17 16:32:42 +00:00
|
|
|
if( !refSegInflatedBB.Intersects( zone->GetBoundingBox() ) )
|
|
|
|
continue;
|
|
|
|
|
2020-10-03 13:19:42 +00:00
|
|
|
int halfWidth = refSegWidth / 2;
|
|
|
|
|
|
|
|
if( aRefSeg->Type() == PCB_VIA_T )
|
|
|
|
{
|
|
|
|
VIA* refVia = static_cast<VIA*>( aRefSeg );
|
|
|
|
|
|
|
|
if( !refVia->FlashLayer( aLayer ) )
|
|
|
|
halfWidth = refVia->GetDrill() / 2 + bds.GetHolePlatingThickness();
|
|
|
|
}
|
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
auto constraint = m_drcEngine->EvalRulesForItems( DRC_CONSTRAINT_TYPE_CLEARANCE,
|
|
|
|
aRefSeg, zone, aLayer );
|
2020-09-28 22:27:33 +00:00
|
|
|
int minClearance = constraint.GetValue().Min();
|
|
|
|
int allowedDist = minClearance + halfWidth - bds.GetDRCEpsilon();
|
|
|
|
|
|
|
|
const SHAPE_POLY_SET& zonePoly = zone->GetFilledPolysList( aLayer );
|
|
|
|
int actual;
|
|
|
|
VECTOR2I location;
|
2020-09-07 12:31:19 +00:00
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
accountCheck( constraint );
|
2020-06-17 22:36:54 +00:00
|
|
|
|
2020-09-28 22:27:33 +00:00
|
|
|
if( zonePoly.Collide( testSeg, allowedDist, &actual, &location ) )
|
2020-09-11 16:24:27 +00:00
|
|
|
{
|
|
|
|
actual = std::max( 0, actual - halfWidth );
|
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_CLEARANCE );
|
2020-06-17 22:36:54 +00:00
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
m_msg.Printf( drcItem->GetErrorText() + _( " (%s clearance %s; actual %s)" ),
|
|
|
|
constraint.GetName(),
|
2020-10-02 20:51:24 +00:00
|
|
|
MessageTextFromValue( userUnits(), minClearance ),
|
|
|
|
MessageTextFromValue( userUnits(), actual ) );
|
2020-06-17 22:36:54 +00:00
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
drcItem->SetErrorMessage( m_msg );
|
|
|
|
drcItem->SetItems( aRefSeg, zone );
|
|
|
|
drcItem->SetViolatingRule( constraint.GetParentRule() );
|
2020-06-17 22:36:54 +00:00
|
|
|
|
2020-09-28 22:27:33 +00:00
|
|
|
reportViolation( drcItem, (wxPoint) location );
|
2020-06-17 22:36:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-13 23:28:08 +00:00
|
|
|
|
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
void DRC_TEST_PROVIDER_COPPER_CLEARANCE::testPadClearances( )
|
2020-06-13 23:28:08 +00:00
|
|
|
{
|
2020-09-17 13:36:34 +00:00
|
|
|
const int delta = 25; // This is the number of tests between 2 calls to the progress bar
|
2020-09-11 16:24:27 +00:00
|
|
|
std::vector<D_PAD*> sortedPads;
|
2020-06-13 23:28:08 +00:00
|
|
|
|
|
|
|
m_board->GetSortedPadListByXthenYCoord( sortedPads );
|
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
reportAux( "Testing %d pads...", sortedPads.size());
|
2020-08-11 23:50:56 +00:00
|
|
|
|
2020-06-13 23:28:08 +00:00
|
|
|
if( sortedPads.empty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// find the max size of the pads (used to stop the pad-to-pad tests)
|
|
|
|
int max_size = 0;
|
|
|
|
|
|
|
|
for( D_PAD* pad : sortedPads )
|
|
|
|
{
|
|
|
|
// GetBoundingRadius() is the radius of the minimum sized circle fully containing the pad
|
|
|
|
int radius = pad->GetBoundingRadius();
|
|
|
|
|
|
|
|
if( radius > max_size )
|
|
|
|
max_size = radius;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Better to be fast than accurate; this keeps us from having to look up / calculate the
|
|
|
|
// actual clearances
|
|
|
|
max_size += m_largestClearance;
|
|
|
|
|
|
|
|
// Test the pads
|
2020-09-17 13:36:34 +00:00
|
|
|
for( int idx = 0; idx < (int) sortedPads.size(); idx++ )
|
2020-06-13 23:28:08 +00:00
|
|
|
{
|
2020-09-16 09:15:04 +00:00
|
|
|
D_PAD* pad = sortedPads[idx];
|
|
|
|
|
2020-09-18 19:57:54 +00:00
|
|
|
if( !reportProgress( idx, sortedPads.size(), delta ) )
|
|
|
|
break;
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2020-06-19 21:34:19 +00:00
|
|
|
int x_limit = pad->GetPosition().x + pad->GetBoundingRadius() + max_size;
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2020-09-16 09:15:04 +00:00
|
|
|
doPadToPadsDrc( idx, sortedPads, x_limit );
|
2020-06-13 23:28:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-16 09:15:04 +00:00
|
|
|
void DRC_TEST_PROVIDER_COPPER_CLEARANCE::doPadToPadsDrc( int aRefPadIdx,
|
|
|
|
std::vector<D_PAD*>& aSortedPadsList,
|
|
|
|
int aX_limit )
|
2020-06-13 23:28:08 +00:00
|
|
|
{
|
|
|
|
const static LSET all_cu = LSET::AllCuMask();
|
2020-09-11 16:24:27 +00:00
|
|
|
const BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2020-09-17 16:32:42 +00:00
|
|
|
D_PAD* refPad = aSortedPadsList[aRefPadIdx];
|
|
|
|
LSET layerMask = refPad->GetLayerSet() & all_cu;
|
|
|
|
EDA_RECT refPadInflatedBB = refPad->GetBoundingBox();
|
|
|
|
|
|
|
|
refPadInflatedBB.Inflate( m_largestClearance );
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2020-09-16 09:15:04 +00:00
|
|
|
for( int idx = aRefPadIdx; idx < (int)aSortedPadsList.size(); ++idx )
|
2020-06-13 23:28:08 +00:00
|
|
|
{
|
2020-09-12 19:28:22 +00:00
|
|
|
bool exceedClearance = m_drcEngine->IsErrorLimitExceeded( DRCE_CLEARANCE );
|
|
|
|
bool exceedShorting = m_drcEngine->IsErrorLimitExceeded( DRCE_CLEARANCE );
|
|
|
|
|
|
|
|
if( exceedClearance && exceedShorting )
|
|
|
|
return;
|
|
|
|
|
2020-09-16 09:15:04 +00:00
|
|
|
D_PAD* pad = aSortedPadsList[idx];
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2020-09-16 09:15:04 +00:00
|
|
|
if( pad == refPad )
|
2020-06-13 23:28:08 +00:00
|
|
|
continue;
|
|
|
|
|
2020-09-16 09:15:04 +00:00
|
|
|
// We can stop the test when pad->GetPosition().x > aX_limit
|
|
|
|
// because the list is sorted by X poditions, and other pads are too far.
|
|
|
|
if( pad->GetPosition().x > aX_limit )
|
2020-06-13 23:28:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
// The pad must be in a net (i.e pt_pad->GetNet() != 0 ),
|
|
|
|
// But no problem if pads have the same netcode (same net)
|
2020-09-16 09:15:04 +00:00
|
|
|
if( pad->GetNetCode() && ( refPad->GetNetCode() == pad->GetNetCode() ) )
|
2020-06-13 23:28:08 +00:00
|
|
|
continue;
|
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
// If pads are equivalent (ie: from the same footprint with the same pad number)...
|
2020-09-29 12:07:55 +00:00
|
|
|
if( pad->SameLogicalPadAs( refPad ) )
|
2020-06-13 23:28:08 +00:00
|
|
|
{
|
2020-09-11 16:24:27 +00:00
|
|
|
// ...and have nets, then they must be the same net
|
2020-09-16 09:15:04 +00:00
|
|
|
if( pad->GetNetCode() && refPad->GetNetCode()
|
|
|
|
&& pad->GetNetCode() != refPad->GetNetCode()
|
2020-09-12 19:28:22 +00:00
|
|
|
&& !exceedShorting )
|
2020-07-30 20:41:52 +00:00
|
|
|
{
|
2020-08-11 22:15:50 +00:00
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_SHORTING_ITEMS );
|
2020-07-30 20:41:52 +00:00
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
m_msg.Printf( drcItem->GetErrorText() + _( " (nets %s and %s)" ),
|
2020-09-16 09:15:04 +00:00
|
|
|
pad->GetNetname(), refPad->GetNetname() );
|
2020-09-11 16:24:27 +00:00
|
|
|
|
|
|
|
drcItem->SetErrorMessage( m_msg );
|
2020-09-16 09:15:04 +00:00
|
|
|
drcItem->SetItems( pad, refPad );
|
2020-07-30 20:41:52 +00:00
|
|
|
|
2020-09-16 09:15:04 +00:00
|
|
|
reportViolation( drcItem, refPad->GetPosition());
|
2020-07-30 20:41:52 +00:00
|
|
|
}
|
2020-09-11 16:24:27 +00:00
|
|
|
|
|
|
|
continue;
|
2020-06-13 23:28:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// if either pad has no drill and is only on technical layers, not a clearance violation
|
|
|
|
if( ( ( pad->GetLayerSet() & layerMask ) == 0 && !pad->GetDrillSize().x ) ||
|
2020-09-16 09:15:04 +00:00
|
|
|
( ( refPad->GetLayerSet() & layerMask ) == 0 && !refPad->GetDrillSize().x ) )
|
2020-06-13 23:28:08 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-09-17 16:32:42 +00:00
|
|
|
if( !refPadInflatedBB.Intersects( pad->GetBoundingBox() ) )
|
|
|
|
continue;
|
|
|
|
|
2020-09-16 09:15:04 +00:00
|
|
|
for( PCB_LAYER_ID layer : refPad->GetLayerSet().Seq() )
|
2020-09-11 16:24:27 +00:00
|
|
|
{
|
2020-09-12 19:28:22 +00:00
|
|
|
if( exceedClearance )
|
|
|
|
break;
|
|
|
|
|
2020-09-28 22:27:33 +00:00
|
|
|
auto constraint = m_drcEngine->EvalRulesForItems( DRC_CONSTRAINT_TYPE_CLEARANCE,
|
|
|
|
refPad, pad, layer );
|
|
|
|
int minClearance = constraint.GetValue().Min();
|
|
|
|
int clearanceAllowed = minClearance - bds.GetDRCEpsilon();
|
|
|
|
int actual;
|
|
|
|
VECTOR2I pos;
|
2020-09-07 12:31:19 +00:00
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
accountCheck( constraint );
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2020-09-29 17:18:19 +00:00
|
|
|
SHAPE_SEGMENT refPadCylinder;
|
|
|
|
const SHAPE* refPadShape;
|
|
|
|
|
2020-09-29 20:40:17 +00:00
|
|
|
if( refPad->FlashLayer( layer ) )
|
2020-09-29 17:18:19 +00:00
|
|
|
{
|
|
|
|
refPadShape = refPad->GetEffectiveShape().get();
|
|
|
|
}
|
2020-09-30 15:38:35 +00:00
|
|
|
else if( refPad->GetAttribute() == PAD_ATTRIB_PTH )
|
2020-09-29 17:18:19 +00:00
|
|
|
{
|
|
|
|
// Note: drill size represents finish size, which means the actual holes size is the
|
|
|
|
// plating thickness larger.
|
|
|
|
refPadCylinder = *pad->GetEffectiveHoleShape();
|
|
|
|
refPadCylinder.SetWidth( refPadCylinder.GetWidth() + bds.GetHolePlatingThickness() );
|
|
|
|
refPadShape = &refPadCylinder;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
SHAPE_SEGMENT padCylinder;
|
|
|
|
const SHAPE* padShape;
|
|
|
|
|
2020-09-29 20:40:17 +00:00
|
|
|
if( pad->FlashLayer( layer ) )
|
2020-09-29 17:18:19 +00:00
|
|
|
{
|
|
|
|
padShape = pad->GetEffectiveShape().get();
|
|
|
|
}
|
2020-09-30 15:38:35 +00:00
|
|
|
else if( pad->GetAttribute() == PAD_ATTRIB_PTH )
|
2020-09-29 17:18:19 +00:00
|
|
|
{
|
|
|
|
// Note: drill size represents finish size, which means the actual holes size is the
|
|
|
|
// plating thickness larger.
|
|
|
|
padCylinder = *pad->GetEffectiveHoleShape();
|
|
|
|
padCylinder.SetWidth( padCylinder.GetWidth() + bds.GetHolePlatingThickness() );
|
|
|
|
padShape = &padCylinder;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2020-09-29 17:18:19 +00:00
|
|
|
if( refPadShape->Collide( padShape, clearanceAllowed, &actual, &pos ) )
|
2020-09-11 16:24:27 +00:00
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_CLEARANCE );
|
2020-07-22 23:05:37 +00:00
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
m_msg.Printf( drcItem->GetErrorText() + _( " (%s clearance %s; actual %s)" ),
|
|
|
|
constraint.GetName(),
|
2020-10-02 20:51:24 +00:00
|
|
|
MessageTextFromValue( userUnits(), minClearance ),
|
|
|
|
MessageTextFromValue( userUnits(), actual ) );
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
drcItem->SetErrorMessage( m_msg );
|
2020-09-16 09:15:04 +00:00
|
|
|
drcItem->SetItems( refPad, pad );
|
2020-09-11 16:24:27 +00:00
|
|
|
drcItem->SetViolatingRule( constraint.GetParentRule() );
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2020-09-28 22:27:33 +00:00
|
|
|
reportViolation( drcItem, (wxPoint) pos );
|
2020-09-12 19:28:22 +00:00
|
|
|
break;
|
2020-09-11 16:24:27 +00:00
|
|
|
}
|
2020-06-13 23:28:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
void DRC_TEST_PROVIDER_COPPER_CLEARANCE::testZones()
|
2020-06-18 16:55:22 +00:00
|
|
|
{
|
2020-09-18 19:57:54 +00:00
|
|
|
const int delta = 50; // This is the number of tests between 2 calls to the progress bar
|
|
|
|
|
2020-06-18 16:55:22 +00:00
|
|
|
// Test copper areas for valid netcodes -> fixme, goes to connectivity checks
|
|
|
|
|
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 );
|
|
|
|
std::vector<SHAPE_POLY_SET> smoothed_polys;
|
|
|
|
smoothed_polys.resize( m_board->GetAreaCount() );
|
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;
|
|
|
|
|
2020-09-22 03:40:05 +00:00
|
|
|
for( int ii = 0; ii < m_board->GetAreaCount(); ii++ )
|
2020-06-18 16:55:22 +00:00
|
|
|
{
|
2020-09-22 03:40:05 +00:00
|
|
|
ZONE_CONTAINER* zoneRef = m_board->GetArea( ii );
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-22 03:40:05 +00:00
|
|
|
if( zoneRef->IsOnLayer( layer ) )
|
|
|
|
zoneRef->BuildSmoothedPoly( smoothed_polys[ii], layer );
|
|
|
|
}
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-22 03:40:05 +00:00
|
|
|
// iterate through all areas
|
|
|
|
for( int ia = 0; ia < m_board->GetAreaCount(); ia++ )
|
|
|
|
{
|
|
|
|
if( !reportProgress( ia, m_board->GetAreaCount(), delta ) )
|
|
|
|
break;
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-22 03:40:05 +00:00
|
|
|
ZONE_CONTAINER* zoneRef = m_board->GetArea( ia );
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-22 03:40:05 +00:00
|
|
|
if( !zoneRef->IsOnLayer( layer ) )
|
2020-06-18 16:55:22 +00:00
|
|
|
continue;
|
|
|
|
|
2020-09-22 03:40:05 +00:00
|
|
|
// If we are testing a single zone, then iterate through all other zones
|
|
|
|
// Otherwise, we have already tested the zone combination
|
|
|
|
for( int ia2 = ia + 1; ia2 < m_board->GetAreaCount(); ia2++ )
|
|
|
|
{
|
|
|
|
ZONE_CONTAINER* zoneToTest = m_board->GetArea( ia2 );
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-22 03:40:05 +00:00
|
|
|
if( zoneRef == zoneToTest )
|
|
|
|
continue;
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-22 03:40:05 +00:00
|
|
|
// test for same layer
|
|
|
|
if( !zoneToTest->IsOnLayer( layer ) )
|
|
|
|
continue;
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-22 03:40:05 +00:00
|
|
|
// Test for same net
|
|
|
|
if( zoneRef->GetNetCode() == zoneToTest->GetNetCode() && zoneRef->GetNetCode() >= 0 )
|
|
|
|
continue;
|
2020-09-07 12:31:19 +00:00
|
|
|
|
2020-09-22 03:40:05 +00:00
|
|
|
// test for different priorities
|
|
|
|
if( zoneRef->GetPriority() != zoneToTest->GetPriority() )
|
|
|
|
continue;
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-22 03:40:05 +00:00
|
|
|
// test for different types
|
2020-09-21 23:32:07 +00:00
|
|
|
if( zoneRef->GetIsRuleArea() != zoneToTest->GetIsRuleArea() )
|
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
|
|
|
// Examine a candidate zone: compare zoneToTest to zoneRef
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-22 03:40:05 +00:00
|
|
|
// Get clearance used in zone to zone test.
|
|
|
|
auto constraint = m_drcEngine->EvalRulesForItems( DRC_CONSTRAINT_TYPE_CLEARANCE,
|
|
|
|
zoneRef, zoneToTest );
|
|
|
|
int zone2zoneClearance = constraint.GetValue().Min();
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-22 03:40:05 +00:00
|
|
|
accountCheck( constraint );
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-22 03:40:05 +00:00
|
|
|
// Keepout areas have no clearance, so set zone2zoneClearance to 1
|
|
|
|
// ( zone2zoneClearance = 0 can create problems in test functions)
|
2020-09-21 23:32:07 +00:00
|
|
|
if( zoneRef->GetIsRuleArea() ) // fixme: really?
|
2020-09-22 03:40:05 +00:00
|
|
|
zone2zoneClearance = 1;
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-22 03:40:05 +00:00
|
|
|
// test for some corners of zoneRef inside zoneToTest
|
|
|
|
for( auto iterator = smoothed_polys[ia].IterateWithHoles(); iterator; iterator++ )
|
|
|
|
{
|
|
|
|
VECTOR2I currentVertex = *iterator;
|
|
|
|
wxPoint pt( currentVertex.x, currentVertex.y );
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-22 03:40:05 +00:00
|
|
|
if( smoothed_polys[ia2].Contains( currentVertex ) )
|
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_ZONES_INTERSECT );
|
|
|
|
drcItem->SetItems( zoneRef, zoneToTest );
|
|
|
|
drcItem->SetViolatingRule( constraint.GetParentRule() );
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-22 03:40:05 +00:00
|
|
|
reportViolation( drcItem, pt );
|
|
|
|
}
|
|
|
|
}
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-22 03:40:05 +00:00
|
|
|
// test for some corners of zoneToTest inside zoneRef
|
|
|
|
for( auto iterator = smoothed_polys[ia2].IterateWithHoles(); iterator; iterator++ )
|
2020-06-18 16:55:22 +00:00
|
|
|
{
|
2020-09-22 03:40:05 +00:00
|
|
|
VECTOR2I currentVertex = *iterator;
|
|
|
|
wxPoint pt( currentVertex.x, currentVertex.y );
|
|
|
|
|
|
|
|
if( smoothed_polys[ia].Contains( currentVertex ) )
|
2020-06-18 16:55:22 +00:00
|
|
|
{
|
2020-09-22 03:40:05 +00:00
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_ZONES_INTERSECT );
|
|
|
|
drcItem->SetItems( zoneToTest, zoneRef );
|
|
|
|
drcItem->SetViolatingRule( constraint.GetParentRule() );
|
|
|
|
|
|
|
|
reportViolation( drcItem, pt );
|
2020-06-18 16:55:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-22 03:40:05 +00:00
|
|
|
// Iterate through all the segments of refSmoothedPoly
|
|
|
|
std::map<wxPoint, int> conflictPoints;
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-22 03:40:05 +00:00
|
|
|
for( auto refIt = smoothed_polys[ia].IterateSegmentsWithHoles(); refIt; refIt++ )
|
2020-06-18 16:55:22 +00:00
|
|
|
{
|
2020-09-22 03:40:05 +00:00
|
|
|
// Build ref segment
|
|
|
|
SEG refSegment = *refIt;
|
|
|
|
|
|
|
|
// Iterate through all the segments in smoothed_polys[ia2]
|
|
|
|
for( auto testIt = smoothed_polys[ia2].IterateSegmentsWithHoles(); testIt; testIt++ )
|
|
|
|
{
|
|
|
|
// Build test segment
|
|
|
|
SEG testSegment = *testIt;
|
|
|
|
wxPoint pt;
|
|
|
|
|
|
|
|
int ax1, ay1, ax2, ay2;
|
|
|
|
ax1 = refSegment.A.x;
|
|
|
|
ay1 = refSegment.A.y;
|
|
|
|
ax2 = refSegment.B.x;
|
|
|
|
ay2 = refSegment.B.y;
|
|
|
|
|
|
|
|
int bx1, by1, bx2, by2;
|
|
|
|
bx1 = testSegment.A.x;
|
|
|
|
by1 = testSegment.A.y;
|
|
|
|
bx2 = testSegment.B.x;
|
|
|
|
by2 = testSegment.B.y;
|
|
|
|
|
|
|
|
int d = GetClearanceBetweenSegments( bx1, by1, bx2, by2,
|
|
|
|
0,
|
|
|
|
ax1, ay1, ax2, ay2,
|
|
|
|
0,
|
|
|
|
zone2zoneClearance,
|
|
|
|
&pt.x, &pt.y );
|
|
|
|
|
|
|
|
if( d < zone2zoneClearance )
|
|
|
|
{
|
|
|
|
if( conflictPoints.count( pt ) )
|
|
|
|
conflictPoints[ pt ] = std::min( conflictPoints[ pt ], d );
|
|
|
|
else
|
|
|
|
conflictPoints[ pt ] = d;
|
|
|
|
}
|
|
|
|
}
|
2020-06-18 16:55:22 +00:00
|
|
|
}
|
2020-09-22 03:40:05 +00:00
|
|
|
|
|
|
|
for( const std::pair<const wxPoint, int>& conflict : conflictPoints )
|
2020-06-18 16:55:22 +00:00
|
|
|
{
|
2020-09-22 03:40:05 +00:00
|
|
|
int actual = conflict.second;
|
|
|
|
std::shared_ptr<DRC_ITEM> drcItem;
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-22 03:40:05 +00:00
|
|
|
if( actual <= 0 )
|
|
|
|
{
|
|
|
|
drcItem = DRC_ITEM::Create( DRCE_ZONES_INTERSECT );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
drcItem = DRC_ITEM::Create( DRCE_CLEARANCE );
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-22 03:40:05 +00:00
|
|
|
m_msg.Printf( drcItem->GetErrorText() + _( " (%s clearance %s; actual %s)" ),
|
|
|
|
constraint.GetName(),
|
2020-10-02 20:51:24 +00:00
|
|
|
MessageTextFromValue( userUnits(), zone2zoneClearance ),
|
|
|
|
MessageTextFromValue( userUnits(), conflict.second ) );
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-22 03:40:05 +00:00
|
|
|
drcItem->SetErrorMessage( m_msg );
|
|
|
|
}
|
|
|
|
|
|
|
|
drcItem->SetItems( zoneRef, zoneToTest );
|
|
|
|
drcItem->SetViolatingRule( constraint.GetParentRule() );
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2020-09-22 03:40:05 +00:00
|
|
|
reportViolation( drcItem, conflict.first );
|
|
|
|
}
|
2020-06-18 16:55:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
int DRC_TEST_PROVIDER_COPPER_CLEARANCE::GetNumPhases() const
|
|
|
|
{
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-13 10:37:20 +00:00
|
|
|
std::set<DRC_CONSTRAINT_TYPE_T> DRC_TEST_PROVIDER_COPPER_CLEARANCE::GetConstraintTypes() const
|
2020-06-13 23:28:08 +00:00
|
|
|
{
|
2020-09-13 10:37:20 +00:00
|
|
|
return { DRC_CONSTRAINT_TYPE_CLEARANCE };
|
2020-06-13 23:28:08 +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
|
|
|
}
|