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
|
|
|
|
*/
|
|
|
|
|
2020-09-11 21:50:53 +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>
|
2020-09-11 21:50:53 +00:00
|
|
|
#include <drc/drc_test_provider.h>
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
#include <drawing_sheet/ds_draw_item.h>
|
|
|
|
#include <drawing_sheet/ds_proxy_view_item.h>
|
2020-08-25 17:42:52 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Miscellaneous tests:
|
|
|
|
|
|
|
|
- DRCE_DISABLED_LAYER_ITEM, ///< item on a disabled layer
|
|
|
|
- DRCE_INVALID_OUTLINE, ///< invalid board outline
|
|
|
|
- DRCE_UNRESOLVED_VARIABLE,
|
|
|
|
|
|
|
|
TODO:
|
|
|
|
- if grows too big, split into separate providers
|
|
|
|
*/
|
|
|
|
|
|
|
|
class DRC_TEST_PROVIDER_MISC : public DRC_TEST_PROVIDER
|
|
|
|
{
|
|
|
|
public:
|
2020-09-16 10:27:46 +00:00
|
|
|
DRC_TEST_PROVIDER_MISC() :
|
|
|
|
m_board( nullptr )
|
2020-08-25 17:42:52 +00:00
|
|
|
{
|
|
|
|
m_isRuleDriven = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~DRC_TEST_PROVIDER_MISC()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool Run() override;
|
|
|
|
|
|
|
|
virtual const wxString GetName() const override
|
|
|
|
{
|
|
|
|
return "miscellanous";
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual const wxString GetDescription() const override
|
|
|
|
{
|
|
|
|
return "Misc checks (board outline, missing textvars)";
|
|
|
|
}
|
|
|
|
|
2021-01-01 22:29:15 +00:00
|
|
|
virtual std::set<DRC_CONSTRAINT_T> GetConstraintTypes() const override;
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
int GetNumPhases() const override;
|
|
|
|
|
2020-08-25 17:42:52 +00:00
|
|
|
private:
|
|
|
|
void testOutline();
|
|
|
|
void testDisabledLayers();
|
|
|
|
void testTextVars();
|
|
|
|
|
|
|
|
BOARD* m_board;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-09-11 21:50:53 +00:00
|
|
|
void DRC_TEST_PROVIDER_MISC::testOutline()
|
2020-08-25 17:42:52 +00:00
|
|
|
{
|
2020-12-24 21:00:41 +00:00
|
|
|
SHAPE_POLY_SET dummyOutline;
|
2020-11-24 14:22:05 +00:00
|
|
|
bool errorHandled = false;
|
|
|
|
|
2020-11-21 20:42:27 +00:00
|
|
|
OUTLINE_ERROR_HANDLER errorHandler =
|
|
|
|
[&]( const wxString& msg, BOARD_ITEM* itemA, BOARD_ITEM* itemB, const wxPoint& pt )
|
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_INVALID_OUTLINE );
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-11-21 20:42:27 +00:00
|
|
|
drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + msg );
|
|
|
|
drcItem->SetItems( itemA, itemB );
|
2020-10-22 20:27:46 +00:00
|
|
|
|
2020-11-21 20:42:27 +00:00
|
|
|
reportViolation( drcItem, pt );
|
2020-11-24 14:22:05 +00:00
|
|
|
errorHandled = true;
|
2020-11-21 20:42:27 +00:00
|
|
|
};
|
2020-11-20 13:55:10 +00:00
|
|
|
|
2020-12-24 21:00:41 +00:00
|
|
|
// Use a really tight chaining epsilon here so that we report errors that might affect
|
|
|
|
// other tools (such as STEP export).
|
|
|
|
constexpr int chainingEpsilon = Millimeter2iu( 0.02 ) / 100;
|
|
|
|
|
2020-12-25 12:07:10 +00:00
|
|
|
if( !BuildBoardPolygonOutlines( m_board, dummyOutline, m_board->GetDesignSettings().m_MaxError,
|
|
|
|
chainingEpsilon, &errorHandler ) )
|
2020-11-21 20:42:27 +00:00
|
|
|
{
|
2020-11-24 14:22:05 +00:00
|
|
|
if( errorHandled )
|
|
|
|
{
|
|
|
|
// if there is an invalid outline, then there must be an outline
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_INVALID_OUTLINE );
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-11-24 14:22:05 +00:00
|
|
|
m_msg.Printf( _( "(no edges found on Edge.Cuts layer)" ) );
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-11-24 14:22:05 +00:00
|
|
|
drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + m_msg );
|
|
|
|
drcItem->SetItems( m_board );
|
2020-10-22 20:27:46 +00:00
|
|
|
|
2020-11-24 14:22:05 +00:00
|
|
|
reportViolation( drcItem, m_board->GetBoundingBox().Centre() );
|
|
|
|
}
|
2020-10-22 20:27:46 +00:00
|
|
|
}
|
2020-08-25 17:42:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-11 21:50:53 +00:00
|
|
|
void DRC_TEST_PROVIDER_MISC::testDisabledLayers()
|
2020-08-25 17:42:52 +00:00
|
|
|
{
|
|
|
|
LSET disabledLayers = m_board->GetEnabledLayers().flip();
|
|
|
|
|
|
|
|
// Perform the test only for copper layers
|
|
|
|
disabledLayers &= LSET::AllCuMask();
|
|
|
|
|
2020-09-11 21:50:53 +00:00
|
|
|
auto checkDisabledLayers =
|
|
|
|
[&]( BOARD_ITEM* item ) -> bool
|
|
|
|
{
|
|
|
|
LSET refLayers ( item->GetLayer() );
|
2020-09-04 23:12:15 +00:00
|
|
|
|
2020-09-11 21:50:53 +00:00
|
|
|
if( ( disabledLayers & refLayers ).any() )
|
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM>drcItem = DRC_ITEM::Create( DRCE_DISABLED_LAYER_ITEM );
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-11-02 16:20:00 +00:00
|
|
|
m_msg.Printf( _( "(layer %s)" ),
|
2020-09-11 21:50:53 +00:00
|
|
|
item->GetLayerName() );
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-11-02 16:20:00 +00:00
|
|
|
drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + m_msg );
|
2020-09-11 21:50:53 +00:00
|
|
|
drcItem->SetItems( item );
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-11-24 22:16:41 +00:00
|
|
|
reportViolation( drcItem, item->GetPosition() );
|
2020-09-11 21:50:53 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
2020-08-25 17:42:52 +00:00
|
|
|
|
|
|
|
// fixme: what about graphical items?
|
2020-11-11 23:05:59 +00:00
|
|
|
forEachGeometryItem( { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_ZONE_T, PCB_PAD_T },
|
2020-09-11 21:50:53 +00:00
|
|
|
LSET::AllLayersMask(), checkDisabledLayers );
|
2020-08-25 17:42:52 +00:00
|
|
|
}
|
|
|
|
|
2020-09-11 21:50:53 +00:00
|
|
|
void DRC_TEST_PROVIDER_MISC::testTextVars()
|
2020-08-25 17:42:52 +00:00
|
|
|
{
|
2020-09-11 21:50:53 +00:00
|
|
|
auto checkUnresolvedTextVar =
|
|
|
|
[&]( EDA_ITEM* item ) -> bool
|
|
|
|
{
|
2020-09-12 19:28:22 +00:00
|
|
|
if( m_drcEngine->IsErrorLimitExceeded( DRCE_UNRESOLVED_VARIABLE ) )
|
|
|
|
return false;
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-09-12 19:28:22 +00:00
|
|
|
EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( item );
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-09-12 19:28:22 +00:00
|
|
|
if( text && text->GetShownText().Matches( wxT( "*${*}*" ) ) )
|
2020-09-11 21:50:53 +00:00
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM>drcItem = DRC_ITEM::Create( DRCE_UNRESOLVED_VARIABLE );
|
|
|
|
drcItem->SetItems( item );
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-11-24 22:16:41 +00:00
|
|
|
reportViolation( drcItem, item->GetPosition() );
|
2020-09-11 21:50:53 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
forEachGeometryItem( { PCB_FP_TEXT_T, PCB_TEXT_T }, LSET::AllLayersMask(),
|
2020-09-11 21:50:53 +00:00
|
|
|
checkUnresolvedTextVar );
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_PROXY_VIEW_ITEM* drawingSheet = m_drcEngine->GetDrawingSheet();
|
|
|
|
DS_DRAW_ITEM_LIST drawItems;
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2021-02-22 16:37:43 +00:00
|
|
|
if( !drawingSheet || m_drcEngine->IsErrorLimitExceeded( DRCE_UNRESOLVED_VARIABLE ) )
|
2020-08-25 17:42:52 +00:00
|
|
|
return;
|
|
|
|
|
2021-02-22 16:37:43 +00:00
|
|
|
drawItems.SetMilsToIUfactor( IU_PER_MILS );
|
|
|
|
drawItems.SetPageNumber( "1" );
|
|
|
|
drawItems.SetSheetCount( 1 );
|
|
|
|
drawItems.SetFileName( "dummyFilename" );
|
|
|
|
drawItems.SetSheetName( "dummySheet" );
|
|
|
|
drawItems.SetSheetLayer( "dummyLayer" );
|
|
|
|
drawItems.SetProject( m_board->GetProject() );
|
|
|
|
drawItems.BuildDrawItemsList( drawingSheet->GetPageInfo(), drawingSheet->GetTitleBlock() );
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
for( DS_DRAW_ITEM_BASE* item = drawItems.GetFirst(); item; item = drawItems.GetNext() )
|
2020-08-25 17:42:52 +00:00
|
|
|
{
|
2020-09-12 19:28:22 +00:00
|
|
|
if( m_drcEngine->IsErrorLimitExceeded( DRCE_UNRESOLVED_VARIABLE ) )
|
|
|
|
break;
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DRAW_ITEM_TEXT* text = dynamic_cast<DS_DRAW_ITEM_TEXT*>( item );
|
2020-09-12 19:28:22 +00:00
|
|
|
|
|
|
|
if( text && text->GetShownText().Matches( wxT( "*${*}*" ) ) )
|
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_UNRESOLVED_VARIABLE );
|
|
|
|
drcItem->SetItems( text );
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-11-24 22:16:41 +00:00
|
|
|
reportViolation( drcItem, text->GetPosition() );
|
2020-08-25 17:42:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-11 21:50:53 +00:00
|
|
|
bool DRC_TEST_PROVIDER_MISC::Run()
|
2020-08-25 17:42:52 +00:00
|
|
|
{
|
|
|
|
m_board = m_drcEngine->GetBoard();
|
|
|
|
|
2021-02-27 13:43:41 +00:00
|
|
|
if( !m_drcEngine->IsErrorLimitExceeded( DRCE_INVALID_OUTLINE ) )
|
|
|
|
{
|
|
|
|
if( !reportPhase( _( "Checking board outline..." ) ) )
|
|
|
|
return false; // DRC cancelled
|
2020-09-18 19:57:54 +00:00
|
|
|
|
2021-02-27 13:43:41 +00:00
|
|
|
testOutline();
|
|
|
|
}
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2021-02-27 13:43:41 +00:00
|
|
|
if( !m_drcEngine->IsErrorLimitExceeded( DRCE_DISABLED_LAYER_ITEM ) )
|
|
|
|
{
|
|
|
|
if( !reportPhase( _( "Checking disabled layers..." ) ) )
|
|
|
|
return false; // DRC cancelled
|
2020-09-18 19:57:54 +00:00
|
|
|
|
2021-02-27 13:43:41 +00:00
|
|
|
testDisabledLayers();
|
|
|
|
}
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2021-02-27 13:43:41 +00:00
|
|
|
if( !m_drcEngine->IsErrorLimitExceeded( DRCE_UNRESOLVED_VARIABLE ) )
|
|
|
|
{
|
|
|
|
if( !reportPhase( _( "Checking text variables..." ) ) )
|
|
|
|
return false; // DRC cancelled
|
2020-09-18 19:57:54 +00:00
|
|
|
|
2021-02-27 13:43:41 +00:00
|
|
|
testTextVars();
|
|
|
|
}
|
2020-08-25 17:42:52 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
int DRC_TEST_PROVIDER_MISC::GetNumPhases() const
|
|
|
|
{
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-01 22:29:15 +00:00
|
|
|
std::set<DRC_CONSTRAINT_T> DRC_TEST_PROVIDER_MISC::GetConstraintTypes() const
|
2020-08-25 17:42:52 +00:00
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace detail
|
|
|
|
{
|
2020-09-11 21:50:53 +00:00
|
|
|
static DRC_REGISTER_TEST_PROVIDER<DRC_TEST_PROVIDER_MISC> dummy;
|
2020-08-25 17:42:52 +00:00
|
|
|
}
|