2024-09-18 18:34:27 +05:00
|
|
|
# Bonsai - OpenBIM Blender Add-on
|
|
|
|
|
# Copyright (C) 2022 Dion Moult <dion@thinkmoult.com>
|
|
|
|
|
#
|
|
|
|
|
# This file is part of Bonsai.
|
|
|
|
|
#
|
|
|
|
|
# Bonsai 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.
|
|
|
|
|
#
|
|
|
|
|
# Bonsai 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 Bonsai. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
import bpy
|
|
|
|
|
import ifcopenshell
|
|
|
|
|
import ifcopenshell.util.classification
|
|
|
|
|
import ifcopenshell.util.element
|
|
|
|
|
import bonsai.core.tool
|
|
|
|
|
import bonsai.tool as tool
|
|
|
|
|
from test.bim.bootstrap import NewFile
|
|
|
|
|
from bonsai.tool.classification import Classification as subject
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestImplementsTool(NewFile):
|
|
|
|
|
def test_run(self):
|
|
|
|
|
assert isinstance(subject(), bonsai.core.tool.Classification)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestAddClassificationReferenceFromBSDD(NewFile):
|
|
|
|
|
def test_add_classification_reference(self):
|
|
|
|
|
bpy.ops.bim.create_project()
|
|
|
|
|
ifc_file = tool.Ifc.get()
|
|
|
|
|
context = bpy.context
|
|
|
|
|
bpy.ops.mesh.primitive_cube_add(size=10, location=(0, 0, 4))
|
|
|
|
|
obj = bpy.data.objects["Cube"]
|
|
|
|
|
bpy.ops.bim.assign_class(ifc_class="IfcSpace", predefined_type="SPACE", userdefined_type="")
|
|
|
|
|
element = tool.Ifc.get_entity(obj)
|
|
|
|
|
assert element
|
|
|
|
|
|
2025-08-05 08:01:48 +02:00
|
|
|
bpy.ops.bim.load_bsdd_dictionaries()
|
2024-09-18 18:34:27 +05:00
|
|
|
uri = "https://identifier.buildingsmart.org/uri/molio/cciconstruction/1.0"
|
2025-08-05 08:01:48 +02:00
|
|
|
tool.Bsdd.set_library_active(uri, True)
|
2025-06-20 14:27:31 +05:00
|
|
|
props = tool.Bsdd.get_bsdd_props()
|
|
|
|
|
tool.Classification.get_classification_props().classification_source = "BSDD"
|
2024-09-18 18:34:27 +05:00
|
|
|
props.should_filter_ifc_class = True
|
|
|
|
|
props.keyword = "Room"
|
|
|
|
|
bpy.ops.bim.search_bsdd_classifications()
|
|
|
|
|
props.active_classification_index = next(i for i, c in enumerate(props.classifications) if c.name == "Room")
|
|
|
|
|
bpy.ops.bim.add_classification_reference_from_bsdd(obj="IfcSpace/Cube", obj_type="Object")
|
|
|
|
|
refs = ifcopenshell.util.classification.get_references(element)
|
|
|
|
|
assert len(refs) == 1
|
2025-06-16 12:29:41 +05:00
|
|
|
assert next(iter(refs)).Location.startswith(uri)
|
2024-09-18 18:34:27 +05:00
|
|
|
|
|
|
|
|
def test_add_classification_refence_with_props(self):
|
|
|
|
|
bpy.ops.bim.create_project()
|
|
|
|
|
ifc_file = tool.Ifc.get()
|
|
|
|
|
context = bpy.context
|
|
|
|
|
bpy.ops.mesh.primitive_cube_add(size=10, location=(0, 0, 4))
|
|
|
|
|
obj = bpy.data.objects["Cube"]
|
|
|
|
|
bpy.ops.bim.assign_class(ifc_class="IfcSpace", predefined_type="SPACE", userdefined_type="")
|
|
|
|
|
element = tool.Ifc.get_entity(obj)
|
|
|
|
|
assert element
|
|
|
|
|
|
2025-08-05 08:01:48 +02:00
|
|
|
bpy.ops.bim.load_bsdd_dictionaries()
|
2024-09-18 18:34:27 +05:00
|
|
|
uri = "https://identifier.buildingsmart.org/uri/molio/cciconstruction/1.0"
|
2025-08-05 08:01:48 +02:00
|
|
|
tool.Bsdd.set_library_active(uri, True)
|
2025-06-20 14:27:31 +05:00
|
|
|
props = tool.Bsdd.get_bsdd_props()
|
|
|
|
|
tool.Classification.get_classification_props().classification_source = "BSDD"
|
2024-09-18 18:34:27 +05:00
|
|
|
props.should_filter_ifc_class = True
|
|
|
|
|
props.keyword = "Room"
|
|
|
|
|
bpy.ops.bim.search_bsdd_classifications()
|
|
|
|
|
# https://identifier.buildingsmart.org/uri/molio/cciconstruction/1.0/class/A-AAA
|
|
|
|
|
props.active_classification_index = next(i for i, c in enumerate(props.classifications) if c.name == "Room")
|
2025-08-05 08:01:48 +02:00
|
|
|
tool.Pset.get_pset_props(obj="IfcSpace/Cube", obj_type="Object").pset_name = uri
|
2024-09-18 18:34:27 +05:00
|
|
|
bpy.ops.bim.add_classification_reference_from_bsdd(obj="IfcSpace/Cube", obj_type="Object")
|
2025-08-05 08:01:48 +02:00
|
|
|
bpy.ops.bim.import_bsdd_classes(obj="IfcSpace/Cube", obj_type="Object")
|
|
|
|
|
props.active_class_index = 0
|
|
|
|
|
assert len(props.properties) == 1
|
|
|
|
|
bsdd_property = props.properties[0]
|
|
|
|
|
assert bsdd_property.pset == "Pset_SpaceCommon"
|
|
|
|
|
assert bsdd_property.name == "Handicap Accessible"
|
|
|
|
|
bsdd_property.is_selected = True
|
|
|
|
|
bpy.ops.bim.add_bsdd_properties(obj="IfcSpace/Cube", obj_type="Object")
|
2024-09-18 18:34:27 +05:00
|
|
|
pset = ifcopenshell.util.element.get_pset(element, "Pset_SpaceCommon")
|
2025-08-05 08:01:48 +02:00
|
|
|
assert pset and pset["HandicapAccessible"] == False
|
2024-09-18 18:34:27 +05:00
|
|
|
refs = ifcopenshell.util.classification.get_references(element)
|
|
|
|
|
assert len(refs) == 1
|
2025-06-16 12:29:41 +05:00
|
|
|
assert next(iter(refs)).Location.startswith(uri)
|
2024-09-18 18:34:27 +05:00
|
|
|
|
|
|
|
|
def test_add_clasification_reference_with_object_type(self):
|
2025-08-05 08:01:48 +02:00
|
|
|
"""
|
|
|
|
|
Check that an IfcSpace cube can be selected and receive a BSDD classification reference/property set
|
|
|
|
|
even if its IFC class mismatches the class bSDD expects by disabling class filtering.
|
|
|
|
|
Sets up the IFC4X3_ADD2 project, creates the cube, assigns IfcSpace, loads and activates the BSDD library,
|
|
|
|
|
searches for "check-in conveyor", adds the classification reference with obj_type="Object", and imports it.
|
|
|
|
|
Asserts 20 properties were loaded and that the first is in "ISet_AirportDomain", named "Conveying speed", and selected.
|
|
|
|
|
"""
|
|
|
|
|
tool.Project.get_project_props().export_schema = "IFC4X3_ADD2"
|
2024-09-18 18:34:27 +05:00
|
|
|
bpy.ops.bim.create_project()
|
2025-08-05 08:01:48 +02:00
|
|
|
ifc_file = tool.Ifc.get()
|
2024-09-18 18:34:27 +05:00
|
|
|
context = bpy.context
|
|
|
|
|
bpy.ops.mesh.primitive_cube_add(size=10, location=(0, 0, 4))
|
|
|
|
|
obj = bpy.data.objects["Cube"]
|
|
|
|
|
bpy.ops.bim.assign_class(ifc_class="IfcSpace", predefined_type="SPACE", userdefined_type="")
|
|
|
|
|
element = tool.Ifc.get_entity(obj)
|
|
|
|
|
assert element
|
|
|
|
|
|
2025-08-05 08:01:48 +02:00
|
|
|
bpy.ops.bim.load_bsdd_dictionaries()
|
|
|
|
|
uri = "https://identifier.buildingsmart.org/uri/bs-airport/airport/1.0"
|
|
|
|
|
tool.Bsdd.set_library_active(uri, True)
|
2025-06-20 14:27:31 +05:00
|
|
|
props = tool.Bsdd.get_bsdd_props()
|
|
|
|
|
tool.Classification.get_classification_props().classification_source = "BSDD"
|
2024-09-18 18:34:27 +05:00
|
|
|
props.should_filter_ifc_class = False # Important due to class mismatch.
|
2025-03-09 21:35:20 +11:00
|
|
|
props.keyword = "check-in conveyor"
|
2024-09-18 18:34:27 +05:00
|
|
|
bpy.ops.bim.search_bsdd_classifications()
|
2025-08-05 08:01:48 +02:00
|
|
|
# https://identifier.buildingsmart.org/uri/bs-airport/airport/1.0/class/AD-BHS-007
|
|
|
|
|
|
2024-09-18 18:34:27 +05:00
|
|
|
props.active_classification_index = next(
|
2025-08-05 08:01:48 +02:00
|
|
|
i for i, c in enumerate(props.classifications) if c.name.lower() == "check-in conveyor"
|
2024-09-18 18:34:27 +05:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
bpy.ops.bim.add_classification_reference_from_bsdd(obj="IfcSpace/Cube", obj_type="Object")
|
2025-08-05 08:01:48 +02:00
|
|
|
tool.Pset.get_pset_props(obj="IfcSpace/Cube", obj_type="Object").pset_name = uri
|
|
|
|
|
bpy.ops.bim.import_bsdd_classes(obj="IfcSpace/Cube", obj_type="Object")
|
|
|
|
|
|
|
|
|
|
props.active_class_index = 0
|
|
|
|
|
assert len(props.properties) == 20
|
|
|
|
|
bsdd_property = props.properties[0]
|
|
|
|
|
assert bsdd_property.pset == "ISet_AirportDomain"
|
|
|
|
|
assert bsdd_property.name == "Conveying speed"
|
2024-09-18 18:34:27 +05:00
|
|
|
assert not ifcopenshell.util.element.get_psets(element)
|