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 <geometry/seg.h>
32 #include <memory>
33 #include <vector>
34 #include <tools/pcb_tool_base.h>
35 #include <drc/drc_marker_factory.h>
36 
37 #define OK_DRC 0
38 #define BAD_DRC 1
39 
40 
41 // DRC error codes could be defined by an enum.
42 // however a #define is used because error code value is displayed in DRC messages,
43 // and using #define that shows each numerical value helps for debug.
44 
46 #define DRCE_ 1 // not used yet
47 #define DRCE_UNCONNECTED_ITEMS 2
48 #define DRCE_TRACK_NEAR_THROUGH_HOLE 3
49 #define DRCE_TRACK_NEAR_PAD 4
50 #define DRCE_TRACK_NEAR_VIA 5
51 #define DRCE_VIA_NEAR_VIA 6
52 #define DRCE_VIA_NEAR_TRACK 7
53 #define DRCE_TRACK_ENDS1 8
54 #define DRCE_TRACK_ENDS2 9
55 #define DRCE_TRACK_ENDS3 10
56 #define DRCE_TRACK_ENDS4 11
57 #define DRCE_TRACK_SEGMENTS_TOO_CLOSE 12
58 #define DRCE_TRACKS_CROSSING 13
59 #define DRCE_ENDS_PROBLEM1 14
60 #define DRCE_ENDS_PROBLEM2 15
61 #define DRCE_ENDS_PROBLEM3 16
62 #define DRCE_ENDS_PROBLEM4 17
63 #define DRCE_ENDS_PROBLEM5 18
64 #define DRCE_PAD_NEAR_PAD1 19
65 #define DRCE_VIA_HOLE_BIGGER 20
66 #define DRCE_MICRO_VIA_INCORRECT_LAYER_PAIR 21
67 #define DRCE_ZONES_INTERSECT 22
68 #define DRCE_ZONES_TOO_CLOSE 23
69 #define DRCE_SUSPICIOUS_NET_FOR_ZONE_OUTLINE 24
70 #define DRCE_HOLE_NEAR_PAD 25
71 #define DRCE_HOLE_NEAR_TRACK 26
72 #define DRCE_TOO_SMALL_TRACK_WIDTH 27
73 #define DRCE_TOO_SMALL_VIA 28
74 #define DRCE_TOO_SMALL_MICROVIA 29
75 #define DRCE_TOO_SMALL_VIA_DRILL 30
76 #define DRCE_TOO_SMALL_MICROVIA_DRILL 31
77 #define DRCE_NETCLASS_TRACKWIDTH 32
78 #define DRCE_NETCLASS_CLEARANCE 33
79 #define DRCE_NETCLASS_VIASIZE 34
80 #define DRCE_NETCLASS_VIADRILLSIZE 35
81 #define DRCE_NETCLASS_uVIASIZE 36
82 #define DRCE_NETCLASS_uVIADRILLSIZE 37
83 #define DRCE_VIA_INSIDE_KEEPOUT 38
84 #define DRCE_TRACK_INSIDE_KEEPOUT 39
85 #define DRCE_PAD_INSIDE_KEEPOUT 40
86 #define DRCE_TRACK_NEAR_COPPER 41
87 #define DRCE_VIA_NEAR_COPPER 42
88 #define DRCE_PAD_NEAR_COPPER 43
89 #define DRCE_TRACK_NEAR_ZONE 44
90 #define DRCE_OVERLAPPING_FOOTPRINTS 45
91 #define DRCE_MISSING_COURTYARD_IN_FOOTPRINT 46
92 #define DRCE_MALFORMED_COURTYARD_IN_FOOTPRINT 47
93 #define DRCE_MICRO_VIA_NOT_ALLOWED 48
95 #define DRCE_BURIED_VIA_NOT_ALLOWED 49
96 #define DRCE_DISABLED_LAYER_ITEM 50
97 #define DRCE_DRILLED_HOLES_TOO_CLOSE 51
98 #define DRCE_TRACK_NEAR_EDGE 53
99 #define DRCE_INVALID_OUTLINE 54
100 #define DRCE_MISSING_FOOTPRINT 55
101 #define DRCE_DUPLICATE_FOOTPRINT 56
102 #define DRCE_EXTRA_FOOTPRINT 57
103 
104 #define DRCE_SHORT 58
105 #define DRCE_REDUNDANT_VIA 59
106 #define DRCE_DUPLICATE_TRACK 60
107 #define DRCE_MERGE_TRACKS 61
108 #define DRCE_DANGLING_TRACK 62
109 #define DRCE_DANGLING_VIA 63
110 #define DRCE_ZERO_LENGTH_TRACK 64
111 #define DRCE_TRACK_IN_PAD 65
112 
113 
114 class PCB_EDIT_FRAME;
115 class DIALOG_DRC_CONTROL;
116 class BOARD_ITEM;
117 class BOARD;
118 class D_PAD;
119 class ZONE_CONTAINER;
120 class TRACK;
121 class MARKER_PCB;
122 class DRC_ITEM;
123 class NETCLASS;
124 class EDA_TEXT;
125 class DRAWSEGMENT;
126 class NETLIST;
127 class wxWindow;
128 class wxString;
129 class wxTextCtrl;
130 
131 
139 {
140 public:
141 
146  virtual void DeleteAllItems() = 0;
147 
155  virtual const DRC_ITEM* GetItem( int aIndex ) = 0;
156 
163  virtual void DeleteItem( int aIndex ) = 0;
164 
169  virtual int GetCount() = 0;
170 
171  virtual ~DRC_ITEM_LIST() { }
172 };
173 
174 
175 typedef std::vector<DRC_ITEM*> DRC_LIST;
176 
177 
186 class DRC : public PCB_TOOL_BASE
187 {
188  friend class DIALOG_DRC_CONTROL;
189 
190 public:
191  DRC();
192  ~DRC();
193 
195  void Reset( RESET_REASON aReason ) override;
196 
197 private:
198 
199  // protected or private functions() are lowercase first character.
200  bool m_doPad2PadTest; // enable pad to pad clearance tests
201  bool m_doUnconnectedTest; // enable unconnected tests
202  bool m_doZonesTest; // enable zone to items clearance tests
203  bool m_doKeepoutTest; // enable keepout areas to items clearance tests
204  bool m_doCreateRptFile; // enable creating a report file
205  bool m_refillZones; // refill zones if requested (by user).
206  bool m_reportAllTrackErrors; // Report all tracks errors (or only 4 first errors)
207  bool m_testFootprints; // Test footprints against schematic
208 
209  wxString m_rptFilename;
210 
212 
213  /* In DRC functions, many calculations are using coordinates relative
214  * to the position of the segment under test (segm to segm DRC, segm to pad DRC
215  * Next variables store coordinates relative to the start point of this segment
216  */
217  wxPoint m_padToTestPos; // Position of the pad to compare in drc test segm to pad or pad to pad
218  wxPoint m_segmEnd; // End point of the reference segment (start point = (0,0) )
219 
220  /* Some functions are comparing the ref segm to pads or others segments using
221  * coordinates relative to the ref segment considered as the X axis
222  * so we store the ref segment length (the end point relative to these axis)
223  * and the segment orientation (used to rotate other coordinates)
224  */
225  double m_segmAngle; // Ref segm orientation in 0,1 degre
226  int m_segmLength; // length of the reference segment
227 
228  /* variables used in checkLine to test DRC segm to segm:
229  * define the area relative to the ref segment that does not contains any other segment
230  */
235 
241 
244  bool m_drcRun;
246 
247 
249  void setTransitions() override;
250 
254  void updatePointers();
255 
259  void addMarkerToPcb( MARKER_PCB* aMarker );
260 
261  //-----<categorical group tests>-----------------------------------------
262 
272  bool testNetClasses();
273 
282  void testTracks( wxWindow * aActiveWindow, bool aShowProgressBar );
283 
284  void testPad2Pad();
285 
286  void testDrilledHoles();
287 
288  void testUnconnected();
289 
290  void testZones();
291 
292  void testKeepoutAreas();
293 
294  // aTextItem is type BOARD_ITEM* to accept either TEXTE_PCB or TEXTE_MODULE
295  void testCopperTextItem( BOARD_ITEM* aTextItem );
296 
297  void testCopperDrawItem( DRAWSEGMENT* aDrawing );
298 
300 
302  void testDisabledLayers();
303 
307  void testOutline();
308 
309  //-----<single "item" tests>-----------------------------------------
310 
311  bool doNetClass( const std::shared_ptr<NETCLASS>& aNetClass, wxString& msg );
312 
325  bool doPadToPadsDrc( D_PAD* aRefPad, D_PAD** aStart, D_PAD** aEnd, int x_limit );
326 
337  bool doTrackDrc( TRACK* aRefSeg, TRACKS::iterator aStartIt, TRACKS::iterator aEndIt,
338  bool aTestZones );
339 
344 
345  //-----<single tests>----------------------------------------------
346 
352  bool checkClearancePadToPad( D_PAD* aRefPad, D_PAD* aPad );
353 
354 
369  bool checkClearanceSegmToPad( const D_PAD* aPad, int aSegmentWidth, int aMinDist );
370 
371 
384  static bool checkMarginToCircle( wxPoint aCentre, int aRadius, int aLength );
385 
386 
395  bool checkLine( wxPoint aSegStart, wxPoint aSegEnd );
396 
397  //-----</single tests>---------------------------------------------
398 
399 public:
409  int TestZoneToZoneOutline( ZONE_CONTAINER* aZone, bool aCreateMarkers );
410 
415  static void TestFootprints(
416  NETLIST& aNetlist, BOARD* aPCB, EDA_UNITS aUnits, DRC_LIST& aDRCList );
417 
431  void ShowDRCDialog( wxWindow* aParent );
432 
433  int ShowDRCDialog( const TOOL_EVENT& aEvent );
434 
443  void DestroyDRCDialog( int aReason );
444 
450  void RunTests( wxTextCtrl* aMessages = NULL );
451 };
452 
453 
454 #endif // DRC_H
bool m_refillZones
Definition: drc.h:205
bool doNetClass(const std::shared_ptr< NETCLASS > &aNetClass, wxString &msg)
EDA_UNITS
Definition: common.h:72
bool m_doCreateRptFile
Definition: drc.h:204
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
void DestroyDRCDialog(int aReason)
Deletes this ui dialog box and zeros out its pointer to remember the state of the dialog's existence.
DIALOG_DRC_CONTROL * m_drcDialog
Definition: drc.h:239
virtual ~DRC_ITEM_LIST()
Definition: drc.h:171
DRC_ITEM is a holder for a DRC (in Pcbnew) or ERC (in Eeschema) error item.
Definition: drc_item.h:48
void testCopperTextAndGraphics()
int TestZoneToZoneOutline(ZONE_CONTAINER *aZone, bool aCreateMarkers)
Tests whether distance between zones complies with the DRC rules.
int m_ycliplo
Definition: drc.h:232
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
virtual const DRC_ITEM * GetItem(int aIndex)=0
Function GetItem retrieves a DRC_ITEM by pointer.
DRC_LIST m_footprints
list of footprint warnings, as DRC_ITEMs
Definition: drc.h:243
void setTransitions() override
Sets up handlers for various events.
void testKeepoutAreas()
int m_ycliphi
Definition: drc.h:234
void testCopperDrawItem(DRAWSEGMENT *aDrawing)
int m_segmLength
Definition: drc.h:226
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...
void testOutline()
Test that the board outline is contiguous and composed of valid elements.
wxPoint m_padToTestPos
Definition: drc.h:217
bool doTrackDrc(TRACK *aRefSeg, TRACKS::iterator aStartIt, TRACKS::iterator aEndIt, bool aTestZones)
Test the current segment.
void testCopperTextItem(BOARD_ITEM *aTextItem)
Definitions for tracks, vias and zones.
virtual void DeleteItem(int aIndex)=0
Function DeleteAllItems removes and deletes desired item from the list.
BOARD * m_pcb
Definition: drc.h:237
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...
void Reset(RESET_REASON aReason) override
Function Reset() Brings the tool to a known, initial state.
bool m_testFootprints
Definition: drc.h:207
void addMarkerToPcb(MARKER_PCB *aMarker)
Adds a DRC marker to the PCB through the COMMIT mechanism.
bool m_doKeepoutTest
Definition: drc.h:203
bool m_doZonesTest
Definition: drc.h:202
Class that constructs DRC markers of various kinds with messages according to items and error code.
NETLIST stores all of information read from a netlist along with the flags used to update the NETLIST...
Definition: pcb_netlist.h:217
#define NULL
void testZones()
SHAPE_POLY_SET.
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
static bool checkMarginToCircle(wxPoint aCentre, int aRadius, int aLength)
Check the distance from a point to a segment.
bool m_reportAllTrackErrors
Definition: drc.h:206
std::vector< DRC_ITEM * > DRC_LIST
Definition: drc.h:175
bool m_drcRun
Definition: drc.h:244
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.
int m_xcliphi
Definition: drc.h:233
PCB_EDIT_FRAME * m_pcbEditorFrame
The pcb frame editor which owns the board.
Definition: drc.h:236
bool m_doPad2PadTest
Definition: drc.h:200
void testPad2Pad()
bool m_footprintsTested
Definition: drc.h:245
bool checkClearancePadToPad(D_PAD *aRefPad, D_PAD *aPad)
MARKER_PCB * m_currentMarker
Definition: drc.h:211
bool checkClearanceSegmToPad(const D_PAD *aPad, int aSegmentWidth, int aMinDist)
Check the distance from a pad to segment.
wxPoint m_segmEnd
Definition: drc.h:218
SHAPE_POLY_SET m_board_outlines
The board outline including cutouts.
Definition: drc.h:238
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.
wxString m_rptFilename
Definition: drc.h:209
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:160
Design Rule Checker object that performs all the DRC tests.
Definition: drc.h:186
virtual void DeleteAllItems()=0
Function DeleteAllItems removes and deletes all the items in the list.
PCB_EDIT_FRAME is the main frame for Pcbnew.
Provide an abstract interface of a DRC_ITEM* list manager.
Definition: drc.h:138
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:79
DRC_MARKER_FACTORY m_markerFactory
Class that generates markers.
Definition: drc.h:240
DRC_LIST m_unconnected
list of unconnected pads, as DRC_ITEMs
Definition: drc.h:242
void testUnconnected()
void RunTests(wxTextCtrl *aMessages=NULL)
Run all the tests specified with a previous call to SetSettings()
int m_xcliplo
Definition: drc.h:231
bool m_doUnconnectedTest
Definition: drc.h:201
virtual int GetCount()=0
Function GetCount returns the number of items in the list.
double m_segmAngle
Definition: drc.h:225
static void TestFootprints(NETLIST &aNetlist, BOARD *aPCB, EDA_UNITS aUnits, DRC_LIST &aDRCList)
Test the board footprints against a netlist.
void doFootprintOverlappingDrc()
Test for footprint courtyard overlaps.