From 51ec213f452955c9fca887f83484ea5cb9a4a7ff Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Mon, 22 Aug 2016 17:34:38 -0300 Subject: [PATCH] Draft: Added Draft Slope command - allows to change the slope of a selected Line or Wire --- src/Mod/Arch/InitGui.py | 3 +- src/Mod/Draft/DraftTools.py | 55 ++- src/Mod/Draft/InitGui.py | 3 +- src/Mod/Draft/Resources/Draft.qrc | 1 + src/Mod/Draft/Resources/icons/Draft_Slope.svg | 415 ++++++++++++++++++ 5 files changed, 474 insertions(+), 3 deletions(-) create mode 100644 src/Mod/Draft/Resources/icons/Draft_Slope.svg diff --git a/src/Mod/Arch/InitGui.py b/src/Mod/Arch/InitGui.py index 16fad7faeae6..f12e4a6999ce 100644 --- a/src/Mod/Arch/InitGui.py +++ b/src/Mod/Arch/InitGui.py @@ -62,7 +62,8 @@ def Initialize(self): "Draft_ShowSnapBar","Draft_ToggleGrid","Draft_UndoLine", "Draft_FinishLine","Draft_CloseLine"] self.draftutils = ["Draft_VisGroup","Draft_Heal","Draft_FlipDimension", - "Draft_ToggleConstructionMode","Draft_ToggleContinueMode","Draft_Edit"] + "Draft_ToggleConstructionMode","Draft_ToggleContinueMode","Draft_Edit", + "Draft_Slope"] self.snapList = ['Draft_Snap_Lock','Draft_Snap_Midpoint','Draft_Snap_Perpendicular', 'Draft_Snap_Grid','Draft_Snap_Intersection','Draft_Snap_Parallel', 'Draft_Snap_Endpoint','Draft_Snap_Angle','Draft_Snap_Center', diff --git a/src/Mod/Draft/DraftTools.py b/src/Mod/Draft/DraftTools.py index b7b8a295d2fa..44cf592cb7b4 100644 --- a/src/Mod/Draft/DraftTools.py +++ b/src/Mod/Draft/DraftTools.py @@ -604,7 +604,7 @@ def Activated(self): ['Draft.makeWire(['+pts+'])']+rems)]) return - Line.Activated(self,name=translate("draft","DWire")) + Line.Activated(self,name=translate("draft","DWire")) class BSpline(Line): @@ -4564,6 +4564,58 @@ def numericInput(self,numx,numy,numz): self.finish() +class Draft_Slope(): + + def GetResources(self): + return {'Pixmap' : 'Draft_Slope', + 'MenuText': QtCore.QT_TRANSLATE_NOOP("Draft_Slope", "Set slope"), + 'ToolTip' : QtCore.QT_TRANSLATE_NOOP("Draft_Slope", "Sets the slope of a selected line or wire")} + + def Activated(self): + if not FreeCADGui.Selection.getSelection(): + return + for obj in FreeCADGui.Selection.getSelection(): + if Draft.getType(obj) != "Wire": + msg(translate("draft", "This tool only works with Wires and Lines\n")) + return + w = QtGui.QWidget() + w.setWindowTitle(translate("Draft","Slope")) + layout = QtGui.QHBoxLayout(w) + label = QtGui.QLabel(w) + label.setText(translate("Draft", "Slope")+":") + layout.addWidget(label) + self.spinbox = QtGui.QDoubleSpinBox(w) + self.spinbox.setMinimum(-9999.99) + self.spinbox.setMaximum(9999.99) + self.spinbox.setSingleStep(0.01) + self.spinbox.setToolTip(translate("Draft", "Slope to give toselected Wires/Lines: 0 = horizontal, 1 = 45deg up, -1 = 45deg down")) + layout.addWidget(self.spinbox) + taskwidget = QtGui.QWidget() + taskwidget.form = w + taskwidget.accept = self.accept + FreeCADGui.Control.showDialog(taskwidget) + + def accept(self): + if hasattr(self,"spinbox"): + pc = self.spinbox.value() + FreeCAD.ActiveDocument.openTransaction("Change slope") + for obj in FreeCADGui.Selection.getSelection(): + if Draft.getType(obj) == "Wire": + if len(obj.Points) > 1: + lp = None + np = [] + for p in obj.Points: + if not lp: + lp = p + else: + z = pc*FreeCAD.Vector(p.x,p.y,lp.z).Length + lp = FreeCAD.Vector(p.x,p.y,z) + np.append(lp) + obj.Points = np + FreeCAD.ActiveDocument.commitTransaction() + FreeCADGui.Control.closeDialog() + FreeCAD.ActiveDocument.recompute() + #--------------------------------------------------------------------------- # Snap tools #--------------------------------------------------------------------------- @@ -4788,6 +4840,7 @@ def Activated(self): FreeCADGui.addCommand('Draft_Heal',Heal()) FreeCADGui.addCommand('Draft_VisGroup',VisGroup()) FreeCADGui.addCommand('Draft_Mirror',Mirror()) +FreeCADGui.addCommand('Draft_Slope',Draft_Slope()) # context commands FreeCADGui.addCommand('Draft_FinishLine',FinishLine()) diff --git a/src/Mod/Draft/InitGui.py b/src/Mod/Draft/InitGui.py index bc236e501441..4aad8f8f0c73 100644 --- a/src/Mod/Draft/InitGui.py +++ b/src/Mod/Draft/InitGui.py @@ -82,7 +82,8 @@ def QT_TRANSLATE_NOOP(scope, text): "Draft_ShowSnapBar","Draft_ToggleGrid"] self.lineList = ["Draft_UndoLine","Draft_FinishLine","Draft_CloseLine"] self.utils = ["Draft_VisGroup","Draft_Heal","Draft_FlipDimension", - "Draft_ToggleConstructionMode","Draft_ToggleContinueMode","Draft_Edit"] + "Draft_ToggleConstructionMode","Draft_ToggleContinueMode","Draft_Edit", + "Draft_Slope"] self.snapList = ['Draft_Snap_Lock','Draft_Snap_Midpoint','Draft_Snap_Perpendicular', 'Draft_Snap_Grid','Draft_Snap_Intersection','Draft_Snap_Parallel', 'Draft_Snap_Endpoint','Draft_Snap_Angle','Draft_Snap_Center', diff --git a/src/Mod/Draft/Resources/Draft.qrc b/src/Mod/Draft/Resources/Draft.qrc index bc07b6813d9a..2ade2035bec6 100644 --- a/src/Mod/Draft/Resources/Draft.qrc +++ b/src/Mod/Draft/Resources/Draft.qrc @@ -69,6 +69,7 @@ icons/Draft_FlipDimension.svg icons/Draft_Mirror.svg icons/Draft_Grid.svg + icons/Draft_Slope.svg icons/DraftWorkbench.svg patterns/concrete.svg patterns/cross.svg diff --git a/src/Mod/Draft/Resources/icons/Draft_Slope.svg b/src/Mod/Draft/Resources/icons/Draft_Slope.svg new file mode 100644 index 000000000000..3231a10a9261 --- /dev/null +++ b/src/Mod/Draft/Resources/icons/Draft_Slope.svg @@ -0,0 +1,415 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + +