2020-07-27 13:33:06 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-03-11 21:16:52 +00:00
|
|
|
* Copyright (C) 2004-2022 KiCad Developers.
|
2020-07-27 13:33:06 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2022-03-15 16:43:28 +00:00
|
|
|
#include <geometry/shape_segment.h>
|
2021-06-03 18:05:43 +00:00
|
|
|
#include <footprint.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <pad.h>
|
2021-06-11 21:07:02 +00:00
|
|
|
#include <pcb_track.h>
|
2022-03-15 16:43:28 +00:00
|
|
|
#include <board_design_settings.h>
|
2021-06-06 19:03:10 +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 21:50:53 +00:00
|
|
|
#include <drc/drc_test_provider_clearance_base.h>
|
2022-03-15 16:43:28 +00:00
|
|
|
#include "convert_basic_shapes_to_polygon.h"
|
2020-07-27 13:33:06 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Drilled hole size test. scans vias/through-hole pads and checks for min drill sizes
|
|
|
|
Errors generated:
|
2021-01-03 22:57:51 +00:00
|
|
|
- DRCE_DRILL_OUT_OF_RANGE
|
|
|
|
- DRCE_MICROVIA_DRILL_OUT_OF_RANGE
|
2022-03-15 16:43:28 +00:00
|
|
|
- DRCE_PADSTACK
|
2020-07-27 13:33:06 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
class DRC_TEST_PROVIDER_HOLE_SIZE : public DRC_TEST_PROVIDER
|
|
|
|
{
|
|
|
|
public:
|
2021-09-27 09:27:09 +00:00
|
|
|
DRC_TEST_PROVIDER_HOLE_SIZE()
|
2020-07-27 13:33:06 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~DRC_TEST_PROVIDER_HOLE_SIZE()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool Run() override;
|
|
|
|
|
|
|
|
virtual const wxString GetName() const override
|
|
|
|
{
|
2022-03-11 21:16:52 +00:00
|
|
|
return wxT( "hole_size" );
|
2020-07-27 13:33:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual const wxString GetDescription() const override
|
|
|
|
{
|
2022-03-11 21:16:52 +00:00
|
|
|
return wxT( "Tests sizes of drilled holes (via/pad drills)" );
|
2020-07-27 13:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2022-03-15 16:43:28 +00:00
|
|
|
void checkViaHole( PCB_VIA* via, bool aExceedMicro, bool aExceedStd );
|
|
|
|
void checkPadHole( PAD* aPad );
|
|
|
|
void checkPadStack( PAD* aPad );
|
2020-07-27 13:33:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-09-11 21:50:53 +00:00
|
|
|
bool DRC_TEST_PROVIDER_HOLE_SIZE::Run()
|
2020-07-27 13:33:06 +00:00
|
|
|
{
|
2021-02-27 13:43:41 +00:00
|
|
|
if( !m_drcEngine->IsErrorLimitExceeded( DRCE_DRILL_OUT_OF_RANGE ) )
|
2020-07-27 13:33:06 +00:00
|
|
|
{
|
2021-02-27 13:43:41 +00:00
|
|
|
if( !reportPhase( _( "Checking pad holes..." ) ) )
|
|
|
|
return false; // DRC cancelled
|
|
|
|
|
2021-09-27 09:27:09 +00:00
|
|
|
for( FOOTPRINT* footprint : m_drcEngine->GetBoard()->Footprints() )
|
2020-07-27 13:33:06 +00:00
|
|
|
{
|
2022-03-15 16:43:28 +00:00
|
|
|
if( m_drcEngine->IsErrorLimitExceeded( DRCE_DRILL_OUT_OF_RANGE )
|
|
|
|
&& m_drcEngine->IsErrorLimitExceeded( DRCE_PADSTACK ) )
|
|
|
|
{
|
2020-07-27 13:33:06 +00:00
|
|
|
break;
|
2022-03-15 16:43:28 +00:00
|
|
|
}
|
2020-09-12 19:28:22 +00:00
|
|
|
|
2021-02-27 13:43:41 +00:00
|
|
|
for( PAD* pad : footprint->Pads() )
|
|
|
|
{
|
2022-03-15 16:43:28 +00:00
|
|
|
if( !m_drcEngine->IsErrorLimitExceeded( DRCE_DRILL_OUT_OF_RANGE ) )
|
|
|
|
checkPadHole( pad );
|
2021-02-27 13:43:41 +00:00
|
|
|
|
2022-03-15 16:43:28 +00:00
|
|
|
if( !m_drcEngine->IsErrorLimitExceeded( DRCE_PADSTACK ) )
|
|
|
|
checkPadStack( pad );
|
2021-02-27 13:43:41 +00:00
|
|
|
}
|
2020-07-27 13:33:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-27 13:43:41 +00:00
|
|
|
if( !m_drcEngine->IsErrorLimitExceeded( DRCE_MICROVIA_DRILL_OUT_OF_RANGE )
|
|
|
|
|| !m_drcEngine->IsErrorLimitExceeded( DRCE_DRILL_OUT_OF_RANGE ) )
|
2020-07-27 13:33:06 +00:00
|
|
|
{
|
2021-02-27 13:43:41 +00:00
|
|
|
if( !m_drcEngine->IsErrorLimitExceeded( DRCE_DRILL_OUT_OF_RANGE ) )
|
|
|
|
{
|
|
|
|
if( !reportPhase( _( "Checking via holes..." ) ) )
|
|
|
|
return false; // DRC cancelled
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( !reportPhase( _( "Checking micro-via holes..." ) ) )
|
|
|
|
return false; // DRC cancelled
|
|
|
|
}
|
2020-07-27 13:33:06 +00:00
|
|
|
|
2021-09-27 09:27:09 +00:00
|
|
|
for( PCB_TRACK* track : m_drcEngine->GetBoard()->Tracks() )
|
2021-02-27 13:43:41 +00:00
|
|
|
{
|
|
|
|
if( track->Type() == PCB_VIA_T )
|
2022-03-12 13:34:25 +00:00
|
|
|
{
|
|
|
|
bool exceedMicro = m_drcEngine->IsErrorLimitExceeded( DRCE_MICROVIA_DRILL_OUT_OF_RANGE );
|
|
|
|
bool exceedStd = m_drcEngine->IsErrorLimitExceeded( DRCE_DRILL_OUT_OF_RANGE );
|
2021-02-27 13:43:41 +00:00
|
|
|
|
2022-03-12 13:34:25 +00:00
|
|
|
if( exceedMicro && exceedStd )
|
|
|
|
break;
|
2020-09-12 19:28:22 +00:00
|
|
|
|
2022-03-15 16:43:28 +00:00
|
|
|
checkViaHole( static_cast<PCB_VIA*>( track ), exceedMicro, exceedStd );
|
2022-03-12 13:34:25 +00:00
|
|
|
}
|
2021-02-27 13:43:41 +00:00
|
|
|
}
|
2020-07-27 13:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
reportRuleStatistics();
|
|
|
|
|
2022-03-11 21:16:52 +00:00
|
|
|
return !m_drcEngine->IsCancelled();
|
2020-07-27 13:33:06 +00:00
|
|
|
}
|
|
|
|
|
2022-03-15 16:43:28 +00:00
|
|
|
void DRC_TEST_PROVIDER_HOLE_SIZE::checkPadStack( PAD* aPad )
|
|
|
|
{
|
|
|
|
if( aPad->GetAttribute() == PAD_ATTRIB::PTH )
|
|
|
|
{
|
|
|
|
if( !aPad->IsOnCopperLayer() )
|
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_PADSTACK );
|
|
|
|
m_msg.Printf( _( " (PTH pad has no copper layers)" ) );
|
|
|
|
|
|
|
|
drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + m_msg );
|
|
|
|
drcItem->SetItems( aPad );
|
|
|
|
|
|
|
|
reportViolation( drcItem, aPad->GetPosition(), UNDEFINED_LAYER );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LSET lset = aPad->GetLayerSet() & LSET::AllCuMask();
|
|
|
|
PCB_LAYER_ID layer = lset.Seq().at( 0 );
|
|
|
|
int maxError = m_drcEngine->GetBoard()->GetDesignSettings().m_MaxError;
|
|
|
|
SHAPE_POLY_SET padOutline;
|
|
|
|
|
|
|
|
aPad->TransformShapeWithClearanceToPolygon( padOutline, layer, 0, maxError,
|
|
|
|
ERROR_LOC::ERROR_INSIDE );
|
|
|
|
|
|
|
|
const SHAPE_SEGMENT* drillShape = aPad->GetEffectiveHoleShape();
|
|
|
|
const SEG drillSeg = drillShape->GetSeg();
|
|
|
|
SHAPE_POLY_SET drillOutline;
|
|
|
|
|
|
|
|
TransformOvalToPolygon( drillOutline, drillSeg.A, drillSeg.B,
|
|
|
|
drillShape->GetWidth(), maxError, ERROR_LOC::ERROR_INSIDE );
|
|
|
|
|
|
|
|
padOutline.BooleanSubtract( drillOutline, SHAPE_POLY_SET::POLYGON_MODE::PM_FAST );
|
|
|
|
|
|
|
|
if( padOutline.IsEmpty() )
|
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_PADSTACK );
|
|
|
|
m_msg.Printf( _( " (PTH pad's hole leaves no copper)" ) );
|
|
|
|
|
|
|
|
drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + m_msg );
|
|
|
|
drcItem->SetItems( aPad );
|
|
|
|
|
|
|
|
reportViolation( drcItem, aPad->GetPosition(), UNDEFINED_LAYER );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-07-27 13:33:06 +00:00
|
|
|
|
2022-03-15 16:43:28 +00:00
|
|
|
void DRC_TEST_PROVIDER_HOLE_SIZE::checkPadHole( PAD* aPad )
|
2020-07-27 13:33:06 +00:00
|
|
|
{
|
2021-01-03 22:57:51 +00:00
|
|
|
int holeMinor = std::min( aPad->GetDrillSize().x, aPad->GetDrillSize().y );
|
|
|
|
int holeMajor = std::max( aPad->GetDrillSize().x, aPad->GetDrillSize().y );
|
2020-07-27 13:33:06 +00:00
|
|
|
|
2021-01-03 22:57:51 +00:00
|
|
|
if( holeMinor == 0 )
|
2020-09-12 19:28:22 +00:00
|
|
|
return;
|
2020-07-27 13:33:06 +00:00
|
|
|
|
2021-02-08 14:53:49 +00:00
|
|
|
auto constraint = m_drcEngine->EvalRules( HOLE_SIZE_CONSTRAINT, aPad, nullptr,
|
|
|
|
UNDEFINED_LAYER /* holes are not layer-specific */ );
|
2021-01-03 22:57:51 +00:00
|
|
|
bool fail_min = false;
|
|
|
|
bool fail_max = false;
|
|
|
|
int constraintValue;
|
2020-07-27 13:33:06 +00:00
|
|
|
|
2021-09-05 15:06:12 +00:00
|
|
|
if( constraint.GetSeverity() == RPT_SEVERITY_IGNORE )
|
|
|
|
return;
|
|
|
|
|
2021-01-03 22:57:51 +00:00
|
|
|
if( constraint.Value().HasMin() && holeMinor < constraint.Value().Min() )
|
|
|
|
{
|
|
|
|
fail_min = true;
|
|
|
|
constraintValue = constraint.Value().Min();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( constraint.Value().HasMax() && holeMajor > constraint.Value().Max() )
|
2020-07-27 13:33:06 +00:00
|
|
|
{
|
2021-01-03 22:57:51 +00:00
|
|
|
fail_max = true;
|
|
|
|
constraintValue = constraint.Value().Max();
|
|
|
|
}
|
2020-07-27 13:33:06 +00:00
|
|
|
|
2021-01-03 22:57:51 +00:00
|
|
|
if( fail_min || fail_max )
|
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_DRILL_OUT_OF_RANGE );
|
|
|
|
|
|
|
|
if( fail_min )
|
|
|
|
{
|
|
|
|
m_msg.Printf( _( "(%s min width %s; actual %s)" ),
|
|
|
|
constraint.GetName(),
|
|
|
|
MessageTextFromValue( userUnits(), constraintValue ),
|
|
|
|
MessageTextFromValue( userUnits(), holeMinor ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_msg.Printf( _( "(%s max width %s; actual %s)" ),
|
|
|
|
constraint.GetName(),
|
|
|
|
MessageTextFromValue( userUnits(), constraintValue ),
|
|
|
|
MessageTextFromValue( userUnits(), holeMajor ) );
|
|
|
|
}
|
2020-07-27 13:33:06 +00:00
|
|
|
|
2020-11-02 16:20:00 +00:00
|
|
|
drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + m_msg );
|
2020-07-27 13:33:06 +00:00
|
|
|
drcItem->SetItems( aPad );
|
2020-09-11 21:50:53 +00:00
|
|
|
drcItem->SetViolatingRule( constraint.GetParentRule() );
|
2020-07-27 13:33:06 +00:00
|
|
|
|
2021-12-26 13:47:00 +00:00
|
|
|
reportViolation( drcItem, aPad->GetPosition(), UNDEFINED_LAYER );
|
2020-07-27 13:33:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-15 16:43:28 +00:00
|
|
|
void DRC_TEST_PROVIDER_HOLE_SIZE::checkViaHole( PCB_VIA* via, bool aExceedMicro, bool aExceedStd )
|
2020-07-27 13:33:06 +00:00
|
|
|
{
|
2020-09-12 19:28:22 +00:00
|
|
|
int errorCode;
|
|
|
|
|
|
|
|
if( via->GetViaType() == VIATYPE::MICROVIA )
|
|
|
|
{
|
|
|
|
if( aExceedMicro )
|
|
|
|
return;
|
|
|
|
|
2021-01-03 22:57:51 +00:00
|
|
|
errorCode = DRCE_MICROVIA_DRILL_OUT_OF_RANGE;
|
2020-09-12 19:28:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( aExceedStd )
|
|
|
|
return;
|
|
|
|
|
2021-01-03 22:57:51 +00:00
|
|
|
errorCode = DRCE_DRILL_OUT_OF_RANGE;
|
2020-09-12 19:28:22 +00:00
|
|
|
}
|
|
|
|
|
2021-02-08 14:53:49 +00:00
|
|
|
auto constraint = m_drcEngine->EvalRules( HOLE_SIZE_CONSTRAINT, via, nullptr,
|
|
|
|
UNDEFINED_LAYER /* holes are not layer-specific */ );
|
2021-01-03 22:57:51 +00:00
|
|
|
bool fail_min = false;
|
|
|
|
bool fail_max = false;
|
|
|
|
int constraintValue;
|
2020-07-27 13:33:06 +00:00
|
|
|
|
2021-09-05 15:06:12 +00:00
|
|
|
if( constraint.GetSeverity() == RPT_SEVERITY_IGNORE )
|
|
|
|
return;
|
|
|
|
|
2021-01-03 22:57:51 +00:00
|
|
|
if( constraint.Value().HasMin() && via->GetDrillValue() < constraint.Value().Min() )
|
|
|
|
{
|
|
|
|
fail_min = true;
|
|
|
|
constraintValue = constraint.Value().Min();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( constraint.Value().HasMax() && via->GetDrillValue() > constraint.Value().Max() )
|
|
|
|
{
|
|
|
|
fail_max = true;
|
|
|
|
constraintValue = constraint.Value().Max();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( fail_min || fail_max )
|
2020-07-27 13:33:06 +00:00
|
|
|
{
|
2020-08-11 22:15:50 +00:00
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( errorCode );
|
2020-07-27 13:33:06 +00:00
|
|
|
|
2021-01-03 22:57:51 +00:00
|
|
|
if( fail_min )
|
|
|
|
{
|
|
|
|
m_msg.Printf( _( "(%s min width %s; actual %s)" ),
|
|
|
|
constraint.GetName(),
|
|
|
|
MessageTextFromValue( userUnits(), constraintValue ),
|
|
|
|
MessageTextFromValue( userUnits(), via->GetDrillValue() ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_msg.Printf( _( "(%s max width %s; actual %s)" ),
|
|
|
|
constraint.GetName(),
|
|
|
|
MessageTextFromValue( userUnits(), constraintValue ),
|
|
|
|
MessageTextFromValue( userUnits(), via->GetDrillValue() ) );
|
|
|
|
}
|
2020-07-27 13:33:06 +00:00
|
|
|
|
2020-11-02 16:20:00 +00:00
|
|
|
drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + m_msg );
|
2020-07-27 13:33:06 +00:00
|
|
|
drcItem->SetItems( via );
|
2020-09-11 21:50:53 +00:00
|
|
|
drcItem->SetViolatingRule( constraint.GetParentRule() );
|
2020-07-27 13:33:06 +00:00
|
|
|
|
2021-12-26 13:47:00 +00:00
|
|
|
reportViolation( drcItem, via->GetPosition(), UNDEFINED_LAYER );
|
2020-07-27 13:33:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace detail
|
|
|
|
{
|
2020-09-11 21:50:53 +00:00
|
|
|
static DRC_REGISTER_TEST_PROVIDER<DRC_TEST_PROVIDER_HOLE_SIZE> dummy;
|
2020-07-31 01:46:05 +00:00
|
|
|
}
|