0000634: Draft to Sketch conversion

This commit is contained in:
Yorik van Havre 2012-08-11 18:28:18 -03:00
parent 1859ec2559
commit 7a338f30cb
3 changed files with 38 additions and 38 deletions

View File

@ -1562,10 +1562,8 @@ def makeSketch(objectslist,autoconstraints=False,addTo=None,name="Sketch"):
if tp == "BSpline":
print "makeSketch: BSplines not supported"
elif tp == "Circle":
if obj.FirstAngle == obj.LastAngle:
nobj.addGeometry(obj.Shape.Edges[0].Curve)
else:
nobj.addGeometry(Part.ArcOfCircle(obj.Shape.Edges[0].Curve,math.radians(obj.FirstAngle),math.radians(obj.LastAngle)))
g = (DraftGeomUtils.geom(obj.Shape.Edges[0],nobj.Placement))
nobj.addGeometry(g)
# TODO add Radius constraits
ok = True
elif tp == "Rectangle":
@ -1586,6 +1584,7 @@ def makeSketch(objectslist,autoconstraints=False,addTo=None,name="Sketch"):
nobj.addConstraint(Constraint("Vertical",last))
ok = True
elif tp in ["Wire","Polygon"]:
if obj.FilletRadius == 0:
closed = False
if tp == "Polygon":
closed = True

View File

@ -370,17 +370,18 @@ def geom(edge,plac=FreeCAD.Placement()):
c = edge.Curve.Center
cu = Part.Circle(edge.Curve.Center,normal,edge.Curve.Radius)
ref = plac.Rotation.multVec(Vector(1,0,0))
a1 = math.pi + DraftVecUtils.angle(v1.sub(c),ref,normal)
a2 = DraftVecUtils.angle(v2.sub(c),ref,normal)
a1 = DraftVecUtils.angle(v1.sub(c),ref,DraftVecUtils.neg(normal))
a2 = DraftVecUtils.angle(v2.sub(c),ref,DraftVecUtils.neg(normal))
# direction check
if a1 > a2:
if edge.Curve.Axis.getAngle(normal) > 1:
a1,a2 = a2,a1
#print "creating sketch arc from ",cu, ", p1=",v1, " (",math.degrees(a1), "d) p2=",v2," (", math.degrees(a2),"d)"
p= Part.ArcOfCircle(cu,a1,a2)
return p
else:
print edge.Curve
return edge.Curve
def mirror (point, edge):
@ -772,8 +773,8 @@ def getNormal(shape):
if (shape.ShapeType == "Face") and hasattr(shape,"normalAt"):
n = shape.normalAt(0.5,0.5)
elif shape.ShapeType == "Edge":
if isinstance(shape.Curve,Part.Circle):
n = shape.Curve.Axis
if isinstance(shape.Edges[0].Curve,Part.Circle):
n = shape.Edges[0].Curve.Axis
else:
for e in shape.Edges:
if isinstance(e.Curve,Part.Circle):

View File

@ -3711,7 +3711,7 @@ class Draft2Sketch():
elif obj.isDerivedFrom("Part::Part2DObjectPython"):
Draft.makeSketch(obj,autoconstraints=True)
elif obj.isDerivedFrom("Part::Feature"):
if len(obj.Shape.Wires) == 1:
if (len(obj.Shape.Wires) == 1) or (len(obj.Shape.Edges) == 1):
Draft.makeSketch(obj,autoconstraints=False)
FreeCAD.ActiveDocument.commitTransaction()