Skip to content

Commit

Permalink
Draft: Added Draft Slope command - allows to change the slope of a se…
Browse files Browse the repository at this point in the history
…lected Line or Wire
  • Loading branch information
yorikvanhavre committed Aug 22, 2016
1 parent 94f07c8 commit 51ec213
Show file tree
Hide file tree
Showing 5 changed files with 474 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Mod/Arch/InitGui.py
Expand Up @@ -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',
Expand Down
55 changes: 54 additions & 1 deletion src/Mod/Draft/DraftTools.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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
#---------------------------------------------------------------------------
Expand Down Expand Up @@ -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())
Expand Down
3 changes: 2 additions & 1 deletion src/Mod/Draft/InitGui.py
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions src/Mod/Draft/Resources/Draft.qrc
Expand Up @@ -69,6 +69,7 @@
<file>icons/Draft_FlipDimension.svg</file>
<file>icons/Draft_Mirror.svg</file>
<file>icons/Draft_Grid.svg</file>
<file>icons/Draft_Slope.svg</file>
<file>icons/DraftWorkbench.svg</file>
<file>patterns/concrete.svg</file>
<file>patterns/cross.svg</file>
Expand Down

0 comments on commit 51ec213

Please sign in to comment.