2020-08-25 17:42:52 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-03-09 00:47:37 +00:00
|
|
|
* Copyright (C) 2004-2022 KiCad Developers.
|
2020-08-25 17:42:52 +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
|
|
|
|
*/
|
|
|
|
|
2022-03-11 22:02:43 +00:00
|
|
|
#include <atomic>
|
2020-08-25 17:42:52 +00:00
|
|
|
#include <common.h>
|
2022-03-11 20:13:47 +00:00
|
|
|
#include <board_design_settings.h>
|
|
|
|
#include <drc/drc_rtree.h>
|
2020-09-11 15:04:11 +00:00
|
|
|
#include <drc/drc_engine.h>
|
|
|
|
#include <drc/drc_item.h>
|
|
|
|
#include <drc/drc_rule.h>
|
|
|
|
#include <drc/drc_test_provider.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <pad.h>
|
2022-06-15 00:41:10 +00:00
|
|
|
#include <progress_reporter.h>
|
2023-09-06 21:19:38 +00:00
|
|
|
#include <core/thread_pool.h>
|
2021-06-03 18:05:43 +00:00
|
|
|
#include <zone.h>
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2022-03-11 20:13:47 +00:00
|
|
|
|
2020-08-25 17:42:52 +00:00
|
|
|
/*
|
|
|
|
"Disallow" test. Goes through all items, matching types/conditions drop errors.
|
|
|
|
Errors generated:
|
|
|
|
- DRCE_ALLOWED_ITEMS
|
2021-05-24 18:53:19 +00:00
|
|
|
- DRCE_TEXT_ON_EDGECUTS
|
2020-08-25 17:42:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
class DRC_TEST_PROVIDER_DISALLOW : public DRC_TEST_PROVIDER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DRC_TEST_PROVIDER_DISALLOW()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~DRC_TEST_PROVIDER_DISALLOW()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool Run() override;
|
|
|
|
|
|
|
|
virtual const wxString GetName() const override
|
|
|
|
{
|
2022-03-11 21:16:52 +00:00
|
|
|
return wxT( "disallow" );
|
2020-08-25 17:42:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual const wxString GetDescription() const override
|
|
|
|
{
|
2022-03-11 21:16:52 +00:00
|
|
|
return wxT( "Tests for disallowed items (e.g. keepouts)" );
|
2020-08-25 17:42:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-09-11 21:50:53 +00:00
|
|
|
bool DRC_TEST_PROVIDER_DISALLOW::Run()
|
2020-08-25 17:42:52 +00:00
|
|
|
{
|
2020-09-18 19:57:54 +00:00
|
|
|
if( !reportPhase( _( "Checking keepouts & disallow constraints..." ) ) )
|
2021-02-27 13:43:41 +00:00
|
|
|
return false; // DRC cancelled
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2022-03-11 20:13:47 +00:00
|
|
|
BOARD* board = m_drcEngine->GetBoard();
|
|
|
|
int epsilon = board->GetDesignSettings().GetDRCEpsilon();
|
|
|
|
|
|
|
|
// First build out the board's cache of copper-keepout to copper-zone caches. This is where
|
|
|
|
// the bulk of the time is spent, and we can do this in parallel.
|
|
|
|
//
|
|
|
|
std::vector<ZONE*> antiCopperKeepouts;
|
|
|
|
std::vector<ZONE*> copperZones;
|
|
|
|
std::vector<std::pair<ZONE*, ZONE*>> toCache;
|
2022-07-31 22:21:11 +00:00
|
|
|
std::atomic<size_t> done( 1 );
|
2022-03-11 20:13:47 +00:00
|
|
|
int totalCount = 0;
|
|
|
|
|
|
|
|
forEachGeometryItem( {}, LSET::AllLayersMask(),
|
|
|
|
[&]( BOARD_ITEM* item ) -> bool
|
|
|
|
{
|
|
|
|
ZONE* zone = dynamic_cast<ZONE*>( item );
|
|
|
|
|
|
|
|
if( zone && zone->GetIsRuleArea() && zone->GetDoNotAllowCopperPour() )
|
|
|
|
antiCopperKeepouts.push_back( zone );
|
|
|
|
else if( zone && zone->IsOnCopperLayer() )
|
|
|
|
copperZones.push_back( zone );
|
|
|
|
|
|
|
|
totalCount++;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} );
|
|
|
|
|
|
|
|
for( ZONE* ruleArea : antiCopperKeepouts )
|
|
|
|
{
|
|
|
|
for( ZONE* copperZone : copperZones )
|
|
|
|
{
|
|
|
|
toCache.push_back( { ruleArea, copperZone } );
|
|
|
|
totalCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-31 22:21:11 +00:00
|
|
|
auto query_areas =
|
|
|
|
[&]( std::pair<ZONE* /* rule area */, ZONE* /* copper zone */> areaZonePair ) -> size_t
|
2022-06-15 00:41:10 +00:00
|
|
|
{
|
|
|
|
if( m_drcEngine->IsCancelled() )
|
|
|
|
return 0;
|
2022-03-11 20:13:47 +00:00
|
|
|
|
2022-08-31 16:17:14 +00:00
|
|
|
ZONE* ruleArea = areaZonePair.first;
|
|
|
|
ZONE* copperZone = areaZonePair.second;
|
2022-10-01 21:09:38 +00:00
|
|
|
BOX2I areaBBox = ruleArea->GetBoundingBox();
|
|
|
|
BOX2I copperBBox = copperZone->GetBoundingBox();
|
2022-08-31 16:17:14 +00:00
|
|
|
bool isInside = false;
|
2022-03-11 20:13:47 +00:00
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
if( copperZone->IsFilled() && areaBBox.Intersects( copperBBox ) )
|
|
|
|
{
|
2022-10-06 14:08:22 +00:00
|
|
|
// Collisions include touching, so we need to deflate outline by enough to
|
|
|
|
// exclude it. This is particularly important for detecting copper fills as
|
|
|
|
// they will be exactly touching along the entire exclusion border.
|
2022-06-15 00:41:10 +00:00
|
|
|
SHAPE_POLY_SET areaPoly = ruleArea->Outline()->CloneDropTriangulation();
|
2022-10-06 14:08:22 +00:00
|
|
|
areaPoly.Fracture( SHAPE_POLY_SET::PM_FAST );
|
2023-10-05 07:34:24 +00:00
|
|
|
areaPoly.Deflate( epsilon, CORNER_STRATEGY::ALLOW_ACUTE_CORNERS, ARC_LOW_DEF );
|
2022-03-11 20:13:47 +00:00
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
DRC_RTREE* zoneRTree = board->m_CopperZoneRTreeCache[ copperZone ].get();
|
|
|
|
|
|
|
|
if( zoneRTree )
|
|
|
|
{
|
|
|
|
for( PCB_LAYER_ID layer : ruleArea->GetLayerSet().Seq() )
|
|
|
|
{
|
|
|
|
if( zoneRTree->QueryColliding( areaBBox, &areaPoly, layer ) )
|
2022-03-11 20:13:47 +00:00
|
|
|
{
|
2022-06-15 00:41:10 +00:00
|
|
|
isInside = true;
|
2022-07-31 22:21:11 +00:00
|
|
|
break;
|
2022-03-11 20:13:47 +00:00
|
|
|
}
|
2022-06-15 00:41:10 +00:00
|
|
|
|
|
|
|
if( m_drcEngine->IsCancelled() )
|
|
|
|
return 0;
|
2022-03-11 20:13:47 +00:00
|
|
|
}
|
2022-06-15 00:41:10 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-11 20:13:47 +00:00
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
if( m_drcEngine->IsCancelled() )
|
|
|
|
return 0;
|
2022-03-11 20:13:47 +00:00
|
|
|
|
2022-08-03 09:10:23 +00:00
|
|
|
PTR_PTR_LAYER_CACHE_KEY key = { ruleArea, copperZone, UNDEFINED_LAYER };
|
2022-06-14 23:10:01 +00:00
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> cacheLock( board->m_CachesMutex );
|
2022-08-28 16:41:39 +00:00
|
|
|
board->m_IntersectsAreaCache[ key ] = isInside;
|
2022-06-15 00:41:10 +00:00
|
|
|
}
|
2022-06-14 23:10:01 +00:00
|
|
|
|
2022-07-31 22:21:11 +00:00
|
|
|
done.fetch_add( 1 );
|
2022-03-11 20:13:47 +00:00
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
return 1;
|
|
|
|
};
|
2022-03-11 20:13:47 +00:00
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
thread_pool& tp = GetKiCadThreadPool();
|
|
|
|
std::vector<std::future<size_t>> returns;
|
2022-03-11 20:13:47 +00:00
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
returns.reserve( toCache.size() );
|
|
|
|
|
2022-07-31 22:21:11 +00:00
|
|
|
for( const std::pair<ZONE*, ZONE*>& areaZonePair : toCache )
|
|
|
|
returns.emplace_back( tp.submit( query_areas, areaZonePair ) );
|
2022-06-15 00:41:10 +00:00
|
|
|
|
2022-09-14 20:28:46 +00:00
|
|
|
for( const std::future<size_t>& ret : returns )
|
2022-03-11 20:13:47 +00:00
|
|
|
{
|
2022-09-14 20:28:46 +00:00
|
|
|
std::future_status status = ret.wait_for( std::chrono::milliseconds( 250 ) );
|
2022-06-15 00:41:10 +00:00
|
|
|
|
2022-09-14 20:28:46 +00:00
|
|
|
while( status != std::future_status::ready )
|
2022-06-15 00:41:10 +00:00
|
|
|
{
|
2022-07-31 22:21:11 +00:00
|
|
|
m_drcEngine->ReportProgress( static_cast<double>( done ) / toCache.size() );
|
2022-09-14 20:28:46 +00:00
|
|
|
status = ret.wait_for( std::chrono::milliseconds( 250 ) );
|
2022-08-03 09:10:23 +00:00
|
|
|
}
|
2022-03-11 20:13:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( m_drcEngine->IsCancelled() )
|
|
|
|
return false;
|
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
// Now go through all the board objects calling the DRC_ENGINE to run the actual disallow
|
2022-03-11 20:13:47 +00:00
|
|
|
// tests. These should be reasonably quick using the caches generated above.
|
|
|
|
//
|
2022-08-03 09:10:23 +00:00
|
|
|
const int progressDelta = 250;
|
|
|
|
int ii = static_cast<int>( toCache.size() );
|
2021-06-02 13:00:11 +00:00
|
|
|
|
2022-03-09 00:47:37 +00:00
|
|
|
auto checkTextOnEdgeCuts =
|
|
|
|
[&]( BOARD_ITEM* item )
|
|
|
|
{
|
2023-06-06 15:09:34 +00:00
|
|
|
if( item->Type() == PCB_FIELD_T || item->Type() == PCB_TEXT_T || item->Type() == PCB_TEXTBOX_T
|
2022-03-09 00:47:37 +00:00
|
|
|
|| BaseType( item->Type() ) == PCB_DIMENSION_T )
|
|
|
|
{
|
|
|
|
if( item->GetLayer() == Edge_Cuts )
|
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> drc = DRC_ITEM::Create( DRCE_TEXT_ON_EDGECUTS );
|
|
|
|
drc->SetItems( item );
|
|
|
|
reportViolation( drc, item->GetPosition(), Edge_Cuts );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
auto checkDisallow =
|
2020-10-21 23:59:40 +00:00
|
|
|
[&]( BOARD_ITEM* item )
|
|
|
|
{
|
2022-03-21 18:18:39 +00:00
|
|
|
DRC_CONSTRAINT constraint = m_drcEngine->EvalRules( DISALLOW_CONSTRAINT, item,
|
|
|
|
nullptr, UNDEFINED_LAYER );
|
2020-12-04 19:29:04 +00:00
|
|
|
|
2021-09-05 15:06:12 +00:00
|
|
|
if( constraint.m_DisallowFlags && constraint.GetSeverity() != RPT_SEVERITY_IGNORE )
|
2020-10-21 23:59:40 +00:00
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_ALLOWED_ITEMS );
|
2022-12-21 18:20:04 +00:00
|
|
|
DRC_RULE* rule = constraint.GetParentRule();
|
|
|
|
VECTOR2I pos = item->GetPosition();
|
|
|
|
PCB_LAYER_ID layer = UNDEFINED_LAYER;
|
|
|
|
wxString msg;
|
2020-10-21 23:59:40 +00:00
|
|
|
|
2022-06-15 23:42:34 +00:00
|
|
|
msg.Printf( drcItem->GetErrorText() + wxS( " (%s)" ), constraint.GetName() );
|
2020-10-21 23:59:40 +00:00
|
|
|
|
2022-06-15 23:42:34 +00:00
|
|
|
drcItem->SetErrorMessage( msg );
|
2020-10-21 23:59:40 +00:00
|
|
|
drcItem->SetItems( item );
|
2022-12-21 18:20:04 +00:00
|
|
|
drcItem->SetViolatingRule( rule );
|
2022-03-21 18:18:39 +00:00
|
|
|
|
|
|
|
if( item->GetLayerSet().count() )
|
|
|
|
layer = item->GetLayerSet().Seq().front();
|
|
|
|
|
2022-12-21 18:20:04 +00:00
|
|
|
if( rule->m_Implicit )
|
|
|
|
{
|
|
|
|
// Provide a better location for keepout area collisions.
|
|
|
|
BOARD_ITEM* ruleItem = board->GetItem( rule->m_ImplicitItemId );
|
|
|
|
|
|
|
|
if( ZONE* keepout = dynamic_cast<ZONE*>( ruleItem ) )
|
|
|
|
{
|
|
|
|
std::shared_ptr<SHAPE> shape = item->GetEffectiveShape( layer );
|
|
|
|
int dummyActual;
|
|
|
|
|
|
|
|
keepout->Outline()->Collide( shape.get(), board->m_DRCMaxClearance,
|
|
|
|
&dummyActual, &pos );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
reportViolation( drcItem, pos, layer );
|
2020-10-21 23:59:40 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-09 00:47:37 +00:00
|
|
|
forEachGeometryItem( {}, LSET::AllLayersMask(),
|
|
|
|
[&]( BOARD_ITEM* item ) -> bool
|
|
|
|
{
|
|
|
|
if( !m_drcEngine->IsErrorLimitExceeded( DRCE_TEXT_ON_EDGECUTS ) )
|
|
|
|
checkTextOnEdgeCuts( item );
|
|
|
|
|
|
|
|
if( !m_drcEngine->IsErrorLimitExceeded( DRCE_ALLOWED_ITEMS ) )
|
2021-03-07 17:54:49 +00:00
|
|
|
{
|
2022-03-09 00:47:37 +00:00
|
|
|
ZONE* zone = dynamic_cast<ZONE*>( item );
|
2021-03-07 17:54:49 +00:00
|
|
|
|
2022-03-09 00:47:37 +00:00
|
|
|
if( zone && zone->GetIsRuleArea() )
|
2021-03-07 17:54:49 +00:00
|
|
|
return true;
|
2021-06-02 13:00:11 +00:00
|
|
|
|
2022-03-09 00:47:37 +00:00
|
|
|
item->ClearFlags( HOLE_PROXY ); // Just in case
|
2020-10-21 23:59:40 +00:00
|
|
|
|
2022-03-09 00:47:37 +00:00
|
|
|
checkDisallow( item );
|
2021-02-17 10:19:59 +00:00
|
|
|
|
2022-07-15 15:14:11 +00:00
|
|
|
if( item->HasHole() )
|
2022-03-09 00:47:37 +00:00
|
|
|
{
|
|
|
|
item->SetFlags( HOLE_PROXY );
|
2022-07-15 15:14:11 +00:00
|
|
|
checkDisallow( item );
|
2022-03-09 00:47:37 +00:00
|
|
|
item->ClearFlags( HOLE_PROXY );
|
|
|
|
}
|
2020-10-21 23:59:40 +00:00
|
|
|
}
|
|
|
|
|
2022-08-03 09:10:23 +00:00
|
|
|
if( !reportProgress( ii++, totalCount, progressDelta ) )
|
2022-03-11 20:13:47 +00:00
|
|
|
return false;
|
|
|
|
|
2020-10-21 23:59:40 +00:00
|
|
|
return true;
|
2022-03-09 00:47:37 +00:00
|
|
|
} );
|
2020-08-25 17:42:52 +00:00
|
|
|
|
|
|
|
reportRuleStatistics();
|
|
|
|
|
2022-03-11 20:13:47 +00:00
|
|
|
return !m_drcEngine->IsCancelled();
|
2020-08-25 17:42:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace detail
|
|
|
|
{
|
2020-09-11 21:50:53 +00:00
|
|
|
static DRC_REGISTER_TEST_PROVIDER<DRC_TEST_PROVIDER_DISALLOW> dummy;
|
2020-09-07 12:31:19 +00:00
|
|
|
}
|