Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import_step: do not assign labels to Compound.for_construction #663

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/build123d/importers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import os
from math import degrees
from pathlib import Path
from typing import TextIO, Union
from typing import TextIO, Union, Optional

import OCP.IFSelect
from OCP.BRep import BRep_Builder
Expand Down Expand Up @@ -172,12 +172,14 @@ def get_col(obj: TopoDS_Shape) -> Quantity_ColorRGBA:

return shape_color

def build_assembly(assembly: Compound) -> list[Shape]:
def build_assembly(
assembly: Compound, parent_tdf_label: Optional[TDF_Label] = None
) -> list[Shape]:
tdf_labels = TDF_LabelSequence()
if assembly.for_construction is None:
if parent_tdf_label is None:
shape_tool.GetFreeShapes(tdf_labels)
else:
shape_tool.GetComponents_s(assembly.for_construction, tdf_labels)
shape_tool.GetComponents_s(parent_tdf_label, tdf_labels)

sub_shapes: list[Shape] = []
for i in range(tdf_labels.Length()):
Expand All @@ -195,13 +197,12 @@ def build_assembly(assembly: Compound) -> list[Shape]:
sub_shape_loc = assembly.location.wrapped.Multiplied(sub_shape_loc)
sub_shape: Shape = sub_shape_type()
sub_shape.wrapped = downcast(topo_shape.Moved(sub_shape_loc))
sub_shape.for_construction = ref_tdf_label
sub_shape.color = Color(get_color(topo_shape))
sub_shape.label = get_name(ref_tdf_label)

sub_shape.parent = assembly
if shape_tool.IsAssembly_s(ref_tdf_label):
sub_shape.children = build_assembly(sub_shape)
sub_shape.children = build_assembly(sub_shape, ref_tdf_label)
sub_shapes.append(sub_shape)
return sub_shapes

Expand Down
3 changes: 2 additions & 1 deletion src/build123d/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -2312,7 +2312,8 @@ def __deepcopy__(self, memo) -> Self:
cls = self.__class__
result = cls.__new__(cls)
memo[id(self)] = result
memo[id(self.wrapped)] = downcast(BRepBuilderAPI_Copy(self.wrapped).Shape())
if self.wrapped is not None:
memo[id(self.wrapped)] = downcast(BRepBuilderAPI_Copy(self.wrapped).Shape())
for key, value in self.__dict__.items():
setattr(result, key, copy.deepcopy(value, memo))
if key == "joints":
Expand Down
6 changes: 6 additions & 0 deletions tests/test_importers.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ def test_single_object(self):
box = import_step("test.step")
self.assertTrue(isinstance(box, Solid))

def test_move_single_object(self):
export_step(Solid.make_box(1, 1, 1), "test.step")
box = import_step("test.step")
box_moved = Pos(X=1) * box
self.assertEqual(tuple(box_moved.location.position), (1, 0, 0))

def test_single_label_color(self):
box_to_export = Solid.make_box(1, 1, 1)
box_to_export.label = "box"
Expand Down
Loading