KiCad PCB EDA Suite
drc_engine.cpp File Reference
#include <reporter.h>
#include <widgets/progress_reporter.h>
#include <kicad_string.h>
#include <drc/drc_engine.h>
#include <drc/drc_rule_parser.h>
#include <drc/drc_rule.h>
#include <drc/drc_rule_condition.h>
#include <drc/drc_test_provider.h>
#include <track.h>
#include <footprint.h>
#include <geometry/shape.h>
#include <geometry/shape_segment.h>
#include <geometry/shape_null.h>

Go to the source code of this file.

Macros

#define REPORT(s)   { if( aReporter ) { aReporter->Report( s ); } }
 
#define UNITS   aReporter ? aReporter->GetUnits() : EDA_UNITS::MILLIMETRES
 

Functions

void drcPrintDebugMessage (int level, const wxString &msg, const char *function, int line)
 
static bool isKeepoutZone (const BOARD_ITEM *aItem, bool aCheckFlags)
 
static wxString formatConstraint (const DRC_CONSTRAINT &constraint)
 

Macro Definition Documentation

◆ REPORT

#define REPORT (   s)    { if( aReporter ) { aReporter->Report( s ); } }

◆ UNITS

#define UNITS   aReporter ? aReporter->GetUnits() : EDA_UNITS::MILLIMETRES

Function Documentation

◆ drcPrintDebugMessage()

void drcPrintDebugMessage ( int  level,
const wxString &  msg,
const char *  function,
int  line 
)

Definition at line 40 of file drc_engine.cpp.

41 {
42  wxString valueStr;
43 
44  if( wxGetEnv( "DRC_DEBUG", &valueStr ) )
45  {
46  int setLevel = wxAtoi( valueStr );
47 
48  if( level <= setLevel )
49  {
50  printf("%-30s:%d | %s\n", function, line, (const char *) msg.c_str() );
51  }
52  }
53 }

◆ formatConstraint()

static wxString formatConstraint ( const DRC_CONSTRAINT constraint)
static

Definition at line 442 of file drc_engine.cpp.

443 {
444  struct FORMATTER
445  {
446  DRC_CONSTRAINT_T type;
447  wxString name;
448  std::function<wxString(const DRC_CONSTRAINT&)> formatter;
449  };
450 
451  auto formatMinMax =
452  []( const DRC_CONSTRAINT& c ) -> wxString
453  {
454  wxString str;
455  const auto value = c.GetValue();
456 
457  if ( value.HasMin() )
458  str += wxString::Format( " min: %d", value.Min() );
459 
460  if ( value.HasOpt() )
461  str += wxString::Format( " opt: %d", value.Opt() );
462 
463  if ( value.HasMax() )
464  str += wxString::Format( " max: %d", value.Max() );
465 
466  return str;
467  };
468 
469  std::vector<FORMATTER> formats =
470  {
471  { CLEARANCE_CONSTRAINT, "clearance", formatMinMax },
472  { HOLE_CLEARANCE_CONSTRAINT, "hole_clearance", formatMinMax },
473  { HOLE_TO_HOLE_CONSTRAINT, "hole_to_hole", formatMinMax },
474  { EDGE_CLEARANCE_CONSTRAINT, "edge_clearance", formatMinMax },
475  { HOLE_SIZE_CONSTRAINT, "hole_size", formatMinMax },
476  { COURTYARD_CLEARANCE_CONSTRAINT, "courtyard_clearance", formatMinMax },
477  { SILK_CLEARANCE_CONSTRAINT, "silk_clearance", formatMinMax },
478  { TRACK_WIDTH_CONSTRAINT, "track_width", formatMinMax },
479  { ANNULAR_WIDTH_CONSTRAINT, "annular_width", formatMinMax },
480  { DISALLOW_CONSTRAINT, "disallow", nullptr },
481  { VIA_DIAMETER_CONSTRAINT, "via_diameter", formatMinMax },
482  { LENGTH_CONSTRAINT, "length", formatMinMax },
483  { SKEW_CONSTRAINT, "skew", formatMinMax },
484  { VIA_COUNT_CONSTRAINT, "via_count", formatMinMax }
485  };
486 
487  for( FORMATTER& fmt : formats )
488  {
489  if( fmt.type == constraint.m_Type )
490  {
491  wxString rv = fmt.name + " ";
492 
493  if( fmt.formatter )
494  rv += fmt.formatter( constraint );
495 
496  return rv;
497  }
498  }
499 
500  return "?";
501 }
DRC_CONSTRAINT_T
Definition: drc_rule.h:41
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
const char * name
Definition: DXF_plotter.cpp:59
DRC_CONSTRAINT_T m_Type
Definition: drc_rule.h:141

References ANNULAR_WIDTH_CONSTRAINT, CLEARANCE_CONSTRAINT, COURTYARD_CLEARANCE_CONSTRAINT, DISALLOW_CONSTRAINT, EDGE_CLEARANCE_CONSTRAINT, Format(), HOLE_CLEARANCE_CONSTRAINT, HOLE_SIZE_CONSTRAINT, HOLE_TO_HOLE_CONSTRAINT, LENGTH_CONSTRAINT, DRC_CONSTRAINT::m_Type, name, SILK_CLEARANCE_CONSTRAINT, SKEW_CONSTRAINT, TRACK_WIDTH_CONSTRAINT, VIA_COUNT_CONSTRAINT, and VIA_DIAMETER_CONSTRAINT.

Referenced by DRC_ENGINE::compileRules().

◆ isKeepoutZone()

static bool isKeepoutZone ( const BOARD_ITEM aItem,
bool  aCheckFlags 
)
static

Definition at line 90 of file drc_engine.cpp.

91 {
92  if( !aItem )
93  return false;
94 
95  if( aItem->Type() != PCB_ZONE_T && aItem->Type() != PCB_FP_ZONE_T )
96  return false;
97 
98  const ZONE* zone = static_cast<const ZONE*>( aItem );
99 
100  if( !zone->GetIsRuleArea() )
101  return false;
102 
103  if( aCheckFlags )
104  {
105  if( !zone->GetDoNotAllowTracks()
106  && !zone->GetDoNotAllowVias()
107  && !zone->GetDoNotAllowPads()
108  && !zone->GetDoNotAllowCopperPour()
109  && !zone->GetDoNotAllowFootprints() )
110  {
111  return false;
112  }
113  }
114 
115  return true;
116 }
bool GetDoNotAllowFootprints() const
Definition: zone.h:735
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition: zone.h:730
bool GetDoNotAllowVias() const
Definition: zone.h:732
bool GetDoNotAllowPads() const
Definition: zone.h:734
bool GetDoNotAllowCopperPour() const
Definition: zone.h:731
bool GetDoNotAllowTracks() const
Definition: zone.h:733
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
class ZONE, a copper pour area
Definition: typeinfo.h:105
class ZONE, managed by a footprint
Definition: typeinfo.h:94
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:163

References ZONE::GetDoNotAllowCopperPour(), ZONE::GetDoNotAllowFootprints(), ZONE::GetDoNotAllowPads(), ZONE::GetDoNotAllowTracks(), ZONE::GetDoNotAllowVias(), ZONE::GetIsRuleArea(), PCB_FP_ZONE_T, PCB_ZONE_T, and EDA_ITEM::Type().

Referenced by DRC_ENGINE::EvalRules(), and DRC_ENGINE::loadImplicitRules().