-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathattach.py
134 lines (110 loc) · 4.32 KB
/
attach.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
################################################################################
# attach.py
#
# NC code creator for attaching Z coordinates to a surface
#
import recreator
import ocl
import ocl_funcs
import nc.nc
attached = False
units = 1.0
################################################################################
class Creator(recreator.Redirector):
def __init__(self, original):
recreator.Redirector.__init__(self, original)
self.stl = None
self.cutter = None
self.minz = None
self.path = None
self.pdcf = None
self.material_allowance = 0.0
############################################################################
## Shift in Z
def setPdcfIfNotSet(self):
if self.pdcf == None:
self.pdcf = ocl.PathDropCutter()
self.pdcf.setSTL(self.stl)
self.pdcf.setCutter(self.cutter)
self.pdcf.setSampling(0.1)
self.pdcf.setZ(self.minz/units)
def z2(self, z):
path = ocl.Path()
# use a line with no length
path.append(ocl.Line(ocl.Point(self.x, self.y, self.z), ocl.Point(self.x, self.y, self.z)))
self.setPdcfIfNotSet()
if (self.z>self.minz):
self.pdcf.setZ(self.z) # Adjust Z if we have gotten a higher limit (Fix pocketing loosing steps when using attach?)
else:
self.pdcf.setZ(self.minz/units) # Else use minz
self.pdcf.setPath(path)
self.pdcf.run()
plist = self.pdcf.getCLPoints()
p = plist[0]
return p.z + self.material_allowance/units
def cut_path(self):
if self.path == None: return
self.setPdcfIfNotSet()
if (self.z>self.minz):
self.pdcf.setZ(self.z) # Adjust Z if we have gotten a higher limit (Fix pocketing loosing steps when using attach?)
else:
self.pdcf.setZ(self.minz/units) # Else use minz
# get the points on the surface
self.pdcf.setPath(self.path)
self.pdcf.run()
plist = self.pdcf.getCLPoints()
#refine the points
f = ocl.LineCLFilter()
f.setTolerance(0.005)
for p in plist:
f.addCLPoint(p)
f.run()
plist = f.getCLPoints()
i = 0
for p in plist:
if i > 0:
self.original.feed(p.x/units, p.y/units, p.z/units + self.material_allowance/units)
i = i + 1
self.path = ocl.Path()
def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None ):
if z != None and self.z != None:
if z < self.z:
return
recreator.Redirector.rapid(self, x, y, z, a, b, c)
def feed(self, x=None, y=None, z=None, a=None, b=None, c=None):
px = self.x
py = self.y
pz = self.z
recreator.Redirector.feed(self, x, y, z, a, b, c)
if self.x == None or self.y == None or self.z == None:
return
if px == self.x and py == self.y:
return
# add a line to the path
if self.path == None: self.path = ocl.Path()
self.path.append(ocl.Line(ocl.Point(px, py, pz), ocl.Point(self.x, self.y, self.z)))
def arc(self, x=None, y=None, z=None, i=None, j=None, k=None, r=None, ccw = True):
px = self.x
py = self.y
pz = self.z
recreator.Redirector.arc(self, x, y, z, i, j, k, r, ccw)
# add an arc to the path
if self.path == None: self.path = ocl.Path()
self.path.append(ocl.Arc(ocl.Point(px, py, pz), ocl.Point(self.x, self.y, self.z), ocl.Point(i, j, pz), ccw))
def set_ocl_cutter(self, cutter):
self.cutter = cutter
################################################################################
def attach_begin():
global attached
if attached == True:
attach_end()
nc.nc.creator = Creator(nc.nc.creator)
recreator.units = units
attached = True
nc.nc.creator.pdcf = None
nc.nc.creator.path = None
def attach_end():
global attached
nc.nc.creator.cut_path()
nc.nc.creator = nc.nc.creator.original
attached = False