Preparing for the removal of positional functions from the language. The first big step is to change all our KCL code examples, test code, public samples etc to all use keyword functions. Apologies for how large this PR is. Most of it is: - Changing example KCL that defined its own functions, so the functions now use keyword arguments rather than positional arguments. E.g. change `cube([20, 20])` to be `cube(center = [20, 20])`. - Some parts of the code assumed positional code and didn't handle keyword calls, e.g. the linter would only check for positional calls to startSketchOn. Now they should work with either positional or keyword. - Update all the artifacts This does _not_ remove support for positional calls. That will be in a follow-up PR.
365 lines
10 KiB
Plaintext
365 lines
10 KiB
Plaintext
@no_std
|
|
@settings(defaultLengthUnit = mm)
|
|
|
|
import Face from "std::types"
|
|
|
|
/// Blend a transitional edge along a tagged path, smoothing the sharp edge.
|
|
///
|
|
/// Fillet is similar in function and use to a chamfer, except
|
|
/// a chamfer will cut a sharp transition along an edge while fillet
|
|
/// will smoothly blend the transition.
|
|
///
|
|
/// ```
|
|
/// width = 20
|
|
/// length = 10
|
|
/// thickness = 1
|
|
/// filletRadius = 2
|
|
///
|
|
/// mountingPlateSketch = startSketchOn(XY)
|
|
/// |> startProfile(at = [-width/2, -length/2])
|
|
/// |> line(endAbsolute = [width/2, -length/2], tag = $edge1)
|
|
/// |> line(endAbsolute = [width/2, length/2], tag = $edge2)
|
|
/// |> line(endAbsolute = [-width/2, length/2], tag = $edge3)
|
|
/// |> close(tag = $edge4)
|
|
///
|
|
/// mountingPlate = extrude(mountingPlateSketch, length = thickness)
|
|
/// |> fillet(
|
|
/// radius = filletRadius,
|
|
/// tags = [
|
|
/// getNextAdjacentEdge(edge1),
|
|
/// getNextAdjacentEdge(edge2),
|
|
/// getNextAdjacentEdge(edge3),
|
|
/// getNextAdjacentEdge(edge4)
|
|
/// ],
|
|
/// )
|
|
/// ```
|
|
///
|
|
/// ```
|
|
/// width = 20
|
|
/// length = 10
|
|
/// thickness = 1
|
|
/// filletRadius = 1
|
|
///
|
|
/// mountingPlateSketch = startSketchOn(XY)
|
|
/// |> startProfile(at = [-width/2, -length/2])
|
|
/// |> line(endAbsolute = [width/2, -length/2], tag = $edge1)
|
|
/// |> line(endAbsolute = [width/2, length/2], tag = $edge2)
|
|
/// |> line(endAbsolute = [-width/2, length/2], tag = $edge3)
|
|
/// |> close(tag = $edge4)
|
|
///
|
|
/// mountingPlate = extrude(mountingPlateSketch, length = thickness)
|
|
/// |> fillet(
|
|
/// radius = filletRadius,
|
|
/// tolerance = 0.000001,
|
|
/// tags = [
|
|
/// getNextAdjacentEdge(edge1),
|
|
/// getNextAdjacentEdge(edge2),
|
|
/// getNextAdjacentEdge(edge3),
|
|
/// getNextAdjacentEdge(edge4)
|
|
/// ],
|
|
/// )
|
|
/// ```
|
|
@(impl = std_rust)
|
|
export fn fillet(
|
|
/// The solid whose edges should be filletted
|
|
@solid: Solid,
|
|
/// The radius of the fillet
|
|
radius: number(Length),
|
|
/// The paths you want to fillet
|
|
tags: [Edge; 1+],
|
|
/// The tolerance for this fillet
|
|
tolerance?: number(Length),
|
|
/// Create a new tag which refers to this fillet
|
|
tag?: tag,
|
|
): Solid {}
|
|
|
|
/// Cut a straight transitional edge along a tagged path.
|
|
///
|
|
/// Chamfer is similar in function and use to a fillet, except
|
|
/// a fillet will blend the transition along an edge, rather than cut
|
|
/// a sharp, straight transitional edge.
|
|
///
|
|
/// ```
|
|
/// // Chamfer a mounting plate.
|
|
/// width = 20
|
|
/// length = 10
|
|
/// thickness = 1
|
|
/// chamferLength = 2
|
|
///
|
|
/// mountingPlateSketch = startSketchOn(XY)
|
|
/// |> startProfile(at = [-width/2, -length/2])
|
|
/// |> line(endAbsolute = [width/2, -length/2], tag = $edge1)
|
|
/// |> line(endAbsolute = [width/2, length/2], tag = $edge2)
|
|
/// |> line(endAbsolute = [-width/2, length/2], tag = $edge3)
|
|
/// |> close(tag = $edge4)
|
|
///
|
|
/// mountingPlate = extrude(mountingPlateSketch, length = thickness)
|
|
/// |> chamfer(
|
|
/// length = chamferLength,
|
|
/// tags = [
|
|
/// getNextAdjacentEdge(edge1),
|
|
/// getNextAdjacentEdge(edge2),
|
|
/// getNextAdjacentEdge(edge3),
|
|
/// getNextAdjacentEdge(edge4)
|
|
/// ],
|
|
/// )
|
|
/// ```
|
|
///
|
|
/// ```
|
|
/// // Sketch on the face of a chamfer.
|
|
/// fn cube(pos, scale) {
|
|
/// sg = startSketchOn(XY)
|
|
/// |> startProfile(at = pos)
|
|
/// |> line(end = [0, scale])
|
|
/// |> line(end = [scale, 0])
|
|
/// |> line(end = [0, -scale])
|
|
///
|
|
/// return sg
|
|
/// }
|
|
///
|
|
/// part001 = cube(pos = [0,0], scale = 20)
|
|
/// |> close(tag = $line1)
|
|
/// |> extrude(length = 20)
|
|
/// // We tag the chamfer to reference it later.
|
|
/// |> chamfer(
|
|
/// length = 10,
|
|
/// tags = [getOppositeEdge(line1)],
|
|
/// tag = $chamfer1,
|
|
/// )
|
|
///
|
|
/// sketch001 = startSketchOn(part001, face = chamfer1)
|
|
/// |> startProfile(at = [10, 10])
|
|
/// |> line(end = [2, 0])
|
|
/// |> line(end = [0, 2])
|
|
/// |> line(end = [-2, 0])
|
|
/// |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
|
/// |> close()
|
|
/// |> extrude(length = 10)
|
|
/// ```
|
|
@(impl = std_rust)
|
|
export fn chamfer(
|
|
/// The solid whose edges should be chamfered
|
|
@solid: Solid,
|
|
/// The length of the chamfer
|
|
length: number(Length),
|
|
/// The paths you want to chamfer
|
|
tags: [Edge; 1+],
|
|
/// Create a new tag which refers to this chamfer
|
|
tag?: tag,
|
|
): Solid {}
|
|
|
|
/// Remove volume from a 3-dimensional shape such that a wall of the
|
|
/// provided thickness remains, taking volume starting at the provided
|
|
/// face, leaving it open in that direction.
|
|
///
|
|
/// ```
|
|
/// // Remove the end face for the extrusion.
|
|
/// firstSketch = startSketchOn(XY)
|
|
/// |> startProfile(at = [-12, 12])
|
|
/// |> line(end = [24, 0])
|
|
/// |> line(end = [0, -24])
|
|
/// |> line(end = [-24, 0])
|
|
/// |> close()
|
|
/// |> extrude(length = 6)
|
|
///
|
|
/// // Remove the end face for the extrusion.
|
|
/// shell(
|
|
/// firstSketch,
|
|
/// faces = [END],
|
|
/// thickness = 0.25,
|
|
/// )
|
|
/// ```
|
|
///
|
|
/// ```
|
|
/// // Remove the start face for the extrusion.
|
|
/// firstSketch = startSketchOn(-XZ)
|
|
/// |> startProfile(at = [-12, 12])
|
|
/// |> line(end = [24, 0])
|
|
/// |> line(end = [0, -24])
|
|
/// |> line(end = [-24, 0])
|
|
/// |> close()
|
|
/// |> extrude(length = 6)
|
|
///
|
|
/// // Remove the start face for the extrusion.
|
|
/// shell(
|
|
/// firstSketch,
|
|
/// faces = [START],
|
|
/// thickness = 0.25,
|
|
/// )
|
|
/// ```
|
|
///
|
|
/// ```
|
|
/// // Remove a tagged face and the end face for the extrusion.
|
|
/// firstSketch = startSketchOn(XY)
|
|
/// |> startProfile(at = [-12, 12])
|
|
/// |> line(end = [24, 0])
|
|
/// |> line(end = [0, -24])
|
|
/// |> line(end = [-24, 0], tag = $myTag)
|
|
/// |> close()
|
|
/// |> extrude(length = 6)
|
|
///
|
|
/// // Remove a tagged face for the extrusion.
|
|
/// shell(
|
|
/// firstSketch,
|
|
/// faces = [myTag],
|
|
/// thickness = 0.25,
|
|
/// )
|
|
/// ```
|
|
///
|
|
/// ```
|
|
/// // Remove multiple faces at once.
|
|
/// firstSketch = startSketchOn(XY)
|
|
/// |> startProfile(at = [-12, 12])
|
|
/// |> line(end = [24, 0])
|
|
/// |> line(end = [0, -24])
|
|
/// |> line(end = [-24, 0], tag = $myTag)
|
|
/// |> close()
|
|
/// |> extrude(length = 6)
|
|
///
|
|
/// // Remove a tagged face and the end face for the extrusion.
|
|
/// shell(
|
|
/// firstSketch,
|
|
/// faces = [myTag, END],
|
|
/// thickness = 0.25,
|
|
/// )
|
|
/// ```
|
|
///
|
|
/// ```
|
|
/// // Shell a sketch on face.
|
|
/// size = 100
|
|
/// case = startSketchOn(-XZ)
|
|
/// |> startProfile(at = [-size, -size])
|
|
/// |> line(end = [2 * size, 0])
|
|
/// |> line(end = [0, 2 * size])
|
|
/// |> tangentialArc(endAbsolute = [-size, size])
|
|
/// |> close()
|
|
/// |> extrude(length = 65)
|
|
///
|
|
/// thing1 = startSketchOn(case, face = END)
|
|
/// |> circle( center = [-size / 2, -size / 2], radius = 25 )
|
|
/// |> extrude(length = 50)
|
|
///
|
|
/// thing2 = startSketchOn(case, face = END)
|
|
/// |> circle( center = [size / 2, -size / 2], radius = 25 )
|
|
/// |> extrude(length = 50)
|
|
///
|
|
/// // We put "case" in the shell function to shell the entire object.
|
|
/// shell(case, faces = [START], thickness = 5)
|
|
/// ```
|
|
///
|
|
/// ```
|
|
/// // Shell a sketch on face object on the end face.
|
|
/// size = 100
|
|
/// case = startSketchOn(XY)
|
|
/// |> startProfile(at = [-size, -size])
|
|
/// |> line(end = [2 * size, 0])
|
|
/// |> line(end = [0, 2 * size])
|
|
/// |> tangentialArc(endAbsolute = [-size, size])
|
|
/// |> close()
|
|
/// |> extrude(length = 65)
|
|
///
|
|
/// thing1 = startSketchOn(case, face = END)
|
|
/// |> circle( center = [-size / 2, -size / 2], radius = 25 )
|
|
/// |> extrude(length = 50)
|
|
///
|
|
/// thing2 = startSketchOn(case, face = END)
|
|
/// |> circle( center = [size / 2, -size / 2], radius = 25 )
|
|
/// |> extrude(length = 50)
|
|
///
|
|
/// // We put "thing1" in the shell function to shell the end face of the object.
|
|
/// shell(thing1, faces = [END], thickness = 5)
|
|
/// ```
|
|
///
|
|
/// ```
|
|
/// // Shell sketched on face objects on the end face, include all sketches to shell
|
|
/// // the entire object.
|
|
///
|
|
/// size = 100
|
|
/// case = startSketchOn(XY)
|
|
/// |> startProfile(at = [-size, -size])
|
|
/// |> line(end = [2 * size, 0])
|
|
/// |> line(end = [0, 2 * size])
|
|
/// |> tangentialArc(endAbsolute = [-size, size])
|
|
/// |> close()
|
|
/// |> extrude(length = 65)
|
|
///
|
|
/// thing1 = startSketchOn(case, face = END)
|
|
/// |> circle( center = [-size / 2, -size / 2], radius = 25 )
|
|
/// |> extrude(length = 50)
|
|
///
|
|
/// thing2 = startSketchOn(case, face = END)
|
|
/// |> circle( center = [size / 2, -size / 2], radius = 25)
|
|
/// |> extrude(length = 50)
|
|
///
|
|
/// // We put "thing1" and "thing2" in the shell function to shell the end face of the object.
|
|
/// shell([thing1, thing2], faces = [END], thickness = 5)
|
|
/// ```
|
|
@(impl = std_rust)
|
|
export fn shell(
|
|
/// Which solid (or solids) to shell out
|
|
@solids: [Solid; 1+],
|
|
/// The thickness of the shell
|
|
thickness: number(Length),
|
|
/// The faces you want removed
|
|
faces: [tag; 1+],
|
|
): [Solid] {}
|
|
|
|
|
|
/// Make the inside of a 3D object hollow.
|
|
///
|
|
/// Remove volume from a 3-dimensional shape such that a wall of the
|
|
/// provided thickness remains around the exterior of the shape.
|
|
///
|
|
/// ```
|
|
/// // Hollow a basic sketch.
|
|
/// firstSketch = startSketchOn(XY)
|
|
/// |> startProfile(at = [-12, 12])
|
|
/// |> line(end = [24, 0])
|
|
/// |> line(end = [0, -24])
|
|
/// |> line(end = [-24, 0])
|
|
/// |> close()
|
|
/// |> extrude(length = 6)
|
|
/// |> hollow (thickness = 0.25)
|
|
/// ```
|
|
///
|
|
/// ```
|
|
/// // Hollow a basic sketch.
|
|
/// firstSketch = startSketchOn(-XZ)
|
|
/// |> startProfile(at = [-12, 12])
|
|
/// |> line(end = [24, 0])
|
|
/// |> line(end = [0, -24])
|
|
/// |> line(end = [-24, 0])
|
|
/// |> close()
|
|
/// |> extrude(length = 6)
|
|
/// |> hollow (thickness = 0.5)
|
|
/// ```
|
|
///
|
|
/// ```
|
|
/// // Hollow a sketch on face object.
|
|
/// size = 100
|
|
/// case = startSketchOn(-XZ)
|
|
/// |> startProfile(at = [-size, -size])
|
|
/// |> line(end = [2 * size, 0])
|
|
/// |> line(end = [0, 2 * size])
|
|
/// |> tangentialArc(endAbsolute = [-size, size])
|
|
/// |> close()
|
|
/// |> extrude(length = 65)
|
|
///
|
|
/// thing1 = startSketchOn(case, face = END)
|
|
/// |> circle( center = [-size / 2, -size / 2], radius = 25 )
|
|
/// |> extrude(length = 50)
|
|
///
|
|
/// thing2 = startSketchOn(case, face = END)
|
|
/// |> circle( center = [size / 2, -size / 2], radius = 25 )
|
|
/// |> extrude(length = 50)
|
|
///
|
|
/// hollow(case, thickness = 0.5)
|
|
/// ```
|
|
@(impl = std_rust)
|
|
export fn hollow(
|
|
/// Which solid to hollow out
|
|
@solid: Solid,
|
|
/// The thickness of the remaining shell
|
|
thickness: number(Length),
|
|
): Solid {}
|