mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 10:11:46 +00:00
Fix terrible bug #1819 where duplicating mapped elements didn't actually copy the geometry mapping.
This commit is contained in:
@@ -169,7 +169,7 @@ class IfcExporter:
|
|||||||
if parent.is_a("IfcSpatialStructureElement") and not element.is_a("IfcSpatialStructureElement"):
|
if parent.is_a("IfcSpatialStructureElement") and not element.is_a("IfcSpatialStructureElement"):
|
||||||
if parent != ifcopenshell.util.element.get_container(element):
|
if parent != ifcopenshell.util.element.get_container(element):
|
||||||
blenderbim.core.spatial.assign_container(
|
blenderbim.core.spatial.assign_container(
|
||||||
tool.Ifc, tool.Collector, tool.Container, structure_obj=parent_obj, element_obj=obj
|
tool.Ifc, tool.Collector, tool.Spatial, structure_obj=parent_obj, element_obj=obj
|
||||||
)
|
)
|
||||||
elif parent != ifcopenshell.util.element.get_aggregate(element):
|
elif parent != ifcopenshell.util.element.get_aggregate(element):
|
||||||
blenderbim.core.aggregate.assign_object(
|
blenderbim.core.aggregate.assign_object(
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ def copy_class(ifc, collector, root, obj=None):
|
|||||||
ifc.link(element, obj)
|
ifc.link(element, obj)
|
||||||
relating_type = root.get_element_type(element)
|
relating_type = root.get_element_type(element)
|
||||||
if relating_type and root.does_type_have_representations(relating_type):
|
if relating_type and root.does_type_have_representations(relating_type):
|
||||||
ifc.run("type.assign_type", related_object=element, relating_type=relating_type)
|
ifc.run("type.map_type_representations", related_object=element, relating_type=relating_type)
|
||||||
else:
|
else:
|
||||||
root.run_geometry_add_representation(obj=obj, context=root.get_object_context(obj))
|
root.run_geometry_add_representation(obj=obj, context=root.get_object_context(obj))
|
||||||
collector.assign(obj)
|
collector.assign(obj)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ markers =
|
|||||||
geometry
|
geometry
|
||||||
material
|
material
|
||||||
misc
|
misc
|
||||||
|
model
|
||||||
owner
|
owner
|
||||||
patch
|
patch
|
||||||
project
|
project
|
||||||
|
|||||||
@@ -89,3 +89,19 @@ Scenario: Override duplicate move - with active IFC data
|
|||||||
And the object "IfcWall/Cube.001" is an "IfcWall"
|
And the object "IfcWall/Cube.001" is an "IfcWall"
|
||||||
And the object "IfcBuildingStorey/My Storey.001" exists
|
And the object "IfcBuildingStorey/My Storey.001" exists
|
||||||
And the object "IfcBuildingStorey/My Storey.001" is an "IfcBuildingStorey"
|
And the object "IfcBuildingStorey/My Storey.001" is an "IfcBuildingStorey"
|
||||||
|
|
||||||
|
Scenario: Override duplicate move - copying a type instance with a representation map
|
||||||
|
Given an empty IFC project
|
||||||
|
And I add a cube
|
||||||
|
And the object "Cube" is selected
|
||||||
|
And I set "scene.BIMRootProperties.ifc_product" to "IfcElementType"
|
||||||
|
And I set "scene.BIMRootProperties.ifc_class" to "IfcWallType"
|
||||||
|
And I press "bim.assign_class"
|
||||||
|
And I set "scene.BIMTypeProperties.ifc_class" to "IfcWallType"
|
||||||
|
And the variable "cube" is "{ifc}.by_type('IfcWallType')[0].id()"
|
||||||
|
And I set "scene.BIMTypeProperties.relating_type" to "{cube}"
|
||||||
|
And I press "bim.add_type_instance"
|
||||||
|
And the object "IfcWall/Instance" is selected
|
||||||
|
When I press "object.duplicate_move"
|
||||||
|
Then the object "IfcWall/Instance.001" exists
|
||||||
|
And the object "IfcWall/Instance.001" has a "MappedRepresentation" representation of "Model/Body/MODEL_VIEW"
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
@model
|
||||||
|
Feature: Model
|
||||||
|
|
||||||
|
Scenario: Add type instance - add from a mesh
|
||||||
|
Given an empty IFC project
|
||||||
|
And I add a cube
|
||||||
|
And the object "Cube" is selected
|
||||||
|
And I set "scene.BIMRootProperties.ifc_product" to "IfcElementType"
|
||||||
|
And I set "scene.BIMRootProperties.ifc_class" to "IfcWallType"
|
||||||
|
And I press "bim.assign_class"
|
||||||
|
And I set "scene.BIMTypeProperties.ifc_class" to "IfcWallType"
|
||||||
|
And the variable "cube" is "{ifc}.by_type('IfcWallType')[0].id()"
|
||||||
|
And I set "scene.BIMTypeProperties.relating_type" to "{cube}"
|
||||||
|
When I press "bim.add_type_instance"
|
||||||
|
Then the object "IfcWall/Instance" exists
|
||||||
|
|
||||||
|
Scenario: Add type instance - add from an empty
|
||||||
|
Given an empty IFC project
|
||||||
|
And I add an empty
|
||||||
|
And the object "Empty" is selected
|
||||||
|
And I set "scene.BIMRootProperties.ifc_product" to "IfcElementType"
|
||||||
|
And I set "scene.BIMRootProperties.ifc_class" to "IfcWallType"
|
||||||
|
And I press "bim.assign_class"
|
||||||
|
And I set "scene.BIMTypeProperties.ifc_class" to "IfcWallType"
|
||||||
|
And the variable "empty" is "{ifc}.by_type('IfcWallType')[0].id()"
|
||||||
|
And I set "scene.BIMTypeProperties.relating_type" to "{empty}"
|
||||||
|
When I press "bim.add_type_instance"
|
||||||
|
Then the object "IfcWall/Instance" exists
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import bpy
|
import bpy
|
||||||
|
import webbrowser
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import blenderbim.tool as tool
|
import blenderbim.tool as tool
|
||||||
import blenderbim.bim
|
import blenderbim.bim
|
||||||
@@ -29,6 +30,9 @@ scenarios("feature")
|
|||||||
|
|
||||||
variables = {"cwd": os.getcwd(), "ifc": "IfcStore.get_file()"}
|
variables = {"cwd": os.getcwd(), "ifc": "IfcStore.get_file()"}
|
||||||
|
|
||||||
|
# Monkey-patch webbrowser opening since we want to test headlessly
|
||||||
|
webbrowser.open = lambda x: True
|
||||||
|
|
||||||
|
|
||||||
def replace_variables(value):
|
def replace_variables(value):
|
||||||
for key, new_value in variables.items():
|
for key, new_value in variables.items():
|
||||||
@@ -204,14 +208,14 @@ def the_object_name_has_a_body_of_value(name, value):
|
|||||||
assert the_object_name_exists(name).data.body == value
|
assert the_object_name_exists(name).data.body == value
|
||||||
|
|
||||||
|
|
||||||
@then(parsers.parse('the object "{name}" has a "{_type}" representation of "{context}"'))
|
@then(parsers.parse('the object "{name}" has a "{type}" representation of "{context}"'))
|
||||||
def the_object_name_has_a_type_representation_of_context(name, _type, context):
|
def the_object_name_has_a_representation_type_of_context(name, type, context):
|
||||||
ifc = an_ifc_file_exists()
|
ifc = an_ifc_file_exists()
|
||||||
element = ifc.by_id(the_object_name_exists(name).BIMObjectProperties.ifc_definition_id)
|
element = ifc.by_id(the_object_name_exists(name).BIMObjectProperties.ifc_definition_id)
|
||||||
context, subcontext, target_view = context.split("/")
|
context, subcontext, target_view = context.split("/")
|
||||||
assert ifcopenshell.util.representation.get_representation(
|
rep = ifcopenshell.util.representation.get_representation(element, context, subcontext or None, target_view or None)
|
||||||
element, context, subcontext or None, target_view or None
|
assert rep
|
||||||
)
|
assert rep.RepresentationType == type
|
||||||
|
|
||||||
|
|
||||||
@then(parsers.parse('the material "{name}" exists'))
|
@then(parsers.parse('the material "{name}" exists'))
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class TestCopyClass:
|
|||||||
ifc.link("element", "obj").should_be_called()
|
ifc.link("element", "obj").should_be_called()
|
||||||
root.get_element_type("element").should_be_called().will_return("type")
|
root.get_element_type("element").should_be_called().will_return("type")
|
||||||
root.does_type_have_representations("type").should_be_called().will_return(True)
|
root.does_type_have_representations("type").should_be_called().will_return(True)
|
||||||
ifc.run("type.assign_type", related_object="element", relating_type="type").should_be_called()
|
ifc.run("type.map_type_representations", related_object="element", relating_type="type").should_be_called()
|
||||||
collector.assign("obj").should_be_called()
|
collector.assign("obj").should_be_called()
|
||||||
root.is_opening_element("element").should_be_called().will_return(False)
|
root.is_opening_element("element").should_be_called().will_return(False)
|
||||||
subject.copy_class(ifc, collector, root, obj="obj")
|
subject.copy_class(ifc, collector, root, obj="obj")
|
||||||
@@ -65,7 +65,7 @@ class TestCopyClass:
|
|||||||
ifc.link("element", "obj").should_be_called()
|
ifc.link("element", "obj").should_be_called()
|
||||||
root.get_element_type("element").should_be_called().will_return("type")
|
root.get_element_type("element").should_be_called().will_return("type")
|
||||||
root.does_type_have_representations("type").should_be_called().will_return(True)
|
root.does_type_have_representations("type").should_be_called().will_return(True)
|
||||||
ifc.run("type.assign_type", related_object="element", relating_type="type").should_be_called()
|
ifc.run("type.map_type_representations", related_object="element", relating_type="type").should_be_called()
|
||||||
collector.assign("obj").should_be_called()
|
collector.assign("obj").should_be_called()
|
||||||
root.is_opening_element("element").should_be_called().will_return(True)
|
root.is_opening_element("element").should_be_called().will_return(True)
|
||||||
root.add_dynamic_opening_voids("element", "obj").should_be_called()
|
root.add_dynamic_opening_voids("element", "obj").should_be_called()
|
||||||
|
|||||||
@@ -54,8 +54,14 @@ class Usecase:
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
self.map_representations()
|
ifcopenshell.api.run(
|
||||||
|
"type.map_type_representations",
|
||||||
|
self.file,
|
||||||
|
related_object=self.settings["related_object"],
|
||||||
|
relating_type=self.settings["relating_type"],
|
||||||
|
)
|
||||||
self.map_material_usages()
|
self.map_material_usages()
|
||||||
|
return types
|
||||||
|
|
||||||
def map_representations(self):
|
def map_representations(self):
|
||||||
if not self.settings["relating_type"].RepresentationMaps:
|
if not self.settings["relating_type"].RepresentationMaps:
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import ifcopenshell
|
||||||
|
import ifcopenshell.api
|
||||||
|
import ifcopenshell.util.element
|
||||||
|
|
||||||
|
|
||||||
|
class Usecase:
|
||||||
|
def __init__(self, file, **settings):
|
||||||
|
self.file = file
|
||||||
|
self.settings = {
|
||||||
|
"related_object": None,
|
||||||
|
"relating_type": None,
|
||||||
|
}
|
||||||
|
for key, value in settings.items():
|
||||||
|
self.settings[key] = value
|
||||||
|
|
||||||
|
def execute(self):
|
||||||
|
if not self.settings["relating_type"].RepresentationMaps:
|
||||||
|
return
|
||||||
|
representations = []
|
||||||
|
if self.settings["related_object"].Representation:
|
||||||
|
representations = self.settings["related_object"].Representation.Representations
|
||||||
|
for representation in representations:
|
||||||
|
print('for each rep', representation)
|
||||||
|
ifcopenshell.api.run(
|
||||||
|
"geometry.unassign_representation",
|
||||||
|
self.file,
|
||||||
|
product=self.settings["related_object"],
|
||||||
|
representation=representation,
|
||||||
|
)
|
||||||
|
ifcopenshell.api.run("geometry.remove_representation", self.file, **{"representation": representation})
|
||||||
|
for representation_map in self.settings["relating_type"].RepresentationMaps:
|
||||||
|
representation = representation_map.MappedRepresentation
|
||||||
|
mapped_representation = ifcopenshell.api.run(
|
||||||
|
"geometry.map_representation", self.file, representation=representation
|
||||||
|
)
|
||||||
|
ifcopenshell.api.run(
|
||||||
|
"geometry.assign_representation",
|
||||||
|
self.file,
|
||||||
|
product=self.settings["related_object"],
|
||||||
|
representation=mapped_representation,
|
||||||
|
)
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import test.bootstrap
|
||||||
|
import ifcopenshell.api
|
||||||
|
|
||||||
|
|
||||||
|
class TestMapTypeRepresentations(test.bootstrap.IFC4):
|
||||||
|
def test_doing_nothing_if_the_type_has_no_representation_maps(self):
|
||||||
|
element = self.file.createIfcWall()
|
||||||
|
type = self.file.createIfcWallType()
|
||||||
|
ifcopenshell.api.run("type.assign_type", self.file, related_object=element, relating_type=type)
|
||||||
|
total_elements = len([e for e in self.file])
|
||||||
|
ifcopenshell.api.run("type.map_type_representations", self.file, related_object=element, relating_type=type)
|
||||||
|
assert len([e for e in self.file]) == total_elements
|
||||||
|
|
||||||
|
def test_removing_existing_element_representations_and_mapping_type_representations(self):
|
||||||
|
context = self.file.createIfcGeometricRepresentationSubContext()
|
||||||
|
element = self.file.createIfcWall(
|
||||||
|
Representation=self.file.createIfcProductRepresentation(
|
||||||
|
Representations=[self.file.createIfcShapeRepresentation(ContextOfItems=context)]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
type = self.file.createIfcWallType(
|
||||||
|
RepresentationMaps=[
|
||||||
|
self.file.createIfcRepresentationMap(
|
||||||
|
MappedRepresentation=self.file.createIfcShapeRepresentation(ContextOfItems=context)
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
self.file.createIfcRelDefinesByType(RelatingType=type, RelatedObjects=[element])
|
||||||
|
ifcopenshell.api.run("type.map_type_representations", self.file, related_object=element, relating_type=type)
|
||||||
|
rep = element.Representation.Representations[0]
|
||||||
|
assert rep.RepresentationType == "MappedRepresentation"
|
||||||
|
assert rep.Items[0].MappingSource == type.RepresentationMaps[0]
|
||||||
|
assert len(self.file.by_type("IfcShapeRepresentation")) == 2
|
||||||
Reference in New Issue
Block a user