cadquery/monitor/case.py
2022-07-23 16:12:56 -03:00

91 lines
2.3 KiB
Python

import cadquery2 as cq
from cadquery2 import exporters
from parameters import *
screen_cutout = (
cq.Sketch().trapezoid(screen_w, screen_l, 90, mode="a").reset().vertices().fillet(1)
)
board_cutout = (
cq.Sketch().trapezoid(55, 50, 90, mode="a").reset().vertices("<X").fillet(5)
)
cable_relief = cq.Sketch().trapezoid(width, 30, 90)
segment_breaks_top = (
cq.Sketch()
.rarray(1, length, 1, 1)
.trapezoid(width / 3, 35, 110, mode="a")
.reset()
.vertices()
.fillet(5)
)
segment_breaks_bottom = (
cq.Sketch()
.rarray(1, length, 1, 1)
.trapezoid(width / 3, 35, 70, mode="a")
.reset()
.vertices()
.fillet(5)
)
back_reinforcement = (
cq.Sketch().trapezoid(width / 2, 15, 90, mode="a").reset().vertices().fillet(2)
)
threaded_inserts = cq.Sketch().rarray(width / 8, 0, 4, 1).circle(ti_radius, mode="a")
# Case for the screen
case = (
# Basic filleted box shape
cq.Workplane("bottom")
.lineTo(-width, 0)
.lineTo(-width, height)
.lineTo(0, height)
.close()
.extrude(length)
.faces(">X")
.shell(-shell_t)
.edges("|X")
.fillet(fillet_s)
# Cutout visible screen area from top face
.faces(">Z")
.workplane(centerOption="CenterOfBoundBox")
.center((width - screen_w) / 2 - screen_left_margin, 0)
.placeSketch(screen_cutout)
.cutBlind(-shell_t)
# Cutout for segment breaks
.faces(">Z")
.workplane(centerOption="CenterOfBoundBox")
.center(0, length / 2)
.placeSketch(segment_breaks_top)
.cutBlind(-1000)
.center(0, -length)
.placeSketch(segment_breaks_bottom)
.cutBlind(-1000)
# Cutout for the circuit board
.faces("<Z")
.workplane(centerOption="CenterOfBoundBox")
.center(width / 2 - 27.5, 0)
.placeSketch(board_cutout)
.cutBlind(-shell_t)
# Make some room for the ribbon cable
.faces("<Z[-2]")
.workplane(centerOption="CenterOfBoundBox")
.placeSketch(cable_relief)
.cutBlind(-1)
# Back reinforcement with holes for threaded inserts
.faces("<Z")
.workplane(centerOption="CenterOfBoundBox")
.placeSketch(back_reinforcement)
.extrude(1 + 1 + ti_depth - shell_t)
.faces("<Z")
.workplane(centerOption="CenterOfBoundBox")
.placeSketch(threaded_inserts)
.cutBlind(-ti_depth)
)
exporters.export(case, "case.stl")