From d72d5a5b219bd2092cea0727f93df41854bcbe2c Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Fri, 10 May 2019 22:27:08 -0300 Subject: [PATCH] Draft: allow to use different snapping task dialogs --- src/Mod/Draft/DraftGui.py | 15 +++++++++------ src/Mod/Draft/DraftSnap.py | 17 ++++++++++++++--- src/Mod/Draft/DraftTools.py | 5 ++++- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/Mod/Draft/DraftGui.py b/src/Mod/Draft/DraftGui.py index d1a82a251c..52d2f0dfc9 100644 --- a/src/Mod/Draft/DraftGui.py +++ b/src/Mod/Draft/DraftGui.py @@ -945,6 +945,9 @@ class DraftToolBar: if p.GetBool("focusOnLength",False) and self.lengthValue.isVisible(): self.lengthValue.setFocus() self.lengthValue.selectAll() + elif self.angleLock.isVisible() and self.angleLock.isChecked(): + self.lengthValue.setFocus() + self.lengthValue.selectAll() elif f==None or f=="x": self.xValue.setFocus() self.xValue.selectAll() @@ -998,11 +1001,11 @@ class DraftToolBar: self.angleValue.hide() self.angleLock.hide() - def lineUi(self,title=None): + def lineUi(self,title=None,cancel=None,extra=None,getcoords=None,rel=False): if title: - self.pointUi(title,icon="Draft_Line") + self.pointUi(title,cancel,extra,getcoords,rel,icon="Draft_Line") else: - self.pointUi(translate("draft", "Line"),icon="Draft_Line") + self.pointUi(translate("draft", "Line"),cancel,extra,getcoords,rel,icon="Draft_Line") self.extraLineUi() self.xValue.setEnabled(True) self.yValue.setEnabled(True) @@ -1010,11 +1013,11 @@ class DraftToolBar: self.undoButton.show() self.continueCmd.show() - def wireUi(self,title=None): + def wireUi(self,title=None,cancel=None,extra=None,getcoords=None,rel=False): if title: - self.pointUi(title) + self.pointUi(title,cancel,extra,getcoords,rel) else: - self.pointUi(translate("draft", "DWire"),icon="Draft_Wire") + self.pointUi(translate("draft", "DWire"),cancel,extra,getcoords,rel,icon="Draft_Wire") self.xValue.setEnabled(True) self.yValue.setEnabled(True) self.isRelative.show() diff --git a/src/Mod/Draft/DraftSnap.py b/src/Mod/Draft/DraftSnap.py index 45c33a0e40..dbd24e80ca 100644 --- a/src/Mod/Draft/DraftSnap.py +++ b/src/Mod/Draft/DraftSnap.py @@ -1133,10 +1133,10 @@ class Snapper: if self.constrainLine: self.constrainLine.off() - def getPoint(self,last=None,callback=None,movecallback=None,extradlg=None): + def getPoint(self,last=None,callback=None,movecallback=None,extradlg=None,title=None,mode="point"): """ - getPoint([last],[callback],[movecallback],[extradlg]) : gets a 3D point + getPoint([last],[callback],[movecallback],[extradlg],[title]) : gets a 3D point from the screen. You can provide an existing point, in that case additional snap options and a tracker are available. You can also pass a function as callback, which will get called @@ -1155,6 +1155,8 @@ class Snapper: If the callback function accepts more than one argument, it will also receive the last snapped object. Finally, a qt widget can be passed as an extra taskbox. + title is the title of the point task box + mode is the dialog box you want (default is point, you can also use wire and line) If getPoint() is invoked without any argument, nothing is done but the callbacks are removed, so it can be used as a cancel function. @@ -1233,8 +1235,17 @@ class Snapper: callback(None) # adding callback functions + if mode == "line": + interface = self.ui.lineUi + elif mode == "wire": + interface = self.ui.wireUi + else: + interface = self.ui.pointUi if callback: - self.ui.pointUi(cancel=cancel,getcoords=getcoords,extra=extradlg,rel=bool(last)) + if title: + interface(title=title,cancel=cancel,getcoords=getcoords,extra=extradlg,rel=bool(last)) + else: + interface(cancel=cancel,getcoords=getcoords,extra=extradlg,rel=bool(last)) self.callbackClick = self.view.addEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(),click) self.callbackMove = self.view.addEventCallbackPivy(coin.SoLocation2Event.getClassTypeId(),move) diff --git a/src/Mod/Draft/DraftTools.py b/src/Mod/Draft/DraftTools.py index 5c08273c09..85d280842f 100644 --- a/src/Mod/Draft/DraftTools.py +++ b/src/Mod/Draft/DraftTools.py @@ -2547,6 +2547,7 @@ class Modifier(DraftTool): def __init__(self): DraftTool.__init__(self) + self.copymode = False class Move(Modifier): "The Draft_Move FreeCAD command definition" @@ -2581,8 +2582,10 @@ class Move(Modifier): self.selected_objects = FreeCADGui.Selection.getSelection() self.selected_objects = Draft.getGroupContents(self.selected_objects, addgroups=True, spaces=True, noarchchild=True) self.selected_subelements = FreeCADGui.Selection.getSelectionEx() - self.ui.pointUi(self.name) + self.ui.lineUi(self.name) self.ui.modUi() + if self.copymode: + self.ui.isCopy.setChecked(True) self.ui.xValue.setFocus() self.ui.xValue.selectAll() self.call = self.view.addEventCallback("SoEvent", self.action)