Added button to redraw a page

This commit is contained in:
Youen 2022-10-16 16:07:29 +02:00
parent 477d49e1e8
commit 5f2bfc1f6f
4 changed files with 47 additions and 5 deletions

View File

@ -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')

View File

@ -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)

22
ahb_cmd_view_refresh.py Normal file
View File

@ -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())

View File

@ -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