Path: Finish GUI & Cleanup

This commit is contained in:
sliptonic
2018-09-18 09:46:04 -05:00
parent 61908e5cc7
commit 65fcda7daa
3 changed files with 42 additions and 43 deletions

View File

@@ -20,6 +20,10 @@
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# * Bilinear interpolation code modified heavily from the interpolation *
# * library https://github.com/pmav99/interpolation *
# * Copyright (c) 2013 by Panagiotis Mavrogiorgos *
# * *
# ***************************************************************************
import FreeCAD
import FreeCADGui
@@ -27,7 +31,7 @@ import Path
import PathScripts.PathUtils as PathUtils
from bisect import bisect_left
from PySide import QtCore, QtGui
from PySide import QtCore
"""Z Depth Correction Dressup. This dressup takes a probe file as input and does bilinear interpolation of the Zdepths to correct for a surface which is not parallel to the milling table/bed. The probe file should conform to the format specified by the linuxcnc G38 probe logging: 9-number coordinate consisting of XYZABCUVW http://linuxcnc.org/docs/html/gcode/g-code.html#gcode:g38
"""
@@ -69,28 +73,22 @@ class ObjectDressup:
i = bisect_left(x_index, x) - 1
j = bisect_left(y_index, y) - 1
if True: #self.extrapolate:
# fix x index
if i == -1:
x_slice = slice(None, 2)
elif i == self.x_length - 1:
x_slice = slice(-2, None)
else:
x_slice = slice(i, i + 2)
# fix y index
if j == -1:
j = 0
y_slice = slice(None, 2)
elif j == self.y_length - 1:
j = -2
y_slice = slice(-2, None)
else:
y_slice = slice(j, j + 2)
# fix x index
if i == -1:
x_slice = slice(None, 2)
elif i == self.x_length - 1:
x_slice = slice(-2, None)
else:
if i == -1 or i == self.x_length - 1:
raise ValueError("Extrapolation not allowed!")
if j == -1 or j == self.y_length - 1:
raise ValueError("Extrapolation not allowed!")
x_slice = slice(i, i + 2)
# fix y index
if j == -1:
j = 0
y_slice = slice(None, 2)
elif j == self.y_length - 1:
j = -2
y_slice = slice(-2, None)
else:
y_slice = slice(j, j + 2)
x1, x2 = x_index[x_slice]
y1, y2 = y_index[y_slice]

View File

@@ -63,11 +63,13 @@ class ObjectProbing(PathOp.ObjectOp):
obj.addProperty("App::PropertyInteger", "PointCountX", "Probe", QtCore.QT_TRANSLATE_NOOP("App::Property", "Number of points to probe in X direction"))
obj.addProperty("App::PropertyInteger", "PointCountY", "Probe", QtCore.QT_TRANSLATE_NOOP("App::Property", "Number of points to probe in Y direction"))
obj.addProperty("App::PropertyFile", "OutputFileName", "Path", QtCore.QT_TRANSLATE_NOOP("App::Property", "The output location for the probe data to be written"))
def drange(self, start=1.0, stop=5.0, step=1.0):
r = start
while r <= stop:
yield r
r += step
def nextpoint(self, startpoint=0.0, endpoint=0.0, count=3):
curstep = 0
dist = (endpoint - startpoint) / (count - 1)
while curstep <= count-1:
yield startpoint + (curstep * dist)
curstep += 1
def opExecute(self, obj):
'''opExecute(obj) ... generate probe locations.'''
@@ -77,15 +79,12 @@ class ObjectProbing(PathOp.ObjectOp):
stock = PathUtils.findParentJob(obj).Stock
bb = stock.Shape.BoundBox
xdist = (bb.XMax - bb.XMin)/ (obj.PointCountX - 1)
ydist = (bb.YMax - bb.YMin)/ (obj.PointCountY - 1)
openstring = '(PROBEOPEN {})'.format(obj.OutputFileName)
self.commandlist.append(Path.Command(openstring))
self.commandlist.append(Path.Command("G0", {"Z":obj.ClearanceHeight.Value}))
self.commandlist.append(Path.Command("G0", {"X":bb.XMin, "Y":bb.YMin, "Z":obj.SafeHeight.Value}))
for x in self.drange(bb.XMin, bb.XMax, xdist):
for y in self.drange(bb.YMin, bb.YMax, ydist):
for x in self.nextpoint(bb.XMin, bb.XMax, obj.PointCountX):
for y in self.nextpoint(bb.YMin, bb.YMax, obj.PointCountY):
self.commandlist.append(Path.Command("G0", {"X":x + obj.Xoffset.Value, "Y":y + obj.Yoffset.Value, "Z":obj.SafeHeight.Value}))
self.commandlist.append(Path.Command("G38.2",{"Z":obj.FinalDepth.Value, "F":obj.ToolController.VertFeed.Value}))
self.commandlist.append(Path.Command("G0", {"Z":obj.SafeHeight.Value}))
@@ -97,7 +96,7 @@ class ObjectProbing(PathOp.ObjectOp):
'''opSetDefaultValues(obj, job) ... set default value for RetractHeight'''
def SetupProperties():
setup = ['Xoffset', 'Yoffset', 'PointCountX', 'PointCountY']
setup = ['Xoffset', 'Yoffset', 'PointCountX', 'PointCountY', 'OutputFileName']
return setup
def Create(name, obj = None):

View File

@@ -35,6 +35,10 @@ __author__ = "sliptonic (Brad Collette)"
__url__ = "http://www.freecadweb.org"
__doc__ = "Probing operation page controller and command implementation."
# Qt tanslation handling
def translate(context, text, disambig=None):
return QtCore.QCoreApplication.translate(context, text, disambig)
class TaskPanelOpPage(PathOpGui.TaskPanelPage):
'''Page controller class for the Probing operation.'''
@@ -44,8 +48,6 @@ class TaskPanelOpPage(PathOpGui.TaskPanelPage):
def getFields(self, obj):
'''getFields(obj) ... transfers values from UI to obj's proprties'''
# if obj.StartVertex != self.form.startVertex.value():
# obj.StartVertex = self.form.startVertex.value()
self.updateToolController(obj, self.form.toolController)
PathGui.updateInputField(obj, 'Xoffset', self.form.Xoffset)
PathGui.updateInputField(obj, 'Yoffset', self.form.Yoffset)
@@ -55,7 +57,6 @@ class TaskPanelOpPage(PathOpGui.TaskPanelPage):
def setFields(self, obj):
'''setFields(obj) ... transfers obj's property values to UI'''
#self.form.startVertex.setValue(obj.StartVertex)
self.setupToolController(obj, self.form.toolController)
self.form.Xoffset.setText(FreeCAD.Units.Quantity(obj.Xoffset.Value, FreeCAD.Units.Length).UserString)
self.form.Yoffset.setText(FreeCAD.Units.Quantity(obj.Yoffset.Value, FreeCAD.Units.Length).UserString)
@@ -72,14 +73,15 @@ class TaskPanelOpPage(PathOpGui.TaskPanelPage):
signals.append(self.form.OutputFileName.editingFinished)
signals.append(self.form.Xoffset.valueChanged)
signals.append(self.form.Yoffset.valueChanged)
signals.append(self.form.SetOutputFileName.clicked)
#signals.append(self.form.SetOutputFileName.clicked)
self.form.SetOutputFileName.clicked.connect(self.SetOutputFileName)
return signals
# def SetOutputFileName(self):
# filename = QtGui.QFileDialog.getSaveFileName(self.form, translate("Path_Probe", "Select Output File"), None, translate("Path_Probe", "All Files (*.*)"))
# if filename and filename[0]:
# self.obj.OutputFileName = str(filename[0])
# self.setFields()
def SetOutputFileName(self):
filename = QtGui.QFileDialog.getSaveFileName(self.form, translate("Path_Probe", "Select Output File"), None, translate("Path_Probe", "All Files (*.*)"))
if filename and filename[0]:
self.obj.OutputFileName = str(filename[0])
self.setFields(self.obj)
Command = PathOpGui.SetupOperation('Probe',
PathProbe.Create,