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
# -*- coding: utf-8 -*-
"""
$Id$
Copyright 2010 Lars Kruse <devel@sumpfralle.de>
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/>.
"""
""" the points of a path are only used for describing coordinates. Thus we
don't really need complete "Point" instances that consume a lot of memory.
Since python 2.6 the "namedtuple" factory is available.
This reduces the memory consumption of a toolpath down to 1/3.
"""
try:
# this works for python 2.6 or above (saves memory)
# TODO: disabled for now - check if we could enable it later ...
import INVALID_IMPORT
from collections import namedtuple
tuple_point = namedtuple("TuplePoint", "x y z")
get_point_object = lambda point: tuple_point(point.x, point.y, point.z)
except ImportError:
# dummy for python < v2.6 (consumes more memory)
get_point_object = lambda point: point
from pycam.Geometry import IDGenerator
class Path(IDGenerator):
def __init__(self):
super(Path, self).__init__()
self.top_join = None
self.bot_join = None
self.winding = 0
self.points = []
def __repr__(self):
text = ""
text += "path %d: " % self.id
first = True
for point in self.points:
if first:
first = False
else:
text += "-"
text += "%d(%g,%g,%g)" % (point.id, point.x, point.y, point.z)
return text
def insert(self, index, point):
self.points.insert(index, get_point_object(point))
def append(self, point):
self.points.append(get_point_object(point))
def reverse(self):
self.points.reverse()