mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-22 22:12:32 +00:00
Object style colours are now auto synchronised upon export. See #1585.
This commit is contained in:
@@ -67,9 +67,9 @@ class IfcExporter:
|
|||||||
to_delete = []
|
to_delete = []
|
||||||
|
|
||||||
for ifc_definition_id, obj in IfcStore.id_map.items():
|
for ifc_definition_id, obj in IfcStore.id_map.items():
|
||||||
|
if isinstance(obj, bpy.types.Material):
|
||||||
|
continue
|
||||||
try:
|
try:
|
||||||
if isinstance(obj, bpy.types.Material):
|
|
||||||
continue
|
|
||||||
self.sync_object_placement(obj)
|
self.sync_object_placement(obj)
|
||||||
self.sync_object_container(ifc_definition_id, obj)
|
self.sync_object_container(ifc_definition_id, obj)
|
||||||
except ReferenceError:
|
except ReferenceError:
|
||||||
@@ -89,7 +89,10 @@ class IfcExporter:
|
|||||||
if not obj:
|
if not obj:
|
||||||
continue
|
continue
|
||||||
try:
|
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:
|
except ReferenceError:
|
||||||
pass # The object is likely deleted
|
pass # The object is likely deleted
|
||||||
IfcStore.edited_objs.clear()
|
IfcStore.edited_objs.clear()
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ def mode_callback(obj, data):
|
|||||||
|
|
||||||
|
|
||||||
def name_callback(obj, data):
|
def name_callback(obj, data):
|
||||||
|
# TODO Do we still need this, now that we are monitoring the undo redo objects?
|
||||||
try:
|
try:
|
||||||
obj.name
|
obj.name
|
||||||
except:
|
except:
|
||||||
@@ -76,6 +77,11 @@ def name_callback(obj, data):
|
|||||||
AttributeData.load(IfcStore.get_file(), obj.BIMObjectProperties.ifc_definition_id)
|
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():
|
def active_object_callback():
|
||||||
obj = bpy.context.active_object
|
obj = bpy.context.active_object
|
||||||
for obj in bpy.context.selected_objects:
|
for obj in bpy.context.selected_objects:
|
||||||
|
|||||||
@@ -114,9 +114,19 @@ class IfcStore:
|
|||||||
IfcStore.id_map[element.id()] = obj
|
IfcStore.id_map[element.id()] = obj
|
||||||
if hasattr(element, "GlobalId"):
|
if hasattr(element, "GlobalId"):
|
||||||
IfcStore.guid_map[element.GlobalId] = obj
|
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)
|
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:
|
for listener in IfcStore.element_listeners:
|
||||||
listener(element, obj)
|
listener(element, obj)
|
||||||
|
|
||||||
@@ -140,6 +150,10 @@ class IfcStore:
|
|||||||
IfcStore.guid_map[data["guid"]] = obj
|
IfcStore.guid_map[data["guid"]] = obj
|
||||||
blenderbim.bim.handler.subscribe_to(obj, "mode", blenderbim.bim.handler.mode_callback)
|
blenderbim.bim.handler.subscribe_to(obj, "mode", blenderbim.bim.handler.mode_callback)
|
||||||
blenderbim.bim.handler.subscribe_to(obj, "name", blenderbim.bim.handler.name_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
|
@staticmethod
|
||||||
def unlink_element(element=None, obj=None):
|
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
|
obj = bpy.data.materials.get(self.obj) if self.obj else bpy.context.active_object.active_material
|
||||||
self.file = IfcStore.get_file()
|
self.file = IfcStore.get_file()
|
||||||
result = ifcopenshell.api.run("material.add_material", self.file, **{"name": obj.name})
|
result = ifcopenshell.api.run("material.add_material", self.file, **{"name": obj.name})
|
||||||
obj.BIMObjectProperties.ifc_definition_id = result.id()
|
|
||||||
IfcStore.link_element(result, obj)
|
IfcStore.link_element(result, obj)
|
||||||
if obj.BIMMaterialProperties.ifc_style_id:
|
if obj.BIMMaterialProperties.ifc_style_id:
|
||||||
context = ifcopenshell.util.representation.get_context(self.file, "Model", "Body", "MODEL_VIEW")
|
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["name"] = material.name
|
||||||
settings["external_definition"] = None # TODO: Implement. See #1222
|
settings["external_definition"] = None # TODO: Implement. See #1222
|
||||||
style = ifcopenshell.api.run("style.add_style", self.file, **settings)
|
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:
|
if material.BIMObjectProperties.ifc_definition_id:
|
||||||
context = ifcopenshell.util.representation.get_context(self.file, "Model", "Body", "MODEL_VIEW")
|
context = ifcopenshell.util.representation.get_context(self.file, "Model", "Body", "MODEL_VIEW")
|
||||||
if context:
|
if context:
|
||||||
|
|||||||
@@ -20,14 +20,13 @@ class BIM_PT_style(Panel):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def draw(self, context):
|
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)
|
row = self.layout.row(align=True)
|
||||||
if props.ifc_style_id:
|
if props.ifc_style_id:
|
||||||
row.operator("bim.update_style_colours", icon="GREASEPENCIL")
|
row.operator("bim.update_style_colours", icon="GREASEPENCIL").material = material.name
|
||||||
op = row.operator("bim.unlink_style", icon="UNLINKED", text="")
|
row.operator("bim.unlink_style", icon="UNLINKED", text="").material = material.name
|
||||||
op.material = context.active_object.active_material.name
|
row.operator("bim.remove_style", icon="X", text="").material = material.name
|
||||||
op = row.operator("bim.remove_style", icon="X", text="")
|
|
||||||
op.material = context.active_object.active_material.name
|
|
||||||
else:
|
else:
|
||||||
row.operator("bim.add_style", icon="ADD")
|
row.operator("bim.add_style", icon="ADD")
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class Usecase:
|
|||||||
self.update_colour_rgb(element.SurfaceColour, self.settings["surface_colour"])
|
self.update_colour_rgb(element.SurfaceColour, self.settings["surface_colour"])
|
||||||
else:
|
else:
|
||||||
element.SurfaceColour = self.create_colour_rgb(self.settings["surface_colour"])
|
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.is_a("IfcSurfaceStyleRendering"):
|
||||||
if element.DiffuseColour:
|
if element.DiffuseColour:
|
||||||
self.update_colour_rgb(element.DiffuseColour, self.settings["diffuse_colour"])
|
self.update_colour_rgb(element.DiffuseColour, self.settings["diffuse_colour"])
|
||||||
@@ -44,7 +44,7 @@ class Usecase:
|
|||||||
def create_surface_style_rendering(self):
|
def create_surface_style_rendering(self):
|
||||||
return self.file.create_entity("IfcSurfaceStyleRendering", **{
|
return self.file.create_entity("IfcSurfaceStyleRendering", **{
|
||||||
"SurfaceColour": self.create_colour_rgb(self.settings["surface_colour"]),
|
"SurfaceColour": self.create_colour_rgb(self.settings["surface_colour"]),
|
||||||
"Transparency": (self.settings["transparency"] - 1) * -1,
|
"Transparency": self.settings["transparency"],
|
||||||
"ReflectanceMethod": "NOTDEFINED",
|
"ReflectanceMethod": "NOTDEFINED",
|
||||||
"DiffuseColour": self.create_colour_rgb(self.settings["diffuse_colour"])
|
"DiffuseColour": self.create_colour_rgb(self.settings["diffuse_colour"])
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user