You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
3.0 KiB
84 lines
3.0 KiB
import FreeCADGui as Gui |
|
import FreeCAD as App |
|
|
|
class AHB_View_Annotate: |
|
def GetResources(self): |
|
return {"MenuText": "Annotate view", |
|
"ToolTip": "Annotates a TechDraw view with object names", |
|
"Pixmap": "" |
|
} |
|
|
|
def IsActive(self): |
|
return True |
|
|
|
def Activated(self): |
|
workbench = Gui.getWorkbench("AssemblyHandbookWorkbench") #: :type workbench: AssemblyHandbookWorkbench |
|
|
|
if len(Gui.Selection.getSelection()) != 1: |
|
raise Exception("Please select exactly one TechDraw view") |
|
|
|
view = Gui.Selection.getSelection()[0] |
|
if view.TypeId != 'TechDraw::DrawViewPart': |
|
raise Exception("Selected object is not a TechDraw view") |
|
|
|
overlay_view = workbench.techDrawExtensions.getOverlayView(view) |
|
|
|
doc = view.Document |
|
|
|
page = workbench.techDrawExtensions.getViewPage(view) |
|
if page is None: |
|
raise Exception("Can't find page in which the selected view is located") |
|
|
|
# Remove balloons referencing missing objects |
|
for balloon in page.Views: |
|
if balloon.TypeId == 'TechDraw::DrawViewBalloon' and "Assembly_handbook_Source" in balloon.PropertiesList: |
|
if balloon.SourceView != view and balloon.SourceView != overlay_view: continue |
|
partLink = workbench.techDrawExtensions.getBalloonSourcePart(balloon) |
|
if partLink is None or partLink not in view.XSource: |
|
ref_name = "<no ref>" |
|
try: |
|
ref_name = balloon.Assembly_handbook_Source[1] |
|
except: |
|
pass |
|
print(balloon.Name + " references missing object " + ref_name + ", removing balloon") |
|
doc.removeObject(balloon.Name) |
|
|
|
for partLink in view.XSource: |
|
balloon = None |
|
|
|
# Search an existing balloon to update |
|
for obj in page.Views: |
|
if obj.TypeId == 'TechDraw::DrawViewBalloon' and workbench.techDrawExtensions.getBalloonSourcePart(obj) == partLink: |
|
if obj.SourceView != overlay_view: continue |
|
balloon = obj |
|
|
|
# Create a new balloon if needed |
|
if balloon is None: |
|
if workbench.techDrawExtensions.isNewPartInView(view, partLink): |
|
partName = partLink.Name |
|
|
|
balloonName = partName + "_Balloon" |
|
|
|
balloon = doc.addObject("TechDraw::DrawViewBalloon", balloonName) |
|
balloon.SourceView = overlay_view |
|
|
|
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") |
|
|
|
page.addView(balloon) |
|
|
|
workbench.techDrawExtensions.updateBalloon(balloon) |
|
|
|
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) |
|
|
|
from ahb_command import AHB_CommandWrapper |
|
AHB_CommandWrapper.addGuiCommand('AHB_view_annotate', AHB_View_Annotate())
|
|
|