From 5f2bfc1f6f48ae1ffd6bf9f703a301d51cc6204c Mon Sep 17 00:00:00 2001 From: Youen Date: Sun, 16 Oct 2022 16:07:29 +0200 Subject: [PATCH] Added button to redraw a page --- InitGui.py | 3 +++ ahb_cmd_new_step.py | 7 ++----- ahb_cmd_view_refresh.py | 22 ++++++++++++++++++++++ ahb_techdraw_extensions.py | 20 ++++++++++++++++++++ 4 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 ahb_cmd_view_refresh.py diff --git a/InitGui.py b/InitGui.py index 6ad8f19..9a7eed1 100644 --- a/InitGui.py +++ b/InitGui.py @@ -110,6 +110,9 @@ class AssemblyHandbookWorkbench(Gui.Workbench): toolbox.append("AHB_view_edit_source_parts") toolbox.append("AHB_view_add_source_parts") toolbox.append("AHB_view_remove_source_parts") + + self.importModule('ahb_cmd_view_refresh') + toolbox.append("AHB_view_refresh") if self.dev: self.importModule('ahb_cmd_reload') diff --git a/ahb_cmd_new_step.py b/ahb_cmd_new_step.py index 5dd97ba..63dc557 100644 --- a/ahb_cmd_new_step.py +++ b/ahb_cmd_new_step.py @@ -86,11 +86,8 @@ class AHB_New_Step: obj.Assembly_handbook_PreviousStepView = view.Name print(obj.Label + ' has been moved after the new step') - if not page.KeepUpdated and len(view.XSource) > 0: - page.KeepUpdated = True - def restoreKeepUpdated(): - page.KeepUpdated = False - QTimer.singleShot(100, restoreKeepUpdated) + if len(view.XSource) > 0: + workbench.techDrawExtensions.forceRedrawPage(page) Gui.Selection.clearSelection() Gui.Selection.addSelection(page) diff --git a/ahb_cmd_view_refresh.py b/ahb_cmd_view_refresh.py new file mode 100644 index 0000000..9f334db --- /dev/null +++ b/ahb_cmd_view_refresh.py @@ -0,0 +1,22 @@ +import FreeCADGui as Gui +import FreeCAD as App + +class AHB_RefreshView: + def GetResources(self): + return {"MenuText": "Refresh page", + "ToolTip": "Redraws the current page", + "Pixmap": "" + } + + def IsActive(self): + workbench = Gui.getWorkbench("AssemblyHandbookWorkbench") #: :type workbench: AssemblyHandbookWorkbench + return workbench.techDrawExtensions.getActivePage() is not None + + def Activated(self): + workbench = Gui.getWorkbench("AssemblyHandbookWorkbench") #: :type workbench: AssemblyHandbookWorkbench + page = workbench.techDrawExtensions.getActivePage() + if page is not None: + workbench.techDrawExtensions.forceRedrawPage(page) + +from ahb_command import AHB_CommandWrapper +AHB_CommandWrapper.addGuiCommand('AHB_view_refresh', AHB_RefreshView()) diff --git a/ahb_techdraw_extensions.py b/ahb_techdraw_extensions.py index bdb62a8..905a97d 100644 --- a/ahb_techdraw_extensions.py +++ b/ahb_techdraw_extensions.py @@ -257,6 +257,12 @@ class TechDrawExtensions: balloon.ViewObject.Fontsize = 4 balloon.BubbleShape = 'Inspection' balloon.EndTypeScale = 4 + + def getActivePage(self): + activeView = Gui.activeView() + if activeView is None: return None + activePage = activeView.getPage() if hasattr(activeView, 'getPage') else None + return activePage def getViewPage(self, view): for obj in view.InList: @@ -265,6 +271,20 @@ class TechDrawExtensions: return obj return None + def forceRedrawPage(self, page, callback = None): + if page.KeepUpdated: + for view in page.Views: + view.recompute() + if callback is not None: + callback() + else: + page.KeepUpdated = True + def restoreKeepUpdated(): + page.KeepUpdated = False + if callback is not None: + callback() + QTimer.singleShot(10, restoreKeepUpdated) + def computePartCenter(self, view, obj): if obj.TypeId == 'App::Link': partLink = obj