Skip to content

Commit

Permalink
Added Compound constructor and deprecated make_compound Issue #523
Browse files Browse the repository at this point in the history
  • Loading branch information
gumyr committed Feb 2, 2024
1 parent e6b9ca6 commit d520fc4
Show file tree
Hide file tree
Showing 15 changed files with 182 additions and 83 deletions.
6 changes: 2 additions & 4 deletions src/build123d/build_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def _add_to_context(
raise RuntimeError("Nothing to intersect with")
self._obj = self._obj.intersect(*typed[self._shape])
elif mode == Mode.REPLACE:
self._obj = Compound.make_compound(list(typed[self._shape]))
self._obj = Compound(list(typed[self._shape]))

if self._obj is not None and clean:
self._obj = self._obj.clean()
Expand Down Expand Up @@ -452,9 +452,7 @@ def _add_to_context(
if isinstance(self._obj, Compound):
self._obj = self._sub_class(self._obj.wrapped)
else:
self._obj = self._sub_class(
Compound.make_compound(self._shapes()).wrapped
)
self._obj = self._sub_class(Compound(self._shapes()).wrapped)

# Add to pending
if self._tag == "BuildPart":
Expand Down
2 changes: 1 addition & 1 deletion src/build123d/build_sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def sketch(self):
global_objs = []
for plane in workplanes:
global_objs.append(plane.from_local_coords(self._obj))
return Sketch(Compound.make_compound(global_objs).wrapped)
return Sketch(Compound(global_objs).wrapped)

def __init__(
self,
Expand Down
12 changes: 9 additions & 3 deletions src/build123d/exporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ def __init__(
BRepLib.BuildCurves3d_s(el, TOLERANCE)

# Convert and store the results.
self.visible_lines = Compound.make_compound(map(Shape, visible))
self.hidden_lines = Compound.make_compound(map(Shape, hidden))
self.visible_lines = Compound(map(Shape, visible))
self.hidden_lines = Compound(map(Shape, hidden))


# ---------------------------------------------------------------------------
Expand All @@ -149,6 +149,7 @@ def __init__(

class AutoNameEnum(Enum):
"""An enum class that automatically sets members' value to their name."""

@staticmethod
def _generate_next_value_(name, start, count, last_values):
return name
Expand Down Expand Up @@ -865,6 +866,7 @@ class ExportSVG(Export2D):
ValueError: Invalid unit.
"""

# pylint: disable=too-many-instance-attributes
_Converter = Callable[[Edge], ET.Element]

Expand Down Expand Up @@ -1375,7 +1377,11 @@ def _stroke_dasharray(self, layer: _Layer):
ltname = layer.line_type.value
_, pattern = Export2D.LINETYPE_DEFS[ltname]

d = self.dot_length.value if isinstance(self.dot_length, DotLength) else self.dot_length
d = (
self.dot_length.value
if isinstance(self.dot_length, DotLength)
else self.dot_length
)
pattern = copy(pattern)
plen = len(pattern)
for i in range(0, plen):
Expand Down
5 changes: 3 additions & 2 deletions src/build123d/importers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from build123d.geometry import Color
from build123d.topology import Compound, Face, Shape, ShapeList, Wire


def import_brep(file_name: str) -> Shape:
"""Import shape from a BREP file
Expand Down Expand Up @@ -86,7 +87,7 @@ def import_step(file_name: str) -> Compound:
reader = STEPControl_Reader()
read_status = reader.ReadFile(file_name)
# pylint fails to understand OCP's module here, so suppress on the next line.
if read_status != OCP.IFSelect.IFSelect_RetDone: # pylint: disable=no-member
if read_status != OCP.IFSelect.IFSelect_RetDone: # pylint: disable=no-member
raise ValueError(f"STEP File {file_name} could not be loaded")
for i in range(reader.NbRootsForTransfer()):
reader.TransferRoot(i + 1)
Expand All @@ -100,7 +101,7 @@ def import_step(file_name: str) -> Compound:
for shape in occ_shapes:
solids.append(Shape.cast(shape))

return Compound.make_compound(solids)
return Compound(solids)


def import_stl(file_name: str) -> Face:
Expand Down
9 changes: 5 additions & 4 deletions src/build123d/joints.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def symbol(self) -> Compound:
"""A CAD symbol representing the axis of rotation as bound to part"""
radius = self.parent.bounding_box().diagonal / 30

return Compound.make_compound(
return Compound(
[
Edge.make_line((0, 0, 0), (0, 0, radius * 10)),
Edge.make_circle(radius),
Expand Down Expand Up @@ -328,7 +328,7 @@ class LinearJoint(Joint):
def symbol(self) -> Compound:
"""A CAD symbol of the linear axis positioned relative to_part"""
radius = (self.linear_range[1] - self.linear_range[0]) / 15
return Compound.make_compound(
return Compound(
[
Edge.make_line(
(0, 0, self.linear_range[0]), (0, 0, self.linear_range[1])
Expand Down Expand Up @@ -492,13 +492,14 @@ class CylindricalJoint(Joint):
Raises:
ValueError: angle_reference must be normal to axis
"""

# pylint: disable=too-many-instance-attributes

@property
def symbol(self) -> Compound:
"""A CAD symbol representing the cylindrical axis as bound to part"""
radius = (self.linear_range[1] - self.linear_range[0]) / 15
return Compound.make_compound(
return Compound(
[
Edge.make_line(
(0, 0, self.linear_range[0]), (0, 0, self.linear_range[1])
Expand Down Expand Up @@ -640,7 +641,7 @@ def symbol(self) -> Compound:
circle_y = Edge.make_circle(radius, self.angle_reference.rotated((90, 0, 0)))
circle_z = Edge.make_circle(radius, self.angle_reference.rotated((0, 90, 0)))

return Compound.make_compound(
return Compound(
[
circle_x,
circle_y,
Expand Down
6 changes: 3 additions & 3 deletions src/build123d/objects_part.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ def __init__(
context._add_to_context(*new_solids, mode=mode)

if len(new_solids) > 1:
new_part = Compound.make_compound(new_solids).wrapped
new_part = Compound(new_solids).wrapped
elif isinstance(new_solids[0], Compound): # Don't add extra layers
new_part = new_solids[0].wrapped
else:
new_part = Compound.make_compound(new_solids).wrapped
new_part = Compound(new_solids).wrapped

super().__init__(
obj=new_part,
# obj=Compound.make_compound(new_solids).wrapped,
# obj=Compound(new_solids).wrapped,
label=part.label,
material=part.material,
joints=part.joints,
Expand Down
2 changes: 1 addition & 1 deletion src/build123d/objects_sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def __init__(
if isinstance(context, BuildSketch):
context._add_to_context(*new_faces, mode=mode)

super().__init__(Compound.make_compound(new_faces).wrapped)
super().__init__(Compound(new_faces).wrapped)


class Circle(BaseSketchObject):
Expand Down
28 changes: 14 additions & 14 deletions src/build123d/operations_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def add(
else:
raise RuntimeError(f"Builder {context.__class__.__name__} is unsupported")

return Compound.make_compound(new_objects)
return Compound(new_objects)


def bounding_box(
Expand Down Expand Up @@ -234,7 +234,7 @@ def bounding_box(
)
if context is not None:
context._add_to_context(*new_faces, mode=mode)
return Sketch(Compound.make_compound(new_faces).wrapped)
return Sketch(Compound(new_faces).wrapped)

new_objects = []
for obj in object_list:
Expand All @@ -251,7 +251,7 @@ def bounding_box(
)
if context is not None:
context._add_to_context(*new_objects, mode=mode)
return Part(Compound.make_compound(new_objects).wrapped)
return Part(Compound(new_objects).wrapped)


#:TypeVar("ChamferFilletType"): Type of objects which can be chamfered or filleted
Expand Down Expand Up @@ -326,7 +326,7 @@ def chamfer(

if context is not None:
context._add_to_context(new_part, mode=Mode.REPLACE)
return Part(Compound.make_compound([new_part]).wrapped)
return Part(Compound([new_part]).wrapped)

if target._dim == 2:
# Convert BaseSketchObject into Sketch so casting into Sketch during construction works
Expand All @@ -344,7 +344,7 @@ def chamfer(
)
else:
new_faces.append(face)
new_sketch = Sketch(Compound.make_compound(new_faces).wrapped)
new_sketch = Sketch(Compound(new_faces).wrapped)

if context is not None:
context._add_to_context(new_sketch, mode=Mode.REPLACE)
Expand Down Expand Up @@ -428,7 +428,7 @@ def fillet(

if context is not None:
context._add_to_context(new_part, mode=Mode.REPLACE)
return Part(Compound.make_compound([new_part]).wrapped)
return Part(Compound([new_part]).wrapped)

if target._dim == 2:
# Convert BaseSketchObject into Sketch so casting into Sketch during construction works
Expand All @@ -445,7 +445,7 @@ def fillet(
new_faces.append(face.fillet_2d(radius, vertices_in_face))
else:
new_faces.append(face)
new_sketch = Sketch(Compound.make_compound(new_faces).wrapped)
new_sketch = Sketch(Compound(new_faces).wrapped)

if context is not None:
context._add_to_context(new_sketch, mode=Mode.REPLACE)
Expand Down Expand Up @@ -522,7 +522,7 @@ def mirror(
if context is not None:
context._add_to_context(*mirrored, mode=mode)

mirrored_compound = Compound.make_compound(mirrored)
mirrored_compound = Compound(mirrored)
if all([obj._dim == 3 for obj in object_list]):
return Part(mirrored_compound.wrapped)
if all([obj._dim == 2 for obj in object_list]):
Expand Down Expand Up @@ -656,7 +656,7 @@ def offset(
if context is not None:
context._add_to_context(*new_objects, mode=mode)

offset_compound = Compound.make_compound(new_objects)
offset_compound = Compound(new_objects)
if all([obj._dim == 3 for obj in object_list]):
return Part(offset_compound.wrapped)
if all([obj._dim == 2 for obj in object_list]):
Expand Down Expand Up @@ -806,7 +806,7 @@ def project(
if projected_points:
result = ShapeList(projected_points)
else:
result = Compound.make_compound(projected_shapes)
result = Compound(projected_shapes)
if all([obj._dim == 2 for obj in object_list]):
result = Sketch(result.wrapped)
elif all([obj._dim == 1 for obj in object_list]):
Expand Down Expand Up @@ -881,7 +881,7 @@ def scale(
if context is not None:
context._add_to_context(*new_objects, mode=mode)

scale_compound = Compound.make_compound(new_objects)
scale_compound = Compound(new_objects)
if all([obj._dim == 3 for obj in object_list]):
return Part(scale_compound.wrapped)
if all([obj._dim == 2 for obj in object_list]):
Expand Down Expand Up @@ -934,7 +934,7 @@ def split(
if context is not None:
context._add_to_context(*new_objects, mode=mode)

split_compound = Compound.make_compound(new_objects)
split_compound = Compound(new_objects)
if all([obj._dim == 3 for obj in object_list]):
return Part(split_compound.wrapped)
if all([obj._dim == 2 for obj in object_list]):
Expand Down Expand Up @@ -1059,5 +1059,5 @@ def sweep(
new_faces = [face.clean() for face in new_faces]

if new_solids:
return Part(Compound.make_compound(new_solids).wrapped)
return Sketch(Compound.make_compound(new_faces).wrapped)
return Part(Compound(new_solids).wrapped)
return Sketch(Compound(new_faces).wrapped)
12 changes: 6 additions & 6 deletions src/build123d/operations_part.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def extrude(
if clean:
new_solids = [solid.clean() for solid in new_solids]

return Part(Compound.make_compound(new_solids).wrapped)
return Part(Compound(new_solids).wrapped)


def loft(
Expand Down Expand Up @@ -250,7 +250,7 @@ def loft(
elif clean:
new_solid = new_solid.clean()

return Part(Compound.make_compound([new_solid]).wrapped)
return Part(Compound([new_solid]).wrapped)


def make_brake_formed(
Expand Down Expand Up @@ -356,7 +356,7 @@ def make_brake_formed(
elif clean:
new_solid = new_solid.clean()

return Part(Compound.make_compound([new_solid]).wrapped)
return Part(Compound([new_solid]).wrapped)


def project_workplane(
Expand Down Expand Up @@ -472,7 +472,7 @@ def revolve(

new_solids.append(Solid.revolve(profile, angle, axis))

new_solid = Compound.make_compound(new_solids)
new_solid = Compound(new_solids)
if context is not None:
context._add_to_context(*new_solids, clean=clean, mode=mode)
elif clean:
Expand Down Expand Up @@ -541,7 +541,7 @@ def section(
if clean:
new_objects = [r.clean() for r in new_objects]

return Sketch(Compound.make_compound(new_objects).wrapped)
return Sketch(Compound(new_objects).wrapped)


def thicken(
Expand Down Expand Up @@ -616,4 +616,4 @@ def thicken(
if clean:
new_solids = [solid.clean() for solid in new_solids]

return Part(Compound.make_compound(new_solids).wrapped)
return Part(Compound(new_solids).wrapped)
4 changes: 2 additions & 2 deletions src/build123d/operations_sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def make_face(
context._add_to_context(pending_face, mode=mode)
context.pending_edges = ShapeList()

return Sketch(Compound.make_compound([pending_face]).wrapped)
return Sketch(Compound([pending_face]).wrapped)


def make_hull(
Expand Down Expand Up @@ -104,7 +104,7 @@ def make_hull(
context._add_to_context(pending_face, mode=mode)
context.pending_edges = ShapeList()

return Sketch(Compound.make_compound([pending_face]).wrapped)
return Sketch(Compound([pending_face]).wrapped)


def trace(
Expand Down
Loading

0 comments on commit d520fc4

Please sign in to comment.