KiCad PCB EDA Suite
DRC Class Reference

Design Rule Checker object that performs all the DRC tests. More...

#include <drc.h>

Public Member Functions

 DRC (PCB_EDIT_FRAME *aPcbWindow)
 
 ~DRC ()
 
int DrcOnCreatingTrack (TRACK *aRefSeg, TRACK *aList)
 tests the current segment and returns the result and displays the error in the status panel only if one exists. More...
 
int DrcOnCreatingZone (ZONE_CONTAINER *aArea, int aCornerIndex)
 tests the outline segment starting at CornerIndex and returns the result and displays the error in the status panel only if one exists. More...
 
int TestZoneToZoneOutline (ZONE_CONTAINER *aZone, bool aCreateMarkers)
 Tests whether distance between zones complies with the DRC rules. More...
 
void ShowDRCDialog (wxWindow *aParent=NULL)
 Open a dialog and prompts the user, then if a test run button is clicked, runs the test(s) and creates the MARKERS. More...
 
void DestroyDRCDialog (int aReason)
 Deletes this ui dialog box and zeros out its pointer to remember the state of the dialog's existence. More...
 
void SetSettings (bool aPad2PadTest, bool aUnconnectedTest, bool aZonesTest, bool aKeepoutTest, bool aRefillZones, bool aCourtyardTest, bool aCourtyardMissingTest, bool aReportAllTrackErrors, const wxString &aReportName, bool aSaveReport)
 Save all the UI or test settings and may be called before running the tests. More...
 
void RunTests (wxTextCtrl *aMessages=NULL)
 Run all the tests specified with a previous call to SetSettings() More...
 
void ListUnconnectedPads ()
 Gather a list of all the unconnected pads and shows them in the dialog, and optionally prints a report of such. More...
 
MARKER_PCBGetCurrentMarker ()
 

Private Member Functions

void updatePointers ()
 Update needed pointers from the one pointer which is known not to change. More...
 
MARKER_PCBfillMarker (const TRACK *aTrack, BOARD_ITEM *aItem, int aErrorCode, MARKER_PCB *fillMe)
 Creates a marker and fills it in with information but does not add it to the BOARD. More...
 
MARKER_PCBfillMarker (D_PAD *aPad, BOARD_ITEM *aItem, int aErrorCode, MARKER_PCB *fillMe)
 
MARKER_PCBfillMarker (ZONE_CONTAINER *aArea, int aErrorCode, MARKER_PCB *fillMe)
 
MARKER_PCBfillMarker (const wxPoint &aPos, int aErrorCode, const wxString &aMessage, MARKER_PCB *fillMe)
 
MARKER_PCBfillMarker (const ZONE_CONTAINER *aArea, const wxPoint &aPos, int aErrorCode, MARKER_PCB *fillMe)
 Create a marker and fills it in with information but do not add it to the BOARD. More...
 
MARKER_PCBfillMarker (int aErrorCode, const wxString &aMessage, MARKER_PCB *fillMe)
 Fill a MARKER which will report on a generic problem with the board which is not geographically locatable. More...
 
void addMarkerToPcb (MARKER_PCB *aMarker)
 Adds a DRC marker to the PCB through the COMMIT mechanism. More...
 
bool testNetClasses ()
 Go through each NETCLASS and verifies that its clearance, via size, track width, and track clearance are larger than those in board.m_designSettings. More...
 
void testTracks (wxWindow *aActiveWindow, bool aShowProgressBar)
 Perform the DRC on all tracks. More...
 
void testPad2Pad ()
 
void testUnconnected ()
 
void testZones ()
 
void testKeepoutAreas ()
 
void testTexts ()
 
bool doNetClass (const std::shared_ptr< NETCLASS > &aNetClass, wxString &msg)
 
bool doPadToPadsDrc (D_PAD *aRefPad, D_PAD **aStart, D_PAD **aEnd, int x_limit)
 Test the clearance between aRefPad and other pads. More...
 
bool doTrackDrc (TRACK *aRefSeg, TRACK *aStart, bool doPads=true)
 Test the current segment. More...
 
bool doTrackKeepoutDrc (TRACK *aRefSeg)
 Test the current segment or via. More...
 
bool doEdgeZoneDrc (ZONE_CONTAINER *aArea, int aCornerIndex)
 Test a segment in ZONE_CONTAINER * aArea: Test Edge inside other areas Test Edge too close other areas. More...
 
bool doFootprintOverlappingDrc ()
 Test for footprint courtyard overlaps. More...
 
bool checkClearancePadToPad (D_PAD *aRefPad, D_PAD *aPad)
 
bool checkClearanceSegmToPad (const D_PAD *aPad, int aSegmentWidth, int aMinDist)
 Check the distance from a pad to segment. More...
 
bool checkLine (wxPoint aSegStart, wxPoint aSegEnd)
 Function checkLine (helper function used in drc calculations to see if one track is in contact with another track). More...
 

Static Private Member Functions

static bool checkMarginToCircle (wxPoint aCentre, int aRadius, int aLength)
 Check the distance from a point to a segment. More...
 

Private Attributes

bool m_doPad2PadTest
 
bool m_doUnconnectedTest
 
bool m_doZonesTest
 
bool m_doKeepoutTest
 
bool m_doCreateRptFile
 
bool m_doFootprintOverlapping
 
bool m_doNoCourtyardDefined
 
bool m_refillZones
 
bool m_reportAllTrackErrors
 
wxString m_rptFilename
 
MARKER_PCBm_currentMarker
 
bool m_abortDRC
 
bool m_drcInProgress
 
bool m_drcInLegacyRoutingMode
 in legacy canvas, when creating a track, the drc test must only display the error message, and do not create a DRC marker. More...
 
wxPoint m_padToTestPos
 
wxPoint m_segmEnd
 
double m_segmAngle
 
int m_segmLength
 
int m_xcliplo
 
int m_ycliplo
 
int m_xcliphi
 
int m_ycliphi
 
PCB_EDIT_FRAMEm_pcbEditorFrame
 The pcb frame editor which owns the board. More...
 
BOARDm_pcb
 
DIALOG_DRC_CONTROLm_drcDialog
 
DRC_LIST m_unconnected
 list of unconnected pads, as DRC_ITEMs More...
 

Friends

class DIALOG_DRC_CONTROL
 

Detailed Description

Design Rule Checker object that performs all the DRC tests.

The output of the checking goes to the BOARD file in the form of two MARKER lists. Those two lists are displayable in the drc dialog box. And they can optionally be sent to a text file on disk. This class is given access to the windows and the BOARD that it needs via its constructor or public access functions.

Definition at line 162 of file drc.h.

Constructor & Destructor Documentation

DRC::DRC ( PCB_EDIT_FRAME aPcbWindow)

Definition at line 133 of file drc.cpp.

References PCB_BASE_FRAME::GetBoard(), m_abortDRC, m_currentMarker, m_doCreateRptFile, m_doFootprintOverlapping, m_doKeepoutTest, m_doNoCourtyardDefined, m_doPad2PadTest, m_doUnconnectedTest, m_doZonesTest, m_drcDialog, m_drcInLegacyRoutingMode, m_drcInProgress, m_pcb, m_pcbEditorFrame, m_refillZones, m_reportAllTrackErrors, m_segmAngle, m_segmLength, m_xcliphi, m_xcliplo, m_ycliphi, and m_ycliplo.

134 {
135  m_pcbEditorFrame = aPcbWindow;
136  m_pcb = aPcbWindow->GetBoard();
137  m_drcDialog = NULL;
138 
139  // establish initial values for everything:
140  m_drcInLegacyRoutingMode = false;
141  m_doPad2PadTest = true; // enable pad to pad clearance tests
142  m_doUnconnectedTest = true; // enable unconnected tests
143  m_doZonesTest = true; // enable zone to items clearance tests
144  m_doKeepoutTest = true; // enable keepout areas to items clearance tests
145  m_doFootprintOverlapping = true; // enable courtyards areas overlap tests
146  m_doNoCourtyardDefined = true; // enable missing courtyard in footprint warning
147  m_abortDRC = false;
148  m_drcInProgress = false;
149  m_refillZones = false; // Only fill zones if requested by user.
150  m_reportAllTrackErrors = false;
151  m_doCreateRptFile = false;
152 
153  // m_rptFilename set to empty by its constructor
154 
155  m_currentMarker = NULL;
156 
157  m_segmAngle = 0;
158  m_segmLength = 0;
159 
160  m_xcliplo = 0;
161  m_ycliplo = 0;
162  m_xcliphi = 0;
163  m_ycliphi = 0;
164 }
bool m_refillZones
Definition: drc.h:176
bool m_doNoCourtyardDefined
Definition: drc.h:175
bool m_doCreateRptFile
Definition: drc.h:173
DIALOG_DRC_CONTROL * m_drcDialog
Definition: drc.h:219
int m_ycliplo
Definition: drc.h:213
int m_ycliphi
Definition: drc.h:215
int m_segmLength
Definition: drc.h:207
BOARD * GetBoard() const
BOARD * m_pcb
Definition: drc.h:218
bool m_doFootprintOverlapping
Definition: drc.h:174
bool m_doKeepoutTest
Definition: drc.h:172
bool m_doZonesTest
Definition: drc.h:171
bool m_abortDRC
Definition: drc.h:183
bool m_drcInProgress
Definition: drc.h:184
bool m_reportAllTrackErrors
Definition: drc.h:177
int m_xcliphi
Definition: drc.h:214
PCB_EDIT_FRAME * m_pcbEditorFrame
The pcb frame editor which owns the board.
Definition: drc.h:217
bool m_doPad2PadTest
Definition: drc.h:169
MARKER_PCB * m_currentMarker
Definition: drc.h:181
bool m_drcInLegacyRoutingMode
in legacy canvas, when creating a track, the drc test must only display the error message...
Definition: drc.h:192
int m_xcliplo
Definition: drc.h:212
bool m_doUnconnectedTest
Definition: drc.h:170
double m_segmAngle
Definition: drc.h:206
DRC::~DRC ( )

Definition at line 167 of file drc.cpp.

References i, and m_unconnected.

168 {
169  // maybe someday look at pointainer.h <- google for "pointainer.h"
170  for( unsigned i = 0; i<m_unconnected.size(); ++i )
171  delete m_unconnected[i];
172 }
size_t i
Definition: json11.cpp:597
DRC_LIST m_unconnected
list of unconnected pads, as DRC_ITEMs
Definition: drc.h:221

Member Function Documentation

void DRC::addMarkerToPcb ( MARKER_PCB aMarker)
private

Adds a DRC marker to the PCB through the COMMIT mechanism.

Definition at line 98 of file drc.cpp.

References COMMIT::Add(), m_currentMarker, m_drcInLegacyRoutingMode, m_pcbEditorFrame, BOARD_COMMIT::Push(), and EDA_DRAW_FRAME::SetMsgPanel().

Referenced by doFootprintOverlappingDrc(), doNetClass(), testKeepoutAreas(), testPad2Pad(), testTexts(), testTracks(), and testZones().

99 {
100  // In legacy routing mode, do not add markers to the board.
101  // only shows the drc error message
103  {
104  m_pcbEditorFrame->SetMsgPanel( aMarker );
105  delete aMarker;
106  m_currentMarker = nullptr;
107  }
108  else
109  {
110  BOARD_COMMIT commit( m_pcbEditorFrame );
111  commit.Add( aMarker );
112  commit.Push( wxEmptyString, false, false );
113  }
114 }
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Function SetMsgPanel clears the message panel and populates it with the contents of aList...
Definition: draw_frame.cpp:831
PCB_EDIT_FRAME * m_pcbEditorFrame
The pcb frame editor which owns the board.
Definition: drc.h:217
MARKER_PCB * m_currentMarker
Definition: drc.h:181
bool m_drcInLegacyRoutingMode
in legacy canvas, when creating a track, the drc test must only display the error message...
Definition: drc.h:192
bool DRC::checkClearancePadToPad ( D_PAD aRefPad,
D_PAD aPad 
)
private
Parameters
aRefPadThe reference pad to check
aPadAnother pad to check against
Returns
bool - true if clearance between aRefPad and aPad is >= dist_min, else false

Definition at line 784 of file drc_clearance_test_functions.cpp.

References SHAPE_POLY_SET::Append(), ArcTangente(), D_PAD::BuildPadPolygon(), checkClearanceSegmToPad(), SHAPE_POLY_SET::COutline(), SHAPE_LINE_CHAIN::CPoint(), D_PAD::CustomShapeAsPolygonToBoardPosition(), delta, dist, EuclideanNorm(), D_PAD::GetBoundingRadius(), D_PAD::GetClearance(), D_PAD::GetCustomShapeAsPolygon(), D_PAD::GetOrientation(), GetRoundRectCornerCenters(), D_PAD::GetRoundRectCornerRadius(), D_PAD::GetShape(), D_PAD::GetSize(), KiROUND(), m_padToTestPos, m_segmAngle, m_segmEnd, m_segmLength, NORMALIZE_ANGLE_POS(), SHAPE_POLY_SET::OutlineCount(), PAD_SHAPE_CIRCLE, PAD_SHAPE_CUSTOM, PAD_SHAPE_OVAL, PAD_SHAPE_RECT, PAD_SHAPE_ROUNDRECT, PAD_SHAPE_TRAPEZOID, SHAPE_LINE_CHAIN::PointCount(), poly2polyDRC(), RotatePoint(), D_PAD::ShapePos(), wxPoint::x, and wxPoint::y.

Referenced by doPadToPadsDrc().

785 {
786  int dist;
787  double pad_angle;
788 
789  // Get the clearance between the 2 pads. this is the min distance between aRefPad and aPad
790  int dist_min = aRefPad->GetClearance( aPad );
791 
792  // relativePadPos is the aPad shape position relative to the aRefPad shape position
793  wxPoint relativePadPos = aPad->ShapePos() - aRefPad->ShapePos();
794 
795  dist = KiROUND( EuclideanNorm( relativePadPos ) );
796 
797  // Quick test: Clearance is OK if the bounding circles are further away than "dist_min"
798  int delta = dist - aRefPad->GetBoundingRadius() - aPad->GetBoundingRadius();
799 
800  if( delta >= dist_min )
801  return true;
802 
803  /* Here, pads are near and DRC depend on the pad shapes
804  * We must compare distance using a fine shape analysis
805  * Because a circle or oval shape is the easier shape to test, try to have
806  * aRefPad shape type = PAD_SHAPE_CIRCLE or PAD_SHAPE_OVAL.
807  * if aRefPad = TRAP. and aPad = RECT, also swap pads
808  * Swap aRefPad and aPad if needed
809  */
810  bool swap_pads;
811  swap_pads = false;
812 
813  // swap pads to make comparisons easier
814  // Note also a ROUNDRECT pad with a corner radius = r can be considered as
815  // a smaller RECT (size - 2*r) with a clearance increased by r
816  // priority is aRefPad = ROUND then OVAL then RECT/ROUNDRECT then other
817  if( aRefPad->GetShape() != aPad->GetShape() && aRefPad->GetShape() != PAD_SHAPE_CIRCLE )
818  {
819  // pad ref shape is here oval, rect, roundrect, trapezoid or custom
820  switch( aPad->GetShape() )
821  {
822  case PAD_SHAPE_CIRCLE:
823  swap_pads = true;
824  break;
825 
826  case PAD_SHAPE_OVAL:
827  swap_pads = true;
828  break;
829 
830  case PAD_SHAPE_RECT:
831  case PAD_SHAPE_ROUNDRECT:
832  if( aRefPad->GetShape() != PAD_SHAPE_OVAL )
833  swap_pads = true;
834  break;
835 
836  case PAD_SHAPE_TRAPEZOID:
837  case PAD_SHAPE_CUSTOM:
838  break;
839  }
840  }
841 
842  if( swap_pads )
843  {
844  std::swap( aRefPad, aPad );
845  relativePadPos = -relativePadPos;
846  }
847 
848  // corners of aRefPad (used only for rect/roundrect/trap pad)
849  wxPoint polyref[4];
850  // corners of aRefPad (used only for custom pad)
851  SHAPE_POLY_SET polysetref;
852 
853  // corners of aPad (used only for rect/roundrect/trap pad)
854  wxPoint polycompare[4];
855  // corners of aPad (used only custom pad)
856  SHAPE_POLY_SET polysetcompare;
857 
858  /* Because pad exchange, aRefPad shape is PAD_SHAPE_CIRCLE or PAD_SHAPE_OVAL,
859  * if one of the 2 pads was a PAD_SHAPE_CIRCLE or PAD_SHAPE_OVAL.
860  * Therefore, if aRefPad is a PAD_SHAPE_RECT, PAD_SHAPE_ROUNDRECT or a PAD_SHAPE_TRAPEZOID,
861  * aPad is also a PAD_SHAPE_RECT, PAD_SHAPE_ROUNDRECT or a PAD_SHAPE_TRAPEZOID
862  */
863  bool diag = true;
864 
865  switch( aRefPad->GetShape() )
866  {
867  case PAD_SHAPE_CIRCLE:
868 
869  /* One can use checkClearanceSegmToPad to test clearance
870  * aRefPad is like a track segment with a null length and a witdth = GetSize().x
871  */
872  m_segmLength = 0;
873  m_segmAngle = 0;
874 
875  m_segmEnd.x = m_segmEnd.y = 0;
876 
877  m_padToTestPos = relativePadPos;
878  diag = checkClearanceSegmToPad( aPad, aRefPad->GetSize().x, dist_min );
879  break;
880 
881  case PAD_SHAPE_TRAPEZOID:
882  case PAD_SHAPE_ROUNDRECT:
883  case PAD_SHAPE_RECT:
884  case PAD_SHAPE_CUSTOM:
885  // pad_angle = pad orient relative to the aRefPad orient
886  pad_angle = aRefPad->GetOrientation() + aPad->GetOrientation();
887  NORMALIZE_ANGLE_POS( pad_angle );
888 
889  if( aRefPad->GetShape() == PAD_SHAPE_ROUNDRECT )
890  {
891  int padRadius = aRefPad->GetRoundRectCornerRadius();
892  dist_min += padRadius;
893  GetRoundRectCornerCenters( polyref, padRadius, wxPoint( 0, 0 ),
894  aRefPad->GetSize(), aRefPad->GetOrientation() );
895  }
896  else if( aRefPad->GetShape() == PAD_SHAPE_CUSTOM )
897  {
898  polysetref.Append( aRefPad->GetCustomShapeAsPolygon() );
899 
900  // The reference pad can be rotated. calculate the rotated
901  // coordiantes ( note, the ref pad position is the origin of
902  // coordinates for this drc test)
903  aRefPad->CustomShapeAsPolygonToBoardPosition( &polysetref,
904  wxPoint( 0, 0 ), aRefPad->GetOrientation() );
905  }
906  else
907  {
908  // BuildPadPolygon has meaning for rect a trapeziod shapes
909  // and returns the 4 corners
910  aRefPad->BuildPadPolygon( polyref, wxSize( 0, 0 ), aRefPad->GetOrientation() );
911  }
912 
913  switch( aPad->GetShape() )
914  {
915  case PAD_SHAPE_ROUNDRECT:
916  case PAD_SHAPE_RECT:
917  case PAD_SHAPE_TRAPEZOID:
918  case PAD_SHAPE_CUSTOM:
919  if( aPad->GetShape() == PAD_SHAPE_ROUNDRECT )
920  {
921  int padRadius = aPad->GetRoundRectCornerRadius();
922  dist_min += padRadius;
923  GetRoundRectCornerCenters( polycompare, padRadius, relativePadPos,
924  aPad->GetSize(), aPad->GetOrientation() );
925  }
926  else if( aPad->GetShape() == PAD_SHAPE_CUSTOM )
927  {
928  polysetcompare.Append( aPad->GetCustomShapeAsPolygon() );
929 
930  // The pad to compare can be rotated. calculate the rotated
931  // coordinattes ( note, the pad to compare position
932  // is the relativePadPos for this drc test
933  aPad->CustomShapeAsPolygonToBoardPosition( &polysetcompare,
934  relativePadPos, aPad->GetOrientation() );
935  }
936  else
937  {
938  aPad->BuildPadPolygon( polycompare, wxSize( 0, 0 ), aPad->GetOrientation() );
939 
940  // Move aPad shape to relativePadPos
941  for( int ii = 0; ii < 4; ii++ )
942  polycompare[ii] += relativePadPos;
943  }
944  // And now test polygons: We have 3 cases:
945  // one poly is complex and the other is basic (has only 4 corners)
946  // both polys are complex
947  // both polys are basic (have only 4 corners) the most usual case
948  if( polysetref.OutlineCount() && polysetcompare.OutlineCount() == 0)
949  {
950  const SHAPE_LINE_CHAIN& refpoly = polysetref.COutline( 0 );
951  // And now test polygons:
952  if( !poly2polyDRC( (wxPoint*) &refpoly.CPoint( 0 ), refpoly.PointCount(),
953  polycompare, 4, dist_min ) )
954  diag = false;
955  }
956  else if( polysetref.OutlineCount() == 0 && polysetcompare.OutlineCount())
957  {
958  const SHAPE_LINE_CHAIN& cmppoly = polysetcompare.COutline( 0 );
959  // And now test polygons:
960  if( !poly2polyDRC( (wxPoint*) &cmppoly.CPoint( 0 ), cmppoly.PointCount(),
961  polyref, 4, dist_min ) )
962  diag = false;
963  }
964  else if( polysetref.OutlineCount() && polysetcompare.OutlineCount() )
965  {
966  const SHAPE_LINE_CHAIN& refpoly = polysetref.COutline( 0 );
967  const SHAPE_LINE_CHAIN& cmppoly = polysetcompare.COutline( 0 );
968 
969  // And now test polygons:
970  if( !poly2polyDRC( (wxPoint*) &refpoly.CPoint( 0 ), refpoly.PointCount(),
971  (wxPoint*) &cmppoly.CPoint( 0 ), cmppoly.PointCount(), dist_min ) )
972  diag = false;
973  }
974  else if( !poly2polyDRC( polyref, 4, polycompare, 4, dist_min ) )
975  diag = false;
976  break;
977 
978  default:
979  wxLogDebug( wxT( "DRC::checkClearancePadToPad: unexpected pad shape %d" ), aPad->GetShape() );
980  break;
981  }
982  break;
983 
984  case PAD_SHAPE_OVAL: /* an oval pad is like a track segment */
985  {
986  /* Create a track segment with same dimensions as the oval aRefPad
987  * and use checkClearanceSegmToPad function to test aPad to aRefPad clearance
988  */
989  int segm_width;
990  m_segmAngle = aRefPad->GetOrientation(); // Segment orient.
991 
992  if( aRefPad->GetSize().y < aRefPad->GetSize().x ) // Build an horizontal equiv segment
993  {
994  segm_width = aRefPad->GetSize().y;
995  m_segmLength = aRefPad->GetSize().x - aRefPad->GetSize().y;
996  }
997  else // Vertical oval: build an horizontal equiv segment and rotate 90.0 deg
998  {
999  segm_width = aRefPad->GetSize().x;
1000  m_segmLength = aRefPad->GetSize().y - aRefPad->GetSize().x;
1001  m_segmAngle += 900;
1002  }
1003 
1004  /* the start point must be 0,0 and currently relativePadPos
1005  * is relative the center of pad coordinate */
1006  wxPoint segstart;
1007  segstart.x = -m_segmLength / 2; // Start point coordinate of the horizontal equivalent segment
1008 
1009  RotatePoint( &segstart, m_segmAngle ); // actual start point coordinate of the equivalent segment
1010  // Calculate segment end position relative to the segment origin
1011  m_segmEnd.x = -2 * segstart.x;
1012  m_segmEnd.y = -2 * segstart.y;
1013 
1014  // Recalculate the equivalent segment angle in 0,1 degrees
1015  // to prepare a call to checkClearanceSegmToPad()
1017 
1018  // move pad position relative to the segment origin
1019  m_padToTestPos = relativePadPos - segstart;
1020 
1021  // Use segment to pad check to test the second pad:
1022  diag = checkClearanceSegmToPad( aPad, segm_width, dist_min );
1023  break;
1024  }
1025 
1026  default:
1027  wxMessageBox( wxT( "DRC::checkClearancePadToPad: unknown pad shape" ) );
1028  break;
1029  }
1030 
1031  return diag;
1032 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:112
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:106
const SHAPE_POLY_SET & GetCustomShapeAsPolygon() const
Accessor to the custom shape as one polygon.
Definition: class_pad.h:341
void BuildPadPolygon(wxPoint aCoord[4], wxSize aInflateValue, double aRotation) const
Function BuildPadPolygon Has meaning only for polygonal pads (trapezoid and rectangular) Build the Co...
int PointCount() const
Function PointCount()
int GetRoundRectCornerRadius() const
Function GetRoundRectCornerRadius Has meaning only for rounded rect pads.
Definition: class_pad.h:524
static const int dist[10][10]
Definition: dist.cpp:57
int m_segmLength
Definition: drc.h:207
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:216
int OutlineCount() const
Returns the number of outlines in the set
void NORMALIZE_ANGLE_POS(T &Angle)
Definition: trigo.h:241
wxPoint m_padToTestPos
Definition: drc.h:198
PAD_SHAPE_T GetShape() const
Function GetShape.
Definition: class_pad.h:216
static const int delta[8][2]
Definition: solve.cpp:112
void CustomShapeAsPolygonToBoardPosition(SHAPE_POLY_SET *aMergedPolygon, wxPoint aPosition, double aRotation) const
When created, the corners coordinates are relative to the pad position, orientation 0...
double ArcTangente(int dy, int dx)
Definition: trigo.cpp:170
int GetBoundingRadius() const
Function GetBoundingRadius returns the radius of a minimum sized circle which fully encloses this pad...
Definition: class_pad.h:599
Class SHAPE_POLY_SET.
const wxSize & GetSize() const
Definition: class_pad.h:269
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
bool checkClearanceSegmToPad(const D_PAD *aPad, int aSegmentWidth, int aMinDist)
Check the distance from a pad to segment.
wxPoint m_segmEnd
Definition: drc.h:199
Class SHAPE_LINE_CHAIN.
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in tenths of degrees, but soon degrees.
Definition: class_pad.h:382
bool poly2polyDRC(wxPoint *aTref, int aTrefCount, wxPoint *aTcompare, int aTcompareCount, int aDist)
DRC control: these functions make a DRC between pads, tracks and pads versus tracks.
void GetRoundRectCornerCenters(wxPoint aCenters[4], int aRadius, const wxPoint &aPosition, const wxSize &aSize, double aRotation)
Helper function GetRoundRectCornerCenters Has meaning only for rounded rect Returns the centers of th...
int GetClearance(BOARD_CONNECTED_ITEM *aItem=NULL) const override
Function GetClearance returns the clearance in internal units.
Definition: class_pad.cpp:546
wxPoint ShapePos() const
Definition: class_pad.cpp:500
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
double m_segmAngle
Definition: drc.h:206
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline) ...
bool DRC::checkClearanceSegmToPad ( const D_PAD aPad,
int  aSegmentWidth,
int  aMinDist 
)
private

Check the distance from a pad to segment.

This function uses several instance variable not passed in: m_segmLength = length of the segment being tested m_segmAngle = angle of the segment with the X axis; m_segmEnd = end coordinate of the segment m_padToTestPos = position of pad relative to the origin of segment

Parameters
aPadIs the pad involved in the check
aSegmentWidthwidth of the segment to test
aMinDistIs the minimum clearance needed
Returns
true distance >= dist_min, false if distance < dist_min

Definition at line 1040 of file drc_clearance_test_functions.cpp.

References abs, SHAPE_POLY_SET::Append(), D_PAD::BuildPadPolygon(), checkLine(), checkMarginToCircle(), SHAPE_POLY_SET::COutline(), SHAPE_LINE_CHAIN::CPoint(), D_PAD::CustomShapeAsPolygonToBoardPosition(), delta, D_PAD::GetBoundingRadius(), D_PAD::GetCustomShapeAsPolygon(), D_PAD::GetDelta(), D_PAD::GetOrientation(), D_PAD::GetRoundRectCornerRadius(), D_PAD::GetShape(), D_PAD::GetSize(), m_padToTestPos, m_segmAngle, m_segmEnd, m_segmLength, m_xcliphi, m_xcliplo, m_ycliphi, m_ycliplo, min, PAD_SHAPE_CIRCLE, PAD_SHAPE_CUSTOM, PAD_SHAPE_OVAL, PAD_SHAPE_RECT, PAD_SHAPE_ROUNDRECT, PAD_SHAPE_TRAPEZOID, SHAPE_LINE_CHAIN::PointCount(), poly2segmentDRC(), RotatePoint(), wxPoint::x, and wxPoint::y.

Referenced by checkClearancePadToPad(), doTrackDrc(), and testTexts().

1041 {
1042  // Note:
1043  // we are using a horizontal segment for test, because we know here
1044  // only the length and orientation+ of the segment
1045  // Therefore the coordinates of the shape of pad to compare
1046  // must be calculated in a axis system rotated by m_segmAngle
1047  // and centered to the segment origin, before they can be tested
1048  // against the segment
1049  // We are using:
1050  // m_padToTestPos the position of the pad shape in this axis system
1051  // m_segmAngle the axis system rotation
1052 
1053  int segmHalfWidth = aSegmentWidth / 2;
1054  int distToLine = segmHalfWidth + aMinDist;
1055 
1056  wxSize padHalfsize; // half dimension of the pad
1057 
1058  if( aPad->GetShape() == PAD_SHAPE_CUSTOM )
1059  {
1060  // For a custom pad, the pad size has no meaning, we only can
1061  // use the bounding radius
1062  padHalfsize.x = padHalfsize.y = aPad->GetBoundingRadius();
1063  }
1064  else
1065  {
1066  padHalfsize = aPad->GetSize() / 2;
1067  }
1068 
1069  if( aPad->GetShape() == PAD_SHAPE_TRAPEZOID ) // The size is bigger, due to GetDelta() extra size
1070  {
1071  padHalfsize.x += std::abs(aPad->GetDelta().y) / 2; // Remember: GetDelta().y is the GetSize().x change
1072  padHalfsize.y += std::abs(aPad->GetDelta().x) / 2; // Remember: GetDelta().x is the GetSize().y change
1073  }
1074 
1075  if( aPad->GetShape() == PAD_SHAPE_CIRCLE )
1076  {
1077  /* Easy case: just test the distance between segment and pad centre
1078  * calculate pad coordinates in the X,Y axis with X axis = segment to test
1079  */
1081  return checkMarginToCircle( m_padToTestPos, distToLine + padHalfsize.x, m_segmLength );
1082  }
1083 
1084  /* calculate the bounding box of the pad, including the clearance and the segment width
1085  * if the line from 0 to m_segmEnd does not intersect this bounding box,
1086  * the clearance is always OK
1087  * But if intersect, a better analysis of the pad shape must be done.
1088  */
1089  m_xcliplo = m_padToTestPos.x - distToLine - padHalfsize.x;
1090  m_ycliplo = m_padToTestPos.y - distToLine - padHalfsize.y;
1091  m_xcliphi = m_padToTestPos.x + distToLine + padHalfsize.x;
1092  m_ycliphi = m_padToTestPos.y + distToLine + padHalfsize.y;
1093 
1094  wxPoint startPoint( 0, 0 );
1095  wxPoint endPoint = m_segmEnd;
1096 
1097  double orient = aPad->GetOrientation();
1098 
1099  RotatePoint( &startPoint, m_padToTestPos, -orient );
1100  RotatePoint( &endPoint, m_padToTestPos, -orient );
1101 
1102  if( checkLine( startPoint, endPoint ) )
1103  return true;
1104 
1105  /* segment intersects the bounding box. But there is not always a DRC error.
1106  * A fine analysis of the pad shape must be done.
1107  */
1108  switch( aPad->GetShape() )
1109  {
1110  case PAD_SHAPE_CIRCLE:
1111  // This case was already tested, so it cannot be found here.
1112  // it is here just to avoid compil warning, and to remember
1113  // it is already tested.
1114  return false;
1115 
1116  case PAD_SHAPE_OVAL:
1117  {
1118  /* an oval is a complex shape, but is a rectangle and 2 circles
1119  * these 3 basic shapes are more easy to test.
1120  *
1121  * In calculations we are using a vertical or horizontal oval shape
1122  * (i.e. a vertical or horizontal rounded segment)
1123  */
1124  wxPoint cstart = m_padToTestPos;
1125  wxPoint cend = m_padToTestPos; // center of each circle
1126  int delta = std::abs( padHalfsize.y - padHalfsize.x );
1127  int radius = std::min( padHalfsize.y, padHalfsize.x );
1128 
1129  if( padHalfsize.x > padHalfsize.y ) // horizontal equivalent segment
1130  {
1131  cstart.x -= delta;
1132  cend.x += delta;
1133  // Build the rectangular clearance area between the two circles
1134  // the rect starts at cstart.x and ends at cend.x and its height
1135  // is (radius + distToLine)*2
1136  m_xcliplo = cstart.x;
1137  m_ycliplo = cstart.y - radius - distToLine;
1138  m_xcliphi = cend.x;
1139  m_ycliphi = cend.y + radius + distToLine;
1140  }
1141  else // vertical equivalent segment
1142  {
1143  cstart.y -= delta;
1144  cend.y += delta;
1145  // Build the rectangular clearance area between the two circles
1146  // the rect starts at cstart.y and ends at cend.y and its width
1147  // is (radius + distToLine)*2
1148  m_xcliplo = cstart.x - distToLine - radius;
1149  m_ycliplo = cstart.y;
1150  m_xcliphi = cend.x + distToLine + radius;
1151  m_ycliphi = cend.y;
1152  }
1153 
1154  // Test the rectangular clearance area between the two circles (the rounded ends)
1155  // If the segment legth is zero, only check the endpoints, skip the rectangle
1156  if( m_segmLength && !checkLine( startPoint, endPoint ) )
1157  {
1158  return false;
1159  }
1160 
1161  // test the first end
1162  // Calculate the actual position of the circle, given the pad orientation:
1163  RotatePoint( &cstart, m_padToTestPos, orient );
1164 
1165  // Calculate the actual position of the circle in the new X,Y axis, relative
1166  // to the segment:
1167  RotatePoint( &cstart, m_segmAngle );
1168 
1169  if( !checkMarginToCircle( cstart, radius + distToLine, m_segmLength ) )
1170  {
1171  return false;
1172  }
1173 
1174  // test the second end
1175  RotatePoint( &cend, m_padToTestPos, orient );
1176  RotatePoint( &cend, m_segmAngle );
1177 
1178  if( !checkMarginToCircle( cend, radius + distToLine, m_segmLength ) )
1179  {
1180  return false;
1181  }
1182  }
1183  break;
1184 
1185  case PAD_SHAPE_ROUNDRECT:
1186  {
1187  // a round rect is a smaller rect, with a clearance augmented by the corners radius
1188  int r = aPad->GetRoundRectCornerRadius();
1189  padHalfsize.x -= r;
1190  padHalfsize.y -= r;
1191  distToLine += r;
1192  }
1193  // Fall through
1194  case PAD_SHAPE_RECT:
1195  // the area to test is a rounded rectangle.
1196  // this can be done by testing 2 rectangles and 4 circles (the corners)
1197 
1198  // Testing the first rectangle dimx + distToLine, dimy:
1199  m_xcliplo = m_padToTestPos.x - padHalfsize.x - distToLine;
1200  m_ycliplo = m_padToTestPos.y - padHalfsize.y;
1201  m_xcliphi = m_padToTestPos.x + padHalfsize.x + distToLine;
1202  m_ycliphi = m_padToTestPos.y + padHalfsize.y;
1203 
1204  if( !checkLine( startPoint, endPoint ) )
1205  return false;
1206 
1207  // Testing the second rectangle dimx , dimy + distToLine
1208  m_xcliplo = m_padToTestPos.x - padHalfsize.x;
1209  m_ycliplo = m_padToTestPos.y - padHalfsize.y - distToLine;
1210  m_xcliphi = m_padToTestPos.x + padHalfsize.x;
1211  m_ycliphi = m_padToTestPos.y + padHalfsize.y + distToLine;
1212 
1213  if( !checkLine( startPoint, endPoint ) )
1214  return false;
1215 
1216  // testing the 4 circles which are the clearance area of each corner:
1217 
1218  // testing the left top corner of the rectangle
1219  startPoint.x = m_padToTestPos.x - padHalfsize.x;
1220  startPoint.y = m_padToTestPos.y - padHalfsize.y;
1221  RotatePoint( &startPoint, m_padToTestPos, orient );
1222  RotatePoint( &startPoint, m_segmAngle );
1223 
1224  if( !checkMarginToCircle( startPoint, distToLine, m_segmLength ) )
1225  return false;
1226 
1227  // testing the right top corner of the rectangle
1228  startPoint.x = m_padToTestPos.x + padHalfsize.x;
1229  startPoint.y = m_padToTestPos.y - padHalfsize.y;
1230  RotatePoint( &startPoint, m_padToTestPos, orient );
1231  RotatePoint( &startPoint, m_segmAngle );
1232 
1233  if( !checkMarginToCircle( startPoint, distToLine, m_segmLength ) )
1234  return false;
1235 
1236  // testing the left bottom corner of the rectangle
1237  startPoint.x = m_padToTestPos.x - padHalfsize.x;
1238  startPoint.y = m_padToTestPos.y + padHalfsize.y;
1239  RotatePoint( &startPoint, m_padToTestPos, orient );
1240  RotatePoint( &startPoint, m_segmAngle );
1241 
1242  if( !checkMarginToCircle( startPoint, distToLine, m_segmLength ) )
1243  return false;
1244 
1245  // testing the right bottom corner of the rectangle
1246  startPoint.x = m_padToTestPos.x + padHalfsize.x;
1247  startPoint.y = m_padToTestPos.y + padHalfsize.y;
1248  RotatePoint( &startPoint, m_padToTestPos, orient );
1249  RotatePoint( &startPoint, m_segmAngle );
1250 
1251  if( !checkMarginToCircle( startPoint, distToLine, m_segmLength ) )
1252  return false;
1253 
1254  break;
1255 
1256  case PAD_SHAPE_TRAPEZOID:
1257  {
1258  wxPoint poly[4];
1259  aPad->BuildPadPolygon( poly, wxSize( 0, 0 ), orient );
1260 
1261  // Move shape to m_padToTestPos
1262  for( int ii = 0; ii < 4; ii++ )
1263  {
1264  poly[ii] += m_padToTestPos;
1265  RotatePoint( &poly[ii], m_segmAngle );
1266  }
1267 
1268  if( !poly2segmentDRC( poly, 4, wxPoint( 0, 0 ),
1269  wxPoint(m_segmLength,0), distToLine ) )
1270  return false;
1271  }
1272  break;
1273 
1274  case PAD_SHAPE_CUSTOM:
1275  {
1276  SHAPE_POLY_SET polyset;
1277  polyset.Append( aPad->GetCustomShapeAsPolygon() );
1278  // The pad can be rotated. calculate the coordinates
1279  // relatives to the segment being tested
1280  // Note, the pad position relative to the segment origin
1281  // is m_padToTestPos
1282  aPad->CustomShapeAsPolygonToBoardPosition( &polyset,
1283  m_padToTestPos, orient );
1284 
1285  // Rotate all coordinates by m_segmAngle, because the segment orient
1286  // is m_segmAngle
1287  // we are using a horizontal segment for test, because we know here
1288  // only the lenght and orientation+ of the segment
1289  // therefore all coordinates of the pad to test must be rotated by
1290  // m_segmAngle (they are already relative to the segment origin)
1291  aPad->CustomShapeAsPolygonToBoardPosition( &polyset,
1292  wxPoint( 0, 0 ), m_segmAngle );
1293 
1294  const SHAPE_LINE_CHAIN& refpoly = polyset.COutline( 0 );
1295 
1296  if( !poly2segmentDRC( (wxPoint*) &refpoly.CPoint( 0 ),
1297  refpoly.PointCount(),
1298  wxPoint( 0, 0 ), wxPoint(m_segmLength,0),
1299  distToLine ) )
1300  return false;
1301  }
1302  break;
1303  }
1304 
1305  return true;
1306 }
int m_ycliplo
Definition: drc.h:213
const SHAPE_POLY_SET & GetCustomShapeAsPolygon() const
Accessor to the custom shape as one polygon.
Definition: class_pad.h:341
void BuildPadPolygon(wxPoint aCoord[4], wxSize aInflateValue, double aRotation) const
Function BuildPadPolygon Has meaning only for polygonal pads (trapezoid and rectangular) Build the Co...
int PointCount() const
Function PointCount()
int GetRoundRectCornerRadius() const
Function GetRoundRectCornerRadius Has meaning only for rounded rect pads.
Definition: class_pad.h:524
int m_ycliphi
Definition: drc.h:215
bool poly2segmentDRC(wxPoint *aTref, int aTrefCount, wxPoint aSegStart, wxPoint aSegEnd, int aDist)
int m_segmLength
Definition: drc.h:207
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:216
wxPoint m_padToTestPos
Definition: drc.h:198
PAD_SHAPE_T GetShape() const
Function GetShape.
Definition: class_pad.h:216
#define abs(a)
Definition: auxiliary.h:84
static const int delta[8][2]
Definition: solve.cpp:112
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 CustomShapeAsPolygonToBoardPosition(SHAPE_POLY_SET *aMergedPolygon, wxPoint aPosition, double aRotation) const
When created, the corners coordinates are relative to the pad position, orientation 0...
int GetBoundingRadius() const
Function GetBoundingRadius returns the radius of a minimum sized circle which fully encloses this pad...
Definition: class_pad.h:599
Class SHAPE_POLY_SET.
const wxSize & GetSize() const
Definition: class_pad.h:269
static bool checkMarginToCircle(wxPoint aCentre, int aRadius, int aLength)
Check the distance from a point to a segment.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
int m_xcliphi
Definition: drc.h:214
wxPoint m_segmEnd
Definition: drc.h:199
Class SHAPE_LINE_CHAIN.
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in tenths of degrees, but soon degrees.
Definition: class_pad.h:382
const wxSize & GetDelta() const
Definition: class_pad.h:272
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
int m_xcliplo
Definition: drc.h:212
double m_segmAngle
Definition: drc.h:206
#define min(a, b)
Definition: auxiliary.h:85
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline) ...
bool DRC::checkLine ( wxPoint  aSegStart,
wxPoint  aSegEnd 
)
private

Function checkLine (helper function used in drc calculations to see if one track is in contact with another track).

Helper function checkLine Test if a line intersects a bounding box (a rectangle) The rectangle is defined by m_xcliplo, m_ycliplo and m_xcliphi, m_ycliphi return true if the line from aSegStart to aSegEnd is outside the bounding box.

Test if a line intersects a bounding box (a rectangle) The rectangle is defined by m_xcliplo, m_ycliplo and m_xcliphi, m_ycliphi return true if the line from aSegStart to aSegEnd is outside the bounding box

Definition at line 1368 of file drc_clearance_test_functions.cpp.

References m_xcliphi, m_xcliplo, m_ycliphi, m_ycliplo, USCALE(), WHEN_INSIDE, WHEN_OUTSIDE, wxPoint::x, and wxPoint::y.

Referenced by checkClearanceSegmToPad(), and doTrackDrc().

1369 {
1370 #define WHEN_OUTSIDE return true
1371 #define WHEN_INSIDE
1372  int temp;
1373 
1374  if( aSegStart.x > aSegEnd.x )
1375  std::swap( aSegStart, aSegEnd );
1376 
1377  if( (aSegEnd.x <= m_xcliplo) || (aSegStart.x >= m_xcliphi) )
1378  {
1379  WHEN_OUTSIDE;
1380  }
1381 
1382  if( aSegStart.y < aSegEnd.y )
1383  {
1384  if( (aSegEnd.y <= m_ycliplo) || (aSegStart.y >= m_ycliphi) )
1385  {
1386  WHEN_OUTSIDE;
1387  }
1388 
1389  if( aSegStart.y < m_ycliplo )
1390  {
1391  temp = USCALE( (aSegEnd.x - aSegStart.x), (m_ycliplo - aSegStart.y),
1392  (aSegEnd.y - aSegStart.y) );
1393 
1394  if( (aSegStart.x += temp) >= m_xcliphi )
1395  {
1396  WHEN_OUTSIDE;
1397  }
1398 
1399  aSegStart.y = m_ycliplo;
1400  WHEN_INSIDE;
1401  }
1402 
1403  if( aSegEnd.y > m_ycliphi )
1404  {
1405  temp = USCALE( (aSegEnd.x - aSegStart.x), (aSegEnd.y - m_ycliphi),
1406  (aSegEnd.y - aSegStart.y) );
1407 
1408  if( (aSegEnd.x -= temp) <= m_xcliplo )
1409  {
1410  WHEN_OUTSIDE;
1411  }
1412 
1413  aSegEnd.y = m_ycliphi;
1414  WHEN_INSIDE;
1415  }
1416 
1417  if( aSegStart.x < m_xcliplo )
1418  {
1419  temp = USCALE( (aSegEnd.y - aSegStart.y), (m_xcliplo - aSegStart.x),
1420  (aSegEnd.x - aSegStart.x) );
1421  aSegStart.y += temp;
1422  aSegStart.x = m_xcliplo;
1423  WHEN_INSIDE;
1424  }
1425 
1426  if( aSegEnd.x > m_xcliphi )
1427  {
1428  temp = USCALE( (aSegEnd.y - aSegStart.y), (aSegEnd.x - m_xcliphi),
1429  (aSegEnd.x - aSegStart.x) );
1430  aSegEnd.y -= temp;
1431  aSegEnd.x = m_xcliphi;
1432  WHEN_INSIDE;
1433  }
1434  }
1435  else
1436  {
1437  if( (aSegStart.y <= m_ycliplo) || (aSegEnd.y >= m_ycliphi) )
1438  {
1439  WHEN_OUTSIDE;
1440  }
1441 
1442  if( aSegStart.y > m_ycliphi )
1443  {
1444  temp = USCALE( (aSegEnd.x - aSegStart.x), (aSegStart.y - m_ycliphi),
1445  (aSegStart.y - aSegEnd.y) );
1446 
1447  if( (aSegStart.x += temp) >= m_xcliphi )
1448  {
1449  WHEN_OUTSIDE;
1450  }
1451 
1452  aSegStart.y = m_ycliphi;
1453  WHEN_INSIDE;
1454  }
1455 
1456  if( aSegEnd.y < m_ycliplo )
1457  {
1458  temp = USCALE( (aSegEnd.x - aSegStart.x), (m_ycliplo - aSegEnd.y),
1459  (aSegStart.y - aSegEnd.y) );
1460 
1461  if( (aSegEnd.x -= temp) <= m_xcliplo )
1462  {
1463  WHEN_OUTSIDE;
1464  }
1465 
1466  aSegEnd.y = m_ycliplo;
1467  WHEN_INSIDE;
1468  }
1469 
1470  if( aSegStart.x < m_xcliplo )
1471  {
1472  temp = USCALE( (aSegStart.y - aSegEnd.y), (m_xcliplo - aSegStart.x),
1473  (aSegEnd.x - aSegStart.x) );
1474  aSegStart.y -= temp;
1475  aSegStart.x = m_xcliplo;
1476  WHEN_INSIDE;
1477  }
1478 
1479  if( aSegEnd.x > m_xcliphi )
1480  {
1481  temp = USCALE( (aSegStart.y - aSegEnd.y), (aSegEnd.x - m_xcliphi),
1482  (aSegEnd.x - aSegStart.x) );
1483  aSegEnd.y += temp;
1484  aSegEnd.x = m_xcliphi;
1485  WHEN_INSIDE;
1486  }
1487  }
1488 
1489  // Do not divide here to avoid rounding errors
1490  if( ( (aSegEnd.x + aSegStart.x) < m_xcliphi * 2 )
1491  && ( (aSegEnd.x + aSegStart.x) > m_xcliplo * 2) \
1492  && ( (aSegEnd.y + aSegStart.y) < m_ycliphi * 2 )
1493  && ( (aSegEnd.y + aSegStart.y) > m_ycliplo * 2 ) )
1494  {
1495  return false;
1496  }
1497  else
1498  {
1499  return true;
1500  }
1501 }
static int USCALE(unsigned arg, unsigned num, unsigned den)
#define WHEN_OUTSIDE
int m_ycliplo
Definition: drc.h:213
int m_ycliphi
Definition: drc.h:215
int m_xcliphi
Definition: drc.h:214
#define WHEN_INSIDE
int m_xcliplo
Definition: drc.h:212
bool DRC::checkMarginToCircle ( wxPoint  aCentre,
int  aRadius,
int  aLength 
)
staticprivate

Check the distance from a point to a segment.

Helper function checkMarginToCircle Check the distance between a circle (round pad, via or round end of track) and a segment.

The segment is expected starting at 0,0, and on the X axis (used to test DRC between a segment and a round pad, via or round end of a track

Parameters
aCentreThe coordinate of the circle's center
aRadiusA "keep out" radius centered over the circle
aLengthThe length of the segment (i.e. coordinate of end, because it is on the X axis)
Returns
bool - true if distance >= radius, else false when distance < aRadius

the segment is expected starting at 0,0, and on the X axis return true if distance >= aRadius

Definition at line 1315 of file drc_clearance_test_functions.cpp.

References abs, EuclideanNorm(), wxPoint::x, and wxPoint::y.

Referenced by checkClearanceSegmToPad(), and doTrackDrc().

1316 {
1317  if( abs( aCentre.y ) >= aRadius ) // trivial case
1318  return true;
1319 
1320  // Here, distance between aCentre and X axis is < aRadius
1321  if( (aCentre.x > -aRadius ) && ( aCentre.x < (aLength + aRadius) ) )
1322  {
1323  if( (aCentre.x >= 0) && (aCentre.x <= aLength) )
1324  return false; // aCentre is between the starting point and the ending point of the segm
1325 
1326  if( aCentre.x > aLength ) // aCentre is after the ending point
1327  aCentre.x -= aLength; // move aCentre to the starting point of the segment
1328 
1329  if( EuclideanNorm( aCentre ) < aRadius )
1330  // distance between aCentre and the starting point or the ending point is < aRadius
1331  return false;
1332  }
1333 
1334  return true;
1335 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:112
#define abs(a)
Definition: auxiliary.h:84
void DRC::DestroyDRCDialog ( int  aReason)

Deletes this ui dialog box and zeros out its pointer to remember the state of the dialog's existence.

Parameters
aReasonIndication of which button was clicked to cause the destruction. if aReason == wxID_OK, design parameters values which can be entered from the dialog will bbe saved in design parameters list

Definition at line 117 of file drc.cpp.

References DIALOG_DRC_CONTROL::GetRptSettings(), m_doCreateRptFile, m_drcDialog, and m_rptFilename.

Referenced by DIALOG_DRC_CONTROL::OnActivateDlg(), DIALOG_DRC_CONTROL::OnCancelClick(), DIALOG_DRC_CONTROL::OnOkClick(), and DIALOG_PLOT::onRunDRC().

118 {
119  if( m_drcDialog )
120  {
121  if( aReason == wxID_OK )
122  {
123  // if user clicked OK, save his choices in this DRC object.
125  }
126 
127  m_drcDialog->Destroy();
128  m_drcDialog = NULL;
129  }
130 }
bool m_doCreateRptFile
Definition: drc.h:173
DIALOG_DRC_CONTROL * m_drcDialog
Definition: drc.h:219
void GetRptSettings(bool *aEnable, wxString &aFileName)
Definition: dialog_drc.cpp:191
wxString m_rptFilename
Definition: drc.h:179
bool DRC::doEdgeZoneDrc ( ZONE_CONTAINER aArea,
int  aCornerIndex 
)
private

Test a segment in ZONE_CONTAINER * aArea: Test Edge inside other areas Test Edge too close other areas.

Parameters
aAreaThe current area.
aCornerIndexThe first corner of the segment to test.
Returns
bool - false if DRC error or true if OK

Definition at line 684 of file drc_clearance_test_functions.cpp.

References SEG::A, SEG::B, SHAPE_POLY_SET::Contains(), COPPERAREA_CLOSE_TO_COPPERAREA, COPPERAREA_INSIDE_COPPERAREA, fillMarker(), BOARD::GetArea(), BOARD::GetAreaCount(), GetClearanceBetweenSegments(), ZONE_CONTAINER::GetIsKeepout(), ZONE_CONTAINER::GetLayer(), BOARD_CONNECTED_ITEM::GetNetCode(), ZONE_CONTAINER::GetPriority(), SHAPE_POLY_SET::GetRelativeIndices(), ZONE_CONTAINER::GetZoneClearance(), ZONE_CONTAINER::IsOnCopperLayer(), SHAPE_POLY_SET::IterateSegmentsWithHoles(), SHAPE_POLY_SET::VERTEX_INDEX::m_contour, m_currentMarker, m_pcb, SHAPE_POLY_SET::VERTEX_INDEX::m_polygon, SHAPE_POLY_SET::VERTEX_INDEX::m_vertex, max, ZONE_CONTAINER::Outline(), SHAPE_POLY_SET::Polygon(), SHAPE_LINE_CHAIN::Segment(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by DrcOnCreatingZone().

685 {
686  if( !aArea->IsOnCopperLayer() ) // Cannot have a Drc error if not on copper layer
687  return true;
688  // Get polygon, contour and vertex index.
690 
691  // If the vertex does not exist, there is no conflict
692  if( !aArea->Outline()->GetRelativeIndices( aCornerIndex, &index ) )
693  return true;
694 
695  // Retrieve the selected contour
696  SHAPE_LINE_CHAIN contour;
697  contour = aArea->Outline()->Polygon( index.m_polygon )[index.m_contour];
698 
699  // Retrieve the segment that starts at aCornerIndex-th corner.
700  SEG selectedSegment = contour.Segment( index.m_vertex );
701 
702  VECTOR2I start = selectedSegment.A;
703  VECTOR2I end = selectedSegment.B;
704 
705  // iterate through all areas
706  for( int ia2 = 0; ia2 < m_pcb->GetAreaCount(); ia2++ )
707  {
708  ZONE_CONTAINER* area_to_test = m_pcb->GetArea( ia2 );
709  int zone_clearance = std::max( area_to_test->GetZoneClearance(),
710  aArea->GetZoneClearance() );
711 
712  // test for same layer
713  if( area_to_test->GetLayer() != aArea->GetLayer() )
714  continue;
715 
716  // Test for same net
717  if( ( aArea->GetNetCode() == area_to_test->GetNetCode() ) && (aArea->GetNetCode() >= 0) )
718  continue;
719 
720  // test for same priority
721  if( area_to_test->GetPriority() != aArea->GetPriority() )
722  continue;
723 
724  // test for same type
725  if( area_to_test->GetIsKeepout() != aArea->GetIsKeepout() )
726  continue;
727 
728  // For keepout, there is no clearance, so use a minimal value for it
729  // use 1, not 0 as value to avoid some issues in tests
730  if( area_to_test->GetIsKeepout() )
731  zone_clearance = 1;
732 
733  // test for ending line inside area_to_test
734  if( area_to_test->Outline()->Contains( end ) )
735  {
736  // COPPERAREA_COPPERAREA error: corner inside copper area
737  m_currentMarker = fillMarker( aArea, static_cast<wxPoint>( end ),
739  m_currentMarker );
740  return false;
741  }
742 
743  // now test spacing between areas
744  int ax1 = start.x;
745  int ay1 = start.y;
746  int ax2 = end.x;
747  int ay2 = end.y;
748 
749  // Iterate through all edges in the polygon.
751  for( iterator = area_to_test->Outline()->IterateSegmentsWithHoles(); iterator; iterator++ )
752  {
753  SEG segment = *iterator;
754 
755  int bx1 = segment.A.x;
756  int by1 = segment.A.y;
757  int bx2 = segment.B.x;
758  int by2 = segment.B.y;
759 
760  int x, y; // variables containing the intersecting point coordinates
761  int d = GetClearanceBetweenSegments( bx1, by1, bx2, by2,
762  0,
763  ax1, ay1, ax2, ay2,
764  0,
765  zone_clearance,
766  &x, &y );
767 
768  if( d < zone_clearance )
769  {
770  // COPPERAREA_COPPERAREA error : edge intersect or too close
771  m_currentMarker = fillMarker( aArea, wxPoint( x, y ),
773  m_currentMarker );
774  return false;
775  }
776 
777  }
778  }
779 
780  return true;
781 }
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
SEGMENT_ITERATOR IterateSegmentsWithHoles()
Returns an iterator object, for all outlines in the set (with holes)
MARKER_PCB * fillMarker(const TRACK *aTrack, BOARD_ITEM *aItem, int aErrorCode, MARKER_PCB *fillMe)
Creates a marker and fills it in with information but does not add it to the BOARD.
virtual PCB_LAYER_ID GetLayer() const override
Function GetLayer returns the primary layer this item is on.
Definition: class_zone.cpp:175
SHAPE_POLY_SET * Outline()
Definition: class_zone.h:236
bool Contains(const VECTOR2I &aP, int aSubpolyIndex=-1, bool aIgnoreHoles=false) const
Returns true if a given subpolygon contains the point aP.
Struct VERTEX_INDEX.
#define COPPERAREA_INSIDE_COPPERAREA
copper area outlines intersect
Definition: drc.h:65
Class SEGMENT_ITERATOR_TEMPLATE.
int GetClearanceBetweenSegments(int x1i, int y1i, int x1f, int y1f, int w1, int x2i, int y2i, int x2f, int y2f, int w2, int max_cl, int *x, int *y)
BOARD * m_pcb
Definition: drc.h:218
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:602
#define COPPERAREA_CLOSE_TO_COPPERAREA
copper area outlines are too close
Definition: drc.h:66
bool GetRelativeIndices(int aGlobalIdx, VERTEX_INDEX *aRelativeIndices) const
Function GetRelativeIndices.
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:1015
int GetNetCode() const
Function GetNetCode.
MARKER_PCB * m_currentMarker
Definition: drc.h:181
Definition: seg.h:36
SEG Segment(int aIndex)
Function Segment()
bool IsOnCopperLayer() const
Function IsOnCopperLayer.
Definition: class_zone.cpp:181
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:986
#define max(a, b)
Definition: auxiliary.h:86
Class SHAPE_LINE_CHAIN.
VECTOR2I A
Definition: seg.h:46
POLYGON & Polygon(int aIndex)
Returns the aIndex-th subpolygon in the set
unsigned GetPriority() const
Function GetPriority.
Definition: class_zone.h:101
int GetZoneClearance() const
Definition: class_zone.h:192
VECTOR2I B
Definition: seg.h:47
bool DRC::doFootprintOverlappingDrc ( )
private

Test for footprint courtyard overlaps.

Returns
bool - false if DRC error or true if OK

Definition at line 1200 of file drc.cpp.

References addMarkerToPcb(), SHAPE_POLY_SET::Append(), SHAPE_POLY_SET::BooleanIntersection(), DRCE_MALFORMED_COURTYARD_IN_FOOTPRINT, DRCE_MISSING_COURTYARD_IN_FOOTPRINT, DRCE_OVERLAPPING_FOOTPRINTS, fillMarker(), m_currentMarker, m_doFootprintOverlapping, m_doNoCourtyardDefined, BOARD::m_Modules, m_pcb, MODULE::Next(), SHAPE_POLY_SET::OutlineCount(), SHAPE_POLY_SET::PM_FAST, SHAPE_POLY_SET::RemoveAllContours(), SHAPE_POLY_SET::Vertex(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by RunTests().

1201 {
1202  // Detects missing (or malformed) footprint courtyard,
1203  // and for footprint with courtyard, courtyards overlap.
1204  wxString msg;
1205  bool success = true;
1206 
1207  // Update courtyard polygons, and test for missing courtyard definition:
1208  for( MODULE* footprint = m_pcb->m_Modules; footprint; footprint = footprint->Next() )
1209  {
1210  bool is_ok = footprint->BuildPolyCourtyard();
1211 
1212  if( !is_ok && m_doFootprintOverlapping )
1213  {
1214  msg.Printf( _( "footprint \"%s\" has malformed courtyard" ),
1215  footprint->GetReference().GetData() );
1216  m_currentMarker = fillMarker( footprint->GetPosition(),
1218  msg, m_currentMarker );
1220  m_currentMarker = nullptr;
1221  success = false;
1222  }
1223 
1224  if( !m_doNoCourtyardDefined )
1225  continue;
1226 
1227  if( footprint->GetPolyCourtyardFront().OutlineCount() == 0 &&
1228  footprint->GetPolyCourtyardBack().OutlineCount() == 0 &&
1229  is_ok )
1230  {
1231  msg.Printf( _( "footprint \"%s\" has no courtyard defined" ),
1232  footprint->GetReference().GetData() );
1233  m_currentMarker = fillMarker( footprint->GetPosition(),
1235  msg, m_currentMarker );
1237  m_currentMarker = nullptr;
1238  success = false;
1239  }
1240  }
1241 
1243  return success;
1244 
1245  // Now test for overlapping on top layer:
1246  SHAPE_POLY_SET courtyard; // temporary storage of the courtyard of current footprint
1247 
1248  for( MODULE* footprint = m_pcb->m_Modules; footprint; footprint = footprint->Next() )
1249  {
1250  if( footprint->GetPolyCourtyardFront().OutlineCount() == 0 )
1251  continue; // No courtyard defined
1252 
1253  for( MODULE* candidate = footprint->Next(); candidate; candidate = candidate->Next() )
1254  {
1255  if( candidate->GetPolyCourtyardFront().OutlineCount() == 0 )
1256  continue; // No courtyard defined
1257 
1258  courtyard.RemoveAllContours();
1259  courtyard.Append( footprint->GetPolyCourtyardFront() );
1260 
1261  // Build the common area between footprint and the candidate:
1262  courtyard.BooleanIntersection( candidate->GetPolyCourtyardFront(),
1264 
1265  // If no overlap, courtyard is empty (no common area).
1266  // Therefore if a common polygon exists, this is a DRC error
1267  if( courtyard.OutlineCount() )
1268  {
1269  //Overlap between footprint and candidate
1270  msg.Printf( _( "footprints \"%s\" and \"%s\" overlap on front (top) layer" ),
1271  footprint->GetReference().GetData(),
1272  candidate->GetReference().GetData() );
1273  VECTOR2I& pos = courtyard.Vertex( 0, 0, -1 );
1274  wxPoint loc( pos.x, pos.y );
1276  m_currentMarker );
1278  m_currentMarker = nullptr;
1279  success = false;
1280  }
1281  }
1282  }
1283 
1284  // Test for overlapping on bottom layer:
1285  for( MODULE* footprint = m_pcb->m_Modules; footprint; footprint = footprint->Next() )
1286  {
1287  if( footprint->GetPolyCourtyardBack().OutlineCount() == 0 )
1288  continue; // No courtyard defined
1289 
1290  for( MODULE* candidate = footprint->Next(); candidate; candidate = candidate->Next() )
1291  {
1292  if( candidate->GetPolyCourtyardBack().OutlineCount() == 0 )
1293  continue; // No courtyard defined
1294 
1295  courtyard.RemoveAllContours();
1296  courtyard.Append( footprint->GetPolyCourtyardBack() );
1297 
1298  // Build the common area between footprint and the candidate:
1299  courtyard.BooleanIntersection( candidate->GetPolyCourtyardBack(),
1301 
1302  // If no overlap, courtyard is empty (no common area).
1303  // Therefore if a common polygon exists, this is a DRC error
1304  if( courtyard.OutlineCount() )
1305  {
1306  //Overlap between footprint and candidate
1307  msg.Printf( _( "footprints \"%s\" and \"%s\" overlap on back (bottom) layer" ),
1308  footprint->GetReference().GetData(),
1309  candidate->GetReference().GetData() );
1310  VECTOR2I& pos = courtyard.Vertex( 0, 0, -1 );
1311  wxPoint loc( pos.x, pos.y );
1313  m_currentMarker );
1315  m_currentMarker = nullptr;
1316  success = false;
1317  }
1318  }
1319  }
1320 
1321  return success;
1322 }
bool m_doNoCourtyardDefined
Definition: drc.h:175
MARKER_PCB * fillMarker(const TRACK *aTrack, BOARD_ITEM *aItem, int aErrorCode, MARKER_PCB *fillMe)
Creates a marker and fills it in with information but does not add it to the BOARD.
MODULE * Next() const
Definition: class_module.h:121
int OutlineCount() const
Returns the number of outlines in the set
#define DRCE_MALFORMED_COURTYARD_IN_FOOTPRINT
footprint has a courtyard but malformed
Definition: drc.h:89
#define DRCE_MISSING_COURTYARD_IN_FOOTPRINT
footprint has no courtyard defined
Definition: drc.h:88
BOARD * m_pcb
Definition: drc.h:218
bool m_doFootprintOverlapping
Definition: drc.h:174
VECTOR2I & Vertex(int aIndex, int aOutline, int aHole)
Returns the index-th vertex in a given hole outline within a given outline
void addMarkerToPcb(MARKER_PCB *aMarker)
Adds a DRC marker to the PCB through the COMMIT mechanism.
Definition: drc.cpp:98
Class SHAPE_POLY_SET.
#define DRCE_OVERLAPPING_FOOTPRINTS
footprint courtyards overlap
Definition: drc.h:87
void BooleanIntersection(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Performs boolean polyset intersection For aFastMode meaning, see function booleanOp ...
MARKER_PCB * m_currentMarker
Definition: drc.h:181
DLIST< MODULE > m_Modules
Definition: class_board.h:247
void RemoveAllContours()
Removes all outlines & holes (clears) the polygon set.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline) ...
bool DRC::doNetClass ( const std::shared_ptr< NETCLASS > &  aNetClass,
wxString &  msg 
)
private

Definition at line 553 of file drc.cpp.

References addMarkerToPcb(), DRCE_NETCLASS_CLEARANCE, DRCE_NETCLASS_TRACKWIDTH, DRCE_NETCLASS_uVIADRILLSIZE, DRCE_NETCLASS_uVIASIZE, DRCE_NETCLASS_VIADRILLSIZE, DRCE_NETCLASS_VIASIZE, fillMarker(), FmtVal, GetChars(), BOARD::GetDesignSettings(), m_currentMarker, BOARD_DESIGN_SETTINGS::m_MicroViasMinDrill, BOARD_DESIGN_SETTINGS::m_MicroViasMinSize, m_pcb, BOARD_DESIGN_SETTINGS::m_TrackMinWidth, BOARD_DESIGN_SETTINGS::m_ViasMinDrill, and BOARD_DESIGN_SETTINGS::m_ViasMinSize.

Referenced by testNetClasses().

554 {
555  bool ret = true;
556 
558 
559 #define FmtVal( x ) GetChars( StringFromValue( g_UserUnit, x ) )
560 
561 #if 0 // set to 1 when (if...) BOARD_DESIGN_SETTINGS has a m_MinClearance value
562  if( nc->GetClearance() < g.m_MinClearance )
563  {
564  msg.Printf( _( "NETCLASS: \"%s\" has Clearance:%s which is less than global:%s" ),
565  GetChars( nc->GetName() ),
566  FmtVal( nc->GetClearance() ),
567  FmtVal( g.m_TrackClearance )
568  );
569 
571  m_currentMarker = nullptr;
572  ret = false;
573  }
574 #endif
575 
576  if( nc->GetTrackWidth() < g.m_TrackMinWidth )
577  {
578  msg.Printf( _( "NETCLASS: \"%s\" has TrackWidth:%s which is less than global:%s" ),
579  GetChars( nc->GetName() ),
580  FmtVal( nc->GetTrackWidth() ),
582  );
583 
585  m_currentMarker = nullptr;
586  ret = false;
587  }
588 
589  if( nc->GetViaDiameter() < g.m_ViasMinSize )
590  {
591  msg.Printf( _( "NETCLASS: \"%s\" has Via Dia:%s which is less than global:%s" ),
592  GetChars( nc->GetName() ),
593  FmtVal( nc->GetViaDiameter() ),
594  FmtVal( g.m_ViasMinSize )
595  );
596 
598  m_currentMarker = nullptr;
599  ret = false;
600  }
601 
602  if( nc->GetViaDrill() < g.m_ViasMinDrill )
603  {
604  msg.Printf( _( "NETCLASS: \"%s\" has Via Drill:%s which is less than global:%s" ),
605  GetChars( nc->GetName() ),
606  FmtVal( nc->GetViaDrill() ),
608  );
609 
611  m_currentMarker = nullptr;
612  ret = false;
613  }
614 
615  if( nc->GetuViaDiameter() < g.m_MicroViasMinSize )
616  {
617  msg.Printf( _( "NETCLASS: \"%s\" has uVia Dia:%s which is less than global:%s" ),
618  GetChars( nc->GetName() ),
619  FmtVal( nc->GetuViaDiameter() ),
621  );
622 
624  m_currentMarker = nullptr;
625  ret = false;
626  }
627 
628  if( nc->GetuViaDrill() < g.m_MicroViasMinDrill )
629  {
630  msg.Printf( _( "NETCLASS: \"%s\" has uVia Drill:%s which is less than global:%s" ),
631  GetChars( nc->GetName() ),
632  FmtVal( nc->GetuViaDrill() ),
634  );
635 
637  m_currentMarker = nullptr;
638  ret = false;
639  }
640 
641  return ret;
642 }
MARKER_PCB * fillMarker(const TRACK *aTrack, BOARD_ITEM *aItem, int aErrorCode, MARKER_PCB *fillMe)
Creates a marker and fills it in with information but does not add it to the BOARD.
#define DRCE_NETCLASS_TRACKWIDTH
netclass has TrackWidth < board.m_designSettings->m_TrackMinWidth
Definition: drc.h:75
#define DRCE_NETCLASS_CLEARANCE
netclass has Clearance < board.m_designSettings->m_TrackClearance
Definition: drc.h:76
BOARD * m_pcb
Definition: drc.h:218
#define DRCE_NETCLASS_uVIADRILLSIZE
netclass has ViaSize < board.m_designSettings->m_MicroViasMinDrill
Definition: drc.h:80
#define DRCE_NETCLASS_VIASIZE
netclass has ViaSize < board.m_designSettings->m_ViasMinSize
Definition: drc.h:77
void addMarkerToPcb(MARKER_PCB *aMarker)
Adds a DRC marker to the PCB through the COMMIT mechanism.
Definition: drc.cpp:98
int m_TrackMinWidth
track min value for width ((min copper size value
int m_ViasMinSize
vias (not micro vias) min diameter
int m_ViasMinDrill
vias (not micro vias) min drill diameter
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:535
#define DRCE_NETCLASS_VIADRILLSIZE
netclass has ViaDrillSize < board.m_designSettings->m_ViasMinDrill
Definition: drc.h:78
int m_MicroViasMinSize
micro vias (not vias) min diameter
#define FmtVal(x)
MARKER_PCB * m_currentMarker
Definition: drc.h:181
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
int m_MicroViasMinDrill
micro vias (not vias) min drill diameter
#define DRCE_NETCLASS_uVIASIZE
netclass has ViaSize < board.m_designSettings->m_MicroViasMinSize
Definition: drc.h:79
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
bool DRC::doPadToPadsDrc ( D_PAD aRefPad,
D_PAD **  aStart,
D_PAD **  aEnd,
int  x_limit 
)
private

Test the clearance between aRefPad and other pads.

The pad list must be sorted by x coordinate.

Parameters
aRefPadis the pad to test
aStartis the first pad of the list to test against aRefPad
aEndis the end of the list and is not included
x_limitis used to stop the test (i.e. when the current pad pos X in list exceeds this limit, because the list is sorted by X coordinate)

Definition at line 1066 of file drc.cpp.

References LSET::AllCuMask(), checkClearancePadToPad(), DRCE_HOLE_NEAR_PAD, DRCE_PAD_NEAR_PAD1, fillMarker(), D_PAD::GetDrillShape(), D_PAD::GetDrillSize(), D_PAD::GetLayerSet(), BOARD_CONNECTED_ITEM::GetNetCode(), D_PAD::GetOrientation(), D_PAD::GetParent(), D_PAD::GetPosition(), m_currentMarker, m_pcb, PAD_DRILL_SHAPE_CIRCLE, PAD_DRILL_SHAPE_OBLONG, PAD_SHAPE_CIRCLE, PAD_SHAPE_OVAL, D_PAD::PadNameEqual(), D_PAD::SetLayerSet(), D_PAD::SetLocalClearance(), D_PAD::SetOrientation(), D_PAD::SetPosition(), D_PAD::SetShape(), D_PAD::SetSize(), and wxPoint::x.

Referenced by testPad2Pad().

1067 {
1068  const static LSET all_cu = LSET::AllCuMask();
1069 
1070  LSET layerMask = aRefPad->GetLayerSet() & all_cu;
1071 
1072  /* used to test DRC pad to holes: this dummy pad has the size and shape of the hole
1073  * to test pad to pad hole DRC, using the pad to pad DRC test function.
1074  * Therefore, this dummy pad is a circle or an oval.
1075  * A pad must have a parent because some functions expect a non null parent
1076  * to find the parent board, and some other data
1077  */
1078  MODULE dummymodule( m_pcb ); // Creates a dummy parent
1079  D_PAD dummypad( &dummymodule );
1080 
1081  // Ensure the hole is on all copper layers
1082  dummypad.SetLayerSet( all_cu | dummypad.GetLayerSet() );
1083 
1084  // Use the minimal local clearance value for the dummy pad.
1085  // The clearance of the active pad will be used as minimum distance to a hole
1086  // (a value = 0 means use netclass value)
1087  dummypad.SetLocalClearance( 1 );
1088 
1089  for( D_PAD** pad_list = aStart; pad_list<aEnd; ++pad_list )
1090  {
1091  D_PAD* pad = *pad_list;
1092 
1093  if( pad == aRefPad )
1094  continue;
1095 
1096  // We can stop the test when pad->GetPosition().x > x_limit
1097  // because the list is sorted by X values
1098  if( pad->GetPosition().x > x_limit )
1099  break;
1100 
1101  // No problem if pads which are on copper layers are on different copper layers,
1102  // (pads can be only on a technical layer, to build complex pads)
1103  // but their hole (if any ) can create DRC error because they are on all
1104  // copper layers, so we test them
1105  if( ( pad->GetLayerSet() & layerMask ) == 0 &&
1106  ( pad->GetLayerSet() & all_cu ) != 0 &&
1107  ( aRefPad->GetLayerSet() & all_cu ) != 0 )
1108  {
1109  // if holes are in the same location and have the same size and shape,
1110  // this can be accepted
1111  if( pad->GetPosition() == aRefPad->GetPosition()
1112  && pad->GetDrillSize() == aRefPad->GetDrillSize()
1113  && pad->GetDrillShape() == aRefPad->GetDrillShape() )
1114  {
1115  if( aRefPad->GetDrillShape() == PAD_DRILL_SHAPE_CIRCLE )
1116  continue;
1117 
1118  // for oval holes: must also have the same orientation
1119  if( pad->GetOrientation() == aRefPad->GetOrientation() )
1120  continue;
1121  }
1122 
1123  /* Here, we must test clearance between holes and pads
1124  * dummy pad size and shape is adjusted to pad drill size and shape
1125  */
1126  if( pad->GetDrillSize().x )
1127  {
1128  // pad under testing has a hole, test this hole against pad reference
1129  dummypad.SetPosition( pad->GetPosition() );
1130  dummypad.SetSize( pad->GetDrillSize() );
1131  dummypad.SetShape( pad->GetDrillShape() == PAD_DRILL_SHAPE_OBLONG ?
1133  dummypad.SetOrientation( pad->GetOrientation() );
1134 
1135  if( !checkClearancePadToPad( aRefPad, &dummypad ) )
1136  {
1137  // here we have a drc error on pad!
1138  m_currentMarker = fillMarker( pad, aRefPad,
1140  return false;
1141  }
1142  }
1143 
1144  if( aRefPad->GetDrillSize().x ) // pad reference has a hole
1145  {
1146  dummypad.SetPosition( aRefPad->GetPosition() );
1147  dummypad.SetSize( aRefPad->GetDrillSize() );
1148  dummypad.SetShape( aRefPad->GetDrillShape() == PAD_DRILL_SHAPE_OBLONG ?
1150  dummypad.SetOrientation( aRefPad->GetOrientation() );
1151 
1152  if( !checkClearancePadToPad( pad, &dummypad ) )
1153  {
1154  // here we have a drc error on aRefPad!
1155  m_currentMarker = fillMarker( aRefPad, pad,
1157  return false;
1158  }
1159  }
1160 
1161  continue;
1162  }
1163 
1164  // The pad must be in a net (i.e pt_pad->GetNet() != 0 ),
1165  // But no problem if pads have the same netcode (same net)
1166  if( pad->GetNetCode() && ( aRefPad->GetNetCode() == pad->GetNetCode() ) )
1167  continue;
1168 
1169  // if pads are from the same footprint
1170  if( pad->GetParent() == aRefPad->GetParent() )
1171  {
1172  // and have the same pad number ( equivalent pads )
1173 
1174  // one can argue that this 2nd test is not necessary, that any
1175  // two pads from a single module are acceptable. This 2nd test
1176  // should eventually be a configuration option.
1177  if( pad->PadNameEqual( aRefPad ) )
1178  continue;
1179  }
1180 
1181  // if either pad has no drill and is only on technical layers, not a clearance violation
1182  if( ( ( pad->GetLayerSet() & layerMask ) == 0 && !pad->GetDrillSize().x ) ||
1183  ( ( aRefPad->GetLayerSet() & layerMask ) == 0 && !aRefPad->GetDrillSize().x ) )
1184  {
1185  continue;
1186  }
1187 
1188  if( !checkClearancePadToPad( aRefPad, pad ) )
1189  {
1190  // here we have a drc error!
1192  return false;
1193  }
1194  }
1195 
1196  return true;
1197 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:673
bool PadNameEqual(const D_PAD *other) const
Definition: class_pad.h:207
#define DRCE_PAD_NEAR_PAD1
pad too close to pad
Definition: drc.h:62
MARKER_PCB * fillMarker(const TRACK *aTrack, BOARD_ITEM *aItem, int aErrorCode, MARKER_PCB *fillMe)
Creates a marker and fills it in with information but does not add it to the BOARD.
#define DRCE_HOLE_NEAR_PAD
hole too close to pad
Definition: drc.h:68
MODULE * GetParent() const
Definition: class_pad.h:162
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:219
PAD_DRILL_SHAPE_T GetDrillShape() const
Definition: class_pad.h:388
const wxSize & GetDrillSize() const
Definition: class_pad.h:275
BOARD * m_pcb
Definition: drc.h:218
Class LSET is a set of PCB_LAYER_IDs.
LSET GetLayerSet() const override
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
Definition: class_pad.h:402
int GetNetCode() const
Function GetNetCode.
bool checkClearancePadToPad(D_PAD *aRefPad, D_PAD *aPad)
MARKER_PCB * m_currentMarker
Definition: drc.h:181
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in tenths of degrees, but soon degrees.
Definition: class_pad.h:382
const wxPoint GetPosition() const override
Definition: class_pad.h:220
bool DRC::doTrackDrc ( TRACK aRefSeg,
TRACK aStart,
bool  doPads = true 
)
private

Test the current segment.

Parameters
aRefSegThe segment to test
aStartthe first item of track list to test against (usually BOARD::m_Track)
doPadstrue if should do pads test
Returns
bool - true if no problems, else false and m_currentMarker is filled in with the problem information.

Definition at line 138 of file drc_clearance_test_functions.cpp.

References abs, COMMIT::Add(), LSET::AllCuMask(), PNS::angle(), ArcTangente(), B_Cu, checkClearanceSegmToPad(), checkLine(), checkMarginToCircle(), delta, DRCE_BURIED_VIA_NOT_ALLOWED, DRCE_ENDS_PROBLEM1, DRCE_ENDS_PROBLEM2, DRCE_ENDS_PROBLEM3, DRCE_ENDS_PROBLEM4, DRCE_ENDS_PROBLEM5, DRCE_MICRO_VIA_INCORRECT_LAYER_PAIR, DRCE_MICRO_VIA_NOT_ALLOWED, DRCE_TOO_SMALL_MICROVIA, DRCE_TOO_SMALL_MICROVIA_DRILL, DRCE_TOO_SMALL_TRACK_WIDTH, DRCE_TOO_SMALL_VIA, DRCE_TOO_SMALL_VIA_DRILL, DRCE_TRACK_ENDS1, DRCE_TRACK_ENDS2, DRCE_TRACK_ENDS3, DRCE_TRACK_ENDS4, DRCE_TRACK_NEAR_PAD, DRCE_TRACK_NEAR_THROUGH_HOLE, DRCE_TRACK_NEAR_VIA, DRCE_TRACK_SEGMENTS_TOO_CLOSE, DRCE_TRACKS_CROSSING, DRCE_VIA_HOLE_BIGGER, DRCE_VIA_NEAR_TRACK, DRCE_VIA_NEAR_VIA, err, EuclideanNorm(), F_Cu, fillMarker(), TRACK::GetClearance(), BOARD_DESIGN_SETTINGS::GetCopperLayerCount(), BOARD::GetDesignSettings(), D_PAD::GetDrillShape(), D_PAD::GetDrillSize(), VIA::GetDrillValue(), TRACK::GetEnd(), BOARD_ITEM::GetLayerSet(), D_PAD::GetLayerSet(), BOARD_CONNECTED_ITEM::GetNetClass(), BOARD_CONNECTED_ITEM::GetNetCode(), D_PAD::GetOrientation(), BOARD::GetPadCount(), BOARD::GetPads(), D_PAD::GetPosition(), TRACK::GetStart(), VIA::GetViaType(), TRACK::GetWidth(), In1_Cu, VIA::LayerPair(), BOARD_DESIGN_SETTINGS::m_BlindBuriedViaAllowed, m_drcInLegacyRoutingMode, BOARD_DESIGN_SETTINGS::m_MicroViasAllowed, BOARD_DESIGN_SETTINGS::m_MicroViasMinDrill, BOARD_DESIGN_SETTINGS::m_MicroViasMinSize, m_padToTestPos, m_pcb, m_pcbEditorFrame, m_reportAllTrackErrors, m_segmAngle, m_segmEnd, m_segmLength, BOARD_DESIGN_SETTINGS::m_TrackMinWidth, BOARD_DESIGN_SETTINGS::m_ViasMinDrill, BOARD_DESIGN_SETTINGS::m_ViasMinSize, m_xcliphi, m_xcliplo, m_ycliphi, m_ycliplo, TRACK::Next(), PAD_DRILL_SHAPE_OBLONG, PAD_SHAPE_CIRCLE, PAD_SHAPE_OVAL, PCB_VIA_T, BOARD_COMMIT::Push(), RotatePoint(), D_PAD::SetLayerSet(), EDA_DRAW_FRAME::SetMsgPanel(), D_PAD::SetOrientation(), D_PAD::SetPosition(), D_PAD::SetShape(), D_PAD::SetSize(), D_PAD::ShapePos(), EDA_ITEM::Type(), VIA_BLIND_BURIED, VIA_MICROVIA, wxPoint::x, and wxPoint::y.

Referenced by DrcOnCreatingTrack(), and testTracks().

139 {
140  TRACK* track;
141  wxPoint delta; // length on X and Y axis of segments
142  LSET layerMask;
143  int net_code_ref;
144  wxPoint shape_pos;
145 
146  std::vector<MARKER_PCB*> markers;
147 
148  auto commitMarkers = [&]()
149  {
150  // In legacy routing mode, do not add markers to the board.
151  // only shows the drc error message
153  {
154  while( markers.size() > 0 )
155  {
156  m_pcbEditorFrame->SetMsgPanel( markers.back() );
157  delete markers.back();
158  markers.pop_back();
159  }
160  }
161  else
162  {
163  BOARD_COMMIT commit( m_pcbEditorFrame );
164 
165  for( auto marker : markers )
166  commit.Add( marker );
167 
168  commit.Push( wxEmptyString, false, false );
169  }
170  };
171 
172  // Returns false if we should return false from call site, or true to continue
173  auto handleNewMarker = [&]() -> bool
174  {
176  {
177  if( markers.size() > 0 )
178  commitMarkers();
179 
180  return false;
181  }
182  else
183  return true;
184  };
185 
186  NETCLASSPTR netclass = aRefSeg->GetNetClass();
188 
189  /* In order to make some calculations more easier or faster,
190  * pads and tracks coordinates will be made relative to the reference segment origin
191  */
192  wxPoint origin = aRefSeg->GetStart(); // origin will be the origin of other coordinates
193 
194  m_segmEnd = delta = aRefSeg->GetEnd() - origin;
195  m_segmAngle = 0;
196 
197  layerMask = aRefSeg->GetLayerSet();
198  net_code_ref = aRefSeg->GetNetCode();
199 
200  // Phase 0 : Test vias
201  if( aRefSeg->Type() == PCB_VIA_T )
202  {
203  const VIA *refvia = static_cast<const VIA*>( aRefSeg );
204  // test if the via size is smaller than minimum
205  if( refvia->GetViaType() == VIA_MICROVIA )
206  {
207  if( refvia->GetWidth() < dsnSettings.m_MicroViasMinSize )
208  {
209  markers.push_back( fillMarker( refvia, nullptr,
210  DRCE_TOO_SMALL_MICROVIA, nullptr ) );
211  if( !handleNewMarker() )
212  return false;
213  }
214 
215  if( refvia->GetDrillValue() < dsnSettings.m_MicroViasMinDrill )
216  {
217  markers.push_back( fillMarker( refvia, nullptr,
218  DRCE_TOO_SMALL_MICROVIA_DRILL, nullptr ) );
219  if( !handleNewMarker() )
220  return false;
221  }
222  }
223  else
224  {
225  if( refvia->GetWidth() < dsnSettings.m_ViasMinSize )
226  {
227  markers.push_back( fillMarker( refvia, nullptr,
228  DRCE_TOO_SMALL_VIA, nullptr ) );
229  if( !handleNewMarker() )
230  return false;
231  }
232 
233  if( refvia->GetDrillValue() < dsnSettings.m_ViasMinDrill )
234  {
235  markers.push_back( fillMarker( refvia, nullptr,
236  DRCE_TOO_SMALL_VIA_DRILL, nullptr ) );
237  if( !handleNewMarker() )
238  return false;
239  }
240  }
241 
242  // test if via's hole is bigger than its diameter
243  // This test is necessary since the via hole size and width can be modified
244  // and a default via hole can be bigger than some vias sizes
245  if( refvia->GetDrillValue() > refvia->GetWidth() )
246  {
247  markers.push_back( fillMarker( refvia, nullptr,
248  DRCE_VIA_HOLE_BIGGER, nullptr ) );
249  if( !handleNewMarker() )
250  return false;
251  }
252 
253  // test if the type of via is allowed due to design rules
254  if( ( refvia->GetViaType() == VIA_MICROVIA ) &&
255  ( m_pcb->GetDesignSettings().m_MicroViasAllowed == false ) )
256  {
257  markers.push_back( fillMarker( refvia, nullptr,
258  DRCE_MICRO_VIA_NOT_ALLOWED, nullptr ) );
259  if( !handleNewMarker() )
260  return false;
261  }
262 
263  // test if the type of via is allowed due to design rules
264  if( ( refvia->GetViaType() == VIA_BLIND_BURIED ) &&
266  {
267  markers.push_back( fillMarker( refvia, nullptr,
268  DRCE_BURIED_VIA_NOT_ALLOWED, nullptr ) );
269  if( !handleNewMarker() )
270  return false;
271  }
272 
273  // For microvias: test if they are blind vias and only between 2 layers
274  // because they are used for very small drill size and are drill by laser
275  // and **only one layer** can be drilled
276  if( refvia->GetViaType() == VIA_MICROVIA )
277  {
278  PCB_LAYER_ID layer1, layer2;
279  bool err = true;
280 
281  refvia->LayerPair( &layer1, &layer2 );
282 
283  if( layer1 > layer2 )
284  std::swap( layer1, layer2 );
285 
286  if( layer2 == B_Cu && layer1 == m_pcb->GetDesignSettings().GetCopperLayerCount() - 2 )
287  err = false;
288  else if( layer1 == F_Cu && layer2 == In1_Cu )
289  err = false;
290 
291  if( err )
292  {
293  markers.push_back( fillMarker( refvia, nullptr,
295  if( !handleNewMarker() )
296  return false;
297  }
298  }
299 
300  }
301  else // This is a track segment
302  {
303  if( aRefSeg->GetWidth() < dsnSettings.m_TrackMinWidth )
304  {
305  markers.push_back( fillMarker( aRefSeg, nullptr,
306  DRCE_TOO_SMALL_TRACK_WIDTH, nullptr ) );
307  if( !handleNewMarker() )
308  return false;
309  }
310  }
311 
312  // for a non horizontal or vertical segment Compute the segment angle
313  // in tenths of degrees and its length
314  if( delta.x || delta.y )
315  {
316  // Compute the segment angle in 0,1 degrees
317  m_segmAngle = ArcTangente( delta.y, delta.x );
318 
319  // Compute the segment length: we build an equivalent rotated segment,
320  // this segment is horizontal, therefore dx = length
321  RotatePoint( &delta, m_segmAngle ); // delta.x = length, delta.y = 0
322  }
323 
324  m_segmLength = delta.x;
325 
326  /******************************************/
327  /* Phase 1 : test DRC track to pads : */
328  /******************************************/
329 
330  /* Use a dummy pad to test DRC tracks versus holes, for pads not on all copper layers
331  * but having a hole
332  * This dummy pad has the size and shape of the hole
333  * to test tracks to pad hole DRC, using checkClearanceSegmToPad test function.
334  * Therefore, this dummy pad is a circle or an oval.
335  * A pad must have a parent because some functions expect a non null parent
336  * to find the parent board, and some other data
337  */
338  MODULE dummymodule( m_pcb ); // Creates a dummy parent
339  D_PAD dummypad( &dummymodule );
340 
341  dummypad.SetLayerSet( LSET::AllCuMask() ); // Ensure the hole is on all layers
342 
343  // Compute the min distance to pads
344  if( testPads )
345  {
346  unsigned pad_count = m_pcb->GetPadCount();
347 
348  auto pads = m_pcb->GetPads();
349 
350  for( unsigned ii = 0; ii < pad_count; ++ii )
351  {
352  D_PAD* pad = pads[ii];
353 
354  /* No problem if pads are on another layer,
355  * But if a drill hole exists (a pad on a single layer can have a hole!)
356  * we must test the hole
357  */
358  if( !( pad->GetLayerSet() & layerMask ).any() )
359  {
360  /* We must test the pad hole. In order to use the function
361  * checkClearanceSegmToPad(),a pseudo pad is used, with a shape and a
362  * size like the hole
363  */
364  if( pad->GetDrillSize().x == 0 )
365  continue;
366 
367  dummypad.SetSize( pad->GetDrillSize() );
368  dummypad.SetPosition( pad->GetPosition() );
369  dummypad.SetShape( pad->GetDrillShape() == PAD_DRILL_SHAPE_OBLONG ?
371  dummypad.SetOrientation( pad->GetOrientation() );
372 
373  m_padToTestPos = dummypad.GetPosition() - origin;
374 
375  if( !checkClearanceSegmToPad( &dummypad, aRefSeg->GetWidth(),
376  netclass->GetClearance() ) )
377  {
378  markers.push_back( fillMarker( aRefSeg, pad,
379  DRCE_TRACK_NEAR_THROUGH_HOLE, nullptr ) );
380  if( !handleNewMarker() )
381  return false;
382  }
383 
384  continue;
385  }
386 
387  // The pad must be in a net (i.e pt_pad->GetNet() != 0 )
388  // but no problem if the pad netcode is the current netcode (same net)
389  if( pad->GetNetCode() // the pad must be connected
390  && net_code_ref == pad->GetNetCode() ) // the pad net is the same as current net -> Ok
391  continue;
392 
393  // DRC for the pad
394  shape_pos = pad->ShapePos();
395  m_padToTestPos = shape_pos - origin;
396 
397  if( !checkClearanceSegmToPad( pad, aRefSeg->GetWidth(),
398  aRefSeg->GetClearance( pad ) ) )
399  {
400  markers.push_back( fillMarker( aRefSeg, pad,
401  DRCE_TRACK_NEAR_PAD, nullptr ) );
402  if( !handleNewMarker() )
403  return false;
404  }
405  }
406  }
407 
408  /***********************************************/
409  /* Phase 2: test DRC with other track segments */
410  /***********************************************/
411 
412  // At this point the reference segment is the X axis
413 
414  // Test the reference segment with other track segments
415  wxPoint segStartPoint;
416  wxPoint segEndPoint;
417 
418  for( track = aStart; track; track = track->Next() )
419  {
420  // No problem if segments have the same net code:
421  if( net_code_ref == track->GetNetCode() )
422  continue;
423 
424  // No problem if segment are on different layers :
425  if( !( layerMask & track->GetLayerSet() ).any() )
426  continue;
427 
428  // the minimum distance = clearance plus half the reference track
429  // width plus half the other track's width
430  int w_dist = aRefSeg->GetClearance( track );
431  w_dist += ( aRefSeg->GetWidth() + track->GetWidth() ) / 2;
432 
433  // Due to many double to int conversions during calculations, which
434  // create rounding issues,
435  // the exact clearance margin cannot be really known.
436  // To avoid false bad DRC detection due to these rounding issues,
437  // slightly decrease the w_dist (remove one nanometer is enough !)
438  w_dist -= 1;
439 
440  // If the reference segment is a via, we test it here
441  if( aRefSeg->Type() == PCB_VIA_T )
442  {
443  delta = track->GetEnd() - track->GetStart();
444  segStartPoint = aRefSeg->GetStart() - track->GetStart();
445 
446  if( track->Type() == PCB_VIA_T )
447  {
448  // Test distance between two vias, i.e. two circles, trivial case
449  if( EuclideanNorm( segStartPoint ) < w_dist )
450  {
451  markers.push_back( fillMarker( aRefSeg, track,
452  DRCE_VIA_NEAR_VIA, nullptr ) );
453  if( !handleNewMarker() )
454  return false;
455  }
456  }
457  else // test via to segment
458  {
459  // Compute l'angle du segment a tester;
460  double angle = ArcTangente( delta.y, delta.x );
461 
462  // Compute new coordinates ( the segment become horizontal)
463  RotatePoint( &delta, angle );
464  RotatePoint( &segStartPoint, angle );
465 
466  if( !checkMarginToCircle( segStartPoint, w_dist, delta.x ) )
467  {
468  markers.push_back( fillMarker( track, aRefSeg,
469  DRCE_VIA_NEAR_TRACK, nullptr ) );
470  if( !handleNewMarker() )
471  return false;
472  }
473  }
474 
475  continue;
476  }
477 
478  /* We compute segStartPoint, segEndPoint = starting and ending point coordinates for
479  * the segment to test in the new axis : the new X axis is the
480  * reference segment. We must translate and rotate the segment to test
481  */
482  segStartPoint = track->GetStart() - origin;
483  segEndPoint = track->GetEnd() - origin;
484  RotatePoint( &segStartPoint, m_segmAngle );
485  RotatePoint( &segEndPoint, m_segmAngle );
486 
487  if( track->Type() == PCB_VIA_T )
488  {
489  if( checkMarginToCircle( segStartPoint, w_dist, m_segmLength ) )
490  continue;
491 
492  markers.push_back( fillMarker( aRefSeg, track,
493  DRCE_TRACK_NEAR_VIA, nullptr ) );
494  if( !handleNewMarker() )
495  return false;
496  }
497 
498  /* We have changed axis:
499  * the reference segment is Horizontal.
500  * 3 cases : the segment to test can be parallel, perpendicular or have another direction
501  */
502  if( segStartPoint.y == segEndPoint.y ) // parallel segments
503  {
504  if( abs( segStartPoint.y ) >= w_dist )
505  continue;
506 
507  // Ensure segStartPoint.x <= segEndPoint.x
508  if( segStartPoint.x > segEndPoint.x )
509  std::swap( segStartPoint.x, segEndPoint.x );
510 
511  if( segStartPoint.x > ( -w_dist ) && segStartPoint.x < ( m_segmLength + w_dist ) )
512  {
513  // the start point is inside the reference range
514  // X........
515  // O--REF--+
516 
517  // Fine test : we consider the rounded shape of each end of the track segment:
518  if( segStartPoint.x >= 0 && segStartPoint.x <= m_segmLength )
519  {
520  markers.push_back( fillMarker( aRefSeg, track,
521  DRCE_TRACK_ENDS1, nullptr ) );
522  if( !handleNewMarker() )
523  return false;
524  }
525 
526  if( !checkMarginToCircle( segStartPoint, w_dist, m_segmLength ) )
527  {
528  markers.push_back( fillMarker( aRefSeg, track,
529  DRCE_TRACK_ENDS2, nullptr ) );
530  if( !handleNewMarker() )
531  return false;
532  }
533  }
534 
535  if( segEndPoint.x > ( -w_dist ) && segEndPoint.x < ( m_segmLength + w_dist ) )
536  {
537  // the end point is inside the reference range
538  // .....X
539  // O--REF--+
540  // Fine test : we consider the rounded shape of the ends
541  if( segEndPoint.x >= 0 && segEndPoint.x <= m_segmLength )
542  {
543  markers.push_back( fillMarker( aRefSeg, track,
544  DRCE_TRACK_ENDS3, nullptr ) );
545  if( !handleNewMarker() )
546  return false;
547  }
548 
549  if( !checkMarginToCircle( segEndPoint, w_dist, m_segmLength ) )
550  {
551  markers.push_back( fillMarker( aRefSeg, track,
552  DRCE_TRACK_ENDS4, nullptr ) );
553  if( !handleNewMarker() )
554  return false;
555  }
556  }
557 
558  if( segStartPoint.x <= 0 && segEndPoint.x >= 0 )
559  {
560  // the segment straddles the reference range (this actually only
561  // checks if it straddles the origin, because the other cases where already
562  // handled)
563  // X.............X
564  // O--REF--+
565  markers.push_back( fillMarker( aRefSeg, track,
566  DRCE_TRACK_SEGMENTS_TOO_CLOSE, nullptr ) );
567  if( !handleNewMarker() )
568  return false;
569  }
570  }
571  else if( segStartPoint.x == segEndPoint.x ) // perpendicular segments
572  {
573  if( ( segStartPoint.x <= ( -w_dist ) ) || ( segStartPoint.x >= ( m_segmLength + w_dist ) ) )
574  continue;
575 
576  // Test if segments are crossing
577  if( segStartPoint.y > segEndPoint.y )
578  std::swap( segStartPoint.y, segEndPoint.y );
579 
580  if( ( segStartPoint.y < 0 ) && ( segEndPoint.y > 0 ) )
581  {
582  markers.push_back( fillMarker( aRefSeg, track,
583  DRCE_TRACKS_CROSSING, nullptr ) );
584  if( !handleNewMarker() )
585  return false;
586  }
587 
588  // At this point the drc error is due to an end near a reference segm end
589  if( !checkMarginToCircle( segStartPoint, w_dist, m_segmLength ) )
590  {
591  markers.push_back( fillMarker( aRefSeg, track,
592  DRCE_ENDS_PROBLEM1, nullptr ) );
593  if( !handleNewMarker() )
594  return false;
595  }
596  if( !checkMarginToCircle( segEndPoint, w_dist, m_segmLength ) )
597  {
598  markers.push_back( fillMarker( aRefSeg, track,
599  DRCE_ENDS_PROBLEM2, nullptr ) );
600  if( !handleNewMarker() )
601  return false;
602  }
603  }
604  else // segments quelconques entre eux
605  {
606  // calcul de la "surface de securite du segment de reference
607  // First rought 'and fast) test : the track segment is like a rectangle
608 
609  m_xcliplo = m_ycliplo = -w_dist;
610  m_xcliphi = m_segmLength + w_dist;
611  m_ycliphi = w_dist;
612 
613  // A fine test is needed because a serment is not exactly a
614  // rectangle, it has rounded ends
615  if( !checkLine( segStartPoint, segEndPoint ) )
616  {
617  /* 2eme passe : the track has rounded ends.
618  * we must a fine test for each rounded end and the
619  * rectangular zone
620  */
621 
622  m_xcliplo = 0;
624 
625  if( !checkLine( segStartPoint, segEndPoint ) )
626  {
627  markers.push_back( fillMarker( aRefSeg, track,
628  DRCE_ENDS_PROBLEM3, nullptr ) );
629  if( !handleNewMarker() )
630  return false;
631  }
632  else // The drc error is due to the starting or the ending point of the reference segment
633  {
634  // Test the starting and the ending point
635  segStartPoint = track->GetStart();
636  segEndPoint = track->GetEnd();
637  delta = segEndPoint - segStartPoint;
638 
639  // Compute the segment orientation (angle) en 0,1 degre
640  double angle = ArcTangente( delta.y, delta.x );
641 
642  // Compute the segment length: delta.x = length after rotation
643  RotatePoint( &delta, angle );
644 
645  /* Comute the reference segment coordinates relatives to a
646  * X axis = current tested segment
647  */
648  wxPoint relStartPos = aRefSeg->GetStart() - segStartPoint;
649  wxPoint relEndPos = aRefSeg->GetEnd() - segStartPoint;
650 
651  RotatePoint( &relStartPos, angle );
652  RotatePoint( &relEndPos, angle );
653 
654  if( !checkMarginToCircle( relStartPos, w_dist, delta.x ) )
655  {
656  markers.push_back( fillMarker( aRefSeg, track,
657  DRCE_ENDS_PROBLEM4, nullptr ) );
658  if( !handleNewMarker() )
659  return false;
660  }
661 
662  if( !checkMarginToCircle( relEndPos, w_dist, delta.x ) )
663  {
664  markers.push_back( fillMarker( aRefSeg, track,
665  DRCE_ENDS_PROBLEM5, nullptr ) );
666  if( !handleNewMarker() )
667  return false;
668  }
669  }
670  }
671  }
672  }
673 
674  if( markers.size() > 0 )
675  {
676  commitMarkers();
677  return false;
678  }
679  else
680  return true;
681 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:112
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:673
#define DRCE_TOO_SMALL_MICROVIA_DRILL
Too small micro via drill.
Definition: drc.h:74
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
#define DRCE_TOO_SMALL_VIA
Too small via size.
Definition: drc.h:71
MARKER_PCB * fillMarker(const TRACK *aTrack, BOARD_ITEM *aItem, int aErrorCode, MARKER_PCB *fillMe)
Creates a marker and fills it in with information but does not add it to the BOARD.
int m_ycliplo
Definition: drc.h:213
#define DRCE_TRACK_ENDS4
2 parallel track segments too close: fine end point test
Definition: drc.h:54
int m_ycliphi
Definition: drc.h:215
#define DRCE_TRACK_NEAR_PAD
pad too close to track
Definition: drc.h:47
int m_segmLength
Definition: drc.h:207
PAD_DRILL_SHAPE_T GetDrillShape() const
Definition: class_pad.h:388
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:216
const wxSize & GetDrillSize() const
Definition: class_pad.h:275
wxPoint m_padToTestPos
Definition: drc.h:198
#define abs(a)
Definition: auxiliary.h:84
static const int delta[8][2]
Definition: solve.cpp:112
const wxPoint & GetEnd() const
Definition: class_track.h:119
#define DRCE_TRACK_ENDS2
2 parallel track segments too close: fine start point test
Definition: drc.h:52
#define DRCE_TRACK_SEGMENTS_TOO_CLOSE
2 parallel track segments too close: segm ends between segref ends
Definition: drc.h:55
#define DRCE_BURIED_VIA_NOT_ALLOWED
buried vias are not allowed
Definition: drc.h:92
#define DRCE_TRACK_NEAR_VIA
track too close to via
Definition: drc.h:48
BOARD * m_pcb
Definition: drc.h:218
#define DRCE_TOO_SMALL_MICROVIA
Too small micro via size.
Definition: drc.h:72
bool checkLine(wxPoint aSegStart, wxPoint aSegEnd)
Function checkLine (helper function used in drc calculations to see if one track is in contact with a...
#define DRCE_VIA_HOLE_BIGGER
via&#39;s hole is bigger than its diameter
Definition: drc.h:63
PCB_LAYER_ID
A quick note on layer IDs:
Class LSET is a set of PCB_LAYER_IDs.
int GetCopperLayerCount() const
Function GetCopperLayerCount.
VIATYPE_T GetViaType() const
Definition: class_track.h:460
double ArcTangente(int dy, int dx)
Definition: trigo.cpp:170
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Function SetMsgPanel clears the message panel and populates it with the contents of aList...
Definition: draw_frame.cpp:831
std::shared_ptr< NETCLASS > GetNetClass() const
Function GetNetClass returns the NETCLASS for this item.
#define DRCE_MICRO_VIA_INCORRECT_LAYER_PAIR
micro via&#39;s layer pair incorrect (layers must be adjacent)
Definition: drc.h:64
const wxPoint & GetStart() const
Definition: class_track.h:122
int m_TrackMinWidth
track min value for width ((min copper size value
#define DRCE_TRACK_ENDS1
2 parallel track segments too close: fine start point test
Definition: drc.h:51
int m_ViasMinSize
vias (not micro vias) min diameter
LSET GetLayerSet() const override
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
Definition: class_pad.h:402
#define DRCE_TRACK_ENDS3
2 parallel track segments too close: fine end point test
Definition: drc.h:53
#define DRCE_ENDS_PROBLEM2
track ends are too close
Definition: drc.h:58
int m_ViasMinDrill
vias (not micro vias) min drill diameter
virtual LSET GetLayerSet() const
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
#define DRCE_ENDS_PROBLEM3
track ends are too close
Definition: drc.h:59
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:535
void SetSize(const wxSize &aSize)
Definition: class_pad.h:268
static bool checkMarginToCircle(wxPoint aCentre, int aRadius, int aLength)
Check the distance from a point to a segment.
bool m_BlindBuriedViaAllowed
true to allow blind/buried vias
bool m_reportAllTrackErrors
Definition: drc.h:177
virtual int GetClearance(BOARD_CONNECTED_ITEM *aItem=NULL) const override
Function GetClearance returns the clearance in internal units.
int m_xcliphi
Definition: drc.h:214
int m_MicroViasMinSize
micro vias (not vias) min diameter
PCB_EDIT_FRAME * m_pcbEditorFrame
The pcb frame editor which owns the board.
Definition: drc.h:217
string & err
Definition: json11.cpp:598
unsigned GetPadCount()
Function GetPadCount.
void LayerPair(PCB_LAYER_ID *top_layer, PCB_LAYER_ID *bottom_layer) const
Function LayerPair Return the 2 layers used by the via (the via actually uses all layers between thes...
#define DRCE_ENDS_PROBLEM4
track ends are too close
Definition: drc.h:60
int GetNetCode() const
Function GetNetCode.
#define DRCE_VIA_NEAR_VIA
via too close to via
Definition: drc.h:49
#define DRCE_TRACKS_CROSSING
tracks are crossing
Definition: drc.h:56
bool checkClearanceSegmToPad(const D_PAD *aPad, int aSegmentWidth, int aMinDist)
Check the distance from a pad to segment.
#define DRCE_ENDS_PROBLEM5
track ends are too close
Definition: drc.h:61
const std::vector< D_PAD * > GetPads()
Function GetPads returns a reference to a list of all the pads.
wxPoint m_segmEnd
Definition: drc.h:199
TRACK * Next() const
Definition: class_track.h:99
int GetDrillValue() const
Function GetDrillValue "calculates" the drill value for vias (m-Drill if > 0, or default drill value ...
int GetWidth() const
Definition: class_track.h:116
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in tenths of degrees, but soon degrees.
Definition: class_pad.h:382
#define DRCE_VIA_NEAR_TRACK
via too close to track
Definition: drc.h:50
wxPoint ShapePos() const
Definition: class_pad.cpp:500
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
bool m_MicroViasAllowed
true to allow micro vias
#define DRCE_MICRO_VIA_NOT_ALLOWED
micro vias are not allowed
Definition: drc.h:91
int m_MicroViasMinDrill
micro vias (not vias) min drill diameter
const wxPoint GetPosition() const override
Definition: class_pad.h:220
bool m_drcInLegacyRoutingMode
in legacy canvas, when creating a track, the drc test must only display the error message...
Definition: drc.h:192
int m_xcliplo
Definition: drc.h:212
#define DRCE_ENDS_PROBLEM1
track ends are too close
Definition: drc.h:57
#define DRCE_TOO_SMALL_VIA_DRILL
Too small via drill.
Definition: drc.h:73
#define DRCE_TRACK_NEAR_THROUGH_HOLE
thru hole is too close to track
Definition: drc.h:46
double m_segmAngle
Definition: drc.h:206
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
#define DRCE_TOO_SMALL_TRACK_WIDTH
Too small track width.
Definition: drc.h:70
bool DRC::doTrackKeepoutDrc ( TRACK aRefSeg)
private

Test the current segment or via.

Parameters
aRefSegThe segment to test
Returns
bool - true if no problems, else false and m_currentMarker is filled in with the problem information.

Definition at line 1017 of file drc.cpp.

References ZONE_CONTAINER::CommonLayerExists(), SHAPE_POLY_SET::Distance(), DRCE_TRACK_INSIDE_KEEPOUT, DRCE_VIA_INSIDE_KEEPOUT, fillMarker(), BOARD::GetArea(), BOARD::GetAreaCount(), ZONE_CONTAINER::GetDoNotAllowTracks(), ZONE_CONTAINER::GetDoNotAllowVias(), TRACK::GetEnd(), ZONE_CONTAINER::GetIsKeepout(), BOARD_ITEM::GetLayer(), BOARD_ITEM::GetLayerSet(), TRACK::GetPosition(), TRACK::GetStart(), TRACK::GetWidth(), ZONE_CONTAINER::IsOnLayer(), m_currentMarker, m_pcb, ZONE_CONTAINER::Outline(), PCB_TRACE_T, PCB_VIA_T, and EDA_ITEM::Type().

Referenced by DrcOnCreatingTrack().

1018 {
1019  // Test keepout areas for vias, tracks and pads inside keepout areas
1020  for( int ii = 0; ii < m_pcb->GetAreaCount(); ii++ )
1021  {
1022  ZONE_CONTAINER* area = m_pcb->GetArea( ii );
1023 
1024  if( !area->GetIsKeepout() )
1025  continue;
1026 
1027  if( aRefSeg->Type() == PCB_TRACE_T )
1028  {
1029  if( !area->GetDoNotAllowTracks() )
1030  continue;
1031 
1032  if( !area->IsOnLayer( aRefSeg->GetLayer() ) )
1033  continue;
1034 
1035  if( area->Outline()->Distance( SEG( aRefSeg->GetStart(), aRefSeg->GetEnd() ),
1036  aRefSeg->GetWidth() ) == 0 )
1037  {
1038  m_currentMarker = fillMarker( aRefSeg, NULL,
1040  return false;
1041  }
1042  }
1043  else if( aRefSeg->Type() == PCB_VIA_T )
1044  {
1045  if( !area->GetDoNotAllowVias() )
1046  continue;
1047 
1048  auto viaLayers = aRefSeg->GetLayerSet();
1049 
1050  if( !area->CommonLayerExists( viaLayers ) )
1051  continue;
1052 
1053  if( area->Outline()->Distance( aRefSeg->GetPosition() ) < aRefSeg->GetWidth()/2 )
1054  {
1055  m_currentMarker = fillMarker( aRefSeg, NULL,
1057  return false;
1058  }
1059  }
1060  }
1061 
1062  return true;
1063 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
bool CommonLayerExists(const LSET aLayerSet) const
Function CommonLayerExist Test if this zone shares a common layer with the given layer set...
Definition: class_zone.cpp:194
MARKER_PCB * fillMarker(const TRACK *aTrack, BOARD_ITEM *aItem, int aErrorCode, MARKER_PCB *fillMe)
Creates a marker and fills it in with information but does not add it to the BOARD.
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
virtual bool IsOnLayer(PCB_LAYER_ID) const override
Function IsOnLayer tests to see if this object is on the given layer.
Definition: class_zone.cpp:265
SHAPE_POLY_SET * Outline()
Definition: class_zone.h:236
#define DRCE_VIA_INSIDE_KEEPOUT
Via in inside a keepout area.
Definition: drc.h:81
const wxPoint & GetEnd() const
Definition: class_track.h:119
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
BOARD * m_pcb
Definition: drc.h:218
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:602
const wxPoint GetPosition() const override
Definition: class_track.h:113
const wxPoint & GetStart() const
Definition: class_track.h:122
virtual LSET GetLayerSet() const
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:1015
MARKER_PCB * m_currentMarker
Definition: drc.h:181
Definition: seg.h:36
bool GetDoNotAllowTracks() const
Definition: class_zone.h:605
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:986
bool GetDoNotAllowVias() const
Definition: class_zone.h:604
int GetWidth() const
Definition: class_track.h:116
int Distance(VECTOR2I aPoint)
Function DistanceToPolygon computes the minimum distance between aPoint and all the polygons in the s...
#define DRCE_TRACK_INSIDE_KEEPOUT
Track in inside a keepout area.
Definition: drc.h:82
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
int DRC::DrcOnCreatingTrack ( TRACK aRefSeg,
TRACK aList 
)

tests the current segment and returns the result and displays the error in the status panel only if one exists.

No marker created or added to the board. Must be used only during track creation in legacy canvas

Parameters
aRefSegThe current segment to test.
aListThe track list to test (usually m_Pcb->m_Track)
Returns
int - BAD_DRC (1) if DRC error or OK_DRC (0) if OK

Definition at line 175 of file drc.cpp.

References BAD_DRC, doTrackDrc(), doTrackKeepoutDrc(), m_currentMarker, m_drcInLegacyRoutingMode, m_pcbEditorFrame, m_reportAllTrackErrors, OK_DRC, EDA_DRAW_FRAME::SetMsgPanel(), and updatePointers().

Referenced by PCB_EDIT_FRAME::Add45DegreeSegment(), PCB_EDIT_FRAME::Begin_Route(), PCB_EDIT_FRAME::End_Route(), PCB_EDIT_FRAME::Other_Layer_Route(), PCB_EDIT_FRAME::PlaceDraggedOrMovedTrackSegment(), and PCB_EDIT_FRAME::SetTrackSegmentWidth().

176 {
177  updatePointers();
178 
179  // Set right options for this on line drc
180  int drc_state = m_drcInLegacyRoutingMode;
182  int rpt_state = m_reportAllTrackErrors;
183  m_reportAllTrackErrors = false;
184 
185  if( !doTrackDrc( aRefSegm, aList, true ) )
186  {
187  if( m_currentMarker )
189 
190  m_drcInLegacyRoutingMode = drc_state;
191  m_reportAllTrackErrors = rpt_state;
192  return BAD_DRC;
193  }
194 
195  if( !doTrackKeepoutDrc( aRefSegm ) )
196  {
197  wxASSERT( m_currentMarker );
198 
200  delete m_currentMarker;
201  m_currentMarker = nullptr;
202  m_drcInLegacyRoutingMode = drc_state;
203  m_reportAllTrackErrors = rpt_state;
204  return BAD_DRC;
205  }
206 
207  m_drcInLegacyRoutingMode = drc_state;
208  m_reportAllTrackErrors = rpt_state;
209  return OK_DRC;
210 }
#define OK_DRC
Definition: drc.h:35
bool doTrackKeepoutDrc(TRACK *aRefSeg)
Test the current segment or via.
Definition: drc.cpp:1017
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Function SetMsgPanel clears the message panel and populates it with the contents of aList...
Definition: draw_frame.cpp:831
void updatePointers()
Update needed pointers from the one pointer which is known not to change.
Definition: drc.cpp:538
bool m_reportAllTrackErrors
Definition: drc.h:177
PCB_EDIT_FRAME * m_pcbEditorFrame
The pcb frame editor which owns the board.
Definition: drc.h:217
#define BAD_DRC
Definition: drc.h:36
MARKER_PCB * m_currentMarker
Definition: drc.h:181
bool doTrackDrc(TRACK *aRefSeg, TRACK *aStart, bool doPads=true)
Test the current segment.
bool m_drcInLegacyRoutingMode
in legacy canvas, when creating a track, the drc test must only display the error message...
Definition: drc.h:192
int DRC::DrcOnCreatingZone ( ZONE_CONTAINER aArea,
int  aCornerIndex 
)

tests the outline segment starting at CornerIndex and returns the result and displays the error in the status panel only if one exists.

Test Edge inside other areas Test Edge too close other areas No marker created or added to the board. Must be used only during zone creation in legacy canvas

Parameters
aAreaThe area parent which contains the corner.
aCornerIndexThe starting point of the segment to test.
Returns
int - BAD_DRC (1) if DRC error or OK_DRC (0) if OK

Definition at line 374 of file drc.cpp.

References BAD_DRC, doEdgeZoneDrc(), m_currentMarker, m_drcInLegacyRoutingMode, m_pcbEditorFrame, m_reportAllTrackErrors, OK_DRC, EDA_DRAW_FRAME::SetMsgPanel(), and updatePointers().

Referenced by PCB_EDIT_FRAME::Begin_Zone(), and PCB_EDIT_FRAME::End_Zone().

375 {
376  updatePointers();
377 
378  // Set right options for this on line drc
379  int drc_state = m_drcInLegacyRoutingMode;
381  int rpt_state = m_reportAllTrackErrors;
382  m_reportAllTrackErrors = false;
383 
384  if( !doEdgeZoneDrc( aArea, aCornerIndex ) )
385  {
386  wxASSERT( m_currentMarker );
388  delete m_currentMarker;
389  m_currentMarker = nullptr;
390  m_drcInLegacyRoutingMode = drc_state;
391  m_reportAllTrackErrors = rpt_state;
392  return BAD_DRC;
393  }
394 
395  m_drcInLegacyRoutingMode = drc_state;
396  m_reportAllTrackErrors = rpt_state;
397  return OK_DRC;
398 }
#define OK_DRC
Definition: drc.h:35
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Function SetMsgPanel clears the message panel and populates it with the contents of aList...
Definition: draw_frame.cpp:831
void updatePointers()
Update needed pointers from the one pointer which is known not to change.
Definition: drc.cpp:538
bool m_reportAllTrackErrors
Definition: drc.h:177
PCB_EDIT_FRAME * m_pcbEditorFrame
The pcb frame editor which owns the board.
Definition: drc.h:217
#define BAD_DRC
Definition: drc.h:36
bool doEdgeZoneDrc(ZONE_CONTAINER *aArea, int aCornerIndex)
Test a segment in ZONE_CONTAINER * aArea: Test Edge inside other areas Test Edge too close other area...
MARKER_PCB * m_currentMarker
Definition: drc.h:181
bool m_drcInLegacyRoutingMode
in legacy canvas, when creating a track, the drc test must only display the error message...
Definition: drc.h:192
MARKER_PCB * DRC::fillMarker ( const TRACK aTrack,
BOARD_ITEM aItem,
int  aErrorCode,
MARKER_PCB fillMe 
)
private

Creates a marker and fills it in with information but does not add it to the BOARD.

Use this to report any kind of DRC problem or unconnected pad problem.

Parameters
aTrackThe reference track.
aItemAnother item on the BOARD, such as a VIA, SEGZONE, or TRACK.
aErrorCodeA categorizing identifier for the particular type of error that is being reported.
fillMeA MARKER_PCB* which is to be filled in, or NULL if one is to first be allocated, then filled.

Definition at line 49 of file drc_marker_functions.cpp.

References TRACK::GetEnd(), GetLineLength(), TRACK::GetPosition(), TRACK::GetSelectMenuText(), EDA_ITEM::GetSelectMenuText(), TRACK::GetStart(), PCB_PAD_T, PCB_TEXT_T, PCB_TRACE_T, PCB_VIA_T, MARKER_BASE::SetData(), MARKER_PCB::SetItem(), and EDA_ITEM::Type().

Referenced by doEdgeZoneDrc(), doFootprintOverlappingDrc(), doNetClass(), doPadToPadsDrc(), doTrackDrc(), doTrackKeepoutDrc(), testKeepoutAreas(), testTexts(), and testZones().

51 {
52  wxString textA = aTrack->GetSelectMenuText();
53  wxString textB;
54 
55  wxPoint position;
56  wxPoint posB;
57 
58  if( aItem ) // aItem might be NULL
59  {
60  textB = aItem->GetSelectMenuText();
61 
62  if( aItem->Type() == PCB_PAD_T )
63  {
64  posB = position = ((D_PAD*)aItem)->GetPosition();
65  }
66  else if( aItem->Type() == PCB_VIA_T )
67  {
68  posB = position = ((VIA*)aItem)->GetPosition();
69  }
70  else if( aItem->Type() == PCB_TRACE_T )
71  {
72  TRACK* track = (TRACK*) aItem;
73 
74  posB = track->GetPosition();
75 
76  wxPoint endPos = track->GetEnd();
77 
78  // either of aItem's start or end will be used for the marker position
79  // first assume start, then switch at end if needed. decision made on
80  // distance from end of aTrack.
81  position = track->GetStart();
82 
83  double dToEnd = GetLineLength( endPos, aTrack->GetEnd() );
84  double dToStart = GetLineLength( position, aTrack->GetEnd() );
85 
86  if( dToEnd < dToStart )
87  position = endPos;
88  }
89  else if( aItem->Type() == PCB_TEXT_T )
90  {
91  position = aTrack->GetPosition();
92  posB = ((TEXTE_PCB*) aItem)->GetPosition();
93  }
94  }
95  else
96  position = aTrack->GetPosition();
97 
98  if( fillMe )
99  {
100  if( aItem )
101  fillMe->SetData( aErrorCode, position,
102  textA, aTrack->GetPosition(),
103  textB, posB );
104  else
105  fillMe->SetData( aErrorCode, position,
106  textA, aTrack->GetPosition() );
107  }
108  else
109  {
110  if( aItem )
111  {
112  fillMe = new MARKER_PCB( aErrorCode, position,
113  textA, aTrack->GetPosition(),
114  textB, posB );
115  fillMe->SetItem( aItem );
116  }
117  else
118  {
119  fillMe = new MARKER_PCB( aErrorCode, position,
120  textA, aTrack->GetPosition() );
121  }
122  }
123 
124  return fillMe;
125 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
double GetLineLength(const wxPoint &aPointA, const wxPoint &aPointB)
Function GetLineLength returns the length of a line segment defined by aPointA and aPointB...
Definition: trigo.h:191
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
virtual wxString GetSelectMenuText() const
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
const wxPoint & GetEnd() const
Definition: class_track.h:119
void SetData(int aErrorCode, const wxPoint &aMarkerPos, const wxString &aText, const wxPoint &aPos, const wxString &bText, const wxPoint &bPos)
Function SetData fills in all the reportable data associated with a MARKER.
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
void SetItem(const BOARD_ITEM *aItem)
const wxPoint GetPosition() const override
Definition: class_track.h:113
const wxPoint & GetStart() const
Definition: class_track.h:122
virtual wxString GetSelectMenuText() const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
MARKER_PCB * DRC::fillMarker ( D_PAD aPad,
BOARD_ITEM aItem,
int  aErrorCode,
MARKER_PCB fillMe 
)
private

Definition at line 128 of file drc_marker_functions.cpp.

References D_PAD::GetPosition(), EDA_ITEM::GetSelectMenuText(), D_PAD::GetSelectMenuText(), PCB_PAD_T, PCB_TEXT_T, MARKER_BASE::SetData(), MARKER_PCB::SetItem(), and EDA_ITEM::Type().

129 {
130  wxString textA = aPad->GetSelectMenuText();
131  wxString textB;
132 
133  wxPoint posA = aPad->GetPosition();
134  wxPoint posB;
135 
136  if( aItem )
137  {
138  textB = aItem->GetSelectMenuText();
139 
140  switch( aItem->Type() )
141  {
142  case PCB_PAD_T:
143  posB = ((D_PAD*)aItem)->GetPosition();
144  break;
145 
146  case PCB_TEXT_T:
147  posB = ((TEXTE_PCB*)aItem)->GetPosition();
148  break;
149 
150  default:
151  wxLogDebug( wxT("fillMarker: unsupported item") );
152  break;
153  }
154  }
155 
156  if( fillMe )
157  {
158  fillMe->SetData( aErrorCode, posA, textA, posA, textB, posB );
159  }
160  else
161  {
162  fillMe = new MARKER_PCB( aErrorCode, posA, textA, posA, textB, posB );
163  fillMe->SetItem( aPad ); // TODO it has to be checked
164  }
165 
166  return fillMe;
167 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
wxString GetSelectMenuText() const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: class_pad.cpp:1202
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
virtual wxString GetSelectMenuText() const
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
void SetData(int aErrorCode, const wxPoint &aMarkerPos, const wxString &aText, const wxPoint &aPos, const wxString &bText, const wxPoint &bPos)
Function SetData fills in all the reportable data associated with a MARKER.
void SetItem(const BOARD_ITEM *aItem)
const wxPoint GetPosition() const override
Definition: class_pad.h:220
MARKER_PCB * DRC::fillMarker ( ZONE_CONTAINER aArea,
int  aErrorCode,
MARKER_PCB fillMe 
)
private

Definition at line 170 of file drc_marker_functions.cpp.

References ZONE_CONTAINER::GetPosition(), ZONE_CONTAINER::GetSelectMenuText(), MARKER_BASE::SetData(), and MARKER_PCB::SetItem().

171 {
172  wxString textA = aArea->GetSelectMenuText();
173 
174  wxPoint posA = aArea->GetPosition();
175 
176  if( fillMe )
177  {
178  fillMe->SetData( aErrorCode, posA, textA, posA );
179  }
180  else
181  {
182  fillMe = new MARKER_PCB( aErrorCode, posA, textA, posA );
183  fillMe->SetItem( aArea );
184  }
185 
186  return fillMe;
187 }
wxString GetSelectMenuText() const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
const wxPoint GetPosition() const override
Function GetPosition.
Definition: class_zone.cpp:169
void SetData(int aErrorCode, const wxPoint &aMarkerPos, const wxString &aText, const wxPoint &aPos, const wxString &bText, const wxPoint &bPos)
Function SetData fills in all the reportable data associated with a MARKER.
void SetItem(const BOARD_ITEM *aItem)
MARKER_PCB * DRC::fillMarker ( const wxPoint aPos,
int  aErrorCode,
const wxString &  aMessage,
MARKER_PCB fillMe 
)
private

Definition at line 228 of file drc_marker_functions.cpp.

References MARKER_BASE::SetData().

229 {
230  wxPoint posA = aPos;
231 
232  if( fillMe )
233  fillMe->SetData( aErrorCode, posA, aMessage, posA );
234  else
235  fillMe = new MARKER_PCB( aErrorCode, posA, aMessage, posA );
236 
237  return fillMe;
238 }
void SetData(int aErrorCode, const wxPoint &aMarkerPos, const wxString &aText, const wxPoint &aPos, const wxString &bText, const wxPoint &bPos)
Function SetData fills in all the reportable data associated with a MARKER.
MARKER_PCB * DRC::fillMarker ( const ZONE_CONTAINER aArea,
const wxPoint aPos,
int  aErrorCode,
MARKER_PCB fillMe 
)
private

Create a marker and fills it in with information but do not add it to the BOARD.

Use this to report any kind of DRC problem, or unconnected pad problem.

Parameters
aAreaThe zone to test
aPosposition of error
aErrorCodeType of error
fillMeA MARKER_PCB* which is to be filled in, or NULL if one is to first be allocated, then filled.

Definition at line 190 of file drc_marker_functions.cpp.

References ZONE_CONTAINER::GetSelectMenuText(), MARKER_BASE::SetData(), and MARKER_PCB::SetItem().

194 {
195  wxString textA = aArea->GetSelectMenuText();
196 
197  wxPoint posA = aPos;
198 
199  if( fillMe )
200  {
201  fillMe->SetData( aErrorCode, posA, textA, posA );
202  }
203  else
204  {
205  fillMe = new MARKER_PCB( aErrorCode, posA, textA, posA );
206  fillMe->SetItem( aArea );
207  }
208 
209  return fillMe;
210 }
wxString GetSelectMenuText() const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
void SetData(int aErrorCode, const wxPoint &aMarkerPos, const wxString &aText, const wxPoint &aPos, const wxString &bText, const wxPoint &bPos)
Function SetData fills in all the reportable data associated with a MARKER.
void SetItem(const BOARD_ITEM *aItem)
MARKER_PCB * DRC::fillMarker ( int  aErrorCode,
const wxString &  aMessage,
MARKER_PCB fillMe 
)
private

Fill a MARKER which will report on a generic problem with the board which is not geographically locatable.

Definition at line 213 of file drc_marker_functions.cpp.

References MARKER_BASE::SetData(), and MARKER_BASE::SetShowNoCoordinate().

214 {
215  wxPoint posA; // not displayed
216 
217  if( fillMe )
218  fillMe->SetData( aErrorCode, posA, aMessage, posA );
219  else
220  fillMe = new MARKER_PCB( aErrorCode, posA, aMessage, posA );
221 
222  fillMe->SetShowNoCoordinate();
223 
224  return fillMe;
225 }
void SetShowNoCoordinate()
Definition: marker_base.h:192
void SetData(int aErrorCode, const wxPoint &aMarkerPos, const wxString &aText, const wxPoint &aPos, const wxString &bText, const wxPoint &bPos)
Function SetData fills in all the reportable data associated with a MARKER.
MARKER_PCB* DRC::GetCurrentMarker ( )
inline
Returns
a pointer to the current marker (last created marker

Definition at line 540 of file drc.h.

Referenced by PCB_EDIT_FRAME::Other_Layer_Route().

541  {
542  return m_currentMarker;
543  }
MARKER_PCB * m_currentMarker
Definition: drc.h:181
void DRC::ListUnconnectedPads ( )

Gather a list of all the unconnected pads and shows them in the dialog, and optionally prints a report of such.

Definition at line 529 of file drc.cpp.

References testUnconnected(), and updatePointers().

Referenced by DIALOG_DRC_CONTROL::OnListUnconnectedClick().

530 {
531  testUnconnected();
532 
533  // update the m_drcDialog listboxes
534  updatePointers();
535 }
void updatePointers()
Update needed pointers from the one pointer which is known not to change.
Definition: drc.cpp:538
void testUnconnected()
Definition: drc.cpp:771
void DRC::RunTests ( wxTextCtrl *  aMessages = NULL)

Run all the tests specified with a previous call to SetSettings()

Parameters
aMessages= a wxTextControl where to display some activity messages. Can be NULL

Definition at line 401 of file drc.cpp.

References PCB_EDIT_FRAME::Check_All_Zones(), doFootprintOverlappingDrc(), PCB_EDIT_FRAME::Fill_All_Zones(), PCB_BASE_FRAME::GetBoard(), m_doFootprintOverlapping, m_doKeepoutTest, m_doNoCourtyardDefined, m_doPad2PadTest, m_doUnconnectedTest, m_pcb, m_pcbEditorFrame, m_refillZones, testKeepoutAreas(), testNetClasses(), testPad2Pad(), testTexts(), testTracks(), testUnconnected(), testZones(), and updatePointers().

Referenced by DIALOG_DRC_CONTROL::OnStartdrcClick().

402 {
403  // be sure m_pcb is the current board, not a old one
404  // ( the board can be reloaded )
406 
407  // someone should have cleared the two lists before calling this.
408 
409  if( !testNetClasses() )
410  {
411  // testing the netclasses is a special case because if the netclasses
412  // do not pass the BOARD_DESIGN_SETTINGS checks, then every member of a net
413  // class (a NET) will cause its items such as tracks, vias, and pads
414  // to also fail. So quit after *all* netclass errors have been reported.
415  if( aMessages )
416  aMessages->AppendText( _( "Aborting\n" ) );
417 
418  // update the m_drcDialog listboxes
419  updatePointers();
420 
421  return;
422  }
423 
424  // test pad to pad clearances, nothing to do with tracks, vias or zones.
425  if( m_doPad2PadTest )
426  {
427  if( aMessages )
428  {
429  aMessages->AppendText( _( "Pad clearances...\n" ) );
430  wxSafeYield();
431  }
432 
433  testPad2Pad();
434  }
435 
436  // test track and via clearances to other tracks, pads, and vias
437  if( aMessages )
438  {
439  aMessages->AppendText( _( "Track clearances...\n" ) );
440  wxSafeYield();
441  }
442 
443  testTracks( aMessages ? aMessages->GetParent() : m_pcbEditorFrame, true );
444 
445  // caller (a wxTopLevelFrame) is the wxDialog or the Pcb Editor frame that call DRC:
446  wxWindow* caller = aMessages ? aMessages->GetParent() : m_pcbEditorFrame;
447 
448  if( m_refillZones )
449  {
450  if( aMessages )
451  aMessages->AppendText( _( "Refilling all zones...\n" ) );
452 
453  m_pcbEditorFrame->Fill_All_Zones( caller );
454  }
455  else
456  {
457  if( aMessages )
458  aMessages->AppendText( _( "Checking zone fills...\n" ) );
459 
461  }
462 
463  // test zone clearances to other zones
464  if( aMessages )
465  {
466  aMessages->AppendText( _( "Zone to zone clearances...\n" ) );
467  wxSafeYield();
468  }
469 
470  testZones();
471 
472  // find and gather unconnected pads.
473  if( m_doUnconnectedTest )
474  {
475  if( aMessages )
476  {
477  aMessages->AppendText( _( "Unconnected pads...\n" ) );
478  aMessages->Refresh();
479  }
480 
481  testUnconnected();
482  }
483 
484  // find and gather vias, tracks, pads inside keepout areas.
485  if( m_doKeepoutTest )
486  {
487  if( aMessages )
488  {
489  aMessages->AppendText( _( "Keepout areas ...\n" ) );
490  aMessages->Refresh();
491  }
492 
494  }
495 
496  // find and gather vias, tracks, pads inside text boxes.
497  if( aMessages )
498  {
499  aMessages->AppendText( _( "Test texts...\n" ) );
500  wxSafeYield();
501  }
502 
503  testTexts();
504 
505  // find overlapping courtyard ares.
507  {
508  if( aMessages )
509  {
510  aMessages->AppendText( _( "Courtyard areas...\n" ) );
511  aMessages->Refresh();
512  }
513 
515  }
516 
517  // update the m_drcDialog listboxes
518  updatePointers();
519 
520  if( aMessages )
521  {
522  // no newline on this one because it is last, don't want the window
523  // to unnecessarily scroll.
524  aMessages->AppendText( _( "Finished" ) );
525  }
526 }
bool m_refillZones
Definition: drc.h:176
bool m_doNoCourtyardDefined
Definition: drc.h:175
void testKeepoutAreas()
Definition: drc.cpp:839
void Check_All_Zones(wxWindow *aActiveWindow)
Function Check_All_Zones Checks for out-of-date fills and fills them if requested by the user...
BOARD * GetBoard() const
void testTexts()
Definition: drc.cpp:893
BOARD * m_pcb
Definition: drc.h:218
bool m_doFootprintOverlapping
Definition: drc.h:174
bool m_doKeepoutTest
Definition: drc.h:172
void testZones()
Definition: drc.cpp:801
void updatePointers()
Update needed pointers from the one pointer which is known not to change.
Definition: drc.cpp:538
PCB_EDIT_FRAME * m_pcbEditorFrame
The pcb frame editor which owns the board.
Definition: drc.h:217
bool m_doPad2PadTest
Definition: drc.h:169
void testPad2Pad()
Definition: drc.cpp:668
bool doFootprintOverlappingDrc()
Test for footprint courtyard overlaps.
Definition: drc.cpp:1200
bool testNetClasses()
Go through each NETCLASS and verifies that its clearance, via size, track width, and track clearance ...
Definition: drc.cpp:645
void testTracks(wxWindow *aActiveWindow, bool aShowProgressBar)
Perform the DRC on all tracks.
Definition: drc.cpp:712
int Fill_All_Zones(wxWindow *aActiveWindow)
Function Fill_All_Zones Fill all zones on the board The old fillings are removed. ...
void testUnconnected()
Definition: drc.cpp:771
bool m_doUnconnectedTest
Definition: drc.h:170
void DRC::SetSettings ( bool  aPad2PadTest,
bool  aUnconnectedTest,
bool  aZonesTest,
bool  aKeepoutTest,
bool  aRefillZones,
bool  aCourtyardTest,
bool  aCourtyardMissingTest,
bool  aReportAllTrackErrors,
const wxString &  aReportName,
bool  aSaveReport 
)
inline

Save all the UI or test settings and may be called before running the tests.

Parameters
aPad2PadTestTells whether to test pad to pad distances.
aUnconnectedTestTells whether to list unconnected pads.
aZonesTestTells whether to test zones.
aRefillZonesRefill zones before performing DRC.
aKeepoutTestTells whether to test keepout areas.
aCourtyardTestTells whether to test footprint courtyard overlap.
aCourtyardMissingTestTells whether to test missing courtyard definition in footprint.
aReportAllTrackErrorsTells whether or not to stop checking track connections after the first error.
aReportNameA string telling the disk file report name entered.
aSaveReportA boolean telling whether to generate disk file report.

Definition at line 504 of file drc.h.

Referenced by DIALOG_DRC_CONTROL::OnListUnconnectedClick(), and DIALOG_DRC_CONTROL::OnStartdrcClick().

509  {
510  m_doPad2PadTest = aPad2PadTest;
511  m_doUnconnectedTest = aUnconnectedTest;
512  m_doZonesTest = aZonesTest;
513  m_doKeepoutTest = aKeepoutTest;
514  m_rptFilename = aReportName;
515  m_doCreateRptFile = aSaveReport;
516  m_doFootprintOverlapping = aCourtyardTest;
517  m_doNoCourtyardDefined = aCourtyardMissingTest;
518  m_refillZones = aRefillZones;
519  m_drcInLegacyRoutingMode = false;
520  m_reportAllTrackErrors = aReportAllTrackErrors;
521  }
bool m_refillZones
Definition: drc.h:176
bool m_doNoCourtyardDefined
Definition: drc.h:175
bool m_doCreateRptFile
Definition: drc.h:173
bool m_doFootprintOverlapping
Definition: drc.h:174
bool m_doKeepoutTest
Definition: drc.h:172
bool m_doZonesTest
Definition: drc.h:171
bool m_reportAllTrackErrors
Definition: drc.h:177
bool m_doPad2PadTest
Definition: drc.h:169
wxString m_rptFilename
Definition: drc.h:179
bool m_drcInLegacyRoutingMode
in legacy canvas, when creating a track, the drc test must only display the error message...
Definition: drc.h:192
bool m_doUnconnectedTest
Definition: drc.h:170
void DRC::ShowDRCDialog ( wxWindow *  aParent = NULL)

Open a dialog and prompts the user, then if a test run button is clicked, runs the test(s) and creates the MARKERS.

The dialog is only created if it is not already in existence.

Parameters
aParentis the parent window for wxWidgets. Usually the PCB editor frame but can be another dialog if aParent == NULL (default), the parent will be the PCB editor frame and the dialog will be not modal (just float on parent if aParent is specified, the dialog will be modal. The modal mode is mandatory if the dialog is created from another dialog, not from the PCB editor frame

Definition at line 59 of file drc.cpp.

References ACTIONS::cancelInteractive, TOOL_MANAGER::DeactivateTool(), DIALOG_DRC_CONTROL, EDA_DRAW_FRAME::GetToolManager(), m_doCreateRptFile, m_drcDialog, m_pcbEditorFrame, m_rptFilename, TOOL_MANAGER::RunAction(), PCB_ACTIONS::selectionClear, DIALOG_DRC_CONTROL::SetRptSettings(), DIALOG_SHIM::Show(), and updatePointers().

Referenced by DIALOG_PLOT::onRunDRC(), and PCB_EDIT_FRAME::Process_Special_Functions().

60 {
61  bool show_dlg_modal = true;
62 
63  // the dialog needs a parent frame. if it is not specified, this is
64  // the PCB editor frame specified in DRC class.
65  if( aParent == NULL )
66  {
67  // if any parent is specified, the dialog is modal.
68  // if this is the default PCB editor frame, it is not modal
69  show_dlg_modal = false;
70  aParent = m_pcbEditorFrame;
71  }
72 
74  toolMgr->RunAction( ACTIONS::cancelInteractive, true );
75  toolMgr->DeactivateTool();
76  toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
77 
78  if( !m_drcDialog )
79  {
80  m_drcDialog = new DIALOG_DRC_CONTROL( this, m_pcbEditorFrame, aParent );
82 
84 
85  if( show_dlg_modal )
86  m_drcDialog->ShowModal();
87  else
88  m_drcDialog->Show( true );
89  }
90  else // The dialog is just not visible (because the user has double clicked on an error item)
91  {
93  m_drcDialog->Show( true );
94  }
95 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
bool m_doCreateRptFile
Definition: drc.h:173
DIALOG_DRC_CONTROL * m_drcDialog
Definition: drc.h:219
static TOOL_ACTION cancelInteractive
Definition: actions.h:45
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
void DeactivateTool()
Function DeactivateTool() Deactivates the currently active tool.
Class TOOL_MANAGER.
Definition: tool_manager.h:49
void updatePointers()
Update needed pointers from the one pointer which is known not to change.
Definition: drc.cpp:538
PCB_EDIT_FRAME * m_pcbEditorFrame
The pcb frame editor which owns the board.
Definition: drc.h:217
bool Show(bool show) override
friend class DIALOG_DRC_CONTROL
Definition: drc.h:164
TOOL_MANAGER * GetToolManager() const
Function GetToolManager returns the tool manager instance, if any.
Definition: draw_frame.h:910
wxString m_rptFilename
Definition: drc.h:179
void SetRptSettings(bool aEnable, const wxString &aFileName)
Enable/disable the report file creation.
Definition: dialog_drc.cpp:182
void DRC::testKeepoutAreas ( )
private

Definition at line 839 of file drc.cpp.

References addMarkerToPcb(), ZONE_CONTAINER::CommonLayerExists(), SHAPE_POLY_SET::Distance(), DRCE_TRACK_INSIDE_KEEPOUT, DRCE_VIA_INSIDE_KEEPOUT, fillMarker(), BOARD::GetArea(), BOARD::GetAreaCount(), ZONE_CONTAINER::GetDoNotAllowTracks(), ZONE_CONTAINER::GetDoNotAllowVias(), ZONE_CONTAINER::GetIsKeepout(), BOARD_ITEM::GetLayerSet(), ZONE_CONTAINER::IsOnLayer(), m_currentMarker, m_pcb, BOARD::m_Track, TRACK::Next(), ZONE_CONTAINER::Outline(), PCB_TRACE_T, and PCB_VIA_T.

Referenced by RunTests().

840 {
841  // Test keepout areas for vias, tracks and pads inside keepout areas
842  for( int ii = 0; ii < m_pcb->GetAreaCount(); ii++ )
843  {
844  ZONE_CONTAINER* area = m_pcb->GetArea( ii );
845 
846  if( !area->GetIsKeepout() )
847  {
848  continue;
849  }
850 
851  for( TRACK* segm = m_pcb->m_Track; segm != NULL; segm = segm->Next() )
852  {
853  if( segm->Type() == PCB_TRACE_T )
854  {
855  if( !area->GetDoNotAllowTracks() )
856  continue;
857 
858  // Ignore if the keepout zone is not on the same layer
859  if( !area->IsOnLayer( segm->GetLayer() ) )
860  continue;
861 
862  if( area->Outline()->Distance( SEG( segm->GetStart(), segm->GetEnd() ),
863  segm->GetWidth() ) == 0 )
864  {
865  addMarkerToPcb( fillMarker( segm, NULL,
867  m_currentMarker = nullptr;
868  }
869  }
870  else if( segm->Type() == PCB_VIA_T )
871  {
872  if( ! area->GetDoNotAllowVias() )
873  continue;
874 
875  auto viaLayers = segm->GetLayerSet();
876 
877  if( !area->CommonLayerExists( viaLayers ) )
878  continue;
879 
880  if( area->Outline()->Distance( segm->GetPosition() ) < segm->GetWidth()/2 )
881  {
882  addMarkerToPcb( fillMarker( segm, NULL,
884  m_currentMarker = nullptr;
885  }
886  }
887  }
888  // Test pads: TODO
889  }
890 }
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
bool CommonLayerExists(const LSET aLayerSet) const
Function CommonLayerExist Test if this zone shares a common layer with the given layer set...
Definition: class_zone.cpp:194
MARKER_PCB * fillMarker(const TRACK *aTrack, BOARD_ITEM *aItem, int aErrorCode, MARKER_PCB *fillMe)
Creates a marker and fills it in with information but does not add it to the BOARD.
virtual bool IsOnLayer(PCB_LAYER_ID) const override
Function IsOnLayer tests to see if this object is on the given layer.
Definition: class_zone.cpp:265
SHAPE_POLY_SET * Outline()
Definition: class_zone.h:236
#define DRCE_VIA_INSIDE_KEEPOUT
Via in inside a keepout area.
Definition: drc.h:81
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
BOARD * m_pcb
Definition: drc.h:218
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:602
void addMarkerToPcb(MARKER_PCB *aMarker)
Adds a DRC marker to the PCB through the COMMIT mechanism.
Definition: drc.cpp:98
virtual LSET GetLayerSet() const
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:1015
MARKER_PCB * m_currentMarker
Definition: drc.h:181
Definition: seg.h:36
bool GetDoNotAllowTracks() const
Definition: class_zone.h:605
TRACK * Next() const
Definition: class_track.h:99
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:986
bool GetDoNotAllowVias() const
Definition: class_zone.h:604
int Distance(VECTOR2I aPoint)
Function DistanceToPolygon computes the minimum distance between aPoint and all the polygons in the s...
#define DRCE_TRACK_INSIDE_KEEPOUT
Track in inside a keepout area.
Definition: drc.h:82
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
DLIST< TRACK > m_Track
Definition: class_board.h:248
bool DRC::testNetClasses ( )
private

Go through each NETCLASS and verifies that its clearance, via size, track width, and track clearance are larger than those in board.m_designSettings.

This is necessary because the actual DRC checks are run against the NETCLASS limits, so in order enforce global limits, we first check the NETCLASSes against the global limits.

Returns
bool - true if succes, else false but only after reporting all NETCLASS violations.

Definition at line 645 of file drc.cpp.

References NETCLASSES::begin(), doNetClass(), NETCLASSES::end(), NETCLASSES::GetDefault(), BOARD::GetDesignSettings(), i, BOARD_DESIGN_SETTINGS::m_NetClasses, and m_pcb.

Referenced by RunTests().

646 {
647  bool ret = true;
648 
650 
651  wxString msg; // construct this only once here, not in a loop, since somewhat expensive.
652 
653  if( !doNetClass( netclasses.GetDefault(), msg ) )
654  ret = false;
655 
656  for( NETCLASSES::const_iterator i = netclasses.begin(); i != netclasses.end(); ++i )
657  {
658  NETCLASSPTR nc = i->second;
659 
660  if( !doNetClass( nc, msg ) )
661  ret = false;
662  }
663 
664  return ret;
665 }
bool doNetClass(const std::shared_ptr< NETCLASS > &aNetClass, wxString &msg)
Definition: drc.cpp:553
iterator end()
Definition: netclass.h:256
NETCLASS_MAP::const_iterator const_iterator
Definition: netclass.h:258
BOARD * m_pcb
Definition: drc.h:218
iterator begin()
Definition: netclass.h:255
Class NETCLASSES is a container for NETCLASS instances.
Definition: netclass.h:231
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:535
NETCLASSPTR GetDefault() const
Function GetDefault.
Definition: netclass.h:275
size_t i
Definition: json11.cpp:597
NETCLASSES m_NetClasses
List of current netclasses. There is always the default netclass.
void DRC::testPad2Pad ( )
private

Definition at line 668 of file drc.cpp.

References addMarkerToPcb(), doPadToPadsDrc(), D_PAD::GetBoundingRadius(), D_PAD::GetClearance(), D_PAD::GetPosition(), BOARD::GetSortedPadListByXthenYCoord(), i, m_currentMarker, m_pcb, and wxPoint::x.

Referenced by RunTests().

669 {
670  std::vector<D_PAD*> sortedPads;
671 
672  m_pcb->GetSortedPadListByXthenYCoord( sortedPads );
673 
674  if( sortedPads.size() == 0 )
675  return;
676 
677  // find the max size of the pads (used to stop the test)
678  int max_size = 0;
679 
680  for( unsigned i = 0; i < sortedPads.size(); ++i )
681  {
682  D_PAD* pad = sortedPads[i];
683 
684  // GetBoundingRadius() is the radius of the minimum sized circle fully containing the pad
685  int radius = pad->GetBoundingRadius();
686 
687  if( radius > max_size )
688  max_size = radius;
689  }
690 
691  // Upper limit of pad list (limit not included)
692  D_PAD** listEnd = &sortedPads[0] + sortedPads.size();
693 
694  // Test the pads
695  for( unsigned i = 0; i< sortedPads.size(); ++i )
696  {
697  D_PAD* pad = sortedPads[i];
698 
699  int x_limit = max_size + pad->GetClearance() +
700  pad->GetBoundingRadius() + pad->GetPosition().x;
701 
702  if( !doPadToPadsDrc( pad, &sortedPads[i], listEnd, x_limit ) )
703  {
704  wxASSERT( m_currentMarker );
706  m_currentMarker = nullptr;
707  }
708  }
709 }
void GetSortedPadListByXthenYCoord(std::vector< D_PAD * > &aVector, int aNetCode=-1)
Function GetSortedPadListByXthenYCoord first empties then fills the vector with all pads and sorts th...
BOARD * m_pcb
Definition: drc.h:218
void addMarkerToPcb(MARKER_PCB *aMarker)
Adds a DRC marker to the PCB through the COMMIT mechanism.
Definition: drc.cpp:98
int GetBoundingRadius() const
Function GetBoundingRadius returns the radius of a minimum sized circle which fully encloses this pad...
Definition: class_pad.h:599
bool doPadToPadsDrc(D_PAD *aRefPad, D_PAD **aStart, D_PAD **aEnd, int x_limit)
Test the clearance between aRefPad and other pads.
Definition: drc.cpp:1066
MARKER_PCB * m_currentMarker
Definition: drc.h:181
size_t i
Definition: json11.cpp:597
int GetClearance(BOARD_CONNECTED_ITEM *aItem=NULL) const override
Function GetClearance returns the clearance in internal units.
Definition: class_pad.cpp:546
const wxPoint GetPosition() const override
Definition: class_pad.h:220
void DRC::testTexts ( )
private

Definition at line 893 of file drc.cpp.

References addMarkerToPcb(), ArcTangente(), checkClearanceSegmToPad(), delta, dist, BOARD::Drawings(), DRCE_PAD_INSIDE_TEXT, DRCE_TRACK_INSIDE_TEXT, DRCE_VIA_INSIDE_TEXT, fillMarker(), D_PAD::GetClearance(), BOARD::GetPads(), EDA_TEXT::GetThickness(), IsCopperLayer(), D_PAD::IsOnLayer(), m_currentMarker, m_padToTestPos, m_pcb, m_segmAngle, m_segmEnd, m_segmLength, BOARD::m_Track, TRACK::Next(), PCB_TEXT_T, PCB_TRACE_T, PCB_VIA_T, SEG::PointCloserThan(), RotatePoint(), D_PAD::ShapePos(), EDA_TEXT::TransformTextShapeToSegmentList(), wxPoint::x, and wxPoint::y.

Referenced by RunTests().

894 {
895  std::vector<wxPoint> textShape; // a buffer to store the text shape (set of segments)
896  std::vector<D_PAD*> padList = m_pcb->GetPads();
897 
898  // Test text areas for vias, tracks and pads inside text areas
899  for( auto item : m_pcb->Drawings() )
900  {
901  // Drc test only items on copper layers
902  if( !IsCopperLayer( item->GetLayer() ) )
903  continue;
904 
905  // only texts on copper layers are tested
906  if( item->Type() != PCB_TEXT_T )
907  continue;
908 
909  textShape.clear();
910 
911  // So far the bounding box makes up the text-area
912  TEXTE_PCB* text = (TEXTE_PCB*) item;
913  text->TransformTextShapeToSegmentList( textShape );
914 
915  if( textShape.size() == 0 ) // Should not happen (empty text?)
916  continue;
917 
918  for( TRACK* track = m_pcb->m_Track; track != NULL; track = track->Next() )
919  {
920  if( !track->IsOnLayer( item->GetLayer() ) )
921  continue;
922 
923  // Test the distance between each segment and the current track/via
924  int min_dist = ( track->GetWidth() + text->GetThickness() ) /2 +
925  track->GetClearance(NULL);
926 
927  if( track->Type() == PCB_TRACE_T )
928  {
929  SEG segref( track->GetStart(), track->GetEnd() );
930 
931  // Error condition: Distance between text segment and track segment is
932  // smaller than the clearance of the segment
933  for( unsigned jj = 0; jj < textShape.size(); jj += 2 )
934  {
935  SEG segtest( textShape[jj], textShape[jj+1] );
936  int dist = segref.Distance( segtest );
937 
938  if( dist < min_dist )
939  {
940  addMarkerToPcb( fillMarker( track, text,
942  m_currentMarker ) );
943  m_currentMarker = nullptr;
944  break;
945  }
946  }
947  }
948  else if( track->Type() == PCB_VIA_T )
949  {
950  // Error condition: Distance between text segment and via is
951  // smaller than the clearance of the via
952  for( unsigned jj = 0; jj < textShape.size(); jj += 2 )
953  {
954  SEG segtest( textShape[jj], textShape[jj+1] );
955 
956  if( segtest.PointCloserThan( track->GetPosition(), min_dist ) )
957  {
958  addMarkerToPcb( fillMarker( track, text,
960  m_currentMarker = nullptr;
961  break;
962  }
963  }
964  }
965  }
966 
967  // Test pads
968  for( unsigned ii = 0; ii < padList.size(); ii++ )
969  {
970  D_PAD* pad = padList[ii];
971 
972  if( !pad->IsOnLayer( item->GetLayer() ) )
973  continue;
974 
975  wxPoint shape_pos = pad->ShapePos();
976 
977  for( unsigned jj = 0; jj < textShape.size(); jj += 2 )
978  {
979  /* In order to make some calculations more easier or faster,
980  * pads and tracks coordinates will be made relative
981  * to the segment origin
982  */
983  wxPoint origin = textShape[jj]; // origin will be the origin of other coordinates
984  m_segmEnd = textShape[jj+1] - origin;
986  m_segmAngle = 0;
987 
988  // for a non horizontal or vertical segment Compute the segment angle
989  // in tenths of degrees and its length
990  if( delta.x || delta.y ) // delta.x == delta.y == 0 for vias
991  {
992  // Compute the segment angle in 0,1 degrees
993  m_segmAngle = ArcTangente( delta.y, delta.x );
994 
995  // Compute the segment length: we build an equivalent rotated segment,
996  // this segment is horizontal, therefore dx = length
997  RotatePoint( &delta, m_segmAngle ); // delta.x = length, delta.y = 0
998  }
999 
1000  m_segmLength = delta.x;
1001  m_padToTestPos = shape_pos - origin;
1002 
1003  if( !checkClearanceSegmToPad( pad, text->GetThickness(),
1004  pad->GetClearance(NULL) ) )
1005  {
1006  addMarkerToPcb( fillMarker( pad, text,
1008  m_currentMarker = nullptr;
1009  break;
1010  }
1011  }
1012  }
1013  }
1014 }
#define DRCE_TRACK_INSIDE_TEXT
Track in inside a text area.
Definition: drc.h:85
MARKER_PCB * fillMarker(const TRACK *aTrack, BOARD_ITEM *aItem, int aErrorCode, MARKER_PCB *fillMe)
Creates a marker and fills it in with information but does not add it to the BOARD.
static const int dist[10][10]
Definition: dist.cpp:57
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
int m_segmLength
Definition: drc.h:207
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:216
wxPoint m_padToTestPos
Definition: drc.h:198
static const int delta[8][2]
Definition: solve.cpp:112
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
int GetThickness() const
Function GetThickness returns pen width.
Definition: eda_text.h:152
BOARD * m_pcb
Definition: drc.h:218
void addMarkerToPcb(MARKER_PCB *aMarker)
Adds a DRC marker to the PCB through the COMMIT mechanism.
Definition: drc.cpp:98
double ArcTangente(int dy, int dx)
Definition: trigo.cpp:170
#define DRCE_VIA_INSIDE_TEXT
Via in inside a text area.
Definition: drc.h:84
#define DRCE_PAD_INSIDE_TEXT
Pad in inside a text area.
Definition: drc.h:86
MARKER_PCB * m_currentMarker
Definition: drc.h:181
Definition: seg.h:36
bool checkClearanceSegmToPad(const D_PAD *aPad, int aSegmentWidth, int aMinDist)
Check the distance from a pad to segment.
const std::vector< D_PAD * > GetPads()
Function GetPads returns a reference to a list of all the pads.
wxPoint m_segmEnd
Definition: drc.h:199
TRACK * Next() const
Definition: class_track.h:99
void TransformTextShapeToSegmentList(std::vector< wxPoint > &aCornerBuffer) const
Convert the text shape to a list of segment each segment is stored as 2 wxPoints: the starting point ...
Definition: eda_text.cpp:479
int GetClearance(BOARD_CONNECTED_ITEM *aItem=NULL) const override
Function GetClearance returns the clearance in internal units.
Definition: class_pad.cpp:546
wxPoint ShapePos() const
Definition: class_pad.cpp:500
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
DLIST< TRACK > m_Track
Definition: class_board.h:248
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Function IsOnLayer tests to see if this object is on the given layer.
Definition: class_pad.h:650
double m_segmAngle
Definition: drc.h:206
DLIST_ITERATOR_WRAPPER< BOARD_ITEM > Drawings()
Definition: class_board.h:254
void DRC::testTracks ( wxWindow *  aActiveWindow,
bool  aShowProgressBar 
)
private

Perform the DRC on all tracks.

This test can take a while, a progress bar can be displayed

Parameters
aActiveWindow= the active window ued as parent for the progress bar
aShowProgressBar= true to show a progress bar (Note: it is shown only if there are many tracks)

Definition at line 712 of file drc.cpp.

References addMarkerToPcb(), delta, doTrackDrc(), m_currentMarker, m_pcb, BOARD::m_Track, and TRACK::Next().

Referenced by RunTests().

713 {
714  wxProgressDialog * progressDialog = NULL;
715  const int delta = 500; // This is the number of tests between 2 calls to the
716  // progress bar
717  int count = 0;
718 
719  for( TRACK* segm = m_pcb->m_Track; segm && segm->Next(); segm = segm->Next() )
720  count++;
721 
722  int deltamax = count/delta;
723 
724  if( aShowProgressBar && deltamax > 3 )
725  {
726  // Do not use wxPD_APP_MODAL style here: it is not necessary and create issues
727  // on OSX
728  progressDialog = new wxProgressDialog( _( "Track clearances" ), wxEmptyString,
729  deltamax, aActiveWindow,
730  wxPD_AUTO_HIDE | wxPD_CAN_ABORT | wxPD_ELAPSED_TIME );
731  progressDialog->Update( 0, wxEmptyString );
732  }
733 
734  int ii = 0;
735  count = 0;
736 
737  for( TRACK* segm = m_pcb->m_Track; segm; segm = segm->Next() )
738  {
739  if( ii++ > delta )
740  {
741  ii = 0;
742  count++;
743 
744  if( progressDialog )
745  {
746  if( !progressDialog->Update( count, wxEmptyString ) )
747  break; // Aborted by user
748 #ifdef __WXMAC__
749  // Work around a dialog z-order issue on OS X
750  if( count == deltamax )
751  aActiveWindow->Raise();
752 #endif
753  }
754  }
755 
756  if( !doTrackDrc( segm, segm->Next(), true ) )
757  {
758  if( m_currentMarker )
759  {
761  m_currentMarker = nullptr;
762  }
763  }
764  }
765 
766  if( progressDialog )
767  progressDialog->Destroy();
768 }
static const int delta[8][2]
Definition: solve.cpp:112
BOARD * m_pcb
Definition: drc.h:218
void addMarkerToPcb(MARKER_PCB *aMarker)
Adds a DRC marker to the PCB through the COMMIT mechanism.
Definition: drc.cpp:98
MARKER_PCB * m_currentMarker
Definition: drc.h:181
TRACK * Next() const
Definition: class_track.h:99
bool doTrackDrc(TRACK *aRefSeg, TRACK *aStart, bool doPads=true)
Test the current segment.
DLIST< TRACK > m_Track
Definition: class_board.h:248
void DRC::testUnconnected ( )
private

Definition at line 771 of file drc.cpp.

References DRCE_UNCONNECTED_ITEMS, BOARD::GetConnectivity(), m_pcb, and m_unconnected.

Referenced by ListUnconnectedPads(), and RunTests().

772 {
773 
774  auto connectivity = m_pcb->GetConnectivity();
775 
776  connectivity->Clear();
777  connectivity->Build( m_pcb ); // just in case. This really needs to be reliable.
778  connectivity->RecalculateRatsnest();
779 
780  std::vector<CN_EDGE> edges;
781  connectivity->GetUnconnectedEdges( edges );
782 
783  for( const auto& edge : edges )
784  {
785  wxString t_src = edge.GetSourceNode()->Parent()->GetSelectMenuText();
786  wxString t_dst = edge.GetTargetNode()->Parent()->GetSelectMenuText();
787  auto src = edge.GetSourcePos();
788  auto dst = edge.GetTargetPos();
789 
790 
791  DRC_ITEM* uncItem = new DRC_ITEM( DRCE_UNCONNECTED_ITEMS,
792  t_src,
793  t_dst,
794  wxPoint( src.x, src.y ), wxPoint( dst.x, dst.y ) );
795  m_unconnected.push_back( uncItem );
796 
797  }
798 }
Class DRC_ITEM is a holder for a DRC (in Pcbnew) or ERC (in Eeschema) error item. ...
Definition: drc_item.h:45
#define DRCE_UNCONNECTED_ITEMS
items are unconnected
Definition: drc.h:45
BOARD * m_pcb
Definition: drc.h:218
DRC_LIST m_unconnected
list of unconnected pads, as DRC_ITEMs
Definition: drc.h:221
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:293
void DRC::testZones ( )
private

Definition at line 801 of file drc.cpp.

References addMarkerToPcb(), DRCE_SUSPICIOUS_NET_FOR_ZONE_OUTLINE, fillMarker(), BOARD::GetArea(), BOARD::GetAreaCount(), BOARD::GetConnectivity(), BOARD_CONNECTED_ITEM::GetNetCode(), ZONE_CONTAINER::IsOnCopperLayer(), m_currentMarker, m_pcb, and TestZoneToZoneOutline().

Referenced by RunTests().

802 {
803  // Test copper areas for valid netcodes
804  // if a netcode is < 0 the netname was not found when reading a netlist
805  // if a netcode is == 0 the netname is void, and the zone is not connected.
806  // This is allowed, but i am not sure this is a good idea
807  //
808  // In recent Pcbnew versions, the netcode is always >= 0, but an internal net name
809  // is stored, and initialized from the file or the zone properties editor.
810  // if it differs from the net name from net code, there is a DRC issue
811  for( int ii = 0; ii < m_pcb->GetAreaCount(); ii++ )
812  {
813  ZONE_CONTAINER* test_area = m_pcb->GetArea( ii );
814 
815  if( !test_area->IsOnCopperLayer() )
816  continue;
817 
818  int netcode = test_area->GetNetCode();
819 
820  // a netcode < 0 or > 0 and no pad in net is a error or strange
821  // perhaps a "dead" net, which happens when all pads in this net were removed
822  // Remark: a netcode < 0 should not happen (this is more a bug somewhere)
823  int pads_in_net = (test_area->GetNetCode() > 0) ?
824  m_pcb->GetConnectivity()->GetPadCount( test_area->GetNetCode() ) : 1;
825 
826  if( ( netcode < 0 ) || pads_in_net == 0 )
827  {
828  addMarkerToPcb( fillMarker( test_area,
830  m_currentMarker = nullptr;
831  }
832  }
833 
834  // Test copper areas outlines, and create markers when needed
835  TestZoneToZoneOutline( NULL, true );
836 }
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
MARKER_PCB * fillMarker(const TRACK *aTrack, BOARD_ITEM *aItem, int aErrorCode, MARKER_PCB *fillMe)
Creates a marker and fills it in with information but does not add it to the BOARD.
int TestZoneToZoneOutline(ZONE_CONTAINER *aZone, bool aCreateMarkers)
Tests whether distance between zones complies with the DRC rules.
Definition: drc.cpp:213
#define DRCE_SUSPICIOUS_NET_FOR_ZONE_OUTLINE
copper area has a net but no pads in nets, which is suspicious
Definition: drc.h:67
BOARD * m_pcb
Definition: drc.h:218
void addMarkerToPcb(MARKER_PCB *aMarker)
Adds a DRC marker to the PCB through the COMMIT mechanism.
Definition: drc.cpp:98
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:1015
int GetNetCode() const
Function GetNetCode.
MARKER_PCB * m_currentMarker
Definition: drc.h:181
bool IsOnCopperLayer() const
Function IsOnCopperLayer.
Definition: class_zone.cpp:181
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:986
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:293
int DRC::TestZoneToZoneOutline ( ZONE_CONTAINER aZone,
bool  aCreateMarkers 
)

Tests whether distance between zones complies with the DRC rules.

Parameters
aZonezone to compare with other zones, or if NULL then all zones are compared to all others.
aCreateMarkersif true create DRC markers. False: do not create markers. only fing drc errors
Returns
Errors count

Definition at line 213 of file drc.cpp.

References SEG::A, COMMIT::Add(), SEG::B, ZONE_CONTAINER::BuildSmoothedPoly(), SHAPE_POLY_SET::Contains(), COPPERAREA_CLOSE_TO_COPPERAREA, COPPERAREA_INSIDE_COPPERAREA, BOARD::GetArea(), BOARD::GetAreaCount(), PCB_BASE_FRAME::GetBoard(), ZONE_CONTAINER::GetClearance(), GetClearanceBetweenSegments(), ZONE_CONTAINER::GetIsKeepout(), ZONE_CONTAINER::GetLayer(), BOARD_CONNECTED_ITEM::GetNetCode(), ZONE_CONTAINER::GetPriority(), ZONE_CONTAINER::GetSelectMenuText(), ZONE_CONTAINER::IsOnCopperLayer(), SHAPE_POLY_SET::IterateSegmentsWithHoles(), SHAPE_POLY_SET::IterateWithHoles(), m_pcbEditorFrame, BOARD_COMMIT::Push(), wxPoint::x, VECTOR2< T >::x, wxPoint::y, and VECTOR2< T >::y.

Referenced by PCB_EDIT_FRAME::duplicateZone(), PCB_EDIT_FRAME::End_Move_Zone_Corner_Or_Outlines(), PCB_EDIT_FRAME::End_Zone(), PCB_EDIT_FRAME::Remove_Zone_Corner(), and testZones().

214 {
215  BOARD* board = m_pcbEditorFrame->GetBoard();
216  BOARD_COMMIT commit( m_pcbEditorFrame );
217  int nerrors = 0;
218 
219  // iterate through all areas
220  for( int ia = 0; ia < board->GetAreaCount(); ia++ )
221  {
222  ZONE_CONTAINER* zoneRef = board->GetArea( ia );
223  SHAPE_POLY_SET refSmoothedPoly;
224 
225  zoneRef->BuildSmoothedPoly( refSmoothedPoly );
226 
227  if( !zoneRef->IsOnCopperLayer() )
228  continue;
229 
230  // When testing only a single area, skip all others
231  if( aZone && ( aZone != zoneRef) )
232  continue;
233 
234  for( int ia2 = 0; ia2 < board->GetAreaCount(); ia2++ )
235  {
236  ZONE_CONTAINER* zoneToTest = board->GetArea( ia2 );
237  SHAPE_POLY_SET testSmoothedPoly;
238 
239  zoneToTest->BuildSmoothedPoly( testSmoothedPoly );
240 
241  if( zoneRef == zoneToTest )
242  continue;
243 
244  // test for same layer
245  if( zoneRef->GetLayer() != zoneToTest->GetLayer() )
246  continue;
247 
248  // Test for same net
249  if( zoneRef->GetNetCode() == zoneToTest->GetNetCode() && zoneRef->GetNetCode() >= 0 )
250  continue;
251 
252  // test for different priorities
253  if( zoneRef->GetPriority() != zoneToTest->GetPriority() )
254  continue;
255 
256  // test for different types
257  if( zoneRef->GetIsKeepout() != zoneToTest->GetIsKeepout() )
258  continue;
259 
260  // Examine a candidate zone: compare zoneToTest to zoneRef
261 
262  // Get clearance used in zone to zone test. The policy used to
263  // obtain that value is now part of the zone object itself by way of
264  // ZONE_CONTAINER::GetClearance().
265  int zone2zoneClearance = zoneRef->GetClearance( zoneToTest );
266 
267  // Keepout areas have no clearance, so set zone2zoneClearance to 1
268  // ( zone2zoneClearance = 0 can create problems in test functions)
269  if( zoneRef->GetIsKeepout() )
270  zone2zoneClearance = 1;
271 
272  // test for some corners of zoneRef inside zoneToTest
273  for( auto iterator = refSmoothedPoly.IterateWithHoles(); iterator; iterator++ )
274  {
275  VECTOR2I currentVertex = *iterator;
276 
277  if( testSmoothedPoly.Contains( currentVertex ) )
278  {
279  // COPPERAREA_COPPERAREA error: copper area ref corner inside copper area
280  if( aCreateMarkers )
281  {
282  wxPoint pt( currentVertex.x, currentVertex.y );
283  wxString msg1 = zoneRef->GetSelectMenuText();
284  wxString msg2 = zoneToTest->GetSelectMenuText();
286  pt, msg1, pt, msg2, pt );
287  commit.Add( marker );
288  }
289 
290  nerrors++;
291  }
292  }
293 
294  // test for some corners of zoneToTest inside zoneRef
295  for( auto iterator = testSmoothedPoly.IterateWithHoles(); iterator; iterator++ )
296  {
297  VECTOR2I currentVertex = *iterator;
298 
299  if( refSmoothedPoly.Contains( currentVertex ) )
300  {
301  // COPPERAREA_COPPERAREA error: copper area corner inside copper area ref
302  if( aCreateMarkers )
303  {
304  wxPoint pt( currentVertex.x, currentVertex.y );
305  wxString msg1 = zoneToTest->GetSelectMenuText();
306  wxString msg2 = zoneRef->GetSelectMenuText();
308  pt, msg1, pt, msg2, pt );
309  commit.Add( marker );
310  }
311 
312  nerrors++;
313  }
314  }
315 
316  // Iterate through all the segments of refSmoothedPoly
317  for( auto refIt = refSmoothedPoly.IterateSegmentsWithHoles(); refIt; refIt++ )
318  {
319  // Build ref segment
320  SEG refSegment = *refIt;
321 
322  // Iterate through all the segments in testSmoothedPoly
323  for( auto testIt = testSmoothedPoly.IterateSegmentsWithHoles(); testIt; testIt++ )
324  {
325  // Build test segment
326  SEG testSegment = *testIt;
327  wxPoint pt;
328 
329  int ax1, ay1, ax2, ay2;
330  ax1 = refSegment.A.x;
331  ay1 = refSegment.A.y;
332  ax2 = refSegment.B.x;
333  ay2 = refSegment.B.y;
334 
335  int bx1, by1, bx2, by2;
336  bx1 = testSegment.A.x;
337  by1 = testSegment.A.y;
338  bx2 = testSegment.B.x;
339  by2 = testSegment.B.y;
340 
341  int d = GetClearanceBetweenSegments( bx1, by1, bx2, by2,
342  0,
343  ax1, ay1, ax2, ay2,
344  0,
345  zone2zoneClearance,
346  &pt.x, &pt.y );
347 
348  if( d < zone2zoneClearance )
349  {
350  // COPPERAREA_COPPERAREA error : intersect or too close
351  if( aCreateMarkers )
352  {
353  wxString msg1 = zoneRef->GetSelectMenuText();
354  wxString msg2 = zoneToTest->GetSelectMenuText();
356  pt, msg1, pt, msg2, pt );
357  commit.Add( marker );
358  }
359 
360  nerrors++;
361  }
362  }
363  }
364  }
365  }
366 
367  if( aCreateMarkers )
368  commit.Push( wxEmptyString, false, false );
369 
370  return nerrors;
371 }
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
wxString GetSelectMenuText() const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
SEGMENT_ITERATOR IterateSegmentsWithHoles()
Returns an iterator object, for all outlines in the set (with holes)
virtual PCB_LAYER_ID GetLayer() const override
Function GetLayer returns the primary layer this item is on.
Definition: class_zone.cpp:175
bool BuildSmoothedPoly(SHAPE_POLY_SET &aSmoothedPoly) const
Function GetSmoothedPoly returns a pointer to the corner-smoothed version of m_Poly if it exists...
bool Contains(const VECTOR2I &aP, int aSubpolyIndex=-1, bool aIgnoreHoles=false) const
Returns true if a given subpolygon contains the point aP.
#define COPPERAREA_INSIDE_COPPERAREA
copper area outlines intersect
Definition: drc.h:65
BOARD * GetBoard() const
int GetClearanceBetweenSegments(int x1i, int y1i, int x1f, int y1f, int w1, int x2i, int y2i, int x2f, int y2f, int w2, int max_cl, int *x, int *y)
int GetClearance(BOARD_CONNECTED_ITEM *aItem=NULL) const override
Function GetClearance returns the clearance in internal units.
Definition: class_zone.cpp:780
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:602
#define COPPERAREA_CLOSE_TO_COPPERAREA
copper area outlines are too close
Definition: drc.h:66
ITERATOR IterateWithHoles(int aOutline)
Function IterateWithHoles.
Class SHAPE_POLY_SET.
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:1015
PCB_EDIT_FRAME * m_pcbEditorFrame
The pcb frame editor which owns the board.
Definition: drc.h:217
int GetNetCode() const
Function GetNetCode.
Definition: seg.h:36
bool IsOnCopperLayer() const
Function IsOnCopperLayer.
Definition: class_zone.cpp:181
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:986
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
VECTOR2I A
Definition: seg.h:46
unsigned GetPriority() const
Function GetPriority.
Definition: class_zone.h:101
VECTOR2I B
Definition: seg.h:47
void DRC::updatePointers ( )
private

Update needed pointers from the one pointer which is known not to change.

Definition at line 538 of file drc.cpp.

References PCB_BASE_FRAME::GetBoard(), DIALOG_DRC_CONTROL_BASE::m_ClearanceListBox, m_drcDialog, m_pcb, m_pcbEditorFrame, m_unconnected, DIALOG_DRC_CONTROL_BASE::m_UnconnectedListBox, DRCLISTBOX::SetList(), and DIALOG_DRC_CONTROL::UpdateDisplayedCounts().

Referenced by DrcOnCreatingTrack(), DrcOnCreatingZone(), ListUnconnectedPads(), RunTests(), and ShowDRCDialog().

539 {
540  // update my pointers, m_pcbEditorFrame is the only unchangeable one
542 
543  if( m_drcDialog ) // Use diag list boxes only in DRC dialog
544  {
547 
549  }
550 }
DIALOG_DRC_CONTROL * m_drcDialog
Definition: drc.h:219
void UpdateDisplayedCounts()
Definition: dialog_drc.cpp:760
void SetList(DRC_ITEM_LIST *aList)
Function SetList sets the DRC_ITEM_LIST for this listbox.
BOARD * GetBoard() const
DRCLISTBOX * m_UnconnectedListBox
BOARD * m_pcb
Definition: drc.h:218
DRCLISTBOX * m_ClearanceListBox
Class DRC_LIST_MARKERS is an implementation of the interface named DRC_ITEM_LIST which uses a BOARD i...
PCB_EDIT_FRAME * m_pcbEditorFrame
The pcb frame editor which owns the board.
Definition: drc.h:217
Class DRC_LIST_UNCONNECTED is an implementation of the interface named DRC_ITEM_LIST which uses a vec...
DRC_LIST m_unconnected
list of unconnected pads, as DRC_ITEMs
Definition: drc.h:221

Friends And Related Function Documentation

friend class DIALOG_DRC_CONTROL
friend

Definition at line 164 of file drc.h.

Referenced by ShowDRCDialog().

Member Data Documentation

bool DRC::m_abortDRC
private

Definition at line 183 of file drc.h.

Referenced by DRC().

bool DRC::m_doCreateRptFile
private

Definition at line 173 of file drc.h.

Referenced by DestroyDRCDialog(), DRC(), and ShowDRCDialog().

bool DRC::m_doFootprintOverlapping
private

Definition at line 174 of file drc.h.

Referenced by doFootprintOverlappingDrc(), DRC(), and RunTests().

bool DRC::m_doKeepoutTest
private

Definition at line 172 of file drc.h.

Referenced by DRC(), and RunTests().

bool DRC::m_doNoCourtyardDefined
private

Definition at line 175 of file drc.h.

Referenced by doFootprintOverlappingDrc(), DRC(), and RunTests().

bool DRC::m_doPad2PadTest
private

Definition at line 169 of file drc.h.

Referenced by DRC(), and RunTests().

bool DRC::m_doUnconnectedTest
private

Definition at line 170 of file drc.h.

Referenced by DRC(), and RunTests().

bool DRC::m_doZonesTest
private

Definition at line 171 of file drc.h.

Referenced by DRC().

DIALOG_DRC_CONTROL* DRC::m_drcDialog
private

Definition at line 219 of file drc.h.

Referenced by DestroyDRCDialog(), DRC(), ShowDRCDialog(), and updatePointers().

bool DRC::m_drcInLegacyRoutingMode
private

in legacy canvas, when creating a track, the drc test must only display the error message, and do not create a DRC marker.

if m_drcInLegacyRoutingMode it true only the message will be displayed m_drcInLegacyRoutingMode = false is the normal Drc mode

Definition at line 192 of file drc.h.

Referenced by addMarkerToPcb(), doTrackDrc(), DRC(), DrcOnCreatingTrack(), and DrcOnCreatingZone().

bool DRC::m_drcInProgress
private

Definition at line 184 of file drc.h.

Referenced by DRC().

wxPoint DRC::m_padToTestPos
private

Definition at line 198 of file drc.h.

Referenced by checkClearancePadToPad(), checkClearanceSegmToPad(), doTrackDrc(), and testTexts().

PCB_EDIT_FRAME* DRC::m_pcbEditorFrame
private

The pcb frame editor which owns the board.

Definition at line 217 of file drc.h.

Referenced by addMarkerToPcb(), doTrackDrc(), DRC(), DrcOnCreatingTrack(), DrcOnCreatingZone(), RunTests(), ShowDRCDialog(), TestZoneToZoneOutline(), and updatePointers().

bool DRC::m_refillZones
private

Definition at line 176 of file drc.h.

Referenced by DRC(), and RunTests().

bool DRC::m_reportAllTrackErrors
private

Definition at line 177 of file drc.h.

Referenced by doTrackDrc(), DRC(), DrcOnCreatingTrack(), and DrcOnCreatingZone().

wxString DRC::m_rptFilename
private

Definition at line 179 of file drc.h.

Referenced by DestroyDRCDialog(), and ShowDRCDialog().

double DRC::m_segmAngle
private

Definition at line 206 of file drc.h.

Referenced by checkClearancePadToPad(), checkClearanceSegmToPad(), doTrackDrc(), DRC(), and testTexts().

wxPoint DRC::m_segmEnd
private

Definition at line 199 of file drc.h.

Referenced by checkClearancePadToPad(), checkClearanceSegmToPad(), doTrackDrc(), and testTexts().

int DRC::m_segmLength
private

Definition at line 207 of file drc.h.

Referenced by checkClearancePadToPad(), checkClearanceSegmToPad(), doTrackDrc(), DRC(), and testTexts().

DRC_LIST DRC::m_unconnected
private

list of unconnected pads, as DRC_ITEMs

Definition at line 221 of file drc.h.

Referenced by testUnconnected(), updatePointers(), and ~DRC().

int DRC::m_xcliphi
private

Definition at line 214 of file drc.h.

Referenced by checkClearanceSegmToPad(), checkLine(), doTrackDrc(), and DRC().

int DRC::m_xcliplo
private

Definition at line 212 of file drc.h.

Referenced by checkClearanceSegmToPad(), checkLine(), doTrackDrc(), and DRC().

int DRC::m_ycliphi
private

Definition at line 215 of file drc.h.

Referenced by checkClearanceSegmToPad(), checkLine(), doTrackDrc(), and DRC().

int DRC::m_ycliplo
private

Definition at line 213 of file drc.h.

Referenced by checkClearanceSegmToPad(), checkLine(), doTrackDrc(), and DRC().


The documentation for this class was generated from the following files: