Path: Adaptive - fix for edge selections

This commit is contained in:
kreso-t
2018-09-05 22:30:51 +02:00
committed by wmayer
parent f7ff42fe2b
commit 834a374f7b
3 changed files with 120 additions and 96 deletions

View File

@@ -16,75 +16,6 @@ def discretize(edge, flipDirection=False):
if flipDirection: pts.reverse()
return pts
def IsEqualInXYPlane(e1, e2):
return math.sqrt((e2.x-e1.x)*(e2.x-e1.x) +
(e2.y - e1.y) * (e2.y - e1.y))<0.01
def connectEdges(edges):
''' Makes the list of connected discretized paths '''
# find edge
lastPoint=None
remaining = []
pathArray = []
combined = []
for edge in edges:
#print edge
p1 = edge.valueAt(edge.FirstParameter)
p2 = edge.valueAt(edge.LastParameter)
m1 = edge.valueAt((edge.LastParameter+edge.LastParameter)/2)
duplicate = False
for ex in remaining:
exp1 = ex.valueAt(ex.FirstParameter)
exp2 = ex.valueAt(ex.LastParameter)
exm1 = ex.valueAt((ex.FirstParameter + ex.LastParameter)/2)
if IsEqualInXYPlane(exp1, p1) and IsEqualInXYPlane(exp2, p2) and IsEqualInXYPlane(exm1, m1):
duplicate = True
#print "duplicate"
if IsEqualInXYPlane(exp1, p2) and IsEqualInXYPlane(exp2, p1) and IsEqualInXYPlane(exm1, m1):
duplicate = True
#print "duplicate"
if not duplicate:
remaining.append(edge)
newPath=True
while len(remaining)>0:
if newPath:
edge=remaining[0]
p1 = edge.valueAt(edge.FirstParameter)
p2 = edge.valueAt(edge.LastParameter)
if len(combined)>0: pathArray.append(combined)
combined = []
combined.append(discretize(edge))
remaining.remove(edge)
lastPoint=p2
newPath=False
anyMatch=False
for e in remaining:
p1 = e.valueAt(e.FirstParameter)
p2 = e.valueAt(e.LastParameter)
if IsEqualInXYPlane(lastPoint,p1):
combined.append(discretize(e))
remaining.remove(e)
lastPoint=p2
anyMatch=True
break
elif IsEqualInXYPlane(lastPoint,p2):
combined.append(discretize(e,True))
remaining.remove(e)
lastPoint=p1
anyMatch=True
break
if not anyMatch:
newPath=True
#make sure last path is appended
if len(combined)>0: pathArray.append(combined)
combined = []
return pathArray
def convertTo2d(pathArray):
output = []
for path in pathArray:
@@ -267,14 +198,15 @@ def Execute(op,obj):
obj.StopProcessing = False
if obj.Tolerance<0.001: obj.Tolerance=0.001
edges=[]
pathArray=[]
for base, subs in obj.Base:
for sub in subs:
shape=base.Shape.getElement(sub)
for edge in shape.Edges:
edges.append(edge)
pathArray.append([discretize(edge)])
pathArray=connectEdges(edges)
#pathArray=connectEdges(edges)
path2d = convertTo2d(pathArray)
stockPaths = []
if op.stock.StockType == "CreateCylinder":
@@ -289,6 +221,8 @@ def Execute(op,obj):
v.append(FreeCAD.Vector(stockBB.XMin,stockBB.YMin,0))
stockPaths.append([v])
stockPath2d = convertTo2d(stockPaths)
opType = area.AdaptiveOperationType.ClearingInside
if obj.OperationType == "Clearing":
if obj.Side == "Outside":
@@ -301,8 +235,6 @@ def Execute(op,obj):
else:
opType = area.AdaptiveOperationType.ProfilingInside
path2d = convertTo2d(pathArray)
stockPath2d = convertTo2d(stockPaths)
# put here all properties that influence calculation of adaptive base paths,
inputStateObject = {
@@ -426,7 +358,7 @@ class PathAdaptive(PathOp.ObjectOp):
obj.StepOver = 20
obj.LiftDistance=0
# obj.ProcessHoles = True
obj.ForceInsideOut = True
obj.ForceInsideOut = False
obj.Stopped = False
obj.StopProcessing = False
obj.HelixAngle = 5