<constraint />
Overview
The <constraint />
element is used to enforce geometric relationships between different elements in a PCB footprint. Constraints can set specific distances and alignments, such as center-to-center, edge-to-edge, or ensuring two elements line up along the same axis.
Below is a reference example that demonstrates how constraints are used within a footprint. This example is part of a test suite to validate that a KeyswitchSocket component is correctly flipped when placed on different layers of a board.
/**
* A switch shaft you can use to connect a pluggable Kailh socket.
*/
const KeyswitchSocket = (props: {
name: string
pcbX?: number
pcbY?: number
layer?: "top" | "bottom"
}) => (
<chip
{...props}
cadModel={{
objUrl: "/easyeda/C5184526",
}}
footprint={
<footprint>
{/* <silkscreentext text={props.name} /> */}
<smtpad
shape="rect"
width="2.55mm"
height="2.5mm"
portHints={["pin1"]}
layer="top"
/>
<smtpad
shape="rect"
width="2.55mm"
height="2.5mm"
portHints={["pin2"]}
layer="top"
/>
<hole name="H1" diameter="3mm" />
<hole name="H2" diameter="3mm" />
<constraint xDist="6.35mm" centerToCenter left=".H1" right=".H2" />
<constraint yDist="2.54mm" centerToCenter top=".H1" bottom=".H2" />
<constraint edgeToEdge xDist="11.3mm" left=".pin1" right=".pin2" />
<constraint sameY for={[".pin1", ".H1"]} />
<constraint sameY for={[".pin2", ".H2"]} />
<constraint
edgeToEdge
xDist={(11.3 - 6.35 - 3) / 2}
left=".pin1"
right=".H1"
/>
</footprint>
}
/>
)
export default () => (
<board width="40mm" height="40mm">
<KeyswitchSocket name="SW1" pcbX={-10} pcbY={0} layer="top" />
<KeyswitchSocket name="SW2" pcbX={10} pcbY={0} layer="bottom" />
</board>
)
Key Constraints Summary
<constraint xDist="..." centerToCenter ... />
: Defines a constraint based on the center positions of two elements.<constraint edgeToEdge xDist="..." ... />
: Sets a fixed distance between the edges of two elements.<constraint sameY for={["...", "..."]} />
: Ensures that multiple elements share the same Y coordinate.
Use these constraints to help align footprint elements consistently across your designs.