forked from youen/assembly_handbook
Added code to initialize pages when loading a document (fix for balloons visibility and image file path)
This commit is contained in:
parent
f62ab9eb70
commit
13ff11293a
@ -43,12 +43,29 @@ class DocLinkObserver:
|
|||||||
class DocObserver:
|
class DocObserver:
|
||||||
changed_object_by_type = {}
|
changed_object_by_type = {}
|
||||||
selection_by_type = {}
|
selection_by_type = {}
|
||||||
|
doc_callbacks = {}
|
||||||
|
|
||||||
was_selected = []
|
was_selected = []
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Gui.Selection.addObserver(self)
|
Gui.Selection.addObserver(self)
|
||||||
|
|
||||||
|
def slotActivateDocument(self, doc):
|
||||||
|
#print('slotActivateDocument', doc.Name)
|
||||||
|
self._triggerDocumentEvent(doc, 'activate')
|
||||||
|
|
||||||
|
def slotCreatedDocument(self, doc):
|
||||||
|
#print('slotCreatedDocument', doc.Name)
|
||||||
|
self._triggerDocumentEvent(doc, 'created')
|
||||||
|
|
||||||
|
def slotDeletedDocument(self, doc):
|
||||||
|
#print('slotDeletedDocument', doc.Name)
|
||||||
|
self._triggerDocumentEvent(doc, 'deleted')
|
||||||
|
|
||||||
|
def _triggerDocumentEvent(self, doc, event):
|
||||||
|
for callback in self.doc_callbacks.values():
|
||||||
|
callback(doc, event)
|
||||||
|
|
||||||
def slotChangedObject(self, obj, prop):
|
def slotChangedObject(self, obj, prop):
|
||||||
#print("object changed: " + str(obj).replace('<', '').replace(' object>', '') + " " + obj.Name + " : " + str(prop))
|
#print("object changed: " + str(obj).replace('<', '').replace(' object>', '') + " " + obj.Name + " : " + str(prop))
|
||||||
callbacks = self.changed_object_by_type.get(obj.TypeId, None)
|
callbacks = self.changed_object_by_type.get(obj.TypeId, None)
|
||||||
@ -95,3 +112,6 @@ class DocObserver:
|
|||||||
callbacks = {}
|
callbacks = {}
|
||||||
self.selection_by_type[type_id] = callbacks
|
self.selection_by_type[type_id] = callbacks
|
||||||
callbacks[callback_id] = callback
|
callbacks[callback_id] = callback
|
||||||
|
|
||||||
|
def onDocumentEvent(self, callback_id: str, callback):
|
||||||
|
self.doc_callbacks[callback_id] = callback
|
||||||
|
@ -207,7 +207,7 @@ class RasterView:
|
|||||||
self.image_view.Assembly_handbook_ViewVolumeHeight = viewVolume.getHeight()
|
self.image_view.Assembly_handbook_ViewVolumeHeight = viewVolume.getHeight()
|
||||||
self.image_view.Assembly_handbook_ViewVolumeDepth = viewVolume.getDepth()
|
self.image_view.Assembly_handbook_ViewVolumeDepth = viewVolume.getDepth()
|
||||||
|
|
||||||
max_res = 3200 # todo: keep aspect ratio when we limit max image dimensions
|
max_res = 3200
|
||||||
#max_res = 1500
|
#max_res = 1500
|
||||||
resolution = [
|
resolution = [
|
||||||
int(viewVolume.getWidth() * view.Scale * 10),
|
int(viewVolume.getWidth() * view.Scale * 10),
|
||||||
@ -291,7 +291,7 @@ class RasterView:
|
|||||||
image.Scale = image_scale
|
image.Scale = image_scale
|
||||||
image.X = view.X
|
image.X = view.X
|
||||||
image.Y = view.Y
|
image.Y = view.Y
|
||||||
image.ImageFile = self.image_file_name # TODO: see if it's possible to set a relative path
|
image.ImageFile = self.image_file_name
|
||||||
image.ViewObject.Crop = True
|
image.ViewObject.Crop = True
|
||||||
image.Width = composite_img.size[0] * image_scale / 10.0 * 1.01
|
image.Width = composite_img.size[0] * image_scale / 10.0 * 1.01
|
||||||
image.Height = composite_img.size[1] * image_scale / 10.0 * 1.01
|
image.Height = composite_img.size[1] * image_scale / 10.0 * 1.01
|
||||||
|
@ -77,10 +77,16 @@ class TechDrawExtensions:
|
|||||||
|
|
||||||
enable_selected_part_highlight = False # disable for now, for performance reasons
|
enable_selected_part_highlight = False # disable for now, for performance reasons
|
||||||
|
|
||||||
|
initialized_documents = []
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
workbench = Gui.getWorkbench("AssemblyHandbookWorkbench") #: :type workbench: AssemblyHandbookWorkbench
|
workbench = Gui.getWorkbench("AssemblyHandbookWorkbench") #: :type workbench: AssemblyHandbookWorkbench
|
||||||
workbench.docObserver.onObjectTypeChanged('balloon_changed', 'TechDraw::DrawViewBalloon', lambda obj, prop: self.onBalloonChanged(obj, prop))
|
workbench.docObserver.onObjectTypeChanged('balloon_changed', 'TechDraw::DrawViewBalloon', lambda obj, prop: self.onBalloonChanged(obj, prop))
|
||||||
workbench.docObserver.onObjectTypeSelected('balloon_selected', 'TechDraw::DrawViewBalloon', lambda operation, obj, sub, point: self.onBalloonSelected(operation, obj, sub, point))
|
workbench.docObserver.onObjectTypeSelected('balloon_selected', 'TechDraw::DrawViewBalloon', lambda operation, obj, sub, point: self.onBalloonSelected(operation, obj, sub, point))
|
||||||
|
workbench.docObserver.onDocumentEvent('techdrawext_doc_event', lambda doc, event: self.onDocumentEvent(doc, event))
|
||||||
|
|
||||||
|
if App.ActiveDocument is not None:
|
||||||
|
self.onDocumentEvent(App.ActiveDocument, 'activate')
|
||||||
|
|
||||||
def repaint(self, view, fast_render = True):
|
def repaint(self, view, fast_render = True):
|
||||||
self.views_to_repaint[view] = fast_render
|
self.views_to_repaint[view] = fast_render
|
||||||
@ -646,7 +652,19 @@ class TechDrawExtensions:
|
|||||||
QTimer.singleShot(10, restoreKeepUpdated)
|
QTimer.singleShot(10, restoreKeepUpdated)
|
||||||
|
|
||||||
def refreshOverlays(self, page, callback = None):
|
def refreshOverlays(self, page, callback = None):
|
||||||
|
import os
|
||||||
|
|
||||||
|
doc = page.Document
|
||||||
|
for image in page.Views:
|
||||||
|
if image.TypeId == 'TechDraw::DrawViewImage':
|
||||||
|
folder_name = '/' + os.path.basename(doc.FileName).replace('.FCStd', '') + '_raster/'
|
||||||
|
if folder_name in image.ImageFile:
|
||||||
|
full_path = doc.FileName.replace('.FCStd', '') + '_raster/' + image.ImageFile.split(folder_name)[1]
|
||||||
|
if image.ImageFile != full_path:
|
||||||
|
image.ImageFile = full_path
|
||||||
|
|
||||||
if page.KeepUpdated:
|
if page.KeepUpdated:
|
||||||
|
if callback:
|
||||||
callback()
|
callback()
|
||||||
else:
|
else:
|
||||||
page.KeepUpdated = True
|
page.KeepUpdated = True
|
||||||
@ -772,3 +790,26 @@ class TechDrawExtensions:
|
|||||||
cache = ViewCache()
|
cache = ViewCache()
|
||||||
self.view_cache[view] = cache
|
self.view_cache[view] = cache
|
||||||
return cache
|
return cache
|
||||||
|
|
||||||
|
def onDocumentEvent(self, doc, event):
|
||||||
|
if event == 'activate':
|
||||||
|
if doc not in self.initialized_documents:
|
||||||
|
self.initialized_documents.append(doc)
|
||||||
|
self.initializeDocument(doc)
|
||||||
|
elif event == 'deleted':
|
||||||
|
if doc in self.initialized_documents:
|
||||||
|
self.initialized_documents.remove(doc)
|
||||||
|
|
||||||
|
def initializeDocument(self, doc):
|
||||||
|
def doInit():
|
||||||
|
try:
|
||||||
|
for obj in doc.Objects:
|
||||||
|
if obj.TypeId == 'TechDraw::DrawPage':
|
||||||
|
self.onPageLoaded(obj)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
QTimer.singleShot(0, doInit)
|
||||||
|
|
||||||
|
def onPageLoaded(self, page):
|
||||||
|
self.refreshOverlays(page)
|
||||||
|
Loading…
Reference in New Issue
Block a user