Debian Codegraph @

examples/python/test.py

raw
1 from opencamlib import ocl
2
3 def pointToXYZ(point):
4 return "X{:.5f}".format(point.x).rstrip('0').rstrip('.') + " Y{:.5f}".format(point.y).rstrip('0').rstrip('.') + " Z{:.5f}".format(point.z).rstrip('0').rstrip('.')
5
6 def waterline(surface, cutter, z, sampling):
7 wl = ocl.Waterline()
8 wl.setSTL(surface)
9 wl.setCutter(cutter)
10 wl.setZ(z)
11 wl.setSampling(sampling)
12 wl.run()
13 gcode = ''
14 loops = wl.getLoops()
15 for loop in loops:
16 for point in loop:
17 gcode += "G01 " + pointToXYZ(point) + "\n"
18 print(gcode)
19
20 def adaptiveWaterline(surface, cutter, z, sampling, minSampling):
21 print('AdaptiveWaterline')
22 awl = ocl.AdaptiveWaterline()
23 awl.setSTL(surface)
24 awl.setCutter(cutter)
25 awl.setZ(z)
26 awl.setSampling(sampling)
27 awl.setMinSampling(minSampling)
28 awl.run()
29 gcode = ''
30 loops = awl.getLoops()
31 for loop in loops:
32 for point in loop:
33 gcode += "G01 " + pointToXYZ(point) + "\n"
34 print(gcode)
35
36 def pathDropCutter(surface, cutter, sampling, path):
37 print('PathDropCutter')
38 pdc = ocl.PathDropCutter()
39 pdc.setSTL(surface)
40 pdc.setCutter(cutter)
41 pdc.setPath(path)
42 pdc.setZ(0)
43 pdc.setSampling(sampling)
44 pdc.run()
45 points = pdc.getCLPoints()
46 gcode = ''
47 for point in points:
48 gcode += "G01 " + pointToXYZ(point) + "\n"
49 print(gcode)
50
51 def adaptivePathDropCutter(surface, cutter, sampling, minSampling, path):
52 print('AdaptivePathDropCutter')
53 apdc = ocl.AdaptivePathDropCutter()
54 apdc.setSTL(surface)
55 apdc.setCutter(cutter)
56 apdc.setPath(path)
57 apdc.setZ(0)
58 apdc.setSampling(sampling)
59 apdc.setMinSampling(minSampling)
60 apdc.run()
61 points = apdc.getCLPoints()
62 gcode = ''
63 for point in points:
64 gcode += "G01 " + pointToXYZ(point) + "\n"
65 print(gcode)
66
67 if __name__ == "__main__":
68 print(ocl.version())
69 surface = ocl.STLSurf()
70 ocl.STLReader("../../stl/gnu_tux_mod.stl", surface)
71 cutter = ocl.CylCutter(4, 20)
72 waterline(surface, cutter, 1, 0.1)
73 adaptiveWaterline(surface, cutter, 1, 0.1, 0.001)
74 path = ocl.Path()
75 p1 = ocl.Point(-2, 4, 0)
76 p2 = ocl.Point(11, 4, 0)
77 l = ocl.Line(p1, p2)
78 path.append(l)
79 pathDropCutter(surface, cutter, 0.1, path)
80 adaptivePathDropCutter(surface, cutter, 0.04, 0.01, path)
81 print("done.")