Fix #2626. New IFC overrides for setting object origins.

This commit is contained in:
Dion Moult
2023-08-17 17:25:28 +10:00
parent 14bffda53c
commit 8260469c9b
3 changed files with 54 additions and 4 deletions
@@ -26,17 +26,18 @@ classes = (
operator.GetRepresentationIfcParameters, operator.GetRepresentationIfcParameters,
operator.OverrideDelete, operator.OverrideDelete,
operator.OverrideDuplicateMove, operator.OverrideDuplicateMove,
operator.OverrideDuplicateMoveAggregate,
operator.OverrideDuplicateMoveAggregateMacro,
operator.OverrideDuplicateMoveLinked, operator.OverrideDuplicateMoveLinked,
operator.OverrideDuplicateMoveLinkedMacro, operator.OverrideDuplicateMoveLinkedMacro,
operator.OverrideDuplicateMoveMacro, operator.OverrideDuplicateMoveMacro,
operator.OverrideDuplicateMoveAggregate,
operator.OverrideDuplicateMoveAggregateMacro,
operator.RefreshAggregate,
operator.OverrideJoin, operator.OverrideJoin,
operator.OverrideModeSetEdit, operator.OverrideModeSetEdit,
operator.OverrideModeSetObject, operator.OverrideModeSetObject,
operator.OverrideOriginSet,
operator.OverrideOutlinerDelete, operator.OverrideOutlinerDelete,
operator.OverridePasteBuffer, operator.OverridePasteBuffer,
operator.RefreshAggregate,
operator.RemoveConnection, operator.RemoveConnection,
operator.RemoveRepresentation, operator.RemoveRepresentation,
operator.SelectConnection, operator.SelectConnection,
@@ -50,6 +51,7 @@ classes = (
ui.BIM_PT_connections, ui.BIM_PT_connections,
ui.BIM_PT_mesh, ui.BIM_PT_mesh,
ui.BIM_PT_workarounds, ui.BIM_PT_workarounds,
ui.BIM_MT_object_set_origin,
) )
@@ -57,6 +57,31 @@ class EditObjectPlacement(bpy.types.Operator, Operator):
core.edit_object_placement(tool.Ifc, tool.Geometry, tool.Surveyor, obj=obj) core.edit_object_placement(tool.Ifc, tool.Geometry, tool.Surveyor, obj=obj)
class OverrideOriginSet(bpy.types.Operator, Operator):
bl_idname = "bim.override_origin_set"
bl_label = "IFC Origin Set"
bl_options = {"REGISTER", "UNDO"}
obj: bpy.props.StringProperty()
origin_type: bpy.props.StringProperty()
def _execute(self, context):
objs = [bpy.data.objects.get(self.obj)] if self.obj else context.selected_objects
for obj in objs:
element = tool.Ifc.get_entity(obj)
if not element:
continue
if tool.Ifc.is_moved(obj):
core.edit_object_placement(tool.Ifc, tool.Geometry, tool.Surveyor, obj=obj)
representation = tool.Geometry.get_active_representation(obj)
if not representation:
continue
representation = ifcopenshell.util.representation.resolve_representation(representation)
if not tool.Geometry.is_meshlike(representation):
continue
bpy.ops.object.origin_set(type=self.origin_type)
bpy.ops.bim.update_representation(obj=obj.name)
class AddRepresentation(bpy.types.Operator, Operator): class AddRepresentation(bpy.types.Operator, Operator):
bl_idname = "bim.add_representation" bl_idname = "bim.add_representation"
bl_label = "Add Representation" bl_label = "Add Representation"
@@ -18,7 +18,7 @@
import bpy import bpy
import blenderbim.tool as tool import blenderbim.tool as tool
from bpy.types import Panel from bpy.types import Panel, Menu
from blenderbim.bim.ifc import IfcStore from blenderbim.bim.ifc import IfcStore
from blenderbim.bim.helper import prop_with_search from blenderbim.bim.helper import prop_with_search
from blenderbim.bim.module.geometry.data import RepresentationsData, ConnectionsData, DerivedPlacementsData from blenderbim.bim.module.geometry.data import RepresentationsData, ConnectionsData, DerivedPlacementsData
@@ -29,6 +29,29 @@ def object_menu(self, context):
self.layout.operator("bim.override_object_duplicate_move", icon="PLUGIN") self.layout.operator("bim.override_object_duplicate_move", icon="PLUGIN")
self.layout.operator("bim.override_object_delete", icon="PLUGIN") self.layout.operator("bim.override_object_delete", icon="PLUGIN")
self.layout.operator("bim.override_paste_buffer", icon="PLUGIN") self.layout.operator("bim.override_paste_buffer", icon="PLUGIN")
self.layout.menu("BIM_MT_object_set_origin", icon="PLUGIN")
class BIM_MT_object_set_origin(Menu):
bl_idname = "BIM_MT_object_set_origin"
bl_label = "IFC Set Origin"
def draw(self, context):
self.layout.operator(
"bim.override_origin_set", icon="PLUGIN", text="IFC Geometry to Origin"
).origin_type = "GEOMETRY_ORIGIN"
self.layout.operator(
"bim.override_origin_set", icon="PLUGIN", text="IFC Origin to Geometry"
).origin_type = "ORIGIN_GEOMETRY"
self.layout.operator(
"bim.override_origin_set", icon="PLUGIN", text="IFC Origin to 3D Cursor"
).origin_type = "ORIGIN_CURSOR"
self.layout.operator(
"bim.override_origin_set", icon="PLUGIN", text="IFC Origin to Center of Mass (Surface)"
).origin_type = "ORIGIN_CENTER_OF_MASS"
self.layout.operator(
"bim.override_origin_set", icon="PLUGIN", text="IFC Origin to Center of Mass (Volume)"
).origin_type = "ORIGIN_CENTER_OF_VOLUME"
def outliner_menu(self, context): def outliner_menu(self, context):