From b8f1e40de35e63f2374b5ef5e3505d33dee4660c Mon Sep 17 00:00:00 2001 From: Youen Date: Sat, 31 Dec 2022 16:52:40 +0100 Subject: [PATCH] Added code to work arround TechDraw bugs when using the "annotate view" button --- ahb_cmd_view_annotate.py | 12 +++++++++++- ahb_techdraw_extensions.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/ahb_cmd_view_annotate.py b/ahb_cmd_view_annotate.py index e739db0..bc63c3d 100644 --- a/ahb_cmd_view_annotate.py +++ b/ahb_cmd_view_annotate.py @@ -14,11 +14,19 @@ class AHB_View_Annotate: def Activated(self): workbench = Gui.getWorkbench("AssemblyHandbookWorkbench") #: :type workbench: AssemblyHandbookWorkbench + if len(Gui.Selection.getSelection()) == 0: + page = workbench.techDrawExtensions.getActivePage() + workbench.techDrawExtensions.refreshOverlays(page) + return + if len(Gui.Selection.getSelection()) != 1: raise Exception("Please select exactly one TechDraw view") view = Gui.Selection.getSelection()[0] - if view.TypeId != 'TechDraw::DrawViewPart': + if view.TypeId == 'TechDraw::DrawPage': + workbench.techDrawExtensions.refreshOverlays(view) + return + elif view.TypeId != 'TechDraw::DrawViewPart': raise Exception("Selected object is not a TechDraw view") overlay_view = workbench.techDrawExtensions.getOverlayView(view) @@ -60,6 +68,8 @@ class AHB_View_Annotate: for partLink in view.XSource: workbench.techDrawExtensions.add_or_update_balloon(view, partLink, '') + + workbench.techDrawExtensions.refreshOverlays(page) from ahb_command import AHB_CommandWrapper AHB_CommandWrapper.addGuiCommand('AHB_view_annotate', AHB_View_Annotate()) diff --git a/ahb_techdraw_extensions.py b/ahb_techdraw_extensions.py index f70a10b..a6ada90 100644 --- a/ahb_techdraw_extensions.py +++ b/ahb_techdraw_extensions.py @@ -640,6 +640,44 @@ class TechDrawExtensions: if callback is not None: callback() QTimer.singleShot(10, restoreKeepUpdated) + + def refreshOverlays(self, page, callback = None): + if page.KeepUpdated: + callback() + else: + page.KeepUpdated = True + def restoreKeepUpdated(): + for view in page.Views: + if view.TypeId == 'TechDraw::DrawViewPart': + if view.Name.endswith('_overlay'): + view.touch() + view.recompute() + for sub_view in page.Views: + try: + if sub_view.SourceView == view: + sub_view.recompute() + except: + pass + page.KeepUpdated = False + + for view in page.Views: + if view.TypeId == 'TechDraw::DrawViewBalloon': + if view.ViewObject.Visibility: + # workaround for a TechDraw bug: sometimes the balloon should be visible but doesn't appear, showing it again fixes the issue + view.ViewObject.Visibility = False + def makeRedrawCallback(view): + def redrawBalloon(): + view.ViewObject.Visibility = True + return redrawBalloon + QTimer.singleShot(0, makeRedrawCallback(view)) + else: + # workaround for a TechDraw bug: sometimes the balloon text is visible even if the balloon is hidden, hiding it again fixes the issue + view.ViewObject.Visibility = True + view.ViewObject.Visibility = False + + if callback is not None: + callback() + QTimer.singleShot(10, restoreKeepUpdated) def getSourceView(self, view): if view.Name.endswith('_overlay'):