This commit is contained in:
gumyr 2025-11-08 10:29:53 -05:00
commit 38e69844b3
3 changed files with 18 additions and 7 deletions

View file

@ -451,7 +451,7 @@ class Face(Mixin2D[TopoDS_Face]):
@overload
def __init__(
self,
obj: TopoDS_Face,
obj: TopoDS_Face | Plane,
label: str = "",
color: Color | None = None,
parent: Compound | None = None,
@ -459,7 +459,7 @@ class Face(Mixin2D[TopoDS_Face]):
"""Build a Face from an OCCT TopoDS_Shape/TopoDS_Face
Args:
obj (TopoDS_Shape, optional): OCCT Face.
obj (TopoDS_Shape | Plane, optional): OCCT Face or Plane.
label (str, optional): Defaults to ''.
color (Color, optional): Defaults to None.
parent (Compound, optional): assembly parent. Defaults to None.
@ -489,7 +489,9 @@ class Face(Mixin2D[TopoDS_Face]):
if args:
l_a = len(args)
if isinstance(args[0], TopoDS_Shape):
if isinstance(args[0], Plane):
obj = args[0]
elif isinstance(args[0], TopoDS_Shape):
obj, label, color, parent = args[:4] + (None,) * (4 - l_a)
elif isinstance(args[0], Wire):
outer_wire, inner_wires, label, color, parent = args[:5] + (None,) * (
@ -518,6 +520,9 @@ class Face(Mixin2D[TopoDS_Face]):
color = kwargs.get("color", color)
parent = kwargs.get("parent", parent)
if isinstance(obj, Plane):
obj = BRepBuilderAPI_MakeFace(obj.wrapped).Face()
if outer_wire is not None:
inner_topods_wires = (
[w.wrapped for w in inner_wires] if inner_wires is not None else []
@ -1033,6 +1038,12 @@ class Face(Mixin2D[TopoDS_Face]):
plane: Plane = Plane.XY,
) -> Face:
"""Create a unlimited size Face aligned with plane"""
warnings.warn(
"The 'make_plane' method is deprecated and will be removed in a future version.",
DeprecationWarning,
stacklevel=2,
)
pln_shape = BRepBuilderAPI_MakeFace(plane.wrapped).Face()
return cls(pln_shape)

View file

@ -130,8 +130,8 @@ class TestFace(unittest.TestCase):
distance=1, distance2=2, vertices=[vertex], edge=other_edge
)
def test_make_rect(self):
test_face = Face.make_plane()
def test_plane_as_face(self):
test_face = Face(Plane.XY)
self.assertAlmostEqual(test_face.normal_at(), (0, 0, 1), 5)
def test_length_width(self):

View file

@ -475,7 +475,7 @@ class TestShape(unittest.TestCase):
self.assertAlmostEqual(Vector(verts[0]), (1, 2, 0), 5)
self.assertListEqual(edges, [])
verts, edges = Vertex(1, 2, 0)._ocp_section(Face.make_plane(Plane.XY))
verts, edges = Vertex(1, 2, 0)._ocp_section(Face(Plane.XY))
self.assertAlmostEqual(Vector(verts[0]), (1, 2, 0), 5)
self.assertListEqual(edges, [])
@ -493,7 +493,7 @@ class TestShape(unittest.TestCase):
self.assertEqual(len(edges1), 1)
self.assertAlmostEqual(edges1[0].length, 20, 5)
vertices2, edges2 = cylinder._ocp_section(Face.make_plane(pln))
vertices2, edges2 = cylinder._ocp_section(Face(pln))
self.assertEqual(len(vertices2), 1)
self.assertEqual(len(edges2), 1)
self.assertAlmostEqual(Vector(vertices2[0]), (5, 0, 0), 5)