From 4c221b41ad06bc9326160262a97e769f5e00fc99 Mon Sep 17 00:00:00 2001 From: Gorgious56 Date: Thu, 17 Aug 2023 16:26:21 +0200 Subject: [PATCH] You can now purge unused profiles --- .../blenderbim/bim/module/profile/__init__.py | 1 + .../blenderbim/bim/module/profile/operator.py | 12 +++++++ .../blenderbim/bim/module/profile/ui.py | 31 ++++++++++--------- .../blenderbim/bim/module/project/__init__.py | 1 + .../blenderbim/bim/module/project/ui.py | 13 ++++++++ src/blenderbim/blenderbim/core/profile.py | 25 +++++++++++++++ 6 files changed, 69 insertions(+), 14 deletions(-) create mode 100644 src/blenderbim/blenderbim/core/profile.py diff --git a/src/blenderbim/blenderbim/bim/module/profile/__init__.py b/src/blenderbim/blenderbim/bim/module/profile/__init__.py index 9c697aaf60..d1ac725aeb 100644 --- a/src/blenderbim/blenderbim/bim/module/profile/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/profile/__init__.py @@ -29,6 +29,7 @@ classes = ( operator.EnableEditingArbitraryProfile, operator.EnableEditingProfile, operator.LoadProfiles, + operator.PurgeOrphanProfiles, operator.RemoveProfileDef, prop.Profile, prop.BIMProfileProperties, diff --git a/src/blenderbim/blenderbim/bim/module/profile/operator.py b/src/blenderbim/blenderbim/bim/module/profile/operator.py index e5d4d5de96..9194c895ff 100644 --- a/src/blenderbim/blenderbim/bim/module/profile/operator.py +++ b/src/blenderbim/blenderbim/bim/module/profile/operator.py @@ -21,6 +21,7 @@ import ifcopenshell.api import blenderbim.bim.helper import blenderbim.tool as tool import blenderbim.bim.module.model.profile as model_profile +import blenderbim.core.profile as core from blenderbim.bim.module.model.decorator import ProfileDecorator from blenderbim.bim.module.profile.prop import generate_thumbnail_for_active_profile from blenderbim.bim.module.profile.data import refresh @@ -213,3 +214,14 @@ class EditArbitraryProfile(bpy.types.Operator, tool.Ifc.Operator): props.active_arbitrary_profile_id = 0 model_profile.DumbProfileRegenerator().regenerate_from_profile_def(profile) + + +class PurgeOrphanProfiles(bpy.types.Operator, tool.Ifc.Operator): + bl_idname = "bim.purge_orphan_profiles" + bl_label = "Purge Orphan Profiles" + bl_options = {"REGISTER", "UNDO"} + + def _execute(self, context): + profiles_ids = [profile_prop.ifc_definition_id for profile_prop in context.scene.BIMProfileProperties.profiles] + core.purge_orphan_profiles(tool.Ifc, profiles_ids=profiles_ids) + bpy.ops.bim.load_profiles() diff --git a/src/blenderbim/blenderbim/bim/module/profile/ui.py b/src/blenderbim/blenderbim/bim/module/profile/ui.py index 29a54ab587..ca2ea03d68 100644 --- a/src/blenderbim/blenderbim/bim/module/profile/ui.py +++ b/src/blenderbim/blenderbim/bim/module/profile/ui.py @@ -79,21 +79,24 @@ class BIM_PT_profiles(Panel): self.props, "active_profile_index", ) - if active_profile and active_profile.ifc_class in ( - "IfcArbitraryClosedProfileDef", - "IfcArbitraryProfileDefWithVoids", - ): - if self.props.active_arbitrary_profile_id: - row = self.layout.row(align=True) - row.operator("bim.edit_arbitrary_profile", text="Save Arbitrary Profile", icon="CHECKMARK") - row.operator("bim.disable_editing_arbitrary_profile", text="", icon="CANCEL") - else: - row = self.layout.row() - row.operator("bim.enable_editing_arbitrary_profile", text="Edit Arbitrary Profile", icon="GREASEPENCIL") + if active_profile: + if active_profile.ifc_class in ( + "IfcArbitraryClosedProfileDef", + "IfcArbitraryProfileDefWithVoids", + ): + if self.props.active_arbitrary_profile_id: + row = self.layout.row(align=True) + row.operator("bim.edit_arbitrary_profile", text="Save Arbitrary Profile", icon="CHECKMARK") + row.operator("bim.disable_editing_arbitrary_profile", text="", icon="CANCEL") + else: + row = self.layout.row() + row.operator( + "bim.enable_editing_arbitrary_profile", text="Edit Arbitrary Profile", icon="GREASEPENCIL" + ) - profile_entity = tool.Ifc.get().by_id(active_profile.ifc_definition_id) - users_of_profile = tool.Ifc.get().get_total_inverses(profile_entity) - self.layout.label(icon="INFO", text=f"Profile has {users_of_profile} inverse relationship(s) in project") + profile_entity = tool.Ifc.get().by_id(active_profile.ifc_definition_id) + users_of_profile = tool.Ifc.get().get_total_inverses(profile_entity) + self.layout.label(icon="INFO", text=f"Profile has {users_of_profile} inverse relationship(s) in project") if self.props.active_profile_id: self.draw_editable_ui(context) diff --git a/src/blenderbim/blenderbim/bim/module/project/__init__.py b/src/blenderbim/blenderbim/bim/module/project/__init__.py index 2bd50dd132..3fe18e7f2f 100644 --- a/src/blenderbim/blenderbim/bim/module/project/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/project/__init__.py @@ -56,6 +56,7 @@ classes = ( ui.BIM_PT_project, ui.BIM_PT_project_library, ui.BIM_PT_links, + ui.BIM_PT_purge, ui.BIM_UL_library, ui.BIM_UL_filter_categories, ui.BIM_UL_links, diff --git a/src/blenderbim/blenderbim/bim/module/project/ui.py b/src/blenderbim/blenderbim/bim/module/project/ui.py index 7558fc3762..129b23cf38 100644 --- a/src/blenderbim/blenderbim/bim/module/project/ui.py +++ b/src/blenderbim/blenderbim/bim/module/project/ui.py @@ -381,3 +381,16 @@ class BIM_UL_links(UIList): op.filepath = item.name op = row.operator("bim.unlink_ifc", text="", icon="X") op.filepath = item.name + + +class BIM_PT_purge(Panel): + bl_label = "Purge Data" + bl_options = {"DEFAULT_CLOSED"} + bl_space_type = "PROPERTIES" + bl_region_type = "WINDOW" + bl_context = "scene" + bl_parent_id = "BIM_PT_tab_quality_control" + + def draw(self, context): + layout = self.layout + layout.operator("bim.purge_orphan_profiles") diff --git a/src/blenderbim/blenderbim/core/profile.py b/src/blenderbim/blenderbim/core/profile.py new file mode 100644 index 0000000000..f4f36badc8 --- /dev/null +++ b/src/blenderbim/blenderbim/core/profile.py @@ -0,0 +1,25 @@ +# BlenderBIM Add-on - OpenBIM Blender Add-on +# Copyright (C) 2023 Dion Moult +# +# This file is part of BlenderBIM Add-on. +# +# BlenderBIM Add-on is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# BlenderBIM Add-on is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with BlenderBIM Add-on. If not, see . + + +def purge_orphan_profiles(ifc, profiles_ids): + for profile_id in profiles_ids: + profile_ifc = ifc.get().by_id(profile_id) + if ifc.get().get_total_inverses(profile_ifc) > 0: + continue + ifc.run("profile.remove_profile", profile=profile_ifc)