Fix a variety of IFC validation errors in entity creation and asset appending

This commit is contained in:
Dion Moult
2022-10-14 18:19:26 +11:00
parent 10bde73c1a
commit a34c0cb35c
9 changed files with 217 additions and 1395 deletions
@@ -69,7 +69,8 @@ class TestAppendAsset(test.bootstrap.IFC4):
library.createIfcStyledItem(Item=item)
mapped_rep = library.createIfcShapeRepresentation(Items=[item])
element.RepresentationMaps = [library.createIfcRepresentationMap(MappedRepresentation=mapped_rep)]
ifcopenshell.api.run("project.append_asset", self.file, library=library, element=element)
new = ifcopenshell.api.run("project.append_asset", self.file, library=library, element=element)
assert len(new.RepresentationMaps[0].MappedRepresentation.Items[0].StyledByItem) == 1
assert self.file.by_type("IfcStyledItem")[0].Item == self.file.by_type("IfcBoundingBox")[0]
def test_append_a_material(self):
@@ -108,6 +109,27 @@ class TestAppendAsset(test.bootstrap.IFC4):
assert len(self.file.by_type("IfcGeometricRepresentationContext")) == 1
context = self.file.by_type("IfcMaterial")[0].HasRepresentation[0].Representations[0].ContextOfItems
assert context == file_context
assert context.WorldCoordinateSystem
def test_append_a_material_with_a_representation_and_reuse_an_existing_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")
file_subcontext = ifcopenshell.api.run("context.add_context", self.file, parent=file_context, context_type="Model", context_identifier="Body", target_view="MODEL_VIEW")
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, parent=context, context_type="Model", context_identifier="Body", target_view="MODEL_VIEW")
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 == file_subcontext
assert subcontext.ParentContext.WorldCoordinateSystem
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")
@@ -0,0 +1,72 @@
# IfcOpenShell - IFC toolkit and geometry engine
# Copyright (C) 2022 Dion Moult <dion@thinkmoult.com>
#
# This file is part of IfcOpenShell.
#
# IfcOpenShell is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# IfcOpenShell is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import test.bootstrap
import ifcopenshell.api
class TestCreateEntity(test.bootstrap.IFC4):
def test_creating_a_simple_entity_with_automatic_global_id(self):
wall = ifcopenshell.api.run(
"root.create_entity", self.file, ifc_class="IfcWall", predefined_type="SOLIDWALL", name="Foo"
)
assert wall.is_a() == "IfcWall"
assert len(wall.GlobalId) == 22
assert wall.Name == "Foo"
assert wall.PredefinedType == "SOLIDWALL"
def test_handling_predefined_types(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall", name="Foo")
assert element.PredefinedType == "NOTDEFINED"
element = ifcopenshell.api.run(
"root.create_entity", self.file, ifc_class="IfcWall", predefined_type="SHEAR", name="Foo"
)
assert element.PredefinedType == "SHEAR"
element = ifcopenshell.api.run(
"root.create_entity", self.file, ifc_class="IfcWall", predefined_type="Foobar", name="Foo"
)
assert element.PredefinedType == "USERDEFINED"
assert element.ObjectType == "Foobar"
element = ifcopenshell.api.run(
"root.create_entity", self.file, ifc_class="IfcWallType", predefined_type="Foobar", name="Foo"
)
assert element.PredefinedType == "USERDEFINED"
assert element.ElementType == "Foobar"
element = ifcopenshell.api.run(
"root.create_entity", self.file, ifc_class="IfcTaskType", predefined_type="Foobar", name="Foo"
)
assert element.PredefinedType == "USERDEFINED"
assert element.ProcessType == "Foobar"
def test_setting_default_values_for_validity(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcDoorStyle", name="Foo")
assert element.OperationType == "NOTDEFINED"
assert element.ConstructionType == "NOTDEFINED"
assert element.ParameterTakesPrecedence == False
assert element.Sizeable == False
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWindowStyle", name="Foo")
assert element.OperationType == "NOTDEFINED"
assert element.ConstructionType == "NOTDEFINED"
assert element.ParameterTakesPrecedence == False
assert element.Sizeable == False
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcDoorType", name="Foo")
assert element.OperationType == "NOTDEFINED"
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWindowType", name="Foo")
assert element.PartitioningType == "NOTDEFINED"
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFurnitureType", name="Foo")
assert element.AssemblyPlace == "NOTDEFINED"