Reuse tool.Ifc.Operator

This commit is contained in:
Andrej730
2024-09-06 17:45:18 +05:00
parent 871cd45f53
commit eaaa18468a
12 changed files with 30 additions and 125 deletions
@@ -391,14 +391,11 @@ class DisableEditingBoundary(bpy.types.Operator):
return {"FINISHED"}
class EditBoundaryAttributes(bpy.types.Operator):
class EditBoundaryAttributes(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.edit_boundary_attributes"
bl_label = "Disable Editing Boundary Relations"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
bprops = context.active_object.bim_boundary_properties
boundary = tool.Ifc.get_entity(context.active_object)
@@ -412,7 +409,7 @@ class EditBoundaryAttributes(bpy.types.Operator):
return {"FINISHED"}
class UpdateBoundaryGeometry(bpy.types.Operator):
class UpdateBoundaryGeometry(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.update_boundary_geometry"
bl_label = "Update Boundary Geometry"
bl_description = """
@@ -421,9 +418,6 @@ class UpdateBoundaryGeometry(bpy.types.Operator):
"""
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
tool.Boundary.move_origin_to_space_origin(context.active_object)
settings = tool.Boundary.get_assign_connection_geometry_settings(context.active_object)
@@ -77,14 +77,11 @@ class DisableEditingConstraint(bpy.types.Operator):
return {"FINISHED"}
class AddObjective(bpy.types.Operator):
class AddObjective(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.add_objective"
bl_label = "Add Objective"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
result = ifcopenshell.api.run("constraint.add_objective", IfcStore.get_file())
bpy.ops.bim.load_objectives()
@@ -92,14 +89,11 @@ class AddObjective(bpy.types.Operator):
return {"FINISHED"}
class EditObjective(bpy.types.Operator):
class EditObjective(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.edit_objective"
bl_label = "Edit Objective"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
props = context.scene.BIMConstraintProperties
attributes = {}
@@ -120,15 +114,12 @@ class EditObjective(bpy.types.Operator):
return {"FINISHED"}
class RemoveConstraint(bpy.types.Operator):
class RemoveConstraint(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.remove_constraint"
bl_label = "Remove Constraint"
bl_options = {"REGISTER", "UNDO"}
constraint: bpy.props.IntProperty()
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
props = context.scene.BIMConstraintProperties
self.file = IfcStore.get_file()
@@ -168,16 +159,13 @@ class DisableAssigningConstraint(bpy.types.Operator):
return {"FINISHED"}
class AssignConstraint(bpy.types.Operator):
class AssignConstraint(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.assign_constraint"
bl_label = "Assign Constraint"
bl_options = {"REGISTER", "UNDO"}
obj: bpy.props.StringProperty()
constraint: bpy.props.IntProperty()
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
self.file = tool.Ifc.get()
objs = [bpy.data.objects.get(self.obj)] if self.obj else context.selected_objects
@@ -194,16 +182,13 @@ class AssignConstraint(bpy.types.Operator):
return {"FINISHED"}
class UnassignConstraint(bpy.types.Operator):
class UnassignConstraint(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.unassign_constraint"
bl_label = "Unassign Constraint"
bl_options = {"REGISTER", "UNDO"}
obj: bpy.props.StringProperty()
constraint: bpy.props.IntProperty()
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
self.file = tool.Ifc.get()
objs = [bpy.data.objects.get(self.obj)] if self.obj else context.selected_objects
@@ -224,7 +224,7 @@ class CreateAllShapes(bpy.types.Operator):
return {"FINISHED"}
class CreateShapeFromStepId(bpy.types.Operator):
class CreateShapeFromStepId(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.create_shape_from_step_id"
bl_label = "Create Shape From STEP ID"
bl_description = "Recreate a mesh object from a STEP ID"
@@ -236,9 +236,6 @@ class CreateShapeFromStepId(bpy.types.Operator):
def poll(cls, context):
return IfcStore.get_file()
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
logger = logging.getLogger("ImportIFC")
self.ifc_import_settings = import_ifc.IfcImportSettings.factory(context, IfcStore.path, logger)
@@ -1233,7 +1233,7 @@ class DuplicateLinkedAggregateTo3dCursor(bpy.types.Operator):
)
class RefreshLinkedAggregate(bpy.types.Operator):
class RefreshLinkedAggregate(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.refresh_linked_aggregate"
bl_label = "IFC Refresh Linked Aggregate"
bl_options = {"REGISTER", "UNDO"}
@@ -1242,14 +1242,6 @@ class RefreshLinkedAggregate(bpy.types.Operator):
def poll(cls, context):
return len(context.selected_objects) > 0
def execute(self, context):
# Deep magick from the dawn of time
if IfcStore.get_file():
IfcStore.execute_ifc_operator(self, context)
return {"FINISHED"}
return {"FINISHED"}
def _execute(self, context):
self.new_active_obj = None
self.group_name = "BBIM_Linked_Aggregate"
@@ -1576,15 +1568,12 @@ class OverridePasteBuffer(bpy.types.Operator):
return {"FINISHED"}
class OverrideModeSetEdit(bpy.types.Operator):
class OverrideModeSetEdit(bpy.types.Operator, tool.Ifc.Operator):
bl_description = "Switch from Object mode to Edit mode"
bl_idname = "bim.override_mode_set_edit"
bl_label = "IFC Mode Set Edit"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
selected_objs = tool.Blender.get_selected_objects()
active_obj = context.active_object
@@ -1702,15 +1691,12 @@ class OverrideModeSetEdit(bpy.types.Operator):
return self.execute(context)
class OverrideModeSetObject(bpy.types.Operator):
class OverrideModeSetObject(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.override_mode_set_object"
bl_label = "IFC Mode Set Object"
bl_options = {"REGISTER", "UNDO"}
should_save: bpy.props.BoolProperty(name="Should Save", default=True)
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
if not context.active_object:
return {"FINISHED"}
+5 -20
View File
@@ -78,14 +78,11 @@ class DisableEditingLayer(bpy.types.Operator):
return {"FINISHED"}
class AddPresentationLayer(bpy.types.Operator):
class AddPresentationLayer(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.add_presentation_layer"
bl_label = "Add Layer"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
result = ifcopenshell.api.run("layer.add_layer", IfcStore.get_file())
bpy.ops.bim.load_layers()
@@ -93,14 +90,11 @@ class AddPresentationLayer(bpy.types.Operator):
return {"FINISHED"}
class EditPresentationLayer(bpy.types.Operator):
class EditPresentationLayer(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.edit_presentation_layer"
bl_label = "Edit Layer"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
props = context.scene.BIMLayerProperties
attributes = {}
@@ -117,15 +111,12 @@ class EditPresentationLayer(bpy.types.Operator):
return {"FINISHED"}
class RemovePresentationLayer(bpy.types.Operator):
class RemovePresentationLayer(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.remove_presentation_layer"
bl_label = "Remove Presentation Layer"
bl_options = {"REGISTER", "UNDO"}
layer: bpy.props.IntProperty()
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
props = context.scene.BIMLayerProperties
self.file = IfcStore.get_file()
@@ -134,7 +125,7 @@ class RemovePresentationLayer(bpy.types.Operator):
return {"FINISHED"}
class AssignPresentationLayer(bpy.types.Operator):
class AssignPresentationLayer(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.assign_presentation_layer"
bl_label = "Assign Presentation Layer"
bl_description = "Assign presentation layer to the active representation of the active object"
@@ -142,9 +133,6 @@ class AssignPresentationLayer(bpy.types.Operator):
item: bpy.props.StringProperty()
layer: bpy.props.IntProperty()
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
item = bpy.data.meshes.get(self.item) if self.item else context.active_object.data
self.file = IfcStore.get_file()
@@ -159,7 +147,7 @@ class AssignPresentationLayer(bpy.types.Operator):
return {"FINISHED"}
class UnassignPresentationLayer(bpy.types.Operator):
class UnassignPresentationLayer(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.unassign_presentation_layer"
bl_label = "Unassign Presentation Layer"
bl_description = "Unassign presentation layer from the active representation of the active object"
@@ -167,9 +155,6 @@ class UnassignPresentationLayer(bpy.types.Operator):
item: bpy.props.StringProperty()
layer: bpy.props.IntProperty()
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
item = bpy.data.meshes.get(self.item) if self.item else context.active_object.data
self.file = IfcStore.get_file()
@@ -112,7 +112,7 @@ class AddDefaultType(bpy.types.Operator, tool.Ifc.Operator):
bpy.ops.bim.add_type()
class AddConstrTypeInstance(bpy.types.Operator):
class AddConstrTypeInstance(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.add_constr_type_instance"
bl_label = "Add"
bl_options = {"REGISTER", "UNDO"}
@@ -123,9 +123,6 @@ class AddConstrTypeInstance(bpy.types.Operator):
def invoke(self, context, event):
return self.execute(context)
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
props = context.scene.BIMModelProperties
relating_type_id = self.relating_type_id or props.relating_type_id
@@ -367,7 +367,7 @@ class SaveLibraryFile(bpy.types.Operator):
return {"FINISHED"}
class AppendEntireLibrary(bpy.types.Operator):
class AppendEntireLibrary(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.append_entire_library"
bl_label = "Append Entire Library"
@@ -375,9 +375,6 @@ class AppendEntireLibrary(bpy.types.Operator):
def poll(cls, context):
return IfcStore.get_file()
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
self.file = IfcStore.get_file()
self.library = IfcStore.library_file
@@ -389,7 +386,7 @@ class AppendEntireLibrary(bpy.types.Operator):
return {"FINISHED"}
class AppendLibraryElementByQuery(bpy.types.Operator):
class AppendLibraryElementByQuery(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.append_library_element_by_query"
bl_label = "Append Library Element By Query"
query: bpy.props.StringProperty(name="Query")
@@ -398,9 +395,6 @@ class AppendLibraryElementByQuery(bpy.types.Operator):
def poll(cls, context):
return IfcStore.get_file()
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
self.file = IfcStore.get_file()
self.library = IfcStore.library_file
@@ -416,7 +410,7 @@ class AppendLibraryElementByQuery(bpy.types.Operator):
self.layout.prop(self, "query")
class AppendLibraryElement(bpy.types.Operator):
class AppendLibraryElement(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.append_library_element"
bl_label = "Append Library Element"
bl_options = {"REGISTER", "UNDO"}
@@ -431,9 +425,6 @@ class AppendLibraryElement(bpy.types.Operator):
cls.poll_message_set("Please create or load a project first.")
return poll
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
self.file = IfcStore.get_file()
element = ifcopenshell.api.run(
+3 -12
View File
@@ -305,15 +305,12 @@ class BIM_OT_clear_list(bpy.types.Operator):
return {"FINISHED"}
class BIM_OT_rename_parameters(bpy.types.Operator):
class BIM_OT_rename_parameters(bpy.types.Operator, tool.Ifc.Operator):
bl_label = "Rename Parameters"
bl_idname = "bim.rename_parameters"
bl_options = {"REGISTER", "UNDO"}
bl_description = "Rename parameters that are subclasses of IfcElement"
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
props_to_map = context.scene.RenameProperties
ifc_file = IfcStore.get_file()
@@ -342,15 +339,12 @@ class BIM_OT_rename_parameters(bpy.types.Operator):
obj_prop.Name = prop2map.new_property_name
class BIM_OT_add_edit_custom_property(bpy.types.Operator):
class BIM_OT_add_edit_custom_property(bpy.types.Operator, tool.Ifc.Operator):
bl_label = "Add or Edit a Custom Property"
bl_idname = "bim.add_edit_custom_property"
bl_options = {"REGISTER", "UNDO"}
index: bpy.props.IntProperty()
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
self.file = IfcStore.get_file()
props = context.scene.AddEditProperties
@@ -399,16 +393,13 @@ class BIM_OT_add_edit_custom_property(bpy.types.Operator):
return prop_enum_value
class BIM_OT_bulk_remove_psets(bpy.types.Operator):
class BIM_OT_bulk_remove_psets(bpy.types.Operator, tool.Ifc.Operator):
bl_label = "Bulk Remove Psets from Selected Objects"
bl_idname = "bim.bulk_remove_psets"
bl_options = {"REGISTER", "UNDO"}
bl_description = "Bulk remove psets from selected objects"
index: bpy.props.IntProperty()
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
self.file = IfcStore.get_file()
props = context.scene.DeletePsets
@@ -74,16 +74,13 @@ class DisableReassignClass(bpy.types.Operator):
return {"FINISHED"}
class ReassignClass(bpy.types.Operator):
class ReassignClass(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.reassign_class"
bl_label = "Reassign IFC Class"
bl_description = "Reassign IFC class for selected objects"
bl_options = {"REGISTER", "UNDO"}
obj: bpy.props.StringProperty()
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
if self.obj:
objects = [bpy.data.objects.get(self.obj)]
@@ -211,7 +208,7 @@ class AssignClass(bpy.types.Operator, tool.Ifc.Operator):
context.view_layer.objects.active = active_object
class UnlinkObject(bpy.types.Operator):
class UnlinkObject(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.unlink_object"
bl_label = "Unlink Object"
bl_description = (
@@ -225,9 +222,6 @@ class UnlinkObject(bpy.types.Operator):
should_delete: bpy.props.BoolProperty(name="Delete IFC Element", default=True)
skip_invoke: bpy.props.BoolProperty(default=False, options={"SKIP_SAVE"})
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
if self.obj:
objects = [bpy.data.objects.get(self.obj)]
@@ -523,7 +523,7 @@ class AssignProcess(bpy.types.Operator, tool.Ifc.Operator):
pass # TODO
class UnassignProcess(bpy.types.Operator):
class UnassignProcess(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.unassign_process"
bl_label = "Unassign Process"
bl_options = {"REGISTER", "UNDO"}
@@ -532,9 +532,6 @@ class UnassignProcess(bpy.types.Operator):
related_object: bpy.props.IntProperty()
resource: bpy.props.IntProperty()
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
if self.related_object_type == "RESOURCE":
core.unassign_resource(
@@ -877,16 +874,13 @@ class RemoveWorkTime(bpy.types.Operator, tool.Ifc.Operator):
return {"FINISHED"}
class AssignRecurrencePattern(bpy.types.Operator):
class AssignRecurrencePattern(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.assign_recurrence_pattern"
bl_label = "Assign Recurrence Pattern"
bl_options = {"REGISTER", "UNDO"}
work_time: bpy.props.IntProperty()
recurrence_type: bpy.props.StringProperty()
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
core.assign_recurrence_pattern(
tool.Ifc, work_time=tool.Ifc.get().by_id(self.work_time), recurrence_type=self.recurrence_type
@@ -894,15 +888,12 @@ class AssignRecurrencePattern(bpy.types.Operator):
return {"FINISHED"}
class UnassignRecurrencePattern(bpy.types.Operator):
class UnassignRecurrencePattern(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.unassign_recurrence_pattern"
bl_label = "Unassign Recurrence Pattern"
bl_options = {"REGISTER", "UNDO"}
recurrence_pattern: bpy.props.IntProperty()
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
core.unassign_recurrence_pattern(tool.Ifc, recurrence_pattern=tool.Ifc.get().by_id(self.recurrence_pattern))
return {"FINISHED"}
@@ -53,15 +53,12 @@ class AssignType(bpy.types.Operator, tool.Ifc.Operator):
obj.name = tool.Model.generate_occurrence_name(type, element.is_a())
class UnassignType(bpy.types.Operator):
class UnassignType(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.unassign_type"
bl_label = "Unassign Type"
bl_options = {"REGISTER", "UNDO"}
related_object: bpy.props.StringProperty()
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
def exclude_callback(attribute):
return attribute.is_a("IfcProfileDef") and attribute.ProfileName
@@ -175,16 +175,13 @@ class RemoveOpening(bpy.types.Operator, tool.Ifc.Operator):
return {"FINISHED"}
class AddFilling(bpy.types.Operator):
class AddFilling(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.add_filling"
bl_label = "Add Filling"
bl_options = {"REGISTER", "UNDO"}
opening: bpy.props.StringProperty()
obj: bpy.props.StringProperty()
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
obj = context.scene.objects.get(self.obj, context.active_object)
opening = context.scene.objects.get(self.opening, context.scene.VoidProperties.desired_opening)