New feature to resize / squash / stretch objects to their storey height. Useful for remodeling IFCs for construction simulations.

This commit is contained in:
Dion Moult
2021-10-18 14:15:16 +11:00
parent c78e7b3ba8
commit 33f4461a87
12 changed files with 369 additions and 8 deletions
+15 -3
View File
@@ -2,24 +2,36 @@
Feature: Misc
Scenario: Set override colour
Given an empty IFC project
Given an empty Blender session
And I add a cube
And the object "Cube" is selected
When I press "bim.set_override_colour"
Then nothing happens
Scenario: Set viewport shadow from sun
Given an empty IFC project
Given an empty Blender session
And I add a sun
And the object "Sun" is selected
When I press "bim.set_viewport_shadow_from_sun"
Then nothing happens
Scenario: Snap spaces together
Given an empty IFC project
Given an empty Blender session
And I add a cube
And I add a cube
And the object "Cube" is selected
And additionally the object "Cube.001" is selected
When I press "bim.snap_spaces_together"
Then nothing happens
Scenario: Resize to storey
Given an empty IFC project
And I add a cube
And the object "Cube" is selected
And I set "scene.BIMRootProperties.ifc_class" to "IfcWall"
And I press "bim.assign_class"
And the object "IfcWall/Cube" is selected
And the variable "storey" is "tool.Ifc.get().by_type('IfcBuildingStorey')[0].id()"
And I press "bim.assign_container(structure={storey})"
When I press "bim.resize_to_storey"
Then nothing happens
+7
View File
@@ -56,6 +56,13 @@ def material():
prophet.verify()
@pytest.fixture
def misc():
prophet = Prophecy(blenderbim.core.tool.Misc)
yield prophet
prophet.verify()
@pytest.fixture
def owner():
prophet = Prophecy(blenderbim.core.tool.Owner)
+41
View File
@@ -0,0 +1,41 @@
# 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 blenderbim.core.misc as subject
from test.core.bootstrap import misc
class TestResizeToStorey:
def test_run(self, misc):
misc.get_object_storey("obj").should_be_called().will_return("storey")
misc.get_storey_elevation_in_si("storey").should_be_called().will_return("elevation")
misc.get_storey_height_in_si("storey").should_be_called().will_return("height")
misc.set_object_origin_to_bottom("obj").should_be_called()
misc.move_object_to_elevation("obj", "elevation").should_be_called()
misc.scale_object_to_height("obj", "height").should_be_called()
misc.mark_object_as_edited("obj").should_be_called()
subject.resize_to_storey(misc, obj="obj")
def test_doing_nothing_when_the_object_has_no_storey(self, misc):
misc.get_object_storey("obj").should_be_called().will_return(None)
subject.resize_to_storey(misc, obj="obj")
def test_doing_nothing_when_the_storey_has_no_height(self, misc):
misc.get_object_storey("obj").should_be_called().will_return("storey")
misc.get_storey_height_in_si("storey").should_be_called().will_return(None)
subject.resize_to_storey(misc, obj="obj")
+151
View File
@@ -0,0 +1,151 @@
# 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 test.bim.bootstrap
import blenderbim.core.tool
import blenderbim.tool as tool
from blenderbim.tool.misc import Misc as subject
from blenderbim.bim.ifc import IfcStore
class TestImplementsTool(test.bim.bootstrap.NewFile):
def test_run(self):
assert isinstance(subject(), blenderbim.core.tool.Misc)
class TestGetObjectStorey(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
obj = bpy.data.objects.new("Object", None)
wall = ifc.createIfcWall()
tool.Ifc.link(wall, obj)
storey = ifc.createIfcBuildingStorey()
ifcopenshell.api.run("spatial.assign_container", ifc, product=wall, relating_structure=storey)
assert subject.get_object_storey(obj) == storey
def test_only_returning_a_building_storey(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
obj = bpy.data.objects.new("Object", None)
wall = ifc.createIfcWall()
tool.Ifc.link(wall, obj)
building = ifc.createIfcBuilding()
ifcopenshell.api.run("spatial.assign_container", ifc, product=wall, relating_structure=building)
assert subject.get_object_storey(obj) is None
def test_returning_nothing_if_uncontained(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
obj = bpy.data.objects.new("Object", None)
wall = ifc.createIfcWall()
tool.Ifc.link(wall, obj)
assert subject.get_object_storey(obj) is None
class TestGetStoreyElevation(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
ifc.createIfcProject()
unit = ifcopenshell.api.run("unit.add_si_unit", ifc, prefix="MILLI")
ifcopenshell.api.run("unit.assign_unit", ifc, units=[unit])
storey = ifc.createIfcBuildingStorey()
storey.Elevation = 3000
tool.Ifc.set(ifc)
assert subject.get_storey_elevation_in_si(storey) == 3.0
class TestGetStoreyHeight(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
ifc.createIfcProject()
unit = ifcopenshell.api.run("unit.add_si_unit", ifc, prefix="MILLI")
ifcopenshell.api.run("unit.assign_unit", ifc, units=[unit])
tool.Ifc.set(ifc)
building = ifc.createIfcBuilding()
storey = ifc.createIfcBuildingStorey()
storey.Elevation = 3000
storey2 = ifc.createIfcBuildingStorey()
storey2.Elevation = 5000
ifcopenshell.api.run("aggregate.assign_object", ifc, product=storey, relating_object=building)
ifcopenshell.api.run("aggregate.assign_object", ifc, product=storey2, relating_object=building)
assert subject.get_storey_height_in_si(storey) == 2.0
def test_only_considering_storeys_in_the_same_building(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
building = ifc.createIfcBuilding()
storey = ifc.createIfcBuildingStorey()
storey.Elevation = 3000
storey2 = ifc.createIfcBuildingStorey()
storey2.Elevation = 5000
ifcopenshell.api.run("aggregate.assign_object", ifc, product=storey, relating_object=building)
assert subject.get_storey_height_in_si(storey) is None
def test_returning_none_if_the_storey_height_is_undefined(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
building = ifc.createIfcBuilding()
storey = ifc.createIfcBuildingStorey()
ifcopenshell.api.run("aggregate.assign_object", ifc, product=storey, relating_object=building)
assert subject.get_storey_height_in_si(storey) is None
class TestSetObjectOriginToBottom(test.bim.bootstrap.NewFile):
def test_run(self):
bpy.ops.mesh.primitive_cube_add()
obj = bpy.data.objects.get("Cube")
subject.set_object_origin_to_bottom(obj)
assert list(obj.matrix_world.translation) == [0.0, 0.0, -1.0]
def test_moving_the_origin_of_a_rotated_object(self):
bpy.ops.mesh.primitive_cube_add()
obj = bpy.data.objects.get("Cube")
obj.rotation_euler[1] = math.pi / 2
bpy.context.view_layer.update()
subject.set_object_origin_to_bottom(obj)
assert list(obj.matrix_world.translation) == [0.0, 0.0, -1.0]
class TestMoveObjectToElevation(test.bim.bootstrap.NewFile):
def test_run(self):
bpy.ops.mesh.primitive_cube_add()
obj = bpy.data.objects.get("Cube")
subject.move_object_to_elevation(obj, 3)
assert list(obj.matrix_world.translation) == [0.0, 0.0, 3.0]
class TestScaleObjectToHeight(test.bim.bootstrap.NewFile):
def test_run(self):
bpy.ops.mesh.primitive_cube_add()
obj = bpy.data.objects.get("Cube")
subject.set_object_origin_to_bottom(obj)
subject.scale_object_to_height(obj, 3)
assert obj.dimensions[2] == 3.0
assert list(obj.scale) == [1.0, 1.0, 1.0]
class TestMarkObjectAsEdited(test.bim.bootstrap.NewFile):
def test_run(self):
obj = bpy.data.objects.new("Cube", None)
subject.mark_object_as_edited(obj)
assert obj in IfcStore.edited_objs