mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-15 13:48:09 +00:00
Fix bug in IFC2X3 where updating style colours didn't work.
This commit is contained in:
@@ -32,6 +32,7 @@ import blenderbim.core.aggregate
|
|||||||
import blenderbim.core.spatial
|
import blenderbim.core.spatial
|
||||||
import blenderbim.core.style
|
import blenderbim.core.style
|
||||||
from blenderbim.bim.ifc import IfcStore
|
from blenderbim.bim.ifc import IfcStore
|
||||||
|
from mathutils import Vector
|
||||||
|
|
||||||
|
|
||||||
class IfcExporter:
|
class IfcExporter:
|
||||||
@@ -133,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 list(obj.scale) != [1.0, 1.0, 1.0]:
|
if (obj.scale - Vector((1., 1.,1.))).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"):
|
||||||
|
|||||||
@@ -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.0, 1.0, 1.0)):
|
if (obj.scale - Vector((1., 1.,1.))).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
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ class Style(blenderbim.core.tool.Style):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_surface_shading_attributes(cls, obj):
|
def get_surface_shading_attributes(cls, obj):
|
||||||
return {
|
data = {
|
||||||
"SurfaceColour": {
|
"SurfaceColour": {
|
||||||
"Name": None,
|
"Name": None,
|
||||||
"Red": obj.diffuse_color[0],
|
"Red": obj.diffuse_color[0],
|
||||||
@@ -92,6 +92,9 @@ class Style(blenderbim.core.tool.Style):
|
|||||||
},
|
},
|
||||||
"Transparency": 1 - obj.diffuse_color[3],
|
"Transparency": 1 - obj.diffuse_color[3],
|
||||||
}
|
}
|
||||||
|
if tool.Ifc.get_schema() == "IFC2X3":
|
||||||
|
del data["Transparency"]
|
||||||
|
return data
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_surface_shading_style(cls, obj):
|
def get_surface_shading_style(cls, obj):
|
||||||
|
|||||||
@@ -131,6 +131,7 @@ class TestGetSurfaceRenderingStyle(NewFile):
|
|||||||
|
|
||||||
class TestGetSurfaceShadingAttributes(NewFile):
|
class TestGetSurfaceShadingAttributes(NewFile):
|
||||||
def test_get_colours_from_a_basic_material(self):
|
def test_get_colours_from_a_basic_material(self):
|
||||||
|
tool.Ifc.set(ifcopenshell.file())
|
||||||
obj = bpy.data.materials.new("Material")
|
obj = bpy.data.materials.new("Material")
|
||||||
obj.diffuse_color = [1, 1, 1, 1]
|
obj.diffuse_color = [1, 1, 1, 1]
|
||||||
assert subject.get_surface_shading_attributes(obj) == {
|
assert subject.get_surface_shading_attributes(obj) == {
|
||||||
@@ -143,6 +144,19 @@ class TestGetSurfaceShadingAttributes(NewFile):
|
|||||||
"Transparency": 0,
|
"Transparency": 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def test_get_colours_from_a_basic_material_ifc2x3(self):
|
||||||
|
tool.Ifc.set(ifcopenshell.file(schema="IFC2X3"))
|
||||||
|
obj = bpy.data.materials.new("Material")
|
||||||
|
obj.diffuse_color = [1, 1, 1, 1]
|
||||||
|
assert subject.get_surface_shading_attributes(obj) == {
|
||||||
|
"SurfaceColour": {
|
||||||
|
"Name": None,
|
||||||
|
"Red": 1,
|
||||||
|
"Green": 1,
|
||||||
|
"Blue": 1,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class TestGetSurfaceShadingStyle(NewFile):
|
class TestGetSurfaceShadingStyle(NewFile):
|
||||||
def test_run(self):
|
def test_run(self):
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
import pytest
|
import pytest
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import ifcopenshell.api
|
import ifcopenshell.api
|
||||||
|
import ifcopenshell.api.owner.settings
|
||||||
|
|
||||||
|
|
||||||
class IFC4:
|
class IFC4:
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def setup(self):
|
def setup(self):
|
||||||
self.file = ifcopenshell.api.run("project.create_file")
|
self.file = ifcopenshell.api.run("project.create_file")
|
||||||
|
ifcopenshell.api.owner.settings.get_user = lambda ifc: (ifc.by_type("IfcPersonAndOrganization") or [None])[0]
|
||||||
|
ifcopenshell.api.owner.settings.get_application = lambda ifc: (ifc.by_type("IfcApplication") or [None])[0]
|
||||||
|
|
||||||
|
|
||||||
class IFC2X3:
|
class IFC2X3:
|
||||||
|
|||||||
Reference in New Issue
Block a user