+ added RFE #442 - allow to set custom ctrl, shift & alt combinations in Draft module

git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5024 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
yorikvanhavre 2011-10-14 20:14:26 +00:00
parent ee271a0186
commit 10c5ddb115
4 changed files with 1870 additions and 1601 deletions

View File

@ -93,7 +93,8 @@ def typecheck (args_and_types, name="?"):
def getParamType(param):
if param in ["dimsymbol","dimPrecision","dimorientation","precision","defaultWP",
"snapRange","gridEvery","linewidth","UiMode"]:
"snapRange","gridEvery","linewidth","UiMode","modconstrain","modsnap",
"modalt"]:
return "int"
elif param in ["constructiongroupname","textfont","patternFile","template"]:
return "string"

File diff suppressed because it is too large Load Diff

View File

@ -143,10 +143,6 @@
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
@ -154,19 +150,6 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_9">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="Gui::PrefSpinBox" name="gui::prefspinbox">
<property name="toolTip">
@ -185,6 +168,121 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_20">
<property name="text">
<string>Constrain mod</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefComboBox" name="gui::prefcombobox_5">
<property name="toolTip">
<string>The Constraining modifier key</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>modconstrain</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
<item>
<property name="text">
<string>shift</string>
</property>
</item>
<item>
<property name="text">
<string>ctrl</string>
</property>
</item>
<item>
<property name="text">
<string>alt</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QLabel" name="label_21">
<property name="text">
<string>Snap mod</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefComboBox" name="gui::prefcombobox_6">
<property name="toolTip">
<string>The snap modifier key</string>
</property>
<property name="currentIndex">
<number>1</number>
</property>
<property name="prefEntry" stdset="0">
<cstring>modsnap</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
<item>
<property name="text">
<string>shift</string>
</property>
</item>
<item>
<property name="text">
<string>ctrl</string>
</property>
</item>
<item>
<property name="text">
<string>alt</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QLabel" name="label_22">
<property name="text">
<string>Alt mod</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefComboBox" name="gui::prefcombobox_7">
<property name="toolTip">
<string>The alt modifier key</string>
</property>
<property name="currentIndex">
<number>2</number>
</property>
<property name="prefEntry" stdset="0">
<cstring>modalt</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
<item>
<property name="text">
<string>shift</string>
</property>
</item>
<item>
<property name="text">
<string>ctrl</string>
</property>
</item>
<item>
<property name="text">
<string>alt</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
@ -194,19 +292,6 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="Gui::PrefLineEdit" name="gui::preflineedit_2">
<property name="toolTip">
@ -296,7 +381,7 @@
<string>If this is checked, you will always snap to existing objects while drawing. If not, you will be snapping only when pressing CTRL.</string>
</property>
<property name="text">
<string>Always snap to objects (disable CTRL-snapping)</string>
<string>Always snap to objects (disable snap mod key)</string>
</property>
<property name="checked">
<bool>true</bool>

View File

@ -78,6 +78,12 @@ elif defaultWP == 3: plane.alignToPointAndAxis(Vector(0,0,0), Vector(1,0,0), 0)
# last snapped objects, for quick intersection calculation
lastObj = [0,0]
# set modifier keys
MODS = ["shift","ctrl","alt"]
MODCONSTRAIN = MODS[Draft.getParam("modconstrain")]
MODSNAP = MODS[Draft.getParam("modsnap")]
MODALT = MODS[Draft.getParam("modalt")]
#---------------------------------------------------------------------------
# Global state
#---------------------------------------------------------------------------
@ -426,7 +432,7 @@ def getPoint(target,args,mobile=False,sym=False,workingplane=True):
ui = FreeCADGui.draftToolBar
view = FreeCADGui.ActiveDocument.ActiveView
point = view.getPoint(args["Position"][0],args["Position"][1])
point = snapPoint(target,point,args["Position"],args["CtrlDown"])
point = snapPoint(target,point,args["Position"],hasMod(args,MODSNAP))
if (not plane.weak) and workingplane:
# working plane was explicitely selected - project onto it
@ -444,7 +450,7 @@ def getPoint(target,args,mobile=False,sym=False,workingplane=True):
else:
point = plane.projectPoint(point, viewDirection)
ctrlPoint = Vector(point.x,point.y,point.z)
if (args["ShiftDown"]): # constraining
if (hasMod(args,MODCONSTRAIN)): # constraining
if mobile and (target.constrain == None):
target.node.append(point)
point = constrainPoint(target,point,mobile=mobile,sym=sym)
@ -477,6 +483,25 @@ def getSupport(args):
except:
pass
return obj
def hasMod(args,mod):
"checks if args has a specific modifier"
if mod == "shift":
return args["ShiftDown"]
elif mod == "ctrl":
return args["CtrlDown"]
elif mod == "alt":
return args["AltDown"]
def setMod(args,mod,state):
"sets a specific modifier state in args"
if mod == "shift":
args["ShiftDown"] = state
elif mod == "ctrl":
args["CtrlDown"] = state
elif mod == "alt":
args["AltDown"] = state
#---------------------------------------------------------------------------
# Trackers
@ -1311,7 +1336,7 @@ class Line(Creator):
self.ui.cross(True)
self.linetrack.p2(point)
# Draw constraint tracker line.
if (arg["ShiftDown"]):
if hasMod(arg,MODCONSTRAIN):
self.constraintrack.p1(point)
self.constraintrack.p2(ctrlPoint)
self.constraintrack.on()
@ -1444,7 +1469,7 @@ class BSpline(Line):
self.ui.cross(True)
self.bsplinetrack.update(self.node + [point])
# Draw constraint tracker line.
if (arg["ShiftDown"]):
if hasMod(arg,MODCONSTRAIN):
self.constraintrack.p1(point)
self.constraintrack.p2(ctrlPoint)
self.constraintrack.on()
@ -1715,7 +1740,7 @@ class Arc(Creator):
if not fcvec.isNull(viewdelta):
point = point.add(fcvec.neg(viewdelta))
if (self.step == 0): # choose center
if arg["AltDown"]:
if hasMod(arg,MODALT):
if not self.altdown:
self.ui.cross(False)
self.altdown = True
@ -1734,7 +1759,7 @@ class Arc(Creator):
cir = fcgeo.circleFrom1tan2pt(self.tangents[0], self.tanpoints[0], point)
self.center = fcgeo.findClosestCircle(point,cir).Center
self.arctrack.setCenter(self.center)
if arg["AltDown"]:
if hasMod(arg,MODALT):
if not self.altdown:
self.ui.cross(False)
self.altdown = True
@ -1761,7 +1786,7 @@ class Arc(Creator):
self.ui.setRadiusValue(self.rad)
self.arctrack.setRadius(self.rad)
# Draw constraint tracker line.
if (arg["ShiftDown"]):
if hasMod(arg,MODCONSTRAIN):
self.constraintrack.p1(point)
self.constraintrack.p2(ctrlPoint)
self.constraintrack.on()
@ -1776,7 +1801,7 @@ class Arc(Creator):
else: angle = 0
self.linetrack.p2(fcvec.scaleTo(point.sub(self.center),self.rad).add(self.center))
# Draw constraint tracker line.
if (arg["ShiftDown"]):
if hasMod(arg,MODCONSTRAIN):
self.constraintrack.p1(point)
self.constraintrack.p2(ctrlPoint)
self.constraintrack.on()
@ -1790,7 +1815,7 @@ class Arc(Creator):
else: angle = 0
self.linetrack.p2(fcvec.scaleTo(point.sub(self.center),self.rad).add(self.center))
# Draw constraint tracker line.
if (arg["ShiftDown"]):
if hasMod(arg,MODCONSTRAIN):
self.constraintrack.p1(point)
self.constraintrack.p2(ctrlPoint)
self.constraintrack.on()
@ -1809,7 +1834,7 @@ class Arc(Creator):
point = point.add(fcvec.neg(viewdelta))
if (self.step == 0): # choose center
self.support = getSupport(arg)
if arg["AltDown"]:
if hasMod(arg,MODALT):
snapped=self.view.getObjectInfo((arg["Position"][0],arg["Position"][1]))
if snapped:
ob = self.doc.getObject(snapped['Object'])
@ -1996,7 +2021,7 @@ class Polygon(Creator):
if not fcvec.isNull(viewdelta):
point = point.add(fcvec.neg(viewdelta))
if (self.step == 0): # choose center
if arg["AltDown"]:
if hasMod(arg,MODALT):
if not self.altdown:
self.ui.cross(False)
self.altdown = True
@ -2015,7 +2040,7 @@ class Polygon(Creator):
cir = fcgeo.circleFrom1tan2pt(self.tangents[0], self.tanpoints[0], point)
self.center = fcgeo.findClosestCircle(point,cir).Center
self.arctrack.setCenter(self.center)
if arg["AltDown"]:
if hasMod(arg,MODALT):
if not self.altdown:
self.ui.cross(False)
self.altdown = True
@ -2042,7 +2067,7 @@ class Polygon(Creator):
self.ui.setRadiusValue(self.rad)
self.arctrack.setRadius(self.rad)
# Draw constraint tracker line.
if (arg["ShiftDown"]):
if hasMod(arg,MODCONSTRAIN):
self.constraintrack.p1(point)
self.constraintrack.p2(ctrlPoint)
self.constraintrack.on()
@ -2061,7 +2086,7 @@ class Polygon(Creator):
point = point.add(fcvec.neg(viewdelta))
if (self.step == 0): # choose center
if not self.node: self.support = getSupport(arg)
if arg["AltDown"]:
if hasMod(arg,MODALT):
snapped=self.view.getObjectInfo((arg["Position"][0],arg["Position"][1]))
if snapped:
ob = self.doc.getObject(snapped['Object'])
@ -2263,12 +2288,12 @@ class Dimension(Creator):
if arg["Type"] == "SoKeyboardEvent" and arg["Key"] == "ESCAPE":
self.finish()
if (arg["Type"] == "SoLocation2Event"): #mouse movement detection
shift = arg["ShiftDown"]
shift = hasMod(arg,MODCONSTRAIN)
if self.arcmode or self.point2:
arg["ShiftDown"] = False
setMod(arg,MODCONSTRAIN,False)
point,ctrlPoint = getPoint(self,arg)
self.ui.cross(True)
if arg["AltDown"] and (len(self.node)<3):
if hasMod(arg,MODALT) and (len(self.node)<3):
self.ui.cross(False)
self.dimtrack.off()
if not self.altdown:
@ -2346,7 +2371,7 @@ class Dimension(Creator):
if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
point,ctrlPoint = getPoint(self,arg)
if not self.node: self.support = getSupport(arg)
if arg["AltDown"] and (len(self.node)<3):
if hasMod(arg,MODALT) and (len(self.node)<3):
snapped = self.view.getObjectInfo((arg["Position"][0],arg["Position"][1]))
if snapped:
ob = self.doc.getObject(snapped['Object'])
@ -2572,7 +2597,7 @@ class Move(Modifier):
self.linetrack.p2(point)
self.ui.cross(True)
# Draw constraint tracker line.
if (arg["ShiftDown"]):
if hasMod(arg,MODCONSTRAIN):
self.constraintrack.p1(point)
self.constraintrack.p2(ctrlPoint)
self.constraintrack.on()
@ -2582,7 +2607,7 @@ class Move(Modifier):
delta = point.sub(last)
self.ghost.trans.translation.setValue([delta.x,delta.y,delta.z])
if self.extendedCopy:
if not arg["AltDown"]: self.finish()
if not hasMod(arg,MODALT): self.finish()
if (arg["Type"] == "SoMouseButtonEvent"):
if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
point,ctrlPoint = getPoint(self,arg)
@ -2596,11 +2621,11 @@ class Move(Modifier):
self.planetrack.set(point)
else:
last = self.node[0]
if self.ui.isCopy.isChecked() or arg["AltDown"]:
if self.ui.isCopy.isChecked() or hasMod(arg,MODALT):
self.move(point.sub(last),True)
else:
self.move(point.sub(last))
if arg["AltDown"]:
if hasMod(arg,MODALT):
self.extendedCopy = True
else:
self.finish(cont=True)
@ -2732,7 +2757,7 @@ class Rotate(Modifier):
if not fcvec.isNull(viewdelta):
point = point.add(fcvec.neg(viewdelta))
if self.extendedCopy:
if not arg["AltDown"]:
if not hasMod(arg,MODALT):
self.step = 3
self.finish()
if (self.step == 0):
@ -2744,7 +2769,7 @@ class Rotate(Modifier):
else: angle = 0
self.linetrack.p2(point)
# Draw constraint tracker line.
if (arg["ShiftDown"]):
if hasMod(arg,MODCONSTRAIN):
self.constraintrack.p1(point)
self.constraintrack.p2(ctrlPoint)
self.constraintrack.on()
@ -2766,7 +2791,7 @@ class Rotate(Modifier):
self.ghost.trans.rotation.setValue(coin.SbVec3f(fcvec.tup(plane.axis)),sweep)
self.linetrack.p2(point)
# Draw constraint tracker line.
if (arg["ShiftDown"]):
if hasMod(arg,MODCONSTRAIN):
self.constraintrack.p1(point)
self.constraintrack.p2(ctrlPoint)
self.constraintrack.on()
@ -2811,11 +2836,11 @@ class Rotate(Modifier):
sweep = (2*math.pi-self.firstangle)+angle
else:
sweep = angle - self.firstangle
if self.ui.isCopy.isChecked() or arg["AltDown"]:
if self.ui.isCopy.isChecked() or hasMod(arg,MODALT):
self.rot(sweep,True)
else:
self.rot(sweep)
if arg["AltDown"]:
if hasMod(arg,MODALT):
self.extendedCopy = True
else:
self.finish(cont=True)
@ -2915,7 +2940,7 @@ class Offset(Modifier):
if (arg["Type"] == "SoLocation2Event"):
self.ui.cross(True)
point,ctrlPoint = getPoint(self,arg)
if (arg["ShiftDown"]) and self.constrainSeg:
if hasMod(arg,MODCONSTRAIN) and self.constrainSeg:
dist = fcgeo.findPerpendicular(point,self.shape,self.constrainSeg[1])
e = self.shape.Edges[self.constrainSeg[1]]
self.constraintrack.p1(e.Vertexes[0].Point)
@ -2950,15 +2975,15 @@ class Offset(Modifier):
self.ui.radiusValue.setFocus()
self.ui.radiusValue.selectAll()
if self.extendedCopy:
if not arg["AltDown"]: self.finish()
if not hasMod(arg,MODALT): self.finish()
if (arg["Type"] == "SoMouseButtonEvent"):
if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
copymode = False
occmode = self.ui.occOffset.isChecked()
if arg["AltDown"] or self.ui.isCopy.isChecked(): copymode = True
if hasMod(arg,MODALT) or self.ui.isCopy.isChecked(): copymode = True
if self.dvec:
self.commit(translate("draft","Offset"),partial(Draft.offset,self.sel,self.dvec,copymode,occ=occmode))
if arg["AltDown"]:
if hasMod(arg,MODALT):
self.extendedCopy = True
else:
self.finish()
@ -3383,11 +3408,11 @@ class Trimex(Modifier):
self.finish()
if (arg["Type"] == "SoLocation2Event"): #mouse movement detection
self.ui.cross(True)
self.shift = arg["ShiftDown"]
self.alt = arg["AltDown"]
self.shift = hasMod(arg,MODCONSTRAIN)
self.alt = hasMod(arg,MODALT)
wp = not(self.extrudeMode and self.shift)
self.point = getPoint(self,arg,workingplane=wp)[0]
if arg["CtrlDown"]: self.snapped = None
if hasMod(arg,MODSNAP): self.snapped = None
else: self.snapped = self.view.getObjectInfo((arg["Position"][0],arg["Position"][1]))
if self.extrudeMode:
dist = self.extrude(self.shift)
@ -3403,9 +3428,9 @@ class Trimex(Modifier):
if (arg["Type"] == "SoMouseButtonEvent"):
if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
cursor = arg["Position"]
self.shift = arg["ShiftDown"]
self.alt = arg["AltDown"]
if arg["CtrlDown"]: self.snapped = None
self.shift = hasMod(arg,MODCONSTRAIN)
self.alt = hasMod(arg,MODALT)
if hasMod(arg,MODSNAP): self.snapped = None
else: self.snapped = self.view.getObjectInfo((cursor[0],cursor[1]))
self.trimObject()
self.finish()
@ -3652,7 +3677,7 @@ class Scale(Modifier):
self.linetrack.p2(point)
self.ui.cross(True)
# Draw constraint tracker line.
if (arg["ShiftDown"]):
if hasMod(arg,MODCONSTRAIN):
self.constraintrack.p1(point)
self.constraintrack.p2(ctrlPoint)
self.constraintrack.on()
@ -3666,7 +3691,7 @@ class Scale(Modifier):
corr = fcvec.neg(corr.sub(self.node[0]))
self.ghost.trans.translation.setValue([corr.x,corr.y,corr.z])
if self.extendedCopy:
if not arg["AltDown"]: self.finish()
if not hasMod(arg,MODALT): self.finish()
if (arg["Type"] == "SoMouseButtonEvent"):
if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
point,ctrlPoint = getPoint(self,arg,sym=True)
@ -3680,11 +3705,11 @@ class Scale(Modifier):
msg(translate("draft", "Pick scale factor:\n"))
else:
last = self.node[0]
if self.ui.isCopy.isChecked() or arg["AltDown"]:
if self.ui.isCopy.isChecked() or hasMod(arg,MODALT):
self.scale(point.sub(last),True)
else:
self.scale(point.sub(last))
if arg["AltDown"]:
if hasMod(arg,MODALT):
self.extendedCopy = True
else:
self.finish(cont=True)
@ -3938,7 +3963,7 @@ class Edit(Modifier):
if self.editing != None:
point,ctrlPoint = getPoint(self,arg)
# Draw constraint tracker line.
if (arg["ShiftDown"]):
if hasMod(arg,MODCONSTRAIN):
self.constraintrack.p1(point)
self.constraintrack.p2(ctrlPoint)
self.constraintrack.on()