Skip to content

Commit

Permalink
Ported PR #875 to refactored topology
Browse files Browse the repository at this point in the history
  • Loading branch information
gumyr committed Feb 18, 2025
1 parent 838933b commit 39b4fc2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/build123d/topology/two_d.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
from collections.abc import Iterable, Sequence

import OCP.TopAbs as ta
from OCP.BRep import BRep_Tool
from OCP.BRep import BRep_Tool, BRep_Builder
from OCP.BRepAdaptor import BRepAdaptor_Surface
from OCP.BRepAlgo import BRepAlgo
from OCP.BRepAlgoAPI import BRepAlgoAPI_Common
Expand Down Expand Up @@ -1453,10 +1453,13 @@ def __init__(
obj = obj_list[0]

if isinstance(obj, Face):
builder = BRepBuilderAPI_MakeShell(
BRepAdaptor_Surface(obj.wrapped).Surface().Surface()
)
obj = builder.Shape()
if obj.wrapped is None:
raise ValueError(f"Can't create a Shell from empty Face")
builder = BRep_Builder()
shell = TopoDS_Shell()
builder.MakeShell(shell)
builder.Add(shell, obj.wrapped)
obj = shell
elif isinstance(obj, Iterable):
obj = _sew_topods_faces([f.wrapped for f in obj])

Expand Down
6 changes: 6 additions & 0 deletions tests/test_direct_api/test_shells.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import math
import unittest

from build123d.build_enums import GeomType
from build123d.geometry import Plane, Rot, Vector
from build123d.objects_curve import JernArc, Polyline, Spline
from build123d.objects_sketch import Circle
Expand All @@ -42,6 +43,11 @@ def test_shell_init(self):
box_shell = Shell(box_faces)
self.assertTrue(box_shell.is_valid())

def test_shell_init_single_face(self):
face = Solid.make_cone(1, 0, 2).faces().filter_by(GeomType.CONE).first
shell = Shell(face)
self.assertTrue(shell.is_valid())

def test_center(self):
box_faces = Solid.make_box(1, 1, 1).faces()
box_shell = Shell(box_faces)
Expand Down

0 comments on commit 39b4fc2

Please sign in to comment.