KiCad PCB EDA Suite
DRC_COURTYARD_OVERLAP Class Reference

A class that provides the courtyard-based DRC checks. More...

#include <courtyard_overlap.h>

Inheritance diagram for DRC_COURTYARD_OVERLAP:
DRC_PROVIDER

Public Types

using MARKER_HANDLER = std::function< void(MARKER_PCB *)>
 A callable that can handle a single generated PCB_MARKER. More...
 

Public Member Functions

 DRC_COURTYARD_OVERLAP (const DRC_MARKER_FACTORY &aMarkerFactory, MARKER_HANDLER aMarkerHandler)
 
bool RunDRC (BOARD &aBoard) const override
 Runs this provider against the given PCB with configured options (if any). More...
 

Protected Member Functions

const DRC_MARKER_FACTORYGetMarkerFactory () const
 Access to the stored reference to a marker constructor. More...
 
void HandleMarker (std::unique_ptr< MARKER_PCB > aMarker) const
 Pass a given marker to the marker handler. More...
 

Detailed Description

A class that provides the courtyard-based DRC checks.

Definition at line 35 of file courtyard_overlap.h.

Member Typedef Documentation

◆ MARKER_HANDLER

using DRC_PROVIDER::MARKER_HANDLER = std::function<void( MARKER_PCB* )>
inherited

A callable that can handle a single generated PCB_MARKER.

Definition at line 46 of file drc_provider.h.

Constructor & Destructor Documentation

◆ DRC_COURTYARD_OVERLAP()

DRC_COURTYARD_OVERLAP::DRC_COURTYARD_OVERLAP ( const DRC_MARKER_FACTORY aMarkerFactory,
MARKER_HANDLER  aMarkerHandler 
)

Definition at line 49 of file courtyard_overlap.cpp.

51  : DRC_PROVIDER( aMarkerFactory, aMarkerHandler )
52 {
53 }
DRC_PROVIDER(const DRC_MARKER_FACTORY &aMarkerMaker, MARKER_HANDLER aMarkerHandler)

Member Function Documentation

◆ GetMarkerFactory()

const DRC_MARKER_FACTORY & DRC_PROVIDER::GetMarkerFactory ( ) const
protectedinherited

Access to the stored reference to a marker constructor.

Definition at line 33 of file drc_provider.cpp.

34 {
35  return m_marker_factory;
36 }
const DRC_MARKER_FACTORY & m_marker_factory
A marker generator to make markers in the right context.
Definition: drc_provider.h:78

References DRC_PROVIDER::m_marker_factory.

Referenced by RunDRC().

◆ HandleMarker()

void DRC_PROVIDER::HandleMarker ( std::unique_ptr< MARKER_PCB aMarker) const
protectedinherited

Pass a given marker to the marker handler.

Definition at line 39 of file drc_provider.cpp.

40 {
41  // The marker hander currently takes a raw pointer,
42  // but it also assumes ownership
43  m_marker_handler( aMarker.release() );
44 }
MARKER_HANDLER m_marker_handler
The handler for any generated markers.
Definition: drc_provider.h:81

References DRC_PROVIDER::m_marker_handler.

Referenced by RunDRC().

◆ RunDRC()

bool DRC_COURTYARD_OVERLAP::RunDRC ( BOARD aBoard) const
overridevirtual

Runs this provider against the given PCB with configured options (if any).

Note: Board is non-const, as some DRC functions modify the board (e.g. zone fill or polygon coalescing)

Implements DRC_PROVIDER.

Definition at line 56 of file courtyard_overlap.cpp.

57 {
58  wxLogTrace( DRC_COURTYARD_TRACE, "Running DRC: Courtyard" );
59 
60  // Detects missing (or malformed) footprint courtyard,
61  // and for footprint with courtyard, courtyards overlap.
62  wxString msg;
63  bool success = true;
64 
65  const DRC_MARKER_FACTORY& marker_factory = GetMarkerFactory();
66 
67  // Update courtyard polygons, and test for missing courtyard definition:
68  for( auto footprint : aBoard.Modules() )
69  {
70  wxPoint pos = footprint->GetPosition();
71  bool is_ok = footprint->BuildPolyCourtyard();
72 
73  if( !is_ok && aBoard.GetDesignSettings().m_ProhibitOverlappingCourtyards )
74  {
75  auto marker = std::unique_ptr<MARKER_PCB>( marker_factory.NewMarker(
76  pos, footprint, DRCE_MALFORMED_COURTYARD_IN_FOOTPRINT ) );
77  HandleMarker( std::move( marker ) );
78  success = false;
79  }
80 
82  continue;
83 
84  if( footprint->GetPolyCourtyardFront().OutlineCount() == 0
85  && footprint->GetPolyCourtyardBack().OutlineCount() == 0 && is_ok )
86  {
87  auto marker = std::unique_ptr<MARKER_PCB>( marker_factory.NewMarker(
88  pos, footprint, DRCE_MISSING_COURTYARD_IN_FOOTPRINT ) );
89  HandleMarker( std::move( marker ) );
90  success = false;
91  }
92  }
93 
95  return success;
96 
97  wxLogTrace( DRC_COURTYARD_TRACE, "Checking for courtyard overlap" );
98 
99  // Now test for overlapping on top layer:
100  SHAPE_POLY_SET courtyard; // temporary storage of the courtyard of current footprint
101 
102  for( auto it1 = aBoard.Modules().begin(); it1 != aBoard.Modules().end(); it1++ )
103  {
104  auto footprint = *it1;
105 
106  if( footprint->GetPolyCourtyardFront().OutlineCount() == 0 )
107  continue; // No courtyard defined
108 
109  for( auto it2 = it1 + 1; it2 != aBoard.Modules().end(); it2++ )
110  {
111  auto candidate = *it2;
112 
113  if( candidate->GetPolyCourtyardFront().OutlineCount() == 0 )
114  continue; // No courtyard defined
115 
116  courtyard.RemoveAllContours();
117  courtyard.Append( footprint->GetPolyCourtyardFront() );
118 
119  // Build the common area between footprint and the candidate:
120  courtyard.BooleanIntersection(
121  candidate->GetPolyCourtyardFront(), SHAPE_POLY_SET::PM_FAST );
122 
123  // If no overlap, courtyard is empty (no common area).
124  // Therefore if a common polygon exists, this is a DRC error
125  if( courtyard.OutlineCount() )
126  {
127  //Overlap between footprint and candidate
128  VECTOR2I& pos = courtyard.Vertex( 0, 0, -1 );
129  auto marker = std::unique_ptr<MARKER_PCB>(
130  marker_factory.NewMarker( wxPoint( pos.x, pos.y ), footprint, candidate,
132  HandleMarker( std::move( marker ) );
133  success = false;
134  }
135  }
136  }
137 
138  // Test for overlapping on bottom layer:
139  for( auto it1 = aBoard.Modules().begin(); it1 != aBoard.Modules().end(); it1++ )
140  {
141  auto footprint = *it1;
142 
143  if( footprint->GetPolyCourtyardBack().OutlineCount() == 0 )
144  continue; // No courtyard defined
145 
146  for( auto it2 = it1 + 1; it2 != aBoard.Modules().end(); it2++ )
147  {
148  auto candidate = *it2;
149 
150  if( candidate->GetPolyCourtyardBack().OutlineCount() == 0 )
151  continue; // No courtyard defined
152 
153  courtyard.RemoveAllContours();
154  courtyard.Append( footprint->GetPolyCourtyardBack() );
155 
156  // Build the common area between footprint and the candidate:
157  courtyard.BooleanIntersection(
158  candidate->GetPolyCourtyardBack(), SHAPE_POLY_SET::PM_FAST );
159 
160  // If no overlap, courtyard is empty (no common area).
161  // Therefore if a common polygon exists, this is a DRC error
162  if( courtyard.OutlineCount() )
163  {
164  //Overlap between footprint and candidate
165  VECTOR2I& pos = courtyard.Vertex( 0, 0, -1 );
166  auto marker = std::unique_ptr<MARKER_PCB>(
167  marker_factory.NewMarker( wxPoint( pos.x, pos.y ), footprint, candidate,
169  HandleMarker( std::move( marker ) );
170  success = false;
171  }
172  }
173  }
174 
175  return success;
176 }
int OutlineCount() const
Returns the number of outlines in the set
const DRC_MARKER_FACTORY & GetMarkerFactory() const
Access to the stored reference to a marker constructor.
void HandleMarker(std::unique_ptr< MARKER_PCB > aMarker) const
Pass a given marker to the marker handler.
bool m_ProhibitOverlappingCourtyards
check for overlapping courtyards in DRC
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:540
#define DRCE_MALFORMED_COURTYARD_IN_FOOTPRINT
footprint has a courtyard but malformed
Definition: drc.h:92
#define DRCE_MISSING_COURTYARD_IN_FOOTPRINT
footprint has no courtyard defined
Definition: drc.h:91
VECTOR2I & Vertex(int aIndex, int aOutline, int aHole)
Returns the index-th vertex in a given hole outline within a given outline
Class that constructs DRC markers of various kinds with messages according to items and error code.
MODULES & Modules()
Definition: class_board.h:236
Class SHAPE_POLY_SET.
MARKER_PCB * NewMarker(TRACK *aTrack, BOARD_ITEM *aConflitItem, const SEG &aConflictSeg, int aErrorCode) const
Creates a marker on a track, via or pad.
#define DRCE_OVERLAPPING_FOOTPRINTS
footprint courtyards overlap
Definition: drc.h:90
void BooleanIntersection(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Performs boolean polyset intersection For aFastMode meaning, see function booleanOp
bool m_RequireCourtyards
require courtyard definitions in footprints
void RemoveAllContours()
Removes all outlines & holes (clears) the polygon set.
static const wxChar * DRC_COURTYARD_TRACE
Flag to enable courtyard DRC debug tracing.
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)

References SHAPE_POLY_SET::Append(), SHAPE_POLY_SET::BooleanIntersection(), DRC_COURTYARD_TRACE, DRCE_MALFORMED_COURTYARD_IN_FOOTPRINT, DRCE_MISSING_COURTYARD_IN_FOOTPRINT, DRCE_OVERLAPPING_FOOTPRINTS, BOARD::GetDesignSettings(), DRC_PROVIDER::GetMarkerFactory(), DRC_PROVIDER::HandleMarker(), BOARD_DESIGN_SETTINGS::m_ProhibitOverlappingCourtyards, BOARD_DESIGN_SETTINGS::m_RequireCourtyards, BOARD::Modules(), DRC_MARKER_FACTORY::NewMarker(), 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 DRC::doFootprintOverlappingDrc().


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