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-19 21:34:19 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <class_pad.h>
|
2020-09-15 19:13:45 +00:00
|
|
|
#include <class_track.h>
|
2020-07-22 23:05:37 +00:00
|
|
|
#include <geometry/shape_segment.h>
|
2020-10-27 20:15:54 +00:00
|
|
|
#include <geometry/shape_circle.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-10-27 17:09:27 +00:00
|
|
|
#include "drc_rtree.h"
|
2020-06-19 21:34:19 +00:00
|
|
|
|
2020-07-27 13:33:06 +00:00
|
|
|
/*
|
|
|
|
Holes clearance test. Checks pad and via holes for their mechanical clearances.
|
|
|
|
Generated errors:
|
|
|
|
- DRCE_HOLE_CLEARANCE
|
|
|
|
|
|
|
|
TODO: vias-in-smd-pads check
|
|
|
|
*/
|
|
|
|
|
2020-06-19 21:34:19 +00:00
|
|
|
class DRC_TEST_PROVIDER_HOLE_CLEARANCE : public DRC_TEST_PROVIDER_CLEARANCE_BASE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DRC_TEST_PROVIDER_HOLE_CLEARANCE () :
|
2020-07-31 01:46:05 +00:00
|
|
|
DRC_TEST_PROVIDER_CLEARANCE_BASE(),
|
2020-10-27 17:09:27 +00:00
|
|
|
m_board( nullptr )
|
|
|
|
{
|
|
|
|
}
|
2020-06-19 21:34:19 +00:00
|
|
|
|
2020-07-31 01:46:05 +00:00
|
|
|
virtual ~DRC_TEST_PROVIDER_HOLE_CLEARANCE()
|
2020-06-19 21:34:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool Run() override;
|
|
|
|
|
2020-07-31 01:46:05 +00:00
|
|
|
virtual const wxString GetName() const override
|
2020-06-19 21:34:19 +00:00
|
|
|
{
|
2020-07-31 01:46:05 +00:00
|
|
|
return "hole_clearance";
|
2020-06-19 21:34:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual const wxString GetDescription() const override
|
|
|
|
{
|
2020-10-27 17:09:27 +00:00
|
|
|
return "Tests hole to hole spacing";
|
2020-06-19 21:34:19 +00:00
|
|
|
}
|
|
|
|
|
2020-09-13 10:37:20 +00:00
|
|
|
virtual std::set<DRC_CONSTRAINT_TYPE_T> GetConstraintTypes() const override;
|
2020-06-19 21:34:19 +00:00
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
int GetNumPhases() const override;
|
|
|
|
|
2020-06-19 21:34:19 +00:00
|
|
|
private:
|
2020-10-28 12:24:10 +00:00
|
|
|
bool testHoleAgainstHole( BOARD_ITEM* aItem, SHAPE_CIRCLE* aHole, BOARD_ITEM* aOther );
|
2020-07-15 16:23:56 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
BOARD* m_board;
|
|
|
|
DRC_RTREE m_holeTree;
|
2020-06-19 21:34:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
static std::shared_ptr<SHAPE_CIRCLE> getDrilledHoleShape( BOARD_ITEM* aItem )
|
|
|
|
{
|
|
|
|
if( aItem->Type() == PCB_VIA_T )
|
|
|
|
{
|
|
|
|
VIA* via = static_cast<VIA*>( aItem );
|
|
|
|
return std::make_shared<SHAPE_CIRCLE>( via->GetCenter(), via->GetDrillValue() / 2 );
|
|
|
|
}
|
|
|
|
else if( aItem->Type() == PCB_PAD_T )
|
|
|
|
{
|
|
|
|
D_PAD* pad = static_cast<D_PAD*>( aItem );
|
|
|
|
return std::make_shared<SHAPE_CIRCLE>( pad->GetPosition(), pad->GetDrillSize().x / 2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::make_shared<SHAPE_CIRCLE>( VECTOR2I( 0, 0 ), 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-11 21:50:53 +00:00
|
|
|
bool DRC_TEST_PROVIDER_HOLE_CLEARANCE::Run()
|
2020-06-19 21:34:19 +00:00
|
|
|
{
|
|
|
|
m_board = m_drcEngine->GetBoard();
|
2020-06-30 08:42:43 +00:00
|
|
|
|
2020-08-11 22:17:43 +00:00
|
|
|
DRC_CONSTRAINT worstClearanceConstraint;
|
|
|
|
|
2020-11-02 16:20:00 +00:00
|
|
|
if( m_drcEngine->QueryWorstConstraint( HOLE_CLEARANCE_CONSTRAINT, worstClearanceConstraint ) )
|
2020-06-30 08:42:43 +00:00
|
|
|
{
|
2020-08-11 22:17:43 +00:00
|
|
|
m_largestClearance = worstClearanceConstraint.GetValue().Min();
|
2020-09-14 17:54:14 +00:00
|
|
|
reportAux( "Worst hole clearance : %d nm", m_largestClearance );
|
2020-06-30 08:42:43 +00:00
|
|
|
}
|
2020-08-11 22:17:43 +00:00
|
|
|
else
|
|
|
|
{
|
2020-09-14 17:54:14 +00:00
|
|
|
reportAux( "No hole clearance constraints found..." );
|
2020-08-11 22:17:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
// This is the number of tests between 2 calls to the progress bar
|
|
|
|
const size_t delta = 50;
|
|
|
|
size_t count = 0;
|
|
|
|
size_t ii = 0;
|
2020-07-27 13:33:06 +00:00
|
|
|
|
2020-10-29 13:18:15 +00:00
|
|
|
m_holeTree.clear();
|
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
auto countItems =
|
|
|
|
[&]( BOARD_ITEM* item ) -> bool
|
|
|
|
{
|
|
|
|
if( item->Type() == PCB_PAD_T )
|
|
|
|
++count;
|
|
|
|
else if( item->Type() == PCB_VIA_T )
|
|
|
|
++count;
|
2020-06-19 21:34:19 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
return true;
|
|
|
|
};
|
2020-06-19 21:34:19 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
auto addToHoleTree =
|
|
|
|
[&]( BOARD_ITEM* item ) -> bool
|
|
|
|
{
|
|
|
|
if( !reportProgress( ii++, count, delta ) )
|
|
|
|
return false;
|
2020-06-19 21:34:19 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
item->ClearFlags( SKIP_STRUCT );
|
2020-06-19 21:34:19 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
if( item->Type() == PCB_PAD_T )
|
|
|
|
{
|
|
|
|
D_PAD* pad = static_cast<D_PAD*>( item );
|
2020-06-19 21:34:19 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
// Check for round hole
|
|
|
|
if( pad->GetDrillSize().x && pad->GetDrillSize().x == pad->GetDrillSize().y )
|
2020-11-01 14:03:13 +00:00
|
|
|
m_holeTree.Insert( item, m_largestClearance, F_Cu );
|
2020-10-27 17:09:27 +00:00
|
|
|
}
|
|
|
|
else if( item->Type() == PCB_VIA_T )
|
|
|
|
{
|
|
|
|
VIA* via = static_cast<VIA*>( item );
|
2020-09-11 16:24:27 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
// Check for drilled hole
|
|
|
|
if( via->GetViaType() == VIATYPE::THROUGH )
|
2020-11-01 14:03:13 +00:00
|
|
|
m_holeTree.Insert( item, m_largestClearance, F_Cu );
|
2020-10-27 17:09:27 +00:00
|
|
|
}
|
2020-09-11 16:24:27 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
return true;
|
|
|
|
};
|
2020-09-17 13:36:34 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
if( !reportPhase( _( "Checking hole to hole clearances..." ) ) )
|
|
|
|
return false;
|
2020-06-19 21:34:19 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
forEachGeometryItem( { PCB_PAD_T, PCB_VIA_T }, LSET::AllLayersMask(), countItems );
|
2020-06-19 21:34:19 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
count *= 2; // One for adding to tree; one for checking
|
2020-06-19 21:34:19 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
forEachGeometryItem( { PCB_PAD_T, PCB_VIA_T }, LSET::AllLayersMask(), addToHoleTree );
|
2020-06-19 21:34:19 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
for( TRACK* track : m_board->Tracks() )
|
2020-06-19 21:34:19 +00:00
|
|
|
{
|
2020-10-27 17:09:27 +00:00
|
|
|
if( track->Type() != PCB_VIA_T )
|
2020-06-19 21:34:19 +00:00
|
|
|
continue;
|
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
VIA* via = static_cast<VIA*>( track );
|
2020-07-31 01:46:05 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
if( !reportProgress( ii++, count, delta ) )
|
2020-06-19 21:34:19 +00:00
|
|
|
break;
|
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
std::shared_ptr<SHAPE_CIRCLE> holeShape = getDrilledHoleShape( via );
|
2020-06-19 21:34:19 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
m_holeTree.QueryColliding( via, F_Cu, F_Cu,
|
2020-11-02 16:20:00 +00:00
|
|
|
// Filter:
|
2020-10-27 17:09:27 +00:00
|
|
|
[&]( BOARD_ITEM* other ) -> bool
|
|
|
|
{
|
|
|
|
if( other->HasFlag( SKIP_STRUCT ) )
|
|
|
|
return false;
|
2020-07-15 16:23:56 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
return true;
|
|
|
|
},
|
2020-11-02 16:20:00 +00:00
|
|
|
// Visitor:
|
2020-10-28 13:52:30 +00:00
|
|
|
[&]( BOARD_ITEM* other ) -> bool
|
2020-10-27 17:09:27 +00:00
|
|
|
{
|
2020-10-28 12:24:10 +00:00
|
|
|
return testHoleAgainstHole( via, holeShape.get(), other );
|
2020-10-27 17:09:27 +00:00
|
|
|
},
|
|
|
|
m_largestClearance );
|
2020-07-27 13:33:06 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
via->SetFlags( SKIP_STRUCT );
|
|
|
|
}
|
2020-06-19 21:34:19 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
for( MODULE* footprint : m_board->Modules() )
|
|
|
|
{
|
|
|
|
for( D_PAD* pad : footprint->Pads() )
|
2020-10-13 15:31:36 +00:00
|
|
|
{
|
2020-10-27 17:09:27 +00:00
|
|
|
if( !reportProgress( ii++, count, delta ) )
|
|
|
|
break;
|
2020-09-11 16:24:27 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
std::shared_ptr<SHAPE_CIRCLE> holeShape = getDrilledHoleShape( pad );
|
2020-10-13 15:31:36 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
m_holeTree.QueryColliding( pad, F_Cu, F_Cu,
|
2020-11-02 16:20:00 +00:00
|
|
|
// Filter:
|
2020-10-27 17:09:27 +00:00
|
|
|
[&]( BOARD_ITEM* other ) -> bool
|
|
|
|
{
|
|
|
|
if( other->HasFlag( SKIP_STRUCT ) )
|
|
|
|
return false;
|
2020-06-19 21:34:19 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
return true;
|
|
|
|
},
|
2020-11-02 16:20:00 +00:00
|
|
|
// Visitor:
|
2020-10-28 13:52:30 +00:00
|
|
|
[&]( BOARD_ITEM* other ) -> bool
|
2020-10-27 17:09:27 +00:00
|
|
|
{
|
2020-10-28 12:24:10 +00:00
|
|
|
return testHoleAgainstHole( pad, holeShape.get(), other );
|
2020-10-27 17:09:27 +00:00
|
|
|
},
|
|
|
|
m_largestClearance );
|
2020-06-19 21:34:19 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
pad->SetFlags( SKIP_STRUCT );
|
2020-06-19 21:34:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
reportRuleStatistics();
|
2020-07-27 13:33:06 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
return true;
|
2020-07-27 13:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-28 12:24:10 +00:00
|
|
|
bool DRC_TEST_PROVIDER_HOLE_CLEARANCE::testHoleAgainstHole( BOARD_ITEM* aItem, SHAPE_CIRCLE* aHole,
|
|
|
|
BOARD_ITEM* aOther )
|
2020-07-27 13:33:06 +00:00
|
|
|
{
|
2020-10-27 17:09:27 +00:00
|
|
|
if( m_drcEngine->IsErrorLimitExceeded( DRCE_DRILLED_HOLES_TOO_CLOSE ) )
|
|
|
|
return false;
|
2020-09-12 19:28:22 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
std::shared_ptr<SHAPE_CIRCLE> otherHole = getDrilledHoleShape( aItem );
|
2020-07-27 13:33:06 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
// Holes with identical locations are allowable
|
|
|
|
if( aHole->GetCenter() == otherHole->GetCenter() )
|
|
|
|
return true;
|
2020-07-27 13:33:06 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
int actual = ( aHole->GetCenter() - otherHole->GetCenter() ).EuclideanNorm();
|
|
|
|
actual = std::max( 0, actual - aHole->GetRadius() - otherHole->GetRadius() );
|
2020-07-27 13:33:06 +00:00
|
|
|
|
2020-11-02 16:20:00 +00:00
|
|
|
auto constraint = m_drcEngine->EvalRulesForItems( HOLE_CLEARANCE_CONSTRAINT, aItem, aOther );
|
2020-10-27 17:09:27 +00:00
|
|
|
int minClearance = constraint.GetValue().Min();
|
2020-07-27 13:33:06 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
accountCheck( constraint.GetParentRule() );
|
2020-07-31 01:46:05 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
if( actual < minClearance )
|
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( DRCE_DRILLED_HOLES_TOO_CLOSE );
|
2020-07-27 13:33:06 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
m_msg.Printf( _( "(%s clearance %s; actual %s)" ),
|
|
|
|
constraint.GetName(),
|
|
|
|
MessageTextFromValue( userUnits(), minClearance ),
|
|
|
|
MessageTextFromValue( userUnits(), actual ) );
|
2020-07-27 13:33:06 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + m_msg );
|
|
|
|
drce->SetItems( aItem, aOther );
|
|
|
|
drce->SetViolatingRule( constraint.GetParentRule() );
|
2020-07-27 13:33:06 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
reportViolation( drce, (wxPoint) aHole->GetCenter() );
|
2020-07-27 13:33:06 +00:00
|
|
|
}
|
2020-10-27 17:09:27 +00:00
|
|
|
|
|
|
|
return true;
|
2020-07-27 13:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
int DRC_TEST_PROVIDER_HOLE_CLEARANCE::GetNumPhases() const
|
|
|
|
{
|
2020-10-27 17:09:27 +00:00
|
|
|
return 1;
|
2020-09-14 17:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-13 10:37:20 +00:00
|
|
|
std::set<DRC_CONSTRAINT_TYPE_T> DRC_TEST_PROVIDER_HOLE_CLEARANCE::GetConstraintTypes() const
|
2020-06-19 21:34:19 +00:00
|
|
|
{
|
2020-11-02 16:20:00 +00:00
|
|
|
return { HOLE_CLEARANCE_CONSTRAINT };
|
2020-06-19 21:34:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace detail
|
|
|
|
{
|
2020-09-11 21:50:53 +00:00
|
|
|
static DRC_REGISTER_TEST_PROVIDER<DRC_TEST_PROVIDER_HOLE_CLEARANCE> dummy;
|
2020-07-31 01:46:05 +00:00
|
|
|
}
|