2020-08-25 17:42:52 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-03-13 12:27:43 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2021-06-11 21:07:02 +00:00
|
|
|
#include <pcb_track.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <drc/drc_engine.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
|
|
|
|
|
|
|
/*
|
2020-11-02 16:20:00 +00:00
|
|
|
Via/pad annular ring width test. Checks if there's sufficient copper ring around
|
|
|
|
PTH/NPTH holes (vias/pads)
|
2020-08-25 17:42:52 +00:00
|
|
|
Errors generated:
|
2021-06-26 09:11:22 +00:00
|
|
|
- DRCE_ANNULAR_WIDTH
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-09-08 13:44:44 +00:00
|
|
|
Todo:
|
2020-08-25 17:42:52 +00:00
|
|
|
- check pad holes too.
|
|
|
|
- pad stack support (different IAR/OAR values depending on layer)
|
|
|
|
*/
|
|
|
|
|
2021-06-26 09:11:22 +00:00
|
|
|
class DRC_TEST_PROVIDER_ANNULAR_WIDTH : public DRC_TEST_PROVIDER
|
2020-08-25 17:42:52 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-06-26 09:11:22 +00:00
|
|
|
DRC_TEST_PROVIDER_ANNULAR_WIDTH()
|
2020-08-25 17:42:52 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-06-26 09:11:22 +00:00
|
|
|
virtual ~DRC_TEST_PROVIDER_ANNULAR_WIDTH()
|
2020-08-25 17:42:52 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool Run() override;
|
|
|
|
|
|
|
|
virtual const wxString GetName() const override
|
|
|
|
{
|
2022-03-13 12:27:43 +00:00
|
|
|
return wxT( "annular_width" );
|
2020-08-25 17:42:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual const wxString GetDescription() const override
|
|
|
|
{
|
2022-03-13 12:27:43 +00:00
|
|
|
return wxT( "Tests pad/via annular rings" );
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-06-26 09:11:22 +00:00
|
|
|
bool DRC_TEST_PROVIDER_ANNULAR_WIDTH::Run()
|
2020-08-25 17:42:52 +00:00
|
|
|
{
|
2021-02-27 13:43:41 +00:00
|
|
|
if( m_drcEngine->IsErrorLimitExceeded( DRCE_ANNULAR_WIDTH ) )
|
|
|
|
{
|
2022-03-13 12:27:43 +00:00
|
|
|
reportAux( wxT( "Annular width violations ignored. Skipping check." ) );
|
2021-02-27 13:43:41 +00:00
|
|
|
return true; // continue with other tests
|
|
|
|
}
|
|
|
|
|
2020-09-16 15:03:55 +00:00
|
|
|
const int delta = 250; // This is the number of tests between 2 calls to the progress bar
|
|
|
|
|
2020-11-02 16:20:00 +00:00
|
|
|
if( !m_drcEngine->HasRulesForConstraintType( ANNULAR_WIDTH_CONSTRAINT ) )
|
2020-08-25 17:42:52 +00:00
|
|
|
{
|
2022-03-13 12:27:43 +00:00
|
|
|
reportAux( wxT( "No annular width constraints found. Tests not run." ) );
|
2021-02-27 13:43:41 +00:00
|
|
|
return true; // continue with other tests
|
2020-08-25 17:42:52 +00:00
|
|
|
}
|
|
|
|
|
2020-09-18 19:57:54 +00:00
|
|
|
if( !reportPhase( _( "Checking via annular rings..." ) ) )
|
2021-02-27 13:43:41 +00:00
|
|
|
return false; // DRC cancelled
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2021-06-26 09:11:22 +00:00
|
|
|
auto checkAnnularWidth =
|
2020-09-11 21:50:53 +00:00
|
|
|
[&]( BOARD_ITEM* item ) -> bool
|
|
|
|
{
|
2020-09-23 10:46:41 +00:00
|
|
|
if( m_drcEngine->IsErrorLimitExceeded( DRCE_ANNULAR_WIDTH ) )
|
2020-09-12 19:28:22 +00:00
|
|
|
return false;
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
int v_min = 0;
|
|
|
|
int v_max = 0;
|
|
|
|
PCB_VIA* via = dyn_cast<PCB_VIA*>( item );
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-09-11 21:50:53 +00:00
|
|
|
// fixme: check minimum IAR/OAR ring for THT pads too
|
|
|
|
if( !via )
|
|
|
|
return true;
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2021-02-08 14:53:49 +00:00
|
|
|
// PADSTACKS TODO: once we have padstacks we'll need to run this per-layer....
|
|
|
|
auto constraint = m_drcEngine->EvalRules( ANNULAR_WIDTH_CONSTRAINT, via, nullptr,
|
|
|
|
UNDEFINED_LAYER );
|
2021-06-26 09:11:22 +00:00
|
|
|
int annularWidth = ( via->GetWidth() - via->GetDrillValue() ) / 2;
|
2020-09-11 21:50:53 +00:00
|
|
|
bool fail_min = false;
|
|
|
|
bool fail_max = false;
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-09-11 21:50:53 +00:00
|
|
|
if( constraint.Value().HasMin() )
|
|
|
|
{
|
|
|
|
v_min = constraint.Value().Min();
|
2021-06-26 09:11:22 +00:00
|
|
|
fail_min = annularWidth < v_min;
|
2020-09-11 21:50:53 +00:00
|
|
|
}
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-09-11 21:50:53 +00:00
|
|
|
if( constraint.Value().HasMax() )
|
|
|
|
{
|
|
|
|
v_max = constraint.Value().Max();
|
2021-06-26 09:11:22 +00:00
|
|
|
fail_max = annularWidth > v_max;
|
2020-09-11 21:50:53 +00:00
|
|
|
}
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-09-11 21:50:53 +00:00
|
|
|
if( fail_min || fail_max )
|
|
|
|
{
|
2020-09-23 10:46:41 +00:00
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_ANNULAR_WIDTH );
|
2022-06-15 23:42:34 +00:00
|
|
|
wxString msg;
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-09-22 14:50:15 +00:00
|
|
|
if( fail_min )
|
2022-06-15 23:42:34 +00:00
|
|
|
msg.Printf( _( "(%s min annular width %s; actual %s)" ),
|
2020-09-22 14:50:15 +00:00
|
|
|
constraint.GetName(),
|
2020-10-02 20:51:24 +00:00
|
|
|
MessageTextFromValue( userUnits(), v_min ),
|
2021-06-26 09:11:22 +00:00
|
|
|
MessageTextFromValue( userUnits(), annularWidth ) );
|
2020-09-22 14:50:15 +00:00
|
|
|
|
|
|
|
if( fail_max )
|
2022-06-15 23:42:34 +00:00
|
|
|
msg.Printf( _( "(%s max annular width %s; actual %s)" ),
|
2020-09-22 14:50:15 +00:00
|
|
|
constraint.GetName(),
|
2020-10-02 20:51:24 +00:00
|
|
|
MessageTextFromValue( userUnits(), v_max ),
|
2021-06-26 09:11:22 +00:00
|
|
|
MessageTextFromValue( userUnits(), annularWidth ) );
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2022-06-15 23:42:34 +00:00
|
|
|
drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + 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-11-24 22:16:41 +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-16 15:03:55 +00:00
|
|
|
BOARD* board = m_drcEngine->GetBoard();
|
|
|
|
int ii = 0;
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_TRACK* item : board->Tracks() )
|
2020-09-16 15:03:55 +00:00
|
|
|
{
|
2020-09-18 19:57:54 +00:00
|
|
|
if( !reportProgress( ii++, board->Tracks().size(), delta ) )
|
2022-03-13 12:27:43 +00:00
|
|
|
return false; // DRC cancelled
|
2020-09-16 15:03:55 +00:00
|
|
|
|
2021-06-26 09:11:22 +00:00
|
|
|
if( !checkAnnularWidth( item ) )
|
2022-03-13 12:27:43 +00:00
|
|
|
break;
|
2020-09-16 15:03:55 +00:00
|
|
|
}
|
2020-08-25 17:42:52 +00:00
|
|
|
|
|
|
|
reportRuleStatistics();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-26 09:11:22 +00:00
|
|
|
int DRC_TEST_PROVIDER_ANNULAR_WIDTH::GetNumPhases() const
|
2020-09-14 17:54:14 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-26 09:11:22 +00:00
|
|
|
std::set<DRC_CONSTRAINT_T> DRC_TEST_PROVIDER_ANNULAR_WIDTH::GetConstraintTypes() const
|
2020-08-25 17:42:52 +00:00
|
|
|
{
|
2020-11-02 16:20:00 +00:00
|
|
|
return { ANNULAR_WIDTH_CONSTRAINT };
|
2020-08-25 17:42:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace detail
|
|
|
|
{
|
2021-06-26 09:11:22 +00:00
|
|
|
static DRC_REGISTER_TEST_PROVIDER<DRC_TEST_PROVIDER_ANNULAR_WIDTH> dummy;
|
2020-09-08 13:44:44 +00:00
|
|
|
}
|