2021-10-18 19:23:40 +11:00
|
|
|
# BlenderBIM Add-on - OpenBIM Blender Add-on
|
|
|
|
|
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
|
|
|
|
#
|
|
|
|
|
# This file is part of BlenderBIM Add-on.
|
|
|
|
|
#
|
|
|
|
|
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# BlenderBIM Add-on 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 General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
import bpy
|
|
|
|
|
import math
|
|
|
|
|
import numpy
|
|
|
|
|
import ifcopenshell
|
|
|
|
|
import blenderbim.core.tool
|
|
|
|
|
import blenderbim.tool as tool
|
|
|
|
|
from mathutils import Vector
|
2021-10-22 18:07:34 +11:00
|
|
|
from test.bim.bootstrap import NewFile
|
2021-10-18 19:23:40 +11:00
|
|
|
from blenderbim.tool.geometry import Geometry as subject
|
|
|
|
|
from blenderbim.bim.ifc import IfcStore
|
|
|
|
|
|
|
|
|
|
|
2021-10-22 18:07:34 +11:00
|
|
|
class TestImplementsTool(NewFile):
|
2021-10-18 19:23:40 +11:00
|
|
|
def test_run(self):
|
|
|
|
|
assert isinstance(subject(), blenderbim.core.tool.Geometry)
|
|
|
|
|
|
|
|
|
|
|
2021-10-22 18:07:34 +11:00
|
|
|
class TestChangeObjectData(NewFile):
|
2021-10-19 12:57:21 +11:00
|
|
|
def test_change_single_object_data(self):
|
|
|
|
|
data1 = bpy.data.meshes.new("Mesh")
|
|
|
|
|
data2 = bpy.data.meshes.new("Mesh")
|
|
|
|
|
obj1 = bpy.data.objects.new("Object", data1)
|
|
|
|
|
obj2 = bpy.data.objects.new("Object", data1)
|
|
|
|
|
subject.change_object_data(obj1, data2, is_global=False)
|
|
|
|
|
assert obj1.data == data2
|
|
|
|
|
assert obj2.data == data1
|
|
|
|
|
|
|
|
|
|
def test_change_object_data_globally(self):
|
|
|
|
|
data1 = bpy.data.meshes.new("Mesh")
|
|
|
|
|
data2 = bpy.data.meshes.new("Mesh")
|
|
|
|
|
obj1 = bpy.data.objects.new("Object", data1)
|
|
|
|
|
obj2 = bpy.data.objects.new("Object", data1)
|
|
|
|
|
subject.change_object_data(obj1, data2, is_global=True)
|
|
|
|
|
assert obj1.data == data2
|
|
|
|
|
assert obj2.data == data2
|
|
|
|
|
|
|
|
|
|
|
2021-10-22 18:07:34 +11:00
|
|
|
class TestClearModifiers(NewFile):
|
2021-10-19 12:57:21 +11:00
|
|
|
def test_run(self):
|
|
|
|
|
obj = bpy.data.objects.new("Object", bpy.data.meshes.new("Mesh"))
|
|
|
|
|
obj.modifiers.new("IfcOpeningElement", "BOOLEAN")
|
2021-10-22 16:23:36 +11:00
|
|
|
subject.clear_modifiers(obj)
|
2021-10-19 12:57:21 +11:00
|
|
|
assert len(obj.modifiers) == 0
|
|
|
|
|
|
|
|
|
|
|
2021-10-22 18:07:34 +11:00
|
|
|
class TestCreateDynamicVoids(NewFile):
|
2021-10-19 12:57:21 +11:00
|
|
|
def test_run(self):
|
|
|
|
|
ifc = ifcopenshell.file()
|
|
|
|
|
tool.Ifc.set(ifc)
|
|
|
|
|
wall = ifc.createIfcWall()
|
|
|
|
|
opening = ifc.createIfcOpeningElement()
|
|
|
|
|
ifcopenshell.api.run("void.add_opening", ifc, opening=opening, element=wall)
|
|
|
|
|
wall_obj = bpy.data.objects.new("Object", bpy.data.meshes.new("Mesh"))
|
|
|
|
|
opening_obj = bpy.data.objects.new("Object", bpy.data.meshes.new("Mesh"))
|
|
|
|
|
tool.Ifc.link(wall, wall_obj)
|
|
|
|
|
tool.Ifc.link(opening, opening_obj)
|
|
|
|
|
subject.create_dynamic_voids(wall_obj)
|
|
|
|
|
modifier = wall_obj.modifiers[0]
|
|
|
|
|
assert modifier.type == "BOOLEAN"
|
|
|
|
|
assert modifier.name == "IfcOpeningElement"
|
|
|
|
|
assert modifier.operation == "DIFFERENCE"
|
|
|
|
|
assert modifier.object == opening_obj
|
|
|
|
|
assert modifier.solver == "EXACT"
|
|
|
|
|
assert modifier.use_self is True
|
|
|
|
|
|
|
|
|
|
|
2021-10-22 18:07:34 +11:00
|
|
|
class TestDoesObjectHaveMeshWithFaces(NewFile):
|
2021-10-18 19:23:40 +11:00
|
|
|
def test_empties_return_false(self):
|
|
|
|
|
obj = bpy.data.objects.new("Object", None)
|
|
|
|
|
assert subject.does_object_have_mesh_with_faces(obj) is False
|
|
|
|
|
|
|
|
|
|
def test_non_meshes_return_false(self):
|
|
|
|
|
obj = bpy.data.objects.new("Object", bpy.data.cameras.new("Curve"))
|
|
|
|
|
assert subject.does_object_have_mesh_with_faces(obj) is False
|
|
|
|
|
|
|
|
|
|
def test_meshes_without_faces_return_false(self):
|
|
|
|
|
obj = bpy.data.objects.new("Object", bpy.data.meshes.new("Mesh"))
|
|
|
|
|
assert subject.does_object_have_mesh_with_faces(obj) is False
|
|
|
|
|
|
|
|
|
|
def test_meshes_with_faces_return_true(self):
|
|
|
|
|
bpy.ops.mesh.primitive_cube_add()
|
|
|
|
|
obj = bpy.data.objects.get("Cube")
|
|
|
|
|
assert subject.does_object_have_mesh_with_faces(obj) is True
|
|
|
|
|
|
|
|
|
|
|
2021-10-22 18:07:34 +11:00
|
|
|
class TestDuplicateObjectData(NewFile):
|
2021-10-18 19:23:40 +11:00
|
|
|
def test_run(self):
|
|
|
|
|
data = bpy.data.meshes.new("Mesh")
|
|
|
|
|
obj = bpy.data.objects.new("Object", data)
|
|
|
|
|
assert subject.duplicate_object_data(obj) == obj.data
|
|
|
|
|
assert obj.data != data
|
|
|
|
|
assert isinstance(obj.data, bpy.types.Mesh)
|
|
|
|
|
|
|
|
|
|
|
2021-10-22 18:07:34 +11:00
|
|
|
class TestGetObjectData(NewFile):
|
2021-10-18 19:23:40 +11:00
|
|
|
def test_run(self):
|
|
|
|
|
data = bpy.data.meshes.new("Mesh")
|
|
|
|
|
obj = bpy.data.objects.new("Object", data)
|
|
|
|
|
assert subject.get_object_data(obj) == obj.data
|
|
|
|
|
|
|
|
|
|
|
2021-10-22 18:07:34 +11:00
|
|
|
class TestGetObjectMaterialsWithoutStyles(NewFile):
|
2021-10-18 19:23:40 +11:00
|
|
|
def test_run(self):
|
|
|
|
|
material1 = bpy.data.materials.new("Material")
|
|
|
|
|
material2 = bpy.data.materials.new("Material")
|
|
|
|
|
material3 = bpy.data.materials.new("Material")
|
|
|
|
|
material3.BIMMaterialProperties.ifc_style_id = 1
|
|
|
|
|
obj = bpy.data.objects.new("Object", bpy.data.meshes.new("Mesh"))
|
|
|
|
|
obj.data.materials.append(material1)
|
|
|
|
|
obj.data.materials.append(material2)
|
|
|
|
|
obj.data.materials.append(material3)
|
|
|
|
|
assert subject.get_object_materials_without_styles(obj) == [material1, material2]
|
|
|
|
|
|
|
|
|
|
|
2021-10-22 18:07:34 +11:00
|
|
|
class TestGetRepresentationData(NewFile):
|
2021-10-19 12:57:21 +11:00
|
|
|
def test_run(self):
|
|
|
|
|
ifc = ifcopenshell.file()
|
|
|
|
|
context = ifc.createIfcGeometricRepresentationContext()
|
|
|
|
|
representation = ifc.createIfcShapeRepresentation()
|
|
|
|
|
representation.ContextOfItems = context
|
|
|
|
|
data = bpy.data.meshes.new("1/2")
|
|
|
|
|
assert subject.get_representation_data(representation) == data
|
|
|
|
|
|
|
|
|
|
|
2021-10-22 18:07:34 +11:00
|
|
|
class TestGetRepresentationName(NewFile):
|
2021-10-18 19:23:40 +11:00
|
|
|
def test_run(self):
|
|
|
|
|
ifc = ifcopenshell.file()
|
|
|
|
|
context = ifc.createIfcGeometricRepresentationContext()
|
|
|
|
|
representation = ifc.createIfcShapeRepresentation()
|
2021-10-19 12:57:21 +11:00
|
|
|
representation.ContextOfItems = context
|
|
|
|
|
assert subject.get_representation_name(representation) == f"{context.id()}/{representation.id()}"
|
2021-10-18 19:23:40 +11:00
|
|
|
|
|
|
|
|
|
2021-10-22 18:07:34 +11:00
|
|
|
class TestGetCartesianPointCoordinateOffset(NewFile):
|
2021-10-18 19:23:40 +11:00
|
|
|
def test_run(self):
|
|
|
|
|
obj = bpy.data.objects.new("Object", None)
|
|
|
|
|
obj.BIMObjectProperties.blender_offset_type = "CARTESIAN_POINT"
|
|
|
|
|
props = bpy.context.scene.BIMGeoreferenceProperties
|
|
|
|
|
props.has_blender_offset = True
|
|
|
|
|
props.blender_eastings = "1"
|
|
|
|
|
props.blender_northings = "2"
|
|
|
|
|
props.blender_orthogonal_height = "3"
|
|
|
|
|
assert subject.get_cartesian_point_coordinate_offset(obj) == Vector((1.0, 2.0, 3.0))
|
|
|
|
|
|
|
|
|
|
def test_get_null_if_not_a_cartesian_point_offset_type(self):
|
|
|
|
|
obj = bpy.data.objects.new("Object", None)
|
|
|
|
|
props = bpy.context.scene.BIMGeoreferenceProperties
|
|
|
|
|
props.has_blender_offset = True
|
|
|
|
|
props.blender_eastings = "1"
|
|
|
|
|
props.blender_northings = "2"
|
|
|
|
|
props.blender_orthogonal_height = "3"
|
|
|
|
|
assert subject.get_cartesian_point_coordinate_offset(obj) is None
|
|
|
|
|
|
|
|
|
|
def test_get_null_if_no_blender_offset(self):
|
|
|
|
|
obj = bpy.data.objects.new("Object", None)
|
|
|
|
|
obj.BIMObjectProperties.blender_offset_type = "CARTESIAN_POINT"
|
|
|
|
|
props = bpy.context.scene.BIMGeoreferenceProperties
|
|
|
|
|
props.has_blender_offset = False
|
|
|
|
|
assert subject.get_cartesian_point_coordinate_offset(obj) is None
|
|
|
|
|
|
|
|
|
|
|
2021-10-22 18:07:34 +11:00
|
|
|
class TestGetTotalRepresentationItems(NewFile):
|
2021-10-18 19:23:40 +11:00
|
|
|
def test_run(self):
|
|
|
|
|
material1 = bpy.data.materials.new("Material")
|
|
|
|
|
material2 = bpy.data.materials.new("Material")
|
|
|
|
|
obj = bpy.data.objects.new("Object", bpy.data.meshes.new("Mesh"))
|
|
|
|
|
obj.data.materials.append(material1)
|
|
|
|
|
obj.data.materials.append(material2)
|
|
|
|
|
assert subject.get_total_representation_items(obj) == 2
|
|
|
|
|
|
|
|
|
|
|
2021-10-22 18:07:34 +11:00
|
|
|
class TestImportRepresentation(NewFile):
|
2021-10-19 12:57:21 +11:00
|
|
|
def test_importing_a_normal_shape(self):
|
|
|
|
|
ifc = ifcopenshell.open("test/files/basic.ifc")
|
|
|
|
|
tool.Ifc.set(ifc)
|
|
|
|
|
obj = bpy.data.objects.new("Object", bpy.data.meshes.new("Mesh"))
|
|
|
|
|
material = bpy.data.materials.new("Material")
|
|
|
|
|
material.BIMMaterialProperties.ifc_style_id = 101
|
|
|
|
|
element = ifc.by_type("IfcWall")[0]
|
|
|
|
|
tool.Ifc.link(element, obj)
|
|
|
|
|
representation = element.Representation.Representations[0]
|
|
|
|
|
mesh = subject.import_representation(obj, representation, enable_dynamic_voids=False)
|
|
|
|
|
assert len(mesh.polygons) == 12
|
|
|
|
|
assert mesh.materials[0] == material
|
|
|
|
|
|
|
|
|
|
def test_importing_non_body_curves(self):
|
|
|
|
|
ifc = ifcopenshell.open("test/files/annotation.ifc")
|
|
|
|
|
tool.Ifc.set(ifc)
|
|
|
|
|
obj = bpy.data.objects.new("Object", bpy.data.meshes.new("Mesh"))
|
|
|
|
|
element = ifc.by_type("IfcWall")[0]
|
|
|
|
|
tool.Ifc.link(element, obj)
|
|
|
|
|
representation = element.Representation.Representations[0]
|
|
|
|
|
mesh = subject.import_representation(obj, representation, enable_dynamic_voids=False)
|
|
|
|
|
assert len(mesh.polygons) == 0
|
|
|
|
|
assert len(mesh.edges) == 4
|
|
|
|
|
|
|
|
|
|
|
2021-10-22 18:07:34 +11:00
|
|
|
class TestIsBodyRepresentation(NewFile):
|
2021-10-19 12:57:21 +11:00
|
|
|
def test_run(self):
|
|
|
|
|
ifc = ifcopenshell.file()
|
|
|
|
|
context = ifc.createIfcGeometricRepresentationContext()
|
|
|
|
|
representation = ifc.createIfcShapeRepresentation()
|
|
|
|
|
representation.ContextOfItems = context
|
|
|
|
|
context.ContextIdentifier = "Body"
|
|
|
|
|
assert subject.is_body_representation(representation) is True
|
|
|
|
|
context.ContextIdentifier = "Clearance"
|
|
|
|
|
assert subject.is_body_representation(representation) is False
|
|
|
|
|
|
|
|
|
|
|
2021-10-22 18:07:34 +11:00
|
|
|
class TestLink(NewFile):
|
2021-10-18 19:23:40 +11:00
|
|
|
def test_run(self):
|
|
|
|
|
ifc = ifcopenshell.file()
|
|
|
|
|
element = ifc.createIfcShapeRepresentation()
|
|
|
|
|
obj = bpy.data.meshes.new("Mesh")
|
|
|
|
|
subject.link(element, obj)
|
|
|
|
|
assert obj.BIMMeshProperties.ifc_definition_id == element.id()
|
|
|
|
|
|
|
|
|
|
|
2021-10-22 18:07:34 +11:00
|
|
|
class TestRenameObjectData(NewFile):
|
2021-10-18 19:23:40 +11:00
|
|
|
def test_run(self):
|
|
|
|
|
obj = bpy.data.meshes.new("Mesh")
|
2021-10-19 12:57:21 +11:00
|
|
|
subject.rename_object(obj, "name")
|
2021-10-18 19:23:40 +11:00
|
|
|
assert obj.name == "name"
|
|
|
|
|
|
|
|
|
|
|
2021-10-22 18:07:34 +11:00
|
|
|
class TestResolveMappedRepresentation(NewFile):
|
2021-10-19 12:57:21 +11:00
|
|
|
def test_run(self):
|
|
|
|
|
ifc = ifcopenshell.file()
|
|
|
|
|
mapped_representation = ifc.createIfcShapeRepresentation()
|
|
|
|
|
representation = ifc.createIfcShapeRepresentation()
|
|
|
|
|
mapped_representation.RepresentationType = "MappedRepresentation"
|
|
|
|
|
mapped_representation.Items = [
|
|
|
|
|
ifc.createIfcMappedItem(MappingSource=ifc.createIfcRepresentationMap(MappedRepresentation=representation))
|
|
|
|
|
]
|
|
|
|
|
assert subject.resolve_mapped_representation(mapped_representation) == representation
|
|
|
|
|
|
|
|
|
|
def test_return_a_representation_if_not_mapped(self):
|
|
|
|
|
ifc = ifcopenshell.file()
|
|
|
|
|
representation = ifc.createIfcShapeRepresentation()
|
|
|
|
|
assert subject.resolve_mapped_representation(representation) == representation
|
|
|
|
|
|
|
|
|
|
|
2021-10-22 18:07:34 +11:00
|
|
|
class TestShouldForceFacetedBrep(NewFile):
|
2021-10-18 19:23:40 +11:00
|
|
|
def test_run(self):
|
|
|
|
|
result = bpy.context.scene.BIMGeometryProperties.should_force_faceted_brep
|
|
|
|
|
assert subject.should_force_faceted_brep() is result
|
|
|
|
|
|
|
|
|
|
|
2021-10-22 18:07:34 +11:00
|
|
|
class TestShouldForceTriangulation(NewFile):
|
2021-10-18 19:23:40 +11:00
|
|
|
def test_run(self):
|
|
|
|
|
result = bpy.context.scene.BIMGeometryProperties.should_force_triangulation
|
|
|
|
|
assert subject.should_force_triangulation() is result
|
|
|
|
|
|
|
|
|
|
|
2021-10-22 18:07:34 +11:00
|
|
|
class TestShouldUsePresentationStyleAssignment(NewFile):
|
2021-10-18 19:23:40 +11:00
|
|
|
def test_run(self):
|
|
|
|
|
result = bpy.context.scene.BIMGeometryProperties.should_use_presentation_style_assignment
|
|
|
|
|
assert subject.should_use_presentation_style_assignment() is result
|
2021-10-22 18:07:34 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestGetProfileSetUsage(NewFile):
|
|
|
|
|
def test_getting_a_profile_set_usage(self):
|
|
|
|
|
ifc = ifcopenshell.file()
|
|
|
|
|
element = ifc.createIfcColumn()
|
|
|
|
|
assert subject.get_profile_set_usage(element) is None
|
|
|
|
|
usage = ifc.createIfcMaterialProfileSetUsage()
|
|
|
|
|
ifc.createIfcRelAssociatesMaterial(RelatingMaterial=usage, RelatedObjects=[element])
|
|
|
|
|
assert subject.get_profile_set_usage(element) == usage
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestGetIfcRepresentationClass(NewFile):
|
|
|
|
|
def test_detecting_profile_set_representations(self):
|
|
|
|
|
ifc = ifcopenshell.file()
|
|
|
|
|
tool.Ifc.set(ifc)
|
|
|
|
|
element = ifc.createIfcColumn()
|
|
|
|
|
ifc.createIfcRelAssociatesMaterial(
|
|
|
|
|
RelatingMaterial=ifc.createIfcMaterialProfileSetUsage(), RelatedObjects=[element]
|
|
|
|
|
)
|
|
|
|
|
representation = ifc.createIfcShapeRepresentation()
|
|
|
|
|
assert (
|
|
|
|
|
subject.get_ifc_representation_class(element, representation)
|
|
|
|
|
== "IfcExtrudedAreaSolid/IfcMaterialProfileSetUsage"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def test_detecting_rectangular_extrusions(self):
|
|
|
|
|
ifc = ifcopenshell.file()
|
|
|
|
|
tool.Ifc.set(ifc)
|
|
|
|
|
element = ifc.createIfcColumn()
|
|
|
|
|
representation = ifc.createIfcShapeRepresentation(
|
|
|
|
|
Items=[ifc.createIfcExtrudedAreaSolid(SweptArea=ifc.createIfcRectangleProfileDef())]
|
|
|
|
|
)
|
|
|
|
|
assert (
|
|
|
|
|
subject.get_ifc_representation_class(element, representation)
|
|
|
|
|
== "IfcExtrudedAreaSolid/IfcRectangleProfileDef"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def test_detecting_circle_extrusions(self):
|
|
|
|
|
ifc = ifcopenshell.file()
|
|
|
|
|
tool.Ifc.set(ifc)
|
|
|
|
|
element = ifc.createIfcColumn()
|
|
|
|
|
representation = ifc.createIfcShapeRepresentation(
|
|
|
|
|
Items=[ifc.createIfcExtrudedAreaSolid(SweptArea=ifc.createIfcCircleProfileDef())]
|
|
|
|
|
)
|
|
|
|
|
assert (
|
|
|
|
|
subject.get_ifc_representation_class(element, representation) == "IfcExtrudedAreaSolid/IfcCircleProfileDef"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def test_returning_null_for_non_parametric_representations(self):
|
|
|
|
|
ifc = ifcopenshell.file()
|
|
|
|
|
tool.Ifc.set(ifc)
|
|
|
|
|
assert subject.get_ifc_representation_class(ifc.createIfcColumn(), ifc.createIfcShapeRepresentation()) is None
|