Skip to content

Commit

Permalink
fix error when discretize N=1
Browse files Browse the repository at this point in the history
cleanup
InitGui to add Path_Probe command
Probe setupsheet
  • Loading branch information
sliptonic committed Mar 26, 2020
1 parent 040324c commit 4e91020
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/Mod/Path/InitGui.py
Expand Up @@ -87,7 +87,7 @@ def Initialize(self):
# build commands list
projcmdlist = ["Path_Job", "Path_Post"]
toolcmdlist = ["Path_Inspect", "Path_Simulator", "Path_ToolLibraryEdit", "Path_SelectLoop", "Path_OpActiveToggle"]
prepcmdlist = ["Path_Fixture", "Path_Comment", "Path_Stop", "Path_Custom"]
prepcmdlist = ["Path_Fixture", "Path_Comment", "Path_Stop", "Path_Custom", "Path_Probe"]
twodopcmdlist = ["Path_Contour", "Path_Profile_Faces", "Path_Profile_Edges", "Path_Pocket_Shape", "Path_Drilling", "Path_MillFace", "Path_Helix", "Path_Adaptive" ]
threedopcmdlist = ["Path_Pocket_3D"]
engravecmdlist = ["Path_Engrave", "Path_Deburr"]
Expand Down
38 changes: 23 additions & 15 deletions src/Mod/Path/PathScripts/PathDressupZCorrect.py
Expand Up @@ -32,7 +32,6 @@
import PathScripts.PathGeom as PathGeom
import PathScripts.PathLog as PathLog
import PathScripts.PathUtils as PathUtils
#from bisect import bisect_left

from PySide import QtCore, QtGui

Expand All @@ -41,7 +40,7 @@

LOG_MODULE = PathLog.thisModule()

if True:
if False:
PathLog.setLevel(PathLog.Level.DEBUG, LOG_MODULE)
PathLog.setLevel(PathLog.Level.DEBUG, LOG_MODULE)
else:
Expand All @@ -52,10 +51,12 @@
def translate(context, text, disambig=None):
return QtCore.QCoreApplication.translate(context, text, disambig)


movecommands = ['G1', 'G01', 'G2', 'G02', 'G3', 'G03']
rapidcommands = ['G0', 'G00']
arccommands = ['G2', 'G3', 'G02', 'G03']


class ObjectDressup:

def __init__(self, obj):
Expand All @@ -68,6 +69,7 @@ def __init__(self, obj):
obj.addProperty("App::PropertyDistance", "SegInterpolate", "Interpolate", QtCore.QT_TRANSLATE_NOOP("Path_DressupZCorrectp", "break segments into smaller segments of this length."))
obj.ArcInterpolate = 0.1
obj.SegInterpolate = 1.0

def __getstate__(self):
return None

Expand All @@ -91,7 +93,7 @@ def _loadFile(self, obj, filename):
if filename == "":
return

f1 = open(filename, 'r')
f1 = open(filename, 'r')

try:
pointlist = []
Expand All @@ -101,7 +103,7 @@ def _loadFile(self, obj, filename):
yval = round(float(w[1]), 2)
zval = round(float(w[2]), 2)

pointlist.append([xval, yval,zval])
pointlist.append([xval, yval, zval])
PathLog.debug(pointlist)

cols = list(zip(*pointlist))
Expand All @@ -114,23 +116,22 @@ def _loadFile(self, obj, filename):
points = sorted([p for p in pointlist if p[1] == y])
inner = []
for p in points:
inner.append(FreeCAD.Vector(p[0],p[1],p[2]))
inner.append(FreeCAD.Vector(p[0], p[1], p[2]))
array.append(inner)

intSurf = Part.BSplineSurface()
intSurf.interpolate(array)

obj.interpSurface = intSurf.toShape()
except:
except Exception:
raise ValueError("File does not contain appropriate point data")


def execute(self, obj):

sampleD = obj.SegInterpolate.Value
curveD = obj.ArcInterpolate.Value

if obj.interpSurface.isNull(): #No valid probe data. return unchanged path
if obj.interpSurface.isNull(): # No valid probe data. return unchanged path
obj.Path = obj.Base.Path
return

Expand All @@ -143,9 +144,9 @@ def execute(self, obj):
pathlist = obj.Base.Path.Commands

newcommandlist = []
currLocation = {'X':0,'Y':0,'Z':0, 'F': 0}
currLocation = {'X': 0, 'Y': 0, 'Z': 0, 'F': 0}

for c in pathlist: #obj.Base.Path.Commands:
for c in pathlist:
PathLog.debug(c)
PathLog.debug(" curLoc:{}".format(currLocation))
newparams = dict(c.Parameters)
Expand All @@ -156,12 +157,16 @@ def execute(self, obj):
if arcwire is None:
continue
if c.Name in arccommands:
pointlist = arcwire.discretize(Deflection=curveD)
pointlist = arcwire.discretize(Deflection=curveD)
else:
pointlist = arcwire.discretize(Number=int(arcwire.Length / sampleD))
disc_number = int(arcwire.Length / sampleD)
if disc_number > 1:
pointlist = arcwire.discretize(Number=int(arcwire.Length / sampleD))
else:
pointlist = [v.Point for v in arcwire.Vertexes]
for point in pointlist:
offset = self._bilinearInterpolate(surface, point.x, point.y)
newcommand = Path.Command("G1", {'X':point.x, 'Y':point.y, 'Z':point.z + offset})
newcommand = Path.Command("G1", {'X': point.x, 'Y': point.y, 'Z': point.z + offset})
newcommandlist.append(newcommand)
currLocation.update(newcommand.Parameters)
currLocation['Z'] = zval
Expand All @@ -173,6 +178,7 @@ def execute(self, obj):
path = Path.Path(newcommandlist)
obj.Path = path


class TaskPanel:

def __init__(self, obj):
Expand All @@ -182,10 +188,11 @@ def __init__(self, obj):
self.interpshape = FreeCAD.ActiveDocument.addObject("Part::Feature", "InterpolationSurface")
self.interpshape.Shape = obj.interpSurface
self.interpshape.ViewObject.Transparency = 60
self.interpshape.ViewObject.ShapeColor = (1.00000,1.00000,0.01961)
self.interpshape.ViewObject.ShapeColor = (1.00000, 1.00000, 0.01961)
self.interpshape.ViewObject.Selectable = False
stock = PathUtils.findParentJob(obj).Stock
self.interpshape.Placement.Base.z = stock.Shape.BoundBox.ZMax

def reject(self):
FreeCAD.ActiveDocument.abortTransaction()
FreeCADGui.Control.closeDialog()
Expand All @@ -203,7 +210,6 @@ def accept(self):
def getFields(self):
self.obj.Proxy.execute(self.obj)


def updateUI(self):

if PathLog.getLevel(LOG_MODULE) == PathLog.Level.DEBUG:
Expand Down Expand Up @@ -231,6 +237,7 @@ def setFields(self):

def open(self):
pass

def setupUi(self):
self.setFields()
# now that the form is filled, setup the signal handlers
Expand Down Expand Up @@ -285,6 +292,7 @@ def onDelete(self, arg1=None, arg2=None):
arg1.Object.Base = None
return True


class CommandPathDressup:

def GetResources(self):
Expand Down
14 changes: 7 additions & 7 deletions src/Mod/Path/PathScripts/PathProbe.py
Expand Up @@ -30,7 +30,6 @@
import PathScripts.PathOp as PathOp
import PathScripts.PathUtils as PathUtils

#from PathScripts.PathUtils import waiting_effects
from PySide import QtCore

__title__ = "Path Probing Operation"
Expand Down Expand Up @@ -81,25 +80,26 @@ def opExecute(self, obj):

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", {"Z": obj.ClearanceHeight.Value}))

for y in self.nextpoint(bb.YMin, bb.YMax, obj.PointCountY):
for x in self.nextpoint(bb.XMin, bb.XMax, obj.PointCountX):
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}))
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}))

self.commandlist.append(Path.Command("(PROBECLOSE)"))


def opSetDefaultValues(self, obj, job):
'''opSetDefaultValues(obj, job) ... set default value for RetractHeight'''


def SetupProperties():
setup = ['Xoffset', 'Yoffset', 'PointCountX', 'PointCountY', 'OutputFileName']
return setup

def Create(name, obj = None):

def Create(name, obj=None):
'''Create(name) ... Creates and returns a Probing operation.'''
if obj is None:
obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", name)
Expand Down
17 changes: 8 additions & 9 deletions src/Mod/Path/PathScripts/PathProbeGui.py
Expand Up @@ -35,10 +35,12 @@
__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.'''

Expand Down Expand Up @@ -73,7 +75,6 @@ def getSignalsForUpdate(self, obj):
signals.append(self.form.OutputFileName.editingFinished)
signals.append(self.form.Xoffset.valueChanged)
signals.append(self.form.Yoffset.valueChanged)
#signals.append(self.form.SetOutputFileName.clicked)
self.form.SetOutputFileName.clicked.connect(self.SetOutputFileName)
return signals

Expand All @@ -83,13 +84,11 @@ def SetOutputFileName(self):
self.obj.OutputFileName = str(filename[0])
self.setFields(self.obj)

Command = PathOpGui.SetupOperation('Probe',
PathProbe.Create,
TaskPanelOpPage,
'Path-Probe',
QtCore.QT_TRANSLATE_NOOP("Probe", "Probe"),
QtCore.QT_TRANSLATE_NOOP("Probe", "Create a Probing Grid from a job stock"),
PathProbe.SetupProperties)

FreeCAD.Console.PrintLog("Loading PathProbeGui... done\n")
Command = PathOpGui.SetupOperation('Probe', PathProbe.Create, TaskPanelOpPage,
'Path-Probe',
QtCore.QT_TRANSLATE_NOOP("Probe", "Probe"),
QtCore.QT_TRANSLATE_NOOP("Probe", "Create a Probing Grid from a job stock"),
PathProbe.SetupProperties)

FreeCAD.Console.PrintLog("Loading PathProbeGui... done\n")
1 change: 1 addition & 0 deletions src/Mod/Path/PathScripts/PathSetupSheetOpPrototype.py
Expand Up @@ -149,6 +149,7 @@ class OpPrototype(object):
'App::PropertyBool': PropertyBool,
'App::PropertyDistance': PropertyDistance,
'App::PropertyEnumeration': PropertyEnumeration,
'App::PropertyFile': PropertyString,
'App::PropertyFloat': PropertyFloat,
'App::PropertyFloatConstraint': Property,
'App::PropertyFloatList': Property,
Expand Down

0 comments on commit 4e91020

Please sign in to comment.