KiCad PCB EDA Suite
drc.h
Go to the documentation of this file.
1 
5 /*
6  * This program source code file is part of KiCad, a free EDA CAD application.
7  *
8  * Copyright (C) 2007-2016 Dick Hollenbeck, dick@softplc.com
9  * Copyright (C) 2017-2018 KiCad Developers, see change_log.txt for contributors.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, you may find one here:
23  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
24  * or you may search the http://www.gnu.org website for the version 2 license,
25  * or you may write to the Free Software Foundation, Inc.,
26  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
27  */
28 
29 #ifndef DRC_H
30 #define DRC_H
31 
32 #include <vector>
33 #include <memory>
34 #include <geometry/seg.h>
35 
36 #define OK_DRC 0
37 #define BAD_DRC 1
38 
39 
40 // DRC error codes could be defined by an enum.
41 // however a #define is used because error code value is displayed in DRC messages,
42 // and using #define that shows each numerical value helps for debug.
43 
45 #define DRCE_ 1 // not used yet
46 #define DRCE_UNCONNECTED_ITEMS 2
47 #define DRCE_TRACK_NEAR_THROUGH_HOLE 3
48 #define DRCE_TRACK_NEAR_PAD 4
49 #define DRCE_TRACK_NEAR_VIA 5
50 #define DRCE_VIA_NEAR_VIA 6
51 #define DRCE_VIA_NEAR_TRACK 7
52 #define DRCE_TRACK_ENDS1 8
53 #define DRCE_TRACK_ENDS2 9
54 #define DRCE_TRACK_ENDS3 10
55 #define DRCE_TRACK_ENDS4 11
56 #define DRCE_TRACK_SEGMENTS_TOO_CLOSE 12
57 #define DRCE_TRACKS_CROSSING 13
58 #define DRCE_ENDS_PROBLEM1 14
59 #define DRCE_ENDS_PROBLEM2 15
60 #define DRCE_ENDS_PROBLEM3 16
61 #define DRCE_ENDS_PROBLEM4 17
62 #define DRCE_ENDS_PROBLEM5 18
63 #define DRCE_PAD_NEAR_PAD1 19
64 #define DRCE_VIA_HOLE_BIGGER 20
65 #define DRCE_MICRO_VIA_INCORRECT_LAYER_PAIR 21
66 #define DRCE_ZONES_INTERSECT 22
67 #define DRCE_ZONES_TOO_CLOSE 23
68 #define DRCE_SUSPICIOUS_NET_FOR_ZONE_OUTLINE 24
69 #define DRCE_HOLE_NEAR_PAD 25
70 #define DRCE_HOLE_NEAR_TRACK 26
71 #define DRCE_TOO_SMALL_TRACK_WIDTH 27
72 #define DRCE_TOO_SMALL_VIA 28
73 #define DRCE_TOO_SMALL_MICROVIA 29
74 #define DRCE_TOO_SMALL_VIA_DRILL 30
75 #define DRCE_TOO_SMALL_MICROVIA_DRILL 31
76 #define DRCE_NETCLASS_TRACKWIDTH 32
77 #define DRCE_NETCLASS_CLEARANCE 33
78 #define DRCE_NETCLASS_VIASIZE 34
79 #define DRCE_NETCLASS_VIADRILLSIZE 35
80 #define DRCE_NETCLASS_uVIASIZE 36
81 #define DRCE_NETCLASS_uVIADRILLSIZE 37
82 #define DRCE_VIA_INSIDE_KEEPOUT 38
83 #define DRCE_TRACK_INSIDE_KEEPOUT 39
84 #define DRCE_PAD_INSIDE_KEEPOUT 40
85 #define DRCE_TRACK_NEAR_COPPER 41
86 #define DRCE_VIA_NEAR_COPPER 42
87 #define DRCE_PAD_NEAR_COPPER 43
88 #define DRCE_TRACK_NEAR_ZONE 44
89 #define DRCE_OVERLAPPING_FOOTPRINTS 45
90 #define DRCE_MISSING_COURTYARD_IN_FOOTPRINT 46
91 #define DRCE_MALFORMED_COURTYARD_IN_FOOTPRINT 47
92 #define DRCE_MICRO_VIA_NOT_ALLOWED 48
94 #define DRCE_BURIED_VIA_NOT_ALLOWED 49
95 #define DRCE_DISABLED_LAYER_ITEM 50
96 #define DRCE_DRILLED_HOLES_TOO_CLOSE 51
97 
98 
99 class EDA_DRAW_PANEL;
100 class PCB_EDIT_FRAME;
101 class DIALOG_DRC_CONTROL;
102 class BOARD_ITEM;
103 class BOARD;
104 class D_PAD;
105 class ZONE_CONTAINER;
106 class TRACK;
107 class MARKER_PCB;
108 class DRC_ITEM;
109 class NETCLASS;
110 class EDA_TEXT;
111 class DRAWSEGMENT;
112 class wxWindow;
113 class wxString;
114 class wxTextCtrl;
115 
116 
124 {
125 public:
126 
131  virtual void DeleteAllItems() = 0;
132 
140  virtual const DRC_ITEM* GetItem( int aIndex ) = 0;
141 
148  virtual void DeleteItem( int aIndex ) = 0;
149 
154  virtual int GetCount() = 0;
155 
156  virtual ~DRC_ITEM_LIST() { }
157 };
158 
159 
160 typedef std::vector<DRC_ITEM*> DRC_LIST;
161 
162 
171 class DRC
172 {
173  friend class DIALOG_DRC_CONTROL;
174 
175 private:
176 
177  // protected or private functions() are lowercase first character.
185 
186  wxString m_rptFilename;
187 
189 
197 
198  /* In DRC functions, many calculations are using coordinates relative
199  * to the position of the segment under test (segm to segm DRC, segm to pad DRC
200  * Next variables store coordinates relative to the start point of this segment
201  */
202  wxPoint m_padToTestPos; // Position of the pad to compare in drc test segm to pad or pad to pad
203  wxPoint m_segmEnd; // End point of the reference segment (start point = (0,0) )
204 
205  /* Some functions are comparing the ref segm to pads or others segments using
206  * coordinates relative to the ref segment considered as the X axis
207  * so we store the ref segment length (the end point relative to these axis)
208  * and the segment orientation (used to rotate other coordinates)
209  */
210  double m_segmAngle; // Ref segm orientation in 0,1 degre
211  int m_segmLength; // length of the reference segment
212 
213  /* variables used in checkLine to test DRC segm to segm:
214  * define the area relative to the ref segment that does not contains any other segment
215  */
220 
224 
226 
227 
231  void updatePointers();
232 
233 
243  MARKER_PCB* newMarker( TRACK* aTrack, BOARD_ITEM* aConflitItem, const SEG& aConflictSeg,
244  int aErrorCode );
245 
246  MARKER_PCB* newMarker( TRACK* aTrack, ZONE_CONTAINER* aConflictZone, int aErrorCode );
247 
248  MARKER_PCB* newMarker( D_PAD* aPad, BOARD_ITEM* aConflictItem, int aErrorCode );
249 
258  MARKER_PCB* newMarker( const wxPoint& aPos, BOARD_ITEM* aItem, int aErrorCode );
259 
260  MARKER_PCB* newMarker( const wxPoint& aPos, BOARD_ITEM* aItem, BOARD_ITEM* bItem,
261  int aErrorCode );
262 
267  MARKER_PCB* newMarker( int aErrorCode, const wxString& aMessage );
268 
272  void addMarkerToPcb( MARKER_PCB* aMarker );
273 
274  //-----<categorical group tests>-----------------------------------------
275 
285  bool testNetClasses();
286 
295  void testTracks( wxWindow * aActiveWindow, bool aShowProgressBar );
296 
297  void testPad2Pad();
298 
299  void testDrilledHoles();
300 
301  void testUnconnected();
302 
303  void testZones();
304 
305  void testKeepoutAreas();
306 
307  // aTextItem is type BOARD_ITEM* to accept either TEXTE_PCB or TEXTE_MODULE
308  void testCopperTextItem( BOARD_ITEM* aTextItem );
309 
310  void testCopperDrawItem( DRAWSEGMENT* aDrawing );
311 
312  void testCopperTextAndGraphics();
313 
315  void testDisabledLayers();
316 
317  //-----<single "item" tests>-----------------------------------------
318 
319  bool doNetClass( const std::shared_ptr<NETCLASS>& aNetClass, wxString& msg );
320 
333  bool doPadToPadsDrc( D_PAD* aRefPad, D_PAD** aStart, D_PAD** aEnd, int x_limit );
334 
344  bool doTrackDrc( TRACK* aRefSeg, TRACK* aStart, bool doPads = true );
345 
353  bool doTrackKeepoutDrc( TRACK* aRefSeg );
354 
355 
365  bool doEdgeZoneDrc( ZONE_CONTAINER* aArea, int aCornerIndex );
366 
372  bool doFootprintOverlappingDrc();
373 
374  //-----<single tests>----------------------------------------------
375 
381  bool checkClearancePadToPad( D_PAD* aRefPad, D_PAD* aPad );
382 
383 
398  bool checkClearanceSegmToPad( const D_PAD* aPad, int aSegmentWidth, int aMinDist );
399 
400 
413  static bool checkMarginToCircle( wxPoint aCentre, int aRadius, int aLength );
414 
415 
424  bool checkLine( wxPoint aSegStart, wxPoint aSegEnd );
425 
426  //-----</single tests>---------------------------------------------
427 
428 public:
429  DRC( PCB_EDIT_FRAME* aPcbWindow );
430 
431  ~DRC();
432 
443  int DrcOnCreatingTrack( TRACK* aRefSeg, TRACK* aList );
444 
457  int DrcOnCreatingZone( ZONE_CONTAINER* aArea, int aCornerIndex );
458 
468  int TestZoneToZoneOutline( ZONE_CONTAINER* aZone, bool aCreateMarkers );
469 
483  void ShowDRCDialog( wxWindow* aParent = NULL );
484 
493  void DestroyDRCDialog( int aReason );
494 
495 
508  void SetSettings( bool aPad2PadTest, bool aUnconnectedTest,
509  bool aZonesTest, bool aKeepoutTest, bool aRefillZones,
510  bool aReportAllTrackErrors,
511  const wxString& aReportName, bool aSaveReport )
512  {
513  m_doPad2PadTest = aPad2PadTest;
514  m_doUnconnectedTest = aUnconnectedTest;
515  m_doZonesTest = aZonesTest;
516  m_doKeepoutTest = aKeepoutTest;
517  m_rptFilename = aReportName;
518  m_doCreateRptFile = aSaveReport;
519  m_refillZones = aRefillZones;
520  m_drcInLegacyRoutingMode = false;
521  m_reportAllTrackErrors = aReportAllTrackErrors;
522  }
523 
524 
530  void RunTests( wxTextCtrl* aMessages = NULL );
531 
536  void ListUnconnectedPads();
537 
542  {
543  return m_currentMarker;
544  }
545 };
546 
547 
548 #endif // DRC_H
bool m_refillZones
Definition: drc.h:183
bool m_doCreateRptFile
Definition: drc.h:182
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
DIALOG_DRC_CONTROL * m_drcDialog
Definition: drc.h:223
virtual ~DRC_ITEM_LIST()
Definition: drc.h:156
Class DRC_ITEM is a holder for a DRC (in Pcbnew) or ERC (in Eeschema) error item. ...
Definition: drc_item.h:48
int m_ycliplo
Definition: drc.h:217
Class 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.
int m_ycliphi
Definition: drc.h:219
int m_segmLength
Definition: drc.h:211
wxPoint m_padToTestPos
Definition: drc.h:202
virtual void DeleteItem(int aIndex)=0
Function DeleteAllItems removes and deletes desired item from the list.
BOARD * m_pcb
Definition: drc.h:222
Class EDA_TEXT is a mix-in class (via multiple inheritance) that handles texts such as labels...
Definition: eda_text.h:127
bool m_doKeepoutTest
Definition: drc.h:181
bool m_doZonesTest
Definition: drc.h:180
Class NETCLASS handles a collection of nets and the parameters used to route or test these nets...
Definition: netclass.h:55
MARKER_PCB * GetCurrentMarker()
Definition: drc.h:541
bool m_reportAllTrackErrors
Definition: drc.h:184
std::vector< DRC_ITEM * > DRC_LIST
Definition: drc.h:160
int m_xcliphi
Definition: drc.h:218
PCB_EDIT_FRAME * m_pcbEditorFrame
The pcb frame editor which owns the board.
Definition: drc.h:221
bool m_doPad2PadTest
Definition: drc.h:178
MARKER_PCB * m_currentMarker
Definition: drc.h:188
Definition: seg.h:36
void SetSettings(bool aPad2PadTest, bool aUnconnectedTest, bool aZonesTest, bool aKeepoutTest, bool aRefillZones, bool aReportAllTrackErrors, const wxString &aReportName, bool aSaveReport)
Save all the UI or test settings and may be called before running the tests.
Definition: drc.h:508
wxPoint m_segmEnd
Definition: drc.h:203
wxString m_rptFilename
Definition: drc.h:186
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:170
Design Rule Checker object that performs all the DRC tests.
Definition: drc.h:171
virtual void DeleteAllItems()=0
Function DeleteAllItems removes and deletes all the items in the list.
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
Provide an abstract interface of a DRC_ITEM* list manager.
Definition: drc.h:123
DRC_LIST m_unconnected
list of unconnected pads, as DRC_ITEMs
Definition: drc.h:225
bool m_drcInLegacyRoutingMode
in legacy canvas, when creating a track, the drc test must only display the error message...
Definition: drc.h:196
int m_xcliplo
Definition: drc.h:216
bool m_doUnconnectedTest
Definition: drc.h:179
virtual int GetCount()=0
Function GetCount returns the number of items in the list.
double m_segmAngle
Definition: drc.h:210