Skip to content

Commit

Permalink
Draft: Added button to working plane task panel to orient the view to…
Browse files Browse the repository at this point in the history
… the WP
  • Loading branch information
yorikvanhavre committed Jul 9, 2019
1 parent 78239e4 commit 7c53cbf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Mod/Draft/DraftGui.py
Expand Up @@ -660,6 +660,9 @@ def setupToolBar(self,task=False):
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:
Expand Down Expand Up @@ -732,6 +735,7 @@ def setupToolBar(self,task=False):
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
Expand Down Expand Up @@ -888,6 +892,8 @@ def retranslateUi(self, widget=None):
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
Expand Down Expand Up @@ -1014,6 +1020,7 @@ def selectPlaneUi(self):
self.snapValue.show()
p = Draft.getParam("snapRange", 8)
self.snapValue.setValue(p)
self.alignToWPButton.show()

def extraLineUi(self):
'''shows length and angle controls'''
Expand Down Expand Up @@ -1198,6 +1205,7 @@ def offUi(self):
self.snapLabel.hide()
self.snapValue.hide()
self.WPLabel.hide()
self.alignToWPButton.hide()

def trimUi(self,title=translate("draft","Trim")):
self.taskUi(title)
Expand Down Expand Up @@ -1714,6 +1722,9 @@ def selectCurrentView(self):
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"):
Expand Down
5 changes: 5 additions & 0 deletions src/Mod/Draft/DraftTools.py
Expand Up @@ -509,6 +509,11 @@ def selectHandler(self, arg):
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
Expand Down

0 comments on commit 7c53cbf

Please sign in to comment.