(version 1)
#PCBWay Custom DRC for Kicad 7

# 6 layers, 2 oz outer and 1 oz inner. Optimized for lowest cost.

# ----------------------------------- Minimum trace width and spacing --------------------

# 2oz copper
(rule "Minimum Trace Width and Spacing (outer layer)"
(constraint track_width (min 0.2mm))
(constraint clearance (min 0.2mm))
(layer outer)
(condition "A.Type == 'track'"))

(rule "Minimum Trace Width and Spacing (innner layer)"
(constraint track_width (min 0.2mm))
(constraint clearance (min 0.2mm))
(layer inner)
(condition "A.Type == 'track'"))

# ------------------------------------------------------------------------------------------------------

# Drill/hole size - listed here to maintain order of rule application. Must not override rule set in Via hole/diameter size below.
(rule "drill hole size (mechanical)"
(constraint hole_size (min 0.15mm) (max 6.3mm)))

# ----------------------------------- Via hole/diameter size (PICK ONE) --------------------------------

(rule "Minimum Via Diameter and Hole Size"
(constraint hole_size (min 0.25mm))
(constraint via_diameter (min 0.55mm))
(condition "A.Type == 'via'"))


# ----------------------------------- Drill/hole size --------------------------------------------------

(rule "PTH Hole Size"
(constraint hole_size (min 0.25mm) (max 6.35mm))
(condition "A.Type != 'Via' && A.isPlated()"))

(rule "Minimum Non-plated Hole Size"
(constraint hole_size (min 0.5mm))
(condition "A.Type == 'pad' && !A.isPlated()"))

(rule "Pad Size"
(constraint hole_size (min 0.25mm))
(constraint annular_width (min 0.15mm))
(condition "A.Type == 'Pad' && A.isPlated()"))

(rule "Minimum Castellated Hole Size"
(constraint hole_size (min 0.6mm))
(condition "A.Type == 'pad' && A.Fabrication_Property == 'Castellated pad'"))

(rule "Min. Plated Slot Width"
(constraint hole_size (min 0.5mm))
(condition "(A.Hole_Size_X != A.Hole_Size_Y) && A.isPlated()"))

(rule "Min. Non-Plated Slot Width"
(constraint hole_size (min 0.8mm))
(condition "(A.Hole_Size_X != A.Hole_Size_Y) && !A.isPlated()"))


# ----------------------------------- Minimum clearance ------------------------------------------------

(rule "hole to hole clearance (different nets)"
(constraint hole_to_hole (min 0.5mm))
(condition "A.Net != B.Net"))

(rule "via to track clearance"
(constraint hole_clearance (min 0.254mm))
(condition "A.Type == 'via' && B.Type == 'track'"))

(rule "via to via clearance (same nets)"
(constraint hole_to_hole (min 0.254mm))
(condition "A.Type == 'via' && B.Type == A.Type && A.Net == B.Net"))

(rule "pad to pad clearance (with hole, different nets)"
(constraint hole_to_hole (min 0.5mm))
(condition "A.Type == 'pad' && B.Type == A.Type && A.Net != B.Net"))

(rule "pad to pad clearance (without hole, different nets)"
(constraint clearance (min 0.2mm))
(condition "A.Type == 'Pad' && B.Type == 'Pad'"))

(rule "NPTH to Track clearance"
(constraint hole_clearance (min 0.254mm))
(condition "A.Pad_Type == 'NPTH, mechanical' && B.Type == 'track'"))

(rule "NPTH with copper around"
(constraint hole_clearance (min 0.20mm))
(condition "A.Pad_Type == 'NPTH, mechanical' && B.Type != 'track'"))

(rule "PTH to Track clearance"
(constraint hole_clearance (min 0.33mm))
(condition "A.isPlated() && A.Type != 'Via' && B.Type == 'track'"))

(rule "Pad to Track clearance"
(constraint clearance (min 0.2mm))
(condition "A.isPlated() && A.Type != 'Via' && B.Type == 'track'"))

# ----------------------------------- Board Outlines (PICK ONE) -------------------------------------
#Default Routed Edge Clearance
(rule "Trace to Outline"
(constraint edge_clearance (min 0.3mm))
(condition "A.Type == 'track'"))

# ----------------------------------- Silkscreen ----------------------------------------------------
(rule "Minimum Text"
(constraint text_thickness (min 0.15mm))
(constraint text_height (min 0.8mm))
(layer "?.Silkscreen"))

(rule "Pad to Silkscreen"
(constraint silk_clearance (min 0.15mm))
(layer outer)
(condition "A.Type == 'pad' && (B.Type == 'text' || B.Type == 'graphic')"))

# ----------------------------------- Test Points Courtyard -----------------------------------------
(rule "Test Point Courtyard Exclusion"
(constraint courtyard_clearance (min -1mm))
(condition "A.Reference =='TP*'"))

# ----------------------------------- Fiducials Courtyard -------------------------------------------
(rule "Fiducials Courtyard Exclusion"
(constraint courtyard_clearance (min -1mm))
(condition "A.Reference =='FM*'"))
