@ -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