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-11-12 20:19:22 +00:00
|
|
|
#include <pad.h>
|
|
|
|
#include <track.h>
|
2020-09-11 15:04:11 +00:00
|
|
|
#include <drc/drc_engine.h>
|
|
|
|
#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>
|
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:
|
|
|
|
- DRCE_TOO_SMALL_DRILL
|
|
|
|
- DRCE_TOO_SMALL_MICROVIA_DRILL
|
|
|
|
|
|
|
|
TODO: max drill size check
|
|
|
|
*/
|
|
|
|
|
|
|
|
class DRC_TEST_PROVIDER_HOLE_SIZE : public DRC_TEST_PROVIDER
|
|
|
|
{
|
|
|
|
public:
|
2020-07-31 01:46:05 +00:00
|
|
|
DRC_TEST_PROVIDER_HOLE_SIZE() :
|
|
|
|
m_board( nullptr )
|
2020-07-27 13:33:06 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~DRC_TEST_PROVIDER_HOLE_SIZE()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool Run() override;
|
|
|
|
|
|
|
|
virtual const wxString GetName() const override
|
|
|
|
{
|
|
|
|
return "hole_size";
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual const wxString GetDescription() const override
|
|
|
|
{
|
|
|
|
return "Tests sizes of drilled holes (via/pad drills)";
|
|
|
|
}
|
|
|
|
|
2020-09-13 10:37:20 +00:00
|
|
|
virtual std::set<DRC_CONSTRAINT_TYPE_T> GetConstraintTypes() const override;
|
2020-07-27 13:33:06 +00:00
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
int GetNumPhases() const override;
|
|
|
|
|
2020-07-27 13:33:06 +00:00
|
|
|
private:
|
2020-09-12 19:28:22 +00:00
|
|
|
void checkVia( VIA* via, bool aExceedMicro, bool aExceedStd );
|
2020-11-12 22:30:02 +00:00
|
|
|
void checkPad( PAD* aPad );
|
2020-07-27 13:33:06 +00:00
|
|
|
|
|
|
|
BOARD* m_board;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-09-11 21:50:53 +00:00
|
|
|
bool DRC_TEST_PROVIDER_HOLE_SIZE::Run()
|
2020-07-27 13:33:06 +00:00
|
|
|
{
|
2020-09-18 19:57:54 +00:00
|
|
|
if( !reportPhase( _( "Checking pad holes..." ) ) )
|
|
|
|
return false;
|
2020-07-27 13:33:06 +00:00
|
|
|
|
2020-09-04 23:19:01 +00:00
|
|
|
m_board = m_drcEngine->GetBoard();
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2020-07-27 13:33:06 +00:00
|
|
|
{
|
2020-09-12 19:28:22 +00:00
|
|
|
if( m_drcEngine->IsErrorLimitExceeded( DRCE_TOO_SMALL_DRILL ) )
|
|
|
|
break;
|
|
|
|
|
2020-11-12 23:50:33 +00:00
|
|
|
for( PAD* pad : footprint->Pads() )
|
2020-07-27 13:33:06 +00:00
|
|
|
{
|
2020-09-12 19:28:22 +00:00
|
|
|
if( m_drcEngine->IsErrorLimitExceeded( DRCE_TOO_SMALL_DRILL ) )
|
2020-07-27 13:33:06 +00:00
|
|
|
break;
|
2020-09-12 19:28:22 +00:00
|
|
|
|
|
|
|
checkPad( pad );
|
2020-07-27 13:33:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-18 19:57:54 +00:00
|
|
|
if( !reportPhase( _( "Checking via holes..." ) ) )
|
|
|
|
return false;
|
2020-07-27 13:33:06 +00:00
|
|
|
|
|
|
|
std::vector<VIA*> vias;
|
|
|
|
|
2020-09-11 21:50:53 +00:00
|
|
|
for( TRACK* track : m_board->Tracks() )
|
2020-07-27 13:33:06 +00:00
|
|
|
{
|
|
|
|
if( track->Type() == PCB_VIA_T )
|
|
|
|
vias.push_back( static_cast<VIA*>( track ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-11 21:50:53 +00:00
|
|
|
for( VIA* via : vias )
|
2020-07-27 13:33:06 +00:00
|
|
|
{
|
2020-09-12 19:28:22 +00:00
|
|
|
bool exceedMicro = m_drcEngine->IsErrorLimitExceeded( DRCE_TOO_SMALL_MICROVIA_DRILL );
|
|
|
|
bool exceedStd = m_drcEngine->IsErrorLimitExceeded( DRCE_TOO_SMALL_DRILL );
|
|
|
|
|
|
|
|
if( exceedMicro && exceedStd )
|
2020-07-27 13:33:06 +00:00
|
|
|
break;
|
2020-09-12 19:28:22 +00:00
|
|
|
|
|
|
|
checkVia( via, exceedMicro, exceedStd );
|
2020-07-27 13:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
reportRuleStatistics();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
void DRC_TEST_PROVIDER_HOLE_SIZE::checkPad( PAD* aPad )
|
2020-07-27 13:33:06 +00:00
|
|
|
{
|
|
|
|
int holeSize = std::min( aPad->GetDrillSize().x, aPad->GetDrillSize().y );
|
|
|
|
|
|
|
|
if( holeSize == 0 )
|
2020-09-12 19:28:22 +00:00
|
|
|
return;
|
2020-07-27 13:33:06 +00:00
|
|
|
|
2020-11-02 16:20:00 +00:00
|
|
|
auto constraint = m_drcEngine->EvalRulesForItems( HOLE_SIZE_CONSTRAINT, aPad );
|
2020-09-11 21:50:53 +00:00
|
|
|
int minHole = constraint.GetValue().Min();
|
2020-07-27 13:33:06 +00:00
|
|
|
|
2020-08-11 22:17:43 +00:00
|
|
|
accountCheck( constraint );
|
2020-07-27 13:33:06 +00:00
|
|
|
|
|
|
|
if( holeSize < minHole )
|
|
|
|
{
|
2020-08-11 22:15:50 +00:00
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_TOO_SMALL_DRILL );
|
2020-07-27 13:33:06 +00:00
|
|
|
|
2020-11-02 16:20:00 +00:00
|
|
|
m_msg.Printf( _( "(%s %s; actual %s)" ),
|
2020-09-11 21:50:53 +00:00
|
|
|
constraint.GetName(),
|
2020-10-02 20:51:24 +00:00
|
|
|
MessageTextFromValue( userUnits(), minHole ),
|
|
|
|
MessageTextFromValue( userUnits(), holeSize ) );
|
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
|
|
|
|
2020-11-24 22:16:41 +00:00
|
|
|
reportViolation( drcItem, aPad->GetPosition() );
|
2020-07-27 13:33:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-12 19:28:22 +00:00
|
|
|
void DRC_TEST_PROVIDER_HOLE_SIZE::checkVia( 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;
|
|
|
|
|
|
|
|
errorCode = DRCE_TOO_SMALL_MICROVIA_DRILL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( aExceedStd )
|
|
|
|
return;
|
|
|
|
|
|
|
|
errorCode = DRCE_TOO_SMALL_DRILL;
|
|
|
|
}
|
|
|
|
|
2020-11-02 16:20:00 +00:00
|
|
|
auto constraint = m_drcEngine->EvalRulesForItems( HOLE_SIZE_CONSTRAINT, via );
|
2020-09-11 21:50:53 +00:00
|
|
|
int minHole = constraint.GetValue().Min();
|
2020-07-27 13:33:06 +00:00
|
|
|
|
2020-08-11 22:17:43 +00:00
|
|
|
accountCheck( constraint );
|
2020-07-27 13:33:06 +00:00
|
|
|
|
|
|
|
if( via->GetDrillValue() < minHole )
|
|
|
|
{
|
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
|
|
|
|
2020-11-02 16:20:00 +00:00
|
|
|
m_msg.Printf( _( "(%s %s; actual %s)" ),
|
2020-09-11 21:50:53 +00:00
|
|
|
constraint.GetName(),
|
2020-10-02 20:51:24 +00:00
|
|
|
MessageTextFromValue( userUnits(), minHole ),
|
|
|
|
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
|
|
|
|
2020-11-24 22:16:41 +00:00
|
|
|
reportViolation( drcItem, via->GetPosition() );
|
2020-07-27 13:33:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
int DRC_TEST_PROVIDER_HOLE_SIZE::GetNumPhases() const
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-13 10:37:20 +00:00
|
|
|
std::set<DRC_CONSTRAINT_TYPE_T> DRC_TEST_PROVIDER_HOLE_SIZE::GetConstraintTypes() const
|
2020-07-27 13:33:06 +00:00
|
|
|
{
|
2020-11-02 16:20:00 +00:00
|
|
|
return { HOLE_SIZE_CONSTRAINT };
|
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
|
|
|
}
|