KiCad PCB EDA Suite
drc_netclass_tester.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 (C) 2020 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 
24 
25 #include <drc/drc_netclass_tester.h>
26 
27 
29  DRC_TEST_PROVIDER( std::move( aMarkerHandler ) ),
30  m_units( EDA_UNITS::MILLIMETRES ),
31  m_board( nullptr )
32 {
33 }
34 
35 
37 {
38  m_units = aUnits;
39  m_board = &aBoard;
40 
41  bool success = true;
42  NETCLASSES& netclasses = m_board->GetDesignSettings().m_NetClasses;
43 
44  success &= checkNetClass( netclasses.GetDefault() );
45 
46  for( NETCLASSES::const_iterator i = netclasses.begin(); i != netclasses.end(); ++i )
47  success &= checkNetClass( i->second );
48 
49  return success;
50 }
51 
52 
53 bool DRC_NETCLASS_TESTER::checkNetClass( const NETCLASSPTR& nc )
54 {
55  bool ret = true;
56 
58 
59  if( nc->GetClearance() < bds.m_MinClearance )
60  {
61  DRC_ITEM* drcItem = new DRC_ITEM( DRCE_NETCLASS_CLEARANCE );
62 
63  m_msg.Printf( drcItem->GetErrorText() + _( " (board minimum %s; %s netclass %s)" ),
65  nc->GetName(),
66  MessageTextFromValue( m_units, nc->GetClearance(), true ) );
67 
68  drcItem->SetErrorMessage( m_msg );
69  HandleMarker( new MARKER_PCB( drcItem, wxPoint() ) );
70  ret = false;
71  }
72 
73  if( nc->GetTrackWidth() < bds.m_TrackMinWidth )
74  {
75  DRC_ITEM* drcItem = new DRC_ITEM( DRCE_NETCLASS_TRACKWIDTH );
76 
77  m_msg.Printf( drcItem->GetErrorText() + _( " (board minimum %s; %s netclass %s)" ),
79  nc->GetName(),
80  MessageTextFromValue( m_units, nc->GetTrackWidth(), true ) );
81 
82  drcItem->SetErrorMessage( m_msg );
83  HandleMarker( new MARKER_PCB( drcItem, wxPoint() ) );
84  ret = false;
85  }
86 
87  if( nc->GetViaDiameter() < bds.m_ViasMinSize )
88  {
89  DRC_ITEM* drcItem = new DRC_ITEM( DRCE_NETCLASS_VIASIZE );
90 
91  m_msg.Printf( drcItem->GetErrorText() + _( " (board minimum %s; %s netclass %s)" ),
93  nc->GetName(),
94  MessageTextFromValue( m_units, nc->GetViaDiameter(), true ) );
95 
96  drcItem->SetErrorMessage( m_msg );
97  HandleMarker( new MARKER_PCB( drcItem, wxPoint() ) );
98  ret = false;
99  }
100 
101  if( nc->GetViaDrill() < bds.m_MinThroughDrill )
102  {
103  DRC_ITEM* drcItem = new DRC_ITEM( DRCE_NETCLASS_VIADRILLSIZE );
104 
105  m_msg.Printf( drcItem->GetErrorText() + _( " (board min through hole %s; %s netclass %s)" ),
107  nc->GetName(),
108  MessageTextFromValue( m_units, nc->GetViaDrill(), true ) );
109 
110  drcItem->SetErrorMessage( m_msg );
111  HandleMarker( new MARKER_PCB( drcItem, wxPoint() ) );
112  ret = false;
113  }
114 
115  int ncViaAnnulus = ( nc->GetViaDiameter() - nc->GetViaDrill() ) / 2;
116 
117  if( ncViaAnnulus < bds.m_ViasMinAnnulus )
118  {
119  DRC_ITEM* drcItem = new DRC_ITEM( DRCE_NETCLASS_VIAANNULUS );
120 
121  m_msg.Printf( drcItem->GetErrorText() + _( " (board minimum %s; %s netclass %s)" ),
123  nc->GetName(),
124  MessageTextFromValue( m_units, ncViaAnnulus, true ) );
125 
126  drcItem->SetErrorMessage( m_msg );
127  HandleMarker( new MARKER_PCB( drcItem, wxPoint() ) );
128  ret = false;
129  }
130 
131  if( nc->GetuViaDiameter() < bds.m_MicroViasMinSize )
132  {
133  DRC_ITEM* drcItem = new DRC_ITEM( DRCE_NETCLASS_uVIASIZE );
134 
135  m_msg.Printf( drcItem->GetErrorText() + _( " (board minimum %s; %s netclass %s)" ),
137  nc->GetName(),
138  MessageTextFromValue( m_units, nc->GetuViaDiameter(), true ) );
139 
140  drcItem->SetErrorMessage( m_msg );
141  HandleMarker( new MARKER_PCB( drcItem, wxPoint() ) );
142  ret = false;
143  }
144 
145  if( nc->GetuViaDrill() < bds.m_MicroViasMinDrill )
146  {
148 
149  m_msg.Printf( drcItem->GetErrorText() + _( " (board minimum %s; %s netclass %s)" ),
151  nc->GetName(),
152  MessageTextFromValue( m_units, nc->GetuViaDrill(), true ) );
153 
154  drcItem->SetErrorMessage( m_msg );
155  HandleMarker( new MARKER_PCB( drcItem, wxPoint() ) );
156  ret = false;
157  }
158 
159  return ret;
160 }
161 
162 
EDA_UNITS
Definition: common.h:198
netclass has ViaDrillSize < board.m_designSettings->m_MinThroughDrill
netclass has Clearance < board.m_designSettings->m_TrackClearance
DRC_NETCLASS_TESTER(MARKER_HANDLER aMarkerHandler)
Template specialization to enable wxStrings for certain containers (e.g. unordered_map)
Definition: bitmap.cpp:56
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:551
iterator end()
Definition: netclass.h:243
bool checkNetClass(const NETCLASSPTR &nc)
netclass has ViaSize < board.m_designSettings->m_ViasMinSize
NETCLASS_MAP::const_iterator const_iterator
Definition: netclass.h:245
wxString GetErrorText() const
Definition: rc_item.h:169
iterator begin()
Definition: netclass.h:242
NETCLASSES is a container for NETCLASS instances.
Definition: netclass.h:222
void HandleMarker(MARKER_PCB *aMarker) const
Pass a given marker to the marker handler.
bool RunDRC(EDA_UNITS aUnits, BOARD &aBoard) override
Runs this provider against the given PCB with configured options (if any).
wxString MessageTextFromValue(EDA_UNITS aUnits, int aValue, bool aUseMils, EDA_DATA_TYPE aType)
Definition: base_units.cpp:124
DRC_TEST_PROVIDER is a base class that represents a DRC "provider" which runs some DRC functions over...
std::function< void(MARKER_PCB *)> MARKER_HANDLER
A callable that can handle a single generated PCB_MARKER.
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180
#define _(s)
Definition: 3d_actions.cpp:33
netclass has TrackWidth < board.m_designSettings->m_TrackMinWidth
netclass ViaSize & ViaDrill leave annulus < board.m_designSettings->m_ViasMinAnnulus
NETCLASSPTR GetDefault() const
Function GetDefault.
Definition: netclass.h:262
void SetErrorMessage(const wxString &aMessage)
Definition: rc_item.h:117
netclass has ViaSize < board.m_designSettings->m_MicroViasMinDrill
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
netclass has ViaSize < board.m_designSettings->m_MicroViasMinSize