55 VECTOR2I& aMidpoint,
int& aDistance )
60 std::vector<PCB_SHAPE*> shapes;
62 for(
int ii = 0; ii < items.
GetCount(); ++ii )
67 shapes.push_back( shape );
70 int best = std::numeric_limits<int>::max();
74 for(
size_t ii = 0; ii < shapes.size(); ++ii )
76 std::shared_ptr<SHAPE> shapeA = shapes[ii]->GetEffectiveShape();
78 for(
size_t jj = ii + 1; jj < shapes.size(); ++jj )
80 std::shared_ptr<SHAPE> shapeB = shapes[jj]->GetEffectiveShape();
84 if( shapeA && shapeB && shapeA->NearestPoints( shapeB.get(), ptA, ptB ) )
86 int dist = ( ptA - ptB ).EuclideanNorm();
100 if( aItemA && aItemB )
103 aMidpoint = ( bestA + bestB ) / 2;
123 virtual bool Run()
override;
125 virtual const wxString
GetName()
const override {
return wxT(
"miscellaneous" ); };
141 bool errorHandled =
false;
152 std::swap( itemA, itemB );
161 shapeA =
static_cast<PCB_SHAPE*
>( itemA );
162 shapeB =
static_cast<PCB_SHAPE*
>( itemB );
172 if( shapeA && shapeB )
178 d[0] = ( pts0[0] - pts1[0] ).SquaredEuclideanNorm();
179 d[1] = ( pts0[0] - pts1[1] ).SquaredEuclideanNorm();
180 d[2] = ( pts0[1] - pts1[0] ).SquaredEuclideanNorm();
181 d[3] = ( pts0[1] - pts1[1] ).SquaredEuclideanNorm();
183 int idx = std::min_element( d, d + 4 ) - d;
184 gap = std::sqrt( d[idx] );
185 markerPos = ( pts0[idx / 2] + pts1[idx % 2] ) / 2;
196 drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS(
" " ) + msg2 );
197 drcItem->SetItems( itemA, itemB );
204 const int minSizeForValideGraphics =
pcbIUScale.mmToIU( 0.001 );
217 msg.Printf(
_(
"(Suspicious items found on Edge.Cuts layer)" ) );
219 drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS(
" " ) + msg );
229 int chainingEpsilon =
m_board->GetOutlinesChainingEpsilon();
245 msg.Printf(
_(
"(no edges found on Edge.Cuts layer)" ) );
247 drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS(
" " ) + msg );
258 const int progressDelta = 2000;
274 auto checkDisabledLayers =
292 if( disabledLayers.test(
pad->GetPrincipalLayer() ) )
293 badLayer = item->GetLayer();
306 via->LayerPair( &top, &bottom );
308 if( disabledLayers.test( top ) )
310 else if( disabledLayers.test( bottom ) )
320 LSET badLayers = disabledLayers & item->GetLayerSet();
322 if( badLayers.any() )
323 badLayer = badLayers.
Seq().front();
331 msg.Printf(
_(
"(layer %s)" ),
LayerName( badLayer ) );
333 drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS(
" " ) + msg );
334 drcItem->SetItems( item );
349 const int progressDelta = 2000;
360 auto checkAssertions =
372 drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS(
" (" )
374 drcItem->SetItems( item );
391 const int progressDelta = 2000;
395 static const std::vector<KICAD_T> itemTypes = {
404 static wxRegEx warningExpr( wxS(
"^\\$\\{DRC_WARNING\\s*([^}]*)\\}(.*)$" ) );
405 static wxRegEx errorExpr( wxS(
"^\\$\\{DRC_ERROR\\s*([^}]*)\\}(.*)$" ) );
407 if( warningExpr.Matches(
text ) )
412 wxString drcText = warningExpr.GetMatch(
text, 1 );
415 drcItem->SetItems( item );
417 drcText +=
_(
" (in drawing sheet)" );
419 drcItem->SetErrorMessage( drcText );
427 if( errorExpr.Matches(
text ) )
432 wxString drcText = errorExpr.GetMatch(
text, 1 );
435 drcItem->SetItems( item );
437 drcText +=
_(
" (in drawing sheet)" );
439 drcItem->SetErrorMessage( drcText );
471 if(
result.Matches( wxT(
"*${*}*" ) ) )
474 drcItem->SetItems( item );
497 drawItems.
BuildDrawItemsList( drawingSheet->GetPageInfo(), drawingSheet->GetTitleBlock() );
513 else if(
text->GetShownText(
true ).Matches( wxT(
"*${*}*" ) ) )
516 drcItem->SetItems( drawingSheet );
530 std::shared_ptr<NET_SETTINGS> netSettings =
m_board->GetProject()->GetProjectFile().NetSettings();
531 const std::shared_ptr<TUNING_PROFILES> tuningProfiles =
532 m_board->GetProject()->GetProjectFile().TuningProfileParameters();
534 std::set<wxString> profileNames;
535 std::ranges::for_each( tuningProfiles->GetTuningProfiles(),
538 if( const wxString name = tuningProfile.m_ProfileName; name != wxEmptyString )
539 profileNames.insert( name );
542 for(
const auto& [
name, netclass] : netSettings->GetNetclasses() )
547 const wxString profileName = netclass->GetTuningProfile();
549 if( netclass->HasTuningProfile() && !profileNames.contains( profileName ) )
552 wxString errMsg = wxString::Format(
"%s (Net Class: %s, Tuning Profile: %s)", drcItem->GetErrorText(),
name,
554 drcItem->SetErrorMessage( errMsg );
576 if( !
reportPhase(
_(
"Checking disabled layers..." ) ) )
602 if( !
reportPhase(
_(
"Checking for missing tuning profiles..." ) ) )
constexpr EDA_IU_SCALE pcbIUScale
BASE_SET & flip(size_t pos)
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Information pertinent to a Pcbnew printed circuit board.
int GetCount() const
Return the number of objects in the list.
DRC_RULE * GetParentRule() const
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
virtual const wxString GetName() const override
void testMissingTuningProfiles()
virtual ~DRC_TEST_PROVIDER_MISC()=default
void testDisabledLayers()
virtual bool Run() override
Run this provider against the given PCB with configured options (if any).
virtual bool reportPhase(const wxString &aStageName)
int forEachGeometryItem(const std::vector< KICAD_T > &aTypes, const LSET &aLayers, const std::function< bool(BOARD_ITEM *)> &aFunc)
void reportViolation(std::shared_ptr< DRC_ITEM > &item, const VECTOR2I &aMarkerPos, int aMarkerLayer, const std::function< void(PCB_MARKER *)> &aPathGenerator=[](PCB_MARKER *){})
static std::vector< KICAD_T > s_allBasicItems
virtual bool reportProgress(size_t aCount, size_t aSize, size_t aDelta=1)
Base class to handle basic graphic items.
Store the list of graphic items: rect, lines, polygons and texts to draw/plot the title block and fra...
DS_DRAW_ITEM_BASE * GetFirst()
void BuildDrawItemsList(const PAGE_INFO &aPageInfo, const TITLE_BLOCK &aTitleBlock)
Drawing or plot the drawing sheet.
void SetFileName(const wxString &aFileName)
Set the filename to draw/plot.
void SetSheetName(const wxString &aSheetName)
Set the sheet name to draw/plot.
void SetSheetLayer(const wxString &aSheetLayer)
Set the sheet layer to draw/plot.
void SetSheetCount(int aSheetCount)
Set the value of the count of sheets, for basic inscriptions.
void SetPageNumber(const wxString &aPageNumber)
Set the value of the sheet number.
DS_DRAW_ITEM_BASE * GetNext()
void SetProject(const PROJECT *aProject)
virtual VECTOR2I GetPosition() const
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
LSET is a set of PCB_LAYER_IDs.
LSEQ Seq(const LSEQ &aSequence) const
Return an LSEQ from the union of this LSET and a desired sequence.
static const LSET & AllLayersMask()
static LSET AllCuMask()
return AllCuMask( MAX_CU_LAYERS );
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Collect all BOARD_ITEM objects of a given set of KICAD_T type(s).
void Collect(BOARD_ITEM *aBoard, const std::vector< KICAD_T > &aTypes)
Collect BOARD_ITEM objects using this class's Inspector method, which does the collection.
VECTOR2I::extended_type ecoord
Represent a set of closed polygons.
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
#define FOR_ERC_DRC
Expand '${var-name}' templates in text.
bool TestBoardOutlinesGraphicItems(BOARD *aBoard, int aMinDist, OUTLINE_ERROR_HANDLER *aErrorHandler)
Test a board graphic items on edge cut layer for validity.
bool BuildBoardPolygonOutlines(BOARD *aBoard, SHAPE_POLY_SET &aOutlines, int aErrorMax, int aChainingEpsilon, OUTLINE_ERROR_HANDLER *aErrorHandler, bool aAllowUseArcsInPolygons)
Extract the board outlines and build a closed polygon from lines, arcs and circle items on edge cut l...
const std::function< void(const wxString &msg, BOARD_ITEM *itemA, BOARD_ITEM *itemB, const VECTOR2I &pt)> OUTLINE_ERROR_HANDLER
@ DRCE_DISABLED_LAYER_ITEM
@ DRCE_MISSING_TUNING_PROFILE
@ DRCE_UNRESOLVED_VARIABLE
static void findClosestOutlineGap(BOARD *aBoard, PCB_SHAPE *&aItemA, PCB_SHAPE *&aItemB, VECTOR2I &aMidpoint, int &aDistance)
wxString LayerName(int aLayer)
Returns the default display name for a given layer.
@ LAYER_DRAWINGSHEET
Sheet frame and title block.
PCB_LAYER_ID
A quick note on layer IDs:
static DRC_REGISTER_TEST_PROVIDER< DRC_TEST_PROVIDER_ANNULAR_WIDTH > dummy
@ SMD
Smd pad, appears on the solder paste layer (default)
@ CONN
Like smd, does not appear on the solder paste layer (default) Note: also has a special attribute in G...
Represents a single line in the tuning profile configuration grid.
wxString result
Test unit parsing edge cases and error handling.
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
@ PCB_ZONE_T
class ZONE, a copper pour area
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
@ PCB_TABLECELL_T
class PCB_TABLECELL, PCB_TEXTBOX for use in tables
@ PCB_PAD_T
class PAD, a pad in a footprint
@ PCB_DIMENSION_T
class PCB_DIMENSION_BASE: abstract dimension meta-type
VECTOR2< int32_t > VECTOR2I