@ -69,6 +69,8 @@ class TechDrawExtensions:
edited_view = None
edited_view = None
enable_selected_part_highlight = False # disable for now, for performance reasons
def __init__ ( self ) :
def __init__ ( self ) :
workbench = Gui . getWorkbench ( " AssemblyHandbookWorkbench " ) #: :type workbench: AssemblyHandbookWorkbench
workbench = Gui . getWorkbench ( " AssemblyHandbookWorkbench " ) #: :type workbench: AssemblyHandbookWorkbench
workbench . docObserver . onObjectTypeChanged ( ' balloon_changed ' , ' TechDraw::DrawViewBalloon ' , lambda obj , prop : self . onBalloonChanged ( obj , prop ) )
workbench . docObserver . onObjectTypeChanged ( ' balloon_changed ' , ' TechDraw::DrawViewBalloon ' , lambda obj , prop : self . onBalloonChanged ( obj , prop ) )
@ -101,6 +103,7 @@ class TechDrawExtensions:
parts_to_paint = [ ]
parts_to_paint = [ ]
# repaint parts that are highlighted by selection
# repaint parts that are highlighted by selection
if self . enable_selected_part_highlight :
for balloon in selected_balloons :
for balloon in selected_balloons :
part = doc . getObject ( balloon . Assembly_handbook_PartName )
part = doc . getObject ( balloon . Assembly_handbook_PartName )
if part in view . XSource :
if part in view . XSource :
@ -122,7 +125,7 @@ class TechDrawExtensions:
default_line_thickness = 0.05
default_line_thickness = 0.05
line_thickness = default_line_thickness
line_thickness = default_line_thickness
default_color = ( 0 , 0 , 0 )
default_color = ( 0.65 , 0.65 , 0.65 )
color = default_color
color = default_color
if part is not None :
if part is not None :
@ -134,8 +137,10 @@ class TechDrawExtensions:
prev_view = doc . getObject ( view . Assembly_handbook_PreviousStepView )
prev_view = doc . getObject ( view . Assembly_handbook_PreviousStepView )
if prev_view is not None :
if prev_view is not None :
if not part in prev_view . XSource :
if not part in prev_view . XSource :
line_thickness = 0.3
line_thickness = 0.2
color = ( 0 , 0 , 0 )
if self . enable_selected_part_highlight :
for balloon in selected_balloons :
for balloon in selected_balloons :
if part . Name == balloon . Assembly_handbook_PartName :
if part . Name == balloon . Assembly_handbook_PartName :
color = ( 0.0 , 0.85 , 0.0 ) # selection highlighting
color = ( 0.0 , 0.85 , 0.0 ) # selection highlighting
@ -181,6 +186,12 @@ class TechDrawExtensions:
view . requestPaint ( )
view . requestPaint ( )
def updateBalloonCursor ( self , view ) :
selected_balloons = [ ]
for obj in Gui . Selection . getSelection ( ) :
if obj . TypeId == ' TechDraw::DrawViewBalloon ' and obj . SourceView == view and ' Assembly_handbook_PartName ' in obj . PropertiesList :
selected_balloons . append ( obj )
cursor = self . view_cursors . get ( view , None )
cursor = self . view_cursors . get ( view , None )
if cursor is None :
if cursor is None :
cursor = CursorItem ( view = view )
cursor = CursorItem ( view = view )
@ -299,7 +310,9 @@ class TechDrawExtensions:
if " Assembly_handbook_PartName " in balloon . PropertiesList :
if " Assembly_handbook_PartName " in balloon . PropertiesList :
#print(operation + " " + balloon.Name)
#print(operation + " " + balloon.Name)
view = balloon . SourceView
view = balloon . SourceView
self . repaint ( view )
self . updateBalloonCursor ( view )
if self . enable_selected_part_highlight :
self . repaint ( view ) # disabled for now, for performance reasons
def onBalloonChanged ( self , obj , prop ) :
def onBalloonChanged ( self , obj , prop ) :
# Avoid reentry
# Avoid reentry
@ -319,17 +332,37 @@ class TechDrawExtensions:
doc = view . Document
doc = view . Document
obj = doc . getObject ( balloon . Assembly_handbook_PartName )
obj = doc . getObject ( balloon . Assembly_handbook_PartName )
partDisplayName = self . getPartDisplayName ( obj )
objectCenterView = workbench . techDrawExtensions . computePartCenter ( view , obj )
objectCenterView = workbench . techDrawExtensions . computePartCenter ( view , obj )
balloon . OriginX = objectCenterView . x + balloon . Assembly_handbook_OriginOffsetX
balloon . OriginX = objectCenterView . x + balloon . Assembly_handbook_OriginOffsetX
balloon . OriginY = objectCenterView . y + balloon . Assembly_handbook_OriginOffsetY
balloon . OriginY = objectCenterView . y + balloon . Assembly_handbook_OriginOffsetY
balloon . Text = obj . LinkedObject . Document . Name if obj . TypeId == ' App::Link ' else obj . Name
balloon . Text = partDisplay Name
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 = 4
def getPartDisplayName ( self , obj ) :
if obj . TypeId == ' App::Link ' :
linked_obj = obj . LinkedObject
if ' Assembly_handbook_PartDisplayName ' in linked_obj . PropertiesList :
return linked_obj . Assembly_handbook_PartDisplayName
else :
return linked_obj . Document . Name
return obj . Name
def isNewPartInView ( self , view , obj ) :
doc = view . Document
if ' Assembly_handbook_PreviousStepView ' in view . PropertiesList :
prev_view = doc . getObject ( view . Assembly_handbook_PreviousStepView )
if prev_view is not None :
if not obj in prev_view . XSource :
return True
return False
def getActivePage ( self ) :
def getActivePage ( self ) :
activeView = Gui . activeView ( )
activeView = Gui . activeView ( )
if activeView is None : return None
if activeView is None : return None
@ -347,6 +380,19 @@ class TechDrawExtensions:
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 :
self . refreshView ( view )
self . refreshView ( view )
elif view . TypeId == ' TechDraw::DrawViewBalloon ' :
if view . ViewObject . Visibility :
# workaround for a TechDraw bug: sometimes the balloon should be visible but doesn't appear, showing it again fixes the issue
view . ViewObject . Visibility = False
def makeRedrawCallback ( view ) :
def redrawBalloon ( ) :
view . ViewObject . Visibility = True
return redrawBalloon
QTimer . singleShot ( 0 , makeRedrawCallback ( view ) )
else :
# workaround for a TechDraw bug: sometimes the balloon text is visible even if the balloon is hidden, hiding it again fixes the issue
view . ViewObject . Visibility = True
view . ViewObject . Visibility = False
if page . KeepUpdated :
if page . KeepUpdated :
for view in page . Views :
for view in page . Views :