You can now purge unused profiles

This commit is contained in:
Gorgious56
2023-08-17 16:26:21 +02:00
parent f9ee96c47e
commit 4c221b41ad
6 changed files with 69 additions and 14 deletions
@@ -29,6 +29,7 @@ classes = (
operator.EnableEditingArbitraryProfile,
operator.EnableEditingProfile,
operator.LoadProfiles,
operator.PurgeOrphanProfiles,
operator.RemoveProfileDef,
prop.Profile,
prop.BIMProfileProperties,
@@ -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()
@@ -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)
@@ -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,
@@ -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")
+25
View File
@@ -0,0 +1,25 @@
# BlenderBIM Add-on - OpenBIM Blender Add-on
# Copyright (C) 2023 Dion Moult <dion@thinkmoult.com>
#
# 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 <http://www.gnu.org/licenses/>.
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)