Skip to content

Commit

Permalink
Path: Add Property to Job for geometry tolerance
Browse files Browse the repository at this point in the history
  • Loading branch information
ianrrees committed Apr 2, 2017
1 parent 78d8272 commit c913481
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 10 deletions.
37 changes: 30 additions & 7 deletions src/Mod/Path/Gui/Resources/preferences/PathJob.ui
Expand Up @@ -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">
Expand Down Expand Up @@ -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">
Expand Down
4 changes: 4 additions & 0 deletions src/Mod/Path/PathScripts/PathJob.py
Expand Up @@ -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"))
Expand Down
9 changes: 8 additions & 1 deletion src/Mod/Path/PathScripts/PathPreferences.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand All @@ -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"
Expand Down
8 changes: 7 additions & 1 deletion src/Mod/Path/PathScripts/PathPreferencesPathJob.py
Expand Up @@ -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
Expand All @@ -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())
Expand Down Expand Up @@ -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())

Expand Down
9 changes: 8 additions & 1 deletion src/Mod/Path/PathScripts/PathSurface.py
Expand Up @@ -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:
Expand Down

0 comments on commit c913481

Please sign in to comment.