Commit 7ab35a68 authored by sumpfralle's avatar sumpfralle

better progress visualization for 2D model offsetting


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@890 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 073da262
...@@ -485,7 +485,7 @@ class ContourModel(BaseModel): ...@@ -485,7 +485,7 @@ class ContourModel(BaseModel):
def get_offset_model(self, offset, callback=None): def get_offset_model(self, offset, callback=None):
result = ContourModel(plane=self._plane) result = ContourModel(plane=self._plane)
for group in self.get_polygons(): for group in self.get_polygons():
new_groups = group.get_offset_polygons(offset) new_groups = group.get_offset_polygons(offset, callback=callback)
result.extend(new_groups) result.extend(new_groups)
if callback and callback(): if callback and callback():
return None return None
......
...@@ -582,7 +582,7 @@ class Polygon(TransformableContainer): ...@@ -582,7 +582,7 @@ class Polygon(TransformableContainer):
self._cached_offset_polygons[offset] = result_polygons self._cached_offset_polygons[offset] = result_polygons
return result_polygons return result_polygons
def get_offset_polygons(self, offset): def get_offset_polygons(self, offset, callback=None):
def get_shifted_vertex(index, offset): def get_shifted_vertex(index, offset):
p1 = self._points[index] p1 = self._points[index]
p2 = self._points[(index + 1) % len(self._points)] p2 = self._points[(index + 1) % len(self._points)]
...@@ -697,6 +697,8 @@ class Polygon(TransformableContainer): ...@@ -697,6 +697,8 @@ class Polygon(TransformableContainer):
p1 = points[index] p1 = points[index]
p2 = points[(index + 1) % len(points)] p2 = points[(index + 1) % len(points)]
new_lines.append(Line(p1, p2)) new_lines.append(Line(p1, p2))
if callback and callback():
return None
cleaned_line_groups = simplify_polygon_intersections(new_lines) cleaned_line_groups = simplify_polygon_intersections(new_lines)
if cleaned_line_groups is None: if cleaned_line_groups is None:
log.debug("Skipping offset polygon: intersections could not be " \ log.debug("Skipping offset polygon: intersections could not be " \
...@@ -710,6 +712,8 @@ class Polygon(TransformableContainer): ...@@ -710,6 +712,8 @@ class Polygon(TransformableContainer):
self_is_outer = self.is_outer() self_is_outer = self.is_outer()
groups = [] groups = []
for lines in cleaned_line_groups: for lines in cleaned_line_groups:
if callback and callback():
return None
group = Polygon(self.plane) group = Polygon(self.plane)
for line in lines: for line in lines:
group.append(line) group.append(line)
...@@ -734,6 +738,8 @@ class Polygon(TransformableContainer): ...@@ -734,6 +738,8 @@ class Polygon(TransformableContainer):
for group in groups: for group in groups:
inside = False inside = False
for group_test in groups: for group_test in groups:
if callback and callback():
return None
if group_test is group: if group_test is group:
continue continue
if group_test.is_polygon_inside(group): if group_test.is_polygon_inside(group):
......
...@@ -218,12 +218,8 @@ def generate_toolpath(model, tool_settings=None, ...@@ -218,12 +218,8 @@ def generate_toolpath(model, tool_settings=None,
if (not contour_model is None) and (engrave_offset != 0): if (not contour_model is None) and (engrave_offset != 0):
if not callback is None: if not callback is None:
callback(text="Preparing contour model with offset ...") callback(text="Preparing contour model with offset ...")
progress_callback = ProgressCounter(
len(contour_model.get_polygons()), callback).increment
else:
progress_callback = None
contour_model = contour_model.get_offset_model(engrave_offset, contour_model = contour_model.get_offset_model(engrave_offset,
callback=progress_callback) callback=callback)
if contour_model is None: if contour_model is None:
return "Failed to calculate offset polygons" return "Failed to calculate offset polygons"
if not callback is None: if not callback is None:
......
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