From 2fe75fcd478372fd58cee9022caebed9bd40e6c4 Mon Sep 17 00:00:00 2001 From: HDR Date: Wed, 20 Jul 2016 09:25:26 +0600 Subject: [PATCH] Cleanup --- FlatCAMObj.py | 1 + VisPyTesselators.py | 2 +- VisPyVisuals.py | 41 ++++++++--------------------------------- 3 files changed, 10 insertions(+), 34 deletions(-) diff --git a/FlatCAMObj.py b/FlatCAMObj.py index 58fb9e6..97d0478 100644 --- a/FlatCAMObj.py +++ b/FlatCAMObj.py @@ -11,6 +11,7 @@ from VisPyVisuals import ShapeCollection from shapely.geometry.base import CAP_STYLE, JOIN_STYLE +# Interrupts plotting process if FlatCAMObj has been deleted class ObjectDeleted(Exception): pass diff --git a/VisPyTesselators.py b/VisPyTesselators.py index 037397e..72ecb75 100644 --- a/VisPyTesselators.py +++ b/VisPyTesselators.py @@ -30,7 +30,6 @@ class GLUTess: pass def triangulate(self, polygon): - # Create tessellation object """ Triangulates polygon :param polygon: shapely.geometry.polygon @@ -39,6 +38,7 @@ class GLUTess: Array of triangle vertex indices [t0i0, t0i1, t0i2, t1i0, t1i1, ... ] Array of polygon points [(x0, y0), (x1, y1), ... ] """ + # Create tessellation object tess = GLU.gluNewTess() # Setup callbacks diff --git a/VisPyVisuals.py b/VisPyVisuals.py index d34fe1c..48b9744 100644 --- a/VisPyVisuals.py +++ b/VisPyVisuals.py @@ -14,7 +14,7 @@ def _update_shape_buffers(data, triangulation='glu'): Translates Shapely geometry to internal buffers for speedup redraws :param data: dict Input shape data - :param triangulation: + :param triangulation: str Triangulation engine """ mesh_vertices = [] # Vertices for mesh @@ -78,32 +78,6 @@ def _update_shape_buffers(data, triangulation='glu'): return data -def _open_ring(vertices): - """ - Make lines ring open - :param vertices: numpy.array - Array of lines vertices - :return: numpy.array - Opened line strip - """ - return vertices[:-1] if not vertices[0] != vertices[-1] else vertices - - -def _generate_edges(count): - """ - Generates edges indexes in form: [[0, 1], [1, 2], [2, 3], ... ] - :param count: int - Edges count - :return: numpy.array - Edges - """ - edges = np.empty((count, 2), dtype=np.uint32) - edges[:, 0] = np.arange(count) - edges[:, 1] = edges[:, 0] + 1 - edges[-1, 1] = 0 - return edges - - def _linearring_to_segments(arr): # Close linear ring """ @@ -254,18 +228,21 @@ class ShapeCollectionVisual(CompoundVisual): :param layer: int Layer number. 0 - lowest. :param tolerance: float - Geometry simplify tolerance + Geometry simplifying tolerance :return: int Index of shape """ + # Get new key self.lock.acquire(True) self.last_key += 1 key = self.last_key self.lock.release() + # Prepare data for translation self.data[key] = {'geometry': shape, 'color': color, 'face_color': face_color, - 'visible': visible, 'layer': layer, 'tolerance': tolerance} + 'visible': visible, 'layer': layer, 'tolerance': tolerance} + # Add data to process pool self.results[key] = self.pool.apply_async(_update_shape_buffers, [self.data[key]]) if update: @@ -313,8 +290,6 @@ class ShapeCollectionVisual(CompoundVisual): try: line_pts[data['layer']] += data['line_pts'] line_colors[data['layer']] += data['line_colors'] - # mesh_tris[data['layer']] += [[x + len(mesh_vertices[data['layer']]) - # for x in y] for y in data['mesh_tris']] mesh_tris[data['layer']] += [x + len(mesh_vertices[data['layer']]) for x in data['mesh_tris']] @@ -353,9 +328,9 @@ class ShapeCollectionVisual(CompoundVisual): """ for i in self.data.keys() if not indexes else indexes: try: - self.results[i].wait() + self.results[i].wait() # Wait for process results if i in self.data: - self.data[i] = self.results[i].get() + self.data[i] = self.results[i].get() # Store translated data except Exception as e: print e