0001078: Draft now snaps to center of polygons and cylinders

This commit is contained in:
Yorik van Havre 2013-06-20 21:21:35 -03:00
parent f05be462bc
commit 33faa40101
2 changed files with 18 additions and 0 deletions

View File

@ -301,6 +301,8 @@ def findIntersection(edge1,edge2,infinite1=False,infinite2=False,ex1=False,ex2=F
if dirVec.dot(arc.Curve.Axis) != 0 :
toPlane = Vector(arc.Curve.Axis) ; toPlane.normalize()
d = pt1.dot(toPlane)
if not d:
return []
dToPlane = center.sub(pt1).dot(toPlane)
toPlane = Vector(pt1)
toPlane.scale(dToPlane/d,dToPlane/d,dToPlane/d)

View File

@ -269,6 +269,9 @@ class Snapper:
snaps.append([b,'endpoint',b])
elif obj.isDerivedFrom("Part::Feature"):
if Draft.getType(obj) == "Polygon":
snaps.extend(self.snapToPolygon(obj))
if (not self.maxEdges) or (len(obj.Edges) <= self.maxEdges):
if "Edge" in comp:
# we are snapping to an edge
@ -650,6 +653,19 @@ class Snapper:
for p in pt:
snaps.append([p,'intersection',p])
return snaps
def snapToPolygon(self,obj):
"returns a list of polygon center snap locations"
snaps = []
c = obj.Placement.Base
for edge in obj.Shape.Edges:
p1 = edge.Vertexes[0].Point
p2 = edge.Vertexes[-1].Point
v1 = p1.add((p2-p1).scale(.25,.25,.25))
v2 = p1.add((p2-p1).scale(.75,.75,.75))
snaps.append([v1,'center',c])
snaps.append([v2,'center',c])
return snaps
def snapToVertex(self,info,active=False):
p = Vector(info['x'],info['y'],info['z'])