From 830b2aada74305b786be98d821565e204ef42f3a Mon Sep 17 00:00:00 2001 From: Roy-043 Date: Tue, 28 Jan 2025 17:37:29 +0100 Subject: [PATCH] Draft: fix handling of annotation Links in TD DraftViews Fixes #19199. --- src/Mod/Draft/draftfunctions/svg.py | 105 +++++++++++++++++----------- 1 file changed, 63 insertions(+), 42 deletions(-) diff --git a/src/Mod/Draft/draftfunctions/svg.py b/src/Mod/Draft/draftfunctions/svg.py index 32f3c302ff70..bb21394442d6 100644 --- a/src/Mod/Draft/draftfunctions/svg.py +++ b/src/Mod/Draft/draftfunctions/svg.py @@ -425,54 +425,75 @@ def get_svg(obj, It defaults to `True`. """ # If this is a group, recursively call this function to gather - # all the SVG strings from the contents of the group - if hasattr(obj, "isDerivedFrom"): - if (obj.isDerivedFrom("App::DocumentObjectGroup") - or utils.get_type(obj) in ["Layer", "BuildingPart", "IfcGroup"] - or obj.isDerivedFrom("App::LinkGroup") - or (obj.isDerivedFrom("App::Link") - and obj.LinkedObject.isDerivedFrom("App::DocumentObjectGroup"))): + # all the SVG strings from the contents of the group. + if (obj.isDerivedFrom("App::DocumentObjectGroup") + or utils.get_type(obj) in ["Layer", "BuildingPart", "IfcGroup"] + or obj.isDerivedFrom("App::LinkGroup") + or (obj.isDerivedFrom("App::Link") + and obj.LinkedObject.isDerivedFrom("App::DocumentObjectGroup"))): - hidden_doc = None + hidden_doc = None - if (obj.isDerivedFrom("App::LinkGroup") - or (obj.isDerivedFrom("App::Link") - and obj.LinkedObject.isDerivedFrom("App::DocumentObjectGroup"))): - if obj.Placement.isIdentity(): - if obj.isDerivedFrom("App::LinkGroup"): - group = obj.ElementList - else: - group = obj.Group + if (obj.isDerivedFrom("App::LinkGroup") + or (obj.isDerivedFrom("App::Link") + and obj.LinkedObject.isDerivedFrom("App::DocumentObjectGroup"))): + if obj.Placement.isIdentity(): + if obj.isDerivedFrom("App::LinkGroup"): + group = obj.ElementList else: - # Using a hidden doc hack to handle placements. - hidden_doc = App.newDocument(name="hidden", hidden=True, temp=True) - new = hidden_doc.copyObject(obj, True) - pla = new.Placement - new.Placement = App.Placement() - if new.isDerivedFrom("App::LinkGroup"): - group = new.ElementList - else: - group = new.Group - for child in group: - child.Placement = pla * child.Placement + group = obj.Group else: - group = obj.Group - - svg = "" - for child in group: - svg += get_svg(child, - scale, linewidth, fontsize, - fillstyle, direction, linestyle, - color, linespacing, techdraw, - rotation, fillspaces, override) + # Hidden doc hack: + hidden_doc = App.newDocument(name="hidden", hidden=True, temp=True) + new = hidden_doc.copyObject(obj, True) + pla = new.Placement + new.Placement = App.Placement() + if new.isDerivedFrom("App::LinkGroup"): + group = new.ElementList + else: + group = new.Group + for child in group: + child.Placement = pla * child.Placement + else: + group = obj.Group + + svg = "" + for child in group: + svg += get_svg(child, + scale, linewidth, fontsize, + fillstyle, direction, linestyle, + color, linespacing, techdraw, + rotation, fillspaces, override) + + if hidden_doc is not None: + try: + App.closeDocument(hidden_doc.Name) + except: + pass - if hidden_doc is not None: - try: - App.closeDocument(hidden_doc.Name) - except: - pass + return svg - return svg + # Handle Links to texts and dimensions. These Links do not have a Shape. + if obj.isDerivedFrom("App::Link") and obj.LinkedObject and not hasattr(obj, "Shape"): + # Hidden doc hack: + hidden_doc = App.newDocument(name="hidden", hidden=True, temp=True) + new = hidden_doc.copyObject(obj.LinkedObject, True) + if utils.get_type(new) in ("Dimension", "LinearDimension", "AngularDimension"): + new.Proxy.transform(new, obj.Placement) + elif utils.get_type(new) == "Text" or obj.LinkTransform: + new.Placement = obj.Placement * new.Placement + else: + new.Placement = obj.Placement + svg = get_svg(new, + scale, linewidth, fontsize, + fillstyle, direction, linestyle, + color, linespacing, techdraw, + rotation, fillspaces, override) + try: + App.closeDocument(hidden_doc.Name) + except: + pass + return svg vobj = _get_view_object(obj)