KiCad PCB EDA Suite
drc_engine.cpp File Reference
#include <reporter.h>
#include <progress_reporter.h>
#include <string_utils.h>
#include <board_design_settings.h>
#include <drc/drc_engine.h>
#include <drc/drc_rtree.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 <footprint.h>
#include <pad.h>
#include <pcb_track.h>
#include <zone.h>
#include <geometry/shape.h>
#include <geometry/shape_segment.h>
#include <geometry/shape_null.h>
#include <convert_basic_shapes_to_polygon.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
 
#define REPORT_VALUE(v)   MessageTextFromValue( UNITS, v )
 

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 ); } }

◆ REPORT_VALUE

#define REPORT_VALUE (   v)    MessageTextFromValue( UNITS, v )

◆ 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 45 of file drc_engine.cpp.

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

◆ formatConstraint()

static wxString formatConstraint ( const DRC_CONSTRAINT constraint)
static

Definition at line 463 of file drc_engine.cpp.

464 {
465  struct FORMATTER
466  {
467  DRC_CONSTRAINT_T type;
468  wxString name;
469  std::function<wxString(const DRC_CONSTRAINT&)> formatter;
470  };
471 
472  auto formatMinMax =
473  []( const DRC_CONSTRAINT& c ) -> wxString
474  {
475  wxString str;
476  const auto value = c.GetValue();
477 
478  if ( value.HasMin() )
479  str += wxString::Format( " min: %d", value.Min() );
480 
481  if ( value.HasOpt() )
482  str += wxString::Format( " opt: %d", value.Opt() );
483 
484  if ( value.HasMax() )
485  str += wxString::Format( " max: %d", value.Max() );
486 
487  return str;
488  };
489 
490  std::vector<FORMATTER> formats =
491  {
492  { CLEARANCE_CONSTRAINT, "clearance", formatMinMax },
493  { HOLE_CLEARANCE_CONSTRAINT, "hole_clearance", formatMinMax },
494  { HOLE_TO_HOLE_CONSTRAINT, "hole_to_hole", formatMinMax },
495  { EDGE_CLEARANCE_CONSTRAINT, "edge_clearance", formatMinMax },
496  { HOLE_SIZE_CONSTRAINT, "hole_size", formatMinMax },
497  { COURTYARD_CLEARANCE_CONSTRAINT, "courtyard_clearance", formatMinMax },
498  { SILK_CLEARANCE_CONSTRAINT, "silk_clearance", formatMinMax },
499  { TRACK_WIDTH_CONSTRAINT, "track_width", formatMinMax },
500  { ANNULAR_WIDTH_CONSTRAINT, "annular_width", formatMinMax },
501  { DISALLOW_CONSTRAINT, "disallow", nullptr },
502  { VIA_DIAMETER_CONSTRAINT, "via_diameter", formatMinMax },
503  { LENGTH_CONSTRAINT, "length", formatMinMax },
504  { SKEW_CONSTRAINT, "skew", formatMinMax },
505  { VIA_COUNT_CONSTRAINT, "via_count", formatMinMax }
506  };
507 
508  for( FORMATTER& fmt : formats )
509  {
510  if( fmt.type == constraint.m_Type )
511  {
512  wxString rv = fmt.name + " ";
513 
514  if( fmt.formatter )
515  rv += fmt.formatter( constraint );
516 
517  return rv;
518  }
519  }
520 
521  return "?";
522 }
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:56
DRC_CONSTRAINT_T m_Type
Definition: drc_rule.h:144

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 95 of file drc_engine.cpp.

96 {
97  if( !aItem )
98  return false;
99 
100  if( aItem->Type() != PCB_ZONE_T && aItem->Type() != PCB_FP_ZONE_T )
101  return false;
102 
103  const ZONE* zone = static_cast<const ZONE*>( aItem );
104 
105  if( !zone->GetIsRuleArea() )
106  return false;
107 
108  if( aCheckFlags )
109  {
110  if( !zone->GetDoNotAllowTracks()
111  && !zone->GetDoNotAllowVias()
112  && !zone->GetDoNotAllowPads()
113  && !zone->GetDoNotAllowCopperPour()
114  && !zone->GetDoNotAllowFootprints() )
115  {
116  return false;
117  }
118  }
119 
120  return true;
121 }
bool GetDoNotAllowFootprints() const
Definition: zone.h:738
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition: zone.h:733
bool GetDoNotAllowVias() const
Definition: zone.h:735
bool GetDoNotAllowPads() const
Definition: zone.h:737
bool GetDoNotAllowCopperPour() const
Definition: zone.h:734
bool GetDoNotAllowTracks() const
Definition: zone.h:736
Handle a list of polygons defining a copper zone.
Definition: zone.h:56
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:112

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().