0000715: Draft snap

This commit is contained in:
Yorik van Havre 2012-06-11 14:31:27 -03:00
parent 769528e86e
commit 2efc4915a1
2 changed files with 65 additions and 22 deletions

View File

@ -137,7 +137,7 @@ class DraftLineEdit(QtGui.QLineEdit):
self.emit(QtCore.SIGNAL("up()"))
elif event.key() == QtCore.Qt.Key_Down:
self.emit(QtCore.SIGNAL("down()"))
elif (event.key() == QtCore.Qt.Key_Z) and QtCore.Qt.ControlModifier:
elif (event.key() == QtCore.Qt.Key_Z) and (int(event.modifiers()) == QtCore.Qt.ControlModifier):
self.emit(QtCore.SIGNAL("undo()"))
else:
QtGui.QLineEdit.keyPressEvent(self, event)
@ -184,6 +184,7 @@ class DraftToolBar:
self.crossedViews = []
self.isTaskOn = False
self.fillmode = Draft.getParam("fillmode")
self.mask = None
if self.taskmode:
# add only a dummy widget, since widgets are created on demand
@ -593,6 +594,7 @@ class DraftToolBar:
self.cancel = None
self.sourceCmd = None
self.pointcallback = None
self.mask = None
if self.taskmode:
self.isTaskOn = False
self.baseWidget = QtGui.QWidget()
@ -882,15 +884,16 @@ class DraftToolBar:
last = self.sourceCmd.node[0]
else:
last = self.sourceCmd.node[-1]
numx = last.x + numx
numy = last.y + numy
numz = last.z + numz
print "last:",last
v = FreeCAD.Vector(numx,numy,numz)
print "orig:",v
if FreeCAD.DraftWorkingPlane:
v = FreeCAD.Vector(numx,numy,numz)
v = FreeCAD.DraftWorkingPlane.getGlobalCoords(v)
numx = v.x
numy = v.y
numz = v.z
v = FreeCAD.DraftWorkingPlane.getGlobalRot(v)
print "rotated:",v
numx = last.x + v.x
numy = last.y + v.y
numz = last.z + v.z
self.sourceCmd.numericInput(numx,numy,numz)
def finish(self):
@ -963,6 +966,12 @@ class DraftToolBar:
self.toggleradius(1)
elif txt.endsWith("]"):
self.toggleradius(-1)
elif txt.endsWith("x"):
self.constrain("x")
elif txt.endsWith("y"):
self.constrain("y")
elif txt.endsWith("z"):
self.constrain("z")
elif txt.endsWith("c"):
if self.closeButton.isVisible():
self.closeLine()
@ -1025,29 +1034,38 @@ class DraftToolBar:
dp = point
if self.relativeMode and (last != None):
if plane:
dp = plane.getLocalCoords(FreeCAD.Vector(point.x-last.x, point.y-last.y, point.z-last.z))
dp = plane.getLocalRot(FreeCAD.Vector(point.x-last.x, point.y-last.y, point.z-last.z))
else:
dp = FreeCAD.Vector(point.x-last.x, point.y-last.y, point.z-last.z)
# set widgets
self.xValue.setText("%.2f" % dp.x)
self.yValue.setText("%.2f" % dp.y)
self.zValue.setText("%.2f" % dp.z)
if self.mask in ['y','z']:
self.xValue.setText("0.00")
else:
self.xValue.setText("%.2f" % dp.x)
if self.mask in ['x','z']:
self.yValue.setText("0.00")
else:
self.yValue.setText("%.2f" % dp.y)
if self.mask in ['x','y']:
self.zValue.setText("0.00")
else:
self.zValue.setText("%.2f" % dp.z)
# set masks
if mask == "x":
if (mask == "x") or (self.mask == "x"):
self.xValue.setEnabled(True)
self.yValue.setEnabled(False)
self.zValue.setEnabled(False)
self.xValue.setFocus()
self.xValue.selectAll()
elif mask == "y":
elif (mask == "y") or (self.mask == "y"):
self.xValue.setEnabled(False)
self.yValue.setEnabled(True)
self.zValue.setEnabled(False)
self.yValue.setFocus()
self.yValue.selectAll()
elif mask == "z":
elif (mask == "z") or (self.mask == "z"):
self.xValue.setEnabled(False)
self.yValue.setEnabled(False)
self.zValue.setEnabled(True)
@ -1168,6 +1186,16 @@ class DraftToolBar:
Draft.setParam("snapRange",par+val)
FreeCADGui.Snapper.showradius()
def constrain(self,val):
if self.mask == val:
self.mask = None
if hasattr(FreeCADGui,"Snapper"):
FreeCADGui.Snapper.mask = None
else:
self.mask = val
if hasattr(FreeCADGui,"Snapper"):
FreeCADGui.Snapper.mask = val
#---------------------------------------------------------------------------
# TaskView operations
#---------------------------------------------------------------------------

View File

@ -60,6 +60,7 @@ class Snapper:
self.constraintAxis = None
self.basepoint = None
self.affinity = None
self.mask = None
self.cursorMode = None
if Draft.getParam("maxSnap"):
self.maxEdges = Draft.getParam("maxSnapEdges")
@ -126,7 +127,7 @@ class Snapper:
def cstr(point):
"constrains if needed"
if constrain:
if constrain or self.mask:
fpt = self.constrain(point,lastpoint)
else:
self.unconstrain()
@ -211,7 +212,9 @@ class Snapper:
else:
# first stick to the snapped object
point = self.snapToVertex(self.snapInfo)[0]
s = self.snapToVertex(self.snapInfo)
if s:
point = s[0]
# active snapping
comp = self.snapInfo['Component']
@ -278,7 +281,7 @@ class Snapper:
self.lastObj[1] = obj.Name
if not snaps:
return point
return cstr(point)
# calculating the nearest snap point
shortest = 1000000000000000000
@ -395,7 +398,7 @@ class Snapper:
def snapToPolar(self,point,last):
"snaps to polar lines from the given point"
if self.isEnabled('ortho'):
if self.isEnabled('ortho') and (not self.mask):
if last:
vecs = []
if hasattr(FreeCAD,"DraftWorkingPlane"):
@ -535,9 +538,11 @@ class Snapper:
"returns a perpendicular X extension snap location"
if self.isEnabled("extension") and self.isEnabled("perpendicular"):
if last and self.extLine:
tmpEdge = Part.Line(self.extLine.p1(),self.extLine.p2()).toShape()
np = self.getPerpendicular(tmpEdge,last)
return [np,'perpendicular',np]
if self.extLine.p1() != self.extLine.p2():
tmpEdge = Part.Line(self.extLine.p1(),self.extLine.p2()).toShape()
np = self.getPerpendicular(tmpEdge,last)
return [np,'perpendicular',np]
return None
def snapToElines(self,e1,e2):
"returns a snap location at the infinite intersection of the given edges"
@ -668,6 +673,7 @@ class Snapper:
self.setCursor()
if Draft.getParam("hideSnapBar"):
self.toolbar.hide()
self.mask = None
def constrain(self,point,basepoint=None,axis=None):
'''constrain(point,basepoint=None,axis=None: Returns a
@ -696,6 +702,8 @@ class Snapper:
delta = point.sub(self.basepoint)
# setting constraint axis
if self.mask:
self.affinity = self.mask
if not self.affinity:
self.affinity = FreeCAD.DraftWorkingPlane.getClosestAxis(delta)
if isinstance(axis,FreeCAD.Vector):
@ -920,6 +928,13 @@ class Snapper:
if FreeCADGui.ActiveDocument:
self.setTrackers()
def setGrid(self):
"sets the grid, if visible"
if self.grid and (not self.forceGridOff):
if self.grid.Visible:
self.grid.set()
self.setTrackers()
def setTrackers(self):
v = Draft.get3DView()
if v in self.trackers[0]: