2020-05-17 14:40:06 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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 <drc/drc_drilled_hole_tester.h>
|
|
|
|
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <drc/drc.h>
|
|
|
|
|
|
|
|
#include <widgets/ui_common.h>
|
|
|
|
|
|
|
|
|
|
|
|
DRC_DRILLED_HOLE_TESTER::DRC_DRILLED_HOLE_TESTER( MARKER_HANDLER aMarkerHandler ) :
|
|
|
|
DRC_TEST_PROVIDER( std::move( aMarkerHandler ) ),
|
|
|
|
m_units( EDA_UNITS::MILLIMETRES ),
|
|
|
|
m_board( nullptr ),
|
|
|
|
m_largestRadius( 0 )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DRC_DRILLED_HOLE_TESTER::RunDRC( EDA_UNITS aUnits, BOARD& aBoard )
|
|
|
|
{
|
|
|
|
bool success = true;
|
|
|
|
|
|
|
|
// Test drilled holes to minimize drill bit breakage.
|
|
|
|
//
|
|
|
|
// Check pad & std. via circular holes for hole-to-hole-min (non-circular holes are milled)
|
|
|
|
// Check pad & std. via holes for via-min-drill (minimum hole classification)
|
|
|
|
// Check uvia holes for uvia-min-drill (laser drill classification)
|
|
|
|
|
|
|
|
m_units = aUnits;
|
|
|
|
m_board = &aBoard;
|
|
|
|
m_holes.clear();
|
|
|
|
m_largestRadius = 0;
|
|
|
|
|
|
|
|
for( MODULE* mod : aBoard.Modules() )
|
|
|
|
{
|
|
|
|
for( D_PAD* pad : mod->Pads( ) )
|
2020-05-18 00:20:16 +00:00
|
|
|
success &= checkPad( pad );
|
2020-05-17 14:40:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for( TRACK* track : aBoard.Tracks() )
|
|
|
|
{
|
|
|
|
VIA* via = dynamic_cast<VIA*>( track );
|
|
|
|
|
|
|
|
if( via )
|
|
|
|
{
|
|
|
|
if( via->GetViaType() == VIATYPE::MICROVIA )
|
2020-05-18 00:20:16 +00:00
|
|
|
success &= checkMicroVia( via );
|
2020-05-17 14:40:06 +00:00
|
|
|
else
|
2020-05-18 00:20:16 +00:00
|
|
|
success &= checkVia( via );
|
2020-05-17 14:40:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-18 00:20:16 +00:00
|
|
|
success &= checkHoles();
|
2020-05-17 14:40:06 +00:00
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DRC_DRILLED_HOLE_TESTER::checkPad( D_PAD* aPad )
|
|
|
|
{
|
|
|
|
bool success = true;
|
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
|
|
|
|
|
2020-08-07 20:18:33 +00:00
|
|
|
// drilled holes go all the way through, so which layer we use shouldn't matter
|
|
|
|
PCB_LAYER_ID layer = F_Cu;
|
|
|
|
int holeSize = std::min( aPad->GetDrillSize().x, aPad->GetDrillSize().y );
|
2020-05-17 14:40:06 +00:00
|
|
|
|
|
|
|
if( holeSize == 0 )
|
|
|
|
return true;
|
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
if( !bds.Ignore( DRCE_TOO_SMALL_DRILL ) )
|
2020-05-17 14:40:06 +00:00
|
|
|
{
|
2020-08-07 20:18:33 +00:00
|
|
|
int minHole;
|
|
|
|
const DRC_CONSTRAINT* constraint = GetConstraint( aPad, nullptr, DRC_RULE_ID_HOLE_SIZE,
|
|
|
|
layer, &m_source );
|
2020-05-17 14:40:06 +00:00
|
|
|
|
2020-08-07 20:18:33 +00:00
|
|
|
if( constraint )
|
2020-05-17 14:40:06 +00:00
|
|
|
{
|
2020-08-07 20:18:33 +00:00
|
|
|
minHole = constraint->m_Value.Min();
|
|
|
|
m_source = wxString::Format( _( "'%s' rule" ), m_source );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
minHole = bds.m_MinThroughDrill;
|
|
|
|
m_source = _( "board minimum" );
|
2020-05-17 14:40:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( holeSize < minHole )
|
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_TOO_SMALL_DRILL );
|
2020-05-17 14:40:06 +00:00
|
|
|
|
2020-05-22 10:31:14 +00:00
|
|
|
m_msg.Printf( drcItem->GetErrorText() + _( " (%s %s; actual %s)" ),
|
2020-08-07 20:18:33 +00:00
|
|
|
m_source,
|
2020-05-18 00:20:16 +00:00
|
|
|
MessageTextFromValue( m_units, minHole, true ),
|
|
|
|
MessageTextFromValue( m_units, holeSize, true ) );
|
2020-05-17 14:40:06 +00:00
|
|
|
|
2020-05-18 00:20:16 +00:00
|
|
|
drcItem->SetErrorMessage( m_msg );
|
2020-05-17 14:40:06 +00:00
|
|
|
drcItem->SetItems( aPad );
|
|
|
|
|
|
|
|
HandleMarker( new MARKER_PCB( drcItem, aPad->GetPosition() ) );
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !bds.Ignore( DRCE_DRILLED_HOLES_TOO_CLOSE ) && bds.m_HoleToHoleMin != 0 )
|
|
|
|
{
|
|
|
|
if( aPad->GetDrillShape() == PAD_DRILL_SHAPE_CIRCLE )
|
|
|
|
addHole( aPad->GetPosition(), aPad->GetDrillSize().x / 2, aPad );
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DRC_DRILLED_HOLE_TESTER::checkVia( VIA* via )
|
|
|
|
{
|
|
|
|
bool success = true;
|
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
|
|
|
|
|
2020-08-07 20:18:33 +00:00
|
|
|
// drilled holes go all the way through, so which layer we use shouldn't matter
|
|
|
|
PCB_LAYER_ID layer = F_Cu;
|
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
if( !bds.Ignore( DRCE_TOO_SMALL_DRILL ) )
|
2020-05-17 14:40:06 +00:00
|
|
|
{
|
2020-08-07 20:18:33 +00:00
|
|
|
int minHole;
|
|
|
|
const DRC_CONSTRAINT* constraint = GetConstraint( via, nullptr, DRC_RULE_ID_HOLE_SIZE,
|
|
|
|
layer, &m_source );
|
2020-05-17 14:40:06 +00:00
|
|
|
|
2020-08-07 20:18:33 +00:00
|
|
|
if( constraint )
|
|
|
|
{
|
|
|
|
minHole = constraint->m_Value.Min();
|
|
|
|
m_source = wxString::Format( _( "'%s' rule" ), m_source );
|
|
|
|
}
|
|
|
|
else
|
2020-05-17 14:40:06 +00:00
|
|
|
{
|
2020-08-07 20:18:33 +00:00
|
|
|
minHole = bds.m_MinThroughDrill;
|
|
|
|
m_source = _( "board minimum" );
|
2020-05-17 14:40:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( via->GetDrillValue() < minHole )
|
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_TOO_SMALL_DRILL );
|
2020-05-17 14:40:06 +00:00
|
|
|
|
2020-05-22 10:31:14 +00:00
|
|
|
m_msg.Printf( drcItem->GetErrorText() + _( " (%s %s; actual %s)" ),
|
2020-08-07 20:18:33 +00:00
|
|
|
m_source,
|
2020-05-18 00:20:16 +00:00
|
|
|
MessageTextFromValue( m_units, minHole, true ),
|
|
|
|
MessageTextFromValue( m_units, via->GetDrillValue(), true ) );
|
2020-05-17 14:40:06 +00:00
|
|
|
|
2020-05-18 00:20:16 +00:00
|
|
|
drcItem->SetErrorMessage( m_msg );
|
2020-05-17 14:40:06 +00:00
|
|
|
drcItem->SetItems( via );
|
|
|
|
|
|
|
|
HandleMarker( new MARKER_PCB( drcItem, via->GetPosition() ) );
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !bds.Ignore( DRCE_DRILLED_HOLES_TOO_CLOSE ) && bds.m_HoleToHoleMin != 0 )
|
|
|
|
{
|
|
|
|
addHole( via->GetPosition(), via->GetDrillValue() / 2, via );
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DRC_DRILLED_HOLE_TESTER::checkMicroVia( VIA* via )
|
|
|
|
{
|
|
|
|
bool success = true;
|
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
|
|
|
|
|
2020-08-07 20:18:33 +00:00
|
|
|
// while microvia holes don't necessarily go all the way through, they can't be different
|
|
|
|
// sizes on different layers so we should still be safe enough using a fixed layer.
|
|
|
|
PCB_LAYER_ID layer = F_Cu;
|
|
|
|
|
2020-05-17 14:40:06 +00:00
|
|
|
if( !bds.Ignore( DRCE_TOO_SMALL_MICROVIA_DRILL ) )
|
|
|
|
{
|
2020-08-07 20:18:33 +00:00
|
|
|
int minHole;
|
|
|
|
const DRC_CONSTRAINT* constraint = GetConstraint( via, nullptr, DRC_RULE_ID_HOLE_SIZE,
|
|
|
|
layer, &m_source );
|
2020-05-17 14:40:06 +00:00
|
|
|
|
2020-08-07 20:18:33 +00:00
|
|
|
if( constraint )
|
|
|
|
{
|
|
|
|
minHole = constraint->m_Value.Min();
|
|
|
|
m_source = wxString::Format( _( "'%s' rule" ), m_source );
|
|
|
|
}
|
|
|
|
else
|
2020-05-17 14:40:06 +00:00
|
|
|
{
|
2020-08-07 20:18:33 +00:00
|
|
|
minHole = bds.m_MicroViasMinDrill;
|
|
|
|
m_source = _( "board minimum" );
|
2020-05-17 14:40:06 +00:00
|
|
|
}
|
|
|
|
|
2020-08-11 13:33:16 +00:00
|
|
|
if( via->GetDrillValue() < minHole )
|
2020-05-17 14:40:06 +00:00
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_TOO_SMALL_MICROVIA_DRILL );
|
2020-05-17 14:40:06 +00:00
|
|
|
|
2020-05-22 10:31:14 +00:00
|
|
|
m_msg.Printf( drcItem->GetErrorText() + _( " (%s %s; actual %s)" ),
|
2020-08-07 20:18:33 +00:00
|
|
|
m_source,
|
2020-05-18 00:20:16 +00:00
|
|
|
MessageTextFromValue( m_units, minHole, true ),
|
|
|
|
MessageTextFromValue( m_units, via->GetDrillValue(), true ) );
|
2020-05-17 14:40:06 +00:00
|
|
|
|
2020-05-18 00:20:16 +00:00
|
|
|
drcItem->SetErrorMessage( m_msg );
|
2020-05-17 14:40:06 +00:00
|
|
|
drcItem->SetItems( via );
|
|
|
|
|
|
|
|
HandleMarker( new MARKER_PCB( drcItem, via->GetPosition() ) );
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DRC_DRILLED_HOLE_TESTER::addHole( const wxPoint& aLocation, int aRadius, BOARD_ITEM* aOwner )
|
|
|
|
{
|
|
|
|
DRILLED_HOLE hole;
|
|
|
|
|
|
|
|
hole.m_location = aLocation;
|
|
|
|
hole.m_drillRadius = aRadius;
|
|
|
|
hole.m_owner = aOwner;
|
|
|
|
|
|
|
|
m_largestRadius = std::max( m_largestRadius, aRadius );
|
|
|
|
|
|
|
|
m_holes.push_back( hole );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DRC_DRILLED_HOLE_TESTER::checkHoles()
|
|
|
|
{
|
|
|
|
bool success = true;
|
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
|
|
|
|
|
|
|
|
// No need to check if we're ignoring DRCE_DRILLED_HOLES_TOO_CLOSE; if we are then we
|
|
|
|
// won't have collected any holes to test.
|
|
|
|
|
|
|
|
// Sort holes by X for performance. In the nested iteration we then need to look at
|
|
|
|
// following holes only while they are within the refHole's neighborhood as defined by
|
|
|
|
// the refHole radius + the minimum hole-to-hole clearance + the largest radius any of
|
|
|
|
// the following holes can have.
|
|
|
|
std::sort( m_holes.begin(), m_holes.end(),
|
|
|
|
[]( const DRILLED_HOLE& a, const DRILLED_HOLE& b )
|
|
|
|
{
|
|
|
|
if( a.m_location.x == b.m_location.x )
|
|
|
|
return a.m_location.y < b.m_location.y;
|
|
|
|
else
|
|
|
|
return a.m_location.x < b.m_location.x;
|
|
|
|
} );
|
|
|
|
|
|
|
|
for( size_t ii = 0; ii < m_holes.size(); ++ii )
|
|
|
|
{
|
|
|
|
const DRILLED_HOLE& refHole = m_holes[ ii ];
|
|
|
|
int neighborhood = refHole.m_drillRadius + bds.m_HoleToHoleMin + m_largestRadius;
|
|
|
|
|
|
|
|
for( size_t jj = ii + 1; jj < m_holes.size(); ++jj )
|
|
|
|
{
|
|
|
|
const DRILLED_HOLE& checkHole = m_holes[ jj ];
|
|
|
|
|
|
|
|
if( refHole.m_location.x + neighborhood < checkHole.m_location.x )
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Holes with identical locations are allowable
|
|
|
|
if( checkHole.m_location == refHole.m_location )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int actual = KiROUND( GetLineLength( checkHole.m_location, refHole.m_location ) );
|
|
|
|
actual = std::max( 0, actual - checkHole.m_drillRadius - refHole.m_drillRadius );
|
|
|
|
|
|
|
|
if( actual < bds.m_HoleToHoleMin )
|
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_DRILLED_HOLES_TOO_CLOSE );
|
2020-05-17 14:40:06 +00:00
|
|
|
|
2020-05-18 00:20:16 +00:00
|
|
|
m_msg.Printf( drcItem->GetErrorText() + _( " (board minimum %s; actual %s)" ),
|
|
|
|
MessageTextFromValue( m_units, bds.m_HoleToHoleMin, true ),
|
|
|
|
MessageTextFromValue( m_units, actual, true ) );
|
2020-05-17 14:40:06 +00:00
|
|
|
|
2020-05-18 00:20:16 +00:00
|
|
|
drcItem->SetErrorMessage( m_msg );
|
2020-05-17 14:40:06 +00:00
|
|
|
drcItem->SetItems( refHole.m_owner, checkHole.m_owner );
|
|
|
|
|
|
|
|
HandleMarker( new MARKER_PCB( drcItem, refHole.m_location ) );
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|