KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_drc_netclass_literal.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, see <https://www.gnu.org/licenses/>.
18 */
19
22#include <board.h>
24#include <drc/drc_engine.h>
25#include <drc/drc_item.h>
26#include <drc/drc_rule.h>
27#include <netclass.h>
28#include <pcb_track.h>
31
32
33// An expression string cannot end in a backslash, so such a class loses only its own rules and is reported
34BOOST_AUTO_TEST_CASE( DRCNetclassNameEndingInBackslash )
35{
36 SETTINGS_MANAGER settingsManager;
37 std::unique_ptr<BOARD> board;
38
39 KI_TEST::LoadBoard( settingsManager, "connection_width_rules", board );
40
41 BOARD_DESIGN_SETTINGS& bds = board->GetDesignSettings();
42 bds.m_NetSettings->GetNetclasses().at( wxS( "High_current" ) )->SetName( wxS( "High_current\\" ) );
43
44 std::vector<wxString> warnings;
45
47 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
48 const std::function<void( PCB_MARKER* )>& aPathGenerator )
49 {
50 if( aItem->GetErrorCode() == DRCE_GENERIC_WARNING )
51 warnings.push_back( aItem->GetErrorMessage( false ) );
52 } );
53
54 BOOST_REQUIRE_NO_THROW( bds.m_DRCEngine->InitEngine( board->GetDesignRulesPath() ) );
55 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
56
57 BOOST_CHECK_EQUAL( warnings.size(), 1 );
58 BOOST_CHECK( !warnings.empty() && warnings[0].Contains( wxS( "'High_current\\'" ) ) );
59
60 PCB_TRACK* netA = nullptr;
61 PCB_TRACK* netB = nullptr;
62
63 for( PCB_TRACK* track : board->Tracks() )
64 {
65 if( track->GetNetname() == wxS( "net_1" ) )
66 netA = track;
67 else if( track->GetNetname() == wxS( "net_3" ) )
68 netB = track;
69 }
70
71 BOOST_REQUIRE( netA && netB );
72
73 DRC_CONSTRAINT constraint = bds.m_DRCEngine->EvalRules( CLEARANCE_CONSTRAINT, netA, netB, F_Cu );
74
75 BOOST_REQUIRE( constraint.GetParentRule() );
76 BOOST_CHECK_EQUAL( constraint.GetParentRule()->m_ImplicitNetclass, wxS( "Default" ) );
77}
Container for design settings for a BOARD object.
std::shared_ptr< NET_SETTINGS > m_NetSettings
std::shared_ptr< DRC_ENGINE > m_DRCEngine
DRC_RULE * GetParentRule() const
Definition drc_rule.h:147
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
DRC_CONSTRAINT EvalRules(DRC_CONSTRAINT_T aConstraintType, const BOARD_ITEM *a, const BOARD_ITEM *b, PCB_LAYER_ID aLayer, REPORTER *aReporter=nullptr)
void InitEngine(const wxFileName &aRulePath)
Initialize the DRC engine.
wxString m_ImplicitNetclass
Netclass named by an implicit netclass rule's condition.
Definition drc_rule.h:81
const std::map< wxString, std::shared_ptr< NETCLASS > > & GetNetclasses() const
Gets all netclasses.
@ CLEARANCE_CONSTRAINT
@ DRCE_GENERIC_WARNING
Definition drc_item.h:104
@ F_Cu
Definition layer_ids.h:60
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
BOOST_AUTO_TEST_CASE(DRCNetclassNameEndingInBackslash)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708