2020-08-25 17:42:52 +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 <class_track.h>
|
2020-09-11 15:04:11 +00:00
|
|
|
#include <drc/drc_item.h>
|
|
|
|
#include <drc/drc_rule.h>
|
|
|
|
#include <drc/drc_test_provider.h>
|
2020-08-25 17:42:52 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Via diameter test.
|
|
|
|
|
|
|
|
Errors generated:
|
2020-09-18 15:50:41 +00:00
|
|
|
- DRCE_VIA_DIAMETER
|
2020-08-25 17:42:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
2020-09-13 10:37:20 +00:00
|
|
|
virtual std::set<DRC_CONSTRAINT_TYPE_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_VIA_DIAMETER::Run()
|
2020-08-25 17:42:52 +00:00
|
|
|
{
|
2020-09-17 13:36:34 +00:00
|
|
|
const int delta = 100; // This is the number of tests between 2 calls to the progress bar
|
|
|
|
|
2020-09-13 10:37:20 +00:00
|
|
|
if( !m_drcEngine->HasRulesForConstraintType( DRC_CONSTRAINT_TYPE_VIA_DIAMETER ) )
|
2020-08-25 17:42:52 +00:00
|
|
|
{
|
2020-09-14 17:54:14 +00:00
|
|
|
reportAux( "No diameter constraints found. Skipping check." );
|
2020-08-25 17:42:52 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-09-18 19:57:54 +00:00
|
|
|
if( !reportPhase( _( "Checking via diameters..." ) ) )
|
|
|
|
return false;
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-09-11 21:50:53 +00:00
|
|
|
auto checkViaDiameter =
|
|
|
|
[&]( BOARD_ITEM* item ) -> bool
|
|
|
|
{
|
2020-09-12 19:28:22 +00:00
|
|
|
if( m_drcEngine->IsErrorLimitExceeded( DRCE_VIA_DIAMETER ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
VIA* via = dyn_cast<VIA*>( item );
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-09-11 21:50:53 +00:00
|
|
|
// fixme: move to pad stack check?
|
|
|
|
if( !via )
|
|
|
|
return true;
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-09-11 21:50:53 +00:00
|
|
|
auto constraint = m_drcEngine->EvalRulesForItems( DRC_CONSTRAINT_TYPE_VIA_DIAMETER,
|
|
|
|
item );
|
|
|
|
bool fail_min = false;
|
|
|
|
bool fail_max = false;
|
2020-09-17 13:36:34 +00:00
|
|
|
int constraintDiameter = 0;
|
2020-09-11 21:50:53 +00:00
|
|
|
int actual = via->GetWidth();
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-09-11 21:50:53 +00:00
|
|
|
if( constraint.Value().HasMin() && actual < constraint.Value().Min() )
|
|
|
|
{
|
|
|
|
fail_min = true;
|
|
|
|
constraintDiameter = constraint.Value().Min();
|
|
|
|
}
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-09-11 21:50:53 +00:00
|
|
|
if( constraint.Value().HasMax() && actual > constraint.Value().Max() )
|
|
|
|
{
|
|
|
|
fail_max = true;
|
|
|
|
constraintDiameter = constraint.Value().Max();
|
|
|
|
}
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-10-10 11:24:31 +00:00
|
|
|
if( fail_min )
|
|
|
|
{
|
|
|
|
m_msg.Printf( _( " (%s min diameter %s; actual %s)" ),
|
|
|
|
constraint.GetName(),
|
|
|
|
MessageTextFromValue( userUnits(), constraintDiameter ),
|
|
|
|
MessageTextFromValue( userUnits(), actual ) );
|
|
|
|
}
|
|
|
|
else if( fail_max )
|
|
|
|
{
|
|
|
|
m_msg.Printf( _( " (%s max diameter %s; actual %s)" ),
|
|
|
|
constraint.GetName(),
|
|
|
|
MessageTextFromValue( userUnits(), constraintDiameter ),
|
|
|
|
MessageTextFromValue( userUnits(), actual ) );
|
|
|
|
}
|
|
|
|
|
2020-09-11 21:50:53 +00:00
|
|
|
if( fail_min || fail_max )
|
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_VIA_DIAMETER );
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-10-10 11:24:31 +00:00
|
|
|
drcItem->SetErrorMessage( drcItem->GetErrorText() + m_msg );
|
2020-09-11 21:50:53 +00:00
|
|
|
drcItem->SetItems( item );
|
|
|
|
drcItem->SetViolatingRule( constraint.GetParentRule() );
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
reportViolation( drcItem, via->GetPosition());
|
2020-09-11 21:50:53 +00:00
|
|
|
}
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-09-11 21:50:53 +00:00
|
|
|
return true;
|
|
|
|
};
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-09-17 13:36:34 +00:00
|
|
|
int ii = 0;
|
|
|
|
|
|
|
|
for( TRACK* item : m_drcEngine->GetBoard()->Tracks() )
|
|
|
|
{
|
2020-09-18 19:57:54 +00:00
|
|
|
if( !reportProgress( ii++, m_drcEngine->GetBoard()->Tracks().size(), delta ) )
|
|
|
|
break;
|
2020-09-17 13:36:34 +00:00
|
|
|
|
|
|
|
if( !checkViaDiameter( item ) )
|
|
|
|
break;
|
|
|
|
}
|
2020-08-25 17:42:52 +00:00
|
|
|
|
|
|
|
reportRuleStatistics();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
int DRC_TEST_PROVIDER_VIA_DIAMETER::GetNumPhases() const
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-13 10:37:20 +00:00
|
|
|
std::set<DRC_CONSTRAINT_TYPE_T> DRC_TEST_PROVIDER_VIA_DIAMETER::GetConstraintTypes() const
|
2020-08-25 17:42:52 +00:00
|
|
|
{
|
2020-09-13 10:37:20 +00:00
|
|
|
return { DRC_CONSTRAINT_TYPE_VIA_DIAMETER };
|
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_VIA_DIAMETER> dummy;
|
2020-10-02 20:51:24 +00:00
|
|
|
}
|