Browse Source

multiple small improvements

- improved naming of balloons (part name appears more clearly, balloon numbering is at the end)
- balloons for parts that were already in the previous step are hidden by default
- disabled highlighting of part drawing related to the selected balloon (for performance reasons)
- added possibility to explicitely set the display name of a part (instead of using the file name)
- added workaround for balloons that are not rendered until selected
master
Youen 2 years ago
parent
commit
9dbaa141f1
  1. 7
      ahb_cmd_view_annotate.py
  2. 54
      ahb_techdraw_extensions.py

7
ahb_cmd_view_annotate.py

@ -49,7 +49,9 @@ class AHB_View_Annotate:
if balloon is None:
partName = partLink.Name
balloon = doc.addObject("TechDraw::DrawViewBalloon", "Balloon" + partName)
balloonName = partName + "_Balloon"
balloon = doc.addObject("TechDraw::DrawViewBalloon", balloonName)
balloon.SourceView = view
balloon.addProperty("App::PropertyString", "Assembly_handbook_PartName", "Assembly_handbook")
@ -64,6 +66,9 @@ class AHB_View_Annotate:
balloon.X = int(balloon.OriginX) + 20
balloon.Y = int(balloon.OriginY) + 20
if not workbench.techDrawExtensions.isNewPartInView(view, partLink):
balloon.ViewObject.Visibility = False
else:
workbench.techDrawExtensions.updateBalloon(balloon)

54
ahb_techdraw_extensions.py

@ -69,6 +69,8 @@ class TechDrawExtensions:
edited_view = None
enable_selected_part_highlight = False # disable for now, for performance reasons
def __init__(self):
workbench = Gui.getWorkbench("AssemblyHandbookWorkbench") #: :type workbench: AssemblyHandbookWorkbench
workbench.docObserver.onObjectTypeChanged('balloon_changed', 'TechDraw::DrawViewBalloon', lambda obj, prop: self.onBalloonChanged(obj, prop))
@ -101,6 +103,7 @@ class TechDrawExtensions:
parts_to_paint = []
# repaint parts that are highlighted by selection
if self.enable_selected_part_highlight:
for balloon in selected_balloons:
part = doc.getObject(balloon.Assembly_handbook_PartName)
if part in view.XSource:
@ -122,7 +125,7 @@ class TechDrawExtensions:
default_line_thickness = 0.05
line_thickness = default_line_thickness
default_color = (0, 0, 0)
default_color = (0.65, 0.65, 0.65)
color = default_color
if part is not None:
@ -134,8 +137,10 @@ class TechDrawExtensions:
prev_view = doc.getObject(view.Assembly_handbook_PreviousStepView)
if prev_view is not None:
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:
if part.Name == balloon.Assembly_handbook_PartName:
color = (0.0, 0.85, 0.0) # selection highlighting
@ -181,6 +186,12 @@ class TechDrawExtensions:
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)
if cursor is None:
cursor = CursorItem(view = view)
@ -299,7 +310,9 @@ class TechDrawExtensions:
if "Assembly_handbook_PartName" in balloon.PropertiesList:
#print(operation + " " + balloon.Name)
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):
# Avoid reentry
@ -319,17 +332,37 @@ class TechDrawExtensions:
doc = view.Document
obj = doc.getObject(balloon.Assembly_handbook_PartName)
partDisplayName = self.getPartDisplayName(obj)
objectCenterView = workbench.techDrawExtensions.computePartCenter(view, obj)
balloon.OriginX = objectCenterView.x + balloon.Assembly_handbook_OriginOffsetX
balloon.OriginY = objectCenterView.y + balloon.Assembly_handbook_OriginOffsetY
balloon.Text = obj.LinkedObject.Document.Name if obj.TypeId == 'App::Link' else obj.Name
balloon.Text = partDisplayName
balloon.ViewObject.Font = 'DejaVu Sans'
balloon.ViewObject.Fontsize = 4
balloon.BubbleShape = 'Inspection'
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):
activeView = Gui.activeView()
if activeView is None: return None
@ -347,6 +380,19 @@ class TechDrawExtensions:
for view in page.Views:
if view.TypeId == 'TechDraw::DrawViewPart' and 'Assembly_handbook_PreviousStepView' in view.PropertiesList:
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:
for view in page.Views:

Loading…
Cancel
Save