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