2020-09-18 14:24:09 +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-09-18 14:24:09 +00:00
|
|
|
|
|
|
|
#include <geometry/seg.h>
|
|
|
|
#include <geometry/shape_segment.h>
|
|
|
|
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <drc/drc_engine.h>
|
2020-09-18 14:24:09 +00:00
|
|
|
#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 pads clearance test. Check all pads against silkscreen (mask opening in the pad vs silkscreen)
|
|
|
|
Errors generated:
|
2020-10-04 11:44:22 +00:00
|
|
|
- DRCE_SILK_MASK_CLEARANCE
|
2020-09-18 14:24:09 +00:00
|
|
|
*/
|
|
|
|
|
2020-10-04 11:44:22 +00:00
|
|
|
class DRC_TEST_PROVIDER_SILK_TO_MASK : public ::DRC_TEST_PROVIDER
|
2020-09-18 14:24:09 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-10-04 11:44:22 +00:00
|
|
|
DRC_TEST_PROVIDER_SILK_TO_MASK ():
|
2020-10-03 10:47:41 +00:00
|
|
|
m_board( nullptr ),
|
|
|
|
m_largestClearance( 0 )
|
2020-09-18 14:24:09 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-10-04 11:44:22 +00:00
|
|
|
virtual ~DRC_TEST_PROVIDER_SILK_TO_MASK()
|
2020-09-18 14:24:09 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool Run() override;
|
|
|
|
|
2020-10-03 10:47:41 +00:00
|
|
|
virtual const wxString GetName() const override
|
2020-09-18 14:24:09 +00:00
|
|
|
{
|
2020-10-04 11:44:22 +00:00
|
|
|
return "silk_to_mask";
|
2020-09-18 14:24:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual const wxString GetDescription() const override
|
|
|
|
{
|
2020-10-04 11:44:22 +00:00
|
|
|
return "Tests for silkscreen being clipped by solder mask";
|
2020-09-18 14:24:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-18 14:24:09 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
BOARD* m_board;
|
|
|
|
int m_largestClearance;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-10-05 13:31:10 +00:00
|
|
|
bool DRC_TEST_PROVIDER_SILK_TO_MASK::Run()
|
2020-09-18 14:24:09 +00:00
|
|
|
{
|
|
|
|
m_board = m_drcEngine->GetBoard();
|
|
|
|
|
2020-10-14 10:18:09 +00:00
|
|
|
if( m_drcEngine->IsErrorLimitExceeded( DRCE_SILK_MASK_CLEARANCE ) )
|
|
|
|
{
|
2021-02-27 13:43:41 +00:00
|
|
|
reportAux( "Silkscreen clipping violations ignored. Tests not run." );
|
|
|
|
return true; // continue with other tests
|
2020-10-14 10:18:09 +00:00
|
|
|
}
|
|
|
|
|
2020-09-18 14:24:09 +00:00
|
|
|
DRC_CONSTRAINT worstClearanceConstraint;
|
|
|
|
m_largestClearance = 0;
|
|
|
|
|
2020-11-02 16:20:00 +00:00
|
|
|
if( m_drcEngine->QueryWorstConstraint( SILK_CLEARANCE_CONSTRAINT, worstClearanceConstraint ) )
|
2020-09-18 14:24:09 +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 potential soldermask clipping..." ) ) )
|
2021-02-27 13:43:41 +00:00
|
|
|
return false; // DRC cancelled
|
2020-09-18 14:24:09 +00:00
|
|
|
|
2020-10-04 11:44:22 +00:00
|
|
|
DRC_RTREE maskTree, silkTree;
|
2020-09-18 14:24:09 +00:00
|
|
|
|
2020-10-04 11:44:22 +00:00
|
|
|
auto addMaskToTree =
|
|
|
|
[&maskTree]( BOARD_ITEM *item ) -> bool
|
2020-09-18 14:24:09 +00:00
|
|
|
{
|
2021-06-02 13:00:11 +00:00
|
|
|
for( PCB_LAYER_ID layer : { F_Mask, B_Mask } )
|
|
|
|
{
|
|
|
|
if( item->IsOnLayer( layer ) )
|
|
|
|
maskTree.Insert( item, layer );
|
|
|
|
}
|
|
|
|
|
2020-09-18 14:24:09 +00:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2020-09-23 21:49:18 +00:00
|
|
|
auto addSilkToTree =
|
|
|
|
[&silkTree]( BOARD_ITEM *item ) -> bool
|
2020-09-18 14:24:09 +00:00
|
|
|
{
|
2021-06-02 13:00:11 +00:00
|
|
|
for( PCB_LAYER_ID layer : { F_SilkS, B_SilkS } )
|
|
|
|
{
|
|
|
|
if( item->IsOnLayer( layer ) )
|
|
|
|
silkTree.Insert( item, layer );
|
|
|
|
}
|
|
|
|
|
2020-09-18 14:24:09 +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-04 11:44:22 +00:00
|
|
|
if( m_drcEngine->IsErrorLimitExceeded( DRCE_SILK_MASK_CLEARANCE ) )
|
2020-09-29 20:22:45 +00:00
|
|
|
return false;
|
|
|
|
|
2020-10-02 18:58:12 +00:00
|
|
|
if( isInvisibleText( aRefItem->parent ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if( isInvisibleText( aTestItem->parent ) )
|
|
|
|
return true;
|
|
|
|
|
2021-02-08 14:53:49 +00:00
|
|
|
auto constraint = m_drcEngine->EvalRules( SILK_CLEARANCE_CONSTRAINT,
|
|
|
|
aRefItem->parent, aTestItem->parent,
|
|
|
|
aLayers.first );
|
2021-01-23 00:09:18 +00:00
|
|
|
|
|
|
|
int minClearance = constraint.GetValue().Min();
|
2020-09-18 14:24:09 +00:00
|
|
|
|
2021-01-23 00:09:18 +00:00
|
|
|
if( minClearance < 0 )
|
2020-09-28 22:27:33 +00:00
|
|
|
return true;
|
2020-09-18 14:24:09 +00:00
|
|
|
|
2021-01-23 00:09:18 +00:00
|
|
|
int actual;
|
|
|
|
VECTOR2I pos;
|
2020-10-06 12:20:29 +00:00
|
|
|
|
2021-01-23 00:09:18 +00:00
|
|
|
if( aRefItem->shape->Collide( aTestItem->shape, minClearance, &actual, &pos ) )
|
2020-10-06 12:20:29 +00:00
|
|
|
{
|
2021-01-23 00:09:18 +00:00
|
|
|
std::shared_ptr<DRC_ITEM> drce = DRC_ITEM::Create( DRCE_SILK_MASK_CLEARANCE );
|
2020-10-06 12:20:29 +00:00
|
|
|
|
2021-01-23 00:09:18 +00:00
|
|
|
if( minClearance > 0 )
|
|
|
|
{
|
|
|
|
m_msg.Printf( _( "(%s clearance %s; actual %s)" ),
|
|
|
|
constraint.GetName(),
|
|
|
|
MessageTextFromValue( userUnits(), minClearance ),
|
|
|
|
MessageTextFromValue( userUnits(), actual ) );
|
|
|
|
|
|
|
|
drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + m_msg );
|
|
|
|
}
|
2020-09-18 14:24:09 +00:00
|
|
|
|
2021-01-23 00:09:18 +00:00
|
|
|
drce->SetItems( aRefItem->parent, aTestItem->parent );
|
|
|
|
drce->SetViolatingRule( constraint.GetParentRule() );
|
2020-09-18 14:24:09 +00:00
|
|
|
|
2021-01-23 00:09:18 +00:00
|
|
|
reportViolation( drce, (wxPoint) pos );
|
|
|
|
|
|
|
|
*aCollisionDetected = true;
|
|
|
|
}
|
2020-09-18 14:24:09 +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 23:18:52 +00:00
|
|
|
int numMask = forEachGeometryItem( s_allBasicItems, LSET( 2, F_Mask, B_Mask ), addMaskToTree );
|
|
|
|
int numSilk = forEachGeometryItem( s_allBasicItems, LSET( 2, F_SilkS, B_SilkS ), addSilkToTree );
|
2020-10-04 11:44:22 +00:00
|
|
|
|
2020-10-12 22:59:01 +00:00
|
|
|
reportAux( _("Testing %d mask apertures against %d silkscreen features."), numMask, numSilk );
|
2020-09-23 21:49:18 +00:00
|
|
|
|
|
|
|
const std::vector<DRC_RTREE::LAYER_PAIR> layerPairs =
|
|
|
|
{
|
2020-10-04 11:44:22 +00:00
|
|
|
DRC_RTREE::LAYER_PAIR( F_SilkS, F_Mask ),
|
|
|
|
DRC_RTREE::LAYER_PAIR( B_SilkS, B_Mask )
|
2020-09-23 21:49:18 +00:00
|
|
|
};
|
|
|
|
|
2020-10-12 22:59:01 +00:00
|
|
|
// This is the number of tests between 2 calls to the progress bar
|
|
|
|
const int delta = 250;
|
|
|
|
|
|
|
|
maskTree.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
|
|
|
{
|
|
|
|
return reportProgress( aCount, aSize, delta );
|
|
|
|
} );
|
2020-09-23 21:49:18 +00:00
|
|
|
|
|
|
|
reportRuleStatistics();
|
2020-09-18 14:24:09 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-01 22:29:15 +00:00
|
|
|
std::set<DRC_CONSTRAINT_T> DRC_TEST_PROVIDER_SILK_TO_MASK::GetConstraintTypes() const
|
2020-09-18 14:24:09 +00:00
|
|
|
{
|
2020-11-02 16:20:00 +00:00
|
|
|
return { SILK_CLEARANCE_CONSTRAINT };
|
2020-09-18 14:24:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace detail
|
|
|
|
{
|
2020-10-05 13:31:10 +00:00
|
|
|
static DRC_REGISTER_TEST_PROVIDER<DRC_TEST_PROVIDER_SILK_TO_MASK> dummy;
|
2020-10-21 23:38:14 +00:00
|
|
|
}
|