mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-27 18:57:17 +00:00
Fix #2379. Regressions where context adding never had any tests and failed.
This commit is contained in:
@@ -189,12 +189,18 @@ class Usecase:
|
|||||||
|
|
||||||
def create_equivalent_context(self, added_context):
|
def create_equivalent_context(self, added_context):
|
||||||
if added_context.is_a("IfcGeometricRepresentationSubContext"):
|
if added_context.is_a("IfcGeometricRepresentationSubContext"):
|
||||||
|
parent = self.get_equivalent_existing_context(added_context.ParentContext)
|
||||||
|
if not parent:
|
||||||
|
parent = self.create_equivalent_context(added_context.ParentContext)
|
||||||
return ifcopenshell.api.run(
|
return ifcopenshell.api.run(
|
||||||
"context.add_context",
|
"context.add_context",
|
||||||
context=added_context.ContextType,
|
self.file,
|
||||||
subcontext=added_context.ContextIdentifier,
|
parent=parent,
|
||||||
|
context_type=added_context.ContextType,
|
||||||
|
context_identifier=added_context.ContextIdentifier,
|
||||||
target_view=added_context.TargetView,
|
target_view=added_context.TargetView,
|
||||||
)
|
)
|
||||||
return ifcopenshell.api.run(
|
return ifcopenshell.api.run(
|
||||||
"context.add_context", context=added_context.ContextType, subcontext=added_context.ContextIdentifier
|
"context.add_context", self.file, context_type=added_context.ContextType,
|
||||||
|
context_identifier=added_context.ContextIdentifier
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -68,6 +68,59 @@ class TestAppendAsset(test.bootstrap.IFC4):
|
|||||||
ifcopenshell.api.run("project.append_asset", self.file, library=library, element=material)
|
ifcopenshell.api.run("project.append_asset", self.file, library=library, element=material)
|
||||||
assert len(self.file.by_type("IfcMaterial")) == 1
|
assert len(self.file.by_type("IfcMaterial")) == 1
|
||||||
|
|
||||||
|
def test_append_a_material_with_a_representation(self):
|
||||||
|
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||||
|
|
||||||
|
library = ifcopenshell.api.run("project.create_file")
|
||||||
|
ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcProject")
|
||||||
|
material = ifcopenshell.api.run("material.add_material", library, name="Material")
|
||||||
|
style = ifcopenshell.api.run("style.add_style", library)
|
||||||
|
context = ifcopenshell.api.run("context.add_context", library, context_type="Model")
|
||||||
|
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=material)
|
||||||
|
assert len(self.file.by_type("IfcMaterial")) == 1
|
||||||
|
assert len(self.file.by_type("IfcGeometricRepresentationContext")) == 1
|
||||||
|
context = self.file.by_type("IfcMaterial")[0].HasRepresentation[0].Representations[0].ContextOfItems
|
||||||
|
assert context.ContextType == "Model"
|
||||||
|
|
||||||
|
def test_append_a_material_with_a_representation_and_reuse_an_existing_context(self):
|
||||||
|
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||||
|
file_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")
|
||||||
|
material = ifcopenshell.api.run("material.add_material", library, name="Material")
|
||||||
|
style = ifcopenshell.api.run("style.add_style", library)
|
||||||
|
context = ifcopenshell.api.run("context.add_context", library, context_type="Model")
|
||||||
|
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=material)
|
||||||
|
assert len(self.file.by_type("IfcMaterial")) == 1
|
||||||
|
assert len(self.file.by_type("IfcGeometricRepresentationContext")) == 1
|
||||||
|
context = self.file.by_type("IfcMaterial")[0].HasRepresentation[0].Representations[0].ContextOfItems
|
||||||
|
assert context == file_context
|
||||||
|
|
||||||
|
def test_append_a_material_with_a_representation_and_reuse_an_existing_context_by_a_new_subcontext(self):
|
||||||
|
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||||
|
file_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")
|
||||||
|
material = ifcopenshell.api.run("material.add_material", library, name="Material")
|
||||||
|
style = ifcopenshell.api.run("style.add_style", library)
|
||||||
|
context = ifcopenshell.api.run("context.add_context", library, context_type="Model")
|
||||||
|
subcontext = ifcopenshell.api.run("context.add_context", library, context_type="Model",
|
||||||
|
context_identifier="Body", target_view="MODEL_VIEW", parent=context)
|
||||||
|
ifcopenshell.api.run("style.assign_material_style", library, material=material, style=style, context=subcontext)
|
||||||
|
ifcopenshell.api.run("project.append_asset", self.file, library=library, element=material)
|
||||||
|
assert len(self.file.by_type("IfcMaterial")) == 1
|
||||||
|
assert len(self.file.by_type("IfcGeometricRepresentationContext", include_subtypes=False)) == 1
|
||||||
|
assert len(self.file.by_type("IfcGeometricRepresentationSubContext", include_subtypes=False)) == 1
|
||||||
|
subcontext = self.file.by_type("IfcMaterial")[0].HasRepresentation[0].Representations[0].ContextOfItems
|
||||||
|
assert subcontext.ContextType == "Model"
|
||||||
|
assert subcontext.ContextIdentifier == "Body"
|
||||||
|
assert subcontext.TargetView == "MODEL_VIEW"
|
||||||
|
assert subcontext.ParentContext == file_context
|
||||||
|
|
||||||
def test_append_a_cost_schedule(self):
|
def test_append_a_cost_schedule(self):
|
||||||
library = ifcopenshell.api.run("project.create_file")
|
library = ifcopenshell.api.run("project.create_file")
|
||||||
schedule = ifcopenshell.api.run("cost.add_cost_schedule", library, name="Schedule")
|
schedule = ifcopenshell.api.run("cost.add_cost_schedule", library, name="Schedule")
|
||||||
|
|||||||
Reference in New Issue
Block a user