Skip to content

Commit

Permalink
Added transition to 1D sweep - Issue #482
Browse files Browse the repository at this point in the history
  • Loading branch information
gumyr committed Feb 4, 2024
1 parent a8ee1b4 commit 7b5e154
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/build123d/operations_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,9 @@ def sweep(
new_faces = []
if edge_list:
for sec in section_list:
swept = Face.sweep(sec, path_wire) # Could generate a shell here
swept = Face.sweep(
sec, path_wire, transition
) # Could generate a shell here
new_faces.extend(swept.faces())

if context is not None:
Expand Down
47 changes: 37 additions & 10 deletions src/build123d/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@
from OCP.BRepOffsetAPI import (
BRepOffsetAPI_MakeFilling,
BRepOffsetAPI_MakeOffset,
BRepOffsetAPI_MakePipe,
BRepOffsetAPI_MakePipeShell,
BRepOffsetAPI_MakeThickSolid,
BRepOffsetAPI_ThruSections,
Expand Down Expand Up @@ -5597,16 +5596,44 @@ def sew_faces(cls, faces: Iterable[Face]) -> list[ShapeList[Face]]:

return sewn_faces

# @classmethod
# def sweep(cls, profile: Edge, path: Union[Edge, Wire]) -> Face:
# """Sweep a 1D profile along a 1D path"""
# if isinstance(path, Edge):
# path = Wire([path])
# # Ensure the edges in the path are ordered correctly
# path = Wire(path.order_edges())
# pipe_sweep = BRepOffsetAPI_MakePipe(path.wrapped, profile.wrapped)
# pipe_sweep.Build()
# return Face(pipe_sweep.Shape())

@classmethod
def sweep(cls, profile: Edge, path: Union[Edge, Wire]) -> Face:
"""Sweep a 1D profile along a 1D path"""
if isinstance(path, Edge):
path = Wire([path])
# Ensure the edges in the path are ordered correctly
path = Wire(path.order_edges())
pipe_sweep = BRepOffsetAPI_MakePipe(path.wrapped, profile.wrapped)
pipe_sweep.Build()
return Face(pipe_sweep.Shape())
def sweep(
cls,
profile: Union[Edge, Wire],
path: Union[Edge, Wire],
transition=Transition.RIGHT,
) -> Face:
"""sweep
Sweep a 1D profile along a 1D path
Args:
profile (Union[Edge, Wire]): the object to sweep
path (Union[Wire, Edge]): the path to follow when sweeping
transition (Transition, optional): handling of profile orientation at C1 path
discontinuities. Defaults to Transition.RIGHT.
Returns:
Face: resulting face, may be non-planar
"""
profile = profile.to_wire()
path = Wire(Wire(path).order_edges())
builder = BRepOffsetAPI_MakePipeShell(path.wrapped)
builder.Add(profile.wrapped, False, False)
builder.SetTransitionMode(Solid._transModeDict[transition])
builder.Build()
return Shape.cast(builder.Shape()).clean().face()

@classmethod
def make_surface_from_array_of_points(
Expand Down
7 changes: 7 additions & 0 deletions tests/test_build_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,13 @@ def test_sweep_edge(self):
self.assertTrue(isinstance(swept, Sketch))
self.assertAlmostEqual(swept.area, 2 * 10, 5)

def test_sweep_edge_along_wire(self):
spine = Polyline((0, 0), (1, 10), (10, 10))
with BuildSketch() as bs:
sect = spine.wire().perpendicular_line(2, 0)
sweep(sect, spine, transition=Transition.RIGHT)
self.assertGreater(bs.sketch.area, 38)

def test_no_path(self):
with self.assertRaises(ValueError):
sweep(PolarLine((1, 0), 2, 135))
Expand Down

0 comments on commit 7b5e154

Please sign in to comment.