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
# -*- coding: utf-8 -*-
"""
$Id$
Copyright 2008 Lode Leroy
This file is part of PyCAM.
PyCAM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
PyCAM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
"""
__all__ = ["PathAccumulator", "SimpleCutter", "ZigZagCutter", "PolygonCutter",
"ContourCutter", "BasePathProcessor"]
class BasePathProcessor(object):
def __init__(self):
self.paths = []
def new_direction(self, direction):
pass
def end_direction(self):
pass
def finish(self):
pass
def sort_layered(self, upper_first=True):
if upper_first:
compare_height = lambda path1, path2: \
path1.points[0][2] < path2.points[0][2]
else:
compare_height = lambda path1, path2: \
path1.points[0][2] > path2.points[0][2]
finished = False
while not finished:
index = 0
finished = True
while index < len(self.paths) - 1:
current_path = self.paths[index]
next_path = self.paths[index + 1]
if compare_height(current_path, next_path):
del self.paths[index]
self.paths.insert(index + 1, current_path)
finished = False
index += 1