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 @overload
def __init__( def __init__(
self, self,
obj: TopoDS_Face, obj: TopoDS_Face | Plane,
label: str = "", label: str = "",
color: Color | None = None, color: Color | None = None,
parent: Compound | 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 """Build a Face from an OCCT TopoDS_Shape/TopoDS_Face
Args: Args:
obj (TopoDS_Shape, optional): OCCT Face. obj (TopoDS_Shape | Plane, optional): OCCT Face or Plane.
label (str, optional): Defaults to ''. label (str, optional): Defaults to ''.
color (Color, optional): Defaults to None. color (Color, optional): Defaults to None.
parent (Compound, optional): assembly parent. Defaults to None. parent (Compound, optional): assembly parent. Defaults to None.
@ -489,7 +489,9 @@ class Face(Mixin2D[TopoDS_Face]):
if args: if args:
l_a = len(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) obj, label, color, parent = args[:4] + (None,) * (4 - l_a)
elif isinstance(args[0], Wire): elif isinstance(args[0], Wire):
outer_wire, inner_wires, label, color, parent = args[:5] + (None,) * ( outer_wire, inner_wires, label, color, parent = args[:5] + (None,) * (
@ -518,6 +520,9 @@ class Face(Mixin2D[TopoDS_Face]):
color = kwargs.get("color", color) color = kwargs.get("color", color)
parent = kwargs.get("parent", parent) parent = kwargs.get("parent", parent)
if isinstance(obj, Plane):
obj = BRepBuilderAPI_MakeFace(obj.wrapped).Face()
if outer_wire is not None: if outer_wire is not None:
inner_topods_wires = ( inner_topods_wires = (
[w.wrapped for w in inner_wires] if inner_wires is not None else [] [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, plane: Plane = Plane.XY,
) -> Face: ) -> Face:
"""Create a unlimited size Face aligned with plane""" """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() pln_shape = BRepBuilderAPI_MakeFace(plane.wrapped).Face()
return cls(pln_shape) return cls(pln_shape)

View file

@ -130,8 +130,8 @@ class TestFace(unittest.TestCase):
distance=1, distance2=2, vertices=[vertex], edge=other_edge distance=1, distance2=2, vertices=[vertex], edge=other_edge
) )
def test_make_rect(self): def test_plane_as_face(self):
test_face = Face.make_plane() test_face = Face(Plane.XY)
self.assertAlmostEqual(test_face.normal_at(), (0, 0, 1), 5) self.assertAlmostEqual(test_face.normal_at(), (0, 0, 1), 5)
def test_length_width(self): 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.assertAlmostEqual(Vector(verts[0]), (1, 2, 0), 5)
self.assertListEqual(edges, []) 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.assertAlmostEqual(Vector(verts[0]), (1, 2, 0), 5)
self.assertListEqual(edges, []) self.assertListEqual(edges, [])
@ -493,7 +493,7 @@ class TestShape(unittest.TestCase):
self.assertEqual(len(edges1), 1) self.assertEqual(len(edges1), 1)
self.assertAlmostEqual(edges1[0].length, 20, 5) 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(vertices2), 1)
self.assertEqual(len(edges2), 1) self.assertEqual(len(edges2), 1)
self.assertAlmostEqual(Vector(vertices2[0]), (5, 0, 0), 5) self.assertAlmostEqual(Vector(vertices2[0]), (5, 0, 0), 5)