mirror of
https://github.com/gumyr/build123d.git
synced 2025-12-06 02:30:55 -08:00
Added transition to 1D sweep - Issue #482
This commit is contained in:
parent
a8ee1b492d
commit
7b5e154666
3 changed files with 47 additions and 11 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -122,7 +122,6 @@ from OCP.BRepOffset import BRepOffset_MakeOffset, BRepOffset_Skin
|
|||
from OCP.BRepOffsetAPI import (
|
||||
BRepOffsetAPI_MakeFilling,
|
||||
BRepOffsetAPI_MakeOffset,
|
||||
BRepOffsetAPI_MakePipe,
|
||||
BRepOffsetAPI_MakePipeShell,
|
||||
BRepOffsetAPI_MakeThickSolid,
|
||||
BRepOffsetAPI_ThruSections,
|
||||
|
|
@ -5597,16 +5596,44 @@ class Face(Shape):
|
|||
|
||||
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(
|
||||
|
|
|
|||
|
|
@ -824,6 +824,13 @@ class TestSweep(unittest.TestCase):
|
|||
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))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue