Merge pull request #11467 from Roy-043/Draft-make-mod-key-prefs-non-global
Draft: make mod key prefs non-global
This commit is contained in:
@@ -98,11 +98,6 @@ from draftguitools.gui_layers import Layer
|
||||
# update the translation engine
|
||||
FreeCADGui.updateLocale()
|
||||
|
||||
# Set modifier keys
|
||||
from draftguitools.gui_tool_utils import MODCONSTRAIN
|
||||
from draftguitools.gui_tool_utils import MODSNAP
|
||||
from draftguitools.gui_tool_utils import MODALT
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# General functions
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@@ -155,7 +155,7 @@ class Arc(gui_base_original.Creator):
|
||||
if not DraftVecUtils.isNull(viewdelta):
|
||||
self.point = self.point.add(viewdelta.negative())
|
||||
if self.step == 0: # choose center
|
||||
if gui_tool_utils.hasMod(arg, gui_tool_utils.MODALT):
|
||||
if gui_tool_utils.hasMod(arg, gui_tool_utils.get_mod_alt_key()):
|
||||
if not self.altdown:
|
||||
self.altdown = True
|
||||
self.ui.switchUi(True)
|
||||
@@ -178,7 +178,7 @@ class Arc(gui_base_original.Creator):
|
||||
_c = DraftGeomUtils.findClosestCircle(self.point, cir)
|
||||
self.center = _c.Center
|
||||
self.arctrack.setCenter(self.center)
|
||||
if gui_tool_utils.hasMod(arg, gui_tool_utils.MODALT):
|
||||
if gui_tool_utils.hasMod(arg, gui_tool_utils.get_mod_alt_key()):
|
||||
if not self.altdown:
|
||||
self.altdown = True
|
||||
if info:
|
||||
@@ -237,7 +237,7 @@ class Arc(gui_base_original.Creator):
|
||||
gui_tool_utils.getSupport(arg)
|
||||
(self.point,
|
||||
ctrlPoint, info) = gui_tool_utils.getPoint(self, arg)
|
||||
if gui_tool_utils.hasMod(arg, gui_tool_utils.MODALT):
|
||||
if gui_tool_utils.hasMod(arg, gui_tool_utils.get_mod_alt_key()):
|
||||
snapped = self.view.getObjectInfo((arg["Position"][0],
|
||||
arg["Position"][1]))
|
||||
if snapped:
|
||||
|
||||
@@ -362,13 +362,13 @@ class Dimension(gui_base_original.Creator):
|
||||
if arg["Key"] == "ESCAPE":
|
||||
self.finish()
|
||||
elif arg["Type"] == "SoLocation2Event": # mouse movement detection
|
||||
shift = gui_tool_utils.hasMod(arg, gui_tool_utils.MODCONSTRAIN)
|
||||
shift = gui_tool_utils.hasMod(arg, gui_tool_utils.get_mod_constrain_key())
|
||||
if self.arcmode or self.point2:
|
||||
gui_tool_utils.setMod(arg, gui_tool_utils.MODCONSTRAIN, False)
|
||||
gui_tool_utils.setMod(arg, gui_tool_utils.get_mod_constrain_key(), False)
|
||||
(self.point,
|
||||
ctrlPoint, self.info) = gui_tool_utils.getPoint(self, arg,
|
||||
noTracker=(len(self.node)>0))
|
||||
if (gui_tool_utils.hasMod(arg, gui_tool_utils.MODALT)
|
||||
if (gui_tool_utils.hasMod(arg, gui_tool_utils.get_mod_alt_key())
|
||||
or self.selectmode) and (len(self.node) < 3):
|
||||
self.dimtrack.off()
|
||||
if not self.altdown:
|
||||
@@ -467,7 +467,7 @@ class Dimension(gui_base_original.Creator):
|
||||
self.ui.redraw()
|
||||
if (not self.node) and (not self.support):
|
||||
gui_tool_utils.getSupport(arg)
|
||||
if (gui_tool_utils.hasMod(arg, gui_tool_utils.MODALT)
|
||||
if (gui_tool_utils.hasMod(arg, gui_tool_utils.get_mod_alt_key())
|
||||
or self.selectmode) and (len(self.node) < 3):
|
||||
# print("snapped: ",self.info)
|
||||
if self.info:
|
||||
|
||||
@@ -171,7 +171,7 @@ class Label(gui_base_original.Creator):
|
||||
if hasattr(Gui, "Snapper"):
|
||||
Gui.Snapper.affinity = None # don't keep affinity
|
||||
if len(self.node) == 2:
|
||||
gui_tool_utils.setMod(arg, gui_tool_utils.MODCONSTRAIN, True)
|
||||
gui_tool_utils.setMod(arg, gui_tool_utils.get_mod_constrain_key(), True)
|
||||
self.point, ctrlPoint, info = gui_tool_utils.getPoint(self, arg)
|
||||
gui_tool_utils.redraw3DView()
|
||||
elif arg["Type"] == "SoMouseButtonEvent":
|
||||
|
||||
@@ -147,7 +147,7 @@ class Mirror(gui_base_original.Modifier):
|
||||
self.ghost.setMatrix(mtx) # Ignores the position of the matrix.
|
||||
self.ghost.move(App.Vector(mtx.col(3)[:3]))
|
||||
if self.extendedCopy:
|
||||
if not gui_tool_utils.hasMod(arg, gui_tool_utils.MODALT):
|
||||
if not gui_tool_utils.hasMod(arg, gui_tool_utils.get_mod_alt_key()):
|
||||
self.finish()
|
||||
gui_tool_utils.redraw3DView()
|
||||
elif arg["Type"] == "SoMouseButtonEvent":
|
||||
@@ -166,11 +166,11 @@ class Mirror(gui_base_original.Modifier):
|
||||
else:
|
||||
last = self.node[0]
|
||||
if (self.ui.isCopy.isChecked()
|
||||
or gui_tool_utils.hasMod(arg, gui_tool_utils.MODALT)):
|
||||
or gui_tool_utils.hasMod(arg, gui_tool_utils.get_mod_alt_key())):
|
||||
self.mirror(last, self.point, True)
|
||||
else:
|
||||
self.mirror(last, self.point)
|
||||
if gui_tool_utils.hasMod(arg, gui_tool_utils.MODALT):
|
||||
if gui_tool_utils.hasMod(arg, gui_tool_utils.get_mod_alt_key()):
|
||||
self.extendedCopy = True
|
||||
else:
|
||||
self.finish()
|
||||
|
||||
@@ -149,7 +149,7 @@ class Move(gui_base_original.Modifier):
|
||||
ghost.move(self.vector)
|
||||
ghost.on()
|
||||
if self.extendedCopy:
|
||||
if not gui_tool_utils.hasMod(arg, gui_tool_utils.MODALT):
|
||||
if not gui_tool_utils.hasMod(arg, gui_tool_utils.get_mod_alt_key()):
|
||||
self.finish()
|
||||
gui_tool_utils.redraw3DView()
|
||||
|
||||
@@ -172,8 +172,8 @@ class Move(gui_base_original.Modifier):
|
||||
last = self.node[0]
|
||||
self.vector = self.point.sub(last)
|
||||
self.move(self.ui.isCopy.isChecked()
|
||||
or gui_tool_utils.hasMod(arg, gui_tool_utils.MODALT))
|
||||
if gui_tool_utils.hasMod(arg, gui_tool_utils.MODALT):
|
||||
or gui_tool_utils.hasMod(arg, gui_tool_utils.get_mod_alt_key()))
|
||||
if gui_tool_utils.hasMod(arg, gui_tool_utils.get_mod_alt_key()):
|
||||
self.extendedCopy = True
|
||||
else:
|
||||
self.finish(cont=None)
|
||||
|
||||
@@ -166,7 +166,7 @@ class Offset(gui_base_original.Modifier):
|
||||
self.finish()
|
||||
elif arg["Type"] == "SoLocation2Event":
|
||||
self.point, ctrlPoint, info = gui_tool_utils.getPoint(self, arg)
|
||||
if (gui_tool_utils.hasMod(arg, gui_tool_utils.MODCONSTRAIN)
|
||||
if (gui_tool_utils.hasMod(arg, gui_tool_utils.get_mod_constrain_key())
|
||||
and self.constrainSeg):
|
||||
dist = DraftGeomUtils.findPerpendicular(self.point,
|
||||
self.shape,
|
||||
@@ -218,7 +218,7 @@ class Offset(gui_base_original.Modifier):
|
||||
self.ui.radiusValue.setFocus()
|
||||
self.ui.radiusValue.selectAll()
|
||||
if self.extendedCopy:
|
||||
if not gui_tool_utils.hasMod(arg, gui_tool_utils.MODALT):
|
||||
if not gui_tool_utils.hasMod(arg, gui_tool_utils.get_mod_alt_key()):
|
||||
self.finish()
|
||||
gui_tool_utils.redraw3DView()
|
||||
|
||||
@@ -227,7 +227,7 @@ class Offset(gui_base_original.Modifier):
|
||||
copymode = False
|
||||
occmode = self.ui.occOffset.isChecked()
|
||||
self.param.SetBool("Offset_OCC", occmode)
|
||||
if (gui_tool_utils.hasMod(arg, gui_tool_utils.MODALT)
|
||||
if (gui_tool_utils.hasMod(arg, gui_tool_utils.get_mod_alt_key())
|
||||
or self.ui.isCopy.isChecked()):
|
||||
copymode = True
|
||||
Gui.addModule("Draft")
|
||||
@@ -261,7 +261,7 @@ class Offset(gui_base_original.Modifier):
|
||||
'FreeCAD.ActiveDocument.recompute()']
|
||||
self.commit(translate("draft", "Offset"),
|
||||
_cmd_list)
|
||||
if gui_tool_utils.hasMod(arg, gui_tool_utils.MODALT):
|
||||
if gui_tool_utils.hasMod(arg, gui_tool_utils.get_mod_alt_key()):
|
||||
self.extendedCopy = True
|
||||
else:
|
||||
self.finish()
|
||||
|
||||
@@ -119,7 +119,7 @@ class Polygon(gui_base_original.Creator):
|
||||
if not DraftVecUtils.isNull(viewdelta):
|
||||
self.point = self.point.add(viewdelta.negative())
|
||||
if self.step == 0: # choose center
|
||||
if gui_tool_utils.hasMod(arg, gui_tool_utils.MODALT):
|
||||
if gui_tool_utils.hasMod(arg, gui_tool_utils.get_mod_alt_key()):
|
||||
if not self.altdown:
|
||||
self.altdown = True
|
||||
self.ui.switchUi(True)
|
||||
@@ -142,7 +142,7 @@ class Polygon(gui_base_original.Creator):
|
||||
_c = DraftGeomUtils.findClosestCircle(self.point, cir)
|
||||
self.center = _c.Center
|
||||
self.arctrack.setCenter(self.center)
|
||||
if gui_tool_utils.hasMod(arg, gui_tool_utils.MODALT):
|
||||
if gui_tool_utils.hasMod(arg, gui_tool_utils.get_mod_alt_key()):
|
||||
if not self.altdown:
|
||||
self.altdown = True
|
||||
snapped = self.view.getObjectInfo((arg["Position"][0],
|
||||
@@ -181,7 +181,7 @@ class Polygon(gui_base_original.Creator):
|
||||
gui_tool_utils.getSupport(arg)
|
||||
(self.point,
|
||||
ctrlPoint, info) = gui_tool_utils.getPoint(self, arg)
|
||||
if gui_tool_utils.hasMod(arg, gui_tool_utils.MODALT):
|
||||
if gui_tool_utils.hasMod(arg, gui_tool_utils.get_mod_alt_key()):
|
||||
snapped = self.view.getObjectInfo((arg["Position"][0],
|
||||
arg["Position"][1]))
|
||||
if snapped:
|
||||
|
||||
@@ -130,7 +130,7 @@ class Rotate(gui_base_original.Modifier):
|
||||
if not DraftVecUtils.isNull(viewdelta):
|
||||
self.point = self.point.add(viewdelta.negative())
|
||||
if self.extendedCopy:
|
||||
if not gui_tool_utils.hasMod(arg, gui_tool_utils.MODALT):
|
||||
if not gui_tool_utils.hasMod(arg, gui_tool_utils.get_mod_alt_key()):
|
||||
self.step = 3
|
||||
self.finish()
|
||||
if self.step == 0:
|
||||
@@ -223,8 +223,8 @@ class Rotate(gui_base_original.Modifier):
|
||||
else:
|
||||
self.angle = angle - self.firstangle
|
||||
self.rotate(self.ui.isCopy.isChecked()
|
||||
or gui_tool_utils.hasMod(arg, gui_tool_utils.MODALT))
|
||||
if gui_tool_utils.hasMod(arg, gui_tool_utils.MODALT):
|
||||
or gui_tool_utils.hasMod(arg, gui_tool_utils.get_mod_alt_key()))
|
||||
if gui_tool_utils.hasMod(arg, gui_tool_utils.get_mod_alt_key()):
|
||||
self.extendedCopy = True
|
||||
else:
|
||||
self.finish(cont=None)
|
||||
|
||||
@@ -44,9 +44,18 @@ from draftutils.messages import _wrn
|
||||
|
||||
# Set modifier keys from the parameter database
|
||||
MODS = ["shift", "ctrl", "alt"]
|
||||
MODCONSTRAIN = MODS[utils.get_param("modconstrain", 0)]
|
||||
MODSNAP = MODS[utils.get_param("modsnap", 1)]
|
||||
MODALT = MODS[utils.get_param("modalt", 2)]
|
||||
|
||||
|
||||
def get_mod_constrain_key():
|
||||
return MODS[utils.get_param("modconstrain", 0)]
|
||||
|
||||
|
||||
def get_mod_snap_key():
|
||||
return MODS[utils.get_param("modsnap", 1)]
|
||||
|
||||
|
||||
def get_mod_alt_key():
|
||||
return MODS[utils.get_param("modalt", 2)]
|
||||
|
||||
|
||||
def format_unit(exp, unit="mm"):
|
||||
@@ -187,14 +196,14 @@ def get_point(target, args, noTracker=False):
|
||||
else:
|
||||
last = None
|
||||
|
||||
amod = has_mod(args, MODSNAP)
|
||||
cmod = has_mod(args, MODCONSTRAIN)
|
||||
smod = has_mod(args, get_mod_snap_key())
|
||||
cmod = has_mod(args, get_mod_constrain_key())
|
||||
point = None
|
||||
|
||||
if hasattr(Gui, "Snapper"):
|
||||
point = Gui.Snapper.snap(args["Position"],
|
||||
lastpoint=last,
|
||||
active=amod,
|
||||
active=smod,
|
||||
constrain=cmod,
|
||||
noTracker=noTracker)
|
||||
info = Gui.Snapper.snapInfo
|
||||
|
||||
@@ -187,16 +187,15 @@ class Trimex(gui_base_original.Modifier):
|
||||
if arg["Key"] == "ESCAPE":
|
||||
self.finish()
|
||||
elif arg["Type"] == "SoLocation2Event": # mouse movement detection
|
||||
self.shift = gui_tool_utils.hasMod(arg,
|
||||
gui_tool_utils.MODCONSTRAIN)
|
||||
self.alt = gui_tool_utils.hasMod(arg, gui_tool_utils.MODALT)
|
||||
self.ctrl = gui_tool_utils.hasMod(arg, gui_tool_utils.MODSNAP)
|
||||
self.shift = gui_tool_utils.hasMod(arg, gui_tool_utils.get_mod_constrain_key())
|
||||
self.alt = gui_tool_utils.hasMod(arg, gui_tool_utils.get_mod_alt_key())
|
||||
self.ctrl = gui_tool_utils.hasMod(arg, gui_tool_utils.get_mod_snap_key())
|
||||
if self.extrudeMode:
|
||||
arg["ShiftDown"] = False
|
||||
elif hasattr(Gui, "Snapper"):
|
||||
Gui.Snapper.setSelectMode(not self.ctrl)
|
||||
self.point, cp, info = gui_tool_utils.getPoint(self, arg)
|
||||
if gui_tool_utils.hasMod(arg, gui_tool_utils.MODSNAP):
|
||||
if gui_tool_utils.hasMod(arg, gui_tool_utils.get_mod_snap_key()):
|
||||
self.snapped = None
|
||||
else:
|
||||
self.snapped = self.view.getObjectInfo((arg["Position"][0],
|
||||
@@ -226,10 +225,9 @@ class Trimex(gui_base_original.Modifier):
|
||||
elif arg["Type"] == "SoMouseButtonEvent":
|
||||
if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
|
||||
cursor = arg["Position"]
|
||||
self.shift = gui_tool_utils.hasMod(arg,
|
||||
gui_tool_utils.MODCONSTRAIN)
|
||||
self.alt = gui_tool_utils.hasMod(arg, gui_tool_utils.MODALT)
|
||||
if gui_tool_utils.hasMod(arg, gui_tool_utils.MODSNAP):
|
||||
self.shift = gui_tool_utils.hasMod(arg, gui_tool_utils.get_mod_constrain_key())
|
||||
self.alt = gui_tool_utils.hasMod(arg, gui_tool_utils.get_mod_alt_key())
|
||||
if gui_tool_utils.hasMod(arg, gui_tool_utils.get_mod_snap_key()):
|
||||
self.snapped = None
|
||||
else:
|
||||
self.snapped = self.view.getObjectInfo((cursor[0],
|
||||
|
||||
Reference in New Issue
Block a user