From 24caf8dab184d7acadbe1cbb5aafde109581013d Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Wed, 28 Aug 2019 20:09:25 -0300 Subject: [PATCH] Draft: Fixed text color and faces with holes in SVG rendering --- src/Mod/Draft/DraftGeomUtils.py | 37 ++++++++++++++++++++------------- src/Mod/Draft/getSVG.py | 18 ++++++++++++---- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/Mod/Draft/DraftGeomUtils.py b/src/Mod/Draft/DraftGeomUtils.py index 45dd4942bc..ac54097671 100644 --- a/src/Mod/Draft/DraftGeomUtils.py +++ b/src/Mod/Draft/DraftGeomUtils.py @@ -872,21 +872,28 @@ def sortEdgesOld(lEdges, aVertex=None): return [] -def invert(edge): - '''invert(edge): returns an inverted copy of this edge''' - if len(edge.Vertexes) == 1: - return edge - if geomType(edge) == "Line": - return Part.LineSegment(edge.Vertexes[-1].Point,edge.Vertexes[0].Point).toShape() - elif geomType(edge) == "Circle": - mp = findMidpoint(edge) - return Part.Arc(edge.Vertexes[-1].Point,mp,edge.Vertexes[0].Point).toShape() - elif geomType(edge) in ["BSplineCurve","BezierCurve"]: - if isLine(edge.Curve): - return Part.LineSegment(edge.Vertexes[-1].Point,edge.Vertexes[0].Point).toShape() - print("DraftGeomUtils.invert: unable to invert ",edge.Curve) - return edge - +def invert(shape): + '''invert(edge): returns an inverted copy of this edge or wire''' + if shape.ShapeType == "Wire": + edges = [invert(edge) for edge in shape.OrderedEdges] + edges.reverse() + return Part.Wire(edges) + elif shape.ShapeType == "Edge": + if len(shape.Vertexes) == 1: + return shape + if geomType(shape) == "Line": + return Part.LineSegment(shape.Vertexes[-1].Point,shape.Vertexes[0].Point).toShape() + elif geomType(shape) == "Circle": + mp = findMidpoint(shape) + return Part.Arc(shape.Vertexes[-1].Point,mp,shape.Vertexes[0].Point).toShape() + elif geomType(shape) in ["BSplineCurve","BezierCurve"]: + if isLine(shape.Curve): + return Part.LineSegment(shape.Vertexes[-1].Point,shape.Vertexes[0].Point).toShape() + print("DraftGeomUtils.invert: unable to invert",shape.Curve) + return shape + else: + print("DraftGeomUtils.invert: unable to handle",shape.ShapeType) + return shape def flattenWire(wire): '''flattenWire(wire): forces a wire to get completely flat diff --git a/src/Mod/Draft/getSVG.py b/src/Mod/Draft/getSVG.py index 9ae8eeb1f5..97a4fa2049 100644 --- a/src/Mod/Draft/getSVG.py +++ b/src/Mod/Draft/getSVG.py @@ -1,7 +1,6 @@ import six import FreeCAD, math, os, DraftVecUtils, WorkingPlane -import Part, DraftGeomUtils from FreeCAD import Vector from Draft import getType, getrgb, svgpatterns, gui @@ -75,6 +74,8 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct any text). You can also supply an arbitrary projection vector. the scale parameter allows to scale linewidths down, so they are resolution-independant.''' + import Part, DraftGeomUtils + # if this is a group, gather all the svg views of its children if hasattr(obj,"isDerivedFrom"): if obj.isDerivedFrom("App::DocumentObjectGroup") or getType(obj) == "Layer": @@ -130,7 +131,7 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct lstyle = getLineStyle(obj.ViewObject.DrawStyle, scale) def getPath(edges=[],wires=[],pathname=None): - import Part,DraftGeomUtils + svg = "\n' else: - svg = '