KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_drc_invalid_outline_issue24241.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
36
39
40#include <board.h>
42#include <pcb_shape.h>
43#include <drc/drc_item.h>
44#include <drc/drc_engine.h>
47
48
50{
52
54 {
55 if( m_board && m_board->GetDesignSettings().m_DRCEngine )
56 m_board->GetDesignSettings().m_DRCEngine->ClearViolationHandler();
57
58 if( m_board )
59 {
60 m_board->SetProject( nullptr );
61 m_board = nullptr;
62 }
63 }
64
66 std::unique_ptr<BOARD> m_board;
67};
68
69
70BOOST_FIXTURE_TEST_CASE( DegenerateArcOutlineMarkerIssue24241,
72{
73 KI_TEST::LoadBoard( m_settingsManager, "issue24241/issue24241", m_board );
74
75 BOOST_REQUIRE_MESSAGE( m_board, "Failed to load board issue24241" );
76
77 std::vector<std::shared_ptr<DRC_ITEM>> violations;
78 std::vector<VECTOR2I> markerPositions;
79 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
80
81 BOOST_REQUIRE_MESSAGE( bds.m_DRCEngine, "DRC engine not initialized" );
82
83 for( int ii = DRCE_FIRST; ii <= DRCE_LAST; ++ii )
85
87
89 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int /*aLayer*/,
90 const std::function<void( PCB_MARKER* )>& /*aPathGenerator*/ )
91 {
92 if( bds.GetSeverity( aItem->GetErrorCode() ) == SEVERITY::RPT_SEVERITY_ERROR )
93 {
94 violations.push_back( aItem );
95 markerPositions.push_back( aPos );
96 }
97 } );
98
99 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
100
102
103 BOOST_TEST_MESSAGE( wxString::Format( "Found %d invalid-outline violations",
104 (int) violations.size() ) );
105
106 BOOST_REQUIRE_GE( violations.size(), 1u );
107
108 // Locate the degenerate arc directly from the board. Its three control
109 // points should all coincide.
110 PCB_SHAPE* degenerateArc = nullptr;
111
112 for( BOARD_ITEM* item : m_board->Drawings() )
113 {
114 if( item->Type() != PCB_SHAPE_T )
115 continue;
116
117 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
118
119 if( shape->GetShape() != SHAPE_T::ARC || shape->GetLayer() != Edge_Cuts )
120 continue;
121
122 if( shape->GetStart() == shape->GetEnd() && shape->GetStart() == shape->GetArcMid() )
123 {
124 degenerateArc = shape;
125 break;
126 }
127 }
128
129 BOOST_REQUIRE_MESSAGE( degenerateArc,
130 "Reproduction board is expected to contain a degenerate arc" );
131
132 // At least one violation must reference the degenerate arc (either as
133 // its primary or auxiliary item) and place the marker at the arc's
134 // coordinates so the user can navigate to it.
135 bool foundLinkedViolation = false;
136
137 for( size_t ii = 0; ii < violations.size(); ++ii )
138 {
139 const std::shared_ptr<DRC_ITEM>& v = violations[ii];
140 const VECTOR2I& pos = markerPositions[ii];
141
142 const bool itemMatches = v->GetMainItemID() == degenerateArc->m_Uuid
143 || v->GetAuxItemID() == degenerateArc->m_Uuid;
144
145 if( itemMatches && pos == degenerateArc->GetStart() )
146 {
147 foundLinkedViolation = true;
148 break;
149 }
150 }
151
152 BOOST_CHECK_MESSAGE( foundLinkedViolation,
153 "Expected a violation that references the degenerate arc and "
154 "places the marker at its coordinates so the user can locate it" );
155}
Container for design settings for a BOARD object.
std::map< int, SEVERITY > m_DRCSeverities
std::shared_ptr< DRC_ENGINE > m_DRCEngine
SEVERITY GetSeverity(int aDRCErrorCode)
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:80
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
void ClearViolationHandler()
Definition drc_engine.h:169
const KIID m_Uuid
Definition eda_item.h:531
SHAPE_T GetShape() const
Definition eda_shape.h:185
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition eda_shape.h:232
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition eda_shape.h:190
VECTOR2I GetArcMid() const
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition pcb_shape.h:67
@ DRCE_INVALID_OUTLINE
Definition drc_item.h:69
@ DRCE_FIRST
Definition drc_item.h:35
@ DRCE_LAST
Definition drc_item.h:120
@ Edge_Cuts
Definition layer_ids.h:108
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_IGNORE
BOOST_FIXTURE_TEST_CASE(DegenerateArcOutlineMarkerIssue24241, DRC_INVALID_OUTLINE_DEGENERATE_ARC_FIXTURE)
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
BOOST_TEST_MESSAGE("\n=== Real-World Polygon PIP Benchmark ===\n"<< formatTable(table))
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:81
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683