Browse Source

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)
pull/1/head
Youen 2 years ago
parent
commit
007e652567
  1. 10
      ahb_cmd_view_annotate.py
  2. 24
      ahb_parts_cache.py
  3. 27
      ahb_techdraw_extensions.py

10
ahb_cmd_view_annotate.py

@ -31,9 +31,13 @@ class AHB_View_Annotate:
for balloon in page.Views: for balloon in page.Views:
if balloon.TypeId == 'TechDraw::DrawViewBalloon' and "Assembly_handbook_Source" in balloon.PropertiesList: if balloon.TypeId == 'TechDraw::DrawViewBalloon' and "Assembly_handbook_Source" in balloon.PropertiesList:
if balloon.SourceView != view: continue 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: 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") print(balloon.Name + " references missing object " + ref_name + ", removing balloon")
doc.removeObject(balloon.Name) doc.removeObject(balloon.Name)
@ -42,7 +46,7 @@ class AHB_View_Annotate:
# Search an existing balloon to update # Search an existing balloon to update
for obj in page.Views: 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 if obj.SourceView != view: continue
balloon = obj balloon = obj

24
ahb_parts_cache.py

@ -9,11 +9,11 @@ class PartCachedView:
self.obj_name = obj.Name self.obj_name = obj.Name
self.cached_lines = None self.cached_lines = None
def render(self): def render(self, in_doc):
import numpy as np import numpy as np
import os 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 workbench = Gui.getWorkbench("AssemblyHandbookWorkbench") #: :type workbench: AssemblyHandbookWorkbench
@ -21,14 +21,14 @@ class PartCachedView:
obj = doc.getObject(self.obj_name) #: :type obj: App.DocumentObject obj = doc.getObject(self.obj_name) #: :type obj: App.DocumentObject
# create temporary view # create temporary view
page = doc.addObject('TechDraw::DrawPage', 'TmpPage') page = in_doc.addObject('TechDraw::DrawPage', 'TmpPage')
if not page.KeepUpdated: page.KeepUpdated = True if not page.KeepUpdated: page.KeepUpdated = True
template = doc.addObject('TechDraw::DrawSVGTemplate', 'Template') template = in_doc.addObject('TechDraw::DrawSVGTemplate', 'Template')
import ahb_locator import ahb_locator
template.Template = os.path.join(os.path.dirname(ahb_locator.__file__), "resources/A4_Landscape_blank.svg") template.Template = os.path.join(os.path.dirname(ahb_locator.__file__), "resources/A4_Landscape_blank.svg")
page.Template = template page.Template = template
tmpView = doc.addObject('TechDraw::DrawViewPart', 'TmpView') tmpView = in_doc.addObject('TechDraw::DrawViewPart', 'TmpView')
tmpView.ViewObject.Visibility = False tmpView.ViewObject.Visibility = False
tmpView.Direction = self.direction tmpView.Direction = self.direction
tmpView.XDirection = self.x_direction tmpView.XDirection = self.x_direction
@ -64,16 +64,20 @@ class PartCachedView:
lineIdx = lineIdx + 1 lineIdx = lineIdx + 1
# delete temporary view # delete temporary view
doc.removeObject(page.Name) in_doc.removeObject(page.Name)
class PartsCache: class PartsCache:
part_views = {} part_views = {}
def getPart2DView(self, view, obj): 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) part_view = self.part_views.get(key, None)
if part_view is None: if part_view is None:
part_view = PartCachedView(view.Direction, view.XDirection, obj) part_view = PartCachedView(view.Direction, view.XDirection, object_to_render)
part_view.render() part_view.render(obj.Document)
self.part_views[key] = part_view self.part_views[key] = part_view
return part_view return part_view

27
ahb_techdraw_extensions.py

@ -56,7 +56,10 @@ class CursorItem(QtGui.QGraphicsItem):
class ViewCache: class ViewCache:
def __init__(self): def __init__(self):
self.projected_points = {} # maps 3D vectors to their 2D projection self.reset()
def reset(self):
self.projected_origin = None
class TechDrawExtensions: class TechDrawExtensions:
views_to_repaint = {} views_to_repaint = {}
@ -91,6 +94,9 @@ class TechDrawExtensions:
for view in to_repaint: for view in to_repaint:
#print("Repainting " + view.Name) #print("Repainting " + view.Name)
view_cache = self.getViewCache(view)
view_cache.reset()
doc = view.Document doc = view.Document
selected_balloons = [] selected_balloons = []
@ -339,7 +345,7 @@ class TechDrawExtensions:
balloon.ViewObject.Font = 'DejaVu Sans' balloon.ViewObject.Font = 'DejaVu Sans'
balloon.ViewObject.Fontsize = 4 balloon.ViewObject.Fontsize = 4
balloon.BubbleShape = 'Inspection' balloon.BubbleShape = 'Inspection'
balloon.EndTypeScale = 4 balloon.EndTypeScale = 1
def getBalloonSourcePart(self, balloon): def getBalloonSourcePart(self, balloon):
try: try:
@ -438,7 +444,7 @@ class TechDrawExtensions:
else: else:
objectCenterWorld = obj.Shape.CenterOfGravity objectCenterWorld = obj.Shape.CenterOfGravity
view_cache = self.getViewCache(view) '''view_cache = self.getViewCache(view)
key = (objectCenterWorld.x, objectCenterWorld.y, objectCenterWorld.z) key = (objectCenterWorld.x, objectCenterWorld.y, objectCenterWorld.z)
projected_point = view_cache.projected_points.get(key, None) projected_point = view_cache.projected_points.get(key, None)
@ -451,7 +457,20 @@ class TechDrawExtensions:
view.removeCosmeticVertex(vertId) view.removeCosmeticVertex(vertId)
view_cache.projected_points[key] = projected_point 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): def getViewCache(self, view):
cache = self.view_cache.get(view, None) cache = self.view_cache.get(view, None)

Loading…
Cancel
Save