From 7b97498f003d4baea9ef1cfa59c618fd2bcdb850 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Thu, 29 Mar 2012 11:57:18 -0300 Subject: [PATCH] Bugfixes in Draft Upgrade --- src/Mod/Draft/DraftTools.py | 20 ++++++++++++++++---- src/Mod/Draft/draftlibs/fcgeo.py | 14 ++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/Mod/Draft/DraftTools.py b/src/Mod/Draft/DraftTools.py index f5c056ed7..324aad4a5 100644 --- a/src/Mod/Draft/DraftTools.py +++ b/src/Mod/Draft/DraftTools.py @@ -2368,8 +2368,12 @@ class Upgrade(Modifier): else: # only closed wires for w in wires: - f = Part.Face(w) - faces.append(f) + if fcgeo.isPlanar(w): + f = Part.Face(w) + faces.append(f) + else: + msg(translate("draft", "One wire is not planar, upgrade not done\n")) + self.nodelete = True for f in faces: if not curves: msg(translate("draft", "Found a closed wire: making a Draft wire\n")) @@ -2390,8 +2394,16 @@ class Upgrade(Modifier): edges.append(Part.Line(p1,p0).toShape()) w = Part.Wire(fcgeo.sortEdges(edges)) if len(edges) == 1: - msg(translate("draft", "Found 1 open edge: making a line\n")) - newob = Draft.makeWire(w,closed=False) + if len(w.Vertexes) == 2: + msg(translate("draft", "Found 1 open edge: making a line\n")) + newob = Draft.makeWire(w,closed=False) + elif len(w.Vertexes) == 1: + msg(translate("draft", "Found 1 circular edge: making a circle\n")) + c = w.Edges[0].Curve.Center + r = w.Edges[0].Curve.Radius + p = FreeCAD.Placement() + p.move(c) + newob = Draft.makeCircle(r,p) else: msg(translate("draft", "Found 1 open wire: closing it\n")) if not curves: diff --git a/src/Mod/Draft/draftlibs/fcgeo.py b/src/Mod/Draft/draftlibs/fcgeo.py index 9863a2b1a..ee38aa8ee 100755 --- a/src/Mod/Draft/draftlibs/fcgeo.py +++ b/src/Mod/Draft/draftlibs/fcgeo.py @@ -911,6 +911,20 @@ def isCoplanar(faces): return False return True +def isPlanar(shape): + "checks if the given shape is planar" + if len(shape.Vertexes) <= 3: + return True + pts = [v.Point for v in shape.Vertexes[0:3]] + bt = Part.Face(Part.makePolygon(pts+[pts[0]])) + n = bt.normalAt(0,0) + for p in shape.Vertexes[3:]: + pv = p.Point.sub(pts[0]) + rv = fcvec.project(pv,n) + if not fcvec.isNull(rv): + return False + return True + def findWires(edges): '''finds connected edges in the list, and returns a list of lists containing edges that can be connected'''