mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 06:58:56 +00:00
Added bim.mirror_geometry() operator for truly mirroring products / types
This commit is contained in:
committed by
Ryan Schultz
parent
e52e68602d
commit
31f6be77f9
@@ -84,7 +84,6 @@ classes = (
|
|||||||
product.MirrorElements,
|
product.MirrorElements,
|
||||||
product.TrueMirrorElements,
|
product.TrueMirrorElements,
|
||||||
product.SetActiveType,
|
product.SetActiveType,
|
||||||
product.ChangeSwingDirection,
|
|
||||||
workspace.Hotkey,
|
workspace.Hotkey,
|
||||||
workspace.BIM_MT_add_representation_item,
|
workspace.BIM_MT_add_representation_item,
|
||||||
wall.AddPerpendicularWall,
|
wall.AddPerpendicularWall,
|
||||||
|
|||||||
@@ -682,11 +682,11 @@ class MirrorElements(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
|
|
||||||
obj.matrix_world = newmat
|
obj.matrix_world = newmat
|
||||||
|
|
||||||
class ChangeSwingDirection(bpy.types.Operator, tool.Ifc.Operator):
|
class TrueMirrorElements(bpy.types.Operator, tool.Ifc.Operator):
|
||||||
bl_idname = "bim.change_swing_direction"
|
bl_idname = "bim.mirror_geometry"
|
||||||
bl_label = "Change door / window swing direction"
|
bl_label = "Mirror Element Geometry"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
bl_description = "Changes the swing direction of the selection door / window"
|
bl_description = "Mirrors the selected objects by mirroring their representation (or their types representation)"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def poll(cls, context):
|
def poll(cls, context):
|
||||||
@@ -706,14 +706,11 @@ class ChangeSwingDirection(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
active_context = tool.Geometry.get_active_representation_context(obj)
|
active_context = tool.Geometry.get_active_representation_context(obj)
|
||||||
|
|
||||||
if type_element:
|
if type_element:
|
||||||
# obj has a type, try to change swing direction of type
|
# obj has a type, use / create inverted type and assign it
|
||||||
if (type_pset := ifcopenshell.util.element.get_pset(type_element, "BBIM_Door", "Data")):
|
self.assign_inverted_type(element)
|
||||||
# get or create inverted type and assign it
|
|
||||||
self.assign_inverted_door_type(element)
|
|
||||||
else:
|
else:
|
||||||
if (obj_pset := ifcopenshell.util.element.get_pset(element, "BBIM_Door", "Data", should_inherit=False)):
|
# invert representation of entity directly
|
||||||
# obj has an own geometric door representation, simply flip the door_type
|
self.invert_representation(element)
|
||||||
self.invert_door_swing(element)
|
|
||||||
|
|
||||||
# bonsai does not automatically switch to the representation that should be active in the given context
|
# bonsai does not automatically switch to the representation that should be active in the given context
|
||||||
# when switching to a type that was previously viewed in another context (e.g. plan view),
|
# when switching to a type that was previously viewed in another context (e.g. plan view),
|
||||||
@@ -728,6 +725,23 @@ class ChangeSwingDirection(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
should_sync_changes_first=False,
|
should_sync_changes_first=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def invert_general_object(self, element):
|
||||||
|
if element.is_a("IfcProduct"):
|
||||||
|
if not element.Representation:
|
||||||
|
return
|
||||||
|
|
||||||
|
for representation in element.Representation.Representations:
|
||||||
|
for item in representation.Items:
|
||||||
|
builder = ifcopenshell.util.shape_builder.ShapeBuilder(tool.Ifc.get())
|
||||||
|
builder.mirror(item, (1, 0), create_copy=False)
|
||||||
|
elif element.is_a("IfcTypeProduct"):
|
||||||
|
for representation_map in element.RepresentationMaps:
|
||||||
|
for item in representation_map.MappedRepresentation.Items:
|
||||||
|
builder = ifcopenshell.util.shape_builder.ShapeBuilder(tool.Ifc.get())
|
||||||
|
builder.mirror(item, (1, 0), create_copy=False)
|
||||||
|
|
||||||
|
tool.Geometry.reload_representation(tool.Ifc.get_object(element))
|
||||||
|
|
||||||
def invert_door_swing(self, element):
|
def invert_door_swing(self, element):
|
||||||
obj = tool.Ifc.get_object(element)
|
obj = tool.Ifc.get_object(element)
|
||||||
|
|
||||||
@@ -761,6 +775,12 @@ class ChangeSwingDirection(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
|
|
||||||
tool.Model.mark_thumbnail_for_update(element)
|
tool.Model.mark_thumbnail_for_update(element)
|
||||||
|
|
||||||
|
def invert_representation(self, element):
|
||||||
|
if ifcopenshell.util.element.get_pset(element, "BBIM_Door", "Data"):
|
||||||
|
self.invert_door_swing(element)
|
||||||
|
else:
|
||||||
|
self.invert_general_object(element)
|
||||||
|
|
||||||
def get_inverted_type(self, type_element):
|
def get_inverted_type(self, type_element):
|
||||||
inverted_pset = ifcopenshell.util.element.get_pset(type_element, "BBIM_InvertedSwingType", "Data")
|
inverted_pset = ifcopenshell.util.element.get_pset(type_element, "BBIM_InvertedSwingType", "Data")
|
||||||
if not inverted_pset:
|
if not inverted_pset:
|
||||||
@@ -778,14 +798,14 @@ class ChangeSwingDirection(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
|
|
||||||
ifcopenshell.api.pset.edit_pset(tool.Ifc.get(), inverted_pset, "BBIM_InvertedSwingType", { "Data": json.dumps({ "inverted_swing_type": inverted_type_element.id() }) })
|
ifcopenshell.api.pset.edit_pset(tool.Ifc.get(), inverted_pset, "BBIM_InvertedSwingType", { "Data": json.dumps({ "inverted_swing_type": inverted_type_element.id() }) })
|
||||||
|
|
||||||
def assign_inverted_door_type(self, element):
|
def assign_inverted_type(self, element):
|
||||||
type_element = ifcopenshell.util.element.get_type(element)
|
type_element = ifcopenshell.util.element.get_type(element)
|
||||||
|
|
||||||
inverted_type = self.get_inverted_type(type_element)
|
inverted_type = self.get_inverted_type(type_element)
|
||||||
if not inverted_type:
|
if not inverted_type:
|
||||||
old_to_new, _ = tool.Geometry.duplicate_ifc_objects([ tool.Ifc.get_object(type_element) ])
|
old_to_new, _ = tool.Geometry.duplicate_ifc_objects([ tool.Ifc.get_object(type_element) ])
|
||||||
inverted_type = old_to_new[type_element][0]
|
inverted_type = old_to_new[type_element][0]
|
||||||
self.invert_door_swing(inverted_type)
|
self.invert_representation(inverted_type)
|
||||||
self.set_inverted_type(inverted_type, type_element)
|
self.set_inverted_type(inverted_type, type_element)
|
||||||
self.set_inverted_type(type_element, inverted_type)
|
self.set_inverted_type(type_element, inverted_type)
|
||||||
|
|
||||||
|
|||||||
@@ -1307,7 +1307,7 @@ class Hotkey(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
def hotkey_S_C_F(self):
|
def hotkey_S_C_F(self):
|
||||||
if not bpy.context.selected_objects:
|
if not bpy.context.selected_objects:
|
||||||
return
|
return
|
||||||
bpy.ops.bim.change_swing_direction()
|
bpy.ops.bim.mirror_geometry()
|
||||||
|
|
||||||
def hotkey_S_G(self):
|
def hotkey_S_G(self):
|
||||||
obj = bpy.context.active_object
|
obj = bpy.context.active_object
|
||||||
|
|||||||
Reference in New Issue
Block a user