2020-09-23 21:49:18 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2020-10-12 09:27:12 +00:00
|
|
|
#include <pcb_shape.h>
|
2020-09-23 21:49:18 +00:00
|
|
|
|
|
|
|
#include <geometry/seg.h>
|
|
|
|
#include <geometry/shape_segment.h>
|
|
|
|
|
|
|
|
#include <drc/drc_item.h>
|
|
|
|
#include <drc/drc_rule.h>
|
|
|
|
#include <drc/drc_test_provider_clearance_base.h>
|
|
|
|
|
|
|
|
#include <drc/drc_rtree.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
Silk to silk clearance test. Check all silkscreen features against each other.
|
|
|
|
Errors generated:
|
2020-10-11 21:30:43 +00:00
|
|
|
- DRCE_OVERLAPPING_SILK
|
2020-09-23 21:49:18 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2020-10-11 10:51:23 +00:00
|
|
|
class DRC_TEST_PROVIDER_SILK_CLEARANCE : public DRC_TEST_PROVIDER
|
2020-09-23 21:49:18 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-10-26 09:46:08 +00:00
|
|
|
DRC_TEST_PROVIDER_SILK_CLEARANCE ():
|
|
|
|
m_board( nullptr ),
|
|
|
|
m_largestClearance( 0 )
|
2020-09-23 21:49:18 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-10-11 10:51:23 +00:00
|
|
|
virtual ~DRC_TEST_PROVIDER_SILK_CLEARANCE()
|
2020-09-23 21:49:18 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool Run() override;
|
|
|
|
|
2020-10-12 23:47:36 +00:00
|
|
|
virtual const wxString GetName() const override
|
2020-09-23 21:49:18 +00:00
|
|
|
{
|
2020-10-11 10:51:23 +00:00
|
|
|
return "silk_clearance";
|
2020-09-23 21:49:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual const wxString GetDescription() const override
|
|
|
|
{
|
|
|
|
return "Tests for overlapping silkscreen features.";
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int GetNumPhases() const override
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-01-01 22:29:15 +00:00
|
|
|
virtual std::set<DRC_CONSTRAINT_T> GetConstraintTypes() const override;
|
2020-09-23 21:49:18 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
BOARD* m_board;
|
|
|
|
int m_largestClearance;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-10-11 10:51:23 +00:00
|
|
|
bool DRC_TEST_PROVIDER_SILK_CLEARANCE::Run()
|
2020-09-23 21:49:18 +00:00
|
|
|
{
|
2020-10-27 17:09:27 +00:00
|
|
|
// This is the number of tests between 2 calls to the progress bar
|
|
|
|
const int delta = 250;
|
|
|
|
|
2020-09-23 21:49:18 +00:00
|
|
|
m_board = m_drcEngine->GetBoard();
|
|
|
|
|
|
|
|
DRC_CONSTRAINT worstClearanceConstraint;
|
|
|
|
m_largestClearance = 0;
|
|
|
|
|
2020-10-14 10:18:09 +00:00
|
|
|
if( m_drcEngine->IsErrorLimitExceeded( DRCE_OVERLAPPING_SILK ) )
|
|
|
|
{
|
|
|
|
reportAux( "Silkscreen clearance testing not run." );
|
2020-10-17 10:27:27 +00:00
|
|
|
return true;
|
2020-10-14 10:18:09 +00:00
|
|
|
}
|
|
|
|
|
2020-11-02 16:20:00 +00:00
|
|
|
if( m_drcEngine->QueryWorstConstraint( SILK_CLEARANCE_CONSTRAINT, worstClearanceConstraint ) )
|
2020-09-23 21:49:18 +00:00
|
|
|
m_largestClearance = worstClearanceConstraint.m_Value.Min();
|
|
|
|
|
|
|
|
reportAux( "Worst clearance : %d nm", m_largestClearance );
|
2020-10-05 13:31:10 +00:00
|
|
|
|
|
|
|
if( !reportPhase( _( "Checking silkscreen for overlapping items..." ) ) )
|
|
|
|
return false;
|
2020-09-23 21:49:18 +00:00
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
DRC_RTREE silkTree;
|
|
|
|
DRC_RTREE targetTree;
|
|
|
|
int ii = 0;
|
|
|
|
int targets = 0;
|
2020-09-23 21:49:18 +00:00
|
|
|
|
2020-10-11 10:51:23 +00:00
|
|
|
auto addToSilkTree =
|
2020-10-27 17:09:27 +00:00
|
|
|
[&silkTree]( BOARD_ITEM* item ) -> bool
|
2020-09-23 21:49:18 +00:00
|
|
|
{
|
2020-11-01 14:03:13 +00:00
|
|
|
silkTree.Insert( item );
|
2020-09-23 21:49:18 +00:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2020-10-27 17:09:27 +00:00
|
|
|
auto countTargets =
|
|
|
|
[&targets]( BOARD_ITEM* item ) -> bool
|
|
|
|
{
|
|
|
|
++targets;
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2020-10-11 10:51:23 +00:00
|
|
|
auto addToTargetTree =
|
2020-10-27 17:09:27 +00:00
|
|
|
[&]( BOARD_ITEM* item ) -> bool
|
2020-10-11 10:51:23 +00:00
|
|
|
{
|
2020-10-27 17:09:27 +00:00
|
|
|
if( !reportProgress( ii++, targets, delta ) )
|
|
|
|
return false;
|
|
|
|
|
2020-11-01 14:03:13 +00:00
|
|
|
targetTree.Insert( item );
|
2020-10-11 10:51:23 +00:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2020-09-28 22:27:33 +00:00
|
|
|
auto checkClearance =
|
2020-10-04 11:46:35 +00:00
|
|
|
[&]( const DRC_RTREE::LAYER_PAIR& aLayers, DRC_RTREE::ITEM_WITH_SHAPE* aRefItem,
|
|
|
|
DRC_RTREE::ITEM_WITH_SHAPE* aTestItem, bool* aCollisionDetected ) -> bool
|
2020-09-28 22:27:33 +00:00
|
|
|
{
|
2020-10-11 21:30:43 +00:00
|
|
|
if( m_drcEngine->IsErrorLimitExceeded( DRCE_OVERLAPPING_SILK ) )
|
2020-09-29 20:22:45 +00:00
|
|
|
return false;
|
|
|
|
|
2021-01-23 00:09:18 +00:00
|
|
|
if( isInvisibleText( aRefItem->parent ) || isInvisibleText( aTestItem->parent ) )
|
2020-10-12 09:27:12 +00:00
|
|
|
return true;
|
|
|
|
|
2021-02-08 14:53:49 +00:00
|
|
|
auto constraint = m_drcEngine->EvalRules( SILK_CLEARANCE_CONSTRAINT,
|
|
|
|
aRefItem->parent, aTestItem->parent,
|
|
|
|
aLayers.second );
|
2020-10-12 20:13:02 +00:00
|
|
|
|
|
|
|
if( constraint.IsNull() )
|
|
|
|
return true;
|
|
|
|
|
2021-01-23 00:09:18 +00:00
|
|
|
int minClearance = constraint.GetValue().Min();
|
|
|
|
|
|
|
|
if( minClearance < 0 )
|
|
|
|
return true;
|
|
|
|
|
2020-09-28 22:27:33 +00:00
|
|
|
int actual;
|
|
|
|
VECTOR2I pos;
|
2020-09-23 21:49:18 +00:00
|
|
|
|
2020-10-12 09:27:12 +00:00
|
|
|
// Graphics are often compound shapes so ignore collisions between shapes in a
|
|
|
|
// single footprint or on the board.
|
|
|
|
PCB_SHAPE* refGraphic = dynamic_cast<PCB_SHAPE*>( aRefItem->parent );
|
|
|
|
PCB_SHAPE* testGraphic = dynamic_cast<PCB_SHAPE*>( aTestItem->parent );
|
2020-09-23 21:49:18 +00:00
|
|
|
|
2020-10-12 09:27:12 +00:00
|
|
|
if( refGraphic && testGraphic )
|
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT *refParentFP = dynamic_cast<FOOTPRINT*>( refGraphic->GetParent() );
|
|
|
|
FOOTPRINT *testParentFP = dynamic_cast<FOOTPRINT*>( testGraphic->GetParent() );
|
2020-09-23 21:49:18 +00:00
|
|
|
|
2020-10-12 09:27:12 +00:00
|
|
|
if( refParentFP == testParentFP ) // also true when both are nullptr
|
2020-09-28 22:27:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
2020-09-23 21:49:18 +00:00
|
|
|
|
2021-01-23 00:09:18 +00:00
|
|
|
if( aRefItem->shape->Collide( aTestItem->shape, minClearance, &actual, &pos ) )
|
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_OVERLAPPING_SILK );
|
2020-09-23 21:49:18 +00:00
|
|
|
|
2021-01-23 00:09:18 +00:00
|
|
|
if( minClearance > 0 )
|
|
|
|
{
|
|
|
|
m_msg.Printf( _( "(%s clearance %s; actual %s)" ),
|
|
|
|
constraint.GetParentRule()->m_Name,
|
|
|
|
MessageTextFromValue( userUnits(), minClearance ),
|
|
|
|
MessageTextFromValue( userUnits(), actual ) );
|
2020-10-06 12:20:29 +00:00
|
|
|
|
2021-01-23 00:09:18 +00:00
|
|
|
drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + m_msg );
|
|
|
|
}
|
2020-10-06 12:20:29 +00:00
|
|
|
|
2021-01-23 00:09:18 +00:00
|
|
|
drcItem->SetItems( aRefItem->parent, aTestItem->parent );
|
|
|
|
drcItem->SetViolatingRule( constraint.GetParentRule() );
|
2020-10-06 12:20:29 +00:00
|
|
|
|
2021-01-23 00:09:18 +00:00
|
|
|
reportViolation( drcItem, (wxPoint) pos );
|
2020-09-23 21:49:18 +00:00
|
|
|
|
2021-01-23 00:09:18 +00:00
|
|
|
*aCollisionDetected = true;
|
|
|
|
}
|
2020-09-23 21:49:18 +00:00
|
|
|
|
2020-09-29 20:22:45 +00:00
|
|
|
return true;
|
2020-09-28 22:27:33 +00:00
|
|
|
};
|
2020-09-23 21:49:18 +00:00
|
|
|
|
2020-10-25 20:24:47 +00:00
|
|
|
forEachGeometryItem( s_allBasicItems, LSET( 2, F_SilkS, B_SilkS ), addToSilkTree );
|
2020-11-20 21:22:27 +00:00
|
|
|
forEachGeometryItem( s_allBasicItems,
|
|
|
|
LSET::FrontMask() | LSET::BackMask() | LSET( 2, Edge_Cuts, Margin ),
|
|
|
|
countTargets );
|
2020-10-27 17:09:27 +00:00
|
|
|
|
|
|
|
targets *= 2; // One for adding to RTree; one for testing
|
|
|
|
|
2020-11-20 21:22:27 +00:00
|
|
|
forEachGeometryItem( s_allBasicItems,
|
|
|
|
LSET::FrontMask() | LSET::BackMask() | LSET( 2, Edge_Cuts, Margin ),
|
|
|
|
addToTargetTree );
|
2020-09-23 21:49:18 +00:00
|
|
|
|
2020-10-11 13:15:22 +00:00
|
|
|
reportAux( _("Testing %d silkscreen features against %d board items."),
|
|
|
|
silkTree.size(),
|
|
|
|
targetTree.size() );
|
2020-09-23 21:49:18 +00:00
|
|
|
|
|
|
|
const std::vector<DRC_RTREE::LAYER_PAIR> layerPairs =
|
|
|
|
{
|
|
|
|
DRC_RTREE::LAYER_PAIR( F_SilkS, F_SilkS ),
|
2020-10-11 10:51:23 +00:00
|
|
|
DRC_RTREE::LAYER_PAIR( F_SilkS, F_Mask ),
|
|
|
|
DRC_RTREE::LAYER_PAIR( F_SilkS, F_Adhes ),
|
|
|
|
DRC_RTREE::LAYER_PAIR( F_SilkS, F_Paste ),
|
|
|
|
DRC_RTREE::LAYER_PAIR( F_SilkS, F_CrtYd ),
|
|
|
|
DRC_RTREE::LAYER_PAIR( F_SilkS, F_Fab ),
|
|
|
|
DRC_RTREE::LAYER_PAIR( F_SilkS, F_Cu ),
|
|
|
|
DRC_RTREE::LAYER_PAIR( F_SilkS, Edge_Cuts ),
|
2020-11-20 21:22:27 +00:00
|
|
|
DRC_RTREE::LAYER_PAIR( F_SilkS, Margin ),
|
2020-10-11 10:51:23 +00:00
|
|
|
DRC_RTREE::LAYER_PAIR( B_SilkS, B_SilkS ),
|
|
|
|
DRC_RTREE::LAYER_PAIR( B_SilkS, B_Mask ),
|
|
|
|
DRC_RTREE::LAYER_PAIR( B_SilkS, B_Adhes ),
|
|
|
|
DRC_RTREE::LAYER_PAIR( B_SilkS, B_Paste ),
|
|
|
|
DRC_RTREE::LAYER_PAIR( B_SilkS, B_CrtYd ),
|
|
|
|
DRC_RTREE::LAYER_PAIR( B_SilkS, B_Fab ),
|
|
|
|
DRC_RTREE::LAYER_PAIR( B_SilkS, B_Cu ),
|
2020-11-20 21:22:27 +00:00
|
|
|
DRC_RTREE::LAYER_PAIR( B_SilkS, Edge_Cuts ),
|
|
|
|
DRC_RTREE::LAYER_PAIR( B_SilkS, Margin )
|
2020-09-23 21:49:18 +00:00
|
|
|
};
|
|
|
|
|
2020-10-12 22:59:01 +00:00
|
|
|
targetTree.QueryCollidingPairs( &silkTree, layerPairs, checkClearance, m_largestClearance,
|
2020-10-12 23:47:36 +00:00
|
|
|
[&]( int aCount, int aSize ) -> bool
|
2020-10-12 22:59:01 +00:00
|
|
|
{
|
2020-10-27 17:09:27 +00:00
|
|
|
return reportProgress( ++ii, targets, delta );
|
2020-10-12 22:59:01 +00:00
|
|
|
} );
|
2020-09-23 21:49:18 +00:00
|
|
|
|
|
|
|
reportRuleStatistics();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-01 22:29:15 +00:00
|
|
|
std::set<DRC_CONSTRAINT_T> DRC_TEST_PROVIDER_SILK_CLEARANCE::GetConstraintTypes() const
|
2020-09-23 21:49:18 +00:00
|
|
|
{
|
2020-11-02 16:20:00 +00:00
|
|
|
return { SILK_CLEARANCE_CONSTRAINT };
|
2020-09-23 21:49:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace detail
|
|
|
|
{
|
2020-10-11 10:51:23 +00:00
|
|
|
static DRC_REGISTER_TEST_PROVIDER<DRC_TEST_PROVIDER_SILK_CLEARANCE> dummy;
|
2020-10-01 16:49:17 +00:00
|
|
|
}
|