Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions examples/mountedPcbModule-female.example.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { JsCadView } from "jscad-fiber"
import { ExtrudedPads } from "lib/index"
import MountedPCBModule from "lib/MountedPcbModule"

export default () => {
return (
<JsCadView zAxisUp showGrid>
<ExtrudedPads footprint="mountedpcbmodule_pinrow20_rows2_pinrowbottom_width40_height22_female_holes(topleft,topright,bottomleft,bottomright)" />
<MountedPCBModule
numPins={20}
rows={2}
pinRowSide="bottom"
width={40}
height={22}
holes={["topleft", "topright", "bottomleft", "bottomright"]}
female
/>
</JsCadView>
)
}
14 changes: 8 additions & 6 deletions lib/FemaleHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Colorize, Cuboid, Cylinder, Hull, Subtract } from "jscad-fiber"
export const FemaleHeader = ({
x,
y,
z = 0,
pitch = 2.54,
legsLength = 3,
innerDiameter = 0.945,
Expand All @@ -13,6 +14,7 @@ export const FemaleHeader = ({
}: {
x: number
y: number
z?: number
pitch?: number
legsLength?: number
innerDiameter?: number
Expand All @@ -31,19 +33,19 @@ export const FemaleHeader = ({
<Cuboid
color="#000"
size={[bodyLength, bodyWidth, bodyHeight]}
center={[x, y, flipZ(bodyHeight / 2)]}
center={[x, y, flipZ(z + bodyHeight / 2)]}
/>
{innerDiameter ? (
<Cylinder
height={bodyHeight + 0.1}
radius={innerDiameter / 2}
center={[x, y, flipZ(bodyHeight / 2)]}
center={[x, y, flipZ(z + bodyHeight / 2)]}
color="#222"
/>
) : (
<Cuboid
size={[gapWidth, gapWidth, bodyHeight]}
center={[x, y, flipZ(bodyHeight / 2)]}
center={[x, y, flipZ(z + bodyHeight / 2)]}
/>
)}
</Subtract>
Expand All @@ -53,18 +55,18 @@ export const FemaleHeader = ({
<Cuboid
color="silver"
size={[pinThickness, pinThickness, legsLength * 0.9]}
center={[x, y, flipZ((-legsLength / 2) * 0.9)]}
center={[x, y, flipZ(z + (-legsLength / 2) * 0.9)]}
/>
<Cuboid
color="silver"
size={[pinThickness / 1.8, pinThickness / 1.8, legsLength]}
center={[x, y, flipZ(-legsLength / 2)]}
center={[x, y, flipZ(z + -legsLength / 2)]}
/>
</Hull>
<Cuboid
color="silver"
size={[gapWidth, gapWidth, gapWidth * 0.5]}
center={[x, y, flipZ((gapWidth / 2) * 0.5)]}
center={[x, y, flipZ(z + (gapWidth / 2) * 0.5)]}
/>
</Colorize>
</>
Expand Down
1 change: 1 addition & 0 deletions lib/Footprinter3d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ export const Footprinter3d = ({ footprint }: { footprint: string }) => {
holeInset={holeInset}
pinRowHoleEdgeToEdgeDist={pinRowHoleEdgeToEdgeDist}
nopin={fpJson.nopin}
female={fpJson.female}
/>
)
}
Expand Down
17 changes: 15 additions & 2 deletions lib/MountedPcbModule.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Colorize, Cuboid, Cylinder, Subtract } from "jscad-fiber"
import { PinHeader } from "./PinHeader"
import { FemaleHeader } from "./FemaleHeader"

export const MountedPcbModule = ({
numPins = 5,
Expand All @@ -14,6 +15,7 @@ export const MountedPcbModule = ({
holes = [],
holeInset = 1.0,
pinRowHoleEdgeToEdgeDist = 2.0,
female,
nopin,
}: {
numPins?: number
Expand All @@ -28,6 +30,7 @@ export const MountedPcbModule = ({
holes?: string[]
holeInset?: number
pinRowHoleEdgeToEdgeDist?: number
female?: boolean
nopin?: boolean
}) => {
const boardCenterZ = boardThickness / 2
Expand Down Expand Up @@ -121,7 +124,7 @@ export const MountedPcbModule = ({
const pinBodyHeight = 2
const longSidePinLength = 6
const shortSidePinLength = 3
const boardOffsetZ = nopin ? 0 : pinBodyHeight
const boardOffsetZ = nopin || female ? 0 : pinBodyHeight
// Board body with holes subtracted
const boardBody = (
<Colorize color="#008080">
Expand Down Expand Up @@ -181,11 +184,21 @@ export const MountedPcbModule = ({
/>
))

const femaleHeaderRow = pins.map((pin, index) => (
<FemaleHeader
key={`female-pin-3d-${index}`}
x={pin.x}
y={pin.y}
flipZ={(z: number) => -z}
/>
))

return (
<>
{boardBody}
{platedHoles}
{!nopin && headerPins}
{!female && !nopin && headerPins}
{female && femaleHeaderRow}
</>
)
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions tests/snapshots/mountedpcbmodule-female.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { expect, test } from "bun:test"
import { renderFootprint } from "tests/helpers/render-footprint"

test("mountedpcbmodule with female header and holes", async () => {
const pngBuffer = renderFootprint(
"mountedpcbmodule_pinrow20_rows2_pinrowbottom_width40_height22_female_holes(topleft,topright,bottomleft,bottomright)",
)
await expect(pngBuffer).toMatchPngSnapshot(import.meta.path)
}, 10000)