Fix #1576. Managing IfcSystem subtypes is now possible.

This commit is contained in:
Dion Moult
2022-01-20 18:21:57 +11:00
parent 000e3acb2b
commit 67952ed159
20 changed files with 817 additions and 166 deletions
@@ -0,0 +1,97 @@
@system
Feature: System
Scenario: Load systems
Given an empty IFC project
When I press "bim.load_systems"
Then nothing happens
Scenario: Disable system editing UI
Given an empty IFC project
When I press "bim.load_systems"
And I press "bim.disable_system_editing_ui"
Then nothing happens
Scenario: Add system
Given an empty IFC project
And I press "bim.load_systems"
When I press "bim.add_system"
Then nothing happens
Scenario: Edit system
Given an empty IFC project
And I press "bim.load_systems"
And I press "bim.add_system"
And the variable "system" is "{ifc}.by_type('IfcSystem')[0].id()"
And I press "bim.enable_editing_system(system={system})"
When I press "bim.edit_system"
Then nothing happens
Scenario: Edit system
Given an empty IFC project
And I press "bim.load_systems"
And I press "bim.add_system"
And the variable "system" is "{ifc}.by_type('IfcSystem')[0].id()"
When I press "bim.remove_system(system={system})"
Then nothing happens
Scenario: Enable editing system
Given an empty IFC project
And I press "bim.load_systems"
And I press "bim.add_system"
And the variable "system" is "{ifc}.by_type('IfcSystem')[0].id()"
When I press "bim.enable_editing_system(system={system})"
Then nothing happens
Scenario: Disable editing system
Given an empty IFC project
And I press "bim.load_systems"
And I press "bim.add_system"
And the variable "system" is "{ifc}.by_type('IfcSystem')[0].id()"
And I press "bim.enable_editing_system(system={system})"
When I press "bim.disable_editing_system"
Then nothing happens
Scenario: Assign system
Given an empty IFC project
And I press "bim.load_systems"
And I press "bim.add_system"
And the variable "system" is "{ifc}.by_type('IfcSystem')[0].id()"
And I press "bim.enable_editing_system(system={system})"
And I add a cube
And the object "Cube" is selected
And I set "scene.BIMRootProperties.ifc_class" to "IfcPump"
And I press "bim.assign_class"
And the object "IfcPump/Cube" is selected
When I press "bim.assign_system(system={system})"
Then nothing happens
Scenario: Unassign system
Given an empty IFC project
And I press "bim.load_systems"
And I press "bim.add_system"
And the variable "system" is "{ifc}.by_type('IfcSystem')[0].id()"
And I press "bim.enable_editing_system(system={system})"
And I add a cube
And the object "Cube" is selected
And I set "scene.BIMRootProperties.ifc_class" to "IfcPump"
And I press "bim.assign_class"
And the object "IfcPump/Cube" is selected
And I press "bim.assign_system(system={system})"
When I press "bim.unassign_system(system={system})"
Then nothing happens
Scenario: Select system products
Given an empty IFC project
And I press "bim.load_systems"
And I press "bim.add_system"
And the variable "system" is "{ifc}.by_type('IfcSystem')[0].id()"
And I press "bim.enable_editing_system(system={system})"
And I add a cube
And the object "Cube" is selected
And I set "scene.BIMRootProperties.ifc_class" to "IfcPump"
And I press "bim.assign_class"
And the object "IfcPump/Cube" is selected
And I press "bim.assign_system(system={system})"
When I press "bim.select_system_products(system={system})"
Then nothing happens
+7
View File
@@ -168,6 +168,13 @@ def surveyor():
prophet.verify()
@pytest.fixture
def system():
prophet = Prophecy(blenderbim.core.tool.System)
yield prophet
prophet.verify()
@pytest.fixture
def type():
prophet = Prophecy(blenderbim.core.tool.Type)
+90
View File
@@ -0,0 +1,90 @@
# BlenderBIM Add-on - OpenBIM Blender Add-on
# Copyright (C) 2022 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 blenderbim.core.system as subject
from test.core.bootstrap import ifc, system
class TestLoadSystems:
def test_run(self, system):
system.import_systems().should_be_called()
system.enable_system_editing_ui().should_be_called()
system.disable_editing_system().should_be_called()
subject.load_systems(system)
class TestDisableSystemEditingUI:
def test_run(self, system):
system.disable_editing_system().should_be_called()
system.disable_system_editing_ui().should_be_called()
subject.disable_system_editing_ui(system)
class TestAddSystem:
def test_run(self, ifc, system):
ifc.run("system.add_system", ifc_class="ifc_class").should_be_called()
system.import_systems().should_be_called()
subject.add_system(ifc, system, ifc_class="ifc_class")
class TestEditSystem:
def test_run(self, ifc, system):
system.export_system_attributes().should_be_called().will_return("attributes")
ifc.run("system.edit_system", system="system", attributes="attributes").should_be_called()
system.disable_editing_system().should_be_called()
system.import_systems().should_be_called()
subject.edit_system(ifc, system, system="system")
class TestRemoveSystem:
def test_run(self, ifc, system):
ifc.run("system.remove_system", system="system").should_be_called()
system.import_systems().should_be_called()
subject.remove_system(ifc, system, system="system")
class TestEnableEditingSystem:
def test_run(self, system):
system.import_system_attributes("system").should_be_called()
system.set_active_system("system").should_be_called()
subject.enable_editing_system(system, system="system")
class TestDisableEditingSystem:
def test_run(self, system):
system.disable_editing_system().should_be_called()
subject.disable_editing_system(system)
class TestAssignSystem:
def test_run(self, ifc):
ifc.run("system.assign_system", product="product", system="system").should_be_called()
subject.assign_system(ifc, system="system", product="product")
class TestUnassignSystem:
def test_run(self, ifc):
ifc.run("system.unassign_system", product="product", system="system").should_be_called()
subject.unassign_system(ifc, system="system", product="product")
class TestSelectSystemProducts:
def test_run(self, system):
system.select_system_products("system").should_be_called()
subject.select_system_products(system, system="system")
+152
View File
@@ -0,0 +1,152 @@
# BlenderBIM Add-on - OpenBIM Blender Add-on
# Copyright (C) 2022 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 ifcopenshell
import blenderbim.core.tool
import blenderbim.tool as tool
from test.bim.bootstrap import NewFile
from blenderbim.tool.system import System as subject
class TestImplementsTool(NewFile):
def test_run(self):
assert isinstance(subject(), blenderbim.core.tool.System)
class TestDisableEditingSystem(NewFile):
def test_run(self):
bpy.context.scene.BIMSystemProperties.active_system_id = 10
subject.disable_editing_system()
assert bpy.context.scene.BIMSystemProperties.active_system_id == 0
class TestDisableSystemEditingUI(NewFile):
def test_run(self):
subject.enable_system_editing_ui()
subject.disable_system_editing_ui()
assert bpy.context.scene.BIMSystemProperties.is_editing is False
class TestEnableSystemEditingUI(NewFile):
def test_run(self):
subject.enable_system_editing_ui()
assert bpy.context.scene.BIMSystemProperties.is_editing is True
class TestExportSystemAttributes(NewFile):
def test_run(self):
TestImportSystemAttributes().test_importing_a_system()
assert subject.export_system_attributes() == {
"GlobalId": "GlobalId",
"Name": "Name",
"Description": "Description",
"ObjectType": "ObjectType",
}
class TestImportSystemAttributes(NewFile):
def test_importing_a_system(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
system = ifc.createIfcSystem()
system.GlobalId = "GlobalId"
system.Name = "Name"
system.Description = "Description"
system.ObjectType = "ObjectType"
subject().import_system_attributes(system)
props = bpy.context.scene.BIMSystemProperties
assert props.system_attributes.get("GlobalId").string_value == "GlobalId"
assert props.system_attributes.get("Name").string_value == "Name"
assert props.system_attributes.get("Description").string_value == "Description"
assert props.system_attributes.get("ObjectType").string_value == "ObjectType"
def test_importing_a_building_system(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
system = ifc.createIfcBuildingSystem()
system.GlobalId = "GlobalId"
system.Name = "Name"
system.Description = "Description"
system.ObjectType = "ObjectType"
system.PredefinedType = "SHADING"
system.LongName = "LongName"
subject().import_system_attributes(system)
props = bpy.context.scene.BIMSystemProperties
assert props.system_attributes.get("GlobalId").string_value == "GlobalId"
assert props.system_attributes.get("Name").string_value == "Name"
assert props.system_attributes.get("Description").string_value == "Description"
assert props.system_attributes.get("ObjectType").string_value == "ObjectType"
assert props.system_attributes.get("PredefinedType").enum_value == "SHADING"
assert props.system_attributes.get("LongName").string_value == "LongName"
def test_importing_a_distribution_system(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
system = ifc.createIfcDistributionSystem()
system.GlobalId = "GlobalId"
system.Name = "Name"
system.Description = "Description"
system.ObjectType = "ObjectType"
system.PredefinedType = "ELECTRICAL"
system.LongName = "LongName"
subject().import_system_attributes(system)
props = bpy.context.scene.BIMSystemProperties
assert props.system_attributes.get("GlobalId").string_value == "GlobalId"
assert props.system_attributes.get("Name").string_value == "Name"
assert props.system_attributes.get("Description").string_value == "Description"
assert props.system_attributes.get("ObjectType").string_value == "ObjectType"
assert props.system_attributes.get("PredefinedType").enum_value == "ELECTRICAL"
assert props.system_attributes.get("LongName").string_value == "LongName"
class TestImportSystems(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
system = ifc.createIfcDistributionSystem()
zone = ifc.createIfcZone()
subject.import_systems()
props = bpy.context.scene.BIMSystemProperties
assert len(props.systems) == 1
assert props.systems[0].ifc_definition_id == system.id()
assert props.systems[0].name == "Unnamed"
assert props.systems[0].ifc_class == "IfcDistributionSystem"
class TestSelectSystemProducts(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcPump")
system = ifcopenshell.api.run("system.add_system", ifc, ifc_class="IfcSystem")
ifcopenshell.api.run("system.assign_system", ifc, product=element, system=system)
obj = bpy.data.objects.new("Object", None)
bpy.context.scene.collection.objects.link(obj)
tool.Ifc.link(element, obj)
subject.select_system_products(system)
assert obj in bpy.context.selected_objects
class TestSetActiveSystem(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
system = ifcopenshell.api.run("system.add_system", ifc, ifc_class="IfcSystem")
subject.set_active_system(system)
assert bpy.context.scene.BIMSystemProperties.active_system_id == system.id()