mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-18 06:21:40 +00:00
Fix #2550. Bug where material styles weren't included when appending from a library
This commit is contained in:
@@ -61,12 +61,7 @@ class Usecase:
|
|||||||
element = self.add_element(self.settings["element"])
|
element = self.add_element(self.settings["element"])
|
||||||
if not element.HasRepresentation:
|
if not element.HasRepresentation:
|
||||||
return element
|
return element
|
||||||
added_contexts = [
|
self.reuse_existing_contexts()
|
||||||
e
|
|
||||||
for e in self.file.traverse(element.HasRepresentation[0])
|
|
||||||
if e.is_a("IfcGeometricRepresentationContext")
|
|
||||||
]
|
|
||||||
self.reuse_existing_contexts(added_contexts)
|
|
||||||
return element
|
return element
|
||||||
|
|
||||||
def append_cost_schedule(self):
|
def append_cost_schedule(self):
|
||||||
@@ -88,13 +83,12 @@ class Usecase:
|
|||||||
return element
|
return element
|
||||||
self.whitelisted_inverse_attributes = {
|
self.whitelisted_inverse_attributes = {
|
||||||
"IfcObjectDefinition": ["HasAssociations"],
|
"IfcObjectDefinition": ["HasAssociations"],
|
||||||
"IfcMaterialDefinition": ["HasExternalReferences", "HasProperties"],
|
"IfcMaterialDefinition": ["HasExternalReferences", "HasProperties", "HasRepresentation"],
|
||||||
"IfcRepresentationItem": ["StyledByItem"],
|
"IfcRepresentationItem": ["StyledByItem"],
|
||||||
}
|
}
|
||||||
self.existing_contexts = self.file.by_type("IfcGeometricRepresentationContext")
|
self.existing_contexts = self.file.by_type("IfcGeometricRepresentationContext")
|
||||||
element = self.add_element(self.settings["element"])
|
element = self.add_element(self.settings["element"])
|
||||||
added_contexts = [e for e in self.file.traverse(element) if e.is_a("IfcGeometricRepresentationContext")]
|
self.reuse_existing_contexts()
|
||||||
self.reuse_existing_contexts(added_contexts)
|
|
||||||
return element
|
return element
|
||||||
|
|
||||||
def append_product(self):
|
def append_product(self):
|
||||||
@@ -110,8 +104,7 @@ class Usecase:
|
|||||||
}
|
}
|
||||||
self.existing_contexts = self.file.by_type("IfcGeometricRepresentationContext")
|
self.existing_contexts = self.file.by_type("IfcGeometricRepresentationContext")
|
||||||
element = self.add_element(self.settings["element"])
|
element = self.add_element(self.settings["element"])
|
||||||
added_contexts = [e for e in self.file.traverse(element) if e.is_a("IfcGeometricRepresentationContext")]
|
self.reuse_existing_contexts()
|
||||||
self.reuse_existing_contexts(added_contexts)
|
|
||||||
|
|
||||||
element_type = ifcopenshell.util.element.get_type(self.settings["element"])
|
element_type = ifcopenshell.util.element.get_type(self.settings["element"])
|
||||||
if element_type:
|
if element_type:
|
||||||
@@ -186,7 +179,8 @@ class Usecase:
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def reuse_existing_contexts(self, added_contexts):
|
def reuse_existing_contexts(self):
|
||||||
|
added_contexts = set([e for e in self.added_elements.values() if e.is_a("IfcGeometricRepresentationContext")])
|
||||||
for added_context in added_contexts:
|
for added_context in added_contexts:
|
||||||
equivalent_existing_context = self.get_equivalent_existing_context(added_context)
|
equivalent_existing_context = self.get_equivalent_existing_context(added_context)
|
||||||
if not equivalent_existing_context:
|
if not equivalent_existing_context:
|
||||||
@@ -227,6 +221,8 @@ class Usecase:
|
|||||||
target_view=added_context.TargetView,
|
target_view=added_context.TargetView,
|
||||||
)
|
)
|
||||||
return ifcopenshell.api.run(
|
return ifcopenshell.api.run(
|
||||||
"context.add_context", self.file, context_type=added_context.ContextType,
|
"context.add_context",
|
||||||
context_identifier=added_context.ContextIdentifier
|
self.file,
|
||||||
|
context_type=added_context.ContextType,
|
||||||
|
context_identifier=added_context.ContextIdentifier,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -73,6 +73,24 @@ class TestAppendAsset(test.bootstrap.IFC4):
|
|||||||
assert len(new.RepresentationMaps[0].MappedRepresentation.Items[0].StyledByItem) == 1
|
assert len(new.RepresentationMaps[0].MappedRepresentation.Items[0].StyledByItem) == 1
|
||||||
assert self.file.by_type("IfcStyledItem")[0].Item == self.file.by_type("IfcBoundingBox")[0]
|
assert self.file.by_type("IfcStyledItem")[0].Item == self.file.by_type("IfcBoundingBox")[0]
|
||||||
|
|
||||||
|
def test_append_a_type_product_with_a_styled_materials(self):
|
||||||
|
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||||
|
local_context = ifcopenshell.api.run("context.add_context", self.file, context_type="Model")
|
||||||
|
|
||||||
|
library = ifcopenshell.api.run("project.create_file")
|
||||||
|
ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcProject")
|
||||||
|
context = ifcopenshell.api.run("context.add_context", library, context_type="Model")
|
||||||
|
|
||||||
|
element = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType")
|
||||||
|
material = ifcopenshell.api.run("material.add_material", library, name="Material")
|
||||||
|
ifcopenshell.api.run("material.assign_material", library, product=element, material=material)
|
||||||
|
style = ifcopenshell.api.run("style.add_style", library)
|
||||||
|
ifcopenshell.api.run("style.assign_material_style", library, material=material, style=style, context=context)
|
||||||
|
ifcopenshell.api.run("project.append_asset", self.file, library=library, element=element)
|
||||||
|
assert self.file.by_type("IfcWallType")[0].HasAssociations[0].RelatingMaterial.Name == "Material"
|
||||||
|
assert self.file.by_type("IfcWallType")[0].HasAssociations[0].RelatingMaterial.HasRepresentation
|
||||||
|
assert len(self.file.by_type("IfcGeometricRepresentationContext")) == 1
|
||||||
|
|
||||||
def test_append_a_material(self):
|
def test_append_a_material(self):
|
||||||
library = ifcopenshell.api.run("project.create_file")
|
library = ifcopenshell.api.run("project.create_file")
|
||||||
material = ifcopenshell.api.run("material.add_material", library, name="Material")
|
material = ifcopenshell.api.run("material.add_material", library, name="Material")
|
||||||
|
|||||||
Reference in New Issue
Block a user