From cef27c7a721b333f8fe9159ccdb684289ab0beb4 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Tue, 9 Jul 2019 12:29:32 -0300 Subject: [PATCH] Draft: Added button to working plane task panel to orient the view to the WP --- src/Mod/Draft/DraftGui.py | 11 +++++++++++ src/Mod/Draft/DraftTools.py | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/src/Mod/Draft/DraftGui.py b/src/Mod/Draft/DraftGui.py index bd6d520353..a2b5749f21 100644 --- a/src/Mod/Draft/DraftGui.py +++ b/src/Mod/Draft/DraftGui.py @@ -660,6 +660,9 @@ class DraftToolBar: self.snapLabel = self._label("snapLabel", gl) self.snapValue = self._spinbox("snapValue", gl) self.snapValue.setValue(Draft.getParam("snapRange", 8)) + bl = QtGui.QHBoxLayout() + self.layout.addLayout(bl) + self.alignToWPButton = self._pushbutton("alignToWP", bl,icon="dagViewVisible") # spacer if not self.taskmode: @@ -732,6 +735,7 @@ class DraftToolBar: QtCore.QObject.connect(self.mainlineValue,QtCore.SIGNAL("valueChanged(int)"),self.setMainline) QtCore.QObject.connect(self.centerPlane,QtCore.SIGNAL("stateChanged(int)"),self.setCenterPlane) QtCore.QObject.connect(self.snapValue,QtCore.SIGNAL("valueChanged(int)"),self.setSnapValue) + QtCore.QObject.connect(self.alignToWPButton,QtCore.SIGNAL("clicked()"),self.alignToWP) # following lines can cause a crash and are not needed anymore when using the task panel # http://forum.freecadweb.org/viewtopic.php?f=3&t=6952 @@ -888,6 +892,8 @@ class DraftToolBar: self.centerPlane.setToolTip(translate("draft", "Centers the working plane on the current view")) self.snapLabel.setText(translate("draft", "Snapping radius")) self.snapValue.setToolTip(translate("draft", "This is the distance in screen pixels under which a point will be snapped. You can also change the radius while drawing, using keys")+" "+inCommandShortcuts["Increase"][0]+" , "+inCommandShortcuts["Decrease"][0]) + self.alignToWPButton.setText(translate("draft", "Align view")) + self.alignToWPButton.setToolTip(translate("draft", "Aligns the view direction to face the current working plane")) self.retranslateTray(widget) # Update the maximum width of the push buttons @@ -1014,6 +1020,7 @@ class DraftToolBar: self.snapValue.show() p = Draft.getParam("snapRange", 8) self.snapValue.setValue(p) + self.alignToWPButton.show() def extraLineUi(self): '''shows length and angle controls''' @@ -1198,6 +1205,7 @@ class DraftToolBar: self.snapLabel.hide() self.snapValue.hide() self.WPLabel.hide() + self.alignToWPButton.hide() def trimUi(self,title=translate("draft","Trim")): self.taskUi(title) @@ -1714,6 +1722,9 @@ class DraftToolBar: def selectResetPlane(self): self.sourceCmd.selectHandler("reset") + def alignToWP(self): + self.sourceCmd.selectHandler("alignToWP") + def undoSegment(self): "undo last line segment" if hasattr(self.sourceCmd,"undolast"): diff --git a/src/Mod/Draft/DraftTools.py b/src/Mod/Draft/DraftTools.py index aaaf579317..1bdf6c2c2f 100644 --- a/src/Mod/Draft/DraftTools.py +++ b/src/Mod/Draft/DraftTools.py @@ -509,6 +509,11 @@ class SelectPlane(DraftTool): FreeCADGui.doCommandGui("FreeCAD.DraftWorkingPlane.reset()") self.display('Auto') self.finish() + elif arg == "alignToWP": + c = FreeCADGui.ActiveDocument.ActiveView.getCameraNode() + r = FreeCAD.DraftWorkingPlane.getRotation().Rotation.Q + c.orientation.setValue(r) + self.finish() def offsetHandler(self, arg): self.offset = arg