Added transition to 1D sweep - Issue #482

This commit is contained in:
gumyr 2024-02-03 20:05:10 -05:00
parent a8ee1b492d
commit 7b5e154666
3 changed files with 47 additions and 11 deletions

View file

@ -1047,7 +1047,9 @@ def sweep(
new_faces = [] new_faces = []
if edge_list: if edge_list:
for sec in section_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()) new_faces.extend(swept.faces())
if context is not None: if context is not None:

View file

@ -122,7 +122,6 @@ from OCP.BRepOffset import BRepOffset_MakeOffset, BRepOffset_Skin
from OCP.BRepOffsetAPI import ( from OCP.BRepOffsetAPI import (
BRepOffsetAPI_MakeFilling, BRepOffsetAPI_MakeFilling,
BRepOffsetAPI_MakeOffset, BRepOffsetAPI_MakeOffset,
BRepOffsetAPI_MakePipe,
BRepOffsetAPI_MakePipeShell, BRepOffsetAPI_MakePipeShell,
BRepOffsetAPI_MakeThickSolid, BRepOffsetAPI_MakeThickSolid,
BRepOffsetAPI_ThruSections, BRepOffsetAPI_ThruSections,
@ -5597,16 +5596,44 @@ class Face(Shape):
return sewn_faces 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 @classmethod
def sweep(cls, profile: Edge, path: Union[Edge, Wire]) -> Face: def sweep(
"""Sweep a 1D profile along a 1D path""" cls,
if isinstance(path, Edge): profile: Union[Edge, Wire],
path = Wire([path]) path: Union[Edge, Wire],
# Ensure the edges in the path are ordered correctly transition=Transition.RIGHT,
path = Wire(path.order_edges()) ) -> Face:
pipe_sweep = BRepOffsetAPI_MakePipe(path.wrapped, profile.wrapped) """sweep
pipe_sweep.Build()
return Face(pipe_sweep.Shape()) 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 @classmethod
def make_surface_from_array_of_points( def make_surface_from_array_of_points(

View file

@ -824,6 +824,13 @@ class TestSweep(unittest.TestCase):
self.assertTrue(isinstance(swept, Sketch)) self.assertTrue(isinstance(swept, Sketch))
self.assertAlmostEqual(swept.area, 2 * 10, 5) 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): def test_no_path(self):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
sweep(PolarLine((1, 0), 2, 135)) sweep(PolarLine((1, 0), 2, 135))