mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-23 11:22:44 +00:00
Fix bug where an added default material was not linked and auto synced.
This commit is contained in:
@@ -134,7 +134,7 @@ class IfcExporter:
|
|||||||
def sync_object_placement(self, obj):
|
def sync_object_placement(self, obj):
|
||||||
blender_matrix = np.array(obj.matrix_world)
|
blender_matrix = np.array(obj.matrix_world)
|
||||||
element = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
|
element = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
|
||||||
if (obj.scale - Vector((1., 1.,1.))).length > 1e-4:
|
if (obj.scale - Vector((1.0, 1.0, 1.0))).length > 1e-4:
|
||||||
bpy.ops.bim.update_representation(obj=obj.name)
|
bpy.ops.bim.update_representation(obj=obj.name)
|
||||||
return element
|
return element
|
||||||
if element.is_a("IfcGridAxis"):
|
if element.is_a("IfcGridAxis"):
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ class UnlinkMaterial(bpy.types.Operator, Operator):
|
|||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
core.unlink_material(tool.Material, obj=context.active_object.active_material)
|
core.unlink_material(tool.Ifc, obj=context.active_object.active_material)
|
||||||
|
|
||||||
|
|
||||||
class AssignMaterial(bpy.types.Operator):
|
class AssignMaterial(bpy.types.Operator):
|
||||||
|
|||||||
@@ -17,11 +17,11 @@
|
|||||||
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
def unlink_material(material, obj=None):
|
def unlink_material(ifc, obj=None):
|
||||||
material.unlink(obj)
|
ifc.unlink(obj=obj)
|
||||||
|
|
||||||
|
|
||||||
def add_default_material(ifc, material):
|
def add_default_material(ifc, material):
|
||||||
obj = material.add_default_material_object()
|
obj = material.add_default_material_object()
|
||||||
material.link(ifc.run("material.add_material", name="Default"), obj)
|
ifc.link(ifc.run("material.add_material", name="Default"), obj)
|
||||||
return obj
|
return obj
|
||||||
|
|||||||
@@ -121,8 +121,6 @@ class Ifc:
|
|||||||
@interface
|
@interface
|
||||||
class Material:
|
class Material:
|
||||||
def add_default_material_object(cls): pass
|
def add_default_material_object(cls): pass
|
||||||
def link(cls, element, obj): pass
|
|
||||||
def unlink(cls, obj): pass
|
|
||||||
|
|
||||||
|
|
||||||
@interface
|
@interface
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ class Geometry(blenderbim.core.tool.Geometry):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def clear_scale(cls, obj):
|
def clear_scale(cls, obj):
|
||||||
if (obj.scale - Vector((1., 1.,1.))).length > 1e-4:
|
if (obj.scale - Vector((1.0, 1.0, 1.0))).length > 1e-4:
|
||||||
if obj.data.users == 1:
|
if obj.data.users == 1:
|
||||||
context_override = {}
|
context_override = {}
|
||||||
context_override["object"] = context_override["active_object"] = obj
|
context_override["object"] = context_override["active_object"] = obj
|
||||||
|
|||||||
@@ -27,11 +27,3 @@ class Material(blenderbim.core.tool.Material):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def add_default_material_object(cls):
|
def add_default_material_object(cls):
|
||||||
return bpy.data.materials.new("Default")
|
return bpy.data.materials.new("Default")
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def link(cls, material, obj):
|
|
||||||
obj.BIMObjectProperties.ifc_definition_id = material.id()
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def unlink(self, obj):
|
|
||||||
obj.BIMObjectProperties.ifc_definition_id = 0
|
|
||||||
|
|||||||
@@ -6,7 +6,24 @@ Scenario: Add default material
|
|||||||
When I press "bim.add_default_material"
|
When I press "bim.add_default_material"
|
||||||
Then the material "Default" exists
|
Then the material "Default" exists
|
||||||
|
|
||||||
Scenario: Unlink object
|
Scenario: Add material
|
||||||
|
Given an empty IFC project
|
||||||
|
And I add a cube
|
||||||
|
And the object "Cube" is selected
|
||||||
|
And I add a material
|
||||||
|
When I press "bim.add_material"
|
||||||
|
Then the material "Material" is an IFC material
|
||||||
|
|
||||||
|
Scenario: Remove material
|
||||||
|
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.remove_material"
|
||||||
|
Then the material "Material" is not an IFC material
|
||||||
|
|
||||||
|
Scenario: Unlink material
|
||||||
Given an empty IFC project
|
Given an empty IFC project
|
||||||
And I add a cube
|
And I add a cube
|
||||||
And the object "Cube" is selected
|
And the object "Cube" is selected
|
||||||
|
|||||||
@@ -367,6 +367,12 @@ def the_object_name_is_not_an_ifc_element(name):
|
|||||||
assert id != 0, f"The ID is {id}"
|
assert id != 0, f"The ID is {id}"
|
||||||
|
|
||||||
|
|
||||||
|
@then(parsers.parse('the material "{name}" is 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 material'))
|
@then(parsers.parse('the material "{name}" is not an IFC material'))
|
||||||
def the_material_name_is_not_an_ifc_material(name):
|
def the_material_name_is_not_an_ifc_material(name):
|
||||||
id = the_material_name_exists(name).BIMObjectProperties.ifc_definition_id
|
id = the_material_name_exists(name).BIMObjectProperties.ifc_definition_id
|
||||||
|
|||||||
@@ -21,14 +21,14 @@ from test.core.bootstrap import ifc, material
|
|||||||
|
|
||||||
|
|
||||||
class TestUnlinkMaterial:
|
class TestUnlinkMaterial:
|
||||||
def test_run(self, material):
|
def test_run(self, ifc):
|
||||||
material.unlink("obj").should_be_called()
|
ifc.unlink(obj="obj").should_be_called()
|
||||||
subject.unlink_material(material, obj="obj")
|
subject.unlink_material(ifc, obj="obj")
|
||||||
|
|
||||||
|
|
||||||
class TestAddDefaultMaterial:
|
class TestAddDefaultMaterial:
|
||||||
def test_run(self, ifc, material):
|
def test_run(self, ifc, material):
|
||||||
material.add_default_material_object().should_be_called().will_return("obj")
|
material.add_default_material_object().should_be_called().will_return("obj")
|
||||||
ifc.run("material.add_material", name="Default").should_be_called().will_return("material")
|
ifc.run("material.add_material", name="Default").should_be_called().will_return("material")
|
||||||
material.link("material", "obj").should_be_called()
|
ifc.link("material", "obj").should_be_called()
|
||||||
assert subject.add_default_material(ifc, material) == "obj"
|
assert subject.add_default_material(ifc, material) == "obj"
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ class TestGetObject(test.bim.bootstrap.NewFile):
|
|||||||
|
|
||||||
|
|
||||||
class TestLink(test.bim.bootstrap.NewFile):
|
class TestLink(test.bim.bootstrap.NewFile):
|
||||||
def test_run(self):
|
def test_link_an_object(self):
|
||||||
ifc = ifcopenshell.file()
|
ifc = ifcopenshell.file()
|
||||||
subject.set(ifc)
|
subject.set(ifc)
|
||||||
element = ifc.createIfcWall()
|
element = ifc.createIfcWall()
|
||||||
@@ -110,9 +110,18 @@ class TestLink(test.bim.bootstrap.NewFile):
|
|||||||
assert subject.get_entity(obj) == element
|
assert subject.get_entity(obj) == element
|
||||||
assert subject.get_object(element) == obj
|
assert subject.get_object(element) == obj
|
||||||
|
|
||||||
|
def test_link_a_material(self):
|
||||||
|
ifc = ifcopenshell.file()
|
||||||
|
subject.set(ifc)
|
||||||
|
element = ifc.createIfcMaterial()
|
||||||
|
obj = bpy.data.materials.new("Material")
|
||||||
|
subject.link(element, obj)
|
||||||
|
assert subject.get_entity(obj) == element
|
||||||
|
assert subject.get_object(element) == obj
|
||||||
|
|
||||||
|
|
||||||
class TestUnlink(test.bim.bootstrap.NewFile):
|
class TestUnlink(test.bim.bootstrap.NewFile):
|
||||||
def test_run(self):
|
def test_unlink_an_object(self):
|
||||||
ifc = ifcopenshell.file()
|
ifc = ifcopenshell.file()
|
||||||
subject.set(ifc)
|
subject.set(ifc)
|
||||||
element = ifc.createIfcWall()
|
element = ifc.createIfcWall()
|
||||||
@@ -122,6 +131,16 @@ class TestUnlink(test.bim.bootstrap.NewFile):
|
|||||||
assert subject.get_entity(obj) is None
|
assert subject.get_entity(obj) is None
|
||||||
assert subject.get_object(element) is None
|
assert subject.get_object(element) is None
|
||||||
|
|
||||||
|
def test_unlink_a_material(self):
|
||||||
|
ifc = ifcopenshell.file()
|
||||||
|
subject.set(ifc)
|
||||||
|
element = ifc.createIfcMaterial()
|
||||||
|
obj = bpy.data.materials.new("Material")
|
||||||
|
subject.link(element, obj)
|
||||||
|
subject.unlink(element, obj)
|
||||||
|
assert subject.get_entity(obj) is None
|
||||||
|
assert subject.get_object(element) is None
|
||||||
|
|
||||||
def test_unlinking_using_an_object(self):
|
def test_unlinking_using_an_object(self):
|
||||||
ifc = ifcopenshell.file()
|
ifc = ifcopenshell.file()
|
||||||
subject.set(ifc)
|
subject.set(ifc)
|
||||||
|
|||||||
@@ -34,22 +34,3 @@ class TestAddDefaultMaterialObject(NewFile):
|
|||||||
material = subject.add_default_material_object()
|
material = subject.add_default_material_object()
|
||||||
assert isinstance(material, bpy.types.Material)
|
assert isinstance(material, bpy.types.Material)
|
||||||
assert material.name == "Default"
|
assert material.name == "Default"
|
||||||
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|||||||
Reference in New Issue
Block a user