0000634: Draft to Sketch conversion
This commit is contained in:
parent
1859ec2559
commit
7a338f30cb
|
@ -1562,10 +1562,8 @@ def makeSketch(objectslist,autoconstraints=False,addTo=None,name="Sketch"):
|
||||||
if tp == "BSpline":
|
if tp == "BSpline":
|
||||||
print "makeSketch: BSplines not supported"
|
print "makeSketch: BSplines not supported"
|
||||||
elif tp == "Circle":
|
elif tp == "Circle":
|
||||||
if obj.FirstAngle == obj.LastAngle:
|
g = (DraftGeomUtils.geom(obj.Shape.Edges[0],nobj.Placement))
|
||||||
nobj.addGeometry(obj.Shape.Edges[0].Curve)
|
nobj.addGeometry(g)
|
||||||
else:
|
|
||||||
nobj.addGeometry(Part.ArcOfCircle(obj.Shape.Edges[0].Curve,math.radians(obj.FirstAngle),math.radians(obj.LastAngle)))
|
|
||||||
# TODO add Radius constraits
|
# TODO add Radius constraits
|
||||||
ok = True
|
ok = True
|
||||||
elif tp == "Rectangle":
|
elif tp == "Rectangle":
|
||||||
|
@ -1586,6 +1584,7 @@ def makeSketch(objectslist,autoconstraints=False,addTo=None,name="Sketch"):
|
||||||
nobj.addConstraint(Constraint("Vertical",last))
|
nobj.addConstraint(Constraint("Vertical",last))
|
||||||
ok = True
|
ok = True
|
||||||
elif tp in ["Wire","Polygon"]:
|
elif tp in ["Wire","Polygon"]:
|
||||||
|
if obj.FilletRadius == 0:
|
||||||
closed = False
|
closed = False
|
||||||
if tp == "Polygon":
|
if tp == "Polygon":
|
||||||
closed = True
|
closed = True
|
||||||
|
|
|
@ -370,17 +370,18 @@ def geom(edge,plac=FreeCAD.Placement()):
|
||||||
c = edge.Curve.Center
|
c = edge.Curve.Center
|
||||||
cu = Part.Circle(edge.Curve.Center,normal,edge.Curve.Radius)
|
cu = Part.Circle(edge.Curve.Center,normal,edge.Curve.Radius)
|
||||||
ref = plac.Rotation.multVec(Vector(1,0,0))
|
ref = plac.Rotation.multVec(Vector(1,0,0))
|
||||||
a1 = math.pi + DraftVecUtils.angle(v1.sub(c),ref,normal)
|
a1 = DraftVecUtils.angle(v1.sub(c),ref,DraftVecUtils.neg(normal))
|
||||||
a2 = DraftVecUtils.angle(v2.sub(c),ref,normal)
|
a2 = DraftVecUtils.angle(v2.sub(c),ref,DraftVecUtils.neg(normal))
|
||||||
|
|
||||||
# direction check
|
# direction check
|
||||||
if a1 > a2:
|
if edge.Curve.Axis.getAngle(normal) > 1:
|
||||||
a1,a2 = a2,a1
|
a1,a2 = a2,a1
|
||||||
|
|
||||||
#print "creating sketch arc from ",cu, ", p1=",v1, " (",math.degrees(a1), "d) p2=",v2," (", math.degrees(a2),"d)"
|
#print "creating sketch arc from ",cu, ", p1=",v1, " (",math.degrees(a1), "d) p2=",v2," (", math.degrees(a2),"d)"
|
||||||
|
|
||||||
p= Part.ArcOfCircle(cu,a1,a2)
|
p= Part.ArcOfCircle(cu,a1,a2)
|
||||||
return p
|
return p
|
||||||
else:
|
else:
|
||||||
|
print edge.Curve
|
||||||
return edge.Curve
|
return edge.Curve
|
||||||
|
|
||||||
def mirror (point, edge):
|
def mirror (point, edge):
|
||||||
|
@ -772,8 +773,8 @@ def getNormal(shape):
|
||||||
if (shape.ShapeType == "Face") and hasattr(shape,"normalAt"):
|
if (shape.ShapeType == "Face") and hasattr(shape,"normalAt"):
|
||||||
n = shape.normalAt(0.5,0.5)
|
n = shape.normalAt(0.5,0.5)
|
||||||
elif shape.ShapeType == "Edge":
|
elif shape.ShapeType == "Edge":
|
||||||
if isinstance(shape.Curve,Part.Circle):
|
if isinstance(shape.Edges[0].Curve,Part.Circle):
|
||||||
n = shape.Curve.Axis
|
n = shape.Edges[0].Curve.Axis
|
||||||
else:
|
else:
|
||||||
for e in shape.Edges:
|
for e in shape.Edges:
|
||||||
if isinstance(e.Curve,Part.Circle):
|
if isinstance(e.Curve,Part.Circle):
|
||||||
|
|
|
@ -3711,7 +3711,7 @@ class Draft2Sketch():
|
||||||
elif obj.isDerivedFrom("Part::Part2DObjectPython"):
|
elif obj.isDerivedFrom("Part::Part2DObjectPython"):
|
||||||
Draft.makeSketch(obj,autoconstraints=True)
|
Draft.makeSketch(obj,autoconstraints=True)
|
||||||
elif obj.isDerivedFrom("Part::Feature"):
|
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)
|
Draft.makeSketch(obj,autoconstraints=False)
|
||||||
FreeCAD.ActiveDocument.commitTransaction()
|
FreeCAD.ActiveDocument.commitTransaction()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user