Skip to content

Commit

Permalink
Added Wire as input to Wire constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
gumyr committed Feb 3, 2024
1 parent b44c404 commit 92d3dc4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/build123d/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -7146,6 +7146,23 @@ def __init__(
parent (Compound, optional): assembly parent. Defaults to None.
"""

@overload
def __init__(
self,
wire: Wire,
label: str = "",
color: Color = None,
parent: Compound = None,
):
"""Build a Wire from an WIre - used when the input could be an Edge or Wire.
Args:
wire (Wire): Wire to convert to another Wire
label (str, optional): Defaults to ''.
color (Color, optional): Defaults to None.
parent (Compound, optional): assembly parent. Defaults to None.
"""

@overload
def __init__(
self,
Expand All @@ -7171,14 +7188,16 @@ def __init__(
"""

def __init__(self, *args, **kwargs):
edge, edges, sequenced, obj, label, color, parent = (None,) * 7
edge, edges, wire, sequenced, obj, label, color, parent = (None,) * 8

if args:
l_a = len(args)
if isinstance(args[0], TopoDS_Shape):
obj, label, color, parent = args[:4] + (None,) * (4 - l_a)
elif isinstance(args[0], Edge):
edge, label, color, parent = args[:4] + (None,) * (4 - l_a)
elif isinstance(args[0], Wire):
wire, label, color, parent = args[:4] + (None,) * (4 - l_a)
elif isinstance(args[0], Iterable):
edges, sequenced, label, color, parent = args[:5] + (None,) * (5 - l_a)

Expand All @@ -7200,7 +7219,9 @@ def __init__(self, *args, **kwargs):

if edge is not None:
edges = [edge]
if edges:
if wire is not None:
obj = wire.wrapped
elif edges:
obj = Wire._make_wire(edges, False if sequenced is None else sequenced)

super().__init__(
Expand Down
2 changes: 2 additions & 0 deletions tests/test_direct_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3673,6 +3673,8 @@ def test_constructor(self):
self.assertTrue(w6.is_valid())
self.assertEqual(w6.label, "w6")
self.assertTupleAlmostEquals(w6.color.to_tuple(), (1.0, 0.0, 0.0, 1.0), 5)
w7 = Wire(w6)
self.assertTrue(w7.is_valid())
with self.assertRaises(ValueError):
Wire(bob="fred")

Expand Down

0 comments on commit 92d3dc4

Please sign in to comment.