Merge pull request #663 from mbugert/fix-issue-662

import_step: do not assign labels to Compound.for_construction
This commit is contained in:
Roger Maitland 2024-07-25 10:10:20 -04:00 committed by GitHub
commit cba77abbaf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 7 deletions

View file

@ -32,7 +32,7 @@ license:
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
@ -172,12 +172,14 @@ def import_step(filename: str) -> Compound:
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()):
@ -195,13 +197,12 @@ def import_step(filename: str) -> Compound:
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

View file

@ -2312,7 +2312,8 @@ class Shape(NodeMixin):
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":

View file

@ -108,6 +108,12 @@ class ImportSTEP(unittest.TestCase):
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"