From a4cd4bea21923daa0e3042138acddcc0fab135f7 Mon Sep 17 00:00:00 2001 From: vocx-fc Date: Fri, 2 Aug 2019 15:43:52 -0500 Subject: [PATCH] Draft: importSVG.py, 4 space indentation, 5/? lines, polylines, ellipses --- src/Mod/Draft/importSVG.py | 138 ++++++++++++++++++------------------- 1 file changed, 69 insertions(+), 69 deletions(-) diff --git a/src/Mod/Draft/importSVG.py b/src/Mod/Draft/importSVG.py index 88c26ba127..9d5773bed7 100644 --- a/src/Mod/Draft/importSVG.py +++ b/src/Mod/Draft/importSVG.py @@ -1232,83 +1232,83 @@ class svgHandler(xml.sax.ContentHandler): if self.currentsymbol: self.symbols[self.currentsymbol].append(obj) - # Process lines - if name == "line": - if not pathname: - pathname = 'Line' - p1 = Vector(data['x1'], -data['y1'], 0) - p2 = Vector(data['x2'], -data['y2'], 0) - sh = Part.LineSegment(p1, p2).toShape() - sh = self.applyTrans(sh) - obj = self.doc.addObject("Part::Feature", pathname) - obj.Shape = sh - self.format(obj) - if self.currentsymbol: - self.symbols[self.currentsymbol].append(obj) + # Process lines + if name == "line": + if not pathname: + pathname = 'Line' + p1 = Vector(data['x1'], -data['y1'], 0) + p2 = Vector(data['x2'], -data['y2'], 0) + sh = Part.LineSegment(p1, p2).toShape() + sh = self.applyTrans(sh) + obj = self.doc.addObject("Part::Feature", pathname) + obj.Shape = sh + self.format(obj) + if self.currentsymbol: + self.symbols[self.currentsymbol].append(obj) - # Process polylines and polygons - if name == "polyline" or name == "polygon": - # A simpler implementation would be - # sh = Part.makePolygon([Vector(svgx,-svgy,0) for svgx,svgy in zip(points[0::2],points[1::2])]) - # - # but it would be more difficult to search for duplicate - # points beforehand. - if not pathname: - pathname = 'Polyline' - points = [float(d) for d in data['points']] - FreeCAD.Console.PrintMessage('points %s\n' % str(points)) - lenpoints = len(points) - if lenpoints >= 4 and lenpoints % 2 == 0: - lastvec = Vector(points[0], -points[1], 0) - path = [] - if name == 'polygon': - points = points+points[:2] # emulate closepath - for svgx, svgy in zip(points[2::2], points[3::2]): - currentvec = Vector(svgx, -svgy, 0) - if not DraftVecUtils.equals(lastvec, currentvec): - seg = Part.LineSegment(lastvec, currentvec).toShape() - #print "polyline seg ",lastvec,currentvec - lastvec = currentvec - path.append(seg) - if path: - sh = Part.Wire(path) - if self.fill and sh.isClosed(): - sh = Part.Face(sh) - sh = self.applyTrans(sh) - obj = self.doc.addObject("Part::Feature", pathname) - obj.Shape = sh - if self.currentsymbol: - self.symbols[self.currentsymbol].append(obj) - - # Process ellipses - if name == "ellipse": - if not pathname: - pathname = 'Ellipse' - c = Vector(data.get('cx', 0), -data.get('cy', 0), 0) - rx = data['rx'] - ry = data['ry'] - if rx > ry: - sh = Part.Ellipse(c, rx, ry).toShape() - else: - sh = Part.Ellipse(c, ry, rx).toShape() - m3 = FreeCAD.Matrix() - m3.move(c) - # 90 - rot90 = FreeCAD.Matrix(0, -1, 0, 0, 1, 0) - m3 = m3.multiply(rot90) - m3.move(c.multiply(-1)) - sh.transformShape(m3) - # sh = sh.transformGeometry(m3) - if self.fill: - sh = Part.Wire([sh]) + # Process polylines and polygons + if name == "polyline" or name == "polygon": + # A simpler implementation would be + # sh = Part.makePolygon([Vector(svgx,-svgy,0) for svgx,svgy in zip(points[0::2],points[1::2])]) + # + # but it would be more difficult to search for duplicate + # points beforehand. + if not pathname: + pathname = 'Polyline' + points = [float(d) for d in data['points']] + FreeCAD.Console.PrintMessage('points %s\n' % str(points)) + lenpoints = len(points) + if lenpoints >= 4 and lenpoints % 2 == 0: + lastvec = Vector(points[0], -points[1], 0) + path = [] + if name == 'polygon': + points = points+points[:2] # emulate closepath + for svgx, svgy in zip(points[2::2], points[3::2]): + currentvec = Vector(svgx, -svgy, 0) + if not DraftVecUtils.equals(lastvec, currentvec): + seg = Part.LineSegment(lastvec, currentvec).toShape() + #print "polyline seg ",lastvec,currentvec + lastvec = currentvec + path.append(seg) + if path: + sh = Part.Wire(path) + if self.fill and sh.isClosed(): sh = Part.Face(sh) sh = self.applyTrans(sh) obj = self.doc.addObject("Part::Feature", pathname) obj.Shape = sh - self.format(obj) if self.currentsymbol: self.symbols[self.currentsymbol].append(obj) + # Process ellipses + if name == "ellipse": + if not pathname: + pathname = 'Ellipse' + c = Vector(data.get('cx', 0), -data.get('cy', 0), 0) + rx = data['rx'] + ry = data['ry'] + if rx > ry: + sh = Part.Ellipse(c, rx, ry).toShape() + else: + sh = Part.Ellipse(c, ry, rx).toShape() + m3 = FreeCAD.Matrix() + m3.move(c) + # 90 + rot90 = FreeCAD.Matrix(0, -1, 0, 0, 1, 0) + m3 = m3.multiply(rot90) + m3.move(c.multiply(-1)) + sh.transformShape(m3) + # sh = sh.transformGeometry(m3) + if self.fill: + sh = Part.Wire([sh]) + sh = Part.Face(sh) + sh = self.applyTrans(sh) + obj = self.doc.addObject("Part::Feature", pathname) + obj.Shape = sh + self.format(obj) + if self.currentsymbol: + self.symbols[self.currentsymbol].append(obj) + # Process circles if (name == "circle") and (not ("freecad:skip" in data)) : if not pathname: