Browse Source

fixed bugs for link branch

- App.Base.Vector2d has no "distance" method
- balloons were not treated as a group but one by one
master
Youen 2 years ago
parent
commit
f62ab9eb70
  1. 18
      ahb_cmd_view_annotate.py

18
ahb_cmd_view_annotate.py

@ -69,12 +69,14 @@ class AHB_View_Annotate:
print(balloon.Name + " references missing object " + ref_name + ", removing balloon")
doc.removeObject(balloon.Name)
balloonsCreated = []
for partLink in view.XSource:
balloonsCreated = workbench.techDrawExtensions.add_or_update_balloon(view, partLink, '')
balloonsCreated.extend(workbench.techDrawExtensions.add_or_update_balloon(view, partLink, ''))
if len(balloonsCreated) > 0:
regroupedBalloons = self.RegroupNearestSimilarBalloons(balloonsCreated)
self.PlaceBalloonsInCircle(regroupedBalloons)
#self.PlaceBalloonsInCircle(balloonsCreated)
#self.PlaceBalloonsInCircle(regroupedBalloons)
self.PlaceBalloonsInCircle(balloonsCreated)
workbench.techDrawExtensions.refreshOverlays(page)
@ -86,13 +88,13 @@ class AHB_View_Annotate:
realBalloon = balloon[0] if type(balloon) is list else balloon
totalX = totalX + int(realBalloon.OriginX)
totalY = totalY + int(realBalloon.OriginY)
return App.Base.Vector2d(totalX / len(balloons), totalY / len(balloons))
return App.Vector(totalX / len(balloons), totalY / len(balloons))
def IsSimilarBalloonNear(self, balloonA, balloonB):
MAX_DISTANCE_BETWEEN_REGROUPED_BALLOONS = 50
if balloonA.Text == balloonB.Text:
pos = App.Base.Vector2d(balloonA.OriginX, balloonA.OriginY)
dist = pos.distance(App.Base.Vector2d(balloonB.OriginX, balloonB.OriginY))
pos = App.Vector(balloonA.OriginX, balloonA.OriginY)
dist = pos.distanceToPoint(App.Vector(balloonB.OriginX, balloonB.OriginY))
return dist < MAX_DISTANCE_BETWEEN_REGROUPED_BALLOONS
else:
return False
@ -119,13 +121,13 @@ class AHB_View_Annotate:
for i in range(nbBalloons):
xPos = round(center.x + 600 * math.cos(balloonPosStep * i))
yPos = round(center.y + 600 * math.sin(balloonPosStep * i))
balloonPos = App.Base.Vector2d(xPos, yPos)
balloonPos = App.Vector(xPos, yPos)
# Find nearest arrow to avoid arrow crossing each other
smallestDistance = 0
balloonToUse = None
for balloon in balloons:
realBalloon = balloon[0] if type(balloon) is list else balloon
dist = balloonPos.distance(App.Base.Vector2d(realBalloon.OriginX, realBalloon.OriginY))
dist = balloonPos.distanceToPoint(App.Vector(realBalloon.OriginX, realBalloon.OriginY))
if smallestDistance == 0 or dist < smallestDistance:
smallestDistance = dist
balloonToUse = balloon

Loading…
Cancel
Save