KiCad PCB EDA Suite
drc.h
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) 2007-2016 Dick Hollenbeck, dick@softplc.com
5  * Copyright (C) 2017-2019 KiCad Developers, see change_log.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef DRC_H
26 #define DRC_H
27 
28 #include <class_board.h>
29 #include <class_track.h>
30 #include <class_marker_pcb.h>
31 #include <geometry/seg.h>
33 #include <memory>
34 #include <vector>
35 #include <tools/pcb_tool_base.h>
36 
37 #define OK_DRC 0
38 #define BAD_DRC 1
39 
40 
41 
93 
102 
104 };
105 
106 
107 class PCB_EDIT_FRAME;
108 class DIALOG_DRC;
109 class BOARD_ITEM;
110 class BOARD;
111 class D_PAD;
112 class ZONE_CONTAINER;
113 class TRACK;
114 class MARKER_PCB;
115 class DRC_ITEM;
116 class NETCLASS;
117 class EDA_TEXT;
118 class DRAWSEGMENT;
119 class NETLIST;
120 class wxWindow;
121 class wxString;
122 class wxTextCtrl;
123 
124 
133 class DRC : public PCB_TOOL_BASE
134 {
135  friend class DIALOG_DRC;
136 
137 public:
138  DRC();
139  ~DRC();
140 
142  void Reset( RESET_REASON aReason ) override;
143 
144 private:
145 
146  // protected or private functions() are lowercase first character.
147  bool m_doPad2PadTest; // enable pad to pad clearance tests
148  bool m_doUnconnectedTest; // enable unconnected tests
149  bool m_doZonesTest; // enable zone to items clearance tests
150  bool m_doKeepoutTest; // enable keepout areas to items clearance tests
151  bool m_refillZones; // refill zones if requested (by user).
152  bool m_reportAllTrackErrors; // Report all tracks errors (or only 4 first errors)
153  bool m_testFootprints; // Test footprints against schematic
154 
155  /* In DRC functions, many calculations are using coordinates relative
156  * to the position of the segment under test (segm to segm DRC, segm to pad DRC
157  * Next variables store coordinates relative to the start point of this segment
158  */
159  wxPoint m_padToTestPos; // Position of the pad for segm-to-pad and pad-to-pad
160  wxPoint m_segmEnd; // End point of the reference segment (start = (0, 0) )
161 
162  /* Some functions are comparing the ref segm to pads or others segments using
163  * coordinates relative to the ref segment considered as the X axis
164  * so we store the ref segment length (the end point relative to these axis)
165  * and the segment orientation (used to rotate other coordinates)
166  */
167  double m_segmAngle; // Ref segm orientation in 0.1 degree
168  int m_segmLength; // length of the reference segment
169 
170  /* variables used in checkLine to test DRC segm to segm:
171  * define the area relative to the ref segment that does not contains any other segment
172  */
177 
178  PCB_EDIT_FRAME* m_pcbEditorFrame; // The pcb frame editor which owns the board
180  SHAPE_POLY_SET m_board_outlines; // The board outline including cutouts
182 
183  std::vector<DRC_ITEM*> m_unconnected; // list of unconnected pads
184  std::vector<DRC_ITEM*> m_footprints; // list of footprint warnings
185  bool m_drcRun;
187 
189  void setTransitions() override;
190 
194  void updatePointers();
195 
197 
201  void addMarkerToPcb( MARKER_PCB* aMarker );
202 
206  wxPoint getLocation( TRACK* aTrack, ZONE_CONTAINER* aConflictZone ) const;
207  wxPoint getLocation( TRACK* aTrack, BOARD_ITEM* aConflitItem, const SEG& aConflictSeg ) const;
208 
209  //-----<categorical group tests>-----------------------------------------
210 
220  bool testNetClasses();
221 
230  void testTracks( wxWindow * aActiveWindow, bool aShowProgressBar );
231 
232  void testPad2Pad();
233 
234  void testDrilledHoles();
235 
236  void testUnconnected();
237 
238  void testZones();
239 
240  void testKeepoutAreas();
241 
242  // aTextItem is type BOARD_ITEM* to accept either TEXTE_PCB or TEXTE_MODULE
243  void testCopperTextItem( BOARD_ITEM* aTextItem );
244 
245  void testCopperDrawItem( DRAWSEGMENT* aDrawing );
246 
248 
250  void testDisabledLayers();
251 
255  void testOutline();
256 
257  //-----<single "item" tests>-----------------------------------------
258 
259  bool doNetClass( const std::shared_ptr<NETCLASS>& aNetClass, wxString& msg );
260 
273  bool doPadToPadsDrc( D_PAD* aRefPad, D_PAD** aStart, D_PAD** aEnd, int x_limit );
274 
285  void doTrackDrc( TRACK* aRefSeg, TRACKS::iterator aStartIt, TRACKS::iterator aEndIt,
286  bool aTestZones );
287 
292 
293  //-----<single tests>----------------------------------------------
294 
300  bool checkClearancePadToPad( D_PAD* aRefPad, D_PAD* aPad );
301 
302 
317  bool checkClearanceSegmToPad( const D_PAD* aPad, int aSegmentWidth, int aMinDist );
318 
319 
332  static bool checkMarginToCircle( wxPoint aCentre, int aRadius, int aLength );
333 
334 
343  bool checkLine( wxPoint aSegStart, wxPoint aSegEnd );
344 
345  //-----</single tests>---------------------------------------------
346 
347 public:
354 
359  static void TestFootprints( NETLIST& aNetlist, BOARD* aPCB, EDA_UNITS aUnits,
360  std::vector<DRC_ITEM*>& aDRCList );
361 
375  void ShowDRCDialog( wxWindow* aParent );
376 
377  int ShowDRCDialog( const TOOL_EVENT& aEvent );
378 
384  bool IsDRCDialogShown();
385 
394  void DestroyDRCDialog( int aReason );
395 
401  void RunTests( wxTextCtrl* aMessages = NULL );
402 };
403 
404 
405 #endif // DRC_H
bool m_refillZones
Definition: drc.h:151
bool doNetClass(const std::shared_ptr< NETCLASS > &aNetClass, wxString &msg)
Definition: drc.h:94
hole too close to track
Definition: drc.h:61
EDA_UNITS
Definition: common.h:184
std::vector< DRC_ITEM * > m_footprints
Definition: drc.h:184
copper area outlines intersect
Definition: drc.h:57
Too small via size.
Definition: drc.h:63
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
static void TestFootprints(NETLIST &aNetlist, BOARD *aPCB, EDA_UNITS aUnits, std::vector< DRC_ITEM * > &aDRCList)
Test the board footprints against a netlist.
void DestroyDRCDialog(int aReason)
Deletes this ui dialog box and zeros out its pointer to remember the state of the dialog's existence.
micro vias are not allowed
Definition: drc.h:84
void testCopperTextAndGraphics()
overlapping drilled holes break drill bits
Definition: drc.h:87
PCB_DRC_CODE
DRC error codes:
Definition: drc.h:43
track too close to via
Definition: drc.h:48
int m_ycliplo
Definition: drc.h:174
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
Via in inside a keepout area.
Definition: drc.h:73
void doOverlappingCourtyardsDrc()
Test for footprint courtyard overlaps.
footprint not found for netlist item
Definition: drc.h:90
void setTransitions() override
Sets up handlers for various events.
more than one footprints found for netlist item
Definition: drc.h:91
void testKeepoutAreas()
int m_ycliphi
Definition: drc.h:176
void testCopperDrawItem(DRAWSEGMENT *aDrawing)
int m_segmLength
Definition: drc.h:168
copper area has a net but no pads in nets, which is suspicious
Definition: drc.h:59
void ShowDRCDialog(wxWindow *aParent)
Open a dialog and prompts the user, then if a test run button is clicked, runs the test(s) and create...
EDA_UNITS userUnits() const
Definition: drc.h:196
Too small micro via size.
Definition: drc.h:64
via and copper graphic collide or are too close
Definition: drc.h:77
track ends are too close
Definition: drc.h:51
tracks are crossing
Definition: drc.h:53
netclass has Clearance < board.m_designSettings->m_TrackClearance
Definition: drc.h:68
void testOutline()
Test that the board outline is contiguous and composed of valid elements.
wxPoint m_padToTestPos
Definition: drc.h:159
via too close to via
Definition: drc.h:49
void testCopperTextItem(BOARD_ITEM *aTextItem)
2 parallel track segments too close: segm ends between segref ends
Definition: drc.h:52
Definitions for tracks, vias and zones.
footprint has no courtyard defined
Definition: drc.h:81
BOARD * m_pcb
Definition: drc.h:179
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:109
void testDrilledHoles()
bool checkLine(wxPoint aSegStart, wxPoint aSegEnd)
Function checkLine (helper function used in drc calculations to see if one track is in contact with a...
netlist item not found for footprint
Definition: drc.h:92
track too close to board edge
Definition: drc.h:88
Markers used to show a drc problem on boards.
void Reset(RESET_REASON aReason) override
Function Reset() Brings the tool to a known, initial state.
bool m_testFootprints
Definition: drc.h:153
void addMarkerToPcb(MARKER_PCB *aMarker)
Adds a DRC marker to the PCB through the COMMIT mechanism.
bool m_doKeepoutTest
Definition: drc.h:150
Too small track width.
Definition: drc.h:62
Pad in inside a keepout area.
Definition: drc.h:75
bool m_doZonesTest
Definition: drc.h:149
NETLIST stores all of information read from a netlist along with the flags used to update the NETLIST...
Definition: pcb_netlist.h:212
#define NULL
void testZones()
SHAPE_POLY_SET.
Definition: drc.h:103
item on a disabled layer
Definition: drc.h:86
pad too close to track
Definition: drc.h:47
void updatePointers()
Update needed pointers from the one pointer which is known not to change.
TOOL_EVENT.
Definition: tool_event.h:171
NETCLASS handles a collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:55
invalid board outline
Definition: drc.h:89
static bool checkMarginToCircle(wxPoint aCentre, int aRadius, int aLength)
Check the distance from a point to a segment.
std::vector< DRC_ITEM * > m_unconnected
Definition: drc.h:183
bool m_reportAllTrackErrors
Definition: drc.h:152
netclass has TrackWidth < board.m_designSettings->m_TrackMinWidth
Definition: drc.h:67
thru hole is too close to track
Definition: drc.h:46
bool m_drcRun
Definition: drc.h:185
void testDisabledLayers()
Tests for items placed on disabled layers (causing false connections).
bool doPadToPadsDrc(D_PAD *aRefPad, D_PAD **aStart, D_PAD **aEnd, int x_limit)
Test the clearance between aRefPad and other pads.
Too small micro via drill.
Definition: drc.h:66
via's hole is bigger than its diameter
Definition: drc.h:55
int m_xcliphi
Definition: drc.h:175
PCB_EDIT_FRAME * m_pcbEditorFrame
Definition: drc.h:178
micro via's layer pair incorrect (layers must be adjacent)
Definition: drc.h:56
bool m_doPad2PadTest
Definition: drc.h:147
void testPad2Pad()
bool m_footprintsTested
Definition: drc.h:186
bool checkClearancePadToPad(D_PAD *aRefPad, D_PAD *aPad)
Definition: seg.h:39
bool checkClearanceSegmToPad(const D_PAD *aPad, int aSegmentWidth, int aMinDist)
Check the distance from a pad to segment.
Too small via drill.
Definition: drc.h:65
wxPoint m_segmEnd
Definition: drc.h:160
SHAPE_POLY_SET m_board_outlines
Definition: drc.h:180
pad and copper graphic collide or are too close
Definition: drc.h:78
bool testNetClasses()
Go through each NETCLASS and verifies that its clearance, via size, track width, and track clearance ...
void testTracks(wxWindow *aActiveWindow, bool aShowProgressBar)
Perform the DRC on all tracks.
netclass has ViaDrillSize < board.m_designSettings->m_ViasMinDrill
Definition: drc.h:70
track & copper graphic collide or are too close
Definition: drc.h:76
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:163
Design Rule Checker object that performs all the DRC tests.
Definition: drc.h:133
Track in inside a keepout area.
Definition: drc.h:74
track & zone collide or are too close together
Definition: drc.h:79
int TestZoneToZoneOutlines()
Tests whether distance between zones complies with the DRC rules.
via too close to track
Definition: drc.h:50
PCB_EDIT_FRAME is the main frame for Pcbnew.
items are unconnected
Definition: drc.h:45
hole too close to pad
Definition: drc.h:60
footprint courtyards overlap
Definition: drc.h:80
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:78
bool IsDRCDialogShown()
Check to see if the DRC dialog is currently shown.
netclass has ViaSize < board.m_designSettings->m_MicroViasMinDrill
Definition: drc.h:72
DIALOG_DRC * m_drcDialog
Definition: drc.h:181
Definition: drc.h:44
copper area outlines are too close
Definition: drc.h:58
footprint has a courtyard but malformed
Definition: drc.h:82
void testUnconnected()
void RunTests(wxTextCtrl *aMessages=NULL)
Run all the tests specified with a previous call to SetSettings()
buried vias are not allowed
Definition: drc.h:85
void doTrackDrc(TRACK *aRefSeg, TRACKS::iterator aStartIt, TRACKS::iterator aEndIt, bool aTestZones)
Test the current segment.
pad too close to pad
Definition: drc.h:54
int m_xcliplo
Definition: drc.h:173
netclass has ViaSize < board.m_designSettings->m_ViasMinSize
Definition: drc.h:69
bool m_doUnconnectedTest
Definition: drc.h:148
double m_segmAngle
Definition: drc.h:167
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
netclass has ViaSize < board.m_designSettings->m_MicroViasMinSize
Definition: drc.h:71
wxPoint getLocation(TRACK *aTrack, ZONE_CONTAINER *aConflictZone) const
Fetches a reasonable point for marking a violoation between two non-point objects.