Skip to content
Permalink
Browse files

Fixed all ops to use Op...Depth in order to not mess with the express…

…ions.
  • Loading branch information
mlampert committed Oct 17, 2017
1 parent 1a29468 commit eaa7b6f591c38d63db9bee47bcc810bb0372debf
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>422</width>
<height>432</height>
<height>434</height>
</rect>
</property>
<property name="windowTitle">
@@ -110,7 +110,7 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="defaultsGroup">
<widget class="QGroupBox" name="settingsGroup">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Enable to include the default values in the template.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
@@ -121,26 +121,36 @@
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QCheckBox" name="defaultToolRapid">
<item row="1" column="0">
<widget class="QCheckBox" name="settingOperationHeights">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Enable to include the default rapid tool speeds in the template.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Enable to include the default heights for operations in the template.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Tool Rapid Speeds</string>
<string>Operation Heights</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="defaultOperationHeights">
<item row="1" column="1">
<widget class="QCheckBox" name="settingOperationDepths">
<property name="text">
<string>Operation Depths</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="settingToolRapid">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Enable to include the default heights for operations in the template.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Enable to include the default rapid tool speeds in the template.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Operation Heights</string>
<string>Tool Rapid Speeds</string>
</property>
<property name="checked">
<bool>true</bool>
@@ -189,9 +199,10 @@
<tabstop>stockGroup</tabstop>
<tabstop>stockExtent</tabstop>
<tabstop>stockPlacement</tabstop>
<tabstop>defaultsGroup</tabstop>
<tabstop>defaultToolRapid</tabstop>
<tabstop>defaultOperationHeights</tabstop>
<tabstop>settingsGroup</tabstop>
<tabstop>settingOperationHeights</tabstop>
<tabstop>settingOperationDepths</tabstop>
<tabstop>settingToolRapid</tabstop>
<tabstop>toolsGroup</tabstop>
<tabstop>toolsList</tabstop>
<tabstop>buttonBox</tabstop>
@@ -140,29 +140,11 @@ def opSetDefaultValues(self, obj):

if shape:
bb = shape.BoundBox
obj.StartDepth = bb.ZMax
obj.FinalDepth = bb.ZMin
if PathOp.FeatureStepDown & self.opFeatures(obj):
obj.StepDown = 1.0
obj.OpStartDepth = bb.ZMax
obj.OpFinalDepth = bb.ZMin
else:
obj.StartDepth = 1.0
obj.FinalDepth = 0.0
if PathOp.FeatureStepDown & self.opFeatures(obj):
obj.StepDown = 1.0

if PathOp.FeatureHeights & self.opFeatures(obj):
try:
shape = self.areaOpShapeForDepths(obj)
except:
shape = None

if shape:
bb = shape.BoundBox
obj.ClearanceHeight = bb.ZMax + 5.0
obj.SafeHeight = bb.ZMax + 3.0
else:
obj.ClearanceHeight = 10.0
obj.SafeHeight = 8.0
obj.OpStartDepth = 1.0
obj.OpFinalDepth = 0.0

self.areaOpSetDefaultValues(obj)

@@ -184,15 +184,13 @@ def opSetDefaultValues(self, obj):
job = PathUtils.findParentJob(obj)
if job and job.Base:
bb = job.Base.Shape.BoundBox
obj.StartDepth = bb.ZMax
obj.FinalDepth = bb.ZMin
obj.ClearanceHeight = bb.ZMax + 5.0
obj.SafeHeight = bb.ZMax + 3.0
obj.OpStartDepth = bb.ZMax
obj.OpFinalDepth = bb.ZMin
else:
obj.FinalDepth = -0.1
if obj.StartDepth.Value != obj.FinalDepth.Value:
obj.OpFinalDepth = -0.1
if obj.OpStartDepth.Value != obj.OpFinalDepth.Value:
# maintain behaviour of a single run
obj.StepDown = obj.StartDepth.Value - obj.FinalDepth.Value
obj.OpStepDown = obj.OpStartDepth.Value - obj.OpFinalDepth.Value

def Create(name):
'''Create(name) ... Creates and returns a Engrave operation.'''
@@ -158,6 +158,15 @@ def __init__(self, job, parent=None):
spHint = "%s" % job.Stock.Placement
self.dialog.stockPlacementHint.setText(spHint)

rapidChanged = not job.SetupSheet.Proxy.hasDefaultToolRapids()
depthsChanged = not job.SetupSheet.Proxy.hasDefaultOperationDepths()
heightsChanged = not job.SetupSheet.Proxy.hasDefaultOperationHeights()
settingsChanged = rapidChanged or depthsChanged or heightsChanged
self.dialog.settingsGroup.setChecked(settingsChanged)
self.dialog.settingToolRapid.setChecked(rapidChanged)
self.dialog.settingOperationDepths.setChecked(depthsChanged)
self.dialog.settingOperationHeights.setChecked(heightsChanged)

for tc in sorted(job.ToolController, key=lambda o: o.Label):
item = QtGui.QListWidgetItem(tc.Label)
item.setData(self.DataObject, tc)
@@ -189,12 +198,14 @@ def includeStockExtent(self):
def includeStockPlacement(self):
return self.dialog.stockPlacement.isChecked()

def includeDefaults(self):
return self.dialog.defaultsGroup.isChecked()
def includeDefaultToolRapid(self):
return self.dialog.defaultToolRapid.isChecked()
def includeDefaultOperationHeights(self):
return self.dialog.defaultOperationHeights.isChecked()
def includeSettings(self):
return self.dialog.settingsGroup.isChecked()
def includeSettingToolRapid(self):
return self.dialog.settingToolRapid.isChecked()
def includeSettingOperationHeights(self):
return self.dialog.settingOperationHeights.isChecked()
def includeSettingOperationDepths(self):
return self.dialog.settingOperationDepths.isChecked()

def exec_(self):
return self.dialog.exec_()
@@ -255,9 +266,9 @@ def Execute(cls, job, path, dialog=None):
# setup sheet
setupSheetAttrs = None
if dialog:
setupSheetAttrs = job.Proxy.setupSheet.templateAttributes(dialog.includeDefaultToolRapid(), dialog.includeDefaultOperationHeights())
setupSheetAttrs = job.Proxy.setupSheet.templateAttributes(dialog.includeSettingToolRapid(), dialog.includeSettingOperationHeights(), dialog.includeSettingOperationDepths())
else:
setupSheetAttrs = job.Proxy.setupSheet.templateAttributes(True, True)
setupSheetAttrs = job.Proxy.setupSheet.templateAttributes(True, True, True)
if setupSheetAttrs:
attrs[PathJob.JobTemplate.SetupSheet] = setupSheetAttrs

@@ -71,10 +71,8 @@ def areaOpOnChanged(self, obj, prop):
base, sub = obj.Base[0]
shape = base.Shape.getElement(sub[0])
d = PathUtils.guessDepths(shape, None)
obj.ClearanceHeight = d.clearance_height
obj.SafeHeight = d.safe_height + 1
obj.StartDepth = d.safe_height
obj.FinalDepth = d.start_depth
obj.OpStartDepth = d.safe_height
obj.OpFinalDepth = d.start_depth

def areaOpShapes(self, obj):
'''areaOpShapes(obj) ... return top face'''
@@ -118,10 +116,8 @@ def areaOpSetDefaultValues(self, obj):
job = PathUtils.findParentJob(obj)
if job and job.Base:
d = PathUtils.guessDepths(job.Base.Shape, None)
obj.ClearanceHeight = d.clearance_height
obj.SafeHeight = d.safe_height + 1
obj.StartDepth = d.safe_height
obj.FinalDepth = d.start_depth
obj.OpStartDepth = d.safe_height
obj.OpFinalDepth = d.start_depth

def Create(name):
'''Create(name) ... Creates and returns a Mill Facing operation.'''
@@ -246,13 +246,13 @@ def setDefaultValues(self, obj):
obj.OpToolDiameter = 1.0

if FeatureDepths & features:
obj.setExpression('StartDepth', 'OpStartDepth')
obj.setExpression('FinalDepth', 'OpFinalDepth')
obj.setExpression('StartDepth', job.SetupSheet.StartDepthExpression)
obj.setExpression('FinalDepth', job.SetupSheet.FinalDepthExpression)
obj.OpStartDepth = 1.0
obj.OpFinalDepth = 0.0

if FeatureStepDown & features:
obj.setExpression('StepDown', 'OpToolDiameter')
obj.setExpression('StepDown', job.SetupSheet.StepDownExpression)

if FeatureHeights & features:
if job.SetupSheet.SafeHeightExpression:
@@ -264,6 +264,7 @@ def setDefaultValues(self, obj):
obj.UseStartPoint = False

self.opSetDefaultValues(obj)
obj.recompute()

def _setBaseAndStock(self, obj, ignoreErrors=False):
job = PathUtils.findParentJob(obj)
@@ -142,8 +142,8 @@ def areaOpSetDefaultValues(self, obj):
job = PathUtils.findParentJob(obj)
if job and job.Stock:
bb = job.Stock.Shape.BoundBox
obj.FinalDepth = bb.ZMin
obj.StartDepth = bb.ZMax
obj.OpFinalDepth = bb.ZMin
obj.OpStartDepth = bb.ZMax

def Create(name):
'''Create(name) ... Creates and returns a Pocket operation.'''
@@ -27,6 +27,9 @@
import PathScripts.PathLog as PathLog
import PySide

from PathScripts.PathGeom import PathGeom


__title__ = "Setup Sheet for a Job."
__author__ = "sliptonic (Brad Collette)"
__url__ = "http://www.freecadweb.org"
@@ -44,10 +47,16 @@ def translate(context, text, disambig=None):
class Template:
HorizRapid = 'HorizRapid'
VertRapid = 'VertRapid'
SafeHeightOffset = 'SafeHeight'
SafeHeightOffset = 'SafeHeightOffset'
SafeHeightExpression = 'SafeHeightExpression'
ClearanceHeightOffset = 'ClearanceHeight'
ClearanceHeightOffset = 'ClearanceHeightOffset'
ClearanceHeightExpression = 'ClearanceHeightExpression'
StartDepthExpression = 'StartDepthExpression'
FinalDepthExpression = 'FinalDepthExpression'
StepDownExpression = 'StepDownExpression'

All = [HorizRapid, VertRapid, SafeHeightOffset, SafeHeightExpression, ClearanceHeightOffset, ClearanceHeightExpression, StartDepthExpression, FinalDepthExpression, StepDownExpression]


def _traverseTemplateAttributes(attrs, codec):
coded = {}
@@ -73,6 +82,15 @@ class SetupSheet:

TemplateReference = '${SetupSheet}'

DefaultSafeHeightOffset = '3 mm'
DefaultClearanceHeightOffset = '5 mm'
DefaultSafeHeightExpression = "StartDepth+${SetupSheet}.SafeHeightOffset"
DefaultClearanceHeightExpression = "StartDepth+${SetupSheet}.ClearanceHeightOffset"

DefaultStartDepthExpression = 'OpStartDepth'
DefaultFinalDepthExpression = 'OpFinalDepth'
DefaultStepDownExpression = 'OpToolDiameter'

def __init__(self, obj):
self.obj = obj
obj.addProperty('App::PropertySpeed', 'VertRapid', 'ToolController', translate('PathSetupSheet', 'Default speed for horizontal rapid moves.'))
@@ -83,10 +101,18 @@ def __init__(self, obj):
obj.addProperty('App::PropertyLength', 'ClearanceHeightOffset', 'OperationHeights', translate('PathSetupSheet', 'The usage of this field depends on ClearanceHeightExpression - by default is value is added to StartDepth and used for ClearanceHeight of an operation.'))
obj.addProperty('App::PropertyString', 'ClearanceHeightExpression', 'OperationHeights', translate('PathSetupSheet', 'Expression set for the ClearanceHeight of new operations.'))

obj.SafeHeightOffset = '3 mm'
obj.ClearanceHeightOffset = '5 mm'
obj.SafeHeightExpression = "StartDepth+%s.SafeHeightOffset" % self.expressionReference()
obj.ClearanceHeightExpression = "StartDepth+%s.ClearanceHeightOffset" % self.expressionReference()
obj.addProperty('App::PropertyString', 'StartDepthExpression', 'OperationDepths', translate('PathSetupSheet', 'Expression used for StartDepth of new operations.'))
obj.addProperty('App::PropertyString', 'FinalDepthExpression', 'OperationDepths', translate('PathSetupSheet', 'Expression used for FinalDepth of new operations.'))
obj.addProperty('App::PropertyString', 'StepDownExpression', 'OperationDepths', translate('PathSetupSheet', 'Expression used for StepDown of new operations.'))

obj.SafeHeightOffset = self.decodeAttributeString(self.DefaultSafeHeightOffset)
obj.ClearanceHeightOffset = self.decodeAttributeString(self.DefaultClearanceHeightOffset)
obj.SafeHeightExpression = self.decodeAttributeString(self.DefaultSafeHeightExpression)
obj.ClearanceHeightExpression = self.decodeAttributeString(self.DefaultClearanceHeightExpression)

obj.StartDepthExpression = self.decodeAttributeString(self.DefaultStartDepthExpression)
obj.FinalDepthExpression = self.decodeAttributeString(self.DefaultFinalDepthExpression)
obj.StepDownExpression = self.decodeAttributeString(self.DefaultStepDownExpression)

obj.Proxy = self

@@ -100,23 +126,37 @@ def __setstate__(self, state):
break
return None

def hasDefaultToolRapids(self):
return PathGeom.isRoughly(self.obj.VertRapid.Value, 0) and PathGeom.isRoughly(self.obj.HorizRapid.Value, 0)

def hasDefaultOperationHeights(self):
if self.obj.SafeHeightOffset.UserString != FreeCAD.Units.Quantity(self.DefaultSafeHeightOffset).UserString:
return False
if self.obj.ClearanceHeightOffset.UserString != FreeCAD.Units.Quantity(self.DefaultClearanceHeightOffset).UserString:
return False
if self.obj.SafeHeightExpression != self.decodeAttributeString(self.DefaultSafeHeightExpression):
return False
if self.obj.ClearanceHeightExpression != self.decodeAttributeString(self.DefaultClearanceHeightExpression):
return False
return True

def hasDefaultOperationDepths(self):
if self.obj.StartDepthExpression != self.DefaultStartDepthExpression:
return False
if self.obj.FinalDepthExpression != self.DefaultFinalDepthExpression:
return False
if self.obj.StepDownExpression != self.DefaultStepDownExpression:
return False
return True

def setFromTemplate(self, attrs):
'''setFromTemplate(attrs) ... sets the default values from the given dictionary.'''
if attrs.get(Template.VertRapid):
self.obj.VertRapid = attrs[Template.VertRapid]
if attrs.get(Template.HorizRapid):
self.obj.HorizRapid = attrs[Template.HorizRapid]
if attrs.get(Template.SafeHeightOffset):
self.obj.SafeHeightOffset = attrs[Template.SafeHeightOffset]
if attrs.get(Template.SafeHeightExpression):
self.obj.SafeHeightExpression = attrs[Template.SafeHeightExpression]
if attrs.get(Template.ClearanceHeightOffset):
self.obj.ClearanceHeightOffset = attrs[Template.ClearanceHeightOffset]
if attrs.get(Template.ClearanceHeightExpression):
self.obj.ClearanceHeightExpression = attrs[Template.ClearanceHeightExpression]

def templateAttributes(self, includeRapids=True, includeHeights=True):
'''templateAttributes(includeRapids, includeHeights) ... answers a dictionary with the default values.'''
for name in Template.All:
if attrs.get(name) is not None:
setattr(self.obj, name, attrs[name])

def templateAttributes(self, includeRapids=True, includeHeights=True, includeDepths=True):
'''templateAttributes(includeRapids, includeHeights, includeDepths) ... answers a dictionary with the default values.'''
attrs = {}
if includeRapids:
attrs[Template.VertRapid] = self.obj.VertRapid.UserString
@@ -126,6 +166,10 @@ def templateAttributes(self, includeRapids=True, includeHeights=True):
attrs[Template.SafeHeightExpression] = self.obj.SafeHeightExpression
attrs[Template.ClearanceHeightOffset] = self.obj.ClearanceHeightOffset.UserString
attrs[Template.ClearanceHeightExpression] = self.obj.ClearanceHeightExpression
if includeDepths:
attrs[Template.StartDepthExpression] = self.obj.StartDepthExpression
attrs[Template.FinalDepthExpression] = self.obj.FinalDepthExpression
attrs[Template.StepDownExpression] = self.obj.StepDownExpression
return attrs

def expressionReference(self):
@@ -150,13 +194,20 @@ def expressionReference(self):
# https://forum.freecadweb.org/viewtopic.php?f=10&t=24845
return self.obj.Name

def encodeAttributeString(self, attr):
'''encodeAttributeString(attr) ... return the encoded string of a template attribute.'''
return unicode(attr.replace(self.expressionReference(), self.TemplateReference))
def decodeAttributeString(self, attr):
'''decodeAttributeString(attr) ... return the decoded string of a template attribute.'''
return unicode(attr.replace(self.TemplateReference, self.expressionReference()))

def encodeTemplateAttributes(self, attrs):
'''encodeTemplateAttributes(attrs) ... return a dictionary with all values encoded.'''
return _traverseTemplateAttributes(attrs, lambda value: unicode(value.replace(self.expressionReference(), self.TemplateReference)))
return _traverseTemplateAttributes(attrs, self.encodeAttributeString)

def decodeTemplateAttributes(self, attrs):
'''decodeTemplateAttributes(attrs) ... expand template attributes to reference the receiver where applicable.'''
return _traverseTemplateAttributes(attrs, lambda value: unicode(value.replace(self.TemplateReference, self.expressionReference())))
return _traverseTemplateAttributes(attrs, self.decodeAttributeString)


def Create(name='SetupSheet'):

0 comments on commit eaa7b6f

Please sign in to comment.
You can’t perform that action at this time.