Merge pull request #11428 from Roy-043/Draft-make-in-command-shortcuts-non-global

Draft: make in-command shortcuts non-global
This commit is contained in:
Roy-043
2023-11-18 19:44:17 +01:00
committed by GitHub

View File

@@ -48,124 +48,90 @@ import Draft
import DraftVecUtils
import WorkingPlane
from draftutils.translate import translate
# in-command shortcut definitions: Shortcut / Translation / related UI control
inCommandShortcuts = {
"Relative": [
Draft.getParam("inCommandShortcutRelative", "R"),
translate("draft","Relative"),
"isRelative"
],
"Global": [Draft.getParam("inCommandShortcutGlobal", "G"),
translate("draft","Global"),
"isGlobal"
],
"Continue": [
Draft.getParam("inCommandShortcutContinue", "T"),
translate("draft","Continue"),
"continueCmd"
],
"Close": [
Draft.getParam("inCommandShortcutClose", "O"),
translate("draft","Close"),
"closeButton"
],
"Copy": [
Draft.getParam("inCommandShortcutCopy", "P"),
translate("draft","Copy"),
"isCopy"
],
"SubelementMode": [
Draft.getParam("inCommandShortcutSubelementMode", "D"),
translate("draft","Subelement mode"),
"isSubelementMode"
],
"Fill": [
Draft.getParam("inCommandShortcutFill", "L"),
translate("draft","Fill"),
"hasFill"
],
"Exit": [
Draft.getParam("inCommandShortcutExit", "A"),
translate("draft","Exit"),
"finishButton"
],
"Snap": [
Draft.getParam("inCommandShortcutSnap", "S"),
translate("draft","Snap On/Off"),
None
],
"Increase": [
Draft.getParam("inCommandShortcutIncreaseRadius", "["),
translate("draft","Increase snap radius"),
None
],
"Decrease": [
Draft.getParam("inCommandShortcutDecreaseRadius", "]"),
translate("draft","Decrease snap radius"),
None
],
"RestrictX": [
Draft.getParam("inCommandShortcutRestrictX", "X"),
translate("draft","Restrict X"),
None
],
"RestrictY": [
Draft.getParam("inCommandShortcutRestrictY", "Y"),
translate("draft","Restrict Y"),
None
],
"RestrictZ": [
Draft.getParam("inCommandShortcutRestrictZ", "Z"),
translate("draft","Restrict Z"),
None
],
"SelectEdge": [
Draft.getParam("inCommandShortcutSelectEdge", "E"),
translate("draft","Select edge"),
"selectButton"
],
"AddHold": [
Draft.getParam("inCommandShortcutAddHold", "Q"),
translate("draft","Add custom snap point"),
None
],
"Length": [
Draft.getParam("inCommandShortcutLength", "H"),
translate("draft","Length mode"),
"lengthValue"
],
"Wipe": [
Draft.getParam("inCommandShortcutWipe", "W"),
translate("draft","Wipe"),
"wipeButton"
],
"SetWP": [
Draft.getParam("inCommandShortcutSetWP", "U"),
translate("draft","Set Working Plane"),
"orientWPButton"
],
"CycleSnap": [
Draft.getParam("inCommandShortcutCycleSnap", "`"),
translate("draft","Cycle snap object"),
None
],
"Undo": [
Draft.getParam("inCommandShortcutUndo", "/"),
translate("draft","Undo last segment"),
None
],
}
from draftutils.todo import todo
from draftutils.translate import translate
from draftutils.units import display_external
translate("draft", "Relative")
translate("draft", "Global")
translate("draft", "Continue")
translate("draft", "Close")
translate("draft", "Copy")
translate("draft", "Subelement mode")
translate("draft", "Fill")
translate("draft", "Exit")
translate("draft", "Snap On/Off")
translate("draft", "Increase snap radius")
translate("draft", "Decrease snap radius")
translate("draft", "Restrict X")
translate("draft", "Restrict Y")
translate("draft", "Restrict Z")
translate("draft", "Select edge")
translate("draft", "Add custom snap point")
translate("draft", "Length mode")
translate("draft", "Wipe")
translate("draft", "Set Working Plane")
translate("draft", "Cycle snap object")
translate("draft", "Undo last segment")
def _get_incmd_shortcut_default(itm):
if itm == "Relative":
# isRelative
return "R"
if itm == "Global":
# isGlobal
return "G"
if itm == "Continue":
# continueCmd
return "T"
if itm == "Close":
# closeButton
return "O"
if itm == "Copy":
# isCopy
return "P"
if itm == "SubelementMode":
# isSubelementMode
return "D"
if itm == "Fill":
# hasFill
return "L"
if itm == "Exit":
# finishButton
return "A"
if itm == "Snap":
return "S"
if itm == "IncreaseRadius":
return "["
if itm == "DecreaseRadius":
return "]"
if itm == "RestrictX":
return "X"
if itm == "RestrictY":
return "Y"
if itm == "RestrictZ":
return "Z"
if itm == "SelectEdge":
return "E"
if itm == "AddHold":
return "Q"
if itm == "Length":
# lengthValue
return "H"
if itm == "Wipe":
# wipeButton
return "W"
if itm == "SetWP":
# orientWPButton
return "U"
if itm == "CycleSnap":
return "`"
if itm == "Undo":
return "/"
def _get_incmd_shortcut(itm):
return Draft.getParam("inCommandShortcut" + itm, _get_incmd_shortcut_default(itm)).upper()
#---------------------------------------------------------------------------
# UNITS handling
#---------------------------------------------------------------------------
from draftutils.units import (getDefaultUnit,
makeFormatSpec,
displayExternal)
#---------------------------------------------------------------------------
# Customized widgets
@@ -176,7 +142,7 @@ class DraftBaseWidget(QtGui.QWidget):
super().__init__(parent)
def eventFilter(self, widget, event):
if (event.type() == QtCore.QEvent.KeyPress
and event.text().upper() == inCommandShortcuts["CycleSnap"][0]):
and event.text().upper() == _get_incmd_shortcut("CycleSnap")):
if hasattr(FreeCADGui,"Snapper"):
FreeCADGui.Snapper.cycleSnapObject()
return True
@@ -608,58 +574,57 @@ class DraftToolBar:
self.labelangle.setText(translate("draft", "Angle"))
self.lengthValue.setToolTip(translate("draft", "Length of current segment"))
self.angleValue.setToolTip(translate("draft", "Angle of current segment"))
#self.angleLock.setText(translate("draft", "&Lock"))
self.angleLock.setToolTip(translate(
"draft", "Check this to lock the current angle")\
+ " (" + inCommandShortcuts["Length"][0] + ")")
+ " (" + _get_incmd_shortcut("Length") + ")")
self.labelRadius.setText(translate("draft", "Radius"))
self.radiusValue.setToolTip(translate("draft", "Radius of Circle"))
self.isRelative.setText(translate(
"draft", "Relative") + " (" + inCommandShortcuts["Relative"][0] + ")")
"draft", "Relative") + " (" + _get_incmd_shortcut("Relative") + ")")
self.isRelative.setToolTip(translate(
"draft", "Coordinates relative to last point or to coordinate system "
+ "origin\nif is the first point to set"))
self.isGlobal.setText(translate(
"draft", "Global") + " (" + inCommandShortcuts["Global"][0] + ")")
"draft", "Global") + " (" + _get_incmd_shortcut("Global") + ")")
self.isGlobal.setToolTip(translate(
"draft", "Coordinates relative to global coordinate system."
+ "\nUncheck to use working plane coordinate system"))
self.hasFill.setText(translate(
"draft", "Filled")+" ("+inCommandShortcuts["Fill"][0]+")")
"draft", "Filled") + " (" + _get_incmd_shortcut("Fill") + ")")
self.hasFill.setToolTip(translate(
"draft", "Check this if the object should appear as filled, "
+ "otherwise it will appear as wireframe.\nNot available if "
+ "Draft preference option 'Use Part Primitives' is enabled"))
self.finishButton.setText(translate(
"draft", "Finish")+" ("+inCommandShortcuts["Exit"][0]+")")
"draft", "Finish") + " (" + _get_incmd_shortcut("Exit") + ")")
self.finishButton.setToolTip(translate(
"draft", "Finishes the current drawing or editing operation"))
self.continueCmd.setToolTip(translate(
"draft", "If checked, command will not finish until you press "
+ "the command button again"))
self.continueCmd.setText(translate(
"draft", "Continue") + " (" + inCommandShortcuts["Continue"][0] + ")")
"draft", "Continue") + " (" + _get_incmd_shortcut("Continue") + ")")
self.occOffset.setToolTip(translate(
"draft", "If checked, an OCC-style offset will be performed"
+ " instead of the classic offset"))
self.occOffset.setText(translate("draft", "&OCC-style offset"))
self.occOffset.setText(translate("draft", "OCC-style offset"))
self.undoButton.setText(translate("draft", "&Undo")+" ("+inCommandShortcuts["Undo"][0]+")")
self.undoButton.setText(translate("draft", "Undo") + " (" + _get_incmd_shortcut("Undo") + ")")
self.undoButton.setToolTip(translate("draft", "Undo the last segment"))
self.closeButton.setText(translate("draft", "Close")+" ("+inCommandShortcuts["Close"][0]+")")
self.closeButton.setText(translate("draft", "Close") + " (" + _get_incmd_shortcut("Close") + ")")
self.closeButton.setToolTip(translate("draft", "Finishes and closes the current line"))
self.wipeButton.setText(translate("draft", "Wipe")+" ("+inCommandShortcuts["Wipe"][0]+")")
self.wipeButton.setText(translate("draft", "Wipe") + " (" + _get_incmd_shortcut("Wipe") + ")")
self.wipeButton.setToolTip(translate("draft", "Wipes the existing segments of this line and starts again from the last point"))
self.orientWPButton.setText(translate("draft", "Set WP")+" ("+inCommandShortcuts["SetWP"][0]+")")
self.orientWPButton.setText(translate("draft", "Set WP") + " (" + _get_incmd_shortcut("SetWP") + ")")
self.orientWPButton.setToolTip(translate("draft", "Reorients the working plane on the last segment"))
self.selectButton.setText(translate("draft", "Select edge")+" ("+inCommandShortcuts["SelectEdge"][0]+")")
self.selectButton.setText(translate("draft", "Select edge") + " (" + _get_incmd_shortcut("SelectEdge") + ")")
self.selectButton.setToolTip(translate("draft", "Selects an existing edge to be measured by this dimension"))
self.numFacesLabel.setText(translate("draft", "Sides"))
self.numFaces.setToolTip(translate("draft", "Number of sides"))
self.isCopy.setText(translate("draft", "Copy")+" ("+inCommandShortcuts["Copy"][0]+")")
self.isCopy.setToolTip(translate("draft", "If checked, objects will be copied instead of moved. Preferences -> Draft -> Global copy mode to keep this mode in next commands"))
self.isSubelementMode.setText(translate("draft", "Modify subelements")+" ("+inCommandShortcuts["SubelementMode"][0]+")")
self.isCopy.setText(translate("draft", "Copy") + " (" + _get_incmd_shortcut("Copy") + ")")
self.isCopy.setToolTip(translate("draft", "If checked, objects will be copied instead of moved"))
self.isSubelementMode.setText(translate("draft", "Modify subelements") + " (" + _get_incmd_shortcut("SubelementMode") + ")")
self.isSubelementMode.setToolTip(translate("draft", "If checked, subelements will be modified instead of entire objects"))
self.textOkButton.setText(translate("draft", "Create text"))
self.textOkButton.setToolTip(translate("draft", "Press this button to create the text object, or finish your text with two blank lines"))
@@ -1152,102 +1117,89 @@ class DraftToolBar:
treated as shortcuts
"""
# in-command shortcut definitions
#Relative
#Continue
#Close
#Copy
#Fill
#Exit
#Snap
#Increase
#Decrease
#RestrictX
#RestrictY
#RestrictZ
#SelectEdge
#AddHold
#Length
#Wipe
#SetWP
#Undo
if txt[0] in "0123456789":
self.updateSnapper()
return
spec = False
if txt.upper().startswith(inCommandShortcuts["Relative"][0]):
# Most frequently used shortcuts first:
if txt.upper().startswith(_get_incmd_shortcut("Relative")):
if self.isRelative.isVisible():
self.isRelative.setChecked(not self.isRelative.isChecked())
self.relativeMode = self.isRelative.isChecked()
spec = True
if txt.upper().startswith(inCommandShortcuts["Global"][0]):
elif txt.upper().startswith(_get_incmd_shortcut("Global")):
if self.isGlobal.isVisible():
self.isGlobal.setChecked(not self.isGlobal.isChecked())
self.globalMode = self.isGlobal.isChecked()
spec = True
elif txt.upper().startswith(inCommandShortcuts["Fill"][0]):
if self.hasFill.isVisible():
self.hasFill.setChecked(not self.hasFill.isChecked())
elif txt.upper().startswith(_get_incmd_shortcut("Length")):
if self.lengthValue.isVisible():
self.constrain("angle")
self.displayPoint()
spec = True
elif txt.upper().startswith(inCommandShortcuts["Exit"][0]):
if self.finishButton.isVisible():
self.finish()
elif txt.upper().startswith(inCommandShortcuts["Continue"][0]):
if self.continueCmd.isVisible():
self.toggleContinue()
spec = True
elif txt.upper().startswith(inCommandShortcuts["Wipe"][0]):
if self.wipeButton.isVisible():
self.wipeLine()
spec = True
elif txt.upper().startswith(inCommandShortcuts["SelectEdge"][0]):
self.selectEdge()
spec = True
elif txt.upper().startswith(inCommandShortcuts["Snap"][0]):
self.togglesnap()
spec = True
elif txt.upper().startswith(inCommandShortcuts["Increase"][0]):
self.toggleradius(1)
spec = True
elif txt.upper().startswith(inCommandShortcuts["Decrease"][0]):
self.toggleradius(-1)
spec = True
elif txt.upper().startswith(inCommandShortcuts["AddHold"][0]):
if hasattr(FreeCADGui,"Snapper"):
FreeCADGui.Snapper.addHoldPoint()
spec = True
elif txt.upper().startswith(inCommandShortcuts["RestrictX"][0]):
elif txt.upper().startswith(_get_incmd_shortcut("RestrictX")):
self.constrain("x")
self.displayPoint()
spec = True
elif txt.upper().startswith(inCommandShortcuts["RestrictY"][0]):
elif txt.upper().startswith(_get_incmd_shortcut("RestrictY")):
self.constrain("y")
self.displayPoint()
spec = True
elif txt.upper().startswith(inCommandShortcuts["RestrictZ"][0]):
elif txt.upper().startswith(_get_incmd_shortcut("RestrictZ")):
self.constrain("z")
self.displayPoint()
spec = True
elif txt.upper().startswith(inCommandShortcuts["Length"][0]):
self.constrain("angle")
self.displayPoint()
spec = True
elif txt.upper().startswith(inCommandShortcuts["Close"][0]):
if self.closeButton.isVisible():
self.closeLine()
elif txt.upper().startswith(inCommandShortcuts["SetWP"][0]):
if self.orientWPButton.isVisible():
self.orientWP()
spec = True
elif txt.upper().startswith(inCommandShortcuts["Copy"][0]):
elif txt.upper().startswith(_get_incmd_shortcut("Copy")):
if self.isCopy.isVisible():
self.isCopy.setChecked(not self.isCopy.isChecked())
spec = True
elif txt.upper().startswith(inCommandShortcuts["Undo"][0]):
self.undoSegment()
elif txt.upper().startswith(_get_incmd_shortcut("Exit")):
if self.finishButton.isVisible():
self.finish()
elif txt.upper().startswith(_get_incmd_shortcut("Close")):
if self.closeButton.isVisible():
self.closeLine()
elif txt.upper().startswith(_get_incmd_shortcut("AddHold")):
if hasattr(FreeCADGui,"Snapper"):
FreeCADGui.Snapper.addHoldPoint()
spec = True
elif txt.upper().startswith(inCommandShortcuts["SubelementMode"][0]):
elif txt.upper().startswith(_get_incmd_shortcut("Snap")):
self.togglesnap()
spec = True
elif txt.upper().startswith(_get_incmd_shortcut("Fill")):
if self.hasFill.isVisible():
self.hasFill.setChecked(not self.hasFill.isChecked())
spec = True
elif txt.upper().startswith(_get_incmd_shortcut("Continue")):
if self.continueCmd.isVisible():
self.toggleContinue()
spec = True
elif txt.upper().startswith(_get_incmd_shortcut("SetWP")):
if self.orientWPButton.isVisible():
self.orientWP()
spec = True
elif txt.upper().startswith(_get_incmd_shortcut("SelectEdge")):
self.selectEdge()
spec = True
elif txt.upper().startswith(_get_incmd_shortcut("SubelementMode")):
if self.isSubelementMode.isVisible():
self.isSubelementMode.setChecked(not self.isSubelementMode.isChecked())
spec = True
elif txt.upper().startswith(_get_incmd_shortcut("Wipe")):
if self.wipeButton.isVisible():
self.wipeLine()
spec = True
elif txt.upper().startswith(_get_incmd_shortcut("Undo")):
self.undoSegment()
spec = True
elif txt.upper().startswith(_get_incmd_shortcut("IncreaseRadius")):
self.toggleradius(1)
spec = True
elif txt.upper().startswith(_get_incmd_shortcut("DecreaseRadius")):
self.toggleradius(-1)
spec = True
if spec:
widget = self.baseWidget.focusWidget()
field = self.input_fields[widget.objectName()]
@@ -1323,26 +1275,26 @@ class DraftToolBar:
# set widgets
if dp:
if self.mask in ['y','z']:
self.xValue.setText(displayExternal(dp.x,None,'Length'))
self.xValue.setText(display_external(dp.x,None,'Length'))
else:
self.xValue.setText(displayExternal(dp.x,None,'Length'))
self.xValue.setText(display_external(dp.x,None,'Length'))
if self.mask in ['x','z']:
self.yValue.setText(displayExternal(dp.y,None,'Length'))
self.yValue.setText(display_external(dp.y,None,'Length'))
else:
self.yValue.setText(displayExternal(dp.y,None,'Length'))
self.yValue.setText(display_external(dp.y,None,'Length'))
if self.mask in ['x','y']:
self.zValue.setText(displayExternal(dp.z,None,'Length'))
self.zValue.setText(display_external(dp.z,None,'Length'))
else:
self.zValue.setText(displayExternal(dp.z,None,'Length'))
self.zValue.setText(display_external(dp.z,None,'Length'))
# set length and angle
if last and dp and plane:
length, theta, phi = DraftVecUtils.get_spherical_coords(*dp)
theta = math.degrees(theta)
phi = math.degrees(phi)
self.lengthValue.setText(displayExternal(length,None,'Length'))
self.lengthValue.setText(display_external(length,None,'Length'))
#if not self.angleLock.isChecked():
self.angleValue.setText(displayExternal(phi,None,'Angle'))
self.angleValue.setText(display_external(phi,None,'Angle'))
if not mask:
# automask, phi is rounded to identify one of the below cases
phi = round(phi, Draft.precision())
@@ -1419,7 +1371,7 @@ class DraftToolBar:
else:
print("draft: error: couldn't get a color for ",type," type.")
if rgb:
return("rgb("+str(int(r*255))+","+str(int(g*255))+","+str(int(b*255))+")")
return("rgb("+str(int(r*255))+","+str(int(g*255))+","+str(int(b*255)) + ")")
else:
return (r,g,b)
@@ -1518,10 +1470,10 @@ class DraftToolBar:
if not isinstance(val, (int, float)): #??some code passes strings or ???
t = val
elif unit:
t= displayExternal(val,None, unit)
t= display_external(val,None, unit)
else:
print("Error: setRadiusValue called for number without Dimension")
t = displayExternal(val,None, None)
t = display_external(val,None, None)
self.radiusValue.setText(t)
self.radiusValue.setFocus()
@@ -1646,17 +1598,17 @@ class DraftToolBar:
self.avalue = math.degrees(phi)
self.angle = FreeCAD.Vector(DraftVecUtils.get_cartesian_coords(
1, theta, phi))
self.lengthValue.setText(displayExternal(self.lvalue,None,'Length'))
self.angleValue.setText(displayExternal(self.avalue,None,'Angle'))
self.lengthValue.setText(display_external(self.lvalue,None,'Length'))
self.angleValue.setText(display_external(self.avalue,None,'Angle'))
def update_cartesian_coords(self):
self.x, self.y, self.z = DraftVecUtils.get_cartesian_coords(
self.lvalue,math.radians(self.pvalue),math.radians(self.avalue))
self.angle = FreeCAD.Vector(DraftVecUtils.get_cartesian_coords(
1, math.radians(self.pvalue), math.radians(self.avalue)))
self.xValue.setText(displayExternal(self.x,None,'Length'))
self.yValue.setText(displayExternal(self.y,None,'Length'))
self.zValue.setText(displayExternal(self.z,None,'Length'))
self.xValue.setText(display_external(self.x,None,'Length'))
self.yValue.setText(display_external(self.y,None,'Length'))
self.zValue.setText(display_external(self.z,None,'Length'))
#---------------------------------------------------------------------------
# TaskView operations