diff --git a/src/Mod/Path/Gui/Resources/preferences/PathJob.ui b/src/Mod/Path/Gui/Resources/preferences/PathJob.ui index 5a810d249e48..2f28d723a47d 100644 --- a/src/Mod/Path/Gui/Resources/preferences/PathJob.ui +++ b/src/Mod/Path/Gui/Resources/preferences/PathJob.ui @@ -7,19 +7,13 @@ 0 0 503 - 526 + 557 Job Preferences - - 6 - - - 9 - @@ -204,6 +198,35 @@ + + + + Geometry + + + + + + + + + Default Geometry Tolerance + + + + + + + Default value for new Jobs, used for computing Paths. Smaller increases accuracy, but slows down computation + + + + + + + + + diff --git a/src/Mod/Path/PathScripts/PathJob.py b/src/Mod/Path/PathScripts/PathJob.py index 71f2400e1e63..fcc4682c5e9d 100644 --- a/src/Mod/Path/PathScripts/PathJob.py +++ b/src/Mod/Path/PathScripts/PathJob.py @@ -72,6 +72,10 @@ def __init__(self, obj): obj.addProperty("App::PropertyEnumeration", "MachineUnits", "Output", QtCore.QT_TRANSLATE_NOOP("App::Property","Units that the machine works in, ie Metric or Inch")) obj.MachineUnits = ['Metric', 'Inch'] + obj.addProperty("App::PropertyDistance", "GeometryTolerance", "Geometry", + QtCore.QT_TRANSLATE_NOOP("App::Property", "For computing Paths; smaller increases accuracy, but slows down computation")) + obj.GeometryTolerance = PathPreferences.defaultGeometryTolerance() + obj.addProperty("App::PropertyDistance", "X_Max", "Limits", QtCore.QT_TRANSLATE_NOOP("App::Property","The Maximum distance in X the machine can travel")) obj.addProperty("App::PropertyDistance", "Y_Max", "Limits", QtCore.QT_TRANSLATE_NOOP("App::Property","The Maximum distance in X the machine can travel")) obj.addProperty("App::PropertyDistance", "Z_Max", "Limits", QtCore.QT_TRANSLATE_NOOP("App::Property","The Maximum distance in X the machine can travel")) diff --git a/src/Mod/Path/PathScripts/PathPreferences.py b/src/Mod/Path/PathScripts/PathPreferences.py index e1fe309120c9..a3e52ca377c1 100644 --- a/src/Mod/Path/PathScripts/PathPreferences.py +++ b/src/Mod/Path/PathScripts/PathPreferences.py @@ -30,6 +30,8 @@ class PathPreferences: PostProcessorDefault = "PostProcessorDefault" PostProcessorDefaultArgs = "PostProcessorDefaultArgs" PostProcessorBlacklist = "PostProcessorBlacklist" + # Linear tolerance to use when generating Paths, eg when tesselating geometry + GeometryTolerance = "GeometryTolerance" @classmethod def preferences(cls): @@ -70,6 +72,10 @@ def defaultPostProcessorArgs(cls): pref = cls.preferences() return pref.GetString(cls.PostProcessorDefaultArgs, "") + @classmethod + def defaultGeometryTolerance(cls): + return cls.preferences().GetFloat(cls.GeometryTolerance, 0.01) + @classmethod def postProcessorBlacklist(cls): pref = cls.preferences() @@ -79,11 +85,12 @@ def postProcessorBlacklist(cls): return eval(blacklist) @classmethod - def savePostProcessorDefaults(cls, processor, args, blacklist): + def savePostProcessorDefaults(cls, processor, args, blacklist, geometryTolerance): pref = cls.preferences() pref.SetString(cls.PostProcessorDefault, processor) pref.SetString(cls.PostProcessorDefaultArgs, args) pref.SetString(cls.PostProcessorBlacklist, "%s" % (blacklist)) + pref.SetFloat(cls.GeometryTolerance, geometryTolerance) DefaultOutputFile = "DefaultOutputFile" diff --git a/src/Mod/Path/PathScripts/PathPreferencesPathJob.py b/src/Mod/Path/PathScripts/PathPreferencesPathJob.py index cb374133d747..c40cf4dc67d4 100644 --- a/src/Mod/Path/PathScripts/PathPreferencesPathJob.py +++ b/src/Mod/Path/PathScripts/PathPreferencesPathJob.py @@ -24,6 +24,7 @@ import FreeCAD import FreeCADGui +from FreeCAD import Units from PySide import QtCore, QtGui from PathScripts.PathPreferences import PathPreferences from PathScripts.PathPostProcessor import PostProcessor @@ -45,7 +46,8 @@ def saveSettings(self): item = self.form.postProcessorList.item(i) if item.checkState() == QtCore.Qt.CheckState.Unchecked: blacklist.append(item.text()) - PathPreferences.savePostProcessorDefaults(processor, args, blacklist) + geometryTolerance = Units.Quantity(self.form.geometryTolerance.text()) + PathPreferences.savePostProcessorDefaults(processor, args, blacklist, geometryTolerance) path = str(self.form.leOutputFile.text()) policy = str(self.form.cboOutputPolicy.currentText()) @@ -92,6 +94,10 @@ def loadSettings(self): self.verifyAndUpdateDefaultPostProcessorWith(PathPreferences.defaultPostProcessor()) self.form.defaultPostProcessorArgs.setText(PathPreferences.defaultPostProcessorArgs()) + + geomTol = Units.Quantity(PathPreferences.defaultGeometryTolerance(), Units.Length) + self.form.geometryTolerance.setText(geomTol.UserString) + self.form.leOutputFile.setText(PathPreferences.defaultOutputFile()) self.selectComboEntry(self.form.cboOutputPolicy, PathPreferences.defaultOutputPolicy()) diff --git a/src/Mod/Path/PathScripts/PathSurface.py b/src/Mod/Path/PathScripts/PathSurface.py index d66816a261cd..128f33f2038d 100644 --- a/src/Mod/Path/PathScripts/PathSurface.py +++ b/src/Mod/Path/PathScripts/PathSurface.py @@ -306,8 +306,15 @@ def execute(self, obj): mesh = mesh.Mesh bb = mesh.BoundBox else: - bb = mesh.Shape.BoundBox + # try/except is for Path Jobs created before GeometryTolerance + try: + deflection = parentJob.GeometryTolerance + except AttributeError: + from PathScripts.PathPreferences import PathPreferences + deflection = PathPreferences.defaultGeometryTolerance() + mesh = MeshPart.meshFromShape(mesh.Shape, MaxLength=2) + bb = mesh.Shape.BoundBox s = ocl.STLSurf() for f in mesh.Facets: