This commit is contained in:
Bruno Postle
2026-03-23 22:52:09 +00:00
parent d33c53b55a
commit 6b7318321b
4 changed files with 16 additions and 32 deletions
@@ -61,19 +61,13 @@ def copy_representation(
ifcopenshell.api.geometry.copy_representation(model,
source=wall_a, target=wall_b)
"""
source_rep = ifcopenshell.util.representation.get_representation(
source, "Model", context_identifier
)
source_rep = ifcopenshell.util.representation.get_representation(source, "Model", context_identifier)
if source_rep is None:
return None
new_rep = ifcopenshell.util.element.copy_deep(
file, source_rep, exclude=["IfcGeometricRepresentationContext"]
)
new_rep = ifcopenshell.util.element.copy_deep(file, source_rep, exclude=["IfcGeometricRepresentationContext"])
existing_rep = ifcopenshell.util.representation.get_representation(
target, "Model", context_identifier
)
existing_rep = ifcopenshell.util.representation.get_representation(target, "Model", context_identifier)
if existing_rep:
ifcopenshell.api.geometry.unassign_representation(file, product=target, representation=existing_rep)
ifcopenshell.api.geometry.remove_representation(file, representation=existing_rep)
@@ -102,7 +102,6 @@ class TestClipSolid(test.bootstrap.IFC4):
assert result.is_a("IfcBooleanClippingResult")
assert result.SecondOperand.is_a("IfcHalfSpaceSolid")
def test_element_registers_result_in_bbim_boolean(self):
extrusion = self.make_extrusion()
wall = self.file.createIfcWall()
@@ -147,7 +147,6 @@ class TestClipSolidBounded(test.bootstrap.IFC4):
assert result.FirstOperand == first_clip
assert first_clip.FirstOperand == extrusion
def test_element_registers_result_in_bbim_boolean(self):
extrusion = self.make_extrusion()
wall = self.file.createIfcWall()
@@ -28,14 +28,18 @@ class TestCopyRepresentation(test.bootstrap.IFC4):
body = ifcopenshell.util.representation.get_context(self.file, "Model", "Body", "MODEL_VIEW")
if body is None:
model = self.file.createIfcGeometricRepresentationContext(
ContextType="Model", CoordinateSpaceDimension=3, Precision=1e-5,
ContextType="Model",
CoordinateSpaceDimension=3,
Precision=1e-5,
WorldCoordinateSystem=self.file.createIfcAxis2Placement3D(
self.file.createIfcCartesianPoint((0.0, 0.0, 0.0))
),
)
body = self.file.createIfcGeometricRepresentationSubContext(
ContextIdentifier="Body", ContextType="Model",
TargetView="MODEL_VIEW", ParentContext=model,
ContextIdentifier="Body",
ContextType="Model",
TargetView="MODEL_VIEW",
ParentContext=model,
)
return body
@@ -52,9 +56,7 @@ class TestCopyRepresentation(test.bootstrap.IFC4):
wall_b = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
self._add_body_rep(wall_a)
result = ifcopenshell.api.geometry.copy_representation(
self.file, source=wall_a, target=wall_b
)
result = ifcopenshell.api.geometry.copy_representation(self.file, source=wall_a, target=wall_b)
assert result is not None
assert result.is_a("IfcShapeRepresentation")
@@ -67,9 +69,7 @@ class TestCopyRepresentation(test.bootstrap.IFC4):
wall_b = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
source_rep = self._add_body_rep(wall_a)
new_rep = ifcopenshell.api.geometry.copy_representation(
self.file, source=wall_a, target=wall_b
)
new_rep = ifcopenshell.api.geometry.copy_representation(self.file, source=wall_a, target=wall_b)
assert new_rep.id() != source_rep.id()
assert new_rep.Items[0].id() != source_rep.Items[0].id()
@@ -79,9 +79,7 @@ class TestCopyRepresentation(test.bootstrap.IFC4):
wall_b = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
source_rep = self._add_body_rep(wall_a)
new_rep = ifcopenshell.api.geometry.copy_representation(
self.file, source=wall_a, target=wall_b
)
new_rep = ifcopenshell.api.geometry.copy_representation(self.file, source=wall_a, target=wall_b)
assert new_rep.ContextOfItems.id() == source_rep.ContextOfItems.id()
@@ -92,9 +90,7 @@ class TestCopyRepresentation(test.bootstrap.IFC4):
old_rep = self._add_body_rep(wall_b)
old_rep_id = old_rep.id()
ifcopenshell.api.geometry.copy_representation(
self.file, source=wall_a, target=wall_b
)
ifcopenshell.api.geometry.copy_representation(self.file, source=wall_a, target=wall_b)
try:
self.file.by_id(old_rep_id)
@@ -108,9 +104,7 @@ class TestCopyRepresentation(test.bootstrap.IFC4):
source_rep = self._add_body_rep(wall_a)
source_rep_id = source_rep.id()
ifcopenshell.api.geometry.copy_representation(
self.file, source=wall_a, target=wall_b
)
ifcopenshell.api.geometry.copy_representation(self.file, source=wall_a, target=wall_b)
assert self.file.by_id(source_rep_id) is not None # source must still exist
assert ifcopenshell.util.representation.get_representation(wall_a, "Model", "Body") is not None
@@ -119,9 +113,7 @@ class TestCopyRepresentation(test.bootstrap.IFC4):
wall_a = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
wall_b = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
result = ifcopenshell.api.geometry.copy_representation(
self.file, source=wall_a, target=wall_b
)
result = ifcopenshell.api.geometry.copy_representation(self.file, source=wall_a, target=wall_b)
assert result is None