Browse Source

Added button to redraw a page

master
Youen 2 years ago
parent
commit
5f2bfc1f6f
  1. 3
      InitGui.py
  2. 7
      ahb_cmd_new_step.py
  3. 22
      ahb_cmd_view_refresh.py
  4. 20
      ahb_techdraw_extensions.py

3
InitGui.py

@ -110,6 +110,9 @@ class AssemblyHandbookWorkbench(Gui.Workbench):
toolbox.append("AHB_view_edit_source_parts") toolbox.append("AHB_view_edit_source_parts")
toolbox.append("AHB_view_add_source_parts") toolbox.append("AHB_view_add_source_parts")
toolbox.append("AHB_view_remove_source_parts") toolbox.append("AHB_view_remove_source_parts")
self.importModule('ahb_cmd_view_refresh')
toolbox.append("AHB_view_refresh")
if self.dev: if self.dev:
self.importModule('ahb_cmd_reload') self.importModule('ahb_cmd_reload')

7
ahb_cmd_new_step.py

@ -86,11 +86,8 @@ class AHB_New_Step:
obj.Assembly_handbook_PreviousStepView = view.Name obj.Assembly_handbook_PreviousStepView = view.Name
print(obj.Label + ' has been moved after the new step') print(obj.Label + ' has been moved after the new step')
if not page.KeepUpdated and len(view.XSource) > 0: if len(view.XSource) > 0:
page.KeepUpdated = True workbench.techDrawExtensions.forceRedrawPage(page)
def restoreKeepUpdated():
page.KeepUpdated = False
QTimer.singleShot(100, restoreKeepUpdated)
Gui.Selection.clearSelection() Gui.Selection.clearSelection()
Gui.Selection.addSelection(page) Gui.Selection.addSelection(page)

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

20
ahb_techdraw_extensions.py

@ -257,6 +257,12 @@ class TechDrawExtensions:
balloon.ViewObject.Fontsize = 4 balloon.ViewObject.Fontsize = 4
balloon.BubbleShape = 'Inspection' balloon.BubbleShape = 'Inspection'
balloon.EndTypeScale = 4 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): def getViewPage(self, view):
for obj in view.InList: for obj in view.InList:
@ -265,6 +271,20 @@ class TechDrawExtensions:
return obj return obj
return None 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): def computePartCenter(self, view, obj):
if obj.TypeId == 'App::Link': if obj.TypeId == 'App::Link':
partLink = obj partLink = obj

Loading…
Cancel
Save