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>
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 
101 
102 class EDA_DRAW_PANEL;
103 class PCB_EDIT_FRAME;
104 class DIALOG_DRC_CONTROL;
105 class BOARD_ITEM;
106 class BOARD;
107 class D_PAD;
108 class ZONE_CONTAINER;
109 class TRACK;
110 class MARKER_PCB;
111 class DRC_ITEM;
112 class NETCLASS;
113 class EDA_TEXT;
114 class DRAWSEGMENT;
115 class wxWindow;
116 class wxString;
117 class wxTextCtrl;
118 
119 
127 {
128 public:
129 
134  virtual void DeleteAllItems() = 0;
135 
143  virtual const DRC_ITEM* GetItem( int aIndex ) = 0;
144 
151  virtual void DeleteItem( int aIndex ) = 0;
152 
157  virtual int GetCount() = 0;
158 
159  virtual ~DRC_ITEM_LIST() { }
160 };
161 
162 
163 typedef std::vector<DRC_ITEM*> DRC_LIST;
164 
165 
174 class DRC
175 {
176  friend class DIALOG_DRC_CONTROL;
177 
178 private:
179 
180  // protected or private functions() are lowercase first character.
188 
189  wxString m_rptFilename;
190 
192 
200 
201  /* In DRC functions, many calculations are using coordinates relative
202  * to the position of the segment under test (segm to segm DRC, segm to pad DRC
203  * Next variables store coordinates relative to the start point of this segment
204  */
205  wxPoint m_padToTestPos; // Position of the pad to compare in drc test segm to pad or pad to pad
206  wxPoint m_segmEnd; // End point of the reference segment (start point = (0,0) )
207 
208  /* Some functions are comparing the ref segm to pads or others segments using
209  * coordinates relative to the ref segment considered as the X axis
210  * so we store the ref segment length (the end point relative to these axis)
211  * and the segment orientation (used to rotate other coordinates)
212  */
213  double m_segmAngle; // Ref segm orientation in 0,1 degre
214  int m_segmLength; // length of the reference segment
215 
216  /* variables used in checkLine to test DRC segm to segm:
217  * define the area relative to the ref segment that does not contains any other segment
218  */
223 
228 
230 
231 
235  void updatePointers();
236 
237 
247  MARKER_PCB* newMarker( TRACK* aTrack, BOARD_ITEM* aConflitItem, const SEG& aConflictSeg,
248  int aErrorCode );
249 
250  MARKER_PCB* newMarker( TRACK* aTrack, ZONE_CONTAINER* aConflictZone, int aErrorCode );
251 
252  MARKER_PCB* newMarker( D_PAD* aPad, BOARD_ITEM* aConflictItem, int aErrorCode );
253 
262  MARKER_PCB* newMarker( const wxPoint& aPos, BOARD_ITEM* aItem, int aErrorCode );
263 
264  MARKER_PCB* newMarker( const wxPoint& aPos, BOARD_ITEM* aItem, BOARD_ITEM* bItem,
265  int aErrorCode );
266 
271  MARKER_PCB* newMarker( int aErrorCode, const wxString& aMessage );
272 
276  void addMarkerToPcb( MARKER_PCB* aMarker );
277 
278  //-----<categorical group tests>-----------------------------------------
279 
289  bool testNetClasses();
290 
299  void testTracks( wxWindow * aActiveWindow, bool aShowProgressBar );
300 
301  void testPad2Pad();
302 
303  void testDrilledHoles();
304 
305  void testUnconnected();
306 
307  void testZones();
308 
309  void testKeepoutAreas();
310 
311  // aTextItem is type BOARD_ITEM* to accept either TEXTE_PCB or TEXTE_MODULE
312  void testCopperTextItem( BOARD_ITEM* aTextItem );
313 
314  void testCopperDrawItem( DRAWSEGMENT* aDrawing );
315 
316  void testCopperTextAndGraphics();
317 
319  void testDisabledLayers();
320 
324  void testOutline();
325 
326  //-----<single "item" tests>-----------------------------------------
327 
328  bool doNetClass( const std::shared_ptr<NETCLASS>& aNetClass, wxString& msg );
329 
342  bool doPadToPadsDrc( D_PAD* aRefPad, D_PAD** aStart, D_PAD** aEnd, int x_limit );
343 
353  bool doTrackDrc( TRACK* aRefSeg, TRACK* aStart, bool doPads = true );
354 
362  bool doTrackKeepoutDrc( TRACK* aRefSeg );
363 
364 
374  bool doEdgeZoneDrc( ZONE_CONTAINER* aArea, int aCornerIndex );
375 
381  bool doFootprintOverlappingDrc();
382 
383  //-----<single tests>----------------------------------------------
384 
390  bool checkClearancePadToPad( D_PAD* aRefPad, D_PAD* aPad );
391 
392 
407  bool checkClearanceSegmToPad( const D_PAD* aPad, int aSegmentWidth, int aMinDist );
408 
409 
422  static bool checkMarginToCircle( wxPoint aCentre, int aRadius, int aLength );
423 
424 
433  bool checkLine( wxPoint aSegStart, wxPoint aSegEnd );
434 
435  //-----</single tests>---------------------------------------------
436 
437 public:
438  DRC( PCB_EDIT_FRAME* aPcbWindow );
439 
440  ~DRC();
441 
452  int DrcOnCreatingTrack( TRACK* aRefSeg, TRACK* aList );
453 
466  int DrcOnCreatingZone( ZONE_CONTAINER* aArea, int aCornerIndex );
467 
477  int TestZoneToZoneOutline( ZONE_CONTAINER* aZone, bool aCreateMarkers );
478 
492  void ShowDRCDialog( wxWindow* aParent = NULL );
493 
502  void DestroyDRCDialog( int aReason );
503 
504 
517  void SetSettings( bool aPad2PadTest, bool aUnconnectedTest,
518  bool aZonesTest, bool aKeepoutTest, bool aRefillZones,
519  bool aReportAllTrackErrors,
520  const wxString& aReportName, bool aSaveReport )
521  {
522  m_doPad2PadTest = aPad2PadTest;
523  m_doUnconnectedTest = aUnconnectedTest;
524  m_doZonesTest = aZonesTest;
525  m_doKeepoutTest = aKeepoutTest;
526  m_rptFilename = aReportName;
527  m_doCreateRptFile = aSaveReport;
528  m_refillZones = aRefillZones;
529  m_drcInLegacyRoutingMode = false;
530  m_reportAllTrackErrors = aReportAllTrackErrors;
531  }
532 
533 
539  void RunTests( wxTextCtrl* aMessages = NULL );
540 
545  void ListUnconnectedPads();
546 
551  {
552  return m_currentMarker;
553  }
554 };
555 
556 
557 #endif // DRC_H
bool m_refillZones
Definition: drc.h:186
bool m_doCreateRptFile
Definition: drc.h:185
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:59
DIALOG_DRC_CONTROL * m_drcDialog
Definition: drc.h:227
virtual ~DRC_ITEM_LIST()
Definition: drc.h:159
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:220
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:222
int m_segmLength
Definition: drc.h:214
wxPoint m_padToTestPos
Definition: drc.h:205
virtual void DeleteItem(int aIndex)=0
Function DeleteAllItems removes and deletes desired item from the list.
BOARD * m_pcb
Definition: drc.h:225
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:184
bool m_doZonesTest
Definition: drc.h:183
Class SHAPE_POLY_SET.
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:550
bool m_reportAllTrackErrors
Definition: drc.h:187
std::vector< DRC_ITEM * > DRC_LIST
Definition: drc.h:163
int m_xcliphi
Definition: drc.h:221
PCB_EDIT_FRAME * m_pcbEditorFrame
The pcb frame editor which owns the board.
Definition: drc.h:224
bool m_doPad2PadTest
Definition: drc.h:181
MARKER_PCB * m_currentMarker
Definition: drc.h:191
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:517
wxPoint m_segmEnd
Definition: drc.h:206
SHAPE_POLY_SET m_board_outlines
The board outline including cutouts.
Definition: drc.h:226
wxString m_rptFilename
Definition: drc.h:189
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:171
Design Rule Checker object that performs all the DRC tests.
Definition: drc.h:174
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:126
DRC_LIST m_unconnected
list of unconnected pads, as DRC_ITEMs
Definition: drc.h:229
bool m_drcInLegacyRoutingMode
in legacy canvas, when creating a track, the drc test must only display the error message...
Definition: drc.h:199
int m_xcliplo
Definition: drc.h:219
bool m_doUnconnectedTest
Definition: drc.h:182
virtual int GetCount()=0
Function GetCount returns the number of items in the list.
double m_segmAngle
Definition: drc.h:213