Fixed balloon bugs when parts from a different document are added to a view
This commit is contained in:
parent
9cf0944570
commit
e1e4cd743e
@ -29,11 +29,12 @@ class AHB_View_Annotate:
|
||||
|
||||
# Remove balloons referencing missing objects
|
||||
for balloon in page.Views:
|
||||
if balloon.TypeId == 'TechDraw::DrawViewBalloon' and "Assembly_handbook_PartName" in balloon.PropertiesList:
|
||||
if balloon.TypeId == 'TechDraw::DrawViewBalloon' and "Assembly_handbook_Source" in balloon.PropertiesList:
|
||||
if balloon.SourceView != view: continue
|
||||
partLink = doc.getObject(balloon.Assembly_handbook_PartName)
|
||||
partLink = balloon.Assembly_handbook_Source[0] if balloon.Assembly_handbook_Source is not None else None
|
||||
if partLink is None or partLink not in view.XSource:
|
||||
print(balloon.Name + " references missing object " + balloon.Assembly_handbook_PartName + ", removing balloon")
|
||||
ref_name = balloon.Assembly_handbook_Source[1] if balloon.Assembly_handbook_Source is not None else "<no ref>"
|
||||
print(balloon.Name + " references missing object " + ref_name + ", removing balloon")
|
||||
doc.removeObject(balloon.Name)
|
||||
|
||||
for partLink in view.XSource:
|
||||
@ -41,7 +42,7 @@ class AHB_View_Annotate:
|
||||
|
||||
# Search an existing balloon to update
|
||||
for obj in page.Views:
|
||||
if obj.TypeId == 'TechDraw::DrawViewBalloon' and "Assembly_handbook_PartName" in obj.PropertiesList and obj.Assembly_handbook_PartName == partLink.Name:
|
||||
if obj.TypeId == 'TechDraw::DrawViewBalloon' and "Assembly_handbook_Source" in obj.PropertiesList and obj.Assembly_handbook_Source[0] == partLink:
|
||||
if obj.SourceView != view: continue
|
||||
balloon = obj
|
||||
|
||||
@ -54,8 +55,8 @@ class AHB_View_Annotate:
|
||||
balloon = doc.addObject("TechDraw::DrawViewBalloon", balloonName)
|
||||
balloon.SourceView = view
|
||||
|
||||
balloon.addProperty("App::PropertyString", "Assembly_handbook_PartName", "Assembly_handbook")
|
||||
balloon.Assembly_handbook_PartName = partName
|
||||
balloon.addProperty("App::PropertyXLink", "Assembly_handbook_Source", "Assembly_handbook")
|
||||
balloon.Assembly_handbook_Source = (partLink, partLink.Name)
|
||||
|
||||
balloon.addProperty("App::PropertyFloat", "Assembly_handbook_OriginOffsetX", "Assembly_handbook")
|
||||
balloon.addProperty("App::PropertyFloat", "Assembly_handbook_OriginOffsetY", "Assembly_handbook")
|
||||
|
@ -95,7 +95,7 @@ class TechDrawExtensions:
|
||||
|
||||
selected_balloons = []
|
||||
for obj in Gui.Selection.getSelection():
|
||||
if obj.TypeId == 'TechDraw::DrawViewBalloon' and obj.SourceView == view and 'Assembly_handbook_PartName' in obj.PropertiesList:
|
||||
if obj.TypeId == 'TechDraw::DrawViewBalloon' and obj.SourceView == view and 'Assembly_handbook_Source' in obj.PropertiesList:
|
||||
selected_balloons.append(obj)
|
||||
|
||||
is_first_part = True
|
||||
@ -105,7 +105,7 @@ class TechDrawExtensions:
|
||||
# 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)
|
||||
part = self.getBalloonSourcePart(balloon)
|
||||
if part in view.XSource:
|
||||
parts_to_paint.append(part)
|
||||
|
||||
@ -139,7 +139,7 @@ class TechDrawExtensions:
|
||||
|
||||
if self.enable_selected_part_highlight:
|
||||
for balloon in selected_balloons:
|
||||
if part.Name == balloon.Assembly_handbook_PartName:
|
||||
if part == self.getBalloonSourcePart(balloon):
|
||||
color = (0.0, 0.85, 0.0) # selection highlighting
|
||||
|
||||
# iterate edges of actual view and highlight matching edges
|
||||
@ -186,7 +186,7 @@ class TechDrawExtensions:
|
||||
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:
|
||||
if obj.TypeId == 'TechDraw::DrawViewBalloon' and obj.SourceView == view and 'Assembly_handbook_Source' in obj.PropertiesList:
|
||||
selected_balloons.append(obj)
|
||||
|
||||
cursor = self.view_cursors.get(view, None)
|
||||
@ -223,8 +223,8 @@ class TechDrawExtensions:
|
||||
doc = view.Document
|
||||
page = self.getViewPage(view)
|
||||
for balloon in page.Views:
|
||||
if balloon.TypeId == 'TechDraw::DrawViewBalloon' and "Assembly_handbook_PartName" in balloon.PropertiesList and balloon.SourceView == view:
|
||||
obj = doc.getObject(balloon.Assembly_handbook_PartName)
|
||||
if balloon.TypeId == 'TechDraw::DrawViewBalloon' and "Assembly_handbook_Source" in balloon.PropertiesList and balloon.SourceView == view:
|
||||
obj = self.getBalloonSourcePart(balloon)
|
||||
balloonColor = (0.0, 0.0, 0.0)
|
||||
if obj is None or not obj in view.XSource:
|
||||
balloonColor = (1.0, 0.0, 0.0)
|
||||
@ -289,13 +289,13 @@ class TechDrawExtensions:
|
||||
def onCursorMoved(self, view, new_pos):
|
||||
if len(Gui.Selection.getSelection()) == 0: return
|
||||
balloon = Gui.Selection.getSelection()[0]
|
||||
if balloon.TypeId != 'TechDraw::DrawViewBalloon' or not 'Assembly_handbook_PartName' in balloon.PropertiesList: return
|
||||
if balloon.TypeId != 'TechDraw::DrawViewBalloon' or not 'Assembly_handbook_Source' in balloon.PropertiesList: return
|
||||
if balloon.SourceView != view: return
|
||||
|
||||
balloon.OriginX = new_pos.x
|
||||
balloon.OriginY = new_pos.y
|
||||
|
||||
obj = balloon.Document.getObject(balloon.Assembly_handbook_PartName)
|
||||
obj = self.getBalloonSourcePart(balloon)
|
||||
view = balloon.SourceView
|
||||
center = self.computePartCenter(view, obj)
|
||||
|
||||
@ -304,7 +304,7 @@ class TechDrawExtensions:
|
||||
|
||||
def onBalloonSelected(self, operation, balloon, sub, point):
|
||||
#print(operation, obj.Name, sub, point)
|
||||
if "Assembly_handbook_PartName" in balloon.PropertiesList:
|
||||
if 'Assembly_handbook_Source' in balloon.PropertiesList:
|
||||
#print(operation + " " + balloon.Name)
|
||||
view = balloon.SourceView
|
||||
self.updateBalloonCursor(view)
|
||||
@ -317,7 +317,7 @@ class TechDrawExtensions:
|
||||
return
|
||||
|
||||
#print('Balloon changed: ' + obj.Name + '.' + prop)
|
||||
if prop == 'Y' and "Assembly_handbook_PartName" in obj.PropertiesList:
|
||||
if prop == 'Y' and 'Assembly_handbook_Source' in obj.PropertiesList:
|
||||
self.updating_balloon = True
|
||||
self.updateBalloon(obj)
|
||||
self.updating_balloon = False
|
||||
@ -326,8 +326,7 @@ class TechDrawExtensions:
|
||||
workbench = Gui.getWorkbench("AssemblyHandbookWorkbench") #: :type workbench: AssemblyHandbookWorkbench
|
||||
|
||||
view = balloon.SourceView
|
||||
doc = view.Document
|
||||
obj = doc.getObject(balloon.Assembly_handbook_PartName)
|
||||
obj = self.getBalloonSourcePart(balloon)
|
||||
|
||||
partDisplayName = self.getPartDisplayName(obj)
|
||||
|
||||
@ -342,6 +341,12 @@ class TechDrawExtensions:
|
||||
balloon.BubbleShape = 'Inspection'
|
||||
balloon.EndTypeScale = 4
|
||||
|
||||
def getBalloonSourcePart(self, balloon):
|
||||
try:
|
||||
return balloon.Assembly_handbook_Source[0]
|
||||
except:
|
||||
return None
|
||||
|
||||
def isPartLink(self, obj):
|
||||
if obj.TypeId == 'App::Link':
|
||||
return True
|
||||
|
Loading…
Reference in New Issue
Block a user