KiCad PCB EDA Suite
drc_stuff.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 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_STUFF_H
30 #define _DRC_STUFF_H
31 
32 #include <vector>
33 #include <memory>
34 
35 #define OK_DRC 0
36 #define BAD_DRC 1
37 
38 
39 // DRC error codes could be defined by an enum.
40 // however a #define is used because error code value is displayed in DRC messages,
41 // and using #define that shows each numerical value helps for debug.
42 
44 #define DRCE_ 1 // not used yet
45 #define DRCE_UNCONNECTED_ITEMS 2
46 #define DRCE_TRACK_NEAR_THROUGH_HOLE 3
47 #define DRCE_TRACK_NEAR_PAD 4
48 #define DRCE_TRACK_NEAR_VIA 5
49 #define DRCE_VIA_NEAR_VIA 6
50 #define DRCE_VIA_NEAR_TRACK 7
51 #define DRCE_TRACK_ENDS1 8
52 #define DRCE_TRACK_ENDS2 9
53 #define DRCE_TRACK_ENDS3 10
54 #define DRCE_TRACK_ENDS4 11
55 #define DRCE_TRACK_SEGMENTS_TOO_CLOSE 12
56 #define DRCE_TRACKS_CROSSING 13
57 #define DRCE_ENDS_PROBLEM1 14
58 #define DRCE_ENDS_PROBLEM2 15
59 #define DRCE_ENDS_PROBLEM3 16
60 #define DRCE_ENDS_PROBLEM4 17
61 #define DRCE_ENDS_PROBLEM5 18
62 #define DRCE_PAD_NEAR_PAD1 19
63 #define DRCE_VIA_HOLE_BIGGER 20
64 #define DRCE_MICRO_VIA_INCORRECT_LAYER_PAIR 21
65 #define COPPERAREA_INSIDE_COPPERAREA 22
66 #define COPPERAREA_CLOSE_TO_COPPERAREA 23
67 #define DRCE_SUSPICIOUS_NET_FOR_ZONE_OUTLINE 24
68 #define DRCE_HOLE_NEAR_PAD 25
69 #define DRCE_HOLE_NEAR_TRACK 26
70 #define DRCE_TOO_SMALL_TRACK_WIDTH 27
71 #define DRCE_TOO_SMALL_VIA 28
72 #define DRCE_TOO_SMALL_MICROVIA 29
73 #define DRCE_TOO_SMALL_VIA_DRILL 30
74 #define DRCE_TOO_SMALL_MICROVIA_DRILL 31
75 #define DRCE_NETCLASS_TRACKWIDTH 32
76 #define DRCE_NETCLASS_CLEARANCE 33
77 #define DRCE_NETCLASS_VIASIZE 34
78 #define DRCE_NETCLASS_VIADRILLSIZE 35
79 #define DRCE_NETCLASS_uVIASIZE 36
80 #define DRCE_NETCLASS_uVIADRILLSIZE 37
81 #define DRCE_VIA_INSIDE_KEEPOUT 38
82 #define DRCE_TRACK_INSIDE_KEEPOUT 39
83 #define DRCE_PAD_INSIDE_KEEPOUT 40
84 #define DRCE_VIA_INSIDE_TEXT 41
85 #define DRCE_TRACK_INSIDE_TEXT 42
86 #define DRCE_PAD_INSIDE_TEXT 43
87 #define DRCE_OVERLAPPING_FOOTPRINTS 44
88 #define DRCE_MISSING_COURTYARD_IN_FOOTPRINT 45
89 #define DRCE_MALFORMED_COURTYARD_IN_FOOTPRINT 46
90 #define DRCE_MICRO_VIA_NOT_ALLOWED 47
92 #define DRCE_BURIED_VIA_NOT_ALLOWED 48
93 
94 
95 class EDA_DRAW_PANEL;
96 class PCB_EDIT_FRAME;
97 class DIALOG_DRC_CONTROL;
98 class BOARD_ITEM;
99 class BOARD;
100 class D_PAD;
101 class ZONE_CONTAINER;
102 class TRACK;
103 class MARKER_PCB;
104 class DRC_ITEM;
105 class NETCLASS;
106 
107 
116 {
117 public:
118 
123  virtual void DeleteAllItems() = 0;
124 
132  virtual const DRC_ITEM* GetItem( int aIndex ) = 0;
133 
140  virtual void DeleteItem( int aIndex ) = 0;
141 
146  virtual int GetCount() = 0;
147 
148  virtual ~DRC_ITEM_LIST() { }
149 };
150 
151 
152 typedef std::vector<DRC_ITEM*> DRC_LIST;
153 
154 
164 class DRC
165 {
166  friend class DIALOG_DRC_CONTROL;
167 
168 private:
169 
170  // protected or private functions() are lowercase first character.
171 
179 
180  wxString m_rptFilename;
181 
183 
186 
187  /* In DRC functions, many calculations are using coordinates relative
188  * to the position of the segment under test (segm to segm DRC, segm to pad DRC
189  * Next variables store coordinates relative to the start point of this segment
190  */
191  wxPoint m_padToTestPos; // Position of the pad to compare in drc test segm to pad or pad to pad
192  wxPoint m_segmEnd; // End point of the reference segment (start point = (0,0) )
193 
194  /* Some functions are comparing the ref segm to pads or others segments using
195  * coordinates relative to the ref segment considered as the X axis
196  * so we store the ref segment length (the end point relative to these axis)
197  * and the segment orientation (used to rotate other coordinates)
198  */
199  double m_segmAngle; // Ref segm orientation in 0,1 degre
200  int m_segmLength; // length of the reference segment
201 
202  /* variables used in checkLine to test DRC segm to segm:
203  * define the area relative to the ref segment that does not contains any other segment
204  */
209 
213 
215 
216 
222  void updatePointers();
223 
224 
239  MARKER_PCB* fillMarker( const TRACK* aTrack, BOARD_ITEM* aItem, int aErrorCode, MARKER_PCB* fillMe );
240 
241  MARKER_PCB* fillMarker( D_PAD* aPad, BOARD_ITEM* aItem, int aErrorCode, MARKER_PCB* fillMe );
242 
243  MARKER_PCB* fillMarker( ZONE_CONTAINER* aArea, int aErrorCode, MARKER_PCB* fillMe );
244 
245  MARKER_PCB* fillMarker( const wxPoint& aPos, int aErrorCode,
246  const wxString& aMessage, MARKER_PCB* fillMe );
247 
260  MARKER_PCB* fillMarker( const ZONE_CONTAINER* aArea,
261  const wxPoint& aPos,
262  int aErrorCode,
263  MARKER_PCB* fillMe );
264 
270  MARKER_PCB* fillMarker( int aErrorCode, const wxString& aMessage, MARKER_PCB* fillMe );
271 
276  void addMarkerToPcb( MARKER_PCB* aMarker );
277 
278  //-----<categorical group tests>-----------------------------------------
279 
290  bool testNetClasses();
291 
300  void testTracks( wxWindow * aActiveWindow, bool aShowProgressBar );
301 
302  void testPad2Pad();
303 
304  void testUnconnected();
305 
306  void testZones();
307 
308  void testKeepoutAreas();
309 
310  void testTexts();
311 
312  //-----<single "item" tests>-----------------------------------------
313 
314  bool doNetClass( const std::shared_ptr<NETCLASS>& aNetClass, wxString& msg );
315 
325  bool doPadToPadsDrc( D_PAD* aRefPad, D_PAD** aStart, D_PAD** aEnd, int x_limit );
326 
336  bool doTrackDrc( TRACK* aRefSeg, TRACK* aStart, bool doPads = true );
337 
345  bool doTrackKeepoutDrc( TRACK* aRefSeg );
346 
347 
357  bool doEdgeZoneDrc( ZONE_CONTAINER* aArea, int aCornerIndex );
358 
365 
366  //-----<single tests>----------------------------------------------
367 
374  bool checkClearancePadToPad( D_PAD* aRefPad, D_PAD* aPad );
375 
376 
392  bool checkClearanceSegmToPad( const D_PAD* aPad, int aSegmentWidth, int aMinDist );
393 
394 
407  static bool checkMarginToCircle( wxPoint aCentre, int aRadius, int aLength );
408 
409 
418  bool checkLine( wxPoint aSegStart, wxPoint aSegEnd );
419 
420  //-----</single tests>---------------------------------------------
421 
422 public:
423  DRC( PCB_EDIT_FRAME* aPcbWindow );
424 
425  ~DRC();
426 
435  int Drc( TRACK* aRefSeg, TRACK* aList );
436 
447  int Drc( ZONE_CONTAINER* aArea, int aCornerIndex );
448 
457  int DrcBlind( TRACK* aRefSeg, TRACK* aList )
458  {
459  updatePointers();
460 
461  if( ! doTrackDrc( aRefSeg, aList ) )
462  return BAD_DRC;
463 
464  return doTrackKeepoutDrc( aRefSeg ) ? OK_DRC : BAD_DRC;
465  }
466 
467  /*
468  * Tests whether distance between zones complies with the DRC rules.
469  *
470  * @param aZone: zone to compare with other zones, or if NULL then
471  * all zones are compared to all others.
472  * @param aCreateMarkers: if true create DRC markers. False: do not creates anything
473  * @return Errors count
474  */
475  int TestZoneToZoneOutline( ZONE_CONTAINER* aZone, bool aCreateMarkers );
476 
490  void ShowDRCDialog( wxWindow* aParent = NULL );
491 
500  void DestroyDRCDialog( int aReason );
501 
502 
515  void SetSettings( bool aPad2PadTest, bool aUnconnectedTest,
516  bool aZonesTest, bool aKeepoutTest,
517  bool aCourtyardTest, bool aCourtyardMissingTest,
518  const wxString& aReportName, bool aSaveReport )
519  {
520  m_doPad2PadTest = aPad2PadTest;
521  m_doUnconnectedTest = aUnconnectedTest;
522  m_doZonesTest = aZonesTest;
523  m_doKeepoutTest = aKeepoutTest;
524  m_rptFilename = aReportName;
525  m_doCreateRptFile = aSaveReport;
526  m_doFootprintOverlapping = aCourtyardTest;
527  m_doNoCourtyardDefined = aCourtyardMissingTest;
528  }
529 
530 
537  void RunTests( wxTextCtrl* aMessages = NULL );
538 
544  void ListUnconnectedPads();
545 
550  {
551  return m_currentMarker;
552  }
553 
554 };
555 
556 
557 #endif // _DRC_STUFF_H
558 
559 //EOF
bool doNetClass(const std::shared_ptr< NETCLASS > &aNetClass, wxString &msg)
Definition: drc.cpp:505
bool m_doNoCourtyardDefined
Definition: drc_stuff.h:178
bool m_doCreateRptFile
Definition: drc_stuff.h:176
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
#define OK_DRC
Definition: drc_stuff.h:35
void DestroyDRCDialog(int aReason)
Function DestroyDRCDialog deletes this ui dialog box and zeros out its pointer to remember the state ...
Definition: drc.cpp:102
DIALOG_DRC_CONTROL * m_drcDialog
Definition: drc_stuff.h:212
virtual ~DRC_ITEM_LIST()
Definition: drc_stuff.h:148
Class DRC_ITEM is a holder for a DRC (in Pcbnew) or ERC (in Eeschema) error item. ...
MARKER_PCB * fillMarker(const TRACK *aTrack, BOARD_ITEM *aItem, int aErrorCode, MARKER_PCB *fillMe)
Function fillMarker optionally creates a marker and fills it in with information, but does not add it...
int TestZoneToZoneOutline(ZONE_CONTAINER *aZone, bool aCreateMarkers)
Definition: drc.cpp:182
int m_ycliplo
Definition: drc_stuff.h:206
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 DrcBlind(TRACK *aRefSeg, TRACK *aList)
Function DrcBlind tests the current segment and returns the result.
Definition: drc_stuff.h:457
void testKeepoutAreas()
Definition: drc.cpp:783
int m_ycliphi
Definition: drc_stuff.h:208
int m_segmLength
Definition: drc_stuff.h:200
void ListUnconnectedPads()
Function ListUnconnectedPad gathers a list of all the unconnected pads and shows them in the dialog...
Definition: drc.cpp:481
wxPoint m_padToTestPos
Definition: drc_stuff.h:191
void testTexts()
Definition: drc.cpp:837
bool doTrackKeepoutDrc(TRACK *aRefSeg)
Function doTrackKeepoutDrc tests the current segment or via.
Definition: drc.cpp:961
virtual void DeleteItem(int aIndex)=0
Function DeleteAllItems removes and deletes desired item from the list.
BOARD * m_pcb
Definition: drc_stuff.h:211
bool m_doFootprintOverlapping
Definition: drc_stuff.h:177
#define BAD_DRC
Definition: drc_stuff.h:36
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 addMarkerToPcb(MARKER_PCB *aMarker)
Function addMarkerToPcb Adds a DRC marker to the PCB throught the COMMIT mechanism.
Definition: drc.cpp:94
bool m_doKeepoutTest
Definition: drc_stuff.h:175
bool m_doZonesTest
Definition: drc_stuff.h:174
void testZones()
Definition: drc.cpp:745
bool m_abortDRC
Definition: drc_stuff.h:184
bool m_drcInProgress
Definition: drc_stuff.h:185
DRC(PCB_EDIT_FRAME *aPcbWindow)
Definition: drc.cpp:118
void updatePointers()
Function updatePointers is a private helper function used to update needed pointers from the one poin...
Definition: drc.cpp:490
Class NETCLASS handles a collection of nets and the parameters used to route or test these nets...
MARKER_PCB * GetCurrentMarker()
Definition: drc_stuff.h:549
static bool checkMarginToCircle(wxPoint aCentre, int aRadius, int aLength)
Helper function checkMarginToCircle Check the distance from a point to a segment. ...
bool doPadToPadsDrc(D_PAD *aRefPad, D_PAD **aStart, D_PAD **aEnd, int x_limit)
Function doPadToPadsDrc tests the clearance between aRefPad and other pads.
Definition: drc.cpp:1010
int m_xcliphi
Definition: drc_stuff.h:207
PCB_EDIT_FRAME * m_pcbEditorFrame
The pcb frame editor which owns the board.
Definition: drc_stuff.h:210
bool m_doPad2PadTest
Definition: drc_stuff.h:172
void testPad2Pad()
Definition: drc.cpp:620
bool doEdgeZoneDrc(ZONE_CONTAINER *aArea, int aCornerIndex)
Function doEdgeZoneDrc tests a segment in ZONE_CONTAINER * aArea: Test Edge inside other areas Test E...
bool checkClearancePadToPad(D_PAD *aRefPad, D_PAD *aPad)
Function checkClearancePadToPad.
MARKER_PCB * m_currentMarker
Definition: drc_stuff.h:182
bool doFootprintOverlappingDrc()
Function doFootprintOverlappingDrc tests for footprint courtyard overlaps.
Definition: drc.cpp:1144
bool checkClearanceSegmToPad(const D_PAD *aPad, int aSegmentWidth, int aMinDist)
Function checkClearanceSegmToPad check the distance from a pad to segment.
wxPoint m_segmEnd
Definition: drc_stuff.h:192
bool testNetClasses()
Function testNetClasses goes through each NETCLASS and verifies that its clearance, via size, track width, and track clearance are larger than those in board.m_designSettings.
Definition: drc.cpp:597
void testTracks(wxWindow *aActiveWindow, bool aShowProgressBar)
Function testTracks performs the DRC on all tracks.
Definition: drc.cpp:659
void ShowDRCDialog(wxWindow *aParent=NULL)
Function ShowDRCDialog opens a dialog and prompts the user, then if a test run button is clicked...
Definition: drc.cpp:59
wxString m_rptFilename
Definition: drc_stuff.h:180
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
Class DRC is the Design Rule Checker, and performs all the DRC tests.
Definition: drc_stuff.h:164
virtual void DeleteAllItems()=0
Function DeleteAllItems removes and deletes all the items in the list.
Class DRC_ITEM_LIST provides an abstract interface of a DRC_ITEM* list manager.
Definition: drc_stuff.h:115
void SetSettings(bool aPad2PadTest, bool aUnconnectedTest, bool aZonesTest, bool aKeepoutTest, bool aCourtyardTest, bool aCourtyardMissingTest, const wxString &aReportName, bool aSaveReport)
Function SetSettings saves all the UI or test settings and may be called before running the tests...
Definition: drc_stuff.h:515
int Drc(TRACK *aRefSeg, TRACK *aList)
Function Drc tests the current segment and returns the result and displays the error in the status pa...
Definition: drc.cpp:158
bool doTrackDrc(TRACK *aRefSeg, TRACK *aStart, bool doPads=true)
Function DoTrackDrc tests the current segment.
DRC_LIST m_unconnected
list of unconnected pads, as DRC_ITEMs
Definition: drc_stuff.h:214
~DRC()
Definition: drc.cpp:150
void testUnconnected()
Definition: drc.cpp:715
void RunTests(wxTextCtrl *aMessages=NULL)
Function RunTests will actually run all the tests specified with a previous call to SetSettings() ...
Definition: drc.cpp:359
int m_xcliplo
Definition: drc_stuff.h:205
bool m_doUnconnectedTest
Definition: drc_stuff.h:173
virtual int GetCount()=0
Function GetCount returns the number of items in the list.
double m_segmAngle
Definition: drc_stuff.h:199
std::vector< DRC_ITEM * > DRC_LIST
Definition: drc_stuff.h:152