forked from youen/assembly_handbook
fixed multiple issues
- fixed very slow page refresh (related to part center query from cosmetic 3D vertex) - fixed bug when annotating a view that has an invalid part reference - using scale 1.0 for arrow ends (instead of 4.0)
This commit is contained in:
parent
e1e4cd743e
commit
007e652567
@ -31,9 +31,13 @@ class AHB_View_Annotate:
|
||||
for balloon in page.Views:
|
||||
if balloon.TypeId == 'TechDraw::DrawViewBalloon' and "Assembly_handbook_Source" in balloon.PropertiesList:
|
||||
if balloon.SourceView != view: continue
|
||||
partLink = balloon.Assembly_handbook_Source[0] if balloon.Assembly_handbook_Source is not None else None
|
||||
partLink = workbench.techDrawExtensions.getBalloonSourcePart(balloon)
|
||||
if partLink is None or partLink not in view.XSource:
|
||||
ref_name = balloon.Assembly_handbook_Source[1] if balloon.Assembly_handbook_Source is not None else "<no ref>"
|
||||
ref_name = "<no ref>"
|
||||
try:
|
||||
ref_name = balloon.Assembly_handbook_Source[1]
|
||||
except:
|
||||
pass
|
||||
print(balloon.Name + " references missing object " + ref_name + ", removing balloon")
|
||||
doc.removeObject(balloon.Name)
|
||||
|
||||
@ -42,7 +46,7 @@ class AHB_View_Annotate:
|
||||
|
||||
# Search an existing balloon to update
|
||||
for obj in page.Views:
|
||||
if obj.TypeId == 'TechDraw::DrawViewBalloon' and "Assembly_handbook_Source" in obj.PropertiesList and obj.Assembly_handbook_Source[0] == partLink:
|
||||
if obj.TypeId == 'TechDraw::DrawViewBalloon' and workbench.techDrawExtensions.getBalloonSourcePart(obj) == partLink:
|
||||
if obj.SourceView != view: continue
|
||||
balloon = obj
|
||||
|
||||
|
@ -9,11 +9,11 @@ class PartCachedView:
|
||||
self.obj_name = obj.Name
|
||||
self.cached_lines = None
|
||||
|
||||
def render(self):
|
||||
def render(self, in_doc):
|
||||
import numpy as np
|
||||
import os
|
||||
|
||||
print("Rendering " + self.obj_name + " in cache")
|
||||
print("Rendering " + self.doc_name + "#" + self.obj_name + " in cache")
|
||||
|
||||
workbench = Gui.getWorkbench("AssemblyHandbookWorkbench") #: :type workbench: AssemblyHandbookWorkbench
|
||||
|
||||
@ -21,14 +21,14 @@ class PartCachedView:
|
||||
obj = doc.getObject(self.obj_name) #: :type obj: App.DocumentObject
|
||||
|
||||
# create temporary view
|
||||
page = doc.addObject('TechDraw::DrawPage', 'TmpPage')
|
||||
page = in_doc.addObject('TechDraw::DrawPage', 'TmpPage')
|
||||
if not page.KeepUpdated: page.KeepUpdated = True
|
||||
template = doc.addObject('TechDraw::DrawSVGTemplate', 'Template')
|
||||
template = in_doc.addObject('TechDraw::DrawSVGTemplate', 'Template')
|
||||
import ahb_locator
|
||||
template.Template = os.path.join(os.path.dirname(ahb_locator.__file__), "resources/A4_Landscape_blank.svg")
|
||||
page.Template = template
|
||||
|
||||
tmpView = doc.addObject('TechDraw::DrawViewPart', 'TmpView')
|
||||
tmpView = in_doc.addObject('TechDraw::DrawViewPart', 'TmpView')
|
||||
tmpView.ViewObject.Visibility = False
|
||||
tmpView.Direction = self.direction
|
||||
tmpView.XDirection = self.x_direction
|
||||
@ -64,16 +64,20 @@ class PartCachedView:
|
||||
lineIdx = lineIdx + 1
|
||||
|
||||
# delete temporary view
|
||||
doc.removeObject(page.Name)
|
||||
in_doc.removeObject(page.Name)
|
||||
|
||||
class PartsCache:
|
||||
part_views = {}
|
||||
|
||||
def getPart2DView(self, view, obj):
|
||||
key = (view.Direction.x, view.Direction.y, view.Direction.z, view.XDirection.x, view.XDirection.y, view.XDirection.z, obj.Document.Name, obj.Name)
|
||||
object_to_render = obj
|
||||
#if 'LinkedObject' in obj.PropertiesList:
|
||||
# object_to_render = obj.LinkedObject
|
||||
obj_name = object_to_render.Document.Name + '#' + object_to_render.Name
|
||||
key = (view.Direction.x, view.Direction.y, view.Direction.z, view.XDirection.x, view.XDirection.y, view.XDirection.z, obj_name)
|
||||
part_view = self.part_views.get(key, None)
|
||||
if part_view is None:
|
||||
part_view = PartCachedView(view.Direction, view.XDirection, obj)
|
||||
part_view.render()
|
||||
part_view = PartCachedView(view.Direction, view.XDirection, object_to_render)
|
||||
part_view.render(obj.Document)
|
||||
self.part_views[key] = part_view
|
||||
return part_view
|
||||
return part_view
|
||||
|
@ -56,7 +56,10 @@ class CursorItem(QtGui.QGraphicsItem):
|
||||
|
||||
class ViewCache:
|
||||
def __init__(self):
|
||||
self.projected_points = {} # maps 3D vectors to their 2D projection
|
||||
self.reset()
|
||||
|
||||
def reset(self):
|
||||
self.projected_origin = None
|
||||
|
||||
class TechDrawExtensions:
|
||||
views_to_repaint = {}
|
||||
@ -91,6 +94,9 @@ class TechDrawExtensions:
|
||||
for view in to_repaint:
|
||||
#print("Repainting " + view.Name)
|
||||
|
||||
view_cache = self.getViewCache(view)
|
||||
view_cache.reset()
|
||||
|
||||
doc = view.Document
|
||||
|
||||
selected_balloons = []
|
||||
@ -339,7 +345,7 @@ class TechDrawExtensions:
|
||||
balloon.ViewObject.Font = 'DejaVu Sans'
|
||||
balloon.ViewObject.Fontsize = 4
|
||||
balloon.BubbleShape = 'Inspection'
|
||||
balloon.EndTypeScale = 4
|
||||
balloon.EndTypeScale = 1
|
||||
|
||||
def getBalloonSourcePart(self, balloon):
|
||||
try:
|
||||
@ -438,7 +444,7 @@ class TechDrawExtensions:
|
||||
else:
|
||||
objectCenterWorld = obj.Shape.CenterOfGravity
|
||||
|
||||
view_cache = self.getViewCache(view)
|
||||
'''view_cache = self.getViewCache(view)
|
||||
|
||||
key = (objectCenterWorld.x, objectCenterWorld.y, objectCenterWorld.z)
|
||||
projected_point = view_cache.projected_points.get(key, None)
|
||||
@ -451,7 +457,20 @@ class TechDrawExtensions:
|
||||
view.removeCosmeticVertex(vertId)
|
||||
view_cache.projected_points[key] = projected_point
|
||||
|
||||
return projected_point
|
||||
return projected_point'''
|
||||
return self.projectPoint(view, objectCenterWorld)
|
||||
|
||||
def projectPoint(self, view, point3d):
|
||||
# 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)
|
||||
if view_cache.projected_origin is None:
|
||||
vertId = view.makeCosmeticVertex3d(App.Vector(0,0,0))
|
||||
vert = view.getCosmeticVertex(vertId)
|
||||
view_cache.projected_origin = vert.Point
|
||||
view.removeCosmeticVertex(vertId)
|
||||
|
||||
YDirection = view.Direction.cross(view.XDirection)
|
||||
return App.Vector(view.XDirection.dot(point3d) + view_cache.projected_origin.x, YDirection.dot(point3d) + view_cache.projected_origin.y, 0)
|
||||
|
||||
def getViewCache(self, view):
|
||||
cache = self.view_cache.get(view, None)
|
||||
|
Loading…
Reference in New Issue
Block a user