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, 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
40
43
44#include <board.h>
46#include <pcb_shape.h>
47#include <drc/drc_item.h>
48#include <drc/drc_engine.h>
51
52
54{
56
58 {
59 if( m_board && m_board->GetDesignSettings().m_DRCEngine )
60 m_board->GetDesignSettings().m_DRCEngine->ClearViolationHandler();
61
62 if( m_board )
63 {
64 m_board->SetProject( nullptr );
65 m_board = nullptr;
66 }
67 }
68
70 std::unique_ptr<BOARD> m_board;
71};
72
73
74BOOST_FIXTURE_TEST_CASE( DegenerateArcOutlineMarkerIssue24241,
76{
77 KI_TEST::LoadBoard( m_settingsManager, "issue24241/issue24241", m_board );
78
79 BOOST_REQUIRE_MESSAGE( m_board, "Failed to load board issue24241" );
80
81 std::vector<std::shared_ptr<DRC_ITEM>> violations;
82 std::vector<VECTOR2I> markerPositions;
83 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
84
85 BOOST_REQUIRE_MESSAGE( bds.m_DRCEngine, "DRC engine not initialized" );
86
87 for( int ii = DRCE_FIRST; ii <= DRCE_LAST; ++ii )
89
91
93 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int /*aLayer*/,
94 const std::function<void( PCB_MARKER* )>& /*aPathGenerator*/ )
95 {
96 if( bds.GetSeverity( aItem->GetErrorCode() ) == SEVERITY::RPT_SEVERITY_ERROR )
97 {
98 violations.push_back( aItem );
99 markerPositions.push_back( aPos );
100 }
101 } );
102
103 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
104
106
107 BOOST_TEST_MESSAGE( wxString::Format( "Found %d invalid-outline violations",
108 (int) violations.size() ) );
109
110 BOOST_REQUIRE_GE( violations.size(), 1u );
111
112 // Locate the degenerate arc directly from the board. Its three control
113 // points should all coincide.
114 PCB_SHAPE* degenerateArc = nullptr;
115
116 for( BOARD_ITEM* item : m_board->Drawings() )
117 {
118 if( item->Type() != PCB_SHAPE_T )
119 continue;
120
121 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
122
123 if( shape->GetShape() != SHAPE_T::ARC || shape->GetLayer() != Edge_Cuts )
124 continue;
125
126 if( shape->GetStart() == shape->GetEnd() && shape->GetStart() == shape->GetArcMid() )
127 {
128 degenerateArc = shape;
129 break;
130 }
131 }
132
133 BOOST_REQUIRE_MESSAGE( degenerateArc,
134 "Reproduction board is expected to contain a degenerate arc" );
135
136 // At least one violation must reference the degenerate arc (either as
137 // its primary or auxiliary item) and place the marker at the arc's
138 // coordinates so the user can navigate to it.
139 bool foundLinkedViolation = false;
140
141 for( size_t ii = 0; ii < violations.size(); ++ii )
142 {
143 const std::shared_ptr<DRC_ITEM>& v = violations[ii];
144 const VECTOR2I& pos = markerPositions[ii];
145
146 const bool itemMatches = v->GetMainItemID() == degenerateArc->m_Uuid
147 || v->GetAuxItemID() == degenerateArc->m_Uuid;
148
149 if( itemMatches && pos == degenerateArc->GetStart() )
150 {
151 foundLinkedViolation = true;
152 break;
153 }
154 }
155
156 BOOST_CHECK_MESSAGE( foundLinkedViolation,
157 "Expected a violation that references the degenerate arc and "
158 "places the marker at its coordinates so the user can locate it" );
159}
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:84
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:168
void ClearViolationHandler()
Definition drc_engine.h:173
const KIID m_Uuid
Definition eda_item.h:528
SHAPE_T GetShape() const
Definition eda_shape.h:189
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition eda_shape.h:236
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition eda_shape.h:194
VECTOR2I GetArcMid() const
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition pcb_shape.h:71
@ DRCE_INVALID_OUTLINE
Definition drc_item.h:73
@ DRCE_FIRST
Definition drc_item.h:39
@ DRCE_LAST
Definition drc_item.h:124
@ Edge_Cuts
Definition layer_ids.h:112
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:85
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687