When assigning types, your preference of dynamic voids are now preserved.

This commit is contained in:
Dion Moult
2021-10-19 15:43:14 +11:00
parent c1b53859ee
commit 3daf4203d1
16 changed files with 345 additions and 53 deletions
@@ -0,0 +1,17 @@
@type
Feature: Type
Scenario: Assign type
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 I add an empty
And the object "Empty" is selected
And I set "scene.BIMRootProperties.ifc_product" to "IfcElementType"
And I set "scene.BIMRootProperties.ifc_class" to "IfcWallType"
And I press "bim.assign_class"
When the variable "type" is "{ifc}.by_type('IfcWallType')[0].id()"
And I press "bim.assign_type(relating_type={type}, related_object="IfcWall/Cube")"
Then nothing happens
+7
View File
@@ -77,6 +77,13 @@ def owner():
prophet.verify()
@pytest.fixture
def type():
prophet = Prophecy(blenderbim.core.tool.Type)
yield prophet
prophet.verify()
@pytest.fixture
def voider():
prophet = Prophecy(blenderbim.core.tool.Voider)
+30 -1
View File
@@ -179,7 +179,7 @@ class TestAddRepresentation:
class TestSwitchRepresentation:
def test_run(self, ifc, geometry, style, surveyor):
def test_switching_to_a_freshly_reloaded_representation(self, geometry):
geometry.resolve_mapped_representation("mapped_rep").should_be_called().will_return("representation")
geometry.get_representation_data("representation").should_be_called().will_return("data")
geometry.import_representation(
@@ -199,3 +199,32 @@ class TestSwitchRepresentation:
enable_dynamic_voids=True,
is_global=True,
)
def test_switching_to_an_existing_representation(self, geometry):
geometry.resolve_mapped_representation("mapped_rep").should_be_called().will_return("representation")
geometry.get_representation_data("representation").should_be_called().will_return("data")
geometry.change_object_data("obj", "data", is_global=True).should_be_called()
geometry.is_body_representation("representation").should_be_called().will_return(True)
geometry.create_dynamic_voids("obj").should_be_called()
subject.switch_representation(
geometry,
obj="obj",
representation="mapped_rep",
should_reload=False,
enable_dynamic_voids=True,
is_global=True,
)
def test_switching_to_non_dynamic_baked_voids(self, geometry):
geometry.resolve_mapped_representation("mapped_rep").should_be_called().will_return("representation")
geometry.get_representation_data("representation").should_be_called().will_return("data")
geometry.change_object_data("obj", "data", is_global=False).should_be_called()
geometry.clear_dynamic_voids("obj").should_be_called()
subject.switch_representation(
geometry,
obj="obj",
representation="mapped_rep",
should_reload=False,
enable_dynamic_voids=False,
is_global=False,
)
+61
View File
@@ -0,0 +1,61 @@
# 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.type as subject
from test.core.bootstrap import ifc, geometry, type
class TestAssignType:
def test_assigning_and_switching_preferably_to_a_body_representation(self, ifc, geometry, type):
ifc.run("type.assign_type", related_object="element", relating_type="type").should_be_called()
type.get_body_representation("element").should_be_called().will_return("mapped_rep")
ifc.get_object("element").should_be_called().will_return("obj")
type.has_dynamic_voids("obj").should_be_called().will_return(False)
geometry.resolve_mapped_representation("mapped_rep").should_be_called().will_return("representation")
geometry.get_representation_data("representation").should_be_called().will_return("data")
geometry.change_object_data("obj", "data", is_global=False).should_be_called()
geometry.clear_dynamic_voids("obj").should_be_called()
type.disable_editing("obj").should_be_called()
subject.assign_type(ifc, geometry, type, element="element", type="type")
def test_assigning_and_switching_to_any_representation_as_a_fallback(self, ifc, geometry, type):
ifc.run("type.assign_type", related_object="element", relating_type="type").should_be_called()
type.get_body_representation("element").should_be_called().will_return(None)
type.get_any_representation("element").should_be_called().will_return("mapped_rep")
ifc.get_object("element").should_be_called().will_return("obj")
type.has_dynamic_voids("obj").should_be_called().will_return(False)
geometry.resolve_mapped_representation("mapped_rep").should_be_called().will_return("representation")
geometry.get_representation_data("representation").should_be_called().will_return("data")
geometry.change_object_data("obj", "data", is_global=False).should_be_called()
geometry.clear_dynamic_voids("obj").should_be_called()
type.disable_editing("obj").should_be_called()
subject.assign_type(ifc, geometry, type, element="element", type="type")
def test_assigning_and_not_changing_representation_if_not_available(self, ifc, type):
ifc.run("type.assign_type", related_object="element", relating_type="type").should_be_called()
type.get_body_representation("element").should_be_called().will_return(None)
type.get_any_representation("element").should_be_called().will_return(None)
ifc.get_object("element").should_be_called().will_return("obj")
type.disable_editing("obj").should_be_called()
subject.assign_type(ifc, geometry, type, element="element", type="type")
+89
View File
@@ -0,0 +1,89 @@
# 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 ifcopenshell
import blenderbim.core.tool
import blenderbim.tool as tool
from test.bim.bootstrap import NewFile
from blenderbim.tool.type import Type as subject
class TestImplementsTool(NewFile):
def test_run(self):
assert isinstance(subject(), blenderbim.core.tool.Type)
class TestDisableEditing(NewFile):
def test_run(self):
obj = bpy.data.objects.new("Object", None)
obj.BIMTypeProperties.is_editing_type = True
subject.disable_editing(obj)
assert obj.BIMTypeProperties.is_editing_type is False
class TestGetAnyRepresentation(NewFile):
def test_get_product_representation(self):
ifc = ifcopenshell.file()
representation = ifc.createIfcShapeRepresentation()
element = ifc.createIfcWall(Representation=ifc.createIfcProductRepresentation(Representations=[representation]))
assert subject.get_any_representation(element) == representation
def test_get_type_product_representation(self):
ifc = ifcopenshell.file()
representation = ifc.createIfcShapeRepresentation()
element = ifc.createIfcWallType(
RepresentationMaps=[ifc.createIfcRepresentationMap(MappedRepresentation=representation)]
)
assert subject.get_any_representation(element) == representation
class TestGetBodyRepresentation(NewFile):
def test_get_product_representation(self):
ifc = ifcopenshell.file()
rep = ifc.createIfcShapeRepresentation(ContextOfItems=ifc.createIfcGeometricRepresentationSubContext())
body_rep = ifc.createIfcShapeRepresentation(
ContextOfItems=ifc.createIfcGeometricRepresentationSubContext(ContextIdentifier="Body")
)
element = ifc.createIfcWall(Representation=ifc.createIfcProductRepresentation(Representations=[rep, body_rep]))
assert subject.get_body_representation(element) == body_rep
def test_get_type_product_representation(self):
ifc = ifcopenshell.file()
rep = ifc.createIfcShapeRepresentation(ContextOfItems=ifc.createIfcGeometricRepresentationSubContext())
body_rep = ifc.createIfcShapeRepresentation(
ContextOfItems=ifc.createIfcGeometricRepresentationSubContext(ContextIdentifier="Body")
)
element = ifc.createIfcWallType(
RepresentationMaps=[
ifc.createIfcRepresentationMap(MappedRepresentation=rep),
ifc.createIfcRepresentationMap(MappedRepresentation=body_rep),
]
)
assert subject.get_body_representation(element) == body_rep
class TestHasDynamicVoids(NewFile):
def test_run(self):
obj = bpy.data.objects.new("Object", None)
assert subject.has_dynamic_voids(obj) is False
def test_checking_modifiers(self):
obj = bpy.data.objects.new("Object", bpy.data.meshes.new("Mesh"))
obj.modifiers.new("IfcOpeningElement", "BOOLEAN")
assert subject.has_dynamic_voids(obj) is True