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