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 
40 #define DRCE_ 1 // not used yet
41 #define DRCE_UNCONNECTED_PADS 2
42 #define DRCE_TRACK_NEAR_THROUGH_HOLE 3
43 #define DRCE_TRACK_NEAR_PAD 4
44 #define DRCE_TRACK_NEAR_VIA 5
45 #define DRCE_VIA_NEAR_VIA 6
46 #define DRCE_VIA_NEAR_TRACK 7
47 #define DRCE_TRACK_ENDS1 8
48 #define DRCE_TRACK_ENDS2 9
49 #define DRCE_TRACK_ENDS3 10
50 #define DRCE_TRACK_ENDS4 11
51 #define DRCE_TRACK_SEGMENTS_TOO_CLOSE 12
52 #define DRCE_TRACKS_CROSSING 13
53 #define DRCE_ENDS_PROBLEM1 14
54 #define DRCE_ENDS_PROBLEM2 15
55 #define DRCE_ENDS_PROBLEM3 16
56 #define DRCE_ENDS_PROBLEM4 17
57 #define DRCE_ENDS_PROBLEM5 18
58 #define DRCE_PAD_NEAR_PAD1 19
59 #define DRCE_VIA_HOLE_BIGGER 20
60 #define DRCE_MICRO_VIA_INCORRECT_LAYER_PAIR 21
61 #define COPPERAREA_INSIDE_COPPERAREA 22
62 #define COPPERAREA_CLOSE_TO_COPPERAREA 23
63 #define DRCE_SUSPICIOUS_NET_FOR_ZONE_OUTLINE 24
64 #define DRCE_HOLE_NEAR_PAD 25
65 #define DRCE_HOLE_NEAR_TRACK 26
66 #define DRCE_TOO_SMALL_TRACK_WIDTH 27
67 #define DRCE_TOO_SMALL_VIA 28
68 #define DRCE_TOO_SMALL_MICROVIA 29
69 #define DRCE_TOO_SMALL_VIA_DRILL 30
70 #define DRCE_TOO_SMALL_MICROVIA_DRILL 31
71 #define DRCE_NETCLASS_TRACKWIDTH 32
72 #define DRCE_NETCLASS_CLEARANCE 33
73 #define DRCE_NETCLASS_VIASIZE 34
74 #define DRCE_NETCLASS_VIADRILLSIZE 35
75 #define DRCE_NETCLASS_uVIASIZE 36
76 #define DRCE_NETCLASS_uVIADRILLSIZE 37
77 #define DRCE_VIA_INSIDE_KEEPOUT 38
78 #define DRCE_TRACK_INSIDE_KEEPOUT 39
79 #define DRCE_PAD_INSIDE_KEEPOUT 40
80 #define DRCE_VIA_INSIDE_TEXT 41
81 #define DRCE_TRACK_INSIDE_TEXT 42
82 #define DRCE_PAD_INSIDE_TEXT 43
83 #define DRCE_OVERLAPPING_FOOTPRINTS 44
84 #define DRCE_MISSING_COURTYARD_IN_FOOTPRINT 45
85 #define DRCE_MALFORMED_COURTYARD_IN_FOOTPRINT 46
86 
88 
89 class EDA_DRAW_PANEL;
90 class PCB_EDIT_FRAME;
91 class DIALOG_DRC_CONTROL;
92 class BOARD_ITEM;
93 class BOARD;
94 class D_PAD;
95 class ZONE_CONTAINER;
96 class TRACK;
97 class MARKER_PCB;
98 class DRC_ITEM;
99 class NETCLASS;
100 
101 
110 {
111 public:
112 
117  virtual void DeleteAllItems() = 0;
118 
126  virtual const DRC_ITEM* GetItem( int aIndex ) = 0;
127 
134  virtual void DeleteItem( int aIndex ) = 0;
135 
140  virtual int GetCount() = 0;
141 
142  virtual ~DRC_ITEM_LIST() { }
143 };
144 
145 
146 typedef std::vector<DRC_ITEM*> DRC_LIST;
147 
148 
158 class DRC
159 {
160  friend class DIALOG_DRC_CONTROL;
161 
162 private:
163 
164  // protected or private functions() are lowercase first character.
165 
173 
174  wxString m_rptFilename;
175 
177 
180 
181  /* In DRC functions, many calculations are using coordinates relative
182  * to the position of the segment under test (segm to segm DRC, segm to pad DRC
183  * Next variables store coordinates relative to the start point of this segment
184  */
185  wxPoint m_padToTestPos; // Position of the pad to compare in drc test segm to pad or pad to pad
186  wxPoint m_segmEnd; // End point of the reference segment (start point = (0,0) )
187 
188  /* Some functions are comparing the ref segm to pads or others segments using
189  * coordinates relative to the ref segment considered as the X axis
190  * so we store the ref segment length (the end point relative to these axis)
191  * and the segment orientation (used to rotate other coordinates)
192  */
193  double m_segmAngle; // Ref segm orientation in 0,1 degre
194  int m_segmLength; // length of the reference segment
195 
196  /* variables used in checkLine to test DRC segm to segm:
197  * define the area relative to the ref segment that does not contains any other segment
198  */
203 
207 
209 
210 
216  void updatePointers();
217 
218 
233  MARKER_PCB* fillMarker( const TRACK* aTrack, BOARD_ITEM* aItem, int aErrorCode, MARKER_PCB* fillMe );
234 
235  MARKER_PCB* fillMarker( D_PAD* aPad, BOARD_ITEM* aItem, int aErrorCode, MARKER_PCB* fillMe );
236 
237  MARKER_PCB* fillMarker( ZONE_CONTAINER* aArea, int aErrorCode, MARKER_PCB* fillMe );
238 
239  MARKER_PCB* fillMarker( const wxPoint& aPos, int aErrorCode,
240  const wxString& aMessage, MARKER_PCB* fillMe );
241 
254  MARKER_PCB* fillMarker( const ZONE_CONTAINER* aArea,
255  const wxPoint& aPos,
256  int aErrorCode,
257  MARKER_PCB* fillMe );
258 
264  MARKER_PCB* fillMarker( int aErrorCode, const wxString& aMessage, MARKER_PCB* fillMe );
265 
270  void addMarkerToPcb( MARKER_PCB* aMarker );
271 
272  //-----<categorical group tests>-----------------------------------------
273 
284  bool testNetClasses();
285 
294  void testTracks( wxWindow * aActiveWindow, bool aShowProgressBar );
295 
296  void testPad2Pad();
297 
298  void testUnconnected();
299 
300  void testZones();
301 
302  void testKeepoutAreas();
303 
304  void testTexts();
305 
306  //-----<single "item" tests>-----------------------------------------
307 
308  bool doNetClass( std::shared_ptr<NETCLASS> aNetClass, wxString& msg );
309 
319  bool doPadToPadsDrc( D_PAD* aRefPad, D_PAD** aStart, D_PAD** aEnd, int x_limit );
320 
330  bool doTrackDrc( TRACK* aRefSeg, TRACK* aStart, bool doPads = true );
331 
339  bool doTrackKeepoutDrc( TRACK* aRefSeg );
340 
341 
351  bool doEdgeZoneDrc( ZONE_CONTAINER* aArea, int aCornerIndex );
352 
359 
360  //-----<single tests>----------------------------------------------
361 
368  bool checkClearancePadToPad( D_PAD* aRefPad, D_PAD* aPad );
369 
370 
386  bool checkClearanceSegmToPad( const D_PAD* aPad, int aSegmentWidth, int aMinDist );
387 
388 
401  static bool checkMarginToCircle( wxPoint aCentre, int aRadius, int aLength );
402 
403 
412  bool checkLine( wxPoint aSegStart, wxPoint aSegEnd );
413 
414  //-----</single tests>---------------------------------------------
415 
416 public:
417  DRC( PCB_EDIT_FRAME* aPcbWindow );
418 
419  ~DRC();
420 
429  int Drc( TRACK* aRefSeg, TRACK* aList );
430 
441  int Drc( ZONE_CONTAINER* aArea, int aCornerIndex );
442 
451  int DrcBlind( TRACK* aRefSeg, TRACK* aList )
452  {
453  updatePointers();
454 
455  if( ! doTrackDrc( aRefSeg, aList ) )
456  return BAD_DRC;
457 
458  return doTrackKeepoutDrc( aRefSeg ) ? OK_DRC : BAD_DRC;
459  }
460 
461 
475  void ShowDRCDialog( wxWindow* aParent = NULL );
476 
485  void DestroyDRCDialog( int aReason );
486 
487 
500  void SetSettings( bool aPad2PadTest, bool aUnconnectedTest,
501  bool aZonesTest, bool aKeepoutTest,
502  bool aCourtyardTest, bool aCourtyardMissingTest,
503  const wxString& aReportName, bool aSaveReport )
504  {
505  m_doPad2PadTest = aPad2PadTest;
506  m_doUnconnectedTest = aUnconnectedTest;
507  m_doZonesTest = aZonesTest;
508  m_doKeepoutTest = aKeepoutTest;
509  m_rptFilename = aReportName;
510  m_doCreateRptFile = aSaveReport;
511  m_doFootprintOverlapping = aCourtyardTest;
512  m_doNoCourtyardDefined = aCourtyardMissingTest;
513  }
514 
515 
522  void RunTests( wxTextCtrl* aMessages = NULL );
523 
529  void ListUnconnectedPads();
530 
535  {
536  return m_currentMarker;
537  }
538 
539 };
540 
541 
542 #endif // _DRC_STUFF_H
543 
544 //EOF
bool m_doNoCourtyardDefined
Definition: drc_stuff.h:172
bool m_doCreateRptFile
Definition: drc_stuff.h:170
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:78
#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:97
DIALOG_DRC_CONTROL * m_drcDialog
Definition: drc_stuff.h:206
virtual ~DRC_ITEM_LIST()
Definition: drc_stuff.h:142
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 m_ycliplo
Definition: drc_stuff.h:200
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:451
void testKeepoutAreas()
Definition: drc.cpp:632
int m_ycliphi
Definition: drc_stuff.h:202
int m_segmLength
Definition: drc_stuff.h:194
void ListUnconnectedPads()
Function ListUnconnectedPad gathers a list of all the unconnected pads and shows them in the dialog...
Definition: drc.cpp:326
wxPoint m_padToTestPos
Definition: drc_stuff.h:185
void testTexts()
Definition: drc.cpp:681
bool doTrackKeepoutDrc(TRACK *aRefSeg)
Function doTrackKeepoutDrc tests the current segment or via.
Definition: drc.cpp:805
virtual void DeleteItem(int aIndex)=0
Function DeleteAllItems removes and deletes desired item from the list.
BOARD * m_pcb
Definition: drc_stuff.h:205
bool m_doFootprintOverlapping
Definition: drc_stuff.h:171
#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:90
bool m_doKeepoutTest
Definition: drc_stuff.h:169
bool m_doZonesTest
Definition: drc_stuff.h:168
void testZones()
Definition: drc.cpp:594
bool m_abortDRC
Definition: drc_stuff.h:178
bool m_drcInProgress
Definition: drc_stuff.h:179
DRC(PCB_EDIT_FRAME *aPcbWindow)
Definition: drc.cpp:113
void updatePointers()
Function updatePointers is a private helper function used to update needed pointers from the one poin...
Definition: drc.cpp:335
Class NETCLASS handles a collection of nets and the parameters used to route or test these nets...
MARKER_PCB * GetCurrentMarker()
Definition: drc_stuff.h:534
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:852
int m_xcliphi
Definition: drc_stuff.h:201
PCB_EDIT_FRAME * m_pcbEditorFrame
The pcb frame editor which owns the board.
Definition: drc_stuff.h:204
bool m_doPad2PadTest
Definition: drc_stuff.h:166
void testPad2Pad()
Definition: drc.cpp:465
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:176
bool doFootprintOverlappingDrc()
Function doFootprintOverlappingDrc tests for footprint courtyard overlaps.
Definition: drc.cpp:986
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:186
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:442
void testTracks(wxWindow *aActiveWindow, bool aShowProgressBar)
Function testTracks performs the DRC on all tracks.
Definition: drc.cpp:504
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:56
wxString m_rptFilename
Definition: drc_stuff.h:174
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:166
Class DRC is the Design Rule Checker, and performs all the DRC tests.
Definition: drc_stuff.h:158
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:109
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:500
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:153
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:208
~DRC()
Definition: drc.cpp:145
void testUnconnected()
Definition: drc.cpp:559
void RunTests(wxTextCtrl *aMessages=NULL)
Function RunTests will actually run all the tests specified with a previous call to SetSettings() ...
Definition: drc.cpp:192
int m_xcliplo
Definition: drc_stuff.h:199
bool doNetClass(std::shared_ptr< NETCLASS > aNetClass, wxString &msg)
Definition: drc.cpp:350
bool m_doUnconnectedTest
Definition: drc_stuff.h:167
virtual int GetCount()=0
Function GetCount returns the number of items in the list.
double m_segmAngle
Definition: drc_stuff.h:193
std::vector< DRC_ITEM * > DRC_LIST
Definition: drc_stuff.h:146