// French Press
// A french press immersion coffee maker

// Set units
@settings(defaultLengthUnit = in, kclVersion = 1.0)

// Define parameters
carafeDiameter = 4.41
carafeHeight = 7.32
handleThickness = 0.65

// Upper ring of the metal structure
sketch001 = startSketchOn(XZ)
  |> startProfile(at = [carafeDiameter / 2, 5.7])
  |> angledLine(angle = 0, length = 0.1, tag = $rectangleSegmentA001)
  |> angledLine(angle = segAng(rectangleSegmentA001) - 90, length = -0.75, tag = $rectangleSegmentB001)
  |> angledLine(angle = segAng(rectangleSegmentA001), length = -segLen(rectangleSegmentA001), tag = $rectangleSegmentC001)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
  |> revolve(angle = 360, axis = Y)

// Create an angled plane to sketch the supports
plane001 = {
  origin = [-0.26, 0.26, 0.0],
  xAxis = [1, 1, 0.0],
  yAxis = [0.0, 0.0, 1.0],
  zAxis = [1.0, 0.0, 0.0]
}

// Cross section of the metal supports
sketch002 = startSketchOn(plane001)
  |> startProfile(at = [carafeDiameter / 2, 5.7])
  |> xLine(length = 0.1)
  |> yLine(length = -5.2, tag = $edge1)
  |> arc(angleStart = 180, angleEnd = 205, radius = 0.3)
  |> angledLine(angle = -60, length = 0.6, tag = $edge2)
  |> arc(angleStart = 30, angleEnd = -120, radius = 0.6)
  |> angledLine(angle = 150, endAbsoluteY = -0.2, tag = $edge3)
  |> arc(angleStart = 60, angleEnd = 90, radius = 0.5)
  |> xLine(endAbsolute = 0.1, tag = $edgeLen)
  |> yLine(length = 0.1)
  |> xLine(length = segLen(edgeLen) + 0.035, tag = $edge4)
  |> arc(angleStart = 90, angleEnd = 60, radius = 0.6)
  |> angledLine(angle = 150, length = -segLen(edge3) + 0.035, tag = $edge5)
  |> arc(angleStart = -120, angleEnd = 30, radius = 0.5)
  |> angledLine(angle = -60, length = -segLen(edge2) + 0.035, tag = $edge6)
  |> arc(angleStart = 205, angleEnd = 180, radius = 0.6)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
  |> extrude(length = 0.75)
  |> patternCircular3d(
       axis = [0, 0, 1],
       center = [0, 0, 0],
       instances = 4,
       arcDegrees = 360,
       rotateDuplicates = true,
     )

// Cross plate
sketch003 = startSketchOn(offsetPlane(XY, offset = 1))
  |> circle(center = [0, 0], radius = carafeDiameter / 2 - 0.15)

extrude001 = extrude(sketch003, length = 0.050)

sketch004 = startSketchOn(extrude001, face = END)
  |> startProfile(at = [0.3, 0.17])
  |> yLine(length = 1.2)
  |> arc(angleStart = 90, angleEnd = -30, radius = 1.2)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
  |> patternCircular2d(
       center = [0, 0],
       instances = 3,
       arcDegrees = 360,
       rotateDuplicates = true,
     )

extrude002 = extrude(sketch004, length = -0.050)

// Filter screen
sketch005 = startSketchOn(XZ)
  |> startProfile(at = [0.15, 1.11])
  |> xLine(endAbsolute = carafeDiameter / 2 - 0.2)
  |> angledLine(angle = 30, endAbsoluteX = carafeDiameter / 2 - 0.07, tag = $seg1)
  |> angledLine(angle = -60, length = 0.050)
  |> angledLine(angle = 30, length = -segLen(seg1))
  |> xLine(endAbsolute = 0.15)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
  |> revolve(axis = Y)

// Plunger and stem
sketch006 = startSketchOn(XZ)
  |> startProfile(at = [0.1, 1])
  |> line(end = [0.1, 0])
  |> angledLine(angle = 10, endAbsoluteX = 0.05)
  |> yLine(length = 10)
  |> line(end = [0.6, 0])
  |> yLine(length = -.05)
  |> tangentialArc(radius = 0.6, angle = -90)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
  |> revolve(axis = Y)

// Spiral plate
sketch007 = startSketchOn(offsetPlane(XY, offset = 1.12))
  |> circle(center = [0, 0], radius = carafeDiameter / 2 - 0.24)
  |> subtract2d(tool = circle(center = [0, 0], radius = .15))

extrude003 = extrude(sketch007, length = 0.050)

// Pattern holes in the spiral plate
sketch008 = startSketchOn(extrude003, face = END)
  |> circle(center = [1.4, 0], radius = .3)
  |> patternCircular2d(
       center = [0, 0],
       instances = 8,
       arcDegrees = 360,
       rotateDuplicates = true,
     )

extrude004 = extrude(sketch008, length = -0.050)

// Pattern holes in the spiral plate
sketch009 = startSketchOn(extrude003, face = END)
  |> circle(center = [0.6, 0], radius = .2)
  |> patternCircular2d(
       center = [0, 0],
       instances = 4,
       arcDegrees = 360,
       rotateDuplicates = true,
     )

extrude005 = extrude(sketch009, length = -0.050)

// Extrude a glass carafe body
sketch010 = startSketchOn(XY)
  |> circle(center = [0, 0], radius = carafeDiameter / 2)

// Perform a shell operation to hollow the carafe body with the top face removed
extrude006 = extrude(sketch010, length = carafeHeight)
  |> shell(faces = [END], thickness = .07)

// Draw and revolve the lid
sketch011 = startSketchOn(XZ)
  |> startProfile(at = [0.2, carafeHeight - 0.7])
  |> xLine(length = carafeDiameter / 2 - 0.3)
  |> yLine(length = 0.7)
  |> xLine(length = 0.3)
  |> yLine(length = 0.4)
  |> line(end = [-0.02, 0.02])
  |> bezierCurve(control1 = [-0.3, 0], control2 = [carafeDiameter / 10, 1], end = [-carafeDiameter / 2 - 0.1, 1])
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
  |> revolve(axis = Y)

// Draw and extrude handle
sketch012 = startSketchOn(offsetPlane(XZ, offset = handleThickness / 2))
  |> startProfile(at = [2.3, 6.4])
  |> line(end = [0.56, 0])
  |> tangentialArc(endAbsolute = [4.1, 5.26])
  |> tangentialArc(endAbsolute = [4.17, 1.6])
  |> tangentialArc(endAbsolute = [3.13, 0.61])
  |> line(end = [-1.09, 0])
  |> line(end = [0, 0.43])
  |> line(end = [0.99, -0.02])
  |> tangentialArc(endAbsolute = [3.63, 1.6])
  |> tangentialArc(endAbsolute = [3.56, 5.15])
  |> tangentialArc(endAbsolute = [2.72, 5.88])
  |> line(end = [-0.4, 0])
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
extrude007 = extrude(sketch012, length = -handleThickness)
