KiCad PCB EDA Suite
DRC_MARKER_FACTORY Class Reference

Class that constructs DRC markers of various kinds with messages according to items and error code. More...

#include <drc_marker_factory.h>

Public Types

using UNITS_PROVIDER = std::function< EDA_UNITS_T()>
 

Public Member Functions

 DRC_MARKER_FACTORY ()
 
void SetUnitsProvider (UNITS_PROVIDER aUnitsProvider)
 Set the provider for the units (this will be called for each new marker constructed) More...
 
void SetUnits (EDA_UNITS_T aUnits)
 Set the units provider to a function returning a constant value. More...
 
MARKER_PCBNewMarker (TRACK *aTrack, BOARD_ITEM *aConflitItem, const SEG &aConflictSeg, int aErrorCode) const
 Creates a marker on a track, via or pad. More...
 
MARKER_PCBNewMarker (TRACK *aTrack, ZONE_CONTAINER *aConflictZone, int aErrorCode) const
 
MARKER_PCBNewMarker (D_PAD *aPad, BOARD_ITEM *aConflictItem, int aErrorCode) const
 
MARKER_PCBNewMarker (const wxPoint &aPos, BOARD_ITEM *aItem, int aErrorCode) const
 Creates a marker at a given location. More...
 
MARKER_PCBNewMarker (const wxPoint &aPos, BOARD_ITEM *aItem, BOARD_ITEM *bItem, int aErrorCode) const
 
MARKER_PCBNewMarker (int aErrorCode, const wxString &aMessage) const
 Create a MARKER which will report on a generic problem with the board which is not geographically locatable. More...
 

Private Member Functions

EDA_UNITS_T getCurrentUnits () const
 

Private Attributes

UNITS_PROVIDER m_units_provider
 

Detailed Description

Class that constructs DRC markers of various kinds with messages according to items and error code.

Definition at line 42 of file drc_marker_factory.h.

Member Typedef Documentation

◆ UNITS_PROVIDER

Definition at line 45 of file drc_marker_factory.h.

Constructor & Destructor Documentation

◆ DRC_MARKER_FACTORY()

DRC_MARKER_FACTORY::DRC_MARKER_FACTORY ( )

Definition at line 48 of file drc_marker_factory.cpp.

49 {
51 }
void SetUnits(EDA_UNITS_T aUnits)
Set the units provider to a function returning a constant value.

References MILLIMETRES, and SetUnits().

Member Function Documentation

◆ getCurrentUnits()

EDA_UNITS_T DRC_MARKER_FACTORY::getCurrentUnits ( ) const
inlineprivate

Definition at line 96 of file drc_marker_factory.h.

97  {
98  return m_units_provider();
99  }
UNITS_PROVIDER m_units_provider

References m_units_provider.

Referenced by NewMarker().

◆ NewMarker() [1/6]

MARKER_PCB * DRC_MARKER_FACTORY::NewMarker ( TRACK aTrack,
BOARD_ITEM aConflitItem,
const SEG aConflictSeg,
int  aErrorCode 
) const

Creates a marker on a track, via or pad.

Parameters
aTrack/aPadThe reference item.
aConflitItemAnother item on the board which is in conflict with the reference item.
aErrorCodeAn ID for the particular type of error that is being reported.

Definition at line 104 of file drc_marker_factory.cpp.

106 {
107  wxPoint markerPos;
108  wxPoint pt1 = aTrack->GetPosition();
109  wxPoint pt2 = aTrack->GetEnd();
110 
111  // Do a binary search along the track for a "good enough" marker location
112  while( GetLineLength( pt1, pt2 ) > EPSILON )
113  {
114  if( aConflictSeg.Distance( pt1 ) < aConflictSeg.Distance( pt2 ) )
115  pt2 = ( pt1 + pt2 ) / 2;
116  else
117  pt1 = ( pt1 + pt2 ) / 2;
118  }
119 
120  // Once we're within EPSILON pt1 and pt2 are "equivalent"
121  markerPos = pt1;
122 
123  return new MARKER_PCB( getCurrentUnits(), aErrorCode, markerPos, aTrack, aTrack->GetPosition(),
124  aConflitItem, aConflitItem->GetPosition() );
125 }
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:199
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:200
const int EPSILON
const wxPoint GetPosition() const override
Definition: class_track.h:124
virtual const wxPoint GetPosition() const =0
const wxPoint & GetEnd() const
Definition: class_track.h:130
EDA_UNITS_T getCurrentUnits() const

References SEG::Distance(), EPSILON, getCurrentUnits(), TRACK::GetEnd(), GetLineLength(), BOARD_ITEM::GetPosition(), and TRACK::GetPosition().

Referenced by DRC::doEdgeZoneDrc(), DRC::doNetClass(), DRC::doPadToPadsDrc(), DRC::doTrackDrc(), DRC::doTrackKeepoutDrc(), DRC_COURTYARD_OVERLAP::RunDRC(), DRC::testCopperDrawItem(), DRC::testCopperTextItem(), DRC::testDisabledLayers(), DRC::testKeepoutAreas(), DRC::testOutline(), DRC::testZones(), and DRC::TestZoneToZoneOutline().

◆ NewMarker() [2/6]

MARKER_PCB * DRC_MARKER_FACTORY::NewMarker ( TRACK aTrack,
ZONE_CONTAINER aConflictZone,
int  aErrorCode 
) const

Definition at line 66 of file drc_marker_factory.cpp.

68 {
69  SHAPE_POLY_SET* conflictOutline;
70 
71  if( aConflictZone->IsFilled() )
72  conflictOutline = const_cast<SHAPE_POLY_SET*>( &aConflictZone->GetFilledPolysList() );
73  else
74  conflictOutline = aConflictZone->Outline();
75 
76  wxPoint markerPos;
77  wxPoint pt1 = aTrack->GetPosition();
78  wxPoint pt2 = aTrack->GetEnd();
79 
80  // If the mid-point is in the zone, then that's a fine place for the marker
81  if( conflictOutline->Distance( ( pt1 + pt2 ) / 2 ) == 0 )
82  markerPos = ( pt1 + pt2 ) / 2;
83 
84  // Otherwise do a binary search for a "good enough" marker location
85  else
86  {
87  while( GetLineLength( pt1, pt2 ) > EPSILON )
88  {
89  if( conflictOutline->Distance( pt1 ) < conflictOutline->Distance( pt2 ) )
90  pt2 = ( pt1 + pt2 ) / 2;
91  else
92  pt1 = ( pt1 + pt2 ) / 2;
93  }
94 
95  // Once we're within EPSILON pt1 and pt2 are "equivalent"
96  markerPos = pt1;
97  }
98 
99  return new MARKER_PCB( getCurrentUnits(), aErrorCode, markerPos, aTrack, aTrack->GetPosition(),
100  aConflictZone, aConflictZone->GetPosition() );
101 }
bool IsFilled() const
Definition: class_zone.h:187
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:200
SHAPE_POLY_SET * Outline()
Definition: class_zone.h:260
const wxPoint GetPosition() const override
Definition: class_zone.cpp:179
const int EPSILON
const wxPoint GetPosition() const override
Definition: class_track.h:124
Class SHAPE_POLY_SET.
int Distance(VECTOR2I aPoint)
Function DistanceToPolygon computes the minimum distance between aPoint and all the polygons in the s...
const wxPoint & GetEnd() const
Definition: class_track.h:130
EDA_UNITS_T getCurrentUnits() const
const SHAPE_POLY_SET & GetFilledPolysList() const
Function GetFilledPolysList returns a reference to the list of filled polygons.
Definition: class_zone.h:580

References SHAPE_POLY_SET::Distance(), EPSILON, getCurrentUnits(), TRACK::GetEnd(), ZONE_CONTAINER::GetFilledPolysList(), GetLineLength(), ZONE_CONTAINER::GetPosition(), TRACK::GetPosition(), ZONE_CONTAINER::IsFilled(), and ZONE_CONTAINER::Outline().

◆ NewMarker() [3/6]

MARKER_PCB * DRC_MARKER_FACTORY::NewMarker ( D_PAD aPad,
BOARD_ITEM aConflictItem,
int  aErrorCode 
) const

Definition at line 128 of file drc_marker_factory.cpp.

130 {
131  return new MARKER_PCB( getCurrentUnits(), aErrorCode, aPad->GetPosition(), aPad,
132  aPad->GetPosition(), aConflictItem, aConflictItem->GetPosition() );
133 }
virtual const wxPoint GetPosition() const =0
const wxPoint GetPosition() const override
Definition: class_pad.h:222
EDA_UNITS_T getCurrentUnits() const

References getCurrentUnits(), BOARD_ITEM::GetPosition(), and D_PAD::GetPosition().

◆ NewMarker() [4/6]

MARKER_PCB * DRC_MARKER_FACTORY::NewMarker ( const wxPoint &  aPos,
BOARD_ITEM aItem,
int  aErrorCode 
) const

Creates a marker at a given location.

Parameters
aItemThe reference item.
aPosUsually the position of the item, but could be more specific for a zone.
aErrorCodeAn ID for the particular type of error that is being reported.

Definition at line 136 of file drc_marker_factory.cpp.

138 {
139  return new MARKER_PCB(
140  getCurrentUnits(), aErrorCode, aPos, aItem, aPos, nullptr, wxPoint() );
141 }
EDA_UNITS_T getCurrentUnits() const

References getCurrentUnits().

◆ NewMarker() [5/6]

MARKER_PCB * DRC_MARKER_FACTORY::NewMarker ( const wxPoint &  aPos,
BOARD_ITEM aItem,
BOARD_ITEM bItem,
int  aErrorCode 
) const

Definition at line 144 of file drc_marker_factory.cpp.

146 {
147  return new MARKER_PCB( getCurrentUnits(), aErrorCode, aPos, aItem, aItem->GetPosition(), bItem,
148  bItem->GetPosition() );
149 }
virtual const wxPoint GetPosition() const =0
EDA_UNITS_T getCurrentUnits() const

References getCurrentUnits(), and BOARD_ITEM::GetPosition().

◆ NewMarker() [6/6]

MARKER_PCB * DRC_MARKER_FACTORY::NewMarker ( int  aErrorCode,
const wxString &  aMessage 
) const

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

Definition at line 152 of file drc_marker_factory.cpp.

153 {
154  MARKER_PCB* marker = new MARKER_PCB( aErrorCode, wxPoint(), aMessage, wxPoint() );
155 
156  marker->SetShowNoCoordinate();
157 
158  return marker;
159 }
void SetShowNoCoordinate()
Definition: marker_base.h:232

References MARKER_BASE::SetShowNoCoordinate().

◆ SetUnits()

void DRC_MARKER_FACTORY::SetUnits ( EDA_UNITS_T  aUnits)

Set the units provider to a function returning a constant value.

This is a shorthand for #SetUnitProvider.

Definition at line 60 of file drc_marker_factory.cpp.

61 {
62  m_units_provider = [=]() { return aUnits; };
63 }
UNITS_PROVIDER m_units_provider

References m_units_provider.

Referenced by DRC_MARKER_FACTORY().

◆ SetUnitsProvider()

void DRC_MARKER_FACTORY::SetUnitsProvider ( UNITS_PROVIDER  aUnitsProvider)

Set the provider for the units (this will be called for each new marker constructed)

Parameters
aUnitsProvidera callable that returns the current units to use

Definition at line 54 of file drc_marker_factory.cpp.

55 {
56  m_units_provider = aUnitsProvider;
57 }
UNITS_PROVIDER m_units_provider

References m_units_provider.

Referenced by DRC::DRC().

Member Data Documentation

◆ m_units_provider

UNITS_PROVIDER DRC_MARKER_FACTORY::m_units_provider
private

Definition at line 101 of file drc_marker_factory.h.

Referenced by getCurrentUnits(), SetUnits(), and SetUnitsProvider().


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