mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-25 17:57:02 +00:00
IFC Mesh Separate - fix bug when separating an item wouldn't change separated item
Mentioned by Ryan in #6285
This commit is contained in:
@@ -137,22 +137,36 @@ class OverrideMeshSeparate(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
item = tool.Geometry.get_active_representation(obj)
|
item = tool.Geometry.get_active_representation(obj)
|
||||||
representation_obj = tool.Geometry.get_geometry_props().representation_obj
|
representation_obj = tool.Geometry.get_geometry_props().representation_obj
|
||||||
assert item and representation_obj
|
assert item and representation_obj
|
||||||
|
assert (element := tool.Ifc.get_entity(representation_obj))
|
||||||
|
|
||||||
if tool.Geometry.is_meshlike_item(item):
|
if tool.Geometry.is_meshlike_item(item):
|
||||||
bpy.ops.mesh.separate(type=self.type)
|
bpy.ops.mesh.separate(type=self.type)
|
||||||
# Nothing got separated.
|
# Nothing got separated.
|
||||||
if len(context.selected_objects) == 1:
|
if len(context.selected_objects) == 1:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
gprops = tool.Geometry.get_geometry_props()
|
||||||
|
rep_obj = gprops.representation_obj
|
||||||
|
assert rep_obj
|
||||||
|
representation = tool.Geometry.get_active_representation(rep_obj)
|
||||||
|
assert representation
|
||||||
|
representation = ifcopenshell.util.representation.resolve_representation(representation)
|
||||||
|
representation_type: str = representation.RepresentationType
|
||||||
|
|
||||||
|
items: list[ifcopenshell.entity_instance] = list(representation.Items)
|
||||||
for obj_ in context.selected_objects:
|
for obj_ in context.selected_objects:
|
||||||
if obj_ == obj:
|
items.append(self.add_meshlike_item(obj_, representation_type))
|
||||||
continue
|
items.remove(item)
|
||||||
self.add_meshlike_item(obj_)
|
representation.Items = items
|
||||||
|
|
||||||
|
gprops.remove_item_object_by_entity(item)
|
||||||
|
tool.Geometry.remove_representation_item(item, element)
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
self.report({"INFO"}, f"Separating an {item.is_a()} is not supported")
|
self.report({"INFO"}, f"Separating an {item.is_a()} is not supported")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def add_meshlike_item(self, obj: bpy.types.Object) -> None:
|
def add_meshlike_item(self, obj: bpy.types.Object, representation_type: str) -> ifcopenshell.entity_instance:
|
||||||
props = tool.Geometry.get_geometry_props()
|
props = tool.Geometry.get_geometry_props()
|
||||||
obj.show_in_front = True
|
obj.show_in_front = True
|
||||||
tool.Geometry.lock_object(obj)
|
tool.Geometry.lock_object(obj)
|
||||||
@@ -169,11 +183,6 @@ class OverrideMeshSeparate(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
verts /= unit_scale
|
verts /= unit_scale
|
||||||
faces = [p.vertices[:] for p in obj.data.polygons]
|
faces = [p.vertices[:] for p in obj.data.polygons]
|
||||||
|
|
||||||
representation = tool.Geometry.get_active_representation(rep_obj)
|
|
||||||
assert representation
|
|
||||||
representation = ifcopenshell.util.representation.resolve_representation(representation)
|
|
||||||
|
|
||||||
representation_type = representation.RepresentationType
|
|
||||||
if representation_type in ("Brep", "AdvancedBrep"):
|
if representation_type in ("Brep", "AdvancedBrep"):
|
||||||
item = builder.faceted_brep(verts, faces)
|
item = builder.faceted_brep(verts, faces)
|
||||||
elif representation_type == "Tessellation":
|
elif representation_type == "Tessellation":
|
||||||
@@ -181,11 +190,11 @@ class OverrideMeshSeparate(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
else:
|
else:
|
||||||
assert False, f"Unexpected representation type: '{representation_type}'."
|
assert False, f"Unexpected representation type: '{representation_type}'."
|
||||||
|
|
||||||
representation.Items = list(representation.Items) + [item]
|
|
||||||
obj.name = obj.data.name = f"Item/{item.is_a()}/{item.id()}"
|
obj.name = obj.data.name = f"Item/{item.is_a()}/{item.id()}"
|
||||||
tool.Ifc.link(item, obj)
|
tool.Ifc.link(item, obj)
|
||||||
tool.Ifc.link(item, obj.data)
|
tool.Ifc.link(item, obj.data)
|
||||||
props.add_item_object(obj, item)
|
props.add_item_object(obj, item)
|
||||||
|
return item
|
||||||
|
|
||||||
def separate_element(
|
def separate_element(
|
||||||
self, context: bpy.types.Context, element: ifcopenshell.entity_instance, obj: bpy.types.Object
|
self, context: bpy.types.Context, element: ifcopenshell.entity_instance, obj: bpy.types.Object
|
||||||
|
|||||||
@@ -304,6 +304,14 @@ class BIMGeometryProperties(PropertyGroup):
|
|||||||
blender_item.name = name
|
blender_item.name = name
|
||||||
return blender_item
|
return blender_item
|
||||||
|
|
||||||
|
def remove_item_object_by_entity(self, item: ifcopenshell.entity_instance) -> None:
|
||||||
|
ifc_id = item.id()
|
||||||
|
for i, item_obj in enumerate(self.item_objs):
|
||||||
|
if item_obj.ifc_definition_id == ifc_id:
|
||||||
|
self.item_objs.remove(i)
|
||||||
|
return
|
||||||
|
assert False
|
||||||
|
|
||||||
def is_object_valid_for_representation_copy(self, obj: bpy.types.Object) -> bool:
|
def is_object_valid_for_representation_copy(self, obj: bpy.types.Object) -> bool:
|
||||||
return bool(obj != bpy.context.active_object and obj.data)
|
return bool(obj != bpy.context.active_object and obj.data)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user