forked from youen/assembly_handbook
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
This commit is contained in:
parent
44c6e41fff
commit
9dbaa141f1
@ -49,7 +49,9 @@ class AHB_View_Annotate:
|
|||||||
if balloon is None:
|
if balloon is None:
|
||||||
partName = partLink.Name
|
partName = partLink.Name
|
||||||
|
|
||||||
balloon = doc.addObject("TechDraw::DrawViewBalloon", "Balloon" + partName)
|
balloonName = partName + "_Balloon"
|
||||||
|
|
||||||
|
balloon = doc.addObject("TechDraw::DrawViewBalloon", balloonName)
|
||||||
balloon.SourceView = view
|
balloon.SourceView = view
|
||||||
|
|
||||||
balloon.addProperty("App::PropertyString", "Assembly_handbook_PartName", "Assembly_handbook")
|
balloon.addProperty("App::PropertyString", "Assembly_handbook_PartName", "Assembly_handbook")
|
||||||
@ -64,6 +66,9 @@ class AHB_View_Annotate:
|
|||||||
|
|
||||||
balloon.X = int(balloon.OriginX) + 20
|
balloon.X = int(balloon.OriginX) + 20
|
||||||
balloon.Y = int(balloon.OriginY) + 20
|
balloon.Y = int(balloon.OriginY) + 20
|
||||||
|
|
||||||
|
if not workbench.techDrawExtensions.isNewPartInView(view, partLink):
|
||||||
|
balloon.ViewObject.Visibility = False
|
||||||
else:
|
else:
|
||||||
workbench.techDrawExtensions.updateBalloon(balloon)
|
workbench.techDrawExtensions.updateBalloon(balloon)
|
||||||
|
|
||||||
|
@ -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,10 +103,11 @@ class TechDrawExtensions:
|
|||||||
parts_to_paint = []
|
parts_to_paint = []
|
||||||
|
|
||||||
# repaint parts that are highlighted by selection
|
# repaint parts that are highlighted by selection
|
||||||
for balloon in selected_balloons:
|
if self.enable_selected_part_highlight:
|
||||||
part = doc.getObject(balloon.Assembly_handbook_PartName)
|
for balloon in selected_balloons:
|
||||||
if part in view.XSource:
|
part = doc.getObject(balloon.Assembly_handbook_PartName)
|
||||||
parts_to_paint.append(part)
|
if part in view.XSource:
|
||||||
|
parts_to_paint.append(part)
|
||||||
|
|
||||||
# repaint parts that are new in this step (thick line)
|
# repaint parts that are new in this step (thick line)
|
||||||
if 'Assembly_handbook_PreviousStepView' in view.PropertiesList:
|
if 'Assembly_handbook_PreviousStepView' in view.PropertiesList:
|
||||||
@ -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,11 +137,13 @@ 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)
|
||||||
for balloon in selected_balloons:
|
|
||||||
if part.Name == balloon.Assembly_handbook_PartName:
|
if self.enable_selected_part_highlight:
|
||||||
color = (0.0, 0.85, 0.0) # selection highlighting
|
for balloon in selected_balloons:
|
||||||
|
if part.Name == balloon.Assembly_handbook_PartName:
|
||||||
|
color = (0.0, 0.85, 0.0) # selection highlighting
|
||||||
|
|
||||||
# iterate edges of actual view and highlight matching edges
|
# iterate edges of actual view and highlight matching edges
|
||||||
for edgeIdx in range(10000):
|
for edgeIdx in range(10000):
|
||||||
@ -181,18 +186,24 @@ class TechDrawExtensions:
|
|||||||
|
|
||||||
view.requestPaint()
|
view.requestPaint()
|
||||||
|
|
||||||
cursor = self.view_cursors.get(view, None)
|
def updateBalloonCursor(self, view):
|
||||||
if cursor is None:
|
selected_balloons = []
|
||||||
cursor = CursorItem(view = view)
|
for obj in Gui.Selection.getSelection():
|
||||||
TDG.addQGIToView(view, cursor);
|
if obj.TypeId == 'TechDraw::DrawViewBalloon' and obj.SourceView == view and 'Assembly_handbook_PartName' in obj.PropertiesList:
|
||||||
cursor.onViewPosChange(lambda new_pos: self.onCursorMoved(view, new_pos))
|
selected_balloons.append(obj)
|
||||||
self.view_cursors[view] = cursor
|
|
||||||
|
cursor = self.view_cursors.get(view, None)
|
||||||
if len(selected_balloons) == 0:
|
if cursor is None:
|
||||||
cursor.setVisible(False)
|
cursor = CursorItem(view = view)
|
||||||
else:
|
TDG.addQGIToView(view, cursor);
|
||||||
cursor.setViewPos(App.Vector(selected_balloons[0].OriginX, selected_balloons[0].OriginY))
|
cursor.onViewPosChange(lambda new_pos: self.onCursorMoved(view, new_pos))
|
||||||
cursor.setVisible(True)
|
self.view_cursors[view] = cursor
|
||||||
|
|
||||||
|
if len(selected_balloons) == 0:
|
||||||
|
cursor.setVisible(False)
|
||||||
|
else:
|
||||||
|
cursor.setViewPos(App.Vector(selected_balloons[0].OriginX, selected_balloons[0].OriginY))
|
||||||
|
cursor.setVisible(True)
|
||||||
|
|
||||||
def setCurrentViewDirection(self, view):
|
def setCurrentViewDirection(self, view):
|
||||||
from pivy import coin
|
from pivy import coin
|
||||||
@ -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 = partDisplayName
|
||||||
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:
|
||||||
|
Loading…
Reference in New Issue
Block a user