PATH: Delete misplaced and unused files
This commit is contained in:
@@ -26,15 +26,13 @@ import FreeCAD
|
||||
import FreeCADGui
|
||||
import Part
|
||||
import math
|
||||
import Draft
|
||||
import Path
|
||||
import TechDraw
|
||||
# import Path
|
||||
from DraftGeomUtils import geomType
|
||||
from DraftGeomUtils import findWires
|
||||
import DraftVecUtils
|
||||
# from DraftGeomUtils import findWires
|
||||
# import DraftVecUtils
|
||||
import PathScripts
|
||||
from PathScripts import PathJob
|
||||
import itertools
|
||||
# import itertools
|
||||
|
||||
def cleanedges(splines, precision):
|
||||
'''cleanedges([splines],precision). Convert BSpline curves, Beziers, to arcs that can be used for cnc paths.
|
||||
@@ -88,89 +86,89 @@ def curvetowire(obj, steps):
|
||||
def fmt(val): return format(val, '.4f')
|
||||
|
||||
|
||||
def getProjected(shape,direction):
|
||||
"returns projected edges from a shape and a direction"
|
||||
import Part,Drawing
|
||||
edges = []
|
||||
groups = Drawing.projectEx(shape,direction)
|
||||
for g in groups[0:5]:
|
||||
if g:
|
||||
edges.append(g)
|
||||
# if hasattr(obj,"Tessellation") and obj.Tessellation:
|
||||
# return DraftGeomUtils.cleanProjection(Part.makeCompound(edges),obj.Tessellation,obj.SegmentLength)
|
||||
# else:
|
||||
return Part.makeCompound(edges)
|
||||
# def getProjected(shape,direction):
|
||||
# "returns projected edges from a shape and a direction"
|
||||
# import Part,Drawing
|
||||
# edges = []
|
||||
# groups = Drawing.projectEx(shape,direction)
|
||||
# for g in groups[0:5]:
|
||||
# if g:
|
||||
# edges.append(g)
|
||||
# # if hasattr(obj,"Tessellation") and obj.Tessellation:
|
||||
# # return DraftGeomUtils.cleanProjection(Part.makeCompound(edges),obj.Tessellation,obj.SegmentLength)
|
||||
# # else:
|
||||
# return Part.makeCompound(edges)
|
||||
|
||||
|
||||
def silhouette(obj):
|
||||
from FreeCAD import Vector
|
||||
s = getProjected(obj.Shape, Vector(0,0,1))
|
||||
print s
|
||||
w = TechDraw.findOuterWire(s.Edges)
|
||||
return w
|
||||
# def silhouette(obj):
|
||||
# from FreeCAD import Vector
|
||||
# s = getProjected(obj.Shape, Vector(0,0,1))
|
||||
# print s
|
||||
# w = TechDraw.findOuterWire(s.Edges)
|
||||
# return w
|
||||
|
||||
def isSameEdge(e1, e2):
|
||||
"""isSameEdge(e1,e2): return True if the 2 edges are both lines or arcs/circles and have the same
|
||||
points - inspired by Yorik's function isSameLine"""
|
||||
if not (isinstance(e1.Curve, Part.LineSegment) or isinstance(e1.Curve, Part.Circle)):
|
||||
return False
|
||||
if not (isinstance(e2.Curve, Part.LineSegment) or isinstance(e2.Curve, Part.Circle)):
|
||||
return False
|
||||
if type(e1.Curve) != type(e2.Curve):
|
||||
return False
|
||||
if isinstance(e1.Curve, Part.LineSegment):
|
||||
if (DraftVecUtils.equals(e1.Vertexes[0].Point, e2.Vertexes[0].Point)) and \
|
||||
(DraftVecUtils.equals(e1.Vertexes[-1].Point, e2.Vertexes[-1].Point)):
|
||||
return True
|
||||
elif (DraftVecUtils.equals(e1.Vertexes[-1].Point, e2.Vertexes[0].Point)) and \
|
||||
(DraftVecUtils.equals(e1.Vertexes[0].Point, e2.Vertexes[-1].Point)):
|
||||
return True
|
||||
if isinstance(e1.Curve, Part.Circle):
|
||||
center = False
|
||||
radius = False
|
||||
endpts = False
|
||||
if e1.Curve.Center == e2.Curve.Center:
|
||||
center = True
|
||||
if e1.Curve.Radius == e2.Curve.Radius:
|
||||
radius = True
|
||||
if (DraftVecUtils.equals(e1.Vertexes[0].Point, e2.Vertexes[0].Point)) and \
|
||||
(DraftVecUtils.equals(e1.Vertexes[-1].Point, e2.Vertexes[-1].Point)):
|
||||
endpts = True
|
||||
elif (DraftVecUtils.equals(e1.Vertexes[-1].Point, e2.Vertexes[0].Point)) and \
|
||||
(DraftVecUtils.equals(e1.Vertexes[0].Point, e2.Vertexes[-1].Point)):
|
||||
endpts = True
|
||||
if (center and radius and endpts):
|
||||
return True
|
||||
return False
|
||||
# def isSameEdge(e1, e2):
|
||||
# """isSameEdge(e1,e2): return True if the 2 edges are both lines or arcs/circles and have the same
|
||||
# points - inspired by Yorik's function isSameLine"""
|
||||
# if not (isinstance(e1.Curve, Part.Line) or isinstance(e1.Curve, Part.Circle)):
|
||||
# return False
|
||||
# if not (isinstance(e2.Curve, Part.Line) or isinstance(e2.Curve, Part.Circle)):
|
||||
# return False
|
||||
# if type(e1.Curve) != type(e2.Curve):
|
||||
# return False
|
||||
# if isinstance(e1.Curve, Part.Line):
|
||||
# if (DraftVecUtils.equals(e1.Vertexes[0].Point, e2.Vertexes[0].Point)) and \
|
||||
# (DraftVecUtils.equals(e1.Vertexes[-1].Point, e2.Vertexes[-1].Point)):
|
||||
# return True
|
||||
# elif (DraftVecUtils.equals(e1.Vertexes[-1].Point, e2.Vertexes[0].Point)) and \
|
||||
# (DraftVecUtils.equals(e1.Vertexes[0].Point, e2.Vertexes[-1].Point)):
|
||||
# return True
|
||||
# if isinstance(e1.Curve, Part.Circle):
|
||||
# center = False
|
||||
# radius = False
|
||||
# endpts = False
|
||||
# if e1.Curve.Center == e2.Curve.Center:
|
||||
# center = True
|
||||
# if e1.Curve.Radius == e2.Curve.Radius:
|
||||
# radius = True
|
||||
# if (DraftVecUtils.equals(e1.Vertexes[0].Point, e2.Vertexes[0].Point)) and \
|
||||
# (DraftVecUtils.equals(e1.Vertexes[-1].Point, e2.Vertexes[-1].Point)):
|
||||
# endpts = True
|
||||
# elif (DraftVecUtils.equals(e1.Vertexes[-1].Point, e2.Vertexes[0].Point)) and \
|
||||
# (DraftVecUtils.equals(e1.Vertexes[0].Point, e2.Vertexes[-1].Point)):
|
||||
# endpts = True
|
||||
# if (center and radius and endpts):
|
||||
# return True
|
||||
# return False
|
||||
|
||||
|
||||
def segments(poly):
|
||||
''' A sequence of (x,y) numeric coordinates pairs '''
|
||||
return zip(poly, poly[1:] + [poly[0]])
|
||||
|
||||
def is_clockwise(obj):
|
||||
'''tests if a wire or Path is clockwise'''
|
||||
sum = 0
|
||||
if isinstance(obj, Part.Wire):
|
||||
for first, second in itertools.izip(obj.Edges, obj.Edges[1:]):
|
||||
sum = (second.Vertexes[0].X - first.Vertexes[0].X) * (second.Vertexes[0].Y + first.Vertexes[0].Y)
|
||||
sum += (obj.Edges[0].Vertexes[0].X - obj.Edges[-1].Vertexes[0].X) * (obj.Edges[0].Vertexes[0].Y + obj.Edges[-1].Vertexes[0].Y)
|
||||
elif isinstance(obj, Path.Path):
|
||||
movecommands = ['G1', 'G01', 'G2', 'G02', 'G3', 'G03']
|
||||
# def is_clockwise(obj):
|
||||
# '''tests if a wire or Path is clockwise'''
|
||||
# sum = 0
|
||||
# if isinstance(obj, Part.Wire):
|
||||
# for first, second in itertools.izip(obj.Edges, obj.Edges[1:]):
|
||||
# sum = (second.Vertexes[0].X - first.Vertexes[0].X) * (second.Vertexes[0].Y + first.Vertexes[0].Y)
|
||||
# sum += (obj.Edges[0].Vertexes[0].X - obj.Edges[-1].Vertexes[0].X) * (obj.Edges[0].Vertexes[0].Y + obj.Edges[-1].Vertexes[0].Y)
|
||||
# elif isinstance(obj, Path.Path):
|
||||
# movecommands = ['G1', 'G01', 'G2', 'G02', 'G3', 'G03']
|
||||
|
||||
lastLocation = {'Y': 0, 'X': 0, 'Z': 0.0}
|
||||
currLocation = {'Y': 0, 'X': 0, 'Z': 0.0}
|
||||
sum = 0
|
||||
# lastLocation = {'Y': 0, 'X': 0, 'Z': 0.0}
|
||||
# currLocation = {'Y': 0, 'X': 0, 'Z': 0.0}
|
||||
# sum = 0
|
||||
|
||||
for curCommand in obj.Commands:
|
||||
# for curCommand in obj.Commands:
|
||||
|
||||
if curCommand.Name in movecommands:
|
||||
lastLocation.update(currLocation)
|
||||
currLocation.update(curCommand.Parameters)
|
||||
sum += (currLocation["X"] - lastLocation["X"]) * (currLocation["Y"] + lastLocation["Y"])
|
||||
sum += (0 - lastLocation["X"]) * (0 + lastLocation["Y"])
|
||||
# if curCommand.Name in movecommands:
|
||||
# lastLocation.update(currLocation)
|
||||
# currLocation.update(curCommand.Parameters)
|
||||
# sum += (currLocation["X"] - lastLocation["X"]) * (currLocation["Y"] + lastLocation["Y"])
|
||||
# sum += (0 - lastLocation["X"]) * (0 + lastLocation["Y"])
|
||||
|
||||
return sum >= 0
|
||||
# return sum >= 0
|
||||
|
||||
def loopdetect(obj, edge1, edge2):
|
||||
'''
|
||||
@@ -192,15 +190,15 @@ def loopdetect(obj, edge1, edge2):
|
||||
return loopwire
|
||||
|
||||
|
||||
def check_clockwise(poly):
|
||||
'''
|
||||
check_clockwise(poly) a function for returning a boolean if the selected wire is clockwise or counter clockwise
|
||||
based on point order. poly = [(x1,y1),(x2,y2),(x3,y3)]
|
||||
'''
|
||||
clockwise = False
|
||||
if (sum(x0 * y1 - x1 * y0 for ((x0, y0), (x1, y1)) in segments(poly))) < 0:
|
||||
clockwise = not clockwise
|
||||
return clockwise
|
||||
# def check_clockwise(poly):
|
||||
# '''
|
||||
# check_clockwise(poly) a function for returning a boolean if the selected wire is clockwise or counter clockwise
|
||||
# based on point order. poly = [(x1,y1),(x2,y2),(x3,y3)]
|
||||
# '''
|
||||
# clockwise = False
|
||||
# if (sum(x0 * y1 - x1 * y0 for ((x0, y0), (x1, y1)) in segments(poly))) < 0:
|
||||
# clockwise = not clockwise
|
||||
# return clockwise
|
||||
|
||||
|
||||
def filterArcs(arcEdge):
|
||||
@@ -254,235 +252,235 @@ def reverseEdge(e):
|
||||
|
||||
return newedge
|
||||
|
||||
def edge_to_path(lastpt, edge, Z, hf=2.0):
|
||||
if isinstance(edge.Curve, Part.Circle):
|
||||
# FreeCAD.Console.PrintMessage("arc\n")
|
||||
arcstartpt = edge.valueAt(edge.FirstParameter)
|
||||
midpt = edge.valueAt(
|
||||
(edge.FirstParameter + edge.LastParameter) * 0.5)
|
||||
arcendpt = edge.valueAt(edge.LastParameter)
|
||||
# arcchkpt = edge.valueAt(edge.LastParameter * .99)
|
||||
# def edge_to_path(lastpt, edge, Z, hf=2.0):
|
||||
# if isinstance(edge.Curve, Part.Circle):
|
||||
# # FreeCAD.Console.PrintMessage("arc\n")
|
||||
# arcstartpt = edge.valueAt(edge.FirstParameter)
|
||||
# midpt = edge.valueAt(
|
||||
# (edge.FirstParameter + edge.LastParameter) * 0.5)
|
||||
# arcendpt = edge.valueAt(edge.LastParameter)
|
||||
# # arcchkpt = edge.valueAt(edge.LastParameter * .99)
|
||||
|
||||
if DraftVecUtils.equals(lastpt, arcstartpt):
|
||||
startpt = arcstartpt
|
||||
endpt = arcendpt
|
||||
else:
|
||||
startpt = arcendpt
|
||||
endpt = arcstartpt
|
||||
center = edge.Curve.Center
|
||||
relcenter = center.sub(lastpt)
|
||||
# FreeCAD.Console.PrintMessage("arc startpt= " + str(startpt)+ "\n")
|
||||
# FreeCAD.Console.PrintMessage("arc midpt= " + str(midpt)+ "\n")
|
||||
# FreeCAD.Console.PrintMessage("arc endpt= " + str(endpt)+ "\n")
|
||||
arc_cw = check_clockwise(
|
||||
[(startpt.x, startpt.y), (midpt.x, midpt.y), (endpt.x, endpt.y)])
|
||||
# FreeCAD.Console.PrintMessage("arc_cw="+ str(arc_cw)+"\n")
|
||||
if arc_cw:
|
||||
output = "G2"
|
||||
else:
|
||||
output = "G3"
|
||||
output += " X" + str(fmt(endpt.x)) + " Y" + \
|
||||
str(fmt(endpt.y)) + " Z" + str(fmt(Z)) + " F" + str(hf)
|
||||
output += " I" + str(fmt(relcenter.x)) + " J" + \
|
||||
str(fmt(relcenter.y)) + " K" + str(fmt(relcenter.z))
|
||||
output += "\n"
|
||||
lastpt = endpt
|
||||
# FreeCAD.Console.PrintMessage("last pt arc= " + str(lastpt)+ "\n")
|
||||
else:
|
||||
point = edge.Vertexes[-1].Point
|
||||
if DraftVecUtils.equals(point, lastpt): # edges can come flipped
|
||||
point = edge.Vertexes[0].Point
|
||||
output = "G1 X" + str(fmt(point.x)) + " Y" + str(fmt(point.y)) + \
|
||||
" Z" + str(fmt(Z)) + " F" + str(hf) + "\n"
|
||||
lastpt = point
|
||||
# FreeCAD.Console.PrintMessage("line\n")
|
||||
# FreeCAD.Console.PrintMessage("last pt line= " + str(lastpt)+ "\n")
|
||||
return lastpt, output
|
||||
# if DraftVecUtils.equals(lastpt, arcstartpt):
|
||||
# startpt = arcstartpt
|
||||
# endpt = arcendpt
|
||||
# else:
|
||||
# startpt = arcendpt
|
||||
# endpt = arcstartpt
|
||||
# center = edge.Curve.Center
|
||||
# relcenter = center.sub(lastpt)
|
||||
# # FreeCAD.Console.PrintMessage("arc startpt= " + str(startpt)+ "\n")
|
||||
# # FreeCAD.Console.PrintMessage("arc midpt= " + str(midpt)+ "\n")
|
||||
# # FreeCAD.Console.PrintMessage("arc endpt= " + str(endpt)+ "\n")
|
||||
# arc_cw = check_clockwise(
|
||||
# [(startpt.x, startpt.y), (midpt.x, midpt.y), (endpt.x, endpt.y)])
|
||||
# # FreeCAD.Console.PrintMessage("arc_cw="+ str(arc_cw)+"\n")
|
||||
# if arc_cw:
|
||||
# output = "G2"
|
||||
# else:
|
||||
# output = "G3"
|
||||
# output += " X" + str(fmt(endpt.x)) + " Y" + \
|
||||
# str(fmt(endpt.y)) + " Z" + str(fmt(Z)) + " F" + str(hf)
|
||||
# output += " I" + str(fmt(relcenter.x)) + " J" + \
|
||||
# str(fmt(relcenter.y)) + " K" + str(fmt(relcenter.z))
|
||||
# output += "\n"
|
||||
# lastpt = endpt
|
||||
# # FreeCAD.Console.PrintMessage("last pt arc= " + str(lastpt)+ "\n")
|
||||
# else:
|
||||
# point = edge.Vertexes[-1].Point
|
||||
# if DraftVecUtils.equals(point, lastpt): # edges can come flipped
|
||||
# point = edge.Vertexes[0].Point
|
||||
# output = "G1 X" + str(fmt(point.x)) + " Y" + str(fmt(point.y)) + \
|
||||
# " Z" + str(fmt(Z)) + " F" + str(hf) + "\n"
|
||||
# lastpt = point
|
||||
# # FreeCAD.Console.PrintMessage("line\n")
|
||||
# # FreeCAD.Console.PrintMessage("last pt line= " + str(lastpt)+ "\n")
|
||||
# return lastpt, output
|
||||
|
||||
|
||||
def convert(toolpath, Z=0.0, PlungeAngle=90.0, Zprevious=None, StopLength=None, vf=1.0, hf=2.0) :
|
||||
'''convert(toolpath,Z=0.0,vf=1.0,hf=2.0,PlungeAngle=90.0,Zprevious=None,StopLength=None) Converts lines and arcs to G1,G2,G3 moves. Returns a string.'''
|
||||
# def convert(toolpath, Z=0.0, PlungeAngle=90.0, Zprevious=None, StopLength=None, vf=1.0, hf=2.0) :
|
||||
# '''convert(toolpath,Z=0.0,vf=1.0,hf=2.0,PlungeAngle=90.0,Zprevious=None,StopLength=None) Converts lines and arcs to G1,G2,G3 moves. Returns a string.'''
|
||||
|
||||
if PlungeAngle != 90.0:
|
||||
if Zprevious is None:
|
||||
raise Exception("Cannot use PlungeAngle != 90.0 degrees without parameter Zprevious")
|
||||
tanA = math.tan(math.pi * PlungeAngle / 180.0)
|
||||
minA = (Zprevious - Z) / sum(edge.Length for edge in toolpath)
|
||||
if tanA < minA:
|
||||
tanA = minA
|
||||
#FreeCAD.Console.PrintMessage('Increasing ramp angle to {0} degrees, to be able to make a full round\n'.format(math.atan(tanA) * 180.0 / math.pi))
|
||||
else:
|
||||
Zprevious = Z
|
||||
# if PlungeAngle != 90.0:
|
||||
# if Zprevious is None:
|
||||
# raise Exception("Cannot use PlungeAngle != 90.0 degrees without parameter Zprevious")
|
||||
# tanA = math.tan(math.pi * PlungeAngle / 180.0)
|
||||
# minA = (Zprevious - Z) / sum(edge.Length for edge in toolpath)
|
||||
# if tanA < minA:
|
||||
# tanA = minA
|
||||
# #FreeCAD.Console.PrintMessage('Increasing ramp angle to {0} degrees, to be able to make a full round\n'.format(math.atan(tanA) * 180.0 / math.pi))
|
||||
# else:
|
||||
# Zprevious = Z
|
||||
|
||||
lastpt = None
|
||||
output = ""
|
||||
path_length = 0.0
|
||||
Z_cur = Zprevious
|
||||
# lastpt = None
|
||||
# output = ""
|
||||
# path_length = 0.0
|
||||
# Z_cur = Zprevious
|
||||
|
||||
# create the path from the offset shape
|
||||
for edge in toolpath:
|
||||
if not lastpt:
|
||||
# set the first point
|
||||
lastpt = edge.Vertexes[0].Point
|
||||
# FreeCAD.Console.PrintMessage("last pt= " + str(lastpt)+ "\n")
|
||||
output += "G1 X" + str(fmt(lastpt.x)) + " Y" + str(fmt(lastpt.y)) + \
|
||||
" Z" + str(fmt(Z_cur)) + " F" + str(vf) + "\n"
|
||||
# # create the path from the offset shape
|
||||
# for edge in toolpath:
|
||||
# if not lastpt:
|
||||
# # set the first point
|
||||
# lastpt = edge.Vertexes[0].Point
|
||||
# # FreeCAD.Console.PrintMessage("last pt= " + str(lastpt)+ "\n")
|
||||
# output += "G1 X" + str(fmt(lastpt.x)) + " Y" + str(fmt(lastpt.y)) + \
|
||||
# " Z" + str(fmt(Z_cur)) + " F" + str(vf) + "\n"
|
||||
|
||||
if StopLength:
|
||||
if path_length + edge.Length > StopLength:
|
||||
# have to split current edge in two
|
||||
t0 = edge.FirstParameter
|
||||
t1 = edge.LastParameter
|
||||
dL = StopLength - path_length
|
||||
t = t0 + (t1 - t0) * dL / edge.Length
|
||||
assert(t0 < t < t1)
|
||||
edge = edge.split(t).Edges[0]
|
||||
path_length = StopLength
|
||||
else:
|
||||
path_length += edge.Length
|
||||
else:
|
||||
path_length += edge.Length
|
||||
# if StopLength:
|
||||
# if path_length + edge.Length > StopLength:
|
||||
# # have to split current edge in two
|
||||
# t0 = edge.FirstParameter
|
||||
# t1 = edge.LastParameter
|
||||
# dL = StopLength - path_length
|
||||
# t = t0 + (t1 - t0) * dL / edge.Length
|
||||
# assert(t0 < t < t1)
|
||||
# edge = edge.split(t).Edges[0]
|
||||
# path_length = StopLength
|
||||
# else:
|
||||
# path_length += edge.Length
|
||||
# else:
|
||||
# path_length += edge.Length
|
||||
|
||||
if Z_cur > Z:
|
||||
Z_next = Zprevious - path_length * tanA
|
||||
if Z_next < Z:
|
||||
# have to split current edge in two
|
||||
t0 = edge.FirstParameter
|
||||
t1 = edge.LastParameter
|
||||
dZ = Z_cur - Z
|
||||
t = t0 + (t1 - t0) * (dZ / tanA) / edge.Length
|
||||
assert(t0 < t < t1)
|
||||
subwire = edge.split(t)
|
||||
assert(len(subwire.Edges) == 2)
|
||||
Z_cur = Z
|
||||
lastpt, codes = edge_to_path(lastpt, subwire.Edges[0], Z_cur, hf)
|
||||
output += codes
|
||||
edge = subwire.Edges[1]
|
||||
else:
|
||||
Z_cur = Z_next
|
||||
# if Z_cur > Z:
|
||||
# Z_next = Zprevious - path_length * tanA
|
||||
# if Z_next < Z:
|
||||
# # have to split current edge in two
|
||||
# t0 = edge.FirstParameter
|
||||
# t1 = edge.LastParameter
|
||||
# dZ = Z_cur - Z
|
||||
# t = t0 + (t1 - t0) * (dZ / tanA) / edge.Length
|
||||
# assert(t0 < t < t1)
|
||||
# subwire = edge.split(t)
|
||||
# assert(len(subwire.Edges) == 2)
|
||||
# Z_cur = Z
|
||||
# lastpt, codes = edge_to_path(lastpt, subwire.Edges[0], Z_cur, hf)
|
||||
# output += codes
|
||||
# edge = subwire.Edges[1]
|
||||
# else:
|
||||
# Z_cur = Z_next
|
||||
|
||||
lastpt, codes = edge_to_path(lastpt, edge, Z_cur, hf)
|
||||
output += codes
|
||||
# lastpt, codes = edge_to_path(lastpt, edge, Z_cur, hf)
|
||||
# output += codes
|
||||
|
||||
if StopLength:
|
||||
if path_length >= StopLength:
|
||||
break
|
||||
# if StopLength:
|
||||
# if path_length >= StopLength:
|
||||
# break
|
||||
|
||||
return output
|
||||
# return output
|
||||
|
||||
def SortPath(wire, Side, radius, clockwise, firstedge=None, SegLen=0.5):
|
||||
'''SortPath(wire,Side,radius,clockwise,firstedge=None,SegLen =0.5) Sorts the wire and reverses it, if needed. Splits arcs over 180 degrees in two. Returns the reordered offset of the wire. '''
|
||||
if firstedge:
|
||||
edgelist = wire.Edges[:]
|
||||
if wire.isClosed():
|
||||
elindex = None
|
||||
n = 0
|
||||
for e in edgelist:
|
||||
if isSameEdge(e, firstedge):
|
||||
# FreeCAD.Console.PrintMessage('found first edge\n')
|
||||
elindex = n
|
||||
n = n + 1
|
||||
l1 = edgelist[:elindex]
|
||||
l2 = edgelist[elindex:]
|
||||
newedgelist = l2 + l1
|
||||
# def SortPath(wire, Side, radius, clockwise, firstedge=None, SegLen=0.5):
|
||||
# '''SortPath(wire,Side,radius,clockwise,firstedge=None,SegLen =0.5) Sorts the wire and reverses it, if needed. Splits arcs over 180 degrees in two. Returns the reordered offset of the wire. '''
|
||||
# if firstedge:
|
||||
# edgelist = wire.Edges[:]
|
||||
# if wire.isClosed():
|
||||
# elindex = None
|
||||
# n = 0
|
||||
# for e in edgelist:
|
||||
# if isSameEdge(e, firstedge):
|
||||
# # FreeCAD.Console.PrintMessage('found first edge\n')
|
||||
# elindex = n
|
||||
# n = n + 1
|
||||
# l1 = edgelist[:elindex]
|
||||
# l2 = edgelist[elindex:]
|
||||
# newedgelist = l2 + l1
|
||||
|
||||
if clockwise:
|
||||
newedgelist.reverse()
|
||||
last = newedgelist.pop(-1)
|
||||
newedgelist.insert(0, last)
|
||||
# if clockwise:
|
||||
# newedgelist.reverse()
|
||||
# last = newedgelist.pop(-1)
|
||||
# newedgelist.insert(0, last)
|
||||
|
||||
preoffset = []
|
||||
for e in newedgelist:
|
||||
if clockwise:
|
||||
r = reverseEdge(e)
|
||||
preoffset.append(r)
|
||||
else:
|
||||
preoffset.append(e)
|
||||
# preoffset = []
|
||||
# for e in newedgelist:
|
||||
# if clockwise:
|
||||
# r = reverseEdge(e)
|
||||
# preoffset.append(r)
|
||||
# else:
|
||||
# preoffset.append(e)
|
||||
|
||||
sortedpreoff = Part.__sortEdges__(preoffset)
|
||||
wire = Part.Wire(sortedpreoff)
|
||||
#wire = findWires(sortedpreoff)[0]
|
||||
else:
|
||||
sortedpreoff = Part.__sortEdges__(edgelist)
|
||||
wire = Part.Wire(sortedpreoff)
|
||||
#wire = findWires(sortedpreoff)[0]
|
||||
# sortedpreoff = Part.__sortEdges__(preoffset)
|
||||
# wire = Part.Wire(sortedpreoff)
|
||||
# #wire = findWires(sortedpreoff)[0]
|
||||
# else:
|
||||
# sortedpreoff = Part.__sortEdges__(edgelist)
|
||||
# wire = Part.Wire(sortedpreoff)
|
||||
# #wire = findWires(sortedpreoff)[0]
|
||||
|
||||
edgelist = []
|
||||
for e in wire.Edges:
|
||||
if geomType(e) == "Circle":
|
||||
arclist = filterArcs(e)
|
||||
for a in arclist:
|
||||
edgelist.append(a)
|
||||
elif geomType(e) == "LineSegment":
|
||||
edgelist.append(e)
|
||||
elif geomType(e) == "BSplineCurve" or \
|
||||
geomType(e) == "BezierCurve" or \
|
||||
geomType(e) == "Ellipse":
|
||||
edgelist.append(Part.Wire(curvetowire(e, (SegLen))))
|
||||
#newwire = Part.Wire(edgelist)
|
||||
sortededges = Part.__sortEdges__(edgelist)
|
||||
newwire = findWires(sortededges)[0]
|
||||
# edgelist = []
|
||||
# for e in wire.Edges:
|
||||
# if geomType(e) == "Circle":
|
||||
# arclist = filterArcs(e)
|
||||
# for a in arclist:
|
||||
# edgelist.append(a)
|
||||
# elif geomType(e) == "LineSegment":
|
||||
# edgelist.append(e)
|
||||
# elif geomType(e) == "BSplineCurve" or \
|
||||
# geomType(e) == "BezierCurve" or \
|
||||
# geomType(e) == "Ellipse":
|
||||
# edgelist.append(Part.Wire(curvetowire(e, (SegLen))))
|
||||
# #newwire = Part.Wire(edgelist)
|
||||
# sortededges = Part.__sortEdges__(edgelist)
|
||||
# newwire = findWires(sortededges)[0]
|
||||
|
||||
if is_clockwise(newwire) is not clockwise:
|
||||
newwire.reverse()
|
||||
# if is_clockwise(newwire) is not clockwise:
|
||||
# newwire.reverse()
|
||||
|
||||
if Side == 'Left':
|
||||
# we use the OCC offset feature
|
||||
offset = newwire.makeOffset(radius) # tool is outside line
|
||||
elif Side == 'Right':
|
||||
offset = newwire.makeOffset(-radius) # tool is inside line
|
||||
else:
|
||||
if wire.isClosed():
|
||||
offset = newwire.makeOffset(0.0)
|
||||
else:
|
||||
offset = newwire
|
||||
offset.reverse()
|
||||
# if Side == 'Left':
|
||||
# # we use the OCC offset feature
|
||||
# offset = newwire.makeOffset(radius) # tool is outside line
|
||||
# elif Side == 'Right':
|
||||
# offset = newwire.makeOffset(-radius) # tool is inside line
|
||||
# else:
|
||||
# if wire.isClosed():
|
||||
# offset = newwire.makeOffset(0.0)
|
||||
# else:
|
||||
# offset = newwire
|
||||
# offset.reverse()
|
||||
|
||||
return offset
|
||||
# return offset
|
||||
|
||||
|
||||
def MakePath(wire, Side, radius, clockwise, ZClearance, StepDown, ZStart,
|
||||
ZFinalDepth, firstedge=None, PathClosed=True, SegLen=0.5,
|
||||
VertFeed=1.0, HorizFeed=2.0, VertJog=1.0, HorizJog = 2.0, PlungeAngle=90.0):
|
||||
''' makes the path - just a simple profile for now '''
|
||||
offset = SortPath(wire, Side, radius, clockwise, firstedge, SegLen=SegLen)
|
||||
if len(offset.Edges) == 0:
|
||||
return ""
|
||||
# def MakePath(wire, Side, radius, clockwise, ZClearance, StepDown, ZStart,
|
||||
# ZFinalDepth, firstedge=None, PathClosed=True, SegLen=0.5,
|
||||
# VertFeed=1.0, HorizFeed=2.0, VertJog=1.0, HorizJog = 2.0, PlungeAngle=90.0):
|
||||
# ''' makes the path - just a simple profile for now '''
|
||||
# offset = SortPath(wire, Side, radius, clockwise, firstedge, SegLen=SegLen)
|
||||
# if len(offset.Edges) == 0:
|
||||
# return ""
|
||||
|
||||
toolpath = offset.Edges[:]
|
||||
paths = ""
|
||||
paths += "G0 Z" + str(ZClearance) + "F " + fmt(VertJog) + "\n"
|
||||
first = toolpath[0].Vertexes[0].Point
|
||||
paths += "G0 X" + str(fmt(first.x)) + "Y" + str(fmt(first.y)) + "F " + fmt(HorizJog) + "\n"
|
||||
Zprevious = ZStart
|
||||
ZCurrent = ZStart - StepDown
|
||||
# toolpath = offset.Edges[:]
|
||||
# paths = ""
|
||||
# paths += "G0 Z" + str(ZClearance) + "F " + fmt(VertJog) + "\n"
|
||||
# first = toolpath[0].Vertexes[0].Point
|
||||
# paths += "G0 X" + str(fmt(first.x)) + "Y" + str(fmt(first.y)) + "F " + fmt(HorizJog) + "\n"
|
||||
# Zprevious = ZStart
|
||||
# ZCurrent = ZStart - StepDown
|
||||
|
||||
while ZCurrent > ZFinalDepth:
|
||||
paths += convert(toolpath, Z=ZCurrent, Zprevious=Zprevious, PlungeAngle=PlungeAngle,
|
||||
vf=VertFeed, hf=HorizFeed)
|
||||
if not PathClosed:
|
||||
paths += "G0 Z" + str(ZClearance) + "F " + fmt(VertJog)
|
||||
paths += "G0 X" + str(fmt(first.x)) + "Y" + \
|
||||
str(fmt(first.y)) + "F " + fmt(HorizJog) + "\n"
|
||||
Zprevious = ZCurrent
|
||||
ZCurrent = ZCurrent - abs(StepDown)
|
||||
# while ZCurrent > ZFinalDepth:
|
||||
# paths += convert(toolpath, Z=ZCurrent, Zprevious=Zprevious, PlungeAngle=PlungeAngle,
|
||||
# vf=VertFeed, hf=HorizFeed)
|
||||
# if not PathClosed:
|
||||
# paths += "G0 Z" + str(ZClearance) + "F " + fmt(VertJog)
|
||||
# paths += "G0 X" + str(fmt(first.x)) + "Y" + \
|
||||
# str(fmt(first.y)) + "F " + fmt(HorizJog) + "\n"
|
||||
# Zprevious = ZCurrent
|
||||
# ZCurrent = ZCurrent - abs(StepDown)
|
||||
|
||||
# do the final Z value
|
||||
paths += convert(toolpath, Z=ZFinalDepth, Zprevious=Zprevious, PlungeAngle=PlungeAngle,
|
||||
vf=VertFeed, hf=HorizFeed)
|
||||
# # do the final Z value
|
||||
# paths += convert(toolpath, Z=ZFinalDepth, Zprevious=Zprevious, PlungeAngle=PlungeAngle,
|
||||
# vf=VertFeed, hf=HorizFeed)
|
||||
|
||||
# when plunging with != 90 degree we have to do one last pass to clear the remaining ramp
|
||||
if PlungeAngle != 90.0:
|
||||
tanA = math.tan(math.pi * PlungeAngle / 180.0)
|
||||
if tanA <= 0.0:
|
||||
StopLength=None
|
||||
else:
|
||||
StopLength=abs(StepDown/tanA)
|
||||
paths += convert(toolpath, Z=ZFinalDepth, Zprevious=Zprevious, StopLength=StopLength,
|
||||
vf=VertFeed, hf=HorizFeed)
|
||||
# # when plunging with != 90 degree we have to do one last pass to clear the remaining ramp
|
||||
# if PlungeAngle != 90.0:
|
||||
# tanA = math.tan(math.pi * PlungeAngle / 180.0)
|
||||
# if tanA <= 0.0:
|
||||
# StopLength=None
|
||||
# else:
|
||||
# StopLength=abs(StepDown/tanA)
|
||||
# paths += convert(toolpath, Z=ZFinalDepth, Zprevious=Zprevious, StopLength=StopLength,
|
||||
# vf=VertFeed, hf=HorizFeed)
|
||||
|
||||
paths += "G0 Z" + str(ZClearance) + "F " + fmt(VertJog) + "\n"
|
||||
return paths
|
||||
# paths += "G0 Z" + str(ZClearance) + "F " + fmt(VertJog) + "\n"
|
||||
# return paths
|
||||
|
||||
# the next two functions are for automatically populating tool
|
||||
# numbers/height offset numbers based on previously active toolnumbers
|
||||
@@ -548,19 +546,19 @@ def getLastToolLoad(obj):
|
||||
continue
|
||||
return tc
|
||||
|
||||
def getToolControllers(obj):
|
||||
controllers = []
|
||||
try:
|
||||
parent = obj.InList[0]
|
||||
except:
|
||||
parent = None
|
||||
# def getToolControllers(obj):
|
||||
# controllers = []
|
||||
# try:
|
||||
# parent = obj.InList[0]
|
||||
# except:
|
||||
# parent = None
|
||||
|
||||
if parent is not None and hasattr(parent, 'Group'):
|
||||
sibs = parent.Group
|
||||
for g in sibs:
|
||||
if isinstance(g.Proxy, PathScripts.PathLoadTool.LoadTool):
|
||||
controllers.append(g.Name)
|
||||
return controllers
|
||||
# if parent is not None and hasattr(parent, 'Group'):
|
||||
# sibs = parent.Group
|
||||
# for g in sibs:
|
||||
# if isinstance(g.Proxy, PathScripts.PathLoadTool.LoadTool):
|
||||
# controllers.append(g.Name)
|
||||
# return controllers
|
||||
|
||||
|
||||
|
||||
@@ -614,7 +612,6 @@ def addToJob(obj, jobname = None):
|
||||
else:
|
||||
#form = FreeCADGui.PySideUic.loadUi(FreeCAD.getHomePath() + "Mod/Path/DlgJobChooser.ui")
|
||||
form = FreeCADGui.PySideUic.loadUi(":/panels/DlgJobChooser.ui")
|
||||
|
||||
mylist = [i.Name for i in jobs]
|
||||
form.cboProject.addItems(mylist)
|
||||
r = form.exec_()
|
||||
@@ -629,15 +626,15 @@ def addToJob(obj, jobname = None):
|
||||
job.Group = g
|
||||
return job
|
||||
|
||||
def getLastZ(obj):
|
||||
''' find the last z value in the job '''
|
||||
lastZ = ""
|
||||
for g in obj.Group:
|
||||
for c in g.Path.Commands:
|
||||
for n in c.Parameters:
|
||||
if n == 'Z':
|
||||
lastZ = c.Parameters['Z']
|
||||
return lastZ
|
||||
# def getLastZ(obj):
|
||||
# ''' find the last z value in the job '''
|
||||
# lastZ = ""
|
||||
# for g in obj.Group:
|
||||
# for c in g.Path.Commands:
|
||||
# for n in c.Parameters:
|
||||
# if n == 'Z':
|
||||
# lastZ = c.Parameters['Z']
|
||||
# return lastZ
|
||||
|
||||
def rapid(x=None, y=None, z=None):
|
||||
""" Returns gcode string to perform a rapid move."""
|
||||
|
||||
Reference in New Issue
Block a user