2019-01-11 22:03:45 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Dick Hollenbeck, dick@softplc.com
|
|
|
|
* Copyright (C) 2004-2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2020-05-01 17:44:25 +00:00
|
|
|
* Copyright (C) 2018-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-01-11 22:03:45 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2020-05-01 17:44:25 +00:00
|
|
|
#include <drc/drc_courtyard_tester.h>
|
2019-01-11 22:03:45 +00:00
|
|
|
|
|
|
|
#include <class_module.h>
|
2020-02-19 09:31:32 +00:00
|
|
|
#include <drc/drc.h>
|
2019-01-11 22:03:45 +00:00
|
|
|
|
2020-02-28 00:05:40 +00:00
|
|
|
#include <widgets/ui_common.h>
|
2019-01-11 22:03:45 +00:00
|
|
|
|
2020-02-28 00:05:40 +00:00
|
|
|
#include <memory>
|
2020-06-13 23:20:45 +00:00
|
|
|
#include <drc/drc_item.h>
|
2019-01-11 22:03:45 +00:00
|
|
|
|
2020-05-01 17:44:25 +00:00
|
|
|
DRC_COURTYARD_TESTER::DRC_COURTYARD_TESTER( MARKER_HANDLER aMarkerHandler ) :
|
2020-05-17 14:40:06 +00:00
|
|
|
DRC_TEST_PROVIDER( std::move( aMarkerHandler ) )
|
2019-01-11 22:03:45 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-17 14:40:06 +00:00
|
|
|
bool DRC_COURTYARD_TESTER::RunDRC( EDA_UNITS aUnits, BOARD& aBoard )
|
2019-01-11 22:03:45 +00:00
|
|
|
{
|
2020-05-14 21:01:39 +00:00
|
|
|
// Detects missing (or malformed) footprint courtyards and courtyard incursions (for those
|
|
|
|
// with a courtyard).
|
2019-01-11 22:03:45 +00:00
|
|
|
wxString msg;
|
|
|
|
bool success = true;
|
|
|
|
|
|
|
|
// Update courtyard polygons, and test for missing courtyard definition:
|
2020-02-28 00:05:40 +00:00
|
|
|
for( MODULE* footprint : aBoard.Modules() )
|
2019-01-11 22:03:45 +00:00
|
|
|
{
|
2020-05-01 17:44:25 +00:00
|
|
|
if( footprint->BuildPolyCourtyard() )
|
2019-01-11 22:03:45 +00:00
|
|
|
{
|
2020-05-14 21:01:39 +00:00
|
|
|
if( !aBoard.GetDesignSettings().Ignore( DRCE_MISSING_COURTYARD )
|
|
|
|
&& footprint->GetPolyCourtyardFront().OutlineCount() == 0
|
|
|
|
&& footprint->GetPolyCourtyardBack().OutlineCount() == 0 )
|
2020-05-01 17:44:25 +00:00
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_MISSING_COURTYARD );
|
2020-05-14 21:01:39 +00:00
|
|
|
drcItem->SetItems( footprint );
|
|
|
|
HandleMarker( new MARKER_PCB( drcItem, footprint->GetPosition() ) );
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
footprint->GetPolyCourtyardFront().BuildBBoxCaches();
|
|
|
|
footprint->GetPolyCourtyardBack().BuildBBoxCaches();
|
2020-05-01 17:44:25 +00:00
|
|
|
}
|
2019-01-11 22:03:45 +00:00
|
|
|
}
|
2020-05-01 17:44:25 +00:00
|
|
|
else
|
2019-01-11 22:03:45 +00:00
|
|
|
{
|
2020-05-07 13:35:50 +00:00
|
|
|
if( !aBoard.GetDesignSettings().Ignore( DRCE_MALFORMED_COURTYARD ) )
|
2020-05-01 17:44:25 +00:00
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_MALFORMED_COURTYARD );
|
2020-05-07 13:35:50 +00:00
|
|
|
|
|
|
|
msg.Printf( drcItem->GetErrorText() + _( " (not a closed shape)" ) );
|
|
|
|
|
|
|
|
drcItem->SetErrorMessage( msg );
|
2020-05-01 17:44:25 +00:00
|
|
|
drcItem->SetItems( footprint );
|
|
|
|
HandleMarker( new MARKER_PCB( drcItem, footprint->GetPosition() ) );
|
|
|
|
success = false;
|
|
|
|
}
|
2019-01-11 22:03:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-14 21:01:39 +00:00
|
|
|
if( !aBoard.GetDesignSettings().Ignore( DRCE_OVERLAPPING_FOOTPRINTS ) )
|
2019-01-11 22:03:45 +00:00
|
|
|
{
|
2020-05-14 21:01:39 +00:00
|
|
|
for( auto it1 = aBoard.Modules().begin(); it1 != aBoard.Modules().end(); it1++ )
|
2019-01-11 22:03:45 +00:00
|
|
|
{
|
2020-05-14 21:01:39 +00:00
|
|
|
MODULE* footprint = *it1;
|
|
|
|
SHAPE_POLY_SET& footprintFront = footprint->GetPolyCourtyardFront();
|
|
|
|
SHAPE_POLY_SET& footprintBack = footprint->GetPolyCourtyardBack();
|
|
|
|
|
|
|
|
if( footprintFront.OutlineCount() == 0 && footprintBack.OutlineCount() == 0 )
|
|
|
|
continue; // No courtyards defined
|
|
|
|
|
|
|
|
for( auto it2 = it1 + 1; it2 != aBoard.Modules().end(); it2++ )
|
|
|
|
{
|
|
|
|
MODULE* test = *it2;
|
|
|
|
SHAPE_POLY_SET& testFront = test->GetPolyCourtyardFront();
|
|
|
|
SHAPE_POLY_SET& testBack = test->GetPolyCourtyardBack();
|
|
|
|
SHAPE_POLY_SET intersection;
|
|
|
|
bool overlap = false;
|
|
|
|
wxPoint pos;
|
|
|
|
|
|
|
|
if( footprintFront.OutlineCount() > 0 && testFront.OutlineCount() > 0
|
|
|
|
&& footprintFront.BBoxFromCaches().Intersects( testFront.BBoxFromCaches() ) )
|
|
|
|
{
|
|
|
|
intersection.RemoveAllContours();
|
|
|
|
intersection.Append( footprintFront );
|
|
|
|
|
|
|
|
// Build the common area between footprint and the test:
|
|
|
|
intersection.BooleanIntersection( testFront, SHAPE_POLY_SET::PM_FAST );
|
|
|
|
|
|
|
|
// If the intersection exists then they overlap
|
|
|
|
if( intersection.OutlineCount() > 0 )
|
|
|
|
{
|
|
|
|
overlap = true;
|
|
|
|
pos = (wxPoint) intersection.CVertex( 0, 0, -1 );
|
|
|
|
}
|
|
|
|
}
|
2019-05-31 00:15:57 +00:00
|
|
|
|
2020-05-14 21:01:39 +00:00
|
|
|
if( footprintBack.OutlineCount() > 0 && testBack.OutlineCount() > 0
|
|
|
|
&& footprintBack.BBoxFromCaches().Intersects( testBack.BBoxFromCaches() ) )
|
|
|
|
{
|
|
|
|
intersection.RemoveAllContours();
|
|
|
|
intersection.Append( footprintBack );
|
2019-01-11 22:03:45 +00:00
|
|
|
|
2020-05-14 21:01:39 +00:00
|
|
|
intersection.BooleanIntersection( testBack, SHAPE_POLY_SET::PM_FAST );
|
2019-01-11 22:03:45 +00:00
|
|
|
|
2020-05-14 21:01:39 +00:00
|
|
|
if( intersection.OutlineCount() > 0 )
|
|
|
|
{
|
|
|
|
overlap = true;
|
|
|
|
pos = (wxPoint) intersection.CVertex( 0, 0, -1 );
|
|
|
|
}
|
|
|
|
}
|
2019-01-11 22:03:45 +00:00
|
|
|
|
2020-05-14 21:01:39 +00:00
|
|
|
if( overlap )
|
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_OVERLAPPING_FOOTPRINTS );
|
2020-05-14 21:01:39 +00:00
|
|
|
drcItem->SetItems( footprint, test );
|
|
|
|
HandleMarker( new MARKER_PCB( drcItem, pos ) );
|
|
|
|
success = false;
|
|
|
|
}
|
2019-01-11 22:03:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-14 21:01:39 +00:00
|
|
|
if( !aBoard.GetDesignSettings().Ignore( DRCE_PTH_IN_COURTYARD )
|
|
|
|
|| !aBoard.GetDesignSettings().Ignore( DRCE_NPTH_IN_COURTYARD ) )
|
2019-01-11 22:03:45 +00:00
|
|
|
{
|
2020-05-14 21:01:39 +00:00
|
|
|
for( MODULE* footprint : aBoard.Modules() )
|
2019-01-11 22:03:45 +00:00
|
|
|
{
|
2020-05-14 21:01:39 +00:00
|
|
|
SHAPE_POLY_SET& footprintFront = footprint->GetPolyCourtyardFront();
|
|
|
|
SHAPE_POLY_SET& footprintBack = footprint->GetPolyCourtyardBack();
|
2019-01-11 22:03:45 +00:00
|
|
|
|
2020-05-14 21:01:39 +00:00
|
|
|
if( footprintFront.OutlineCount() == 0 && footprintBack.OutlineCount() == 0 )
|
|
|
|
continue; // No courtyards defined
|
2019-01-11 22:03:45 +00:00
|
|
|
|
2020-05-14 21:01:39 +00:00
|
|
|
for( MODULE* candidate : aBoard.Modules() )
|
2019-01-11 22:03:45 +00:00
|
|
|
{
|
2020-05-14 21:01:39 +00:00
|
|
|
if( footprint == candidate )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for( D_PAD* pad : candidate->Pads() )
|
|
|
|
{
|
|
|
|
if( pad->GetDrillSize().x == 0 || pad->GetDrillSize().y == 0 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
wxPoint pos = pad->GetPosition();
|
|
|
|
|
|
|
|
if( footprintFront.Contains( pos, -1, 0, true /* use bbox caches */ )
|
|
|
|
|| footprintBack.Contains( pos, -1, 0, true /* use bbox caches */ ) )
|
|
|
|
{
|
|
|
|
int code = pad->GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED ?
|
|
|
|
DRCE_NPTH_IN_COURTYARD :
|
|
|
|
DRCE_PTH_IN_COURTYARD;
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( code );
|
2020-05-14 21:01:39 +00:00
|
|
|
drcItem->SetItems( footprint, pad );
|
|
|
|
HandleMarker( new MARKER_PCB( drcItem, pos ) );
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
}
|
2019-01-11 22:03:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|