From 4efe780df7de57dd8d107823c757788e3ccf4beb Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Wed, 5 Jul 2023 17:39:43 +1000 Subject: [PATCH] Fix #3356. Include version info in status bar for debugging and new copy debug info button to help bugreporting. --- src/blenderbim/blenderbim/bim/__init__.py | 2 + .../blenderbim/bim/module/debug/__init__.py | 1 + .../blenderbim/bim/module/debug/operator.py | 57 ++++++++++++++++++- .../blenderbim/bim/module/debug/ui.py | 3 + src/blenderbim/blenderbim/bim/ui.py | 32 ++++++++++- 5 files changed, 93 insertions(+), 2 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/__init__.py b/src/blenderbim/blenderbim/bim/__init__.py index 3db56886e0..aa3f728fdd 100644 --- a/src/blenderbim/blenderbim/bim/__init__.py +++ b/src/blenderbim/blenderbim/bim/__init__.py @@ -170,6 +170,7 @@ def register(): bpy.types.SCENE_PT_unit.append(ui.ifc_units) if hasattr(bpy.types, "UI_MT_button_context_menu"): bpy.types.UI_MT_button_context_menu.append(ui.draw_custom_context_menu) + bpy.types.STATUSBAR_HT_header.append(ui.draw_statusbar) for mod in modules.values(): mod.register() @@ -208,6 +209,7 @@ def unregister(): bpy.types.SCENE_PT_unit.remove(ui.ifc_units) if hasattr(bpy.types, "UI_MT_button_context_menu"): bpy.types.UI_MT_button_context_menu.remove(ui.draw_custom_context_menu) + bpy.types.STATUSBAR_HT_header.remove(ui.draw_statusbar) for mod in reversed(list(modules.values())): mod.unregister() diff --git a/src/blenderbim/blenderbim/bim/module/debug/__init__.py b/src/blenderbim/blenderbim/bim/module/debug/__init__.py index f81ffd3b8a..1c0de63341 100644 --- a/src/blenderbim/blenderbim/bim/module/debug/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/debug/__init__.py @@ -20,6 +20,7 @@ import bpy from . import ui, prop, operator classes = ( + operator.CopyDebugInformation, operator.CreateAllShapes, operator.CreateShapeFromStepId, operator.InspectFromObject, diff --git a/src/blenderbim/blenderbim/bim/module/debug/operator.py b/src/blenderbim/blenderbim/bim/module/debug/operator.py index d6787e5034..f2bf9a85af 100644 --- a/src/blenderbim/blenderbim/bim/module/debug/operator.py +++ b/src/blenderbim/blenderbim/bim/module/debug/operator.py @@ -20,6 +20,9 @@ import os import bpy import time import logging +import platform +import subprocess +import addon_utils import ifcopenshell import ifcopenshell.util.placement import ifcopenshell.util.representation @@ -31,6 +34,58 @@ import blenderbim.tool as tool from blenderbim.bim.ifc import IfcStore +class CopyDebugInformation(bpy.types.Operator): + bl_idname = "bim.copy_debug_information" + bl_label = "Copy Debug Information" + bl_description = "Copies debugging information to your clipboard for use in bugreports" + + def execute(self, context): + version = ".".join( + [ + str(x) + for x in [ + addon.bl_info.get("version", (-1, -1, -1)) + for addon in addon_utils.modules() + if addon.bl_info["name"] == "BlenderBIM" + ][0] + ] + ) + info = { + "os": platform.system(), + "os_version": platform.version(), + "python_version": platform.python_version(), + "architecture": platform.architecture(), + "machine": platform.machine(), + "processor": platform.processor(), + "blender_version": bpy.app.version_string, + "blenderbim_version": version, + "ifc": False, + } + + if tool.Ifc.get(): + info.update( + { + "ifc": os.path.basename(tool.Ifc.get_path()) if os.path.isfile(tool.Ifc.get_path()) else "Unsaved", + "schema": tool.Ifc.get().schema, + "preprocessor_version": tool.Ifc.get().wrapped_data.header.file_name.preprocessor_version, + "originating_system": tool.Ifc.get().wrapped_data.header.file_name.originating_system, + } + ) + + # Format it in a readable way + text = "\n".join(f"{k}: {v}" for k, v in info.items()) + print(text) + + if platform.system() == "Windows": + command = "echo | set /p nul=" + text.strip() + elif platform.system() == "Darwin": # for MacOS + command = 'printf "' + text.strip().replace("\n", "\\n").replace('"', "") + '" | pbcopy' + else: # Linux + command = 'printf "' + text.strip().replace("\n", "\\n").replace('"', "") + '" | xclip -selection clipboard' + subprocess.run(command, shell=True, check=True) + return {"FINISHED"} + + class PrintIfcFile(bpy.types.Operator): bl_idname = "bim.print_ifc_file" bl_label = "Print IFC File" @@ -73,7 +128,7 @@ class ConvertToBlender(bpy.types.Operator): def execute(self, context): for o in bpy.data.objects: - if o.type in {'MESH', 'EMPTY'}: + if o.type in {"MESH", "EMPTY"}: o.BIMObjectProperties.ifc_definition_id = 0 if o.data: o.data.BIMMeshProperties.ifc_definition_id = 0 diff --git a/src/blenderbim/blenderbim/bim/module/debug/ui.py b/src/blenderbim/blenderbim/bim/module/debug/ui.py index 8b0f8ca860..7e06e2fb19 100644 --- a/src/blenderbim/blenderbim/bim/module/debug/ui.py +++ b/src/blenderbim/blenderbim/bim/module/debug/ui.py @@ -48,6 +48,9 @@ class BIM_PT_debug(Panel): row = layout.row() row.operator("bim.print_ifc_file") + row = layout.row() + row.operator("bim.copy_debug_information") + row = layout.row() row.operator("bim.purge_hdf5_cache") diff --git a/src/blenderbim/blenderbim/bim/ui.py b/src/blenderbim/blenderbim/bim/ui.py index df9c0940b8..4d8ab1120a 100644 --- a/src/blenderbim/blenderbim/bim/ui.py +++ b/src/blenderbim/blenderbim/bim/ui.py @@ -17,8 +17,9 @@ # along with BlenderBIM Add-on. If not, see . import os -from pathlib import Path import bpy +import addon_utils +from pathlib import Path from bpy.types import Panel from bpy.props import StringProperty, IntProperty, BoolProperty from ifcopenshell.util.doc import ( @@ -486,6 +487,35 @@ class BIM_PT_misc_object(Panel): pass +class UIData: + data = {} + is_loaded = False + + @classmethod + def load(cls): + cls.data = { "version": cls.version() } + cls.is_loaded = True + + @classmethod + def version(cls): + return ".".join( + [ + str(x) + for x in [ + addon.bl_info.get("version", (-1, -1, -1)) + for addon in addon_utils.modules() + if addon.bl_info["name"] == "BlenderBIM" + ][0] + ] + ) + + +def draw_statusbar(self, context): + if not UIData.is_loaded: + UIData.load() + self.layout.label(text=f"BlenderBIM Add-on v{UIData.data['version']}") + + def draw_custom_context_menu(self, context): # https://blender.stackexchange.com/a/275555/86891 if (