Path: Add Property to Job for geometry tolerance

This commit is contained in:
Ian Rees
2017-04-02 18:52:00 +12:00
parent 78d8272d77
commit c913481ec1
5 changed files with 57 additions and 10 deletions

View File

@@ -7,19 +7,13 @@
<x>0</x>
<y>0</y>
<width>503</width>
<height>526</height>
<height>557</height>
</rect>
</property>
<property name="windowTitle">
<string>Job Preferences</string>
</property>
<layout class="QVBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>9</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="sizePolicy">
@@ -204,6 +198,35 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Geometry</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QWidget" name="widget_5" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>Default Geometry Tolerance</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::InputField" name="geometryTolerance">
<property name="toolTip">
<string>Default value for new Jobs, used for computing Paths. Smaller increases accuracy, but slows down computation</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">

View File

@@ -72,6 +72,10 @@ class ObjectPathJob:
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"))

View File

@@ -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 @@ class PathPreferences:
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 @@ class PathPreferences:
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"

View File

@@ -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 @@ class JobPreferencesPage:
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 @@ class JobPreferencesPage:
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())

View File

@@ -306,8 +306,15 @@ class ObjectSurface:
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: