From ce7f2881102c9fe7ea50cfd2028c2a0888f1b864 Mon Sep 17 00:00:00 2001 From: Markus Lampert Date: Tue, 12 Jun 2018 12:48:58 -0700 Subject: [PATCH] Rebase chamfer op on engrave-base and enable path generation. --- src/Mod/Path/PathScripts/PathChamfer.py | 25 +++++++++++++++------ src/Mod/Path/PathScripts/PathEngrave.py | 10 +-------- src/Mod/Path/PathScripts/PathEngraveBase.py | 15 ++++++++++++- src/Mod/Path/PathScripts/PathOp.py | 2 ++ 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathChamfer.py b/src/Mod/Path/PathScripts/PathChamfer.py index e764667a5c..f00d62d59a 100644 --- a/src/Mod/Path/PathScripts/PathChamfer.py +++ b/src/Mod/Path/PathScripts/PathChamfer.py @@ -25,14 +25,14 @@ import FreeCAD import Part import Path -import PathScripts.PathEngrave as PathEngrave +import PathScripts.PathEngraveBase as PathEngraveBase import PathScripts.PathLog as PathLog import PathScripts.PathOp as PathOp import math from PySide import QtCore -if True: +if False: PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule()) PathLog.trackModule(PathLog.thisModule()) else: @@ -42,7 +42,7 @@ else: def translate(context, text, disambig=None): return QtCore.QCoreApplication.translate(context, text, disambig) -class ObjectChamfer(PathOp.ObjectOp): +class ObjectChamfer(PathEngraveBase.ObjectOp): '''Proxy class for Chamfer operation.''' def opFeatures(self, obj): @@ -52,18 +52,28 @@ class ObjectChamfer(PathOp.ObjectOp): obj.addProperty("App::PropertyDistance", "Width", "Chamfer", QtCore.QT_TRANSLATE_NOOP("PathChamfer", "The desired width of the chamfer")) obj.addProperty("App::PropertyDistance", "ExtraDepth", "Chamfer", QtCore.QT_TRANSLATE_NOOP("PathChamfer", "The additional depth of the tool path")) - def opExecute(self, obj): - angle = self.tool.CuttingEdgeAngle + def opUpdateDepths(self, obj, ignoreErrors=False): + angle = obj.ToolController.Tool.CuttingEdgeAngle if 0 == angle: angle = 180 tan = math.tan(math.radians(angle/2)) toolDepth = 0 if 0 == tan else obj.Width.Value / tan extraDepth = obj.ExtraDepth.Value depth = toolDepth + extraDepth + obj.OpFinalDepth = depth + if obj.OpStartDepth < obj.OpFinalDepth: + obj.OpStartDepth = obj.OpFinalDepth + 1 + + def opExecute(self, obj): + angle = self.tool.CuttingEdgeAngle + if 0 == angle: + angle = 180 + tan = math.tan(math.radians(angle/2)) toolOffset = self.tool.FlatRadius extraOffset = self.tool.Diameter/2 - obj.Width.Value if 180 == angle else obj.ExtraDepth.Value / tan offset = toolOffset + extraOffset - PathLog.debug("%s depth(%.2f, %.2f) offset(%.2f, %.2f)" % (obj.Label, toolDepth, extraDepth, toolOffset, extraOffset)) + + zValues = self.getZValues(obj) wires = [] for base, subs in obj.Base: @@ -80,9 +90,10 @@ class ObjectChamfer(PathOp.ObjectOp): for edgelist in Part.sortEdges(edges): basewires.append(Part.Wire(edgelist)) - for w in PathEngrave.adjustWirePlacement(obj, base, basewires): + for w in self.adjustWirePlacement(obj, base, basewires): wires.append(self.offsetWire(w, base, offset)) self.wires = wires + self.buildpathocc(obj, wires, zValues) def offsetWire(self, wire, base, offset): def removeInsideEdges(edges): diff --git a/src/Mod/Path/PathScripts/PathEngrave.py b/src/Mod/Path/PathScripts/PathEngrave.py index 24e94b5ed5..0ac4eeb72d 100644 --- a/src/Mod/Path/PathScripts/PathEngrave.py +++ b/src/Mod/Path/PathScripts/PathEngrave.py @@ -79,15 +79,7 @@ class ObjectEngrave(PathEngraveBase.ObjectOp): if job and job.Base: obj.BaseObject = job.Base - zValues = [] - if obj.StepDown.Value != 0: - z = obj.StartDepth.Value - obj.StepDown.Value - - while z > obj.FinalDepth.Value: - zValues.append(z) - z -= obj.StepDown.Value - zValues.append(obj.FinalDepth.Value) - self.zValues = zValues + zValues = self.getZValues(obj) try: if self.baseobject.isDerivedFrom('Sketcher::SketchObject') or \ diff --git a/src/Mod/Path/PathScripts/PathEngraveBase.py b/src/Mod/Path/PathScripts/PathEngraveBase.py index afe0ad29d1..8b98d40547 100644 --- a/src/Mod/Path/PathScripts/PathEngraveBase.py +++ b/src/Mod/Path/PathScripts/PathEngraveBase.py @@ -48,6 +48,18 @@ def translate(context, text, disambig=None): class ObjectOp(PathOp.ObjectOp): '''Proxy base class for engrave operations.''' + def getZValues(self, obj): + zValues = [] + if obj.StepDown.Value != 0: + z = obj.StartDepth.Value - obj.StepDown.Value + + while z > obj.FinalDepth.Value: + zValues.append(z) + z -= obj.StepDown.Value + zValues.append(obj.FinalDepth.Value) + self.zValues = zValues + return zValues + def buildpathocc(self, obj, wires, zValues): '''buildpathocc(obj, wires, zValues) ... internal helper function to generate engraving commands.''' PathLog.track(obj.Label, len(wires), zValues) @@ -56,7 +68,8 @@ class ObjectOp(PathOp.ObjectOp): offset = wire # reorder the wire - offset = DraftGeomUtils.rebaseWire(offset, obj.StartVertex) + if hasattr(obj, 'StartVertex'): + offset = DraftGeomUtils.rebaseWire(offset, obj.StartVertex) last = None for z in zValues: diff --git a/src/Mod/Path/PathScripts/PathOp.py b/src/Mod/Path/PathScripts/PathOp.py index f737ab7a33..5684dc5674 100644 --- a/src/Mod/Path/PathScripts/PathOp.py +++ b/src/Mod/Path/PathScripts/PathOp.py @@ -210,6 +210,7 @@ class ObjectOp(object): def opUpdateDepths(self, obj): '''opUpdateDepths(obj) ... overwrite to implement special depths calculation. Can safely be overwritten by subclass.''' + pass def opExecute(self, obj): '''opExecute(obj) ... called whenever the receiver needs to be recalculated. @@ -354,6 +355,7 @@ class ObjectOp(object): # update start depth if requested and required if not PathGeom.isRoughly(obj.OpStartDepth.Value, zmax): obj.OpStartDepth = zmax + self.opUpdateDepths(obj) @waiting_effects def execute(self, obj):