gumyr / build123d

A python CAD programming library
Apache License 2.0
386 stars 72 forks source link

Generalize Extrude-until for more than four outcomes #575

Open jdegenstein opened 4 months ago

jdegenstein commented 4 months ago

Currently, extrude-until accepts the Until enum which has 4 values -- (Until.NEXT, Until.LAST, Until.PREVIOUS, Until.FIRST). See the below example for when having the ability to e.g. target all 8 faces would be valuable. I wonder if extending the target parameter to accept faces would be a reasonable approach? I have not investigated that idea yet. The great thing about the current behavior is that it is easy to use, so adding this functionality would ideally not compromise ease of use much.

with BuildPart() as p:
    with BuildSketch() as s:
        with BuildLine() as l:
            m1 = JernArc((0, 0), (1, 0), 20, -20)
            offset(amount=1, side=Side.LEFT)
        single = make_face(mode=Mode.PRIVATE)
        with Locations((0, 8)):
            with GridLocations(1, 8, 1, 2):
                add(single)
        mirror(about=Plane.XZ)
    revolve(axis=Axis.Y)
    with BuildSketch(-Plane.XZ) as s2:
        Circle(5)

complist = ShapeList()
alphas = list()
for i, unt in zip(range(5), (Until.NEXT, Until.LAST, Until.PREVIOUS, Until.FIRST)):
    complist.append(p.part.translate((i * 15, 0, 0)))
    complist.append(
        extrude(s2.sketch, until=unt, target=p.part).translate((i * 15, 0, 0))
    )
    alphas.append(0.3)
    alphas.append(1)

show(*complist, alphas=alphas)

image

gumyr commented 4 months ago

Nice illustration. One of the things that makes the until extrudes challenging is that it's very likely that the extrusion will not encounter a single Face but multiple Faces on a surface. IIRC the CadQuery version only handles a single Face which makes it not very useful. So, when a user specifies a Face (which is a Python object not a OCCT topographical object) the OCCT TopoDS_Face would need to be found and that would have to be a key to finding the whole surface.

A generalized solution isn't impossible but would be challenging. The current implementation could use some hardening as it's possible to break it when Faces are perpendicular to the direction of extrusion and there could be other issues - this is a higher priority to me.