fixes in Draft
+ fix in Draft grid snap, point is now always projected on WP + fix in Draft2Sketch when dealing with arcs
This commit is contained in:
parent
bb854f65b7
commit
0de52ff73f
|
@ -1245,6 +1245,7 @@ def makeSketch(objectslist,autoconstraints=False,addTo=None,name="Sketch"):
|
||||||
nobj = addTo
|
nobj = addTo
|
||||||
else:
|
else:
|
||||||
nobj = FreeCAD.ActiveDocument.addObject("Sketcher::SketchObject",name)
|
nobj = FreeCAD.ActiveDocument.addObject("Sketcher::SketchObject",name)
|
||||||
|
nobj.ViewObject.Autoconstraints = False
|
||||||
for obj in objectslist:
|
for obj in objectslist:
|
||||||
ok = False
|
ok = False
|
||||||
tp = getType(obj)
|
tp = getType(obj)
|
||||||
|
@ -1297,7 +1298,9 @@ def makeSketch(objectslist,autoconstraints=False,addTo=None,name="Sketch"):
|
||||||
if fcgeo.hasOnlyWires(obj.Shape):
|
if fcgeo.hasOnlyWires(obj.Shape):
|
||||||
for w in obj.Shape.Wires:
|
for w in obj.Shape.Wires:
|
||||||
for edge in fcgeo.sortEdges(w.Edges):
|
for edge in fcgeo.sortEdges(w.Edges):
|
||||||
nobj.addGeometry(fcgeo.geom(edge))
|
g = fcgeo.geom(edge)
|
||||||
|
if g:
|
||||||
|
nobj.addGeometry(g)
|
||||||
if autoconstraints:
|
if autoconstraints:
|
||||||
last = nobj.GeometryCount
|
last = nobj.GeometryCount
|
||||||
segs = range(last-len(w.Edges),last-1)
|
segs = range(last-len(w.Edges),last-1)
|
||||||
|
|
|
@ -152,7 +152,7 @@ class Snapper:
|
||||||
if self.extLine:
|
if self.extLine:
|
||||||
self.extLine.off()
|
self.extLine.off()
|
||||||
|
|
||||||
point = FreeCADGui.ActiveDocument.ActiveView.getPoint(screenpos[0],screenpos[1])
|
point = self.getApparentPoint(screenpos[0],screenpos[1])
|
||||||
|
|
||||||
# check if we snapped to something
|
# check if we snapped to something
|
||||||
info = FreeCADGui.ActiveDocument.ActiveView.getObjectInfo((screenpos[0],screenpos[1]))
|
info = FreeCADGui.ActiveDocument.ActiveView.getObjectInfo((screenpos[0],screenpos[1]))
|
||||||
|
@ -260,6 +260,12 @@ class Snapper:
|
||||||
# return the final point
|
# return the final point
|
||||||
return cstr(winner[2])
|
return cstr(winner[2])
|
||||||
|
|
||||||
|
def getApparentPoint(self,x,y):
|
||||||
|
"returns a 3D point, projected on the current working plane"
|
||||||
|
pt = FreeCADGui.ActiveDocument.ActiveView.getPoint(x,y)
|
||||||
|
dv = FreeCADGui.ActiveDocument.ActiveView.getViewDirection()
|
||||||
|
return FreeCAD.DraftWorkingPlane.projectPoint(pt,dv)
|
||||||
|
|
||||||
def snapToExtensions(self,point,last,constrain):
|
def snapToExtensions(self,point,last,constrain):
|
||||||
"returns a point snapped to extension or parallel line to last object, if any"
|
"returns a point snapped to extension or parallel line to last object, if any"
|
||||||
|
|
||||||
|
|
|
@ -3545,6 +3545,9 @@ class Draft2Sketch():
|
||||||
allDraft = False
|
allDraft = False
|
||||||
elif obj.isDerivedFrom("Part::Part2DObjectPython"):
|
elif obj.isDerivedFrom("Part::Part2DObjectPython"):
|
||||||
allSketches = False
|
allSketches = False
|
||||||
|
else:
|
||||||
|
allDraft = False
|
||||||
|
allSketches = False
|
||||||
if not sel:
|
if not sel:
|
||||||
return
|
return
|
||||||
elif allDraft:
|
elif allDraft:
|
||||||
|
@ -3559,9 +3562,12 @@ class Draft2Sketch():
|
||||||
FreeCAD.ActiveDocument.openTransaction("Convert")
|
FreeCAD.ActiveDocument.openTransaction("Convert")
|
||||||
for obj in sel:
|
for obj in sel:
|
||||||
if obj.isDerivedFrom("Sketcher::SketchObject"):
|
if obj.isDerivedFrom("Sketcher::SketchObject"):
|
||||||
Draft.makeSketch(sel,autoconstraints=True)
|
Draft.draftify(obj)
|
||||||
elif obj.isDerivedFrom("Part::Part2DObjectPython"):
|
elif obj.isDerivedFrom("Part::Part2DObjectPython"):
|
||||||
Draft.draftify(sel,makeblock=True)
|
Draft.makeSketch(obj,autoconstraints=True)
|
||||||
|
elif obj.isDerivedFrom("Part::Feature"):
|
||||||
|
if len(obj.Shape.Wires) == 1:
|
||||||
|
Draft.makeSketch(obj,autoconstraints=False)
|
||||||
FreeCAD.ActiveDocument.commitTransaction()
|
FreeCAD.ActiveDocument.commitTransaction()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -361,14 +361,17 @@ def geom(edge):
|
||||||
return edge.Curve
|
return edge.Curve
|
||||||
elif isinstance(edge.Curve,Part.Circle):
|
elif isinstance(edge.Curve,Part.Circle):
|
||||||
if len(edge.Vertexes) == 1:
|
if len(edge.Vertexes) == 1:
|
||||||
return edge.Curve
|
return Part.Circle(edge.Curve.Center,edge.Curve.Axis,edge.Curve.Radius)
|
||||||
else:
|
else:
|
||||||
|
ref = edge.Placement.multVec(Vector(1,0,0))
|
||||||
v1 = edge.Vertexes[0].Point
|
v1 = edge.Vertexes[0].Point
|
||||||
v2 = edge.Vertexes[-1].Point
|
v2 = edge.Vertexes[-1].Point
|
||||||
c = edge.Curve.Center
|
c = edge.Curve.Center
|
||||||
a1 = -fcvec.angle(v1.sub(c))
|
cu = Part.Circle(edge.Curve.Center,edge.Curve.Axis,edge.Curve.Radius)
|
||||||
a2 = -fcvec.angle(v2.sub(c))
|
a1 = -fcvec.angle(v1.sub(c),ref)
|
||||||
return Part.ArcOfCircle(edge.Curve,a1,a2)
|
a2 = -fcvec.angle(v2.sub(c),ref)
|
||||||
|
p= Part.ArcOfCircle(cu,a1,a2)
|
||||||
|
return p
|
||||||
else:
|
else:
|
||||||
return edge.Curve
|
return edge.Curve
|
||||||
|
|
||||||
|
@ -764,12 +767,20 @@ def connect(edges,closed=False):
|
||||||
next = None
|
next = None
|
||||||
if prev:
|
if prev:
|
||||||
# print "debug: fcgeo.connect prev : ",prev.Vertexes[0].Point,prev.Vertexes[-1].Point
|
# print "debug: fcgeo.connect prev : ",prev.Vertexes[0].Point,prev.Vertexes[-1].Point
|
||||||
v1 = findIntersection(curr,prev,True,True)[0]
|
i = findIntersection(curr,prev,True,True)
|
||||||
|
if i:
|
||||||
|
v1 = i[0]
|
||||||
|
else:
|
||||||
|
v1 = curr.Vertexes[0].Point
|
||||||
else:
|
else:
|
||||||
v1 = curr.Vertexes[0].Point
|
v1 = curr.Vertexes[0].Point
|
||||||
if next:
|
if next:
|
||||||
# print "debug: fcgeo.connect next : ",next.Vertexes[0].Point,next.Vertexes[-1].Point
|
# print "debug: fcgeo.connect next : ",next.Vertexes[0].Point,next.Vertexes[-1].Point
|
||||||
v2 = findIntersection(curr,next,True,True)[0]
|
i = findIntersection(curr,next,True,True)
|
||||||
|
if i:
|
||||||
|
v2 = i[0]
|
||||||
|
else:
|
||||||
|
v2 = curr.Vertexes[-1].Point
|
||||||
else:
|
else:
|
||||||
v2 = curr.Vertexes[-1].Point
|
v2 = curr.Vertexes[-1].Point
|
||||||
if isinstance(curr.Curve,Part.Line):
|
if isinstance(curr.Curve,Part.Line):
|
||||||
|
@ -778,7 +789,10 @@ def connect(edges,closed=False):
|
||||||
elif isinstance(curr.Curve,Part.Circle):
|
elif isinstance(curr.Curve,Part.Circle):
|
||||||
if v1 != v2:
|
if v1 != v2:
|
||||||
nedges.append(Part.Arc(v1,findMidPoint(curr),v2))
|
nedges.append(Part.Arc(v1,findMidPoint(curr),v2))
|
||||||
return Part.Wire(nedges)
|
try:
|
||||||
|
return Part.Wire(nedges)
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
|
||||||
def findDistance(point,edge,strict=False):
|
def findDistance(point,edge,strict=False):
|
||||||
'''
|
'''
|
||||||
|
|
Loading…
Reference in New Issue
Block a user