From 9625200a2a24217bf4b9a4ad361434b04f423768 Mon Sep 17 00:00:00 2001 From: Gorgious56 Date: Tue, 3 Aug 2021 01:08:35 +0200 Subject: [PATCH] Improve Debug Panel UI (#1621) * Inline parameters with their respective operator * Restrict min number of polygons to 0 * Simplify high poly mesh operator execution * Clear debug attributes when purging ifc * Poll if ifc file exists in operators * Poll if ifc filepath exists before import * Delete leftover whitespaces --- .../blenderbim/bim/module/debug/operator.py | 39 +++++++++++++------ .../blenderbim/bim/module/debug/prop.py | 2 +- .../blenderbim/bim/module/debug/ui.py | 10 ++--- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/debug/operator.py b/src/blenderbim/blenderbim/bim/module/debug/operator.py index ae5b76b472..b7096f86e8 100644 --- a/src/blenderbim/blenderbim/bim/module/debug/operator.py +++ b/src/blenderbim/blenderbim/bim/module/debug/operator.py @@ -12,6 +12,10 @@ class PrintIfcFile(bpy.types.Operator): bl_idname = "bim.print_ifc_file" bl_label = "Print IFC File" + @classmethod + def poll(cls, context): + return IfcStore.get_file() + def execute(self, context): print(IfcStore.get_file().wrapped_data.to_string()) return {"FINISHED"} @@ -30,6 +34,7 @@ class PurgeIfcLinks(bpy.types.Operator): for material in bpy.data.materials: material.BIMMaterialProperties.ifc_style_id = False context.scene.BIMProperties.ifc_file = "" + context.scene.BIMDebugProperties.attributes.clear() IfcStore.purge() blenderbim.bim.handler.purge_module_data() return {"FINISHED"} @@ -39,6 +44,10 @@ class ValidateIfcFile(bpy.types.Operator): bl_idname = "bim.validate_ifc_file" bl_label = "Validate IFC File" + @classmethod + def poll(cls, context): + return IfcStore.get_file() + def execute(self, context): import ifcopenshell.validate @@ -52,6 +61,10 @@ class ProfileImportIFC(bpy.types.Operator): bl_idname = "bim.profile_import_ifc" bl_label = "Profile Import IFC" + @classmethod + def poll(cls, context): + return IfcStore.get_file() and context.scene.BIMProperties.ifc_file + def execute(self, context): import cProfile import pstats @@ -69,6 +82,10 @@ class CreateAllShapes(bpy.types.Operator): bl_idname = "bim.create_all_shapes" bl_label = "Create All Shapes" + @classmethod + def poll(cls, context): + return IfcStore.get_file() + def execute(self, context): self.file = IfcStore.get_file() elements = self.file.by_type("IfcElement") + self.file.by_type("IfcSpace") @@ -97,6 +114,10 @@ class CreateShapeFromStepId(bpy.types.Operator): bl_label = "Create Shape From STEP ID" bl_options = {"REGISTER", "UNDO"} + @classmethod + def poll(cls, context): + return IfcStore.get_file() + def execute(self, context): return IfcStore.execute_ifc_operator(self, context) @@ -122,17 +143,9 @@ class SelectHighPolygonMeshes(bpy.types.Operator): bl_options = {"REGISTER", "UNDO"} def execute(self, context): - results = {} - for obj in bpy.data.objects: - if not isinstance(obj.data, bpy.types.Mesh) or len(obj.data.polygons) < int( - context.scene.BIMDebugProperties.number_of_polygons - ): - continue - try: - obj.select_set(True) - except: - # If it is not in the view layer - pass + [o.select_set(True) for o in context.view_layer.objects + if o.type == 'MESH' + and len(o.data.polygons) > context.scene.BIMDebugProperties.number_of_polygons] return {"FINISHED"} @@ -157,6 +170,10 @@ class InspectFromStepId(bpy.types.Operator): bl_label = "Inspect From STEP ID" step_id: bpy.props.IntProperty() + @classmethod + def poll(cls, context): + return IfcStore.get_file() + def execute(self, context): self.file = IfcStore.get_file() context.scene.BIMDebugProperties.active_step_id = self.step_id diff --git a/src/blenderbim/blenderbim/bim/module/debug/prop.py b/src/blenderbim/blenderbim/bim/module/debug/prop.py index cc1ef6213c..d7b6868eeb 100644 --- a/src/blenderbim/blenderbim/bim/module/debug/prop.py +++ b/src/blenderbim/blenderbim/bim/module/debug/prop.py @@ -14,7 +14,7 @@ from bpy.props import ( class BIMDebugProperties(PropertyGroup): step_id: IntProperty(name="STEP ID") - number_of_polygons: IntProperty(name="Number of Polygons") + number_of_polygons: IntProperty(name="Number of Polygons", min=0) active_step_id: IntProperty(name="STEP ID") step_id_breadcrumb: CollectionProperty(name="STEP ID Breadcrumb", type=StrProperty) attributes: CollectionProperty(name="Attributes", type=Attribute) diff --git a/src/blenderbim/blenderbim/bim/module/debug/ui.py b/src/blenderbim/blenderbim/bim/module/debug/ui.py index 12d861df7f..5919b6058f 100644 --- a/src/blenderbim/blenderbim/bim/module/debug/ui.py +++ b/src/blenderbim/blenderbim/bim/module/debug/ui.py @@ -32,15 +32,13 @@ class BIM_PT_debug(Panel): row = layout.row() row.operator("bim.profile_import_ifc") - row = layout.row() - row.prop(props, "step_id", text="") - row = layout.row() + row = layout.split(factor=0.7, align=True) row.operator("bim.create_shape_from_step_id") + row.prop(props, "step_id", text="") - row = layout.row() - row.prop(props, "number_of_polygons", text="") - row = layout.row() + row = layout.split(factor=0.7, align=True) row.operator("bim.select_high_polygon_meshes") + row.prop(props, "number_of_polygons", text="") layout.label(text="Inspector:")