|
|
@ -16,6 +16,9 @@ class CursorItem(QtGui.QGraphicsItem): |
|
|
|
self.size = 100.0 |
|
|
|
self.size = 100.0 |
|
|
|
self.view = view |
|
|
|
self.view = view |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def removeSceneEventFilter(self, a, b): |
|
|
|
|
|
|
|
print('removeSceneEventFilter', a, b) |
|
|
|
|
|
|
|
|
|
|
|
def onViewPosChange(self, callback): |
|
|
|
def onViewPosChange(self, callback): |
|
|
|
self.viewPosChangeCallback = callback |
|
|
|
self.viewPosChangeCallback = callback |
|
|
|
|
|
|
|
|
|
|
@ -173,11 +176,33 @@ class TechDrawExtensions: |
|
|
|
overlay.Scale = view.Scale |
|
|
|
overlay.Scale = view.Scale |
|
|
|
overlay.ViewObject.LineWidth = 0.01 |
|
|
|
overlay.ViewObject.LineWidth = 0.01 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# migrate balloons from source view to overlay |
|
|
|
for balloon in page.Views: |
|
|
|
for balloon in page.Views: |
|
|
|
if balloon.TypeId == 'TechDraw::DrawViewBalloon' and "Assembly_handbook_Source" in balloon.PropertiesList and balloon.SourceView == view: |
|
|
|
if balloon.TypeId == 'TechDraw::DrawViewBalloon' and "Assembly_handbook_Source" in balloon.PropertiesList and balloon.SourceView == view: |
|
|
|
if balloon.SourceView == view: |
|
|
|
if balloon.SourceView == view: |
|
|
|
|
|
|
|
old_source = balloon.Assembly_handbook_Source |
|
|
|
|
|
|
|
old_OriginOffsetX = balloon.Assembly_handbook_OriginOffsetX |
|
|
|
|
|
|
|
old_OriginOffsetY = balloon.Assembly_handbook_OriginOffsetY |
|
|
|
|
|
|
|
old_X = balloon.X |
|
|
|
|
|
|
|
old_Y = balloon.Y |
|
|
|
|
|
|
|
old_Visibility = balloon.ViewObject.Visibility |
|
|
|
|
|
|
|
balloonName = balloon.Name |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
doc.removeObject(balloon.Name) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
balloon = doc.addObject("TechDraw::DrawViewBalloon", balloonName) |
|
|
|
balloon.SourceView = overlay |
|
|
|
balloon.SourceView = overlay |
|
|
|
|
|
|
|
balloon.addProperty("App::PropertyXLink", "Assembly_handbook_Source", "Assembly_handbook") |
|
|
|
|
|
|
|
balloon.Assembly_handbook_Source = old_source |
|
|
|
|
|
|
|
balloon.addProperty("App::PropertyFloat", "Assembly_handbook_OriginOffsetX", "Assembly_handbook") |
|
|
|
|
|
|
|
balloon.addProperty("App::PropertyFloat", "Assembly_handbook_OriginOffsetY", "Assembly_handbook") |
|
|
|
|
|
|
|
balloon.Assembly_handbook_OriginOffsetX = old_OriginOffsetX |
|
|
|
|
|
|
|
balloon.Assembly_handbook_OriginOffsetY = old_OriginOffsetY |
|
|
|
page.addView(balloon) |
|
|
|
page.addView(balloon) |
|
|
|
|
|
|
|
self.updateBalloon(balloon) |
|
|
|
|
|
|
|
balloon.X = old_X |
|
|
|
|
|
|
|
balloon.Y = old_Y |
|
|
|
|
|
|
|
balloon.ViewObject.Visibility = old_Visibility |
|
|
|
balloon.recompute() |
|
|
|
balloon.recompute() |
|
|
|
|
|
|
|
|
|
|
|
page.KeepUpdated = True # once we have hidden the source view, there should be no performance issue |
|
|
|
page.KeepUpdated = True # once we have hidden the source view, there should be no performance issue |
|
|
@ -293,6 +318,13 @@ class TechDrawExtensions: |
|
|
|
selected_balloons.append(obj) |
|
|
|
selected_balloons.append(obj) |
|
|
|
|
|
|
|
|
|
|
|
cursor = self.view_cursors.get(view, None) |
|
|
|
cursor = self.view_cursors.get(view, None) |
|
|
|
|
|
|
|
if cursor is not None: |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
cursor.x() # this can throw an exception if the Qt item has been deleted (for example when closing the page) |
|
|
|
|
|
|
|
except Exception as ex: |
|
|
|
|
|
|
|
print("Re-generating cursor...") |
|
|
|
|
|
|
|
cursor = None |
|
|
|
|
|
|
|
|
|
|
|
if cursor is None: |
|
|
|
if cursor is None: |
|
|
|
cursor = CursorItem(view = view) |
|
|
|
cursor = CursorItem(view = view) |
|
|
|
TDG.addQGIToView(view, cursor); |
|
|
|
TDG.addQGIToView(view, cursor); |
|
|
@ -412,7 +444,7 @@ class TechDrawExtensions: |
|
|
|
view = balloon.SourceView |
|
|
|
view = balloon.SourceView |
|
|
|
self.updateBalloonCursor(view) |
|
|
|
self.updateBalloonCursor(view) |
|
|
|
if self.enable_selected_part_highlight: |
|
|
|
if self.enable_selected_part_highlight: |
|
|
|
self.repaint(view) # disabled for now, for performance reasons |
|
|
|
self.repaint(view) |
|
|
|
|
|
|
|
|
|
|
|
def onBalloonChanged(self, obj, prop): |
|
|
|
def onBalloonChanged(self, obj, prop): |
|
|
|
# Avoid reentry |
|
|
|
# Avoid reentry |
|
|
@ -496,6 +528,10 @@ class TechDrawExtensions: |
|
|
|
needPageUpdate = False |
|
|
|
needPageUpdate = False |
|
|
|
for view in page.Views: |
|
|
|
for view in page.Views: |
|
|
|
if view.TypeId == 'TechDraw::DrawViewPart' and 'Assembly_handbook_PreviousStepView' in view.PropertiesList: |
|
|
|
if view.TypeId == 'TechDraw::DrawViewPart' and 'Assembly_handbook_PreviousStepView' in view.PropertiesList: |
|
|
|
|
|
|
|
if not 'Assembly_handbook_RasterView' in view.PropertiesList: |
|
|
|
|
|
|
|
view.addProperty("App::PropertyBool", "Assembly_handbook_RasterView", "Assembly_handbook") |
|
|
|
|
|
|
|
view.Assembly_handbook_RasterView = True |
|
|
|
|
|
|
|
|
|
|
|
if 'Assembly_handbook_RasterView' not in view.PropertiesList or not view.Assembly_handbook_RasterView: |
|
|
|
if 'Assembly_handbook_RasterView' not in view.PropertiesList or not view.Assembly_handbook_RasterView: |
|
|
|
needPageUpdate = True |
|
|
|
needPageUpdate = True |
|
|
|
self.refreshView(view) |
|
|
|
self.refreshView(view) |
|
|
@ -534,7 +570,24 @@ class TechDrawExtensions: |
|
|
|
callback() |
|
|
|
callback() |
|
|
|
QTimer.singleShot(10, restoreKeepUpdated) |
|
|
|
QTimer.singleShot(10, restoreKeepUpdated) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getSourceView(self, view): |
|
|
|
|
|
|
|
if view.Name.endswith('_overlay'): |
|
|
|
|
|
|
|
view = view.Document.getObject(view.Name[0:-8]) |
|
|
|
|
|
|
|
if view is None: |
|
|
|
|
|
|
|
raise Exception("Can't find source view of " + view.Name) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return view |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getOverlayView(self, view): |
|
|
|
|
|
|
|
if view.Name.endswith('_overlay'): |
|
|
|
|
|
|
|
return view |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
overlay = view.Document.getObject(view.Name + '_overlay') |
|
|
|
|
|
|
|
return overlay if overlay is not None else view |
|
|
|
|
|
|
|
|
|
|
|
def computePartCenter(self, view, obj): |
|
|
|
def computePartCenter(self, view, obj): |
|
|
|
|
|
|
|
view = self.getSourceView(view) |
|
|
|
|
|
|
|
|
|
|
|
if obj.TypeId == 'App::Link': |
|
|
|
if obj.TypeId == 'App::Link': |
|
|
|
partLink = obj |
|
|
|
partLink = obj |
|
|
|
objectCenterWorld = partLink.LinkPlacement.Matrix.multiply(partLink.LinkedObject.Shape.CenterOfGravity) |
|
|
|
objectCenterWorld = partLink.LinkPlacement.Matrix.multiply(partLink.LinkedObject.Shape.CenterOfGravity) |
|
|
@ -561,6 +614,12 @@ class TechDrawExtensions: |
|
|
|
return self.projectPoint(view, objectCenterWorld) |
|
|
|
return self.projectPoint(view, objectCenterWorld) |
|
|
|
|
|
|
|
|
|
|
|
def projectPoint(self, view, point3d): |
|
|
|
def projectPoint(self, view, point3d): |
|
|
|
|
|
|
|
if 'Assembly_handbook_RasterView' in view.PropertiesList or view.Assembly_handbook_RasterView: |
|
|
|
|
|
|
|
from ahb_raster_view import RasterView |
|
|
|
|
|
|
|
raster_view = RasterView(view) |
|
|
|
|
|
|
|
if raster_view.init_image_projection(): |
|
|
|
|
|
|
|
return raster_view.project3DPointToSourceView(point3d) |
|
|
|
|
|
|
|
|
|
|
|
# DrawViewPart::projectPoint should be exposed to python in freecad 0.21, but for 0.20 we have to use a workaround |
|
|
|
# DrawViewPart::projectPoint should be exposed to python in freecad 0.21, but for 0.20 we have to use a workaround |
|
|
|
view_cache = self.getViewCache(view) |
|
|
|
view_cache = self.getViewCache(view) |
|
|
|
if view_cache.projected_origin is None: |
|
|
|
if view_cache.projected_origin is None: |
|
|
|