147 lines
4.5 KiB
C++
147 lines
4.5 KiB
C++
/*
|
|
* 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>
|
|
#include <class_track.h>
|
|
#include <drc/drc_engine.h>
|
|
#include <drc/drc.h>
|
|
#include <drc/drc_item.h>
|
|
#include <drc/drc_rule.h>
|
|
#include <drc/drc_test_provider.h>
|
|
|
|
|
|
/*
|
|
Via diameter test.
|
|
|
|
Errors generated:
|
|
- DRCE_TOO_SMALL_VIA
|
|
- DRCE_TOO_SMALL_MICROVIA
|
|
*/
|
|
|
|
class DRC_TEST_PROVIDER_VIA_DIAMETER : public DRC_TEST_PROVIDER
|
|
{
|
|
public:
|
|
DRC_TEST_PROVIDER_VIA_DIAMETER()
|
|
{
|
|
}
|
|
|
|
virtual ~DRC_TEST_PROVIDER_VIA_DIAMETER()
|
|
{
|
|
}
|
|
|
|
virtual bool Run() override;
|
|
|
|
virtual const wxString GetName() const override
|
|
{
|
|
return "diameter";
|
|
};
|
|
|
|
virtual const wxString GetDescription() const override
|
|
{
|
|
return "Tests via diameters";
|
|
}
|
|
|
|
virtual std::set<DRC_CONSTRAINT_TYPE_T> GetMatchingConstraintIds() const override;
|
|
};
|
|
|
|
|
|
bool DRC_TEST_PROVIDER_VIA_DIAMETER::Run()
|
|
{
|
|
if( !m_drcEngine->HasCorrectRulesForId( DRC_CONSTRAINT_TYPE_VIA_DIAMETER ) )
|
|
{
|
|
ReportAux( "No diameter constraints found. Skipping check." );
|
|
return false;
|
|
}
|
|
|
|
ReportStage( ( "Testing via diameters" ), 0, 2 );
|
|
|
|
auto checkViaDiameter =
|
|
[&]( BOARD_ITEM* item ) -> bool
|
|
{
|
|
auto via = dyn_cast<VIA*>( item );
|
|
|
|
// fixme: move to pad stack check?
|
|
if( !via )
|
|
return true;
|
|
|
|
auto constraint = m_drcEngine->EvalRulesForItems( DRC_CONSTRAINT_TYPE_VIA_DIAMETER,
|
|
item );
|
|
bool fail_min = false;
|
|
bool fail_max = false;
|
|
int constraintDiameter;
|
|
int actual = via->GetWidth();
|
|
|
|
if( constraint.Value().HasMin() && actual < constraint.Value().Min() )
|
|
{
|
|
fail_min = true;
|
|
constraintDiameter = constraint.Value().Min();
|
|
}
|
|
|
|
if( constraint.Value().HasMax() && actual > constraint.Value().Max() )
|
|
{
|
|
fail_max = true;
|
|
constraintDiameter = constraint.Value().Max();
|
|
}
|
|
|
|
if( fail_min || fail_max )
|
|
{
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_VIA_DIAMETER );
|
|
|
|
m_msg.Printf( drcItem->GetErrorText() + _( " (%s %s diameter %s; actual %s)" ),
|
|
constraint.GetName(),
|
|
fail_min ? _( "minimum" ) : _( "maximum" ),
|
|
MessageTextFromValue( userUnits(), constraintDiameter, true ) );
|
|
MessageTextFromValue( userUnits(), actual, true ),
|
|
|
|
drcItem->SetErrorMessage( m_msg );
|
|
drcItem->SetItems( item );
|
|
drcItem->SetViolatingRule( constraint.GetParentRule() );
|
|
|
|
ReportWithMarker( drcItem, via->GetPosition() );
|
|
|
|
if( isErrorLimitExceeded( DRCE_VIA_DIAMETER ) )
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
};
|
|
|
|
forEachGeometryItem( { PCB_VIA_T }, LSET::AllCuMask(), checkViaDiameter );
|
|
|
|
reportRuleStatistics();
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
std::set<DRC_CONSTRAINT_TYPE_T> DRC_TEST_PROVIDER_VIA_DIAMETER::GetMatchingConstraintIds() const
|
|
{
|
|
return { DRC_CONSTRAINT_TYPE_T::DRC_CONSTRAINT_TYPE_VIA_DIAMETER };
|
|
}
|
|
|
|
|
|
namespace detail
|
|
{
|
|
static DRC_REGISTER_TEST_PROVIDER<DRC_TEST_PROVIDER_VIA_DIAMETER> dummy;
|
|
} |