mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-11 14:22:33 +00:00
Decomposition mode now selects all children (not parenting) to move a host and all children easily
This commit is contained in:
@@ -265,10 +265,12 @@ class BimTool(WorkSpaceTool):
|
||||
row.label(text="Mode")
|
||||
row = layout.row(align=True)
|
||||
row.label(text="", icon="EVENT_ALT")
|
||||
row.label(text="Opening", icon="EVENT_O")
|
||||
row.label(text="", icon="EVENT_O")
|
||||
row.operator("bim.hotkey", text="Void").hotkey = "A_O"
|
||||
row = layout.row(align=True)
|
||||
row.label(text="", icon="EVENT_ALT")
|
||||
row.label(text="Decomposition", icon="EVENT_D")
|
||||
row.label(text="", icon="EVENT_D")
|
||||
row.operator("bim.hotkey", text="Decomposition").hotkey = "A_D"
|
||||
|
||||
|
||||
class Hotkey(bpy.types.Operator, tool.Ifc.Operator):
|
||||
@@ -401,7 +403,7 @@ class Hotkey(bpy.types.Operator, tool.Ifc.Operator):
|
||||
self.props.z = self.z
|
||||
|
||||
def hotkey_A_D(self):
|
||||
bpy.ops.bim.toggle_decomposition_parenting()
|
||||
bpy.ops.bim.select_decomposition()
|
||||
|
||||
def hotkey_A_O(self):
|
||||
if AuthoringData.data["has_visible_openings"]:
|
||||
|
||||
@@ -20,11 +20,11 @@ import bpy
|
||||
from . import ui, prop, operator
|
||||
|
||||
classes = (
|
||||
operator.AddOpening,
|
||||
operator.RemoveOpening,
|
||||
operator.AddFilling,
|
||||
operator.AddOpening,
|
||||
operator.RemoveFilling,
|
||||
operator.ToggleDecompositionParenting,
|
||||
operator.RemoveOpening,
|
||||
operator.SelectDecomposition,
|
||||
prop.VoidProperties,
|
||||
ui.BIM_PT_voids,
|
||||
ui.BIM_PT_booleans,
|
||||
|
||||
@@ -182,55 +182,18 @@ class RemoveFilling(bpy.types.Operator):
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class ToggleDecompositionParenting(bpy.types.Operator):
|
||||
bl_idname = "bim.toggle_decomposition_parenting"
|
||||
bl_label = "Toggle Decomposition Parenting"
|
||||
class SelectDecomposition(bpy.types.Operator):
|
||||
bl_idname = "bim.select_decomposition"
|
||||
bl_label = "Select Decomposition"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
obj: bpy.props.StringProperty()
|
||||
|
||||
def execute(self, context):
|
||||
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
||||
self.file = IfcStore.get_file()
|
||||
is_parenting = None
|
||||
|
||||
self.decompositions = {}
|
||||
self.load_decompositions(obj)
|
||||
|
||||
for parent, children in self.decompositions.items():
|
||||
bpy.ops.bim.dynamically_void_product(obj=parent.name)
|
||||
for child in children:
|
||||
bpy.ops.bim.dynamically_void_product(obj=child.name)
|
||||
if is_parenting is None:
|
||||
is_parenting = not bool(child.parent)
|
||||
|
||||
if is_parenting:
|
||||
child.parent = parent
|
||||
child.matrix_parent_inverse = parent.matrix_world.inverted()
|
||||
else:
|
||||
parent_matrix_world = child.matrix_world.copy()
|
||||
child.parent = None
|
||||
child.matrix_world = parent_matrix_world
|
||||
|
||||
for obj in context.selected_objects:
|
||||
element = tool.Ifc.get_entity(obj)
|
||||
if not element:
|
||||
continue
|
||||
for subelement in ifcopenshell.util.element.get_decomposition(element):
|
||||
subobj = tool.Ifc.get_object(subelement)
|
||||
if subobj:
|
||||
subobj.select_set(True)
|
||||
return {"FINISHED"}
|
||||
|
||||
def load_decompositions(self, parent_obj):
|
||||
element = self.file.by_id(parent_obj.BIMObjectProperties.ifc_definition_id)
|
||||
for rel in self.file.get_inverse(element):
|
||||
if rel.is_a("IfcRelDecomposes"):
|
||||
if rel[4] != element:
|
||||
continue
|
||||
if isinstance(rel[5], tuple):
|
||||
for related_object in rel[5]:
|
||||
self.add_decomposition(parent_obj, related_object)
|
||||
else:
|
||||
self.add_decomposition(parent_obj, rel[5])
|
||||
elif rel.is_a("IfcRelFillsElement"):
|
||||
if rel.RelatingOpeningElement != element:
|
||||
continue
|
||||
self.add_decomposition(parent_obj, rel.RelatedBuildingElement)
|
||||
|
||||
def add_decomposition(self, parent_obj, child_element):
|
||||
child_obj = IfcStore.get_element(child_element.id())
|
||||
if child_obj:
|
||||
self.decompositions.setdefault(parent_obj, []).append(child_obj)
|
||||
self.load_decompositions(child_obj)
|
||||
|
||||
Reference in New Issue
Block a user