Fixed direction for offsetting holes.
This commit is contained in:
@@ -65,6 +65,7 @@ class ObjectChamfer(PathEngraveBase.ObjectOp):
|
||||
return PathOp.FeatureTool | PathOp.FeatureHeights | PathOp.FeatureBaseEdges | PathOp.FeatureBaseFaces
|
||||
|
||||
def initOperation(self, obj):
|
||||
PathLog.track(obj.Label)
|
||||
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'))
|
||||
obj.addProperty('App::PropertyEnumeration', 'Join', 'Chamfer', QtCore.QT_TRANSLATE_NOOP('PathChamfer', 'How to join chamfer segments'))
|
||||
@@ -72,7 +73,9 @@ class ObjectChamfer(PathEngraveBase.ObjectOp):
|
||||
obj.setEditorMode('Join', 2) # hide for now
|
||||
|
||||
def opExecute(self, obj):
|
||||
PathLog.track(obj.Label)
|
||||
(depth, offset) = toolDepthAndOffset(obj.Width.Value, obj.ExtraDepth.Value, self.tool)
|
||||
PathLog.track(obj.Label, depth, offset)
|
||||
|
||||
self.basewires = []
|
||||
self.adjusted_basewires = []
|
||||
@@ -104,6 +107,7 @@ class ObjectChamfer(PathEngraveBase.ObjectOp):
|
||||
self.buildpathocc(obj, wires, [depth], True)
|
||||
|
||||
def opSetDefaultValues(self, obj):
|
||||
PathLog.track(obj.Label)
|
||||
obj.Width = '1 mm'
|
||||
obj.ExtraDepth = '0.1 mm'
|
||||
obj.Join = 'Round'
|
||||
|
||||
@@ -124,20 +124,23 @@ def offsetWire(wire, base, offset, forward):
|
||||
# if we get to this point the assumption is that makeOffset2D can deal with the edge
|
||||
pass
|
||||
|
||||
offsetWire = wire.makeOffset2D(offset)
|
||||
owire = wire.makeOffset2D(offset)
|
||||
|
||||
if wire.isClosed():
|
||||
if not base.isInside(offsetWire.Edges[0].Vertexes[0].Point, offset/2, True):
|
||||
if not base.isInside(owire.Edges[0].Vertexes[0].Point, offset/2, True):
|
||||
PathLog.track('closed - outside')
|
||||
return orientWire(offsetWire, forward)
|
||||
return orientWire(owire, forward)
|
||||
PathLog.track('closed - inside')
|
||||
try:
|
||||
offsetWire = wire.makeOffset2D(-offset)
|
||||
owire = wire.makeOffset2D(-offset)
|
||||
except:
|
||||
# most likely offsetting didn't work because the wire is a hole
|
||||
# and the offset is too big - making the hole vanish
|
||||
return None
|
||||
return orientWire(offsetWire, forward)
|
||||
# For negative offsets (holes) 'forward' is the other way
|
||||
if forward is None:
|
||||
return orientWire(owire, None)
|
||||
return orientWire(owire, not forward)
|
||||
|
||||
# An edge is considered to be inside of shape if the mid point is inside
|
||||
# Of the remaining edges we take the longest wire to be the engraving side
|
||||
@@ -156,7 +159,7 @@ def offsetWire(wire, base, offset, forward):
|
||||
if base.isInside(edge.Vertexes[0].Point, offset/2, True) and base.isInside(edge.Vertexes[-1].Point, offset/2, True):
|
||||
return True
|
||||
return False
|
||||
outside = [e for e in offsetWire.Edges if not isInside(e)]
|
||||
outside = [e for e in owire.Edges if not isInside(e)]
|
||||
# discard all edges that are not part of the longest wire
|
||||
longestWire = None
|
||||
for w in [Part.Wire(el) for el in Part.sortEdges(outside)]:
|
||||
@@ -184,7 +187,7 @@ def offsetWire(wire, base, offset, forward):
|
||||
# an end point (circle centered at one of the end points of the original wire).
|
||||
# should we come to an end point and determine that we've already collected the
|
||||
# next side, we're done
|
||||
for e in (offsetWire.Edges + offsetWire.Edges):
|
||||
for e in (owire.Edges + owire.Edges):
|
||||
if isCircleAt(e, start):
|
||||
if PathGeom.pointsCoincide(e.Curve.Axis, FreeCAD.Vector(0, 0, 1)):
|
||||
if not collectLeft and leftSideEdges:
|
||||
|
||||
@@ -204,9 +204,9 @@ class TestPathGeomOp(PathTestUtils.PathTestBase):
|
||||
self.assertTrue(wire.isClosed())
|
||||
y = 4 # offset works in both directions
|
||||
x = 4 * math.cos(math.pi/6)
|
||||
self.assertLines(wire.Edges, False, [Vector(0, 4, 0), Vector(-x, -2, 0), Vector(x, -2, 0), Vector(0, 4, 0)])
|
||||
self.assertLines(wire.Edges, False, [Vector(0, 4, 0), Vector(x, -2, 0), Vector(-x, -2, 0), Vector(0, 4, 0)])
|
||||
f = Part.Face(wire)
|
||||
self.assertCoincide(Vector(0, 0, 1), f.Surface.Axis)
|
||||
self.assertCoincide(Vector(0, 0, -1), f.Surface.Axis)
|
||||
|
||||
def test11(self):
|
||||
'''Check offsetting hole wire for more than it's size makes hole vanish.'''
|
||||
@@ -426,7 +426,7 @@ class TestPathGeomOp(PathTestUtils.PathTestBase):
|
||||
for e in wire.Edges:
|
||||
self.assertRoughly(length, e.Length)
|
||||
f = Part.Face(wire)
|
||||
self.assertCoincide(Vector(0, 0, +1), f.Surface.Axis)
|
||||
self.assertCoincide(Vector(0, 0, -1), f.Surface.Axis)
|
||||
|
||||
# change offset orientation
|
||||
wire = PathGeomOp.offsetWire(getWire(obj.Tool), getNegativeShape(obj), 3, False)
|
||||
@@ -435,7 +435,7 @@ class TestPathGeomOp(PathTestUtils.PathTestBase):
|
||||
for e in wire.Edges:
|
||||
self.assertRoughly(length, e.Length)
|
||||
f = Part.Face(wire)
|
||||
self.assertCoincide(Vector(0, 0, -1), f.Surface.Axis)
|
||||
self.assertCoincide(Vector(0, 0, +1), f.Surface.Axis)
|
||||
|
||||
def test28(self):
|
||||
'''Check offsetting a shape hole.'''
|
||||
@@ -452,7 +452,7 @@ class TestPathGeomOp(PathTestUtils.PathTestBase):
|
||||
self.assertRoughly(length, e.Length)
|
||||
if Part.Circle == type(e.Curve):
|
||||
self.assertRoughly(radius, e.Curve.Radius)
|
||||
self.assertCoincide(Vector(0, 0, +1), e.Curve.Axis)
|
||||
self.assertCoincide(Vector(0, 0, -1), e.Curve.Axis)
|
||||
|
||||
# change offset orientation
|
||||
wire = PathGeomOp.offsetWire(getWire(obj.Tool), getNegativeShape(obj), 3, False)
|
||||
@@ -464,7 +464,7 @@ class TestPathGeomOp(PathTestUtils.PathTestBase):
|
||||
self.assertRoughly(length, e.Length)
|
||||
if Part.Circle == type(e.Curve):
|
||||
self.assertRoughly(radius, e.Curve.Radius)
|
||||
self.assertCoincide(Vector(0, 0, -1), e.Curve.Axis)
|
||||
self.assertCoincide(Vector(0, 0, +1), e.Curve.Axis)
|
||||
|
||||
|
||||
def test30(self):
|
||||
|
||||
Reference in New Issue
Block a user