2020-08-25 17:42:52 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-03-17 23:21:37 +00:00
|
|
|
* Copyright (C) 2004-2020 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.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>
|
2021-06-03 18:05:43 +00:00
|
|
|
#include <zone.h>
|
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-17 23:21:37 +00:00
|
|
|
return "disallow";
|
2020-08-25 17:42:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual const wxString GetDescription() const override
|
|
|
|
{
|
2022-03-17 23:21:37 +00:00
|
|
|
return "Tests for disallowed items (e.g. keepouts)";
|
2020-08-25 17:42:52 +00:00
|
|
|
}
|
|
|
|
|
2021-01-01 22:29:15 +00:00
|
|
|
virtual std::set<DRC_CONSTRAINT_T> GetConstraintTypes() const override;
|
2020-09-14 17:54:14 +00:00
|
|
|
|
|
|
|
int GetNumPhases() const override;
|
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
|
|
|
|
2021-06-02 13:00:11 +00:00
|
|
|
// Zones can be expensive (particularly when multi-layer), so we run the progress bar on them
|
|
|
|
BOARD* board = m_drcEngine->GetBoard();
|
|
|
|
int boardZoneCount = board->Zones().size();
|
|
|
|
int delta = std::max( 1, boardZoneCount / board->GetCopperLayerCount() );
|
|
|
|
int ii = 0;
|
|
|
|
|
2020-10-21 23:59:40 +00:00
|
|
|
auto doCheckItem =
|
|
|
|
[&]( BOARD_ITEM* item )
|
|
|
|
{
|
2021-02-08 14:53:49 +00:00
|
|
|
auto constraint = m_drcEngine->EvalRules( DISALLOW_CONSTRAINT, item, nullptr,
|
2021-02-16 15:50:43 +00:00
|
|
|
UNDEFINED_LAYER );
|
2020-12-04 19:29:04 +00:00
|
|
|
|
2020-10-21 23:59:40 +00:00
|
|
|
if( constraint.m_DisallowFlags )
|
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_ALLOWED_ITEMS );
|
|
|
|
|
|
|
|
m_msg.Printf( drcItem->GetErrorText() + wxS( " (%s)" ),
|
|
|
|
constraint.GetName() );
|
|
|
|
|
|
|
|
drcItem->SetErrorMessage( m_msg );
|
|
|
|
drcItem->SetItems( item );
|
|
|
|
drcItem->SetViolatingRule( constraint.GetParentRule() );
|
|
|
|
|
2020-11-24 22:16:41 +00:00
|
|
|
reportViolation( drcItem, item->GetPosition() );
|
2020-10-21 23:59:40 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
auto checkItem =
|
|
|
|
[&]( BOARD_ITEM* item ) -> bool
|
|
|
|
{
|
2021-05-24 18:53:19 +00:00
|
|
|
if( !m_drcEngine->IsErrorLimitExceeded( DRCE_TEXT_ON_EDGECUTS )
|
|
|
|
&& item->GetLayer() == Edge_Cuts )
|
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case PCB_TEXT_T:
|
|
|
|
case PCB_DIM_ALIGNED_T:
|
|
|
|
case PCB_DIM_CENTER_T:
|
|
|
|
case PCB_DIM_ORTHOGONAL_T:
|
|
|
|
case PCB_DIM_LEADER_T:
|
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> drc = DRC_ITEM::Create( DRCE_TEXT_ON_EDGECUTS );
|
|
|
|
drc->SetItems( item );
|
|
|
|
reportViolation( drc, item->GetPosition() );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-21 23:59:40 +00:00
|
|
|
if( m_drcEngine->IsErrorLimitExceeded( DRCE_ALLOWED_ITEMS ) )
|
|
|
|
return false;
|
|
|
|
|
2021-03-07 17:54:49 +00:00
|
|
|
if( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T )
|
|
|
|
{
|
|
|
|
ZONE* zone = static_cast<ZONE*>( item );
|
|
|
|
|
|
|
|
if( zone->GetIsRuleArea() )
|
|
|
|
return true;
|
2021-06-02 13:00:11 +00:00
|
|
|
|
|
|
|
if( item->Type() == PCB_ZONE_T )
|
|
|
|
{
|
|
|
|
if( !reportProgress( ii++, boardZoneCount, delta ) )
|
|
|
|
return false; // DRC cancelled
|
|
|
|
}
|
2021-03-07 17:54:49 +00:00
|
|
|
}
|
|
|
|
|
2020-10-21 23:59:40 +00:00
|
|
|
item->ClearFlags( HOLE_PROXY );
|
|
|
|
doCheckItem( item );
|
|
|
|
|
2021-02-17 10:19:59 +00:00
|
|
|
bool hasHole;
|
|
|
|
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case PCB_VIA_T: hasHole = true; break;
|
|
|
|
case PCB_PAD_T: hasHole = static_cast<PAD*>( item )->GetDrillSizeX() > 0; break;
|
|
|
|
default: hasHole = false; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( hasHole )
|
2020-10-21 23:59:40 +00:00
|
|
|
{
|
|
|
|
item->SetFlags( HOLE_PROXY );
|
|
|
|
doCheckItem( item );
|
2020-12-05 19:43:11 +00:00
|
|
|
item->ClearFlags( HOLE_PROXY );
|
2020-10-21 23:59:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
2020-08-25 17:42:52 +00:00
|
|
|
|
|
|
|
forEachGeometryItem( {}, LSET::AllLayersMask(), checkItem );
|
|
|
|
|
|
|
|
reportRuleStatistics();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
int DRC_TEST_PROVIDER_DISALLOW::GetNumPhases() const
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-01 22:29:15 +00:00
|
|
|
std::set<DRC_CONSTRAINT_T> DRC_TEST_PROVIDER_DISALLOW::GetConstraintTypes() const
|
2020-08-25 17:42:52 +00:00
|
|
|
{
|
2020-11-02 16:20:00 +00:00
|
|
|
return { DISALLOW_CONSTRAINT };
|
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
|
|
|
}
|