cadquery/notebook_nueva/screen_mount.py

133 lines
4.4 KiB
Python
Raw Normal View History

2023-02-17 17:32:01 +00:00
import cadquery as cq
from cadquery import exporters
2022-11-24 20:45:59 +00:00
import dimensions as dim
2022-11-24 20:45:59 +00:00
viewport_cutout = (
cq.Sketch().trapezoid(dim.vis_w, dim.vis_h, 90, mode="a").vertices().fillet(2)
)
screen_cutout = cq.Sketch().trapezoid(dim.scr_w, dim.scr_h, 90, mode="a")
2022-11-25 20:11:31 +00:00
# Circuit board and cable hole.
# This is in the back of the screen, and is a bit shorter in height than the
# screen. It's wider so it removes enough material to make the shape simpler.
2022-11-25 17:46:30 +00:00
board_cutout = cq.Sketch().trapezoid(
dim.scr_w + 5,
dim.scr_h - 10,
2022-11-25 17:46:30 +00:00
90,
2022-11-25 15:28:39 +00:00
mode="a",
)
kbd_cable_hole = cq.Sketch().trapezoid(20, 9, 90, mode="a").vertices().fillet(1)
2023-03-28 14:33:40 +00:00
# y needs to be inverted because this is the top side, adn there's 2 pillars we don't use
dim.mounting_pillar_positions = [(x, -y) for x, y in dim.mounting_pillar_positions[:-2]]
mounting_pillars = (
cq.Sketch()
.push(dim.mounting_pillar_positions)
.trapezoid(-12, 12, 90, mode="a")
.circle(dim.ti_radius, mode="s")
.clean()
)
2022-11-25 20:11:31 +00:00
2022-11-25 15:28:39 +00:00
def model():
return (
cq.Workplane("XY")
.workplane()
.tag("mid_height")
.box(dim.width, dim.tl_height, dim.tl_full_thickness)
# The screen goes rotated
2022-11-25 15:28:39 +00:00
.faces(">Z")
.transformed(rotate=(dim.tl_scr_angle, 0, 0))
# Move the screen "lower" so it doesn't interfere
# so much with the back
.center(0, -2)
2022-11-25 15:28:39 +00:00
.tag("slanted")
2022-11-25 20:11:31 +00:00
# Arbitrary huge trapezoid to cut off the material *in front*
# of the inclined screen
2022-11-25 15:28:39 +00:00
.placeSketch(cq.Sketch().trapezoid(1000, 1000, 90, mode="a"))
.cutBlind(1000)
# Trim the top
.workplaneFromTagged("mid_height")
.workplane(offset=21)
.placeSketch(cq.Sketch().trapezoid(1000, 1000, 90, mode="a"))
.cutBlind(100)
# Make bottom smaller to fit with base
.faces(">X")
.workplane(centerOption="CenterOfBoundBox")
.center(-dim.tl_height / 2, -dim.tl_full_thickness / 2)
.placeSketch(
cq.Sketch()
.polygon(
[
(dim.tl_height_bottom, 0),
(dim.tl_height_bottom, dim.tl_full_thickness / 3),
(dim.tl_height, dim.tl_full_thickness - 21),
(dim.tl_height, dim.tl_full_thickness),
(dim.tl_height + 5, dim.tl_full_thickness + 5),
(dim.tl_height + 5, 0),
(dim.tl_height_bottom, 0),
]
)
.vertices()
.fillet(3)
)
.cutBlind(-1000)
2023-01-27 20:01:37 +00:00
# Fillet top of the object
.edges("|X and >Z")
.fillet(3)
# Cut off viewport hole so we can see the screen
.workplaneFromTagged("slanted")
.placeSketch(viewport_cutout)
.cutBlind(-dim.shell_t)
2023-01-27 20:01:37 +00:00
# Make hole for screen assembly so the whole screen fits
.workplaneFromTagged("slanted")
.workplane(offset=-dim.shell_t, centerOption="CenterOfBoundBox")
2023-01-27 20:01:37 +00:00
# Left bezel is wider than right one, so this hole is displaced to the left
.center(-3, 0)
.placeSketch(screen_cutout)
.cutBlind(-dim.scr_thickness)
2022-11-25 15:28:39 +00:00
# Make it hollow
.faces("<Z")
# Can't be exactly shell_t because cq fails
.shell(-dim.shell_t + 0.01)
2022-11-25 20:11:31 +00:00
# Cut hole for the screen board and cables
2022-11-25 15:28:39 +00:00
.workplaneFromTagged("slanted")
.workplane(offset=-dim.scr_thickness, centerOption="CenterOfBoundBox")
2022-11-25 20:11:31 +00:00
.placeSketch(board_cutout)
2022-11-28 15:19:56 +00:00
.cutBlind(-6)
.workplaneFromTagged("mid_height")
.workplane(offset=-dim.tl_full_thickness / 2, centerOption="CenterOfBoundBox")
.center(-dim.width / 2, dim.tl_height_bottom - dim.tl_height / 2 - dim.shell_t)
.placeSketch(mounting_pillars)
.extrude(10)
# Fillet the front edge of the screen case so it looks softer
.edges(">(0, -10, 5)")
.fillet(2)
2022-11-25 15:28:39 +00:00
)
2022-11-30 17:29:42 +00:00
if __name__ == "__main__":
2023-04-08 17:43:29 +00:00
model = model()
exporters.export(model, "screen_mount.stl")
2022-11-24 20:45:59 +00:00
offset_width = -dim.width / 2
2022-11-30 17:29:42 +00:00
right_side = (
2023-04-08 17:43:29 +00:00
model.faces(">X")
.workplane(centerOption="CenterOfBoundBox", offset=offset_width)
2022-11-30 17:29:42 +00:00
.split(keepTop=True)
)
exporters.export(right_side, "right_screen_mount.stl")
left_side = (
2023-04-08 17:43:29 +00:00
model.faces(">X")
.workplane(centerOption="CenterOfBoundBox", offset=offset_width)
2022-11-30 17:29:42 +00:00
.split(keepBottom=True)
)
2022-11-24 20:45:59 +00:00
2022-11-30 17:29:42 +00:00
exporters.export(left_side, "left_screen_mount.stl")