Skip to content

Commit

Permalink
Polishing PathDrilling
Browse files Browse the repository at this point in the history
  • Loading branch information
pekkaroi authored and wwmayer committed May 10, 2017
1 parent 5150ea3 commit 3e7cab0
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 66 deletions.
45 changes: 12 additions & 33 deletions src/Mod/Path/Gui/Resources/panels/DrillingEdit.ui
Expand Up @@ -162,20 +162,6 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="Gui::InputField" name="peckDepth">
<property name="unit" stdset="0">
<string notr="true">mm</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Peck Depth</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="Heights">
Expand Down Expand Up @@ -223,20 +209,6 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="Gui::InputField" name="retractHeight">
<property name="unit" stdset="0">
<string notr="true">mm</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Retract Height</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="Operation">
Expand Down Expand Up @@ -299,9 +271,16 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QCheckBox" name="checkBox">
<widget class="QCheckBox" name="peckEnabled">
<property name="text">
<string>Peck (using step depth value)</string>
<string>Peck</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::InputField" name="peckDepth">
<property name="unit" stdset="0">
<string notr="true">mm</string>
</property>
</widget>
</item>
Expand All @@ -317,7 +296,7 @@
</widget>
</item>
<item>
<widget class="Gui::InputField" name="retractHeight_2">
<widget class="Gui::InputField" name="retractHeight">
<property name="unit" stdset="0">
<string notr="true">mm</string>
</property>
Expand All @@ -328,14 +307,14 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QCheckBox" name="checkBox_2">
<widget class="QCheckBox" name="dwellEnabled">
<property name="text">
<string>Dwell</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::InputField" name="retractHeight_3">
<widget class="Gui::InputField" name="dwellTime">
<property name="text">
<string>0 sec</string>
</property>
Expand Down
103 changes: 70 additions & 33 deletions src/Mod/Path/PathScripts/PathDrilling.py
Expand Up @@ -63,8 +63,7 @@ def __init__(self, obj):
obj.addProperty("App::PropertyStringList", "Names", "Path", QtCore.QT_TRANSLATE_NOOP("App::Property", "Names of the holes"))
obj.addProperty("App::PropertyVectorList", "Positions", "Path", QtCore.QT_TRANSLATE_NOOP("App::Property", "Locations of insterted holes"))
obj.addProperty("App::PropertyIntegerList", "Enabled", "Path", QtCore.QT_TRANSLATE_NOOP("App::Property", "Enable/disable status of the holes"))
obj.addProperty("App::PropertyFloatList", "Diameters", "Path", QtCore.QT_TRANSLATE_NOOP("App::Property", "Diameters holes"))

obj.addProperty("App::PropertyFloatList", "Diameters", "Path", QtCore.QT_TRANSLATE_NOOP("App::Property", "Diameters of the holes"))

# General Properties
obj.addProperty("App::PropertyBool", "Active", "Path", QtCore.QT_TRANSLATE_NOOP("App::Property","Make False, to prevent operation from generating code"))
Expand All @@ -73,8 +72,10 @@ def __init__(self, obj):

# Drilling Properties
obj.addProperty("App::PropertyLength", "PeckDepth", "Depth", QtCore.QT_TRANSLATE_NOOP("App::Property", "Incremental Drill depth before retracting to clear chips"))
obj.addProperty("App::PropertyBool", "PeckEnabled", "Depth", QtCore.QT_TRANSLATE_NOOP("App::Property", "Enable pecking"))
obj.addProperty("App::PropertyLength", "StartDepth", "Depth", QtCore.QT_TRANSLATE_NOOP("App::Property", "Starting Depth of Tool- first cut depth in Z"))
obj.addProperty("App::PropertyFloat", "DwellTime", "Depth", QtCore.QT_TRANSLATE_NOOP("App::Property", "The time to dwell between peck cycles"))
obj.addProperty("App::PropertyBool", "DwellEnabled", "Depth", QtCore.QT_TRANSLATE_NOOP("App::Property", "Enable dwell"))

# Heights & Depths
obj.addProperty("App::PropertyDistance", "ClearanceHeight", "Depth", QtCore.QT_TRANSLATE_NOOP("App::Property", "The height needed to clear clamps and obstructions"))
Expand Down Expand Up @@ -164,12 +165,12 @@ def execute(self, obj):
if baseobject is None:
return

#Arch PanelSheet
if hasattr(baseobject, "Proxy"):
holes = []
if isinstance(baseobject.Proxy, ArchPanel.PanelSheet):
baseobject.Proxy.execute(baseobject)
i=0;
PathLog.debug('Entering new PanelCut')
holeshapes = baseobject.Proxy.getHoles(baseobject, transform=True)
tooldiameter = obj.ToolController.Proxy.getTool(obj.ToolController).Diameter
for holeshape in holeshapes:
Expand All @@ -182,20 +183,22 @@ def execute(self, obj):
x = edge.Curve.Center.x
y = edge.Curve.Center.y
diameter = edge.BoundBox.XLength
holes.append({'x':x, 'y':y, 'featureName':'PanelEdge'+str(i),'d':diameter})
holes.append({'x':x, 'y':y, 'featureName':baseobject.Name+'.'+'Drill'+str(i),'d':diameter})
i=i+1





else:
holes = self.findHoles(obj, baseobject.Shape)
for i in range(len(holes)):
holes[i]['featureName'] = baseobject.Name + '.' + holes[i]['featureName']
names = []
positions = []
enabled = []
diameters = []
for h in holes:
if len(names)==0:
self.findHeights(obj, baseobject, h)
names.append(h['featureName'])
positions.append(FreeCAD.Vector(h['x'], h['y'],0))
enabled.append(1)
Expand Down Expand Up @@ -225,10 +228,10 @@ def execute(self, obj):
output += "G0 Z" + fmt(obj.ClearanceHeight.Value) + "F " + PathUtils.fmt(self.vertRapid) + "\n"
pword = ""
qword = ""
if obj.PeckDepth.Value > 0:
if obj.PeckDepth.Value > 0 and obj.PeckEnabled:
cmd = "G83"
qword = " Q" + fmt(obj.PeckDepth.Value)
elif obj.DwellTime > 0:
elif obj.DwellTime > 0 and obj.DwellEnabled:
cmd = "G82"
pword = " P" + fmt(obj.DwellTime)
else:
Expand All @@ -253,6 +256,27 @@ def execute(self, obj):
obj.Path = path
obj.ViewObject.Visibility = False

def findHeights(self, obj, bobj, hole):
try:
bb = bobj.Shape.BoundBox
subobj = hole['feature']
fbb = subobj.BoundBox
obj.StartDepth = bb.ZMax
obj.ClearanceHeight = bb.ZMax + 5.0
obj.SafeHeight = bb.ZMax + 3.0
obj.RetractHeight = bb.ZMax + 1.0

if fbb.ZMax < bb.ZMax:
obj.FinalDepth = fbb.ZMax
else:
obj.FinalDepth = bb.ZMin
except:
obj.StartDepth = 5.0
obj.ClearanceHeight = 10.0
obj.SafeHeight = 8.0
obj.RetractHeight = 6.0


def findHoles(self, obj, shape):
import DraftGeomUtils as dgu
PathLog.track('obj: {} shape: {}'.format(obj, shape))
Expand All @@ -265,7 +289,7 @@ def findHoles(self, obj, shape):
candidateEdgeName = "Edge" + str(i +1)
e = shape.getElement(candidateEdgeName)
if PathUtils.isDrillable(shape, e, tooldiameter):
PathLog.debug('edge candidate: {} is drillable '.format(e))
PathLog.debug('edge candidate: {} (hash {})is drillable '.format(e, e.hashCode()))
x = e.Curve.Center.x
y = e.Curve.Center.y
diameter = e.BoundBox.XLength
Expand Down Expand Up @@ -389,6 +413,14 @@ def getFields(self):
self.obj.ClearanceHeight = FreeCAD.Units.Quantity(self.form.clearanceHeight.text()).Value
if hasattr(self.obj, "RetractHeight"):
self.obj.RetractHeight = FreeCAD.Units.Quantity(self.form.retractHeight.text()).Value
if hasattr(self.obj, "DwellTime"):
self.obj.DwellTime = FreeCAD.Units.Quantity(self.form.dwellTime.text()).Value

if hasattr(self.obj, "DwellEnabled"):
self.obj.DwellEnabled = self.form.dwellEnabled.isChecked()
if hasattr(self.obj, "PeckEnabled"):
self.obj.PeckEnabled = self.form.peckEnabled.isChecked()

if hasattr(self.obj, "ToolController"):
PathLog.debug("name: {}".format(self.form.uiToolController.currentText()))
tc = PathUtils.findToolController(self.obj, self.form.uiToolController.currentText())
Expand All @@ -402,20 +434,23 @@ def updateFeatureList(self):
self.form.baseList.setColumnCount(2)
self.form.baseList.setRowCount(0)
self.form.baseList.setHorizontalHeaderLabels(["Feature", "Diameter"])
self.form.baseList.horizontalHeader().setResizeMode(QtGui.QHeaderView.Stretch)

self.form.baseList.horizontalHeader().setStretchLastSection(True)
self.form.baseList.resizeColumnToContents(0)
self.form.baseList.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
for i in range(len(self.obj.Names)):
self.form.baseList.insertRow(self.form.baseList.rowCount())
item = QtGui.QTableWidgetItem(self.obj.Names[i])
item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable)

if self.obj.Enabled[i] == True:
item.setCheckState(QtCore.Qt.Checked)
else:
item.setCheckState(QtCore.Qt.Unchecked)
self.form.baseList.setItem(self.form.baseList.rowCount()-1,0,item)
item = QtGui.QTableWidgetItem("{:.3f}".format(self.obj.Diameters[i]))
self.form.baseList.setItem(self.form.baseList.rowCount()-1,1,item)

self.form.baseList.setItem(self.form.baseList.rowCount()-1,1,item)
self.form.baseList.resizeColumnToContents(0)
self.form.baseList.itemChanged.connect(self.checkedChanged)

self.form.baseList.setSortingEnabled(True)
Expand All @@ -428,6 +463,17 @@ def setFields(self):
self.form.safeHeight.setText(FreeCAD.Units.Quantity(self.obj.SafeHeight.Value, FreeCAD.Units.Length).UserString)
self.form.clearanceHeight.setText(FreeCAD.Units.Quantity(self.obj.ClearanceHeight.Value, FreeCAD.Units.Length).UserString)
self.form.retractHeight.setText(FreeCAD.Units.Quantity(self.obj.RetractHeight.Value, FreeCAD.Units.Length).UserString)
self.form.dwellTime.setText(str(self.obj.DwellTime))

if self.obj.DwellEnabled:
self.form.dwellEnabled.setCheckState(QtCore.Qt.Checked)
else:
self.form.dwellEnabled.setCheckState(QtCore.Qt.Unchecked)

if self.obj.PeckEnabled:
self.form.peckEnabled.setCheckState(QtCore.Qt.Checked)
else:
self.form.peckEnabled.setCheckState(QtCore.Qt.Unchecked)

self.updateFeatureList()

Expand Down Expand Up @@ -455,13 +501,15 @@ def itemActivated(self):
FreeCADGui.Selection.clearSelection()
slist = self.form.baseList.selectedItems()
parentJob = PathUtils.findParentJob(self.obj)
obj = parentJob.Base
for i in slist:
if i.column() == 0:
if i.text() != "":
FreeCADGui.Selection.addSelection(obj, i.text())
else:
FreeCADGui.Selection.addSelection(obj)
objstring = i.text().partition(".")
obj = FreeCAD.ActiveDocument.getObject(objstring[0])
if obj is not None:
if objstring[2] != "":
FreeCADGui.Selection.addSelection(obj, objstring[2])
else:
FreeCADGui.Selection.addSelection(obj)

FreeCADGui.updateGui()

Expand Down Expand Up @@ -566,12 +614,15 @@ def setupUi(self):
self.form.startDepth.editingFinished.connect(self.getFields)
self.form.finalDepth.editingFinished.connect(self.getFields)
self.form.safeHeight.editingFinished.connect(self.getFields)
self.form.retractHeight.editingFinished.connect(self.getFields)
self.form.peckDepth.editingFinished.connect(self.getFields)
self.form.clearanceHeight.editingFinished.connect(self.getFields)
self.form.dwellTime.editingFinished.connect(self.getFields)
self.form.dwellEnabled.stateChanged.connect(self.getFields)
self.form.peckEnabled.stateChanged.connect(self.getFields)

#buttons
#self.form.uiEnableAll.clicked.connect(self.enableAll)
self.form.uiEnableSelected.clicked.connect(self.enableSelected)
#self.form.uiDisableAll.clicked.connect(self.disableAll)
self.form.uiDisableSelected.clicked.connect(self.disableSelected)
self.form.uiFindAllHoles.clicked.connect(self.findAll)
self.form.uiAddSelected.clicked.connect(self.addSelected)
Expand All @@ -584,20 +635,6 @@ def setupUi(self):

self.setFields()

class SelObserver:
def __init__(self):
import PathScripts.PathSelection as PST
PST.drillselect()

def __del__(self):
import PathScripts.PathSelection as PST
PST.clear()

def addSelection(self, doc, obj, sub, pnt):
FreeCADGui.doCommand('Gui.Selection.addSelection(FreeCAD.ActiveDocument.' + obj + ',"' + sub + '")')
FreeCADGui.updateGui()


if FreeCAD.GuiUp:
# register the FreeCAD command
FreeCADGui.addCommand('Path_Drilling', CommandPathDrilling())
Expand Down

0 comments on commit 3e7cab0

Please sign in to comment.