Bugfixes in Draft Upgrade

This commit is contained in:
Yorik van Havre 2012-03-29 11:57:18 -03:00
parent fd36956061
commit 7b97498f00
2 changed files with 30 additions and 4 deletions

View File

@ -2368,8 +2368,12 @@ class Upgrade(Modifier):
else: else:
# only closed wires # only closed wires
for w in wires: for w in wires:
if fcgeo.isPlanar(w):
f = Part.Face(w) f = Part.Face(w)
faces.append(f) faces.append(f)
else:
msg(translate("draft", "One wire is not planar, upgrade not done\n"))
self.nodelete = True
for f in faces: for f in faces:
if not curves: if not curves:
msg(translate("draft", "Found a closed wire: making a Draft wire\n")) 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()) edges.append(Part.Line(p1,p0).toShape())
w = Part.Wire(fcgeo.sortEdges(edges)) w = Part.Wire(fcgeo.sortEdges(edges))
if len(edges) == 1: if len(edges) == 1:
if len(w.Vertexes) == 2:
msg(translate("draft", "Found 1 open edge: making a line\n")) msg(translate("draft", "Found 1 open edge: making a line\n"))
newob = Draft.makeWire(w,closed=False) 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: else:
msg(translate("draft", "Found 1 open wire: closing it\n")) msg(translate("draft", "Found 1 open wire: closing it\n"))
if not curves: if not curves:

View File

@ -911,6 +911,20 @@ def isCoplanar(faces):
return False return False
return True 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): def findWires(edges):
'''finds connected edges in the list, and returns a list of lists containing edges '''finds connected edges in the list, and returns a list of lists containing edges
that can be connected''' that can be connected'''