mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-23 15:16:23 +00:00
You can now toggle whether decomposed elements are parented in blender when editing, so voids/fills etc move with you.
This commit is contained in:
@@ -28,6 +28,7 @@ class BimTool(WorkSpaceTool):
|
|||||||
("bim.hotkey", {"type": "V", "value": "PRESS", "shift": True}, {"properties": [("hotkey", "S_V")]}),
|
("bim.hotkey", {"type": "V", "value": "PRESS", "shift": True}, {"properties": [("hotkey", "S_V")]}),
|
||||||
("bim.hotkey", {"type": "O", "value": "PRESS", "shift": True}, {"properties": [("hotkey", "S_O")]}),
|
("bim.hotkey", {"type": "O", "value": "PRESS", "shift": True}, {"properties": [("hotkey", "S_O")]}),
|
||||||
("bim.hotkey", {"type": "O", "value": "PRESS", "alt": True}, {"properties": [("hotkey", "A_O")]}),
|
("bim.hotkey", {"type": "O", "value": "PRESS", "alt": True}, {"properties": [("hotkey", "A_O")]}),
|
||||||
|
("bim.hotkey", {"type": "D", "value": "PRESS", "alt": True}, {"properties": [("hotkey", "A_D")]}),
|
||||||
)
|
)
|
||||||
|
|
||||||
def draw_settings(context, layout, tool):
|
def draw_settings(context, layout, tool):
|
||||||
@@ -88,6 +89,9 @@ class BimTool(WorkSpaceTool):
|
|||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
row.label(text="", icon="EVENT_ALT")
|
row.label(text="", icon="EVENT_ALT")
|
||||||
row.label(text="Opening", icon="EVENT_O")
|
row.label(text="Opening", icon="EVENT_O")
|
||||||
|
row = layout.row(align=True)
|
||||||
|
row.label(text="", icon="EVENT_ALT")
|
||||||
|
row.label(text="Decomposition", icon="EVENT_D")
|
||||||
|
|
||||||
|
|
||||||
class Hotkey(bpy.types.Operator):
|
class Hotkey(bpy.types.Operator):
|
||||||
@@ -132,5 +136,8 @@ class Hotkey(bpy.types.Operator):
|
|||||||
elif self.props.ifc_class == "IfcSlabType":
|
elif self.props.ifc_class == "IfcSlabType":
|
||||||
bpy.ops.bim.add_slab_opening()
|
bpy.ops.bim.add_slab_opening()
|
||||||
|
|
||||||
|
def hotkey_A_D(self):
|
||||||
|
bpy.ops.bim.toggle_decomposition_parenting()
|
||||||
|
|
||||||
def hotkey_A_O(self):
|
def hotkey_A_O(self):
|
||||||
bpy.ops.bim.toggle_opening_visibility()
|
bpy.ops.bim.toggle_opening_visibility()
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class BIM_PT_class(Panel):
|
|||||||
if props.is_reassigning_class:
|
if props.is_reassigning_class:
|
||||||
row = self.layout.row(align=True)
|
row = self.layout.row(align=True)
|
||||||
row.operator("bim.reassign_class", icon="CHECKMARK")
|
row.operator("bim.reassign_class", icon="CHECKMARK")
|
||||||
row.operator("bim.disable_reassign_class", icon="X", text="")
|
row.operator("bim.disable_reassign_class", icon="CANCEL", text="")
|
||||||
self.draw_class_dropdowns(context)
|
self.draw_class_dropdowns(context)
|
||||||
else:
|
else:
|
||||||
data = Data.products[props.ifc_definition_id]
|
data = Data.products[props.ifc_definition_id]
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ classes = (
|
|||||||
operator.AddFilling,
|
operator.AddFilling,
|
||||||
operator.RemoveFilling,
|
operator.RemoveFilling,
|
||||||
operator.ToggleOpeningVisibility,
|
operator.ToggleOpeningVisibility,
|
||||||
|
operator.ToggleDecompositionParenting,
|
||||||
prop.VoidProperties,
|
prop.VoidProperties,
|
||||||
ui.BIM_PT_voids,
|
ui.BIM_PT_voids,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -142,3 +142,54 @@ class ToggleOpeningVisibility(bpy.types.Operator):
|
|||||||
for collection in [c for c in project.children if "IfcOpeningElements" in c.name]:
|
for collection in [c for c in project.children if "IfcOpeningElements" in c.name]:
|
||||||
collection.hide_viewport = not collection.hide_viewport
|
collection.hide_viewport = not collection.hide_viewport
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
class ToggleDecompositionParenting(bpy.types.Operator):
|
||||||
|
bl_idname = "bim.toggle_decomposition_parenting"
|
||||||
|
bl_label = "Toggle Decomposition Parenting"
|
||||||
|
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
|
||||||
|
|
||||||
|
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 not (rel.is_a("IfcRelDecomposes") or rel.is_a("IfcRelFillsElement")):
|
||||||
|
continue
|
||||||
|
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])
|
||||||
|
|
||||||
|
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