2010-09-20 16:21:47 +00:00
|
|
|
/*
|
2011-09-30 18:15:37 +00:00
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
2010-09-20 16:21:47 +00:00
|
|
|
*
|
2019-06-06 11:10:24 +00:00
|
|
|
* Copyright (C) 2004-2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2010-09-20 16:21:47 +00:00
|
|
|
* Copyright (C) 2007 Dick Hollenbeck, dick@softplc.com
|
2019-06-04 10:45:43 +00:00
|
|
|
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2010-09-20 16:21:47 +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
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <trigo.h>
|
2020-02-19 09:31:32 +00:00
|
|
|
#include <drc/drc.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_track.h>
|
2019-06-04 11:52:03 +00:00
|
|
|
#include <class_drawsegment.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_marker_pcb.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <geometry/polygon_test_point_inside.h>
|
2020-04-26 14:08:11 +00:00
|
|
|
#include <geometry/shape_rect.h>
|
2020-07-04 18:48:22 +00:00
|
|
|
#include <geometry/shape_segment.h>
|
|
|
|
#include <convert_basic_shapes_to_polygon.h>
|
2010-09-20 16:21:47 +00:00
|
|
|
|
|
|
|
|
2020-05-18 00:20:16 +00:00
|
|
|
void DRC::doTrackDrc( BOARD_COMMIT& aCommit, TRACK* aRefSeg, TRACKS::iterator aStartIt,
|
|
|
|
TRACKS::iterator aEndIt, bool aTestZones )
|
2010-09-20 16:21:47 +00:00
|
|
|
{
|
2020-05-15 23:25:33 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_pcb->GetDesignSettings();
|
|
|
|
|
2020-07-04 18:48:22 +00:00
|
|
|
SHAPE_SEGMENT refSeg( aRefSeg->GetStart(), aRefSeg->GetEnd(), aRefSeg->GetWidth() );
|
|
|
|
PCB_LAYER_ID refLayer = aRefSeg->GetLayer();
|
|
|
|
LSET refLayerSet = aRefSeg->GetLayerSet();
|
2020-05-18 00:20:16 +00:00
|
|
|
|
2020-07-04 18:48:22 +00:00
|
|
|
EDA_RECT refSegBB = aRefSeg->GetBoundingBox();
|
|
|
|
int refSegWidth = aRefSeg->GetWidth();
|
2010-09-20 16:21:47 +00:00
|
|
|
|
2019-06-25 02:19:27 +00:00
|
|
|
|
2018-08-23 22:41:57 +00:00
|
|
|
/******************************************/
|
|
|
|
/* Phase 0 : via DRC tests : */
|
|
|
|
/******************************************/
|
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
if( aRefSeg->Type() == PCB_VIA_T )
|
2010-09-20 16:21:47 +00:00
|
|
|
{
|
2020-05-18 00:20:16 +00:00
|
|
|
VIA *refvia = static_cast<VIA*>( aRefSeg );
|
|
|
|
int viaAnnulus = ( refvia->GetWidth() - refvia->GetDrill() ) / 2;
|
2020-08-07 20:18:33 +00:00
|
|
|
int minAnnulus = refvia->GetMinAnnulus( refvia->GetLayer(), &m_clearanceSource );
|
2018-08-27 13:50:50 +00:00
|
|
|
|
2010-09-20 16:21:47 +00:00
|
|
|
// test if the via size is smaller than minimum
|
2019-12-28 00:55:11 +00:00
|
|
|
if( refvia->GetViaType() == VIATYPE::MICROVIA )
|
2010-09-20 16:21:47 +00:00
|
|
|
{
|
2020-05-15 23:25:33 +00:00
|
|
|
if( viaAnnulus < minAnnulus )
|
|
|
|
{
|
2020-06-08 02:19:46 +00:00
|
|
|
DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_VIA_ANNULUS );
|
2020-05-15 23:25:33 +00:00
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
m_msg.Printf( _( "Via annulus too small (%s %s; actual %s)" ),
|
2020-05-18 00:20:16 +00:00
|
|
|
m_clearanceSource,
|
|
|
|
MessageTextFromValue( userUnits(), minAnnulus, true ),
|
|
|
|
MessageTextFromValue( userUnits(), viaAnnulus, true ) );
|
2020-05-15 23:25:33 +00:00
|
|
|
|
2020-05-18 00:20:16 +00:00
|
|
|
drcItem->SetErrorMessage( m_msg );
|
2020-05-15 23:25:33 +00:00
|
|
|
drcItem->SetItems( refvia );
|
|
|
|
|
|
|
|
MARKER_PCB* marker = new MARKER_PCB( drcItem, refvia->GetPosition() );
|
2020-05-18 00:20:16 +00:00
|
|
|
addMarkerToPcb( aCommit, marker );
|
2020-05-15 23:25:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( refvia->GetWidth() < bds.m_MicroViasMinSize )
|
2010-09-20 16:21:47 +00:00
|
|
|
{
|
2020-06-08 02:19:46 +00:00
|
|
|
DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_TOO_SMALL_MICROVIA );
|
2020-04-26 10:30:32 +00:00
|
|
|
|
2020-05-18 00:20:16 +00:00
|
|
|
m_msg.Printf( drcItem->GetErrorText() + _( " (board minimum %s; actual %s)" ),
|
|
|
|
MessageTextFromValue( userUnits(), bds.m_MicroViasMinSize, true ),
|
|
|
|
MessageTextFromValue( userUnits(), refvia->GetWidth(), true ) );
|
2020-04-26 10:30:32 +00:00
|
|
|
|
2020-05-18 00:20:16 +00:00
|
|
|
drcItem->SetErrorMessage( m_msg );
|
2020-04-24 13:36:10 +00:00
|
|
|
drcItem->SetItems( refvia );
|
|
|
|
|
|
|
|
MARKER_PCB* marker = new MARKER_PCB( drcItem, refvia->GetPosition() );
|
2020-05-18 00:20:16 +00:00
|
|
|
addMarkerToPcb( aCommit, marker );
|
2010-09-20 16:21:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-15 23:25:33 +00:00
|
|
|
if( bds.m_ViasMinAnnulus > minAnnulus )
|
|
|
|
{
|
|
|
|
minAnnulus = bds.m_ViasMinAnnulus;
|
2020-05-22 10:31:14 +00:00
|
|
|
m_clearanceSource = _( "board minimum" );
|
2020-05-15 23:25:33 +00:00
|
|
|
}
|
2020-05-11 19:39:30 +00:00
|
|
|
|
2020-05-15 23:25:33 +00:00
|
|
|
if( viaAnnulus < minAnnulus )
|
2020-05-11 19:39:30 +00:00
|
|
|
{
|
2020-06-08 02:19:46 +00:00
|
|
|
DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_VIA_ANNULUS );
|
2020-05-11 19:39:30 +00:00
|
|
|
|
2020-07-06 11:47:42 +00:00
|
|
|
m_msg.Printf( _( "Via annulus too small (%s %s; actual %s)" ),
|
2020-05-18 00:20:16 +00:00
|
|
|
m_clearanceSource,
|
|
|
|
MessageTextFromValue( userUnits(), minAnnulus, true ),
|
|
|
|
MessageTextFromValue( userUnits(), viaAnnulus, true ) );
|
2020-05-11 19:39:30 +00:00
|
|
|
|
2020-05-18 00:20:16 +00:00
|
|
|
drcItem->SetErrorMessage( m_msg );
|
2020-05-11 19:39:30 +00:00
|
|
|
drcItem->SetItems( refvia );
|
|
|
|
|
|
|
|
MARKER_PCB* marker = new MARKER_PCB( drcItem, refvia->GetPosition() );
|
2020-05-18 00:20:16 +00:00
|
|
|
addMarkerToPcb( aCommit, marker );
|
2020-05-11 19:39:30 +00:00
|
|
|
}
|
|
|
|
|
2020-05-15 23:25:33 +00:00
|
|
|
if( refvia->GetWidth() < bds.m_ViasMinSize )
|
2010-09-20 16:21:47 +00:00
|
|
|
{
|
2020-06-08 02:19:46 +00:00
|
|
|
DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_TOO_SMALL_VIA );
|
2020-04-26 10:30:32 +00:00
|
|
|
|
2020-05-18 00:20:16 +00:00
|
|
|
m_msg.Printf( drcItem->GetErrorText() + _( " (board minimum %s; actual %s)" ),
|
|
|
|
MessageTextFromValue( userUnits(), bds.m_ViasMinSize, true ),
|
|
|
|
MessageTextFromValue( userUnits(), refvia->GetWidth(), true ) );
|
2020-04-26 10:30:32 +00:00
|
|
|
|
2020-05-18 00:20:16 +00:00
|
|
|
drcItem->SetErrorMessage( m_msg );
|
2020-04-24 13:36:10 +00:00
|
|
|
drcItem->SetItems( refvia );
|
|
|
|
|
|
|
|
MARKER_PCB* marker = new MARKER_PCB( drcItem, refvia->GetPosition() );
|
2020-05-18 00:20:16 +00:00
|
|
|
addMarkerToPcb( aCommit, marker );
|
2010-09-20 16:21:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// test if via's hole is bigger than its diameter
|
|
|
|
// This test is necessary since the via hole size and width can be modified
|
|
|
|
// and a default via hole can be bigger than some vias sizes
|
2014-04-25 06:00:04 +00:00
|
|
|
if( refvia->GetDrillValue() > refvia->GetWidth() )
|
2010-09-20 16:21:47 +00:00
|
|
|
{
|
2020-06-08 02:19:46 +00:00
|
|
|
DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_VIA_HOLE_BIGGER );
|
2020-04-26 10:30:32 +00:00
|
|
|
|
2020-05-18 00:20:16 +00:00
|
|
|
m_msg.Printf( drcItem->GetErrorText() + _( " (diameter %s; drill %s)" ),
|
|
|
|
MessageTextFromValue( userUnits(), refvia->GetWidth(), true ),
|
|
|
|
MessageTextFromValue( userUnits(), refvia->GetDrillValue(), true ) );
|
2020-04-26 10:30:32 +00:00
|
|
|
|
2020-05-18 00:20:16 +00:00
|
|
|
drcItem->SetErrorMessage( m_msg );
|
2020-04-24 13:36:10 +00:00
|
|
|
drcItem->SetItems( refvia );
|
|
|
|
|
|
|
|
MARKER_PCB* marker = new MARKER_PCB( drcItem, refvia->GetPosition() );
|
2020-05-18 00:20:16 +00:00
|
|
|
addMarkerToPcb( aCommit, marker );
|
2010-09-20 16:21:47 +00:00
|
|
|
}
|
|
|
|
|
2018-01-06 23:37:24 +00:00
|
|
|
// test if the type of via is allowed due to design rules
|
2020-05-15 23:25:33 +00:00
|
|
|
if( refvia->GetViaType() == VIATYPE::MICROVIA && !bds.m_MicroViasAllowed )
|
2018-01-06 23:37:24 +00:00
|
|
|
{
|
2020-06-08 02:19:46 +00:00
|
|
|
DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_ALLOWED_ITEMS );
|
2020-05-01 17:48:36 +00:00
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
m_msg.Printf( _( "Microvia not allowed (board design rule constraints)" ) );
|
2020-05-18 00:20:16 +00:00
|
|
|
drcItem->SetErrorMessage( m_msg );
|
2020-04-24 13:36:10 +00:00
|
|
|
drcItem->SetItems( refvia );
|
|
|
|
|
|
|
|
MARKER_PCB* marker = new MARKER_PCB( drcItem, refvia->GetPosition() );
|
2020-05-18 00:20:16 +00:00
|
|
|
addMarkerToPcb( aCommit, marker );
|
2018-01-06 23:37:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// test if the type of via is allowed due to design rules
|
2020-05-15 23:25:33 +00:00
|
|
|
if( refvia->GetViaType() == VIATYPE::BLIND_BURIED && !bds.m_BlindBuriedViaAllowed )
|
2018-01-06 23:37:24 +00:00
|
|
|
{
|
2020-06-08 02:19:46 +00:00
|
|
|
DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_ALLOWED_ITEMS );
|
2020-05-01 17:48:36 +00:00
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
m_msg.Printf( _( "Blind/buried via not allowed (board design rule constraints)" ) );
|
2020-05-18 00:20:16 +00:00
|
|
|
drcItem->SetErrorMessage( m_msg );
|
2020-04-24 13:36:10 +00:00
|
|
|
drcItem->SetItems( refvia );
|
|
|
|
|
|
|
|
MARKER_PCB* marker = new MARKER_PCB( drcItem, refvia->GetPosition() );
|
2020-05-18 00:20:16 +00:00
|
|
|
addMarkerToPcb( aCommit, marker );
|
2018-01-06 23:37:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-20 16:21:47 +00:00
|
|
|
// For microvias: test if they are blind vias and only between 2 layers
|
|
|
|
// because they are used for very small drill size and are drill by laser
|
|
|
|
// and **only one layer** can be drilled
|
2019-12-28 00:55:11 +00:00
|
|
|
if( refvia->GetViaType() == VIATYPE::MICROVIA )
|
2010-09-20 16:21:47 +00:00
|
|
|
{
|
2020-04-29 19:17:59 +00:00
|
|
|
PCB_LAYER_ID layer1, layer2;
|
|
|
|
bool err = true;
|
2010-09-20 16:21:47 +00:00
|
|
|
|
2014-04-25 06:00:04 +00:00
|
|
|
refvia->LayerPair( &layer1, &layer2 );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
|
|
|
if( layer1 > layer2 )
|
2015-06-26 13:41:56 +00:00
|
|
|
std::swap( layer1, layer2 );
|
2010-09-20 16:21:47 +00:00
|
|
|
|
2020-05-15 23:25:33 +00:00
|
|
|
if( layer2 == B_Cu && layer1 == bds.GetCopperLayerCount() - 2 )
|
2014-06-24 16:17:18 +00:00
|
|
|
err = false;
|
|
|
|
else if( layer1 == F_Cu && layer2 == In1_Cu )
|
2010-09-20 16:21:47 +00:00
|
|
|
err = false;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-09-20 16:21:47 +00:00
|
|
|
if( err )
|
|
|
|
{
|
2020-06-08 02:19:46 +00:00
|
|
|
DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_PADSTACK );
|
2020-04-29 19:17:59 +00:00
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
m_msg.Printf( _( "Microvia through too many layers (%s and %s not adjacent)" ),
|
2020-05-18 00:20:16 +00:00
|
|
|
m_pcb->GetLayerName( layer1 ),
|
|
|
|
m_pcb->GetLayerName( layer2 ) );
|
2020-04-29 19:17:59 +00:00
|
|
|
|
2020-05-18 00:20:16 +00:00
|
|
|
drcItem->SetErrorMessage( m_msg );
|
2020-04-24 13:36:10 +00:00
|
|
|
drcItem->SetItems( refvia );
|
|
|
|
|
|
|
|
MARKER_PCB* marker = new MARKER_PCB( drcItem, refvia->GetPosition() );
|
2020-05-18 00:20:16 +00:00
|
|
|
addMarkerToPcb( aCommit, marker );
|
2010-09-20 16:21:47 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-06 23:37:24 +00:00
|
|
|
|
2010-09-20 16:21:47 +00:00
|
|
|
}
|
|
|
|
else // This is a track segment
|
|
|
|
{
|
2020-05-23 21:48:24 +00:00
|
|
|
int minWidth, maxWidth;
|
|
|
|
aRefSeg->GetWidthConstraints( &minWidth, &maxWidth, &m_clearanceSource );
|
|
|
|
|
|
|
|
int errorCode = 0;
|
|
|
|
int constraintWidth;
|
2020-05-15 23:25:33 +00:00
|
|
|
|
|
|
|
if( refSegWidth < minWidth )
|
2020-05-23 21:48:24 +00:00
|
|
|
{
|
2020-06-08 02:19:46 +00:00
|
|
|
errorCode = DRCE_TRACK_WIDTH;
|
2020-05-23 21:48:24 +00:00
|
|
|
constraintWidth = minWidth;
|
|
|
|
}
|
|
|
|
else if( refSegWidth > maxWidth )
|
|
|
|
{
|
2020-06-08 02:19:46 +00:00
|
|
|
errorCode = DRCE_TRACK_WIDTH;
|
2020-05-23 21:48:24 +00:00
|
|
|
constraintWidth = maxWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( errorCode )
|
2010-09-20 16:21:47 +00:00
|
|
|
{
|
2018-08-27 13:50:50 +00:00
|
|
|
wxPoint refsegMiddle = ( aRefSeg->GetStart() + aRefSeg->GetEnd() ) / 2;
|
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
DRC_ITEM* drcItem = DRC_ITEM::Create( errorCode );
|
2020-04-26 10:30:32 +00:00
|
|
|
|
2020-05-22 10:31:14 +00:00
|
|
|
m_msg.Printf( drcItem->GetErrorText() + _( " (%s %s; actual %s)" ),
|
2020-05-18 00:20:16 +00:00
|
|
|
m_clearanceSource,
|
2020-05-23 21:48:24 +00:00
|
|
|
MessageTextFromValue( userUnits(), constraintWidth, true ),
|
2020-05-18 00:20:16 +00:00
|
|
|
MessageTextFromValue( userUnits(), refSegWidth, true ) );
|
2020-04-26 10:30:32 +00:00
|
|
|
|
2020-05-18 00:20:16 +00:00
|
|
|
drcItem->SetErrorMessage( m_msg );
|
2020-04-24 13:36:10 +00:00
|
|
|
drcItem->SetItems( aRefSeg );
|
|
|
|
|
|
|
|
MARKER_PCB* marker = new MARKER_PCB( drcItem, refsegMiddle );
|
2020-05-18 00:20:16 +00:00
|
|
|
addMarkerToPcb( aCommit, marker );
|
2010-09-20 16:21:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************/
|
|
|
|
/* Phase 1 : test DRC track to pads : */
|
|
|
|
/******************************************/
|
|
|
|
|
|
|
|
// Compute the min distance to pads
|
2019-06-25 02:19:27 +00:00
|
|
|
for( MODULE* mod : m_pcb->Modules() )
|
2010-09-20 16:21:47 +00:00
|
|
|
{
|
2020-04-26 14:38:41 +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).
|
|
|
|
|
2019-06-25 02:19:27 +00:00
|
|
|
for( D_PAD* pad : mod->Pads() )
|
2010-09-20 16:21:47 +00:00
|
|
|
{
|
2020-04-26 14:38:41 +00:00
|
|
|
// Preflight based on bounding boxes.
|
|
|
|
EDA_RECT inflatedBB = refSegBB;
|
2020-05-18 00:20:16 +00:00
|
|
|
inflatedBB.Inflate( pad->GetBoundingRadius() + m_largestClearance );
|
2020-04-26 14:38:41 +00:00
|
|
|
|
|
|
|
if( !inflatedBB.Contains( pad->GetPosition() ) )
|
|
|
|
continue;
|
|
|
|
|
2020-05-18 00:20:16 +00:00
|
|
|
if( !( pad->GetLayerSet() & refLayerSet ).any() )
|
2020-04-27 17:03:38 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// No need to check pads with the same net as the refSeg.
|
|
|
|
if( pad->GetNetCode() && aRefSeg->GetNetCode() == pad->GetNetCode() )
|
|
|
|
continue;
|
|
|
|
|
2020-04-26 10:30:32 +00:00
|
|
|
if( pad->GetDrillSize().x > 0 )
|
2010-09-20 16:21:47 +00:00
|
|
|
{
|
2020-08-07 20:18:33 +00:00
|
|
|
const SHAPE_SEGMENT* slot = pad->GetEffectiveHoleShape();
|
|
|
|
const DRC_CONSTRAINT* constraint = GetConstraint( aRefSeg, pad,
|
|
|
|
DRC_RULE_ID_CLEARANCE, refLayer,
|
|
|
|
&m_clearanceSource );
|
2020-07-04 18:48:22 +00:00
|
|
|
int minClearance;
|
|
|
|
int actual;
|
2020-06-03 11:11:50 +00:00
|
|
|
|
2020-08-07 20:18:33 +00:00
|
|
|
if( constraint )
|
2020-06-03 11:11:50 +00:00
|
|
|
{
|
2020-08-07 20:18:33 +00:00
|
|
|
m_clearanceSource = wxString::Format( _( "'%s' rule" ), m_clearanceSource );
|
|
|
|
minClearance = constraint->m_Value.Min();
|
2020-06-03 11:11:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-07 20:18:33 +00:00
|
|
|
minClearance = aRefSeg->GetClearance( refLayer, nullptr,
|
|
|
|
&m_clearanceSource );
|
2020-06-03 11:11:50 +00:00
|
|
|
}
|
2020-04-27 16:22:42 +00:00
|
|
|
|
2020-07-04 18:48:22 +00:00
|
|
|
if( slot->Collide( &refSeg, minClearance + bds.GetDRCEpsilon(), &actual ) )
|
2010-09-20 16:21:47 +00:00
|
|
|
{
|
2020-06-08 02:19:46 +00:00
|
|
|
DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_CLEARANCE );
|
2020-04-26 10:30:32 +00:00
|
|
|
|
2020-05-21 17:42:42 +00:00
|
|
|
m_msg.Printf( drcItem->GetErrorText() + _( " (%s clearance %s; actual %s)" ),
|
2020-05-18 00:20:16 +00:00
|
|
|
m_clearanceSource,
|
|
|
|
MessageTextFromValue( userUnits(), minClearance, true ),
|
|
|
|
MessageTextFromValue( userUnits(), actual, true ) );
|
2020-04-26 10:30:32 +00:00
|
|
|
|
2020-05-18 00:20:16 +00:00
|
|
|
drcItem->SetErrorMessage( m_msg );
|
2020-04-24 13:36:10 +00:00
|
|
|
drcItem->SetItems( aRefSeg, pad );
|
|
|
|
|
2020-07-04 18:48:22 +00:00
|
|
|
MARKER_PCB* marker = new MARKER_PCB( drcItem, pad->GetPosition() );
|
2020-05-18 00:20:16 +00:00
|
|
|
addMarkerToPcb( aCommit, marker );
|
2018-08-27 13:50:50 +00:00
|
|
|
|
2020-02-28 00:05:40 +00:00
|
|
|
if( !m_reportAllTrackErrors )
|
|
|
|
return;
|
2010-09-20 16:21:47 +00:00
|
|
|
}
|
2020-04-26 10:30:32 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2020-08-07 20:18:33 +00:00
|
|
|
int minClearance = aRefSeg->GetClearance( aRefSeg->GetLayer(), pad,
|
|
|
|
&m_clearanceSource );
|
2020-05-18 00:20:16 +00:00
|
|
|
int actual;
|
2010-09-20 16:21:47 +00:00
|
|
|
|
2020-07-04 18:48:22 +00:00
|
|
|
if( pad->Collide( &refSeg, minClearance - bds.GetDRCEpsilon(), &actual ) )
|
2010-09-20 16:21:47 +00:00
|
|
|
{
|
2020-06-08 02:19:46 +00:00
|
|
|
DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_CLEARANCE );
|
2020-04-26 10:30:32 +00:00
|
|
|
|
2020-05-21 17:42:42 +00:00
|
|
|
m_msg.Printf( drcItem->GetErrorText() + _( " (%s clearance %s; actual %s)" ),
|
2020-05-18 00:20:16 +00:00
|
|
|
m_clearanceSource,
|
|
|
|
MessageTextFromValue( userUnits(), minClearance, true ),
|
|
|
|
MessageTextFromValue( userUnits(), actual, true ) );
|
2020-04-26 10:30:32 +00:00
|
|
|
|
2020-05-18 00:20:16 +00:00
|
|
|
drcItem->SetErrorMessage( m_msg );
|
2020-04-24 13:36:10 +00:00
|
|
|
drcItem->SetItems( aRefSeg, pad );
|
|
|
|
|
2020-07-04 18:48:22 +00:00
|
|
|
MARKER_PCB* marker = new MARKER_PCB( drcItem, pad->GetPosition() );
|
2020-05-18 00:20:16 +00:00
|
|
|
addMarkerToPcb( aCommit, marker );
|
2018-08-27 13:50:50 +00:00
|
|
|
|
2020-02-28 00:05:40 +00:00
|
|
|
if( !m_reportAllTrackErrors )
|
|
|
|
return;
|
2010-09-20 16:21:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************/
|
|
|
|
/* Phase 2: test DRC with other track segments */
|
|
|
|
/***********************************************/
|
|
|
|
|
|
|
|
// Test the reference segment with other track segments
|
2019-05-31 02:30:28 +00:00
|
|
|
for( auto it = aStartIt; it != aEndIt; it++ )
|
2010-09-20 16:21:47 +00:00
|
|
|
{
|
2020-04-26 10:30:32 +00:00
|
|
|
TRACK* track = *it;
|
|
|
|
|
2010-09-20 16:21:47 +00:00
|
|
|
// No problem if segments have the same net code:
|
2020-04-26 12:21:37 +00:00
|
|
|
if( aRefSeg->GetNetCode() == track->GetNetCode() )
|
2010-09-20 16:21:47 +00:00
|
|
|
continue;
|
|
|
|
|
2020-04-26 14:38:41 +00:00
|
|
|
// No problem if tracks are on different layers:
|
2020-05-18 00:20:16 +00:00
|
|
|
// Note that while the general case of GetLayerSet intersection always works,
|
|
|
|
// the others are much faster.
|
|
|
|
bool sameLayers;
|
|
|
|
|
|
|
|
if( aRefSeg->Type() == PCB_VIA_T )
|
|
|
|
{
|
|
|
|
if( track->Type() == PCB_VIA_T )
|
|
|
|
sameLayers = ( refLayerSet & track->GetLayerSet() ).any();
|
|
|
|
else
|
|
|
|
sameLayers = refLayerSet.test( track->GetLayer() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( track->Type() == PCB_VIA_T )
|
|
|
|
sameLayers = track->GetLayerSet().test( refLayer );
|
|
|
|
else
|
|
|
|
sameLayers = track->GetLayer() == refLayer;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !sameLayers )
|
2010-09-20 16:21:47 +00:00
|
|
|
continue;
|
|
|
|
|
2020-05-18 00:20:16 +00:00
|
|
|
// Preflight based on worst-case inflated bounding boxes:
|
2020-04-26 14:38:41 +00:00
|
|
|
EDA_RECT trackBB = track->GetBoundingBox();
|
2020-05-18 00:20:16 +00:00
|
|
|
trackBB.Inflate( m_largestClearance );
|
2020-04-26 14:38:41 +00:00
|
|
|
|
|
|
|
if( !trackBB.Intersects( refSegBB ) )
|
|
|
|
continue;
|
|
|
|
|
2020-08-07 20:18:33 +00:00
|
|
|
int minClearance = aRefSeg->GetClearance( aRefSeg->GetLayer(), track,
|
|
|
|
&m_clearanceSource );
|
2020-07-04 18:48:22 +00:00
|
|
|
int actual;
|
|
|
|
SHAPE_SEGMENT trackSeg( track->GetStart(), track->GetEnd(), track->GetWidth() );
|
2018-08-27 13:50:50 +00:00
|
|
|
|
2020-04-26 10:30:32 +00:00
|
|
|
// Check two tracks crossing first as it reports a DRCE without distances
|
2020-07-04 18:48:22 +00:00
|
|
|
if( OPT_VECTOR2I intersection = refSeg.GetSeg().Intersect( trackSeg.GetSeg() ) )
|
2010-09-20 16:21:47 +00:00
|
|
|
{
|
2020-06-08 02:19:46 +00:00
|
|
|
DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_TRACKS_CROSSING );
|
2020-05-18 00:20:16 +00:00
|
|
|
drcItem->SetErrorMessage( m_msg );
|
2020-04-24 13:36:10 +00:00
|
|
|
drcItem->SetItems( aRefSeg, track );
|
|
|
|
|
2020-04-26 10:30:32 +00:00
|
|
|
MARKER_PCB* marker = new MARKER_PCB( drcItem, (wxPoint) intersection.get() );
|
2020-05-18 00:20:16 +00:00
|
|
|
addMarkerToPcb( aCommit, marker );
|
2018-08-27 13:50:50 +00:00
|
|
|
|
2020-02-28 00:05:40 +00:00
|
|
|
if( !m_reportAllTrackErrors )
|
|
|
|
return;
|
2010-09-20 16:21:47 +00:00
|
|
|
}
|
2020-07-04 18:48:22 +00:00
|
|
|
else if( refSeg.Collide( &trackSeg, minClearance, &actual ) )
|
2010-09-20 16:21:47 +00:00
|
|
|
{
|
2020-07-04 18:48:22 +00:00
|
|
|
wxPoint pos = GetLocation( aRefSeg, trackSeg.GetSeg() );
|
2020-06-08 02:19:46 +00:00
|
|
|
DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_CLEARANCE );
|
2010-09-20 16:21:47 +00:00
|
|
|
|
2020-05-21 17:42:42 +00:00
|
|
|
m_msg.Printf( drcItem->GetErrorText() + _( " (%s clearance %s; actual %s)" ),
|
2020-05-18 00:20:16 +00:00
|
|
|
m_clearanceSource,
|
|
|
|
MessageTextFromValue( userUnits(), minClearance, true ),
|
|
|
|
MessageTextFromValue( userUnits(), actual, true ) );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2020-05-18 00:20:16 +00:00
|
|
|
drcItem->SetErrorMessage( m_msg );
|
2020-04-26 10:30:32 +00:00
|
|
|
drcItem->SetItems( aRefSeg, track );
|
2020-04-24 13:36:10 +00:00
|
|
|
|
2020-07-04 18:48:22 +00:00
|
|
|
MARKER_PCB* marker = new MARKER_PCB( drcItem, pos );
|
2020-05-18 00:20:16 +00:00
|
|
|
addMarkerToPcb( aCommit, marker );
|
2018-08-27 13:50:50 +00:00
|
|
|
|
2020-04-26 10:30:32 +00:00
|
|
|
if( !m_reportAllTrackErrors )
|
|
|
|
return;
|
2010-09-20 16:21:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-19 16:46:46 +00:00
|
|
|
/***************************************/
|
|
|
|
/* Phase 3: test DRC with copper zones */
|
|
|
|
/***************************************/
|
|
|
|
// Can be *very* time consumming.
|
|
|
|
if( aTestZones )
|
2018-08-23 22:41:57 +00:00
|
|
|
{
|
2020-04-26 10:30:32 +00:00
|
|
|
SEG testSeg( aRefSeg->GetStart(), aRefSeg->GetEnd() );
|
2018-08-23 22:41:57 +00:00
|
|
|
|
2019-03-19 16:46:46 +00:00
|
|
|
for( ZONE_CONTAINER* zone : m_pcb->Zones() )
|
|
|
|
{
|
2020-06-24 02:19:08 +00:00
|
|
|
if( !( refLayerSet & zone->GetLayerSet() ).any() || zone->GetIsKeepout() )
|
2019-03-19 16:46:46 +00:00
|
|
|
continue;
|
2018-08-23 22:41:57 +00:00
|
|
|
|
2020-06-24 02:19:08 +00:00
|
|
|
for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
|
|
|
|
{
|
|
|
|
if( zone->GetFilledPolysList( layer ).IsEmpty() )
|
|
|
|
continue;
|
2018-08-27 13:50:50 +00:00
|
|
|
|
2020-06-24 02:19:08 +00:00
|
|
|
if( zone->GetNetCode() && zone->GetNetCode() == aRefSeg->GetNetCode() )
|
|
|
|
continue;
|
2019-03-19 16:46:46 +00:00
|
|
|
|
2020-06-24 02:19:08 +00:00
|
|
|
// to avoid false positive, due to rounding issues and approxiamtions
|
|
|
|
// in distance and clearance calculations, use a small threshold for distance
|
|
|
|
// (1 micron)
|
|
|
|
#define THRESHOLD_DIST Millimeter2iu( 0.001 )
|
2020-04-26 10:30:32 +00:00
|
|
|
|
2020-08-07 20:18:33 +00:00
|
|
|
int minClearance = aRefSeg->GetClearance( aRefSeg->GetLayer(), zone,
|
|
|
|
&m_clearanceSource );
|
2020-07-04 18:48:22 +00:00
|
|
|
int widths = refSegWidth / 2;
|
|
|
|
int allowedDist = minClearance + widths + THRESHOLD_DIST;
|
|
|
|
int actual;
|
|
|
|
|
|
|
|
if( zone->GetFilledPolysList( layer ).Collide( testSeg, allowedDist, &actual ) )
|
2020-06-24 02:19:08 +00:00
|
|
|
{
|
2020-07-04 18:48:22 +00:00
|
|
|
actual = std::max( 0, actual - widths );
|
2020-06-08 02:19:46 +00:00
|
|
|
DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_CLEARANCE );
|
2020-04-26 10:30:32 +00:00
|
|
|
|
2020-06-24 02:19:08 +00:00
|
|
|
m_msg.Printf( drcItem->GetErrorText() + _( " (%s clearance %s; actual %s)" ),
|
2020-07-04 18:48:22 +00:00
|
|
|
m_clearanceSource,
|
|
|
|
MessageTextFromValue( userUnits(), minClearance, true ),
|
|
|
|
MessageTextFromValue( userUnits(), actual, true ) );
|
2020-04-26 10:30:32 +00:00
|
|
|
|
2020-06-24 02:19:08 +00:00
|
|
|
drcItem->SetErrorMessage( m_msg );
|
|
|
|
drcItem->SetItems( aRefSeg, zone );
|
2020-04-24 13:36:10 +00:00
|
|
|
|
2020-06-24 02:19:08 +00:00
|
|
|
MARKER_PCB* marker = new MARKER_PCB( drcItem, GetLocation( aRefSeg, zone ) );
|
|
|
|
addMarkerToPcb( aCommit, marker );
|
|
|
|
}
|
2020-02-28 00:05:40 +00:00
|
|
|
}
|
2019-03-19 16:46:46 +00:00
|
|
|
}
|
2018-08-23 22:41:57 +00:00
|
|
|
}
|
|
|
|
|
2018-11-28 12:11:43 +00:00
|
|
|
/***********************************************/
|
|
|
|
/* Phase 4: test DRC with to board edge */
|
|
|
|
/***********************************************/
|
2020-05-18 20:09:36 +00:00
|
|
|
if( m_board_outline_valid )
|
2018-11-28 12:11:43 +00:00
|
|
|
{
|
2020-05-29 12:36:45 +00:00
|
|
|
int minClearance = bds.m_CopperEdgeClearance;
|
|
|
|
m_clearanceSource = _( "board edge" );
|
|
|
|
|
2020-05-15 23:25:33 +00:00
|
|
|
static DRAWSEGMENT dummyEdge;
|
|
|
|
dummyEdge.SetLayer( Edge_Cuts );
|
2019-04-05 16:10:59 +00:00
|
|
|
|
2020-08-07 20:18:33 +00:00
|
|
|
aRefSeg->GetRuleClearance( &dummyEdge, aRefSeg->GetLayer(), &minClearance,
|
|
|
|
&m_clearanceSource );
|
2020-04-26 12:21:37 +00:00
|
|
|
|
2020-05-29 12:36:45 +00:00
|
|
|
SEG testSeg( aRefSeg->GetStart(), aRefSeg->GetEnd() );
|
2020-04-26 10:30:32 +00:00
|
|
|
int halfWidth = refSegWidth / 2;
|
2020-04-26 12:21:37 +00:00
|
|
|
int center2centerAllowed = minClearance + halfWidth;
|
2018-11-28 12:11:43 +00:00
|
|
|
|
|
|
|
for( auto it = m_board_outlines.IterateSegmentsWithHoles(); it; it++ )
|
|
|
|
{
|
2020-04-26 10:30:32 +00:00
|
|
|
SEG::ecoord center2center_squared = testSeg.SquaredDistance( *it );
|
|
|
|
|
2020-04-28 21:43:29 +00:00
|
|
|
if( center2center_squared < SEG::Square( center2centerAllowed ) )
|
2018-11-28 12:11:43 +00:00
|
|
|
{
|
2020-04-26 10:30:32 +00:00
|
|
|
VECTOR2I pt = testSeg.NearestPoint( *it );
|
2019-06-04 11:52:03 +00:00
|
|
|
|
|
|
|
KICAD_T types[] = { PCB_LINE_T, EOT };
|
|
|
|
DRAWSEGMENT* edge = nullptr;
|
2020-04-26 10:30:32 +00:00
|
|
|
INSPECTOR_FUNC inspector =
|
|
|
|
[&] ( EDA_ITEM* item, void* testData )
|
|
|
|
{
|
|
|
|
DRAWSEGMENT* test_edge = dynamic_cast<DRAWSEGMENT*>( item );
|
2019-06-04 11:52:03 +00:00
|
|
|
|
2020-04-26 10:30:32 +00:00
|
|
|
if( !test_edge || test_edge->GetLayer() != Edge_Cuts )
|
|
|
|
return SEARCH_RESULT::CONTINUE;
|
2019-06-04 11:52:03 +00:00
|
|
|
|
2020-04-26 12:21:37 +00:00
|
|
|
if( test_edge->HitTest( (wxPoint) pt, minClearance + halfWidth ) )
|
2020-04-26 10:30:32 +00:00
|
|
|
{
|
|
|
|
edge = test_edge;
|
|
|
|
return SEARCH_RESULT::QUIT;
|
|
|
|
}
|
2019-06-04 11:52:03 +00:00
|
|
|
|
2020-04-26 10:30:32 +00:00
|
|
|
return SEARCH_RESULT::CONTINUE;
|
|
|
|
};
|
2019-06-04 11:52:03 +00:00
|
|
|
|
|
|
|
// Best-efforts search for edge segment
|
|
|
|
BOARD::IterateForward<BOARD_ITEM*>( m_pcb->Drawings(), inspector, nullptr, types );
|
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
int actual = std::max( 0.0, sqrt( center2center_squared ) - halfWidth );
|
|
|
|
DRC_ITEM* drcItem = DRC_ITEM::Create( DRCE_COPPER_EDGE_CLEARANCE );
|
2020-04-26 10:30:32 +00:00
|
|
|
|
2020-05-18 00:20:16 +00:00
|
|
|
m_msg.Printf( drcItem->GetErrorText() + _( " (%s clearance %s; actual %s)" ),
|
|
|
|
m_clearanceSource,
|
|
|
|
MessageTextFromValue( userUnits(), minClearance, true ),
|
|
|
|
MessageTextFromValue( userUnits(), actual, true ) );
|
2020-04-26 10:30:32 +00:00
|
|
|
|
2020-05-18 00:20:16 +00:00
|
|
|
drcItem->SetErrorMessage( m_msg );
|
2020-04-24 13:36:10 +00:00
|
|
|
drcItem->SetItems( aRefSeg, edge );
|
|
|
|
|
|
|
|
MARKER_PCB* marker = new MARKER_PCB( drcItem, (wxPoint) pt );
|
2020-05-18 00:20:16 +00:00
|
|
|
addMarkerToPcb( aCommit, marker );
|
2018-11-28 12:11:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-09-20 16:21:47 +00:00
|
|
|
}
|
|
|
|
|