Rebase chamfer op on engrave-base and enable path generation.
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user