Commit f752d9b6 authored by sumpfralle's avatar sumpfralle

replace class-based id generation with new IDGenerator class


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1243 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent d16fc11c
......@@ -36,7 +36,7 @@ from pycam.Geometry.TriangleKdtree import TriangleKdtree
from pycam.Geometry.Matrix import TRANSFORMATIONS
from pycam.Toolpath import Bounds
from pycam.Geometry.utils import INFINITE, epsilon
from pycam.Geometry import TransformableContainer
from pycam.Geometry import TransformableContainer, IDGenerator
from pycam.Utils import ProgressCounter
import pycam.Utils.log
......@@ -80,12 +80,10 @@ def get_combined_model(models):
return result
class BaseModel(TransformableContainer):
id = 0
class BaseModel(IDGenerator, TransformableContainer):
def __init__(self):
self.id = BaseModel.id
BaseModel.id += 1
super(BaseModel, self).__init__()
self._item_groups = []
self.name = "model%d" % self.id
self.minx = None
......@@ -1059,11 +1057,10 @@ class TriangleOptimizer(object):
return result
class Rectangle(TransformableContainer):
id = 0
class Rectangle(IDGenerator, TransformableContainer):
def __init__(self, p1, p2, p3, p4, normal=None):
super(Rectangle, self).__init__()
if normal:
orders = ((p1, p2, p3, p4), (p1, p2, p4, p3), (p1, p3, p2, p4),
(p1, p3, p4, p2), (p1, p4, p2, p3), (p1, p4, p3, p2))
......@@ -1082,8 +1079,6 @@ class Rectangle(TransformableContainer):
self.p2 = p2
self.p3 = p3
self.p4 = p4
self.id = Rectangle.id
Rectangle.id += 1
self.reset_cache()
def reset_cache(self):
......
......@@ -38,12 +38,13 @@ except ImportError:
# dummy for python < v2.6 (consumes more memory)
get_point_object = lambda point: point
from pycam.Geometry import IDGenerator
class Path(IDGenerator):
class Path(object):
id = 0
def __init__(self):
self.id = Path.id
Path.id += 1
super(Path, self).__init__()
self.top_join = None
self.bot_join = None
self.winding = 0
......
......@@ -23,7 +23,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
from pycam.Geometry.Line import Line
from pycam.Geometry.Point import Point, Vector
from pycam.Geometry.Plane import Plane
from pycam.Geometry import TransformableContainer, get_bisector
from pycam.Geometry import TransformableContainer, IDGenerator, get_bisector
from pycam.Geometry.utils import number, epsilon
import pycam.Utils.log
# import later to avoid circular imports
......@@ -42,15 +42,14 @@ LINE_WIDTH_OUTER = 1.3
log = pycam.Utils.log.get_logger()
class PolygonInTree(object):
class PolygonInTree(IDGenerator):
""" This class is a wrapper around Polygon objects that is used for sorting.
"""
next_id = 0
def __init__(self, polygon):
self.id = PolygonInTree.next_id
PolygonInTree.next_id += 1
super(PolygonInTree, self).__init__()
self.start = polygon.get_points()[0]
self.end = polygon.get_points()[-1]
self.polygon = polygon
......@@ -878,11 +877,20 @@ class Polygon(TransformableContainer):
if len(new_group) > 0:
group_starts = []
index1 = 0
fallout3 = 0
while index1 < len(new_group):
index2 = 0
fallout2 = len(new_group)
fallout3 += 1
while index2 < len(new_group):
fallout2 -= 1
index_distance = min(abs(index2 - index1), \
abs(len(new_group) - (index2 - index1)))
if fallout3 > 10000:
print "FALLOUT3"
print index_distance, index2, index1, len(new_group), len(group_starts)
import sys
sys.exit(1)
# skip neighbours
if index_distance > 1:
line1 = new_group[index1]
......
......@@ -21,6 +21,8 @@ You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
"""
from pycam.Geometry import IDGenerator
try:
import OpenGL.GL as GL
GL_enabled = True
......@@ -35,6 +37,7 @@ class Node(object):
s += "%g : " % bound
return s
def find_max_spread(nodes):
minval = []
maxval = []
......@@ -57,17 +60,15 @@ def find_max_spread(nodes):
return (maxspreaddim, maxspread)
class kdtree(object):
id = 0
class kdtree(IDGenerator):
def __init__(self, nodes, cutoff, cutoff_distance):
self.id = kdtree.id
super(kdtree, self).__init__()
self.bucket = False
if nodes and len(nodes) > 0:
self.dim = len(nodes[0].bound)
else:
self.dim = 0
kdtree.id += 1
self.cutoff = cutoff
self.cutoff_distance = cutoff_distance
......
......@@ -53,3 +53,4 @@ if _use_precision:
else:
number = lambda value: float(value)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment