Using Component Classes for custom clearance settings?

Hi,

I’m test-driving KiCad 9.0 RC2. I’m quite excited about the addition of component classes but I don’t quite understand how they should be used.

I have set a rule like this:

(rule "fine_pitch"
    (condition "A.hasComponentClass('fine_pitch')")
	(constraint clearance (min 0.1mm)))

Then, in the schematic editor, I’ve tried setting the “Component Class” field to “fine_pitch”. I’ve also tried using the new Rule Area feature to set the component class, and finally, I’ve tried to set the Component Class field in the footprint properties in the PCB Editor. None of these seem to work.

What am I doing wrong?

hasComponentClass will only return true on objects that have a component class, namely footprints. The clearance constraint only applies to copper objects, which footprints are not. So, this rule doesn’t do what you expect.

I suspect what you want is “apply this clearance rule to tracks that are inside the courtyard of this component” rather than “apply this clearance rule to this component” (since the latter doesn’t make sense as described above).

To do this, use a condition function like insideCourtyard('${Class:fine_pitch}'. This is described in the custom rules section of the nightly docs here: PCB Editor | master | English | Documentation | KiCad

This is a bit of a gotcha. I added a note to the docs for hasComponentClass() to hopefully point people in the right direction.

It’s probably worth an example too, which I can do eventually.

Thank you, both!

Indeed, I was suspecting that the pads didn’t have component class. I also had tried A.Parent.hasComponentClass, assuming that the pad’s parent would be the footprint, but I’m not sure if that’s even what Parent does.

Using intersectsCourtyard('${Class:fine_pitch}') worked great, but documenting for the posteriority, there was an interesting snag. I have a copper zone on the same layer, and the neckdown rule reduced the zone clearance globally. It’s obvious when you think about it but it took a while to figure out. Anyhow, this works:

(rule "neckdown"
    (condition "(A.Type != 'Zone') && (A.intersectsCourtyard('${Class:fine_pitch}'))")
    (constraint clearance (min 0.1mm)))

While debugging the issue, I noticed that Component Class set in footprint properties gets ignored. Is that on purpose?

1 Like

Do you mean you added a footprint field Component Class?

If so, that won’t work, you have to assign component classes in the schematic, either with a symbol field or with a directive label. see Schematic Editor | master | English | Documentation | KiCad

Yep, that was what I tried. I assumed that since you can assign netclasses in the PCB editor, you’d be able to do the same for component classes. Anyways, I don’t want to complain, component classes are a really great addition and I’m really glad they’ve been introduced!

There are some complexities in synchronising component classes from the pcb editor to the schematic, so I didn’t implement this for now. I should add a warning if a user tries to add a component class field in the pcb footprint properties editor though.