New feature to unlink Blender materials and IFC materials

This commit is contained in:
Dion Moult
2021-10-16 16:52:47 +11:00
parent 516503b9ca
commit 26cbd82da1
15 changed files with 205 additions and 18 deletions
@@ -20,27 +20,28 @@ import bpy
from . import ui, prop, operator
classes = (
operator.CopyMaterial,
operator.AddMaterial,
operator.RemoveMaterial,
operator.AssignMaterial,
operator.UnassignMaterial,
operator.AddConstituent,
operator.RemoveConstituent,
operator.AddProfile,
operator.RemoveProfile,
operator.AssignParameterizedProfile,
operator.AddLayer,
operator.RemoveLayer,
operator.ReorderMaterialSetItem,
operator.AddListItem,
operator.RemoveListItem,
operator.EnableEditingAssignedMaterial,
operator.AddMaterial,
operator.AddProfile,
operator.AssignMaterial,
operator.AssignParameterizedProfile,
operator.CopyMaterial,
operator.DisableEditingAssignedMaterial,
operator.EditAssignedMaterial,
operator.EnableEditingMaterialSetItem,
operator.DisableEditingMaterialSetItem,
operator.EditAssignedMaterial,
operator.EditMaterialSetItem,
operator.EnableEditingAssignedMaterial,
operator.EnableEditingMaterialSetItem,
operator.RemoveConstituent,
operator.RemoveLayer,
operator.RemoveListItem,
operator.RemoveMaterial,
operator.RemoveProfile,
operator.ReorderMaterialSetItem,
operator.UnassignMaterial,
operator.UnlinkMaterial,
prop.BIMObjectMaterialProperties,
ui.BIM_PT_material,
ui.BIM_PT_object_material,
@@ -23,12 +23,21 @@ import ifcopenshell.util.element
import ifcopenshell.util.attribute
import ifcopenshell.util.representation
import blenderbim.bim.helper
import blenderbim.tool as tool
import blenderbim.core.material as core
from blenderbim.bim.module.material.prop import purge as material_prop_purge
from blenderbim.bim.ifc import IfcStore
from ifcopenshell.api.material.data import Data
from ifcopenshell.api.profile.data import Data as ProfileData
class Operator:
def execute(self, context):
IfcStore.execute_ifc_operator(self, context)
blenderbim.bim.handler.refresh_ui_data()
return {"FINISHED"}
class AssignParameterizedProfile(bpy.types.Operator):
bl_idname = "bim.assign_parameterized_profile"
bl_label = "Assign Parameterized Profile"
@@ -112,6 +121,15 @@ class RemoveMaterial(bpy.types.Operator):
return {"FINISHED"}
class UnlinkMaterial(bpy.types.Operator, Operator):
bl_idname = "bim.unlink_material"
bl_label = "Unlink Material"
bl_options = {"REGISTER", "UNDO"}
def _execute(self, context):
core.unlink_material(tool.Material, obj=context.active_object.active_material)
class AssignMaterial(bpy.types.Operator):
bl_idname = "bim.assign_material"
bl_label = "Assign Material"
@@ -36,9 +36,10 @@ class BIM_PT_material(Panel):
return IfcStore.get_file() and context.active_object and context.active_object.active_material
def draw(self, context):
row = self.layout.row()
row = self.layout.row(align=True)
if bool(context.active_object.active_material.BIMObjectProperties.ifc_definition_id):
row.operator("bim.remove_material", icon="X", text="Remove IFC Material")
row.operator("bim.unlink_material", icon="UNLINKED", text="")
else:
row.operator("bim.add_material", icon="ADD", text="Create IFC Material")
@@ -0,0 +1,21 @@
# 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/>.
def unlink_material(material, obj=None):
material.unlink(obj)
+5
View File
@@ -72,6 +72,11 @@ class Ifc:
def unlink(cls, element=None, obj=None): pass
@interface
class Material:
def unlink(cls, obj): pass
@interface
class Owner:
def add_address_attribute(cls, name): pass
@@ -22,6 +22,7 @@ from blenderbim.tool.collector import Collector
from blenderbim.tool.container import Container
from blenderbim.tool.context import Context
from blenderbim.tool.ifc import Ifc
from blenderbim.tool.material import Material
from blenderbim.tool.owner import Owner
from blenderbim.tool.style import Style
from blenderbim.tool.surveyor import Surveyor
@@ -0,0 +1,32 @@
# 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 ifcopenshell
import blenderbim.core.tool
import blenderbim.tool as tool
import blenderbim.bim.helper
class Material(blenderbim.core.tool.Material):
@classmethod
def link(cls, material, obj):
obj.BIMObjectProperties.ifc_definition_id = material.id()
@classmethod
def unlink(self, obj):
obj.BIMObjectProperties.ifc_definition_id = 0
+1
View File
@@ -3,6 +3,7 @@ markers =
aggregate
context
geometry
material
owner
project
pset_template
@@ -0,0 +1,11 @@
@material
Feature: Material
Scenario: Unlink object
Given an empty IFC project
And I add a cube
And the object "Cube" is selected
And I add a material
And I press "bim.add_material"
When I press "bim.unlink_material"
Then the material "Material" is not an IFC material
@@ -30,7 +30,7 @@ Scenario: Unlink style
And I add a material
And I press "bim.add_style"
When I press "bim.unlink_style"
Then nothing happens
Then the material "Material" is not an IFC style
Scenario: Enable editing style
Given an empty IFC project
+20
View File
@@ -159,6 +159,14 @@ def the_object_name_exists(name) -> bpy.types.Object:
return obj
@then(parsers.parse('the material "{name}" exists'))
def the_material_name_exists(name) -> bpy.types.Material:
obj = bpy.data.materials.get(name)
if not obj:
assert False, f'The material "{name}" does not exist'
return obj
@then("an IFC file does not exist")
def an_ifc_file_does_not_exist():
ifc = IfcStore.get_file()
@@ -249,6 +257,18 @@ def the_object_name_is_not_an_ifc_element(name):
assert id == 0, f"The ID is {id}"
@then(parsers.parse('the material "{name}" is not an IFC material'))
def the_material_name_is_not_an_ifc_material(name):
id = the_material_name_exists(name).BIMObjectProperties.ifc_definition_id
assert id == 0, f"The ID is {id}"
@then(parsers.parse('the material "{name}" is not an IFC style'))
def the_material_name_is_not_an_ifc_material(name):
id = the_material_name_exists(name).BIMMaterialProperties.ifc_style_id
assert id == 0, f"The ID is {id}"
@then(parsers.parse('the object "{name}" has "{number}" vertices'))
def the_object_name_has_number_vertices(name, number):
total = len(the_object_name_exists(name).data.vertices)
+7
View File
@@ -49,6 +49,13 @@ def context():
prophet.verify()
@pytest.fixture
def material():
prophet = Prophecy(blenderbim.core.tool.Material)
yield prophet
prophet.verify()
@pytest.fixture
def owner():
prophet = Prophecy(blenderbim.core.tool.Owner)
+26
View File
@@ -0,0 +1,26 @@
# 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.material as subject
from test.core.bootstrap import ifc, material
class TestUnlinkMaterial:
def test_run(self, material):
material.unlink("obj").should_be_called()
subject.unlink_material(material, obj="obj")
+1 -1
View File
@@ -127,7 +127,7 @@ class TestImportContainers(NewFile):
bpy.ops.bim.copy_class(obj=tool.Ifc.get_object(storey1).name)
storey2 = tool.Ifc.get().by_type("IfcBuildingStorey")[1]
storey2.Name = "Lower"
storey2.ObjectPlacement.RelativePlacement.Location.Coordinates = (0., 0., -100.)
storey2.ObjectPlacement.RelativePlacement.Location.Coordinates = (0.0, 0.0, -100.0)
subject.import_containers(building)
props = bpy.context.scene.BIMSpatialProperties
assert len(props.containers) == 2
+43
View File
@@ -0,0 +1,43 @@
# 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.material import Material as subject
class TestLink(NewFile):
def test_run(self):
obj = bpy.data.materials.new("Material")
ifc = ifcopenshell.file()
material = ifc.createIfcMaterial()
subject.link(material, obj)
assert obj.BIMObjectProperties.ifc_definition_id == material.id()
class TestUnlink(NewFile):
def test_run(self):
obj = bpy.data.materials.new("Material")
ifc = ifcopenshell.file()
material = ifc.createIfcMaterial()
subject.link(material, obj)
subject.unlink(obj)
assert obj.BIMObjectProperties.ifc_definition_id == 0