Object style colours are now auto synchronised upon export. See #1585.

This commit is contained in:
Dion Moult
2021-07-28 21:01:09 +10:00
parent 10b6253a36
commit 2537349ec2
7 changed files with 36 additions and 15 deletions
+6 -3
View File
@@ -67,9 +67,9 @@ class IfcExporter:
to_delete = []
for ifc_definition_id, obj in IfcStore.id_map.items():
if isinstance(obj, bpy.types.Material):
continue
try:
if isinstance(obj, bpy.types.Material):
continue
self.sync_object_placement(obj)
self.sync_object_container(ifc_definition_id, obj)
except ReferenceError:
@@ -89,7 +89,10 @@ class IfcExporter:
if not obj:
continue
try:
bpy.ops.bim.update_representation(obj=obj.name)
if isinstance(obj, bpy.types.Material):
bpy.ops.bim.update_style_colours(material=obj.name)
else:
bpy.ops.bim.update_representation(obj=obj.name)
except ReferenceError:
pass # The object is likely deleted
IfcStore.edited_objs.clear()
+6
View File
@@ -35,6 +35,7 @@ def mode_callback(obj, data):
def name_callback(obj, data):
# TODO Do we still need this, now that we are monitoring the undo redo objects?
try:
obj.name
except:
@@ -76,6 +77,11 @@ def name_callback(obj, data):
AttributeData.load(IfcStore.get_file(), obj.BIMObjectProperties.ifc_definition_id)
def color_callback(obj, data):
if obj.BIMMaterialProperties.ifc_style_id:
IfcStore.edited_objs.add(obj)
def active_object_callback():
obj = bpy.context.active_object
for obj in bpy.context.selected_objects:
+16 -2
View File
@@ -114,9 +114,19 @@ class IfcStore:
IfcStore.id_map[element.id()] = obj
if hasattr(element, "GlobalId"):
IfcStore.guid_map[element.GlobalId] = obj
obj.BIMObjectProperties.ifc_definition_id = element.id()
blenderbim.bim.handler.subscribe_to(obj, "mode", blenderbim.bim.handler.mode_callback)
if element.is_a("IfcSurfaceStyle"):
obj.BIMMaterialProperties.ifc_style_id = element.id()
else:
obj.BIMObjectProperties.ifc_definition_id = element.id()
blenderbim.bim.handler.subscribe_to(obj, "name", blenderbim.bim.handler.name_callback)
if isinstance(obj, bpy.types.Material):
blenderbim.bim.handler.subscribe_to(obj, "diffuse_color", blenderbim.bim.handler.color_callback)
elif isinstance(obj, bpy.types.Object):
blenderbim.bim.handler.subscribe_to(obj, "mode", blenderbim.bim.handler.mode_callback)
for listener in IfcStore.element_listeners:
listener(element, obj)
@@ -140,6 +150,10 @@ class IfcStore:
IfcStore.guid_map[data["guid"]] = obj
blenderbim.bim.handler.subscribe_to(obj, "mode", blenderbim.bim.handler.mode_callback)
blenderbim.bim.handler.subscribe_to(obj, "name", blenderbim.bim.handler.name_callback)
if isinstance(obj, bpy.types.Material):
blenderbim.bim.handler.subscribe_to(obj, "diffuse_color", blenderbim.bim.handler.color_callback)
# TODO Listeners are not re-registered. Does this cause nasty problems to debug later on?
# TODO We're handling id_map and guid_map, but what about edited_objs? This might cause big problems.
@staticmethod
def unlink_element(element=None, obj=None):
@@ -54,7 +54,6 @@ class AddMaterial(bpy.types.Operator):
obj = bpy.data.materials.get(self.obj) if self.obj else bpy.context.active_object.active_material
self.file = IfcStore.get_file()
result = ifcopenshell.api.run("material.add_material", self.file, **{"name": obj.name})
obj.BIMObjectProperties.ifc_definition_id = result.id()
IfcStore.link_element(result, obj)
if obj.BIMMaterialProperties.ifc_style_id:
context = ifcopenshell.util.representation.get_context(self.file, "Model", "Body", "MODEL_VIEW")
@@ -74,7 +74,7 @@ class AddStyle(bpy.types.Operator):
settings["name"] = material.name
settings["external_definition"] = None # TODO: Implement. See #1222
style = ifcopenshell.api.run("style.add_style", self.file, **settings)
material.BIMMaterialProperties.ifc_style_id = style.id()
IfcStore.link_element(style, material)
if material.BIMObjectProperties.ifc_definition_id:
context = ifcopenshell.util.representation.get_context(self.file, "Model", "Body", "MODEL_VIEW")
if context:
@@ -20,14 +20,13 @@ class BIM_PT_style(Panel):
)
def draw(self, context):
props = context.active_object.active_material.BIMMaterialProperties
material = context.active_object.active_material
props = material.BIMMaterialProperties
row = self.layout.row(align=True)
if props.ifc_style_id:
row.operator("bim.update_style_colours", icon="GREASEPENCIL")
op = row.operator("bim.unlink_style", icon="UNLINKED", text="")
op.material = context.active_object.active_material.name
op = row.operator("bim.remove_style", icon="X", text="")
op.material = context.active_object.active_material.name
row.operator("bim.update_style_colours", icon="GREASEPENCIL").material = material.name
row.operator("bim.unlink_style", icon="UNLINKED", text="").material = material.name
row.operator("bim.remove_style", icon="X", text="").material = material.name
else:
row.operator("bim.add_style", icon="ADD")
@@ -23,7 +23,7 @@ class Usecase:
self.update_colour_rgb(element.SurfaceColour, self.settings["surface_colour"])
else:
element.SurfaceColour = self.create_colour_rgb(self.settings["surface_colour"])
element.Transparency = (self.settings["transparency"] - 1) * -1
element.Transparency = self.settings["transparency"]
if element.is_a("IfcSurfaceStyleRendering"):
if element.DiffuseColour:
self.update_colour_rgb(element.DiffuseColour, self.settings["diffuse_colour"])
@@ -44,7 +44,7 @@ class Usecase:
def create_surface_style_rendering(self):
return self.file.create_entity("IfcSurfaceStyleRendering", **{
"SurfaceColour": self.create_colour_rgb(self.settings["surface_colour"]),
"Transparency": (self.settings["transparency"] - 1) * -1,
"Transparency": self.settings["transparency"],
"ReflectanceMethod": "NOTDEFINED",
"DiffuseColour": self.create_colour_rgb(self.settings["diffuse_colour"])
})