Improve performance for bim.aggregate_assing_new_objects_in_aggregate_mode()

Add constrain only to new objects instead of rebuilding all constraints from scratch.
This commit is contained in:
Bruno Perdigão
2024-12-12 23:10:17 -03:00
committed by Bruno Perdigão
parent 3874d19caa
commit 548f6e0566
4 changed files with 10 additions and 4 deletions
+1 -1
View File
@@ -1126,7 +1126,7 @@ class IfcImporter:
if parts: if parts:
relating_obj = tool.Ifc.get_object(element) relating_obj = tool.Ifc.get_object(element)
if relating_obj: if relating_obj:
tool.Aggregate.constrain_parts_to_aggregate(relating_obj) tool.Aggregate.constrain_all_parts_to_aggregate(relating_obj)
bpy.context.scene.BIMAggregateProperties.aggregate_decorator = True bpy.context.scene.BIMAggregateProperties.aggregate_decorator = True
@@ -343,6 +343,8 @@ class AggregateModeDecorator:
new_objs = [o for o in new_objs if o.data] new_objs = [o for o in new_objs if o.data]
for obj in new_objs: for obj in new_objs:
element = tool.Ifc.get_entity(obj) element = tool.Ifc.get_entity(obj)
if (aggregate := ifcopenshell.util.element.get_aggregate(element)) == tool.Ifc.get_entity(props.editing_aggregate):
continue
if element and element.is_a("IfcElement"): if element and element.is_a("IfcElement"):
data = ItemDecorator.get_obj_data(obj) data = ItemDecorator.get_obj_data(obj)
if data: if data:
@@ -67,7 +67,7 @@ class BIM_OT_aggregate_assign_object(bpy.types.Operator, tool.Ifc.Operator):
relating_obj=relating_obj, relating_obj=relating_obj,
related_obj=obj, related_obj=obj,
) )
tool.Aggregate.constrain_parts_to_aggregate(relating_obj) tool.Aggregate.constrain_part_to_aggregate(obj, relating_obj)
props = context.scene.BIMAggregateProperties props = context.scene.BIMAggregateProperties
if relating_obj == props.editing_aggregate and props.in_aggregate_mode: if relating_obj == props.editing_aggregate and props.in_aggregate_mode:
new_editing_obj = props.editing_objects.add() new_editing_obj = props.editing_objects.add()
@@ -185,7 +185,7 @@ class BIM_OT_add_aggregate(bpy.types.Operator, tool.Ifc.Operator):
element_obj=aggregate, element_obj=aggregate,
) )
core.assign_object(tool.Ifc, tool.Aggregate, tool.Collector, relating_obj=aggregate, related_obj=obj) core.assign_object(tool.Ifc, tool.Aggregate, tool.Collector, relating_obj=aggregate, related_obj=obj)
tool.Aggregate.constrain_parts_to_aggregate(aggregate) tool.Aggregate.constrain_all_parts_to_aggregate(aggregate)
def create_aggregate(self, context, ifc_class, aggregate_name): def create_aggregate(self, context, ifc_class, aggregate_name):
aggregate = bpy.data.objects.new(aggregate_name, None) aggregate = bpy.data.objects.new(aggregate_name, None)
@@ -424,13 +424,17 @@ class BIM_OT_aggregate_assing_new_objects_in_aggregate_mode(bpy.types.Operator):
new_objs = [o for o in new_objs if o.data] new_objs = [o for o in new_objs if o.data]
for obj in new_objs: for obj in new_objs:
element = tool.Ifc.get_entity(obj) element = tool.Ifc.get_entity(obj)
if (aggregate := ifcopenshell.util.element.get_aggregate(element)) == tool.Ifc.get_entity(props.editing_aggregate):
continue
if element and element.is_a("IfcElement"): if element and element.is_a("IfcElement"):
obj.select_set(True) obj.select_set(True)
editing_obj = props.editing_objects.add() editing_obj = props.editing_objects.add()
editing_obj.obj = obj editing_obj.obj = obj
props.editing_aggregate.select_set(True) props.editing_aggregate.select_set(True)
context.view_layer.objects.active = new_objs[0]
self.relating_object = tool.Ifc.get_entity(props.editing_aggregate).id() self.relating_object = tool.Ifc.get_entity(props.editing_aggregate).id()
self.related_object = tool.Ifc.get_entity(obj).id() self.related_object = tool.Ifc.get_entity(obj).id()
BIM_OT_aggregate_assign_object._execute(self, context) BIM_OT_aggregate_assign_object._execute(self, context)
return {"FINISHED"} return {"FINISHED"}
+1 -1
View File
@@ -85,7 +85,7 @@ class Aggregate(bonsai.core.tool.Aggregate):
return parts return parts
@classmethod @classmethod
def constrain_parts_to_aggregate(cls, aggregate: bpy.types.Object): def constrain_all_parts_to_aggregate(cls, aggregate: bpy.types.Object):
agg_element = tool.Ifc.get_entity(aggregate) agg_element = tool.Ifc.get_entity(aggregate)
parts = ifcopenshell.util.element.get_parts(agg_element) parts = ifcopenshell.util.element.get_parts(agg_element)
parts_objs = [tool.Ifc.get_object(p) for p in parts] parts_objs = [tool.Ifc.get_object(p) for p in parts]