KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_drc_linewidth.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
26#include <board.h>
28#include <drc/drc_engine.h>
29#include <drc/drc_item.h>
30#include <drc/drc_rule.h>
31#include <drc/drc_rule_parser.h>
32#include <pcb_marker.h>
33#include <pcb_shape.h>
35
36
37namespace
38{
39struct DRC_LINE_WIDTH_FIXTURE
40{
41 ~DRC_LINE_WIDTH_FIXTURE()
42 {
43 if( m_board && m_board->GetDesignSettings().m_DRCEngine )
44 m_board->GetDesignSettings().m_DRCEngine->ClearViolationHandler();
45
46 if( m_board )
47 m_board->SetProject( nullptr );
48 }
49
50 SETTINGS_MANAGER m_settingsManager;
51 std::unique_ptr<BOARD> m_board;
52};
53} // namespace
54
55
56BOOST_FIXTURE_TEST_CASE( DRCLineWidth, DRC_LINE_WIDTH_FIXTURE )
57{
58 KI_TEST::LoadBoard( m_settingsManager, "test_drc_linewidth", m_board );
59 BOOST_REQUIRE( m_board );
60
61 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
62
63 // The project is at schema 2, so min_text_thickness must survive the rename to line width
65
66 for( int ii = DRCE_FIRST; ii <= DRCE_LAST; ++ii )
68
70
71 std::vector<int> codes;
72
74 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
75 const std::function<void( PCB_MARKER* )>& aPathGenerator )
76 {
77 codes.push_back( aItem->GetErrorCode() );
78 } );
79
80 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
81
82 // One copper circle over the 1mm max, four unfilled silk shapes and one silk text under 0.2mm
83 BOOST_CHECK_EQUAL( codes.size(), 6 );
84
85 for( int code : codes )
87}
88
89
90BOOST_AUTO_TEST_CASE( DRCLegacyTextThickness )
91{
92 std::vector<std::shared_ptr<DRC_RULE>> rules;
93 DRC_RULES_PARSER parser( wxT( "(version 1)(rule old (constraint text_thickness (min 0.2mm)))" ),
94 wxT( "legacy rules" ) );
95
96 parser.Parse( rules, nullptr );
97
98 BOOST_REQUIRE_EQUAL( rules.size(), 1 );
99 BOOST_REQUIRE_EQUAL( rules[0]->m_Constraints.size(), 1 );
100 BOOST_CHECK_EQUAL( rules[0]->m_Constraints[0].m_Type, LINE_WIDTH_CONSTRAINT );
101
102 // Exclusions saved before the rename name the old settings key
103 std::shared_ptr<DRC_ITEM> item = DRC_ITEM::Create( wxT( "text_thickness" ) );
104
105 BOOST_REQUIRE( item );
106 BOOST_CHECK_EQUAL( item->GetErrorCode(), DRCE_LINE_WIDTH );
107}
108
109
110BOOST_FIXTURE_TEST_CASE( DRCLineWidthShowMatches, DRC_LINE_WIDTH_FIXTURE )
111{
112 KI_TEST::LoadBoard( m_settingsManager, "test_drc_linewidth", m_board );
113 BOOST_REQUIRE( m_board );
114
115 auto rule = std::make_shared<DRC_RULE>( wxT( "widths" ) );
117 rule->AddConstraint( constraint );
118
119 int shapes = 0;
120
121 for( BOARD_ITEM* item : m_board->GetDesignSettings().m_DRCEngine->GetItemsMatchingRule( rule, nullptr ) )
122 {
123 if( item->Type() == PCB_SHAPE_T )
124 {
125 BOOST_CHECK( !static_cast<PCB_SHAPE*>( item )->IsSolidFill() );
126 shapes++;
127 }
128 }
129
130 // Fifteen graphic shapes, two of them solid filled
131 BOOST_CHECK_EQUAL( shapes, 13 );
132}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
Container for design settings for a BOARD object.
std::map< int, SEVERITY > m_DRCSeverities
std::shared_ptr< DRC_ENGINE > m_DRCEngine
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
void RunTests(EDA_UNITS aUnits, bool aReportAllTrackErrors, bool aTestFootprints, BOARD_COMMIT *aCommit=nullptr)
Run the DRC tests.
void SetViolationHandler(DRC_VIOLATION_HANDLER aHandler)
Set an optional DRC violation handler (receives DRC_ITEMs and positions).
Definition drc_engine.h:164
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition drc_item.cpp:505
void Parse(std::vector< std::shared_ptr< DRC_RULE > > &aRules, REPORTER *aReporter)
@ LINE_WIDTH_CONSTRAINT
@ DRCE_FIRST
Definition drc_item.h:47
@ DRCE_LAST
Definition drc_item.h:145
@ DRCE_LINE_WIDTH
Definition drc_item.h:117
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_IGNORE
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
BOOST_REQUIRE_EQUAL(rows.size(), 1)
BOOST_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
BOOST_REQUIRE(res.columns()==1)
BOOST_AUTO_TEST_CASE(DRCLegacyTextThickness)
BOOST_FIXTURE_TEST_CASE(DRCLineWidth, DRC_LINE_WIDTH_FIXTURE)
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:80
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708