From f49b38a595b0b2f8870ae79e59a4269a19a0103f Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Tue, 29 Jun 2021 15:21:56 +0200 Subject: [PATCH 1/4] Draft: Fix incorrect use of `in` operator Looking at the surrounding code, this should be `==` rather than `in`. The code does work as intended, because a string is always a substring of itself, but better to fix it anyway. Seems this was broken since this code was first introduced in commit 94b0fe1599 (Draft: clean up ViewProviderLabel class) --- src/Mod/Draft/draftviewproviders/view_label.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mod/Draft/draftviewproviders/view_label.py b/src/Mod/Draft/draftviewproviders/view_label.py index 0238363287..571b40e000 100644 --- a/src/Mod/Draft/draftviewproviders/view_label.py +++ b/src/Mod/Draft/draftviewproviders/view_label.py @@ -394,7 +394,7 @@ class ViewProviderLabel(ViewProviderDraftAnnotation): if s: self.arrowpos.scaleFactor.setValue((s, s, s)) - elif prop in "Justification" and "Justification" in properties: + elif prop == "Justification" and "Justification" in properties: if vobj.Justification == "Left": self.text2d.justification = coin.SoText2.LEFT self.text3d.justification = coin.SoAsciiText.LEFT From fd8475b1c6b8d7f1cbb05776d740e2ba5dda023a Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Tue, 29 Jun 2021 15:24:03 +0200 Subject: [PATCH 2/4] Draft: Fix SVG generation for label objects Label objects would produce invalid SVG XML, because the stroke-linecap property was added as if it was a style (with : and ;), but it was inserted in the XML tag directly, rather than inside the style attribute value. The invalid SVG prevented for example a TechDraw draft view from rendering when it contained a label. This was added in commit d8c74c06fd (Draft: Using square endcaps for lines in SVG output). This stroke-linecap is supported both as a presentation attribute inside the style or a XML attribute, so for consistency with the surrounding attributes, it is made a normal attribute, rather than putting it inside the style. See also https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-linecap --- src/Mod/Draft/draftfunctions/svg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mod/Draft/draftfunctions/svg.py b/src/Mod/Draft/draftfunctions/svg.py index ba34655dfd..5e53d217ab 100644 --- a/src/Mod/Draft/draftfunctions/svg.py +++ b/src/Mod/Draft/draftfunctions/svg.py @@ -615,7 +615,7 @@ def get_svg(obj, svg_path += 'fill="none" ' svg_path += 'stroke="{}" '.format(stroke) svg_path += 'stroke-width="{}" '.format(linewidth) - svg_path += 'stroke-linecap:square;' + svg_path += 'stroke-linecap="square" ' svg_path += 'd="{}"'.format(path_dir_str) svg_path += '/>' svg += svg_path From be69ec5e005b423cbcddfeecd6963f404652bd76 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Tue, 29 Jun 2021 15:29:57 +0200 Subject: [PATCH 3/4] Draft: Fix mixup of TextAlignment vs Justification for Labels TextAlignment is the vertical alignment, while Justification is the horizontal alignment. here, get_text was passed the vertical, while it expected the horizontal. This caused the alignment of a Label to be wrong in the resulting SVG (e.g. in a TechDraw draft view). This seems to have been broken since SVG support for Labels was first introduced in commit 3391a5ea4b (Initial work, only text (no lines)). --- src/Mod/Draft/draftfunctions/svg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mod/Draft/draftfunctions/svg.py b/src/Mod/Draft/draftfunctions/svg.py index 5e53d217ab..dd5238e1fa 100644 --- a/src/Mod/Draft/draftfunctions/svg.py +++ b/src/Mod/Draft/draftfunctions/svg.py @@ -641,7 +641,7 @@ def get_svg(obj, fontname = obj.ViewObject.TextFont position = get_proj(obj.Placement.Base, plane) rotation = obj.Placement.Rotation - justification = obj.ViewObject.TextAlignment + justification = obj.ViewObject.Justification text = obj.Text svg += svgtext.get_text(plane, techdraw, stroke, fontsize, fontname, From 214e716a8fd3cc49703a4815d0028efd62f8596d Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Sun, 20 Mar 2022 14:54:20 +0100 Subject: [PATCH 4/4] Draft: Simplify using getattr instead of hasattr Using the default argument supported by getattr makes this code a bit simpler and probably (ever so slightly) faster. See https://forum.freecadweb.org/viewtopic.php?f=10&t=58611 for previous discussion. This is not an exhaustive change, these are just a few I encounted while working with the code. --- src/Mod/Draft/draftobjects/shape2dview.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Mod/Draft/draftobjects/shape2dview.py b/src/Mod/Draft/draftobjects/shape2dview.py index 5183da27ce..df08c6ab34 100644 --- a/src/Mod/Draft/draftobjects/shape2dview.py +++ b/src/Mod/Draft/draftobjects/shape2dview.py @@ -184,9 +184,8 @@ class Shape2DView(DraftObject): return nedges def execute(self,obj): - if hasattr(obj,"AutoUpdate"): - if not obj.AutoUpdate: - return True + if not getattr(obj,"AutoUpdate", True): + return True import Part, DraftGeomUtils obj.positionBySupport() pl = obj.Placement @@ -215,7 +214,7 @@ class Shape2DView(DraftObject): if getattr(obj,"VisibleOnly",True): objs = gui_utils.remove_hidden(objs) shapes = [] - if hasattr(obj,"FuseArch") and obj.FuseArch: + if getattr(obj,"FuseArch", False): shtypes = {} for o in objs: if utils.get_type(o) in ["Wall","Structure"]: