| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | """Provides GUI tools to change the slope of a line. |
| | |
| | It currently only works for a line in the XY plane, it changes the height |
| | of one of its points in the Z direction to create a sloped line. |
| | """ |
| | |
| | |
| | |
| |
|
| | |
| | |
| | import PySide.QtWidgets as QtWidgets |
| | from PySide.QtCore import QT_TRANSLATE_NOOP |
| |
|
| | import FreeCAD as App |
| | import FreeCADGui as Gui |
| | from draftguitools import gui_base |
| | from draftutils import params |
| | from draftutils import utils |
| | from draftutils.translate import translate |
| |
|
| |
|
| | class LineSlope(gui_base.GuiCommandNeedsSelection): |
| | """Gui Command for the Line slope tool. |
| | |
| | For a line in the XY plane, it changes the height of one of its points |
| | to create a sloped line. |
| | |
| | To Do |
| | ----- |
| | Make it work also with lines lying on the YZ and XZ planes, |
| | or in an arbitrary plane, for which the normal is known. |
| | """ |
| |
|
| | def __init__(self): |
| | super().__init__(name=translate("draft", "Change Slope")) |
| |
|
| | def GetResources(self): |
| | """Set icon, menu and tooltip.""" |
| |
|
| | return { |
| | "Pixmap": "Draft_Slope", |
| | "MenuText": QT_TRANSLATE_NOOP("Draft_Slope", "Set Slope"), |
| | "ToolTip": QT_TRANSLATE_NOOP( |
| | "Draft_Slope", |
| | "Sets the slope of the selected line by changing the value of the Z value of one of its points.\nIf a polyline is selected, it will apply the slope transformation to each of its segments.\n\nThe slope will always change the Z value, therefore this command only works well for\nstraight Draft lines that are drawn on the XY-plane.", |
| | ), |
| | } |
| |
|
| | def Activated(self): |
| | """Execute when the command is called.""" |
| | super().Activated() |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| | w = QtWidgets.QWidget() |
| | w.setWindowTitle(translate("Draft", "Slope")) |
| | layout = QtWidgets.QHBoxLayout(w) |
| | label = QtWidgets.QLabel(w) |
| | label.setText(translate("Draft", "Slope")) |
| | layout.addWidget(label) |
| | self.spinbox = QtWidgets.QDoubleSpinBox(w) |
| | self.spinbox.setDecimals(params.get_param("Decimals", path="Units")) |
| | self.spinbox.setMinimum(-9999.99) |
| | self.spinbox.setMaximum(9999.99) |
| | self.spinbox.setSingleStep(0.01) |
| |
|
| | _tip = ( |
| | "New slope of the selected lines.\n" |
| | "This is the tangent of the horizontal angle:\n" |
| | "0 = horizontal\n" |
| | "1 = 45 deg up\n" |
| | "-1 = 45deg down\n" |
| | ) |
| | label.setToolTip(translate("Draft", _tip)) |
| | self.spinbox.setToolTip(translate("Draft", _tip)) |
| | layout.addWidget(self.spinbox) |
| |
|
| | |
| | |
| | |
| | |
| | taskwidget = QtWidgets.QWidget() |
| | taskwidget.form = w |
| |
|
| | |
| | |
| | |
| | |
| | taskwidget.accept = self.accept |
| | Gui.Control.showDialog(taskwidget) |
| |
|
| | def accept(self): |
| | """Execute when clicking the OK button or pressing Enter key. |
| | |
| | It changes the slope of the line that lies on the XY plane. |
| | |
| | TODO: make it work also with lines lying on the YZ and XZ planes. |
| | """ |
| | if hasattr(self, "spinbox"): |
| | pc = self.spinbox.value() |
| | self.doc.openTransaction("Change slope") |
| | for obj in Gui.Selection.getSelection(): |
| | if utils.get_type(obj) == "Wire": |
| | if len(obj.Points) > 1: |
| | lp = None |
| | np = [] |
| | for p in obj.Points: |
| | if not lp: |
| | lp = p |
| | else: |
| | v = p.sub(lp) |
| | z = pc * App.Vector(v.x, v.y, 0).Length |
| | lp = App.Vector(p.x, p.y, lp.z + z) |
| | np.append(lp) |
| | obj.Points = np |
| | self.doc.commitTransaction() |
| | Gui.Control.closeDialog() |
| | self.doc.recompute() |
| |
|
| |
|
| | Draft_Slope = LineSlope |
| | Gui.addCommand("Draft_Slope", LineSlope()) |
| |
|
| | |
| |
|