diff --git a/src/blenderbim/blenderbim/bim/module/ifcgit/__init__.py b/src/blenderbim/blenderbim/bim/module/ifcgit/__init__.py index 5fde698280..f40fcab3ab 100644 --- a/src/blenderbim/blenderbim/bim/module/ifcgit/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/ifcgit/__init__.py @@ -30,6 +30,7 @@ classes = ( operator.DisplayUncommitted, operator.Fetch, operator.Merge, + operator.ObjectLog, operator.Push, operator.RefreshGit, operator.SwitchRevision, @@ -38,6 +39,7 @@ classes = ( prop.IfcGitProperties, ui.IFCGIT_PT_panel, ui.COMMIT_UL_List, + ui.IFCGIT_PT_revision_inspector, ) diff --git a/src/blenderbim/blenderbim/bim/module/ifcgit/operator.py b/src/blenderbim/blenderbim/bim/module/ifcgit/operator.py index 1253c5bbf5..4f25e79b71 100644 --- a/src/blenderbim/blenderbim/bim/module/ifcgit/operator.py +++ b/src/blenderbim/blenderbim/bim/module/ifcgit/operator.py @@ -278,3 +278,26 @@ class Fetch(bpy.types.Operator): remote = repo.remotes[props.select_remote] remote.fetch() return {"FINISHED"} + + +class ObjectLog(bpy.types.Operator): + """Displays Git log of selected object""" + + bl_label = "Selected Object History" + bl_idname = "ifcgit.object_log" + bl_options = {"REGISTER"} + + @classmethod + def poll(cls, context): + if not context.active_object: + cls.poll_message_set("No Active Object") + elif not context.active_object.BIMObjectProperties.ifc_definition_id: + cls.poll_message_set("Active Object doesn't have an IFC definition") + else: + return True + + def execute(self, context): + + step_id = context.active_object.BIMObjectProperties.ifc_definition_id + core.entity_log(tool.IfcGit, tool.Ifc, step_id, self) + return {"FINISHED"} diff --git a/src/blenderbim/blenderbim/bim/module/ifcgit/ui.py b/src/blenderbim/blenderbim/bim/module/ifcgit/ui.py index e9a8ba5dd8..6a4eb7b8d6 100644 --- a/src/blenderbim/blenderbim/bim/module/ifcgit/ui.py +++ b/src/blenderbim/blenderbim/bim/module/ifcgit/ui.py @@ -202,3 +202,32 @@ class COMMIT_UL_List(bpy.types.UIList): else: layout.label(text=refs + commit.message, icon="DECORATE_ANIMATE") layout.label(text=time.strftime("%c", time.localtime(commit.committed_date))) + + +class IFCGIT_PT_revision_inspector(bpy.types.Panel): + """Tool panel to interact with revision history""" + + bl_idname = "IFCGIT_PT_revision_inspector" + bl_label = "Git History" + bl_options = {"DEFAULT_CLOSED"} + bl_space_type = "VIEW_3D" + bl_region_type = "UI" + bl_category = "BlenderBIM" + + def draw(self, context): + + if not IfcGitData.is_loaded: + IfcGitData.load() + + layout = self.layout + + if not IfcGitData.data["git_exe"]: + row = layout.row() + row.label(text="Git is not installed", icon="ERROR") + return + + row = layout.row() + row.operator( + "ifcgit.object_log", + icon="TEXT", + ) diff --git a/src/blenderbim/blenderbim/core/ifcgit.py b/src/blenderbim/blenderbim/core/ifcgit.py index 955ba064e5..945c77cb58 100644 --- a/src/blenderbim/blenderbim/core/ifcgit.py +++ b/src/blenderbim/blenderbim/core/ifcgit.py @@ -71,3 +71,10 @@ def merge_branch(ifcgit, ifc, operator): path_ifc = ifc.get_path() ifcgit.config_ifcmerge() ifcgit.execute_merge(path_ifc, operator) + + +def entity_log(ifcgit, ifc, step_id, operator): + path_ifc = ifc.get_path() + log_text = ifcgit.entity_log(path_ifc, step_id) + # ERROR is only way to display a multi-line message + operator.report({"ERROR"}, log_text) diff --git a/src/blenderbim/blenderbim/tool/ifcgit.py b/src/blenderbim/blenderbim/tool/ifcgit.py index e72d58a5b7..14ecf52002 100644 --- a/src/blenderbim/blenderbim/tool/ifcgit.py +++ b/src/blenderbim/blenderbim/tool/ifcgit.py @@ -192,7 +192,7 @@ class IfcGit: bpy.data.orphans_purge(do_recursive=True) bpy.ops.bim.load_project(filepath=path_ifc) - bpy.ops.object.select_all(action='DESELECT') + bpy.ops.object.select_all(action="DESELECT") @classmethod def branches_by_hexsha(cls, repo): @@ -312,7 +312,7 @@ class IfcGit: def colourise(cls, step_ids): area = next(area for area in bpy.context.screen.areas if area.type == "VIEW_3D") area.spaces[0].shading.color_type = "OBJECT" - bpy.ops.object.select_all(action='DESELECT') + bpy.ops.object.select_all(action="DESELECT") for obj in bpy.context.visible_objects: if not obj.BIMObjectProperties.ifc_definition_id: @@ -422,6 +422,21 @@ class IfcGit: cls.load_project(path_ifc) cls.refresh_revision_list(path_ifc) + @classmethod + def entity_log(cls, path_ifc, step_id): + """Raw git log for this entity""" + repo = IfcGitRepo.repo + if not repo: + return "No repository found :(" + relpath_ifc = os.path.relpath(path_ifc, repo.working_dir) + # regex only returns first match + query = "/^#" + str(step_id) + "[ =]/,/;/:" + relpath_ifc + try: + logtext = repo.git.log("-L", query, "-s") + except: + logtext = "No Git history found :(" + return logtext + class IfcGitRepo: repo = None