Added polar snap locations to Draft snap system
This commit is contained in:
parent
eb12bc8508
commit
813424e90d
|
@ -157,8 +157,10 @@ class Snapper:
|
||||||
# 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]))
|
||||||
|
|
||||||
# checking if parallel to one of the edges of the last objects
|
# checking if parallel to one of the edges of the last objects or to a polar direction
|
||||||
point = self.snapToExtensions(point,lastpoint,constrain)
|
eline = None
|
||||||
|
point,eline = self.snapToPolar(point,lastpoint)
|
||||||
|
point,eline = self.snapToExtensions(point,lastpoint,constrain,eline)
|
||||||
|
|
||||||
if not info:
|
if not info:
|
||||||
|
|
||||||
|
@ -195,8 +197,9 @@ class Snapper:
|
||||||
snaps.extend(self.snapToEndpoints(edge))
|
snaps.extend(self.snapToEndpoints(edge))
|
||||||
snaps.extend(self.snapToMidpoint(edge))
|
snaps.extend(self.snapToMidpoint(edge))
|
||||||
snaps.extend(self.snapToPerpendicular(edge,lastpoint))
|
snaps.extend(self.snapToPerpendicular(edge,lastpoint))
|
||||||
snaps.extend(self.snapToOrtho(edge,lastpoint,constrain))
|
#snaps.extend(self.snapToOrtho(edge,lastpoint,constrain)) # now part of snapToPolar
|
||||||
snaps.extend(self.snapToIntersection(edge))
|
snaps.extend(self.snapToIntersection(edge))
|
||||||
|
snaps.extend(self.snapToElines(edge,eline))
|
||||||
|
|
||||||
if isinstance (edge.Curve,Part.Circle):
|
if isinstance (edge.Curve,Part.Circle):
|
||||||
# the edge is an arc, we have extra options
|
# the edge is an arc, we have extra options
|
||||||
|
@ -266,10 +269,10 @@ class Snapper:
|
||||||
dv = FreeCADGui.ActiveDocument.ActiveView.getViewDirection()
|
dv = FreeCADGui.ActiveDocument.ActiveView.getViewDirection()
|
||||||
return FreeCAD.DraftWorkingPlane.projectPoint(pt,dv)
|
return FreeCAD.DraftWorkingPlane.projectPoint(pt,dv)
|
||||||
|
|
||||||
def snapToExtensions(self,point,last,constrain):
|
def snapToExtensions(self,point,last,constrain,eline):
|
||||||
"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"
|
||||||
|
|
||||||
tsnap = self.snapToExtOrtho(last,constrain)
|
tsnap = self.snapToExtOrtho(last,constrain,eline)
|
||||||
if tsnap:
|
if tsnap:
|
||||||
if (tsnap[0].sub(point)).Length < self.radius:
|
if (tsnap[0].sub(point)).Length < self.radius:
|
||||||
if self.tracker:
|
if self.tracker:
|
||||||
|
@ -280,7 +283,7 @@ class Snapper:
|
||||||
self.extLine.p2(tsnap[2])
|
self.extLine.p2(tsnap[2])
|
||||||
self.extLine.on()
|
self.extLine.on()
|
||||||
self.setCursor(tsnap[1])
|
self.setCursor(tsnap[1])
|
||||||
return tsnap[2]
|
return tsnap[2],eline
|
||||||
|
|
||||||
for o in [self.lastObj[1],self.lastObj[0]]:
|
for o in [self.lastObj[1],self.lastObj[0]]:
|
||||||
if o:
|
if o:
|
||||||
|
@ -303,7 +306,7 @@ class Snapper:
|
||||||
self.extLine.p2(np)
|
self.extLine.p2(np)
|
||||||
self.extLine.on()
|
self.extLine.on()
|
||||||
self.setCursor('extension')
|
self.setCursor('extension')
|
||||||
return np
|
return np,Part.Line(e.Vertexes[0].Point,np).toShape()
|
||||||
else:
|
else:
|
||||||
if last:
|
if last:
|
||||||
de = Part.Line(last,last.add(fcgeo.vec(e))).toShape()
|
de = Part.Line(last,last.add(fcgeo.vec(e))).toShape()
|
||||||
|
@ -314,8 +317,37 @@ class Snapper:
|
||||||
self.tracker.setMarker(self.mk['parallel'])
|
self.tracker.setMarker(self.mk['parallel'])
|
||||||
self.tracker.on()
|
self.tracker.on()
|
||||||
self.setCursor('extension')
|
self.setCursor('extension')
|
||||||
return np
|
return np,de
|
||||||
return point
|
return point,eline
|
||||||
|
|
||||||
|
def snapToPolar(self,point,last):
|
||||||
|
"snaps to polar lines from the given point"
|
||||||
|
polarAngles = [90,45]
|
||||||
|
if last:
|
||||||
|
vecs = []
|
||||||
|
ax = [FreeCAD.DraftWorkingPlane.u,
|
||||||
|
FreeCAD.DraftWorkingPlane.v,
|
||||||
|
FreeCAD.DraftWorkingPlane.axis]
|
||||||
|
for a in polarAngles:
|
||||||
|
if a == 90:
|
||||||
|
vecs.extend([ax[0],fcvec.neg(ax[0])])
|
||||||
|
vecs.extend([ax[1],fcvec.neg(ax[1])])
|
||||||
|
else:
|
||||||
|
v = fcvec.rotate(ax[0],math.radians(a),ax[2])
|
||||||
|
vecs.extend([v,fcvec.neg(v)])
|
||||||
|
v = fcvec.rotate(ax[1],math.radians(a),ax[2])
|
||||||
|
vecs.extend([v,fcvec.neg(v)])
|
||||||
|
for v in vecs:
|
||||||
|
de = Part.Line(last,last.add(v)).toShape()
|
||||||
|
np = self.getPerpendicular(de,point)
|
||||||
|
if (np.sub(point)).Length < self.radius:
|
||||||
|
if self.tracker:
|
||||||
|
self.tracker.setCoords(np)
|
||||||
|
self.tracker.setMarker(self.mk['parallel'])
|
||||||
|
self.tracker.on()
|
||||||
|
self.setCursor('ortho')
|
||||||
|
return np,de
|
||||||
|
return point,None
|
||||||
|
|
||||||
def snapToGrid(self,point):
|
def snapToGrid(self,point):
|
||||||
"returns a grid snap point if available"
|
"returns a grid snap point if available"
|
||||||
|
@ -390,7 +422,7 @@ class Snapper:
|
||||||
snaps.append([p,'ortho',p])
|
snaps.append([p,'ortho',p])
|
||||||
return snaps
|
return snaps
|
||||||
|
|
||||||
def snapToExtOrtho(self,last,constrain):
|
def snapToExtOrtho(self,last,constrain,eline):
|
||||||
"returns an ortho X extension snap location"
|
"returns an ortho X extension snap location"
|
||||||
if constrain and last and self.constraintAxis and self.extLine:
|
if constrain and last and self.constraintAxis and self.extLine:
|
||||||
tmpEdge1 = Part.Line(last,last.add(self.constraintAxis)).toShape()
|
tmpEdge1 = Part.Line(last,last.add(self.constraintAxis)).toShape()
|
||||||
|
@ -399,8 +431,26 @@ class Snapper:
|
||||||
pt = fcgeo.findIntersection(tmpEdge1,tmpEdge2,True,True)
|
pt = fcgeo.findIntersection(tmpEdge1,tmpEdge2,True,True)
|
||||||
if pt:
|
if pt:
|
||||||
return [pt[0],'ortho',pt[0]]
|
return [pt[0],'ortho',pt[0]]
|
||||||
|
if eline:
|
||||||
|
tmpEdge2 = Part.Line(self.extLine.p1(),self.extLine.p2()).toShape()
|
||||||
|
# get the intersection points
|
||||||
|
pt = fcgeo.findIntersection(eline,tmpEdge2,True,True)
|
||||||
|
if pt:
|
||||||
|
return [pt[0],'ortho',pt[0]]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def snapToElines(self,e1,e2):
|
||||||
|
"returns a snap location at the infinite intersection of the given edges"
|
||||||
|
snaps = []
|
||||||
|
if e1 and e2:
|
||||||
|
# get the intersection points
|
||||||
|
pts = fcgeo.findIntersection(e1,e2,True,True)
|
||||||
|
if pts:
|
||||||
|
for p in pts:
|
||||||
|
snaps.append([p,'intersection',p])
|
||||||
|
return snaps
|
||||||
|
|
||||||
|
|
||||||
def snapToAngles(self,shape):
|
def snapToAngles(self,shape):
|
||||||
"returns a list of angle snap locations"
|
"returns a list of angle snap locations"
|
||||||
snaps = []
|
snaps = []
|
||||||
|
|
Loading…
Reference in New Issue
Block a user